Created
May 4, 2014 23:18
-
-
Save redroot/3c7948ec92ecbd3bdf1d to your computer and use it in GitHub Desktop.
Example JS Module pattern
This file contains hidden or 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
| var Header = (function(w,d,undefined)){ | |
| var _elem = null; | |
| var bindButtons = function(){ | |
| $(document).on('click', _elem.find(".js-toggle-sidebar"), function(){ | |
| Sidebar.toggle(); // | |
| }); | |
| } | |
| var init = function(){ | |
| _elem = $("#header"); | |
| bindButtons(); | |
| } | |
| return { | |
| init: init | |
| } | |
| })(window,document); | |
| var Sidebar = (function(w,d,undefined){ | |
| var _elem = null; | |
| var hide = function(){ | |
| _elem.addClass('is-hidden'); | |
| } | |
| var show = function(){ | |
| _elem.removeClass('is-hidden') | |
| } | |
| var init = function(){ | |
| _elem = $("#sidebar"); | |
| } | |
| var toggleSidebar = function(){ | |
| elem.hasClass('is-hidden') ? show() hide(); | |
| } | |
| // code for all other functions | |
| return { | |
| init: init, | |
| hide: hide, | |
| show: show, | |
| toggle: toggle | |
| // more here | |
| } | |
| })(window,document); | |
| window.onload = function(){ | |
| Header.init(); | |
| Sidebar.init(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment