Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Make my site One Zero site
/**
* 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