");
//delete $element.length;
Ox.each($element, function(k, v) {
if (typeof v == "function") {
functions.push(k);
}
});
return functions.sort();
}(),
path: $("script[src*=ox.ui.js]").attr("src")
.replace("js/ox.ui.js", ""),
stack: [], // fixme: used?
symbols: { // fixme: make lowercase
alt: "\u2325",
apple: "\uF8FF",
arrow_down: "\u2193",
arrow_left: "\u2190",
"arrow right": "\u2192",
"arrow up": "\u2191",
"backspace": "\u232B",
"backup": "\u2707",
"ballot": "\u2717",
"black star": "\u2605",
"burn": "\u2622",
"caps lock": "\u21EA",
"check": "\u2713",
"CLEAR": "\u2327",
"CLICK": "\uF803",
"CLOSE": "\u2715",
"COMMAND": "\u2318",
"CONTROL": "\u2303",
"CUT": "\u2702",
"DELETE": "\u2326",
"DIAMOND": "\u25C6",
"EDIT": "\uF802",
"EJECT": "\u23CF",
"ESCAPE": "\u238B",
"END": "\u2198",
"ENTER": "\u2324",
"FLY": "\u2708",
"GEAR": "\u2699",
"HOME": "\u2196",
"INFO": "\u24D8",
"NAVIGATE": "\u2388",
"OPTION": "\u2387",
"PAGE UP": "\u21DE",
"PAGE DOWN": "\u21DF",
"REDO": "\u21BA",
"RETURN": "\u21A9",
"SELECT": "\u21D5",
"SHIFT": "\u21E7",
"SOUND": "\u266B",
"SPACE": "\u2423",
"TAB": "\u21E5",
"TRASH": "\u267A",
"TRIANGLE DOWN": "\u25BC",
"TRIANGLE LEFT": "\u25C0",
triangle_right: "\u25BA",
"TRIANGLE UP": "\u25B2",
"UNDO": "\u21BB",
"VOLTAGE": "\u26A1",
"WARNING": "\u26A0",
"WHITE STAR": "\u2606"
}
},
$window, $document, $body;
$(function() {
$window = $(window),
$document = $(document),
$body = $("body");
Ox.theme(oxui.defaultTheme);
})
/*
============================================================================
Application
============================================================================
*/
/*
----------------------------------------------------------------------------
Ox.App
----------------------------------------------------------------------------
*/
Ox.App = function() {
/*
options:
requestTimeout
requestType
requestURL
*/
return function(options) {
options = options || {};
var self = {},
that = this;
self.options = $.extend({
requestTimeout: oxui.requestTimeout,
requestType: oxui.requestType,
requestURL: oxui.requestURL
}, options);
self.change = function() {
};
that.launch = function() {
$.ajaxSetup({
timeout: self.options.requestTimeout,
type: self.options.requestType,
url: self.options.requestURL
});
};
that.options = function() {
return Ox.getset(self.options, Array.slice.call(arguments), self.change, that);
};
that.request = function(action, data, callback) {
if (arguments.length == 2) {
callback = data;
data = {};
}
return Ox.Request.send({
url: self.options.requestURL,
data: {
action: action,
data: JSON.stringify(data)
},
callback: callback
});
};
return that;
};
}();
/*
----------------------------------------------------------------------------
Ox.Event
----------------------------------------------------------------------------
naming convention for event/trigger
verb.id.namespace, i.e. verb.sourceId.targetId (?)
...
bind("keydown.shift+dot.numpad", function() {
// ...
})
keyboard handler then would:
$.each(stack, function(i, v) {
elements[v].trigger("keydown.shift+0.numpad");
});
and the element would implement
this.trigger(event, data) {
}
...
keyboard handler also triggers keydown.buffer
*/
// use dom elements / jquery instead
Ox.Event = function() {
var $eventHandler = $("
");
return {
bind: function(event, callback) {
$eventHandler.bind(event, callback);
},
trigger: function(event, data) {
$eventHandler.trigger(event, data);
},
unbind: function(event) {
$eventHandler.unbind(event, callback);
}
}
}
Ox.Event_ = function() {
var events = {};
return {
// make these bind, trigger, unbind
publish: function(event, data) {
console.log("publish", event, data);
if (events[event]) {
$.each(events[event], function(i, v) {
setTimeout(function() {
v(data);
}, 0);
});
}
},
subscribe: function(event, callback) {
console.log("subscribe", event, callback);
if (events[event]) {
events[event].push(callback);
} else {
events[event] = [callback];
}
},
unsubscribe: function(event, callback) {
console.log("unsubscribe", event, callback);
$.each(events[event], function(i, v) {
if (Ox.startsWith(callback.toString(), v.toString())) {
events[event].splice(i, 1);
}
});
}
};
}();
/*
----------------------------------------------------------------------------
Ox.Focus
----------------------------------------------------------------------------
*/
Ox.Focus = function() {
var stack = [];
return {
focus: function(id) {
var index = stack.indexOf(id);
if (index > -1) {
oxui.stack.splice(i, 1);
}
oxui.stack.push(id);
},
blur: function(id) {
oxui.stack.pop();
}
};
}();
/*
----------------------------------------------------------------------------
Ox.History
----------------------------------------------------------------------------
*/
/*
----------------------------------------------------------------------------
Ox.Keyboard
----------------------------------------------------------------------------
*/
(function() {
var buffer = "",
bufferTime = 0,
bufferTimeout = 1000,
keyNames = function() {
return {
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",
91: "meta.left",
92: "meta.right",
93: "select",
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"
// see dojo, for ex.
};
}(),
modifierNames = {
altKey: "alt", // mac: option
ctrlKey: "control",
metaKey: "meta", // mac: command
shiftKey: "shift"
};
return function() {
document.keydown(keydown);
function keydown(e) {
var key = [],
ret = true,
time;
$.each(modifierNames, function(k, v) {
if (e[k]) {
key.push(v);
}
});
// avoid pushing modifier twice
if (keyNames[e.keyCode] && keys.indexOf(keyNames[e.keyCode]) == -1) {
key.push(keyNames[e.keyCode]);
}
key = key.join(" ");
if (key.match(/^[\w\d-]$|SPACE/)) {
time = Ox.time();
if (time - bufferTime > bufferTimeout) {
buffer = "";
}
buffer += key == "SPACE" ? " " : key;
bufferTime = time;
}
$.each(stack, function(i, v) {
// fixme: we dont get the return value!
ret = Ox.event.publish(keyboard + Ox.toCamelCase(key) + "." + v);
return ret;
});
}
};
})();
/*
----------------------------------------------------------------------------
Ox.Mouse (??)
----------------------------------------------------------------------------
*/
/*
----------------------------------------------------------------------------
Ox.Request
----------------------------------------------------------------------------
*/
Ox.Request = function() {
var cache = {},
pending = {},
requests = {},
self = {
options: {
timeout: 15000,
type: "POST",
url: "api"
}
};
return {
cancel: function() {
var index;
if (arguments.length == 0) {
requests = {};
} else if (Ox.isFunction(arguments[0])) {
// cancel with function
$.each(requests, function(id, req) {
if (arguments[0](req)) {
delete requests[id];
}
})
} else {
// cancel by id
delete requests[arguments[0]]
}
},
emptyCache: function() {
cache = {};
},
options: function(options) {
return Ox.getset(self.options, options, $.noop(), this);
},
send: function(options) {
options = $.extend({
age: -1,
callback: function() {},
id: Ox.uid(),
timeout: self.options.timeout,
type: self.options.type,
url: self.options.url
}, options);
var req = JSON.stringify({
url: options.url,
data: options.data
});
function callback(data) {
delete requests[options.id];
options.callback(data);
}
function debug(request) {
var $iframe = $("