code
stringlengths
10
343k
docstring
stringlengths
36
21.9k
func_name
stringlengths
1
3.35k
language
stringclasses
1 value
repo
stringlengths
7
58
path
stringlengths
4
131
url
stringlengths
44
195
license
stringclasses
5 values
Size.prototype.setMode = function setMode(x, y, z) { this._node.setSizeMode(x, y, z); return this; };
Set which mode each axis of Size will have its dimensions calculated by. Size can be calculated by absolute pixel definitions, relative to its parent, or by the size of its renderables @method @param {Number} x the mode of size for the width @param {Number} y the mode of size for the height @param {Number} z the mode of size for the depth @return {Size} this
setMode ( x , y , z )
javascript
Famous/engine
components/Size.js
https://github.com/Famous/engine/blob/master/components/Size.js
MIT
Size.prototype.toString = function toString() { return 'Size'; };
Return the name of the Size component @method @return {String} Name of the component
toString ( )
javascript
Famous/engine
components/Size.js
https://github.com/Famous/engine/blob/master/components/Size.js
MIT
Size.prototype.setValue = function setValue(state) { if (this.toString() === state.component) { this.setMode.apply(this, state.sizeMode); if (state.absolute) { this.setAbsolute(state.absolute.x, state.absolute.y, state.absolute.z); } if (state.differential) { this.setAbsolute(state.differential.x, state.differential.y, state.differential.z); } if (state.proportional) { this.setAbsolute(state.proportional.x, state.proportional.y, state.proportional.z); } } return false; };
Updates state of component. @method @param {Object} state state encoded in same format as state retrieved through `getValue` @return {Boolean} boolean indicating whether the new state has been applied
setValue ( state )
javascript
Famous/engine
components/Size.js
https://github.com/Famous/engine/blob/master/components/Size.js
MIT
Size.prototype._isActive = function _isActive(type) { return type.x.isActive() || type.y.isActive() || type.z.isActive(); };
Helper function that grabs the activity of a certain type of size. @method @private @param {Object} type Representation of a type of the sizing model @return {Boolean} boolean indicating whether the new state has been applied
_isActive ( type )
javascript
Famous/engine
components/Size.js
https://github.com/Famous/engine/blob/master/components/Size.js
MIT
Size.prototype.isActive = function isActive(){ return ( this._isActive(this._absolute) || this._isActive(this._proportional) || this._isActive(this._differential) ); };
Helper function that grabs the activity of a certain type of size. @method @param {String} type Type of size @return {Boolean} boolean indicating whether the new state has been applied
isActive ( )
javascript
Famous/engine
components/Size.js
https://github.com/Famous/engine/blob/master/components/Size.js
MIT
Size.prototype.onUpdate = function onUpdate() { var abs = this._absolute; this._node.setAbsoluteSize( abs.x.get(), abs.y.get(), abs.z.get() ); var prop = this._proportional; var diff = this._differential; this._node.setProportionalSize( prop.x.get(), prop.y.get(), prop.z.get() ); this._node.setDifferentialSize( diff.x.get(), diff.y.get(), diff.z.get() ); if (this.isActive()) this._node.requestUpdateOnNextTick(this._id); else this._requestingUpdate = false; };
When the node this component is attached to updates, update the value of the Node's size. @method @return {undefined} undefined
onUpdate ( )
javascript
Famous/engine
components/Size.js
https://github.com/Famous/engine/blob/master/components/Size.js
MIT
Size.prototype.setAbsolute = function setAbsolute(x, y, z, options, callback) { if (!this._requestingUpdate) { this._node.requestUpdate(this._id); this._requestingUpdate = true; } var xCallback; var yCallback; var zCallback; if (z != null) { zCallback = callback; } else if (y != null) { yCallback = callback; } else if (x != null) { xCallback = callback; } var abs = this._absolute; if (x != null) { abs.x.set(x, options, xCallback); } if (y != null) { abs.y.set(y, options, yCallback); } if (z != null) { abs.z.set(z, options, zCallback); } };
Applies absolute size. @method @param {Number} x used to set absolute size in x-direction (width) @param {Number} y used to set absolute size in y-direction (height) @param {Number} z used to set absolute size in z-direction (depth) @param {Object} options options hash @param {Function} callback callback function to be executed after the transitions have been completed @return {Size} this
setAbsolute ( x , y , z , options , callback )
javascript
Famous/engine
components/Size.js
https://github.com/Famous/engine/blob/master/components/Size.js
MIT
Size.prototype.setProportional = function setProportional(x, y, z, options, callback) { if (!this._requestingUpdate) { this._node.requestUpdate(this._id); this._requestingUpdate = true; } var xCallback; var yCallback; var zCallback; if (z != null) { zCallback = callback; } else if (y != null) { yCallback = callback; } else if (x != null) { xCallback = callback; } var prop = this._proportional; if (x != null) { prop.x.set(x, options, xCallback); } if (y != null) { prop.y.set(y, options, yCallback); } if (z != null) { prop.z.set(z, options, zCallback); } return this; };
Applies proportional size. @method @param {Number} x used to set proportional size in x-direction (width) @param {Number} y used to set proportional size in y-direction (height) @param {Number} z used to set proportional size in z-direction (depth) @param {Object} options options hash @param {Function} callback callback function to be executed after the transitions have been completed @return {Size} this
setProportional ( x , y , z , options , callback )
javascript
Famous/engine
components/Size.js
https://github.com/Famous/engine/blob/master/components/Size.js
MIT
Size.prototype.setDifferential = function setDifferential(x, y, z, options, callback) { if (!this._requestingUpdate) { this._node.requestUpdate(this._id); this._requestingUpdate = true; } var xCallback; var yCallback; var zCallback; if (z != null) { zCallback = callback; } else if (y != null) { yCallback = callback; } else if (x != null) { xCallback = callback; } var diff = this._differential; if (x != null) { diff.x.set(x, options, xCallback); } if (y != null) { diff.y.set(y, options, yCallback); } if (z != null) { diff.z.set(z, options, zCallback); } return this; };
Applies differential size to Size component. @method @param {Number} x used to set differential size in x-direction (width) @param {Number} y used to set differential size in y-direction (height) @param {Number} z used to set differential size in z-direction (depth) @param {Object} options options hash @param {Function} callback callback function to be executed after the transitions have been completed @return {Size} this
setDifferential ( x , y , z , options , callback )
javascript
Famous/engine
components/Size.js
https://github.com/Famous/engine/blob/master/components/Size.js
MIT
Size.prototype.get = function get () { return this._node.getSize(); };
Retrieves the computed size applied to the underlying Node. @method @return {Array} size three dimensional computed size
get ( )
javascript
Famous/engine
components/Size.js
https://github.com/Famous/engine/blob/master/components/Size.js
MIT
Size.prototype.halt = function halt () { this._proportional.x.halt(); this._proportional.y.halt(); this._proportional.z.halt(); this._differential.x.halt(); this._differential.y.halt(); this._differential.z.halt(); this._absolute.x.halt(); this._absolute.y.halt(); this._absolute.z.halt(); return this; };
Halts all currently active size transitions. @method @return {Size} this
halt ( )
javascript
Famous/engine
components/Size.js
https://github.com/Famous/engine/blob/master/components/Size.js
MIT
function Scale(node) { Position.call(this, node); this._x.set(1); this._y.set(1); this._z.set(1); }
Scale is a component that allows the tweening of a Node's scale. Scale happens about a Node's origin which is by default [0, 0, .5]. @class Scale @augments Position @param {Node} node Node that the Scale component will be attached to
Scale ( node )
javascript
Famous/engine
components/Scale.js
https://github.com/Famous/engine/blob/master/components/Scale.js
MIT
Scale.prototype.toString = function toString() { return 'Scale'; };
Return the name of the Scale component @method @return {String} Name of the component
toString ( )
javascript
Famous/engine
components/Scale.js
https://github.com/Famous/engine/blob/master/components/Scale.js
MIT
Scale.prototype.update = function update() { this._node.setScale(this._x.get(), this._y.get(), this._z.get()); this._checkUpdate(); };
When the node this component is attached to updates, update the value of the Node's scale. @method @return {undefined} undefined
update ( )
javascript
Famous/engine
components/Scale.js
https://github.com/Famous/engine/blob/master/components/Scale.js
MIT
function Rotation(node) { Position.call(this, node); var initial = node.getRotation(); var x = initial[0]; var y = initial[1]; var z = initial[2]; var w = initial[3]; var xx = x * x; var yy = y * y; var zz = z * z; var ty = 2 * (x * z + y * w); ty = ty < -1 ? -1 : ty > 1 ? 1 : ty; var rx = Math.atan2(2 * (x * w - y * z), 1 - 2 * (xx + yy)); var ry = Math.asin(ty); var rz = Math.atan2(2 * (z * w - x * y), 1 - 2 * (yy + zz)); this._x.set(rx); this._y.set(ry); this._z.set(rz); }
Rotation is a component that allows the tweening of a Node's rotation. Rotation happens about a Node's origin which is by default [0, 0, .5]. @class Rotation @augments Position @param {Node} node Node that the Rotation component will be attached to
Rotation ( node )
javascript
Famous/engine
components/Rotation.js
https://github.com/Famous/engine/blob/master/components/Rotation.js
MIT
Rotation.prototype.toString = function toString() { return 'Rotation'; };
Return the name of the Rotation component @method @return {String} Name of the component
toString ( )
javascript
Famous/engine
components/Rotation.js
https://github.com/Famous/engine/blob/master/components/Rotation.js
MIT
Rotation.prototype.update = function update() { this._node.setRotation(this._x.get(), this._y.get(), this._z.get()); this._checkUpdate(); };
When the node this component is attached to updates, update the value of the Node's rotation @method @return {undefined} undefined
update ( )
javascript
Famous/engine
components/Rotation.js
https://github.com/Famous/engine/blob/master/components/Rotation.js
MIT
function Origin(node) { Position.call(this, node); var initial = node.getOrigin(); this._x.set(initial[0]); this._y.set(initial[1]); this._z.set(initial[2]); }
Origin is a component designed to allow for smooth tweening of where on the Node should be considered the origin for rotations and scales. @class Origin @augments Position @param {Node} node Node that the Origin component will be attached to
Origin ( node )
javascript
Famous/engine
components/Origin.js
https://github.com/Famous/engine/blob/master/components/Origin.js
MIT
Origin.prototype.toString = function toString() { return 'Origin'; };
Return the name of the Origin component @method @return {String} Name of the component
toString ( )
javascript
Famous/engine
components/Origin.js
https://github.com/Famous/engine/blob/master/components/Origin.js
MIT
Origin.prototype.update = function update() { this._node.setOrigin(this._x.get(), this._y.get(), this._z.get()); this._checkUpdate(); };
When the node this component is attached to updates, update the value of the Node's origin @method @return {undefined} undefined
update ( )
javascript
Famous/engine
components/Origin.js
https://github.com/Famous/engine/blob/master/components/Origin.js
MIT
function MountPoint(node) { Position.call(this, node); var initial = node.getMountPoint(); this._x.set(initial[0]); this._y.set(initial[1]); this._z.set(initial[2]); }
MountPoint is a component designed to allow for smooth tweening of where on the Node it is attached to the parent. @class MountPoint @augments Position @param {Node} node Node that the MountPoint component will be attached to
MountPoint ( node )
javascript
Famous/engine
components/MountPoint.js
https://github.com/Famous/engine/blob/master/components/MountPoint.js
MIT
MountPoint.prototype.toString = function toString() { return 'MountPoint'; };
Return the name of the MountPoint component @method @return {String} Name of the component
toString ( )
javascript
Famous/engine
components/MountPoint.js
https://github.com/Famous/engine/blob/master/components/MountPoint.js
MIT
MountPoint.prototype.update = function update() { this._node.setMountPoint(this._x.get(), this._y.get(), this._z.get()); this._checkUpdate(); };
When the node this component is attached to updates, update the value of the Node's mount point. @method @return {undefined} undefined
update ( )
javascript
Famous/engine
components/MountPoint.js
https://github.com/Famous/engine/blob/master/components/MountPoint.js
MIT
function Camera(node) { this._node = node; this._projectionType = Camera.ORTHOGRAPHIC_PROJECTION; this._focalDepth = 0; this._near = 0; this._far = 0; this._requestingUpdate = false; this._id = node.addComponent(this); this._viewTransform = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); this._viewDirty = false; this._perspectiveDirty = false; this.setFlat(); }
Camera is a component that is responsible for sending information to the renderer about where the camera is in the scene. This allows the user to set the type of projection, the focal depth, and other properties to adjust the way the scenes are rendered. @class Camera @param {Node} node to which the instance of Camera will be a component of
Camera ( node )
javascript
Famous/engine
components/Camera.js
https://github.com/Famous/engine/blob/master/components/Camera.js
MIT
Camera.prototype.toString = function toString() { return 'Camera'; };
@method @return {String} Name of the component
toString ( )
javascript
Famous/engine
components/Camera.js
https://github.com/Famous/engine/blob/master/components/Camera.js
MIT
Camera.prototype.setValue = function setValue(state) { if (this.toString() === state.component) { this.set(state.projectionType, state.focalDepth, state.near, state.far); return true; } return false; };
Set the components state based on some serialized data @method @param {Object} state an object defining what the state of the component should be @return {Boolean} status of the set
setValue ( state )
javascript
Famous/engine
components/Camera.js
https://github.com/Famous/engine/blob/master/components/Camera.js
MIT
Camera.prototype.set = function set(type, depth, near, far) { if (!this._requestingUpdate) { this._node.requestUpdate(this._id); this._requestingUpdate = true; } this._projectionType = type; this._focalDepth = depth; this._near = near; this._far = far; };
Set the internals of the component @method @param {Number} type an id corresponding to the type of projection to use @param {Number} depth the depth for the pinhole projection model @param {Number} near the distance of the near clipping plane for a frustum projection @param {Number} far the distance of the far clipping plane for a frustum projection @return {Boolean} status of the set
set ( type , depth , near , far )
javascript
Famous/engine
components/Camera.js
https://github.com/Famous/engine/blob/master/components/Camera.js
MIT
Camera.prototype.setDepth = function setDepth(depth) { if (!this._requestingUpdate) { this._node.requestUpdate(this._id); this._requestingUpdate = true; } this._perspectiveDirty = true; this._projectionType = Camera.PINHOLE_PROJECTION; this._focalDepth = depth; this._near = 0; this._far = 0; return this; };
Set the camera depth for a pinhole projection model @method @param {Number} depth the distance between the Camera and the origin @return {Camera} this
setDepth ( depth )
javascript
Famous/engine
components/Camera.js
https://github.com/Famous/engine/blob/master/components/Camera.js
MIT
Camera.prototype.setFrustum = function setFrustum(near, far) { if (!this._requestingUpdate) { this._node.requestUpdate(this._id); this._requestingUpdate = true; } this._perspectiveDirty = true; this._projectionType = Camera.FRUSTUM_PROJECTION; this._focalDepth = 0; this._near = near; this._far = far; return this; };
Gets object containing serialized data for the component @method @param {Number} near distance from the near clipping plane to the camera @param {Number} far distance from the far clipping plane to the camera @return {Camera} this
setFrustum ( near , far )
javascript
Famous/engine
components/Camera.js
https://github.com/Famous/engine/blob/master/components/Camera.js
MIT
Camera.prototype.setFlat = function setFlat() { if (!this._requestingUpdate) { this._node.requestUpdate(this._id); this._requestingUpdate = true; } this._perspectiveDirty = true; this._projectionType = Camera.ORTHOGRAPHIC_PROJECTION; this._focalDepth = 0; this._near = 0; this._far = 0; return this; };
Set the Camera to have orthographic projection @method @return {Camera} this
setFlat ( )
javascript
Famous/engine
components/Camera.js
https://github.com/Famous/engine/blob/master/components/Camera.js
MIT
Camera.prototype.onUpdate = function onUpdate() { this._requestingUpdate = false; var path = this._node.getLocation(); this._node .sendDrawCommand(Commands.WITH) .sendDrawCommand(path); if (this._perspectiveDirty) { this._perspectiveDirty = false; switch (this._projectionType) { case Camera.FRUSTUM_PROJECTION: this._node.sendDrawCommand(Commands.FRUSTRUM_PROJECTION); this._node.sendDrawCommand(this._near); this._node.sendDrawCommand(this._far); break; case Camera.PINHOLE_PROJECTION: this._node.sendDrawCommand(Commands.PINHOLE_PROJECTION); this._node.sendDrawCommand(this._focalDepth); break; case Camera.ORTHOGRAPHIC_PROJECTION: this._node.sendDrawCommand(Commands.ORTHOGRAPHIC_PROJECTION); break; } } if (this._viewDirty) { this._viewDirty = false; this._node.sendDrawCommand(Commands.CHANGE_VIEW_TRANSFORM); this._node.sendDrawCommand(this._viewTransform[0]); this._node.sendDrawCommand(this._viewTransform[1]); this._node.sendDrawCommand(this._viewTransform[2]); this._node.sendDrawCommand(this._viewTransform[3]); this._node.sendDrawCommand(this._viewTransform[4]); this._node.sendDrawCommand(this._viewTransform[5]); this._node.sendDrawCommand(this._viewTransform[6]); this._node.sendDrawCommand(this._viewTransform[7]); this._node.sendDrawCommand(this._viewTransform[8]); this._node.sendDrawCommand(this._viewTransform[9]); this._node.sendDrawCommand(this._viewTransform[10]); this._node.sendDrawCommand(this._viewTransform[11]); this._node.sendDrawCommand(this._viewTransform[12]); this._node.sendDrawCommand(this._viewTransform[13]); this._node.sendDrawCommand(this._viewTransform[14]); this._node.sendDrawCommand(this._viewTransform[15]); } };
When the node this component is attached to updates, the Camera will send new camera information to the Compositor to update the rendering of the scene. @method @return {undefined} undefined
onUpdate ( )
javascript
Famous/engine
components/Camera.js
https://github.com/Famous/engine/blob/master/components/Camera.js
MIT
Camera.prototype.onTransformChange = function onTransformChange(transform) { var a = transform; this._viewDirty = true; if (!this._requestingUpdate) { this._node.requestUpdate(this._id); this._requestingUpdate = true; } var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], b00 = a00 * a11 - a01 * a10, b01 = a00 * a12 - a02 * a10, b02 = a00 * a13 - a03 * a10, b03 = a01 * a12 - a02 * a11, b04 = a01 * a13 - a03 * a11, b05 = a02 * a13 - a03 * a12, b06 = a20 * a31 - a21 * a30, b07 = a20 * a32 - a22 * a30, b08 = a20 * a33 - a23 * a30, b09 = a21 * a32 - a22 * a31, b10 = a21 * a33 - a23 * a31, b11 = a22 * a33 - a23 * a32, det = 1/(b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06); this._viewTransform[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; this._viewTransform[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; this._viewTransform[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; this._viewTransform[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; this._viewTransform[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; this._viewTransform[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; this._viewTransform[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; this._viewTransform[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; this._viewTransform[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; this._viewTransform[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; this._viewTransform[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; this._viewTransform[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; this._viewTransform[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; this._viewTransform[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; this._viewTransform[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; this._viewTransform[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; };
When the transform of the node this component is attached to changes, have the Camera update its projection matrix and if needed, flag to node to update. @method @param {Array} transform an array denoting the transform matrix of the node @return {Camera} this
onTransformChange ( transform )
javascript
Famous/engine
components/Camera.js
https://github.com/Famous/engine/blob/master/components/Camera.js
MIT
function GestureHandler(node, events) { this.node = node; this.id = node.addComponent(this); this._events = new CallbackStore(); this.last1 = new Vec2(); this.last2 = new Vec2(); this.delta1 = new Vec2(); this.delta2 = new Vec2(); this.velocity1 = new Vec2(); this.velocity2 = new Vec2(); this.dist = 0; this.diff12 = new Vec2(); this.center = new Vec2(); this.centerDelta = new Vec2(); this.centerVelocity = new Vec2(); this.pointer1 = { position: this.last1, delta: this.delta1, velocity: this.velocity1 }; this.pointer2 = { position: this.last2, delta: this.delta2, velocity: this.velocity2 }; this.event = { status: null, time: 0, pointers: [], center: this.center, centerDelta: this.centerDelta, centerVelocity: this.centerVelocity, points: 0, current: 0 }; this.trackedPointerIDs = [-1, -1]; this.timeOfPointer = 0; this.multiTap = 0; this.mice = []; this.gestures = []; this.options = {}; this.trackedGestures = {}; var i; var len; if (events) { for (i = 0, len = events.length; i < len; i++) { this.on(events[i], events[i].callback); } } node.addUIEvent('touchstart'); node.addUIEvent('mousedown'); node.addUIEvent('touchmove'); node.addUIEvent('mousemove'); node.addUIEvent('touchend'); node.addUIEvent('mouseup'); node.addUIEvent('mouseleave'); }
Component to manage gesture events. Will track 'pinch', 'rotate', 'tap', and 'drag' events, on an as-requested basis. @class GestureHandler @param {Node} node The node with which to register the handler. @param {Array} events An array of event objects specifying .event and .callback properties.
GestureHandler ( node , events )
javascript
Famous/engine
components/GestureHandler.js
https://github.com/Famous/engine/blob/master/components/GestureHandler.js
MIT
GestureHandler.prototype.onReceive = function onReceive (ev, payload) { switch(ev) { case 'touchstart': case 'mousedown': _processPointerStart.call(this, payload); break; case 'touchmove': case 'mousemove': _processPointerMove.call(this, payload); break; case 'touchend': case 'mouseup': _processPointerEnd.call(this, payload); break; case 'mouseleave': _processMouseLeave.call(this, payload); break; default: break; } };
onReceive fires when the node this component is attached to gets an event. @method @param {String} ev name of the event @param {Object} payload data associated with the event @return {undefined} undefined
onReceive ( ev , payload )
javascript
Famous/engine
components/GestureHandler.js
https://github.com/Famous/engine/blob/master/components/GestureHandler.js
MIT
GestureHandler.prototype.toString = function toString() { return 'GestureHandler'; };
Return the name of the GestureHandler component @method @return {String} Name of the component
toString ( )
javascript
Famous/engine
components/GestureHandler.js
https://github.com/Famous/engine/blob/master/components/GestureHandler.js
MIT
GestureHandler.prototype.on = function on(ev, cb) { var gesture = ev.event || ev; if (gestures[gesture]) { this.trackedGestures[gesture] = true; this.gestures.push(gesture); if (ev.event) this.options[gesture] = ev; this._events.on(gesture, cb); } };
Register a callback to be invoked on an event. @method @param {Object|String} ev The event object or event name. @param {Function} cb The callback @return {undefined} undefined
on ( ev , cb )
javascript
Famous/engine
components/GestureHandler.js
https://github.com/Famous/engine/blob/master/components/GestureHandler.js
MIT
GestureHandler.prototype.trigger = function trigger (ev, payload) { this._events.trigger(ev, payload); };
Trigger the callback associated with an event, passing in a payload. @method trigger @param {String} ev The event name @param {Object} payload The event payload @return {undefined} undefined
trigger ( ev , payload )
javascript
Famous/engine
components/GestureHandler.js
https://github.com/Famous/engine/blob/master/components/GestureHandler.js
MIT
function _processPointerStart(e) { var t; if (!e.targetTouches) { this.mice[0] = e; t = this.mice; e.identifier = 1; } else t = e.targetTouches; if (t[0] && t[1] && this.trackedPointerIDs[0] === t[0].identifier && this.trackedPointerIDs[1] === t[1].identifier) { return; } this.event.time = Date.now(); var threshold; var id; if (this.trackedPointerIDs[0] !== t[0].identifier) { if (this.trackedGestures.tap) { threshold = (this.options.tap && this.options.tap.threshold) || 250; if (this.event.time - this.timeOfPointer < threshold) this.event.taps++; else this.event.taps = 1; this.timeOfPointer = this.event.time; this.multiTap = 1; } this.event.current = 1; this.event.points = 1; id = t[0].identifier; this.trackedPointerIDs[0] = id; this.last1.set(t[0].pageX, t[0].pageY); this.velocity1.clear(); this.delta1.clear(); this.event.pointers.push(this.pointer1); } if (t[1] && this.trackedPointerIDs[1] !== t[1].identifier) { if (this.trackedGestures.tap) { threshold = (this.options.tap && this.options.tap.threshold) || 250; if (this.event.time - this.timeOfPointer < threshold) this.multiTap = 2; } this.event.current = 2; this.event.points = 2; id = t[1].identifier; this.trackedPointerIDs[1] = id; this.last2.set(t[1].pageX, t[1].pageY); this.velocity2.clear(); this.delta2.clear(); Vec2.add(this.last1, this.last2, this.center).scale(0.5); this.centerDelta.clear(); this.centerVelocity.clear(); Vec2.subtract(this.last2, this.last1, this.diff12); this.dist = this.diff12.length(); if (this.trackedGestures.pinch) { this.event.scale = this.event.scale || 1; this.event.scaleDelta = 0; this.event.scaleVelocity = 0; } if (this.trackedGestures.rotate) { this.event.rotation = this.event.rotation || 0; this.event.rotationDelta = 0; this.event.rotationVelocity = 0; } this.event.pointers.push(this.pointer2); } this.event.status = 'start'; if (this.event.points === 1) { this.center.copy(this.last1); this.centerDelta.clear(); this.centerVelocity.clear(); if (this.trackedGestures.pinch) { this.event.scale = 1; this.event.scaleDelta = 0; this.event.scaleVelocity = 0; } if (this.trackedGestures.rotate) { this.event.rotation = 0; this.event.rotationDelta = 0; this.event.rotationVelocity = 0; } } this.triggerGestures(); }
Process up to the first two touch/mouse move events. Exit out if the first two points are already being tracked. @method _processPointerStart @private @param {Object} e The event object @return {undefined} undefined
_processPointerStart ( e )
javascript
Famous/engine
components/GestureHandler.js
https://github.com/Famous/engine/blob/master/components/GestureHandler.js
MIT
function _processPointerMove(e) { var t; if (!e.targetTouches) { if (!this.event.current) return; this.mice[0] = e; t = this.mice; e.identifier = 1; } else t = e.targetTouches; var time = Date.now(); var dt = time - this.event.time; if (dt === 0) return; var invDt = 1000 / dt; this.event.time = time; this.event.current = 1; this.event.points = 1; if (this.trackedPointerIDs[0] === t[0].identifier) { VEC_REGISTER.set(t[0].pageX, t[0].pageY); Vec2.subtract(VEC_REGISTER, this.last1, this.delta1); Vec2.scale(this.delta1, invDt, this.velocity1); this.last1.copy(VEC_REGISTER); } if (t[1]) { this.event.current = 2; this.event.points = 2; VEC_REGISTER.set(t[1].pageX, t[1].pageY); Vec2.subtract(VEC_REGISTER, this.last2, this.delta2); Vec2.scale(this.delta2, invDt, this.velocity2); this.last2.copy(VEC_REGISTER); Vec2.add(this.last1, this.last2, VEC_REGISTER).scale(0.5); Vec2.subtract(VEC_REGISTER, this.center, this.centerDelta); Vec2.add(this.velocity1, this.velocity2, this.centerVelocity).scale(0.5); this.center.copy(VEC_REGISTER); Vec2.subtract(this.last2, this.last1, VEC_REGISTER); if (this.trackedGestures.rotate) { var dot = VEC_REGISTER.dot(this.diff12); var cross = VEC_REGISTER.cross(this.diff12); var theta = -Math.atan2(cross, dot); this.event.rotation += theta; this.event.rotationDelta = theta; this.event.rotationVelocity = theta * invDt; } var dist = VEC_REGISTER.length(); var scale = dist / this.dist; this.diff12.copy(VEC_REGISTER); this.dist = dist; if (this.trackedGestures.pinch) { this.event.scale *= scale; scale -= 1.0; this.event.scaleDelta = scale; this.event.scaleVelocity = scale * invDt; } } this.event.status = 'move'; if (this.event.points === 1) { this.center.copy(this.last1); this.centerDelta.copy(this.delta1); this.centerVelocity.copy(this.velocity1); if (this.trackedGestures.pinch) { this.event.scale = 1; this.event.scaleDelta = 0; this.event.scaleVelocity = 0; } if (this.trackedGestures.rotate) { this.event.rotation = 0; this.event.rotationDelta = 0; this.event.rotationVelocity = 0; } } this.triggerGestures(); }
Process up to the first two touch/mouse move events. @method _processPointerMove @private @param {Object} e The event object. @return {undefined} undefined
_processPointerMove ( e )
javascript
Famous/engine
components/GestureHandler.js
https://github.com/Famous/engine/blob/master/components/GestureHandler.js
MIT
function _processPointerEnd(e) { var t; if (!e.targetTouches) { if (!this.event.current) return; this.mice.pop(); t = this.mice; } else t = e.targetTouches; if (t[0] && t[1] && this.trackedPointerIDs[0] === t[0].identifier && this.trackedPointerIDs[1] === t[1].identifier) { return; } var id; this.event.status = 'end'; if (!t[0]) { this.event.current = 0; this.trackedPointerIDs[0] = -1; this.trackedPointerIDs[1] = -1; this.triggerGestures(); this.event.pointers.pop(); this.event.pointers.pop(); return; } else if(this.trackedPointerIDs[0] !== t[0].identifier) { this.trackedPointerIDs[0] = -1; id = t[0].identifier; this.trackedPointerIDs[0] = id; this.last1.set(t[0].pageX, t[0].pageY); this.velocity1.clear(); this.delta1.clear(); } if (!t[1]) { this.event.current = 1; this.trackedPointerIDs[1] = -1; this.triggerGestures(); this.event.points = 1; this.event.pointers.pop(); } else if (this.trackedPointerIDs[1] !== t[1].identifier) { this.trackedPointerIDs[1] = -1; this.event.points = 2; id = t[1].identifier; this.trackedPointerIDs[1] = id; this.last2.set(t[1].pageX, t[1].pageY); this.velocity2.clear(); this.delta2.clear(); Vec2.add(this.last1, this.last2, this.center).scale(0.5); this.centerDelta.clear(); this.centerVelocity.clear(); Vec2.subtract(this.last2, this.last1, this.diff12); this.dist = this.diff12.length(); } }
Process up to the first two touch/mouse end events. Exit out if the two points being tracked are still active. @method _processPointerEnd @private @param {Object} e The event object @return {undefined} undefined
_processPointerEnd ( e )
javascript
Famous/engine
components/GestureHandler.js
https://github.com/Famous/engine/blob/master/components/GestureHandler.js
MIT
function _processMouseLeave() { if (this.event.current) { this.event.status = 'end'; this.event.current = 0; this.trackedPointerIDs[0] = -1; this.triggerGestures(); this.event.pointers.pop(); } }
Treats a mouseleave event as a gesture end. @method _processMouseLeave @private @return {undefined} undefined
_processMouseLeave ( )
javascript
Famous/engine
components/GestureHandler.js
https://github.com/Famous/engine/blob/master/components/GestureHandler.js
MIT
function Opacity(node) { this._node = node; this._id = node.addComponent(this); this._value = new Transitionable(1); this._requestingUpdate = false; }
Opacity is a component designed to allow for smooth tweening of the Node's opacity @class Opacity @param {Node} node Node that the Opacity component is attached to
Opacity ( node )
javascript
Famous/engine
components/Opacity.js
https://github.com/Famous/engine/blob/master/components/Opacity.js
MIT
Opacity.prototype.toString = function toString() { return 'Opacity'; };
Return the name of the Opacity component @method @return {String} Name of the component
toString ( )
javascript
Famous/engine
components/Opacity.js
https://github.com/Famous/engine/blob/master/components/Opacity.js
MIT
Opacity.prototype.setValue = function setValue(value) { if (this.toString() === value.component) { this.set(value.value); return true; } return false; };
Set the internal state of the Opacity component @method @param {Object} value Object containing the component key, which holds stringified constructor, and a value key, which contains a numeric value used to set opacity if the constructor value matches @return {Boolean} true if set is successful, false otherwise
setValue ( value )
javascript
Famous/engine
components/Opacity.js
https://github.com/Famous/engine/blob/master/components/Opacity.js
MIT
Opacity.prototype.set = function set(value, transition, callback) { if (!this._requestingUpdate) { this._node.requestUpdate(this._id); this._requestingUpdate = true; } this._value.set(value, transition, callback); return this; };
Set the opacity of the Node @method @param {Number} value value used to set Opacity @param {Object} transition options for the transition @param {Function} callback to be called following Opacity set completion @return {Opacity} this
set ( value , transition , callback )
javascript
Famous/engine
components/Opacity.js
https://github.com/Famous/engine/blob/master/components/Opacity.js
MIT
Opacity.prototype.get = function get() { return this._value.get(); };
Get the current opacity for the component @method @return {Number} opacity as known by the component
get ( )
javascript
Famous/engine
components/Opacity.js
https://github.com/Famous/engine/blob/master/components/Opacity.js
MIT
Opacity.prototype.halt = function halt() { this._value.halt(); return this; };
Stops Opacity transition @method @return {Opacity} this
halt ( )
javascript
Famous/engine
components/Opacity.js
https://github.com/Famous/engine/blob/master/components/Opacity.js
MIT
Opacity.prototype.isActive = function isActive(){ return this._value.isActive(); };
Tells whether or not the opacity is in a transition @method @return {Boolean} whether or not the opacity is transitioning
isActive ( )
javascript
Famous/engine
components/Opacity.js
https://github.com/Famous/engine/blob/master/components/Opacity.js
MIT
Opacity.prototype.update = function update () { this._node.setOpacity(this._value.get()); if (this._value.isActive()) { this._node.requestUpdateOnNextTick(this._id); } else { this._requestingUpdate = false; } };
When the node this component is attached to updates, update the value of the Node's opacity. @method @return {undefined} undefined
update ( )
javascript
Famous/engine
components/Opacity.js
https://github.com/Famous/engine/blob/master/components/Opacity.js
MIT
function Material(name, chunk, inputs, options) { options = options || {}; this.name = name; this.chunk = chunk; this.inputs = inputs ? (Array.isArray(inputs) ? inputs : [inputs]): []; this.uniforms = options.uniforms || {}; this.varyings = options.varyings; this.attributes = options.attributes; this.meshes = []; if (options.texture) { this.texture = options.texture.__isATexture__ ? options.texture : TextureRegistry.register(null, options.texture); } this._id = Material.id++; this.invalidations = []; this.__isAMaterial__ = true; } Material.id = 2; Material.prototype.setUniform = function setUniform(name, value) { this.uniforms[name] = value; this.invalidations.push(name); for(var i = 0; i < this.meshes.length; i++) this.meshes[i]._requestUpdate(); }; module.exports = expressions; expressions.Material = Material; expressions.Texture = function (source) { if (typeof window === 'undefined') return console.error('Texture constructor cannot be run inside of a worker'); return expressions.image([], { texture: source }); }; expressions.Custom = function (schema, inputs, uniforms) { return new Material('custom', {glsl: schema, output: 1, uniforms: uniforms || {}} , inputs); }; // Recursively iterates over a material's inputs, invoking a given callback // with the current material Material.prototype.traverse = function traverse(callback) { var inputs = this.inputs; var len = inputs && inputs.length; var idx = -1; while (++idx < len) inputs[idx].traverse(callback); callback(this); };
Material is a public class that composes a material-graph out of expressions @class Material @constructor @param {Object} definiton of nascent expression with shader code, inputs and uniforms @param {Array} list of Material expressions, images, or constant @param {Object} map of uniform data of float, vec2, vec3, vec4
Material ( name , chunk , inputs , options )
javascript
Famous/engine
webgl-materials/Material.js
https://github.com/Famous/engine/blob/master/webgl-materials/Material.js
MIT
function ElementCache (element, path) { this.tagName = element.tagName.toLowerCase(); this.void = VoidElements[this.tagName]; var constructor = element.constructor; this.formElement = constructor === HTMLInputElement || constructor === HTMLTextAreaElement || constructor === HTMLSelectElement; this.element = element; this.path = path; this.content = null; this.size = new Int16Array(3); this.explicitHeight = false; this.explicitWidth = false; this.postRenderSize = new Float32Array(2); this.listeners = {}; this.preventDefault = {}; this.subscribe = {}; }
ElementCache is being used for keeping track of an element's DOM Element, path, world transform, inverted parent, final transform (as being used for setting the actual `transform`-property) and post render size (final size as being rendered to the DOM). @class ElementCache @param {Element} element DOMElement @param {String} path Path used for uniquely identifying the location in the scene graph.
ElementCache ( element , path )
javascript
Famous/engine
dom-renderers/ElementCache.js
https://github.com/Famous/engine/blob/master/dom-renderers/ElementCache.js
MIT
function invert (out, a) { var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], b00 = a00 * a11 - a01 * a10, b01 = a00 * a12 - a02 * a10, b02 = a00 * a13 - a03 * a10, b03 = a01 * a12 - a02 * a11, b04 = a01 * a13 - a03 * a11, b05 = a02 * a13 - a03 * a12, b06 = a20 * a31 - a21 * a30, b07 = a20 * a32 - a22 * a30, b08 = a20 * a33 - a23 * a30, b09 = a21 * a32 - a22 * a31, b10 = a21 * a33 - a23 * a31, b11 = a22 * a33 - a23 * a32, // Calculate the determinant det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; if (!det) { return null; } det = 1.0 / det; out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; return out; }
A method for inverting a transform matrix @method @param {Array} out array to store the return of the inversion @param {Array} a transform matrix to inverse @return {Array} out output array that is storing the transform matrix
invert ( out , a )
javascript
Famous/engine
dom-renderers/Math.js
https://github.com/Famous/engine/blob/master/dom-renderers/Math.js
MIT
function multiply (out, a, b) { var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3], a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7], a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11], a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15], b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3], b4 = b[4], b5 = b[5], b6 = b[6], b7 = b[7], b8 = b[8], b9 = b[9], b10 = b[10], b11 = b[11], b12 = b[12], b13 = b[13], b14 = b[14], b15 = b[15]; var changed = false; var out0, out1, out2, out3; out0 = b0*a00 + b1*a10 + b2*a20 + b3*a30; out1 = b0*a01 + b1*a11 + b2*a21 + b3*a31; out2 = b0*a02 + b1*a12 + b2*a22 + b3*a32; out3 = b0*a03 + b1*a13 + b2*a23 + b3*a33; changed = changed ? changed : out0 === out[0] || out1 === out[1] || out2 === out[2] || out3 === out[3]; out[0] = out0; out[1] = out1; out[2] = out2; out[3] = out3; b0 = b4; b1 = b5; b2 = b6; b3 = b7; out0 = b0*a00 + b1*a10 + b2*a20 + b3*a30; out1 = b0*a01 + b1*a11 + b2*a21 + b3*a31; out2 = b0*a02 + b1*a12 + b2*a22 + b3*a32; out3 = b0*a03 + b1*a13 + b2*a23 + b3*a33; changed = changed ? changed : out0 === out[4] || out1 === out[5] || out2 === out[6] || out3 === out[7]; out[4] = out0; out[5] = out1; out[6] = out2; out[7] = out3; b0 = b8; b1 = b9; b2 = b10; b3 = b11; out0 = b0*a00 + b1*a10 + b2*a20 + b3*a30; out1 = b0*a01 + b1*a11 + b2*a21 + b3*a31; out2 = b0*a02 + b1*a12 + b2*a22 + b3*a32; out3 = b0*a03 + b1*a13 + b2*a23 + b3*a33; changed = changed ? changed : out0 === out[8] || out1 === out[9] || out2 === out[10] || out3 === out[11]; out[8] = out0; out[9] = out1; out[10] = out2; out[11] = out3; b0 = b12; b1 = b13; b2 = b14; b3 = b15; out0 = b0*a00 + b1*a10 + b2*a20 + b3*a30; out1 = b0*a01 + b1*a11 + b2*a21 + b3*a31; out2 = b0*a02 + b1*a12 + b2*a22 + b3*a32; out3 = b0*a03 + b1*a13 + b2*a23 + b3*a33; changed = changed ? changed : out0 === out[12] || out1 === out[13] || out2 === out[14] || out3 === out[15]; out[12] = out0; out[13] = out1; out[14] = out2; out[15] = out3; return out; }
A method for multiplying two matricies @method @param {Array} out array to store the return of the multiplication @param {Array} a transform matrix to multiply @param {Array} b transform matrix to multiply @return {Array} out output array that is storing the transform matrix
multiply ( out , a , b )
javascript
Famous/engine
dom-renderers/Math.js
https://github.com/Famous/engine/blob/master/dom-renderers/Math.js
MIT
function DOMRenderer (element, selector, compositor) { var _this = this; element.classList.add('famous-dom-renderer'); TRANSFORM = TRANSFORM || vendorPrefix('transform'); this._compositor = compositor; // a reference to the compositor this._target = null; // a register for holding the current // element that the Renderer is operating // upon this._parent = null; // a register for holding the parent // of the target this._path = null; // a register for holding the path of the target // this register must be set first, and then // children, target, and parent are all looked // up from that. this._children = []; // a register for holding the children of the // current target. this._insertElCallbackStore = new CallbackStore(); this._removeElCallbackStore = new CallbackStore(); this._root = new ElementCache(element, selector); // the root // of the dom tree that this // renderer is responsible // for this._boundTriggerEvent = function (ev) { return _this._triggerEvent(ev); }; this._selector = selector; this._elements = {}; this._elements[selector] = this._root; this.perspectiveTransform = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); this._VPtransform = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); this._lastEv = null; }
DOMRenderer is a class responsible for adding elements to the DOM and writing to those elements. There is a DOMRenderer per context, represented as an element and a selector. It is instantiated in the context class. @class DOMRenderer @param {HTMLElement} element an element. @param {String} selector the selector of the element. @param {Compositor} compositor the compositor controlling the renderer
DOMRenderer ( element , selector , compositor )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.subscribe = function subscribe(type) { this._assertTargetLoaded(); this._listen(type); this._target.subscribe[type] = true; };
Attaches an EventListener to the element associated with the passed in path. Prevents the default browser action on all subsequent events if `preventDefault` is truthy. All incoming events will be forwarded to the compositor by invoking the `sendEvent` method. Delegates events if possible by attaching the event listener to the context. @method @param {String} type DOM event type (e.g. click, mouseover). @param {Boolean} preventDefault Whether or not the default browser action should be prevented. @return {undefined} undefined
subscribe ( type )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.preventDefault = function preventDefault(type) { this._assertTargetLoaded(); this._listen(type); this._target.preventDefault[type] = true; };
Used to preventDefault if an event of the specified type is being emitted on the currently loaded target. @method @param {String} type The type of events that should be prevented. @return {undefined} undefined
preventDefault ( type )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.allowDefault = function allowDefault(type) { this._assertTargetLoaded(); this._listen(type); this._target.preventDefault[type] = false; };
Used to undo a previous call to preventDefault. No longer `preventDefault` for this event on the loaded target. @method @private @param {String} type The event type that should no longer be affected by `preventDefault`. @return {undefined} undefined
allowDefault ( type )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype._listen = function _listen(type) { this._assertTargetLoaded(); if ( !this._target.listeners[type] && !this._root.listeners[type] ) { // FIXME Add to content DIV if available var target = eventMap[type][1] ? this._root : this._target; target.listeners[type] = this._boundTriggerEvent; target.element.addEventListener(type, this._boundTriggerEvent); } };
Internal helper function used for adding an event listener for the the currently loaded ElementCache. If the event can be delegated as specified in the {@link EventMap}, the bound {@link _triggerEvent} function will be added as a listener on the root element. Otherwise, the listener will be added directly to the target element. @private @method @param {String} type The event type to listen to (e.g. click). @return {undefined} undefined
_listen ( type )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.unsubscribe = function unsubscribe(type) { this._assertTargetLoaded(); this._target.subscribe[type] = false; };
Unsubscribes from all events that are of the specified type. @method @param {String} type DOM event type (e.g. click, mouseover). @return {undefined} undefined
unsubscribe ( type )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype._triggerEvent = function _triggerEvent(ev) { if (this._lastEv === ev) return; // Use ev.path, which is an array of Elements (polyfilled if needed). var evPath = ev.path ? ev.path : _getPath(ev); // First element in the path is the element on which the event has actually // been emitted. for (var i = 0; i < evPath.length; i++) { // Skip nodes that don't have a dataset property or data-fa-path // attribute. if (!evPath[i].dataset) continue; var path = evPath[i].dataset.faPath; if (!path) continue; // Optionally preventDefault. This needs forther consideration and // should be optional. Eventually this should be a separate command/ // method. if (this._elements[path].preventDefault[ev.type]) { ev.preventDefault(); } // Stop further event propogation and path traversal as soon as the // first ElementCache subscribing for the emitted event has been found. if (this._elements[path] && this._elements[path].subscribe[ev.type]) { this._lastEv = ev; var NormalizedEventConstructor = eventMap[ev.type][0]; // Finally send the event to the Worker Thread through the // compositor. this._compositor.sendEvent(path, ev.type, new NormalizedEventConstructor(ev)); break; } } };
Function to be added using `addEventListener` to the corresponding DOMElement. @method @private @param {Event} ev DOM Event payload @return {undefined} undefined
_triggerEvent ( ev )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.getSizeOf = function getSizeOf(path) { var element = this._elements[path]; if (!element) return null; var res = {val: element.size}; this._compositor.sendEvent(path, 'resize', res); return res; };
getSizeOf gets the dom size of a particular DOM element. This is needed for render sizing in the scene graph. @method @param {String} path path of the Node in the scene graph @return {Array} a vec3 of the offset size of the dom element
getSizeOf ( path )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.draw = function draw(renderState) { if (renderState.perspectiveDirty) { this.perspectiveDirty = true; this.perspectiveTransform[0] = renderState.perspectiveTransform[0]; this.perspectiveTransform[1] = renderState.perspectiveTransform[1]; this.perspectiveTransform[2] = renderState.perspectiveTransform[2]; this.perspectiveTransform[3] = renderState.perspectiveTransform[3]; this.perspectiveTransform[4] = renderState.perspectiveTransform[4]; this.perspectiveTransform[5] = renderState.perspectiveTransform[5]; this.perspectiveTransform[6] = renderState.perspectiveTransform[6]; this.perspectiveTransform[7] = renderState.perspectiveTransform[7]; this.perspectiveTransform[8] = renderState.perspectiveTransform[8]; this.perspectiveTransform[9] = renderState.perspectiveTransform[9]; this.perspectiveTransform[10] = renderState.perspectiveTransform[10]; this.perspectiveTransform[11] = renderState.perspectiveTransform[11]; this.perspectiveTransform[12] = renderState.perspectiveTransform[12]; this.perspectiveTransform[13] = renderState.perspectiveTransform[13]; this.perspectiveTransform[14] = renderState.perspectiveTransform[14]; this.perspectiveTransform[15] = renderState.perspectiveTransform[15]; } if (renderState.viewDirty || renderState.perspectiveDirty) { math.multiply(this._VPtransform, this.perspectiveTransform, renderState.viewTransform); this._root.element.style[TRANSFORM] = this._stringifyMatrix(this._VPtransform); } };
Executes the retrieved draw commands. Draw commands only refer to the cross-browser normalized `transform` property. @method @param {Object} renderState description @return {undefined} undefined
draw ( renderState )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype._assertPathLoaded = function _asserPathLoaded() { if (!this._path) throw new Error('path not loaded'); };
Internal helper function used for ensuring that a path is currently loaded. @method @private @return {undefined} undefined
_asserPathLoaded ( )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype._assertParentLoaded = function _assertParentLoaded() { if (!this._parent) throw new Error('parent not loaded'); };
Internal helper function used for ensuring that a parent is currently loaded. @method @private @return {undefined} undefined
_assertParentLoaded ( )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype._assertChildrenLoaded = function _assertChildrenLoaded() { if (!this._children) throw new Error('children not loaded'); };
Internal helper function used for ensuring that children are currently loaded. @method @private @return {undefined} undefined
_assertChildrenLoaded ( )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype._assertTargetLoaded = function _assertTargetLoaded() { if (!this._target) throw new Error('No target loaded'); };
Internal helper function used for ensuring that a target is currently loaded. @method _assertTargetLoaded @return {undefined} undefined
_assertTargetLoaded ( )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.findParent = function findParent () { this._assertPathLoaded(); var path = this._path; var parent; while (!parent && path.length) { path = path.substring(0, path.lastIndexOf('/')); parent = this._elements[path]; } this._parent = parent; return parent; };
Finds and sets the parent of the currently loaded element (path). @method @private @return {ElementCache} Parent element.
findParent ( )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.findTarget = function findTarget() { this._target = this._elements[this._path]; return this._target; };
Used for determining the target loaded under the current path. @method @deprecated @return {ElementCache|undefined} Element loaded under defined path.
findTarget ( )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.loadPath = function loadPath (path) { this._path = path; this._target = this._elements[this._path]; return this._path; };
Loads the passed in path into the DOMRenderer. @method @param {String} path Path to be loaded @return {String} Loaded path
loadPath ( path )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.resolveChildren = function resolveChildren (element, parent) { var i = 0; var childNode; var path = this._path; var childPath; while ((childNode = parent.childNodes[i])) { if (!childNode.dataset) { i++; continue; } childPath = childNode.dataset.faPath; if (!childPath) { i++; continue; } if (PathUtils.isDescendentOf(childPath, path)) element.appendChild(childNode); else i++; } };
Finds children of a parent element that are descendents of a inserted element in the scene graph. Appends those children to the inserted element. @method resolveChildren @return {void} @param {HTMLElement} element the inserted element @param {HTMLElement} parent the parent of the inserted element
resolveChildren ( element , parent )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.insertEl = function insertEl (tagName) { this.findParent(); this._assertParentLoaded(); if (this._parent.void) throw new Error( this._parent.path + ' is a void element. ' + 'Void elements are not allowed to have children.' ); if (!this._target) this._target = new ElementCache(document.createElement(tagName), this._path); var el = this._target.element; var parent = this._parent.element; this.resolveChildren(el, parent); parent.appendChild(el); this._elements[this._path] = this._target; this._insertElCallbackStore.trigger(this._path, this._target); };
Inserts a DOMElement at the currently loaded path, assuming no target is loaded. Only one DOMElement can be associated with each path. @method @param {String} tagName Tag name (capitalization will be normalized). @return {undefined} undefined
insertEl ( tagName )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.setProperty = function setProperty (name, value) { this._assertTargetLoaded(); this._target.element.style[name] = value; };
Sets a property on the currently loaded target. @method @param {String} name Property name (e.g. background, color, font) @param {String} value Proprty value (e.g. black, 20px) @return {undefined} undefined
setProperty ( name , value )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.setSize = function setSize (width, height) { this._assertTargetLoaded(); this.setWidth(width); this.setHeight(height); };
Sets the size of the currently loaded target. Removes any explicit sizing constraints when passed in `false` ("true-sizing"). Invoking setSize is equivalent to a manual invocation of `setWidth` followed by `setHeight`. @method @param {Number|false} width Width to be set. @param {Number|false} height Height to be set. @return {undefined} undefined
setSize ( width , height )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.setWidth = function setWidth(width) { this._assertTargetLoaded(); var contentWrapper = this._target.content; if (width === false) { this._target.explicitWidth = true; if (contentWrapper) contentWrapper.style.width = ''; width = contentWrapper ? contentWrapper.offsetWidth : 0; this._target.element.style.width = width + 'px'; } else { this._target.explicitWidth = false; if (contentWrapper) contentWrapper.style.width = width + 'px'; this._target.element.style.width = width + 'px'; } this._target.size[0] = width; };
Sets the width of the currently loaded ElementCache. @method @param {Number|false} width The explicit width to be set on the ElementCache's target (and content) element. `false` removes any explicit sizing constraints from the underlying DOM Elements. @return {undefined} undefined
setWidth ( width )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.setHeight = function setHeight(height) { this._assertTargetLoaded(); var contentWrapper = this._target.content; if (height === false) { this._target.explicitHeight = true; if (contentWrapper) contentWrapper.style.height = ''; height = contentWrapper ? contentWrapper.offsetHeight : 0; this._target.element.style.height = height + 'px'; } else { this._target.explicitHeight = false; if (contentWrapper) contentWrapper.style.height = height + 'px'; this._target.element.style.height = height + 'px'; } this._target.size[1] = height; };
Sets the height of the currently loaded ElementCache. @method setHeight @param {Number|false} height The explicit height to be set on the ElementCache's target (and content) element. `false` removes any explicit sizing constraints from the underlying DOM Elements. @return {undefined} undefined
setHeight ( height )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.setAttribute = function setAttribute(name, value) { this._assertTargetLoaded(); this._target.element.setAttribute(name, value); };
Sets an attribute on the currently loaded target. @method @param {String} name Attribute name (e.g. href) @param {String} value Attribute value (e.g. http://famous.org) @return {undefined} undefined
setAttribute ( name , value )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.setMatrix = function setMatrix (transform) { this._assertTargetLoaded(); this._target.element.style[TRANSFORM] = this._stringifyMatrix(transform); };
Sets the passed in transform matrix (world space). Inverts the parent's world transform. @method @param {Float32Array} transform The transform for the loaded DOM Element in world space @return {undefined} undefined
setMatrix ( transform )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.addClass = function addClass(domClass) { this._assertTargetLoaded(); this._target.element.classList.add(domClass); };
Adds a class to the classList associated with the currently loaded target. @method @param {String} domClass Class name to be added to the current target. @return {undefined} undefined
addClass ( domClass )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.removeClass = function removeClass(domClass) { this._assertTargetLoaded(); this._target.element.classList.remove(domClass); };
Removes a class from the classList associated with the currently loaded target. @method @param {String} domClass Class name to be removed from currently loaded target. @return {undefined} undefined
removeClass ( domClass )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype._stringifyMatrix = function _stringifyMatrix(m) { var r = 'matrix3d('; r += (m[0] < 0.000001 && m[0] > -0.000001) ? '0,' : m[0] + ','; r += (m[1] < 0.000001 && m[1] > -0.000001) ? '0,' : m[1] + ','; r += (m[2] < 0.000001 && m[2] > -0.000001) ? '0,' : m[2] + ','; r += (m[3] < 0.000001 && m[3] > -0.000001) ? '0,' : m[3] + ','; r += (m[4] < 0.000001 && m[4] > -0.000001) ? '0,' : m[4] + ','; r += (m[5] < 0.000001 && m[5] > -0.000001) ? '0,' : m[5] + ','; r += (m[6] < 0.000001 && m[6] > -0.000001) ? '0,' : m[6] + ','; r += (m[7] < 0.000001 && m[7] > -0.000001) ? '0,' : m[7] + ','; r += (m[8] < 0.000001 && m[8] > -0.000001) ? '0,' : m[8] + ','; r += (m[9] < 0.000001 && m[9] > -0.000001) ? '0,' : m[9] + ','; r += (m[10] < 0.000001 && m[10] > -0.000001) ? '0,' : m[10] + ','; r += (m[11] < 0.000001 && m[11] > -0.000001) ? '0,' : m[11] + ','; r += (m[12] < 0.000001 && m[12] > -0.000001) ? '0,' : m[12] + ','; r += (m[13] < 0.000001 && m[13] > -0.000001) ? '0,' : m[13] + ','; r += (m[14] < 0.000001 && m[14] > -0.000001) ? '0,' : m[14] + ','; r += m[15] + ')'; return r; };
Stringifies the passed in matrix for setting the `transform` property. @method _stringifyMatrix @private @param {Array} m Matrix as an array or array-like object. @return {String} Stringified matrix as `matrix3d`-property.
_stringifyMatrix ( m )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.onInsertEl = function onInsertEl(path, callback) { this._insertElCallbackStore.on(path, callback); return this; };
Registers a function to be executed when a new element is being inserted at the specified path. @method @param {String} path Path at which to listen for element insertion. @param {Function} callback Function to be executed when an insertion occurs. @return {DOMRenderer} this
onInsertEl ( path , callback )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.offInsertEl = function offInsertEl(path, callback) { this._insertElCallbackStore.off(path, callback); return this; };
Deregisters a listener function to be no longer executed on future element insertions at the specified path. @method @param {String} path Path at which the listener function has been registered. @param {Function} callback Callback function to be deregistered. @return {DOMRenderer} this
offInsertEl ( path , callback )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.onRemoveEl = function onRemoveEl(path, callback) { this._removeElCallbackStore.on(path, callback); return this; };
Registers an event handler to be triggered as soon as an element at the specified path is being removed. @method @param {String} path Path at which to listen for the removal of an element. @param {Function} callback Function to be executed when an element is being removed at the specified path. @return {DOMRenderer} this
onRemoveEl ( path , callback )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.offRemoveEl = function offRemoveEl(path, callback) { this._removeElCallbackStore.off(path, callback); return this; };
Deregisters a listener function to be no longer executed when an element is being removed from the specified path. @method @param {String} path Path at which the listener function has been registered. @param {Function} callback Callback function to be deregistered. @return {DOMRenderer} this
offRemoveEl ( path , callback )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
DOMRenderer.prototype.setContent = function setContent(content) { this._assertTargetLoaded(); if (this._target.formElement) { this._target.element.value = content; } else { if (!this._target.content) { this._target.content = document.createElement('div'); this._target.content.classList.add('famous-dom-element-content'); this._target.element.insertBefore( this._target.content, this._target.element.firstChild ); } this._target.content.innerHTML = content; } this.setSize( this._target.explicitWidth ? false : this._target.size[0], this._target.explicitHeight ? false : this._target.size[1] ); }; /** * Sets the passed in transform matrix (world space). Inverts the parent's world * transform. * * @method * * @param {Float32Array} transform The transform for the loaded DOM Element in world space * * @return {undefined} undefined */ DOMRenderer.prototype.setMatrix = function setMatrix (transform) { this._assertTargetLoaded(); this._target.element.style[TRANSFORM] = this._stringifyMatrix(transform); }; /** * Adds a class to the classList associated with the currently loaded target. * * @method * * @param {String} domClass Class name to be added to the current target. * * @return {undefined} undefined */ DOMRenderer.prototype.addClass = function addClass(domClass) { this._assertTargetLoaded(); this._target.element.classList.add(domClass); }; /** * Removes a class from the classList associated with the currently loaded * target. * * @method * * @param {String} domClass Class name to be removed from currently loaded target. * * @return {undefined} undefined */ DOMRenderer.prototype.removeClass = function removeClass(domClass) { this._assertTargetLoaded(); this._target.element.classList.remove(domClass); }; /** * Stringifies the passed in matrix for setting the `transform` property. * * @method _stringifyMatrix * @private * * @param {Array} m Matrix as an array or array-like object. * @return {String} Stringified matrix as `matrix3d`-property. */ DOMRenderer.prototype._stringifyMatrix = function _stringifyMatrix(m) { var r = 'matrix3d('; r += (m[0] < 0.000001 && m[0] > -0.000001) ? '0,' : m[0] + ','; r += (m[1] < 0.000001 && m[1] > -0.000001) ? '0,' : m[1] + ','; r += (m[2] < 0.000001 && m[2] > -0.000001) ? '0,' : m[2] + ','; r += (m[3] < 0.000001 && m[3] > -0.000001) ? '0,' : m[3] + ','; r += (m[4] < 0.000001 && m[4] > -0.000001) ? '0,' : m[4] + ','; r += (m[5] < 0.000001 && m[5] > -0.000001) ? '0,' : m[5] + ','; r += (m[6] < 0.000001 && m[6] > -0.000001) ? '0,' : m[6] + ','; r += (m[7] < 0.000001 && m[7] > -0.000001) ? '0,' : m[7] + ','; r += (m[8] < 0.000001 && m[8] > -0.000001) ? '0,' : m[8] + ','; r += (m[9] < 0.000001 && m[9] > -0.000001) ? '0,' : m[9] + ','; r += (m[10] < 0.000001 && m[10] > -0.000001) ? '0,' : m[10] + ','; r += (m[11] < 0.000001 && m[11] > -0.000001) ? '0,' : m[11] + ','; r += (m[12] < 0.000001 && m[12] > -0.000001) ? '0,' : m[12] + ','; r += (m[13] < 0.000001 && m[13] > -0.000001) ? '0,' : m[13] + ','; r += (m[14] < 0.000001 && m[14] > -0.000001) ? '0,' : m[14] + ','; r += m[15] + ')'; return r; }; /** * Registers a function to be executed when a new element is being inserted at * the specified path. * * @method * * @param {String} path Path at which to listen for element insertion. * @param {Function} callback Function to be executed when an insertion * occurs. * @return {DOMRenderer} this */ DOMRenderer.prototype.onInsertEl = function onInsertEl(path, callback) { this._insertElCallbackStore.on(path, callback); return this; }; /** * Deregisters a listener function to be no longer executed on future element * insertions at the specified path. * * @method * * @param {String} path Path at which the listener function has been * registered. * @param {Function} callback Callback function to be deregistered. * @return {DOMRenderer} this */ DOMRenderer.prototype.offInsertEl = function offInsertEl(path, callback) { this._insertElCallbackStore.off(path, callback); return this; }; /** * Registers an event handler to be triggered as soon as an element at the * specified path is being removed. * * @method * * @param {String} path Path at which to listen for the removal of an * element. * @param {Function} callback Function to be executed when an element is * being removed at the specified path. * @return {DOMRenderer} this */ DOMRenderer.prototype.onRemoveEl = function onRemoveEl(path, callback) { this._removeElCallbackStore.on(path, callback); return this; }; /** * Deregisters a listener function to be no longer executed when an element is * being removed from the specified path. * * @method * * @param {String} path Path at which the listener function has been * registered. * @param {Function} callback Callback function to be deregistered. * @return {DOMRenderer} this */ DOMRenderer.prototype.offRemoveEl = function offRemoveEl(path, callback) { this._removeElCallbackStore.off(path, callback); return this; }; module.exports = DOMRenderer;
Sets the `innerHTML` content of the currently loaded target. @method @param {String} content Content to be set as `innerHTML` @return {undefined} undefined
setContent ( content )
javascript
Famous/engine
dom-renderers/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/DOMRenderer.js
MIT
function Event(ev) { // [Constructor(DOMString type, optional EventInit eventInitDict), // Exposed=Window,Worker] // interface Event { // readonly attribute DOMString type; // readonly attribute EventTarget? target; // readonly attribute EventTarget? currentTarget; // const unsigned short NONE = 0; // const unsigned short CAPTURING_PHASE = 1; // const unsigned short AT_TARGET = 2; // const unsigned short BUBBLING_PHASE = 3; // readonly attribute unsigned short eventPhase; // void stopPropagation(); // void stopImmediatePropagation(); // readonly attribute boolean bubbles; // readonly attribute boolean cancelable; // void preventDefault(); // readonly attribute boolean defaultPrevented; // [Unforgeable] readonly attribute boolean isTrusted; // readonly attribute DOMTimeStamp timeStamp; // void initEvent(DOMString type, boolean bubbles, boolean cancelable); // }; /** * @name Event#type * @type String */ this.type = ev.type; /** * @name Event#defaultPrevented * @type Boolean */ this.defaultPrevented = ev.defaultPrevented; /** * @name Event#timeStamp * @type Number */ this.timeStamp = ev.timeStamp; /** * Used for exposing the current target's value. * * @name Event#value * @type String */ var targetConstructor = ev.target.constructor; // TODO Support HTMLKeygenElement if ( targetConstructor === HTMLInputElement || targetConstructor === HTMLTextAreaElement || targetConstructor === HTMLSelectElement ) { this.value = ev.target.value; } }
The Event class is being used in order to normalize native DOM events. Events need to be normalized in order to be serialized through the structured cloning algorithm used by the `postMessage` method (Web Workers). Wrapping DOM events also has the advantage of providing a consistent interface for interacting with DOM events across browsers by copying over a subset of the exposed properties that is guaranteed to be consistent across browsers. See [UI Events (formerly DOM Level 3 Events)](http://www.w3.org/TR/2015/WD-uievents-20150428/#interface-Event). @class Event @param {Event} ev The native DOM event.
Event ( ev )
javascript
Famous/engine
dom-renderers/events/Event.js
https://github.com/Famous/engine/blob/master/dom-renderers/events/Event.js
MIT
Event.prototype.toString = function toString () { return 'Event'; };
Return the name of the event type @method @return {String} Name of the event type
toString ( )
javascript
Famous/engine
dom-renderers/events/Event.js
https://github.com/Famous/engine/blob/master/dom-renderers/events/Event.js
MIT
function WheelEvent(ev) { // [Constructor(DOMString typeArg, optional WheelEventInit wheelEventInitDict)] // interface WheelEvent : MouseEvent { // // DeltaModeCode // const unsigned long DOM_DELTA_PIXEL = 0x00; // const unsigned long DOM_DELTA_LINE = 0x01; // const unsigned long DOM_DELTA_PAGE = 0x02; // readonly attribute double deltaX; // readonly attribute double deltaY; // readonly attribute double deltaZ; // readonly attribute unsigned long deltaMode; // }; MouseEvent.call(this, ev); /** * @name WheelEvent#DOM_DELTA_PIXEL * @type Number */ this.DOM_DELTA_PIXEL = 0x00; /** * @name WheelEvent#DOM_DELTA_LINE * @type Number */ this.DOM_DELTA_LINE = 0x01; /** * @name WheelEvent#DOM_DELTA_PAGE * @type Number */ this.DOM_DELTA_PAGE = 0x02; /** * @name WheelEvent#deltaX * @type Number */ this.deltaX = ev.deltaX; /** * @name WheelEvent#deltaY * @type Number */ this.deltaY = ev.deltaY; /** * @name WheelEvent#deltaZ * @type Number */ this.deltaZ = ev.deltaZ; /** * @name WheelEvent#deltaMode * @type Number */ this.deltaMode = ev.deltaMode; }
See [UI Events (formerly DOM Level 3 Events)](http://www.w3.org/TR/2015/WD-uievents-20150428/#events-wheelevents). @class WheelEvent @augments UIEvent @param {Event} ev The native DOM event.
WheelEvent ( ev )
javascript
Famous/engine
dom-renderers/events/WheelEvent.js
https://github.com/Famous/engine/blob/master/dom-renderers/events/WheelEvent.js
MIT
function MouseEvent(ev) { // [Constructor(DOMString typeArg, optional MouseEventInit mouseEventInitDict)] // interface MouseEvent : UIEvent { // readonly attribute long screenX; // readonly attribute long screenY; // readonly attribute long clientX; // readonly attribute long clientY; // readonly attribute boolean ctrlKey; // readonly attribute boolean shiftKey; // readonly attribute boolean altKey; // readonly attribute boolean metaKey; // readonly attribute short button; // readonly attribute EventTarget? relatedTarget; // // Introduced in this specification // readonly attribute unsigned short buttons; // boolean getModifierState (DOMString keyArg); // }; UIEvent.call(this, ev); /** * @name MouseEvent#screenX * @type Number */ this.screenX = ev.screenX; /** * @name MouseEvent#screenY * @type Number */ this.screenY = ev.screenY; /** * @name MouseEvent#clientX * @type Number */ this.clientX = ev.clientX; /** * @name MouseEvent#clientY * @type Number */ this.clientY = ev.clientY; /** * @name MouseEvent#ctrlKey * @type Boolean */ this.ctrlKey = ev.ctrlKey; /** * @name MouseEvent#shiftKey * @type Boolean */ this.shiftKey = ev.shiftKey; /** * @name MouseEvent#altKey * @type Boolean */ this.altKey = ev.altKey; /** * @name MouseEvent#metaKey * @type Boolean */ this.metaKey = ev.metaKey; /** * @type MouseEvent#button * @type Number */ this.button = ev.button; /** * @type MouseEvent#buttons * @type Number */ this.buttons = ev.buttons; /** * @type MouseEvent#pageX * @type Number */ this.pageX = ev.pageX; /** * @type MouseEvent#pageY * @type Number */ this.pageY = ev.pageY; /** * @type MouseEvent#x * @type Number */ this.x = ev.x; /** * @type MouseEvent#y * @type Number */ this.y = ev.y; /** * @type MouseEvent#offsetX * @type Number */ this.offsetX = ev.offsetX; /** * @type MouseEvent#offsetY * @type Number */ this.offsetY = ev.offsetY; }
See [UI Events (formerly DOM Level 3 Events)](http://www.w3.org/TR/2015/WD-uievents-20150428/#events-mouseevents). @class KeyboardEvent @augments UIEvent @param {Event} ev The native DOM event.
MouseEvent ( ev )
javascript
Famous/engine
dom-renderers/events/MouseEvent.js
https://github.com/Famous/engine/blob/master/dom-renderers/events/MouseEvent.js
MIT
function CompositionEvent(ev) { // [Constructor(DOMString typeArg, optional CompositionEventInit compositionEventInitDict)] // interface CompositionEvent : UIEvent { // readonly attribute DOMString data; // }; UIEvent.call(this, ev); /** * @name CompositionEvent#data * @type String */ this.data = ev.data; }
See [UI Events (formerly DOM Level 3 Events)](http://www.w3.org/TR/2015/WD-uievents-20150428/#events-compositionevents). @class CompositionEvent @augments UIEvent @param {Event} ev The native DOM event.
CompositionEvent ( ev )
javascript
Famous/engine
dom-renderers/events/CompositionEvent.js
https://github.com/Famous/engine/blob/master/dom-renderers/events/CompositionEvent.js
MIT
function UIEvent(ev) { // [Constructor(DOMString type, optional UIEventInit eventInitDict)] // interface UIEvent : Event { // readonly attribute Window? view; // readonly attribute long detail; // }; Event.call(this, ev); /** * @name UIEvent#detail * @type Number */ this.detail = ev.detail; }
See [UI Events (formerly DOM Level 3 Events)](http://www.w3.org/TR/2015/WD-uievents-20150428). @class UIEvent @augments Event @param {Event} ev The native DOM event.
UIEvent ( ev )
javascript
Famous/engine
dom-renderers/events/UIEvent.js
https://github.com/Famous/engine/blob/master/dom-renderers/events/UIEvent.js
MIT
function InputEvent(ev) { // [Constructor(DOMString typeArg, optional InputEventInit inputEventInitDict)] // interface InputEvent : UIEvent { // readonly attribute DOMString inputType; // readonly attribute DOMString data; // readonly attribute boolean isComposing; // readonly attribute Range targetRange; // }; UIEvent.call(this, ev); /** * @name InputEvent#inputType * @type String */ this.inputType = ev.inputType; /** * @name InputEvent#data * @type String */ this.data = ev.data; /** * @name InputEvent#isComposing * @type Boolean */ this.isComposing = ev.isComposing; /** * **Limited browser support**. * * @name InputEvent#targetRange * @type Boolean */ this.targetRange = ev.targetRange; }
See [Input Events](http://w3c.github.io/editing-explainer/input-events.html#idl-def-InputEvent). @class InputEvent @augments UIEvent @param {Event} ev The native DOM event.
InputEvent ( ev )
javascript
Famous/engine
dom-renderers/events/InputEvent.js
https://github.com/Famous/engine/blob/master/dom-renderers/events/InputEvent.js
MIT
function FocusEvent(ev) { // [Constructor(DOMString typeArg, optional FocusEventInit focusEventInitDict)] // interface FocusEvent : UIEvent { // readonly attribute EventTarget? relatedTarget; // }; UIEvent.call(this, ev); }
See [UI Events (formerly DOM Level 3 Events)](http://www.w3.org/TR/2015/WD-uievents-20150428/#events-focusevent). @class FocusEvent @augments UIEvent @param {Event} ev The native DOM event.
FocusEvent ( ev )
javascript
Famous/engine
dom-renderers/events/FocusEvent.js
https://github.com/Famous/engine/blob/master/dom-renderers/events/FocusEvent.js
MIT
function KeyboardEvent(ev) { // [Constructor(DOMString typeArg, optional KeyboardEventInit keyboardEventInitDict)] // interface KeyboardEvent : UIEvent { // // KeyLocationCode // const unsigned long DOM_KEY_LOCATION_STANDARD = 0x00; // const unsigned long DOM_KEY_LOCATION_LEFT = 0x01; // const unsigned long DOM_KEY_LOCATION_RIGHT = 0x02; // const unsigned long DOM_KEY_LOCATION_NUMPAD = 0x03; // readonly attribute DOMString key; // readonly attribute DOMString code; // readonly attribute unsigned long location; // readonly attribute boolean ctrlKey; // readonly attribute boolean shiftKey; // readonly attribute boolean altKey; // readonly attribute boolean metaKey; // readonly attribute boolean repeat; // readonly attribute boolean isComposing; // boolean getModifierState (DOMString keyArg); // }; UIEvent.call(this, ev); /** * @name KeyboardEvent#DOM_KEY_LOCATION_STANDARD * @type Number */ this.DOM_KEY_LOCATION_STANDARD = 0x00; /** * @name KeyboardEvent#DOM_KEY_LOCATION_LEFT * @type Number */ this.DOM_KEY_LOCATION_LEFT = 0x01; /** * @name KeyboardEvent#DOM_KEY_LOCATION_RIGHT * @type Number */ this.DOM_KEY_LOCATION_RIGHT = 0x02; /** * @name KeyboardEvent#DOM_KEY_LOCATION_NUMPAD * @type Number */ this.DOM_KEY_LOCATION_NUMPAD = 0x03; /** * @name KeyboardEvent#key * @type String */ this.key = ev.key; /** * @name KeyboardEvent#code * @type String */ this.code = ev.code; /** * @name KeyboardEvent#location * @type Number */ this.location = ev.location; /** * @name KeyboardEvent#ctrlKey * @type Boolean */ this.ctrlKey = ev.ctrlKey; /** * @name KeyboardEvent#shiftKey * @type Boolean */ this.shiftKey = ev.shiftKey; /** * @name KeyboardEvent#altKey * @type Boolean */ this.altKey = ev.altKey; /** * @name KeyboardEvent#metaKey * @type Boolean */ this.metaKey = ev.metaKey; /** * @name KeyboardEvent#repeat * @type Boolean */ this.repeat = ev.repeat; /** * @name KeyboardEvent#isComposing * @type Boolean */ this.isComposing = ev.isComposing; /** * @name KeyboardEvent#keyCode * @type String * @deprecated */ this.keyCode = ev.keyCode; }
See [UI Events (formerly DOM Level 3 Events)](http://www.w3.org/TR/2015/WD-uievents-20150428/#events-keyboardevents). @class KeyboardEvent @augments UIEvent @param {Event} ev The native DOM event.
KeyboardEvent ( ev )
javascript
Famous/engine
dom-renderers/events/KeyboardEvent.js
https://github.com/Famous/engine/blob/master/dom-renderers/events/KeyboardEvent.js
MIT
function Touch(touch) { // interface Touch { // readonly attribute long identifier; // readonly attribute EventTarget target; // readonly attribute double screenX; // readonly attribute double screenY; // readonly attribute double clientX; // readonly attribute double clientY; // readonly attribute double pageX; // readonly attribute double pageY; // }; /** * @name Touch#identifier * @type Number */ this.identifier = touch.identifier; /** * @name Touch#screenX * @type Number */ this.screenX = touch.screenX; /** * @name Touch#screenY * @type Number */ this.screenY = touch.screenY; /** * @name Touch#clientX * @type Number */ this.clientX = touch.clientX; /** * @name Touch#clientY * @type Number */ this.clientY = touch.clientY; /** * @name Touch#pageX * @type Number */ this.pageX = touch.pageX; /** * @name Touch#pageY * @type Number */ this.pageY = touch.pageY; }
See [Touch Interface](http://www.w3.org/TR/2013/REC-touch-events-20131010/#touch-interface). @class Touch @private @param {Touch} touch The native Touch object.
Touch ( touch )
javascript
Famous/engine
dom-renderers/events/TouchEvent.js
https://github.com/Famous/engine/blob/master/dom-renderers/events/TouchEvent.js
MIT
function cloneTouchList(touchList) { if (!touchList) return EMPTY_ARRAY; // interface TouchList { // readonly attribute unsigned long length; // getter Touch? item (unsigned long index); // }; var touchListArray = []; for (var i = 0; i < touchList.length; i++) { touchListArray[i] = new Touch(touchList[i]); } return touchListArray; }
Normalizes the browser's native TouchList by converting it into an array of normalized Touch objects. @method cloneTouchList @private @param {TouchList} touchList The native TouchList array. @return {Array.<Touch>} An array of normalized Touch objects.
cloneTouchList ( touchList )
javascript
Famous/engine
dom-renderers/events/TouchEvent.js
https://github.com/Famous/engine/blob/master/dom-renderers/events/TouchEvent.js
MIT
function TouchEvent(ev) { // interface TouchEvent : UIEvent { // readonly attribute TouchList touches; // readonly attribute TouchList targetTouches; // readonly attribute TouchList changedTouches; // readonly attribute boolean altKey; // readonly attribute boolean metaKey; // readonly attribute boolean ctrlKey; // readonly attribute boolean shiftKey; // }; UIEvent.call(this, ev); /** * @name TouchEvent#touches * @type Array.<Touch> */ this.touches = cloneTouchList(ev.touches); /** * @name TouchEvent#targetTouches * @type Array.<Touch> */ this.targetTouches = cloneTouchList(ev.targetTouches); /** * @name TouchEvent#changedTouches * @type TouchList */ this.changedTouches = cloneTouchList(ev.changedTouches); /** * @name TouchEvent#altKey * @type Boolean */ this.altKey = ev.altKey; /** * @name TouchEvent#metaKey * @type Boolean */ this.metaKey = ev.metaKey; /** * @name TouchEvent#ctrlKey * @type Boolean */ this.ctrlKey = ev.ctrlKey; /** * @name TouchEvent#shiftKey * @type Boolean */ this.shiftKey = ev.shiftKey; }
See [Touch Event Interface](http://www.w3.org/TR/2013/REC-touch-events-20131010/#touchevent-interface). @class TouchEvent @augments UIEvent @param {Event} ev The native DOM event.
TouchEvent ( ev )
javascript
Famous/engine
dom-renderers/events/TouchEvent.js
https://github.com/Famous/engine/blob/master/dom-renderers/events/TouchEvent.js
MIT
function createUnidirectionalCompositor(t) { return { sendEvent: function () { t.fail('DOMRenderer should not send delegated events for a static DOM tree'); } }; }
Helpers method used for creating a mock compositor that fails on received events. Used for ensuring that certain DOMRenderer methods don't (directly or indirectly) trigger DOM events. @method createUnidirectionalCompositor @private @param {tape} t tape-test object @return {Object} mock compositor
createUnidirectionalCompositor ( t )
javascript
Famous/engine
dom-renderers/test/DOMRenderer.js
https://github.com/Famous/engine/blob/master/dom-renderers/test/DOMRenderer.js
MIT
function TextureManager(gl) { this.registry = []; this._needsResample = []; this._activeTexture = 0; this._boundTexture = null; this._checkerboard = createCheckerboard(); this.gl = gl; }
Handles loading, binding, and resampling of textures for WebGLRenderer. @class TextureManager @constructor @param {WebGL_Context} gl Context used to create and bind textures. @return {undefined} undefined
TextureManager ( gl )
javascript
Famous/engine
webgl-renderers/TextureManager.js
https://github.com/Famous/engine/blob/master/webgl-renderers/TextureManager.js
MIT
TextureManager.prototype.update = function update(time) { var registryLength = this.registry.length; for (var i = 1; i < registryLength; i++) { var texture = this.registry[i]; if (texture && texture.isLoaded && texture.resampleRate) { if (!texture.lastResample || time - texture.lastResample > texture.resampleRate) { if (!this._needsResample[texture.id]) { this._needsResample[texture.id] = true; texture.lastResample = time; } } } } };
Update function used by WebGLRenderer to queue resamples on registered textures. @method @param {Number} time Time in milliseconds according to the compositor. @return {undefined} undefined
update ( time )
javascript
Famous/engine
webgl-renderers/TextureManager.js
https://github.com/Famous/engine/blob/master/webgl-renderers/TextureManager.js
MIT