Last active
August 4, 2016 09:29
-
-
Save Andrinoid/4f890225105fd326f12c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//set event on documnet but fire if target is true | |
document.addEventListener('click', function(e) { | |
var clsList = Array.prototype.slice.call(e.target.classList); | |
if(cls.indexOf('hero-heading') > -1) { | |
console.log('hello'); | |
} | |
}) | |
function cssAnimationEvent(element, type, callback) { | |
var self = this; | |
var pfx = ["webkit", "moz", "MS", "o", ""]; | |
for (var p = 0; p < pfx.length; p++) { | |
if (!pfx[p]) type = type.toLowerCase(); | |
element.addEventListener(pfx[p]+type, function() { | |
callback(element); | |
}, false); | |
} | |
} | |
//image prelaoder with promise. Note you need a polyfill for promise to work. | |
function preloadImage(src) { | |
var promise = new Promise(function(resolve, reject){ | |
var image = new Image(); | |
image.src = src; | |
image.onload = function() { | |
resolve(); | |
} | |
image.onerror = function() { | |
reject(Error('Image'+ src +' faled to load')); | |
} | |
}); | |
return promise; | |
} | |
//simple jsonp function | |
function jsonp(url, callback) { | |
var callbackName = 'jsonp_callback_' + Math.round(100000 * Math.random()); | |
window[callbackName] = function(data) { | |
delete window[callbackName]; | |
document.body.removeChild(script); | |
callback(data); | |
}; | |
var script = document.createElement('script'); | |
script.src = url + (url.indexOf('?') >= 0 ? '&' : '?') + 'callback=' + callbackName; | |
document.body.appendChild(script); | |
} | |
getUrlParameter = function getUrlParameter(sParam) { | |
var sPageURL = window.location.search.substring(1); | |
var sURLVariables = sPageURL.split('&'); | |
var sParameterName = void 0; | |
var i = void 0; | |
for (i = 0; i < sURLVariables.length; i++) { | |
sParameterName = sURLVariables[i].split('='); | |
if (sParameterName[0] === sParam) { | |
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); | |
} | |
} | |
return ''; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment