Skip to content

Instantly share code, notes, and snippets.

@funivan
Created June 8, 2012 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funivan/2895903 to your computer and use it in GitHub Desktop.
Save funivan/2895903 to your computer and use it in GitHub Desktop.
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