Skip to content

Commit

Permalink
Added initialiseElement to ckan.module to allow for after dom ready i…
Browse files Browse the repository at this point in the history
…nitialization of js modules
  • Loading branch information
johnmartin committed Oct 2, 2012
1 parent f8851b2 commit b160598
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions ckan/public/base/javascript/module.js
Expand Up @@ -255,21 +255,11 @@ this.ckan = this.ckan || {};
* Returns the module object.
*/
module.initialize = function () {
var registry = module.registry;

// Start caching all calls to .publish() until all modules are loaded.
ckan.pubsub.enqueue();

jQuery('[data-module]', document.body).each(function (index, element) {
var names = jQuery.trim(this.getAttribute(MODULE_PREFIX)).split(' ');

jQuery.each(names, function (index, name) {
var Module = registry[name];

if (Module && typeof Module === 'function') {
module.createInstance(Module, element);
}
});
module.initializeElement(this);
});

// Now trigger all .publish() calls so that all modules receive them.
Expand All @@ -278,6 +268,19 @@ this.ckan = this.ckan || {};
return module;
};

module.initializeElement = function(element) {
var registry = module.registry;
var names = jQuery.trim(element.getAttribute(MODULE_PREFIX)).split(' ');

jQuery.each(names, function (index, name) {
var Module = registry[name];

if (Module && typeof Module === 'function') {
module.createInstance(Module, element);
}
});
};

/* Creates a new module instance for the element provided.
*
* The module factory is called with the sandbox, options object and
Expand Down

0 comments on commit b160598

Please sign in to comment.