This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A "deeper" indented text effect with the :before and :after pseudo-elements. | |
*/ | |
html, body { | |
height: 100%; | |
} | |
body { | |
margin: 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* FPS Meter | |
* @author Victor N - www.vitim.us | |
* | |
* @param {function} callback Function that will display the fps rate | |
* @param {number} refreshRate Defines the frequency the fps will be updated in ms | |
* @returns {function} | |
*/ | |
function fpsMeter(callback, refreshRate){ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Hide the address bar - vitim.us */ | |
function hideAddressBar(){ | |
setTimeout(function(){ | |
if(scrollY) return; | |
scrollTo(scrollX, 1); | |
setTimeout(function() | |
if(scrollY==1) | |
scrollTo(scrollX, 0); | |
}, 1); | |
}, 1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Function that count occurrences of a substring in a string; | |
* @param {String} string The string | |
* @param {String} subString The sub string to search for | |
* @param {Boolean} [allowOverlapping] Optional. (Default:false) | |
* | |
* @author Vitim.us https://gist.github.com/victornpb/7736865/edit | |
* @see Unit Test https://jsfiddle.net/Victornpb/5axuh96u/ | |
* @see http://stackoverflow.com/questions/4009756/how-to-count-string-occurrence-in-string/7924240#7924240 | |
*/ | |
function occurrences(string, subString, allowOverlapping) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** format string | |
* format("Hello {0}! {1}-{2}.", "World", "foo", "bar") --> "Hello World! foo-bar." | |
*/ | |
function format(string, etc) { | |
var args = arguments; | |
return string.replace(/{(\d+)}/g, function(match, number) { | |
return typeof args[+number+1]!="undefined" ? args[+number+1] : match; | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//create element | |
function tag(tag, attributes, childs){ | |
function isArray(o) { | |
return Object.prototype.toString.call(o) === "[object Array]"; | |
} | |
function isElement(o) { | |
return !!(o && o.nodeType == 1); | |
} | |
function isTextNode(o) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add a event to a element; | |
* @param {Object} element Element or ID; | |
* @param {String} trigger Trigger to fire action eg:load,click,mouseover,etc; | |
* @param {Function} action A pointer to a function to be called on trigger; | |
*/ | |
function addEvent(element, trigger, action){ | |
if(typeof element==="string"){element=document.getElementById(element);} | |
if(element.addEventListener){ | |
element.addEventListener(trigger,action,false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Constructor that create a Loop object to run blocking loops, but allow | |
* it to be interrupted when requested to give a change to make DOM updates | |
* @author Victor B - www.vitim.us | |
*/ | |
function AsyncLoop(){ | |
this.loop; //called on every loop | |
this.onUpdate; //called when the loop is interrupted | |
this.onComplete; //called when the loop is finished | |
this.requestInterruptToUpdateDOM = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* FPS Meter - Returns a function that is used to compute the framerate without the overhead of updating the DOM every frame. | |
* @author Victor B - www.vitim.us | |
* @param {element} elm DOM Element to write the framerate | |
* @param {number} refresh Updates per second of the DOM | |
* @param {function} callback Function called on every DOM update | |
* @return {function} Returns a function that will be called inside the loop | |
*/ | |
function fpsMeter(elm, refresh, callback){ | |
//var elm; //element |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Stopwatch constructor to measure the elapsed time | |
* @author Victor B - www.vitim.us | |
*/ | |
function Stopwatch(){ | |
this.running = false; | |
this.startTimestamp; | |
this.endTimestamp; | |
} | |
Stopwatch.prototype.start = function(){ |
OlderNewer