Last active
August 29, 2015 14:25
-
-
Save toh82/0fc9c0922d896f3c5f48 to your computer and use it in GitHub Desktop.
JS Module Launcher
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 ($) { | |
var moduleLauncher = { | |
oSettings: { | |
prefix: 'js_', | |
moduleRegister: [], | |
debug: false | |
}, | |
/** | |
* Method to print out debug information | |
* | |
* @param {object} oObject | |
* @param {string} sMessage | |
* @private | |
*/ | |
debug: function (sMessage, oObject) { | |
if (this.oSettings.debug) { | |
console.log(sMessage, oObject); | |
} | |
}, | |
/** | |
* | |
* @param {string} sModuleName | |
* @param {object} oCallback | |
*/ | |
registerModule: function (sModuleName, oCallback) { | |
var oModuleRegister = this.oSettings.moduleRegister, | |
bHasModule = $.inArray(sModuleName, oModuleRegister) != -1; | |
if(!bHasModule) { | |
oModuleRegister.push({ | |
name: sModuleName, | |
callback: oCallback | |
}); | |
} | |
}, | |
launchModules: function () { | |
var oModuleRegister = this.oSettings.moduleRegister, | |
sModuleNamePrefix = this.oSettings.prefix; | |
$.each(oModuleRegister, function () { | |
var $module = $('.' + sModuleNamePrefix + this.name), | |
oCallback = this.callback, | |
oThis = this; | |
if ($module.length !== 0) { | |
oCallback.call( | |
oThis, | |
$module | |
); | |
} | |
}); | |
} | |
}; | |
moduleLauncher.registerModule( | |
'equalizeHeights', | |
function ($elements) { | |
$elements.equalizeHeights('equalize-heights-parent', true); | |
} | |
); | |
$(window).load(function () { | |
moduleLauncher.launchModules(); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some ideas: