* @return string
*/
wcfIdentify: function() {
- return window.domUtilIdentify(this[0]);
+ return window.bc_wcfDOMUtil.identify(this[0]);
},
/**
* @return string
*/
getRandomID: function() {
- return window.domUtilGetUniqueId();
+ return window.bc_wcfDOMUtil.getUniqueId();
},
/**
/**
* Dropdown API
+ *
+ * @deprecated 2.2 - please use `UI/SimpleDropdown` instead
*/
WCF.Dropdown = {
- /**
- * list of callbacks
- * @var object
- */
- _callbacks: { },
-
- /**
- * initialization state
- * @var boolean
- */
- _didInit: false,
-
- /**
- * list of registered dropdowns
- * @var object
- */
- _dropdowns: { },
-
-
-
- /**
- * container for dropdown menus
- * @var object
- */
- _menuContainer: null,
-
- /**
- * list of registered dropdown menus
- * @var object
- */
- _menus: { },
-
- _api: null,
-
/**
* Initializes dropdowns.
*/
init: function(api) {
- if (api) this._api = api;
- else if (this._api !== null) this._api.initAll();
+ window.bc_wcfSimpleDropdown.initAll();
},
/**
* @param boolean isLazyInitialization
*/
initDropdown: function(button, isLazyInitialization) {
- this._api.init(button[0], isLazyInitialization);
+ window.bc_wcfSimpleDropdown.init(button[0], isLazyInitialization);
},
/**
* @param string containerID
*/
removeDropdown: function(containerID) {
- this._api.remove(containerID);
+ window.bc_wcfSimpleDropdown.remove(containerID);
},
/**
* @param jQuery dropdownMenu
*/
initDropdownFragment: function(dropdown, dropdownMenu) {
- this._api.initFragment(dropdown[0], dropdownMenu[0]);
+ window.bc_wcfSimpleDropdown.initFragment(dropdown[0], dropdownMenu[0]);
},
/**
* @var object callback
*/
registerCallback: function(identifier, callback) {
- this._api.registerCallback(identifier, callback);
+ window.bc_wcfSimpleDropdown.registerCallback(identifier, callback);
},
/**
* @param string targetID
*/
_toggle: function(event, targetID) {
- this._api._toggle(event, targetID);
+ window.bc_wcfSimpleDropdown._toggle(event, targetID);
},
/**
* @param string containerID
*/
toggleDropdown: function(containerID) {
- this._api._toggle(null, containerID);
+ window.bc_wcfSimpleDropdown._toggle(null, containerID);
},
/**
* @return jQuery
*/
getDropdown: function(containerID) {
- var dropdown = this._api.getDropdown(containerID);
+ var dropdown = window.bc_wcfSimpleDropdown.getDropdown(containerID);
return (dropdown) ? $(dropdown) : null;
},
* @return jQuery
*/
getDropdownMenu: function(containerID) {
- var menu = this._api.getDropdownMenu(containerID);
+ var menu = window.bc_wcfSimpleDropdown.getDropdownMenu(containerID);
return (menu) ? $(menu) : null;
},
* @param string containerID
*/
setAlignmentByID: function(containerID) {
- this._api.setAlignmentById(containerID);
+ window.bc_wcfSimpleDropdown.setAlignmentById(containerID);
},
/**
* @param jQuery dropdownMenu
*/
setAlignment: function(dropdown, dropdownMenu) {
- this._api.setAlignment(dropdown[0], dropdownMenu[0]);
+ window.bc_wcfSimpleDropdown.setAlignment(dropdown[0], dropdownMenu[0]);
},
/**
* Closes all dropdowns.
*/
_closeAll: function() {
- this._api.closeAll();
+ window.bc_wcfSimpleDropdown.closeAll();
},
/**
* @param string containerID
*/
close: function(containerID) {
- this._api.close(containerID);
+ window.bc_wcfSimpleDropdown.close(containerID);
},
/**
* @return boolean
*/
destroy: function(containerID) {
- this._api.destroy(containerID);
+ window.bc_wcfSimpleDropdown.destroy(containerID);
}
};
* preventing errors from blocking the iteration. Furthermore you should
* always handle clicks on your overlay's container and return 'false' to
* prevent bubbling.
+ *
+ * @deprecated 2.2 - please use `UI/CloseOverlay` instead
*/
WCF.CloseOverlayHandler = {
- /**
- * list of callbacks
- * @var WCF.Dictionary
- */
- _callbacks: new WCF.Dictionary(),
-
- /**
- * indicates that overlay handler is listening to click events on body-tag
- * @var boolean
- */
- _isListening: false,
-
/**
* Adds a new callback.
*
* @param object callback
*/
addCallback: function(identifier, callback) {
- this._bindListener();
-
- if (this._callbacks.isset(identifier)) {
- console.debug("[WCF.CloseOverlayHandler] identifier '" + identifier + "' is already bound to a callback");
- return false;
- }
-
- this._callbacks.add(identifier, callback);
+ require(['UI/CloseOverlay'], function(UICloseOverlay) {
+ UICloseOverlay.add(identifier, callback);
+ });
},
/**
* @param string identifier
*/
removeCallback: function(identifier) {
- if (this._callbacks.isset(identifier)) {
- this._callbacks.remove(identifier);
- }
+ require(['UI/CloseOverlay'], function(UICloseOverlay) {
+ UICloseOverlay.remove(identifier);
+ });
},
/**
* Triggers the callbacks programmatically.
*/
forceExecution: function() {
- this._executeCallbacks();
- },
-
- /**
- * Binds click event handler.
- */
- _bindListener: function() {
- if (this._isListening) return;
-
- $(document.body).click($.proxy(this._executeCallbacks, this));
-
- this._isListening = true;
- },
-
- /**
- * Executes callbacks on click.
- */
- _executeCallbacks: function(event) {
- this._callbacks.each(function(pair) {
- // execute callback
- pair.value();
+ require(['UI/CloseOverlay'], function(UICloseOverlay) {
+ UICloseOverlay.execute();
});
}
};
}
};
+ // expose on window object for backward compatibility
+ window.bc_wcfDOMUtil = DOMUtil;
+
return DOMUtil;
});
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLab/WCF/Date/Time/Relative
*/
-define(['DOM/ChangeListener', 'Language', 'WoltLab/WCF/Timer/Repeating'], function(DOMChangeListener, Language, Repeating) {
+define(['DOM/ChangeListener', 'Language', 'WoltLab/WCF/Date/Util', 'WoltLab/WCF/Timer/Repeating'], function(DOMChangeListener, Language, DateUtil, Repeating) {
"use strict";
var _elements = document.getElementsByTagName('time');
var days = Math.ceil((midnight / 1000 - elTimestamp) / 86400);
// get day of week
- var dateObj = WCF.Date.Util.getTimezoneDate((elTimestamp * 1000), elOffset * 1000);
+ var dateObj = DateUtil.getTimezoneDate((elTimestamp * 1000), elOffset * 1000);
var dow = dateObj.getDay();
var day = Language.get('__days')[dow];
--- /dev/null
+/**
+ * Provides utility functions for date operations.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2015 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLab/WCF/Date/Util
+ */
+define([], function() {
+ "use strict";
+
+ /**
+ * @exports WoltLab/WCF/Date/Util
+ */
+ var DateUtil = {
+ /**
+ * Returns UTC timestamp, if date is not given, current time will be used.
+ *
+ * @param Date date target date
+ * @return integer UTC timestamp in seconds
+ */
+ gmdate: function(data) {
+ if ((!date instanceof Date)) {
+ date = new Date();
+ }
+
+ return Math.round(Date.UTC(
+ date.getUTCFullYear(),
+ date.getUTCMonth(),
+ date.getUTCDay(),
+ date.getUTCHours(),
+ date.getUTCMinutes(),
+ date.getUTCSeconds()
+ ) / 1000);
+ },
+
+ /**
+ * Returns a Date object with precise offset (including timezone and local timezone).
+ *
+ * @param integer timestamp timestamp in miliseconds
+ * @param integer offset timezone offset in miliseconds
+ * @return Date localized date
+ */
+ getTimezoneDate: function(timestamp, offset) {
+ var date = new Date(timestamp);
+ var localOffset = date.getTimezoneOffset() * 60000;
+
+ return new Date((timestamp + localOffset + offset));
+ }
+ };
+
+ return DateUtil;
+});
--- /dev/null
+/**
+ * Allows to be informed when a click event bubbled up to the document's body.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2015 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLab/WCF/UI/CloseOlveray
+ */
+define(['CallbackList'], function(CallbackList) {
+ "use strict";
+
+ var _callbackList = new CallbackList();
+
+ /**
+ * @exports WoltLab/WCF/UI/CloseOverlay
+ */
+ var UICloseOverlay = {
+ /**
+ * Sets up global event listener for bubbled clicks events.
+ */
+ setup: function() {
+ document.body.addEventListener('click', this.execute.bind(this));
+ },
+
+ /**
+ * @see WoltLab/WCF/CallbackList#add
+ */
+ add: _callbackList.add.bind(_callbackList),
+
+ /**
+ * @see WoltLab/WCF/CallbackList#remove
+ */
+ remove: _callbackList.remove.bind(_callbackList),
+
+ /**
+ * Invokes all registered callbacks.
+ */
+ execute: function() {
+ _callbackList.forEach(null, function(callback) {
+ callback();
+ });
+ }
+ };
+
+ UICloseOverlay.setup();
+
+ return UICloseOverlay;
+});
* @module WoltLab/WCF/UI/Dialog
*/
define(
- [ 'enquire', 'Core', 'Dictionary', 'Environment', 'Language', 'DOM/ChangeListener', 'DOM/Util'],
- function(enquire, Core, Dictionary, Environment, Language, DOMChangeListener, DOMUtil)
+ [ 'enquire', 'Core', 'Dictionary', 'Environment', 'Language', 'DOM/ChangeListener', 'DOM/Util', 'UI/Confirmation'],
+ function(enquire, Core, Dictionary, Environment, Language, DOMChangeListener, DOMUtil, UIConfirmation)
{
"use strict";
if (!options.closable) options.backdropCloseOnClick = false;
if (options.closeConfirmMessage) {
options.onBeforeClose = (function(id) {
- WCF.System.Confirmation.show(options.closeConfirmMessage, (function(action) {
- if (action === 'confirm') {
+ UIConfirmation.show({
+ confirm: (function() {
this.close(id);
- }
- }).bind(this));
+ }).bind(this),
+ message: options.closeConfirmMessage
+ })
}).bind(this);
}
* @module WoltLab/WCF/UI/Dropdown/Simple
*/
define(
- [ 'CallbackList', 'Dictionary', 'UI/Alignment', 'DOM/ChangeListener', 'DOM/Traverse', 'DOM/Util'],
- function(CallbackList, Dictionary, UIAlignment, DOMChangeListener, DOMTraverse, DOMUtil)
+ [ 'CallbackList', 'Dictionary', 'UI/Alignment', 'DOM/ChangeListener', 'DOM/Traverse', 'DOM/Util', 'UI/CloseOverlay'],
+ function(CallbackList, Dictionary, UIAlignment, DOMChangeListener, DOMTraverse, DOMUtil, UICloseOverlay)
{
"use strict";
this.initAll();
- WCF.Dropdown.init(this);
-
- WCF.CloseOverlayHandler.addCallback('WoltLab/WCF/UI/Dropdown/Simple', this.closeAll.bind(this));
+ UICloseOverlay.add('WoltLab/WCF/UI/Dropdown/Simple', this.closeAll.bind(this));
DOMChangeListener.add('WoltLab/WCF/UI/Dropdown/Simple', this.initAll.bind(this));
document.addEventListener('scroll', this._onScroll.bind(this));
+
+ // expose on window object for backward compatibility
+ window.bc_wcfSimpleDropdown = this;
},
/**
}
}).bind(this));
+ // TODO
WCF.Dropdown.Interactive.Handler.closeAll();
if (event !== null) {
define(['Core', 'Dictionary', 'DOM/ChangeListener', 'DOM/Traverse', 'DOM/Util', 'UI/SimpleDropdown'], function(Core, Dictionary, DOMChangeListener, DOMTraverse, DOMUtil, SimpleDropdown) {
"use strict";
+ var _containers = new Dictionary();
+ var _dropdowns = new Dictionary();
+ var _dropdownMenus = new Dictionary();
+ var _itemLists = new Dictionary();
+
/**
- * @constructor
+ * @exports WoltLab/WCF/UI/FlexibleMenu
*/
- function UIFlexibleMenu() {
- this._containers = new Dictionary();
- this._dropdowns = new Dictionary();
- this._dropdownMenus = new Dictionary();
- this._itemLists = new Dictionary();
- };
- UIFlexibleMenu.prototype = {
+ var UIFlexibleMenu = {
/**
* Register default menus and set up event listeners.
*/
var navigationHeader = document.querySelector('.navigationHeader');
if (navigationHeader !== null) this.register(DOMUtil.identify(navigationHeader));
-
window.addEventListener('resize', this.rebuildAll.bind(this));
DOMChangeListener.add('WoltLab/WCF/UI/FlexibleMenu', this.registerTabMenus.bind(this));
},
throw "Expected a valid element id, '" + containerId + "' does not exist.";
}
- if (this._containers.has(containerId)) {
+ if (_containers.has(containerId)) {
return;
}
- var lists = DOMTraverse.childrenByTag(container, 'UL');
- if (!lists.length) {
+ var list = DOMTraverse.childByTag(container, 'UL');
+ if (list === null) {
throw "Expected an <ul> element as child of container '" + containerId + "'.";
}
- this._containers.set(containerId, container);
- this._itemLists.set(containerId, lists[0]);
+ _containers.set(containerId, container);
+ _itemLists.set(containerId, list);
this.rebuild(containerId);
},
var tabMenus = document.querySelectorAll('.tabMenuContainer:not(.jsFlexibleMenuEnabled), .messageTabMenu:not(.jsFlexibleMenuEnabled)');
for (var i = 0, length = tabMenus.length; i < length; i++) {
var tabMenu = tabMenus[i];
- var navs = DOMTraverse.childrenByTag(tabMenu, 'NAV');
- if (navs.length !== 0) {
+ var nav = DOMTraverse.childByTag(tabMenu, 'NAV');
+ if (nav !== null) {
tabMenu.classList.add('jsFlexibleMenuEnabled');
- this.register(DOMUtil.identify(navs[0]));
+ this.register(DOMUtil.identify(nav));
}
}
},
* Rebuilds all menus, e.g. on window resize.
*/
rebuildAll: function() {
- this._containers.forEach((function(container, containerId) {
+ _containers.forEach((function(container, containerId) {
this.rebuild(containerId);
}).bind(this));
},
* @param {string} containerId element id
*/
rebuild: function(containerId) {
- var container = this._containers.get(containerId);
+ var container = _containers.get(containerId);
if (container === undefined) {
throw "Expected a valid element id, '" + containerId + "' is unknown.";
}
availableWidth -= DOMUtil.styleAsInt(styles, 'margin-left');
availableWidth -= DOMUtil.styleAsInt(styles, 'margin-right');
- var list = this._itemLists.get(containerId);
+ var list = _itemLists.get(containerId);
var items = DOMTraverse.childrenByTag(list, 'LI');
- var dropdown = this._dropdowns.get(containerId);
+ var dropdown = _dropdowns.get(containerId);
var dropdownWidth = 0;
if (dropdown !== undefined) {
// show all items for calculation
dropdownMenu.classList.add('dropdownMenu');
dropdown.appendChild(dropdownMenu);
- this._dropdowns.set(containerId, dropdown);
- this._dropdownMenus.set(containerId, dropdownMenu);
+ _dropdowns.set(containerId, dropdown);
+ _dropdownMenus.set(containerId, dropdownMenu);
SimpleDropdown.init(icon);
}
else {
- dropdownMenu = this._dropdownMenus.get(containerId);
+ dropdownMenu = _dropdownMenus.get(containerId);
}
if (dropdown.parentNode === null) {
}
};
- return new UIFlexibleMenu();
+ return UIFlexibleMenu;
});
* @module WoltLab/WCF/UI/Mobile
*/
define(
- [ 'enquire', 'Environment', 'Language', 'DOM/ChangeListener', 'DOM/Traverse'],
- function(enquire, Environment, Language, DOMChangeListener, DOMTraverse)
+ [ 'enquire', 'Environment', 'Language', 'DOM/ChangeListener', 'DOM/Traverse', 'UI/CloseHandler'],
+ function(enquire, Environment, Language, DOMChangeListener, DOMTraverse, UICloseHandler)
{
"use strict";
this._initSearchBar();
this._initButtonGroupNavigation();
- WCF.CloseOverlayHandler.addCallback('WoltLab/WCF/UI/Mobile', this._closeAllMenus.bind(this));
+ UICloseHandler.add('WoltLab/WCF/UI/Mobile', this._closeAllMenus.bind(this));
DOMChangeListener.add('WoltLab/WCF/UI/Mobile', this._initButtonGroupNavigation.bind(this));
},
'List': 'WoltLab/WCF/List',
'ObjectMap': 'WoltLab/WCF/ObjectMap',
'UI/Alignment': 'WoltLab/WCF/UI/Alignment',
+ 'UI/CloseOverlay': 'WoltLab/WCF/UI/CloseOverlay',
'UI/Confirmation': 'WoltLab/WCF/UI/Confirmation',
'UI/Dialog': 'WoltLab/WCF/UI/Dialog',
'UI/SimpleDropdown': 'WoltLab/WCF/UI/Dropdown/Simple',