id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
10,900
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function() { var actions = this._actions, nActions = this._nActiveActions, bindings = this._bindings, nBindings = this._nActiveBindings; this._nActiveActions = 0; this._nActiveBindings = 0; for ( var i = 0; i !== nActions; ++ i ) { actions[ i ].reset(); } for ( var i = 0; i !== nBindings; ++ i ) { bindings[ i ].useCount = 0; } return this; }
javascript
function() { var actions = this._actions, nActions = this._nActiveActions, bindings = this._bindings, nBindings = this._nActiveBindings; this._nActiveActions = 0; this._nActiveBindings = 0; for ( var i = 0; i !== nActions; ++ i ) { actions[ i ].reset(); } for ( var i = 0; i !== nBindings; ++ i ) { bindings[ i ].useCount = 0; } return this; }
[ "function", "(", ")", "{", "var", "actions", "=", "this", ".", "_actions", ",", "nActions", "=", "this", ".", "_nActiveActions", ",", "bindings", "=", "this", ".", "_bindings", ",", "nBindings", "=", "this", ".", "_nActiveBindings", ";", "this", ".", "_nActiveActions", "=", "0", ";", "this", ".", "_nActiveBindings", "=", "0", ";", "for", "(", "var", "i", "=", "0", ";", "i", "!==", "nActions", ";", "++", "i", ")", "{", "actions", "[", "i", "]", ".", "reset", "(", ")", ";", "}", "for", "(", "var", "i", "=", "0", ";", "i", "!==", "nBindings", ";", "++", "i", ")", "{", "bindings", "[", "i", "]", ".", "useCount", "=", "0", ";", "}", "return", "this", ";", "}" ]
deactivates all previously scheduled actions
[ "deactivates", "all", "previously", "scheduled", "actions" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L13630-L13654
10,901
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function( clip ) { var actions = this._actions, clipUuid = clip.uuid, actionsByClip = this._actionsByClip, actionsForClip = actionsByClip[ clipUuid ]; if ( actionsForClip !== undefined ) { // note: just calling _removeInactiveAction would mess up the // iteration state and also require updating the state we can // just throw away var actionsToRemove = actionsForClip.knownActions; for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) { var action = actionsToRemove[ i ]; this._deactivateAction( action ); var cacheIndex = action._cacheIndex, lastInactiveAction = actions[ actions.length - 1 ]; action._cacheIndex = null; action._byClipCacheIndex = null; lastInactiveAction._cacheIndex = cacheIndex; actions[ cacheIndex ] = lastInactiveAction; actions.pop(); this._removeInactiveBindingsForAction( action ); } delete actionsByClip[ clipUuid ]; } }
javascript
function( clip ) { var actions = this._actions, clipUuid = clip.uuid, actionsByClip = this._actionsByClip, actionsForClip = actionsByClip[ clipUuid ]; if ( actionsForClip !== undefined ) { // note: just calling _removeInactiveAction would mess up the // iteration state and also require updating the state we can // just throw away var actionsToRemove = actionsForClip.knownActions; for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) { var action = actionsToRemove[ i ]; this._deactivateAction( action ); var cacheIndex = action._cacheIndex, lastInactiveAction = actions[ actions.length - 1 ]; action._cacheIndex = null; action._byClipCacheIndex = null; lastInactiveAction._cacheIndex = cacheIndex; actions[ cacheIndex ] = lastInactiveAction; actions.pop(); this._removeInactiveBindingsForAction( action ); } delete actionsByClip[ clipUuid ]; } }
[ "function", "(", "clip", ")", "{", "var", "actions", "=", "this", ".", "_actions", ",", "clipUuid", "=", "clip", ".", "uuid", ",", "actionsByClip", "=", "this", ".", "_actionsByClip", ",", "actionsForClip", "=", "actionsByClip", "[", "clipUuid", "]", ";", "if", "(", "actionsForClip", "!==", "undefined", ")", "{", "// note: just calling _removeInactiveAction would mess up the", "// iteration state and also require updating the state we can", "// just throw away", "var", "actionsToRemove", "=", "actionsForClip", ".", "knownActions", ";", "for", "(", "var", "i", "=", "0", ",", "n", "=", "actionsToRemove", ".", "length", ";", "i", "!==", "n", ";", "++", "i", ")", "{", "var", "action", "=", "actionsToRemove", "[", "i", "]", ";", "this", ".", "_deactivateAction", "(", "action", ")", ";", "var", "cacheIndex", "=", "action", ".", "_cacheIndex", ",", "lastInactiveAction", "=", "actions", "[", "actions", ".", "length", "-", "1", "]", ";", "action", ".", "_cacheIndex", "=", "null", ";", "action", ".", "_byClipCacheIndex", "=", "null", ";", "lastInactiveAction", ".", "_cacheIndex", "=", "cacheIndex", ";", "actions", "[", "cacheIndex", "]", "=", "lastInactiveAction", ";", "actions", ".", "pop", "(", ")", ";", "this", ".", "_removeInactiveBindingsForAction", "(", "action", ")", ";", "}", "delete", "actionsByClip", "[", "clipUuid", "]", ";", "}", "}" ]
free all resources specific to a particular clip
[ "free", "all", "resources", "specific", "to", "a", "particular", "clip" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L13706-L13745
10,902
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function( root ) { var rootUuid = root.uuid, actionsByClip = this._actionsByClip; for ( var clipUuid in actionsByClip ) { var actionByRoot = actionsByClip[ clipUuid ].actionByRoot, action = actionByRoot[ rootUuid ]; if ( action !== undefined ) { this._deactivateAction( action ); this._removeInactiveAction( action ); } } var bindingsByRoot = this._bindingsByRootAndName, bindingByName = bindingsByRoot[ rootUuid ]; if ( bindingByName !== undefined ) { for ( var trackName in bindingByName ) { var binding = bindingByName[ trackName ]; binding.restoreOriginalState(); this._removeInactiveBinding( binding ); } } }
javascript
function( root ) { var rootUuid = root.uuid, actionsByClip = this._actionsByClip; for ( var clipUuid in actionsByClip ) { var actionByRoot = actionsByClip[ clipUuid ].actionByRoot, action = actionByRoot[ rootUuid ]; if ( action !== undefined ) { this._deactivateAction( action ); this._removeInactiveAction( action ); } } var bindingsByRoot = this._bindingsByRootAndName, bindingByName = bindingsByRoot[ rootUuid ]; if ( bindingByName !== undefined ) { for ( var trackName in bindingByName ) { var binding = bindingByName[ trackName ]; binding.restoreOriginalState(); this._removeInactiveBinding( binding ); } } }
[ "function", "(", "root", ")", "{", "var", "rootUuid", "=", "root", ".", "uuid", ",", "actionsByClip", "=", "this", ".", "_actionsByClip", ";", "for", "(", "var", "clipUuid", "in", "actionsByClip", ")", "{", "var", "actionByRoot", "=", "actionsByClip", "[", "clipUuid", "]", ".", "actionByRoot", ",", "action", "=", "actionByRoot", "[", "rootUuid", "]", ";", "if", "(", "action", "!==", "undefined", ")", "{", "this", ".", "_deactivateAction", "(", "action", ")", ";", "this", ".", "_removeInactiveAction", "(", "action", ")", ";", "}", "}", "var", "bindingsByRoot", "=", "this", ".", "_bindingsByRootAndName", ",", "bindingByName", "=", "bindingsByRoot", "[", "rootUuid", "]", ";", "if", "(", "bindingByName", "!==", "undefined", ")", "{", "for", "(", "var", "trackName", "in", "bindingByName", ")", "{", "var", "binding", "=", "bindingByName", "[", "trackName", "]", ";", "binding", ".", "restoreOriginalState", "(", ")", ";", "this", ".", "_removeInactiveBinding", "(", "binding", ")", ";", "}", "}", "}" ]
free all resources specific to a particular root target object
[ "free", "all", "resources", "specific", "to", "a", "particular", "root", "target", "object" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L13748-L13782
10,903
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function( clip, optionalRoot ) { var action = this.existingAction( clip, optionalRoot ); if ( action !== null ) { this._deactivateAction( action ); this._removeInactiveAction( action ); } }
javascript
function( clip, optionalRoot ) { var action = this.existingAction( clip, optionalRoot ); if ( action !== null ) { this._deactivateAction( action ); this._removeInactiveAction( action ); } }
[ "function", "(", "clip", ",", "optionalRoot", ")", "{", "var", "action", "=", "this", ".", "existingAction", "(", "clip", ",", "optionalRoot", ")", ";", "if", "(", "action", "!==", "null", ")", "{", "this", ".", "_deactivateAction", "(", "action", ")", ";", "this", ".", "_removeInactiveAction", "(", "action", ")", ";", "}", "}" ]
remove a targeted clip from the cache
[ "remove", "a", "targeted", "clip", "from", "the", "cache" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L13785-L13796
10,904
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function( binding, rootUuid, trackName ) { var bindingsByRoot = this._bindingsByRootAndName, bindingByName = bindingsByRoot[ rootUuid ], bindings = this._bindings; if ( bindingByName === undefined ) { bindingByName = {}; bindingsByRoot[ rootUuid ] = bindingByName; } bindingByName[ trackName ] = binding; binding._cacheIndex = bindings.length; bindings.push( binding ); }
javascript
function( binding, rootUuid, trackName ) { var bindingsByRoot = this._bindingsByRootAndName, bindingByName = bindingsByRoot[ rootUuid ], bindings = this._bindings; if ( bindingByName === undefined ) { bindingByName = {}; bindingsByRoot[ rootUuid ] = bindingByName; } bindingByName[ trackName ] = binding; binding._cacheIndex = bindings.length; bindings.push( binding ); }
[ "function", "(", "binding", ",", "rootUuid", ",", "trackName", ")", "{", "var", "bindingsByRoot", "=", "this", ".", "_bindingsByRootAndName", ",", "bindingByName", "=", "bindingsByRoot", "[", "rootUuid", "]", ",", "bindings", "=", "this", ".", "_bindings", ";", "if", "(", "bindingByName", "===", "undefined", ")", "{", "bindingByName", "=", "{", "}", ";", "bindingsByRoot", "[", "rootUuid", "]", "=", "bindingByName", ";", "}", "bindingByName", "[", "trackName", "]", "=", "binding", ";", "binding", ".", "_cacheIndex", "=", "bindings", ".", "length", ";", "bindings", ".", "push", "(", "binding", ")", ";", "}" ]
Memory management for PropertyMixer objects
[ "Memory", "management", "for", "PropertyMixer", "objects" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L14140-L14159
10,905
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function() { var interpolants = this._controlInterpolants, lastActiveIndex = this._nActiveControlInterpolants ++, interpolant = interpolants[ lastActiveIndex ]; if ( interpolant === undefined ) { interpolant = new THREE.LinearInterpolant( new Float32Array( 2 ), new Float32Array( 2 ), 1, this._controlInterpolantsResultBuffer ); interpolant.__cacheIndex = lastActiveIndex; interpolants[ lastActiveIndex ] = interpolant; } return interpolant; }
javascript
function() { var interpolants = this._controlInterpolants, lastActiveIndex = this._nActiveControlInterpolants ++, interpolant = interpolants[ lastActiveIndex ]; if ( interpolant === undefined ) { interpolant = new THREE.LinearInterpolant( new Float32Array( 2 ), new Float32Array( 2 ), 1, this._controlInterpolantsResultBuffer ); interpolant.__cacheIndex = lastActiveIndex; interpolants[ lastActiveIndex ] = interpolant; } return interpolant; }
[ "function", "(", ")", "{", "var", "interpolants", "=", "this", ".", "_controlInterpolants", ",", "lastActiveIndex", "=", "this", ".", "_nActiveControlInterpolants", "++", ",", "interpolant", "=", "interpolants", "[", "lastActiveIndex", "]", ";", "if", "(", "interpolant", "===", "undefined", ")", "{", "interpolant", "=", "new", "THREE", ".", "LinearInterpolant", "(", "new", "Float32Array", "(", "2", ")", ",", "new", "Float32Array", "(", "2", ")", ",", "1", ",", "this", ".", "_controlInterpolantsResultBuffer", ")", ";", "interpolant", ".", "__cacheIndex", "=", "lastActiveIndex", ";", "interpolants", "[", "lastActiveIndex", "]", "=", "interpolant", ";", "}", "return", "interpolant", ";", "}" ]
Memory management of Interpolants for weight and time scale
[ "Memory", "management", "of", "Interpolants", "for", "weight", "and", "time", "scale" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L14226-L14245
10,906
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function( var_args ) { var objects = this._objects, nObjects = objects.length, nCachedObjects = this.nCachedObjects_, indicesByUUID = this._indicesByUUID, bindings = this._bindings, nBindings = bindings.length; for ( var i = 0, n = arguments.length; i !== n; ++ i ) { var object = arguments[ i ], uuid = object.uuid, index = indicesByUUID[ uuid ]; if ( index !== undefined ) { delete indicesByUUID[ uuid ]; if ( index < nCachedObjects ) { // object is cached, shrink the CACHED region var firstActiveIndex = -- nCachedObjects, lastCachedObject = objects[ firstActiveIndex ], lastIndex = -- nObjects, lastObject = objects[ lastIndex ]; // last cached object takes this object's place indicesByUUID[ lastCachedObject.uuid ] = index; objects[ index ] = lastCachedObject; // last object goes to the activated slot and pop indicesByUUID[ lastObject.uuid ] = firstActiveIndex; objects[ firstActiveIndex ] = lastObject; objects.pop(); // accounting is done, now do the same for all bindings for ( var j = 0, m = nBindings; j !== m; ++ j ) { var bindingsForPath = bindings[ j ], lastCached = bindingsForPath[ firstActiveIndex ], last = bindingsForPath[ lastIndex ]; bindingsForPath[ index ] = lastCached; bindingsForPath[ firstActiveIndex ] = last; bindingsForPath.pop(); } } else { // object is active, just swap with the last and pop var lastIndex = -- nObjects, lastObject = objects[ lastIndex ]; indicesByUUID[ lastObject.uuid ] = index; objects[ index ] = lastObject; objects.pop(); // accounting is done, now do the same for all bindings for ( var j = 0, m = nBindings; j !== m; ++ j ) { var bindingsForPath = bindings[ j ]; bindingsForPath[ index ] = bindingsForPath[ lastIndex ]; bindingsForPath.pop(); } } // cached or active } // if object is known } // for arguments this.nCachedObjects_ = nCachedObjects; }
javascript
function( var_args ) { var objects = this._objects, nObjects = objects.length, nCachedObjects = this.nCachedObjects_, indicesByUUID = this._indicesByUUID, bindings = this._bindings, nBindings = bindings.length; for ( var i = 0, n = arguments.length; i !== n; ++ i ) { var object = arguments[ i ], uuid = object.uuid, index = indicesByUUID[ uuid ]; if ( index !== undefined ) { delete indicesByUUID[ uuid ]; if ( index < nCachedObjects ) { // object is cached, shrink the CACHED region var firstActiveIndex = -- nCachedObjects, lastCachedObject = objects[ firstActiveIndex ], lastIndex = -- nObjects, lastObject = objects[ lastIndex ]; // last cached object takes this object's place indicesByUUID[ lastCachedObject.uuid ] = index; objects[ index ] = lastCachedObject; // last object goes to the activated slot and pop indicesByUUID[ lastObject.uuid ] = firstActiveIndex; objects[ firstActiveIndex ] = lastObject; objects.pop(); // accounting is done, now do the same for all bindings for ( var j = 0, m = nBindings; j !== m; ++ j ) { var bindingsForPath = bindings[ j ], lastCached = bindingsForPath[ firstActiveIndex ], last = bindingsForPath[ lastIndex ]; bindingsForPath[ index ] = lastCached; bindingsForPath[ firstActiveIndex ] = last; bindingsForPath.pop(); } } else { // object is active, just swap with the last and pop var lastIndex = -- nObjects, lastObject = objects[ lastIndex ]; indicesByUUID[ lastObject.uuid ] = index; objects[ index ] = lastObject; objects.pop(); // accounting is done, now do the same for all bindings for ( var j = 0, m = nBindings; j !== m; ++ j ) { var bindingsForPath = bindings[ j ]; bindingsForPath[ index ] = bindingsForPath[ lastIndex ]; bindingsForPath.pop(); } } // cached or active } // if object is known } // for arguments this.nCachedObjects_ = nCachedObjects; }
[ "function", "(", "var_args", ")", "{", "var", "objects", "=", "this", ".", "_objects", ",", "nObjects", "=", "objects", ".", "length", ",", "nCachedObjects", "=", "this", ".", "nCachedObjects_", ",", "indicesByUUID", "=", "this", ".", "_indicesByUUID", ",", "bindings", "=", "this", ".", "_bindings", ",", "nBindings", "=", "bindings", ".", "length", ";", "for", "(", "var", "i", "=", "0", ",", "n", "=", "arguments", ".", "length", ";", "i", "!==", "n", ";", "++", "i", ")", "{", "var", "object", "=", "arguments", "[", "i", "]", ",", "uuid", "=", "object", ".", "uuid", ",", "index", "=", "indicesByUUID", "[", "uuid", "]", ";", "if", "(", "index", "!==", "undefined", ")", "{", "delete", "indicesByUUID", "[", "uuid", "]", ";", "if", "(", "index", "<", "nCachedObjects", ")", "{", "// object is cached, shrink the CACHED region", "var", "firstActiveIndex", "=", "--", "nCachedObjects", ",", "lastCachedObject", "=", "objects", "[", "firstActiveIndex", "]", ",", "lastIndex", "=", "--", "nObjects", ",", "lastObject", "=", "objects", "[", "lastIndex", "]", ";", "// last cached object takes this object's place", "indicesByUUID", "[", "lastCachedObject", ".", "uuid", "]", "=", "index", ";", "objects", "[", "index", "]", "=", "lastCachedObject", ";", "// last object goes to the activated slot and pop", "indicesByUUID", "[", "lastObject", ".", "uuid", "]", "=", "firstActiveIndex", ";", "objects", "[", "firstActiveIndex", "]", "=", "lastObject", ";", "objects", ".", "pop", "(", ")", ";", "// accounting is done, now do the same for all bindings", "for", "(", "var", "j", "=", "0", ",", "m", "=", "nBindings", ";", "j", "!==", "m", ";", "++", "j", ")", "{", "var", "bindingsForPath", "=", "bindings", "[", "j", "]", ",", "lastCached", "=", "bindingsForPath", "[", "firstActiveIndex", "]", ",", "last", "=", "bindingsForPath", "[", "lastIndex", "]", ";", "bindingsForPath", "[", "index", "]", "=", "lastCached", ";", "bindingsForPath", "[", "firstActiveIndex", "]", "=", "last", ";", "bindingsForPath", ".", "pop", "(", ")", ";", "}", "}", "else", "{", "// object is active, just swap with the last and pop", "var", "lastIndex", "=", "--", "nObjects", ",", "lastObject", "=", "objects", "[", "lastIndex", "]", ";", "indicesByUUID", "[", "lastObject", ".", "uuid", "]", "=", "index", ";", "objects", "[", "index", "]", "=", "lastObject", ";", "objects", ".", "pop", "(", ")", ";", "// accounting is done, now do the same for all bindings", "for", "(", "var", "j", "=", "0", ",", "m", "=", "nBindings", ";", "j", "!==", "m", ";", "++", "j", ")", "{", "var", "bindingsForPath", "=", "bindings", "[", "j", "]", ";", "bindingsForPath", "[", "index", "]", "=", "bindingsForPath", "[", "lastIndex", "]", ";", "bindingsForPath", ".", "pop", "(", ")", ";", "}", "}", "// cached or active", "}", "// if object is known", "}", "// for arguments", "this", ".", "nCachedObjects_", "=", "nCachedObjects", ";", "}" ]
remove & forget
[ "remove", "&", "forget" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L14483-L14564
10,907
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function( array, type, forceClone ) { if ( ! array || // let 'undefined' and 'null' pass ! forceClone && array.constructor === type ) return array; if ( typeof type.BYTES_PER_ELEMENT === 'number' ) { return new type( array ); // create typed array } return Array.prototype.slice.call( array ); // create Array }
javascript
function( array, type, forceClone ) { if ( ! array || // let 'undefined' and 'null' pass ! forceClone && array.constructor === type ) return array; if ( typeof type.BYTES_PER_ELEMENT === 'number' ) { return new type( array ); // create typed array } return Array.prototype.slice.call( array ); // create Array }
[ "function", "(", "array", ",", "type", ",", "forceClone", ")", "{", "if", "(", "!", "array", "||", "// let 'undefined' and 'null' pass", "!", "forceClone", "&&", "array", ".", "constructor", "===", "type", ")", "return", "array", ";", "if", "(", "typeof", "type", ".", "BYTES_PER_ELEMENT", "===", "'number'", ")", "{", "return", "new", "type", "(", "array", ")", ";", "// create typed array", "}", "return", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "array", ")", ";", "// create Array", "}" ]
converts an array to a specific type
[ "converts", "an", "array", "to", "a", "specific", "type" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L14665-L14678
10,908
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function( times ) { function compareTime( i, j ) { return times[ i ] - times[ j ]; } var n = times.length; var result = new Array( n ); for ( var i = 0; i !== n; ++ i ) result[ i ] = i; result.sort( compareTime ); return result; }
javascript
function( times ) { function compareTime( i, j ) { return times[ i ] - times[ j ]; } var n = times.length; var result = new Array( n ); for ( var i = 0; i !== n; ++ i ) result[ i ] = i; result.sort( compareTime ); return result; }
[ "function", "(", "times", ")", "{", "function", "compareTime", "(", "i", ",", "j", ")", "{", "return", "times", "[", "i", "]", "-", "times", "[", "j", "]", ";", "}", "var", "n", "=", "times", ".", "length", ";", "var", "result", "=", "new", "Array", "(", "n", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "!==", "n", ";", "++", "i", ")", "result", "[", "i", "]", "=", "i", ";", "result", ".", "sort", "(", "compareTime", ")", ";", "return", "result", ";", "}" ]
returns an array by which times and values can be sorted
[ "returns", "an", "array", "by", "which", "times", "and", "values", "can", "be", "sorted" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L14688-L14704
10,909
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function( values, stride, order ) { var nValues = values.length; var result = new values.constructor( nValues ); for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) { var srcOffset = order[ i ] * stride; for ( var j = 0; j !== stride; ++ j ) { result[ dstOffset ++ ] = values[ srcOffset + j ]; } } return result; }
javascript
function( values, stride, order ) { var nValues = values.length; var result = new values.constructor( nValues ); for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) { var srcOffset = order[ i ] * stride; for ( var j = 0; j !== stride; ++ j ) { result[ dstOffset ++ ] = values[ srcOffset + j ]; } } return result; }
[ "function", "(", "values", ",", "stride", ",", "order", ")", "{", "var", "nValues", "=", "values", ".", "length", ";", "var", "result", "=", "new", "values", ".", "constructor", "(", "nValues", ")", ";", "for", "(", "var", "i", "=", "0", ",", "dstOffset", "=", "0", ";", "dstOffset", "!==", "nValues", ";", "++", "i", ")", "{", "var", "srcOffset", "=", "order", "[", "i", "]", "*", "stride", ";", "for", "(", "var", "j", "=", "0", ";", "j", "!==", "stride", ";", "++", "j", ")", "{", "result", "[", "dstOffset", "++", "]", "=", "values", "[", "srcOffset", "+", "j", "]", ";", "}", "}", "return", "result", ";", "}" ]
uses the array previously returned by 'getKeyframeOrder' to sort data
[ "uses", "the", "array", "previously", "returned", "by", "getKeyframeOrder", "to", "sort", "data" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L14707-L14726
10,910
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function( jsonKeys, times, values, valuePropertyName ) { var i = 1, key = jsonKeys[ 0 ]; while ( key !== undefined && key[ valuePropertyName ] === undefined ) { key = jsonKeys[ i ++ ]; } if ( key === undefined ) return; // no data var value = key[ valuePropertyName ]; if ( value === undefined ) return; // no data if ( Array.isArray( value ) ) { do { value = key[ valuePropertyName ]; if ( value !== undefined ) { times.push( key.time ); values.push.apply( values, value ); // push all elements } key = jsonKeys[ i ++ ]; } while ( key !== undefined ); } else if ( value.toArray !== undefined ) { // ...assume THREE.Math-ish do { value = key[ valuePropertyName ]; if ( value !== undefined ) { times.push( key.time ); value.toArray( values, values.length ); } key = jsonKeys[ i ++ ]; } while ( key !== undefined ); } else { // otherwise push as-is do { value = key[ valuePropertyName ]; if ( value !== undefined ) { times.push( key.time ); values.push( value ); } key = jsonKeys[ i ++ ]; } while ( key !== undefined ); } }
javascript
function( jsonKeys, times, values, valuePropertyName ) { var i = 1, key = jsonKeys[ 0 ]; while ( key !== undefined && key[ valuePropertyName ] === undefined ) { key = jsonKeys[ i ++ ]; } if ( key === undefined ) return; // no data var value = key[ valuePropertyName ]; if ( value === undefined ) return; // no data if ( Array.isArray( value ) ) { do { value = key[ valuePropertyName ]; if ( value !== undefined ) { times.push( key.time ); values.push.apply( values, value ); // push all elements } key = jsonKeys[ i ++ ]; } while ( key !== undefined ); } else if ( value.toArray !== undefined ) { // ...assume THREE.Math-ish do { value = key[ valuePropertyName ]; if ( value !== undefined ) { times.push( key.time ); value.toArray( values, values.length ); } key = jsonKeys[ i ++ ]; } while ( key !== undefined ); } else { // otherwise push as-is do { value = key[ valuePropertyName ]; if ( value !== undefined ) { times.push( key.time ); values.push( value ); } key = jsonKeys[ i ++ ]; } while ( key !== undefined ); } }
[ "function", "(", "jsonKeys", ",", "times", ",", "values", ",", "valuePropertyName", ")", "{", "var", "i", "=", "1", ",", "key", "=", "jsonKeys", "[", "0", "]", ";", "while", "(", "key", "!==", "undefined", "&&", "key", "[", "valuePropertyName", "]", "===", "undefined", ")", "{", "key", "=", "jsonKeys", "[", "i", "++", "]", ";", "}", "if", "(", "key", "===", "undefined", ")", "return", ";", "// no data", "var", "value", "=", "key", "[", "valuePropertyName", "]", ";", "if", "(", "value", "===", "undefined", ")", "return", ";", "// no data", "if", "(", "Array", ".", "isArray", "(", "value", ")", ")", "{", "do", "{", "value", "=", "key", "[", "valuePropertyName", "]", ";", "if", "(", "value", "!==", "undefined", ")", "{", "times", ".", "push", "(", "key", ".", "time", ")", ";", "values", ".", "push", ".", "apply", "(", "values", ",", "value", ")", ";", "// push all elements", "}", "key", "=", "jsonKeys", "[", "i", "++", "]", ";", "}", "while", "(", "key", "!==", "undefined", ")", ";", "}", "else", "if", "(", "value", ".", "toArray", "!==", "undefined", ")", "{", "// ...assume THREE.Math-ish", "do", "{", "value", "=", "key", "[", "valuePropertyName", "]", ";", "if", "(", "value", "!==", "undefined", ")", "{", "times", ".", "push", "(", "key", ".", "time", ")", ";", "value", ".", "toArray", "(", "values", ",", "values", ".", "length", ")", ";", "}", "key", "=", "jsonKeys", "[", "i", "++", "]", ";", "}", "while", "(", "key", "!==", "undefined", ")", ";", "}", "else", "{", "// otherwise push as-is", "do", "{", "value", "=", "key", "[", "valuePropertyName", "]", ";", "if", "(", "value", "!==", "undefined", ")", "{", "times", ".", "push", "(", "key", ".", "time", ")", ";", "values", ".", "push", "(", "value", ")", ";", "}", "key", "=", "jsonKeys", "[", "i", "++", "]", ";", "}", "while", "(", "key", "!==", "undefined", ")", ";", "}", "}" ]
function for parsing AOS keyframe formats
[ "function", "for", "parsing", "AOS", "keyframe", "formats" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L14729-L14799
10,911
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function( timeOffset ) { if( timeOffset !== 0.0 ) { var times = this.times; for( var i = 0, n = times.length; i !== n; ++ i ) { times[ i ] += timeOffset; } } return this; }
javascript
function( timeOffset ) { if( timeOffset !== 0.0 ) { var times = this.times; for( var i = 0, n = times.length; i !== n; ++ i ) { times[ i ] += timeOffset; } } return this; }
[ "function", "(", "timeOffset", ")", "{", "if", "(", "timeOffset", "!==", "0.0", ")", "{", "var", "times", "=", "this", ".", "times", ";", "for", "(", "var", "i", "=", "0", ",", "n", "=", "times", ".", "length", ";", "i", "!==", "n", ";", "++", "i", ")", "{", "times", "[", "i", "]", "+=", "timeOffset", ";", "}", "}", "return", "this", ";", "}" ]
move all keyframes either forwards or backwards in time
[ "move", "all", "keyframes", "either", "forwards", "or", "backwards", "in", "time" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L14949-L14965
10,912
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function() { var binding = this.binding; var buffer = this.buffer, stride = this.valueSize, originalValueOffset = stride * 3; binding.getValue( buffer, originalValueOffset ); // accu[0..1] := orig -- initially detect changes against the original for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) { buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ]; } this.cumulativeWeight = 0; }
javascript
function() { var binding = this.binding; var buffer = this.buffer, stride = this.valueSize, originalValueOffset = stride * 3; binding.getValue( buffer, originalValueOffset ); // accu[0..1] := orig -- initially detect changes against the original for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) { buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ]; } this.cumulativeWeight = 0; }
[ "function", "(", ")", "{", "var", "binding", "=", "this", ".", "binding", ";", "var", "buffer", "=", "this", ".", "buffer", ",", "stride", "=", "this", ".", "valueSize", ",", "originalValueOffset", "=", "stride", "*", "3", ";", "binding", ".", "getValue", "(", "buffer", ",", "originalValueOffset", ")", ";", "// accu[0..1] := orig -- initially detect changes against the original", "for", "(", "var", "i", "=", "stride", ",", "e", "=", "originalValueOffset", ";", "i", "!==", "e", ";", "++", "i", ")", "{", "buffer", "[", "i", "]", "=", "buffer", "[", "originalValueOffset", "+", "(", "i", "%", "stride", ")", "]", ";", "}", "this", ".", "cumulativeWeight", "=", "0", ";", "}" ]
remember the state of the bound property and copy it to both accus
[ "remember", "the", "state", "of", "the", "bound", "property", "and", "copy", "it", "to", "both", "accus" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L16092-L16112
10,913
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function ( focalLength ) { // see http://www.bobatkins.com/photography/technical/field_of_view.html var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength; this.fov = THREE.Math.RAD2DEG * 2 * Math.atan( vExtentSlope ); this.updateProjectionMatrix(); }
javascript
function ( focalLength ) { // see http://www.bobatkins.com/photography/technical/field_of_view.html var vExtentSlope = 0.5 * this.getFilmHeight() / focalLength; this.fov = THREE.Math.RAD2DEG * 2 * Math.atan( vExtentSlope ); this.updateProjectionMatrix(); }
[ "function", "(", "focalLength", ")", "{", "// see http://www.bobatkins.com/photography/technical/field_of_view.html", "var", "vExtentSlope", "=", "0.5", "*", "this", ".", "getFilmHeight", "(", ")", "/", "focalLength", ";", "this", ".", "fov", "=", "THREE", ".", "Math", ".", "RAD2DEG", "*", "2", "*", "Math", ".", "atan", "(", "vExtentSlope", ")", ";", "this", ".", "updateProjectionMatrix", "(", ")", ";", "}" ]
Sets the FOV by focal length in respect to the current .filmGauge. The default film gauge is 35, so that the focal length can be specified for a 35mm (full frame) camera. Values for focal length and film gauge must have the same unit.
[ "Sets", "the", "FOV", "by", "focal", "length", "in", "respect", "to", "the", "current", ".", "filmGauge", "." ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L17279-L17287
10,914
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function ( t, p0, p1, p2, p3 ) { return - 3 * p0 * ( 1 - t ) * ( 1 - t ) + 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) + 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 + 3 * t * t * p3; }
javascript
function ( t, p0, p1, p2, p3 ) { return - 3 * p0 * ( 1 - t ) * ( 1 - t ) + 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) + 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 + 3 * t * t * p3; }
[ "function", "(", "t", ",", "p0", ",", "p1", ",", "p2", ",", "p3", ")", "{", "return", "-", "3", "*", "p0", "*", "(", "1", "-", "t", ")", "*", "(", "1", "-", "t", ")", "+", "3", "*", "p1", "*", "(", "1", "-", "t", ")", "*", "(", "1", "-", "t", ")", "-", "6", "*", "t", "*", "p1", "*", "(", "1", "-", "t", ")", "+", "6", "*", "t", "*", "p2", "*", "(", "1", "-", "t", ")", "-", "3", "*", "t", "*", "t", "*", "p2", "+", "3", "*", "t", "*", "t", "*", "p3", ";", "}" ]
Puay Bing, thanks for helping with this derivative!
[ "Puay", "Bing", "thanks", "for", "helping", "with", "this", "derivative!" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L33808-L33815
10,915
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function ( contour ) { var n = contour.length; var a = 0.0; for ( var p = n - 1, q = 0; q < n; p = q ++ ) { a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y; } return a * 0.5; }
javascript
function ( contour ) { var n = contour.length; var a = 0.0; for ( var p = n - 1, q = 0; q < n; p = q ++ ) { a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y; } return a * 0.5; }
[ "function", "(", "contour", ")", "{", "var", "n", "=", "contour", ".", "length", ";", "var", "a", "=", "0.0", ";", "for", "(", "var", "p", "=", "n", "-", "1", ",", "q", "=", "0", ";", "q", "<", "n", ";", "p", "=", "q", "++", ")", "{", "a", "+=", "contour", "[", "p", "]", ".", "x", "*", "contour", "[", "q", "]", ".", "y", "-", "contour", "[", "q", "]", ".", "x", "*", "contour", "[", "p", "]", ".", "y", ";", "}", "return", "a", "*", "0.5", ";", "}" ]
calculate area of the contour polygon
[ "calculate", "area", "of", "the", "contour", "polygon" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L33897-L33910
10,916
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
function( t ) { var delta = 0.0001; var t1 = t - delta; var t2 = t + delta; // Capping in case of danger if ( t1 < 0 ) t1 = 0; if ( t2 > 1 ) t2 = 1; var pt1 = this.getPoint( t1 ); var pt2 = this.getPoint( t2 ); var vec = pt2.clone().sub( pt1 ); return vec.normalize(); }
javascript
function( t ) { var delta = 0.0001; var t1 = t - delta; var t2 = t + delta; // Capping in case of danger if ( t1 < 0 ) t1 = 0; if ( t2 > 1 ) t2 = 1; var pt1 = this.getPoint( t1 ); var pt2 = this.getPoint( t2 ); var vec = pt2.clone().sub( pt1 ); return vec.normalize(); }
[ "function", "(", "t", ")", "{", "var", "delta", "=", "0.0001", ";", "var", "t1", "=", "t", "-", "delta", ";", "var", "t2", "=", "t", "+", "delta", ";", "// Capping in case of danger", "if", "(", "t1", "<", "0", ")", "t1", "=", "0", ";", "if", "(", "t2", ">", "1", ")", "t2", "=", "1", ";", "var", "pt1", "=", "this", ".", "getPoint", "(", "t1", ")", ";", "var", "pt2", "=", "this", ".", "getPoint", "(", "t2", ")", ";", "var", "vec", "=", "pt2", ".", "clone", "(", ")", ".", "sub", "(", "pt1", ")", ";", "return", "vec", ".", "normalize", "(", ")", ";", "}" ]
Returns a unit vector tangent at t In case any sub curve does not implement its tangent derivation, 2 points a small delta apart will be used to find its gradient which seems to give a reasonable approximation
[ "Returns", "a", "unit", "vector", "tangent", "at", "t", "In", "case", "any", "sub", "curve", "does", "not", "implement", "its", "tangent", "derivation", "2", "points", "a", "small", "delta", "apart", "will", "be", "used", "to", "find", "its", "gradient", "which", "seems", "to", "give", "a", "reasonable", "approximation" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L34881-L34898
10,917
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
calculatePositionOnCurve
function calculatePositionOnCurve( u, p, q, radius, position ) { var cu = Math.cos( u ); var su = Math.sin( u ); var quOverP = q / p * u; var cs = Math.cos( quOverP ); position.x = radius * ( 2 + cs ) * 0.5 * cu; position.y = radius * ( 2 + cs ) * su * 0.5; position.z = radius * Math.sin( quOverP ) * 0.5; }
javascript
function calculatePositionOnCurve( u, p, q, radius, position ) { var cu = Math.cos( u ); var su = Math.sin( u ); var quOverP = q / p * u; var cs = Math.cos( quOverP ); position.x = radius * ( 2 + cs ) * 0.5 * cu; position.y = radius * ( 2 + cs ) * su * 0.5; position.z = radius * Math.sin( quOverP ) * 0.5; }
[ "function", "calculatePositionOnCurve", "(", "u", ",", "p", ",", "q", ",", "radius", ",", "position", ")", "{", "var", "cu", "=", "Math", ".", "cos", "(", "u", ")", ";", "var", "su", "=", "Math", ".", "sin", "(", "u", ")", ";", "var", "quOverP", "=", "q", "/", "p", "*", "u", ";", "var", "cs", "=", "Math", ".", "cos", "(", "quOverP", ")", ";", "position", ".", "x", "=", "radius", "*", "(", "2", "+", "cs", ")", "*", "0.5", "*", "cu", ";", "position", ".", "y", "=", "radius", "*", "(", "2", "+", "cs", ")", "*", "su", "*", "0.5", ";", "position", ".", "z", "=", "radius", "*", "Math", ".", "sin", "(", "quOverP", ")", "*", "0.5", ";", "}" ]
this function calculates the current position on the torus curve
[ "this", "function", "calculates", "the", "current", "position", "on", "the", "torus", "curve" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L39290-L39301
10,918
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
subdivide
function subdivide( face, detail ) { var cols = Math.pow( 2, detail ); var a = prepare( that.vertices[ face.a ] ); var b = prepare( that.vertices[ face.b ] ); var c = prepare( that.vertices[ face.c ] ); var v = []; // Construct all of the vertices for this subdivision. for ( var i = 0 ; i <= cols; i ++ ) { v[ i ] = []; var aj = prepare( a.clone().lerp( c, i / cols ) ); var bj = prepare( b.clone().lerp( c, i / cols ) ); var rows = cols - i; for ( var j = 0; j <= rows; j ++ ) { if ( j === 0 && i === cols ) { v[ i ][ j ] = aj; } else { v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) ); } } } // Construct all of the faces. for ( var i = 0; i < cols ; i ++ ) { for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) { var k = Math.floor( j / 2 ); if ( j % 2 === 0 ) { make( v[ i ][ k + 1 ], v[ i + 1 ][ k ], v[ i ][ k ] ); } else { make( v[ i ][ k + 1 ], v[ i + 1 ][ k + 1 ], v[ i + 1 ][ k ] ); } } } }
javascript
function subdivide( face, detail ) { var cols = Math.pow( 2, detail ); var a = prepare( that.vertices[ face.a ] ); var b = prepare( that.vertices[ face.b ] ); var c = prepare( that.vertices[ face.c ] ); var v = []; // Construct all of the vertices for this subdivision. for ( var i = 0 ; i <= cols; i ++ ) { v[ i ] = []; var aj = prepare( a.clone().lerp( c, i / cols ) ); var bj = prepare( b.clone().lerp( c, i / cols ) ); var rows = cols - i; for ( var j = 0; j <= rows; j ++ ) { if ( j === 0 && i === cols ) { v[ i ][ j ] = aj; } else { v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) ); } } } // Construct all of the faces. for ( var i = 0; i < cols ; i ++ ) { for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) { var k = Math.floor( j / 2 ); if ( j % 2 === 0 ) { make( v[ i ][ k + 1 ], v[ i + 1 ][ k ], v[ i ][ k ] ); } else { make( v[ i ][ k + 1 ], v[ i + 1 ][ k + 1 ], v[ i + 1 ][ k ] ); } } } }
[ "function", "subdivide", "(", "face", ",", "detail", ")", "{", "var", "cols", "=", "Math", ".", "pow", "(", "2", ",", "detail", ")", ";", "var", "a", "=", "prepare", "(", "that", ".", "vertices", "[", "face", ".", "a", "]", ")", ";", "var", "b", "=", "prepare", "(", "that", ".", "vertices", "[", "face", ".", "b", "]", ")", ";", "var", "c", "=", "prepare", "(", "that", ".", "vertices", "[", "face", ".", "c", "]", ")", ";", "var", "v", "=", "[", "]", ";", "// Construct all of the vertices for this subdivision.", "for", "(", "var", "i", "=", "0", ";", "i", "<=", "cols", ";", "i", "++", ")", "{", "v", "[", "i", "]", "=", "[", "]", ";", "var", "aj", "=", "prepare", "(", "a", ".", "clone", "(", ")", ".", "lerp", "(", "c", ",", "i", "/", "cols", ")", ")", ";", "var", "bj", "=", "prepare", "(", "b", ".", "clone", "(", ")", ".", "lerp", "(", "c", ",", "i", "/", "cols", ")", ")", ";", "var", "rows", "=", "cols", "-", "i", ";", "for", "(", "var", "j", "=", "0", ";", "j", "<=", "rows", ";", "j", "++", ")", "{", "if", "(", "j", "===", "0", "&&", "i", "===", "cols", ")", "{", "v", "[", "i", "]", "[", "j", "]", "=", "aj", ";", "}", "else", "{", "v", "[", "i", "]", "[", "j", "]", "=", "prepare", "(", "aj", ".", "clone", "(", ")", ".", "lerp", "(", "bj", ",", "j", "/", "rows", ")", ")", ";", "}", "}", "}", "// Construct all of the faces.", "for", "(", "var", "i", "=", "0", ";", "i", "<", "cols", ";", "i", "++", ")", "{", "for", "(", "var", "j", "=", "0", ";", "j", "<", "2", "*", "(", "cols", "-", "i", ")", "-", "1", ";", "j", "++", ")", "{", "var", "k", "=", "Math", ".", "floor", "(", "j", "/", "2", ")", ";", "if", "(", "j", "%", "2", "===", "0", ")", "{", "make", "(", "v", "[", "i", "]", "[", "k", "+", "1", "]", ",", "v", "[", "i", "+", "1", "]", "[", "k", "]", ",", "v", "[", "i", "]", "[", "k", "]", ")", ";", "}", "else", "{", "make", "(", "v", "[", "i", "]", "[", "k", "+", "1", "]", ",", "v", "[", "i", "+", "1", "]", "[", "k", "+", "1", "]", ",", "v", "[", "i", "+", "1", "]", "[", "k", "]", ")", ";", "}", "}", "}", "}" ]
Analytically subdivide a face to the required detail level.
[ "Analytically", "subdivide", "a", "face", "to", "the", "required", "detail", "level", "." ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L39786-L39850
10,919
AlloyTeam/AlloyTouch
example/threejs/asset/three.js
inclination
function inclination( vector ) { return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) ); }
javascript
function inclination( vector ) { return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) ); }
[ "function", "inclination", "(", "vector", ")", "{", "return", "Math", ".", "atan2", "(", "-", "vector", ".", "y", ",", "Math", ".", "sqrt", "(", "(", "vector", ".", "x", "*", "vector", ".", "x", ")", "+", "(", "vector", ".", "z", "*", "vector", ".", "z", ")", ")", ")", ";", "}" ]
Angle above the XZ plane.
[ "Angle", "above", "the", "XZ", "plane", "." ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/example/threejs/asset/three.js#L39864-L39868
10,920
AlloyTeam/AlloyTouch
select/index.js
_mergeListInfo
function _mergeListInfo(list) { var arr = []; var info = {}; for(var i=0,len=list.length; i<len; i++) { arr.push('<li data-value="'+list[i].value+'">' + list[i].name + '</li>'); info[i] = list[i].list ? _mergeListInfo(list[i].list) : {length: 0}; } info.length = i; info.content = arr.join(''); return info; }
javascript
function _mergeListInfo(list) { var arr = []; var info = {}; for(var i=0,len=list.length; i<len; i++) { arr.push('<li data-value="'+list[i].value+'">' + list[i].name + '</li>'); info[i] = list[i].list ? _mergeListInfo(list[i].list) : {length: 0}; } info.length = i; info.content = arr.join(''); return info; }
[ "function", "_mergeListInfo", "(", "list", ")", "{", "var", "arr", "=", "[", "]", ";", "var", "info", "=", "{", "}", ";", "for", "(", "var", "i", "=", "0", ",", "len", "=", "list", ".", "length", ";", "i", "<", "len", ";", "i", "++", ")", "{", "arr", ".", "push", "(", "'<li data-value=\"'", "+", "list", "[", "i", "]", ".", "value", "+", "'\">'", "+", "list", "[", "i", "]", ".", "name", "+", "'</li>'", ")", ";", "info", "[", "i", "]", "=", "list", "[", "i", "]", ".", "list", "?", "_mergeListInfo", "(", "list", "[", "i", "]", ".", "list", ")", ":", "{", "length", ":", "0", "}", ";", "}", "info", ".", "length", "=", "i", ";", "info", ".", "content", "=", "arr", ".", "join", "(", "''", ")", ";", "return", "info", ";", "}" ]
merge options list
[ "merge", "options", "list" ]
4f93a9232a817bd2bfdcc67b46748dc423a2f3ed
https://github.com/AlloyTeam/AlloyTouch/blob/4f93a9232a817bd2bfdcc67b46748dc423a2f3ed/select/index.js#L31-L43
10,921
socketio/socket.io-redis
index.js
Redis
function Redis(nsp){ Adapter.call(this, nsp); this.uid = uid; this.prefix = prefix; this.requestsTimeout = requestsTimeout; this.channel = prefix + '#' + nsp.name + '#'; this.requestChannel = prefix + '-request#' + this.nsp.name + '#'; this.responseChannel = prefix + '-response#' + this.nsp.name + '#'; this.requests = {}; this.customHook = function(data, cb){ cb(null); } if (String.prototype.startsWith) { this.channelMatches = function (messageChannel, subscribedChannel) { return messageChannel.startsWith(subscribedChannel); } } else { // Fallback to other impl for older Node.js this.channelMatches = function (messageChannel, subscribedChannel) { return messageChannel.substr(0, subscribedChannel.length) === subscribedChannel; } } this.pubClient = pub; this.subClient = sub; var self = this; sub.psubscribe(this.channel + '*', function(err){ if (err) self.emit('error', err); }); sub.on('pmessageBuffer', this.onmessage.bind(this)); sub.subscribe([this.requestChannel, this.responseChannel], function(err){ if (err) self.emit('error', err); }); sub.on('messageBuffer', this.onrequest.bind(this)); function onError(err) { self.emit('error', err); } pub.on('error', onError); sub.on('error', onError); }
javascript
function Redis(nsp){ Adapter.call(this, nsp); this.uid = uid; this.prefix = prefix; this.requestsTimeout = requestsTimeout; this.channel = prefix + '#' + nsp.name + '#'; this.requestChannel = prefix + '-request#' + this.nsp.name + '#'; this.responseChannel = prefix + '-response#' + this.nsp.name + '#'; this.requests = {}; this.customHook = function(data, cb){ cb(null); } if (String.prototype.startsWith) { this.channelMatches = function (messageChannel, subscribedChannel) { return messageChannel.startsWith(subscribedChannel); } } else { // Fallback to other impl for older Node.js this.channelMatches = function (messageChannel, subscribedChannel) { return messageChannel.substr(0, subscribedChannel.length) === subscribedChannel; } } this.pubClient = pub; this.subClient = sub; var self = this; sub.psubscribe(this.channel + '*', function(err){ if (err) self.emit('error', err); }); sub.on('pmessageBuffer', this.onmessage.bind(this)); sub.subscribe([this.requestChannel, this.responseChannel], function(err){ if (err) self.emit('error', err); }); sub.on('messageBuffer', this.onrequest.bind(this)); function onError(err) { self.emit('error', err); } pub.on('error', onError); sub.on('error', onError); }
[ "function", "Redis", "(", "nsp", ")", "{", "Adapter", ".", "call", "(", "this", ",", "nsp", ")", ";", "this", ".", "uid", "=", "uid", ";", "this", ".", "prefix", "=", "prefix", ";", "this", ".", "requestsTimeout", "=", "requestsTimeout", ";", "this", ".", "channel", "=", "prefix", "+", "'#'", "+", "nsp", ".", "name", "+", "'#'", ";", "this", ".", "requestChannel", "=", "prefix", "+", "'-request#'", "+", "this", ".", "nsp", ".", "name", "+", "'#'", ";", "this", ".", "responseChannel", "=", "prefix", "+", "'-response#'", "+", "this", ".", "nsp", ".", "name", "+", "'#'", ";", "this", ".", "requests", "=", "{", "}", ";", "this", ".", "customHook", "=", "function", "(", "data", ",", "cb", ")", "{", "cb", "(", "null", ")", ";", "}", "if", "(", "String", ".", "prototype", ".", "startsWith", ")", "{", "this", ".", "channelMatches", "=", "function", "(", "messageChannel", ",", "subscribedChannel", ")", "{", "return", "messageChannel", ".", "startsWith", "(", "subscribedChannel", ")", ";", "}", "}", "else", "{", "// Fallback to other impl for older Node.js", "this", ".", "channelMatches", "=", "function", "(", "messageChannel", ",", "subscribedChannel", ")", "{", "return", "messageChannel", ".", "substr", "(", "0", ",", "subscribedChannel", ".", "length", ")", "===", "subscribedChannel", ";", "}", "}", "this", ".", "pubClient", "=", "pub", ";", "this", ".", "subClient", "=", "sub", ";", "var", "self", "=", "this", ";", "sub", ".", "psubscribe", "(", "this", ".", "channel", "+", "'*'", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "self", ".", "emit", "(", "'error'", ",", "err", ")", ";", "}", ")", ";", "sub", ".", "on", "(", "'pmessageBuffer'", ",", "this", ".", "onmessage", ".", "bind", "(", "this", ")", ")", ";", "sub", ".", "subscribe", "(", "[", "this", ".", "requestChannel", ",", "this", ".", "responseChannel", "]", ",", "function", "(", "err", ")", "{", "if", "(", "err", ")", "self", ".", "emit", "(", "'error'", ",", "err", ")", ";", "}", ")", ";", "sub", ".", "on", "(", "'messageBuffer'", ",", "this", ".", "onrequest", ".", "bind", "(", "this", ")", ")", ";", "function", "onError", "(", "err", ")", "{", "self", ".", "emit", "(", "'error'", ",", "err", ")", ";", "}", "pub", ".", "on", "(", "'error'", ",", "onError", ")", ";", "sub", ".", "on", "(", "'error'", ",", "onError", ")", ";", "}" ]
Adapter constructor. @param {String} namespace name @api public
[ "Adapter", "constructor", "." ]
a1cebc8649584fa08eb1e0b933f9eca980d23ea5
https://github.com/socketio/socket.io-redis/blob/a1cebc8649584fa08eb1e0b933f9eca980d23ea5/index.js#L78-L122
10,922
casperjs/casperjs
modules/colorizer.js
Dummy
function Dummy() { "use strict"; this.colorize = function colorize(text, styleName, pad) { return text; }; this.format = function format(text, style, pad){ return text; }; }
javascript
function Dummy() { "use strict"; this.colorize = function colorize(text, styleName, pad) { return text; }; this.format = function format(text, style, pad){ return text; }; }
[ "function", "Dummy", "(", ")", "{", "\"use strict\"", ";", "this", ".", "colorize", "=", "function", "colorize", "(", "text", ",", "styleName", ",", "pad", ")", "{", "return", "text", ";", "}", ";", "this", ".", "format", "=", "function", "format", "(", "text", ",", "style", ",", "pad", ")", "{", "return", "text", ";", "}", ";", "}" ]
Dummy colorizer. Does basically nothing.
[ "Dummy", "colorizer", ".", "Does", "basically", "nothing", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/colorizer.js#L126-L134
10,923
casperjs/casperjs
modules/xunit.js
generateClassName
function generateClassName(classname) { "use strict"; classname = (classname || "").replace(phantom.casperPath, "").trim(); var script = classname || phantom.casperScript || ""; if (script.indexOf(fs.workingDirectory) === 0) { script = script.substring(fs.workingDirectory.length + 1); } if (script.indexOf('/') === 0) { script = script.substring(1, script.length); } if (~script.indexOf('.')) { script = script.substring(0, script.lastIndexOf('.')); } // If we have trimmed our string down to nothing, default to script name if (!script && phantom.casperScript) { script = phantom.casperScript; } return script || "unknown"; }
javascript
function generateClassName(classname) { "use strict"; classname = (classname || "").replace(phantom.casperPath, "").trim(); var script = classname || phantom.casperScript || ""; if (script.indexOf(fs.workingDirectory) === 0) { script = script.substring(fs.workingDirectory.length + 1); } if (script.indexOf('/') === 0) { script = script.substring(1, script.length); } if (~script.indexOf('.')) { script = script.substring(0, script.lastIndexOf('.')); } // If we have trimmed our string down to nothing, default to script name if (!script && phantom.casperScript) { script = phantom.casperScript; } return script || "unknown"; }
[ "function", "generateClassName", "(", "classname", ")", "{", "\"use strict\"", ";", "classname", "=", "(", "classname", "||", "\"\"", ")", ".", "replace", "(", "phantom", ".", "casperPath", ",", "\"\"", ")", ".", "trim", "(", ")", ";", "var", "script", "=", "classname", "||", "phantom", ".", "casperScript", "||", "\"\"", ";", "if", "(", "script", ".", "indexOf", "(", "fs", ".", "workingDirectory", ")", "===", "0", ")", "{", "script", "=", "script", ".", "substring", "(", "fs", ".", "workingDirectory", ".", "length", "+", "1", ")", ";", "}", "if", "(", "script", ".", "indexOf", "(", "'/'", ")", "===", "0", ")", "{", "script", "=", "script", ".", "substring", "(", "1", ",", "script", ".", "length", ")", ";", "}", "if", "(", "~", "script", ".", "indexOf", "(", "'.'", ")", ")", "{", "script", "=", "script", ".", "substring", "(", "0", ",", "script", ".", "lastIndexOf", "(", "'.'", ")", ")", ";", "}", "// If we have trimmed our string down to nothing, default to script name", "if", "(", "!", "script", "&&", "phantom", ".", "casperScript", ")", "{", "script", "=", "phantom", ".", "casperScript", ";", "}", "return", "script", "||", "\"unknown\"", ";", "}" ]
Generates a value for 'classname' attribute of the JUnit XML report. Uses the (relative) file name of the current casper script without file extension as classname. @param String classname @return String
[ "Generates", "a", "value", "for", "classname", "attribute", "of", "the", "JUnit", "XML", "report", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/xunit.js#L47-L65
10,924
casperjs/casperjs
bin/bootstrap.js
printHelp
function printHelp() { /* global slimer */ var engine = phantom.casperEngine === 'slimerjs' ? slimer : phantom; var version = [engine.version.major, engine.version.minor, engine.version.patch].join('.'); return __terminate([ 'CasperJS version ' + phantom.casperVersion.toString() + ' at ' + phantom.casperPath + ', using ' + phantom.casperEngine + ' version ' + version, fs.read(fs.pathJoin(phantom.casperPath, 'bin', 'usage.txt')) ].join('\n')); }
javascript
function printHelp() { /* global slimer */ var engine = phantom.casperEngine === 'slimerjs' ? slimer : phantom; var version = [engine.version.major, engine.version.minor, engine.version.patch].join('.'); return __terminate([ 'CasperJS version ' + phantom.casperVersion.toString() + ' at ' + phantom.casperPath + ', using ' + phantom.casperEngine + ' version ' + version, fs.read(fs.pathJoin(phantom.casperPath, 'bin', 'usage.txt')) ].join('\n')); }
[ "function", "printHelp", "(", ")", "{", "/* global slimer */", "var", "engine", "=", "phantom", ".", "casperEngine", "===", "'slimerjs'", "?", "slimer", ":", "phantom", ";", "var", "version", "=", "[", "engine", ".", "version", ".", "major", ",", "engine", ".", "version", ".", "minor", ",", "engine", ".", "version", ".", "patch", "]", ".", "join", "(", "'.'", ")", ";", "return", "__terminate", "(", "[", "'CasperJS version '", "+", "phantom", ".", "casperVersion", ".", "toString", "(", ")", "+", "' at '", "+", "phantom", ".", "casperPath", "+", "', using '", "+", "phantom", ".", "casperEngine", "+", "' version '", "+", "version", ",", "fs", ".", "read", "(", "fs", ".", "pathJoin", "(", "phantom", ".", "casperPath", ",", "'bin'", ",", "'usage.txt'", ")", ")", "]", ".", "join", "(", "'\\n'", ")", ")", ";", "}" ]
Prints CasperJS help.
[ "Prints", "CasperJS", "help", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/bin/bootstrap.js#L213-L222
10,925
casperjs/casperjs
samples/dynamic.js
check
function check() { if (links[currentLink] && currentLink < upTo) { this.echo('--- Link ' + currentLink + ' ---'); start.call(this, links[currentLink]); addLinks.call(this, links[currentLink]); currentLink++; this.run(check); } else { this.echo("All done."); this.exit(); } }
javascript
function check() { if (links[currentLink] && currentLink < upTo) { this.echo('--- Link ' + currentLink + ' ---'); start.call(this, links[currentLink]); addLinks.call(this, links[currentLink]); currentLink++; this.run(check); } else { this.echo("All done."); this.exit(); } }
[ "function", "check", "(", ")", "{", "if", "(", "links", "[", "currentLink", "]", "&&", "currentLink", "<", "upTo", ")", "{", "this", ".", "echo", "(", "'--- Link '", "+", "currentLink", "+", "' ---'", ")", ";", "start", ".", "call", "(", "this", ",", "links", "[", "currentLink", "]", ")", ";", "addLinks", ".", "call", "(", "this", ",", "links", "[", "currentLink", "]", ")", ";", "currentLink", "++", ";", "this", ".", "run", "(", "check", ")", ";", "}", "else", "{", "this", ".", "echo", "(", "\"All done.\"", ")", ";", "this", ".", "exit", "(", ")", ";", "}", "}" ]
As long as it has a next link, and is under the maximum limit, will keep running
[ "As", "long", "as", "it", "has", "a", "next", "link", "and", "is", "under", "the", "maximum", "limit", "will", "keep", "running" ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/samples/dynamic.js#L51-L62
10,926
casperjs/casperjs
modules/cli.js
castArgument
function castArgument(arg) { "use strict"; if (arg.match(/^-?\d+$/)) { return parseInt(arg, 10); } else if (arg.match(/^-?\d+\.\d+$/)) { return parseFloat(arg); } else if (arg.match(/^(true|false)$/i)) { return arg.trim().toLowerCase() === "true" ? true : false; } else { return arg; } }
javascript
function castArgument(arg) { "use strict"; if (arg.match(/^-?\d+$/)) { return parseInt(arg, 10); } else if (arg.match(/^-?\d+\.\d+$/)) { return parseFloat(arg); } else if (arg.match(/^(true|false)$/i)) { return arg.trim().toLowerCase() === "true" ? true : false; } else { return arg; } }
[ "function", "castArgument", "(", "arg", ")", "{", "\"use strict\"", ";", "if", "(", "arg", ".", "match", "(", "/", "^-?\\d+$", "/", ")", ")", "{", "return", "parseInt", "(", "arg", ",", "10", ")", ";", "}", "else", "if", "(", "arg", ".", "match", "(", "/", "^-?\\d+\\.\\d+$", "/", ")", ")", "{", "return", "parseFloat", "(", "arg", ")", ";", "}", "else", "if", "(", "arg", ".", "match", "(", "/", "^(true|false)$", "/", "i", ")", ")", "{", "return", "arg", ".", "trim", "(", ")", ".", "toLowerCase", "(", ")", "===", "\"true\"", "?", "true", ":", "false", ";", "}", "else", "{", "return", "arg", ";", "}", "}" ]
Cast a string argument to its typed equivalent. @param String arg @return Mixed
[ "Cast", "a", "string", "argument", "to", "its", "typed", "equivalent", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/cli.js#L138-L149
10,927
casperjs/casperjs
modules/utils.js
betterTypeOf
function betterTypeOf(input) { "use strict"; switch (input) { case undefined: return 'undefined'; case null: return 'null'; default: try { var type = Object.prototype.toString.call(input).match(/^\[object\s(.*)\]$/)[1].toLowerCase(); if (type === 'object' && phantom.casperEngine !== "phantomjs" && '__type' in input) { type = input.__type; } // gecko returns window instead of domwindow else if (type === 'window') { return 'domwindow'; } return type; } catch (e) { return typeof input; } } }
javascript
function betterTypeOf(input) { "use strict"; switch (input) { case undefined: return 'undefined'; case null: return 'null'; default: try { var type = Object.prototype.toString.call(input).match(/^\[object\s(.*)\]$/)[1].toLowerCase(); if (type === 'object' && phantom.casperEngine !== "phantomjs" && '__type' in input) { type = input.__type; } // gecko returns window instead of domwindow else if (type === 'window') { return 'domwindow'; } return type; } catch (e) { return typeof input; } } }
[ "function", "betterTypeOf", "(", "input", ")", "{", "\"use strict\"", ";", "switch", "(", "input", ")", "{", "case", "undefined", ":", "return", "'undefined'", ";", "case", "null", ":", "return", "'null'", ";", "default", ":", "try", "{", "var", "type", "=", "Object", ".", "prototype", ".", "toString", ".", "call", "(", "input", ")", ".", "match", "(", "/", "^\\[object\\s(.*)\\]$", "/", ")", "[", "1", "]", ".", "toLowerCase", "(", ")", ";", "if", "(", "type", "===", "'object'", "&&", "phantom", ".", "casperEngine", "!==", "\"phantomjs\"", "&&", "'__type'", "in", "input", ")", "{", "type", "=", "input", ".", "__type", ";", "}", "// gecko returns window instead of domwindow", "else", "if", "(", "type", "===", "'window'", ")", "{", "return", "'domwindow'", ";", "}", "return", "type", ";", "}", "catch", "(", "e", ")", "{", "return", "typeof", "input", ";", "}", "}", "}" ]
Provides a better typeof operator equivalent, able to retrieve the array type. CAVEAT: this function does not necessarilly map to classical js "type" names, notably a `null` will map to "null" instead of "object". @param mixed input @return String @see http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/
[ "Provides", "a", "better", "typeof", "operator", "equivalent", "able", "to", "retrieve", "the", "array", "type", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L45-L69
10,928
casperjs/casperjs
modules/utils.js
betterInstanceOf
function betterInstanceOf(input, constructor) { "use strict"; /*eslint eqeqeq:0 */ if (typeof input == 'undefined' || input == null) { return false; } var inputToTest = input; while (inputToTest != null) { if (inputToTest == constructor.prototype) { return true; } if (typeof inputToTest == 'xml') { return constructor.prototype == document.prototype; } if (typeof inputToTest == 'undefined') { return false; } inputToTest = inputToTest.__proto__; } return equals(input.constructor.name, constructor.name); }
javascript
function betterInstanceOf(input, constructor) { "use strict"; /*eslint eqeqeq:0 */ if (typeof input == 'undefined' || input == null) { return false; } var inputToTest = input; while (inputToTest != null) { if (inputToTest == constructor.prototype) { return true; } if (typeof inputToTest == 'xml') { return constructor.prototype == document.prototype; } if (typeof inputToTest == 'undefined') { return false; } inputToTest = inputToTest.__proto__; } return equals(input.constructor.name, constructor.name); }
[ "function", "betterInstanceOf", "(", "input", ",", "constructor", ")", "{", "\"use strict\"", ";", "/*eslint eqeqeq:0 */", "if", "(", "typeof", "input", "==", "'undefined'", "||", "input", "==", "null", ")", "{", "return", "false", ";", "}", "var", "inputToTest", "=", "input", ";", "while", "(", "inputToTest", "!=", "null", ")", "{", "if", "(", "inputToTest", "==", "constructor", ".", "prototype", ")", "{", "return", "true", ";", "}", "if", "(", "typeof", "inputToTest", "==", "'xml'", ")", "{", "return", "constructor", ".", "prototype", "==", "document", ".", "prototype", ";", "}", "if", "(", "typeof", "inputToTest", "==", "'undefined'", ")", "{", "return", "false", ";", "}", "inputToTest", "=", "inputToTest", ".", "__proto__", ";", "}", "return", "equals", "(", "input", ".", "constructor", ".", "name", ",", "constructor", ".", "name", ")", ";", "}" ]
Provides a better instanceof operator, capable of checking against the full object prototype hierarchy. @param mixed input @param function constructor @return String @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Details_of_the_Object_Model
[ "Provides", "a", "better", "instanceof", "operator", "capable", "of", "checking", "against", "the", "full", "object", "prototype", "hierarchy", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L80-L100
10,929
casperjs/casperjs
modules/utils.js
cleanUrl
function cleanUrl(url) { "use strict"; if (url.toLowerCase().indexOf('http') !== 0) { return url; } var a = document.createElement('a'); a.href = url; return a.href; }
javascript
function cleanUrl(url) { "use strict"; if (url.toLowerCase().indexOf('http') !== 0) { return url; } var a = document.createElement('a'); a.href = url; return a.href; }
[ "function", "cleanUrl", "(", "url", ")", "{", "\"use strict\"", ";", "if", "(", "url", ".", "toLowerCase", "(", ")", ".", "indexOf", "(", "'http'", ")", "!==", "0", ")", "{", "return", "url", ";", "}", "var", "a", "=", "document", ".", "createElement", "(", "'a'", ")", ";", "a", ".", "href", "=", "url", ";", "return", "a", ".", "href", ";", "}" ]
Cleans a passed URL. @param String url An HTTP URL @return String
[ "Cleans", "a", "passed", "URL", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L109-L117
10,930
casperjs/casperjs
modules/utils.js
computeModifier
function computeModifier(modifierString, modifiers) { "use strict"; var modifier = 0, checkKey = function(key) { if (key in modifiers) return; throw new CasperError(format('%s is not a supported key modifier', key)); }; if (!modifierString) return modifier; var keys = modifierString.split('+'); keys.forEach(checkKey); return keys.reduce(function(acc, key) { return acc | modifiers[key]; }, modifier); }
javascript
function computeModifier(modifierString, modifiers) { "use strict"; var modifier = 0, checkKey = function(key) { if (key in modifiers) return; throw new CasperError(format('%s is not a supported key modifier', key)); }; if (!modifierString) return modifier; var keys = modifierString.split('+'); keys.forEach(checkKey); return keys.reduce(function(acc, key) { return acc | modifiers[key]; }, modifier); }
[ "function", "computeModifier", "(", "modifierString", ",", "modifiers", ")", "{", "\"use strict\"", ";", "var", "modifier", "=", "0", ",", "checkKey", "=", "function", "(", "key", ")", "{", "if", "(", "key", "in", "modifiers", ")", "return", ";", "throw", "new", "CasperError", "(", "format", "(", "'%s is not a supported key modifier'", ",", "key", ")", ")", ";", "}", ";", "if", "(", "!", "modifierString", ")", "return", "modifier", ";", "var", "keys", "=", "modifierString", ".", "split", "(", "'+'", ")", ";", "keys", ".", "forEach", "(", "checkKey", ")", ";", "return", "keys", ".", "reduce", "(", "function", "(", "acc", ",", "key", ")", "{", "return", "acc", "|", "modifiers", "[", "key", "]", ";", "}", ",", "modifier", ")", ";", "}" ]
Computes a modifier string to its PhantomJS equivalent. A modifier string is in the form "ctrl+alt+shift". @param String modifierString Modifier string, eg. "ctrl+alt+shift" @param Object modifiers Modifiers definitions @return Number
[ "Computes", "a", "modifier", "string", "to", "its", "PhantomJS", "equivalent", ".", "A", "modifier", "string", "is", "in", "the", "form", "ctrl", "+", "alt", "+", "shift", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L140-L153
10,931
casperjs/casperjs
modules/utils.js
equals
function equals(v1, v2) { "use strict"; if (isFunction(v1)) { return v1.toString() === v2.toString(); } // with Gecko, instanceof is not enough to test object if (v1 instanceof Object || isObject(v1)) { if (!(v2 instanceof Object || isObject(v2)) || Object.keys(v1).length !== Object.keys(v2).length) { return false; } for (var k in v1) { if (!equals(v1[k], v2[k])) { return false; } } return true; } return v1 === v2; }
javascript
function equals(v1, v2) { "use strict"; if (isFunction(v1)) { return v1.toString() === v2.toString(); } // with Gecko, instanceof is not enough to test object if (v1 instanceof Object || isObject(v1)) { if (!(v2 instanceof Object || isObject(v2)) || Object.keys(v1).length !== Object.keys(v2).length) { return false; } for (var k in v1) { if (!equals(v1[k], v2[k])) { return false; } } return true; } return v1 === v2; }
[ "function", "equals", "(", "v1", ",", "v2", ")", "{", "\"use strict\"", ";", "if", "(", "isFunction", "(", "v1", ")", ")", "{", "return", "v1", ".", "toString", "(", ")", "===", "v2", ".", "toString", "(", ")", ";", "}", "// with Gecko, instanceof is not enough to test object", "if", "(", "v1", "instanceof", "Object", "||", "isObject", "(", "v1", ")", ")", "{", "if", "(", "!", "(", "v2", "instanceof", "Object", "||", "isObject", "(", "v2", ")", ")", "||", "Object", ".", "keys", "(", "v1", ")", ".", "length", "!==", "Object", ".", "keys", "(", "v2", ")", ".", "length", ")", "{", "return", "false", ";", "}", "for", "(", "var", "k", "in", "v1", ")", "{", "if", "(", "!", "equals", "(", "v1", "[", "k", "]", ",", "v2", "[", "k", "]", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", "return", "v1", "===", "v2", ";", "}" ]
Tests equality between the two passed arguments. @param Mixed v1 @param Mixed v2 @param Boolean
[ "Tests", "equality", "between", "the", "two", "passed", "arguments", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L191-L210
10,932
casperjs/casperjs
modules/utils.js
fillBlanks
function fillBlanks(text, pad) { "use strict"; pad = pad || 80; if (text.length < pad) { text += new Array(pad - text.length + 1).join(' '); } return text; }
javascript
function fillBlanks(text, pad) { "use strict"; pad = pad || 80; if (text.length < pad) { text += new Array(pad - text.length + 1).join(' '); } return text; }
[ "function", "fillBlanks", "(", "text", ",", "pad", ")", "{", "\"use strict\"", ";", "pad", "=", "pad", "||", "80", ";", "if", "(", "text", ".", "length", "<", "pad", ")", "{", "text", "+=", "new", "Array", "(", "pad", "-", "text", ".", "length", "+", "1", ")", ".", "join", "(", "' '", ")", ";", "}", "return", "text", ";", "}" ]
Takes a string and append blanks until the pad value is reached. @param String text @param Number pad Pad value (optional; default: 80) @return String
[ "Takes", "a", "string", "and", "append", "blanks", "until", "the", "pad", "value", "is", "reached", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L236-L243
10,933
casperjs/casperjs
modules/utils.js
getPropertyPath
function getPropertyPath(obj, path) { "use strict"; if (!isObject(obj) || !isString(path)) { return undefined; } var value = obj; path.split('.').forEach(function(property) { if (typeof value === "object" && property in value) { value = value[property]; } else { value = undefined; } }); return value; }
javascript
function getPropertyPath(obj, path) { "use strict"; if (!isObject(obj) || !isString(path)) { return undefined; } var value = obj; path.split('.').forEach(function(property) { if (typeof value === "object" && property in value) { value = value[property]; } else { value = undefined; } }); return value; }
[ "function", "getPropertyPath", "(", "obj", ",", "path", ")", "{", "\"use strict\"", ";", "if", "(", "!", "isObject", "(", "obj", ")", "||", "!", "isString", "(", "path", ")", ")", "{", "return", "undefined", ";", "}", "var", "value", "=", "obj", ";", "path", ".", "split", "(", "'.'", ")", ".", "forEach", "(", "function", "(", "property", ")", "{", "if", "(", "typeof", "value", "===", "\"object\"", "&&", "property", "in", "value", ")", "{", "value", "=", "value", "[", "property", "]", ";", "}", "else", "{", "value", "=", "undefined", ";", "}", "}", ")", ";", "return", "value", ";", "}" ]
Retrieves the value of an Object foreign property using a dot-separated path string. Beware, this function doesn't handle object key names containing a dot. @param Object obj The source object @param String path Dot separated path, eg. "x.y.z"
[ "Retrieves", "the", "value", "of", "an", "Object", "foreign", "property", "using", "a", "dot", "-", "separated", "path", "string", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L328-L342
10,934
casperjs/casperjs
modules/utils.js
indent
function indent(string, nchars, prefix) { "use strict"; return string.split('\n').map(function(line) { return (prefix || '') + new Array(nchars).join(' ') + line; }).join('\n'); }
javascript
function indent(string, nchars, prefix) { "use strict"; return string.split('\n').map(function(line) { return (prefix || '') + new Array(nchars).join(' ') + line; }).join('\n'); }
[ "function", "indent", "(", "string", ",", "nchars", ",", "prefix", ")", "{", "\"use strict\"", ";", "return", "string", ".", "split", "(", "'\\n'", ")", ".", "map", "(", "function", "(", "line", ")", "{", "return", "(", "prefix", "||", "''", ")", "+", "new", "Array", "(", "nchars", ")", ".", "join", "(", "' '", ")", "+", "line", ";", "}", ")", ".", "join", "(", "'\\n'", ")", ";", "}" ]
Indents a string. @param String string @param Number nchars @param String prefix @return String
[ "Indents", "a", "string", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L353-L358
10,935
casperjs/casperjs
modules/utils.js
isClipRect
function isClipRect(value) { "use strict"; return isType(value, "cliprect") || ( isObject(value) && isNumber(value.top) && isNumber(value.left) && isNumber(value.width) && isNumber(value.height) ); }
javascript
function isClipRect(value) { "use strict"; return isType(value, "cliprect") || ( isObject(value) && isNumber(value.top) && isNumber(value.left) && isNumber(value.width) && isNumber(value.height) ); }
[ "function", "isClipRect", "(", "value", ")", "{", "\"use strict\"", ";", "return", "isType", "(", "value", ",", "\"cliprect\"", ")", "||", "(", "isObject", "(", "value", ")", "&&", "isNumber", "(", "value", ".", "top", ")", "&&", "isNumber", "(", "value", ".", "left", ")", "&&", "isNumber", "(", "value", ".", "width", ")", "&&", "isNumber", "(", "value", ".", "height", ")", ")", ";", "}" ]
Checks if value is a phantomjs clipRect-compatible object @param mixed value @return Boolean
[ "Checks", "if", "value", "is", "a", "phantomjs", "clipRect", "-", "compatible", "object" ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L412-L419
10,936
casperjs/casperjs
modules/utils.js
isType
function isType(what, typeName) { "use strict"; if (typeof typeName !== "string" || !typeName) { throw new CasperError("You must pass isType() a typeName string"); } return betterTypeOf(what).toLowerCase() === typeName.toLowerCase(); }
javascript
function isType(what, typeName) { "use strict"; if (typeof typeName !== "string" || !typeName) { throw new CasperError("You must pass isType() a typeName string"); } return betterTypeOf(what).toLowerCase() === typeName.toLowerCase(); }
[ "function", "isType", "(", "what", ",", "typeName", ")", "{", "\"use strict\"", ";", "if", "(", "typeof", "typeName", "!==", "\"string\"", "||", "!", "typeName", ")", "{", "throw", "new", "CasperError", "(", "\"You must pass isType() a typeName string\"", ")", ";", "}", "return", "betterTypeOf", "(", "what", ")", ".", "toLowerCase", "(", ")", "===", "typeName", ".", "toLowerCase", "(", ")", ";", "}" ]
Shorthands for checking if a value is of the given type. Can check for arrays. @param mixed what The value to check @param String typeName The type name ("string", "number", "function", etc.) @return Boolean
[ "Shorthands", "for", "checking", "if", "a", "value", "is", "of", "the", "given", "type", ".", "Can", "check", "for", "arrays", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L557-L563
10,937
casperjs/casperjs
modules/utils.js
isValidSelector
function isValidSelector(value) { "use strict"; if (isString(value)) { try { // phantomjs env has a working document object, let's use it document.querySelector(value); } catch(e) { if ('name' in e && (e.name === 'SYNTAX_ERR' || e.name === 'SyntaxError')) { return false; } } return true; } else if (isObject(value)) { if (!value.hasOwnProperty('type')) { return false; } if (!value.hasOwnProperty('path')) { return false; } if (['css', 'xpath'].indexOf(value.type) === -1) { return false; } return true; } return false; }
javascript
function isValidSelector(value) { "use strict"; if (isString(value)) { try { // phantomjs env has a working document object, let's use it document.querySelector(value); } catch(e) { if ('name' in e && (e.name === 'SYNTAX_ERR' || e.name === 'SyntaxError')) { return false; } } return true; } else if (isObject(value)) { if (!value.hasOwnProperty('type')) { return false; } if (!value.hasOwnProperty('path')) { return false; } if (['css', 'xpath'].indexOf(value.type) === -1) { return false; } return true; } return false; }
[ "function", "isValidSelector", "(", "value", ")", "{", "\"use strict\"", ";", "if", "(", "isString", "(", "value", ")", ")", "{", "try", "{", "// phantomjs env has a working document object, let's use it", "document", ".", "querySelector", "(", "value", ")", ";", "}", "catch", "(", "e", ")", "{", "if", "(", "'name'", "in", "e", "&&", "(", "e", ".", "name", "===", "'SYNTAX_ERR'", "||", "e", ".", "name", "===", "'SyntaxError'", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", "else", "if", "(", "isObject", "(", "value", ")", ")", "{", "if", "(", "!", "value", ".", "hasOwnProperty", "(", "'type'", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "value", ".", "hasOwnProperty", "(", "'path'", ")", ")", "{", "return", "false", ";", "}", "if", "(", "[", "'css'", ",", "'xpath'", "]", ".", "indexOf", "(", "value", ".", "type", ")", "===", "-", "1", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks if value is a valid selector Object. @param mixed value @return Boolean
[ "Checks", "if", "value", "is", "a", "valid", "selector", "Object", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L583-L608
10,938
casperjs/casperjs
modules/utils.js
mergeObjectsInGecko
function mergeObjectsInGecko(origin, add, opts) { "use strict"; var options = opts || {}, keepReferences = options.keepReferences; for (var p in add) { if (isPlainObject(add[p])) { if (isPlainObject(origin[p])) { origin[p] = mergeObjects(origin[p], add[p]); } else { origin[p] = keepReferences ? add[p] : clone(add[p]); } } else { // if a property is only a getter, we could have a Javascript error // in strict mode "TypeError: setting a property that has only a getter" // when setting the value to the new object (gecko 25+). // To avoid it, let's define the property on the new object, do not set // directly the value var prop = Object.getOwnPropertyDescriptor(add, p); if (prop.get && !prop.set) { Object.defineProperty(origin, p, prop); } else { origin[p] = add[p]; } } } return origin; }
javascript
function mergeObjectsInGecko(origin, add, opts) { "use strict"; var options = opts || {}, keepReferences = options.keepReferences; for (var p in add) { if (isPlainObject(add[p])) { if (isPlainObject(origin[p])) { origin[p] = mergeObjects(origin[p], add[p]); } else { origin[p] = keepReferences ? add[p] : clone(add[p]); } } else { // if a property is only a getter, we could have a Javascript error // in strict mode "TypeError: setting a property that has only a getter" // when setting the value to the new object (gecko 25+). // To avoid it, let's define the property on the new object, do not set // directly the value var prop = Object.getOwnPropertyDescriptor(add, p); if (prop.get && !prop.set) { Object.defineProperty(origin, p, prop); } else { origin[p] = add[p]; } } } return origin; }
[ "function", "mergeObjectsInGecko", "(", "origin", ",", "add", ",", "opts", ")", "{", "\"use strict\"", ";", "var", "options", "=", "opts", "||", "{", "}", ",", "keepReferences", "=", "options", ".", "keepReferences", ";", "for", "(", "var", "p", "in", "add", ")", "{", "if", "(", "isPlainObject", "(", "add", "[", "p", "]", ")", ")", "{", "if", "(", "isPlainObject", "(", "origin", "[", "p", "]", ")", ")", "{", "origin", "[", "p", "]", "=", "mergeObjects", "(", "origin", "[", "p", "]", ",", "add", "[", "p", "]", ")", ";", "}", "else", "{", "origin", "[", "p", "]", "=", "keepReferences", "?", "add", "[", "p", "]", ":", "clone", "(", "add", "[", "p", "]", ")", ";", "}", "}", "else", "{", "// if a property is only a getter, we could have a Javascript error", "// in strict mode \"TypeError: setting a property that has only a getter\"", "// when setting the value to the new object (gecko 25+).", "// To avoid it, let's define the property on the new object, do not set", "// directly the value", "var", "prop", "=", "Object", ".", "getOwnPropertyDescriptor", "(", "add", ",", "p", ")", ";", "if", "(", "prop", ".", "get", "&&", "!", "prop", ".", "set", ")", "{", "Object", ".", "defineProperty", "(", "origin", ",", "p", ",", "prop", ")", ";", "}", "else", "{", "origin", "[", "p", "]", "=", "add", "[", "p", "]", ";", "}", "}", "}", "return", "origin", ";", "}" ]
Object recursive merging utility for use in the SlimerJS environment @param Object origin the origin object @param Object add the object to merge data into origin @param Object opts optional options to be passed in @return Object
[ "Object", "recursive", "merging", "utility", "for", "use", "in", "the", "SlimerJS", "environment" ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L641-L670
10,939
casperjs/casperjs
modules/utils.js
serialize
function serialize(value, indent) { "use strict"; if (isArray(value)) { value = value.map(function _map(prop) { return isFunction(prop) ? prop.toString().replace(/\s{2,}/, '') : prop; }); } return JSON.stringify(value, null, indent); }
javascript
function serialize(value, indent) { "use strict"; if (isArray(value)) { value = value.map(function _map(prop) { return isFunction(prop) ? prop.toString().replace(/\s{2,}/, '') : prop; }); } return JSON.stringify(value, null, indent); }
[ "function", "serialize", "(", "value", ",", "indent", ")", "{", "\"use strict\"", ";", "if", "(", "isArray", "(", "value", ")", ")", "{", "value", "=", "value", ".", "map", "(", "function", "_map", "(", "prop", ")", "{", "return", "isFunction", "(", "prop", ")", "?", "prop", ".", "toString", "(", ")", ".", "replace", "(", "/", "\\s{2,}", "/", ",", "''", ")", ":", "prop", ";", "}", ")", ";", "}", "return", "JSON", ".", "stringify", "(", "value", ",", "null", ",", "indent", ")", ";", "}" ]
Serializes a value using JSON. @param Mixed value @return String
[ "Serializes", "a", "value", "using", "JSON", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L776-L784
10,940
casperjs/casperjs
modules/utils.js
unique
function unique(array) { "use strict"; var o = {}, r = []; for (var i = 0, len = array.length; i !== len; i++) { var d = array[i]; if (typeof o[d] === "undefined") { o[d] = 1; r[r.length] = d; } } return r; }
javascript
function unique(array) { "use strict"; var o = {}, r = []; for (var i = 0, len = array.length; i !== len; i++) { var d = array[i]; if (typeof o[d] === "undefined") { o[d] = 1; r[r.length] = d; } } return r; }
[ "function", "unique", "(", "array", ")", "{", "\"use strict\"", ";", "var", "o", "=", "{", "}", ",", "r", "=", "[", "]", ";", "for", "(", "var", "i", "=", "0", ",", "len", "=", "array", ".", "length", ";", "i", "!==", "len", ";", "i", "++", ")", "{", "var", "d", "=", "array", "[", "i", "]", ";", "if", "(", "typeof", "o", "[", "d", "]", "===", "\"undefined\"", ")", "{", "o", "[", "d", "]", "=", "1", ";", "r", "[", "r", ".", "length", "]", "=", "d", ";", "}", "}", "return", "r", ";", "}" ]
Returns unique values from an array. Note: ugly code is ugly, but efficient: http://jsperf.com/array-unique2/8 @param Array array @return Array
[ "Returns", "unique", "values", "from", "an", "array", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L795-L807
10,941
casperjs/casperjs
modules/utils.js
versionToString
function versionToString(version) { if (isObject(version)) { try { return [version.major, version.minor, version.patch].join('.'); } catch (e) {} } return version; }
javascript
function versionToString(version) { if (isObject(version)) { try { return [version.major, version.minor, version.patch].join('.'); } catch (e) {} } return version; }
[ "function", "versionToString", "(", "version", ")", "{", "if", "(", "isObject", "(", "version", ")", ")", "{", "try", "{", "return", "[", "version", ".", "major", ",", "version", ".", "minor", ",", "version", ".", "patch", "]", ".", "join", "(", "'.'", ")", ";", "}", "catch", "(", "e", ")", "{", "}", "}", "return", "version", ";", "}" ]
Convert a version object to a string. @param Mixed version a version string or object
[ "Convert", "a", "version", "object", "to", "a", "string", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L815-L822
10,942
casperjs/casperjs
modules/utils.js
matchEngine
function matchEngine(matchSpec) { if (Array !== matchSpec.constructor) { matchSpec = [matchSpec]; } var idx; var len = matchSpec.length; var engineName = phantom.casperEngine; var engineVersion = phantom.version; for (idx = 0; idx < len; ++idx) { var match = matchSpec[idx]; var version = match.version; var min = version && version.min; var max = version && version.max; if ('*' === min) { min = null; } if ('*' === max) { max = null; } if (match.name === engineName && (!min || gteVersion(engineVersion, min)) && (!max || !ltVersion(max, engineVersion)) ) { return match; } } return false; }
javascript
function matchEngine(matchSpec) { if (Array !== matchSpec.constructor) { matchSpec = [matchSpec]; } var idx; var len = matchSpec.length; var engineName = phantom.casperEngine; var engineVersion = phantom.version; for (idx = 0; idx < len; ++idx) { var match = matchSpec[idx]; var version = match.version; var min = version && version.min; var max = version && version.max; if ('*' === min) { min = null; } if ('*' === max) { max = null; } if (match.name === engineName && (!min || gteVersion(engineVersion, min)) && (!max || !ltVersion(max, engineVersion)) ) { return match; } } return false; }
[ "function", "matchEngine", "(", "matchSpec", ")", "{", "if", "(", "Array", "!==", "matchSpec", ".", "constructor", ")", "{", "matchSpec", "=", "[", "matchSpec", "]", ";", "}", "var", "idx", ";", "var", "len", "=", "matchSpec", ".", "length", ";", "var", "engineName", "=", "phantom", ".", "casperEngine", ";", "var", "engineVersion", "=", "phantom", ".", "version", ";", "for", "(", "idx", "=", "0", ";", "idx", "<", "len", ";", "++", "idx", ")", "{", "var", "match", "=", "matchSpec", "[", "idx", "]", ";", "var", "version", "=", "match", ".", "version", ";", "var", "min", "=", "version", "&&", "version", ".", "min", ";", "var", "max", "=", "version", "&&", "version", ".", "max", ";", "if", "(", "'*'", "===", "min", ")", "{", "min", "=", "null", ";", "}", "if", "(", "'*'", "===", "max", ")", "{", "max", "=", "null", ";", "}", "if", "(", "match", ".", "name", "===", "engineName", "&&", "(", "!", "min", "||", "gteVersion", "(", "engineVersion", ",", "min", ")", ")", "&&", "(", "!", "max", "||", "!", "ltVersion", "(", "max", ",", "engineVersion", ")", ")", ")", "{", "return", "match", ";", "}", "}", "return", "false", ";", "}" ]
Checks if the engine matches a specifier. A match specifier is an object of the form: { name: 'casperjs' | 'phantomjs', version: { min: Object, max: Object }, message: String } Minimal and maximal versions to be matched are determined using utils.cmpVersion. @param Mixed matchSpec a single match specifier object or an Array of match specifier objects @return Boolean
[ "Checks", "if", "the", "engine", "matches", "a", "specifier", "." ]
4c236d0e139ca5dc90c91acd364445025e7a1522
https://github.com/casperjs/casperjs/blob/4c236d0e139ca5dc90c91acd364445025e7a1522/modules/utils.js#L896-L925
10,943
node-cron/node-cron
src/node-cron.js
schedule
function schedule(expression, func, options) { let task = createTask(expression, func, options); storage.save(task); return task; }
javascript
function schedule(expression, func, options) { let task = createTask(expression, func, options); storage.save(task); return task; }
[ "function", "schedule", "(", "expression", ",", "func", ",", "options", ")", "{", "let", "task", "=", "createTask", "(", "expression", ",", "func", ",", "options", ")", ";", "storage", ".", "save", "(", "task", ")", ";", "return", "task", ";", "}" ]
Creates a new task to execute given function when the cron expression ticks. @param {string} expression - cron expression. @param {Function} func - task to be executed. @param {Object} options - a set of options for the scheduled task: - scheduled <boolean>: if a schaduled task is ready and running to be performed when the time mach with the cron excpression. - timezone <string>: the tiemzone to execute the tasks. Example: { "scheduled": true, "timezone": "America/Sao_Paulo" } @returns {ScheduledTask} update function.
[ "Creates", "a", "new", "task", "to", "execute", "given", "function", "when", "the", "cron", "expression", "ticks", "." ]
2a3970390b8dffa20b0a1bbf5ba2f71e8b4405d2
https://github.com/node-cron/node-cron/blob/2a3970390b8dffa20b0a1bbf5ba2f71e8b4405d2/src/node-cron.js#L29-L33
10,944
fengyuanchen/viewer
dist/viewer.common.js
getImageNaturalSizes
function getImageNaturalSizes(image, callback) { var newImage = document.createElement('img'); // Modern browsers (except Safari) if (image.naturalWidth && !IS_SAFARI) { callback(image.naturalWidth, image.naturalHeight); return newImage; } var body = document.body || document.documentElement; newImage.onload = function () { callback(newImage.width, newImage.height); if (!IS_SAFARI) { body.removeChild(newImage); } }; newImage.src = image.src; // iOS Safari will convert the image automatically // with its orientation once append it into DOM if (!IS_SAFARI) { newImage.style.cssText = 'left:0;' + 'max-height:none!important;' + 'max-width:none!important;' + 'min-height:0!important;' + 'min-width:0!important;' + 'opacity:0;' + 'position:absolute;' + 'top:0;' + 'z-index:-1;'; body.appendChild(newImage); } return newImage; }
javascript
function getImageNaturalSizes(image, callback) { var newImage = document.createElement('img'); // Modern browsers (except Safari) if (image.naturalWidth && !IS_SAFARI) { callback(image.naturalWidth, image.naturalHeight); return newImage; } var body = document.body || document.documentElement; newImage.onload = function () { callback(newImage.width, newImage.height); if (!IS_SAFARI) { body.removeChild(newImage); } }; newImage.src = image.src; // iOS Safari will convert the image automatically // with its orientation once append it into DOM if (!IS_SAFARI) { newImage.style.cssText = 'left:0;' + 'max-height:none!important;' + 'max-width:none!important;' + 'min-height:0!important;' + 'min-width:0!important;' + 'opacity:0;' + 'position:absolute;' + 'top:0;' + 'z-index:-1;'; body.appendChild(newImage); } return newImage; }
[ "function", "getImageNaturalSizes", "(", "image", ",", "callback", ")", "{", "var", "newImage", "=", "document", ".", "createElement", "(", "'img'", ")", ";", "// Modern browsers (except Safari)", "if", "(", "image", ".", "naturalWidth", "&&", "!", "IS_SAFARI", ")", "{", "callback", "(", "image", ".", "naturalWidth", ",", "image", ".", "naturalHeight", ")", ";", "return", "newImage", ";", "}", "var", "body", "=", "document", ".", "body", "||", "document", ".", "documentElement", ";", "newImage", ".", "onload", "=", "function", "(", ")", "{", "callback", "(", "newImage", ".", "width", ",", "newImage", ".", "height", ")", ";", "if", "(", "!", "IS_SAFARI", ")", "{", "body", ".", "removeChild", "(", "newImage", ")", ";", "}", "}", ";", "newImage", ".", "src", "=", "image", ".", "src", ";", "// iOS Safari will convert the image automatically", "// with its orientation once append it into DOM", "if", "(", "!", "IS_SAFARI", ")", "{", "newImage", ".", "style", ".", "cssText", "=", "'left:0;'", "+", "'max-height:none!important;'", "+", "'max-width:none!important;'", "+", "'min-height:0!important;'", "+", "'min-width:0!important;'", "+", "'opacity:0;'", "+", "'position:absolute;'", "+", "'top:0;'", "+", "'z-index:-1;'", ";", "body", ".", "appendChild", "(", "newImage", ")", ";", "}", "return", "newImage", ";", "}" ]
Get an image's natural sizes. @param {string} image - The target image. @param {Function} callback - The callback function. @returns {HTMLImageElement} The new image.
[ "Get", "an", "image", "s", "natural", "sizes", "." ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L713-L742
10,945
fengyuanchen/viewer
dist/viewer.common.js
onViewed
function onViewed() { var imageData = _this.imageData; title.textContent = alt + ' (' + imageData.naturalWidth + ' \xD7 ' + imageData.naturalHeight + ')'; }
javascript
function onViewed() { var imageData = _this.imageData; title.textContent = alt + ' (' + imageData.naturalWidth + ' \xD7 ' + imageData.naturalHeight + ')'; }
[ "function", "onViewed", "(", ")", "{", "var", "imageData", "=", "_this", ".", "imageData", ";", "title", ".", "textContent", "=", "alt", "+", "' ('", "+", "imageData", ".", "naturalWidth", "+", "' \\xD7 '", "+", "imageData", ".", "naturalHeight", "+", "')'", ";", "}" ]
Generate title after viewed
[ "Generate", "title", "after", "viewed" ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L1724-L1729
10,946
fengyuanchen/viewer
dist/viewer.common.js
prev
function prev() { var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var index = this.index - 1; if (index < 0) { index = loop ? this.length - 1 : 0; } this.view(index); return this; }
javascript
function prev() { var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var index = this.index - 1; if (index < 0) { index = loop ? this.length - 1 : 0; } this.view(index); return this; }
[ "function", "prev", "(", ")", "{", "var", "loop", "=", "arguments", ".", "length", ">", "0", "&&", "arguments", "[", "0", "]", "!==", "undefined", "?", "arguments", "[", "0", "]", ":", "false", ";", "var", "index", "=", "this", ".", "index", "-", "1", ";", "if", "(", "index", "<", "0", ")", "{", "index", "=", "loop", "?", "this", ".", "length", "-", "1", ":", "0", ";", "}", "this", ".", "view", "(", "index", ")", ";", "return", "this", ";", "}" ]
View the previous image @param {boolean} [loop=false] - Indicate if view the last one when it is the first one at present. @returns {Viewer} this
[ "View", "the", "previous", "image" ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L1784-L1795
10,947
fengyuanchen/viewer
dist/viewer.common.js
next
function next() { var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var maxIndex = this.length - 1; var index = this.index + 1; if (index > maxIndex) { index = loop ? 0 : maxIndex; } this.view(index); return this; }
javascript
function next() { var loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; var maxIndex = this.length - 1; var index = this.index + 1; if (index > maxIndex) { index = loop ? 0 : maxIndex; } this.view(index); return this; }
[ "function", "next", "(", ")", "{", "var", "loop", "=", "arguments", ".", "length", ">", "0", "&&", "arguments", "[", "0", "]", "!==", "undefined", "?", "arguments", "[", "0", "]", ":", "false", ";", "var", "maxIndex", "=", "this", ".", "length", "-", "1", ";", "var", "index", "=", "this", ".", "index", "+", "1", ";", "if", "(", "index", ">", "maxIndex", ")", "{", "index", "=", "loop", "?", "0", ":", "maxIndex", ";", "}", "this", ".", "view", "(", "index", ")", ";", "return", "this", ";", "}" ]
View the next image @param {boolean} [loop=false] - Indicate if view the first one when it is the last one at present. @returns {Viewer} this
[ "View", "the", "next", "image" ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L1804-L1816
10,948
fengyuanchen/viewer
dist/viewer.common.js
move
function move(offsetX, offsetY) { var imageData = this.imageData; this.moveTo(isUndefined(offsetX) ? offsetX : imageData.left + Number(offsetX), isUndefined(offsetY) ? offsetY : imageData.top + Number(offsetY)); return this; }
javascript
function move(offsetX, offsetY) { var imageData = this.imageData; this.moveTo(isUndefined(offsetX) ? offsetX : imageData.left + Number(offsetX), isUndefined(offsetY) ? offsetY : imageData.top + Number(offsetY)); return this; }
[ "function", "move", "(", "offsetX", ",", "offsetY", ")", "{", "var", "imageData", "=", "this", ".", "imageData", ";", "this", ".", "moveTo", "(", "isUndefined", "(", "offsetX", ")", "?", "offsetX", ":", "imageData", ".", "left", "+", "Number", "(", "offsetX", ")", ",", "isUndefined", "(", "offsetY", ")", "?", "offsetY", ":", "imageData", ".", "top", "+", "Number", "(", "offsetY", ")", ")", ";", "return", "this", ";", "}" ]
Move the image with relative offsets. @param {number} offsetX - The relative offset distance on the x-axis. @param {number} offsetY - The relative offset distance on the y-axis. @returns {Viewer} this
[ "Move", "the", "image", "with", "relative", "offsets", "." ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L1825-L1832
10,949
fengyuanchen/viewer
dist/viewer.common.js
moveTo
function moveTo(x) { var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; var imageData = this.imageData; x = Number(x); y = Number(y); if (this.viewed && !this.played && this.options.movable) { var changed = false; if (isNumber(x)) { imageData.left = x; changed = true; } if (isNumber(y)) { imageData.top = y; changed = true; } if (changed) { this.renderImage(); } } return this; }
javascript
function moveTo(x) { var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : x; var imageData = this.imageData; x = Number(x); y = Number(y); if (this.viewed && !this.played && this.options.movable) { var changed = false; if (isNumber(x)) { imageData.left = x; changed = true; } if (isNumber(y)) { imageData.top = y; changed = true; } if (changed) { this.renderImage(); } } return this; }
[ "function", "moveTo", "(", "x", ")", "{", "var", "y", "=", "arguments", ".", "length", ">", "1", "&&", "arguments", "[", "1", "]", "!==", "undefined", "?", "arguments", "[", "1", "]", ":", "x", ";", "var", "imageData", "=", "this", ".", "imageData", ";", "x", "=", "Number", "(", "x", ")", ";", "y", "=", "Number", "(", "y", ")", ";", "if", "(", "this", ".", "viewed", "&&", "!", "this", ".", "played", "&&", "this", ".", "options", ".", "movable", ")", "{", "var", "changed", "=", "false", ";", "if", "(", "isNumber", "(", "x", ")", ")", "{", "imageData", ".", "left", "=", "x", ";", "changed", "=", "true", ";", "}", "if", "(", "isNumber", "(", "y", ")", ")", "{", "imageData", ".", "top", "=", "y", ";", "changed", "=", "true", ";", "}", "if", "(", "changed", ")", "{", "this", ".", "renderImage", "(", ")", ";", "}", "}", "return", "this", ";", "}" ]
Move the image to an absolute point. @param {number} x - The x-axis coordinate. @param {number} [y=x] - The y-axis coordinate. @returns {Viewer} this
[ "Move", "the", "image", "to", "an", "absolute", "point", "." ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L1841-L1868
10,950
fengyuanchen/viewer
dist/viewer.common.js
zoom
function zoom(ratio) { var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var imageData = this.imageData; ratio = Number(ratio); if (ratio < 0) { ratio = 1 / (1 - ratio); } else { ratio = 1 + ratio; } this.zoomTo(imageData.width * ratio / imageData.naturalWidth, hasTooltip, _originalEvent); return this; }
javascript
function zoom(ratio) { var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var imageData = this.imageData; ratio = Number(ratio); if (ratio < 0) { ratio = 1 / (1 - ratio); } else { ratio = 1 + ratio; } this.zoomTo(imageData.width * ratio / imageData.naturalWidth, hasTooltip, _originalEvent); return this; }
[ "function", "zoom", "(", "ratio", ")", "{", "var", "hasTooltip", "=", "arguments", ".", "length", ">", "1", "&&", "arguments", "[", "1", "]", "!==", "undefined", "?", "arguments", "[", "1", "]", ":", "false", ";", "var", "_originalEvent", "=", "arguments", ".", "length", ">", "2", "&&", "arguments", "[", "2", "]", "!==", "undefined", "?", "arguments", "[", "2", "]", ":", "null", ";", "var", "imageData", "=", "this", ".", "imageData", ";", "ratio", "=", "Number", "(", "ratio", ")", ";", "if", "(", "ratio", "<", "0", ")", "{", "ratio", "=", "1", "/", "(", "1", "-", "ratio", ")", ";", "}", "else", "{", "ratio", "=", "1", "+", "ratio", ";", "}", "this", ".", "zoomTo", "(", "imageData", ".", "width", "*", "ratio", "/", "imageData", ".", "naturalWidth", ",", "hasTooltip", ",", "_originalEvent", ")", ";", "return", "this", ";", "}" ]
Zoom the image with a relative ratio. @param {number} ratio - The target ratio. @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not. @param {Event} [_originalEvent=null] - The original event if any. @returns {Viewer} this
[ "Zoom", "the", "image", "with", "a", "relative", "ratio", "." ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L1878-L1897
10,951
fengyuanchen/viewer
dist/viewer.common.js
zoomTo
function zoomTo(ratio) { var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var _zoomable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; var options = this.options, pointers = this.pointers, imageData = this.imageData; ratio = Math.max(0, ratio); if (isNumber(ratio) && this.viewed && !this.played && (_zoomable || options.zoomable)) { if (!_zoomable) { var minZoomRatio = Math.max(0.01, options.minZoomRatio); var maxZoomRatio = Math.min(100, options.maxZoomRatio); ratio = Math.min(Math.max(ratio, minZoomRatio), maxZoomRatio); } if (_originalEvent && ratio > 0.95 && ratio < 1.05) { ratio = 1; } var newWidth = imageData.naturalWidth * ratio; var newHeight = imageData.naturalHeight * ratio; if (_originalEvent) { var offset = getOffset(this.viewer); var center = pointers && Object.keys(pointers).length ? getPointersCenter(pointers) : { pageX: _originalEvent.pageX, pageY: _originalEvent.pageY }; // Zoom from the triggering point of the event imageData.left -= (newWidth - imageData.width) * ((center.pageX - offset.left - imageData.left) / imageData.width); imageData.top -= (newHeight - imageData.height) * ((center.pageY - offset.top - imageData.top) / imageData.height); } else { // Zoom from the center of the image imageData.left -= (newWidth - imageData.width) / 2; imageData.top -= (newHeight - imageData.height) / 2; } imageData.width = newWidth; imageData.height = newHeight; imageData.ratio = ratio; this.renderImage(); if (hasTooltip) { this.tooltip(); } } return this; }
javascript
function zoomTo(ratio) { var hasTooltip = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var _originalEvent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; var _zoomable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; var options = this.options, pointers = this.pointers, imageData = this.imageData; ratio = Math.max(0, ratio); if (isNumber(ratio) && this.viewed && !this.played && (_zoomable || options.zoomable)) { if (!_zoomable) { var minZoomRatio = Math.max(0.01, options.minZoomRatio); var maxZoomRatio = Math.min(100, options.maxZoomRatio); ratio = Math.min(Math.max(ratio, minZoomRatio), maxZoomRatio); } if (_originalEvent && ratio > 0.95 && ratio < 1.05) { ratio = 1; } var newWidth = imageData.naturalWidth * ratio; var newHeight = imageData.naturalHeight * ratio; if (_originalEvent) { var offset = getOffset(this.viewer); var center = pointers && Object.keys(pointers).length ? getPointersCenter(pointers) : { pageX: _originalEvent.pageX, pageY: _originalEvent.pageY }; // Zoom from the triggering point of the event imageData.left -= (newWidth - imageData.width) * ((center.pageX - offset.left - imageData.left) / imageData.width); imageData.top -= (newHeight - imageData.height) * ((center.pageY - offset.top - imageData.top) / imageData.height); } else { // Zoom from the center of the image imageData.left -= (newWidth - imageData.width) / 2; imageData.top -= (newHeight - imageData.height) / 2; } imageData.width = newWidth; imageData.height = newHeight; imageData.ratio = ratio; this.renderImage(); if (hasTooltip) { this.tooltip(); } } return this; }
[ "function", "zoomTo", "(", "ratio", ")", "{", "var", "hasTooltip", "=", "arguments", ".", "length", ">", "1", "&&", "arguments", "[", "1", "]", "!==", "undefined", "?", "arguments", "[", "1", "]", ":", "false", ";", "var", "_originalEvent", "=", "arguments", ".", "length", ">", "2", "&&", "arguments", "[", "2", "]", "!==", "undefined", "?", "arguments", "[", "2", "]", ":", "null", ";", "var", "_zoomable", "=", "arguments", ".", "length", ">", "3", "&&", "arguments", "[", "3", "]", "!==", "undefined", "?", "arguments", "[", "3", "]", ":", "false", ";", "var", "options", "=", "this", ".", "options", ",", "pointers", "=", "this", ".", "pointers", ",", "imageData", "=", "this", ".", "imageData", ";", "ratio", "=", "Math", ".", "max", "(", "0", ",", "ratio", ")", ";", "if", "(", "isNumber", "(", "ratio", ")", "&&", "this", ".", "viewed", "&&", "!", "this", ".", "played", "&&", "(", "_zoomable", "||", "options", ".", "zoomable", ")", ")", "{", "if", "(", "!", "_zoomable", ")", "{", "var", "minZoomRatio", "=", "Math", ".", "max", "(", "0.01", ",", "options", ".", "minZoomRatio", ")", ";", "var", "maxZoomRatio", "=", "Math", ".", "min", "(", "100", ",", "options", ".", "maxZoomRatio", ")", ";", "ratio", "=", "Math", ".", "min", "(", "Math", ".", "max", "(", "ratio", ",", "minZoomRatio", ")", ",", "maxZoomRatio", ")", ";", "}", "if", "(", "_originalEvent", "&&", "ratio", ">", "0.95", "&&", "ratio", "<", "1.05", ")", "{", "ratio", "=", "1", ";", "}", "var", "newWidth", "=", "imageData", ".", "naturalWidth", "*", "ratio", ";", "var", "newHeight", "=", "imageData", ".", "naturalHeight", "*", "ratio", ";", "if", "(", "_originalEvent", ")", "{", "var", "offset", "=", "getOffset", "(", "this", ".", "viewer", ")", ";", "var", "center", "=", "pointers", "&&", "Object", ".", "keys", "(", "pointers", ")", ".", "length", "?", "getPointersCenter", "(", "pointers", ")", ":", "{", "pageX", ":", "_originalEvent", ".", "pageX", ",", "pageY", ":", "_originalEvent", ".", "pageY", "}", ";", "// Zoom from the triggering point of the event", "imageData", ".", "left", "-=", "(", "newWidth", "-", "imageData", ".", "width", ")", "*", "(", "(", "center", ".", "pageX", "-", "offset", ".", "left", "-", "imageData", ".", "left", ")", "/", "imageData", ".", "width", ")", ";", "imageData", ".", "top", "-=", "(", "newHeight", "-", "imageData", ".", "height", ")", "*", "(", "(", "center", ".", "pageY", "-", "offset", ".", "top", "-", "imageData", ".", "top", ")", "/", "imageData", ".", "height", ")", ";", "}", "else", "{", "// Zoom from the center of the image", "imageData", ".", "left", "-=", "(", "newWidth", "-", "imageData", ".", "width", ")", "/", "2", ";", "imageData", ".", "top", "-=", "(", "newHeight", "-", "imageData", ".", "height", ")", "/", "2", ";", "}", "imageData", ".", "width", "=", "newWidth", ";", "imageData", ".", "height", "=", "newHeight", ";", "imageData", ".", "ratio", "=", "ratio", ";", "this", ".", "renderImage", "(", ")", ";", "if", "(", "hasTooltip", ")", "{", "this", ".", "tooltip", "(", ")", ";", "}", "}", "return", "this", ";", "}" ]
Zoom the image to an absolute ratio. @param {number} ratio - The target ratio. @param {boolean} [hasTooltip=false] - Indicates if it has a tooltip or not. @param {Event} [_originalEvent=null] - The original event if any. @param {Event} [_zoomable=false] - Indicates if the current zoom is available or not. @returns {Viewer} this
[ "Zoom", "the", "image", "to", "an", "absolute", "ratio", "." ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L1908-L1964
10,952
fengyuanchen/viewer
dist/viewer.common.js
rotateTo
function rotateTo(degree) { var imageData = this.imageData; degree = Number(degree); if (isNumber(degree) && this.viewed && !this.played && this.options.rotatable) { imageData.rotate = degree; this.renderImage(); } return this; }
javascript
function rotateTo(degree) { var imageData = this.imageData; degree = Number(degree); if (isNumber(degree) && this.viewed && !this.played && this.options.rotatable) { imageData.rotate = degree; this.renderImage(); } return this; }
[ "function", "rotateTo", "(", "degree", ")", "{", "var", "imageData", "=", "this", ".", "imageData", ";", "degree", "=", "Number", "(", "degree", ")", ";", "if", "(", "isNumber", "(", "degree", ")", "&&", "this", ".", "viewed", "&&", "!", "this", ".", "played", "&&", "this", ".", "options", ".", "rotatable", ")", "{", "imageData", ".", "rotate", "=", "degree", ";", "this", ".", "renderImage", "(", ")", ";", "}", "return", "this", ";", "}" ]
Rotate the image to an absolute degree. @param {number} degree - The rotate degree. @returns {Viewer} this
[ "Rotate", "the", "image", "to", "an", "absolute", "degree", "." ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L1984-L1996
10,953
fengyuanchen/viewer
dist/viewer.common.js
scale
function scale(scaleX) { var scaleY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : scaleX; var imageData = this.imageData; scaleX = Number(scaleX); scaleY = Number(scaleY); if (this.viewed && !this.played && this.options.scalable) { var changed = false; if (isNumber(scaleX)) { imageData.scaleX = scaleX; changed = true; } if (isNumber(scaleY)) { imageData.scaleY = scaleY; changed = true; } if (changed) { this.renderImage(); } } return this; }
javascript
function scale(scaleX) { var scaleY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : scaleX; var imageData = this.imageData; scaleX = Number(scaleX); scaleY = Number(scaleY); if (this.viewed && !this.played && this.options.scalable) { var changed = false; if (isNumber(scaleX)) { imageData.scaleX = scaleX; changed = true; } if (isNumber(scaleY)) { imageData.scaleY = scaleY; changed = true; } if (changed) { this.renderImage(); } } return this; }
[ "function", "scale", "(", "scaleX", ")", "{", "var", "scaleY", "=", "arguments", ".", "length", ">", "1", "&&", "arguments", "[", "1", "]", "!==", "undefined", "?", "arguments", "[", "1", "]", ":", "scaleX", ";", "var", "imageData", "=", "this", ".", "imageData", ";", "scaleX", "=", "Number", "(", "scaleX", ")", ";", "scaleY", "=", "Number", "(", "scaleY", ")", ";", "if", "(", "this", ".", "viewed", "&&", "!", "this", ".", "played", "&&", "this", ".", "options", ".", "scalable", ")", "{", "var", "changed", "=", "false", ";", "if", "(", "isNumber", "(", "scaleX", ")", ")", "{", "imageData", ".", "scaleX", "=", "scaleX", ";", "changed", "=", "true", ";", "}", "if", "(", "isNumber", "(", "scaleY", ")", ")", "{", "imageData", ".", "scaleY", "=", "scaleY", ";", "changed", "=", "true", ";", "}", "if", "(", "changed", ")", "{", "this", ".", "renderImage", "(", ")", ";", "}", "}", "return", "this", ";", "}" ]
Scale the image. @param {number} scaleX - The scale ratio on the x-axis. @param {number} [scaleY=scaleX] - The scale ratio on the y-axis. @returns {Viewer} this
[ "Scale", "the", "image", "." ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L2029-L2056
10,954
fengyuanchen/viewer
dist/viewer.common.js
play
function play() { var _this2 = this; var fullscreen = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; if (!this.isShown || this.played) { return this; } var options = this.options, player = this.player; var onLoad = this.loadImage.bind(this); var list = []; var total = 0; var index = 0; this.played = true; this.onLoadWhenPlay = onLoad; if (fullscreen) { this.requestFullscreen(); } addClass(player, CLASS_SHOW); forEach(this.items, function (item, i) { var img = item.querySelector('img'); var image = document.createElement('img'); image.src = getData(img, 'originalUrl'); image.alt = img.getAttribute('alt'); total += 1; addClass(image, CLASS_FADE); toggleClass(image, CLASS_TRANSITION, options.transition); if (hasClass(item, CLASS_ACTIVE)) { addClass(image, CLASS_IN); index = i; } list.push(image); addListener(image, EVENT_LOAD, onLoad, { once: true }); player.appendChild(image); }); if (isNumber(options.interval) && options.interval > 0) { var play = function play() { _this2.playing = setTimeout(function () { removeClass(list[index], CLASS_IN); index += 1; index = index < total ? index : 0; addClass(list[index], CLASS_IN); play(); }, options.interval); }; if (total > 1) { play(); } } return this; }
javascript
function play() { var _this2 = this; var fullscreen = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; if (!this.isShown || this.played) { return this; } var options = this.options, player = this.player; var onLoad = this.loadImage.bind(this); var list = []; var total = 0; var index = 0; this.played = true; this.onLoadWhenPlay = onLoad; if (fullscreen) { this.requestFullscreen(); } addClass(player, CLASS_SHOW); forEach(this.items, function (item, i) { var img = item.querySelector('img'); var image = document.createElement('img'); image.src = getData(img, 'originalUrl'); image.alt = img.getAttribute('alt'); total += 1; addClass(image, CLASS_FADE); toggleClass(image, CLASS_TRANSITION, options.transition); if (hasClass(item, CLASS_ACTIVE)) { addClass(image, CLASS_IN); index = i; } list.push(image); addListener(image, EVENT_LOAD, onLoad, { once: true }); player.appendChild(image); }); if (isNumber(options.interval) && options.interval > 0) { var play = function play() { _this2.playing = setTimeout(function () { removeClass(list[index], CLASS_IN); index += 1; index = index < total ? index : 0; addClass(list[index], CLASS_IN); play(); }, options.interval); }; if (total > 1) { play(); } } return this; }
[ "function", "play", "(", ")", "{", "var", "_this2", "=", "this", ";", "var", "fullscreen", "=", "arguments", ".", "length", ">", "0", "&&", "arguments", "[", "0", "]", "!==", "undefined", "?", "arguments", "[", "0", "]", ":", "false", ";", "if", "(", "!", "this", ".", "isShown", "||", "this", ".", "played", ")", "{", "return", "this", ";", "}", "var", "options", "=", "this", ".", "options", ",", "player", "=", "this", ".", "player", ";", "var", "onLoad", "=", "this", ".", "loadImage", ".", "bind", "(", "this", ")", ";", "var", "list", "=", "[", "]", ";", "var", "total", "=", "0", ";", "var", "index", "=", "0", ";", "this", ".", "played", "=", "true", ";", "this", ".", "onLoadWhenPlay", "=", "onLoad", ";", "if", "(", "fullscreen", ")", "{", "this", ".", "requestFullscreen", "(", ")", ";", "}", "addClass", "(", "player", ",", "CLASS_SHOW", ")", ";", "forEach", "(", "this", ".", "items", ",", "function", "(", "item", ",", "i", ")", "{", "var", "img", "=", "item", ".", "querySelector", "(", "'img'", ")", ";", "var", "image", "=", "document", ".", "createElement", "(", "'img'", ")", ";", "image", ".", "src", "=", "getData", "(", "img", ",", "'originalUrl'", ")", ";", "image", ".", "alt", "=", "img", ".", "getAttribute", "(", "'alt'", ")", ";", "total", "+=", "1", ";", "addClass", "(", "image", ",", "CLASS_FADE", ")", ";", "toggleClass", "(", "image", ",", "CLASS_TRANSITION", ",", "options", ".", "transition", ")", ";", "if", "(", "hasClass", "(", "item", ",", "CLASS_ACTIVE", ")", ")", "{", "addClass", "(", "image", ",", "CLASS_IN", ")", ";", "index", "=", "i", ";", "}", "list", ".", "push", "(", "image", ")", ";", "addListener", "(", "image", ",", "EVENT_LOAD", ",", "onLoad", ",", "{", "once", ":", "true", "}", ")", ";", "player", ".", "appendChild", "(", "image", ")", ";", "}", ")", ";", "if", "(", "isNumber", "(", "options", ".", "interval", ")", "&&", "options", ".", "interval", ">", "0", ")", "{", "var", "play", "=", "function", "play", "(", ")", "{", "_this2", ".", "playing", "=", "setTimeout", "(", "function", "(", ")", "{", "removeClass", "(", "list", "[", "index", "]", ",", "CLASS_IN", ")", ";", "index", "+=", "1", ";", "index", "=", "index", "<", "total", "?", "index", ":", "0", ";", "addClass", "(", "list", "[", "index", "]", ",", "CLASS_IN", ")", ";", "play", "(", ")", ";", "}", ",", "options", ".", "interval", ")", ";", "}", ";", "if", "(", "total", ">", "1", ")", "{", "play", "(", ")", ";", "}", "}", "return", "this", ";", "}" ]
Play the images @param {boolean} [fullscreen=false] - Indicate if request fullscreen or not. @returns {Viewer} this
[ "Play", "the", "images" ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L2064-L2128
10,955
fengyuanchen/viewer
dist/viewer.common.js
tooltip
function tooltip() { var _this6 = this; var options = this.options, tooltipBox = this.tooltipBox, imageData = this.imageData; if (!this.viewed || this.played || !options.tooltip) { return this; } tooltipBox.textContent = Math.round(imageData.ratio * 100) + '%'; if (!this.tooltipping) { if (options.transition) { if (this.fading) { dispatchEvent(tooltipBox, EVENT_TRANSITION_END); } addClass(tooltipBox, CLASS_SHOW); addClass(tooltipBox, CLASS_FADE); addClass(tooltipBox, CLASS_TRANSITION); // Force reflow to enable CSS3 transition // eslint-disable-next-line tooltipBox.offsetWidth; addClass(tooltipBox, CLASS_IN); } else { addClass(tooltipBox, CLASS_SHOW); } } else { clearTimeout(this.tooltipping); } this.tooltipping = setTimeout(function () { if (options.transition) { addListener(tooltipBox, EVENT_TRANSITION_END, function () { removeClass(tooltipBox, CLASS_SHOW); removeClass(tooltipBox, CLASS_FADE); removeClass(tooltipBox, CLASS_TRANSITION); _this6.fading = false; }, { once: true }); removeClass(tooltipBox, CLASS_IN); _this6.fading = true; } else { removeClass(tooltipBox, CLASS_SHOW); } _this6.tooltipping = false; }, 1000); return this; }
javascript
function tooltip() { var _this6 = this; var options = this.options, tooltipBox = this.tooltipBox, imageData = this.imageData; if (!this.viewed || this.played || !options.tooltip) { return this; } tooltipBox.textContent = Math.round(imageData.ratio * 100) + '%'; if (!this.tooltipping) { if (options.transition) { if (this.fading) { dispatchEvent(tooltipBox, EVENT_TRANSITION_END); } addClass(tooltipBox, CLASS_SHOW); addClass(tooltipBox, CLASS_FADE); addClass(tooltipBox, CLASS_TRANSITION); // Force reflow to enable CSS3 transition // eslint-disable-next-line tooltipBox.offsetWidth; addClass(tooltipBox, CLASS_IN); } else { addClass(tooltipBox, CLASS_SHOW); } } else { clearTimeout(this.tooltipping); } this.tooltipping = setTimeout(function () { if (options.transition) { addListener(tooltipBox, EVENT_TRANSITION_END, function () { removeClass(tooltipBox, CLASS_SHOW); removeClass(tooltipBox, CLASS_FADE); removeClass(tooltipBox, CLASS_TRANSITION); _this6.fading = false; }, { once: true }); removeClass(tooltipBox, CLASS_IN); _this6.fading = true; } else { removeClass(tooltipBox, CLASS_SHOW); } _this6.tooltipping = false; }, 1000); return this; }
[ "function", "tooltip", "(", ")", "{", "var", "_this6", "=", "this", ";", "var", "options", "=", "this", ".", "options", ",", "tooltipBox", "=", "this", ".", "tooltipBox", ",", "imageData", "=", "this", ".", "imageData", ";", "if", "(", "!", "this", ".", "viewed", "||", "this", ".", "played", "||", "!", "options", ".", "tooltip", ")", "{", "return", "this", ";", "}", "tooltipBox", ".", "textContent", "=", "Math", ".", "round", "(", "imageData", ".", "ratio", "*", "100", ")", "+", "'%'", ";", "if", "(", "!", "this", ".", "tooltipping", ")", "{", "if", "(", "options", ".", "transition", ")", "{", "if", "(", "this", ".", "fading", ")", "{", "dispatchEvent", "(", "tooltipBox", ",", "EVENT_TRANSITION_END", ")", ";", "}", "addClass", "(", "tooltipBox", ",", "CLASS_SHOW", ")", ";", "addClass", "(", "tooltipBox", ",", "CLASS_FADE", ")", ";", "addClass", "(", "tooltipBox", ",", "CLASS_TRANSITION", ")", ";", "// Force reflow to enable CSS3 transition", "// eslint-disable-next-line", "tooltipBox", ".", "offsetWidth", ";", "addClass", "(", "tooltipBox", ",", "CLASS_IN", ")", ";", "}", "else", "{", "addClass", "(", "tooltipBox", ",", "CLASS_SHOW", ")", ";", "}", "}", "else", "{", "clearTimeout", "(", "this", ".", "tooltipping", ")", ";", "}", "this", ".", "tooltipping", "=", "setTimeout", "(", "function", "(", ")", "{", "if", "(", "options", ".", "transition", ")", "{", "addListener", "(", "tooltipBox", ",", "EVENT_TRANSITION_END", ",", "function", "(", ")", "{", "removeClass", "(", "tooltipBox", ",", "CLASS_SHOW", ")", ";", "removeClass", "(", "tooltipBox", ",", "CLASS_FADE", ")", ";", "removeClass", "(", "tooltipBox", ",", "CLASS_TRANSITION", ")", ";", "_this6", ".", "fading", "=", "false", ";", "}", ",", "{", "once", ":", "true", "}", ")", ";", "removeClass", "(", "tooltipBox", ",", "CLASS_IN", ")", ";", "_this6", ".", "fading", "=", "true", ";", "}", "else", "{", "removeClass", "(", "tooltipBox", ",", "CLASS_SHOW", ")", ";", "}", "_this6", ".", "tooltipping", "=", "false", ";", "}", ",", "1000", ")", ";", "return", "this", ";", "}" ]
Show the current ratio of the image with percentage
[ "Show", "the", "current", "ratio", "of", "the", "image", "with", "percentage" ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L2261-L2317
10,956
fengyuanchen/viewer
dist/viewer.common.js
update
function update() { var element = this.element, options = this.options, isImg = this.isImg; // Destroy viewer if the target image was deleted if (isImg && !element.parentNode) { return this.destroy(); } var images = []; forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) { if (options.filter) { if (options.filter(image)) { images.push(image); } } else { images.push(image); } }); if (!images.length) { return this; } this.images = images; this.length = images.length; if (this.ready) { var indexes = []; forEach(this.items, function (item, i) { var img = item.querySelector('img'); var image = images[i]; if (image) { if (image.src !== img.src) { indexes.push(i); } } else { indexes.push(i); } }); setStyle(this.list, { width: 'auto' }); this.initList(); if (this.isShown) { if (this.length) { if (this.viewed) { var index = indexes.indexOf(this.index); if (index >= 0) { this.viewed = false; this.view(Math.max(this.index - (index + 1), 0)); } else { addClass(this.items[this.index], CLASS_ACTIVE); } } } else { this.image = null; this.viewed = false; this.index = 0; this.imageData = null; this.canvas.innerHTML = ''; this.title.innerHTML = ''; } } } else { this.build(); } return this; }
javascript
function update() { var element = this.element, options = this.options, isImg = this.isImg; // Destroy viewer if the target image was deleted if (isImg && !element.parentNode) { return this.destroy(); } var images = []; forEach(isImg ? [element] : element.querySelectorAll('img'), function (image) { if (options.filter) { if (options.filter(image)) { images.push(image); } } else { images.push(image); } }); if (!images.length) { return this; } this.images = images; this.length = images.length; if (this.ready) { var indexes = []; forEach(this.items, function (item, i) { var img = item.querySelector('img'); var image = images[i]; if (image) { if (image.src !== img.src) { indexes.push(i); } } else { indexes.push(i); } }); setStyle(this.list, { width: 'auto' }); this.initList(); if (this.isShown) { if (this.length) { if (this.viewed) { var index = indexes.indexOf(this.index); if (index >= 0) { this.viewed = false; this.view(Math.max(this.index - (index + 1), 0)); } else { addClass(this.items[this.index], CLASS_ACTIVE); } } } else { this.image = null; this.viewed = false; this.index = 0; this.imageData = null; this.canvas.innerHTML = ''; this.title.innerHTML = ''; } } } else { this.build(); } return this; }
[ "function", "update", "(", ")", "{", "var", "element", "=", "this", ".", "element", ",", "options", "=", "this", ".", "options", ",", "isImg", "=", "this", ".", "isImg", ";", "// Destroy viewer if the target image was deleted", "if", "(", "isImg", "&&", "!", "element", ".", "parentNode", ")", "{", "return", "this", ".", "destroy", "(", ")", ";", "}", "var", "images", "=", "[", "]", ";", "forEach", "(", "isImg", "?", "[", "element", "]", ":", "element", ".", "querySelectorAll", "(", "'img'", ")", ",", "function", "(", "image", ")", "{", "if", "(", "options", ".", "filter", ")", "{", "if", "(", "options", ".", "filter", "(", "image", ")", ")", "{", "images", ".", "push", "(", "image", ")", ";", "}", "}", "else", "{", "images", ".", "push", "(", "image", ")", ";", "}", "}", ")", ";", "if", "(", "!", "images", ".", "length", ")", "{", "return", "this", ";", "}", "this", ".", "images", "=", "images", ";", "this", ".", "length", "=", "images", ".", "length", ";", "if", "(", "this", ".", "ready", ")", "{", "var", "indexes", "=", "[", "]", ";", "forEach", "(", "this", ".", "items", ",", "function", "(", "item", ",", "i", ")", "{", "var", "img", "=", "item", ".", "querySelector", "(", "'img'", ")", ";", "var", "image", "=", "images", "[", "i", "]", ";", "if", "(", "image", ")", "{", "if", "(", "image", ".", "src", "!==", "img", ".", "src", ")", "{", "indexes", ".", "push", "(", "i", ")", ";", "}", "}", "else", "{", "indexes", ".", "push", "(", "i", ")", ";", "}", "}", ")", ";", "setStyle", "(", "this", ".", "list", ",", "{", "width", ":", "'auto'", "}", ")", ";", "this", ".", "initList", "(", ")", ";", "if", "(", "this", ".", "isShown", ")", "{", "if", "(", "this", ".", "length", ")", "{", "if", "(", "this", ".", "viewed", ")", "{", "var", "index", "=", "indexes", ".", "indexOf", "(", "this", ".", "index", ")", ";", "if", "(", "index", ">=", "0", ")", "{", "this", ".", "viewed", "=", "false", ";", "this", ".", "view", "(", "Math", ".", "max", "(", "this", ".", "index", "-", "(", "index", "+", "1", ")", ",", "0", ")", ")", ";", "}", "else", "{", "addClass", "(", "this", ".", "items", "[", "this", ".", "index", "]", ",", "CLASS_ACTIVE", ")", ";", "}", "}", "}", "else", "{", "this", ".", "image", "=", "null", ";", "this", ".", "viewed", "=", "false", ";", "this", ".", "index", "=", "0", ";", "this", ".", "imageData", "=", "null", ";", "this", ".", "canvas", ".", "innerHTML", "=", "''", ";", "this", ".", "title", ".", "innerHTML", "=", "''", ";", "}", "}", "}", "else", "{", "this", ".", "build", "(", ")", ";", "}", "return", "this", ";", "}" ]
Update viewer when images changed
[ "Update", "viewer", "when", "images", "changed" ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L2344-L2422
10,957
fengyuanchen/viewer
dist/viewer.common.js
destroy
function destroy() { var element = this.element, options = this.options; if (!getData(element, NAMESPACE)) { return this; } this.destroyed = true; if (this.ready) { if (this.played) { this.stop(); } if (options.inline) { if (this.fulled) { this.exit(); } this.unbind(); } else if (this.isShown) { if (this.viewing) { if (this.imageRendering) { this.imageRendering.abort(); } else if (this.imageInitializing) { this.imageInitializing.abort(); } } if (this.hiding) { this.transitioning.abort(); } this.hidden(); } else if (this.showing) { this.transitioning.abort(); this.hidden(); } this.ready = false; this.viewer.parentNode.removeChild(this.viewer); } else if (options.inline) { if (this.delaying) { this.delaying.abort(); } else if (this.initializing) { this.initializing.abort(); } } if (!options.inline) { removeListener(element, EVENT_CLICK, this.onStart); } removeData(element, NAMESPACE); return this; }
javascript
function destroy() { var element = this.element, options = this.options; if (!getData(element, NAMESPACE)) { return this; } this.destroyed = true; if (this.ready) { if (this.played) { this.stop(); } if (options.inline) { if (this.fulled) { this.exit(); } this.unbind(); } else if (this.isShown) { if (this.viewing) { if (this.imageRendering) { this.imageRendering.abort(); } else if (this.imageInitializing) { this.imageInitializing.abort(); } } if (this.hiding) { this.transitioning.abort(); } this.hidden(); } else if (this.showing) { this.transitioning.abort(); this.hidden(); } this.ready = false; this.viewer.parentNode.removeChild(this.viewer); } else if (options.inline) { if (this.delaying) { this.delaying.abort(); } else if (this.initializing) { this.initializing.abort(); } } if (!options.inline) { removeListener(element, EVENT_CLICK, this.onStart); } removeData(element, NAMESPACE); return this; }
[ "function", "destroy", "(", ")", "{", "var", "element", "=", "this", ".", "element", ",", "options", "=", "this", ".", "options", ";", "if", "(", "!", "getData", "(", "element", ",", "NAMESPACE", ")", ")", "{", "return", "this", ";", "}", "this", ".", "destroyed", "=", "true", ";", "if", "(", "this", ".", "ready", ")", "{", "if", "(", "this", ".", "played", ")", "{", "this", ".", "stop", "(", ")", ";", "}", "if", "(", "options", ".", "inline", ")", "{", "if", "(", "this", ".", "fulled", ")", "{", "this", ".", "exit", "(", ")", ";", "}", "this", ".", "unbind", "(", ")", ";", "}", "else", "if", "(", "this", ".", "isShown", ")", "{", "if", "(", "this", ".", "viewing", ")", "{", "if", "(", "this", ".", "imageRendering", ")", "{", "this", ".", "imageRendering", ".", "abort", "(", ")", ";", "}", "else", "if", "(", "this", ".", "imageInitializing", ")", "{", "this", ".", "imageInitializing", ".", "abort", "(", ")", ";", "}", "}", "if", "(", "this", ".", "hiding", ")", "{", "this", ".", "transitioning", ".", "abort", "(", ")", ";", "}", "this", ".", "hidden", "(", ")", ";", "}", "else", "if", "(", "this", ".", "showing", ")", "{", "this", ".", "transitioning", ".", "abort", "(", ")", ";", "this", ".", "hidden", "(", ")", ";", "}", "this", ".", "ready", "=", "false", ";", "this", ".", "viewer", ".", "parentNode", ".", "removeChild", "(", "this", ".", "viewer", ")", ";", "}", "else", "if", "(", "options", ".", "inline", ")", "{", "if", "(", "this", ".", "delaying", ")", "{", "this", ".", "delaying", ".", "abort", "(", ")", ";", "}", "else", "if", "(", "this", ".", "initializing", ")", "{", "this", ".", "initializing", ".", "abort", "(", ")", ";", "}", "}", "if", "(", "!", "options", ".", "inline", ")", "{", "removeListener", "(", "element", ",", "EVENT_CLICK", ",", "this", ".", "onStart", ")", ";", "}", "removeData", "(", "element", ",", "NAMESPACE", ")", ";", "return", "this", ";", "}" ]
Destroy the viewer
[ "Destroy", "the", "viewer" ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L2426-L2483
10,958
fengyuanchen/viewer
dist/viewer.common.js
Viewer
function Viewer(element) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; classCallCheck(this, Viewer); if (!element || element.nodeType !== 1) { throw new Error('The first argument is required and must be an element.'); } this.element = element; this.options = assign({}, DEFAULTS, isPlainObject(options) && options); this.action = false; this.fading = false; this.fulled = false; this.hiding = false; this.index = 0; this.isImg = false; this.length = 0; this.played = false; this.playing = false; this.pointers = {}; this.ready = false; this.showing = false; this.timeout = false; this.tooltipping = false; this.viewed = false; this.viewing = false; this.isShown = false; this.wheeling = false; this.init(); }
javascript
function Viewer(element) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; classCallCheck(this, Viewer); if (!element || element.nodeType !== 1) { throw new Error('The first argument is required and must be an element.'); } this.element = element; this.options = assign({}, DEFAULTS, isPlainObject(options) && options); this.action = false; this.fading = false; this.fulled = false; this.hiding = false; this.index = 0; this.isImg = false; this.length = 0; this.played = false; this.playing = false; this.pointers = {}; this.ready = false; this.showing = false; this.timeout = false; this.tooltipping = false; this.viewed = false; this.viewing = false; this.isShown = false; this.wheeling = false; this.init(); }
[ "function", "Viewer", "(", "element", ")", "{", "var", "options", "=", "arguments", ".", "length", ">", "1", "&&", "arguments", "[", "1", "]", "!==", "undefined", "?", "arguments", "[", "1", "]", ":", "{", "}", ";", "classCallCheck", "(", "this", ",", "Viewer", ")", ";", "if", "(", "!", "element", "||", "element", ".", "nodeType", "!==", "1", ")", "{", "throw", "new", "Error", "(", "'The first argument is required and must be an element.'", ")", ";", "}", "this", ".", "element", "=", "element", ";", "this", ".", "options", "=", "assign", "(", "{", "}", ",", "DEFAULTS", ",", "isPlainObject", "(", "options", ")", "&&", "options", ")", ";", "this", ".", "action", "=", "false", ";", "this", ".", "fading", "=", "false", ";", "this", ".", "fulled", "=", "false", ";", "this", ".", "hiding", "=", "false", ";", "this", ".", "index", "=", "0", ";", "this", ".", "isImg", "=", "false", ";", "this", ".", "length", "=", "0", ";", "this", ".", "played", "=", "false", ";", "this", ".", "playing", "=", "false", ";", "this", ".", "pointers", "=", "{", "}", ";", "this", ".", "ready", "=", "false", ";", "this", ".", "showing", "=", "false", ";", "this", ".", "timeout", "=", "false", ";", "this", ".", "tooltipping", "=", "false", ";", "this", ".", "viewed", "=", "false", ";", "this", ".", "viewing", "=", "false", ";", "this", ".", "isShown", "=", "false", ";", "this", ".", "wheeling", "=", "false", ";", "this", ".", "init", "(", ")", ";", "}" ]
Create a new Viewer. @param {Element} element - The target element for viewing. @param {Object} [options={}] - The configuration options.
[ "Create", "a", "new", "Viewer", "." ]
b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd
https://github.com/fengyuanchen/viewer/blob/b6b1168eeb25812e6a39c0eba9ec6fb788f8cefd/dist/viewer.common.js#L2646-L2675
10,959
jonathantneal/flexibility
lib/read/index.js
read
function read(element) { // normalized style var style = { alignContent: 'stretch', alignItems: 'stretch', alignSelf: 'auto', borderBottomStyle: 'none', borderBottomWidth: 0, borderLeftStyle: 'none', borderLeftWidth: 0, borderRightStyle: 'none', borderRightWidth: 0, borderTopStyle: 'none', borderTopWidth: 0, boxSizing: 'content-box', display: 'inline', flexBasis: 'auto', flexDirection: 'row', flexGrow: 0, flexShrink: 1, flexWrap: 'nowrap', justifyContent: 'flex-start', height: 'auto', marginTop: 0, marginRight: 0, marginLeft: 0, marginBottom: 0, paddingTop: 0, paddingRight: 0, paddingLeft: 0, paddingBottom: 0, maxHeight: 'none', maxWidth: 'none', minHeight: 0, minWidth: 0, order: 0, position: 'static', width: 'auto' }; // whether element is an element var isElement = element instanceof Element; if (isElement) { // whether element has data-style attribute var hasDataStyleAttr = element.hasAttribute('data-style'); // inline style from data-style or style var inlineStyle = hasDataStyleAttr ? element.getAttribute('data-style') : element.getAttribute('style') || ''; if (!hasDataStyleAttr) { // copy style to data-style element.setAttribute('data-style', inlineStyle); } // append computed style to style var computedStyle = window.getComputedStyle && getComputedStyle(element) || {}; appendComputedStyle(style, computedStyle); // append current style to style var currentStyle = element.currentStyle || {}; appendCurrentStyle(style, currentStyle); // append inline style to style appendInlineStyle(style, inlineStyle); // for each camel-case property for (var prop in style) { style[prop] = getComputedLength(style, prop, element); } // offset measurements var boundingClientRect = element.getBoundingClientRect(); style.offsetHeight = boundingClientRect.height || element.offsetHeight; style.offsetWidth = boundingClientRect.width || element.offsetWidth; } var details = { element: element, style: style }; return details; }
javascript
function read(element) { // normalized style var style = { alignContent: 'stretch', alignItems: 'stretch', alignSelf: 'auto', borderBottomStyle: 'none', borderBottomWidth: 0, borderLeftStyle: 'none', borderLeftWidth: 0, borderRightStyle: 'none', borderRightWidth: 0, borderTopStyle: 'none', borderTopWidth: 0, boxSizing: 'content-box', display: 'inline', flexBasis: 'auto', flexDirection: 'row', flexGrow: 0, flexShrink: 1, flexWrap: 'nowrap', justifyContent: 'flex-start', height: 'auto', marginTop: 0, marginRight: 0, marginLeft: 0, marginBottom: 0, paddingTop: 0, paddingRight: 0, paddingLeft: 0, paddingBottom: 0, maxHeight: 'none', maxWidth: 'none', minHeight: 0, minWidth: 0, order: 0, position: 'static', width: 'auto' }; // whether element is an element var isElement = element instanceof Element; if (isElement) { // whether element has data-style attribute var hasDataStyleAttr = element.hasAttribute('data-style'); // inline style from data-style or style var inlineStyle = hasDataStyleAttr ? element.getAttribute('data-style') : element.getAttribute('style') || ''; if (!hasDataStyleAttr) { // copy style to data-style element.setAttribute('data-style', inlineStyle); } // append computed style to style var computedStyle = window.getComputedStyle && getComputedStyle(element) || {}; appendComputedStyle(style, computedStyle); // append current style to style var currentStyle = element.currentStyle || {}; appendCurrentStyle(style, currentStyle); // append inline style to style appendInlineStyle(style, inlineStyle); // for each camel-case property for (var prop in style) { style[prop] = getComputedLength(style, prop, element); } // offset measurements var boundingClientRect = element.getBoundingClientRect(); style.offsetHeight = boundingClientRect.height || element.offsetHeight; style.offsetWidth = boundingClientRect.width || element.offsetWidth; } var details = { element: element, style: style }; return details; }
[ "function", "read", "(", "element", ")", "{", "// normalized style", "var", "style", "=", "{", "alignContent", ":", "'stretch'", ",", "alignItems", ":", "'stretch'", ",", "alignSelf", ":", "'auto'", ",", "borderBottomStyle", ":", "'none'", ",", "borderBottomWidth", ":", "0", ",", "borderLeftStyle", ":", "'none'", ",", "borderLeftWidth", ":", "0", ",", "borderRightStyle", ":", "'none'", ",", "borderRightWidth", ":", "0", ",", "borderTopStyle", ":", "'none'", ",", "borderTopWidth", ":", "0", ",", "boxSizing", ":", "'content-box'", ",", "display", ":", "'inline'", ",", "flexBasis", ":", "'auto'", ",", "flexDirection", ":", "'row'", ",", "flexGrow", ":", "0", ",", "flexShrink", ":", "1", ",", "flexWrap", ":", "'nowrap'", ",", "justifyContent", ":", "'flex-start'", ",", "height", ":", "'auto'", ",", "marginTop", ":", "0", ",", "marginRight", ":", "0", ",", "marginLeft", ":", "0", ",", "marginBottom", ":", "0", ",", "paddingTop", ":", "0", ",", "paddingRight", ":", "0", ",", "paddingLeft", ":", "0", ",", "paddingBottom", ":", "0", ",", "maxHeight", ":", "'none'", ",", "maxWidth", ":", "'none'", ",", "minHeight", ":", "0", ",", "minWidth", ":", "0", ",", "order", ":", "0", ",", "position", ":", "'static'", ",", "width", ":", "'auto'", "}", ";", "// whether element is an element", "var", "isElement", "=", "element", "instanceof", "Element", ";", "if", "(", "isElement", ")", "{", "// whether element has data-style attribute", "var", "hasDataStyleAttr", "=", "element", ".", "hasAttribute", "(", "'data-style'", ")", ";", "// inline style from data-style or style", "var", "inlineStyle", "=", "hasDataStyleAttr", "?", "element", ".", "getAttribute", "(", "'data-style'", ")", ":", "element", ".", "getAttribute", "(", "'style'", ")", "||", "''", ";", "if", "(", "!", "hasDataStyleAttr", ")", "{", "// copy style to data-style", "element", ".", "setAttribute", "(", "'data-style'", ",", "inlineStyle", ")", ";", "}", "// append computed style to style", "var", "computedStyle", "=", "window", ".", "getComputedStyle", "&&", "getComputedStyle", "(", "element", ")", "||", "{", "}", ";", "appendComputedStyle", "(", "style", ",", "computedStyle", ")", ";", "// append current style to style", "var", "currentStyle", "=", "element", ".", "currentStyle", "||", "{", "}", ";", "appendCurrentStyle", "(", "style", ",", "currentStyle", ")", ";", "// append inline style to style", "appendInlineStyle", "(", "style", ",", "inlineStyle", ")", ";", "// for each camel-case property", "for", "(", "var", "prop", "in", "style", ")", "{", "style", "[", "prop", "]", "=", "getComputedLength", "(", "style", ",", "prop", ",", "element", ")", ";", "}", "// offset measurements", "var", "boundingClientRect", "=", "element", ".", "getBoundingClientRect", "(", ")", ";", "style", ".", "offsetHeight", "=", "boundingClientRect", ".", "height", "||", "element", ".", "offsetHeight", ";", "style", ".", "offsetWidth", "=", "boundingClientRect", ".", "width", "||", "element", ".", "offsetWidth", ";", "}", "var", "details", "=", "{", "element", ":", "element", ",", "style", ":", "style", "}", ";", "return", "details", ";", "}" ]
Return flexbox related details of an element
[ "Return", "flexbox", "related", "details", "of", "an", "element" ]
c7cbaf26c39ba1c0947d16b05d95c8ac9ce022fb
https://github.com/jonathantneal/flexibility/blob/c7cbaf26c39ba1c0947d16b05d95c8ac9ce022fb/lib/read/index.js#L10-L96
10,960
ampproject/amp-by-example
templates/embed/embed.js
fitPreviewToContent
function fitPreviewToContent() { var iframeDoc = preview.contentDocument || preview.contentWindow.document; setPreviewHeight(iframeDoc.body.offsetHeight); }
javascript
function fitPreviewToContent() { var iframeDoc = preview.contentDocument || preview.contentWindow.document; setPreviewHeight(iframeDoc.body.offsetHeight); }
[ "function", "fitPreviewToContent", "(", ")", "{", "var", "iframeDoc", "=", "preview", ".", "contentDocument", "||", "preview", ".", "contentWindow", ".", "document", ";", "setPreviewHeight", "(", "iframeDoc", ".", "body", ".", "offsetHeight", ")", ";", "}" ]
Adjusts the iframe height based on the iframe's document height. The width is unchanged.
[ "Adjusts", "the", "iframe", "height", "based", "on", "the", "iframe", "s", "document", "height", ".", "The", "width", "is", "unchanged", "." ]
76267b11e3a8888c872ce4f306afdcdec959d5c1
https://github.com/ampproject/amp-by-example/blob/76267b11e3a8888c872ce4f306afdcdec959d5c1/templates/embed/embed.js#L35-L38
10,961
ampproject/amp-by-example
templates/embed/embed.js
postEmbedHeightToViewer
function postEmbedHeightToViewer() { var newHeight = document.getElementById('tabinterface').clientHeight; if (newHeight < MIN_IFRAME_HEIGHT) { console.log('embed height too small, reset height to 100px'); newHeight = MIN_IFRAME_HEIGHT; } // Tell the viewer about the new size window.parent.postMessage({ sentinel: 'amp', type: 'embed-size', height: newHeight }, '*'); }
javascript
function postEmbedHeightToViewer() { var newHeight = document.getElementById('tabinterface').clientHeight; if (newHeight < MIN_IFRAME_HEIGHT) { console.log('embed height too small, reset height to 100px'); newHeight = MIN_IFRAME_HEIGHT; } // Tell the viewer about the new size window.parent.postMessage({ sentinel: 'amp', type: 'embed-size', height: newHeight }, '*'); }
[ "function", "postEmbedHeightToViewer", "(", ")", "{", "var", "newHeight", "=", "document", ".", "getElementById", "(", "'tabinterface'", ")", ".", "clientHeight", ";", "if", "(", "newHeight", "<", "MIN_IFRAME_HEIGHT", ")", "{", "console", ".", "log", "(", "'embed height too small, reset height to 100px'", ")", ";", "newHeight", "=", "MIN_IFRAME_HEIGHT", ";", "}", "// Tell the viewer about the new size", "window", ".", "parent", ".", "postMessage", "(", "{", "sentinel", ":", "'amp'", ",", "type", ":", "'embed-size'", ",", "height", ":", "newHeight", "}", ",", "'*'", ")", ";", "}" ]
Post a message containing the document height to the amp-iframe to trigger the resize.
[ "Post", "a", "message", "containing", "the", "document", "height", "to", "the", "amp", "-", "iframe", "to", "trigger", "the", "resize", "." ]
76267b11e3a8888c872ce4f306afdcdec959d5c1
https://github.com/ampproject/amp-by-example/blob/76267b11e3a8888c872ce4f306afdcdec959d5c1/templates/embed/embed.js#L43-L55
10,962
ampproject/amp-by-example
static/sw.js
offlineImage
function offlineImage(name, width, height) { return `<?xml version="1.0"?> <svg width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" xmlns="http://www.w3.org/2000/svg" version="1.1"> <g fill="none" fill-rule="evenodd"><path fill="#F8BBD0" d="M0 0h${width}v${height}H0z"/></g> <text text-anchor="middle" x="${Math.floor(width / 2)}" y="${Math.floor(height / 2)}">image offline (${name})</text> <style><![CDATA[ text{ font: 48px Roboto,Verdana, Helvetica, Arial, sans-serif; } ]]></style> </svg>`; }
javascript
function offlineImage(name, width, height) { return `<?xml version="1.0"?> <svg width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" xmlns="http://www.w3.org/2000/svg" version="1.1"> <g fill="none" fill-rule="evenodd"><path fill="#F8BBD0" d="M0 0h${width}v${height}H0z"/></g> <text text-anchor="middle" x="${Math.floor(width / 2)}" y="${Math.floor(height / 2)}">image offline (${name})</text> <style><![CDATA[ text{ font: 48px Roboto,Verdana, Helvetica, Arial, sans-serif; } ]]></style> </svg>`; }
[ "function", "offlineImage", "(", "name", ",", "width", ",", "height", ")", "{", "return", "`", "${", "width", "}", "${", "height", "}", "${", "width", "}", "${", "height", "}", "${", "width", "}", "${", "height", "}", "${", "Math", ".", "floor", "(", "width", "/", "2", ")", "}", "${", "Math", ".", "floor", "(", "height", "/", "2", ")", "}", "${", "name", "}", "`", ";", "}" ]
Generates a placeholder SVG image of the given size.
[ "Generates", "a", "placeholder", "SVG", "image", "of", "the", "given", "size", "." ]
76267b11e3a8888c872ce4f306afdcdec959d5c1
https://github.com/ampproject/amp-by-example/blob/76267b11e3a8888c872ce4f306afdcdec959d5c1/static/sw.js#L53-L65
10,963
ampproject/amp-by-example
static/sw.js
onMessageReceivedSubscriptionState
function onMessageReceivedSubscriptionState() { let retrievedPushSubscription = null; self.registration.pushManager.getSubscription() .then(pushSubscription => { retrievedPushSubscription = pushSubscription; if (!pushSubscription) { return null; } else { return self.registration.pushManager.permissionState( pushSubscription.options ); } }).then(permissionStateOrNull => { if (permissionStateOrNull == null) { broadcastReply(WorkerMessengerCommand.AMP_SUBSCRIPTION_STATE, false); } else { const isSubscribed = !!retrievedPushSubscription && permissionStateOrNull === 'granted'; broadcastReply(WorkerMessengerCommand.AMP_SUBSCRIPTION_STATE, isSubscribed); } }); }
javascript
function onMessageReceivedSubscriptionState() { let retrievedPushSubscription = null; self.registration.pushManager.getSubscription() .then(pushSubscription => { retrievedPushSubscription = pushSubscription; if (!pushSubscription) { return null; } else { return self.registration.pushManager.permissionState( pushSubscription.options ); } }).then(permissionStateOrNull => { if (permissionStateOrNull == null) { broadcastReply(WorkerMessengerCommand.AMP_SUBSCRIPTION_STATE, false); } else { const isSubscribed = !!retrievedPushSubscription && permissionStateOrNull === 'granted'; broadcastReply(WorkerMessengerCommand.AMP_SUBSCRIPTION_STATE, isSubscribed); } }); }
[ "function", "onMessageReceivedSubscriptionState", "(", ")", "{", "let", "retrievedPushSubscription", "=", "null", ";", "self", ".", "registration", ".", "pushManager", ".", "getSubscription", "(", ")", ".", "then", "(", "pushSubscription", "=>", "{", "retrievedPushSubscription", "=", "pushSubscription", ";", "if", "(", "!", "pushSubscription", ")", "{", "return", "null", ";", "}", "else", "{", "return", "self", ".", "registration", ".", "pushManager", ".", "permissionState", "(", "pushSubscription", ".", "options", ")", ";", "}", "}", ")", ".", "then", "(", "permissionStateOrNull", "=>", "{", "if", "(", "permissionStateOrNull", "==", "null", ")", "{", "broadcastReply", "(", "WorkerMessengerCommand", ".", "AMP_SUBSCRIPTION_STATE", ",", "false", ")", ";", "}", "else", "{", "const", "isSubscribed", "=", "!", "!", "retrievedPushSubscription", "&&", "permissionStateOrNull", "===", "'granted'", ";", "broadcastReply", "(", "WorkerMessengerCommand", ".", "AMP_SUBSCRIPTION_STATE", ",", "isSubscribed", ")", ";", "}", "}", ")", ";", "}" ]
Broadcasts a single boolean describing whether the user is subscribed.
[ "Broadcasts", "a", "single", "boolean", "describing", "whether", "the", "user", "is", "subscribed", "." ]
76267b11e3a8888c872ce4f306afdcdec959d5c1
https://github.com/ampproject/amp-by-example/blob/76267b11e3a8888c872ce4f306afdcdec959d5c1/static/sw.js#L272-L294
10,964
ampproject/amp-by-example
static/sw.js
persistSubscriptionLocally
function persistSubscriptionLocally(subscription) { let subscriptionJSON = JSON.stringify(subscription); idb.open('web-push-db', 1).then(db => { let tx = db.transaction(['web-push-subcription'], 'readwrite'); tx.objectStore('web-push-subcription').put({ id: 1, data: subscriptionJSON }); return tx.complete; }); }
javascript
function persistSubscriptionLocally(subscription) { let subscriptionJSON = JSON.stringify(subscription); idb.open('web-push-db', 1).then(db => { let tx = db.transaction(['web-push-subcription'], 'readwrite'); tx.objectStore('web-push-subcription').put({ id: 1, data: subscriptionJSON }); return tx.complete; }); }
[ "function", "persistSubscriptionLocally", "(", "subscription", ")", "{", "let", "subscriptionJSON", "=", "JSON", ".", "stringify", "(", "subscription", ")", ";", "idb", ".", "open", "(", "'web-push-db'", ",", "1", ")", ".", "then", "(", "db", "=>", "{", "let", "tx", "=", "db", ".", "transaction", "(", "[", "'web-push-subcription'", "]", ",", "'readwrite'", ")", ";", "tx", ".", "objectStore", "(", "'web-push-subcription'", ")", ".", "put", "(", "{", "id", ":", "1", ",", "data", ":", "subscriptionJSON", "}", ")", ";", "return", "tx", ".", "complete", ";", "}", ")", ";", "}" ]
Helper functions for IndexedDB management. Persists the subscription object in IndexedDB.
[ "Helper", "functions", "for", "IndexedDB", "management", ".", "Persists", "the", "subscription", "object", "in", "IndexedDB", "." ]
76267b11e3a8888c872ce4f306afdcdec959d5c1
https://github.com/ampproject/amp-by-example/blob/76267b11e3a8888c872ce4f306afdcdec959d5c1/static/sw.js#L358-L368
10,965
ampproject/amp-by-example
static/sw.js
urlB64ToUint8Array
function urlB64ToUint8Array(base64String) { const padding = '='.repeat((4 - base64String.length % 4) % 4); const base64 = (base64String + padding) .replace(/\-/g, '+') .replace(/_/g, '/'); const rawData = self.atob(base64); const outputArray = new Uint8Array(rawData.length); for (let i = 0; i < rawData.length; ++i) { outputArray[i] = rawData.charCodeAt(i); } return outputArray; }
javascript
function urlB64ToUint8Array(base64String) { const padding = '='.repeat((4 - base64String.length % 4) % 4); const base64 = (base64String + padding) .replace(/\-/g, '+') .replace(/_/g, '/'); const rawData = self.atob(base64); const outputArray = new Uint8Array(rawData.length); for (let i = 0; i < rawData.length; ++i) { outputArray[i] = rawData.charCodeAt(i); } return outputArray; }
[ "function", "urlB64ToUint8Array", "(", "base64String", ")", "{", "const", "padding", "=", "'='", ".", "repeat", "(", "(", "4", "-", "base64String", ".", "length", "%", "4", ")", "%", "4", ")", ";", "const", "base64", "=", "(", "base64String", "+", "padding", ")", ".", "replace", "(", "/", "\\-", "/", "g", ",", "'+'", ")", ".", "replace", "(", "/", "_", "/", "g", ",", "'/'", ")", ";", "const", "rawData", "=", "self", ".", "atob", "(", "base64", ")", ";", "const", "outputArray", "=", "new", "Uint8Array", "(", "rawData", ".", "length", ")", ";", "for", "(", "let", "i", "=", "0", ";", "i", "<", "rawData", ".", "length", ";", "++", "i", ")", "{", "outputArray", "[", "i", "]", "=", "rawData", ".", "charCodeAt", "(", "i", ")", ";", "}", "return", "outputArray", ";", "}" ]
Helper method to convert the VAPID key to a UInt8 array and supply it to applicationServerKey.
[ "Helper", "method", "to", "convert", "the", "VAPID", "key", "to", "a", "UInt8", "array", "and", "supply", "it", "to", "applicationServerKey", "." ]
76267b11e3a8888c872ce4f306afdcdec959d5c1
https://github.com/ampproject/amp-by-example/blob/76267b11e3a8888c872ce4f306afdcdec959d5c1/static/sw.js#L384-L397
10,966
ampproject/amp-by-example
lib/Preview.js
generateEmbeds
function generateEmbeds(config) { glob(config.src + '/**/*.html', {}, (err, files) => { files.forEach(file => generateEmbed(config, file)); }); }
javascript
function generateEmbeds(config) { glob(config.src + '/**/*.html', {}, (err, files) => { files.forEach(file => generateEmbed(config, file)); }); }
[ "function", "generateEmbeds", "(", "config", ")", "{", "glob", "(", "config", ".", "src", "+", "'/**/*.html'", ",", "{", "}", ",", "(", "err", ",", "files", ")", "=>", "{", "files", ".", "forEach", "(", "file", "=>", "generateEmbed", "(", "config", ",", "file", ")", ")", ";", "}", ")", ";", "}" ]
Reads all html files in a folder and generates the embeds.
[ "Reads", "all", "html", "files", "in", "a", "folder", "and", "generates", "the", "embeds", "." ]
76267b11e3a8888c872ce4f306afdcdec959d5c1
https://github.com/ampproject/amp-by-example/blob/76267b11e3a8888c872ce4f306afdcdec959d5c1/lib/Preview.js#L68-L72
10,967
ampproject/amp-by-example
lib/Preview.js
generateEmbed
function generateEmbed(config, file) { const targetPath = path.join(config.destDir, path.relative(config.src, file)); const document = parseDocument(file); const sampleSections = document.sections.filter( s => s.inBody && !s.isEmptyCodeSection() ); sampleSections.forEach((section, index) => { highlight(section.codeSnippet()).then(code => { const tag = section.doc ? slug(section.doc.toLowerCase()) : index; const context = { sample: { file: path.basename(targetPath), preview: addFlag(targetPath, tag, 'preview'), embed: addFlag(targetPath, tag, 'embed'), template: addFlag(targetPath, tag, 'template'), body: section.code, code: code, }, config: config, document: document, }; generate(context.sample.preview, templates.preview, context, /* minify */ true); generate(context.sample.embed, templates.embed, context, /* minify */ true); generateTemplate(context); }); }); }
javascript
function generateEmbed(config, file) { const targetPath = path.join(config.destDir, path.relative(config.src, file)); const document = parseDocument(file); const sampleSections = document.sections.filter( s => s.inBody && !s.isEmptyCodeSection() ); sampleSections.forEach((section, index) => { highlight(section.codeSnippet()).then(code => { const tag = section.doc ? slug(section.doc.toLowerCase()) : index; const context = { sample: { file: path.basename(targetPath), preview: addFlag(targetPath, tag, 'preview'), embed: addFlag(targetPath, tag, 'embed'), template: addFlag(targetPath, tag, 'template'), body: section.code, code: code, }, config: config, document: document, }; generate(context.sample.preview, templates.preview, context, /* minify */ true); generate(context.sample.embed, templates.embed, context, /* minify */ true); generateTemplate(context); }); }); }
[ "function", "generateEmbed", "(", "config", ",", "file", ")", "{", "const", "targetPath", "=", "path", ".", "join", "(", "config", ".", "destDir", ",", "path", ".", "relative", "(", "config", ".", "src", ",", "file", ")", ")", ";", "const", "document", "=", "parseDocument", "(", "file", ")", ";", "const", "sampleSections", "=", "document", ".", "sections", ".", "filter", "(", "s", "=>", "s", ".", "inBody", "&&", "!", "s", ".", "isEmptyCodeSection", "(", ")", ")", ";", "sampleSections", ".", "forEach", "(", "(", "section", ",", "index", ")", "=>", "{", "highlight", "(", "section", ".", "codeSnippet", "(", ")", ")", ".", "then", "(", "code", "=>", "{", "const", "tag", "=", "section", ".", "doc", "?", "slug", "(", "section", ".", "doc", ".", "toLowerCase", "(", ")", ")", ":", "index", ";", "const", "context", "=", "{", "sample", ":", "{", "file", ":", "path", ".", "basename", "(", "targetPath", ")", ",", "preview", ":", "addFlag", "(", "targetPath", ",", "tag", ",", "'preview'", ")", ",", "embed", ":", "addFlag", "(", "targetPath", ",", "tag", ",", "'embed'", ")", ",", "template", ":", "addFlag", "(", "targetPath", ",", "tag", ",", "'template'", ")", ",", "body", ":", "section", ".", "code", ",", "code", ":", "code", ",", "}", ",", "config", ":", "config", ",", "document", ":", "document", ",", "}", ";", "generate", "(", "context", ".", "sample", ".", "preview", ",", "templates", ".", "preview", ",", "context", ",", "/* minify */", "true", ")", ";", "generate", "(", "context", ".", "sample", ".", "embed", ",", "templates", ".", "embed", ",", "context", ",", "/* minify */", "true", ")", ";", "generateTemplate", "(", "context", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Generates embeds for a given file.
[ "Generates", "embeds", "for", "a", "given", "file", "." ]
76267b11e3a8888c872ce4f306afdcdec959d5c1
https://github.com/ampproject/amp-by-example/blob/76267b11e3a8888c872ce4f306afdcdec959d5c1/lib/Preview.js#L77-L103
10,968
ampproject/amp-by-example
lib/Preview.js
highlight
function highlight(code) { return new Promise((resolve, reject) => { pygmentize({ lang: 'html', format: 'html' }, code, function (err, result) { if (err) { console.log(err); reject(err); } else { resolve(result.toString()); }; }); }); }
javascript
function highlight(code) { return new Promise((resolve, reject) => { pygmentize({ lang: 'html', format: 'html' }, code, function (err, result) { if (err) { console.log(err); reject(err); } else { resolve(result.toString()); }; }); }); }
[ "function", "highlight", "(", "code", ")", "{", "return", "new", "Promise", "(", "(", "resolve", ",", "reject", ")", "=>", "{", "pygmentize", "(", "{", "lang", ":", "'html'", ",", "format", ":", "'html'", "}", ",", "code", ",", "function", "(", "err", ",", "result", ")", "{", "if", "(", "err", ")", "{", "console", ".", "log", "(", "err", ")", ";", "reject", "(", "err", ")", ";", "}", "else", "{", "resolve", "(", "result", ".", "toString", "(", ")", ")", ";", "}", ";", "}", ")", ";", "}", ")", ";", "}" ]
Syntax highlights a string.
[ "Syntax", "highlights", "a", "string", "." ]
76267b11e3a8888c872ce4f306afdcdec959d5c1
https://github.com/ampproject/amp-by-example/blob/76267b11e3a8888c872ce4f306afdcdec959d5c1/lib/Preview.js#L108-L119
10,969
ampproject/amp-by-example
lib/Preview.js
generate
function generate(file, template, context, minifyResult) { let string = template.render(context, { 'styles.css': templates.styles, 'embed.js': templates.embedJs }); if (minifyResult) { string = minify(string, { caseSensitive: true, collapseWhitespace: true, html5: true, minifyCSS: true, minifyJS: true, removeComments: true, removeAttributeQuotes: true }); }; writeFile(path.join(context.config.destRoot, file), string); }
javascript
function generate(file, template, context, minifyResult) { let string = template.render(context, { 'styles.css': templates.styles, 'embed.js': templates.embedJs }); if (minifyResult) { string = minify(string, { caseSensitive: true, collapseWhitespace: true, html5: true, minifyCSS: true, minifyJS: true, removeComments: true, removeAttributeQuotes: true }); }; writeFile(path.join(context.config.destRoot, file), string); }
[ "function", "generate", "(", "file", ",", "template", ",", "context", ",", "minifyResult", ")", "{", "let", "string", "=", "template", ".", "render", "(", "context", ",", "{", "'styles.css'", ":", "templates", ".", "styles", ",", "'embed.js'", ":", "templates", ".", "embedJs", "}", ")", ";", "if", "(", "minifyResult", ")", "{", "string", "=", "minify", "(", "string", ",", "{", "caseSensitive", ":", "true", ",", "collapseWhitespace", ":", "true", ",", "html5", ":", "true", ",", "minifyCSS", ":", "true", ",", "minifyJS", ":", "true", ",", "removeComments", ":", "true", ",", "removeAttributeQuotes", ":", "true", "}", ")", ";", "}", ";", "writeFile", "(", "path", ".", "join", "(", "context", ".", "config", ".", "destRoot", ",", "file", ")", ",", "string", ")", ";", "}" ]
Renders the given template into a file.
[ "Renders", "the", "given", "template", "into", "a", "file", "." ]
76267b11e3a8888c872ce4f306afdcdec959d5c1
https://github.com/ampproject/amp-by-example/blob/76267b11e3a8888c872ce4f306afdcdec959d5c1/lib/Preview.js#L124-L141
10,970
ampproject/amp-by-example
lib/Preview.js
addFlag
function addFlag() { const filename = arguments[0]; const postfix = [].slice.call(arguments, 1).join('.'); return filename.replace('.html', '.' + postfix + '.html'); }
javascript
function addFlag() { const filename = arguments[0]; const postfix = [].slice.call(arguments, 1).join('.'); return filename.replace('.html', '.' + postfix + '.html'); }
[ "function", "addFlag", "(", ")", "{", "const", "filename", "=", "arguments", "[", "0", "]", ";", "const", "postfix", "=", "[", "]", ".", "slice", ".", "call", "(", "arguments", ",", "1", ")", ".", "join", "(", "'.'", ")", ";", "return", "filename", ".", "replace", "(", "'.html'", ",", "'.'", "+", "postfix", "+", "'.html'", ")", ";", "}" ]
Appends a list of flags separated by a '.' to a filename.
[ "Appends", "a", "list", "of", "flags", "separated", "by", "a", ".", "to", "a", "filename", "." ]
76267b11e3a8888c872ce4f306afdcdec959d5c1
https://github.com/ampproject/amp-by-example/blob/76267b11e3a8888c872ce4f306afdcdec959d5c1/lib/Preview.js#L146-L150
10,971
ampproject/amp-by-example
lib/Preview.js
generateTemplate
function generateTemplate(context) { let _page; let _phantom; phantom.create([], { logLevel: 'error' }).then(function (ph) { _phantom = ph; ph.createPage() .then(page => { _page = page; const url = path.join(context.config.destRoot, context.sample.embed); return _page.property('viewportSize', {width: 1024, height: 768}) .then(() => _page.open(url) ); }) .then(status => { return _page.evaluate(function() { const element = document.querySelector('#source-panel'); const height = element.getBoundingClientRect().top + element.offsetHeight; return height; }); }) .then(height => { context.sample.height = height; generate(context.sample.template, templates.template, context); }) .then(() => { _page.close(); _phantom.exit(); }) .catch(err => console.log(err)); }); }
javascript
function generateTemplate(context) { let _page; let _phantom; phantom.create([], { logLevel: 'error' }).then(function (ph) { _phantom = ph; ph.createPage() .then(page => { _page = page; const url = path.join(context.config.destRoot, context.sample.embed); return _page.property('viewportSize', {width: 1024, height: 768}) .then(() => _page.open(url) ); }) .then(status => { return _page.evaluate(function() { const element = document.querySelector('#source-panel'); const height = element.getBoundingClientRect().top + element.offsetHeight; return height; }); }) .then(height => { context.sample.height = height; generate(context.sample.template, templates.template, context); }) .then(() => { _page.close(); _phantom.exit(); }) .catch(err => console.log(err)); }); }
[ "function", "generateTemplate", "(", "context", ")", "{", "let", "_page", ";", "let", "_phantom", ";", "phantom", ".", "create", "(", "[", "]", ",", "{", "logLevel", ":", "'error'", "}", ")", ".", "then", "(", "function", "(", "ph", ")", "{", "_phantom", "=", "ph", ";", "ph", ".", "createPage", "(", ")", ".", "then", "(", "page", "=>", "{", "_page", "=", "page", ";", "const", "url", "=", "path", ".", "join", "(", "context", ".", "config", ".", "destRoot", ",", "context", ".", "sample", ".", "embed", ")", ";", "return", "_page", ".", "property", "(", "'viewportSize'", ",", "{", "width", ":", "1024", ",", "height", ":", "768", "}", ")", ".", "then", "(", "(", ")", "=>", "_page", ".", "open", "(", "url", ")", ")", ";", "}", ")", ".", "then", "(", "status", "=>", "{", "return", "_page", ".", "evaluate", "(", "function", "(", ")", "{", "const", "element", "=", "document", ".", "querySelector", "(", "'#source-panel'", ")", ";", "const", "height", "=", "element", ".", "getBoundingClientRect", "(", ")", ".", "top", "+", "element", ".", "offsetHeight", ";", "return", "height", ";", "}", ")", ";", "}", ")", ".", "then", "(", "height", "=>", "{", "context", ".", "sample", ".", "height", "=", "height", ";", "generate", "(", "context", ".", "sample", ".", "template", ",", "templates", ".", "template", ",", "context", ")", ";", "}", ")", ".", "then", "(", "(", ")", "=>", "{", "_page", ".", "close", "(", ")", ";", "_phantom", ".", "exit", "(", ")", ";", "}", ")", ".", "catch", "(", "err", "=>", "console", ".", "log", "(", "err", ")", ")", ";", "}", ")", ";", "}" ]
Opens the embed html file in a browser to determine the initial height.
[ "Opens", "the", "embed", "html", "file", "in", "a", "browser", "to", "determine", "the", "initial", "height", "." ]
76267b11e3a8888c872ce4f306afdcdec959d5c1
https://github.com/ampproject/amp-by-example/blob/76267b11e3a8888c872ce4f306afdcdec959d5c1/lib/Preview.js#L163-L192
10,972
mscdex/busboy
deps/encoding/encoding.js
UTF8Decoder
function UTF8Decoder(options) { var fatal = options.fatal; var /** @type {number} */ utf8_code_point = 0, /** @type {number} */ utf8_bytes_needed = 0, /** @type {number} */ utf8_bytes_seen = 0, /** @type {number} */ utf8_lower_boundary = 0; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte) { if (utf8_bytes_needed !== 0) { return decoderError(fatal); } return EOF_code_point; } byte_pointer.offset(1); if (utf8_bytes_needed === 0) { if (inRange(bite, 0x00, 0x7F)) { return bite; } if (inRange(bite, 0xC2, 0xDF)) { utf8_bytes_needed = 1; utf8_lower_boundary = 0x80; utf8_code_point = bite - 0xC0; } else if (inRange(bite, 0xE0, 0xEF)) { utf8_bytes_needed = 2; utf8_lower_boundary = 0x800; utf8_code_point = bite - 0xE0; } else if (inRange(bite, 0xF0, 0xF4)) { utf8_bytes_needed = 3; utf8_lower_boundary = 0x10000; utf8_code_point = bite - 0xF0; } else { return decoderError(fatal); } utf8_code_point = utf8_code_point * Math.pow(64, utf8_bytes_needed); return null; } if (!inRange(bite, 0x80, 0xBF)) { utf8_code_point = 0; utf8_bytes_needed = 0; utf8_bytes_seen = 0; utf8_lower_boundary = 0; byte_pointer.offset(-1); return decoderError(fatal); } utf8_bytes_seen += 1; utf8_code_point = utf8_code_point + (bite - 0x80) * Math.pow(64, utf8_bytes_needed - utf8_bytes_seen); if (utf8_bytes_seen !== utf8_bytes_needed) { return null; } var code_point = utf8_code_point; var lower_boundary = utf8_lower_boundary; utf8_code_point = 0; utf8_bytes_needed = 0; utf8_bytes_seen = 0; utf8_lower_boundary = 0; if (inRange(code_point, lower_boundary, 0x10FFFF) && !inRange(code_point, 0xD800, 0xDFFF)) { return code_point; } return decoderError(fatal); }; }
javascript
function UTF8Decoder(options) { var fatal = options.fatal; var /** @type {number} */ utf8_code_point = 0, /** @type {number} */ utf8_bytes_needed = 0, /** @type {number} */ utf8_bytes_seen = 0, /** @type {number} */ utf8_lower_boundary = 0; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte) { if (utf8_bytes_needed !== 0) { return decoderError(fatal); } return EOF_code_point; } byte_pointer.offset(1); if (utf8_bytes_needed === 0) { if (inRange(bite, 0x00, 0x7F)) { return bite; } if (inRange(bite, 0xC2, 0xDF)) { utf8_bytes_needed = 1; utf8_lower_boundary = 0x80; utf8_code_point = bite - 0xC0; } else if (inRange(bite, 0xE0, 0xEF)) { utf8_bytes_needed = 2; utf8_lower_boundary = 0x800; utf8_code_point = bite - 0xE0; } else if (inRange(bite, 0xF0, 0xF4)) { utf8_bytes_needed = 3; utf8_lower_boundary = 0x10000; utf8_code_point = bite - 0xF0; } else { return decoderError(fatal); } utf8_code_point = utf8_code_point * Math.pow(64, utf8_bytes_needed); return null; } if (!inRange(bite, 0x80, 0xBF)) { utf8_code_point = 0; utf8_bytes_needed = 0; utf8_bytes_seen = 0; utf8_lower_boundary = 0; byte_pointer.offset(-1); return decoderError(fatal); } utf8_bytes_seen += 1; utf8_code_point = utf8_code_point + (bite - 0x80) * Math.pow(64, utf8_bytes_needed - utf8_bytes_seen); if (utf8_bytes_seen !== utf8_bytes_needed) { return null; } var code_point = utf8_code_point; var lower_boundary = utf8_lower_boundary; utf8_code_point = 0; utf8_bytes_needed = 0; utf8_bytes_seen = 0; utf8_lower_boundary = 0; if (inRange(code_point, lower_boundary, 0x10FFFF) && !inRange(code_point, 0xD800, 0xDFFF)) { return code_point; } return decoderError(fatal); }; }
[ "function", "UTF8Decoder", "(", "options", ")", "{", "var", "fatal", "=", "options", ".", "fatal", ";", "var", "/** @type {number} */", "utf8_code_point", "=", "0", ",", "/** @type {number} */", "utf8_bytes_needed", "=", "0", ",", "/** @type {number} */", "utf8_bytes_seen", "=", "0", ",", "/** @type {number} */", "utf8_lower_boundary", "=", "0", ";", "/**\n * @param {ByteInputStream} byte_pointer The byte stream to decode.\n * @return {?number} The next code point decoded, or null if not enough\n * data exists in the input stream to decode a complete code point.\n */", "this", ".", "decode", "=", "function", "(", "byte_pointer", ")", "{", "var", "bite", "=", "byte_pointer", ".", "get", "(", ")", ";", "if", "(", "bite", "===", "EOF_byte", ")", "{", "if", "(", "utf8_bytes_needed", "!==", "0", ")", "{", "return", "decoderError", "(", "fatal", ")", ";", "}", "return", "EOF_code_point", ";", "}", "byte_pointer", ".", "offset", "(", "1", ")", ";", "if", "(", "utf8_bytes_needed", "===", "0", ")", "{", "if", "(", "inRange", "(", "bite", ",", "0x00", ",", "0x7F", ")", ")", "{", "return", "bite", ";", "}", "if", "(", "inRange", "(", "bite", ",", "0xC2", ",", "0xDF", ")", ")", "{", "utf8_bytes_needed", "=", "1", ";", "utf8_lower_boundary", "=", "0x80", ";", "utf8_code_point", "=", "bite", "-", "0xC0", ";", "}", "else", "if", "(", "inRange", "(", "bite", ",", "0xE0", ",", "0xEF", ")", ")", "{", "utf8_bytes_needed", "=", "2", ";", "utf8_lower_boundary", "=", "0x800", ";", "utf8_code_point", "=", "bite", "-", "0xE0", ";", "}", "else", "if", "(", "inRange", "(", "bite", ",", "0xF0", ",", "0xF4", ")", ")", "{", "utf8_bytes_needed", "=", "3", ";", "utf8_lower_boundary", "=", "0x10000", ";", "utf8_code_point", "=", "bite", "-", "0xF0", ";", "}", "else", "{", "return", "decoderError", "(", "fatal", ")", ";", "}", "utf8_code_point", "=", "utf8_code_point", "*", "Math", ".", "pow", "(", "64", ",", "utf8_bytes_needed", ")", ";", "return", "null", ";", "}", "if", "(", "!", "inRange", "(", "bite", ",", "0x80", ",", "0xBF", ")", ")", "{", "utf8_code_point", "=", "0", ";", "utf8_bytes_needed", "=", "0", ";", "utf8_bytes_seen", "=", "0", ";", "utf8_lower_boundary", "=", "0", ";", "byte_pointer", ".", "offset", "(", "-", "1", ")", ";", "return", "decoderError", "(", "fatal", ")", ";", "}", "utf8_bytes_seen", "+=", "1", ";", "utf8_code_point", "=", "utf8_code_point", "+", "(", "bite", "-", "0x80", ")", "*", "Math", ".", "pow", "(", "64", ",", "utf8_bytes_needed", "-", "utf8_bytes_seen", ")", ";", "if", "(", "utf8_bytes_seen", "!==", "utf8_bytes_needed", ")", "{", "return", "null", ";", "}", "var", "code_point", "=", "utf8_code_point", ";", "var", "lower_boundary", "=", "utf8_lower_boundary", ";", "utf8_code_point", "=", "0", ";", "utf8_bytes_needed", "=", "0", ";", "utf8_bytes_seen", "=", "0", ";", "utf8_lower_boundary", "=", "0", ";", "if", "(", "inRange", "(", "code_point", ",", "lower_boundary", ",", "0x10FFFF", ")", "&&", "!", "inRange", "(", "code_point", ",", "0xD800", ",", "0xDFFF", ")", ")", "{", "return", "code_point", ";", "}", "return", "decoderError", "(", "fatal", ")", ";", "}", ";", "}" ]
8.1 utf-8 @constructor @param {{fatal: boolean}} options
[ "8", ".", "1", "utf", "-", "8" ]
da0e67d503cc39727dfa3a85c142d19de6f2c8c7
https://github.com/mscdex/busboy/blob/da0e67d503cc39727dfa3a85c142d19de6f2c8c7/deps/encoding/encoding.js#L1026-L1096
10,973
mscdex/busboy
deps/encoding/encoding.js
GBKDecoder
function GBKDecoder(gb18030, options) { var fatal = options.fatal; var /** @type {number} */ gbk_first = 0x00, /** @type {number} */ gbk_second = 0x00, /** @type {number} */ gbk_third = 0x00; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte && gbk_first === 0x00 && gbk_second === 0x00 && gbk_third === 0x00) { return EOF_code_point; } if (bite === EOF_byte && (gbk_first !== 0x00 || gbk_second !== 0x00 || gbk_third !== 0x00)) { gbk_first = 0x00; gbk_second = 0x00; gbk_third = 0x00; decoderError(fatal); } byte_pointer.offset(1); var code_point; if (gbk_third !== 0x00) { code_point = null; if (inRange(bite, 0x30, 0x39)) { code_point = indexGB18030CodePointFor( (((gbk_first - 0x81) * 10 + (gbk_second - 0x30)) * 126 + (gbk_third - 0x81)) * 10 + bite - 0x30); } gbk_first = 0x00; gbk_second = 0x00; gbk_third = 0x00; if (code_point === null) { byte_pointer.offset(-3); return decoderError(fatal); } return code_point; } if (gbk_second !== 0x00) { if (inRange(bite, 0x81, 0xFE)) { gbk_third = bite; return null; } byte_pointer.offset(-2); gbk_first = 0x00; gbk_second = 0x00; return decoderError(fatal); } if (gbk_first !== 0x00) { if (inRange(bite, 0x30, 0x39) && gb18030) { gbk_second = bite; return null; } var lead = gbk_first; var pointer = null; gbk_first = 0x00; var offset = bite < 0x7F ? 0x40 : 0x41; if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFE)) { pointer = (lead - 0x81) * 190 + (bite - offset); } code_point = pointer === null ? null : indexCodePointFor(pointer, indexes['gbk']); if (pointer === null) { byte_pointer.offset(-1); } if (code_point === null) { return decoderError(fatal); } return code_point; } if (inRange(bite, 0x00, 0x7F)) { return bite; } if (bite === 0x80) { return 0x20AC; } if (inRange(bite, 0x81, 0xFE)) { gbk_first = bite; return null; } return decoderError(fatal); }; }
javascript
function GBKDecoder(gb18030, options) { var fatal = options.fatal; var /** @type {number} */ gbk_first = 0x00, /** @type {number} */ gbk_second = 0x00, /** @type {number} */ gbk_third = 0x00; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte && gbk_first === 0x00 && gbk_second === 0x00 && gbk_third === 0x00) { return EOF_code_point; } if (bite === EOF_byte && (gbk_first !== 0x00 || gbk_second !== 0x00 || gbk_third !== 0x00)) { gbk_first = 0x00; gbk_second = 0x00; gbk_third = 0x00; decoderError(fatal); } byte_pointer.offset(1); var code_point; if (gbk_third !== 0x00) { code_point = null; if (inRange(bite, 0x30, 0x39)) { code_point = indexGB18030CodePointFor( (((gbk_first - 0x81) * 10 + (gbk_second - 0x30)) * 126 + (gbk_third - 0x81)) * 10 + bite - 0x30); } gbk_first = 0x00; gbk_second = 0x00; gbk_third = 0x00; if (code_point === null) { byte_pointer.offset(-3); return decoderError(fatal); } return code_point; } if (gbk_second !== 0x00) { if (inRange(bite, 0x81, 0xFE)) { gbk_third = bite; return null; } byte_pointer.offset(-2); gbk_first = 0x00; gbk_second = 0x00; return decoderError(fatal); } if (gbk_first !== 0x00) { if (inRange(bite, 0x30, 0x39) && gb18030) { gbk_second = bite; return null; } var lead = gbk_first; var pointer = null; gbk_first = 0x00; var offset = bite < 0x7F ? 0x40 : 0x41; if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFE)) { pointer = (lead - 0x81) * 190 + (bite - offset); } code_point = pointer === null ? null : indexCodePointFor(pointer, indexes['gbk']); if (pointer === null) { byte_pointer.offset(-1); } if (code_point === null) { return decoderError(fatal); } return code_point; } if (inRange(bite, 0x00, 0x7F)) { return bite; } if (bite === 0x80) { return 0x20AC; } if (inRange(bite, 0x81, 0xFE)) { gbk_first = bite; return null; } return decoderError(fatal); }; }
[ "function", "GBKDecoder", "(", "gb18030", ",", "options", ")", "{", "var", "fatal", "=", "options", ".", "fatal", ";", "var", "/** @type {number} */", "gbk_first", "=", "0x00", ",", "/** @type {number} */", "gbk_second", "=", "0x00", ",", "/** @type {number} */", "gbk_third", "=", "0x00", ";", "/**\n * @param {ByteInputStream} byte_pointer The byte stream to decode.\n * @return {?number} The next code point decoded, or null if not enough\n * data exists in the input stream to decode a complete code point.\n */", "this", ".", "decode", "=", "function", "(", "byte_pointer", ")", "{", "var", "bite", "=", "byte_pointer", ".", "get", "(", ")", ";", "if", "(", "bite", "===", "EOF_byte", "&&", "gbk_first", "===", "0x00", "&&", "gbk_second", "===", "0x00", "&&", "gbk_third", "===", "0x00", ")", "{", "return", "EOF_code_point", ";", "}", "if", "(", "bite", "===", "EOF_byte", "&&", "(", "gbk_first", "!==", "0x00", "||", "gbk_second", "!==", "0x00", "||", "gbk_third", "!==", "0x00", ")", ")", "{", "gbk_first", "=", "0x00", ";", "gbk_second", "=", "0x00", ";", "gbk_third", "=", "0x00", ";", "decoderError", "(", "fatal", ")", ";", "}", "byte_pointer", ".", "offset", "(", "1", ")", ";", "var", "code_point", ";", "if", "(", "gbk_third", "!==", "0x00", ")", "{", "code_point", "=", "null", ";", "if", "(", "inRange", "(", "bite", ",", "0x30", ",", "0x39", ")", ")", "{", "code_point", "=", "indexGB18030CodePointFor", "(", "(", "(", "(", "gbk_first", "-", "0x81", ")", "*", "10", "+", "(", "gbk_second", "-", "0x30", ")", ")", "*", "126", "+", "(", "gbk_third", "-", "0x81", ")", ")", "*", "10", "+", "bite", "-", "0x30", ")", ";", "}", "gbk_first", "=", "0x00", ";", "gbk_second", "=", "0x00", ";", "gbk_third", "=", "0x00", ";", "if", "(", "code_point", "===", "null", ")", "{", "byte_pointer", ".", "offset", "(", "-", "3", ")", ";", "return", "decoderError", "(", "fatal", ")", ";", "}", "return", "code_point", ";", "}", "if", "(", "gbk_second", "!==", "0x00", ")", "{", "if", "(", "inRange", "(", "bite", ",", "0x81", ",", "0xFE", ")", ")", "{", "gbk_third", "=", "bite", ";", "return", "null", ";", "}", "byte_pointer", ".", "offset", "(", "-", "2", ")", ";", "gbk_first", "=", "0x00", ";", "gbk_second", "=", "0x00", ";", "return", "decoderError", "(", "fatal", ")", ";", "}", "if", "(", "gbk_first", "!==", "0x00", ")", "{", "if", "(", "inRange", "(", "bite", ",", "0x30", ",", "0x39", ")", "&&", "gb18030", ")", "{", "gbk_second", "=", "bite", ";", "return", "null", ";", "}", "var", "lead", "=", "gbk_first", ";", "var", "pointer", "=", "null", ";", "gbk_first", "=", "0x00", ";", "var", "offset", "=", "bite", "<", "0x7F", "?", "0x40", ":", "0x41", ";", "if", "(", "inRange", "(", "bite", ",", "0x40", ",", "0x7E", ")", "||", "inRange", "(", "bite", ",", "0x80", ",", "0xFE", ")", ")", "{", "pointer", "=", "(", "lead", "-", "0x81", ")", "*", "190", "+", "(", "bite", "-", "offset", ")", ";", "}", "code_point", "=", "pointer", "===", "null", "?", "null", ":", "indexCodePointFor", "(", "pointer", ",", "indexes", "[", "'gbk'", "]", ")", ";", "if", "(", "pointer", "===", "null", ")", "{", "byte_pointer", ".", "offset", "(", "-", "1", ")", ";", "}", "if", "(", "code_point", "===", "null", ")", "{", "return", "decoderError", "(", "fatal", ")", ";", "}", "return", "code_point", ";", "}", "if", "(", "inRange", "(", "bite", ",", "0x00", ",", "0x7F", ")", ")", "{", "return", "bite", ";", "}", "if", "(", "bite", "===", "0x80", ")", "{", "return", "0x20AC", ";", "}", "if", "(", "inRange", "(", "bite", ",", "0x81", ",", "0xFE", ")", ")", "{", "gbk_first", "=", "bite", ";", "return", "null", ";", "}", "return", "decoderError", "(", "fatal", ")", ";", "}", ";", "}" ]
9.1 gbk @constructor @param {boolean} gb18030 True if decoding gb18030, false otherwise. @param {{fatal: boolean}} options
[ "9", ".", "1", "gbk" ]
da0e67d503cc39727dfa3a85c142d19de6f2c8c7
https://github.com/mscdex/busboy/blob/da0e67d503cc39727dfa3a85c142d19de6f2c8c7/deps/encoding/encoding.js#L1244-L1329
10,974
mscdex/busboy
deps/encoding/encoding.js
HZGB2312Decoder
function HZGB2312Decoder(options) { var fatal = options.fatal; var /** @type {boolean} */ hzgb2312 = false, /** @type {number} */ hzgb2312_lead = 0x00; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte && hzgb2312_lead === 0x00) { return EOF_code_point; } if (bite === EOF_byte && hzgb2312_lead !== 0x00) { hzgb2312_lead = 0x00; return decoderError(fatal); } byte_pointer.offset(1); if (hzgb2312_lead === 0x7E) { hzgb2312_lead = 0x00; if (bite === 0x7B) { hzgb2312 = true; return null; } if (bite === 0x7D) { hzgb2312 = false; return null; } if (bite === 0x7E) { return 0x007E; } if (bite === 0x0A) { return null; } byte_pointer.offset(-1); return decoderError(fatal); } if (hzgb2312_lead !== 0x00) { var lead = hzgb2312_lead; hzgb2312_lead = 0x00; var code_point = null; if (inRange(bite, 0x21, 0x7E)) { code_point = indexCodePointFor((lead - 1) * 190 + (bite + 0x3F), indexes['gbk']); } if (bite === 0x0A) { hzgb2312 = false; } if (code_point === null) { return decoderError(fatal); } return code_point; } if (bite === 0x7E) { hzgb2312_lead = 0x7E; return null; } if (hzgb2312) { if (inRange(bite, 0x20, 0x7F)) { hzgb2312_lead = bite; return null; } if (bite === 0x0A) { hzgb2312 = false; } return decoderError(fatal); } if (inRange(bite, 0x00, 0x7F)) { return bite; } return decoderError(fatal); }; }
javascript
function HZGB2312Decoder(options) { var fatal = options.fatal; var /** @type {boolean} */ hzgb2312 = false, /** @type {number} */ hzgb2312_lead = 0x00; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte && hzgb2312_lead === 0x00) { return EOF_code_point; } if (bite === EOF_byte && hzgb2312_lead !== 0x00) { hzgb2312_lead = 0x00; return decoderError(fatal); } byte_pointer.offset(1); if (hzgb2312_lead === 0x7E) { hzgb2312_lead = 0x00; if (bite === 0x7B) { hzgb2312 = true; return null; } if (bite === 0x7D) { hzgb2312 = false; return null; } if (bite === 0x7E) { return 0x007E; } if (bite === 0x0A) { return null; } byte_pointer.offset(-1); return decoderError(fatal); } if (hzgb2312_lead !== 0x00) { var lead = hzgb2312_lead; hzgb2312_lead = 0x00; var code_point = null; if (inRange(bite, 0x21, 0x7E)) { code_point = indexCodePointFor((lead - 1) * 190 + (bite + 0x3F), indexes['gbk']); } if (bite === 0x0A) { hzgb2312 = false; } if (code_point === null) { return decoderError(fatal); } return code_point; } if (bite === 0x7E) { hzgb2312_lead = 0x7E; return null; } if (hzgb2312) { if (inRange(bite, 0x20, 0x7F)) { hzgb2312_lead = bite; return null; } if (bite === 0x0A) { hzgb2312 = false; } return decoderError(fatal); } if (inRange(bite, 0x00, 0x7F)) { return bite; } return decoderError(fatal); }; }
[ "function", "HZGB2312Decoder", "(", "options", ")", "{", "var", "fatal", "=", "options", ".", "fatal", ";", "var", "/** @type {boolean} */", "hzgb2312", "=", "false", ",", "/** @type {number} */", "hzgb2312_lead", "=", "0x00", ";", "/**\n * @param {ByteInputStream} byte_pointer The byte stream to decode.\n * @return {?number} The next code point decoded, or null if not enough\n * data exists in the input stream to decode a complete code point.\n */", "this", ".", "decode", "=", "function", "(", "byte_pointer", ")", "{", "var", "bite", "=", "byte_pointer", ".", "get", "(", ")", ";", "if", "(", "bite", "===", "EOF_byte", "&&", "hzgb2312_lead", "===", "0x00", ")", "{", "return", "EOF_code_point", ";", "}", "if", "(", "bite", "===", "EOF_byte", "&&", "hzgb2312_lead", "!==", "0x00", ")", "{", "hzgb2312_lead", "=", "0x00", ";", "return", "decoderError", "(", "fatal", ")", ";", "}", "byte_pointer", ".", "offset", "(", "1", ")", ";", "if", "(", "hzgb2312_lead", "===", "0x7E", ")", "{", "hzgb2312_lead", "=", "0x00", ";", "if", "(", "bite", "===", "0x7B", ")", "{", "hzgb2312", "=", "true", ";", "return", "null", ";", "}", "if", "(", "bite", "===", "0x7D", ")", "{", "hzgb2312", "=", "false", ";", "return", "null", ";", "}", "if", "(", "bite", "===", "0x7E", ")", "{", "return", "0x007E", ";", "}", "if", "(", "bite", "===", "0x0A", ")", "{", "return", "null", ";", "}", "byte_pointer", ".", "offset", "(", "-", "1", ")", ";", "return", "decoderError", "(", "fatal", ")", ";", "}", "if", "(", "hzgb2312_lead", "!==", "0x00", ")", "{", "var", "lead", "=", "hzgb2312_lead", ";", "hzgb2312_lead", "=", "0x00", ";", "var", "code_point", "=", "null", ";", "if", "(", "inRange", "(", "bite", ",", "0x21", ",", "0x7E", ")", ")", "{", "code_point", "=", "indexCodePointFor", "(", "(", "lead", "-", "1", ")", "*", "190", "+", "(", "bite", "+", "0x3F", ")", ",", "indexes", "[", "'gbk'", "]", ")", ";", "}", "if", "(", "bite", "===", "0x0A", ")", "{", "hzgb2312", "=", "false", ";", "}", "if", "(", "code_point", "===", "null", ")", "{", "return", "decoderError", "(", "fatal", ")", ";", "}", "return", "code_point", ";", "}", "if", "(", "bite", "===", "0x7E", ")", "{", "hzgb2312_lead", "=", "0x7E", ";", "return", "null", ";", "}", "if", "(", "hzgb2312", ")", "{", "if", "(", "inRange", "(", "bite", ",", "0x20", ",", "0x7F", ")", ")", "{", "hzgb2312_lead", "=", "bite", ";", "return", "null", ";", "}", "if", "(", "bite", "===", "0x0A", ")", "{", "hzgb2312", "=", "false", ";", "}", "return", "decoderError", "(", "fatal", ")", ";", "}", "if", "(", "inRange", "(", "bite", ",", "0x00", ",", "0x7F", ")", ")", "{", "return", "bite", ";", "}", "return", "decoderError", "(", "fatal", ")", ";", "}", ";", "}" ]
10.2 hz-gb-2312 @constructor @param {{fatal: boolean}} options
[ "10", ".", "2", "hz", "-", "gb", "-", "2312" ]
da0e67d503cc39727dfa3a85c142d19de6f2c8c7
https://github.com/mscdex/busboy/blob/da0e67d503cc39727dfa3a85c142d19de6f2c8c7/deps/encoding/encoding.js#L1397-L1470
10,975
mscdex/busboy
deps/encoding/encoding.js
Big5Decoder
function Big5Decoder(options) { var fatal = options.fatal; var /** @type {number} */ big5_lead = 0x00, /** @type {?number} */ big5_pending = null; /** * @param {ByteInputStream} byte_pointer The byte steram to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { // NOTE: Hack to support emitting two code points if (big5_pending !== null) { var pending = big5_pending; big5_pending = null; return pending; } var bite = byte_pointer.get(); if (bite === EOF_byte && big5_lead === 0x00) { return EOF_code_point; } if (bite === EOF_byte && big5_lead !== 0x00) { big5_lead = 0x00; return decoderError(fatal); } byte_pointer.offset(1); if (big5_lead !== 0x00) { var lead = big5_lead; var pointer = null; big5_lead = 0x00; var offset = bite < 0x7F ? 0x40 : 0x62; if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0xA1, 0xFE)) { pointer = (lead - 0x81) * 157 + (bite - offset); } if (pointer === 1133) { big5_pending = 0x0304; return 0x00CA; } if (pointer === 1135) { big5_pending = 0x030C; return 0x00CA; } if (pointer === 1164) { big5_pending = 0x0304; return 0x00EA; } if (pointer === 1166) { big5_pending = 0x030C; return 0x00EA; } var code_point = (pointer === null) ? null : indexCodePointFor(pointer, indexes['big5']); if (pointer === null) { byte_pointer.offset(-1); } if (code_point === null) { return decoderError(fatal); } return code_point; } if (inRange(bite, 0x00, 0x7F)) { return bite; } if (inRange(bite, 0x81, 0xFE)) { big5_lead = bite; return null; } return decoderError(fatal); }; }
javascript
function Big5Decoder(options) { var fatal = options.fatal; var /** @type {number} */ big5_lead = 0x00, /** @type {?number} */ big5_pending = null; /** * @param {ByteInputStream} byte_pointer The byte steram to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { // NOTE: Hack to support emitting two code points if (big5_pending !== null) { var pending = big5_pending; big5_pending = null; return pending; } var bite = byte_pointer.get(); if (bite === EOF_byte && big5_lead === 0x00) { return EOF_code_point; } if (bite === EOF_byte && big5_lead !== 0x00) { big5_lead = 0x00; return decoderError(fatal); } byte_pointer.offset(1); if (big5_lead !== 0x00) { var lead = big5_lead; var pointer = null; big5_lead = 0x00; var offset = bite < 0x7F ? 0x40 : 0x62; if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0xA1, 0xFE)) { pointer = (lead - 0x81) * 157 + (bite - offset); } if (pointer === 1133) { big5_pending = 0x0304; return 0x00CA; } if (pointer === 1135) { big5_pending = 0x030C; return 0x00CA; } if (pointer === 1164) { big5_pending = 0x0304; return 0x00EA; } if (pointer === 1166) { big5_pending = 0x030C; return 0x00EA; } var code_point = (pointer === null) ? null : indexCodePointFor(pointer, indexes['big5']); if (pointer === null) { byte_pointer.offset(-1); } if (code_point === null) { return decoderError(fatal); } return code_point; } if (inRange(bite, 0x00, 0x7F)) { return bite; } if (inRange(bite, 0x81, 0xFE)) { big5_lead = bite; return null; } return decoderError(fatal); }; }
[ "function", "Big5Decoder", "(", "options", ")", "{", "var", "fatal", "=", "options", ".", "fatal", ";", "var", "/** @type {number} */", "big5_lead", "=", "0x00", ",", "/** @type {?number} */", "big5_pending", "=", "null", ";", "/**\n * @param {ByteInputStream} byte_pointer The byte steram to decode.\n * @return {?number} The next code point decoded, or null if not enough\n * data exists in the input stream to decode a complete code point.\n */", "this", ".", "decode", "=", "function", "(", "byte_pointer", ")", "{", "// NOTE: Hack to support emitting two code points", "if", "(", "big5_pending", "!==", "null", ")", "{", "var", "pending", "=", "big5_pending", ";", "big5_pending", "=", "null", ";", "return", "pending", ";", "}", "var", "bite", "=", "byte_pointer", ".", "get", "(", ")", ";", "if", "(", "bite", "===", "EOF_byte", "&&", "big5_lead", "===", "0x00", ")", "{", "return", "EOF_code_point", ";", "}", "if", "(", "bite", "===", "EOF_byte", "&&", "big5_lead", "!==", "0x00", ")", "{", "big5_lead", "=", "0x00", ";", "return", "decoderError", "(", "fatal", ")", ";", "}", "byte_pointer", ".", "offset", "(", "1", ")", ";", "if", "(", "big5_lead", "!==", "0x00", ")", "{", "var", "lead", "=", "big5_lead", ";", "var", "pointer", "=", "null", ";", "big5_lead", "=", "0x00", ";", "var", "offset", "=", "bite", "<", "0x7F", "?", "0x40", ":", "0x62", ";", "if", "(", "inRange", "(", "bite", ",", "0x40", ",", "0x7E", ")", "||", "inRange", "(", "bite", ",", "0xA1", ",", "0xFE", ")", ")", "{", "pointer", "=", "(", "lead", "-", "0x81", ")", "*", "157", "+", "(", "bite", "-", "offset", ")", ";", "}", "if", "(", "pointer", "===", "1133", ")", "{", "big5_pending", "=", "0x0304", ";", "return", "0x00CA", ";", "}", "if", "(", "pointer", "===", "1135", ")", "{", "big5_pending", "=", "0x030C", ";", "return", "0x00CA", ";", "}", "if", "(", "pointer", "===", "1164", ")", "{", "big5_pending", "=", "0x0304", ";", "return", "0x00EA", ";", "}", "if", "(", "pointer", "===", "1166", ")", "{", "big5_pending", "=", "0x030C", ";", "return", "0x00EA", ";", "}", "var", "code_point", "=", "(", "pointer", "===", "null", ")", "?", "null", ":", "indexCodePointFor", "(", "pointer", ",", "indexes", "[", "'big5'", "]", ")", ";", "if", "(", "pointer", "===", "null", ")", "{", "byte_pointer", ".", "offset", "(", "-", "1", ")", ";", "}", "if", "(", "code_point", "===", "null", ")", "{", "return", "decoderError", "(", "fatal", ")", ";", "}", "return", "code_point", ";", "}", "if", "(", "inRange", "(", "bite", ",", "0x00", ",", "0x7F", ")", ")", "{", "return", "bite", ";", "}", "if", "(", "inRange", "(", "bite", ",", "0x81", ",", "0xFE", ")", ")", "{", "big5_lead", "=", "bite", ";", "return", "null", ";", "}", "return", "decoderError", "(", "fatal", ")", ";", "}", ";", "}" ]
11.1 big5 @constructor @param {{fatal: boolean}} options
[ "11", ".", "1", "big5" ]
da0e67d503cc39727dfa3a85c142d19de6f2c8c7
https://github.com/mscdex/busboy/blob/da0e67d503cc39727dfa3a85c142d19de6f2c8c7/deps/encoding/encoding.js#L1539-L1608
10,976
mscdex/busboy
deps/encoding/encoding.js
EUCJPDecoder
function EUCJPDecoder(options) { var fatal = options.fatal; var /** @type {number} */ eucjp_first = 0x00, /** @type {number} */ eucjp_second = 0x00; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte) { if (eucjp_first === 0x00 && eucjp_second === 0x00) { return EOF_code_point; } eucjp_first = 0x00; eucjp_second = 0x00; return decoderError(fatal); } byte_pointer.offset(1); var lead, code_point; if (eucjp_second !== 0x00) { lead = eucjp_second; eucjp_second = 0x00; code_point = null; if (inRange(lead, 0xA1, 0xFE) && inRange(bite, 0xA1, 0xFE)) { code_point = indexCodePointFor((lead - 0xA1) * 94 + bite - 0xA1, indexes['jis0212']); } if (!inRange(bite, 0xA1, 0xFE)) { byte_pointer.offset(-1); } if (code_point === null) { return decoderError(fatal); } return code_point; } if (eucjp_first === 0x8E && inRange(bite, 0xA1, 0xDF)) { eucjp_first = 0x00; return 0xFF61 + bite - 0xA1; } if (eucjp_first === 0x8F && inRange(bite, 0xA1, 0xFE)) { eucjp_first = 0x00; eucjp_second = bite; return null; } if (eucjp_first !== 0x00) { lead = eucjp_first; eucjp_first = 0x00; code_point = null; if (inRange(lead, 0xA1, 0xFE) && inRange(bite, 0xA1, 0xFE)) { code_point = indexCodePointFor((lead - 0xA1) * 94 + bite - 0xA1, indexes['jis0208']); } if (!inRange(bite, 0xA1, 0xFE)) { byte_pointer.offset(-1); } if (code_point === null) { return decoderError(fatal); } return code_point; } if (inRange(bite, 0x00, 0x7F)) { return bite; } if (bite === 0x8E || bite === 0x8F || (inRange(bite, 0xA1, 0xFE))) { eucjp_first = bite; return null; } return decoderError(fatal); }; }
javascript
function EUCJPDecoder(options) { var fatal = options.fatal; var /** @type {number} */ eucjp_first = 0x00, /** @type {number} */ eucjp_second = 0x00; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte) { if (eucjp_first === 0x00 && eucjp_second === 0x00) { return EOF_code_point; } eucjp_first = 0x00; eucjp_second = 0x00; return decoderError(fatal); } byte_pointer.offset(1); var lead, code_point; if (eucjp_second !== 0x00) { lead = eucjp_second; eucjp_second = 0x00; code_point = null; if (inRange(lead, 0xA1, 0xFE) && inRange(bite, 0xA1, 0xFE)) { code_point = indexCodePointFor((lead - 0xA1) * 94 + bite - 0xA1, indexes['jis0212']); } if (!inRange(bite, 0xA1, 0xFE)) { byte_pointer.offset(-1); } if (code_point === null) { return decoderError(fatal); } return code_point; } if (eucjp_first === 0x8E && inRange(bite, 0xA1, 0xDF)) { eucjp_first = 0x00; return 0xFF61 + bite - 0xA1; } if (eucjp_first === 0x8F && inRange(bite, 0xA1, 0xFE)) { eucjp_first = 0x00; eucjp_second = bite; return null; } if (eucjp_first !== 0x00) { lead = eucjp_first; eucjp_first = 0x00; code_point = null; if (inRange(lead, 0xA1, 0xFE) && inRange(bite, 0xA1, 0xFE)) { code_point = indexCodePointFor((lead - 0xA1) * 94 + bite - 0xA1, indexes['jis0208']); } if (!inRange(bite, 0xA1, 0xFE)) { byte_pointer.offset(-1); } if (code_point === null) { return decoderError(fatal); } return code_point; } if (inRange(bite, 0x00, 0x7F)) { return bite; } if (bite === 0x8E || bite === 0x8F || (inRange(bite, 0xA1, 0xFE))) { eucjp_first = bite; return null; } return decoderError(fatal); }; }
[ "function", "EUCJPDecoder", "(", "options", ")", "{", "var", "fatal", "=", "options", ".", "fatal", ";", "var", "/** @type {number} */", "eucjp_first", "=", "0x00", ",", "/** @type {number} */", "eucjp_second", "=", "0x00", ";", "/**\n * @param {ByteInputStream} byte_pointer The byte stream to decode.\n * @return {?number} The next code point decoded, or null if not enough\n * data exists in the input stream to decode a complete code point.\n */", "this", ".", "decode", "=", "function", "(", "byte_pointer", ")", "{", "var", "bite", "=", "byte_pointer", ".", "get", "(", ")", ";", "if", "(", "bite", "===", "EOF_byte", ")", "{", "if", "(", "eucjp_first", "===", "0x00", "&&", "eucjp_second", "===", "0x00", ")", "{", "return", "EOF_code_point", ";", "}", "eucjp_first", "=", "0x00", ";", "eucjp_second", "=", "0x00", ";", "return", "decoderError", "(", "fatal", ")", ";", "}", "byte_pointer", ".", "offset", "(", "1", ")", ";", "var", "lead", ",", "code_point", ";", "if", "(", "eucjp_second", "!==", "0x00", ")", "{", "lead", "=", "eucjp_second", ";", "eucjp_second", "=", "0x00", ";", "code_point", "=", "null", ";", "if", "(", "inRange", "(", "lead", ",", "0xA1", ",", "0xFE", ")", "&&", "inRange", "(", "bite", ",", "0xA1", ",", "0xFE", ")", ")", "{", "code_point", "=", "indexCodePointFor", "(", "(", "lead", "-", "0xA1", ")", "*", "94", "+", "bite", "-", "0xA1", ",", "indexes", "[", "'jis0212'", "]", ")", ";", "}", "if", "(", "!", "inRange", "(", "bite", ",", "0xA1", ",", "0xFE", ")", ")", "{", "byte_pointer", ".", "offset", "(", "-", "1", ")", ";", "}", "if", "(", "code_point", "===", "null", ")", "{", "return", "decoderError", "(", "fatal", ")", ";", "}", "return", "code_point", ";", "}", "if", "(", "eucjp_first", "===", "0x8E", "&&", "inRange", "(", "bite", ",", "0xA1", ",", "0xDF", ")", ")", "{", "eucjp_first", "=", "0x00", ";", "return", "0xFF61", "+", "bite", "-", "0xA1", ";", "}", "if", "(", "eucjp_first", "===", "0x8F", "&&", "inRange", "(", "bite", ",", "0xA1", ",", "0xFE", ")", ")", "{", "eucjp_first", "=", "0x00", ";", "eucjp_second", "=", "bite", ";", "return", "null", ";", "}", "if", "(", "eucjp_first", "!==", "0x00", ")", "{", "lead", "=", "eucjp_first", ";", "eucjp_first", "=", "0x00", ";", "code_point", "=", "null", ";", "if", "(", "inRange", "(", "lead", ",", "0xA1", ",", "0xFE", ")", "&&", "inRange", "(", "bite", ",", "0xA1", ",", "0xFE", ")", ")", "{", "code_point", "=", "indexCodePointFor", "(", "(", "lead", "-", "0xA1", ")", "*", "94", "+", "bite", "-", "0xA1", ",", "indexes", "[", "'jis0208'", "]", ")", ";", "}", "if", "(", "!", "inRange", "(", "bite", ",", "0xA1", ",", "0xFE", ")", ")", "{", "byte_pointer", ".", "offset", "(", "-", "1", ")", ";", "}", "if", "(", "code_point", "===", "null", ")", "{", "return", "decoderError", "(", "fatal", ")", ";", "}", "return", "code_point", ";", "}", "if", "(", "inRange", "(", "bite", ",", "0x00", ",", "0x7F", ")", ")", "{", "return", "bite", ";", "}", "if", "(", "bite", "===", "0x8E", "||", "bite", "===", "0x8F", "||", "(", "inRange", "(", "bite", ",", "0xA1", ",", "0xFE", ")", ")", ")", "{", "eucjp_first", "=", "bite", ";", "return", "null", ";", "}", "return", "decoderError", "(", "fatal", ")", ";", "}", ";", "}" ]
12.1 euc.jp @constructor @param {{fatal: boolean}} options
[ "12", ".", "1", "euc", ".", "jp" ]
da0e67d503cc39727dfa3a85c142d19de6f2c8c7
https://github.com/mscdex/busboy/blob/da0e67d503cc39727dfa3a85c142d19de6f2c8c7/deps/encoding/encoding.js#L1664-L1736
10,977
mscdex/busboy
deps/encoding/encoding.js
ShiftJISDecoder
function ShiftJISDecoder(options) { var fatal = options.fatal; var /** @type {number} */ shiftjis_lead = 0x00; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte && shiftjis_lead === 0x00) { return EOF_code_point; } if (bite === EOF_byte && shiftjis_lead !== 0x00) { shiftjis_lead = 0x00; return decoderError(fatal); } byte_pointer.offset(1); if (shiftjis_lead !== 0x00) { var lead = shiftjis_lead; shiftjis_lead = 0x00; if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFC)) { var offset = (bite < 0x7F) ? 0x40 : 0x41; var lead_offset = (lead < 0xA0) ? 0x81 : 0xC1; var code_point = indexCodePointFor((lead - lead_offset) * 188 + bite - offset, indexes['jis0208']); if (code_point === null) { return decoderError(fatal); } return code_point; } byte_pointer.offset(-1); return decoderError(fatal); } if (inRange(bite, 0x00, 0x80)) { return bite; } if (inRange(bite, 0xA1, 0xDF)) { return 0xFF61 + bite - 0xA1; } if (inRange(bite, 0x81, 0x9F) || inRange(bite, 0xE0, 0xFC)) { shiftjis_lead = bite; return null; } return decoderError(fatal); }; }
javascript
function ShiftJISDecoder(options) { var fatal = options.fatal; var /** @type {number} */ shiftjis_lead = 0x00; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte && shiftjis_lead === 0x00) { return EOF_code_point; } if (bite === EOF_byte && shiftjis_lead !== 0x00) { shiftjis_lead = 0x00; return decoderError(fatal); } byte_pointer.offset(1); if (shiftjis_lead !== 0x00) { var lead = shiftjis_lead; shiftjis_lead = 0x00; if (inRange(bite, 0x40, 0x7E) || inRange(bite, 0x80, 0xFC)) { var offset = (bite < 0x7F) ? 0x40 : 0x41; var lead_offset = (lead < 0xA0) ? 0x81 : 0xC1; var code_point = indexCodePointFor((lead - lead_offset) * 188 + bite - offset, indexes['jis0208']); if (code_point === null) { return decoderError(fatal); } return code_point; } byte_pointer.offset(-1); return decoderError(fatal); } if (inRange(bite, 0x00, 0x80)) { return bite; } if (inRange(bite, 0xA1, 0xDF)) { return 0xFF61 + bite - 0xA1; } if (inRange(bite, 0x81, 0x9F) || inRange(bite, 0xE0, 0xFC)) { shiftjis_lead = bite; return null; } return decoderError(fatal); }; }
[ "function", "ShiftJISDecoder", "(", "options", ")", "{", "var", "fatal", "=", "options", ".", "fatal", ";", "var", "/** @type {number} */", "shiftjis_lead", "=", "0x00", ";", "/**\n * @param {ByteInputStream} byte_pointer The byte stream to decode.\n * @return {?number} The next code point decoded, or null if not enough\n * data exists in the input stream to decode a complete code point.\n */", "this", ".", "decode", "=", "function", "(", "byte_pointer", ")", "{", "var", "bite", "=", "byte_pointer", ".", "get", "(", ")", ";", "if", "(", "bite", "===", "EOF_byte", "&&", "shiftjis_lead", "===", "0x00", ")", "{", "return", "EOF_code_point", ";", "}", "if", "(", "bite", "===", "EOF_byte", "&&", "shiftjis_lead", "!==", "0x00", ")", "{", "shiftjis_lead", "=", "0x00", ";", "return", "decoderError", "(", "fatal", ")", ";", "}", "byte_pointer", ".", "offset", "(", "1", ")", ";", "if", "(", "shiftjis_lead", "!==", "0x00", ")", "{", "var", "lead", "=", "shiftjis_lead", ";", "shiftjis_lead", "=", "0x00", ";", "if", "(", "inRange", "(", "bite", ",", "0x40", ",", "0x7E", ")", "||", "inRange", "(", "bite", ",", "0x80", ",", "0xFC", ")", ")", "{", "var", "offset", "=", "(", "bite", "<", "0x7F", ")", "?", "0x40", ":", "0x41", ";", "var", "lead_offset", "=", "(", "lead", "<", "0xA0", ")", "?", "0x81", ":", "0xC1", ";", "var", "code_point", "=", "indexCodePointFor", "(", "(", "lead", "-", "lead_offset", ")", "*", "188", "+", "bite", "-", "offset", ",", "indexes", "[", "'jis0208'", "]", ")", ";", "if", "(", "code_point", "===", "null", ")", "{", "return", "decoderError", "(", "fatal", ")", ";", "}", "return", "code_point", ";", "}", "byte_pointer", ".", "offset", "(", "-", "1", ")", ";", "return", "decoderError", "(", "fatal", ")", ";", "}", "if", "(", "inRange", "(", "bite", ",", "0x00", ",", "0x80", ")", ")", "{", "return", "bite", ";", "}", "if", "(", "inRange", "(", "bite", ",", "0xA1", ",", "0xDF", ")", ")", "{", "return", "0xFF61", "+", "bite", "-", "0xA1", ";", "}", "if", "(", "inRange", "(", "bite", ",", "0x81", ",", "0x9F", ")", "||", "inRange", "(", "bite", ",", "0xE0", ",", "0xFC", ")", ")", "{", "shiftjis_lead", "=", "bite", ";", "return", "null", ";", "}", "return", "decoderError", "(", "fatal", ")", ";", "}", ";", "}" ]
12.3 shift_jis @constructor @param {{fatal: boolean}} options
[ "12", ".", "3", "shift_jis" ]
da0e67d503cc39727dfa3a85c142d19de6f2c8c7
https://github.com/mscdex/busboy/blob/da0e67d503cc39727dfa3a85c142d19de6f2c8c7/deps/encoding/encoding.js#L2016-L2062
10,978
mscdex/busboy
deps/encoding/encoding.js
EUCKRDecoder
function EUCKRDecoder(options) { var fatal = options.fatal; var /** @type {number} */ euckr_lead = 0x00; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte && euckr_lead === 0) { return EOF_code_point; } if (bite === EOF_byte && euckr_lead !== 0) { euckr_lead = 0x00; return decoderError(fatal); } byte_pointer.offset(1); if (euckr_lead !== 0x00) { var lead = euckr_lead; var pointer = null; euckr_lead = 0x00; if (inRange(lead, 0x81, 0xC6)) { var temp = (26 + 26 + 126) * (lead - 0x81); if (inRange(bite, 0x41, 0x5A)) { pointer = temp + bite - 0x41; } else if (inRange(bite, 0x61, 0x7A)) { pointer = temp + 26 + bite - 0x61; } else if (inRange(bite, 0x81, 0xFE)) { pointer = temp + 26 + 26 + bite - 0x81; } } if (inRange(lead, 0xC7, 0xFD) && inRange(bite, 0xA1, 0xFE)) { pointer = (26 + 26 + 126) * (0xC7 - 0x81) + (lead - 0xC7) * 94 + (bite - 0xA1); } var code_point = (pointer === null) ? null : indexCodePointFor(pointer, indexes['euc-kr']); if (pointer === null) { byte_pointer.offset(-1); } if (code_point === null) { return decoderError(fatal); } return code_point; } if (inRange(bite, 0x00, 0x7F)) { return bite; } if (inRange(bite, 0x81, 0xFD)) { euckr_lead = bite; return null; } return decoderError(fatal); }; }
javascript
function EUCKRDecoder(options) { var fatal = options.fatal; var /** @type {number} */ euckr_lead = 0x00; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte && euckr_lead === 0) { return EOF_code_point; } if (bite === EOF_byte && euckr_lead !== 0) { euckr_lead = 0x00; return decoderError(fatal); } byte_pointer.offset(1); if (euckr_lead !== 0x00) { var lead = euckr_lead; var pointer = null; euckr_lead = 0x00; if (inRange(lead, 0x81, 0xC6)) { var temp = (26 + 26 + 126) * (lead - 0x81); if (inRange(bite, 0x41, 0x5A)) { pointer = temp + bite - 0x41; } else if (inRange(bite, 0x61, 0x7A)) { pointer = temp + 26 + bite - 0x61; } else if (inRange(bite, 0x81, 0xFE)) { pointer = temp + 26 + 26 + bite - 0x81; } } if (inRange(lead, 0xC7, 0xFD) && inRange(bite, 0xA1, 0xFE)) { pointer = (26 + 26 + 126) * (0xC7 - 0x81) + (lead - 0xC7) * 94 + (bite - 0xA1); } var code_point = (pointer === null) ? null : indexCodePointFor(pointer, indexes['euc-kr']); if (pointer === null) { byte_pointer.offset(-1); } if (code_point === null) { return decoderError(fatal); } return code_point; } if (inRange(bite, 0x00, 0x7F)) { return bite; } if (inRange(bite, 0x81, 0xFD)) { euckr_lead = bite; return null; } return decoderError(fatal); }; }
[ "function", "EUCKRDecoder", "(", "options", ")", "{", "var", "fatal", "=", "options", ".", "fatal", ";", "var", "/** @type {number} */", "euckr_lead", "=", "0x00", ";", "/**\n * @param {ByteInputStream} byte_pointer The byte stream to decode.\n * @return {?number} The next code point decoded, or null if not enough\n * data exists in the input stream to decode a complete code point.\n */", "this", ".", "decode", "=", "function", "(", "byte_pointer", ")", "{", "var", "bite", "=", "byte_pointer", ".", "get", "(", ")", ";", "if", "(", "bite", "===", "EOF_byte", "&&", "euckr_lead", "===", "0", ")", "{", "return", "EOF_code_point", ";", "}", "if", "(", "bite", "===", "EOF_byte", "&&", "euckr_lead", "!==", "0", ")", "{", "euckr_lead", "=", "0x00", ";", "return", "decoderError", "(", "fatal", ")", ";", "}", "byte_pointer", ".", "offset", "(", "1", ")", ";", "if", "(", "euckr_lead", "!==", "0x00", ")", "{", "var", "lead", "=", "euckr_lead", ";", "var", "pointer", "=", "null", ";", "euckr_lead", "=", "0x00", ";", "if", "(", "inRange", "(", "lead", ",", "0x81", ",", "0xC6", ")", ")", "{", "var", "temp", "=", "(", "26", "+", "26", "+", "126", ")", "*", "(", "lead", "-", "0x81", ")", ";", "if", "(", "inRange", "(", "bite", ",", "0x41", ",", "0x5A", ")", ")", "{", "pointer", "=", "temp", "+", "bite", "-", "0x41", ";", "}", "else", "if", "(", "inRange", "(", "bite", ",", "0x61", ",", "0x7A", ")", ")", "{", "pointer", "=", "temp", "+", "26", "+", "bite", "-", "0x61", ";", "}", "else", "if", "(", "inRange", "(", "bite", ",", "0x81", ",", "0xFE", ")", ")", "{", "pointer", "=", "temp", "+", "26", "+", "26", "+", "bite", "-", "0x81", ";", "}", "}", "if", "(", "inRange", "(", "lead", ",", "0xC7", ",", "0xFD", ")", "&&", "inRange", "(", "bite", ",", "0xA1", ",", "0xFE", ")", ")", "{", "pointer", "=", "(", "26", "+", "26", "+", "126", ")", "*", "(", "0xC7", "-", "0x81", ")", "+", "(", "lead", "-", "0xC7", ")", "*", "94", "+", "(", "bite", "-", "0xA1", ")", ";", "}", "var", "code_point", "=", "(", "pointer", "===", "null", ")", "?", "null", ":", "indexCodePointFor", "(", "pointer", ",", "indexes", "[", "'euc-kr'", "]", ")", ";", "if", "(", "pointer", "===", "null", ")", "{", "byte_pointer", ".", "offset", "(", "-", "1", ")", ";", "}", "if", "(", "code_point", "===", "null", ")", "{", "return", "decoderError", "(", "fatal", ")", ";", "}", "return", "code_point", ";", "}", "if", "(", "inRange", "(", "bite", ",", "0x00", ",", "0x7F", ")", ")", "{", "return", "bite", ";", "}", "if", "(", "inRange", "(", "bite", ",", "0x81", ",", "0xFD", ")", ")", "{", "euckr_lead", "=", "bite", ";", "return", "null", ";", "}", "return", "decoderError", "(", "fatal", ")", ";", "}", ";", "}" ]
13.1 euc-kr @constructor @param {{fatal: boolean}} options
[ "13", ".", "1", "euc", "-", "kr" ]
da0e67d503cc39727dfa3a85c142d19de6f2c8c7
https://github.com/mscdex/busboy/blob/da0e67d503cc39727dfa3a85c142d19de6f2c8c7/deps/encoding/encoding.js#L2124-L2185
10,979
mscdex/busboy
deps/encoding/encoding.js
UTF16Decoder
function UTF16Decoder(utf16_be, options) { var fatal = options.fatal; var /** @type {?number} */ utf16_lead_byte = null, /** @type {?number} */ utf16_lead_surrogate = null; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte && utf16_lead_byte === null && utf16_lead_surrogate === null) { return EOF_code_point; } if (bite === EOF_byte && (utf16_lead_byte !== null || utf16_lead_surrogate !== null)) { return decoderError(fatal); } byte_pointer.offset(1); if (utf16_lead_byte === null) { utf16_lead_byte = bite; return null; } var code_point; if (utf16_be) { code_point = (utf16_lead_byte << 8) + bite; } else { code_point = (bite << 8) + utf16_lead_byte; } utf16_lead_byte = null; if (utf16_lead_surrogate !== null) { var lead_surrogate = utf16_lead_surrogate; utf16_lead_surrogate = null; if (inRange(code_point, 0xDC00, 0xDFFF)) { return 0x10000 + (lead_surrogate - 0xD800) * 0x400 + (code_point - 0xDC00); } byte_pointer.offset(-2); return decoderError(fatal); } if (inRange(code_point, 0xD800, 0xDBFF)) { utf16_lead_surrogate = code_point; return null; } if (inRange(code_point, 0xDC00, 0xDFFF)) { return decoderError(fatal); } return code_point; }; }
javascript
function UTF16Decoder(utf16_be, options) { var fatal = options.fatal; var /** @type {?number} */ utf16_lead_byte = null, /** @type {?number} */ utf16_lead_surrogate = null; /** * @param {ByteInputStream} byte_pointer The byte stream to decode. * @return {?number} The next code point decoded, or null if not enough * data exists in the input stream to decode a complete code point. */ this.decode = function(byte_pointer) { var bite = byte_pointer.get(); if (bite === EOF_byte && utf16_lead_byte === null && utf16_lead_surrogate === null) { return EOF_code_point; } if (bite === EOF_byte && (utf16_lead_byte !== null || utf16_lead_surrogate !== null)) { return decoderError(fatal); } byte_pointer.offset(1); if (utf16_lead_byte === null) { utf16_lead_byte = bite; return null; } var code_point; if (utf16_be) { code_point = (utf16_lead_byte << 8) + bite; } else { code_point = (bite << 8) + utf16_lead_byte; } utf16_lead_byte = null; if (utf16_lead_surrogate !== null) { var lead_surrogate = utf16_lead_surrogate; utf16_lead_surrogate = null; if (inRange(code_point, 0xDC00, 0xDFFF)) { return 0x10000 + (lead_surrogate - 0xD800) * 0x400 + (code_point - 0xDC00); } byte_pointer.offset(-2); return decoderError(fatal); } if (inRange(code_point, 0xD800, 0xDBFF)) { utf16_lead_surrogate = code_point; return null; } if (inRange(code_point, 0xDC00, 0xDFFF)) { return decoderError(fatal); } return code_point; }; }
[ "function", "UTF16Decoder", "(", "utf16_be", ",", "options", ")", "{", "var", "fatal", "=", "options", ".", "fatal", ";", "var", "/** @type {?number} */", "utf16_lead_byte", "=", "null", ",", "/** @type {?number} */", "utf16_lead_surrogate", "=", "null", ";", "/**\n * @param {ByteInputStream} byte_pointer The byte stream to decode.\n * @return {?number} The next code point decoded, or null if not enough\n * data exists in the input stream to decode a complete code point.\n */", "this", ".", "decode", "=", "function", "(", "byte_pointer", ")", "{", "var", "bite", "=", "byte_pointer", ".", "get", "(", ")", ";", "if", "(", "bite", "===", "EOF_byte", "&&", "utf16_lead_byte", "===", "null", "&&", "utf16_lead_surrogate", "===", "null", ")", "{", "return", "EOF_code_point", ";", "}", "if", "(", "bite", "===", "EOF_byte", "&&", "(", "utf16_lead_byte", "!==", "null", "||", "utf16_lead_surrogate", "!==", "null", ")", ")", "{", "return", "decoderError", "(", "fatal", ")", ";", "}", "byte_pointer", ".", "offset", "(", "1", ")", ";", "if", "(", "utf16_lead_byte", "===", "null", ")", "{", "utf16_lead_byte", "=", "bite", ";", "return", "null", ";", "}", "var", "code_point", ";", "if", "(", "utf16_be", ")", "{", "code_point", "=", "(", "utf16_lead_byte", "<<", "8", ")", "+", "bite", ";", "}", "else", "{", "code_point", "=", "(", "bite", "<<", "8", ")", "+", "utf16_lead_byte", ";", "}", "utf16_lead_byte", "=", "null", ";", "if", "(", "utf16_lead_surrogate", "!==", "null", ")", "{", "var", "lead_surrogate", "=", "utf16_lead_surrogate", ";", "utf16_lead_surrogate", "=", "null", ";", "if", "(", "inRange", "(", "code_point", ",", "0xDC00", ",", "0xDFFF", ")", ")", "{", "return", "0x10000", "+", "(", "lead_surrogate", "-", "0xD800", ")", "*", "0x400", "+", "(", "code_point", "-", "0xDC00", ")", ";", "}", "byte_pointer", ".", "offset", "(", "-", "2", ")", ";", "return", "decoderError", "(", "fatal", ")", ";", "}", "if", "(", "inRange", "(", "code_point", ",", "0xD800", ",", "0xDBFF", ")", ")", "{", "utf16_lead_surrogate", "=", "code_point", ";", "return", "null", ";", "}", "if", "(", "inRange", "(", "code_point", ",", "0xDC00", ",", "0xDFFF", ")", ")", "{", "return", "decoderError", "(", "fatal", ")", ";", "}", "return", "code_point", ";", "}", ";", "}" ]
14.2 utf-16 @constructor @param {boolean} utf16_be True if big-endian, false if little-endian. @param {{fatal: boolean}} options
[ "14", ".", "2", "utf", "-", "16" ]
da0e67d503cc39727dfa3a85c142d19de6f2c8c7
https://github.com/mscdex/busboy/blob/da0e67d503cc39727dfa3a85c142d19de6f2c8c7/deps/encoding/encoding.js#L2250-L2300
10,980
angular-translate/angular-translate
Gruntfile.js
function () { var scopes = fs.readdirSync('./test_scopes').filter(function (filename) { return filename[0] !== '.'; }); var config = { options: { color: false, interactive: false } }; // Create a sub config for each test scope for (var idx in scopes) { var scope = scopes[idx]; config['test_scopes_' + scope] = { options: { cwd: 'test_scopes/' + scope, production: false } }; } return config; }
javascript
function () { var scopes = fs.readdirSync('./test_scopes').filter(function (filename) { return filename[0] !== '.'; }); var config = { options: { color: false, interactive: false } }; // Create a sub config for each test scope for (var idx in scopes) { var scope = scopes[idx]; config['test_scopes_' + scope] = { options: { cwd: 'test_scopes/' + scope, production: false } }; } return config; }
[ "function", "(", ")", "{", "var", "scopes", "=", "fs", ".", "readdirSync", "(", "'./test_scopes'", ")", ".", "filter", "(", "function", "(", "filename", ")", "{", "return", "filename", "[", "0", "]", "!==", "'.'", ";", "}", ")", ";", "var", "config", "=", "{", "options", ":", "{", "color", ":", "false", ",", "interactive", ":", "false", "}", "}", ";", "// Create a sub config for each test scope", "for", "(", "var", "idx", "in", "scopes", ")", "{", "var", "scope", "=", "scopes", "[", "idx", "]", ";", "config", "[", "'test_scopes_'", "+", "scope", "]", "=", "{", "options", ":", "{", "cwd", ":", "'test_scopes/'", "+", "scope", ",", "production", ":", "false", "}", "}", ";", "}", "return", "config", ";", "}" ]
Returns configuration for bower-install plugin
[ "Returns", "configuration", "for", "bower", "-", "install", "plugin" ]
eda9f29b3343d84f43f9fa30a39a1ae636d1c494
https://github.com/angular-translate/angular-translate/blob/eda9f29b3343d84f43f9fa30a39a1ae636d1c494/Gruntfile.js#L12-L33
10,981
angular-translate/angular-translate
src/directive/translate-attr.js
function () { angular.forEach(translateAttr, function (translationId, attributeName) { if (!translationId) { return; } previousAttributes[attributeName] = true; // if translation id starts with '.' and translateNamespace given, prepend namespace if (scope.translateNamespace && translationId.charAt(0) === '.') { translationId = scope.translateNamespace + translationId; } $translate(translationId, translateValues, attr.translateInterpolation, undefined, scope.translateLanguage, translateSanitizeStrategy) .then(function (translation) { element.attr(attributeName, translation); }, function (translationId) { element.attr(attributeName, translationId); }); }); // Removing unused attributes that were previously used angular.forEach(previousAttributes, function (flag, attributeName) { if (!translateAttr[attributeName]) { element.removeAttr(attributeName); delete previousAttributes[attributeName]; } }); }
javascript
function () { angular.forEach(translateAttr, function (translationId, attributeName) { if (!translationId) { return; } previousAttributes[attributeName] = true; // if translation id starts with '.' and translateNamespace given, prepend namespace if (scope.translateNamespace && translationId.charAt(0) === '.') { translationId = scope.translateNamespace + translationId; } $translate(translationId, translateValues, attr.translateInterpolation, undefined, scope.translateLanguage, translateSanitizeStrategy) .then(function (translation) { element.attr(attributeName, translation); }, function (translationId) { element.attr(attributeName, translationId); }); }); // Removing unused attributes that were previously used angular.forEach(previousAttributes, function (flag, attributeName) { if (!translateAttr[attributeName]) { element.removeAttr(attributeName); delete previousAttributes[attributeName]; } }); }
[ "function", "(", ")", "{", "angular", ".", "forEach", "(", "translateAttr", ",", "function", "(", "translationId", ",", "attributeName", ")", "{", "if", "(", "!", "translationId", ")", "{", "return", ";", "}", "previousAttributes", "[", "attributeName", "]", "=", "true", ";", "// if translation id starts with '.' and translateNamespace given, prepend namespace", "if", "(", "scope", ".", "translateNamespace", "&&", "translationId", ".", "charAt", "(", "0", ")", "===", "'.'", ")", "{", "translationId", "=", "scope", ".", "translateNamespace", "+", "translationId", ";", "}", "$translate", "(", "translationId", ",", "translateValues", ",", "attr", ".", "translateInterpolation", ",", "undefined", ",", "scope", ".", "translateLanguage", ",", "translateSanitizeStrategy", ")", ".", "then", "(", "function", "(", "translation", ")", "{", "element", ".", "attr", "(", "attributeName", ",", "translation", ")", ";", "}", ",", "function", "(", "translationId", ")", "{", "element", ".", "attr", "(", "attributeName", ",", "translationId", ")", ";", "}", ")", ";", "}", ")", ";", "// Removing unused attributes that were previously used", "angular", ".", "forEach", "(", "previousAttributes", ",", "function", "(", "flag", ",", "attributeName", ")", "{", "if", "(", "!", "translateAttr", "[", "attributeName", "]", ")", "{", "element", ".", "removeAttr", "(", "attributeName", ")", ";", "delete", "previousAttributes", "[", "attributeName", "]", ";", "}", "}", ")", ";", "}" ]
Main update translations function
[ "Main", "update", "translations", "function" ]
eda9f29b3343d84f43f9fa30a39a1ae636d1c494
https://github.com/angular-translate/angular-translate/blob/eda9f29b3343d84f43f9fa30a39a1ae636d1c494/src/directive/translate-attr.js#L75-L101
10,982
angular-translate/angular-translate
src/service/loader-partial.js
function () { return $http( angular.extend({ method : 'GET', url : self.parseUrl(self.urlTemplate || urlTemplate, lang) }, $httpOptions) ); }
javascript
function () { return $http( angular.extend({ method : 'GET', url : self.parseUrl(self.urlTemplate || urlTemplate, lang) }, $httpOptions) ); }
[ "function", "(", ")", "{", "return", "$http", "(", "angular", ".", "extend", "(", "{", "method", ":", "'GET'", ",", "url", ":", "self", ".", "parseUrl", "(", "self", ".", "urlTemplate", "||", "urlTemplate", ",", "lang", ")", "}", ",", "$httpOptions", ")", ")", ";", "}" ]
private helper helpers
[ "private", "helper", "helpers" ]
eda9f29b3343d84f43f9fa30a39a1ae636d1c494
https://github.com/angular-translate/angular-translate/blob/eda9f29b3343d84f43f9fa30a39a1ae636d1c494/src/service/loader-partial.js#L63-L71
10,983
dceejay/RedMap
worldmap/worldmap.js
function() { ws = new SockJS(location.pathname.split("index")[0] + 'socket'); ws.onopen = function() { console.log("CONNECTED"); if (!inIframe) { document.getElementById("footer").innerHTML = "<font color='#494'>"+ibmfoot+"</font>"; } ws.send(JSON.stringify({action:"connected"})); onoffline(); }; ws.onclose = function() { console.log("DISCONNECTED"); if (!inIframe) { document.getElementById("footer").innerHTML = "<font color='#900'>"+ibmfoot+"</font>"; } setTimeout(function() { connect(); }, 2500); }; ws.onmessage = function(e) { var data = JSON.parse(e.data); //console.log("DATA" typeof data,data); if (Array.isArray(data)) { //console.log("ARRAY"); // map.closePopup(); // var bnds= L.latLngBounds([0,0]); for (var prop in data) { if (data[prop].command) { doCommand(data[prop].command); delete data[prop].command; } if (data[prop].hasOwnProperty("name")) { setMarker(data[prop]); // bnds.extend(markers[data[prop].name].getLatLng()); } else { console.log("SKIP A",data[prop]); } } // map.fitBounds(bnds.pad(0.25)); } else { if (data.command) { doCommand(data.command); delete data.command; } if (data.hasOwnProperty("name")) { setMarker(data); } else if (data.hasOwnProperty("type")) { doGeojson(data); } else { console.log("SKIP",data); // if (typeof data === "string") { doDialog(data); } // else { console.log("SKIP",data); } } } }; }
javascript
function() { ws = new SockJS(location.pathname.split("index")[0] + 'socket'); ws.onopen = function() { console.log("CONNECTED"); if (!inIframe) { document.getElementById("footer").innerHTML = "<font color='#494'>"+ibmfoot+"</font>"; } ws.send(JSON.stringify({action:"connected"})); onoffline(); }; ws.onclose = function() { console.log("DISCONNECTED"); if (!inIframe) { document.getElementById("footer").innerHTML = "<font color='#900'>"+ibmfoot+"</font>"; } setTimeout(function() { connect(); }, 2500); }; ws.onmessage = function(e) { var data = JSON.parse(e.data); //console.log("DATA" typeof data,data); if (Array.isArray(data)) { //console.log("ARRAY"); // map.closePopup(); // var bnds= L.latLngBounds([0,0]); for (var prop in data) { if (data[prop].command) { doCommand(data[prop].command); delete data[prop].command; } if (data[prop].hasOwnProperty("name")) { setMarker(data[prop]); // bnds.extend(markers[data[prop].name].getLatLng()); } else { console.log("SKIP A",data[prop]); } } // map.fitBounds(bnds.pad(0.25)); } else { if (data.command) { doCommand(data.command); delete data.command; } if (data.hasOwnProperty("name")) { setMarker(data); } else if (data.hasOwnProperty("type")) { doGeojson(data); } else { console.log("SKIP",data); // if (typeof data === "string") { doDialog(data); } // else { console.log("SKIP",data); } } } }; }
[ "function", "(", ")", "{", "ws", "=", "new", "SockJS", "(", "location", ".", "pathname", ".", "split", "(", "\"index\"", ")", "[", "0", "]", "+", "'socket'", ")", ";", "ws", ".", "onopen", "=", "function", "(", ")", "{", "console", ".", "log", "(", "\"CONNECTED\"", ")", ";", "if", "(", "!", "inIframe", ")", "{", "document", ".", "getElementById", "(", "\"footer\"", ")", ".", "innerHTML", "=", "\"<font color='#494'>\"", "+", "ibmfoot", "+", "\"</font>\"", ";", "}", "ws", ".", "send", "(", "JSON", ".", "stringify", "(", "{", "action", ":", "\"connected\"", "}", ")", ")", ";", "onoffline", "(", ")", ";", "}", ";", "ws", ".", "onclose", "=", "function", "(", ")", "{", "console", ".", "log", "(", "\"DISCONNECTED\"", ")", ";", "if", "(", "!", "inIframe", ")", "{", "document", ".", "getElementById", "(", "\"footer\"", ")", ".", "innerHTML", "=", "\"<font color='#900'>\"", "+", "ibmfoot", "+", "\"</font>\"", ";", "}", "setTimeout", "(", "function", "(", ")", "{", "connect", "(", ")", ";", "}", ",", "2500", ")", ";", "}", ";", "ws", ".", "onmessage", "=", "function", "(", "e", ")", "{", "var", "data", "=", "JSON", ".", "parse", "(", "e", ".", "data", ")", ";", "//console.log(\"DATA\" typeof data,data);", "if", "(", "Array", ".", "isArray", "(", "data", ")", ")", "{", "//console.log(\"ARRAY\");", "// map.closePopup();", "// var bnds= L.latLngBounds([0,0]);", "for", "(", "var", "prop", "in", "data", ")", "{", "if", "(", "data", "[", "prop", "]", ".", "command", ")", "{", "doCommand", "(", "data", "[", "prop", "]", ".", "command", ")", ";", "delete", "data", "[", "prop", "]", ".", "command", ";", "}", "if", "(", "data", "[", "prop", "]", ".", "hasOwnProperty", "(", "\"name\"", ")", ")", "{", "setMarker", "(", "data", "[", "prop", "]", ")", ";", "// bnds.extend(markers[data[prop].name].getLatLng());", "}", "else", "{", "console", ".", "log", "(", "\"SKIP A\"", ",", "data", "[", "prop", "]", ")", ";", "}", "}", "// map.fitBounds(bnds.pad(0.25));", "}", "else", "{", "if", "(", "data", ".", "command", ")", "{", "doCommand", "(", "data", ".", "command", ")", ";", "delete", "data", ".", "command", ";", "}", "if", "(", "data", ".", "hasOwnProperty", "(", "\"name\"", ")", ")", "{", "setMarker", "(", "data", ")", ";", "}", "else", "if", "(", "data", ".", "hasOwnProperty", "(", "\"type\"", ")", ")", "{", "doGeojson", "(", "data", ")", ";", "}", "else", "{", "console", ".", "log", "(", "\"SKIP\"", ",", "data", ")", ";", "// if (typeof data === \"string\") { doDialog(data); }", "// else { console.log(\"SKIP\",data); }", "}", "}", "}", ";", "}" ]
Create the socket
[ "Create", "the", "socket" ]
94aa812ed2c63d02205c29e3e367815229f441f6
https://github.com/dceejay/RedMap/blob/94aa812ed2c63d02205c29e3e367815229f441f6/worldmap/worldmap.js#L47-L92
10,984
dceejay/RedMap
worldmap/worldmap.js
doTidyUp
function doTidyUp(l) { var d = parseInt(Date.now()/1000); for (var m in markers) { if ((l && (l == markers[m].lay)) || typeof markers[m].ts != "undefined") { if ((l && (l == markers[m].lay)) || (markers[m].hasOwnProperty("ts") && (Number(markers[m].ts) < d) && (markers[m].lay !== "_drawing"))) { //console.log("STALE :",m); layers[markers[m].lay].removeLayer(markers[m]); if (typeof polygons[m] != "undefined") { layers[markers[m].lay].removeLayer(polygons[m]); delete polygons[m]; } if (typeof polygons[m+"_"] != "undefined") { layers[polygons[m+"_"].lay].removeLayer(polygons[m+"_"]); delete polygons[m+"_"]; } delete markers[m]; } } } if (l) { if (layers[l]) { map.removeLayer(layers[l]); layercontrol.removeLayer(layers[l]); delete layers[l]; } if (overlays[l]) { map.removeLayer(overlays[l]); layercontrol.removeLayer(overlays[l]); delete overlays[l]; } } }
javascript
function doTidyUp(l) { var d = parseInt(Date.now()/1000); for (var m in markers) { if ((l && (l == markers[m].lay)) || typeof markers[m].ts != "undefined") { if ((l && (l == markers[m].lay)) || (markers[m].hasOwnProperty("ts") && (Number(markers[m].ts) < d) && (markers[m].lay !== "_drawing"))) { //console.log("STALE :",m); layers[markers[m].lay].removeLayer(markers[m]); if (typeof polygons[m] != "undefined") { layers[markers[m].lay].removeLayer(polygons[m]); delete polygons[m]; } if (typeof polygons[m+"_"] != "undefined") { layers[polygons[m+"_"].lay].removeLayer(polygons[m+"_"]); delete polygons[m+"_"]; } delete markers[m]; } } } if (l) { if (layers[l]) { map.removeLayer(layers[l]); layercontrol.removeLayer(layers[l]); delete layers[l]; } if (overlays[l]) { map.removeLayer(overlays[l]); layercontrol.removeLayer(overlays[l]); delete overlays[l]; } } }
[ "function", "doTidyUp", "(", "l", ")", "{", "var", "d", "=", "parseInt", "(", "Date", ".", "now", "(", ")", "/", "1000", ")", ";", "for", "(", "var", "m", "in", "markers", ")", "{", "if", "(", "(", "l", "&&", "(", "l", "==", "markers", "[", "m", "]", ".", "lay", ")", ")", "||", "typeof", "markers", "[", "m", "]", ".", "ts", "!=", "\"undefined\"", ")", "{", "if", "(", "(", "l", "&&", "(", "l", "==", "markers", "[", "m", "]", ".", "lay", ")", ")", "||", "(", "markers", "[", "m", "]", ".", "hasOwnProperty", "(", "\"ts\"", ")", "&&", "(", "Number", "(", "markers", "[", "m", "]", ".", "ts", ")", "<", "d", ")", "&&", "(", "markers", "[", "m", "]", ".", "lay", "!==", "\"_drawing\"", ")", ")", ")", "{", "//console.log(\"STALE :\",m);", "layers", "[", "markers", "[", "m", "]", ".", "lay", "]", ".", "removeLayer", "(", "markers", "[", "m", "]", ")", ";", "if", "(", "typeof", "polygons", "[", "m", "]", "!=", "\"undefined\"", ")", "{", "layers", "[", "markers", "[", "m", "]", ".", "lay", "]", ".", "removeLayer", "(", "polygons", "[", "m", "]", ")", ";", "delete", "polygons", "[", "m", "]", ";", "}", "if", "(", "typeof", "polygons", "[", "m", "+", "\"_\"", "]", "!=", "\"undefined\"", ")", "{", "layers", "[", "polygons", "[", "m", "+", "\"_\"", "]", ".", "lay", "]", ".", "removeLayer", "(", "polygons", "[", "m", "+", "\"_\"", "]", ")", ";", "delete", "polygons", "[", "m", "+", "\"_\"", "]", ";", "}", "delete", "markers", "[", "m", "]", ";", "}", "}", "}", "if", "(", "l", ")", "{", "if", "(", "layers", "[", "l", "]", ")", "{", "map", ".", "removeLayer", "(", "layers", "[", "l", "]", ")", ";", "layercontrol", ".", "removeLayer", "(", "layers", "[", "l", "]", ")", ";", "delete", "layers", "[", "l", "]", ";", "}", "if", "(", "overlays", "[", "l", "]", ")", "{", "map", ".", "removeLayer", "(", "overlays", "[", "l", "]", ")", ";", "layercontrol", ".", "removeLayer", "(", "overlays", "[", "l", "]", ")", ";", "delete", "overlays", "[", "l", "]", ";", "}", "}", "}" ]
Remove old markers
[ "Remove", "old", "markers" ]
94aa812ed2c63d02205c29e3e367815229f441f6
https://github.com/dceejay/RedMap/blob/94aa812ed2c63d02205c29e3e367815229f441f6/worldmap/worldmap.js#L253-L276
10,985
dceejay/RedMap
worldmap/worldmap.js
doSearch
function doSearch() { var value = document.getElementById('search').value; marks = []; marksIndex = 0; for (var key in markers) { if ( (~(key.toLowerCase()).indexOf(value.toLowerCase())) && (mb.contains(markers[key].getLatLng()))) { marks.push(markers[key]); } if (markers[key].icon === value) { marks.push(markers[key]); } } moveToMarks(); if (marks.length === 0) { // If no markers found let's try a geolookup... var protocol = location.protocol; if (protocol == "file:") { protocol = "https:"; } var searchUrl = protocol + "//nominatim.openstreetmap.org/search?format=json&limit=1&q="; fetch(searchUrl + value) // Call the fetch function passing the url of the API as a parameter .then(function(resp) { return resp.json(); }) .then(function(data) { if (data.length > 0) { var bb = data[0].boundingbox; map.fitBounds([ [bb[0],bb[2]], [bb[1],bb[3]] ]); map.panTo([data[0].lat, data[0].lon]); } else { document.getElementById('searchResult').innerHTML = "&nbsp;<font color='#ff0'>Not Found</font>"; } }) .catch(function(err) { if (err.toString() === "TypeError: Failed to fetch") { document.getElementById('searchResult').innerHTML = "&nbsp;<font color='#ff0'>Not Found</font>"; } }); } else { if (lockit) { document.getElementById('searchResult').innerHTML = "&nbsp;<font color='#ff0'>Found "+marks.length+" results within bounds.</font>"; } else { document.getElementById('searchResult').innerHTML = "&nbsp;<font color='#ff0'>Found "+marks.length+" results.</font>"; } } }
javascript
function doSearch() { var value = document.getElementById('search').value; marks = []; marksIndex = 0; for (var key in markers) { if ( (~(key.toLowerCase()).indexOf(value.toLowerCase())) && (mb.contains(markers[key].getLatLng()))) { marks.push(markers[key]); } if (markers[key].icon === value) { marks.push(markers[key]); } } moveToMarks(); if (marks.length === 0) { // If no markers found let's try a geolookup... var protocol = location.protocol; if (protocol == "file:") { protocol = "https:"; } var searchUrl = protocol + "//nominatim.openstreetmap.org/search?format=json&limit=1&q="; fetch(searchUrl + value) // Call the fetch function passing the url of the API as a parameter .then(function(resp) { return resp.json(); }) .then(function(data) { if (data.length > 0) { var bb = data[0].boundingbox; map.fitBounds([ [bb[0],bb[2]], [bb[1],bb[3]] ]); map.panTo([data[0].lat, data[0].lon]); } else { document.getElementById('searchResult').innerHTML = "&nbsp;<font color='#ff0'>Not Found</font>"; } }) .catch(function(err) { if (err.toString() === "TypeError: Failed to fetch") { document.getElementById('searchResult').innerHTML = "&nbsp;<font color='#ff0'>Not Found</font>"; } }); } else { if (lockit) { document.getElementById('searchResult').innerHTML = "&nbsp;<font color='#ff0'>Found "+marks.length+" results within bounds.</font>"; } else { document.getElementById('searchResult').innerHTML = "&nbsp;<font color='#ff0'>Found "+marks.length+" results.</font>"; } } }
[ "function", "doSearch", "(", ")", "{", "var", "value", "=", "document", ".", "getElementById", "(", "'search'", ")", ".", "value", ";", "marks", "=", "[", "]", ";", "marksIndex", "=", "0", ";", "for", "(", "var", "key", "in", "markers", ")", "{", "if", "(", "(", "~", "(", "key", ".", "toLowerCase", "(", ")", ")", ".", "indexOf", "(", "value", ".", "toLowerCase", "(", ")", ")", ")", "&&", "(", "mb", ".", "contains", "(", "markers", "[", "key", "]", ".", "getLatLng", "(", ")", ")", ")", ")", "{", "marks", ".", "push", "(", "markers", "[", "key", "]", ")", ";", "}", "if", "(", "markers", "[", "key", "]", ".", "icon", "===", "value", ")", "{", "marks", ".", "push", "(", "markers", "[", "key", "]", ")", ";", "}", "}", "moveToMarks", "(", ")", ";", "if", "(", "marks", ".", "length", "===", "0", ")", "{", "// If no markers found let's try a geolookup...", "var", "protocol", "=", "location", ".", "protocol", ";", "if", "(", "protocol", "==", "\"file:\"", ")", "{", "protocol", "=", "\"https:\"", ";", "}", "var", "searchUrl", "=", "protocol", "+", "\"//nominatim.openstreetmap.org/search?format=json&limit=1&q=\"", ";", "fetch", "(", "searchUrl", "+", "value", ")", "// Call the fetch function passing the url of the API as a parameter", ".", "then", "(", "function", "(", "resp", ")", "{", "return", "resp", ".", "json", "(", ")", ";", "}", ")", ".", "then", "(", "function", "(", "data", ")", "{", "if", "(", "data", ".", "length", ">", "0", ")", "{", "var", "bb", "=", "data", "[", "0", "]", ".", "boundingbox", ";", "map", ".", "fitBounds", "(", "[", "[", "bb", "[", "0", "]", ",", "bb", "[", "2", "]", "]", ",", "[", "bb", "[", "1", "]", ",", "bb", "[", "3", "]", "]", "]", ")", ";", "map", ".", "panTo", "(", "[", "data", "[", "0", "]", ".", "lat", ",", "data", "[", "0", "]", ".", "lon", "]", ")", ";", "}", "else", "{", "document", ".", "getElementById", "(", "'searchResult'", ")", ".", "innerHTML", "=", "\"&nbsp;<font color='#ff0'>Not Found</font>\"", ";", "}", "}", ")", ".", "catch", "(", "function", "(", "err", ")", "{", "if", "(", "err", ".", "toString", "(", ")", "===", "\"TypeError: Failed to fetch\"", ")", "{", "document", ".", "getElementById", "(", "'searchResult'", ")", ".", "innerHTML", "=", "\"&nbsp;<font color='#ff0'>Not Found</font>\"", ";", "}", "}", ")", ";", "}", "else", "{", "if", "(", "lockit", ")", "{", "document", ".", "getElementById", "(", "'searchResult'", ")", ".", "innerHTML", "=", "\"&nbsp;<font color='#ff0'>Found \"", "+", "marks", ".", "length", "+", "\" results within bounds.</font>\"", ";", "}", "else", "{", "document", ".", "getElementById", "(", "'searchResult'", ")", ".", "innerHTML", "=", "\"&nbsp;<font color='#ff0'>Found \"", "+", "marks", ".", "length", "+", "\" results.</font>\"", ";", "}", "}", "}" ]
Search for markers with names of ... or icons of ...
[ "Search", "for", "markers", "with", "names", "of", "...", "or", "icons", "of", "..." ]
94aa812ed2c63d02205c29e3e367815229f441f6
https://github.com/dceejay/RedMap/blob/94aa812ed2c63d02205c29e3e367815229f441f6/worldmap/worldmap.js#L306-L350
10,986
dceejay/RedMap
worldmap/worldmap.js
moveToMarks
function moveToMarks() { if (marks.length > marksIndex) { var m = marks[marksIndex]; map.setView(m.getLatLng(), map.getZoom()); m.openPopup(); marksIndex++; setTimeout(moveToMarks, 2500); } }
javascript
function moveToMarks() { if (marks.length > marksIndex) { var m = marks[marksIndex]; map.setView(m.getLatLng(), map.getZoom()); m.openPopup(); marksIndex++; setTimeout(moveToMarks, 2500); } }
[ "function", "moveToMarks", "(", ")", "{", "if", "(", "marks", ".", "length", ">", "marksIndex", ")", "{", "var", "m", "=", "marks", "[", "marksIndex", "]", ";", "map", ".", "setView", "(", "m", ".", "getLatLng", "(", ")", ",", "map", ".", "getZoom", "(", ")", ")", ";", "m", ".", "openPopup", "(", ")", ";", "marksIndex", "++", ";", "setTimeout", "(", "moveToMarks", ",", "2500", ")", ";", "}", "}" ]
Jump to a markers position - centralise it on map
[ "Jump", "to", "a", "markers", "position", "-", "centralise", "it", "on", "map" ]
94aa812ed2c63d02205c29e3e367815229f441f6
https://github.com/dceejay/RedMap/blob/94aa812ed2c63d02205c29e3e367815229f441f6/worldmap/worldmap.js#L353-L361
10,987
dceejay/RedMap
worldmap/worldmap.js
clearSearch
function clearSearch() { var value = document.getElementById('search').value; marks = []; marksIndex = 0; for (var key in markers) { if ( (~(key.toLowerCase()).indexOf(value.toLowerCase())) && (mb.contains(markers[key].getLatLng()))) { marks.push(markers[key]); } } removeMarks(); if (lockit) { document.getElementById('searchResult').innerHTML = ""; } else { document.getElementById('searchResult').innerHTML = ""; } }
javascript
function clearSearch() { var value = document.getElementById('search').value; marks = []; marksIndex = 0; for (var key in markers) { if ( (~(key.toLowerCase()).indexOf(value.toLowerCase())) && (mb.contains(markers[key].getLatLng()))) { marks.push(markers[key]); } } removeMarks(); if (lockit) { document.getElementById('searchResult').innerHTML = ""; } else { document.getElementById('searchResult').innerHTML = ""; } }
[ "function", "clearSearch", "(", ")", "{", "var", "value", "=", "document", ".", "getElementById", "(", "'search'", ")", ".", "value", ";", "marks", "=", "[", "]", ";", "marksIndex", "=", "0", ";", "for", "(", "var", "key", "in", "markers", ")", "{", "if", "(", "(", "~", "(", "key", ".", "toLowerCase", "(", ")", ")", ".", "indexOf", "(", "value", ".", "toLowerCase", "(", ")", ")", ")", "&&", "(", "mb", ".", "contains", "(", "markers", "[", "key", "]", ".", "getLatLng", "(", ")", ")", ")", ")", "{", "marks", ".", "push", "(", "markers", "[", "key", "]", ")", ";", "}", "}", "removeMarks", "(", ")", ";", "if", "(", "lockit", ")", "{", "document", ".", "getElementById", "(", "'searchResult'", ")", ".", "innerHTML", "=", "\"\"", ";", "}", "else", "{", "document", ".", "getElementById", "(", "'searchResult'", ")", ".", "innerHTML", "=", "\"\"", ";", "}", "}" ]
Clear Search With Marker names
[ "Clear", "Search", "With", "Marker", "names" ]
94aa812ed2c63d02205c29e3e367815229f441f6
https://github.com/dceejay/RedMap/blob/94aa812ed2c63d02205c29e3e367815229f441f6/worldmap/worldmap.js#L364-L380
10,988
dceejay/RedMap
worldmap/worldmap.js
setMarker
function setMarker(data) { var rightmenu = function(m) { // customise right click context menu var rightcontext = ""; if (polygons[data.name] == undefined) { rightcontext = "<button id='delbutton' onclick='delMarker(\""+data.name+"\",true);'>Delete</button>"; } else if (data.editable) { rightcontext = "<button onclick='editPoly(\""+data.name+"\",true);'>Edit</button><button onclick='delMarker(\""+data.name+"\",true);'>Delete</button>"; } if ((data.contextmenu !== undefined) && (typeof data.contextmenu === "string")) { rightcontext = data.contextmenu.replace(/\$name/g,data.name); delete data.contextmenu; } if (rightcontext.length > 0) { var rightmenuMarker = L.popup({offset:[0,-12]}).setContent("<b>"+data.name+"</b><br/>"+rightcontext); if (hiderightclick !== true) { m.on('contextmenu', function(e) { L.DomEvent.stopPropagation(e); rightmenuMarker.setLatLng(e.latlng); map.openPopup(rightmenuMarker); }); } } return m; } //console.log("DATA" typeof data, data); if (data.deleted) { // remove markers we are told to delMarker(data.name); return; } var ll; var lli = null; var opt = {}; opt.color = data.color || "#910000"; opt.fillColor = data.fillColor || "#910000"; opt.stroke = (data.hasOwnProperty("stroke")) ? data.stroke : true; opt.weight = data.weight || 2; opt.opacity = data.opacity || 1; opt.fillOpacity = data.fillOpacity || 0.2; opt.clickable = (data.hasOwnProperty("clickable")) ? data.clickable : false; opt.fill = (data.hasOwnProperty("fill")) ? data.fill : true; if (data.hasOwnProperty("dashArray")) { opt.dashArray = data.dashArray; } // Replace building if (data.hasOwnProperty("building")) { if ((data.building === "") && layers.hasOwnProperty("buildings")) { map.removeLayer(layers["buildings"]); layercontrol._update(); layers["buildings"] = overlays["buildings"].set(""); return; } //layers["buildings"] = new OSMBuildings(map).set(data.building); layers["buildings"] = overlays["buildings"].set(data.building); map.addLayer(layers["buildings"]); return; } var lay = data.layer || "unknown"; if (!data.hasOwnProperty("action") || data.action.indexOf("layer") === -1) { if (typeof layers[lay] == "undefined") { // add layer if if doesn't exist if (clusterAt > 0) { layers[lay] = new L.MarkerClusterGroup({ maxClusterRadius:50, spiderfyDistanceMultiplier:1.8, disableClusteringAtZoom:clusterAt //zoomToBoundsOnClick:false }); } else { layers[lay] = new L.LayerGroup(); } overlays[lay] = layers[lay]; if (showLayerMenu !== false) { layercontrol.addOverlay(layers[lay],lay); } map.addLayer(overlays[lay]); //console.log("ADDED LAYER",lay,layers); } if (!allData.hasOwnProperty(data.name)) { allData[data.name] = {}; } delete data.action; Object.keys(data).forEach(key => { if (data[key] == null) { delete allData[data.name][key]; } else { allData[data.name][key] = data[key]; } }); data = Object.assign({},allData[data.name]); } delete data.action; if (typeof markers[data.name] != "undefined") { if (markers[data.name].lay !== data.layer) { delMarker(data.name); } else { try {layers[lay].removeLayer(markers[data.name]); } catch(e) { console.log("OOPS"); } } } if (typeof polygons[data.name] != "undefined") { layers[lay].removeLayer(polygons[data.name]); } if (data.hasOwnProperty("line") && Array.isArray(data.line)) { delete opt.fill; if (!data.hasOwnProperty("weight")) { opt.weight = 3; } //Standard settings different for lines if (!data.hasOwnProperty("opacity")) { opt.opacity = 0.8; } var polyln = L.polyline(data.line, opt); polygons[data.name] = polyln; } else if (data.hasOwnProperty("area") && Array.isArray(data.area)) { var polyarea; if (data.area.length === 2) { polyarea = L.rectangle(data.area, opt); } else { polyarea = L.polygon(data.area, opt); } polygons[data.name] = polyarea; } else if (data.hasOwnProperty("sdlat") && data.hasOwnProperty("sdlon")) { if (!data.hasOwnProperty("iconColor")) { opt.color = "blue"; } //different standard Color Settings if (!data.hasOwnProperty("fillColor")) { opt.fillColor = "blue"; } var ellipse = L.ellipse(new L.LatLng((data.lat*1), (data.lon*1)), [200000*data.sdlon*Math.cos(data.lat*Math.PI/180), 200000*data.sdlat], 0, opt); polygons[data.name] = ellipse; } else if (data.hasOwnProperty("radius")) { if (data.hasOwnProperty("lat") && data.hasOwnProperty("lon")) { var polycirc; if (Array.isArray(data.radius)) { polycirc = L.ellipse(new L.LatLng((data.lat*1), (data.lon*1)), [data.radius[0]*Math.cos(data.lat*Math.PI/180), data.radius[1]], data.tilt || 0, opt); } else { polycirc = L.circle(new L.LatLng((data.lat*1), (data.lon*1)), data.radius*1, opt); } polygons[data.name] = polycirc; } } if (polygons[data.name] !== undefined) { polygons[data.name].lay = lay; if (opt.clickable) { var words = "<b>"+data.name+"</b>"; if (data.popup) { var words = words + "<br/>" + data.popup; } polygons[data.name].bindPopup(words, {autoClose:false, closeButton:true, closeOnClick:false, minWidth:200}); } polygons[data.name] = rightmenu(polygons[data.name]); layers[lay].addLayer(polygons[data.name]); } else { if (typeof data.coordinates == "object") { ll = new L.LatLng(data.coordinates[1],data.coordinates[0]); } else if (data.hasOwnProperty("position") && data.position.hasOwnProperty("lat") && data.position.hasOwnProperty("lon")) { data.lat = data.position.lat*1; data.lon = data.position.lon*1; data.alt = data.position.alt; if (parseFloat(data.position.alt) == data.position.alt) { data.alt = data.position.alt + " m"; } delete data.position; ll = new L.LatLng((data.lat*1), (data.lon*1)); } else if (data.hasOwnProperty("lat") && data.hasOwnProperty("lon")) { ll = new L.LatLng((data.lat*1), (data.lon*1)); } else if (data.hasOwnProperty("latitude") && data.hasOwnProperty("longitude")) { ll = new L.LatLng((data.latitude*1), (data.longitude*1)); } else { console.log("No location:",data); return; } // Adding new L.LatLng object (lli) when optional intensity value is defined. Only for use in heatmap layer if (typeof data.coordinates == "object") { lli = new L.LatLng(data.coordinates[2],data.coordinates[1],data.coordinates[0]); } else if (data.hasOwnProperty("lat") && data.hasOwnProperty("lon") && data.hasOwnProperty("intensity")) { lli = new L.LatLng((data.lat*1), (data.lon*1), (data.intensity*1)); } else if (data.hasOwnProperty("latitude") && data.hasOwnProperty("longitude") && data.hasOwnProperty("intensity")) { lli = new L.LatLng((data.latitude*1), (data.longitude*1), (data.intensity*1)); } else { lli = ll } // Create the icons... handle plane, car, ship, wind, earthquake as specials var marker, myMarker; var icon, q; var words=""; var labelOffset = [12,0]; var drag = false; if (data.draggable === true) { drag = true; } //console.log("ICON",data.icon); if (data.hasOwnProperty("icon")) { if (data.icon === "ship") { marker = L.boatMarker(ll, { title: data.name, color: (data.iconColor || "blue") }); marker.setHeading(parseFloat(data.hdg || data.bearing || "0")); q = 'https://www.bing.com/images/search?q='+data.icon+'%20%2B"'+encodeURIComponent(data.name)+'"'; words += '<a href=\''+q+'\' target="_thingpic">Pictures</a><br>'; } else if (data.icon === "plane") { data.iconColor = data.iconColor || "black"; if (data.hasOwnProperty("squawk")) { data.iconColor = "red"; } icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="310px" height="310px" viewBox="0 0 310 310">'; icon += '<path d="M134.875,19.74c0.04-22.771,34.363-22.771,34.34,0.642v95.563L303,196.354v35.306l-133.144-43.821v71.424l30.813,24.072v27.923l-47.501-14.764l-47.501,14.764v-27.923l30.491-24.072v-71.424L3,231.66v-35.306l131.875-80.409V19.74z" fill="'+data.iconColor+'"/></svg>'; var svgplane = "data:image/svg+xml;base64," + btoa(icon); var dir = parseFloat(data.hdg || data.bearing || "0"); myMarker = L.divIcon({ className:"planeicon", iconAnchor: [16, 16], html:'<img src="'+svgplane+'" style="width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);"/>' }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); //q = 'https://www.bing.com/images/search?q='+data.icon+'%20'+encodeURIComponent(data.name); //words += '<a href=\''+q+'\' target="_thingpic">Pictures</a><br>'; } else if (data.icon === "helicopter") { data.iconColor = data.iconColor || "black"; if (data.hasOwnProperty("squawk")) { data.iconColor = "red"; } icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="314" height="314" viewBox="0 0 314.5 314.5">'; icon += '<path d="M268.8 3c-3.1-3.1-8.3-2.9-11.7 0.5L204.9 55.7C198.5 23.3 180.8 0 159.9 0c-21.9 0-40.3 25.5-45.7 60.2L57.4 3.5c-3.4-3.4-8.6-3.6-11.7-0.5 -3.1 3.1-2.9 8.4 0.5 11.7l66.3 66.3c0 0.2 0 0.4 0 0.6 0 20.9 4.6 39.9 12.1 54.4l-78.4 78.4c-3.4 3.4-3.6 8.6-0.5 11.7 3.1 3.1 8.3 2.9 11.7-0.5l76.1-76.1c3.2 3.7 6.7 6.7 10.4 8.9v105.8l-47.7 32.2v18l50.2-22.3h26.9l50.2 22.3v-18L175.8 264.2v-105.8c2.7-1.7 5.4-3.8 7.8-6.2l73.4 73.4c3.4 3.4 8.6 3.6 11.7 0.5 3.1-3.1 2.9-8.3-0.5-11.7l-74.9-74.9c8.6-14.8 14-35.2 14-57.8 0-1.9-0.1-3.8-0.2-5.8l61.2-61.2C271.7 11.3 271.9 6.1 268.8 3z" fill="'+data.iconColor+'"/></svg>'; var svgheli = "data:image/svg+xml;base64," + btoa(icon); var dir = parseFloat(data.hdg || data.bearing || "0"); myMarker = L.divIcon({ className:"heliicon", iconAnchor: [16, 16], html:'<img src="'+svgheli+'" style="width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);"/>' }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if (data.icon === "uav") { data.iconColor = data.iconColor || "black"; if (data.hasOwnProperty("squawk")) { data.iconColor = "red"; } icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100">'; icon+= '<path d="M62 82h-8V64h36c0-5-4-9-9-9H54v-8c0-3 4-5 4-11.1 0-4.4-3.6-8-8-8-4.4 0-8 3.6-8 8 0 5.1 4 8.1 4 11.1V55h-27c-5 0-9 4-9 9h36v18H38c-2.4 0-5 2.3-5 5L50 92l17-5C67 84.3 64.4 82 62 82z" fill="'+data.iconColor+'"/></svg>'; var svguav = "data:image/svg+xml;base64," + btoa(icon); var dir = parseFloat(data.hdg || data.bearing || "0"); myMarker = L.divIcon({ className:"uavicon", iconAnchor: [16, 16], html:'<img src="'+svguav+'" style="width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);"/>', }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if (data.icon === "car") { data.iconColor = data.iconColor || "black"; icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="47px" height="47px" viewBox="0 0 47 47">'; icon += '<path d="M29.395,0H17.636c-3.117,0-5.643,3.467-5.643,6.584v34.804c0,3.116,2.526,5.644,5.643,5.644h11.759 c3.116,0,5.644-2.527,5.644-5.644V6.584C35.037,3.467,32.511,0,29.395,0z M34.05,14.188v11.665l-2.729,0.351v-4.806L34.05,14.188z M32.618,10.773c-1.016,3.9-2.219,8.51-2.219,8.51H16.631l-2.222-8.51C14.41,10.773,23.293,7.755,32.618,10.773z M15.741,21.713 v4.492l-2.73-0.349V14.502L15.741,21.713z M13.011,37.938V27.579l2.73,0.343v8.196L13.011,37.938z M14.568,40.882l2.218-3.336 h13.771l2.219,3.336H14.568z M31.321,35.805v-7.872l2.729-0.355v10.048L31.321,35.805z" fill="'+data.iconColor+'"/></svg>'; var svgcar = "data:image/svg+xml;base64," + btoa(icon); var dir = parseFloat(data.hdg || data.bearing || "0"); myMarker = L.divIcon({ className:"caricon", iconAnchor: [16, 16], html:'<img src="'+svgcar+'" style="width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);"/>', }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if (data.icon === "arrow") { data.iconColor = data.iconColor || "black"; icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="32px" height="32px" viewBox="0 0 32 32">'; icon += '<path d="m16.2 0.6l-10.9 31 10.7-11.1 10.5 11.1 -10.3-31z" fill="'+data.iconColor+'"/></svg>'; var svgarrow = "data:image/svg+xml;base64," + btoa(icon); var dir = parseFloat(data.hdg || data.bearing || "0"); myMarker = L.divIcon({ className:"arrowicon", iconAnchor: [16, 16], html:"'<img src='"+svgarrow+"' style='width:32px; height:32px; -webkit-transform:translate(0px,-16px) rotate("+dir+"deg); -moz-transform:translate(0px,-16px) rotate("+dir+"deg);'/>", }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if (data.icon === "wind") { data.iconColor = data.iconColor || "black"; icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="32px" height="32px" viewBox="0 0 32 32">'; icon += '<path d="M16.7 31.7l7-6.9c0.4-0.4 0.4-1 0-1.4 -0.4-0.4-1-0.4-1.4 0l-5.3 5.2V17.3l6.7-6.6c0.2-0.2 0.3-0.5 0.3-0.7v-9c0-0.9-1.1-1.3-1.7-0.7l-6.3 6.2L9.7 0.3C9.1-0.3 8 0.1 8 1.1v8.8c0 0.3 0.1 0.6 0.3 0.8l6.7 6.6v11.3l-5.3-5.2c-0.4-0.4-1-0.4-1.4 0 -0.4 0.4-0.4 1 0 1.4l7 6.9c0.2 0.2 0.5 0.3 0.7 0.3C16.2 32 16.5 31.9 16.7 31.7zM10 9.6V3.4l5 4.9v6.2L10 9.6zM17 8.3l5-4.9v6.2l-5 4.9V8.3z" fill="'+data.iconColor+'"/></svg>'; var svgwind = "data:image/svg+xml;base64," + btoa(icon); var dir = parseFloat(data.hdg || data.bearing || "0"); myMarker = L.divIcon({ className:"windicon", iconAnchor: [16, 16], html:'<img src="'+svgwind+'" style="width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);"/>', }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if (data.icon === "satellite") { data.iconColor = data.iconColor || "black"; icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100">'; icon += '<polygon points="38.17 39.4 45.24 32.33 43.34 27.92 24.21 8.78 14.59 18.4 33.72 37.53" fill="'+data.iconColor+'"/>'; icon += '<path d="M69.22 44.57L54.38 29.73c-1.1-1.1-2.91-1.1-4.01 0L35.53 44.57c-1.1 1.1-1.1 2.91 0 4.01l14.84 14.84c1.1 1.1 2.91 1.1 4.01 0l14.84-14.84C70.32 47.47 70.32 45.67 69.22 44.57z" fill="'+data.iconColor+'"/>'; icon += '<polygon points="71.04 55.61 66.58 53.75 59.52 60.82 61.42 65.23 80.55 84.36 90.17 74.75" fill="'+data.iconColor+'"/>'; icon += '<path d="M28.08 55.26l-6.05 0.59C23.11 68.13 32.78 77.94 45 79.22l0.59-6.05C36.26 72.15 28.89 64.66 28.08 55.26z" fill="'+data.iconColor+'"/>'; icon += '<path d="M15.88 56.54L9.83 57.13c1.67 18.06 16.03 32.43 34.08 34.09l0.59-6.04C29.34 83.76 17.29 71.71 15.88 56.54z" fill="'+data.iconColor+'"/>'; icon += '</svg>'; var svgsat = "data:image/svg+xml;base64," + btoa(icon); myMarker = L.divIcon({ className:"satelliteicon", iconAnchor: [16, 16], html:'<img src="'+svgsat+'" style="width:32px; height:32px;"/>', }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if ((data.icon === "iss") || (data.icon === "ISS")) { data.iconColor = data.iconColor || "black"; icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 48 48">'; icon += '<path id="iss" d="m4.55 30.97l6.85-12.68 0.59 0.32 -6.85 12.68 4.27 2.3 6.85-12.68 0.49 0.27 -0.81 1.5c-0.26 0.48-0.07 1.1 0.44 1.37l5.09 2.75c0.5 0.27 1.12 0.1 1.38-0.39l0.81-1.5 0.72 0.39 -1.49 2.75c-0.41 0.76-0.38 1.58 0.08 1.82l4.61 2.49c0.45 0.24 1.15-0.18 1.56-0.94l1.49-2.75 0.69 0.37 -6.85 12.68 4.26 2.3 6.85-12.68 0.59 0.32 -6.85 12.69 4.26 2.3 14.46-26.78 -4.26-2.3 -6.88 12.74 -0.59-0.32 6.88-12.74 -4.26-2.3 -6.88 12.74 -0.69-0.37 1.49-2.75c0.41-0.76 '; icon += '0.38-1.58-0.08-1.82l-1.4-0.75 0.5-0.92c1.02 0.17 2.09-0.32 2.62-1.3 0.67-1.23 0.22-2.76-0.99-3.42 -1.21-0.65-2.74-0.19-3.4 1.05 -0.53 0.98-0.35 2.14 0.35 2.9l-0.5 0.92 -1.8-0.97c-0.45-0.24-1.15 0.17-1.57 0.94l-1.49 2.75 -0.72-0.39 0.81-1.5c0.26-0.48 0.07-1.1-0.44-1.36l-5.09-2.75c-0.5-0.27-1.12-0.1-1.38 0.39l-0.81 1.5 -0.49-0.27 6.88-12.74 -4.26-2.3 -6.88 12.74 -0.59-0.32 6.88-12.74 -4.26-2.3 -14.46 26.78 4.26 2.3zm14.26-11.72c0.2-0.37 0.68-0.51 1.06-0.3l3.93 '; icon += '2.12c0.39 0.21 0.54 0.68 0.34 1.05l-1.81 3.35c-0.2 0.37-0.68 0.51-1.06 0.3l-3.93-2.12c-0.38-0.21-0.53-0.68-0.33-1.05l1.81-3.35zm12.01-1.46c0.45-0.83 1.47-1.14 2.28-0.7 0.81 0.44 1.11 1.46 0.66 2.29 -0.44 0.83-1.47 1.14-2.28 0.7 -0.81-0.44-1.11-1.46-0.66-2.29zm-3.78 4.26c0.35-0.66 0.93-1.04 1.28-0.85l3.57 1.93c0.35 0.19 0.35 0.88-0.01 1.53l-3.19 5.91c-0.35 0.66-0.93 1.04-1.28 0.85l-3.56-1.92c-0.35-0.19-0.35-0.88 0.01-1.53l3.19-5.91zm0.19 7.49c-0.26 0.49-0.87 '; icon += '0.67-1.36 0.41 -0.49-0.26-0.67-0.87-0.41-1.36 0.27-0.49 0.87-0.67 1.36-0.4 0.49 0.26 0.67 0.87 0.41 1.36zm-7.46-6.31c-0.26 0.49-0.87 0.67-1.36 0.41s-0.67-0.87-0.41-1.36c0.27-0.49 0.87-0.67 1.36-0.4s0.67 0.87 0.41 1.36zm2.32 1.25c-0.26 0.49-0.87 0.67-1.36 0.41 -0.49-0.26-0.67-0.87-0.41-1.36 0.27-0.49 0.87-0.67 1.36-0.41 0.49 0.26 0.67 0.87 0.41 1.36z" fill="'+data.iconColor+'"/>'; icon += '</svg>'; var svgiss = "data:image/svg+xml;base64," + btoa(icon); myMarker = L.divIcon({ className:"issicon", iconAnchor: [25, 25], html:'<img src="'+svgiss+'" style="width:50px; height:50px;"/>', }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if (data.icon === "locate") { data.iconColor = data.iconColor || "cyan"; icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="468px" height="468px" viewBox="0 0 468 468">'; icon += '<polygon points="32 32 104 32 104 0 0 0 0 104 32 104" fill="'+data.iconColor+'"/>'; icon += '<polygon points="468 0 364 0 364 32 436 32 436 104 468 104" fill="'+data.iconColor+'"/>'; icon += '<polygon points="0 468 104 468 104 436 32 436 32 364 0 364" fill="'+data.iconColor+'"/>'; icon += '<polygon points="436 436 364 436 364 468 468 468 468 364 436 364" fill="'+data.iconColor+'"/>'; //icon += '<circle cx="234" cy="234" r="22" fill="'+data.iconColor+'"/>'; icon += '</svg>'; var svglocate = "data:image/svg+xml;base64," + btoa(icon); myMarker = L.divIcon({ className:"locateicon", iconAnchor: [16, 16], html:'<img src="'+svglocate+'" style="width:32px; height:32px;"/>', }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); labelOffset = [12,-4]; } else if (data.icon === "friend") { marker = L.marker(ll, { icon: L.divIcon({ className: 'circle f', iconSize: [20, 12] }), title: data.name, draggable:drag }); } else if (data.icon === "hostile") { marker = L.marker(ll, { icon: L.divIcon({ className: 'circle h', iconSize: [16, 16] }), title: data.name, draggable:drag }); } else if (data.icon === "neutral") { marker = L.marker(ll, { icon: L.divIcon({ className: 'circle n', iconSize: [16, 16] }), title: data.name, draggable:drag }); } else if (data.icon === "unknown") { marker = L.marker(ll, { icon: L.divIcon({ className: 'circle', iconSize: [16, 16] }), title: data.name, draggable:drag }); } else if (data.icon === "danger") { marker = L.marker(ll, { icon: L.divIcon({ className: 'up-triangle' }), title: data.name, draggable:drag }); } else if (data.icon === "earthquake") { marker = L.marker(ll, { icon: L.divIcon({ className: 'circle e', iconSize: [data.mag*5, data.mag*5] }), title: data.name, draggable:drag }); } else if (data.icon.match(/^:.*:$/g)) { var em = emojify(data.icon); var col = data.iconColor || "#910000"; myMarker = L.divIcon({ className:"emicon", html: '<center><span style="font-size:2em; color:'+col+'">'+em+'</span></center>', iconSize: [32, 32] }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); labelOffset = [12,-4]; } else if (data.icon.match(/^https?:.*$/)) { myMarker = L.icon({ iconUrl: data.icon, iconSize: [32, 32], iconAnchor: [16, 16], popupAnchor: [0, -16] }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); labelOffset = [12,-4]; } else if (data.icon.substr(0,3) === "fa-") { var col = data.iconColor || "#910000"; var imod = ""; if (data.icon.indexOf(" ") === -1) { imod = "fa-2x "; } myMarker = L.divIcon({ className:"faicon", html: '<center><i class="fa fa-fw '+imod+data.icon+'" style="color:'+col+'"></i></center>', iconSize: [32, 32], popupAnchor: [0, -16] }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); labelOffset = [8,-8]; } else if (data.icon.substr(0,3) === "wi-") { var col = data.iconColor || "#910000"; var imod = ""; if (data.icon.indexOf(" ") === -1) { imod = "wi-2x "; } myMarker = L.divIcon({ className:"wiicon", html: '<center><i class="wi wi-fw '+imod+data.icon+'" style="color:'+col+'"></i></center>', iconSize: [32, 32], popupAnchor: [0, -16] }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); labelOffset = [16,-16]; } else { myMarker = L.VectorMarkers.icon({ icon: data.icon || "circle", markerColor: (data.iconColor || "#910000"), prefix: 'fa', iconColor: 'white' }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); labelOffset = [6,-6]; } } if (data.hasOwnProperty("SIDC")) { // "SIDC":"SFGPU------E***","name":"1.C2 komp","fullname":"1.C2 komp/FTS/INSS" myMarker = new ms.Symbol( data.SIDC.toUpperCase(), { uniqueDesignation:data.name }); // Now that we have a symbol we can ask for the echelon and set the symbol size var opts = data.options || {}; opts.size = opts.size || iconSz[myMarker.getProperties().echelon] || 30; opts.size = opts.size * (opts.scale || 1); myMarker = myMarker.setOptions(opts); var myicon = L.icon({ iconUrl: myMarker.toDataURL(), iconAnchor: [myMarker.getAnchor().x, myMarker.getAnchor().y], className: "natoicon", }); marker = L.marker(ll, { title:data.name, icon:myicon, draggable:drag }); } marker.name = data.name; // var createLabelIcon = function(labelText) { // return L.marker(new L.LatLng(51.05, -1.35), {icon:L.divIcon({ html:labelText })}); // } // send new position at end of move event if point is draggable if (data.draggable === true) { if (data.icon) { marker.icon = data.icon; } if (data.iconColor) { marker.iconColor = data.iconColor; } if (data.SIDC) { marker.SIDC = data.SIDC.toUpperCase(); } marker.on('dragend', function (e) { var l = marker.getLatLng().toString().replace('LatLng(','lat, lon : ').replace(')','') marker.setPopupContent(marker.getPopup().getContent().split("lat, lon")[0] + l); ws.send(JSON.stringify({action:"move",name:marker.name,layer:marker.lay,icon:marker.icon,iconColor:marker.iconColor,SIDC:marker.SIDC,draggable:true,lat:parseFloat(marker.getLatLng().lat.toFixed(6)),lon:parseFloat(marker.getLatLng().lng.toFixed(6))})); }); } // remove icon from list of properties, then add all others to popup if (data.hasOwnProperty("SIDC") && data.hasOwnProperty("options")) { delete data.options; } if (data.hasOwnProperty("icon")) { delete data.icon; } if (data.hasOwnProperty("iconColor")) { delete data.iconColor; } if (data.hasOwnProperty("photourl")) { words += "<img src=\"" + data.photourl + "\" style=\"width:100%; margin-top:10px;\">"; delete data.photourl; } if (data.hasOwnProperty("photoUrl")) { words += "<img src=\"" + data.photoUrl + "\" style=\"width:100%; margin-top:10px;\">"; delete data.photoUrl; } if (data.hasOwnProperty("videoUrl")) { words += '<video controls muted autoplay width="320"><source src="'+data.videoUrl+'" type="video/mp4">Your browser does not support the video tag.</video>'; delete data.videoUrl; } if (data.hasOwnProperty("ttl")) { // save expiry time for this marker if (data.ttl != 0) { marker.ts = parseInt(Date.now()/1000) + Number(data.ttl); } delete data.ttl; } else if (maxage != 0) { marker.ts = parseInt(Date.now()/1000) + Number(maxage); } if (data.hasOwnProperty("weblink")) { if (typeof data.weblink === "string") { words += "<b><a href='"+ data.weblink + "' target='_new'>more information...</a></b><br/>"; } else { var tgt = data.weblink.target || "_new"; words += "<b><a href='"+ data.weblink.url + "' target='"+ tgt + "'>" + data.weblink.name + "</a></b><br/>"; } delete data.weblink; } var p; if (data.hasOwnProperty("popped") && (data.popped === true)) { p = true; delete data.popped; } if (data.hasOwnProperty("popped") && (data.popped === false)) { marker.closePopup(); p = false; delete data.popped; } // If .label then use that rather than name tooltip if (data.label) { if (typeof data.label === "boolean" && data.label === true) { marker.bindTooltip(data.name, { permanent:true, direction:"right", offset:labelOffset }); } else if (typeof data.label === "string" && data.label.length > 0) { marker.bindTooltip(data.label, { permanent:true, direction:"right", offset:labelOffset }); } delete marker.options.title; delete data.label; } // otherwise check for .tooltip then use that rather than name tooltip else if (data.tooltip) { if (typeof data.tooltip === "string" && data.tooltip.length > 0) { marker.bindTooltip(data.tooltip, { direction:"bottom", offset:[0,4] }); delete marker.options.title; delete data.tooltip; } } marker = rightmenu(marker); // Add any remaining properties to the info box var llc = data.lineColor; delete data.lat; delete data.lon; if (data.layer) { delete data.layer; } if (data.lineColor) { delete data.lineColor; } if (data.color) { delete data.color; } if (data.weight) { delete data.weight; } if (data.tracklength) { delete data.tracklength; } if (data.dashArray) { delete data.dashArray; } if (data.fill) { delete data.fill; } if (data.draggable) { delete data.draggable; } for (var i in data) { if ((i != "name") && (i != "length")) { if (typeof data[i] === "object") { words += i +" : "+JSON.stringify(data[i])+"<br/>"; } else { words += i +" : "+data[i]+"<br/>"; } } } if (data.popup) { words = data.popup; } else { words = words + marker.getLatLng().toString().replace('LatLng(','lat, lon : ').replace(')',''); } words = "<b>"+data.name+"</b><br/>" + words; //"<button style=\"border-radius:4px; float:right; background-color:lightgrey;\" onclick='popped=false;popmark.closePopup();'>X</button><br/>" + words; marker.bindPopup(words, {autoClose:false, closeButton:true, closeOnClick:false, minWidth:200}); marker._popup.dname = data.name; marker.lay = lay; // and the layer it is on marker.on('click', function(e) { ws.send(JSON.stringify({action:"click",name:marker.name,layer:marker.lay,icon:marker.icon,iconColor:marker.iconColor,SIDC:marker.SIDC,draggable:true,lat:parseFloat(marker.getLatLng().lat.toFixed(6)),lon:parseFloat(marker.getLatLng().lng.toFixed(6))})); }); if ((data.addtoheatmap !== "false") || (!data.hasOwnProperty("addtoheatmap"))) { // Added to give ability to control if points from active layer contribute to heatmap if (heatAll || map.hasLayer(layers[lay])) { heat.addLatLng(lli); } } markers[data.name] = marker; layers[lay].addLayer(marker); if ((data.hdg != null) && (data.bearing == null)) { data.bearing = data.hdg; delete data.hdg; } if (data.bearing != null) { // if there is a heading if (data.speed != null) { data.length = parseFloat(data.speed || "0") * 50; } // and a speed if (data.length != null) { if (polygons[data.name] != null) { map.removeLayer(polygons[data.name]); } var x = ll.lng * 1; // X coordinate var y = ll.lat * 1; // Y coordinate var ll1 = ll; var angle = parseFloat(data.bearing); var lengthAsDegrees = parseFloat(data.length || "0") / 110540; // metres in a degree..ish var polygon = null; if (data.accuracy != null) { data.accuracy = Number(data.accuracy); var y2 = y + Math.sin((90-angle+data.accuracy)/180*Math.PI)*lengthAsDegrees*Math.cos(y/180*Math.PI); var x2 = x + Math.cos((90-angle+data.accuracy)/180*Math.PI)*lengthAsDegrees; var ll2 = new L.LatLng(y2,x2); var y3 = y + Math.sin((90-angle-data.accuracy)/180*Math.PI)*lengthAsDegrees*Math.cos(y/180*Math.PI); var x3 = x + Math.cos((90-angle-data.accuracy)/180*Math.PI)*lengthAsDegrees; var ll3 = new L.LatLng(y3,x3); polygon = L.polygon([ ll1, ll2, ll3 ], {weight:2, color:llc||'#f30', fillOpacity:0.06, clickable:false}); } else { var ya = y + Math.sin((90-angle)/180*Math.PI)*lengthAsDegrees*Math.cos(y/180*Math.PI); var xa = x + Math.cos((90-angle)/180*Math.PI)*lengthAsDegrees; var lla = new L.LatLng(ya,xa); polygon = L.polygon([ ll1, lla ], {weight:2, color:llc||'#f30', clickable:false}); } if (typeof layers[lay].getVisibleParent === 'function') { var vis = layers[lay].getVisibleParent(marker); if ((polygon !== null) && (vis !== null) && (!vis.hasOwnProperty("lay"))) { polygon.setStyle({opacity:0}); } } polygons[data.name] = polygon; polygons[data.name].lay = lay; layers[lay].addLayer(polygon); } } if (panit) { map.setView(ll,map.getZoom()); } if (p === true) { marker.openPopup(); } } }
javascript
function setMarker(data) { var rightmenu = function(m) { // customise right click context menu var rightcontext = ""; if (polygons[data.name] == undefined) { rightcontext = "<button id='delbutton' onclick='delMarker(\""+data.name+"\",true);'>Delete</button>"; } else if (data.editable) { rightcontext = "<button onclick='editPoly(\""+data.name+"\",true);'>Edit</button><button onclick='delMarker(\""+data.name+"\",true);'>Delete</button>"; } if ((data.contextmenu !== undefined) && (typeof data.contextmenu === "string")) { rightcontext = data.contextmenu.replace(/\$name/g,data.name); delete data.contextmenu; } if (rightcontext.length > 0) { var rightmenuMarker = L.popup({offset:[0,-12]}).setContent("<b>"+data.name+"</b><br/>"+rightcontext); if (hiderightclick !== true) { m.on('contextmenu', function(e) { L.DomEvent.stopPropagation(e); rightmenuMarker.setLatLng(e.latlng); map.openPopup(rightmenuMarker); }); } } return m; } //console.log("DATA" typeof data, data); if (data.deleted) { // remove markers we are told to delMarker(data.name); return; } var ll; var lli = null; var opt = {}; opt.color = data.color || "#910000"; opt.fillColor = data.fillColor || "#910000"; opt.stroke = (data.hasOwnProperty("stroke")) ? data.stroke : true; opt.weight = data.weight || 2; opt.opacity = data.opacity || 1; opt.fillOpacity = data.fillOpacity || 0.2; opt.clickable = (data.hasOwnProperty("clickable")) ? data.clickable : false; opt.fill = (data.hasOwnProperty("fill")) ? data.fill : true; if (data.hasOwnProperty("dashArray")) { opt.dashArray = data.dashArray; } // Replace building if (data.hasOwnProperty("building")) { if ((data.building === "") && layers.hasOwnProperty("buildings")) { map.removeLayer(layers["buildings"]); layercontrol._update(); layers["buildings"] = overlays["buildings"].set(""); return; } //layers["buildings"] = new OSMBuildings(map).set(data.building); layers["buildings"] = overlays["buildings"].set(data.building); map.addLayer(layers["buildings"]); return; } var lay = data.layer || "unknown"; if (!data.hasOwnProperty("action") || data.action.indexOf("layer") === -1) { if (typeof layers[lay] == "undefined") { // add layer if if doesn't exist if (clusterAt > 0) { layers[lay] = new L.MarkerClusterGroup({ maxClusterRadius:50, spiderfyDistanceMultiplier:1.8, disableClusteringAtZoom:clusterAt //zoomToBoundsOnClick:false }); } else { layers[lay] = new L.LayerGroup(); } overlays[lay] = layers[lay]; if (showLayerMenu !== false) { layercontrol.addOverlay(layers[lay],lay); } map.addLayer(overlays[lay]); //console.log("ADDED LAYER",lay,layers); } if (!allData.hasOwnProperty(data.name)) { allData[data.name] = {}; } delete data.action; Object.keys(data).forEach(key => { if (data[key] == null) { delete allData[data.name][key]; } else { allData[data.name][key] = data[key]; } }); data = Object.assign({},allData[data.name]); } delete data.action; if (typeof markers[data.name] != "undefined") { if (markers[data.name].lay !== data.layer) { delMarker(data.name); } else { try {layers[lay].removeLayer(markers[data.name]); } catch(e) { console.log("OOPS"); } } } if (typeof polygons[data.name] != "undefined") { layers[lay].removeLayer(polygons[data.name]); } if (data.hasOwnProperty("line") && Array.isArray(data.line)) { delete opt.fill; if (!data.hasOwnProperty("weight")) { opt.weight = 3; } //Standard settings different for lines if (!data.hasOwnProperty("opacity")) { opt.opacity = 0.8; } var polyln = L.polyline(data.line, opt); polygons[data.name] = polyln; } else if (data.hasOwnProperty("area") && Array.isArray(data.area)) { var polyarea; if (data.area.length === 2) { polyarea = L.rectangle(data.area, opt); } else { polyarea = L.polygon(data.area, opt); } polygons[data.name] = polyarea; } else if (data.hasOwnProperty("sdlat") && data.hasOwnProperty("sdlon")) { if (!data.hasOwnProperty("iconColor")) { opt.color = "blue"; } //different standard Color Settings if (!data.hasOwnProperty("fillColor")) { opt.fillColor = "blue"; } var ellipse = L.ellipse(new L.LatLng((data.lat*1), (data.lon*1)), [200000*data.sdlon*Math.cos(data.lat*Math.PI/180), 200000*data.sdlat], 0, opt); polygons[data.name] = ellipse; } else if (data.hasOwnProperty("radius")) { if (data.hasOwnProperty("lat") && data.hasOwnProperty("lon")) { var polycirc; if (Array.isArray(data.radius)) { polycirc = L.ellipse(new L.LatLng((data.lat*1), (data.lon*1)), [data.radius[0]*Math.cos(data.lat*Math.PI/180), data.radius[1]], data.tilt || 0, opt); } else { polycirc = L.circle(new L.LatLng((data.lat*1), (data.lon*1)), data.radius*1, opt); } polygons[data.name] = polycirc; } } if (polygons[data.name] !== undefined) { polygons[data.name].lay = lay; if (opt.clickable) { var words = "<b>"+data.name+"</b>"; if (data.popup) { var words = words + "<br/>" + data.popup; } polygons[data.name].bindPopup(words, {autoClose:false, closeButton:true, closeOnClick:false, minWidth:200}); } polygons[data.name] = rightmenu(polygons[data.name]); layers[lay].addLayer(polygons[data.name]); } else { if (typeof data.coordinates == "object") { ll = new L.LatLng(data.coordinates[1],data.coordinates[0]); } else if (data.hasOwnProperty("position") && data.position.hasOwnProperty("lat") && data.position.hasOwnProperty("lon")) { data.lat = data.position.lat*1; data.lon = data.position.lon*1; data.alt = data.position.alt; if (parseFloat(data.position.alt) == data.position.alt) { data.alt = data.position.alt + " m"; } delete data.position; ll = new L.LatLng((data.lat*1), (data.lon*1)); } else if (data.hasOwnProperty("lat") && data.hasOwnProperty("lon")) { ll = new L.LatLng((data.lat*1), (data.lon*1)); } else if (data.hasOwnProperty("latitude") && data.hasOwnProperty("longitude")) { ll = new L.LatLng((data.latitude*1), (data.longitude*1)); } else { console.log("No location:",data); return; } // Adding new L.LatLng object (lli) when optional intensity value is defined. Only for use in heatmap layer if (typeof data.coordinates == "object") { lli = new L.LatLng(data.coordinates[2],data.coordinates[1],data.coordinates[0]); } else if (data.hasOwnProperty("lat") && data.hasOwnProperty("lon") && data.hasOwnProperty("intensity")) { lli = new L.LatLng((data.lat*1), (data.lon*1), (data.intensity*1)); } else if (data.hasOwnProperty("latitude") && data.hasOwnProperty("longitude") && data.hasOwnProperty("intensity")) { lli = new L.LatLng((data.latitude*1), (data.longitude*1), (data.intensity*1)); } else { lli = ll } // Create the icons... handle plane, car, ship, wind, earthquake as specials var marker, myMarker; var icon, q; var words=""; var labelOffset = [12,0]; var drag = false; if (data.draggable === true) { drag = true; } //console.log("ICON",data.icon); if (data.hasOwnProperty("icon")) { if (data.icon === "ship") { marker = L.boatMarker(ll, { title: data.name, color: (data.iconColor || "blue") }); marker.setHeading(parseFloat(data.hdg || data.bearing || "0")); q = 'https://www.bing.com/images/search?q='+data.icon+'%20%2B"'+encodeURIComponent(data.name)+'"'; words += '<a href=\''+q+'\' target="_thingpic">Pictures</a><br>'; } else if (data.icon === "plane") { data.iconColor = data.iconColor || "black"; if (data.hasOwnProperty("squawk")) { data.iconColor = "red"; } icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="310px" height="310px" viewBox="0 0 310 310">'; icon += '<path d="M134.875,19.74c0.04-22.771,34.363-22.771,34.34,0.642v95.563L303,196.354v35.306l-133.144-43.821v71.424l30.813,24.072v27.923l-47.501-14.764l-47.501,14.764v-27.923l30.491-24.072v-71.424L3,231.66v-35.306l131.875-80.409V19.74z" fill="'+data.iconColor+'"/></svg>'; var svgplane = "data:image/svg+xml;base64," + btoa(icon); var dir = parseFloat(data.hdg || data.bearing || "0"); myMarker = L.divIcon({ className:"planeicon", iconAnchor: [16, 16], html:'<img src="'+svgplane+'" style="width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);"/>' }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); //q = 'https://www.bing.com/images/search?q='+data.icon+'%20'+encodeURIComponent(data.name); //words += '<a href=\''+q+'\' target="_thingpic">Pictures</a><br>'; } else if (data.icon === "helicopter") { data.iconColor = data.iconColor || "black"; if (data.hasOwnProperty("squawk")) { data.iconColor = "red"; } icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="314" height="314" viewBox="0 0 314.5 314.5">'; icon += '<path d="M268.8 3c-3.1-3.1-8.3-2.9-11.7 0.5L204.9 55.7C198.5 23.3 180.8 0 159.9 0c-21.9 0-40.3 25.5-45.7 60.2L57.4 3.5c-3.4-3.4-8.6-3.6-11.7-0.5 -3.1 3.1-2.9 8.4 0.5 11.7l66.3 66.3c0 0.2 0 0.4 0 0.6 0 20.9 4.6 39.9 12.1 54.4l-78.4 78.4c-3.4 3.4-3.6 8.6-0.5 11.7 3.1 3.1 8.3 2.9 11.7-0.5l76.1-76.1c3.2 3.7 6.7 6.7 10.4 8.9v105.8l-47.7 32.2v18l50.2-22.3h26.9l50.2 22.3v-18L175.8 264.2v-105.8c2.7-1.7 5.4-3.8 7.8-6.2l73.4 73.4c3.4 3.4 8.6 3.6 11.7 0.5 3.1-3.1 2.9-8.3-0.5-11.7l-74.9-74.9c8.6-14.8 14-35.2 14-57.8 0-1.9-0.1-3.8-0.2-5.8l61.2-61.2C271.7 11.3 271.9 6.1 268.8 3z" fill="'+data.iconColor+'"/></svg>'; var svgheli = "data:image/svg+xml;base64," + btoa(icon); var dir = parseFloat(data.hdg || data.bearing || "0"); myMarker = L.divIcon({ className:"heliicon", iconAnchor: [16, 16], html:'<img src="'+svgheli+'" style="width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);"/>' }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if (data.icon === "uav") { data.iconColor = data.iconColor || "black"; if (data.hasOwnProperty("squawk")) { data.iconColor = "red"; } icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100">'; icon+= '<path d="M62 82h-8V64h36c0-5-4-9-9-9H54v-8c0-3 4-5 4-11.1 0-4.4-3.6-8-8-8-4.4 0-8 3.6-8 8 0 5.1 4 8.1 4 11.1V55h-27c-5 0-9 4-9 9h36v18H38c-2.4 0-5 2.3-5 5L50 92l17-5C67 84.3 64.4 82 62 82z" fill="'+data.iconColor+'"/></svg>'; var svguav = "data:image/svg+xml;base64," + btoa(icon); var dir = parseFloat(data.hdg || data.bearing || "0"); myMarker = L.divIcon({ className:"uavicon", iconAnchor: [16, 16], html:'<img src="'+svguav+'" style="width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);"/>', }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if (data.icon === "car") { data.iconColor = data.iconColor || "black"; icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="47px" height="47px" viewBox="0 0 47 47">'; icon += '<path d="M29.395,0H17.636c-3.117,0-5.643,3.467-5.643,6.584v34.804c0,3.116,2.526,5.644,5.643,5.644h11.759 c3.116,0,5.644-2.527,5.644-5.644V6.584C35.037,3.467,32.511,0,29.395,0z M34.05,14.188v11.665l-2.729,0.351v-4.806L34.05,14.188z M32.618,10.773c-1.016,3.9-2.219,8.51-2.219,8.51H16.631l-2.222-8.51C14.41,10.773,23.293,7.755,32.618,10.773z M15.741,21.713 v4.492l-2.73-0.349V14.502L15.741,21.713z M13.011,37.938V27.579l2.73,0.343v8.196L13.011,37.938z M14.568,40.882l2.218-3.336 h13.771l2.219,3.336H14.568z M31.321,35.805v-7.872l2.729-0.355v10.048L31.321,35.805z" fill="'+data.iconColor+'"/></svg>'; var svgcar = "data:image/svg+xml;base64," + btoa(icon); var dir = parseFloat(data.hdg || data.bearing || "0"); myMarker = L.divIcon({ className:"caricon", iconAnchor: [16, 16], html:'<img src="'+svgcar+'" style="width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);"/>', }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if (data.icon === "arrow") { data.iconColor = data.iconColor || "black"; icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="32px" height="32px" viewBox="0 0 32 32">'; icon += '<path d="m16.2 0.6l-10.9 31 10.7-11.1 10.5 11.1 -10.3-31z" fill="'+data.iconColor+'"/></svg>'; var svgarrow = "data:image/svg+xml;base64," + btoa(icon); var dir = parseFloat(data.hdg || data.bearing || "0"); myMarker = L.divIcon({ className:"arrowicon", iconAnchor: [16, 16], html:"'<img src='"+svgarrow+"' style='width:32px; height:32px; -webkit-transform:translate(0px,-16px) rotate("+dir+"deg); -moz-transform:translate(0px,-16px) rotate("+dir+"deg);'/>", }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if (data.icon === "wind") { data.iconColor = data.iconColor || "black"; icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="32px" height="32px" viewBox="0 0 32 32">'; icon += '<path d="M16.7 31.7l7-6.9c0.4-0.4 0.4-1 0-1.4 -0.4-0.4-1-0.4-1.4 0l-5.3 5.2V17.3l6.7-6.6c0.2-0.2 0.3-0.5 0.3-0.7v-9c0-0.9-1.1-1.3-1.7-0.7l-6.3 6.2L9.7 0.3C9.1-0.3 8 0.1 8 1.1v8.8c0 0.3 0.1 0.6 0.3 0.8l6.7 6.6v11.3l-5.3-5.2c-0.4-0.4-1-0.4-1.4 0 -0.4 0.4-0.4 1 0 1.4l7 6.9c0.2 0.2 0.5 0.3 0.7 0.3C16.2 32 16.5 31.9 16.7 31.7zM10 9.6V3.4l5 4.9v6.2L10 9.6zM17 8.3l5-4.9v6.2l-5 4.9V8.3z" fill="'+data.iconColor+'"/></svg>'; var svgwind = "data:image/svg+xml;base64," + btoa(icon); var dir = parseFloat(data.hdg || data.bearing || "0"); myMarker = L.divIcon({ className:"windicon", iconAnchor: [16, 16], html:'<img src="'+svgwind+'" style="width:32px; height:32px; -webkit-transform:rotate('+dir+'deg); -moz-transform:rotate('+dir+'deg);"/>', }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if (data.icon === "satellite") { data.iconColor = data.iconColor || "black"; icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100">'; icon += '<polygon points="38.17 39.4 45.24 32.33 43.34 27.92 24.21 8.78 14.59 18.4 33.72 37.53" fill="'+data.iconColor+'"/>'; icon += '<path d="M69.22 44.57L54.38 29.73c-1.1-1.1-2.91-1.1-4.01 0L35.53 44.57c-1.1 1.1-1.1 2.91 0 4.01l14.84 14.84c1.1 1.1 2.91 1.1 4.01 0l14.84-14.84C70.32 47.47 70.32 45.67 69.22 44.57z" fill="'+data.iconColor+'"/>'; icon += '<polygon points="71.04 55.61 66.58 53.75 59.52 60.82 61.42 65.23 80.55 84.36 90.17 74.75" fill="'+data.iconColor+'"/>'; icon += '<path d="M28.08 55.26l-6.05 0.59C23.11 68.13 32.78 77.94 45 79.22l0.59-6.05C36.26 72.15 28.89 64.66 28.08 55.26z" fill="'+data.iconColor+'"/>'; icon += '<path d="M15.88 56.54L9.83 57.13c1.67 18.06 16.03 32.43 34.08 34.09l0.59-6.04C29.34 83.76 17.29 71.71 15.88 56.54z" fill="'+data.iconColor+'"/>'; icon += '</svg>'; var svgsat = "data:image/svg+xml;base64," + btoa(icon); myMarker = L.divIcon({ className:"satelliteicon", iconAnchor: [16, 16], html:'<img src="'+svgsat+'" style="width:32px; height:32px;"/>', }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if ((data.icon === "iss") || (data.icon === "ISS")) { data.iconColor = data.iconColor || "black"; icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 48 48">'; icon += '<path id="iss" d="m4.55 30.97l6.85-12.68 0.59 0.32 -6.85 12.68 4.27 2.3 6.85-12.68 0.49 0.27 -0.81 1.5c-0.26 0.48-0.07 1.1 0.44 1.37l5.09 2.75c0.5 0.27 1.12 0.1 1.38-0.39l0.81-1.5 0.72 0.39 -1.49 2.75c-0.41 0.76-0.38 1.58 0.08 1.82l4.61 2.49c0.45 0.24 1.15-0.18 1.56-0.94l1.49-2.75 0.69 0.37 -6.85 12.68 4.26 2.3 6.85-12.68 0.59 0.32 -6.85 12.69 4.26 2.3 14.46-26.78 -4.26-2.3 -6.88 12.74 -0.59-0.32 6.88-12.74 -4.26-2.3 -6.88 12.74 -0.69-0.37 1.49-2.75c0.41-0.76 '; icon += '0.38-1.58-0.08-1.82l-1.4-0.75 0.5-0.92c1.02 0.17 2.09-0.32 2.62-1.3 0.67-1.23 0.22-2.76-0.99-3.42 -1.21-0.65-2.74-0.19-3.4 1.05 -0.53 0.98-0.35 2.14 0.35 2.9l-0.5 0.92 -1.8-0.97c-0.45-0.24-1.15 0.17-1.57 0.94l-1.49 2.75 -0.72-0.39 0.81-1.5c0.26-0.48 0.07-1.1-0.44-1.36l-5.09-2.75c-0.5-0.27-1.12-0.1-1.38 0.39l-0.81 1.5 -0.49-0.27 6.88-12.74 -4.26-2.3 -6.88 12.74 -0.59-0.32 6.88-12.74 -4.26-2.3 -14.46 26.78 4.26 2.3zm14.26-11.72c0.2-0.37 0.68-0.51 1.06-0.3l3.93 '; icon += '2.12c0.39 0.21 0.54 0.68 0.34 1.05l-1.81 3.35c-0.2 0.37-0.68 0.51-1.06 0.3l-3.93-2.12c-0.38-0.21-0.53-0.68-0.33-1.05l1.81-3.35zm12.01-1.46c0.45-0.83 1.47-1.14 2.28-0.7 0.81 0.44 1.11 1.46 0.66 2.29 -0.44 0.83-1.47 1.14-2.28 0.7 -0.81-0.44-1.11-1.46-0.66-2.29zm-3.78 4.26c0.35-0.66 0.93-1.04 1.28-0.85l3.57 1.93c0.35 0.19 0.35 0.88-0.01 1.53l-3.19 5.91c-0.35 0.66-0.93 1.04-1.28 0.85l-3.56-1.92c-0.35-0.19-0.35-0.88 0.01-1.53l3.19-5.91zm0.19 7.49c-0.26 0.49-0.87 '; icon += '0.67-1.36 0.41 -0.49-0.26-0.67-0.87-0.41-1.36 0.27-0.49 0.87-0.67 1.36-0.4 0.49 0.26 0.67 0.87 0.41 1.36zm-7.46-6.31c-0.26 0.49-0.87 0.67-1.36 0.41s-0.67-0.87-0.41-1.36c0.27-0.49 0.87-0.67 1.36-0.4s0.67 0.87 0.41 1.36zm2.32 1.25c-0.26 0.49-0.87 0.67-1.36 0.41 -0.49-0.26-0.67-0.87-0.41-1.36 0.27-0.49 0.87-0.67 1.36-0.41 0.49 0.26 0.67 0.87 0.41 1.36z" fill="'+data.iconColor+'"/>'; icon += '</svg>'; var svgiss = "data:image/svg+xml;base64," + btoa(icon); myMarker = L.divIcon({ className:"issicon", iconAnchor: [25, 25], html:'<img src="'+svgiss+'" style="width:50px; height:50px;"/>', }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); } else if (data.icon === "locate") { data.iconColor = data.iconColor || "cyan"; icon = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="468px" height="468px" viewBox="0 0 468 468">'; icon += '<polygon points="32 32 104 32 104 0 0 0 0 104 32 104" fill="'+data.iconColor+'"/>'; icon += '<polygon points="468 0 364 0 364 32 436 32 436 104 468 104" fill="'+data.iconColor+'"/>'; icon += '<polygon points="0 468 104 468 104 436 32 436 32 364 0 364" fill="'+data.iconColor+'"/>'; icon += '<polygon points="436 436 364 436 364 468 468 468 468 364 436 364" fill="'+data.iconColor+'"/>'; //icon += '<circle cx="234" cy="234" r="22" fill="'+data.iconColor+'"/>'; icon += '</svg>'; var svglocate = "data:image/svg+xml;base64," + btoa(icon); myMarker = L.divIcon({ className:"locateicon", iconAnchor: [16, 16], html:'<img src="'+svglocate+'" style="width:32px; height:32px;"/>', }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); labelOffset = [12,-4]; } else if (data.icon === "friend") { marker = L.marker(ll, { icon: L.divIcon({ className: 'circle f', iconSize: [20, 12] }), title: data.name, draggable:drag }); } else if (data.icon === "hostile") { marker = L.marker(ll, { icon: L.divIcon({ className: 'circle h', iconSize: [16, 16] }), title: data.name, draggable:drag }); } else if (data.icon === "neutral") { marker = L.marker(ll, { icon: L.divIcon({ className: 'circle n', iconSize: [16, 16] }), title: data.name, draggable:drag }); } else if (data.icon === "unknown") { marker = L.marker(ll, { icon: L.divIcon({ className: 'circle', iconSize: [16, 16] }), title: data.name, draggable:drag }); } else if (data.icon === "danger") { marker = L.marker(ll, { icon: L.divIcon({ className: 'up-triangle' }), title: data.name, draggable:drag }); } else if (data.icon === "earthquake") { marker = L.marker(ll, { icon: L.divIcon({ className: 'circle e', iconSize: [data.mag*5, data.mag*5] }), title: data.name, draggable:drag }); } else if (data.icon.match(/^:.*:$/g)) { var em = emojify(data.icon); var col = data.iconColor || "#910000"; myMarker = L.divIcon({ className:"emicon", html: '<center><span style="font-size:2em; color:'+col+'">'+em+'</span></center>', iconSize: [32, 32] }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); labelOffset = [12,-4]; } else if (data.icon.match(/^https?:.*$/)) { myMarker = L.icon({ iconUrl: data.icon, iconSize: [32, 32], iconAnchor: [16, 16], popupAnchor: [0, -16] }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); labelOffset = [12,-4]; } else if (data.icon.substr(0,3) === "fa-") { var col = data.iconColor || "#910000"; var imod = ""; if (data.icon.indexOf(" ") === -1) { imod = "fa-2x "; } myMarker = L.divIcon({ className:"faicon", html: '<center><i class="fa fa-fw '+imod+data.icon+'" style="color:'+col+'"></i></center>', iconSize: [32, 32], popupAnchor: [0, -16] }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); labelOffset = [8,-8]; } else if (data.icon.substr(0,3) === "wi-") { var col = data.iconColor || "#910000"; var imod = ""; if (data.icon.indexOf(" ") === -1) { imod = "wi-2x "; } myMarker = L.divIcon({ className:"wiicon", html: '<center><i class="wi wi-fw '+imod+data.icon+'" style="color:'+col+'"></i></center>', iconSize: [32, 32], popupAnchor: [0, -16] }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); labelOffset = [16,-16]; } else { myMarker = L.VectorMarkers.icon({ icon: data.icon || "circle", markerColor: (data.iconColor || "#910000"), prefix: 'fa', iconColor: 'white' }); marker = L.marker(ll, {title:data.name, icon:myMarker, draggable:drag}); labelOffset = [6,-6]; } } if (data.hasOwnProperty("SIDC")) { // "SIDC":"SFGPU------E***","name":"1.C2 komp","fullname":"1.C2 komp/FTS/INSS" myMarker = new ms.Symbol( data.SIDC.toUpperCase(), { uniqueDesignation:data.name }); // Now that we have a symbol we can ask for the echelon and set the symbol size var opts = data.options || {}; opts.size = opts.size || iconSz[myMarker.getProperties().echelon] || 30; opts.size = opts.size * (opts.scale || 1); myMarker = myMarker.setOptions(opts); var myicon = L.icon({ iconUrl: myMarker.toDataURL(), iconAnchor: [myMarker.getAnchor().x, myMarker.getAnchor().y], className: "natoicon", }); marker = L.marker(ll, { title:data.name, icon:myicon, draggable:drag }); } marker.name = data.name; // var createLabelIcon = function(labelText) { // return L.marker(new L.LatLng(51.05, -1.35), {icon:L.divIcon({ html:labelText })}); // } // send new position at end of move event if point is draggable if (data.draggable === true) { if (data.icon) { marker.icon = data.icon; } if (data.iconColor) { marker.iconColor = data.iconColor; } if (data.SIDC) { marker.SIDC = data.SIDC.toUpperCase(); } marker.on('dragend', function (e) { var l = marker.getLatLng().toString().replace('LatLng(','lat, lon : ').replace(')','') marker.setPopupContent(marker.getPopup().getContent().split("lat, lon")[0] + l); ws.send(JSON.stringify({action:"move",name:marker.name,layer:marker.lay,icon:marker.icon,iconColor:marker.iconColor,SIDC:marker.SIDC,draggable:true,lat:parseFloat(marker.getLatLng().lat.toFixed(6)),lon:parseFloat(marker.getLatLng().lng.toFixed(6))})); }); } // remove icon from list of properties, then add all others to popup if (data.hasOwnProperty("SIDC") && data.hasOwnProperty("options")) { delete data.options; } if (data.hasOwnProperty("icon")) { delete data.icon; } if (data.hasOwnProperty("iconColor")) { delete data.iconColor; } if (data.hasOwnProperty("photourl")) { words += "<img src=\"" + data.photourl + "\" style=\"width:100%; margin-top:10px;\">"; delete data.photourl; } if (data.hasOwnProperty("photoUrl")) { words += "<img src=\"" + data.photoUrl + "\" style=\"width:100%; margin-top:10px;\">"; delete data.photoUrl; } if (data.hasOwnProperty("videoUrl")) { words += '<video controls muted autoplay width="320"><source src="'+data.videoUrl+'" type="video/mp4">Your browser does not support the video tag.</video>'; delete data.videoUrl; } if (data.hasOwnProperty("ttl")) { // save expiry time for this marker if (data.ttl != 0) { marker.ts = parseInt(Date.now()/1000) + Number(data.ttl); } delete data.ttl; } else if (maxage != 0) { marker.ts = parseInt(Date.now()/1000) + Number(maxage); } if (data.hasOwnProperty("weblink")) { if (typeof data.weblink === "string") { words += "<b><a href='"+ data.weblink + "' target='_new'>more information...</a></b><br/>"; } else { var tgt = data.weblink.target || "_new"; words += "<b><a href='"+ data.weblink.url + "' target='"+ tgt + "'>" + data.weblink.name + "</a></b><br/>"; } delete data.weblink; } var p; if (data.hasOwnProperty("popped") && (data.popped === true)) { p = true; delete data.popped; } if (data.hasOwnProperty("popped") && (data.popped === false)) { marker.closePopup(); p = false; delete data.popped; } // If .label then use that rather than name tooltip if (data.label) { if (typeof data.label === "boolean" && data.label === true) { marker.bindTooltip(data.name, { permanent:true, direction:"right", offset:labelOffset }); } else if (typeof data.label === "string" && data.label.length > 0) { marker.bindTooltip(data.label, { permanent:true, direction:"right", offset:labelOffset }); } delete marker.options.title; delete data.label; } // otherwise check for .tooltip then use that rather than name tooltip else if (data.tooltip) { if (typeof data.tooltip === "string" && data.tooltip.length > 0) { marker.bindTooltip(data.tooltip, { direction:"bottom", offset:[0,4] }); delete marker.options.title; delete data.tooltip; } } marker = rightmenu(marker); // Add any remaining properties to the info box var llc = data.lineColor; delete data.lat; delete data.lon; if (data.layer) { delete data.layer; } if (data.lineColor) { delete data.lineColor; } if (data.color) { delete data.color; } if (data.weight) { delete data.weight; } if (data.tracklength) { delete data.tracklength; } if (data.dashArray) { delete data.dashArray; } if (data.fill) { delete data.fill; } if (data.draggable) { delete data.draggable; } for (var i in data) { if ((i != "name") && (i != "length")) { if (typeof data[i] === "object") { words += i +" : "+JSON.stringify(data[i])+"<br/>"; } else { words += i +" : "+data[i]+"<br/>"; } } } if (data.popup) { words = data.popup; } else { words = words + marker.getLatLng().toString().replace('LatLng(','lat, lon : ').replace(')',''); } words = "<b>"+data.name+"</b><br/>" + words; //"<button style=\"border-radius:4px; float:right; background-color:lightgrey;\" onclick='popped=false;popmark.closePopup();'>X</button><br/>" + words; marker.bindPopup(words, {autoClose:false, closeButton:true, closeOnClick:false, minWidth:200}); marker._popup.dname = data.name; marker.lay = lay; // and the layer it is on marker.on('click', function(e) { ws.send(JSON.stringify({action:"click",name:marker.name,layer:marker.lay,icon:marker.icon,iconColor:marker.iconColor,SIDC:marker.SIDC,draggable:true,lat:parseFloat(marker.getLatLng().lat.toFixed(6)),lon:parseFloat(marker.getLatLng().lng.toFixed(6))})); }); if ((data.addtoheatmap !== "false") || (!data.hasOwnProperty("addtoheatmap"))) { // Added to give ability to control if points from active layer contribute to heatmap if (heatAll || map.hasLayer(layers[lay])) { heat.addLatLng(lli); } } markers[data.name] = marker; layers[lay].addLayer(marker); if ((data.hdg != null) && (data.bearing == null)) { data.bearing = data.hdg; delete data.hdg; } if (data.bearing != null) { // if there is a heading if (data.speed != null) { data.length = parseFloat(data.speed || "0") * 50; } // and a speed if (data.length != null) { if (polygons[data.name] != null) { map.removeLayer(polygons[data.name]); } var x = ll.lng * 1; // X coordinate var y = ll.lat * 1; // Y coordinate var ll1 = ll; var angle = parseFloat(data.bearing); var lengthAsDegrees = parseFloat(data.length || "0") / 110540; // metres in a degree..ish var polygon = null; if (data.accuracy != null) { data.accuracy = Number(data.accuracy); var y2 = y + Math.sin((90-angle+data.accuracy)/180*Math.PI)*lengthAsDegrees*Math.cos(y/180*Math.PI); var x2 = x + Math.cos((90-angle+data.accuracy)/180*Math.PI)*lengthAsDegrees; var ll2 = new L.LatLng(y2,x2); var y3 = y + Math.sin((90-angle-data.accuracy)/180*Math.PI)*lengthAsDegrees*Math.cos(y/180*Math.PI); var x3 = x + Math.cos((90-angle-data.accuracy)/180*Math.PI)*lengthAsDegrees; var ll3 = new L.LatLng(y3,x3); polygon = L.polygon([ ll1, ll2, ll3 ], {weight:2, color:llc||'#f30', fillOpacity:0.06, clickable:false}); } else { var ya = y + Math.sin((90-angle)/180*Math.PI)*lengthAsDegrees*Math.cos(y/180*Math.PI); var xa = x + Math.cos((90-angle)/180*Math.PI)*lengthAsDegrees; var lla = new L.LatLng(ya,xa); polygon = L.polygon([ ll1, lla ], {weight:2, color:llc||'#f30', clickable:false}); } if (typeof layers[lay].getVisibleParent === 'function') { var vis = layers[lay].getVisibleParent(marker); if ((polygon !== null) && (vis !== null) && (!vis.hasOwnProperty("lay"))) { polygon.setStyle({opacity:0}); } } polygons[data.name] = polygon; polygons[data.name].lay = lay; layers[lay].addLayer(polygon); } } if (panit) { map.setView(ll,map.getZoom()); } if (p === true) { marker.openPopup(); } } }
[ "function", "setMarker", "(", "data", ")", "{", "var", "rightmenu", "=", "function", "(", "m", ")", "{", "// customise right click context menu", "var", "rightcontext", "=", "\"\"", ";", "if", "(", "polygons", "[", "data", ".", "name", "]", "==", "undefined", ")", "{", "rightcontext", "=", "\"<button id='delbutton' onclick='delMarker(\\\"\"", "+", "data", ".", "name", "+", "\"\\\",true);'>Delete</button>\"", ";", "}", "else", "if", "(", "data", ".", "editable", ")", "{", "rightcontext", "=", "\"<button onclick='editPoly(\\\"\"", "+", "data", ".", "name", "+", "\"\\\",true);'>Edit</button><button onclick='delMarker(\\\"\"", "+", "data", ".", "name", "+", "\"\\\",true);'>Delete</button>\"", ";", "}", "if", "(", "(", "data", ".", "contextmenu", "!==", "undefined", ")", "&&", "(", "typeof", "data", ".", "contextmenu", "===", "\"string\"", ")", ")", "{", "rightcontext", "=", "data", ".", "contextmenu", ".", "replace", "(", "/", "\\$name", "/", "g", ",", "data", ".", "name", ")", ";", "delete", "data", ".", "contextmenu", ";", "}", "if", "(", "rightcontext", ".", "length", ">", "0", ")", "{", "var", "rightmenuMarker", "=", "L", ".", "popup", "(", "{", "offset", ":", "[", "0", ",", "-", "12", "]", "}", ")", ".", "setContent", "(", "\"<b>\"", "+", "data", ".", "name", "+", "\"</b><br/>\"", "+", "rightcontext", ")", ";", "if", "(", "hiderightclick", "!==", "true", ")", "{", "m", ".", "on", "(", "'contextmenu'", ",", "function", "(", "e", ")", "{", "L", ".", "DomEvent", ".", "stopPropagation", "(", "e", ")", ";", "rightmenuMarker", ".", "setLatLng", "(", "e", ".", "latlng", ")", ";", "map", ".", "openPopup", "(", "rightmenuMarker", ")", ";", "}", ")", ";", "}", "}", "return", "m", ";", "}", "//console.log(\"DATA\" typeof data, data);", "if", "(", "data", ".", "deleted", ")", "{", "// remove markers we are told to", "delMarker", "(", "data", ".", "name", ")", ";", "return", ";", "}", "var", "ll", ";", "var", "lli", "=", "null", ";", "var", "opt", "=", "{", "}", ";", "opt", ".", "color", "=", "data", ".", "color", "||", "\"#910000\"", ";", "opt", ".", "fillColor", "=", "data", ".", "fillColor", "||", "\"#910000\"", ";", "opt", ".", "stroke", "=", "(", "data", ".", "hasOwnProperty", "(", "\"stroke\"", ")", ")", "?", "data", ".", "stroke", ":", "true", ";", "opt", ".", "weight", "=", "data", ".", "weight", "||", "2", ";", "opt", ".", "opacity", "=", "data", ".", "opacity", "||", "1", ";", "opt", ".", "fillOpacity", "=", "data", ".", "fillOpacity", "||", "0.2", ";", "opt", ".", "clickable", "=", "(", "data", ".", "hasOwnProperty", "(", "\"clickable\"", ")", ")", "?", "data", ".", "clickable", ":", "false", ";", "opt", ".", "fill", "=", "(", "data", ".", "hasOwnProperty", "(", "\"fill\"", ")", ")", "?", "data", ".", "fill", ":", "true", ";", "if", "(", "data", ".", "hasOwnProperty", "(", "\"dashArray\"", ")", ")", "{", "opt", ".", "dashArray", "=", "data", ".", "dashArray", ";", "}", "// Replace building", "if", "(", "data", ".", "hasOwnProperty", "(", "\"building\"", ")", ")", "{", "if", "(", "(", "data", ".", "building", "===", "\"\"", ")", "&&", "layers", ".", "hasOwnProperty", "(", "\"buildings\"", ")", ")", "{", "map", ".", "removeLayer", "(", "layers", "[", "\"buildings\"", "]", ")", ";", "layercontrol", ".", "_update", "(", ")", ";", "layers", "[", "\"buildings\"", "]", "=", "overlays", "[", "\"buildings\"", "]", ".", "set", "(", "\"\"", ")", ";", "return", ";", "}", "//layers[\"buildings\"] = new OSMBuildings(map).set(data.building);", "layers", "[", "\"buildings\"", "]", "=", "overlays", "[", "\"buildings\"", "]", ".", "set", "(", "data", ".", "building", ")", ";", "map", ".", "addLayer", "(", "layers", "[", "\"buildings\"", "]", ")", ";", "return", ";", "}", "var", "lay", "=", "data", ".", "layer", "||", "\"unknown\"", ";", "if", "(", "!", "data", ".", "hasOwnProperty", "(", "\"action\"", ")", "||", "data", ".", "action", ".", "indexOf", "(", "\"layer\"", ")", "===", "-", "1", ")", "{", "if", "(", "typeof", "layers", "[", "lay", "]", "==", "\"undefined\"", ")", "{", "// add layer if if doesn't exist", "if", "(", "clusterAt", ">", "0", ")", "{", "layers", "[", "lay", "]", "=", "new", "L", ".", "MarkerClusterGroup", "(", "{", "maxClusterRadius", ":", "50", ",", "spiderfyDistanceMultiplier", ":", "1.8", ",", "disableClusteringAtZoom", ":", "clusterAt", "//zoomToBoundsOnClick:false", "}", ")", ";", "}", "else", "{", "layers", "[", "lay", "]", "=", "new", "L", ".", "LayerGroup", "(", ")", ";", "}", "overlays", "[", "lay", "]", "=", "layers", "[", "lay", "]", ";", "if", "(", "showLayerMenu", "!==", "false", ")", "{", "layercontrol", ".", "addOverlay", "(", "layers", "[", "lay", "]", ",", "lay", ")", ";", "}", "map", ".", "addLayer", "(", "overlays", "[", "lay", "]", ")", ";", "//console.log(\"ADDED LAYER\",lay,layers);", "}", "if", "(", "!", "allData", ".", "hasOwnProperty", "(", "data", ".", "name", ")", ")", "{", "allData", "[", "data", ".", "name", "]", "=", "{", "}", ";", "}", "delete", "data", ".", "action", ";", "Object", ".", "keys", "(", "data", ")", ".", "forEach", "(", "key", "=>", "{", "if", "(", "data", "[", "key", "]", "==", "null", ")", "{", "delete", "allData", "[", "data", ".", "name", "]", "[", "key", "]", ";", "}", "else", "{", "allData", "[", "data", ".", "name", "]", "[", "key", "]", "=", "data", "[", "key", "]", ";", "}", "}", ")", ";", "data", "=", "Object", ".", "assign", "(", "{", "}", ",", "allData", "[", "data", ".", "name", "]", ")", ";", "}", "delete", "data", ".", "action", ";", "if", "(", "typeof", "markers", "[", "data", ".", "name", "]", "!=", "\"undefined\"", ")", "{", "if", "(", "markers", "[", "data", ".", "name", "]", ".", "lay", "!==", "data", ".", "layer", ")", "{", "delMarker", "(", "data", ".", "name", ")", ";", "}", "else", "{", "try", "{", "layers", "[", "lay", "]", ".", "removeLayer", "(", "markers", "[", "data", ".", "name", "]", ")", ";", "}", "catch", "(", "e", ")", "{", "console", ".", "log", "(", "\"OOPS\"", ")", ";", "}", "}", "}", "if", "(", "typeof", "polygons", "[", "data", ".", "name", "]", "!=", "\"undefined\"", ")", "{", "layers", "[", "lay", "]", ".", "removeLayer", "(", "polygons", "[", "data", ".", "name", "]", ")", ";", "}", "if", "(", "data", ".", "hasOwnProperty", "(", "\"line\"", ")", "&&", "Array", ".", "isArray", "(", "data", ".", "line", ")", ")", "{", "delete", "opt", ".", "fill", ";", "if", "(", "!", "data", ".", "hasOwnProperty", "(", "\"weight\"", ")", ")", "{", "opt", ".", "weight", "=", "3", ";", "}", "//Standard settings different for lines", "if", "(", "!", "data", ".", "hasOwnProperty", "(", "\"opacity\"", ")", ")", "{", "opt", ".", "opacity", "=", "0.8", ";", "}", "var", "polyln", "=", "L", ".", "polyline", "(", "data", ".", "line", ",", "opt", ")", ";", "polygons", "[", "data", ".", "name", "]", "=", "polyln", ";", "}", "else", "if", "(", "data", ".", "hasOwnProperty", "(", "\"area\"", ")", "&&", "Array", ".", "isArray", "(", "data", ".", "area", ")", ")", "{", "var", "polyarea", ";", "if", "(", "data", ".", "area", ".", "length", "===", "2", ")", "{", "polyarea", "=", "L", ".", "rectangle", "(", "data", ".", "area", ",", "opt", ")", ";", "}", "else", "{", "polyarea", "=", "L", ".", "polygon", "(", "data", ".", "area", ",", "opt", ")", ";", "}", "polygons", "[", "data", ".", "name", "]", "=", "polyarea", ";", "}", "else", "if", "(", "data", ".", "hasOwnProperty", "(", "\"sdlat\"", ")", "&&", "data", ".", "hasOwnProperty", "(", "\"sdlon\"", ")", ")", "{", "if", "(", "!", "data", ".", "hasOwnProperty", "(", "\"iconColor\"", ")", ")", "{", "opt", ".", "color", "=", "\"blue\"", ";", "}", "//different standard Color Settings", "if", "(", "!", "data", ".", "hasOwnProperty", "(", "\"fillColor\"", ")", ")", "{", "opt", ".", "fillColor", "=", "\"blue\"", ";", "}", "var", "ellipse", "=", "L", ".", "ellipse", "(", "new", "L", ".", "LatLng", "(", "(", "data", ".", "lat", "*", "1", ")", ",", "(", "data", ".", "lon", "*", "1", ")", ")", ",", "[", "200000", "*", "data", ".", "sdlon", "*", "Math", ".", "cos", "(", "data", ".", "lat", "*", "Math", ".", "PI", "/", "180", ")", ",", "200000", "*", "data", ".", "sdlat", "]", ",", "0", ",", "opt", ")", ";", "polygons", "[", "data", ".", "name", "]", "=", "ellipse", ";", "}", "else", "if", "(", "data", ".", "hasOwnProperty", "(", "\"radius\"", ")", ")", "{", "if", "(", "data", ".", "hasOwnProperty", "(", "\"lat\"", ")", "&&", "data", ".", "hasOwnProperty", "(", "\"lon\"", ")", ")", "{", "var", "polycirc", ";", "if", "(", "Array", ".", "isArray", "(", "data", ".", "radius", ")", ")", "{", "polycirc", "=", "L", ".", "ellipse", "(", "new", "L", ".", "LatLng", "(", "(", "data", ".", "lat", "*", "1", ")", ",", "(", "data", ".", "lon", "*", "1", ")", ")", ",", "[", "data", ".", "radius", "[", "0", "]", "*", "Math", ".", "cos", "(", "data", ".", "lat", "*", "Math", ".", "PI", "/", "180", ")", ",", "data", ".", "radius", "[", "1", "]", "]", ",", "data", ".", "tilt", "||", "0", ",", "opt", ")", ";", "}", "else", "{", "polycirc", "=", "L", ".", "circle", "(", "new", "L", ".", "LatLng", "(", "(", "data", ".", "lat", "*", "1", ")", ",", "(", "data", ".", "lon", "*", "1", ")", ")", ",", "data", ".", "radius", "*", "1", ",", "opt", ")", ";", "}", "polygons", "[", "data", ".", "name", "]", "=", "polycirc", ";", "}", "}", "if", "(", "polygons", "[", "data", ".", "name", "]", "!==", "undefined", ")", "{", "polygons", "[", "data", ".", "name", "]", ".", "lay", "=", "lay", ";", "if", "(", "opt", ".", "clickable", ")", "{", "var", "words", "=", "\"<b>\"", "+", "data", ".", "name", "+", "\"</b>\"", ";", "if", "(", "data", ".", "popup", ")", "{", "var", "words", "=", "words", "+", "\"<br/>\"", "+", "data", ".", "popup", ";", "}", "polygons", "[", "data", ".", "name", "]", ".", "bindPopup", "(", "words", ",", "{", "autoClose", ":", "false", ",", "closeButton", ":", "true", ",", "closeOnClick", ":", "false", ",", "minWidth", ":", "200", "}", ")", ";", "}", "polygons", "[", "data", ".", "name", "]", "=", "rightmenu", "(", "polygons", "[", "data", ".", "name", "]", ")", ";", "layers", "[", "lay", "]", ".", "addLayer", "(", "polygons", "[", "data", ".", "name", "]", ")", ";", "}", "else", "{", "if", "(", "typeof", "data", ".", "coordinates", "==", "\"object\"", ")", "{", "ll", "=", "new", "L", ".", "LatLng", "(", "data", ".", "coordinates", "[", "1", "]", ",", "data", ".", "coordinates", "[", "0", "]", ")", ";", "}", "else", "if", "(", "data", ".", "hasOwnProperty", "(", "\"position\"", ")", "&&", "data", ".", "position", ".", "hasOwnProperty", "(", "\"lat\"", ")", "&&", "data", ".", "position", ".", "hasOwnProperty", "(", "\"lon\"", ")", ")", "{", "data", ".", "lat", "=", "data", ".", "position", ".", "lat", "*", "1", ";", "data", ".", "lon", "=", "data", ".", "position", ".", "lon", "*", "1", ";", "data", ".", "alt", "=", "data", ".", "position", ".", "alt", ";", "if", "(", "parseFloat", "(", "data", ".", "position", ".", "alt", ")", "==", "data", ".", "position", ".", "alt", ")", "{", "data", ".", "alt", "=", "data", ".", "position", ".", "alt", "+", "\" m\"", ";", "}", "delete", "data", ".", "position", ";", "ll", "=", "new", "L", ".", "LatLng", "(", "(", "data", ".", "lat", "*", "1", ")", ",", "(", "data", ".", "lon", "*", "1", ")", ")", ";", "}", "else", "if", "(", "data", ".", "hasOwnProperty", "(", "\"lat\"", ")", "&&", "data", ".", "hasOwnProperty", "(", "\"lon\"", ")", ")", "{", "ll", "=", "new", "L", ".", "LatLng", "(", "(", "data", ".", "lat", "*", "1", ")", ",", "(", "data", ".", "lon", "*", "1", ")", ")", ";", "}", "else", "if", "(", "data", ".", "hasOwnProperty", "(", "\"latitude\"", ")", "&&", "data", ".", "hasOwnProperty", "(", "\"longitude\"", ")", ")", "{", "ll", "=", "new", "L", ".", "LatLng", "(", "(", "data", ".", "latitude", "*", "1", ")", ",", "(", "data", ".", "longitude", "*", "1", ")", ")", ";", "}", "else", "{", "console", ".", "log", "(", "\"No location:\"", ",", "data", ")", ";", "return", ";", "}", "// Adding new L.LatLng object (lli) when optional intensity value is defined. Only for use in heatmap layer", "if", "(", "typeof", "data", ".", "coordinates", "==", "\"object\"", ")", "{", "lli", "=", "new", "L", ".", "LatLng", "(", "data", ".", "coordinates", "[", "2", "]", ",", "data", ".", "coordinates", "[", "1", "]", ",", "data", ".", "coordinates", "[", "0", "]", ")", ";", "}", "else", "if", "(", "data", ".", "hasOwnProperty", "(", "\"lat\"", ")", "&&", "data", ".", "hasOwnProperty", "(", "\"lon\"", ")", "&&", "data", ".", "hasOwnProperty", "(", "\"intensity\"", ")", ")", "{", "lli", "=", "new", "L", ".", "LatLng", "(", "(", "data", ".", "lat", "*", "1", ")", ",", "(", "data", ".", "lon", "*", "1", ")", ",", "(", "data", ".", "intensity", "*", "1", ")", ")", ";", "}", "else", "if", "(", "data", ".", "hasOwnProperty", "(", "\"latitude\"", ")", "&&", "data", ".", "hasOwnProperty", "(", "\"longitude\"", ")", "&&", "data", ".", "hasOwnProperty", "(", "\"intensity\"", ")", ")", "{", "lli", "=", "new", "L", ".", "LatLng", "(", "(", "data", ".", "latitude", "*", "1", ")", ",", "(", "data", ".", "longitude", "*", "1", ")", ",", "(", "data", ".", "intensity", "*", "1", ")", ")", ";", "}", "else", "{", "lli", "=", "ll", "}", "// Create the icons... handle plane, car, ship, wind, earthquake as specials", "var", "marker", ",", "myMarker", ";", "var", "icon", ",", "q", ";", "var", "words", "=", "\"\"", ";", "var", "labelOffset", "=", "[", "12", ",", "0", "]", ";", "var", "drag", "=", "false", ";", "if", "(", "data", ".", "draggable", "===", "true", ")", "{", "drag", "=", "true", ";", "}", "//console.log(\"ICON\",data.icon);", "if", "(", "data", ".", "hasOwnProperty", "(", "\"icon\"", ")", ")", "{", "if", "(", "data", ".", "icon", "===", "\"ship\"", ")", "{", "marker", "=", "L", ".", "boatMarker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "color", ":", "(", "data", ".", "iconColor", "||", "\"blue\"", ")", "}", ")", ";", "marker", ".", "setHeading", "(", "parseFloat", "(", "data", ".", "hdg", "||", "data", ".", "bearing", "||", "\"0\"", ")", ")", ";", "q", "=", "'https://www.bing.com/images/search?q='", "+", "data", ".", "icon", "+", "'%20%2B\"'", "+", "encodeURIComponent", "(", "data", ".", "name", ")", "+", "'\"'", ";", "words", "+=", "'<a href=\\''", "+", "q", "+", "'\\' target=\"_thingpic\">Pictures</a><br>'", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"plane\"", ")", "{", "data", ".", "iconColor", "=", "data", ".", "iconColor", "||", "\"black\"", ";", "if", "(", "data", ".", "hasOwnProperty", "(", "\"squawk\"", ")", ")", "{", "data", ".", "iconColor", "=", "\"red\"", ";", "}", "icon", "=", "'<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" width=\"310px\" height=\"310px\" viewBox=\"0 0 310 310\">'", ";", "icon", "+=", "'<path d=\"M134.875,19.74c0.04-22.771,34.363-22.771,34.34,0.642v95.563L303,196.354v35.306l-133.144-43.821v71.424l30.813,24.072v27.923l-47.501-14.764l-47.501,14.764v-27.923l30.491-24.072v-71.424L3,231.66v-35.306l131.875-80.409V19.74z\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/></svg>'", ";", "var", "svgplane", "=", "\"data:image/svg+xml;base64,\"", "+", "btoa", "(", "icon", ")", ";", "var", "dir", "=", "parseFloat", "(", "data", ".", "hdg", "||", "data", ".", "bearing", "||", "\"0\"", ")", ";", "myMarker", "=", "L", ".", "divIcon", "(", "{", "className", ":", "\"planeicon\"", ",", "iconAnchor", ":", "[", "16", ",", "16", "]", ",", "html", ":", "'<img src=\"'", "+", "svgplane", "+", "'\" style=\"width:32px; height:32px; -webkit-transform:rotate('", "+", "dir", "+", "'deg); -moz-transform:rotate('", "+", "dir", "+", "'deg);\"/>'", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "//q = 'https://www.bing.com/images/search?q='+data.icon+'%20'+encodeURIComponent(data.name);", "//words += '<a href=\\''+q+'\\' target=\"_thingpic\">Pictures</a><br>';", "}", "else", "if", "(", "data", ".", "icon", "===", "\"helicopter\"", ")", "{", "data", ".", "iconColor", "=", "data", ".", "iconColor", "||", "\"black\"", ";", "if", "(", "data", ".", "hasOwnProperty", "(", "\"squawk\"", ")", ")", "{", "data", ".", "iconColor", "=", "\"red\"", ";", "}", "icon", "=", "'<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"314\" height=\"314\" viewBox=\"0 0 314.5 314.5\">'", ";", "icon", "+=", "'<path d=\"M268.8 3c-3.1-3.1-8.3-2.9-11.7 0.5L204.9 55.7C198.5 23.3 180.8 0 159.9 0c-21.9 0-40.3 25.5-45.7 60.2L57.4 3.5c-3.4-3.4-8.6-3.6-11.7-0.5 -3.1 3.1-2.9 8.4 0.5 11.7l66.3 66.3c0 0.2 0 0.4 0 0.6 0 20.9 4.6 39.9 12.1 54.4l-78.4 78.4c-3.4 3.4-3.6 8.6-0.5 11.7 3.1 3.1 8.3 2.9 11.7-0.5l76.1-76.1c3.2 3.7 6.7 6.7 10.4 8.9v105.8l-47.7 32.2v18l50.2-22.3h26.9l50.2 22.3v-18L175.8 264.2v-105.8c2.7-1.7 5.4-3.8 7.8-6.2l73.4 73.4c3.4 3.4 8.6 3.6 11.7 0.5 3.1-3.1 2.9-8.3-0.5-11.7l-74.9-74.9c8.6-14.8 14-35.2 14-57.8 0-1.9-0.1-3.8-0.2-5.8l61.2-61.2C271.7 11.3 271.9 6.1 268.8 3z\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/></svg>'", ";", "var", "svgheli", "=", "\"data:image/svg+xml;base64,\"", "+", "btoa", "(", "icon", ")", ";", "var", "dir", "=", "parseFloat", "(", "data", ".", "hdg", "||", "data", ".", "bearing", "||", "\"0\"", ")", ";", "myMarker", "=", "L", ".", "divIcon", "(", "{", "className", ":", "\"heliicon\"", ",", "iconAnchor", ":", "[", "16", ",", "16", "]", ",", "html", ":", "'<img src=\"'", "+", "svgheli", "+", "'\" style=\"width:32px; height:32px; -webkit-transform:rotate('", "+", "dir", "+", "'deg); -moz-transform:rotate('", "+", "dir", "+", "'deg);\"/>'", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"uav\"", ")", "{", "data", ".", "iconColor", "=", "data", ".", "iconColor", "||", "\"black\"", ";", "if", "(", "data", ".", "hasOwnProperty", "(", "\"squawk\"", ")", ")", "{", "data", ".", "iconColor", "=", "\"red\"", ";", "}", "icon", "=", "'<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 100 100\">'", ";", "icon", "+=", "'<path d=\"M62 82h-8V64h36c0-5-4-9-9-9H54v-8c0-3 4-5 4-11.1 0-4.4-3.6-8-8-8-4.4 0-8 3.6-8 8 0 5.1 4 8.1 4 11.1V55h-27c-5 0-9 4-9 9h36v18H38c-2.4 0-5 2.3-5 5L50 92l17-5C67 84.3 64.4 82 62 82z\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/></svg>'", ";", "var", "svguav", "=", "\"data:image/svg+xml;base64,\"", "+", "btoa", "(", "icon", ")", ";", "var", "dir", "=", "parseFloat", "(", "data", ".", "hdg", "||", "data", ".", "bearing", "||", "\"0\"", ")", ";", "myMarker", "=", "L", ".", "divIcon", "(", "{", "className", ":", "\"uavicon\"", ",", "iconAnchor", ":", "[", "16", ",", "16", "]", ",", "html", ":", "'<img src=\"'", "+", "svguav", "+", "'\" style=\"width:32px; height:32px; -webkit-transform:rotate('", "+", "dir", "+", "'deg); -moz-transform:rotate('", "+", "dir", "+", "'deg);\"/>'", ",", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"car\"", ")", "{", "data", ".", "iconColor", "=", "data", ".", "iconColor", "||", "\"black\"", ";", "icon", "=", "'<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" width=\"47px\" height=\"47px\" viewBox=\"0 0 47 47\">'", ";", "icon", "+=", "'<path d=\"M29.395,0H17.636c-3.117,0-5.643,3.467-5.643,6.584v34.804c0,3.116,2.526,5.644,5.643,5.644h11.759 c3.116,0,5.644-2.527,5.644-5.644V6.584C35.037,3.467,32.511,0,29.395,0z M34.05,14.188v11.665l-2.729,0.351v-4.806L34.05,14.188z M32.618,10.773c-1.016,3.9-2.219,8.51-2.219,8.51H16.631l-2.222-8.51C14.41,10.773,23.293,7.755,32.618,10.773z M15.741,21.713 v4.492l-2.73-0.349V14.502L15.741,21.713z M13.011,37.938V27.579l2.73,0.343v8.196L13.011,37.938z M14.568,40.882l2.218-3.336 h13.771l2.219,3.336H14.568z M31.321,35.805v-7.872l2.729-0.355v10.048L31.321,35.805z\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/></svg>'", ";", "var", "svgcar", "=", "\"data:image/svg+xml;base64,\"", "+", "btoa", "(", "icon", ")", ";", "var", "dir", "=", "parseFloat", "(", "data", ".", "hdg", "||", "data", ".", "bearing", "||", "\"0\"", ")", ";", "myMarker", "=", "L", ".", "divIcon", "(", "{", "className", ":", "\"caricon\"", ",", "iconAnchor", ":", "[", "16", ",", "16", "]", ",", "html", ":", "'<img src=\"'", "+", "svgcar", "+", "'\" style=\"width:32px; height:32px; -webkit-transform:rotate('", "+", "dir", "+", "'deg); -moz-transform:rotate('", "+", "dir", "+", "'deg);\"/>'", ",", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"arrow\"", ")", "{", "data", ".", "iconColor", "=", "data", ".", "iconColor", "||", "\"black\"", ";", "icon", "=", "'<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"32px\" height=\"32px\" viewBox=\"0 0 32 32\">'", ";", "icon", "+=", "'<path d=\"m16.2 0.6l-10.9 31 10.7-11.1 10.5 11.1 -10.3-31z\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/></svg>'", ";", "var", "svgarrow", "=", "\"data:image/svg+xml;base64,\"", "+", "btoa", "(", "icon", ")", ";", "var", "dir", "=", "parseFloat", "(", "data", ".", "hdg", "||", "data", ".", "bearing", "||", "\"0\"", ")", ";", "myMarker", "=", "L", ".", "divIcon", "(", "{", "className", ":", "\"arrowicon\"", ",", "iconAnchor", ":", "[", "16", ",", "16", "]", ",", "html", ":", "\"'<img src='\"", "+", "svgarrow", "+", "\"' style='width:32px; height:32px; -webkit-transform:translate(0px,-16px) rotate(\"", "+", "dir", "+", "\"deg); -moz-transform:translate(0px,-16px) rotate(\"", "+", "dir", "+", "\"deg);'/>\"", ",", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"wind\"", ")", "{", "data", ".", "iconColor", "=", "data", ".", "iconColor", "||", "\"black\"", ";", "icon", "=", "'<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"32px\" height=\"32px\" viewBox=\"0 0 32 32\">'", ";", "icon", "+=", "'<path d=\"M16.7 31.7l7-6.9c0.4-0.4 0.4-1 0-1.4 -0.4-0.4-1-0.4-1.4 0l-5.3 5.2V17.3l6.7-6.6c0.2-0.2 0.3-0.5 0.3-0.7v-9c0-0.9-1.1-1.3-1.7-0.7l-6.3 6.2L9.7 0.3C9.1-0.3 8 0.1 8 1.1v8.8c0 0.3 0.1 0.6 0.3 0.8l6.7 6.6v11.3l-5.3-5.2c-0.4-0.4-1-0.4-1.4 0 -0.4 0.4-0.4 1 0 1.4l7 6.9c0.2 0.2 0.5 0.3 0.7 0.3C16.2 32 16.5 31.9 16.7 31.7zM10 9.6V3.4l5 4.9v6.2L10 9.6zM17 8.3l5-4.9v6.2l-5 4.9V8.3z\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/></svg>'", ";", "var", "svgwind", "=", "\"data:image/svg+xml;base64,\"", "+", "btoa", "(", "icon", ")", ";", "var", "dir", "=", "parseFloat", "(", "data", ".", "hdg", "||", "data", ".", "bearing", "||", "\"0\"", ")", ";", "myMarker", "=", "L", ".", "divIcon", "(", "{", "className", ":", "\"windicon\"", ",", "iconAnchor", ":", "[", "16", ",", "16", "]", ",", "html", ":", "'<img src=\"'", "+", "svgwind", "+", "'\" style=\"width:32px; height:32px; -webkit-transform:rotate('", "+", "dir", "+", "'deg); -moz-transform:rotate('", "+", "dir", "+", "'deg);\"/>'", ",", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"satellite\"", ")", "{", "data", ".", "iconColor", "=", "data", ".", "iconColor", "||", "\"black\"", ";", "icon", "=", "'<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 100 100\">'", ";", "icon", "+=", "'<polygon points=\"38.17 39.4 45.24 32.33 43.34 27.92 24.21 8.78 14.59 18.4 33.72 37.53\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/>'", ";", "icon", "+=", "'<path d=\"M69.22 44.57L54.38 29.73c-1.1-1.1-2.91-1.1-4.01 0L35.53 44.57c-1.1 1.1-1.1 2.91 0 4.01l14.84 14.84c1.1 1.1 2.91 1.1 4.01 0l14.84-14.84C70.32 47.47 70.32 45.67 69.22 44.57z\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/>'", ";", "icon", "+=", "'<polygon points=\"71.04 55.61 66.58 53.75 59.52 60.82 61.42 65.23 80.55 84.36 90.17 74.75\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/>'", ";", "icon", "+=", "'<path d=\"M28.08 55.26l-6.05 0.59C23.11 68.13 32.78 77.94 45 79.22l0.59-6.05C36.26 72.15 28.89 64.66 28.08 55.26z\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/>'", ";", "icon", "+=", "'<path d=\"M15.88 56.54L9.83 57.13c1.67 18.06 16.03 32.43 34.08 34.09l0.59-6.04C29.34 83.76 17.29 71.71 15.88 56.54z\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/>'", ";", "icon", "+=", "'</svg>'", ";", "var", "svgsat", "=", "\"data:image/svg+xml;base64,\"", "+", "btoa", "(", "icon", ")", ";", "myMarker", "=", "L", ".", "divIcon", "(", "{", "className", ":", "\"satelliteicon\"", ",", "iconAnchor", ":", "[", "16", ",", "16", "]", ",", "html", ":", "'<img src=\"'", "+", "svgsat", "+", "'\" style=\"width:32px; height:32px;\"/>'", ",", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "(", "data", ".", "icon", "===", "\"iss\"", ")", "||", "(", "data", ".", "icon", "===", "\"ISS\"", ")", ")", "{", "data", ".", "iconColor", "=", "data", ".", "iconColor", "||", "\"black\"", ";", "icon", "=", "'<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" viewBox=\"0 0 48 48\">'", ";", "icon", "+=", "'<path id=\"iss\" d=\"m4.55 30.97l6.85-12.68 0.59 0.32 -6.85 12.68 4.27 2.3 6.85-12.68 0.49 0.27 -0.81 1.5c-0.26 0.48-0.07 1.1 0.44 1.37l5.09 2.75c0.5 0.27 1.12 0.1 1.38-0.39l0.81-1.5 0.72 0.39 -1.49 2.75c-0.41 0.76-0.38 1.58 0.08 1.82l4.61 2.49c0.45 0.24 1.15-0.18 1.56-0.94l1.49-2.75 0.69 0.37 -6.85 12.68 4.26 2.3 6.85-12.68 0.59 0.32 -6.85 12.69 4.26 2.3 14.46-26.78 -4.26-2.3 -6.88 12.74 -0.59-0.32 6.88-12.74 -4.26-2.3 -6.88 12.74 -0.69-0.37 1.49-2.75c0.41-0.76 '", ";", "icon", "+=", "'0.38-1.58-0.08-1.82l-1.4-0.75 0.5-0.92c1.02 0.17 2.09-0.32 2.62-1.3 0.67-1.23 0.22-2.76-0.99-3.42 -1.21-0.65-2.74-0.19-3.4 1.05 -0.53 0.98-0.35 2.14 0.35 2.9l-0.5 0.92 -1.8-0.97c-0.45-0.24-1.15 0.17-1.57 0.94l-1.49 2.75 -0.72-0.39 0.81-1.5c0.26-0.48 0.07-1.1-0.44-1.36l-5.09-2.75c-0.5-0.27-1.12-0.1-1.38 0.39l-0.81 1.5 -0.49-0.27 6.88-12.74 -4.26-2.3 -6.88 12.74 -0.59-0.32 6.88-12.74 -4.26-2.3 -14.46 26.78 4.26 2.3zm14.26-11.72c0.2-0.37 0.68-0.51 1.06-0.3l3.93 '", ";", "icon", "+=", "'2.12c0.39 0.21 0.54 0.68 0.34 1.05l-1.81 3.35c-0.2 0.37-0.68 0.51-1.06 0.3l-3.93-2.12c-0.38-0.21-0.53-0.68-0.33-1.05l1.81-3.35zm12.01-1.46c0.45-0.83 1.47-1.14 2.28-0.7 0.81 0.44 1.11 1.46 0.66 2.29 -0.44 0.83-1.47 1.14-2.28 0.7 -0.81-0.44-1.11-1.46-0.66-2.29zm-3.78 4.26c0.35-0.66 0.93-1.04 1.28-0.85l3.57 1.93c0.35 0.19 0.35 0.88-0.01 1.53l-3.19 5.91c-0.35 0.66-0.93 1.04-1.28 0.85l-3.56-1.92c-0.35-0.19-0.35-0.88 0.01-1.53l3.19-5.91zm0.19 7.49c-0.26 0.49-0.87 '", ";", "icon", "+=", "'0.67-1.36 0.41 -0.49-0.26-0.67-0.87-0.41-1.36 0.27-0.49 0.87-0.67 1.36-0.4 0.49 0.26 0.67 0.87 0.41 1.36zm-7.46-6.31c-0.26 0.49-0.87 0.67-1.36 0.41s-0.67-0.87-0.41-1.36c0.27-0.49 0.87-0.67 1.36-0.4s0.67 0.87 0.41 1.36zm2.32 1.25c-0.26 0.49-0.87 0.67-1.36 0.41 -0.49-0.26-0.67-0.87-0.41-1.36 0.27-0.49 0.87-0.67 1.36-0.41 0.49 0.26 0.67 0.87 0.41 1.36z\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/>'", ";", "icon", "+=", "'</svg>'", ";", "var", "svgiss", "=", "\"data:image/svg+xml;base64,\"", "+", "btoa", "(", "icon", ")", ";", "myMarker", "=", "L", ".", "divIcon", "(", "{", "className", ":", "\"issicon\"", ",", "iconAnchor", ":", "[", "25", ",", "25", "]", ",", "html", ":", "'<img src=\"'", "+", "svgiss", "+", "'\" style=\"width:50px; height:50px;\"/>'", ",", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"locate\"", ")", "{", "data", ".", "iconColor", "=", "data", ".", "iconColor", "||", "\"cyan\"", ";", "icon", "=", "'<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" x=\"0px\" y=\"0px\" width=\"468px\" height=\"468px\" viewBox=\"0 0 468 468\">'", ";", "icon", "+=", "'<polygon points=\"32 32 104 32 104 0 0 0 0 104 32 104\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/>'", ";", "icon", "+=", "'<polygon points=\"468 0 364 0 364 32 436 32 436 104 468 104\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/>'", ";", "icon", "+=", "'<polygon points=\"0 468 104 468 104 436 32 436 32 364 0 364\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/>'", ";", "icon", "+=", "'<polygon points=\"436 436 364 436 364 468 468 468 468 364 436 364\" fill=\"'", "+", "data", ".", "iconColor", "+", "'\"/>'", ";", "//icon += '<circle cx=\"234\" cy=\"234\" r=\"22\" fill=\"'+data.iconColor+'\"/>';", "icon", "+=", "'</svg>'", ";", "var", "svglocate", "=", "\"data:image/svg+xml;base64,\"", "+", "btoa", "(", "icon", ")", ";", "myMarker", "=", "L", ".", "divIcon", "(", "{", "className", ":", "\"locateicon\"", ",", "iconAnchor", ":", "[", "16", ",", "16", "]", ",", "html", ":", "'<img src=\"'", "+", "svglocate", "+", "'\" style=\"width:32px; height:32px;\"/>'", ",", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "labelOffset", "=", "[", "12", ",", "-", "4", "]", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"friend\"", ")", "{", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "icon", ":", "L", ".", "divIcon", "(", "{", "className", ":", "'circle f'", ",", "iconSize", ":", "[", "20", ",", "12", "]", "}", ")", ",", "title", ":", "data", ".", "name", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"hostile\"", ")", "{", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "icon", ":", "L", ".", "divIcon", "(", "{", "className", ":", "'circle h'", ",", "iconSize", ":", "[", "16", ",", "16", "]", "}", ")", ",", "title", ":", "data", ".", "name", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"neutral\"", ")", "{", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "icon", ":", "L", ".", "divIcon", "(", "{", "className", ":", "'circle n'", ",", "iconSize", ":", "[", "16", ",", "16", "]", "}", ")", ",", "title", ":", "data", ".", "name", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"unknown\"", ")", "{", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "icon", ":", "L", ".", "divIcon", "(", "{", "className", ":", "'circle'", ",", "iconSize", ":", "[", "16", ",", "16", "]", "}", ")", ",", "title", ":", "data", ".", "name", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"danger\"", ")", "{", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "icon", ":", "L", ".", "divIcon", "(", "{", "className", ":", "'up-triangle'", "}", ")", ",", "title", ":", "data", ".", "name", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "data", ".", "icon", "===", "\"earthquake\"", ")", "{", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "icon", ":", "L", ".", "divIcon", "(", "{", "className", ":", "'circle e'", ",", "iconSize", ":", "[", "data", ".", "mag", "*", "5", ",", "data", ".", "mag", "*", "5", "]", "}", ")", ",", "title", ":", "data", ".", "name", ",", "draggable", ":", "drag", "}", ")", ";", "}", "else", "if", "(", "data", ".", "icon", ".", "match", "(", "/", "^:.*:$", "/", "g", ")", ")", "{", "var", "em", "=", "emojify", "(", "data", ".", "icon", ")", ";", "var", "col", "=", "data", ".", "iconColor", "||", "\"#910000\"", ";", "myMarker", "=", "L", ".", "divIcon", "(", "{", "className", ":", "\"emicon\"", ",", "html", ":", "'<center><span style=\"font-size:2em; color:'", "+", "col", "+", "'\">'", "+", "em", "+", "'</span></center>'", ",", "iconSize", ":", "[", "32", ",", "32", "]", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "labelOffset", "=", "[", "12", ",", "-", "4", "]", ";", "}", "else", "if", "(", "data", ".", "icon", ".", "match", "(", "/", "^https?:.*$", "/", ")", ")", "{", "myMarker", "=", "L", ".", "icon", "(", "{", "iconUrl", ":", "data", ".", "icon", ",", "iconSize", ":", "[", "32", ",", "32", "]", ",", "iconAnchor", ":", "[", "16", ",", "16", "]", ",", "popupAnchor", ":", "[", "0", ",", "-", "16", "]", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "labelOffset", "=", "[", "12", ",", "-", "4", "]", ";", "}", "else", "if", "(", "data", ".", "icon", ".", "substr", "(", "0", ",", "3", ")", "===", "\"fa-\"", ")", "{", "var", "col", "=", "data", ".", "iconColor", "||", "\"#910000\"", ";", "var", "imod", "=", "\"\"", ";", "if", "(", "data", ".", "icon", ".", "indexOf", "(", "\" \"", ")", "===", "-", "1", ")", "{", "imod", "=", "\"fa-2x \"", ";", "}", "myMarker", "=", "L", ".", "divIcon", "(", "{", "className", ":", "\"faicon\"", ",", "html", ":", "'<center><i class=\"fa fa-fw '", "+", "imod", "+", "data", ".", "icon", "+", "'\" style=\"color:'", "+", "col", "+", "'\"></i></center>'", ",", "iconSize", ":", "[", "32", ",", "32", "]", ",", "popupAnchor", ":", "[", "0", ",", "-", "16", "]", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "labelOffset", "=", "[", "8", ",", "-", "8", "]", ";", "}", "else", "if", "(", "data", ".", "icon", ".", "substr", "(", "0", ",", "3", ")", "===", "\"wi-\"", ")", "{", "var", "col", "=", "data", ".", "iconColor", "||", "\"#910000\"", ";", "var", "imod", "=", "\"\"", ";", "if", "(", "data", ".", "icon", ".", "indexOf", "(", "\" \"", ")", "===", "-", "1", ")", "{", "imod", "=", "\"wi-2x \"", ";", "}", "myMarker", "=", "L", ".", "divIcon", "(", "{", "className", ":", "\"wiicon\"", ",", "html", ":", "'<center><i class=\"wi wi-fw '", "+", "imod", "+", "data", ".", "icon", "+", "'\" style=\"color:'", "+", "col", "+", "'\"></i></center>'", ",", "iconSize", ":", "[", "32", ",", "32", "]", ",", "popupAnchor", ":", "[", "0", ",", "-", "16", "]", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "labelOffset", "=", "[", "16", ",", "-", "16", "]", ";", "}", "else", "{", "myMarker", "=", "L", ".", "VectorMarkers", ".", "icon", "(", "{", "icon", ":", "data", ".", "icon", "||", "\"circle\"", ",", "markerColor", ":", "(", "data", ".", "iconColor", "||", "\"#910000\"", ")", ",", "prefix", ":", "'fa'", ",", "iconColor", ":", "'white'", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myMarker", ",", "draggable", ":", "drag", "}", ")", ";", "labelOffset", "=", "[", "6", ",", "-", "6", "]", ";", "}", "}", "if", "(", "data", ".", "hasOwnProperty", "(", "\"SIDC\"", ")", ")", "{", "// \"SIDC\":\"SFGPU------E***\",\"name\":\"1.C2 komp\",\"fullname\":\"1.C2 komp/FTS/INSS\"", "myMarker", "=", "new", "ms", ".", "Symbol", "(", "data", ".", "SIDC", ".", "toUpperCase", "(", ")", ",", "{", "uniqueDesignation", ":", "data", ".", "name", "}", ")", ";", "// Now that we have a symbol we can ask for the echelon and set the symbol size", "var", "opts", "=", "data", ".", "options", "||", "{", "}", ";", "opts", ".", "size", "=", "opts", ".", "size", "||", "iconSz", "[", "myMarker", ".", "getProperties", "(", ")", ".", "echelon", "]", "||", "30", ";", "opts", ".", "size", "=", "opts", ".", "size", "*", "(", "opts", ".", "scale", "||", "1", ")", ";", "myMarker", "=", "myMarker", ".", "setOptions", "(", "opts", ")", ";", "var", "myicon", "=", "L", ".", "icon", "(", "{", "iconUrl", ":", "myMarker", ".", "toDataURL", "(", ")", ",", "iconAnchor", ":", "[", "myMarker", ".", "getAnchor", "(", ")", ".", "x", ",", "myMarker", ".", "getAnchor", "(", ")", ".", "y", "]", ",", "className", ":", "\"natoicon\"", ",", "}", ")", ";", "marker", "=", "L", ".", "marker", "(", "ll", ",", "{", "title", ":", "data", ".", "name", ",", "icon", ":", "myicon", ",", "draggable", ":", "drag", "}", ")", ";", "}", "marker", ".", "name", "=", "data", ".", "name", ";", "// var createLabelIcon = function(labelText) {", "// return L.marker(new L.LatLng(51.05, -1.35), {icon:L.divIcon({ html:labelText })});", "// }", "// send new position at end of move event if point is draggable", "if", "(", "data", ".", "draggable", "===", "true", ")", "{", "if", "(", "data", ".", "icon", ")", "{", "marker", ".", "icon", "=", "data", ".", "icon", ";", "}", "if", "(", "data", ".", "iconColor", ")", "{", "marker", ".", "iconColor", "=", "data", ".", "iconColor", ";", "}", "if", "(", "data", ".", "SIDC", ")", "{", "marker", ".", "SIDC", "=", "data", ".", "SIDC", ".", "toUpperCase", "(", ")", ";", "}", "marker", ".", "on", "(", "'dragend'", ",", "function", "(", "e", ")", "{", "var", "l", "=", "marker", ".", "getLatLng", "(", ")", ".", "toString", "(", ")", ".", "replace", "(", "'LatLng('", ",", "'lat, lon : '", ")", ".", "replace", "(", "')'", ",", "''", ")", "marker", ".", "setPopupContent", "(", "marker", ".", "getPopup", "(", ")", ".", "getContent", "(", ")", ".", "split", "(", "\"lat, lon\"", ")", "[", "0", "]", "+", "l", ")", ";", "ws", ".", "send", "(", "JSON", ".", "stringify", "(", "{", "action", ":", "\"move\"", ",", "name", ":", "marker", ".", "name", ",", "layer", ":", "marker", ".", "lay", ",", "icon", ":", "marker", ".", "icon", ",", "iconColor", ":", "marker", ".", "iconColor", ",", "SIDC", ":", "marker", ".", "SIDC", ",", "draggable", ":", "true", ",", "lat", ":", "parseFloat", "(", "marker", ".", "getLatLng", "(", ")", ".", "lat", ".", "toFixed", "(", "6", ")", ")", ",", "lon", ":", "parseFloat", "(", "marker", ".", "getLatLng", "(", ")", ".", "lng", ".", "toFixed", "(", "6", ")", ")", "}", ")", ")", ";", "}", ")", ";", "}", "// remove icon from list of properties, then add all others to popup", "if", "(", "data", ".", "hasOwnProperty", "(", "\"SIDC\"", ")", "&&", "data", ".", "hasOwnProperty", "(", "\"options\"", ")", ")", "{", "delete", "data", ".", "options", ";", "}", "if", "(", "data", ".", "hasOwnProperty", "(", "\"icon\"", ")", ")", "{", "delete", "data", ".", "icon", ";", "}", "if", "(", "data", ".", "hasOwnProperty", "(", "\"iconColor\"", ")", ")", "{", "delete", "data", ".", "iconColor", ";", "}", "if", "(", "data", ".", "hasOwnProperty", "(", "\"photourl\"", ")", ")", "{", "words", "+=", "\"<img src=\\\"\"", "+", "data", ".", "photourl", "+", "\"\\\" style=\\\"width:100%; margin-top:10px;\\\">\"", ";", "delete", "data", ".", "photourl", ";", "}", "if", "(", "data", ".", "hasOwnProperty", "(", "\"photoUrl\"", ")", ")", "{", "words", "+=", "\"<img src=\\\"\"", "+", "data", ".", "photoUrl", "+", "\"\\\" style=\\\"width:100%; margin-top:10px;\\\">\"", ";", "delete", "data", ".", "photoUrl", ";", "}", "if", "(", "data", ".", "hasOwnProperty", "(", "\"videoUrl\"", ")", ")", "{", "words", "+=", "'<video controls muted autoplay width=\"320\"><source src=\"'", "+", "data", ".", "videoUrl", "+", "'\" type=\"video/mp4\">Your browser does not support the video tag.</video>'", ";", "delete", "data", ".", "videoUrl", ";", "}", "if", "(", "data", ".", "hasOwnProperty", "(", "\"ttl\"", ")", ")", "{", "// save expiry time for this marker", "if", "(", "data", ".", "ttl", "!=", "0", ")", "{", "marker", ".", "ts", "=", "parseInt", "(", "Date", ".", "now", "(", ")", "/", "1000", ")", "+", "Number", "(", "data", ".", "ttl", ")", ";", "}", "delete", "data", ".", "ttl", ";", "}", "else", "if", "(", "maxage", "!=", "0", ")", "{", "marker", ".", "ts", "=", "parseInt", "(", "Date", ".", "now", "(", ")", "/", "1000", ")", "+", "Number", "(", "maxage", ")", ";", "}", "if", "(", "data", ".", "hasOwnProperty", "(", "\"weblink\"", ")", ")", "{", "if", "(", "typeof", "data", ".", "weblink", "===", "\"string\"", ")", "{", "words", "+=", "\"<b><a href='\"", "+", "data", ".", "weblink", "+", "\"' target='_new'>more information...</a></b><br/>\"", ";", "}", "else", "{", "var", "tgt", "=", "data", ".", "weblink", ".", "target", "||", "\"_new\"", ";", "words", "+=", "\"<b><a href='\"", "+", "data", ".", "weblink", ".", "url", "+", "\"' target='\"", "+", "tgt", "+", "\"'>\"", "+", "data", ".", "weblink", ".", "name", "+", "\"</a></b><br/>\"", ";", "}", "delete", "data", ".", "weblink", ";", "}", "var", "p", ";", "if", "(", "data", ".", "hasOwnProperty", "(", "\"popped\"", ")", "&&", "(", "data", ".", "popped", "===", "true", ")", ")", "{", "p", "=", "true", ";", "delete", "data", ".", "popped", ";", "}", "if", "(", "data", ".", "hasOwnProperty", "(", "\"popped\"", ")", "&&", "(", "data", ".", "popped", "===", "false", ")", ")", "{", "marker", ".", "closePopup", "(", ")", ";", "p", "=", "false", ";", "delete", "data", ".", "popped", ";", "}", "// If .label then use that rather than name tooltip", "if", "(", "data", ".", "label", ")", "{", "if", "(", "typeof", "data", ".", "label", "===", "\"boolean\"", "&&", "data", ".", "label", "===", "true", ")", "{", "marker", ".", "bindTooltip", "(", "data", ".", "name", ",", "{", "permanent", ":", "true", ",", "direction", ":", "\"right\"", ",", "offset", ":", "labelOffset", "}", ")", ";", "}", "else", "if", "(", "typeof", "data", ".", "label", "===", "\"string\"", "&&", "data", ".", "label", ".", "length", ">", "0", ")", "{", "marker", ".", "bindTooltip", "(", "data", ".", "label", ",", "{", "permanent", ":", "true", ",", "direction", ":", "\"right\"", ",", "offset", ":", "labelOffset", "}", ")", ";", "}", "delete", "marker", ".", "options", ".", "title", ";", "delete", "data", ".", "label", ";", "}", "// otherwise check for .tooltip then use that rather than name tooltip", "else", "if", "(", "data", ".", "tooltip", ")", "{", "if", "(", "typeof", "data", ".", "tooltip", "===", "\"string\"", "&&", "data", ".", "tooltip", ".", "length", ">", "0", ")", "{", "marker", ".", "bindTooltip", "(", "data", ".", "tooltip", ",", "{", "direction", ":", "\"bottom\"", ",", "offset", ":", "[", "0", ",", "4", "]", "}", ")", ";", "delete", "marker", ".", "options", ".", "title", ";", "delete", "data", ".", "tooltip", ";", "}", "}", "marker", "=", "rightmenu", "(", "marker", ")", ";", "// Add any remaining properties to the info box", "var", "llc", "=", "data", ".", "lineColor", ";", "delete", "data", ".", "lat", ";", "delete", "data", ".", "lon", ";", "if", "(", "data", ".", "layer", ")", "{", "delete", "data", ".", "layer", ";", "}", "if", "(", "data", ".", "lineColor", ")", "{", "delete", "data", ".", "lineColor", ";", "}", "if", "(", "data", ".", "color", ")", "{", "delete", "data", ".", "color", ";", "}", "if", "(", "data", ".", "weight", ")", "{", "delete", "data", ".", "weight", ";", "}", "if", "(", "data", ".", "tracklength", ")", "{", "delete", "data", ".", "tracklength", ";", "}", "if", "(", "data", ".", "dashArray", ")", "{", "delete", "data", ".", "dashArray", ";", "}", "if", "(", "data", ".", "fill", ")", "{", "delete", "data", ".", "fill", ";", "}", "if", "(", "data", ".", "draggable", ")", "{", "delete", "data", ".", "draggable", ";", "}", "for", "(", "var", "i", "in", "data", ")", "{", "if", "(", "(", "i", "!=", "\"name\"", ")", "&&", "(", "i", "!=", "\"length\"", ")", ")", "{", "if", "(", "typeof", "data", "[", "i", "]", "===", "\"object\"", ")", "{", "words", "+=", "i", "+", "\" : \"", "+", "JSON", ".", "stringify", "(", "data", "[", "i", "]", ")", "+", "\"<br/>\"", ";", "}", "else", "{", "words", "+=", "i", "+", "\" : \"", "+", "data", "[", "i", "]", "+", "\"<br/>\"", ";", "}", "}", "}", "if", "(", "data", ".", "popup", ")", "{", "words", "=", "data", ".", "popup", ";", "}", "else", "{", "words", "=", "words", "+", "marker", ".", "getLatLng", "(", ")", ".", "toString", "(", ")", ".", "replace", "(", "'LatLng('", ",", "'lat, lon : '", ")", ".", "replace", "(", "')'", ",", "''", ")", ";", "}", "words", "=", "\"<b>\"", "+", "data", ".", "name", "+", "\"</b><br/>\"", "+", "words", ";", "//\"<button style=\\\"border-radius:4px; float:right; background-color:lightgrey;\\\" onclick='popped=false;popmark.closePopup();'>X</button><br/>\" + words;", "marker", ".", "bindPopup", "(", "words", ",", "{", "autoClose", ":", "false", ",", "closeButton", ":", "true", ",", "closeOnClick", ":", "false", ",", "minWidth", ":", "200", "}", ")", ";", "marker", ".", "_popup", ".", "dname", "=", "data", ".", "name", ";", "marker", ".", "lay", "=", "lay", ";", "// and the layer it is on", "marker", ".", "on", "(", "'click'", ",", "function", "(", "e", ")", "{", "ws", ".", "send", "(", "JSON", ".", "stringify", "(", "{", "action", ":", "\"click\"", ",", "name", ":", "marker", ".", "name", ",", "layer", ":", "marker", ".", "lay", ",", "icon", ":", "marker", ".", "icon", ",", "iconColor", ":", "marker", ".", "iconColor", ",", "SIDC", ":", "marker", ".", "SIDC", ",", "draggable", ":", "true", ",", "lat", ":", "parseFloat", "(", "marker", ".", "getLatLng", "(", ")", ".", "lat", ".", "toFixed", "(", "6", ")", ")", ",", "lon", ":", "parseFloat", "(", "marker", ".", "getLatLng", "(", ")", ".", "lng", ".", "toFixed", "(", "6", ")", ")", "}", ")", ")", ";", "}", ")", ";", "if", "(", "(", "data", ".", "addtoheatmap", "!==", "\"false\"", ")", "||", "(", "!", "data", ".", "hasOwnProperty", "(", "\"addtoheatmap\"", ")", ")", ")", "{", "// Added to give ability to control if points from active layer contribute to heatmap", "if", "(", "heatAll", "||", "map", ".", "hasLayer", "(", "layers", "[", "lay", "]", ")", ")", "{", "heat", ".", "addLatLng", "(", "lli", ")", ";", "}", "}", "markers", "[", "data", ".", "name", "]", "=", "marker", ";", "layers", "[", "lay", "]", ".", "addLayer", "(", "marker", ")", ";", "if", "(", "(", "data", ".", "hdg", "!=", "null", ")", "&&", "(", "data", ".", "bearing", "==", "null", ")", ")", "{", "data", ".", "bearing", "=", "data", ".", "hdg", ";", "delete", "data", ".", "hdg", ";", "}", "if", "(", "data", ".", "bearing", "!=", "null", ")", "{", "// if there is a heading", "if", "(", "data", ".", "speed", "!=", "null", ")", "{", "data", ".", "length", "=", "parseFloat", "(", "data", ".", "speed", "||", "\"0\"", ")", "*", "50", ";", "}", "// and a speed", "if", "(", "data", ".", "length", "!=", "null", ")", "{", "if", "(", "polygons", "[", "data", ".", "name", "]", "!=", "null", ")", "{", "map", ".", "removeLayer", "(", "polygons", "[", "data", ".", "name", "]", ")", ";", "}", "var", "x", "=", "ll", ".", "lng", "*", "1", ";", "// X coordinate", "var", "y", "=", "ll", ".", "lat", "*", "1", ";", "// Y coordinate", "var", "ll1", "=", "ll", ";", "var", "angle", "=", "parseFloat", "(", "data", ".", "bearing", ")", ";", "var", "lengthAsDegrees", "=", "parseFloat", "(", "data", ".", "length", "||", "\"0\"", ")", "/", "110540", ";", "// metres in a degree..ish", "var", "polygon", "=", "null", ";", "if", "(", "data", ".", "accuracy", "!=", "null", ")", "{", "data", ".", "accuracy", "=", "Number", "(", "data", ".", "accuracy", ")", ";", "var", "y2", "=", "y", "+", "Math", ".", "sin", "(", "(", "90", "-", "angle", "+", "data", ".", "accuracy", ")", "/", "180", "*", "Math", ".", "PI", ")", "*", "lengthAsDegrees", "*", "Math", ".", "cos", "(", "y", "/", "180", "*", "Math", ".", "PI", ")", ";", "var", "x2", "=", "x", "+", "Math", ".", "cos", "(", "(", "90", "-", "angle", "+", "data", ".", "accuracy", ")", "/", "180", "*", "Math", ".", "PI", ")", "*", "lengthAsDegrees", ";", "var", "ll2", "=", "new", "L", ".", "LatLng", "(", "y2", ",", "x2", ")", ";", "var", "y3", "=", "y", "+", "Math", ".", "sin", "(", "(", "90", "-", "angle", "-", "data", ".", "accuracy", ")", "/", "180", "*", "Math", ".", "PI", ")", "*", "lengthAsDegrees", "*", "Math", ".", "cos", "(", "y", "/", "180", "*", "Math", ".", "PI", ")", ";", "var", "x3", "=", "x", "+", "Math", ".", "cos", "(", "(", "90", "-", "angle", "-", "data", ".", "accuracy", ")", "/", "180", "*", "Math", ".", "PI", ")", "*", "lengthAsDegrees", ";", "var", "ll3", "=", "new", "L", ".", "LatLng", "(", "y3", ",", "x3", ")", ";", "polygon", "=", "L", ".", "polygon", "(", "[", "ll1", ",", "ll2", ",", "ll3", "]", ",", "{", "weight", ":", "2", ",", "color", ":", "llc", "||", "'#f30'", ",", "fillOpacity", ":", "0.06", ",", "clickable", ":", "false", "}", ")", ";", "}", "else", "{", "var", "ya", "=", "y", "+", "Math", ".", "sin", "(", "(", "90", "-", "angle", ")", "/", "180", "*", "Math", ".", "PI", ")", "*", "lengthAsDegrees", "*", "Math", ".", "cos", "(", "y", "/", "180", "*", "Math", ".", "PI", ")", ";", "var", "xa", "=", "x", "+", "Math", ".", "cos", "(", "(", "90", "-", "angle", ")", "/", "180", "*", "Math", ".", "PI", ")", "*", "lengthAsDegrees", ";", "var", "lla", "=", "new", "L", ".", "LatLng", "(", "ya", ",", "xa", ")", ";", "polygon", "=", "L", ".", "polygon", "(", "[", "ll1", ",", "lla", "]", ",", "{", "weight", ":", "2", ",", "color", ":", "llc", "||", "'#f30'", ",", "clickable", ":", "false", "}", ")", ";", "}", "if", "(", "typeof", "layers", "[", "lay", "]", ".", "getVisibleParent", "===", "'function'", ")", "{", "var", "vis", "=", "layers", "[", "lay", "]", ".", "getVisibleParent", "(", "marker", ")", ";", "if", "(", "(", "polygon", "!==", "null", ")", "&&", "(", "vis", "!==", "null", ")", "&&", "(", "!", "vis", ".", "hasOwnProperty", "(", "\"lay\"", ")", ")", ")", "{", "polygon", ".", "setStyle", "(", "{", "opacity", ":", "0", "}", ")", ";", "}", "}", "polygons", "[", "data", ".", "name", "]", "=", "polygon", ";", "polygons", "[", "data", ".", "name", "]", ".", "lay", "=", "lay", ";", "layers", "[", "lay", "]", ".", "addLayer", "(", "polygon", ")", ";", "}", "}", "if", "(", "panit", ")", "{", "map", ".", "setView", "(", "ll", ",", "map", ".", "getZoom", "(", ")", ")", ";", "}", "if", "(", "p", "===", "true", ")", "{", "marker", ".", "openPopup", "(", ")", ";", "}", "}", "}" ]
the MAIN add something to map function
[ "the", "MAIN", "add", "something", "to", "map", "function" ]
94aa812ed2c63d02205c29e3e367815229f441f6
https://github.com/dceejay/RedMap/blob/94aa812ed2c63d02205c29e3e367815229f441f6/worldmap/worldmap.js#L883-L1455
10,989
dceejay/RedMap
worldmap/worldmap.js
doGeojson
function doGeojson(g) { console.log("GEOJSON",g); if (!basemaps["geojson"]) { var opt = { style: function(feature) { var st = { stroke:true, color:"#910000", weight:2, fill:true, fillColor:"#910000", fillOpacity:0.3 }; if (feature.hasOwnProperty("properties")) { console.log("GPROPS", feature.properties) } if (feature.hasOwnProperty("style")) { console.log("GSTYLE", feature.style) } return st; } } opt.onEachFeature = function (f,l) { if (f.properties) { l.bindPopup('<pre>'+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>'); } } overlays["geojson"] = L.geoJson(g,opt); layercontrol.addOverlay(overlays["geojson"],"geojson"); } overlays["geojson"].addData(g); }
javascript
function doGeojson(g) { console.log("GEOJSON",g); if (!basemaps["geojson"]) { var opt = { style: function(feature) { var st = { stroke:true, color:"#910000", weight:2, fill:true, fillColor:"#910000", fillOpacity:0.3 }; if (feature.hasOwnProperty("properties")) { console.log("GPROPS", feature.properties) } if (feature.hasOwnProperty("style")) { console.log("GSTYLE", feature.style) } return st; } } opt.onEachFeature = function (f,l) { if (f.properties) { l.bindPopup('<pre>'+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>'); } } overlays["geojson"] = L.geoJson(g,opt); layercontrol.addOverlay(overlays["geojson"],"geojson"); } overlays["geojson"].addData(g); }
[ "function", "doGeojson", "(", "g", ")", "{", "console", ".", "log", "(", "\"GEOJSON\"", ",", "g", ")", ";", "if", "(", "!", "basemaps", "[", "\"geojson\"", "]", ")", "{", "var", "opt", "=", "{", "style", ":", "function", "(", "feature", ")", "{", "var", "st", "=", "{", "stroke", ":", "true", ",", "color", ":", "\"#910000\"", ",", "weight", ":", "2", ",", "fill", ":", "true", ",", "fillColor", ":", "\"#910000\"", ",", "fillOpacity", ":", "0.3", "}", ";", "if", "(", "feature", ".", "hasOwnProperty", "(", "\"properties\"", ")", ")", "{", "console", ".", "log", "(", "\"GPROPS\"", ",", "feature", ".", "properties", ")", "}", "if", "(", "feature", ".", "hasOwnProperty", "(", "\"style\"", ")", ")", "{", "console", ".", "log", "(", "\"GSTYLE\"", ",", "feature", ".", "style", ")", "}", "return", "st", ";", "}", "}", "opt", ".", "onEachFeature", "=", "function", "(", "f", ",", "l", ")", "{", "if", "(", "f", ".", "properties", ")", "{", "l", ".", "bindPopup", "(", "'<pre>'", "+", "JSON", ".", "stringify", "(", "f", ".", "properties", ",", "null", ",", "' '", ")", ".", "replace", "(", "/", "[\\{\\}\"]", "/", "g", ",", "''", ")", "+", "'</pre>'", ")", ";", "}", "}", "overlays", "[", "\"geojson\"", "]", "=", "L", ".", "geoJson", "(", "g", ",", "opt", ")", ";", "layercontrol", ".", "addOverlay", "(", "overlays", "[", "\"geojson\"", "]", ",", "\"geojson\"", ")", ";", "}", "overlays", "[", "\"geojson\"", "]", ".", "addData", "(", "g", ")", ";", "}" ]
handle any incoming GEOJSON directly - may style badly
[ "handle", "any", "incoming", "GEOJSON", "directly", "-", "may", "style", "badly" ]
94aa812ed2c63d02205c29e3e367815229f441f6
https://github.com/dceejay/RedMap/blob/94aa812ed2c63d02205c29e3e367815229f441f6/worldmap/worldmap.js#L1868-L1889
10,990
dceejay/RedMap
worldmap/leaflet/easy-button.js
function(newState){ // when called with no args, it's a getter if (arguments.length === 0) { return this._currentState.stateName; } // activate by name if(typeof newState == 'string'){ this._activateStateNamed(newState); // activate by index } else if (typeof newState == 'number'){ this._activateState(this._states[newState]); } return this; }
javascript
function(newState){ // when called with no args, it's a getter if (arguments.length === 0) { return this._currentState.stateName; } // activate by name if(typeof newState == 'string'){ this._activateStateNamed(newState); // activate by index } else if (typeof newState == 'number'){ this._activateState(this._states[newState]); } return this; }
[ "function", "(", "newState", ")", "{", "// when called with no args, it's a getter", "if", "(", "arguments", ".", "length", "===", "0", ")", "{", "return", "this", ".", "_currentState", ".", "stateName", ";", "}", "// activate by name", "if", "(", "typeof", "newState", "==", "'string'", ")", "{", "this", ".", "_activateStateNamed", "(", "newState", ")", ";", "// activate by index", "}", "else", "if", "(", "typeof", "newState", "==", "'number'", ")", "{", "this", ".", "_activateState", "(", "this", ".", "_states", "[", "newState", "]", ")", ";", "}", "return", "this", ";", "}" ]
populated on init
[ "populated", "on", "init" ]
94aa812ed2c63d02205c29e3e367815229f441f6
https://github.com/dceejay/RedMap/blob/94aa812ed2c63d02205c29e3e367815229f441f6/worldmap/leaflet/easy-button.js#L219-L238
10,991
dceejay/RedMap
worldmap/leaflet/easy-button.js
State
function State(template, easyButton){ this.title = template.title; this.stateName = template.stateName ? template.stateName : 'unnamed-state'; // build the wrapper this.icon = L.DomUtil.create('span', ''); L.DomUtil.addClass(this.icon, 'button-state state-' + this.stateName.replace(/(^\s*|\s*$)/g,'')); this.icon.innerHTML = buildIcon(template.icon); this.onClick = L.Util.bind(template.onClick?template.onClick:function(){}, easyButton); }
javascript
function State(template, easyButton){ this.title = template.title; this.stateName = template.stateName ? template.stateName : 'unnamed-state'; // build the wrapper this.icon = L.DomUtil.create('span', ''); L.DomUtil.addClass(this.icon, 'button-state state-' + this.stateName.replace(/(^\s*|\s*$)/g,'')); this.icon.innerHTML = buildIcon(template.icon); this.onClick = L.Util.bind(template.onClick?template.onClick:function(){}, easyButton); }
[ "function", "State", "(", "template", ",", "easyButton", ")", "{", "this", ".", "title", "=", "template", ".", "title", ";", "this", ".", "stateName", "=", "template", ".", "stateName", "?", "template", ".", "stateName", ":", "'unnamed-state'", ";", "// build the wrapper", "this", ".", "icon", "=", "L", ".", "DomUtil", ".", "create", "(", "'span'", ",", "''", ")", ";", "L", ".", "DomUtil", ".", "addClass", "(", "this", ".", "icon", ",", "'button-state state-'", "+", "this", ".", "stateName", ".", "replace", "(", "/", "(^\\s*|\\s*$)", "/", "g", ",", "''", ")", ")", ";", "this", ".", "icon", ".", "innerHTML", "=", "buildIcon", "(", "template", ".", "icon", ")", ";", "this", ".", "onClick", "=", "L", ".", "Util", ".", "bind", "(", "template", ".", "onClick", "?", "template", ".", "onClick", ":", "function", "(", ")", "{", "}", ",", "easyButton", ")", ";", "}" ]
constructor for states so only curated states end up getting called
[ "constructor", "for", "states", "so", "only", "curated", "states", "end", "up", "getting", "called" ]
94aa812ed2c63d02205c29e3e367815229f441f6
https://github.com/dceejay/RedMap/blob/94aa812ed2c63d02205c29e3e367815229f441f6/worldmap/leaflet/easy-button.js#L331-L342
10,992
webpack-contrib/sass-loader
lib/webpackImporter.js
webpackImporter
function webpackImporter(resourcePath, resolve, addNormalizedDependency) { function dirContextFrom(fileContext) { return path.dirname( // The first file is 'stdin' when we're using the data option fileContext === 'stdin' ? resourcePath : fileContext ); } // eslint-disable-next-line no-shadow function startResolving(dir, importsToResolve) { return importsToResolve.length === 0 ? Promise.reject() : resolve(dir, importsToResolve[0]).then( (resolvedFile) => { // Add the resolvedFilename as dependency. Although we're also using stats.includedFiles, this might come // in handy when an error occurs. In this case, we don't get stats.includedFiles from node-sass. addNormalizedDependency(resolvedFile); return { // By removing the CSS file extension, we trigger node-sass to include the CSS file instead of just linking it. file: resolvedFile.replace(matchCss, ''), }; }, () => startResolving(dir, tail(importsToResolve)) ); } return (url, prev, done) => { startResolving(dirContextFrom(prev), importsToResolve(url)) // Catch all resolving errors, return the original file and pass responsibility back to other custom importers .catch(() => { return { file: url, }; }) .then(done); }; }
javascript
function webpackImporter(resourcePath, resolve, addNormalizedDependency) { function dirContextFrom(fileContext) { return path.dirname( // The first file is 'stdin' when we're using the data option fileContext === 'stdin' ? resourcePath : fileContext ); } // eslint-disable-next-line no-shadow function startResolving(dir, importsToResolve) { return importsToResolve.length === 0 ? Promise.reject() : resolve(dir, importsToResolve[0]).then( (resolvedFile) => { // Add the resolvedFilename as dependency. Although we're also using stats.includedFiles, this might come // in handy when an error occurs. In this case, we don't get stats.includedFiles from node-sass. addNormalizedDependency(resolvedFile); return { // By removing the CSS file extension, we trigger node-sass to include the CSS file instead of just linking it. file: resolvedFile.replace(matchCss, ''), }; }, () => startResolving(dir, tail(importsToResolve)) ); } return (url, prev, done) => { startResolving(dirContextFrom(prev), importsToResolve(url)) // Catch all resolving errors, return the original file and pass responsibility back to other custom importers .catch(() => { return { file: url, }; }) .then(done); }; }
[ "function", "webpackImporter", "(", "resourcePath", ",", "resolve", ",", "addNormalizedDependency", ")", "{", "function", "dirContextFrom", "(", "fileContext", ")", "{", "return", "path", ".", "dirname", "(", "// The first file is 'stdin' when we're using the data option", "fileContext", "===", "'stdin'", "?", "resourcePath", ":", "fileContext", ")", ";", "}", "// eslint-disable-next-line no-shadow", "function", "startResolving", "(", "dir", ",", "importsToResolve", ")", "{", "return", "importsToResolve", ".", "length", "===", "0", "?", "Promise", ".", "reject", "(", ")", ":", "resolve", "(", "dir", ",", "importsToResolve", "[", "0", "]", ")", ".", "then", "(", "(", "resolvedFile", ")", "=>", "{", "// Add the resolvedFilename as dependency. Although we're also using stats.includedFiles, this might come", "// in handy when an error occurs. In this case, we don't get stats.includedFiles from node-sass.", "addNormalizedDependency", "(", "resolvedFile", ")", ";", "return", "{", "// By removing the CSS file extension, we trigger node-sass to include the CSS file instead of just linking it.", "file", ":", "resolvedFile", ".", "replace", "(", "matchCss", ",", "''", ")", ",", "}", ";", "}", ",", "(", ")", "=>", "startResolving", "(", "dir", ",", "tail", "(", "importsToResolve", ")", ")", ")", ";", "}", "return", "(", "url", ",", "prev", ",", "done", ")", "=>", "{", "startResolving", "(", "dirContextFrom", "(", "prev", ")", ",", "importsToResolve", "(", "url", ")", ")", "// Catch all resolving errors, return the original file and pass responsibility back to other custom importers", ".", "catch", "(", "(", ")", "=>", "{", "return", "{", "file", ":", "url", ",", "}", ";", "}", ")", ".", "then", "(", "done", ")", ";", "}", ";", "}" ]
Returns an importer that uses webpack's resolving algorithm. It's important that the returned function has the correct number of arguments (based on whether the call is sync or async) because otherwise node-sass doesn't exit. @param {string} resourcePath @param {PromisedResolve} resolve @param {Function<string>} addNormalizedDependency @returns {Importer}
[ "Returns", "an", "importer", "that", "uses", "webpack", "s", "resolving", "algorithm", "." ]
e279f2a129eee0bd0b624b5acd498f23a81ee35e
https://github.com/webpack-contrib/sass-loader/blob/e279f2a129eee0bd0b624b5acd498f23a81ee35e/lib/webpackImporter.js#L38-L74
10,993
webpack-contrib/sass-loader
lib/proxyCustomImporters.js
proxyCustomImporters
function proxyCustomImporters(importer, resourcePath) { return [].concat(importer).map( // eslint-disable-next-line no-shadow (importer) => function customImporter() { return importer.apply( this, // eslint-disable-next-line prefer-rest-params Array.from(arguments).map((arg, i) => i === 1 && arg === 'stdin' ? resourcePath : arg ) ); } ); }
javascript
function proxyCustomImporters(importer, resourcePath) { return [].concat(importer).map( // eslint-disable-next-line no-shadow (importer) => function customImporter() { return importer.apply( this, // eslint-disable-next-line prefer-rest-params Array.from(arguments).map((arg, i) => i === 1 && arg === 'stdin' ? resourcePath : arg ) ); } ); }
[ "function", "proxyCustomImporters", "(", "importer", ",", "resourcePath", ")", "{", "return", "[", "]", ".", "concat", "(", "importer", ")", ".", "map", "(", "// eslint-disable-next-line no-shadow", "(", "importer", ")", "=>", "function", "customImporter", "(", ")", "{", "return", "importer", ".", "apply", "(", "this", ",", "// eslint-disable-next-line prefer-rest-params", "Array", ".", "from", "(", "arguments", ")", ".", "map", "(", "(", "arg", ",", "i", ")", "=>", "i", "===", "1", "&&", "arg", "===", "'stdin'", "?", "resourcePath", ":", "arg", ")", ")", ";", "}", ")", ";", "}" ]
Creates new custom importers that use the given `resourcePath` if libsass calls the custom importer with `prev` being 'stdin'. Why do we need this? We have to use the `data` option of node-sass in order to compile our sass because the `resourcePath` might not be an actual file on disk. When using the `data` option, libsass uses the string 'stdin' instead of a filename. We have to fix this behavior in order to provide a consistent experience to the webpack user. @param {Function|Array<Function>} importer @param {string} resourcePath @returns {Array<Function>}
[ "Creates", "new", "custom", "importers", "that", "use", "the", "given", "resourcePath", "if", "libsass", "calls", "the", "custom", "importer", "with", "prev", "being", "stdin", "." ]
e279f2a129eee0bd0b624b5acd498f23a81ee35e
https://github.com/webpack-contrib/sass-loader/blob/e279f2a129eee0bd0b624b5acd498f23a81ee35e/lib/proxyCustomImporters.js#L17-L31
10,994
webpack-contrib/sass-loader
lib/normalizeOptions.js
normalizeOptions
function normalizeOptions(loaderContext, content, webpackImporter) { const options = cloneDeep(utils.getOptions(loaderContext)) || {}; const { resourcePath } = loaderContext; // allow opt.functions to be configured WRT loaderContext if (typeof options.functions === 'function') { options.functions = options.functions(loaderContext); } let { data } = options; if (typeof options.data === 'function') { data = options.data(loaderContext); } options.data = data ? data + os.EOL + content : content; // opt.outputStyle if (!options.outputStyle && loaderContext.minimize) { options.outputStyle = 'compressed'; } // opt.sourceMap // Not using the `this.sourceMap` flag because css source maps are different // @see https://github.com/webpack/css-loader/pull/40 if (options.sourceMap) { // Deliberately overriding the sourceMap option here. // node-sass won't produce source maps if the data option is used and options.sourceMap is not a string. // In case it is a string, options.sourceMap should be a path where the source map is written. // But since we're using the data option, the source map will not actually be written, but // all paths in sourceMap.sources will be relative to that path. // Pretty complicated... :( options.sourceMap = path.join(process.cwd(), '/sass.map'); if ('sourceMapRoot' in options === false) { options.sourceMapRoot = process.cwd(); } if ('omitSourceMapUrl' in options === false) { // The source map url doesn't make sense because we don't know the output path // The css-loader will handle that for us options.omitSourceMapUrl = true; } if ('sourceMapContents' in options === false) { // If sourceMapContents option is not set, set it to true otherwise maps will be empty/null // when exported by webpack-extract-text-plugin. options.sourceMapContents = true; } } // indentedSyntax is a boolean flag. const ext = path.extname(resourcePath); // If we are compiling sass and indentedSyntax isn't set, automatically set it. if ( ext && ext.toLowerCase() === '.sass' && 'indentedSyntax' in options === false ) { options.indentedSyntax = true; } else { options.indentedSyntax = Boolean(options.indentedSyntax); } // Allow passing custom importers to `node-sass`. Accepts `Function` or an array of `Function`s. options.importer = options.importer ? proxyCustomImporters(options.importer, resourcePath) : []; options.importer.push(webpackImporter); // `node-sass` uses `includePaths` to resolve `@import` paths. Append the currently processed file. options.includePaths = options.includePaths || []; options.includePaths.push(path.dirname(resourcePath)); return options; }
javascript
function normalizeOptions(loaderContext, content, webpackImporter) { const options = cloneDeep(utils.getOptions(loaderContext)) || {}; const { resourcePath } = loaderContext; // allow opt.functions to be configured WRT loaderContext if (typeof options.functions === 'function') { options.functions = options.functions(loaderContext); } let { data } = options; if (typeof options.data === 'function') { data = options.data(loaderContext); } options.data = data ? data + os.EOL + content : content; // opt.outputStyle if (!options.outputStyle && loaderContext.minimize) { options.outputStyle = 'compressed'; } // opt.sourceMap // Not using the `this.sourceMap` flag because css source maps are different // @see https://github.com/webpack/css-loader/pull/40 if (options.sourceMap) { // Deliberately overriding the sourceMap option here. // node-sass won't produce source maps if the data option is used and options.sourceMap is not a string. // In case it is a string, options.sourceMap should be a path where the source map is written. // But since we're using the data option, the source map will not actually be written, but // all paths in sourceMap.sources will be relative to that path. // Pretty complicated... :( options.sourceMap = path.join(process.cwd(), '/sass.map'); if ('sourceMapRoot' in options === false) { options.sourceMapRoot = process.cwd(); } if ('omitSourceMapUrl' in options === false) { // The source map url doesn't make sense because we don't know the output path // The css-loader will handle that for us options.omitSourceMapUrl = true; } if ('sourceMapContents' in options === false) { // If sourceMapContents option is not set, set it to true otherwise maps will be empty/null // when exported by webpack-extract-text-plugin. options.sourceMapContents = true; } } // indentedSyntax is a boolean flag. const ext = path.extname(resourcePath); // If we are compiling sass and indentedSyntax isn't set, automatically set it. if ( ext && ext.toLowerCase() === '.sass' && 'indentedSyntax' in options === false ) { options.indentedSyntax = true; } else { options.indentedSyntax = Boolean(options.indentedSyntax); } // Allow passing custom importers to `node-sass`. Accepts `Function` or an array of `Function`s. options.importer = options.importer ? proxyCustomImporters(options.importer, resourcePath) : []; options.importer.push(webpackImporter); // `node-sass` uses `includePaths` to resolve `@import` paths. Append the currently processed file. options.includePaths = options.includePaths || []; options.includePaths.push(path.dirname(resourcePath)); return options; }
[ "function", "normalizeOptions", "(", "loaderContext", ",", "content", ",", "webpackImporter", ")", "{", "const", "options", "=", "cloneDeep", "(", "utils", ".", "getOptions", "(", "loaderContext", ")", ")", "||", "{", "}", ";", "const", "{", "resourcePath", "}", "=", "loaderContext", ";", "// allow opt.functions to be configured WRT loaderContext", "if", "(", "typeof", "options", ".", "functions", "===", "'function'", ")", "{", "options", ".", "functions", "=", "options", ".", "functions", "(", "loaderContext", ")", ";", "}", "let", "{", "data", "}", "=", "options", ";", "if", "(", "typeof", "options", ".", "data", "===", "'function'", ")", "{", "data", "=", "options", ".", "data", "(", "loaderContext", ")", ";", "}", "options", ".", "data", "=", "data", "?", "data", "+", "os", ".", "EOL", "+", "content", ":", "content", ";", "// opt.outputStyle", "if", "(", "!", "options", ".", "outputStyle", "&&", "loaderContext", ".", "minimize", ")", "{", "options", ".", "outputStyle", "=", "'compressed'", ";", "}", "// opt.sourceMap", "// Not using the `this.sourceMap` flag because css source maps are different", "// @see https://github.com/webpack/css-loader/pull/40", "if", "(", "options", ".", "sourceMap", ")", "{", "// Deliberately overriding the sourceMap option here.", "// node-sass won't produce source maps if the data option is used and options.sourceMap is not a string.", "// In case it is a string, options.sourceMap should be a path where the source map is written.", "// But since we're using the data option, the source map will not actually be written, but", "// all paths in sourceMap.sources will be relative to that path.", "// Pretty complicated... :(", "options", ".", "sourceMap", "=", "path", ".", "join", "(", "process", ".", "cwd", "(", ")", ",", "'/sass.map'", ")", ";", "if", "(", "'sourceMapRoot'", "in", "options", "===", "false", ")", "{", "options", ".", "sourceMapRoot", "=", "process", ".", "cwd", "(", ")", ";", "}", "if", "(", "'omitSourceMapUrl'", "in", "options", "===", "false", ")", "{", "// The source map url doesn't make sense because we don't know the output path", "// The css-loader will handle that for us", "options", ".", "omitSourceMapUrl", "=", "true", ";", "}", "if", "(", "'sourceMapContents'", "in", "options", "===", "false", ")", "{", "// If sourceMapContents option is not set, set it to true otherwise maps will be empty/null", "// when exported by webpack-extract-text-plugin.", "options", ".", "sourceMapContents", "=", "true", ";", "}", "}", "// indentedSyntax is a boolean flag.", "const", "ext", "=", "path", ".", "extname", "(", "resourcePath", ")", ";", "// If we are compiling sass and indentedSyntax isn't set, automatically set it.", "if", "(", "ext", "&&", "ext", ".", "toLowerCase", "(", ")", "===", "'.sass'", "&&", "'indentedSyntax'", "in", "options", "===", "false", ")", "{", "options", ".", "indentedSyntax", "=", "true", ";", "}", "else", "{", "options", ".", "indentedSyntax", "=", "Boolean", "(", "options", ".", "indentedSyntax", ")", ";", "}", "// Allow passing custom importers to `node-sass`. Accepts `Function` or an array of `Function`s.", "options", ".", "importer", "=", "options", ".", "importer", "?", "proxyCustomImporters", "(", "options", ".", "importer", ",", "resourcePath", ")", ":", "[", "]", ";", "options", ".", "importer", ".", "push", "(", "webpackImporter", ")", ";", "// `node-sass` uses `includePaths` to resolve `@import` paths. Append the currently processed file.", "options", ".", "includePaths", "=", "options", ".", "includePaths", "||", "[", "]", ";", "options", ".", "includePaths", ".", "push", "(", "path", ".", "dirname", "(", "resourcePath", ")", ")", ";", "return", "options", ";", "}" ]
Derives the sass options from the loader context and normalizes its values with sane defaults. Please note: If loaderContext.query is an options object, it will be re-used across multiple invocations. That's why we must not modify the object directly. @param {LoaderContext} loaderContext @param {string} content @param {Function} webpackImporter @returns {Object}
[ "Derives", "the", "sass", "options", "from", "the", "loader", "context", "and", "normalizes", "its", "values", "with", "sane", "defaults", "." ]
e279f2a129eee0bd0b624b5acd498f23a81ee35e
https://github.com/webpack-contrib/sass-loader/blob/e279f2a129eee0bd0b624b5acd498f23a81ee35e/lib/normalizeOptions.js#L22-L95
10,995
webpack-contrib/sass-loader
lib/importsToResolve.js
importsToResolve
function importsToResolve(url) { const request = utils.urlToRequest(url); // Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot. // @see https://github.com/webpack-contrib/sass-loader/issues/167 const ext = path.extname(request); if (matchModuleImport.test(url)) { return [request, url]; } // libsass' import algorithm works like this: // In case there is a file extension... // - If the file is a CSS-file, do not include it all, but just link it via @import url(). // - The exact file name must match (no auto-resolving of '_'-modules). if (ext === '.css') { return []; } if (ext === '.scss' || ext === '.sass') { return [request, url]; } // In case there is no file extension... // - Prefer modules starting with '_'. // - File extension precedence: .scss, .sass, .css. const basename = path.basename(request); if (basename.charAt(0) === '_') { return [`${request}.scss`, `${request}.sass`, `${request}.css`, url]; } const dirname = path.dirname(request); return [ `${dirname}/_${basename}.scss`, `${dirname}/_${basename}.sass`, `${dirname}/_${basename}.css`, `${request}.scss`, `${request}.sass`, `${request}.css`, url, ]; }
javascript
function importsToResolve(url) { const request = utils.urlToRequest(url); // Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot. // @see https://github.com/webpack-contrib/sass-loader/issues/167 const ext = path.extname(request); if (matchModuleImport.test(url)) { return [request, url]; } // libsass' import algorithm works like this: // In case there is a file extension... // - If the file is a CSS-file, do not include it all, but just link it via @import url(). // - The exact file name must match (no auto-resolving of '_'-modules). if (ext === '.css') { return []; } if (ext === '.scss' || ext === '.sass') { return [request, url]; } // In case there is no file extension... // - Prefer modules starting with '_'. // - File extension precedence: .scss, .sass, .css. const basename = path.basename(request); if (basename.charAt(0) === '_') { return [`${request}.scss`, `${request}.sass`, `${request}.css`, url]; } const dirname = path.dirname(request); return [ `${dirname}/_${basename}.scss`, `${dirname}/_${basename}.sass`, `${dirname}/_${basename}.css`, `${request}.scss`, `${request}.sass`, `${request}.css`, url, ]; }
[ "function", "importsToResolve", "(", "url", ")", "{", "const", "request", "=", "utils", ".", "urlToRequest", "(", "url", ")", ";", "// Keep in mind: ext can also be something like '.datepicker' when the true extension is omitted and the filename contains a dot.", "// @see https://github.com/webpack-contrib/sass-loader/issues/167", "const", "ext", "=", "path", ".", "extname", "(", "request", ")", ";", "if", "(", "matchModuleImport", ".", "test", "(", "url", ")", ")", "{", "return", "[", "request", ",", "url", "]", ";", "}", "// libsass' import algorithm works like this:", "// In case there is a file extension...", "// - If the file is a CSS-file, do not include it all, but just link it via @import url().", "// - The exact file name must match (no auto-resolving of '_'-modules).", "if", "(", "ext", "===", "'.css'", ")", "{", "return", "[", "]", ";", "}", "if", "(", "ext", "===", "'.scss'", "||", "ext", "===", "'.sass'", ")", "{", "return", "[", "request", ",", "url", "]", ";", "}", "// In case there is no file extension...", "// - Prefer modules starting with '_'.", "// - File extension precedence: .scss, .sass, .css.", "const", "basename", "=", "path", ".", "basename", "(", "request", ")", ";", "if", "(", "basename", ".", "charAt", "(", "0", ")", "===", "'_'", ")", "{", "return", "[", "`", "${", "request", "}", "`", ",", "`", "${", "request", "}", "`", ",", "`", "${", "request", "}", "`", ",", "url", "]", ";", "}", "const", "dirname", "=", "path", ".", "dirname", "(", "request", ")", ";", "return", "[", "`", "${", "dirname", "}", "${", "basename", "}", "`", ",", "`", "${", "dirname", "}", "${", "basename", "}", "`", ",", "`", "${", "dirname", "}", "${", "basename", "}", "`", ",", "`", "${", "request", "}", "`", ",", "`", "${", "request", "}", "`", ",", "`", "${", "request", "}", "`", ",", "url", ",", "]", ";", "}" ]
When libsass tries to resolve an import, it uses a special algorithm. Since the sass-loader uses webpack to resolve the modules, we need to simulate that algorithm. This function returns an array of import paths to try. The last entry in the array is always the original url to enable straight-forward webpack.config aliases. @param {string} url @returns {Array<string>}
[ "When", "libsass", "tries", "to", "resolve", "an", "import", "it", "uses", "a", "special", "algorithm", ".", "Since", "the", "sass", "-", "loader", "uses", "webpack", "to", "resolve", "the", "modules", "we", "need", "to", "simulate", "that", "algorithm", ".", "This", "function", "returns", "an", "array", "of", "import", "paths", "to", "try", ".", "The", "last", "entry", "in", "the", "array", "is", "always", "the", "original", "url", "to", "enable", "straight", "-", "forward", "webpack", ".", "config", "aliases", "." ]
e279f2a129eee0bd0b624b5acd498f23a81ee35e
https://github.com/webpack-contrib/sass-loader/blob/e279f2a129eee0bd0b624b5acd498f23a81ee35e/lib/importsToResolve.js#L18-L60
10,996
webpack-contrib/sass-loader
lib/loader.js
sassLoader
function sassLoader(content) { const callback = this.async(); const isSync = typeof callback !== 'function'; const self = this; const { resourcePath } = this; function addNormalizedDependency(file) { // node-sass returns POSIX paths self.dependency(path.normalize(file)); } if (isSync) { throw new Error( 'Synchronous compilation is not supported anymore. See https://github.com/webpack-contrib/sass-loader/issues/333' ); } let resolve = pify(this.resolve); // Supported since v4.27.0 if (this.getResolve) { resolve = this.getResolve({ mainFields: ['sass', 'main'], extensions: ['.scss', '.sass', '.css'], }); } const options = normalizeOptions( this, content, webpackImporter(resourcePath, resolve, addNormalizedDependency) ); // Skip empty files, otherwise it will stop webpack, see issue #21 if (options.data.trim() === '') { callback(null, ''); return; } const render = getRenderFuncFromSassImpl( // eslint-disable-next-line import/no-extraneous-dependencies, global-require options.implementation || getDefaultSassImpl() ); render(options, (err, result) => { if (err) { formatSassError(err, this.resourcePath); if (err.file) { this.dependency(err.file); } callback(err); return; } if (result.map && result.map !== '{}') { // eslint-disable-next-line no-param-reassign result.map = JSON.parse(result.map); // result.map.file is an optional property that provides the output filename. // Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it. // eslint-disable-next-line no-param-reassign delete result.map.file; // One of the sources is 'stdin' according to dart-sass/node-sass because we've used the data input. // Now let's override that value with the correct relative path. // Since we specified options.sourceMap = path.join(process.cwd(), "/sass.map"); in normalizeOptions, // we know that this path is relative to process.cwd(). This is how node-sass works. // eslint-disable-next-line no-param-reassign const stdinIndex = result.map.sources.findIndex( (source) => source.indexOf('stdin') !== -1 ); if (stdinIndex !== -1) { result.map.sources[stdinIndex] = path.relative( process.cwd(), resourcePath ); } // node-sass returns POSIX paths, that's why we need to transform them back to native paths. // This fixes an error on windows where the source-map module cannot resolve the source maps. // @see https://github.com/webpack-contrib/sass-loader/issues/366#issuecomment-279460722 // eslint-disable-next-line no-param-reassign result.map.sourceRoot = path.normalize(result.map.sourceRoot); // eslint-disable-next-line no-param-reassign result.map.sources = result.map.sources.map(path.normalize); } else { // eslint-disable-next-line no-param-reassign result.map = null; } result.stats.includedFiles.forEach(addNormalizedDependency); callback(null, result.css.toString(), result.map); }); }
javascript
function sassLoader(content) { const callback = this.async(); const isSync = typeof callback !== 'function'; const self = this; const { resourcePath } = this; function addNormalizedDependency(file) { // node-sass returns POSIX paths self.dependency(path.normalize(file)); } if (isSync) { throw new Error( 'Synchronous compilation is not supported anymore. See https://github.com/webpack-contrib/sass-loader/issues/333' ); } let resolve = pify(this.resolve); // Supported since v4.27.0 if (this.getResolve) { resolve = this.getResolve({ mainFields: ['sass', 'main'], extensions: ['.scss', '.sass', '.css'], }); } const options = normalizeOptions( this, content, webpackImporter(resourcePath, resolve, addNormalizedDependency) ); // Skip empty files, otherwise it will stop webpack, see issue #21 if (options.data.trim() === '') { callback(null, ''); return; } const render = getRenderFuncFromSassImpl( // eslint-disable-next-line import/no-extraneous-dependencies, global-require options.implementation || getDefaultSassImpl() ); render(options, (err, result) => { if (err) { formatSassError(err, this.resourcePath); if (err.file) { this.dependency(err.file); } callback(err); return; } if (result.map && result.map !== '{}') { // eslint-disable-next-line no-param-reassign result.map = JSON.parse(result.map); // result.map.file is an optional property that provides the output filename. // Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it. // eslint-disable-next-line no-param-reassign delete result.map.file; // One of the sources is 'stdin' according to dart-sass/node-sass because we've used the data input. // Now let's override that value with the correct relative path. // Since we specified options.sourceMap = path.join(process.cwd(), "/sass.map"); in normalizeOptions, // we know that this path is relative to process.cwd(). This is how node-sass works. // eslint-disable-next-line no-param-reassign const stdinIndex = result.map.sources.findIndex( (source) => source.indexOf('stdin') !== -1 ); if (stdinIndex !== -1) { result.map.sources[stdinIndex] = path.relative( process.cwd(), resourcePath ); } // node-sass returns POSIX paths, that's why we need to transform them back to native paths. // This fixes an error on windows where the source-map module cannot resolve the source maps. // @see https://github.com/webpack-contrib/sass-loader/issues/366#issuecomment-279460722 // eslint-disable-next-line no-param-reassign result.map.sourceRoot = path.normalize(result.map.sourceRoot); // eslint-disable-next-line no-param-reassign result.map.sources = result.map.sources.map(path.normalize); } else { // eslint-disable-next-line no-param-reassign result.map = null; } result.stats.includedFiles.forEach(addNormalizedDependency); callback(null, result.css.toString(), result.map); }); }
[ "function", "sassLoader", "(", "content", ")", "{", "const", "callback", "=", "this", ".", "async", "(", ")", ";", "const", "isSync", "=", "typeof", "callback", "!==", "'function'", ";", "const", "self", "=", "this", ";", "const", "{", "resourcePath", "}", "=", "this", ";", "function", "addNormalizedDependency", "(", "file", ")", "{", "// node-sass returns POSIX paths", "self", ".", "dependency", "(", "path", ".", "normalize", "(", "file", ")", ")", ";", "}", "if", "(", "isSync", ")", "{", "throw", "new", "Error", "(", "'Synchronous compilation is not supported anymore. See https://github.com/webpack-contrib/sass-loader/issues/333'", ")", ";", "}", "let", "resolve", "=", "pify", "(", "this", ".", "resolve", ")", ";", "// Supported since v4.27.0", "if", "(", "this", ".", "getResolve", ")", "{", "resolve", "=", "this", ".", "getResolve", "(", "{", "mainFields", ":", "[", "'sass'", ",", "'main'", "]", ",", "extensions", ":", "[", "'.scss'", ",", "'.sass'", ",", "'.css'", "]", ",", "}", ")", ";", "}", "const", "options", "=", "normalizeOptions", "(", "this", ",", "content", ",", "webpackImporter", "(", "resourcePath", ",", "resolve", ",", "addNormalizedDependency", ")", ")", ";", "// Skip empty files, otherwise it will stop webpack, see issue #21", "if", "(", "options", ".", "data", ".", "trim", "(", ")", "===", "''", ")", "{", "callback", "(", "null", ",", "''", ")", ";", "return", ";", "}", "const", "render", "=", "getRenderFuncFromSassImpl", "(", "// eslint-disable-next-line import/no-extraneous-dependencies, global-require", "options", ".", "implementation", "||", "getDefaultSassImpl", "(", ")", ")", ";", "render", "(", "options", ",", "(", "err", ",", "result", ")", "=>", "{", "if", "(", "err", ")", "{", "formatSassError", "(", "err", ",", "this", ".", "resourcePath", ")", ";", "if", "(", "err", ".", "file", ")", "{", "this", ".", "dependency", "(", "err", ".", "file", ")", ";", "}", "callback", "(", "err", ")", ";", "return", ";", "}", "if", "(", "result", ".", "map", "&&", "result", ".", "map", "!==", "'{}'", ")", "{", "// eslint-disable-next-line no-param-reassign", "result", ".", "map", "=", "JSON", ".", "parse", "(", "result", ".", "map", ")", ";", "// result.map.file is an optional property that provides the output filename.", "// Since we don't know the final filename in the webpack build chain yet, it makes no sense to have it.", "// eslint-disable-next-line no-param-reassign", "delete", "result", ".", "map", ".", "file", ";", "// One of the sources is 'stdin' according to dart-sass/node-sass because we've used the data input.", "// Now let's override that value with the correct relative path.", "// Since we specified options.sourceMap = path.join(process.cwd(), \"/sass.map\"); in normalizeOptions,", "// we know that this path is relative to process.cwd(). This is how node-sass works.", "// eslint-disable-next-line no-param-reassign", "const", "stdinIndex", "=", "result", ".", "map", ".", "sources", ".", "findIndex", "(", "(", "source", ")", "=>", "source", ".", "indexOf", "(", "'stdin'", ")", "!==", "-", "1", ")", ";", "if", "(", "stdinIndex", "!==", "-", "1", ")", "{", "result", ".", "map", ".", "sources", "[", "stdinIndex", "]", "=", "path", ".", "relative", "(", "process", ".", "cwd", "(", ")", ",", "resourcePath", ")", ";", "}", "// node-sass returns POSIX paths, that's why we need to transform them back to native paths.", "// This fixes an error on windows where the source-map module cannot resolve the source maps.", "// @see https://github.com/webpack-contrib/sass-loader/issues/366#issuecomment-279460722", "// eslint-disable-next-line no-param-reassign", "result", ".", "map", ".", "sourceRoot", "=", "path", ".", "normalize", "(", "result", ".", "map", ".", "sourceRoot", ")", ";", "// eslint-disable-next-line no-param-reassign", "result", ".", "map", ".", "sources", "=", "result", ".", "map", ".", "sources", ".", "map", "(", "path", ".", "normalize", ")", ";", "}", "else", "{", "// eslint-disable-next-line no-param-reassign", "result", ".", "map", "=", "null", ";", "}", "result", ".", "stats", ".", "includedFiles", ".", "forEach", "(", "addNormalizedDependency", ")", ";", "callback", "(", "null", ",", "result", ".", "css", ".", "toString", "(", ")", ",", "result", ".", "map", ")", ";", "}", ")", ";", "}" ]
The sass-loader makes node-sass and dart-sass available to webpack modules. @this {LoaderContext} @param {string} content
[ "The", "sass", "-", "loader", "makes", "node", "-", "sass", "and", "dart", "-", "sass", "available", "to", "webpack", "modules", "." ]
e279f2a129eee0bd0b624b5acd498f23a81ee35e
https://github.com/webpack-contrib/sass-loader/blob/e279f2a129eee0bd0b624b5acd498f23a81ee35e/lib/loader.js#L21-L115
10,997
webpack-contrib/sass-loader
lib/loader.js
getRenderFuncFromSassImpl
function getRenderFuncFromSassImpl(module) { const { info } = module; const components = info.split('\t'); if (components.length < 2) { throw new Error(`Unknown Sass implementation "${info}".`); } const [implementation, version] = components; if (!semver.valid(version)) { throw new Error(`Invalid Sass version "${version}".`); } if (implementation === 'dart-sass') { if (!semver.satisfies(version, '^1.3.0')) { throw new Error( `Dart Sass version ${version} is incompatible with ^1.3.0.` ); } return module.render.bind(module); } else if (implementation === 'node-sass') { if (!semver.satisfies(version, '^4.0.0')) { throw new Error( `Node Sass version ${version} is incompatible with ^4.0.0.` ); } // There is an issue with node-sass when async custom importers are used // See https://github.com/sass/node-sass/issues/857#issuecomment-93594360 // We need to use a job queue to make sure that one thread is always available to the UV lib if (nodeSassJobQueue === null) { const threadPoolSize = Number(process.env.UV_THREADPOOL_SIZE || 4); nodeSassJobQueue = async.queue( module.render.bind(module), threadPoolSize - 1 ); } return nodeSassJobQueue.push.bind(nodeSassJobQueue); } throw new Error(`Unknown Sass implementation "${implementation}".`); }
javascript
function getRenderFuncFromSassImpl(module) { const { info } = module; const components = info.split('\t'); if (components.length < 2) { throw new Error(`Unknown Sass implementation "${info}".`); } const [implementation, version] = components; if (!semver.valid(version)) { throw new Error(`Invalid Sass version "${version}".`); } if (implementation === 'dart-sass') { if (!semver.satisfies(version, '^1.3.0')) { throw new Error( `Dart Sass version ${version} is incompatible with ^1.3.0.` ); } return module.render.bind(module); } else if (implementation === 'node-sass') { if (!semver.satisfies(version, '^4.0.0')) { throw new Error( `Node Sass version ${version} is incompatible with ^4.0.0.` ); } // There is an issue with node-sass when async custom importers are used // See https://github.com/sass/node-sass/issues/857#issuecomment-93594360 // We need to use a job queue to make sure that one thread is always available to the UV lib if (nodeSassJobQueue === null) { const threadPoolSize = Number(process.env.UV_THREADPOOL_SIZE || 4); nodeSassJobQueue = async.queue( module.render.bind(module), threadPoolSize - 1 ); } return nodeSassJobQueue.push.bind(nodeSassJobQueue); } throw new Error(`Unknown Sass implementation "${implementation}".`); }
[ "function", "getRenderFuncFromSassImpl", "(", "module", ")", "{", "const", "{", "info", "}", "=", "module", ";", "const", "components", "=", "info", ".", "split", "(", "'\\t'", ")", ";", "if", "(", "components", ".", "length", "<", "2", ")", "{", "throw", "new", "Error", "(", "`", "${", "info", "}", "`", ")", ";", "}", "const", "[", "implementation", ",", "version", "]", "=", "components", ";", "if", "(", "!", "semver", ".", "valid", "(", "version", ")", ")", "{", "throw", "new", "Error", "(", "`", "${", "version", "}", "`", ")", ";", "}", "if", "(", "implementation", "===", "'dart-sass'", ")", "{", "if", "(", "!", "semver", ".", "satisfies", "(", "version", ",", "'^1.3.0'", ")", ")", "{", "throw", "new", "Error", "(", "`", "${", "version", "}", "`", ")", ";", "}", "return", "module", ".", "render", ".", "bind", "(", "module", ")", ";", "}", "else", "if", "(", "implementation", "===", "'node-sass'", ")", "{", "if", "(", "!", "semver", ".", "satisfies", "(", "version", ",", "'^4.0.0'", ")", ")", "{", "throw", "new", "Error", "(", "`", "${", "version", "}", "`", ")", ";", "}", "// There is an issue with node-sass when async custom importers are used", "// See https://github.com/sass/node-sass/issues/857#issuecomment-93594360", "// We need to use a job queue to make sure that one thread is always available to the UV lib", "if", "(", "nodeSassJobQueue", "===", "null", ")", "{", "const", "threadPoolSize", "=", "Number", "(", "process", ".", "env", ".", "UV_THREADPOOL_SIZE", "||", "4", ")", ";", "nodeSassJobQueue", "=", "async", ".", "queue", "(", "module", ".", "render", ".", "bind", "(", "module", ")", ",", "threadPoolSize", "-", "1", ")", ";", "}", "return", "nodeSassJobQueue", ".", "push", ".", "bind", "(", "nodeSassJobQueue", ")", ";", "}", "throw", "new", "Error", "(", "`", "${", "implementation", "}", "`", ")", ";", "}" ]
Verifies that the implementation and version of Sass is supported by this loader. @param {Object} module @returns {Function}
[ "Verifies", "that", "the", "implementation", "and", "version", "of", "Sass", "is", "supported", "by", "this", "loader", "." ]
e279f2a129eee0bd0b624b5acd498f23a81ee35e
https://github.com/webpack-contrib/sass-loader/blob/e279f2a129eee0bd0b624b5acd498f23a81ee35e/lib/loader.js#L123-L168
10,998
node-apn/node-apn
lib/token.js
token
function token(input) { let token; if (typeof input === "string") { token = input; } else if (Buffer.isBuffer(input)) { token = input.toString("hex"); } token = token.replace(/[^0-9a-f]/gi, ""); if (token.length === 0) { throw new Error("Token has invalid length"); } return token; }
javascript
function token(input) { let token; if (typeof input === "string") { token = input; } else if (Buffer.isBuffer(input)) { token = input.toString("hex"); } token = token.replace(/[^0-9a-f]/gi, ""); if (token.length === 0) { throw new Error("Token has invalid length"); } return token; }
[ "function", "token", "(", "input", ")", "{", "let", "token", ";", "if", "(", "typeof", "input", "===", "\"string\"", ")", "{", "token", "=", "input", ";", "}", "else", "if", "(", "Buffer", ".", "isBuffer", "(", "input", ")", ")", "{", "token", "=", "input", ".", "toString", "(", "\"hex\"", ")", ";", "}", "token", "=", "token", ".", "replace", "(", "/", "[^0-9a-f]", "/", "gi", ",", "\"\"", ")", ";", "if", "(", "token", ".", "length", "===", "0", ")", "{", "throw", "new", "Error", "(", "\"Token has invalid length\"", ")", ";", "}", "return", "token", ";", "}" ]
Validates a device token Will convert to string and removes invalid characters as required.
[ "Validates", "a", "device", "token" ]
e72259fae1a749ce0a7bc146d7ea89dcd9593fca
https://github.com/node-apn/node-apn/blob/e72259fae1a749ce0a7bc146d7ea89dcd9593fca/lib/token.js#L7-L23
10,999
node-apn/node-apn
lib/notification/index.js
Notification
function Notification (payload) { this.encoding = "utf8"; this.payload = {}; this.compiled = false; this.aps = {}; this.expiry = 0; this.priority = 10; if (payload) { for(let key in payload) { if (payload.hasOwnProperty(key)) { this[key] = payload[key]; } } } }
javascript
function Notification (payload) { this.encoding = "utf8"; this.payload = {}; this.compiled = false; this.aps = {}; this.expiry = 0; this.priority = 10; if (payload) { for(let key in payload) { if (payload.hasOwnProperty(key)) { this[key] = payload[key]; } } } }
[ "function", "Notification", "(", "payload", ")", "{", "this", ".", "encoding", "=", "\"utf8\"", ";", "this", ".", "payload", "=", "{", "}", ";", "this", ".", "compiled", "=", "false", ";", "this", ".", "aps", "=", "{", "}", ";", "this", ".", "expiry", "=", "0", ";", "this", ".", "priority", "=", "10", ";", "if", "(", "payload", ")", "{", "for", "(", "let", "key", "in", "payload", ")", "{", "if", "(", "payload", ".", "hasOwnProperty", "(", "key", ")", ")", "{", "this", "[", "key", "]", "=", "payload", "[", "key", "]", ";", "}", "}", "}", "}" ]
Create a notification @constructor
[ "Create", "a", "notification" ]
e72259fae1a749ce0a7bc146d7ea89dcd9593fca
https://github.com/node-apn/node-apn/blob/e72259fae1a749ce0a7bc146d7ea89dcd9593fca/lib/notification/index.js#L6-L22