From 659a01e182bf56dfc81aa5df84b97761daf18342 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 20 Apr 2016 11:24:29 -0400 Subject: [PATCH] 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(). --- themes/bootstrap3/js/common.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/themes/bootstrap3/js/common.js b/themes/bootstrap3/js/common.js index 90803ee09e6..b355cbe945c 100644 --- a/themes/bootstrap3/js/common.js +++ b/themes/bootstrap3/js/common.js @@ -6,17 +6,25 @@ window.console = window.console || {log: function () {}}; var VuFind = (function() { var defaultSearchBackend = null; var path = null; + var _initialized = false; var _submodules = []; var _translations = {}; var register = function(name, module) { - _submodules.push(name); - this[name] = 'function' == typeof module ? module() : module; + if (_submodules.indexOf(name) === -1) { + _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() { for (var i=0; i<_submodules.length; i++) { this[_submodules[i]].init(); } + _initialized = true; }; var addTranslations = function(s) { -- GitLab