uki 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/uki +1 -1
- data/frameworks/uki/README.rdoc +1 -1
- data/frameworks/uki/examples/core-examples/controls/controls.js +6 -6
- data/frameworks/uki/examples/core-examples/flow/flow.js +4 -4
- data/frameworks/uki/examples/core-examples/linearGradient/gradient.svg +11 -0
- data/frameworks/uki/examples/core-examples/linearGradient/linearGradient.js +87 -0
- data/frameworks/uki/examples/core-examples/popup/popup.js +23 -10
- data/frameworks/uki/examples/core-examples/resizeToContents/resizeToContents.js +12 -1
- data/frameworks/uki/examples/core-examples/slider/slider.js +1 -1
- data/frameworks/uki/examples/core-examples/splitPaneExtended/splitPaneExtended.js +1 -1
- data/frameworks/uki/examples/core-examples/table/table.js +19 -2
- data/frameworks/uki/examples/core-examples/wave/wave-theme.js +1 -1
- data/frameworks/uki/examples/core-examples/wave/wave.js +1 -1
- data/frameworks/uki/examples/more-examples/radioButton/radioButton.js +3 -3
- data/frameworks/uki/examples/more-examples/select/select.js +35 -0
- data/frameworks/uki/examples/touch-examples/scrollPane/scrollPane.js +53 -0
- data/frameworks/uki/spec/unit/background.spec.js +1 -1
- data/frameworks/uki/spec/unit/selector.spec.js +28 -12
- data/frameworks/uki/spec/unit/utils.spec.js +14 -0
- data/frameworks/uki/src/uki-core.js +3 -1
- data/frameworks/uki/src/uki-core/after.js +57 -0
- data/frameworks/uki/src/uki-core/attachment.js +15 -6
- data/frameworks/uki/src/uki-core/background.js +4 -3
- data/frameworks/uki/src/uki-core/background/css.js +1 -0
- data/frameworks/uki/src/uki-core/background/cssBox.js +5 -3
- data/frameworks/uki/src/uki-core/background/linearGradient.js +112 -0
- data/frameworks/uki/src/uki-core/background/multi.js +2 -2
- data/frameworks/uki/src/uki-core/background/rows.js +1 -0
- data/frameworks/uki/src/uki-core/background/sliced9.js +5 -2
- data/frameworks/uki/src/uki-core/builder.js +5 -4
- data/frameworks/uki/src/uki-core/collection.js +18 -13
- data/frameworks/uki/src/uki-core/dom/browser.js +114 -0
- data/frameworks/uki/src/uki-core/dom/event.js +3 -0
- data/frameworks/uki/src/uki-core/image.js +1 -26
- data/frameworks/uki/src/uki-core/selector.js +5 -0
- data/frameworks/uki/src/uki-core/theme.js +24 -23
- data/frameworks/uki/src/uki-core/theme/template.js +1 -1
- data/frameworks/uki/src/uki-core/uki.js +7 -4
- data/frameworks/uki/src/uki-core/utils.js +51 -26
- data/frameworks/uki/src/uki-core/view.js +6 -3
- data/frameworks/uki/src/uki-core/view/base.js +16 -1
- data/frameworks/uki/src/uki-core/view/container.js +15 -5
- data/frameworks/uki/src/uki-core/view/focusable.js +17 -4
- data/frameworks/uki/src/uki-core/view/observable.js +15 -2
- data/frameworks/uki/src/uki-core/view/styleable.js +4 -11
- data/frameworks/uki/src/uki-data/ajax.js +4 -30
- data/frameworks/uki/src/uki-data/json.js +191 -0
- data/frameworks/uki/src/uki-data/localStore.js +37 -0
- data/frameworks/uki/src/uki-data/model.js +1 -1
- data/frameworks/uki/src/uki-more.js +4 -0
- data/frameworks/uki/src/uki-more/more/background.js +2 -0
- data/frameworks/uki/src/uki-more/more/color.js +168 -0
- data/frameworks/uki/src/uki-more/more/utils.js +5 -12
- data/frameworks/uki/src/uki-more/more/view.js +3 -1
- data/frameworks/uki/src/uki-more/more/view/form.js +30 -0
- data/frameworks/uki/src/uki-more/more/view/hTile.js +59 -0
- data/frameworks/uki/src/uki-more/more/view/nativeButton.js +3 -0
- data/frameworks/uki/src/uki-more/more/view/nativeCheckbox.js +38 -0
- data/frameworks/uki/src/uki-more/more/view/nativeControl.js +40 -0
- data/frameworks/uki/src/uki-more/more/view/nativeInput.js +78 -0
- data/frameworks/uki/src/uki-more/more/view/nativeSelect.js +29 -0
- data/frameworks/uki/src/uki-more/more/view/radioButton.js +1 -1
- data/frameworks/uki/src/uki-more/more/view/select-theme.js +55 -0
- data/frameworks/uki/src/uki-more/more/view/select.js +208 -0
- data/frameworks/uki/src/uki-theme/airport.js +145 -88
- data/frameworks/uki/src/uki-theme/airport/i/table/a-down.png +0 -0
- data/frameworks/uki/src/uki-theme/airport/i/table/a-up.png +0 -0
- data/frameworks/uki/src/uki-touch.js +2 -0
- data/frameworks/uki/src/uki-touch/touch.js +1 -0
- data/frameworks/uki/src/uki-touch/touch/const.js +24 -0
- data/frameworks/uki/src/uki-touch/touch/setup.js +52 -0
- data/frameworks/uki/src/uki-touch/touch/view.js +4 -0
- data/frameworks/uki/src/uki-touch/touch/view/scrollPane.js +505 -0
- data/frameworks/uki/src/uki-touch/touch/view/scrollableList.js +27 -0
- data/frameworks/uki/src/uki-view/view/box.js +9 -0
- data/frameworks/uki/src/uki-view/view/button.js +36 -1
- data/frameworks/uki/src/uki-view/view/checkbox.js +32 -3
- data/frameworks/uki/src/uki-view/view/flow.js +37 -9
- data/frameworks/uki/src/uki-view/view/image.js +14 -1
- data/frameworks/uki/src/uki-view/view/label.js +72 -11
- data/frameworks/uki/src/uki-view/view/list.js +143 -13
- data/frameworks/uki/src/uki-view/view/list/render.js +1 -0
- data/frameworks/uki/src/uki-view/view/popup.js +46 -2
- data/frameworks/uki/src/uki-view/view/radio.js +19 -4
- data/frameworks/uki/src/uki-view/view/scrollPane.js +91 -33
- data/frameworks/uki/src/uki-view/view/slider.js +67 -54
- data/frameworks/uki/src/uki-view/view/splitPane.js +102 -9
- data/frameworks/uki/src/uki-view/view/table.js +59 -2
- data/frameworks/uki/src/uki-view/view/table/column.js +45 -17
- data/frameworks/uki/src/uki-view/view/table/header.js +40 -12
- data/frameworks/uki/src/uki-view/view/table/render.js +4 -0
- data/frameworks/uki/src/uki-view/view/textField.js +75 -21
- data/frameworks/uki/src/uki-view/view/toolbar.js +16 -0
- data/lib/uki/builder.rb +1 -1
- data/lib/uki/include_js.rb +2 -2
- data/lib/uki/project.rb +14 -14
- data/templates/index.html.erb +2 -2
- data/templates/myapp.js.erb +2 -2
- data/uki.gemspec +34 -48
- metadata +44 -47
- data/frameworks/uki/src/uki-core/dom/nativeLayout.js +0 -18
- 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/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/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
@@ -0,0 +1,191 @@
|
|
1
|
+
include('data.js');
|
2
|
+
|
3
|
+
// JSON2 library, source: http://www.JSON.org/js.html
|
4
|
+
// Most modern browsers already support this natively, but mobile
|
5
|
+
// browsers often don't, hence this implementation
|
6
|
+
// Relevant APIs:
|
7
|
+
// JSON.stringify(value, replacer, space)
|
8
|
+
|
9
|
+
var JSON = (window && window.JSON) ? window.JSON : {};
|
10
|
+
if (!JSON.stringify) {
|
11
|
+
(function () {
|
12
|
+
function f(n) {
|
13
|
+
return n < 10 ? '0' + n : n;
|
14
|
+
}
|
15
|
+
if (typeof Date.prototype.toJSON !== 'function') {
|
16
|
+
|
17
|
+
Date.prototype.toJSON = function (key) {
|
18
|
+
|
19
|
+
return isFinite(this.valueOf()) ?
|
20
|
+
this.getUTCFullYear() + '-' +
|
21
|
+
f(this.getUTCMonth() + 1) + '-' +
|
22
|
+
f(this.getUTCDate()) + 'T' +
|
23
|
+
f(this.getUTCHours()) + ':' +
|
24
|
+
f(this.getUTCMinutes()) + ':' +
|
25
|
+
f(this.getUTCSeconds()) + 'Z' : null;
|
26
|
+
};
|
27
|
+
|
28
|
+
String.prototype.toJSON =
|
29
|
+
Number.prototype.toJSON =
|
30
|
+
Boolean.prototype.toJSON = function (key) {
|
31
|
+
return this.valueOf();
|
32
|
+
};
|
33
|
+
}
|
34
|
+
|
35
|
+
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
36
|
+
escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
37
|
+
gap, indent,
|
38
|
+
meta = {
|
39
|
+
'\b': '\\b',
|
40
|
+
'\t': '\\t',
|
41
|
+
'\n': '\\n',
|
42
|
+
'\f': '\\f',
|
43
|
+
'\r': '\\r',
|
44
|
+
'"' : '\\"',
|
45
|
+
'\\': '\\\\'
|
46
|
+
},
|
47
|
+
rep;
|
48
|
+
|
49
|
+
function quote(string) {
|
50
|
+
escapable.lastIndex = 0;
|
51
|
+
return escapable.test(string) ?
|
52
|
+
'"' + string.replace(escapable, function (a) {
|
53
|
+
var c = meta[a];
|
54
|
+
return typeof c === 'string' ? c :
|
55
|
+
'\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
56
|
+
}) + '"' :
|
57
|
+
'"' + string + '"';
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
function str(key, holder) {
|
62
|
+
var i, k, v, length, mind = gap, partial, value = holder[key];
|
63
|
+
|
64
|
+
if (value && typeof value === 'object' &&
|
65
|
+
typeof value.toJSON === 'function') {
|
66
|
+
value = value.toJSON(key);
|
67
|
+
}
|
68
|
+
|
69
|
+
if (typeof rep === 'function') {
|
70
|
+
value = rep.call(holder, key, value);
|
71
|
+
}
|
72
|
+
|
73
|
+
switch (typeof value) {
|
74
|
+
case 'string':
|
75
|
+
return quote(value);
|
76
|
+
case 'number':
|
77
|
+
return isFinite(value) ? String(value) : 'null';
|
78
|
+
case 'boolean':
|
79
|
+
case 'null':
|
80
|
+
return String(value);
|
81
|
+
case 'object':
|
82
|
+
if (!value) {
|
83
|
+
return 'null';
|
84
|
+
}
|
85
|
+
|
86
|
+
gap += indent;
|
87
|
+
partial = [];
|
88
|
+
|
89
|
+
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
90
|
+
length = value.length;
|
91
|
+
for (i = 0; i < length; i += 1) {
|
92
|
+
partial[i] = str(i, value) || 'null';
|
93
|
+
}
|
94
|
+
|
95
|
+
v = partial.length === 0 ? '[]' :
|
96
|
+
gap ? '[\n' + gap +
|
97
|
+
partial.join(',\n' + gap) + '\n' +
|
98
|
+
mind + ']' :
|
99
|
+
'[' + partial.join(',') + ']';
|
100
|
+
gap = mind;
|
101
|
+
return v;
|
102
|
+
}
|
103
|
+
|
104
|
+
if (rep && typeof rep === 'object') {
|
105
|
+
length = rep.length;
|
106
|
+
for (i = 0; i < length; i += 1) {
|
107
|
+
k = rep[i];
|
108
|
+
if (typeof k === 'string') {
|
109
|
+
v = str(k, value);
|
110
|
+
if (v) {
|
111
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
} else {
|
116
|
+
for (k in value) {
|
117
|
+
if (Object.hasOwnProperty.call(value, k)) {
|
118
|
+
v = str(k, value);
|
119
|
+
if (v) {
|
120
|
+
partial.push(quote(k) + (gap ? ': ' : ':') + v);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
v = partial.length === 0 ? '{}' :
|
127
|
+
gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
|
128
|
+
mind + '}' : '{' + partial.join(',') + '}';
|
129
|
+
gap = mind;
|
130
|
+
return v;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
if (typeof JSON.stringify !== 'function') {
|
135
|
+
JSON.stringify = function (value, replacer, space) {
|
136
|
+
var i;
|
137
|
+
gap = '';
|
138
|
+
indent = '';
|
139
|
+
if (typeof space === 'number') {
|
140
|
+
for (i = 0; i < space; i += 1) {
|
141
|
+
indent += ' ';
|
142
|
+
}
|
143
|
+
} else if (typeof space === 'string') {
|
144
|
+
indent = space;
|
145
|
+
}
|
146
|
+
|
147
|
+
rep = replacer;
|
148
|
+
if (replacer && typeof replacer !== 'function' &&
|
149
|
+
(typeof replacer !== 'object' ||
|
150
|
+
typeof replacer.length !== 'number')) {
|
151
|
+
throw new Error('JSON.stringify');
|
152
|
+
}
|
153
|
+
|
154
|
+
return str('', {'': value});
|
155
|
+
};
|
156
|
+
}
|
157
|
+
}());
|
158
|
+
}
|
159
|
+
|
160
|
+
|
161
|
+
uki.extend(uki, {
|
162
|
+
|
163
|
+
parseJSON: function(data) {
|
164
|
+
if ( typeof data !== "string" || !data ) {
|
165
|
+
return null;
|
166
|
+
}
|
167
|
+
|
168
|
+
// Make sure leading/trailing whitespace is removed (IE can't handle it)
|
169
|
+
data = uki.trim( data );
|
170
|
+
|
171
|
+
// Make sure the incoming data is actual JSON
|
172
|
+
// Logic borrowed from http://json.org/json2.js
|
173
|
+
if ( /^[\],:{}\s]*$/.test(data.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@")
|
174
|
+
.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]")
|
175
|
+
.replace(/(?:^|:|,)(?:\s*\[)+/g, "")) ) {
|
176
|
+
|
177
|
+
// Try to use the native JSON parser first
|
178
|
+
return window.JSON && window.JSON.parse ?
|
179
|
+
window.JSON.parse( data ) :
|
180
|
+
(new Function("return " + data))();
|
181
|
+
|
182
|
+
} else {
|
183
|
+
throw "Invalid JSON: " + data;
|
184
|
+
}
|
185
|
+
},
|
186
|
+
|
187
|
+
stringifyJSON: function(arg) {
|
188
|
+
// for uki-like method naming convenicnce only
|
189
|
+
return JSON.stringify(arg);
|
190
|
+
}
|
191
|
+
});
|
@@ -0,0 +1,37 @@
|
|
1
|
+
include('json.js');
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Stores/retrieves an object in localStorage (if available) otherwise as cookie
|
5
|
+
*
|
6
|
+
* @author rsaccon
|
7
|
+
* @param {string} key
|
8
|
+
* @param {object} value
|
9
|
+
* @param {string} path
|
10
|
+
* @returns {object}
|
11
|
+
*/
|
12
|
+
uki.localStore = function(key, value, path) {
|
13
|
+
if (('localStorage' in window) && window.localStorage !== null) {
|
14
|
+
var name = "prefs";
|
15
|
+
if (value === undefined) {
|
16
|
+
return localStorage[key];
|
17
|
+
} else {
|
18
|
+
localStorage[key] = value;
|
19
|
+
};
|
20
|
+
} else {
|
21
|
+
if (value === undefined) {
|
22
|
+
var result;
|
23
|
+
if (result = new RegExp("(?:^|; )" +key+ "=([^;]*)").exec(document.cookie)) {
|
24
|
+
return uki.parseJSON(unescape(result[1]));
|
25
|
+
} else return false;
|
26
|
+
} else {
|
27
|
+
var date = new Date();
|
28
|
+
// set expiration to far-future (one year)
|
29
|
+
date.setTime(date.getTime()+(365*24*60*60*1000));
|
30
|
+
document.cookie = [
|
31
|
+
key , '=' , escape(uki.stringifyJSON(value)),
|
32
|
+
'; expires=', date.toUTCString(),
|
33
|
+
'; path=', path || '/'
|
34
|
+
].join("");
|
35
|
+
}
|
36
|
+
}
|
37
|
+
};
|
@@ -4,7 +4,7 @@ include('observable.js');
|
|
4
4
|
*
|
5
5
|
* @example
|
6
6
|
* myModel = uki.newClass(uki.data.Model, function() {
|
7
|
-
* uki.data.model.
|
7
|
+
* uki.data.model.addFields(this, ['name', 'age', 'sex']);
|
8
8
|
* })
|
9
9
|
*
|
10
10
|
* var m = new myModel({ age: 22, name: 'Jonh Smith', sex: 'm' })
|
@@ -1,4 +1,8 @@
|
|
1
|
+
include('uki-more/more/utils.js');
|
1
2
|
include('uki-more/more/view/treeList.js');
|
2
3
|
include('uki-more/more/view/toggleButton.js');
|
3
4
|
include('uki-more/more/view/radioButton.js');
|
4
5
|
include('uki-more/more/view/splitTable.js');
|
6
|
+
include('uki-more/more/view/form.js');
|
7
|
+
include('uki-more/more/view/select.js');
|
8
|
+
include('uki-more/more/view/select-theme.js');
|
@@ -0,0 +1,168 @@
|
|
1
|
+
include('../more.js');
|
2
|
+
|
3
|
+
(function() {
|
4
|
+
|
5
|
+
function rgbToHSL(r, g, b) {
|
6
|
+
r /= 255; g /= 255; b /= 255;
|
7
|
+
var max = Math.max(r, g, b), min = Math.min(r, g, b);
|
8
|
+
var h, s, l = (max + min) / 2;
|
9
|
+
|
10
|
+
if (max == min){
|
11
|
+
h = s = 0; // achromatic
|
12
|
+
} else {
|
13
|
+
var d = max - min;
|
14
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
15
|
+
switch(max) {
|
16
|
+
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
|
17
|
+
case g: h = (b - r) / d + 2; break;
|
18
|
+
case b: h = (r - g) / d + 4; break;
|
19
|
+
}
|
20
|
+
h /= 6;
|
21
|
+
}
|
22
|
+
return [h, s, l];
|
23
|
+
}
|
24
|
+
|
25
|
+
function filter(val) {
|
26
|
+
return (val < 0 || isNaN(val)) ? 0 : ((val > 255) ? 255 : val);
|
27
|
+
}
|
28
|
+
|
29
|
+
function modify(val, diff) {
|
30
|
+
var result = val;
|
31
|
+
if (!isNaN(val)) result += diff;
|
32
|
+
if (result < 0) result = 0;
|
33
|
+
if (result > 1) result = 1;
|
34
|
+
return result;
|
35
|
+
}
|
36
|
+
|
37
|
+
function hslToHexString(h, s, l) {
|
38
|
+
var r, g, b;
|
39
|
+
|
40
|
+
if(s == 0){
|
41
|
+
r = g = b = l; // achromatic
|
42
|
+
}else{
|
43
|
+
function hue2rgb(p, q, t){
|
44
|
+
if(t < 0) t += 1;
|
45
|
+
if(t > 1) t -= 1;
|
46
|
+
if(t < 1/6) return p + (q - p) * 6 * t;
|
47
|
+
if(t < 1/2) return q;
|
48
|
+
if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
|
49
|
+
return p;
|
50
|
+
}
|
51
|
+
|
52
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
53
|
+
var p = 2 * l - q;
|
54
|
+
r = hue2rgb(p, q, h + 1/3);
|
55
|
+
g = hue2rgb(p, q, h);
|
56
|
+
b = hue2rgb(p, q, h - 1/3);
|
57
|
+
}
|
58
|
+
|
59
|
+
r = Math.round(r * 255).toString(16);
|
60
|
+
g = Math.round(g * 255).toString(16);
|
61
|
+
b = Math.round(b * 255).toString(16);
|
62
|
+
|
63
|
+
if (r.length == 1) r = '0' + r;
|
64
|
+
if (g.length == 1) g = '0' + g;
|
65
|
+
if (b.length == 1) b = '0' + b;
|
66
|
+
|
67
|
+
return '#' + r + g + b;
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Creates a HSL color from a hex string or numerical [0..255] RGB args
|
73
|
+
*
|
74
|
+
* @author rsaccon
|
75
|
+
* @param {Number | string} Red component or color hex string
|
76
|
+
* @param {Number} arg1 Green component
|
77
|
+
* @param {Number} arg1 Blue component
|
78
|
+
* @constructor
|
79
|
+
*/
|
80
|
+
var Color = uki.more.Color = function(arg1, arg2, arg3) {
|
81
|
+
var r=255, g=255, b=255;
|
82
|
+
|
83
|
+
if (arguments.length == 1) {
|
84
|
+
|
85
|
+
function process(bits){
|
86
|
+
return [
|
87
|
+
parseInt(bits[1], 16),
|
88
|
+
parseInt(bits[2], 16),
|
89
|
+
parseInt(bits[3], 16)
|
90
|
+
];
|
91
|
+
}
|
92
|
+
|
93
|
+
var bits = /^(\w{2})(\w{2})(\w{2})$/.exec(arg1);
|
94
|
+
|
95
|
+
if (bits) {
|
96
|
+
var channels = process(bits);
|
97
|
+
r = filter(channels[0]);
|
98
|
+
g = filter(channels[1]);
|
99
|
+
b = filter(channels[2]);
|
100
|
+
}
|
101
|
+
} else if (arguments.length == 3) {
|
102
|
+
r = filter(arg1);
|
103
|
+
g = filter(arg2);
|
104
|
+
b = filter(arg3);
|
105
|
+
}
|
106
|
+
|
107
|
+
var hsl = rgbToHSL(r, g, b);
|
108
|
+
this.hue = hsl[0];
|
109
|
+
this.saturation = hsl[1];
|
110
|
+
this.luminance = hsl[2];
|
111
|
+
};
|
112
|
+
|
113
|
+
Color.prototype = /** @lends uki.more.Color.prototype */ {
|
114
|
+
/**
|
115
|
+
* Base color
|
116
|
+
*
|
117
|
+
* @author rsaccon
|
118
|
+
* @returns {string} Color as hex string
|
119
|
+
*/
|
120
|
+
base: function() {
|
121
|
+
return hslToHexString(this.hue, this.saturation, this.luminance);
|
122
|
+
},
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Increseases the lightness of the Base color
|
126
|
+
*
|
127
|
+
* @author rsaccon
|
128
|
+
* @param {Number} val allowed values: [0.0 .. 1.0]
|
129
|
+
* @returns {string} Color as hex string
|
130
|
+
*/
|
131
|
+
lighten: function(val) {
|
132
|
+
return hslToHexString(this.hue, this.saturation, modify(this.luminance, val));
|
133
|
+
},
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Decreseases the lightness of the Base color
|
137
|
+
*
|
138
|
+
* @author rsaccon
|
139
|
+
* @param {Number} val allowed values: [0.0 .. 1.0]
|
140
|
+
* @returns {string} Color as hex string
|
141
|
+
*/
|
142
|
+
darken: function(val) {
|
143
|
+
this.lighten(-1 * val);
|
144
|
+
},
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Increseases the saturation of the Base color
|
148
|
+
*
|
149
|
+
* @author rsaccon
|
150
|
+
* @param {Number} val allowed values: [0.0 .. 1.0]
|
151
|
+
* @returns {string} Color as hex string
|
152
|
+
*/
|
153
|
+
saturate: function(val) {
|
154
|
+
return hslToHexString(this.hue, modify(this.saturation, val), this.luminance);
|
155
|
+
},
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Decreseases the saturation of the Base color
|
159
|
+
*
|
160
|
+
* @author rsaccon
|
161
|
+
* @param {Number} val allowed values: [0.0 .. 1.0]
|
162
|
+
* @returns {string} Color as hex string
|
163
|
+
*/
|
164
|
+
desaturate: function(val) {
|
165
|
+
this.saturate(-1 * val);
|
166
|
+
}
|
167
|
+
};
|
168
|
+
})();
|
@@ -2,19 +2,12 @@ include('../more.js');
|
|
2
2
|
|
3
3
|
uki.more.utils = {
|
4
4
|
range: function (from, to) {
|
5
|
-
var result = new Array(to - from);
|
6
|
-
for (
|
5
|
+
var result = new Array(to - from), idx = 0;
|
6
|
+
for (; from <= to; from++, idx++) {
|
7
7
|
result[idx] = from;
|
8
8
|
};
|
9
9
|
return result;
|
10
|
-
},
|
11
|
-
|
12
|
-
binarySearch: function (array, value) {
|
13
|
-
var low = 0, high = array.length, mid;
|
14
|
-
while (low < high) {
|
15
|
-
mid = (low + high) >> 1;
|
16
|
-
array[mid] < value ? low = mid + 1 : high = mid;
|
17
|
-
}
|
18
|
-
return low;
|
19
10
|
}
|
20
|
-
};
|
11
|
+
};
|
12
|
+
|
13
|
+
uki.extend(uki, uki.more.utils);
|