/** * @author BYK */ if (window.groups) throw new Error('"groups" namespace is already in use!'); groups = { _config: {}, _info: {module: {}}, _initQueue: [], langStrings: {}, warnOnLeave: 0 }; groups.namespace = function(name, defaultConfig, customNS) { if (groups[name]) throw new Error('Namespace already exists!'); groups[name] = customNS || {}; if (defaultConfig) groups._config[name] = Object.extend(defaultConfig, groups._config[name] || {}); }; groups.i18n = function(str) { return (str in groups.langStrings) ? groups.langStrings[str] : str; }; groups.ajaxCall = function(functionName, args, notificationText, callback) { groups.warnOnLeave++; var callbackWrapper = function(result) {groups.warnOnLeave--; (callback || groups.ajaxCall._defaulCallback)(result);} args.push(callbackWrapper); try { groups.notifier.show('loader', notificationText || 'Sending information...'); } catch(e) {} return _S(functionName, args); }; groups.ajaxCall._defaulCallback = function(result) { var success = (result instanceof Array) ? result[0] : result; //TODO: Fix me, very ugly hack below, resets ALL nicEditors with a successfull request! if (success) { groups.modalBox.hide(); if (!groups.warnOnLeave && window.nicEditors && nicEditors.editors) for (var i = nicEditors.editors.length - 1; i >= 0; i--) for (var j = nicEditors.editors[i].nicInstances.length - 1; j >= 0; j--) nicEditors.editors[i].nicInstances[j].oldHash = SHA256.hash(nicEditors.editors[i].nicInstances[j].getContent()); } if (success >= 1 || success === true) { if (result[1]) document.location.href = result[1]; else document.location.reload(true); } else groups.notifier.show(success && 'success' || 'error', result[1] || 'Oops, temporary error occurred. Please try again...'); }; groups._fixSelects = function() { var selectElements = Element.select(groups.modalBox._content, 'select'); for (var i = selectElements.length - 1; i >= 0; i--) selectElements[i].value = selectElements[i].getAttribute('data-default') || selectElements[i].getAttribute('value'); }; groups.addToInit = function() { for (var i = 0, length = arguments.length; i < length; i++) if (groups._initQueue) groups._initQueue.push(arguments[i]); else window.setTimeout(arguments[i], 0); }; groups.init = function() { var initList = groups._initQueue, i = 0, length = initList.length; if (document.loaded) for (; i < length; i++) window.setTimeout(initList[i], 0); else for (; i < length; i++) Event.observe(document, 'dom:loaded', initList[i]); delete groups._initQueue; initList = null; };