Last active
October 12, 2015 23:48
-
-
Save samarpanda/4105651 to your computer and use it in GitHub Desktop.
Module reveal pattern.
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(undefined){ | |
"use strict" | |
if(jQuery === undefined) | |
return; | |
var $ = window.jQuery; | |
var sBASE = function(){ | |
var self, | |
/** | |
* Cache all dom nodes to below config object. To prevent unecessary multiple dom traverse using jQuery(As i am using jQuery here.). | |
*/ | |
config = {}; | |
var UI = { | |
cleanUp: function(){ | |
$("html").removeClass("no-js").find("body").removeClass("no-js"); | |
return this; | |
}, | |
html5PlaceHolder: function($form){ | |
var placeHolderClass = "placeholder", | |
placeHolderAttr = "placeholder", | |
hasSupport = placeHolderAttr in document.createElement('input'); | |
if(hasSupport){ | |
return this; | |
} | |
$form.submit(function(){ | |
$(this).find("["+placeHolderAttr+"]").each(function(){ | |
var input = $(this); | |
if( input.val() == input.attr(placeHolderAttr) ){ | |
input.val(""); | |
} | |
}); | |
}).find("["+placeHolderAttr+"]").focus(function(){ | |
var input = $(this), | |
inputVal = input.val(); | |
if(inputVal == input.attr(placeHolderClass)){ | |
input.val(""); | |
input.removeClass(placeHolderClass); | |
} | |
}).blur(function(){ | |
var input = $(this), | |
inputVal = input.val(); | |
if( inputVal == "" || inputVal == input.attr(placeHolderAttr) ){ | |
input.addClass(placeHolderClass); | |
input.val(input.attr(placeHolderAttr)); | |
} | |
}).blur(); | |
return this; | |
}, | |
dCookie: function(){ | |
if(!document.__defineGetter__){ | |
//IE | |
Object.defineProperty(document, 'cookie', { | |
get: function(){ return ''; }, | |
set: function(){ return true; } | |
}); | |
} else { | |
document.__defineGetter__("cookie", function(){ return ''; }); | |
document.__defineSetter__("cookie", function(){}); | |
} | |
}, | |
init: function(){ | |
console.log("Entry point"); | |
} | |
}; | |
var EXT = {}; | |
return { | |
'UI': UI, | |
'EXT': EXT | |
}; | |
}(); | |
sBASE.UI.init(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment