steveosoule
6/5/2013 - 5:00 PM

Javascript Jquery Pattern

Javascript Jquery Pattern

// http://alistapart.com/article/the-design-of-code-organizing-javascript
(function($) {
    $.jPanelMenu = function(options) {
        var jpm = {
            options: $.extend({
                'animated': true,
                'duration': 500,
                'direction': 'left'
            }, options),
            openMenu: function( ) {
                // Open menu…
                this.setMenuStyle( );
            },
            closeMenu: function( ) {
                // close menu…
                this.setMenuStyle( );
            },
            setMenuStyle: function( ) { 
              // Set style… 
            }
        };

        return {
            open: jpm.openMenu,
            close: jpm.closeMenu,
            someComplexMethod: function( ) { 
              // do complex method…
            }
        };
    };
})(jQuery);

// Calling the API function
var jpm = $.jPanelMenu({
    duration: 1000
});
jpm.open( );