code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
function dollyIn( dollyScale ) { if ( scope.object instanceof THREE.PerspectiveCamera ) { scale /= dollyScale; } else if ( scope.object instanceof THREE.OrthographicCamera ) { scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom * dollyScale ) ); scope.object.updatePr...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
dollyIn
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function dollyOut( dollyScale ) { if ( scope.object instanceof THREE.PerspectiveCamera ) { scale *= dollyScale; } else if ( scope.object instanceof THREE.OrthographicCamera ) { scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / dollyScale ) ); scope.object.updateP...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
dollyOut
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleMouseDownRotate( event ) { //console.log( 'handleMouseDownRotate' ); rotateStart.set( event.clientX, event.clientY ); }
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleMouseDownRotate
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleMouseDownDolly( event ) { //console.log( 'handleMouseDownDolly' ); dollyStart.set( event.clientX, event.clientY ); }
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleMouseDownDolly
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleMouseDownPan( event ) { //console.log( 'handleMouseDownPan' ); panStart.set( event.clientX, event.clientY ); }
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleMouseDownPan
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleMouseMoveRotate( event ) { //console.log( 'handleMouseMoveRotate' ); rotateEnd.set( event.clientX, event.clientY ); rotateDelta.subVectors( rotateEnd, rotateStart ); var element = scope.domElement === document ? scope.domElement.body : scope.domElement; // rotating across whole screen goes ...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleMouseMoveRotate
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleMouseMoveDolly( event ) { //console.log( 'handleMouseMoveDolly' ); dollyEnd.set( event.clientX, event.clientY ); dollyDelta.subVectors( dollyEnd, dollyStart ); if ( dollyDelta.y > 0 ) { dollyIn( getZoomScale() ); } else if ( dollyDelta.y < 0 ) { dollyOut( getZoomScale() ); } ...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleMouseMoveDolly
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleMouseMovePan( event ) { //console.log( 'handleMouseMovePan' ); panEnd.set( event.clientX, event.clientY ); panDelta.subVectors( panEnd, panStart ); pan( panDelta.x, panDelta.y ); panStart.copy( panEnd ); scope.update(); }
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleMouseMovePan
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleMouseUp( event ) { //console.log( 'handleMouseUp' ); }
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleMouseUp
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleMouseWheel( event ) { //console.log( 'handleMouseWheel' ); var delta = 0; if ( event.wheelDelta !== undefined ) { // WebKit / Opera / Explorer 9 delta = event.wheelDelta; } else if ( event.detail !== undefined ) { // Firefox delta = - event.detail; } if ( delta > 0 ) { ...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleMouseWheel
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleKeyDown( event ) { //console.log( 'handleKeyDown' ); switch ( event.keyCode ) { case scope.keys.UP: pan( 0, scope.keyPanSpeed ); scope.update(); break; case scope.keys.BOTTOM: pan( 0, - scope.keyPanSpeed ); scope.update(); break; case scope.keys.LEFT: pan( sc...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleKeyDown
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleTouchStartRotate( event ) { //console.log( 'handleTouchStartRotate' ); rotateStart.set( event.pointers[ 0 ].pageX, event.pointers[ 0 ].pageY ); }
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleTouchStartRotate
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleTouchStartDolly( event ) { //console.log( 'handleTouchStartDolly' ); var dx = event.pointers[ 0 ].pageX - event.pointers[ 1 ].pageX; var dy = event.pointers[ 0 ].pageY - event.pointers[ 1 ].pageY; var distance = Math.sqrt( dx * dx + dy * dy ); dollyStart.set( 0, distance ); }
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleTouchStartDolly
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleTouchStartPan( event ) { //console.log( 'handleTouchStartPan' ); panStart.set( event.deltaX, event.deltaY ); }
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleTouchStartPan
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleTouchMoveRotate( event ) { //console.log( 'handleTouchMoveRotate' ); rotateEnd.set( event.pointers[ 0 ].pageX, event.pointers[ 0 ].pageY ); rotateDelta.subVectors( rotateEnd, rotateStart ); var element = scope.domElement === document ? scope.domElement.body : scope.domElement; // rotating a...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleTouchMoveRotate
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleTouchMoveDolly( event ) { //console.log( 'handleTouchMoveDolly' ); var dx = event.pointers[ 0 ].pageX - event.pointers[ 1 ].pageX; var dy = event.pointers[ 0 ].pageY - event.pointers[ 1 ].pageY; var distance = Math.sqrt( dx * dx + dy * dy ); dollyEnd.set( 0, distance ); dollyDelta.subVec...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleTouchMoveDolly
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleTouchMovePan( event ) { //console.log( 'handleTouchMovePan' ); panEnd.set( event.deltaX, event.deltaY ); panDelta.subVectors( panEnd, panStart ); pan( panDelta.x, panDelta.y ); panStart.copy( panEnd ); scope.update(); }
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleTouchMovePan
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function handleTouchEnd( event ) { //console.log( 'handleTouchEnd' ); }
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
handleTouchEnd
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function onMouseDown( event ) { if ( scope.enabled === false ) return; event.preventDefault(); if ( event.button === scope.mouseButtons.ORBIT ) { if ( scope.enableRotate === false ) return; handleMouseDownRotate( event ); state = STATE.ROTATE; } else if ( event.button === scope.mouseButtons.ZOOM...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
onMouseDown
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function onMouseMove( event ) { if ( scope.enabled === false ) return; event.preventDefault(); if ( state === STATE.ROTATE ) { if ( scope.enableRotate === false ) return; handleMouseMoveRotate( event ); } else if ( state === STATE.DOLLY ) { if ( scope.enableZoom === false ) return; handleMou...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
onMouseMove
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function onMouseUp( event ) { if ( scope.enabled === false ) return; handleMouseUp( event ); document.removeEventListener( 'mousemove', onMouseMove, false ); document.removeEventListener( 'mouseup', onMouseUp, false ); document.removeEventListener( 'mouseout', onMouseUp, false ); scope.dispatchEvent( en...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
onMouseUp
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function onMouseWheel( event ) { if ( scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE ) return; event.preventDefault(); event.stopPropagation(); handleMouseWheel( event ); scope.dispatchEvent( startEvent ); // not sure why these are here... scope.dispatchEvent( endEvent ); ...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
onMouseWheel
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function onKeyDown( event ) { if ( scope.enabled === false || scope.enableKeys === false || scope.enablePan === false ) return; handleKeyDown( event ); }
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
onKeyDown
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function onTouchStart( event ) { if ( scope.enabled === false ) return; switch ( event.touches.length ) { case 1: // one-fingered touch: rotate if ( scope.enableRotate === false ) return; handleTouchStartRotate( event ); state = STATE.TOUCH_ROTATE; break; case 2: // two-fingered touch:...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
onTouchStart
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function onTouchMove( event ) { if ( scope.enabled === false ) return; event.preventDefault(); event.stopPropagation(); switch ( event.touches.length ) { case 1: // one-fingered touch: rotate if ( scope.enableRotate === false ) return; if ( state !== STATE.TOUCH_ROTATE ) return; // is this neede...
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
onTouchMove
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function onTouchEnd( event ) { if ( scope.enabled === false ) return; handleTouchEnd( event ); scope.dispatchEvent( endEvent ); state = STATE.NONE; }
@author qiao / https://github.com/qiao @author mrdoob / http://mrdoob.com @author alteredq / http://alteredqualia.com/ @author WestLangley / http://github.com/WestLangley @author erich666 / http://erichaines.com
onTouchEnd
javascript
UDST/vizicities
src/vendor/OrbitControls.js
https://github.com/UDST/vizicities/blob/master/src/vendor/OrbitControls.js
BSD-3-Clause
function validTest( name ) { var filter = config.filter, run = false; if ( !filter ) { return true; } var not = filter.charAt( 0 ) === "!"; if ( not ) { filter = filter.slice( 1 ); } if ( name.indexOf( filter ) !== -1 ) { return !not; } if ( not ) { run = true; } return run; }
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
validTest
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function sourceFromStacktrace() { try { throw new Error(); } catch ( e ) { if (e.stacktrace) { // Opera return e.stacktrace.split("\n")[6]; } else if (e.stack) { // Firefox, Chrome return e.stack.split("\n")[4]; } else if (e.sourceURL) { // Safari, PhantomJS // TODO sourceURL points at the '...
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
sourceFromStacktrace
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function escapeHtml(s) { if (!s) { return ""; } s = s + ""; return s.replace(/[\&"<>\\]/g, function(s) { switch(s) { case "&": return "&amp;"; case "\\": return "\\\\"; case '"': return '\"'; case "<": return "&lt;"; case ">": return "&gt;"; default: return s; } }); }
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
escapeHtml
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function synchronize( callback ) { config.queue.push( callback ); if ( config.autorun && !config.blocking ) { process(); } }
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
synchronize
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function process() { var start = (new Date()).getTime(); while ( config.queue.length && !config.blocking ) { if ( config.updateRate <= 0 || (((new Date()).getTime() - start) < config.updateRate) ) { config.queue.shift()(); } else { window.setTimeout( process, 13 ); break; } } if (!config.blocking &&...
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
process
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function saveGlobal() { config.pollution = []; if ( config.noglobals ) { for ( var key in window ) { config.pollution.push( key ); } } }
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
saveGlobal
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function checkPollution( name ) { var old = config.pollution; saveGlobal(); var newGlobals = diff( config.pollution, old ); if ( newGlobals.length > 0 ) { ok( false, "Introduced global variable(s): " + newGlobals.join(", ") ); } var deletedGlobals = diff( old, config.pollution ); if ( deletedGlobals.length >...
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
checkPollution
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function diff( a, b ) { var result = a.slice(); for ( var i = 0; i < result.length; i++ ) { for ( var j = 0; j < b.length; j++ ) { if ( result[i] === b[j] ) { result.splice(i, 1); i--; break; } } } return result; }
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
diff
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function fail(message, exception, callback) { if ( typeof console !== "undefined" && console.error && console.warn ) { console.error(message); console.error(exception); console.warn(callback.toString()); } else if ( window.opera && opera.postError ) { opera.postError(message, exception, callback.toString); ...
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
fail
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function extend(a, b) { for ( var prop in b ) { if ( b[prop] === undefined ) { delete a[prop]; } else { a[prop] = b[prop]; } } return a; }
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
extend
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function addEvent(elem, type, fn) { if ( elem.addEventListener ) { elem.addEventListener( type, fn, false ); } else if ( elem.attachEvent ) { elem.attachEvent( "on" + type, fn ); } else { fn(); } }
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
addEvent
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function id(name) { return !!(typeof document !== "undefined" && document && document.getElementById) && document.getElementById( name ); }
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
id
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function bindCallbacks(o, callbacks, args) { var prop = QUnit.objectType(o); if (prop) { if (QUnit.objectType(callbacks[prop]) === "function") { return callbacks[prop].apply(callbacks, args); } else { return callbacks[prop]; // or undefined } } }
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
bindCallbacks
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function useStrictEquality(b, a) { if (b instanceof a.constructor || a instanceof b.constructor) { // to catch short annotaion VS 'new' annotation of a // declaration // e.g. var i = 1; // var j = new Number(1); return a == b; } else { return a === b; } }
Trigger an event on an element. @example triggerEvent( document.body, "click" ); @param DOMElement elem @param String type
useStrictEquality
javascript
littke/inspiritas-bootstrap
bootstrap/js/tests/vendor/qunit.js
https://github.com/littke/inspiritas-bootstrap/blob/master/bootstrap/js/tests/vendor/qunit.js
Apache-2.0
function attribToHtml(str) { return str.replace(pr_amp, '&amp;') .replace(pr_lt, '&lt;') .replace(pr_gt, '&gt;') .replace(pr_quot, '&quot;'); }
like textToHtml but escapes double quotes to be attribute safe.
attribToHtml
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function textToHtml(str) { return str.replace(pr_amp, '&amp;') .replace(pr_lt, '&lt;') .replace(pr_gt, '&gt;'); }
escapest html special characters to html.
textToHtml
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function isRawContent(node) { return 'XMP' === node.tagName; }
is the given node's innerHTML normally unescaped?
isRawContent
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function isPreformatted(node, content) { // PRE means preformatted, and is a very common case, so don't create // unnecessary computed style objects. if ('PRE' === node.tagName) { return true; } if (!newlineRe.test(content)) { return true; } // Don't care var whitespace = ''; // For disconnecte...
Are newlines and adjacent spaces significant in the given node's innerHTML?
isPreformatted
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function normalizedHtml(node, out, opt_sortAttrs) { switch (node.nodeType) { case 1: // an element var name = node.tagName.toLowerCase(); out.push('<', name); var attrs = node.attributes; var n = attrs.length; if (n) { if (opt_sortAttrs) { var so...
Are newlines and adjacent spaces significant in the given node's innerHTML?
normalizedHtml
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function combinePrefixPatterns(regexs) { var capturedGroupIndex = 0; var needToFoldCase = false; var ignoreCase = false; for (var i = 0, n = regexs.length; i < n; ++i) { var regex = regexs[i]; if (regex.ignoreCase) { ignoreCase = true; } else if (/[a-z]/i.test(regex.source.rep...
Given a group of {@link RegExp}s, returns a {@code RegExp} that globally matches the union o the sets o strings matched d by the input RegExp. Since it matches globally, if the input strings have a start-of-input anchor (/^.../), it is ignored for the purposes of unioning. @param {Array.<RegExp>} regexs non multiline, ...
combinePrefixPatterns
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function decodeEscape(charsetPart) { if (charsetPart.charAt(0) !== '\\') { return charsetPart.charCodeAt(0); } switch (charsetPart.charAt(1)) { case 'b': return 8; case 't': return 9; case 'n': return 0xa; case 'v': return 0xb; case 'f': return 0xc; case 'r': ...
Given a group of {@link RegExp}s, returns a {@code RegExp} that globally matches the union o the sets o strings matched d by the input RegExp. Since it matches globally, if the input strings have a start-of-input anchor (/^.../), it is ignored for the purposes of unioning. @param {Array.<RegExp>} regexs non multiline, ...
decodeEscape
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function encodeEscape(charCode) { if (charCode < 0x20) { return (charCode < 0x10 ? '\\x0' : '\\x') + charCode.toString(16); } var ch = String.fromCharCode(charCode); if (ch === '\\' || ch === '-' || ch === '[' || ch === ']') { ch = '\\' + ch; } return ch; }
Given a group of {@link RegExp}s, returns a {@code RegExp} that globally matches the union o the sets o strings matched d by the input RegExp. Since it matches globally, if the input strings have a start-of-input anchor (/^.../), it is ignored for the purposes of unioning. @param {Array.<RegExp>} regexs non multiline, ...
encodeEscape
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function caseFoldCharset(charSet) { var charsetParts = charSet.substring(1, charSet.length - 1).match( new RegExp( '\\\\u[0-9A-Fa-f]{4}' + '|\\\\x[0-9A-Fa-f]{2}' + '|\\\\[0-3][0-7]{0,2}' + '|\\\\[0-7]{1,2}' + '|\\\\[\\s\\S]' ...
Given a group of {@link RegExp}s, returns a {@code RegExp} that globally matches the union o the sets o strings matched d by the input RegExp. Since it matches globally, if the input strings have a start-of-input anchor (/^.../), it is ignored for the purposes of unioning. @param {Array.<RegExp>} regexs non multiline, ...
caseFoldCharset
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function allowAnywhereFoldCaseAndRenumberGroups(regex) { // Split into character sets, escape sequences, punctuation strings // like ('(', '(?:', ')', '^'), and runs of characters that do not // include any of the above. var parts = regex.source.match( new RegExp( '(?:' ...
Given a group of {@link RegExp}s, returns a {@code RegExp} that globally matches the union o the sets o strings matched d by the input RegExp. Since it matches globally, if the input strings have a start-of-input anchor (/^.../), it is ignored for the purposes of unioning. @param {Array.<RegExp>} regexs non multiline, ...
allowAnywhereFoldCaseAndRenumberGroups
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function getInnerHtml(node) { // inner html is hopelessly broken in Safari 2.0.4 when the content is // an html description of well formed XML and the containing tag is a PRE // tag, so we detect that case and emulate innerHTML. if (null === PR_innerHtmlWorks) { var testNode = document.createEleme...
Given a group of {@link RegExp}s, returns a {@code RegExp} that globally matches the union o the sets o strings matched d by the input RegExp. Since it matches globally, if the input strings have a start-of-input anchor (/^.../), it is ignored for the purposes of unioning. @param {Array.<RegExp>} regexs non multiline, ...
getInnerHtml
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function makeTabExpander(tabWidth) { var SPACES = ' '; var charInLine = 0; return function (plainText) { // walk over each character looking for tabs and newlines. // On tabs, expand them. On newlines, reset charInLine. // Otherwise increment charInLine var out = nul...
returns a function that expand tabs to spaces. This function can be fed successive chunks of text, and will maintain its own internal state to keep track of how tabs are expanded. @return {function (string) : string} a function that takes plain text and return the text with tabs expanded. @private
makeTabExpander
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function extractTags(s) { // since the pattern has the 'g' modifier and defines no capturing groups, // this will return a list of all chunks which we then classify and wrap as // PR_Tokens var matches = s.match(pr_chunkPattern); var sourceBuf = []; var sourceBufLen = 0; var extractedTags = ...
split markup into chunks of html tags (style null) and plain text (style {@link #PR_PLAIN}), converting tags which are significant for tokenization (<br>) into their textual equivalent. @param {string} s html where whitespace is considered significant. @return {Object} source code and extracted tags. @private
extractTags
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function isNoCodeTag(tag) { return !!tag // First canonicalize the representation of attributes .replace(/\s(\w+)\s*=\s*(?:\"([^\"]*)\"|'([^\']*)'|(\S+))/g, ' $1="$2$3$4"') // Then look for the attribute we want. .match(/[cC][lL][aA][sS][sS]=\"[^\"]*\bnocode\b/); }
True if the given tag contains a class attribute with the nocode class.
isNoCodeTag
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function appendDecorations(basePos, sourceCode, langHandler, out) { if (!sourceCode) { return; } var job = { source: sourceCode, basePos: basePos }; langHandler(job); out.push.apply(out, job.decorations); }
Apply the given language handler to sourceCode and add the resulting decorations to out. @param {number} basePos the index of sourceCode within the chunk of source whose decorations are already present on out.
appendDecorations
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns) { var shortcuts = {}; var tokenizer; (function () { var allPatterns = shortcutStylePatterns.concat(fallthroughStylePatterns); var allRegexs = []; var regexKeys = {}; for (var i = 0, n = allPatterns.length; i ...
Given triples of [style, pattern, context] returns a lexing function, The lexing function interprets the patterns to find token boundaries and returns a decoration list of the form [index_0, style_0, index_1, style_1, ..., index_n, style_n] where index_n is an index into the sourceCode, and style_n is a style constant ...
createSimpleLexer
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
decorate = function (job) { var sourceCode = job.source, basePos = job.basePos; /** Even entries are positions in source in ascending order. Odd enties * are style markers (e.g., PR_COMMENT) that run from that position until * the end. * @type {Array.<number|string>} */ ...
Lexes job.source and produces an output array job.decorations of style classes preceded by the position at which they start in job.source in order. @param {Object} job an object like {@code source: {string} sourceText plain text, basePos: {int} position of job.source in the larger chunk of sourceCode. }
decorate
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function recombineTagsAndDecorations(job) { var sourceText = job.source; var extractedTags = job.extractedTags; var decorations = job.decorations; var numberLines = job.numberLines; var sourceNode = job.sourceNode; var html = []; // index past the last char in sourceText written to html ...
Breaks {@code job.source} around style boundaries in {@code job.decorations} while re-interleaving {@code job.extractedTags}, and leaves the result in {@code job.prettyPrintedHtml}. @param {Object} job like { source: {string} source as plain text, extractedTags: {Array.<number|string>} extractedTags chunks of raw...
recombineTagsAndDecorations
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function emitTextUpTo(sourceIdx) { if (sourceIdx > outputIdx) { if (openDecoration && openDecoration !== currentDecoration) { // Close the current decoration html.push('</span>'); openDecoration = null; } if (!openDecoration && currentDecoration) { o...
Breaks {@code job.source} around style boundaries in {@code job.decorations} while re-interleaving {@code job.extractedTags}, and leaves the result in {@code job.prettyPrintedHtml}. @param {Object} job like { source: {string} source as plain text, extractedTags: {Array.<number|string>} extractedTags chunks of raw...
emitTextUpTo
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function registerLangHandler(handler, fileExtensions) { for (var i = fileExtensions.length; --i >= 0;) { var ext = fileExtensions[i]; if (!langHandlerRegistry.hasOwnProperty(ext)) { langHandlerRegistry[ext] = handler; } else if ('console' in window) { console['warn']('cannot overri...
Register a language handler for the given file extensions. @param {function (Object)} handler a function from source code to a list of decorations. Takes a single argument job which describes the state of the computation. The single parameter has the form {@code { source: {string} as plain text...
registerLangHandler
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function langHandlerForExtension(extension, source) { if (!(extension && langHandlerRegistry.hasOwnProperty(extension))) { // Treat it as markup if the first non whitespace character is a < and // the last non-whitespace character is a >. extension = /^\s*</.test(source) ? 'default-marku...
Register a language handler for the given file extensions. @param {function (Object)} handler a function from source code to a list of decorations. Takes a single argument job which describes the state of the computation. The single parameter has the form {@code { source: {string} as plain text...
langHandlerForExtension
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function applyDecorator(job) { var sourceCodeHtml = job.sourceCodeHtml; var opt_langExtension = job.langExtension; // Prepopulate output in case processing fails with an exception. job.prettyPrintedHtml = sourceCodeHtml; try { // Extract tags, and convert the source code to plain text. ...
Register a language handler for the given file extensions. @param {function (Object)} handler a function from source code to a list of decorations. Takes a single argument job which describes the state of the computation. The single parameter has the form {@code { source: {string} as plain text...
applyDecorator
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function prettyPrintOne(sourceCodeHtml, opt_langExtension, opt_numberLines) { var job = { sourceCodeHtml: sourceCodeHtml, langExtension: opt_langExtension, numberLines: opt_numberLines }; applyDecorator(job); return job.prettyPrintedHtml; }
@param sourceCodeHtml {string} The HTML to pretty print. @param opt_langExtension {string} The language name to use. Typically, a filename extension like 'cpp' or 'java'. @param opt_numberLines {number|boolean} True to number lines, or the 1-indexed number of the first line in sourceCodeHtml.
prettyPrintOne
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function prettyPrint(opt_whenDone) { function byTagName(tn) { return document.getElementsByTagName(tn); } // fetch a list of nodes to rewrite var codeSegments = [byTagName('pre'), byTagName('code'), byTagName('xmp')]; var elements = []; for (var i = 0; i < codeSegments.length; ++i) { for (var ...
@param sourceCodeHtml {string} The HTML to pretty print. @param opt_langExtension {string} The language name to use. Typically, a filename extension like 'cpp' or 'java'. @param opt_numberLines {number|boolean} True to number lines, or the 1-indexed number of the first line in sourceCodeHtml.
prettyPrint
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function doWork() { var endTime = (window['PR_SHOULD_USE_CONTINUATION'] ? clock.now() + 250 /* ms */ : Infinity); for (; k < elements.length && clock.now() < endTime; k++) { var cs = elements[k]; if (cs.className && cs.className.indexOf('prettyprint'...
@param sourceCodeHtml {string} The HTML to pretty print. @param opt_langExtension {string} The language name to use. Typically, a filename extension like 'cpp' or 'java'. @param opt_numberLines {number|boolean} True to number lines, or the 1-indexed number of the first line in sourceCodeHtml.
doWork
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function replaceWithPrettyPrintedHtml() { var newContent = prettyPrintingJob.prettyPrintedHtml; if (!newContent) { return; } var cs = prettyPrintingJob.sourceNode; // push the prettified html back into the tag. if (!isRawContent(cs)) { // just replace the old html with the new ...
@param sourceCodeHtml {string} The HTML to pretty print. @param opt_langExtension {string} The language name to use. Typically, a filename extension like 'cpp' or 'java'. @param opt_numberLines {number|boolean} True to number lines, or the 1-indexed number of the first line in sourceCodeHtml.
replaceWithPrettyPrintedHtml
javascript
google/WebFundamentals
gae/scripts/prettify-bundle.js
https://github.com/google/WebFundamentals/blob/master/gae/scripts/prettify-bundle.js
Apache-2.0
function generateFeedsForEveryYear(files, options) { // Build RSS feed per year. // Check if we will build the full RSS feeds. if (!global.WF.options.buildRSS) { return; } const filesByYear = wfHelper.splitByYear(files); Object.keys(filesByYear) .filter((year) => year >= global.WF.minFeedDate) ...
Generates feeds for each year. The feed contains all content for that year with the <content> section stripped. @param {*} files @param {!Object} options
generateFeedsForEveryYear
javascript
google/WebFundamentals
gulp-tasks/build.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/build.js
Apache-2.0
function getCLAATFiles(srcPath) { let cmd = '../../../tools/claat update'; return new Promise(function(resolve, reject) { wfHelper.promisedExec(cmd, srcPath) .then(function() { let opts = { srcBase: srcPath, prefixBase: true, }; let files = glob.find('**/index.md', opts); ...
Update the files using the claat tool then return a list of files @param {string} srcPath Where to run the claat tool. @return {Promise} The promise with the list of all files updated.
getCLAATFiles
javascript
google/WebFundamentals
gulp-tasks/claat-export.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/claat-export.js
Apache-2.0
function exportAndUpdate(srcPath, destBase, flatten, bookPath, projPath) { return getCLAATFiles(srcPath) .then(function(files) { return Promise.all(files.map(function(file) { let srcFile = file; let srcImgPath = file.replace('index.md', 'img/'); let destDir = file.replace(srcPath, '').replace(...
Updates files, and copies them to the appropriate directory @param {string} srcPath The source directory to find the files. @param {string} destBase The destination to copy to. @param {Boolean} flatten Whether to flatten the files to one directory. @param {string} bookPath The location of the book.yaml file @param {st...
exportAndUpdate
javascript
google/WebFundamentals
gulp-tasks/claat-export.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/claat-export.js
Apache-2.0
function logMessage(level, filename, position, message, extra) { let logMsg = { filename: filename, position: position, message: message, extra: extra, }; let fileLoc = chalk.cyan(filename); level = level.toUpperCase(); if (position && position.line) { fileLoc += chalk.gray('#') + chalk.cy...
Logs a message to the console @param {string} level ERROR or WARNING, the level of the error @param {string} filename The file the issue occurred in @param {Object} position The line/column the error occurred on @param {string} message The message to be displayed @param {Object} extra Any extra information to show
logMessage
javascript
google/WebFundamentals
gulp-tasks/test.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/test.js
Apache-2.0
function logError(filename, position, message, extra) { if (global.WF.options.testWarnOnly) { logWarning(filename, position, message, extra); return; } logMessage('ERROR', filename, position, message, extra); }
Logs an ERROR message to the console @param {string} filename The file the issue occurred in @param {Object} position The line/column the error occurred on @param {string} message The message to be displayed @param {Object} extra Any extra information to show
logError
javascript
google/WebFundamentals
gulp-tasks/test.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/test.js
Apache-2.0
function logWarning(filename, position, message, extra) { logMessage('WARNING', filename, position, message, extra); }
Logs a WARNING message to the console @param {string} filename The file the issue occurred in @param {Object} position The line/column the error occurred on @param {string} message The message to be displayed @param {Object} extra Any extra information to show
logWarning
javascript
google/WebFundamentals
gulp-tasks/test.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/test.js
Apache-2.0
function printSummary() { const cFilesWithIssues = Object.keys(filesWithIssues).length; gutil.log(''); gutil.log('Test Completed.'); gutil.log('Files tested: ', chalk.cyan(filesTested)); gutil.log(' - with issues:', chalk.yellow(cFilesWithIssues)); gutil.log('Errors : ', chalk.red(allErrors.length)); gu...
Prints a summary of the test results
printSummary
javascript
google/WebFundamentals
gulp-tasks/test.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/test.js
Apache-2.0
function throwIfFailed() { if (allErrors.length >= 1 && !global.WF.options.testWarnOnly) { let errorMessage = `There were ${allErrors.length} errors.`; throw new Error(errorMessage); } }
Throws an exception if there are any test failures.
throwIfFailed
javascript
google/WebFundamentals
gulp-tasks/test.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/test.js
Apache-2.0
function readFile(filename) { try { let contents = fs.readFileSync(filename, 'utf8'); // Check if Byte order mark was included if (RE_BOM.test(contents)) { contents = contents.replace(RE_BOM, ''); const msg = 'File was saved as UTF-8+BOM, please save without BOM'; logWarning(filename, nu...
Reads a file from the file system. @param {string} filename The file to read. @return {string} The contents of the file, or NULL if it failed to read.
readFile
javascript
google/WebFundamentals
gulp-tasks/test.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/test.js
Apache-2.0
function parseJSON(filename, contents) { try { return JSON.parse(contents); } catch (ex) { const msg = `Unable to parse JSON: ${ex.message}`; logError(filename, null, msg, ex); } return null; }
Parses a JSON file Note: The returned promise always resolves, it will never reject. @param {string} filename The name of the file to be tested @param {string} contents The contents of the file to be tested @return {Object} The parsed JSON object
parseJSON
javascript
google/WebFundamentals
gulp-tasks/test.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/test.js
Apache-2.0
function parseYAML(filename, contents) { try { return jsYaml.safeLoad(contents); } catch (ex) { let msg = 'Unable to parse YAML'; if (ex.reason) { msg = ex.reason; } let position = ex.mark; if (position && position.line) { position.line++; } logError(filename, position, m...
Parses a YAML file Note: The returned promise always resolves, it will never reject. @param {string} filename The name of the file to be tested @param {string} contents The contents of the file to be tested @return {Object} The parsed YAML object
parseYAML
javascript
google/WebFundamentals
gulp-tasks/test.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/test.js
Apache-2.0
function getFiles() { gutil.log(' Searching for files...'); if (global.WF.options.testPath || global.WF.options.testAll) { return new Promise(function(resolve, reject) { let globs = ['./gulp-tasks/**/*', './gulpfile.js']; let opts = { prefixBase: true, filter: 'isFile', }; ...
Gets a list of all files to be tested. @return {Promise} The list of files
getFiles
javascript
google/WebFundamentals
gulp-tasks/test.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/test.js
Apache-2.0
function testFile(filename, opts) { const filenameObj = path.parse(filename.toLowerCase()); // Check if the file is an extension we skip if (EXTENSIONS_TO_SKIP.indexOf(filenameObj.ext) >= 0) { if (global.WF.options.verbose) { const msg = 'Skipped (extension).'; gutil.log(chalk.gray('SKIP:'), chal...
Tests & validates a file. Note: The returned promise always resolves, it will never reject. @param {string} filename The name of the file to be tested. @param {Object} opts Options for testing the file @return {Promise} A promise that resolves after the tests have completed.
testFile
javascript
google/WebFundamentals
gulp-tasks/test.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/test.js
Apache-2.0
function printTestResults(results) { if (!results) { return false; } if (Array.isArray(results) === false) { results = [results]; } results.forEach((result) => { const filename = result.filename; const position = result.position; const message = result.message; const extra = result.ext...
Temporary function to print results from refactored tests @param {Array} results The array of results. @return {Array} results as handed in.
printTestResults
javascript
google/WebFundamentals
gulp-tasks/test.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/test.js
Apache-2.0
function updateCodeLab(sourceFile, destFile, bookPath, projPath) { gutil.log(' ', 'Processing', sourceFile); let matches; let authorId; const metadataFile = sourceFile.replace('index.md', 'codelab.json'); const metadata = JSON.parse(fs.readFileSync(metadataFile)); if (metadata.wfProcessed === true) { gu...
Parses & normalizes a markdown file. @param {string} sourceFile Path the the file to read & normalize @param {string} destFile Path to write the normalized file @param {string} bookPath Path to the book.yaml file @param {string} projPath Path to the project.yaml file
updateCodeLab
javascript
google/WebFundamentals
gulp-tasks/wfCodeLabHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfCodeLabHelper.js
Apache-2.0
function getPhotoForContributor(key) { const localImagePath = path.join(PHOTO_PATH, key) + '.jpg'; try { const stat = fs.statSync(localImagePath); if (stat.isFile()) { return key; } } catch (ex) { // do nothing } gutil.log(' ', gutil.colors.red(key), MISSING_AVATAR); return 'no-photo'...
Parses & normalizes a markdown file. @param {string} key The key identifying the user @return {string} filename to use
getPhotoForContributor
javascript
google/WebFundamentals
gulp-tasks/wfContributors.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfContributors.js
Apache-2.0
function buildIncludes(contributors) { gutil.log(' ', 'Building include file for each contributor...'); const keys = Object.keys(contributors); keys.forEach(function(key) { let contributor = contributors[key]; contributor.id = key; contributor.photo = getPhotoForContributor(key); const dest = DEST...
Loop through each contributor and render include file for each person. @param {Array} contributors The list of contributors
buildIncludes
javascript
google/WebFundamentals
gulp-tasks/wfContributors.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfContributors.js
Apache-2.0
function buildIndex(contributors) { gutil.log(' ', 'Building index file of all contributors...'); const context = {contributors: contributors}; wfTemplateHelper.renderTemplate(TEMPLATE_LIST, context, DEST_LIST); }
Build the index file for all contributors. @param {Array} contributors The list of contributors.
buildIndex
javascript
google/WebFundamentals
gulp-tasks/wfContributors.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfContributors.js
Apache-2.0
function buildIndividualPages(contributors) { gutil.log(' ', 'Building individual pages of all contributors...'); const files = wfHelper.getFileList(global.WF.src.content, ['**/*.md']); const filesByAuthor = wfHelper.splitByAuthor(files); const keys = Object.keys(contributors); keys.forEach(function(key) { ...
Loop through each contributor and render individaul contribution index. @param {Array} contributors The list of contributors
buildIndividualPages
javascript
google/WebFundamentals
gulp-tasks/wfContributors.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfContributors.js
Apache-2.0
function getContributors() { gutil.log(' ', 'Reading contributors.yaml file...'); const yamlDoc = fs.readFileSync(CONTRIBUTORS_FILE, 'utf8'); return jsYaml.safeLoad(yamlDoc); }
Reads the contributors file and parses it from YAML to JSON. @return {Array} The list of contributors
getContributors
javascript
google/WebFundamentals
gulp-tasks/wfContributors.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfContributors.js
Apache-2.0
function buildAll() { const contributors = getContributors(); buildIncludes(contributors); buildIndex(contributors); buildIndividualPages(contributors); }
Build all of the necessary contributors files.
buildAll
javascript
google/WebFundamentals
gulp-tasks/wfContributors.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfContributors.js
Apache-2.0
function promisedExec(cmd, cwd) { return new Promise(function(resolve, reject) { const cmdLog = chalk.cyan(`$ ${cmd}`); gutil.log(' ', cmdLog); const execOptions = { cwd: cwd, maxBuffer: 1024 * 1024, }; exec(cmd, execOptions, function(err, stdOut, stdErr) { stdOut = stdOut.trim()...
Executes a shell command and returns the result in a promise. @param {string} cmd The command to run. @param {string} cwd The working directory to run the command in. @return {Promise} The promise that will be resolved on completion.
promisedExec
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0
function promisedRSync(src, dest) { gutil.log(' ', chalk.blue('rsync'), src, '->', dest); return new Promise(function(resolve, reject) { if (fs.existsSync(src) === false) { gutil.log(' ', chalk.red(src), 'doesn\'t exist.'); resolve(); } const rsync = new RSync() .source(src) .des...
Uses RSync to copy files from one directory to another. @param {string} src The source to copy. @param {string} dest The destination to copy to. @return {Promise} The promise that will be resolved on completion.
promisedRSync
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0
function genericComparator(a, b) { if (typeof a === 'string') { a = a.toLowerCase(); } if (typeof b === 'string') { b = b.toLowerCase(); } if (a > b) { return 1; } else if (a < b) { return -1; } return 0; }
Ascending sorting comparator for generic inputs Note: string comparison is case insenstitive @param {Object} a The first item to be compared. @param {Object} b The second item to be compared. @return {number} -1,0,1.
genericComparator
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0
function publishedComparator(aObj, bObj) { const aVal = aObj.datePublishedMoment; const bVal = bObj.datePublishedMoment; if (aVal.isBefore(bVal)) { return 1; } else if (aVal.isAfter(bVal)) { return -1; } else { return updatedComparator(aObj, bObj); } }
Descending sorting comparator for datePublishedMoment - if values are equal, it uses updatedComparator @param {Object} aObj The first object to be compared. @param {Object} bObj The second object to be compared. @return {number} -1,0,1.
publishedComparator
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0
function updatedComparator(aObj, bObj) { const aVal = aObj.dateUpdatedMoment; const bVal = bObj.dateUpdatedMoment; if (aVal.isBefore(bVal)) { return 1; } else if (aVal.isAfter(bVal)) { return -1; } else { return genericComparator(aObj.title, bObj.title); } }
Descending sorting comparator for dateUpdatedMoment - if values are equal, it uses the article title @param {Object} aObj The first object to be compared. @param {Object} bObj The second object to be compared. @return {number} -1,0,1.
updatedComparator
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0
function featuredComparator(aObj, bObj) { const aVal = aObj.dateFeaturedMoment; const bVal = bObj.dateFeaturedMoment; if (aVal.isBefore(bVal)) { return 1; } else if (aVal.isAfter(bVal)) { return -1; } else { return updatedComparator(aObj, bObj); } }
Descending sorting comparator for dateFeaturedMoment - if values are equal, it uses updatedComparator @param {Object} aObj The first object to be compared. @param {Object} bObj The second object to be compared. @return {number} -1,0,1.
featuredComparator
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0
function getRegEx(regEx, content, defaultResponse) { // eslint-disable-next-line no-console, max-len console.log(chalk.red('WARN:'), chalk.cyan('wfHelper.getRegEx'), 'is deprecated'); const result = content.match(regEx); if (result && result[1]) { return result[1]; } return defaultResponse; }
Gets the first regEx match on a string @deprecated Use wfRegEx.getMatch instead @param {RegEx} regEx The regex to test. @param {string} content The content to search. @param {string} [defaultResponse] The default response to provide. @return {string} The regex match.
getRegEx
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0
function readMetadataForFile(file) { const content = fs.readFileSync(file, 'utf8'); if (testHelper.isInclude(file, content)) { return null; } let description = wfRegEx.getMatch(wfRegEx.RE_SNIPPET, content); if (!description) { description = wfRegEx.getMatch(wfRegEx.RE_DESCRIPTION, content); } let ...
Reads the metadata from a markdown file @param {string} file The path to the file to read. @return {Object} the meta data of the file.
readMetadataForFile
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0
function getFileList(base, patterns) { let results = []; const opts = { srcBase: base, prefixBase: true, }; const files = glob.find(patterns, STD_EXCLUDES, opts); files.forEach(function(file) { const metaData = readMetadataForFile(file); if (metaData) { results.push(metaData); } })...
Gets a list of files that match a specific pattern @param {string} base The base path to look. @param {Array} patterns A list of glob patters to look for. @return {Array} A list of files along with their metadata.
getFileList
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0
function splitByYear(files) { let result = {}; files.forEach(function(file) { const year = file.datePublishedYear; if (!result[year]) { result[year] = []; } result[year].push(file); }); return result; }
Splits a list of files by year published @param {Array} files The array of files to split. @return {Object} A list of files split by year.
splitByYear
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0
function splitByMonth(files) { let result = []; files.forEach(function(file) { const month = parseInt(file.datePublishedMonth, 10); if (!result[month]) { result[month] = { title: moment.months()[month - 1], articles: [], }; } result[month].articles.push(file); }); ret...
Splits a list of files by month published @param {Array} files The array of files to split. @return {Array} A list of files split by month.
splitByMonth
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0
function splitByAuthor(files) { let result = {}; files.forEach(function(file) { let authors = file.authors || []; authors.forEach(function(author) { if (!result[author]) { result[author] = []; } result[author].push(file); }); }); return result; }
Splits a list of files by author @param {Array} files The array of files split. @return {Object} A list of files split by author.
splitByAuthor
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0
function dateFormatAtom(dt) { return dateFormatISO(dt); }
Formats a moment() object to: YYYY-MM-DDTHH:mm:ssZ Example: 2017-07-13T13:31:13Z Note: simply a shortcut to dateFormatISO @param {Object} dt The moment object to export. @return {string} YYYY-MM-DDTHH:mm:ssZ.
dateFormatAtom
javascript
google/WebFundamentals
gulp-tasks/wfHelper.js
https://github.com/google/WebFundamentals/blob/master/gulp-tasks/wfHelper.js
Apache-2.0