'), function(val, key) {
if (Ox.isFunction(val)) {
Ox.JQueryElement.prototype[key] = function() {
@@ -31,7 +39,7 @@ Ox.forEach($('
'), function(val, key) {
// if the $element of an ox object was returned
// then return the ox object instead
// so that we can do oxObj.jqFn().oxFn()
- return ret.jquery && Ox.UI.elements[id = ret.data('oxid')] ?
+ return ret && ret.jquery && Ox.UI.elements[id = ret.data('oxid')] ?
Ox.UI.elements[id] : ret;
};
}
diff --git a/source/Ox.UI/js/Core/Ox.Keyboard.js b/source/Ox.UI/js/Core/Ox.Keyboard.js
index 65351cf9..144465f2 100644
--- a/source/Ox.UI/js/Core/Ox.Keyboard.js
+++ b/source/Ox.UI/js/Core/Ox.Keyboard.js
@@ -5,46 +5,7 @@
(function() {
- var buffer = '',
- // the dot notation ('0.numpad') makes the keyboard event ('key_0.numpad')
- // namespaced, so that binding to 'key_0' will catch 'key_0.numpad' too
- keyNames = {
- 0: 'section', 8: 'backspace', 9: 'tab', 12: 'clear', 13: 'enter',
- 16: 'shift', 17: 'control', 18: 'alt', 20: 'capslock', 27: 'escape',
- 32: 'space', 33: 'pageup', 34: 'pagedown', 35: 'end', 36: 'home',
- 37: 'left', 38: 'up', 39: 'right', 40: 'down',
- 45: 'insert', 46: 'delete', 47: 'help',
- 48: '0', 49: '1', 50: '2', 51: '3', 52: '4',
- 53: '5', 54: '6', 55: '7', 56: '8', 57: '9',
- 65: 'a', 66: 'b', 67: 'c', 68: 'd', 69: 'e',
- 70: 'f', 71: 'g', 72: 'h', 73: 'i', 74: 'j',
- 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
- 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't',
- 85: 'u', 86: 'v', 87: 'w', 88: 'x', 89: 'y', 90: 'z',
- // fixme: this is usually 91: window.left, 92: window.right, 93: select
- 91: 'meta.left', 92: 'meta.right', 93: 'meta.right',
- 96: '0.numpad', 97: '1.numpad', 98: '2.numpad', 99: '3.numpad',
- 100: '4.numpad', 101: '5.numpad', 102: '6.numpad', 103: '7.numpad',
- 104: '8.numpad', 105: '9.numpad', 106: 'asterisk.numpad', 107: 'plus.numpad',
- 109: 'minus.numpad', 108: 'enter.numpad', 110: 'dot.numpad', 111: 'slash.numpad',
- 112: 'f1', 113: 'f2', 114: 'f3', 115: 'f4', 116: 'f5',
- 117: 'f6', 118: 'f7', 119: 'f8', 120: 'f9', 121: 'f10',
- 122: 'f11', 123: 'f12', 124: 'f13', 125: 'f14', 126: 'f15', 127: 'f16',
- 144: 'numlock', 145: 'scrolllock',
- 186: 'semicolon', 187: 'equal', 188: 'comma', 189: 'minus',
- 190: 'dot', 191: 'slash', 192: 'backtick', 219: 'openbracket',
- 220: 'backslash', 221: 'closebracket', 222: 'quote', 224: 'meta'
- // see dojo, for ex.
- },
- // meta comes last so that we can differentiate between
- // alt_control_shift_meta.left and alt_control_shift_meta.right
- modifierNames = {
- altKey: 'alt', // Mac: option
- ctrlKey: 'control',
- shiftKey: 'shift',
- metaKey: 'meta', // Mac: command
- },
- resetTimeout, triggerTimeout;
+ var buffer = '', resetTimeout, triggerTimeout;
/*
Ox.UI.ready(function() {
@@ -59,10 +20,10 @@
if ($element.length) {
if (
(
- keyNames[event.keyCode] == 'up' &&
+ Ox.KEYS[event.keyCode] == 'up' &&
$element[0].selectionStart + $element[0].selectionEnd == 0
) || (
- keyNames[event.keyCode] == 'down' &&
+ Ox.KEYS[event.keyCode] == 'down' &&
$element[0].selectionStart == $element.val().length &&
$element[0].selectionEnd == $element.val().length
)
@@ -82,27 +43,41 @@
});
function keydown(event) {
+
var focused = Ox.Focus.focused(),
key,
- keyName = keyNames[event.keyCode] || '',
+ keyName = Ox.KEYS[event.keyCode] || '',
+ keyNames = keyName ? [keyName] : [],
keyBasename = keyName.split('.')[0],
- keys = keyName ? [keyName] : [];
- Ox.forEach(modifierNames, function(v, k) {
+ ret = true;
+
+ Ox.forEach(Ox.MODIFIER_KEYS, function(v, k) {
// avoid pushing modifier twice
if (event[k] && keyBasename != v) {
- keys.splice(-1, 0, v);
+ keyNames.splice(-1, 0, v);
}
});
- key = keys.join('_');
- if (/^(shift_)?[a-z]$|^\d(\.numpad)?$|space/.test(key)) {
+ key = keyNames.join('_');
+ if (focused !== null) {
+ Ox.UI.elements[focused].triggerEvent('key_' + key);
+ // prevent Chrome from going back in history, or scrolling
+ if (
+ [
+ 'backspace', 'down', 'left', 'right', 'space', 'up'
+ ].indexOf(keyBasename) > -1 &&
+ !Ox.UI.elements[focused].hasClass('OxInput')
+ ) {
+ ret = false;
+ }
+ }
+
+ if (/^[\w\d](\.numpad)?$|space/.test(key)) {
// don't register leading spaces or trailing double spaces
if (!(keyName == 'space' && (buffer == '' || / $/.test(buffer)))) {
buffer += keyName == 'space' ? ' ' : keyBasename;
- Ox.print('buffer', buffer)
// clear the trigger timeout only if the key went into the buffer
clearTimeout(triggerTimeout);
triggerTimeout = setTimeout(function() {
- Ox.print('buffer', buffer)
focused !== null && Ox.UI.elements[focused].triggerEvent('keys', {
keys: buffer
});
@@ -114,16 +89,10 @@
resetTimeout = setTimeout(function() {
buffer = '';
}, 1000);
- if (focused !== null) {
- Ox.UI.elements[focused].triggerEvent('key_' + key);
- // prevent Chrome from going back in history, or scrolling
- if (
- ['backspace', 'down', 'left', 'right', 'space', 'up'].indexOf(key) > -1 &&
- !Ox.UI.elements[focused].hasClass('OxInput')
- ) {
- return false;
- }
- }
+
+ Ox.print(ret)
+ return ret;
+
}
})();
diff --git a/source/Ox.UI/js/Core/Ox.SyntaxHighlighter.js b/source/Ox.UI/js/Core/Ox.SyntaxHighlighter.js
index 67e2a669..f8739060 100644
--- a/source/Ox.UI/js/Core/Ox.SyntaxHighlighter.js
+++ b/source/Ox.UI/js/Core/Ox.SyntaxHighlighter.js
@@ -39,12 +39,11 @@ Ox.SyntaxHighlighter = function(options, self) {
self.source = '';
self.tokens = Ox.tokenize(self.options.source);
self.tokens.forEach(function(token, i) {
- var classNames, tokenString;
+ var classNames;
if (
!(self.options.stripComments && token.type == 'comment')
) {
classNames = 'Ox' + Ox.toTitleCase(token.type);
- tokenString = self.options.source.substr(self.cursor, token.length);
if (token.type == 'whitespace') {
if (isAfterLinebreak() && hasIrregularSpaces()) {
classNames += ' OxLeading'
@@ -53,7 +52,7 @@ Ox.SyntaxHighlighter = function(options, self) {
}
}
self.source += '
' +
- encodeToken(tokenString, token.type) + '';
+ encodeToken(token.source, token.type) + '';
}
self.cursor += token.length;
function isAfterLinebreak() {
@@ -65,7 +64,7 @@ Ox.SyntaxHighlighter = function(options, self) {
self.tokens[i + 1].type == 'linebreak';
}
function hasIrregularSpaces() {
- return tokenString.split('').reduce(function(prev, curr) {
+ return token.source.split('').reduce(function(prev, curr) {
return prev + (curr == ' ' ? 1 : 0);
}, 0) % self.options.tabLength;
}
@@ -108,24 +107,24 @@ Ox.SyntaxHighlighter = function(options, self) {
.html(self.source)
.appendTo(that);
- function encodeToken(str, type) {
+ function encodeToken(source, type) {
var linebreak = '
',
tab = Ox.repeat(' ', self.options.tabLength);
if (self.options.showLinebreaks) {
if (type == 'linebreak') {
- linebreak = '¶' + linebreak;
+ linebreak = '\u21A9' + linebreak;
} else {
- linebreak = '
¶' + linebreak;
+ linebreak = '
\u21A9' + linebreak;
}
}
if (self.options.showTabs) {
tab = '
\u2192' + tab.substr(6) + '';
}
- str = Ox.encodeHTML(str)
+ source = Ox.encodeHTML(source)
.replace(/ /g, ' ')
.replace(/\t/g, tab)
.replace(/\n/g, linebreak);
- return str;
+ return source;
}
self.setOption = function() {
diff --git a/source/Ox.UI/js/List/Ox.List.js b/source/Ox.UI/js/List/Ox.List.js
index cbe48e6b..8b20bdd6 100644
--- a/source/Ox.UI/js/List/Ox.List.js
+++ b/source/Ox.UI/js/List/Ox.List.js
@@ -1,4 +1,14 @@
// vim: et:ts=4:sw=4:sts=4:ft=js
+
+/*@
+Basic list object
+(options) -> that
+(options, self) -> that
+options
the list's options
+self shared private variable
+@*/
+
+
Ox.List = function(options, self) {
/***
@@ -17,23 +27,26 @@ Ox.List = function(options, self) {
var self = self || {},
that = new Ox.Container({}, self)
.defaults({
- centered: false,
- construct: null,
- draggable: false,
- format: [],
- itemHeight: 16,
- items: null,
- itemWidth: 16,
- keys: [],
- max: -1,
- min: 0,
- orientation: 'vertical',
- pageLength: 100,
- selected: [],
- sort: [],
- sortable: false,
- type: 'text',
- unique: ''
+ centered: false, //@ if true, and orientation is 'horizontal',
+ //@ then keep the selected item centered
+ construct: null, //@ (data) returns the list item HTML
+ draggable: false, //@ true if the items can be reordered
+ format: [], //@ ???
+ itemHeight: 16, //@ item height
+ items: null, //@ list items
+ //@ (data) returns {items, size, ...}
+ //@ (data, callback) returns [items]
+ itemWidth: 16, //@ item width
+ keys: [], //@ keys of the list items
+ max: -1, //@ max number of items that can be selected
+ min: 0, //@ min number of items that must be selected
+ orientation: 'vertical', //@ 'horizontal' or 'vertical'
+ pageLength: 100, //@ number of items per page
+ selected: [], //@ ids of the selected elements
+ sort: [], //@
+ sortable: false, //@
+ type: 'text', //@
+ unique: '' //@ name of the key that acts as unique id
})
.options(options || {})
.scroll(scroll);
diff --git a/source/Ox.UI/js/Map/Ox.Map.js b/source/Ox.UI/js/Map/Ox.Map.js
index 0c6b0408..02938071 100644
--- a/source/Ox.UI/js/Map/Ox.Map.js
+++ b/source/Ox.UI/js/Map/Ox.Map.js
@@ -1,5 +1,89 @@
// vim: et:ts=4:sw=4:sts=4:ft=js
+/*@
+Ox.Map Basic map object
+ # DESCRIPTION --------------------------------------------------------------
+ Ox.Map
is a wrapper around the
+ Google
+ Maps API.
+ # USAGE --------------------------------------------------------------------
+ () -> Map object
+ (options) -> Map object
+ (options, self) -> Map object
+ # ARGUMENTS ----------------------------------------------------------------
+ options options
+ clickable If true, clicking on the map finds a place
+ editable If true, places are editable
+ findPlaceholder Placeholder text for the find input element
+ labels If true, show labels on the map
+ markers Maximum number of markers to be displayed
+ places <[o]|[]> Array of place objects
+ countryCode ISO 3166 country code
+ east Longitude of the eastern boundary in degrees
+ editable If true, the place is editable
+ geoname Geoname (like "Paris, Île-de-France, France")
+ lat Latitude in degrees
+ lng Longitude in degrees
+ markerColor CSS color of the place marker
+ markerSize size of the place marker in px
+ name Name (like "Paris")
+ north Latitude of the northern boundary in degrees
+ south Latitude of the southern boundary in degrees
+ type Type (like "city" or "country")
+ west Longitude of the western boundary in degrees
+ selected Id of the selected place
+ statusbar If true, the map has a statusbar
+ toolbar If true, the map has a toolbar
+ self Shared private variable
+ # EVENTS -------------------------------------------------------------------
+ addplace Fires when a place has been added
+ place Place object
+ editplace Fires when a place has been edited
+ place Place object
+ geocode Fires when a google geocode request returns
+ latLng Query coordinates, or undefined
+ lat latitude
+ lng longitude
+ address Query string, or undefined
+ results <[o]> Google Maps geocode results
+ address_components <[o]> Address components
+ long_name Long name
+ short_name Short name
+ types <[s]> Types (like "country" or "political")
+ formatted_address Formatted address
+ geometry Geometry
+ bounds Bounds
+ northEast North-east corner
+ lat Latitude
+ lng Longitude
+ southWest South-west corner
+ lat Latitude
+ lng Longitude
+ location Location
+ lat Latitude
+ lng Longitude
+ location_type Location type (like "APPROXIMATE")
+ viewport Viewport
+ northEast North-east corner
+ lat Latitude
+ lng Longitude
+ southWest South-west corner
+ lat Latitude
+ lng Longitude
+ types <[s]> Types (like "country" or "political")
+ # EXAMPLES -----------------------------------------------------------------
+
+ > Ox.Map() === true
+ false
+ > Ox.Map() === false
+ false
+@*/
+
Ox.Map = function(options, self) {
self = self || {};
diff --git a/source/Ox.js b/source/Ox.js
index f25e1312..e36c0819 100644
--- a/source/Ox.js
+++ b/source/Ox.js
@@ -1,6 +1,16 @@
// vim: et:ts=4:sw=4:sts=4:ft=js
// todo: check http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
+// also see https://github.com/tlrobinson/narwhal/blob/master/lib/util.js
+
+
+/*@
+Ox The Ox object
+ See Ox.wrap for details.
+ (value) -> wrapped value
+ value <*> any value
+@*/
+
Ox = function(val) {
return Ox.wrap(val);
};
@@ -11,48 +21,77 @@ Constants
================================================================================
*/
+//@ Ox.AMPM <[str]> ['AM', 'PM']
Ox.AMPM = ['AM', 'PM'];
-//Ox.DAYS = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
+//@ Ox.DURATIONS <[str]> ['year', 'month', 'day', 'minute', 'second']
Ox.DURATIONS = ['year', 'month', 'day', 'minute', 'second'];
+//@ Ox.EARTH_RADIUS Radius of the earth in meters
Ox.EARTH_RADIUS = 6378137;
+//@ Ox.EARTH_CIRCUMFERENCE Circumference of the earth in meters
Ox.EARTH_CIRCUMFERENCE = Ox.EARTH_RADIUS * 2 * Math.PI;
+//@ Ox.HTML_ENTITIES