forked from 0x2620/oxjs
various documentation-related changes
This commit is contained in:
parent
b6fdf0c28b
commit
a6ed310087
13 changed files with 880 additions and 301 deletions
|
|
@ -1,11 +1,67 @@
|
|||
// vim: et:ts=4:sw=4:sts=4:ft=js
|
||||
// check out http://ejohn.org/apps/learn/#36 (-#38, making fns work w/o new)
|
||||
|
||||
Ox.Element = function() {
|
||||
/*@
|
||||
Ox.Element <function:Ox.JQueryElement> Basic UI element object
|
||||
# Usage --------------------------------------------------------------------
|
||||
([options[, self]]) -> <object> UI element
|
||||
# Arguments ----------------------------------------------------------------
|
||||
options <object> the options of the element
|
||||
# Properties
|
||||
element <string> tagname or CSS selector
|
||||
tooltip <object> tooltip (not implemented)
|
||||
options <string> tagname or CSS selector
|
||||
self <object> shared private variable
|
||||
# Properties ---------------------------------------------------------------
|
||||
$element <object> jQuery DOM object
|
||||
bindEvent <function> binds an event to a function, once
|
||||
# Usage
|
||||
(event, callback) -> <object> this element
|
||||
({event: callback, ...}) -> <object> this element
|
||||
# Arguments
|
||||
event <string> event name
|
||||
callback <function> callback function
|
||||
data <object> event data
|
||||
bindEventOnce <function> binds an event to a function
|
||||
defaults <function> sets the default options
|
||||
options <function> sets the options
|
||||
triggerEvent <function> triggers an event
|
||||
unbindEvent <function> unbinds an event
|
||||
# Events -------------------------------------------------------------------
|
||||
anyclick <event> anyclick
|
||||
fires on mouseup, but not on any subsequent mouseup within 250 ms
|
||||
* <*> original event properties
|
||||
doubleclick <event> doubleclick
|
||||
fires on the second mousedown within 250 ms
|
||||
* <*> original event properties
|
||||
drag <event> drag
|
||||
fires on mousemove after dragstart, stops firing on mouseup
|
||||
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
|
||||
dragpause <event> dragpause
|
||||
Fires once when the mouse doesn't move for 250 ms after drag
|
||||
clientDX <number> horizontal drag delta in px
|
||||
clientDY <number> vertical drag delta in px
|
||||
* <*> original event properties
|
||||
dragstart <event> dragstart
|
||||
fires when the mouse is down for 250 ms
|
||||
* <*> original event properties
|
||||
mouserepeat <event> mouserepeat
|
||||
fires every 50 ms after the mouse was down for 250 ms, stops firing on
|
||||
mouseleave or mouseup
|
||||
* <*> original event properties
|
||||
singleclick <event> singleclick
|
||||
fires 250 ms after mouseup, if there was no subsequent mousedown
|
||||
* <*> original event properties
|
||||
@*/
|
||||
|
||||
/***
|
||||
Basic element object
|
||||
***/
|
||||
Ox.Element = function() {
|
||||
|
||||
/*
|
||||
tooltip option can be any of the following:
|
||||
|
|
@ -137,7 +193,7 @@ Ox.Element = function() {
|
|||
that.triggerEvent('mouserepeat');
|
||||
}
|
||||
function mouseup(e) {
|
||||
// only trigger on firse mouseup
|
||||
// only trigger on first mouseup
|
||||
if (!self.mouseup) {
|
||||
that.triggerEvent('anyclick', e);
|
||||
self.mouseup = true;
|
||||
|
|
@ -173,19 +229,29 @@ Ox.Element = function() {
|
|||
|
||||
that._self = self; // fixme: remove
|
||||
|
||||
/*@
|
||||
bindEvent <function> Binds a function to an event
|
||||
(event, callback) -> <f> This element
|
||||
({event: callback, ...}) -> <f> This element
|
||||
callback <f> Callback function
|
||||
data <o> event data (key/value pairs)
|
||||
event <s> Event name (can be namespaced, like "click.foo")
|
||||
@*/
|
||||
that.bindEvent = function() {
|
||||
/***
|
||||
binds a function to an event triggered by this object
|
||||
Usage
|
||||
bindEvent(event, fn)
|
||||
bindEvent({eventA: fnA, eventB: fnB, ...})
|
||||
***/
|
||||
Ox.forEach(Ox.makeObject(arguments), function(fn, event) {
|
||||
bind('bind', event, fn);
|
||||
});
|
||||
return that;
|
||||
}
|
||||
|
||||
/*@
|
||||
bindEventOnce <function> Binds a function to an event, once
|
||||
(event, callback) -> <f> This element
|
||||
({event: callback, ...}) -> <f> This element
|
||||
callback <f> Callback function
|
||||
data <o> event data (key/value pairs)
|
||||
event <s> Event name (can be namespaced, like "click.foo")
|
||||
@*/
|
||||
that.bindEventOnce = function() {
|
||||
Ox.forEach(Ox.makeObject(arguments), function(fn, event) {
|
||||
bind('one', event, fn);
|
||||
|
|
@ -193,6 +259,13 @@ Ox.Element = function() {
|
|||
return that;
|
||||
};
|
||||
|
||||
/*@
|
||||
Sets the default options for an element object
|
||||
({key: value, ...}) -> <f>
|
||||
key <str> the name of the default option
|
||||
that <obj> the element object
|
||||
value <val> the value of the default option
|
||||
@*/
|
||||
that.defaults = function(defaults) {
|
||||
// sets the default options
|
||||
self.defaults = defaults;
|
||||
|
|
@ -200,43 +273,54 @@ Ox.Element = function() {
|
|||
return that;
|
||||
};
|
||||
|
||||
/*@
|
||||
Makes an element object gain focus
|
||||
() -> that
|
||||
that <obj> the element object
|
||||
@*/
|
||||
that.gainFocus = function() {
|
||||
/***
|
||||
make this object gain focus
|
||||
***/
|
||||
Ox.Focus.focus(that.id);
|
||||
return that;
|
||||
};
|
||||
|
||||
/*@
|
||||
Returns true if an element object has focus
|
||||
() -> hasFocus
|
||||
hasFocus <boolean> true if the element has focus
|
||||
@*/
|
||||
that.hasFocus = function() {
|
||||
/***
|
||||
returns true if this object has focus
|
||||
***/
|
||||
return Ox.Focus.focused() == that.id;
|
||||
};
|
||||
|
||||
/*@
|
||||
Makes an element object lose focus
|
||||
() -> that
|
||||
that <object> the element object
|
||||
@*/
|
||||
|
||||
that.loseFocus = function() {
|
||||
/***
|
||||
make this object lose focus
|
||||
***/
|
||||
Ox.Focus.blur(that.id);
|
||||
return that;
|
||||
};
|
||||
|
||||
/*@
|
||||
.options()
|
||||
Gets or sets the options of an element object
|
||||
# Usage
|
||||
() -> <obj> all options
|
||||
(key) -> <val> 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() {
|
||||
/*
|
||||
that.options()
|
||||
returns self.options
|
||||
that.options(key)
|
||||
returns self.options.key
|
||||
that.options(key, val)
|
||||
sets self.options.key to val, calls self.setOption(key, val)
|
||||
if the key has been added or its val has changed, returns that
|
||||
that.options({keyA: valA, keyB: valB})
|
||||
sets self.options.keyA to valA and self.options.keyB to valB,
|
||||
calls self.setOptions(key, val) for every key/value pair
|
||||
that has been added or modified, returns that
|
||||
*/
|
||||
return Ox.getset(self.options, arguments, self.setOption, that);
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue