'use strict'; (function(_) { var noTooltipEvents = {}; /*@ Ox.Element Basic UI element object # Arguments ----------------------------------------------------------- options Options of the element, or just the `element` option element Tagname or CSS selector tooltip Tooltip title, or a function that returns one (e) -> Tooltip title e Mouse event self Shared private variable # Usage --------------------------------------------------------------- ([options[, self]]) -> Element object # Events ---------------------------------------------------------- anyclick anyclick Fires on mouseup, but not on any subsequent mouseup within 250 ms (this is useful if one wants to listen for singleclicks, but not doubleclicks, since it will fire immediately, and won't fire again in case of a doubleclick) * <*> Original event properties doubleclick doubleclick Fires on the second mousedown within 250 ms (this is useful if one wants to listen for both singleclicks and doubleclicks, since it will not trigger a singleclick event) * <*> Original event properties drag drag Fires on mousemove after dragstart, stops firing on mouseup clientDX Horizontal drag delta in px clientDY Vertical drag delta in px * <*> Original event properties dragend dragpause Fires on mouseup after dragstart clientDX Horizontal drag delta in px clientDY Vertical drag delta in px * <*> Original event properties dragenter dragenter Fires when entering an element during drag (this fires on the element being dragged -- the target element is the event's target property) clientDX Horizontal drag delta in px clientDY Vertical drag delta in px * <*> Original event properties dragleave dragleave Fires when leaving an element during drag (this fires on the element being dragged -- the target element is the event's target property) clientDX Horizontal drag delta in px clientDY Vertical drag delta in px * <*> Original event properties dragpause dragpause Fires once when the mouse doesn't move for 250 ms during drag (this is useful in order to execute operations that are too expensive to be attached to the drag event) clientDX Horizontal drag delta in px clientDY Vertical drag delta in px * <*> Original event properties dragstart dragstart Fires when the mouse is down for 250 ms * <*> Original event properties mousedown mousedown Fires on mousedown (this is useful if one wants to listen for singleclicks, but not doubleclicks or drag events, and wants the event to fire as early as possible) * <*> Original event properties mouserepeat mouserepeat Fires every 50 ms after the mouse was down for 250 ms, stops firing on mouseleave or mouseup (this fires like a key that is being pressed and held, and is useful for buttons like scrollbar arrows that need to react to both clicking and holding) mousewheel mousewheel Fires on mousewheel scroll or trackpad swipe deltaFactor Original delta = normalized delta * delta factor deltaX Normalized horizontal scroll delta in px deltaY Normalized vertical scroll delta in px * <*> Original event properties singleclick singleclick Fires 250 ms after mouseup, if there was no subsequent mousedown (this is useful if one wants to listen for both singleclicks and doubleclicks, since it will not fire for doubleclicks) * <*> Original event properties */ Ox.Element = function Element(options, self) { // create private object self = self || {}; self.boundTooltipEvents = noTooltipEvents; self.defaults = {}; self.eventCallbacks = self.eventCallbacks || {}; // allow for Ox.Element('') or Ox.Element('cssSelector') self.options = Ox.isString(options) ? {element: options} : options || {}; self.unbindKeyboard = function unbindKeyboard() { Object.keys(self.eventCallbacks).filter(function(event) { return /^key([\._][\w\.]+)?$/.test(event); }).forEach(function(event) { that.unbindEvent(event); }); }; self.update = function update(key, value) { // update is called whenever an option is modified or added Ox.loop(self.updateCallbacks.length - 1, -1, -1, function(index) { // break if the callback returns false return self.updateCallbacks[index](key, value) !== false; }); }; self.updateCallbacks = self.updateCallbacks || []; // create public object var that = Object.create(Ox.Element.prototype); that.oxid = Ox.uid(); that.$element = $(self.options.element || '
') .addClass('OxElement') .data({oxid: that.oxid}) .on({ mousedown: onMousedown, mousewheel: onMousewheel }); that[0] = that.$element[0]; that.length = 1; that.self = function _self() { return arguments[0] === _ ? self : {}; }; Ox.$elements[that.oxid] = that; if (self.options.element == '