Skip to content
Snippets Groups Projects
Commit 659a01e1 authored by Demian Katz's avatar Demian Katz
Browse files

Smarter VuFind object registration.

- Do not register the same object multiple times, or create duplicate objects.
- Make sure objects are initialized even if register() is called after init().
parent c66f72d7
Branches
Tags
No related merge requests found
...@@ -6,17 +6,25 @@ window.console = window.console || {log: function () {}}; ...@@ -6,17 +6,25 @@ window.console = window.console || {log: function () {}};
var VuFind = (function() { var VuFind = (function() {
var defaultSearchBackend = null; var defaultSearchBackend = null;
var path = null; var path = null;
var _initialized = false;
var _submodules = []; var _submodules = [];
var _translations = {}; var _translations = {};
var register = function(name, module) { var register = function(name, module) {
_submodules.push(name); if (_submodules.indexOf(name) === -1) {
this[name] = 'function' == typeof module ? module() : module; _submodules.push(name);
this[name] = typeof module == 'function' ? module() : module;
}
// If the object has already initialized, we should auto-init on register:
if (_initialized) {
this[name].init();
}
}; };
var init = function() { var init = function() {
for (var i=0; i<_submodules.length; i++) { for (var i=0; i<_submodules.length; i++) {
this[_submodules[i]].init(); this[_submodules[i]].init();
} }
_initialized = true;
}; };
var addTranslations = function(s) { var addTranslations = function(s) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment