Created
April 9, 2012 09:01
-
-
Save fedmich/2342421 to your computer and use it in GitHub Desktop.
Javascript Codes
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
function doc_append ( obj ){ | |
if( document.getElementsByTagName("head").length > 0 ){ | |
document.getElementsByTagName("head")[0].appendChild( obj ); | |
} | |
else{ | |
document.getElementsByTagName("body")[0].appendChild( obj ); | |
} | |
} | |
var url_css = 'http://example.com/css/file.css'; | |
var o_css = document.createElement("link"); | |
o_css.setAttribute("rel", "stylesheet"); | |
o_css.setAttribute("type", "text/css"); | |
o_css.setAttribute("href", url_css + '?r=' + (Math.random()*99999999) ); | |
doc_append( o_css ); | |
var url_js = 'http://example.com/js/file.js'; | |
var o_js = document.createElement("script"); | |
o_js.setAttribute("src", url_js + '?r=' + (Math.random()*99999999) ); | |
doc_append( o_js ); |
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
function gup( name ){ | |
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); | |
var regexS = "[\\?&]"+name+"=([^&#]*)"; | |
var regex = new RegExp( regexS ); | |
var results = regex.exec( window.location.href ); | |
if( results == null ){ | |
return ""; | |
} else{ | |
return results[1]; | |
} | |
} |
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
(function() { | |
var imgs = document.getElementsByTagName('img'); | |
var imgs_no_alt = []; | |
for (var i = 0; i < imgs.length; i++) { | |
if( ! imgs[ i ].alt ){ | |
imgs_no_alt.push( imgs[i] ); | |
} | |
} | |
if( imgs_no_alt.length ){ | |
console.log("The following images don't have alt attributes."); | |
for (var i = 0; i < imgs_no_alt.length; i++) { | |
console.log( imgs_no_alt[i] ); | |
} | |
} | |
else{ | |
console.log('All images have alt attributes.'); | |
} | |
})(); |
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
function img_AspectRatio ( width, height, max_width, max_height) { | |
var ratio = Math.min( max_width / width, max_height / height); | |
return { width:(width * ratio).toFixed(0), height:( height * ratio).toFixed(0) }; | |
} |
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
function inArray(needle, haystack) { | |
var length = haystack.length; | |
for(var i = 0; i < length; i++) { | |
if(haystack[i] == needle) return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment