2011-11-05 16:46:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2011-05-05 18:02:56 +00:00
|
|
|
/*@
|
2012-05-22 13:14:40 +00:00
|
|
|
Ox.Element <f:Ox.JQueryElement> Basic UI element object
|
2011-05-05 18:02:56 +00:00
|
|
|
# Usage --------------------------------------------------------------------
|
2011-10-01 02:21:55 +00:00
|
|
|
(element) -> <object> UI element
|
|
|
|
(options) -> <object> UI element
|
|
|
|
(options, self) -> <object> UI element
|
2011-05-05 18:02:56 +00:00
|
|
|
# Arguments ----------------------------------------------------------------
|
2011-10-01 02:21:55 +00:00
|
|
|
element <string> Tagname or CSS selector
|
|
|
|
options <object> Options of the element
|
2011-05-05 18:02:56 +00:00
|
|
|
# Properties
|
2011-10-01 02:21:55 +00:00
|
|
|
element <string> Tagname or CSS selector
|
|
|
|
tooltip <string|function> Tooltip title, or a function that returns one
|
2011-05-17 18:44:53 +00:00
|
|
|
(e) -> <string> tooltip title
|
|
|
|
e <object> mouse event
|
2011-10-01 02:21:55 +00:00
|
|
|
self <object> Shared private variable
|
2011-05-05 18:02:56 +00:00
|
|
|
# Events -------------------------------------------------------------------
|
|
|
|
anyclick <event> anyclick
|
2011-10-01 02:21:55 +00:00
|
|
|
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)
|
2011-05-05 18:02:56 +00:00
|
|
|
* <*> original event properties
|
|
|
|
doubleclick <event> doubleclick
|
2011-10-01 02:21:55 +00:00
|
|
|
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
|
2011-05-05 18:02:56 +00:00
|
|
|
drag <event> drag
|
2011-09-04 12:19:36 +00:00
|
|
|
Fires on mousemove after dragstart, stops firing on mouseup
|
2011-05-05 18:02:56 +00:00
|
|
|
clientDX <number> horizontal drag delta in px
|
|
|
|
clientDY <number> vertical drag delta in px
|
|
|
|
* <*> original event properties
|
|
|
|
dragend <event> dragpause
|
|
|
|
Fires on mouseup after dragstart
|
|
|
|
clientDX <number> horizontal drag delta in px
|
|
|
|
clientDY <number> vertical drag delta in px
|
|
|
|
* <*> original event properties
|
2011-09-04 12:19:36 +00:00
|
|
|
dragenter <event> dragenter
|
2011-10-01 02:21:55 +00:00
|
|
|
Fires when entering an element during drag (this fires on the element
|
|
|
|
being dragged -- the target element is the event's target property)
|
|
|
|
clientDX <number> horizontal drag delta in px
|
|
|
|
clientDY <number> vertical drag delta in px
|
|
|
|
* <*> original event properties
|
2011-09-04 12:19:36 +00:00
|
|
|
dragleave <event> dragleave
|
2011-10-01 02:21:55 +00:00
|
|
|
Fires when leaving an element during drag (this fires on the element
|
|
|
|
being dragged -- the target element is the event's target property)
|
|
|
|
clientDX <number> horizontal drag delta in px
|
|
|
|
clientDY <number> vertical drag delta in px
|
|
|
|
* <*> original event properties
|
2011-05-05 18:02:56 +00:00
|
|
|
dragpause <event> dragpause
|
2011-10-01 02:21:55 +00:00
|
|
|
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)
|
2011-05-05 18:02:56 +00:00
|
|
|
clientDX <number> horizontal drag delta in px
|
|
|
|
clientDY <number> vertical drag delta in px
|
|
|
|
* <*> original event properties
|
2011-10-01 02:21:55 +00:00
|
|
|
mousedown <event> 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
|
2011-05-05 18:02:56 +00:00
|
|
|
dragstart <event> dragstart
|
2011-09-04 12:19:36 +00:00
|
|
|
Fires when the mouse is down for 250 ms
|
2011-05-05 18:02:56 +00:00
|
|
|
* <*> original event properties
|
|
|
|
mouserepeat <event> mouserepeat
|
2011-09-04 12:19:36 +00:00
|
|
|
Fires every 50 ms after the mouse was down for 250 ms, stops firing on
|
2011-10-01 02:21:55 +00:00
|
|
|
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)
|
2011-05-05 18:02:56 +00:00
|
|
|
singleclick <event> singleclick
|
2011-10-01 02:21:55 +00:00
|
|
|
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)
|
2011-05-05 18:02:56 +00:00
|
|
|
* <*> original event properties
|
|
|
|
@*/
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
Ox.Element = function(options, self) {
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
// create private object
|
|
|
|
self = self || {};
|
|
|
|
// create defaults and options objects
|
|
|
|
self.defaults = {};
|
|
|
|
self.options = options || {};
|
|
|
|
// allow for Ox.TestElement('<tagname>')
|
|
|
|
// or Ox.TestElement('cssSelector')
|
|
|
|
if (Ox.isString(self.options)) {
|
|
|
|
self.options = {
|
|
|
|
element: self.options
|
|
|
|
};
|
|
|
|
}
|
2012-05-28 14:02:25 +00:00
|
|
|
// array of callbacks bound to any event
|
|
|
|
self.eventCallbacks = [];
|
2011-10-01 02:21:55 +00:00
|
|
|
// create event handler
|
|
|
|
// (this can be passed as part of self)
|
|
|
|
if (!self.$eventHandler) {
|
|
|
|
self.$eventHandler = $('<div>');
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
// create public object
|
2012-05-28 14:02:25 +00:00
|
|
|
var that = new Ox.JQueryElement($(self.options.element || '<div>'))
|
|
|
|
.addClass('OxElement')
|
|
|
|
.mousedown(mousedown);
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-11-04 22:14:30 +00:00
|
|
|
setTooltip();
|
2011-04-29 22:07:23 +00:00
|
|
|
|
2012-05-28 14:02:25 +00:00
|
|
|
function bind(event, callback, once) {
|
|
|
|
self.$eventHandler[
|
|
|
|
once ? 'one' : 'on'
|
|
|
|
]('ox_' + event, function(event, data) {
|
|
|
|
call(callback, data, event);
|
2011-10-01 02:21:55 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-05-28 14:02:25 +00:00
|
|
|
function call(callback, data, event) {
|
|
|
|
event.ox_type = event.type.replace(/^ox_/, '');
|
|
|
|
callback.call(that, data || {}, event);
|
|
|
|
}
|
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
function mousedown(e) {
|
|
|
|
/*
|
|
|
|
better mouse events
|
|
|
|
mousedown:
|
|
|
|
trigger mousedown
|
|
|
|
within 250 msec:
|
|
|
|
mouseup: trigger anyclick
|
|
|
|
mouseup + mousedown: trigger doubleclick
|
|
|
|
after 250 msec:
|
|
|
|
mouseup + no mousedown within 250 msec: trigger singleclick
|
|
|
|
no mouseup within 250 msec:
|
|
|
|
trigger mouserepeat every 50 msec
|
|
|
|
trigger dragstart
|
|
|
|
mousemove: trigger drag
|
|
|
|
no mousemove for 250 msec:
|
|
|
|
trigger dragpause
|
|
|
|
mouseup: trigger dragend
|
|
|
|
"anyclick" is not called "click" since this would collide with the click
|
|
|
|
events of some widgets
|
|
|
|
*/
|
|
|
|
var clientX, clientY,
|
|
|
|
dragTimeout = 0,
|
|
|
|
mouseInterval = 0;
|
2011-10-06 04:06:49 +00:00
|
|
|
if (!self._mouseTimeout) {
|
2011-10-01 02:21:55 +00:00
|
|
|
// first mousedown
|
|
|
|
that.triggerEvent('mousedown', e);
|
2011-10-06 04:06:49 +00:00
|
|
|
self._drag = false;
|
|
|
|
self._mouseup = false;
|
|
|
|
self._mouseTimeout = setTimeout(function() {
|
2011-10-01 02:21:55 +00:00
|
|
|
// 250 ms later, no subsequent click
|
2011-10-06 04:06:49 +00:00
|
|
|
self._mouseTimeout = 0;
|
|
|
|
if (self._mouseup) {
|
2011-10-01 02:21:55 +00:00
|
|
|
// mouse went up, trigger singleclick
|
|
|
|
that.triggerEvent('singleclick', e);
|
|
|
|
} else {
|
|
|
|
// mouse is still down, trigger mouserepeat
|
|
|
|
// every 50 ms until mouseleave or mouseup
|
|
|
|
mouserepeat();
|
|
|
|
mouseInterval = setInterval(mouserepeat, 50);
|
|
|
|
that.one('mouseleave', function() {
|
|
|
|
clearInterval(mouseInterval);
|
|
|
|
});
|
|
|
|
// trigger dragstart, set up drag events
|
|
|
|
that.triggerEvent('dragstart', e);
|
2012-05-28 14:02:25 +00:00
|
|
|
$('*').on({
|
2011-10-01 02:21:55 +00:00
|
|
|
mouseenter: dragenter,
|
|
|
|
mouseleave: dragleave
|
|
|
|
});
|
|
|
|
clientX = e.clientX;
|
|
|
|
clientY = e.clientY;
|
|
|
|
Ox.UI.$window
|
2012-05-28 14:02:25 +00:00
|
|
|
.off('mouseup', mouseup)
|
2011-10-01 02:21:55 +00:00
|
|
|
.mousemove(mousemove)
|
|
|
|
.one('mouseup', function(e) {
|
|
|
|
// stop checking for mouserepeat
|
2011-04-22 22:03:10 +00:00
|
|
|
clearInterval(mouseInterval);
|
2011-10-01 02:21:55 +00:00
|
|
|
// stop checking for dragpause
|
|
|
|
clearTimeout(dragTimeout);
|
|
|
|
// stop checking for drag
|
2012-05-28 14:02:25 +00:00
|
|
|
Ox.UI.$window.off('mousemove', mousemove);
|
2011-10-01 02:21:55 +00:00
|
|
|
// stop checking for dragenter and dragleave
|
2012-05-28 14:02:25 +00:00
|
|
|
$('*').off({
|
2011-10-01 02:21:55 +00:00
|
|
|
mouseenter: dragenter,
|
|
|
|
mouseleave: dragleave
|
|
|
|
});
|
|
|
|
// trigger dragend
|
|
|
|
that.triggerEvent('dragend', extend(e));
|
2011-04-22 22:03:10 +00:00
|
|
|
});
|
2011-10-06 04:06:49 +00:00
|
|
|
self._drag = true;
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-10-01 02:21:55 +00:00
|
|
|
}, 250);
|
|
|
|
} else {
|
|
|
|
// second mousedown within 250 ms, trigger doubleclick
|
2011-10-06 04:06:49 +00:00
|
|
|
clearTimeout(self._mouseTimeout);
|
|
|
|
self._mouseTimeout = 0;
|
2011-10-01 02:21:55 +00:00
|
|
|
that.triggerEvent('doubleclick', e);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-10-01 02:21:55 +00:00
|
|
|
Ox.UI.$window.one('mouseup', mouseup);
|
|
|
|
function dragenter(e) {
|
|
|
|
that.triggerEvent('dragenter', extend(e));
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-10-01 02:21:55 +00:00
|
|
|
function dragleave(e) {
|
|
|
|
that.triggerEvent('dragleave', extend(e));
|
|
|
|
}
|
|
|
|
function extend(e) {
|
|
|
|
return Ox.extend({
|
|
|
|
clientDX: e.clientX - clientX,
|
|
|
|
clientDY: e.clientY - clientY
|
|
|
|
}, e);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
|
|
|
function mousemove(e) {
|
2011-10-01 02:21:55 +00:00
|
|
|
e = extend(e);
|
2011-11-03 15:42:41 +00:00
|
|
|
clearTimeout(dragTimeout);
|
2011-10-01 02:21:55 +00:00
|
|
|
dragTimeout = setTimeout(function() {
|
|
|
|
// mouse did not move for 250 ms, trigger dragpause
|
|
|
|
that.triggerEvent('dragpause', e);
|
|
|
|
}, 250);
|
|
|
|
that.triggerEvent('drag', e);
|
|
|
|
}
|
|
|
|
function mouserepeat(e) {
|
|
|
|
that.triggerEvent('mouserepeat', e);
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-10-01 02:21:55 +00:00
|
|
|
function mouseup(e) {
|
2011-10-06 04:06:49 +00:00
|
|
|
if (!self._mouseup && !self._drag) {
|
2011-10-01 02:21:55 +00:00
|
|
|
// mouse went up for the first time, trigger anyclick
|
|
|
|
that.triggerEvent('anyclick', e);
|
2011-10-06 04:06:49 +00:00
|
|
|
self._mouseup = true;
|
2011-10-01 02:21:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
function mouseenter(e) {
|
|
|
|
that.$tooltip.show(e);
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
function mouseleave(e) {
|
|
|
|
that.$tooltip.hide();
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
function mousemove(e) {
|
|
|
|
that.$tooltip.options({
|
|
|
|
title: self.options.tooltip(e)
|
|
|
|
}).show(e);
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-11-04 22:14:30 +00:00
|
|
|
// FIXME: in other widgets, use this,
|
|
|
|
// rather than some self.$tooltip that
|
|
|
|
// will not get garbage collected
|
|
|
|
function setTooltip() {
|
|
|
|
if (self.options.tooltip) {
|
|
|
|
if (Ox.isString(self.options.tooltip)) {
|
|
|
|
that.$tooltip = Ox.Tooltip({
|
2011-12-22 07:24:20 +00:00
|
|
|
title: self.options.tooltip
|
2011-11-04 22:14:30 +00:00
|
|
|
});
|
2012-05-28 14:02:25 +00:00
|
|
|
that.on({
|
2011-11-04 22:14:30 +00:00
|
|
|
mouseenter: mouseenter
|
2012-05-28 14:02:25 +00:00
|
|
|
}).off({
|
2011-11-05 14:29:31 +00:00
|
|
|
mousemove: mousemove
|
2011-11-04 22:14:30 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
that.$tooltip = Ox.Tooltip({
|
|
|
|
animate: false
|
|
|
|
});
|
2012-05-28 14:02:25 +00:00
|
|
|
that.on({
|
2011-11-04 22:14:30 +00:00
|
|
|
mousemove: mousemove
|
2012-05-28 14:02:25 +00:00
|
|
|
}).off({
|
2011-11-05 14:29:31 +00:00
|
|
|
mouseenter: mouseenter
|
2011-11-04 22:14:30 +00:00
|
|
|
});
|
|
|
|
}
|
2012-05-28 14:02:25 +00:00
|
|
|
that.on({
|
2011-11-04 22:14:30 +00:00
|
|
|
mouseleave: mouseleave
|
|
|
|
});
|
|
|
|
} else {
|
2011-11-05 14:29:31 +00:00
|
|
|
if (that.$tooltip) {
|
|
|
|
that.$tooltip.remove();
|
2012-05-28 14:02:25 +00:00
|
|
|
that.off({
|
2011-11-05 14:29:31 +00:00
|
|
|
mouseenter: mouseenter,
|
|
|
|
mousemove: mousemove,
|
|
|
|
mouseleave: mouseleave
|
|
|
|
});
|
|
|
|
}
|
2011-11-04 22:14:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-31 11:29:59 +00:00
|
|
|
self.setOption = function(key, value) {
|
|
|
|
// self.setOption(key, value)
|
2011-10-01 02:21:55 +00:00
|
|
|
// is called when an option changes
|
|
|
|
// (to be implemented by widget)
|
2011-10-31 11:29:59 +00:00
|
|
|
if (key == 'tooltip') {
|
2011-11-04 22:14:30 +00:00
|
|
|
setTooltip();
|
2011-10-31 11:29:59 +00:00
|
|
|
}
|
2011-10-01 02:21:55 +00:00
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
/*@
|
|
|
|
bindEvent <function> Binds a function to an event
|
2012-05-28 14:02:25 +00:00
|
|
|
(callback) -> <o> This element
|
2011-10-01 02:21:55 +00:00
|
|
|
(event, callback) -> <o> This element
|
|
|
|
({event: callback, ...}) -> <o> This element
|
|
|
|
callback <f> Callback function
|
|
|
|
data <o> event data (key/value pairs)
|
|
|
|
event <s> Event name
|
|
|
|
Event names can be namespaced, like <code>'click.foo'</code>
|
|
|
|
@*/
|
|
|
|
that.bindEvent = function() {
|
2012-05-28 14:02:25 +00:00
|
|
|
if (Ox.typeOf(arguments[0]) == 'function') {
|
|
|
|
self.eventCallbacks.push(arguments[0]);
|
|
|
|
} else {
|
|
|
|
Ox.forEach(Ox.makeObject(arguments), function(callback, event) {
|
|
|
|
bind(event, callback);
|
|
|
|
});
|
|
|
|
}
|
2011-10-01 02:21:55 +00:00
|
|
|
return that;
|
2012-01-19 12:29:29 +00:00
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
/*@
|
|
|
|
bindEventOnce <function> Binds a function to an event, once
|
|
|
|
(event, callback) -> <obj> This element object
|
|
|
|
({event: callback, ...}) -> <obj> This element object
|
|
|
|
callback <f> Callback function
|
|
|
|
data <o> event data (key/value pairs)
|
|
|
|
event <s> Event name
|
|
|
|
Event names can be namespaced, like <code>'click.foo'</code>
|
|
|
|
@*/
|
|
|
|
that.bindEventOnce = function() {
|
|
|
|
Ox.forEach(Ox.makeObject(arguments), function(callback, event) {
|
2012-05-28 14:02:25 +00:00
|
|
|
bind(event, callback, true);
|
2011-10-01 02:21:55 +00:00
|
|
|
});
|
|
|
|
return that;
|
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
bindKeyboard <f> bind keyboard
|
|
|
|
() -> <o> object
|
|
|
|
@*/
|
2011-11-01 11:49:46 +00:00
|
|
|
that.bindKeyboard = function() {
|
2012-05-22 14:08:09 +00:00
|
|
|
Ox.Keyboard.bind(that.oxid);
|
2011-11-01 11:49:46 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
/*@
|
2011-12-21 13:42:47 +00:00
|
|
|
defaults <function> Gets or sets the default options for an element object
|
2011-10-01 02:21:55 +00:00
|
|
|
({key: value, ...}) -> <obj> This element object
|
|
|
|
key <str> The name of the default option
|
|
|
|
value <val> The value of the default option
|
|
|
|
@*/
|
2011-12-21 13:42:47 +00:00
|
|
|
that.defaults = function() {
|
|
|
|
var ret;
|
|
|
|
if (arguments.length == 0) {
|
|
|
|
ret = self.defaults;
|
|
|
|
} else if (Ox.isString(arguments[0])) {
|
|
|
|
ret = self.defaults[arguments[0]];
|
|
|
|
} else {
|
|
|
|
self.defaults = arguments[0];
|
|
|
|
self.options = Ox.clone(self.defaults);
|
|
|
|
ret = that;
|
|
|
|
}
|
|
|
|
return ret;
|
2011-10-01 02:21:55 +00:00
|
|
|
};
|
2011-05-05 18:02:56 +00:00
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
/*@
|
|
|
|
gainFocus <function> Makes an element object gain focus
|
|
|
|
() -> <obj> This element object
|
|
|
|
@*/
|
|
|
|
that.gainFocus = function() {
|
2012-05-22 14:08:09 +00:00
|
|
|
Ox.Focus.focus(that.oxid);
|
2011-10-01 02:21:55 +00:00
|
|
|
return that;
|
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
/*@
|
|
|
|
hasFocus <function> Returns true if an element object has focus
|
|
|
|
() -> <boolean> True if the element has focus
|
|
|
|
@*/
|
|
|
|
that.hasFocus = function() {
|
2012-05-22 14:08:09 +00:00
|
|
|
return Ox.Focus.focused() == that.oxid;
|
2011-10-01 02:21:55 +00:00
|
|
|
};
|
2011-05-05 18:02:56 +00:00
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
/*@
|
|
|
|
loseFocus <function> Makes an element object lose focus
|
|
|
|
() -> <object> This element object
|
|
|
|
@*/
|
|
|
|
that.loseFocus = function() {
|
2012-05-22 14:08:09 +00:00
|
|
|
Ox.Focus.blur(that.oxid);
|
2011-10-01 02:21:55 +00:00
|
|
|
return that;
|
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
/*@
|
|
|
|
options <function> Gets or sets the options of an element object
|
|
|
|
# Usage
|
|
|
|
() -> <obj> all options
|
|
|
|
(key) -> <any> the value of option[key]
|
|
|
|
(key, value) -> <obj> this element
|
|
|
|
Sets options[key] to value and calls self.setOption(key, value)
|
|
|
|
if the key/value pair was added or modified
|
|
|
|
({key: value, ...}) -> <obj> this element
|
|
|
|
Sets multiple options and calls self.setOption(key, value)
|
|
|
|
for every key/value pair that was added or modified
|
|
|
|
# Arguments
|
|
|
|
key <str> the name of the option
|
|
|
|
value <val> the value of the option
|
|
|
|
@*/
|
|
|
|
that.options = function() {
|
|
|
|
return Ox.getset(self.options, arguments, self.setOption, that);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*@
|
|
|
|
removeElement <function> Removes an element object and its event handler
|
|
|
|
() -> <obj> This element
|
|
|
|
@*/
|
2011-11-04 22:14:30 +00:00
|
|
|
that.remove = function(remove) {
|
2012-05-22 13:14:40 +00:00
|
|
|
remove !== false && that.find('.OxElement').each(function() {
|
2011-11-01 23:14:29 +00:00
|
|
|
var oxid = $(this).data('oxid'),
|
|
|
|
element = Ox.UI.elements[oxid];
|
2011-11-04 22:14:30 +00:00
|
|
|
element && element.remove(false);
|
2011-11-01 19:56:11 +00:00
|
|
|
});
|
2012-05-22 14:08:09 +00:00
|
|
|
Ox.Focus.remove(that.oxid);
|
|
|
|
Ox.Keyboard.unbind(that.oxid);
|
2011-10-01 02:21:55 +00:00
|
|
|
delete self.$eventHandler;
|
2012-05-22 14:08:09 +00:00
|
|
|
delete Ox.UI.elements[that.oxid];
|
2011-11-01 23:14:29 +00:00
|
|
|
that.$tooltip && that.$tooltip.remove();
|
|
|
|
remove !== false && that.$element.remove();
|
2011-10-01 02:21:55 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
setElement <f> set $element
|
|
|
|
($element) -> null
|
|
|
|
@*/
|
2011-12-21 13:42:47 +00:00
|
|
|
that.setElement = function($element) {
|
2012-05-22 14:08:09 +00:00
|
|
|
$element.addClass('OxElement').data({oxid: that.oxid});
|
2011-12-21 13:42:47 +00:00
|
|
|
that.$element.replaceWith($element);
|
|
|
|
that.$element = $element;
|
|
|
|
that[0] = that.$element[0];
|
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
toggleOption <f> toggle option
|
|
|
|
() -> <o> object
|
|
|
|
@*/
|
2011-12-21 13:42:47 +00:00
|
|
|
that.toggleOption = function() {
|
|
|
|
var options = {};
|
2012-05-19 08:40:59 +00:00
|
|
|
Ox.makeArray(arguments[0]).forEach(function(key) {
|
2011-12-21 13:42:47 +00:00
|
|
|
options[key] == !self.options[key];
|
|
|
|
});
|
|
|
|
that.options(options);
|
|
|
|
};
|
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
/*@
|
|
|
|
triggerEvent <function> Triggers an event
|
|
|
|
(event) -> <object> This element object
|
|
|
|
(event, data) -> <object> This element object
|
|
|
|
({event: data, ...}) -> <object> This element object
|
|
|
|
event <string> Event name
|
|
|
|
data <object> Event data (key/value pairs)
|
|
|
|
@*/
|
|
|
|
that.triggerEvent = function() {
|
|
|
|
Ox.forEach(Ox.makeObject(arguments), function(data, event) {
|
2012-05-28 14:02:25 +00:00
|
|
|
var type = 'ox_' + event;
|
2011-10-01 02:21:55 +00:00
|
|
|
if ([
|
|
|
|
'mousedown', 'mouserepeat', 'anyclick', 'singleclick', 'doubleclick',
|
|
|
|
'dragstart', 'drag', 'dragenter', 'dragleave', 'dragpause', 'dragend',
|
|
|
|
'draganddropstart', 'draganddrop', 'draganddropenter', 'draganddropleave', 'draganddropend',
|
2012-02-04 11:44:19 +00:00
|
|
|
'playing', 'position', 'progress', 'request'
|
2011-10-01 02:21:55 +00:00
|
|
|
].indexOf(event) == -1) {
|
|
|
|
if (!/^pandora_/.test(event)) {
|
2012-05-22 14:08:09 +00:00
|
|
|
Ox.Log('EVENT', that.oxid, self.options.id, 'trigger', event, data);
|
2011-10-01 02:21:55 +00:00
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
}
|
2011-10-01 02:21:55 +00:00
|
|
|
// it is necessary to check if self.$eventHandler exists,
|
|
|
|
// since, for example, when removing the element on click,
|
|
|
|
// singleclick will fire after the removal of the event handler
|
2012-05-28 14:02:25 +00:00
|
|
|
self.$eventHandler && self.$eventHandler.trigger(type, data);
|
|
|
|
self.eventCallbacks.forEach(function(callback) {
|
|
|
|
call(callback, data, {type: type});
|
|
|
|
});
|
2011-10-01 02:21:55 +00:00
|
|
|
});
|
|
|
|
return that;
|
|
|
|
};
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
/*@
|
|
|
|
unbindEvent <function> Unbinds all callbacks from an event
|
|
|
|
To unbind a specific handler, use namespaced events, like
|
|
|
|
<code>bindEvent('click.foo', callback)</code>, and then
|
|
|
|
<code>unbindEvent('click.foo')</code>.
|
2012-05-28 14:02:25 +00:00
|
|
|
() -> <object> This element
|
|
|
|
Unbinds all callbacks from all events
|
|
|
|
(callback) -> <o> This element
|
|
|
|
Unbinds one callback from all events
|
|
|
|
(event) -> <o> This element
|
|
|
|
Unbinds all callbacks from one event
|
|
|
|
(event, callback) -> <o> This element
|
|
|
|
Unbinds one callback from one event
|
|
|
|
({event: callback}, ...) -> <o> This element
|
|
|
|
Unbinds multiple callbacks from multiple events
|
2011-10-01 02:21:55 +00:00
|
|
|
event <string> Event name
|
|
|
|
@*/
|
|
|
|
that.unbindEvent = function() {
|
2012-05-28 14:02:25 +00:00
|
|
|
var callback = arguments[0];
|
2011-10-01 02:21:55 +00:00
|
|
|
if (arguments.length == 0) {
|
2012-05-28 14:02:25 +00:00
|
|
|
self.eventCallbacks = [];
|
|
|
|
self.$eventHandler.off();
|
|
|
|
} else if (Ox.typeOf(callback) == 'function') {
|
|
|
|
self.eventCallbacks = self.eventCallbacks.filter(function(fn) {
|
|
|
|
return fn !== callback;
|
|
|
|
});
|
2011-10-01 02:21:55 +00:00
|
|
|
} else {
|
2012-05-28 14:02:25 +00:00
|
|
|
Ox.makeObject(arguments).forEach(function(callback, event) {
|
|
|
|
self.$eventHandler.off('ox_' + event, callback);
|
2011-10-01 02:21:55 +00:00
|
|
|
});
|
|
|
|
}
|
2011-04-22 22:03:10 +00:00
|
|
|
return that;
|
2011-10-01 02:21:55 +00:00
|
|
|
};
|
|
|
|
|
2012-05-21 10:38:18 +00:00
|
|
|
/*@
|
|
|
|
unbindKeyboard <f> unbind keyboard
|
|
|
|
() -> <o> object
|
|
|
|
@*/
|
2011-11-01 11:49:46 +00:00
|
|
|
that.unbindKeyboard = function() {
|
2012-05-22 14:08:09 +00:00
|
|
|
Ox.Keyboard.unbind(that.oxid);
|
2011-11-01 11:49:46 +00:00
|
|
|
return that;
|
|
|
|
};
|
|
|
|
|
2011-12-21 15:33:52 +00:00
|
|
|
/*@
|
|
|
|
value <f> Shortcut to get or set self.options.value
|
|
|
|
@*/
|
|
|
|
that.value = function() {
|
|
|
|
return that.options(
|
|
|
|
arguments.length == 0 ? 'value' : {value: arguments[0]}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2011-10-01 02:21:55 +00:00
|
|
|
return that;
|
2011-04-22 22:03:10 +00:00
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
};
|