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
/* | |
jQuery's ':empty' selector only returns true if the element contains no text node, or whose text node consists exclusively of zero or more spaces and tabs. This ':notext' selector will return true for elements whose text nodes can also contain line breaks (any whitespace character) and HTML comments. | |
*/ | |
$.expr[':'].notext = function detectNoText(x){ | |
return x.innerHTML && x.innerHTML.replace(/(<!--.*(?!-->))|\s+/g, '').length === 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
<script> | |
// add a class of 'loading' to the HTML, then remove it once the page has finished loading | |
(function(c){ | |
c('scripted loading') | |
window.onload = function(){setTimeout(function(){ | |
c(c().replace('loading','')) | |
},30)} | |
}(function(c){ | |
var h = document.lastChild | |
return c ? h.className = c : h.className |
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
/* Return an object model of a URI query (search or hash) */ | |
function uriQueryObj(str){ | |
if(!str) return false; | |
var str = decodeURIComponent(str), | |
str = /(^#)|(^$)/.test(str) ? str.substr(1) : str, | |
arr = str.substr(1).split('&'), | |
hash = {}; | |
while(arr.length && arr[0]){ | |
var bits = arr.pop().split('=') |
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
// Is the passed CSS property supported? | |
// eg. detectCSS('transition') | |
function detectCSS(prop){ | |
var | |
prop = prop.replace(/-(\w)/g,function(s,g){return g.toUpperCase()}), | |
pre = ',Icab,Khtml,Moz,Ms,O,Webkit'.split(','); | |
for (var i = 0; i < pre.length; ++i){ | |
if(i==1) | |
prop = prop.slice(0,1).toUpperCase() + prop.slice(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
.background { | |
background: rgb(247,247,247); | |
} | |
.fixText { | |
text-shadow: 0 0 1px rgba(247,247,247,.5); | |
} |
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
// Stack window.onload functions | |
function addLoad(func){ | |
var old = window.onload; | |
func instanceof Function | |
&& (window.onload = | |
old instanceof Function | |
? function(){func();old()} | |
: func); | |
}; |
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
// iframes delay page load: cut them out and in to reduce synchronous dependency | |
function asyncFrames(){ | |
$('iframe').each(function(){ | |
var | |
markup = $(this).clone(), | |
guide = $('<b>').replaceAll(this); | |
// addLoad: https://gist.github.com/1226302 | |
addLoad(function(){ | |
guide.replaceWith(markup) |
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 writeStyle(rules){ | |
var head = document.getElementsByTagName('head')[0], | |
el = this.el || document.createElement('style'), | |
rules = rules || ''; | |
if(!this.el) | |
el.type = 'text/css'; | |
if(el.styleSheet){ | |
el.styleSheet.cssText = rules; |
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
// Return all attributes, optionally filtered by RegExp | |
$.fn.attrs = function(expr){ | |
var | |
el = this[0], | |
$el = this, | |
attrArray = []; | |
for(var i=0, attrs = el.attributes; i<attrs.length; ++i){ | |
var attrKey = [ | |
attrs.item(i).nodeName, |
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
// Cross-browser outerHTML: return it, or if an argument was passed, replace the element. | |
$.fn.outerHTML = function(arg){ | |
var $el = this; | |
return arg | |
? $el.replaceWith(arg) | |
: $el.clone().wrap('<b>').parent().html(); | |
}; |
OlderNewer