Created
June 8, 2012 14:29
-
-
Save funivan/2895903 to your computer and use it in GitHub Desktop.
Make my site One Zero site
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
/** | |
* oneZero plugin for true coders | |
* | |
* How to use | |
* | |
* $('html').oneZero(); //replace all chars that is valid for default regex in html node | |
* | |
* $('#footer').oneZero({charsPattern:/^[0-9]$/i}); //replace all numerical chars in #footer node | |
* | |
* | |
* @demo http://funivan.com/?rundemo=onezero | |
* @author Ivan Scherbak <funivan@mail.ua> | |
* @version 6/8/12 5:37 PM | |
*/ | |
(function($) { | |
$.fn.oneZero = function(userOptions) { | |
var options = { | |
charsPattern : /^[a-z0-9\u0410-\u044F\u0401\u0451єїі]$/i | |
} | |
options = $.extend(options, userOptions); | |
var oneZeroMake = function(node){ | |
var nodeElements = node.contents(); | |
nodeElements.each(function(){ | |
if(this.nodeType==3){ | |
var textArray = this.nodeValue.split(""); | |
for(letterIndex in textArray){ | |
if(options.charsPattern.test(textArray[letterIndex])){ | |
if(textArray[letterIndex].charCodeAt(0)%2){ | |
textArray[letterIndex]='1'; | |
}else{ | |
textArray[letterIndex]= '0'; | |
} | |
} | |
} | |
this.nodeValue = textArray.join(""); | |
} else { | |
oneZeroMake($(this)); | |
} | |
}) | |
} | |
oneZeroMake($(this)) | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment