uki 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.gitmodules +3 -0
- data/LICENSE +20 -0
- data/Rakefile +23 -0
- data/Readme.rdoc +9 -0
- data/VERSION +1 -0
- data/bin/uki +102 -0
- data/frameworks/jspec/lib/images/bg.png +0 -0
- data/frameworks/jspec/lib/images/hr.png +0 -0
- data/frameworks/jspec/lib/images/loading.gif +0 -0
- data/frameworks/jspec/lib/images/sprites.bg.png +0 -0
- data/frameworks/jspec/lib/images/sprites.png +0 -0
- data/frameworks/jspec/lib/images/vr.png +0 -0
- data/frameworks/jspec/lib/jspec.css +149 -0
- data/frameworks/jspec/lib/jspec.growl.js +115 -0
- data/frameworks/jspec/lib/jspec.jquery.js +72 -0
- data/frameworks/jspec/lib/jspec.js +1756 -0
- data/frameworks/jspec/lib/jspec.shell.js +39 -0
- data/frameworks/jspec/lib/jspec.timers.js +90 -0
- data/frameworks/jspec/lib/jspec.xhr.js +195 -0
- data/frameworks/uki/README.rdoc +179 -0
- data/frameworks/uki/compiler.jar +0 -0
- data/frameworks/uki/run.rb +2 -0
- data/frameworks/uki/spec/commands/example_command.rb +19 -0
- data/frameworks/uki/spec/dom.html +39 -0
- data/frameworks/uki/spec/support/images/bg.png +0 -0
- data/frameworks/uki/spec/support/images/hr.png +0 -0
- data/frameworks/uki/spec/support/images/loading.gif +0 -0
- data/frameworks/uki/spec/support/images/sprites.bg.png +0 -0
- data/frameworks/uki/spec/support/images/sprites.png +0 -0
- data/frameworks/uki/spec/support/images/vr.png +0 -0
- data/frameworks/uki/spec/support/jspec.css +149 -0
- data/frameworks/uki/spec/support/jspec.js +1773 -0
- data/frameworks/uki/spec/support/jspec.xhr.js +193 -0
- data/frameworks/uki/spec/support/spec.helper.js +1 -0
- data/frameworks/uki/spec/unit/background.spec.js +29 -0
- data/frameworks/uki/spec/unit/builder.spec.js +51 -0
- data/frameworks/uki/spec/unit/data/model.spec.js +29 -0
- data/frameworks/uki/spec/unit/dom/dnd.spec.js +71 -0
- data/frameworks/uki/spec/unit/dom/event.spec.js +78 -0
- data/frameworks/uki/spec/unit/dom.spec.js +28 -0
- data/frameworks/uki/spec/unit/geometry.spec.js +79 -0
- data/frameworks/uki/spec/unit/selector.spec.js +140 -0
- data/frameworks/uki/spec/unit/theme/template.spec.js +31 -0
- data/frameworks/uki/spec/unit/utils.spec.js +176 -0
- data/frameworks/uki/spec/unit/view/base.spec.js +86 -0
- data/frameworks/uki/spec/unit/view/container.spec.js +73 -0
- data/frameworks/uki/spec/unit/view.spec.js +13 -0
- data/frameworks/uki/src/airport.js +1 -0
- data/frameworks/uki/src/uki-core/attachment.js +175 -0
- data/frameworks/uki/src/uki-core/background/css.js +37 -0
- data/frameworks/uki/src/uki-core/background/cssBox.js +73 -0
- data/frameworks/uki/src/uki-core/background/multi.js +20 -0
- data/frameworks/uki/src/uki-core/background/null.js +10 -0
- data/frameworks/uki/src/uki-core/background/rows.js +77 -0
- data/frameworks/uki/src/uki-core/background/sliced9.js +206 -0
- data/frameworks/uki/src/uki-core/background.js +35 -0
- data/frameworks/uki/src/uki-core/builder.js +68 -0
- data/frameworks/uki/src/uki-core/collection.js +278 -0
- data/frameworks/uki/src/uki-core/const.js +17 -0
- data/frameworks/uki/src/uki-core/dom/dnd.js +93 -0
- data/frameworks/uki/src/uki-core/dom/event.js +194 -0
- data/frameworks/uki/src/uki-core/dom/nativeLayout.js +18 -0
- data/frameworks/uki/src/uki-core/dom/offset.js +130 -0
- data/frameworks/uki/src/uki-core/dom/w3cdnd.js +333 -0
- data/frameworks/uki/src/uki-core/dom.js +109 -0
- data/frameworks/uki/src/uki-core/geometry.js +658 -0
- data/frameworks/uki/src/uki-core/image.js +90 -0
- data/frameworks/uki/src/uki-core/selector.js +201 -0
- data/frameworks/uki/src/uki-core/theme/base.js +39 -0
- data/frameworks/uki/src/uki-core/theme/template.js +26 -0
- data/frameworks/uki/src/uki-core/theme.js +45 -0
- data/frameworks/uki/src/uki-core/uki.js +45 -0
- data/frameworks/uki/src/uki-core/utils.js +399 -0
- data/frameworks/uki/src/uki-core/view/base.js +480 -0
- data/frameworks/uki/src/uki-core/view/container.js +155 -0
- data/frameworks/uki/src/uki-core/view/focusable.js +93 -0
- data/frameworks/uki/src/uki-core/view/observable.js +66 -0
- data/frameworks/uki/src/uki-core/view/styleable.js +70 -0
- data/frameworks/uki/src/uki-core/view/utils.js +66 -0
- data/frameworks/uki/src/uki-core/view.js +21 -0
- data/frameworks/uki/src/uki-core.js +36 -0
- data/frameworks/uki/src/uki-data/data.js +1 -0
- data/frameworks/uki/src/uki-data/model.js +28 -0
- data/frameworks/uki/src/uki-data/observable.js +34 -0
- data/frameworks/uki/src/uki-data.js +1 -0
- data/frameworks/uki/src/uki-more/more/utils.js +20 -0
- data/frameworks/uki/src/uki-more/more/view/listContainer.js +4 -0
- data/frameworks/uki/src/uki-more/more/view/multiselectList.js +196 -0
- data/frameworks/uki/src/uki-more/more/view/radioButton.js +27 -0
- data/frameworks/uki/src/uki-more/more/view/splitTable.js +79 -0
- data/frameworks/uki/src/uki-more/more/view/toggleButton.js +24 -0
- data/frameworks/uki/src/uki-more/more/view/treeList/render.js +53 -0
- data/frameworks/uki/src/uki-more/more/view/treeList.js +110 -0
- data/frameworks/uki/src/uki-more/more/view.js +2 -0
- data/frameworks/uki/src/uki-more/more.js +1 -0
- data/frameworks/uki/src/uki-more.js +4 -0
- data/frameworks/uki/src/uki-theamless.js +15 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/down-c.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/down-c.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/down-h.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/down-h.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/down-m.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/down-v.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/focusRing-c.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/focusRing-h.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/focusRing-m.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/focusRing-v.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/focusRing.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/hover-c.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/hover-c.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/hover-h.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/hover-h.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/hover-m.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/hover-v.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/hover.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/normal-c.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/normal-c.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/normal-h.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/normal-h.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/normal-m.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/normal-v.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/button/normal.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/checkbox/checkbox.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/checkbox/focus.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/checkbox/normal.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/checkbox/normal.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/panel/dark-h.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/panel/dark-h.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/panel/dark-m.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/panel/dark.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/popup/normal.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/radio/focus.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/radio/normal.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/radio/normal.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/radio/radio.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/shadow/large-c.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/shadow/large-h.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/shadow/large-m.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/shadow/large-v.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/shadow/large.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/slider/bar-m.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/slider/bar-m.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/slider/bar-v.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/slider/bar-v.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/slider/bar.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/slider/focus.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/slider/handle.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/splitPane/horizontal.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/splitPane/horizontal.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/splitPane/vertical.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/x.gif +0 -0
- data/frameworks/uki/src/uki-theme/airport.js +322 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/down-c.gif +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/down-c.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/down-h.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/down-m.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/down-v.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/down.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/focusRing-c.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/focusRing-h.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/focusRing-m.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/focusRing-v.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/focusRing.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/normal-c.gif +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/normal-c.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/normal-h.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/normal-m.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/normal-v.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/button/normal.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/checkbox/focus.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/checkbox/normal.gif +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/checkbox/normal.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/panel/normal-h.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/panel/normal-m.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/panel/normal.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/popup/normal.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/radio/focus.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/radio/normal.gif +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/radio/normal.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/shadow/large-c.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/shadow/large-h.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/shadow/large-m.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/shadow/large-v.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/shadow/large.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/slider/bar-m.gif +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/slider/bar-m.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/slider/bar-v.gif +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/slider/bar-v.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/slider/bar.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/slider/handle.gif +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/slider/handle.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/splitPane/horizontal.gif +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/splitPane/horizontal.png +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/splitPane/vertical.gif +0 -0
- data/frameworks/uki/src/uki-theme/aristo/i/x.gif +0 -0
- data/frameworks/uki/src/uki-theme/aristo.js +217 -0
- data/frameworks/uki/src/uki-view/view/box.js +1 -0
- data/frameworks/uki/src/uki-view/view/button.js +126 -0
- data/frameworks/uki/src/uki-view/view/checkbox.js +36 -0
- data/frameworks/uki/src/uki-view/view/flow.js +48 -0
- data/frameworks/uki/src/uki-view/view/image.js +9 -0
- data/frameworks/uki/src/uki-view/view/label.js +123 -0
- data/frameworks/uki/src/uki-view/view/list/render.js +23 -0
- data/frameworks/uki/src/uki-view/view/list.js +442 -0
- data/frameworks/uki/src/uki-view/view/popup.js +113 -0
- data/frameworks/uki/src/uki-view/view/radio.js +57 -0
- data/frameworks/uki/src/uki-view/view/scrollPane.js +139 -0
- data/frameworks/uki/src/uki-view/view/slider.js +154 -0
- data/frameworks/uki/src/uki-view/view/splitPane.js +213 -0
- data/frameworks/uki/src/uki-view/view/table/column.js +96 -0
- data/frameworks/uki/src/uki-view/view/table/header.js +53 -0
- data/frameworks/uki/src/uki-view/view/table/render.js +25 -0
- data/frameworks/uki/src/uki-view/view/table.js +71 -0
- data/frameworks/uki/src/uki-view/view/textField.js +145 -0
- data/frameworks/uki/src/uki-view/view/toolbar.js +93 -0
- data/frameworks/uki/src/uki-view.js +15 -0
- data/frameworks/uki/src/uki.js +2 -0
- data/frameworks/uki/thin.yaml +11 -0
- data/frameworks/uki/uki.rb +38 -0
- data/frameworks/uki/uki.ru +2 -0
- data/lib/uki/include_js.rb +50 -0
- data/lib/uki/project.rb +207 -0
- data/lib/uki/routes.rb +20 -0
- data/lib/uki/server.rb +42 -0
- data/lib/uki.rb +9 -0
- data/templates/index.html.erb +10 -0
- data/templates/model.js.erb +5 -0
- data/templates/myapp.js.erb +44 -0
- data/templates/package.js.erb +3 -0
- data/templates/spec.html.erb +23 -0
- data/templates/spec.js.erb +6 -0
- data/templates/view.js.erb +10 -0
- data/uki.gemspec +281 -0
- metadata +317 -0
@@ -0,0 +1,399 @@
|
|
1
|
+
include('uki.js');
|
2
|
+
|
3
|
+
var toString = Object.prototype.toString,
|
4
|
+
trim = String.prototype.trim,
|
5
|
+
|
6
|
+
trimRe = /^\s+|\s+$/g;
|
7
|
+
|
8
|
+
var marked = '__uki_marked';
|
9
|
+
|
10
|
+
var utils =
|
11
|
+
/**
|
12
|
+
* Utility functions. Can be called both as uki.utils.function or uki.function
|
13
|
+
* @namespace
|
14
|
+
*/
|
15
|
+
uki.utils = {
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Sets or retrieves attribute on an object.
|
19
|
+
* <p>If target has function with attr it will be called target[attr](value=)
|
20
|
+
* If no function present attribute will be set/get directly: target[attr] = value or return target[attr]</p>
|
21
|
+
*
|
22
|
+
* @example
|
23
|
+
* uki.attr(view, 'name', 'funny') // sets name to funny on view
|
24
|
+
* uki.attr(view, 'id') // gets id attribute of view
|
25
|
+
*
|
26
|
+
* @param {object} target
|
27
|
+
* @param {string} attr Attribute name
|
28
|
+
* @param {object=} value Value to set
|
29
|
+
* @returns {object} target if value is being set, retrieved value otherwise
|
30
|
+
*/
|
31
|
+
attr: function(target, attr, value) {
|
32
|
+
if (value !== undefined) {
|
33
|
+
// if (target[attr].apply) {
|
34
|
+
if (utils.isFunction(target[attr])) {
|
35
|
+
target[attr](value);
|
36
|
+
} else {
|
37
|
+
target[attr] = value;
|
38
|
+
}
|
39
|
+
return target;
|
40
|
+
} else {
|
41
|
+
// if (target[attr].apply) {
|
42
|
+
if (utils.isFunction(target[attr])) {
|
43
|
+
return target[attr]();
|
44
|
+
} else {
|
45
|
+
return target[attr];
|
46
|
+
}
|
47
|
+
}
|
48
|
+
},
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Runs a function in a given context
|
52
|
+
*
|
53
|
+
* @param {function()} fn
|
54
|
+
* @param {object} context
|
55
|
+
*/
|
56
|
+
proxy: function(fn, context) {
|
57
|
+
return function() {
|
58
|
+
return fn.apply(context, arguments);
|
59
|
+
}
|
60
|
+
},
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Checks if obj is a function
|
64
|
+
*
|
65
|
+
* @param {object} object Object to check
|
66
|
+
* @returns {boolean}
|
67
|
+
*/
|
68
|
+
isFunction: function( obj ) {
|
69
|
+
return toString.call(obj) === "[object Function]";
|
70
|
+
},
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Checks if obj is an Array
|
74
|
+
*
|
75
|
+
* @param {object} object Object to check
|
76
|
+
* @returns {boolean}
|
77
|
+
*/
|
78
|
+
isArray: function( obj ) {
|
79
|
+
return toString.call(obj) === "[object Array]";
|
80
|
+
},
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Trims the string
|
84
|
+
*
|
85
|
+
* @param {string} text
|
86
|
+
* @returns {string} trimmed text
|
87
|
+
*/
|
88
|
+
trim: function( text ) {
|
89
|
+
text = text || '';
|
90
|
+
return trim ? trim.call(text) : text.replace( trimRe, "" );
|
91
|
+
},
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Converts unsafe symbols to entities
|
95
|
+
*
|
96
|
+
* @param {string} html
|
97
|
+
* @returns {string} escaped html
|
98
|
+
*/
|
99
|
+
escapeHTML: function( html ) {
|
100
|
+
var trans = {
|
101
|
+
'&': '&',
|
102
|
+
'<': '<',
|
103
|
+
'>': '>',
|
104
|
+
'"': '"',
|
105
|
+
"'": '''
|
106
|
+
};
|
107
|
+
return html.replace(/[&<>\"\']/g, function(c) { return trans[c]; });
|
108
|
+
},
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Iterates through all non empty values of object or an Array
|
112
|
+
*
|
113
|
+
* @param {object|Array} object Object to iterate through
|
114
|
+
* @param {function(number, object):boolean} callback Called for every item, may return false to stop iteration
|
115
|
+
* @param {object} context Context in which callback should called. If not specified context will be set to
|
116
|
+
* current item
|
117
|
+
* @returns {object}
|
118
|
+
*/
|
119
|
+
each: function( object, callback, context ) {
|
120
|
+
var name, i = 0, length = object.length;
|
121
|
+
|
122
|
+
if ( length === undefined ) {
|
123
|
+
for ( name in object ) {
|
124
|
+
if ( !name || object[ name ] === undefined || !object.hasOwnProperty(name) ) continue;
|
125
|
+
if ( callback.call( context || object[ name ], name, object[ name ] ) === false ) { break; }
|
126
|
+
}
|
127
|
+
} else {
|
128
|
+
for ( var value = object[0]; i < length && callback.call( context || value, i, value ) !== false; value = object[++i] ){}
|
129
|
+
}
|
130
|
+
return object;
|
131
|
+
},
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Checks if elem is in array
|
135
|
+
*
|
136
|
+
* @param {object} elem
|
137
|
+
* @param {object} array
|
138
|
+
* @returns {boolean}
|
139
|
+
*/
|
140
|
+
inArray: function( elem, array ) {
|
141
|
+
for ( var i = 0, length = array.length; i < length; i++ ) {
|
142
|
+
if ( array[ i ] === elem ) { return i; }
|
143
|
+
}
|
144
|
+
|
145
|
+
return -1;
|
146
|
+
},
|
147
|
+
|
148
|
+
/**
|
149
|
+
* Returns unique elements in array
|
150
|
+
*
|
151
|
+
* @param {Array} array
|
152
|
+
* @returns {Array}
|
153
|
+
*/
|
154
|
+
unique: function( array ) {
|
155
|
+
if (array.length && (typeof array[0] == 'object' || typeof array[0] == 'function')) {
|
156
|
+
var result = [],
|
157
|
+
i;
|
158
|
+
|
159
|
+
for (i = 0; i < array.length; i++) {
|
160
|
+
if (!array[i][marked]) { result[result.length] = array[i]; }
|
161
|
+
array[i][marked] = true;
|
162
|
+
};
|
163
|
+
for (i = 0; i < result.length; i++) {
|
164
|
+
delete result[i][marked]
|
165
|
+
};
|
166
|
+
return result;
|
167
|
+
|
168
|
+
} else {
|
169
|
+
|
170
|
+
var ret = [],
|
171
|
+
done = {};
|
172
|
+
|
173
|
+
for ( var i = 0, length = array.length; i < length; i++ ) {
|
174
|
+
var id = array[ i ];
|
175
|
+
|
176
|
+
if ( !done[ id ] ) {
|
177
|
+
done[ id ] = true;
|
178
|
+
ret.push( array[ i ] );
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
return ret;
|
183
|
+
}
|
184
|
+
},
|
185
|
+
|
186
|
+
/**
|
187
|
+
* Searches for all items matching given criteria
|
188
|
+
*
|
189
|
+
* @param {Array} elems Element to search through
|
190
|
+
* @param {function(object, number)} callback Returns true for every matched element
|
191
|
+
* @returns {Array} matched elements
|
192
|
+
*/
|
193
|
+
grep: function( elems, callback ) {
|
194
|
+
var ret = [];
|
195
|
+
|
196
|
+
for ( var i = 0, length = elems.length; i < length; i++ ) {
|
197
|
+
if ( callback( elems[ i ], i ) ) { ret.push( elems[ i ] ); }
|
198
|
+
}
|
199
|
+
|
200
|
+
return ret;
|
201
|
+
},
|
202
|
+
|
203
|
+
/**
|
204
|
+
* Maps elements passing them to callback
|
205
|
+
* @example
|
206
|
+
* x = uki.map([1, 2, 3], function(item) { return -item });
|
207
|
+
*
|
208
|
+
* @param {Array} elems Elements to map
|
209
|
+
* @param {function(object, number)} mapping function
|
210
|
+
* @param {object} context Context in which callback should called. If not specified context will be set to
|
211
|
+
* current item
|
212
|
+
* @returns {Array} mapped values
|
213
|
+
*/
|
214
|
+
map: function( elems, callback, context ) {
|
215
|
+
var ret = [],
|
216
|
+
mapper = utils.isFunction(callback) ? callback :
|
217
|
+
function(e) { return utils.attr(e, callback); };
|
218
|
+
|
219
|
+
for ( var i = 0, length = elems.length; i < length; i++ ) {
|
220
|
+
var value = mapper.call( context || elems[ i ], elems[ i ], i );
|
221
|
+
|
222
|
+
if ( value != null ) { ret[ ret.length ] = value; }
|
223
|
+
}
|
224
|
+
|
225
|
+
return ret;
|
226
|
+
},
|
227
|
+
|
228
|
+
/**
|
229
|
+
* Reduces array
|
230
|
+
* @example
|
231
|
+
* x = uki.reduce(1, [1, 2, 3], function(p, x) { return p * x}) // calculates product
|
232
|
+
*
|
233
|
+
* @param {object} initial Initial value
|
234
|
+
* @param {Array} elems Elements to reduce
|
235
|
+
* @param {function(object, number)} reduce function
|
236
|
+
* @param {object} context Context in which callback should called. If not specified context will be set to
|
237
|
+
* current item
|
238
|
+
* @returns {object}
|
239
|
+
*/
|
240
|
+
reduce: function( initial, elems, callback, context ) {
|
241
|
+
for ( var i = 0, length = elems.length; i < length; i++ ) {
|
242
|
+
initial = callback.call( context || elems[ i ], initial, elems[ i ], i );
|
243
|
+
}
|
244
|
+
return initial;
|
245
|
+
},
|
246
|
+
|
247
|
+
/**
|
248
|
+
* Copies properties from one object to another
|
249
|
+
* @example
|
250
|
+
* uki.extend(x, { width: 13, height: 14 }) // sets x.width = 13, x.height = 14
|
251
|
+
* options = uki.extend({}, defaultOptions, options)
|
252
|
+
*
|
253
|
+
* @param {object} target Object to copy properties into
|
254
|
+
* @param {...object} sources Objects to take properties from
|
255
|
+
* @returns Describe what it returns
|
256
|
+
*/
|
257
|
+
extend: function() {
|
258
|
+
var target = arguments[0] || {}, i = 1, length = arguments.length, options;
|
259
|
+
|
260
|
+
for ( ; i < length; i++ ) {
|
261
|
+
if ( (options = arguments[i]) != null ) {
|
262
|
+
|
263
|
+
for ( var name in options ) {
|
264
|
+
var copy = options[ name ];
|
265
|
+
|
266
|
+
if ( copy !== undefined ) {
|
267
|
+
target[ name ] = copy;
|
268
|
+
}
|
269
|
+
|
270
|
+
}
|
271
|
+
}
|
272
|
+
}
|
273
|
+
|
274
|
+
return target;
|
275
|
+
},
|
276
|
+
|
277
|
+
/**
|
278
|
+
* Creates a new class inherited from base classes. Init function is used as constructor
|
279
|
+
* @example
|
280
|
+
* baseClass = uki.newClass({
|
281
|
+
* init: function() { this.x = 3 }
|
282
|
+
* });
|
283
|
+
*
|
284
|
+
* childClass = uki.newClass(baseClass, {
|
285
|
+
* getSqrt: function() { return this.x*this.x }
|
286
|
+
* });
|
287
|
+
*
|
288
|
+
* @param {object=} superClass If superClass has prototype "real" prototype base inheritance is used,
|
289
|
+
* otherwise superClass properties are simply copied to newClass prototype
|
290
|
+
* @param {Array.<object>=} mixins
|
291
|
+
* @param {object} methods
|
292
|
+
* @returns Describe what it returns
|
293
|
+
*/
|
294
|
+
newClass: function(/* [[superClass], mixin1, mixin2, ..] */ methods) {
|
295
|
+
var klass = function() {
|
296
|
+
this.init.apply(this, arguments);
|
297
|
+
};
|
298
|
+
|
299
|
+
var inheritance, i, startFrom = 0, tmp, baseClasses = [];
|
300
|
+
|
301
|
+
if (arguments.length > 1) {
|
302
|
+
if (arguments[0].prototype) { // real inheritance
|
303
|
+
/** @ignore */
|
304
|
+
inheritance = function() {};
|
305
|
+
inheritance.prototype = arguments[0].prototype;
|
306
|
+
klass.prototype = new inheritance();
|
307
|
+
startFrom = 1;
|
308
|
+
baseClasses = [inheritance.prototype];
|
309
|
+
}
|
310
|
+
}
|
311
|
+
for (i=startFrom; i < arguments.length; i++) {
|
312
|
+
tmp = arguments[i];
|
313
|
+
if (this.isFunction(tmp)) tmp = tmp.apply(tmp, baseClasses);
|
314
|
+
baseClasses.push(tmp);
|
315
|
+
utils.extend(klass.prototype, arguments[i]);
|
316
|
+
};
|
317
|
+
if (!klass.prototype.init) klass.prototype.init = function() {};
|
318
|
+
return klass;
|
319
|
+
},
|
320
|
+
|
321
|
+
/**
|
322
|
+
* Search closest value in a sorted array
|
323
|
+
* @param {nubmer} value to search
|
324
|
+
* @param {array} array sorted array
|
325
|
+
* @returns {number} index of closest value
|
326
|
+
*/
|
327
|
+
binarySearch: function (value, array) {
|
328
|
+
var low = 0, high = array.length, mid;
|
329
|
+
while (low < high) {
|
330
|
+
mid = (low + high) >> 1;
|
331
|
+
array[mid] < value ? low = mid + 1 : high = mid;
|
332
|
+
}
|
333
|
+
return low;
|
334
|
+
},
|
335
|
+
|
336
|
+
|
337
|
+
/**
|
338
|
+
* Creates default uki property function
|
339
|
+
* <p>If value is given to this function it sets property to value
|
340
|
+
* If no arguments given than function returns current property value</p>
|
341
|
+
*
|
342
|
+
* <p>Optional setter can be given. In this case setter will be called instead
|
343
|
+
* of simple this[field] = value</p>
|
344
|
+
*
|
345
|
+
* <p>If used as setter function returns self</p>
|
346
|
+
*
|
347
|
+
* @example
|
348
|
+
* x.width = uki.newProperty('_width');
|
349
|
+
* x.width(12); // x._width = 12
|
350
|
+
* x.width(); // return 12
|
351
|
+
*
|
352
|
+
* @param {string} field Field name
|
353
|
+
* @param {function(object)=} setter
|
354
|
+
* @returns {function(object=):object}
|
355
|
+
*/
|
356
|
+
newProp: function(field, setter) {
|
357
|
+
return function(value) {
|
358
|
+
if (value === undefined) return this[field];
|
359
|
+
if (setter) { setter.call(this, value); } else { this[field] = value; };
|
360
|
+
return this;
|
361
|
+
};
|
362
|
+
},
|
363
|
+
|
364
|
+
/**
|
365
|
+
* Adds several properties (uki.newProp) to a given object.
|
366
|
+
* <p>Field name equals to '_' + property name</p>
|
367
|
+
*
|
368
|
+
* @example
|
369
|
+
* uki.addProps(x, ['width', 'height'])
|
370
|
+
*
|
371
|
+
* @param {object} proto Object to add properties to
|
372
|
+
* @param {Array.<string>} props Property names
|
373
|
+
*/
|
374
|
+
addProps: function(proto, props) {
|
375
|
+
utils.each(props, function() { proto[this] = utils.newProp('_' + this); });
|
376
|
+
},
|
377
|
+
|
378
|
+
toArray: function(arr) {
|
379
|
+
return Array.prototype.slice.call(arr, 0);
|
380
|
+
},
|
381
|
+
|
382
|
+
delegateProp: function(proto, name, target) {
|
383
|
+
var propName = '_' + name;
|
384
|
+
proto[name] = function(value) {
|
385
|
+
if (value === undefined) {
|
386
|
+
if (this[target]) return utils.attr(this[target], name, value);
|
387
|
+
return this[propName];
|
388
|
+
}
|
389
|
+
if (this[target]) {
|
390
|
+
utils.attr(this[target], name, value);
|
391
|
+
} else {
|
392
|
+
this[propName] = value;
|
393
|
+
}
|
394
|
+
return this;
|
395
|
+
};
|
396
|
+
}
|
397
|
+
};
|
398
|
+
|
399
|
+
utils.extend(uki, utils);
|