From 972ccbbfb82c3ffee922995f57e1f1fef4a29720 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Mon, 22 Sep 2014 16:56:54 +0200 Subject: [PATCH] prototypal Ox.Element --- source/Ox.UI/js/Core/Element.js | 812 +++++++++++++++++--------------- 1 file changed, 434 insertions(+), 378 deletions(-) diff --git a/source/Ox.UI/js/Core/Element.js b/source/Ox.UI/js/Core/Element.js index 7d3fa7fd..9b3f255e 100644 --- a/source/Ox.UI/js/Core/Element.js +++ b/source/Ox.UI/js/Core/Element.js @@ -1,314 +1,357 @@ 'use strict'; -/*@ -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 scrollbars 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 -*/ +(function(_) { -Ox.Element = function(options, self) { + /*@ + 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 + */ - // create private object - self = self || {}; - // create defaults and options objects - self.defaults = {}; - // allow for Ox.TestElement('') or Ox.TestElement('cssSelector') - self.options = Ox.isString(options) ? {element: options} : options || {}; - // stack of callbacks bound to option updates - self.updateCallbacks = self.updateCallbacks || []; + Ox.Element = function Element(options, self) { - self.boundTooltipEvents = {}; + // create private object + self = self || {}; + // create defaults and options objects + self.defaults = {}; + // allow for Ox.Element('') or Ox.Element('cssSelector') + self.options = Ox.isString(options) ? {element: options} : options || {}; + // stack of callbacks bound to option updates + self.updateCallbacks = self.updateCallbacks || []; - // create public object - var that = new Ox.JQueryElement($(self.options.element || '
')) - .addClass('OxElement') - .on(Ox.extend({ - mousedown: mousedown, - mousewheel: mousewheel - }, self.options.element == '