Debian Codegraph @

DisplayCAL/report/jsapi-packages.js

raw
1 /* ############################## */
2 /* ##### jsapi Distribution ##### */
3 /* ############################## */
4
5 /*
6 2006 Florian Hoech
7
8 Function.prototype.apply.js
9
10 adds apply method for functions in browsers without native implementation
11 */
12
13 if (!Function.prototype.apply) {
14 Function.prototype.apply = function(o, args) {
15 o = o ? Object(o) : window;
16 o.__apply__ = this;
17 for (var i = 0, sargs = []; i < args.length; i ++) sargs[i] = "args[" + i + "]";
18 var result = eval("o.__apply__(" + sargs.join(",") + ");");
19 o.__apply__ = null;
20 return result
21 }
22 };
23
24 /* ##### Array.prototype.pop.js ##### */
25
26 /*
27 2006 Ash Searle
28
29 http://hexmen.com/blog/2006/12/push-and-pop/
30 */
31
32 if (!Array.prototype.pop) Array.prototype.pop = function() {
33 // Removes the last element from an array and returns that element. This method changes the length of the array.
34 var n = this.length >>> 0, value;
35 if (n) {
36 value = this[--n];
37 delete this[n]
38 };
39 this.length = n;
40 return value
41 };
42
43 if (!Array.pop) Array.pop = function(object) {
44 return Array.prototype.pop.apply(object)
45 };
46
47 /* ##### Array.prototype.shift.js ##### */
48
49 /*
50 2006 Florian Hoech
51
52 Array.prototype.shift.js
53
54 adds shift method for arrays in browsers without native or incorrect implementation
55 */
56
57 if (!Array.prototype.shift) Array.prototype.shift = function() {
58 // Removes the first element from an array and returns that element. This method changes the length of the array.
59 var n = this.length >>> 0, value = this[0];
60 for (var i = 1; i < n; i ++) this[i - 1] = this[i];
61 delete this[n];
62 this.length = n - 1 >>> 0;
63 return value
64 };
65
66 if (!Array.shift) Array.shift = function(object) {
67 return Array.prototype.shift.apply(object)
68 };
69
70 /* ##### Array.prototype.unshift.js ##### */
71
72 /*
73 2006 Florian Hoech
74
75 Array.prototype.unshift.js
76
77 adds unshift method for arrays in browsers without native or incorrect implementation
78 */
79
80 if (!Array.prototype.unshift) Array.prototype.unshift = function() {
81 // Adds one or more elements to the beginning of an array and returns the new length of the array.
82 var n = this.length >>> 0;
83 for (var i = (n - 1) >>> 0; i >= 0; i --) this[i + arguments.length] = this[i];
84 for (var i = arguments.length - 1; i >= 0; i --) {
85 this[i] = arguments[i];
86 n = n + 1 >>> 0
87 };
88 this.length = n;
89 return n
90 };
91
92 /* ##### Array.prototype.push.js ##### */
93
94 /*
95 2006 Ash Searle
96
97 http://hexmen.com/blog/2006/12/push-and-pop/
98 */
99
100 if (!Array.prototype.push || [].push(0) == 0) Array.prototype.push = function() {
101 var n = this.length >>> 0;
102 for (var i = 0; i < arguments.length; i++) {
103 this[n] = arguments[i];
104 n = n + 1 >>> 0
105 };
106 this.length = n;
107 return n
108 };
109
110 /* ##### Array.prototype.splice.js ##### */
111
112 /*
113 2006 Florian Hoech
114
115 Array.prototype.splice.js
116
117 adds splice method for arrays in browsers without native or incorrect implementation
118 */
119
120 if (!Array.prototype.splice || [0].splice(0, 1) === 0) Array.prototype.splice = function(index, howMany) {
121 /*
122 Changes the content of an array, adding new elements while removing old elements.
123 Returns an array containing the removed elements. If only one element is removed, an array of one element is returned.
124 Returns undefined if no arguments are passed.
125 */
126 if (arguments.length == 0) return index;
127 if (typeof index != "number") index = 0;
128 if (index < 0) index = Math.max(0, this.length + index);
129 if (index > this.length) {
130 if (arguments.length > 2) index = this.length;
131 else return []
132 };
133 if (arguments.length < 2) howMany = this.length - index;
134 howMany = (typeof howMany == "number") ? Math.max(0, howMany) : 0;
135 var removedElements = this.slice(index, index + howMany);
136 var elementsToMove = this.slice(index + howMany);
137 this.length = index;
138 for (var i = 2; i < arguments.length; i ++) this[this.length] = arguments[i];
139 for (var i = 0; i < elementsToMove.length; i ++) this[this.length] = elementsToMove[i];
140 return removedElements
141 };
142
143 /* ##### Number.prototype.toFixed.js ##### */
144
145 /*
146 2006 Florian Hoech
147
148 Number.prototype.toFixed.js
149 */
150
151 if (!Number.prototype.toFixed) {
152 Number.prototype.toFixed = function(ln) {
153 if (!ln) ln = 0;
154 var i, n = Math.pow(10, ln),
155 n = (Math.round(this * n) / n) + "";
156 if (ln && (i = n.indexOf(".")) < 0) {
157 i = n.length;
158 n += "."
159 };
160 while (n.substr(i).length < ln + 1) n += "0";
161 return n
162 }
163 };
164
165 /* ##### Array.prototype.indexOf.js ##### */
166
167 /*
168 http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:indexOf
169
170 Summary
171
172 Returns the first index at which a given element can be found in the array, or -1 if it is not present.
173 Method of Array
174 Implemented in: JavaScript 1.6 (Gecko 1.8b2 and later)
175 ECMAScript Edition: none
176
177 Syntax
178
179 var index = array.indexOf(searchElement[, fromIndex]);
180
181 Parameters
182
183 searchElement
184 Element to locate in the array.
185 fromIndex
186 The index at which to begin the search. Defaults to 0, i.e. the whole array will be searched. If the index is greater than or equal to the length of the array, -1 is returned, i.e. the array will not be searched. If negative, it is taken as the offset from the end of the array. Note that even when the index is negative, the array is still searched from front to back. If the calculated index is less than 0, the whole array will be searched.
187
188 Description
189
190 indexOf compares searchElement to elements of the Array using strict equality (the same method used by the ===, or triple-equals, operator).
191
192 Compatibility
193
194 indexOf is a JavaScript extension to the ECMA-262 standard; as such it may not be present in other implementations of the standard. You can work around this by inserting the following code at the beginning of your scripts, allowing use of indexOf in ECMA-262 implementations which do not natively support it. This algorithm is exactly the one used in Firefox and SpiderMonkey.
195
196 Again, note that this implementation aims for absolute compatibility with indexOf in Firefox and the SpiderMonkey JavaScript engine, including in cases where the index passed to indexOf is not an integer value. If you intend to use this in real-world applications, you may not need all of the code to calculate from.
197
198 Example: Using indexOf
199
200 The following example uses indexOf to locate values in an array.
201
202 var array = [2, 5, 9];
203 var index = array.indexOf(2);
204 // index is 0
205 index = array.indexOf(7);
206 // index is -1
207
208 Example: Finding all the occurrences of an element
209
210 The following example uses indexOf to find all the indices of an element in a given array, using push to add them to another array as they are found.
211
212 var indices = [];
213 var idx = array.indexOf(element)
214 while (idx != -1)
215 {
216 indices.push(idx);
217 idx = array.indexOf(element, idx + 1);
218 }
219 */
220
221 // NOTE: semicolons added where necessary to make compatible with JavaScript compressors
222
223 if (!Array.prototype.indexOf)
224 {
225 Array.prototype.indexOf = function(elt /*, from*/)
226 {
227 var len = this.length;
228
229 var from = Number(arguments[1]) || 0;
230 from = (from < 0)
231 ? Math.ceil(from)
232 : Math.floor(from);
233 if (from < 0)
234 from += len;
235
236 for (; from < len; from++)
237 {
238 if (/* from in this && */ /* Not compatible with IE/Mac */
239 this[from] === elt)
240 return from
241 };
242 return -1
243 }
244 };
245
246
247 /* ##### jsapi.js ##### */
248
249 /*
250 <jsapi>
251 <author>2006 Florian Hoech</author>
252 <file>jsapi.js</file>
253 </jsapi>
254 */
255
256 jsapi = function() {
257 return new jsapi.jsapi(arguments);
258 };
259 jsapi.constants = {
260 OBJECTTYPES: {
261 OBJECT: 0,
262 ARRAY: 1,
263 BOOLEAN: 2,
264 DATE: 3,
265 FUNCTION: 4,
266 NUMBER: 5,
267 REGEXP: 6,
268 STRING: 7
269 }
270 };
271 jsapi.extend = function(object, _this) {
272 jsapi.jsapi.prototype.extend(object, _this)
273 };
274 jsapi.jsapi = function() {
275 var objectType;
276 if (!jsapi.initialized) {
277 for (var propertyName in jsapi.dom) if (typeof jsapi.dom[propertyName] == "function" && !jsapi.dom[propertyName]._args) jsapi.dom[propertyName]._args = [jsapi.dom.isNode];
278 for (var propertyName in jsapi.regexp) if (typeof jsapi.regexp[propertyName] == "function") jsapi.regexp[propertyName]._args = [function(argument) {
279 return argument.constructor == RegExp;
280 }];
281 for (var propertyName in jsapi.string) if (typeof jsapi.string[propertyName] == "function") jsapi.string[propertyName]._args = [function(argument) {
282 return typeof argument == "string" || argument.constructor == String;
283 }];
284 for (var propertyName in jsapi) jsapi.extend(jsapi[propertyName], jsapi[propertyName]);
285 var arrayMethodNames = [
286 "every",
287 "filter",
288 "forEach",
289 "indexOf",
290 "join",
291 "lastIndexOf",
292 "map",
293 "slice",
294 "some",
295 /* Mutator methods */
296 "pop",
297 "push",
298 "reverse",
299 "shift",
300 "sort",
301 "splice",
302 "unshift"
303 ];
304 for (var i = 0; i < arrayMethodNames.length; i ++) {
305 (function (arrayMethodName) {
306 jsapi.jsapi.prototype[arrayMethodName] = function () {
307 var result = Array.prototype[arrayMethodName].apply(this, arguments);
308 return typeof result == "object" ? jsapi(result) : (result != null || arrayMethodName == "pop" || arrayMethodName == "shift" ? result : this);
309 }
310 })(arrayMethodNames[i]);
311 };
312 jsapi.initialized = true;
313 };
314 if (this.length == null) this.length = 0;
315 for (var i = 0; i < arguments[0].length; i ++) {
316 var object = arguments[0][i];
317 switch (typeof object) {
318 case "function":
319 objectType = jsapi.constants.OBJECTTYPES.FUNCTION;
320 break;
321 case "number":
322 objectType = jsapi.constants.OBJECTTYPES.NUMBER;
323 break;
324 case "string":
325 objectType = jsapi.constants.OBJECTTYPES.STRING;
326 break;
327 default:
328 if (!object) continue; // null or undefined
329 switch (object.constructor) {
330 case Boolean:
331 objectType = jsapi.constants.OBJECTTYPES.BOOLEAN;
332 break;
333 case Date:
334 objectType = jsapi.constants.OBJECTTYPES.DATE;
335 break;
336 case Number:
337 objectType = jsapi.constants.OBJECTTYPES.NUMBER;
338 break;
339 case RegExp:
340 objectType = jsapi.constants.OBJECTTYPES.REGEXP;
341 break;
342 case String:
343 objectType = jsapi.constants.OBJECTTYPES.STRING;
344 break;
345 default:
346 objectType = jsapi.constants.OBJECTTYPES.OBJECT;
347 }
348 };
349 switch (objectType) {
350 case jsapi.constants.OBJECTTYPES.STRING:
351 var expression = object.split(":");
352 if (expression.length > 1) switch (expression[0]) {
353 case "html":
354 case "xhtml":
355 case "xml":
356 object = jsapi.dom.parseString(expression.slice(1).join(":"));
357 break;
358 case "xpath":
359 object = jsapi.dom.getByXpath(expression.slice(1).join(":"));
360 break;
361 }
362 else if (/<[^<]*>/.test(object)) object = jsapi.dom.parseString(object);
363 default:
364 if (object.constructor == Array) Array.prototype.push.apply(this, object);
365 else if (typeof object == "object" && typeof object.length == "number" && object.constructor != String && object.constructor != Function)
366 Array.prototype.push.apply(this, Array.prototype.slice.apply(object));
367 else this[this.length ++] = object;
368 }
369 };
370 };
371 jsapi.jsapi.prototype = {
372 concat: function(object) {
373 var result = jsapi(this);
374 jsapi.jsapi.apply(result, [object]);
375 return result
376 },
377 extend: function(object, _this) {
378 /*
379 if _this evaluates to false, use the current result as "this"-object.
380 otherwise, use _this as "this"-object and pass the current result as first argument.
381 */
382 for (var propertyName in object) if (typeof object[propertyName] == "function" &&
383 propertyName != "$" &&
384 propertyName != "extend" &&
385 propertyName != "toString" &&
386 propertyName != "valueOf") {
387 if (!this[propertyName]) {
388 this[propertyName] = function() {
389 if (this.length) {
390 var _callbacks = arguments.callee._callbacks;
391 for (var i = 0; i < this.length; i ++) {
392 for (var n = 0; n < _callbacks.length; n ++) {
393 var _this = _callbacks[n]._this || this[i],
394 _arguments = _callbacks[n]._this ? [this[i]].concat(Array.prototype.slice.apply(arguments)) : arguments;
395 if (_callbacks[n].hasValidArguments.apply(_callbacks[n], _arguments)) {
396 this[i] = _callbacks[n].apply(_this, _arguments);
397 }
398 }
399 }
400 };
401 return this;
402 };
403 this[propertyName]._callbacks = [];
404 };
405 if (!object[propertyName].hasValidArguments) {
406 if (object[propertyName]._args) object[propertyName].hasValidArguments = function() {
407 for (var i = 0; i < this._args.length; i ++) {
408 if (!(typeof this._args[i] == "string" ?
409 typeof arguments[i] == this._args[i] :
410 (typeof this._args[i] == "function" ?
411 this._args[i](arguments[i]) :
412 arguments[i] == this._args[i]))) {
413 return false;
414 }
415 };
416 return true
417 };
418 else object[propertyName].hasValidArguments = function() { return true };
419 };
420 object[propertyName]._this = _this;
421 if (this[propertyName]._callbacks.indexOf(object[propertyName]) < 0) this[propertyName]._callbacks.push(object[propertyName]);
422 }
423 },
424 toString: function() {
425 return Array.prototype.slice.apply(this).toString();
426 }
427 };
428
429 /* ##### jsapi.array.js ##### */
430
431 /*
432 <jsapi>
433 <author>2006 Florian Hoech</author>
434 <file>jsapi.array.js</file>
435 <dependencies>
436 jsapi.js
437 </dependencies>
438 </jsapi>
439 */
440
441 jsapi.array = {
442 $: function(object) {
443 // make array from object with only the numerical indices
444 var array = [], n;
445 if (object.length != null) for (var i = 0; i < object.length; i ++) array[i] = object[i];
446 else for (var i in object) if (!isNaN(n = parseInt(i)) && n == i) array[n] = object[i];
447 return array
448 }
449 };
450 jsapi.array.$._args = [null];
451
452 /* ##### jsapi.array.flat.js ##### */
453
454 /*
455 <jsapi>
456 <author>2006 Florian Hoech</author>
457 <file>jsapi.array.search.js</file>
458 <dependencies>
459 jsapi.array.js
460 </dependencies>
461 </jsapi>
462 */
463
464 jsapi.array.flat = function(a) {
465 var r = [];
466 for (var i = 0; i < a.length; i ++) {
467 if (a[i].constructor == Array) r = r.concat(jsapi.array.flat(a[i]));
468 else r.push(a[i])
469 };
470 return r
471 };
472 jsapi.array.flat._args = [Array];
473
474 /* ##### jsapi.dom.js ##### */
475
476 /*
477 <jsapi>
478 <author>2006 Florian Hoech</author>
479 <file>jsapi.dom.js</file>
480 <dependencies>
481 jsapi.js
482 </dependencies>
483 </jsapi>
484 */
485
486 jsapi.dom = {};
487
488 /* ##### jsapi.dom.NODETYPES.js ##### */
489
490 /*
491 <jsapi>
492 <author>2006 Florian Hoech</author>
493 <file>jsapi.dom.NODETYPES.js</file>
494 <dependencies>
495 jsapi.dom.js
496 </dependencies>
497 </jsapi>
498 */
499
500 jsapi.dom.NODETYPES = {
501 "1": "ELEMENT",
502 "2": "ATTRIBUTE",
503 "3": "TEXT",
504 "4": "CDATA_SECTION",
505 "5": "ENTITY_REFERENCE",
506 "6": "ENTITY",
507 "7": "PROCESSING_INSTRUCTION",
508 "8": "COMMENT",
509 "9": "DOCUMENT",
510 "10": "DOCUMENT_TYPE",
511 "11": "DOCUMENT_FRAGMENT",
512 "12": "NOTATION"
513 };
514
515 /* ##### jsapi.dom.isNode.js ##### */
516
517 /*
518 <jsapi>
519 <author>Florian Hoech</author>
520 <file>jsapi.dom.isNode.js</file>
521 <dependencies>
522 jsapi.dom.NODETYPES.js
523 </dependencies>
524 </jsapi>
525 */
526
527 jsapi.dom.isNode = function(object) {
528 return !!(object && jsapi.dom.NODETYPES[object.nodeType] && object.cloneNode);
529 };
530
531 /* ##### jsapi.string.js ##### */
532
533 /*
534 <jsapi>
535 <author>2006 Florian Hoech</author>
536 <file>jsapi.string.js</file>
537 <dependencies>
538 jsapi.js
539 </dependencies>
540 </jsapi>
541 */
542
543 jsapi.string = {};
544
545 /* ##### jsapi.string.trim.js ##### */
546
547 /*
548 <jsapi>
549 <author>2006 Florian Hoech</author>
550 <file>jsapi.string.trim.js</file>
551 <dependencies>
552 jsapi.string.js
553 </dependencies>
554 </jsapi>
555 */
556
557 jsapi.string.trim = function(str) {
558 return str.replace(/(^\s+|\s+$)/g, "")
559 };
560 jsapi.string.trim._args = [String];
561
562 /* ##### jsapi.useragent.js ##### */
563
564 /*
565 <jsapi>
566 <author>2006 Florian Hoech</author>
567 <file>jsapi.useragent.js</file>
568 <dependencies>
569 jsapi.string.trim.js
570 </dependencies>
571 </jsapi>
572
573 TO-DO: add KHTML
574 */
575
576 jsapi.useragent = {
577 $: function (ua) {
578 ua = (ua || navigator.userAgent).toLowerCase();
579 var i, j, match, _match, replace = [
580 [/(\d+\.)(\d+)\.(\d+)(\.(\d+))?/g, "$1$2$3$5"],
581 [/linux/g, ";linux;linux"],
582 [/mac/, ";mac;mac"],
583 [/microsoft ((p)ocket )?internet explorer/g, "ms$2ie"],
584 [/win32/g, "windows"],
585 [/windows (\w+)/g, "windows;windows $1"]
586 ];
587 for (i = 0; i < replace.length; i ++) ua = ua.replace(replace[i][0], replace[i][1]);
588 ua = ua.split(/[\(\)\[\]\{\}\,;]/);
589 for (i in this) {
590 if (typeof this[i] != "object" && typeof this[i] != "function") delete this[i]
591 };
592 for (i = 0; i < ua.length; i ++) {
593 match = ua[i].match(/[a-z\.\-_]+(\s+[a-z\.\-_]+)*\Wv?\d+(\.\d+)*/g);
594 if (match) {
595 for (j = 0; j < match.length; j ++) {
596 _match = match[j].match(/([a-z\.\-_]+(\s[a-z\.\-_]+)*)\Wv?(\d+(\.\d+)*)/);
597 if (!this[_match[1]] || (parseFloat(_match[3]) == _match[3] && this[_match[1]] < parseFloat(_match[3]))) this[_match[1]] = parseFloat(_match[3]) == _match[3] ? parseFloat(_match[3]) : _match[3]
598 }
599 }
600 else {
601 ua[i] = jsapi.string.trim(ua[i]);
602 if (ua[i]) this[ua[i]] = true
603 }
604 };
605 if (this.konqueror && !this.khtml) this.khtml = true;
606 if (this.safari === true) delete this.safari; // safari would have a version number here
607 if (!this.gecko && this.mozilla) {
608 this.compatible = this.mozilla;
609 delete this.mozilla
610 };
611 if (this.opera || this.safari || this.konqueror) {
612 if (this.mozilla) delete this.mozilla;
613 if (this.msie) delete this.msie
614 };
615 return this
616 }
617 };
618 jsapi.useragent.toString = function() {
619 var props = [];
620 for (i in this) {
621 if (typeof this[i] != "object" && typeof this[i] != "function")
622 props.push((/\s/.test(i) ? "'" : "") + i + (/\s/.test(i) ? "'" : "") + ":" + (typeof this[i] == "string" ? '"' : "") + this[i] + (typeof this[i] == "string" ? '"' : ""))
623 };
624 return props.join(", ");
625 };
626 jsapi.useragent.$._args = [String];
627 jsapi.useragent.$();
628
629 /* ##### jsapi.util.js ##### */
630
631 /*
632 <jsapi>
633 <author>2006 Florian Hoech</author>
634 <file>jsapi.util.js</file>
635 <dependencies>
636 jsapi.js
637 </dependencies>
638 </jsapi>
639 */
640
641 jsapi.util = {};
642
643 /* ##### jsapi.generic_accessor_mutator.js ##### */
644
645 /*
646 <jsapi>
647 <author>Florian Hoech</author>
648 <file>jsapi.generic_accessor_mutator.js</file>
649 <dependencies>
650 jsapi.js
651 jsapi.dom.js
652 jsapi.dom.isNode.js
653 jsapi.useragent.js
654 jsapi.util.js
655 </dependencies>
656 </jsapi>
657 */
658
659 jsapi.constants.ATTRIBUTE_ALIASES = {
660 "class": "className",
661 "for": "htmlFor",
662 readonly: "readOnly",
663 maxlength: "maxLength"
664 };
665 jsapi._attribute = function(object, attributeName, value) { // if arguments.length == 2, get attribute. otherwise, if value == null, remove attribute, else set attribute
666 switch (attributeName) {
667 case "style":
668 case "value":
669 return arguments.length == 2 ? jsapi._property(object, attributeName) : jsapi._property(object, attributeName, value);
670 default:
671 if (jsapi.constants.ATTRIBUTE_ALIASES[attributeName]) return jsapi._property.apply(jsapi, arguments);
672 else {
673 if (arguments.length == 2) return object.getAttribute(attributeName); // get attribute
674 if (value == null) object.removeAttribute(attributeName); // remove attribute
675 else object.setAttribute(attributeName, value); // set attribute
676 }
677 };
678 return object
679 };
680 jsapi._property = function(object, propertyName, value) { // if arguments.length == 2, get property. otherwise, if value == null, delete property, else set property
681 switch (propertyName) {
682 case "style":
683 if (arguments.length == 2) return object.style.cssText; // get attribute
684 object.style.cssText = value || ""; // set attribute
685 break;
686 };
687 if (jsapi.dom.isNode(object)) propertyName = jsapi.constants.ATTRIBUTE_ALIASES[propertyName] || propertyName;
688 if (arguments.length == 2) return object[propertyName];
689 object[propertyName] = value; // set property
690 if (value == null) try { delete object[propertyName] } catch (e) { }; // delete property
691 return object
692 };
693 jsapi.dom.attr =
694 jsapi.dom.attribute = function (object, attribute, value) {
695 return arguments.length == 2 && (typeof attribute != "object" || attribute.constructor == Array) ? jsapi._get(object, jsapi._attribute, attribute) : jsapi._set(object, jsapi._attribute, attribute, value);
696 };
697 jsapi.util.prop =
698 jsapi.util.property = function (object, property, value) {
699 return arguments.length == 2 && (typeof property != "object" || property.constructor == Array) ? jsapi._get(object, jsapi._property, property) : jsapi._set(object, jsapi._property, property, value);
700 };
701 jsapi._get = function (object, callback, property) {
702 if (typeof property != "object") return callback(object, property);
703 else {
704 var result = [];
705 for (var i = 0; i < property.length; i ++) result.push(callback(object, property[i]));
706 return result;
707 }
708 };
709 jsapi._set = function (object, callback, property, value) {
710 if (typeof property != "object") callback(object, property, value);
711 else {
712 if (property.constructor == Array) for (var i = 0; i < property.length; i ++) callback(object, property[i], value);
713 else for (var propertyName in property) callback(object, propertyName, property[propertyName] != null ? property[propertyName] : value);
714 };
715 return object;
716 };;
717
718 /* ##### jsapi.dom.attribute.js ##### */
719
720 /*
721 <jsapi>
722 <author>2006 Florian Hoech</author>
723 <file>jsapi.dom.attribute.js</file>
724 <dependencies>
725 jsapi.generic_accessor_mutator.js
726 </dependencies>
727 </jsapi>
728 */
729
730
731 /* ##### jsapi.dom.attributeAddWord.js ##### */
732
733 /*
734 <jsapi>
735 <author>2006 Florian Hoech</author>
736 <file>jsapi.dom.attributeAddWord.js</file>
737 <dependencies>
738 jsapi.dom.attribute.js
739 </dependencies>
740 </jsapi>
741 */
742
743 jsapi.dom.attributeAddWord = function(element, attr, word) {
744 var value = jsapi.dom.attribute(element, attr);
745 return jsapi.dom.attribute(element, attr, (value != null ? value + " " : "") + word)
746 };
747
748 /* ##### jsapi.dom.attributeHasWord.js ##### */
749
750 /*
751 <jsapi>
752 <author>2006 Florian Hoech</author>
753 <file>jsapi.dom.attributeHasWord.js</file>
754 <dependencies>
755 jsapi.dom.attribute.js
756 </dependencies>
757 </jsapi>
758 */
759
760 jsapi.dom.attributeHasWord = function(element, attr, word) {
761 return (new RegExp("(^|\\s)" + word + "(\\s|$)")).test(jsapi.dom.attribute(element, attr))
762 };
763
764 /* ##### jsapi.dom.attributeRemoveWord.js ##### */
765
766 /*
767 <jsapi>
768 <author>2006 Florian Hoech</author>
769 <file>jsapi.dom.attributeRemoveWord.js</file>
770 <dependencies>
771 jsapi.dom.attribute.js
772 </dependencies>
773 </jsapi>
774 */
775
776 jsapi.dom.attributeRemoveWord = function(element, attr, word) {
777 var value = jsapi.dom.attribute(element, attr);
778 if (value) jsapi.dom.attribute(element, attr, value.replace(new RegExp("(^|\\s+)" + word + "(\\s|$)"), "$2"));
779 return element
780 };
781
782 /* ##### jsapi.math.js ##### */
783
784 /*
785 <jsapi>
786 <author>2006 Florian Hoech</author>
787 <file>jsapi.math.js</file>
788 <dependencies>
789 jsapi.array.flat.js
790 </dependencies>
791 </jsapi>
792 */
793
794 jsapi.math = {
795 absmax: function(v) {
796 var a = jsapi.array.flat(arguments), r = a[0];
797 for (var i = 0; i < a.length; i ++) if (Math.abs(r) < Math.abs(a[i])) r = a[i];
798 return r
799 },
800 avg: function() {
801 var a = jsapi.array.flat(arguments), r = 0;
802 for (var i = 0; i < a.length; i ++) r += a[i];
803 return r / a.length
804 },
805 avgabs: function() {
806 var a = jsapi.array.flat(arguments), r = 0;
807 for (var i = 0; i < a.length; i ++) r += Math.abs(a[i]);
808 return r / a.length
809 },
810 cbrt: function(x) {
811 return x >= 0 ? Math.pow (x, 1 / 3) : -Math.pow (-x, 1 / 3)
812 },
813 deg: function(v) {
814 return v * 180 / Math.PI
815 },
816 longToUnsigned: function(num) {
817 while (num < 0) num += 4294967296;
818 return num
819 },
820 max: function(v) {
821 var a = jsapi.array.flat(arguments), r = a[0];
822 for (var i = 0; i < a.length; i ++) r = Math.max(r, a[i]);
823 return r
824 },
825 min: function(v) {
826 var a = jsapi.array.flat(arguments), r = a[0];
827 for (var i = 0; i < a.length; i ++) r = Math.min(r, a[i]);
828 return r
829 },
830 rad: function(v) {
831 return v / 180 * Math.PI
832 }
833 };
834 jsapi.math.absmax._args = [Number];
835 jsapi.math.avg._args = [Number];
836 jsapi.math.cbrt._args = [Number];
837 jsapi.math.deg._args = [Number];
838 jsapi.math.longToUnsigned._args = [Number];
839 jsapi.math.max._args = [Array];
840 jsapi.math.min._args = [Array];
841 jsapi.math.rad._args = [Number];
842
843 /* ##### jsapi.math.color.js ##### */
844
845 /*
846 <jsapi>
847 <author>2006 Florian Hoech</author>
848 <file>jsapi.math.color.js</file>
849 <dependencies>
850 jsapi.math.js
851 </dependencies>
852 </jsapi>
853 */
854
855 jsapi.math.color = {};
856
857 /* ##### jsapi.math.color.XYZ2CorColorTemp.js ##### */
858
859 /*
860 <jsapi>
861 <author>2007 Florian Hoech</author>
862 <file>jsapi.math.color.XYZ2CorColorTemp.js</file>
863 <dependencies>
864 jsapi.math.color.js
865 </dependencies>
866 </jsapi>
867 */
868
869 jsapi.math.color.XYZ2CorColorTemp = function(x, y, z) {
870 // derived from ANSI C implementation by Bruce Lindbloom www.brucelindbloom.com
871
872 // LERP(a,b,c) = linear interpolation macro, is 'a' when c == 0.0 and 'b' when c == 1.0
873 function LERP(a,b,c) {
874 return (b - a) * c + a
875 };
876
877 var rt = [ // reciprocal temperature (K)
878 Number.MIN_VALUE, 10.0e-6, 20.0e-6, 30.0e-6, 40.0e-6, 50.0e-6,
879 60.0e-6, 70.0e-6, 80.0e-6, 90.0e-6, 100.0e-6, 125.0e-6,
880 150.0e-6, 175.0e-6, 200.0e-6, 225.0e-6, 250.0e-6, 275.0e-6,
881 300.0e-6, 325.0e-6, 350.0e-6, 375.0e-6, 400.0e-6, 425.0e-6,
882 450.0e-6, 475.0e-6, 500.0e-6, 525.0e-6, 550.0e-6, 575.0e-6,
883 600.0e-6
884 ];
885
886 var uvt = [
887 [0.18006, 0.26352, -0.24341],
888 [0.18066, 0.26589, -0.25479],
889 [0.18133, 0.26846, -0.26876],
890 [0.18208, 0.27119, -0.28539],
891 [0.18293, 0.27407, -0.30470],
892 [0.18388, 0.27709, -0.32675],
893 [0.18494, 0.28021, -0.35156],
894 [0.18611, 0.28342, -0.37915],
895 [0.18740, 0.28668, -0.40955],
896 [0.18880, 0.28997, -0.44278],
897 [0.19032, 0.29326, -0.47888],
898 [0.19462, 0.30141, -0.58204],
899 [0.19962, 0.30921, -0.70471],
900 [0.20525, 0.31647, -0.84901],
901 [0.21142, 0.32312, -1.0182],
902 [0.21807, 0.32909, -1.2168],
903 [0.22511, 0.33439, -1.4512],
904 [0.23247, 0.33904, -1.7298],
905 [0.24010, 0.34308, -2.0637],
906 [0.24792, 0.34655, -2.4681], // Note: 0.24792 is a corrected value for the error found in W&S as 0.24702
907 [0.25591, 0.34951, -2.9641],
908 [0.26400, 0.35200, -3.5814],
909 [0.27218, 0.35407, -4.3633],
910 [0.28039, 0.35577, -5.3762],
911 [0.28863, 0.35714, -6.7262],
912 [0.29685, 0.35823, -8.5955],
913 [0.30505, 0.35907, -11.324],
914 [0.31320, 0.35968, -15.628],
915 [0.32129, 0.36011, -23.325],
916 [0.32931, 0.36038, -40.770],
917 [0.33724, 0.36051, -116.45]
918 ];
919
920 var us, vs, p, di, dm, i;
921
922 if ((x < 1e-20) && (y < 1e-20) && (z < 1e-20)) return -1; // protect against possible divide-by-zero failure
923
924 us = (4 * x) / (x + 15 * y + 3 * z);
925 vs = (6 * y) / (x + 15 * y + 3 * z);
926 dm = 0;
927 for (i = 0; i < 31; i++) {
928 di = (vs - uvt[i][1]) - uvt[i][2] * (us - uvt[i][0]);
929 if ((i > 0) && (((di < 0) && (dm >= 0)) || ((di >= 0) && (dm < 0)))) break; // found lines bounding (us, vs) : i-1 and i
930 dm = di
931 };
932 if (i == 31) return -1; // bad XYZ input, color temp would be less than minimum of 1666.7 degrees, or too far towards blue
933 di = di / Math.sqrt(1 + uvt[i ][2] * uvt[i ][2]);
934 dm = dm / Math.sqrt(1 + uvt[i - 1][2] * uvt[i - 1][2]);
935 p = dm / (dm - di); // p = interpolation parameter, 0.0 : i-1, 1.0 : i
936 return 1 / (LERP(rt[i - 1], rt[i], p));
937 };
938
939 /* ##### jsapi.math.color.delta.js ##### */
940
941 /*
942 <jsapi>
943 <author>2007 Florian Hoech</author>
944 <file>jsapi.math.color.delta.js</file>
945 <dependencies>
946 jsapi.math.color.js
947 </dependencies>
948 </jsapi>
949 */
950
951 jsapi.math.color.delta = function (L1, a1, b1, L2, a2, b2, method, p1, p2, p3, white, l1, l2, cat, debug) {
952 /*
953 CIE 1994 & CMC calculation code derived from formulas on www.brucelindbloom.com
954 CIE 1994 code uses some alterations seen on www.farbmetrik-gall.de/cielab/korrcielab/cie94.html (see notes in code below)
955 CIE 2000 calculation code derived from Excel spreadsheet available at www.ece.rochester.edu/~gsharma/ciede2000
956 Delta ICtCp based on research by Dolby
957
958 method: either "CIE94", "CMC", "CIE2K", "ICtCp" or "CIE76" (default if method is not set)
959
960 p1, p2, p3 arguments have different meaning for each calculation method:
961
962 CIE 1994: if p1 is not null, calculation will be adjusted for textiles, otherwise graphics arts (default if p1 is not set)
963 CMC(l:c): p1 equals l (lightness) weighting factor and p2 equals c (chroma) weighting factor.
964 commonly used values are CMC(1:1) for perceptability (default if p1 and p2 are not set) and CMC(2:1) for acceptability
965 CIE 2000: p1 becomes kL (lightness) weighting factor, p2 becomes kC (chroma) weighting factor and p3 becomes kH (hue) weighting factor
966 (all three default to 1 if not set)
967
968 white (ref. white for converson from L*a*b* to XYZ) and l1/l2 (white luminance in cd/m2) are used only for delta ICtCp
969 */
970 for (var i = 0; i < 6; i ++) if (typeof arguments[i] != "number" || isNaN(arguments[i])) return NaN;
971 if (typeof method == "string") method = method.toLowerCase();
972 switch (method) {
973 case "94":
974 case "1994":
975 case "cie94":
976 case "cie1994":
977 var textiles = p1,
978 dL = L2 - L1,
979 C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2)),
980 C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2)),
981 dC = C2 - C1,
982 dH2 = Math.pow(a1 - a2, 2) + Math.pow(b1 - b2, 2) - Math.pow(dC, 2),
983 dH = dH2 > 0 ? Math.sqrt(dH2) : 0,
984 SL = 1,
985 K1 = textiles ? 0.048 : 0.045,
986 K2 = textiles ? 0.014 : 0.015,
987 C_ = Math.sqrt(C1 * C2), // symmetric chrominance
988 SC = 1 + K1 * C_,
989 SH = 1 + K2 * C_,
990 KL = textiles ? 2 : 1,
991 KC = 1,
992 KH = 1,
993 dLw = dL / (KL * SL),
994 dCw = dC / (KC * SC),
995 dHw = dH / (KH * SH),
996 dE = Math.sqrt(Math.pow(dLw, 2) + Math.pow(dCw, 2) + Math.pow(dHw, 2));
997 break;
998 case "cmc(2:1)":
999 case "cmc21":
1000 p1 = 2;
1001 case "cmc(1:1)":
1002 case "cmc11":
1003 case "cmc":
1004 var l = typeof p1 == "number" ? p1 : 1,
1005 c = typeof p2 == "number" ? p2 : 1;
1006 dL = L2 - L1,
1007 C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2)),
1008 C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2)),
1009 dC = C2 - C1,
1010 dH2 = Math.pow(a1 - a2, 2) + Math.pow(b1 - b2, 2) - Math.pow(dC, 2),
1011 dH = dH2 > 0 ? Math.sqrt(dH2) : 0,
1012 SL = L1 < 16 ? 0.511 : (0.040975 * L1) / (1 + 0.01765 * L1),
1013 SC = (0.0638 * C1) / (1 + 0.0131 * C1) + 0.638,
1014 F = Math.sqrt(Math.pow(C1, 4) / (Math.pow(C1, 4) + 1900)),
1015 H1 = jsapi.math.deg(Math.atan2(b1, a1)) + (b1 >= 0 ? 0 : 360),
1016 T = 164 <= H1 && H1 <= 345 ? 0.56 + Math.abs(0.2 * Math.cos(jsapi.math.rad(H1 + 168))) : 0.36 + Math.abs(0.4 * Math.cos(jsapi.math.rad(H1 + 35))),
1017 SH = SC * (F * T + 1 - F),
1018 dLw = dL / (l * SL),
1019 dCw = dC / (c * SC),
1020 dHw = dH / SH,
1021 dE = Math.sqrt(Math.pow(dLw, 2) + Math.pow(dCw, 2) + Math.pow(dHw, 2));
1022 break;
1023 case "00":
1024 case "2k":
1025 case "2000":
1026 case "cie00":
1027 case "cie2k":
1028 case "cie2000":
1029 var pow25_7 = Math.pow(25, 7),
1030 k_L = typeof p1 == "number" ? p1 : 1,
1031 k_C = typeof p2 == "number" ? p2 : 1,
1032 k_H = typeof p3 == "number" ? p3 : 1,
1033 C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2)),
1034 C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2)) ,
1035 C_avg = jsapi.math.avg(C1, C2),
1036 G = .5 * (1 - Math.sqrt(Math.pow(C_avg, 7) / (Math.pow(C_avg, 7) + pow25_7))),
1037 L1_ = L1,
1038 a1_ = (1 + G) * a1,
1039 b1_ = b1,
1040 L2_ = L2,
1041 a2_ = (1 + G) * a2,
1042 b2_ = b2,
1043 C1_ = Math.sqrt(Math.pow(a1_, 2) + Math.pow(b1_, 2)),
1044 C2_ = Math.sqrt(Math.pow(a2_, 2) + Math.pow(b2_, 2)),
1045 h1_ = a1_ == 0 && b1_ == 0 ? 0 : jsapi.math.deg(Math.atan2(b1_, a1_)) + (b1_ >= 0 ? 0 : 360),
1046 h2_ = a2_ == 0 && b2_ == 0 ? 0 : jsapi.math.deg(Math.atan2(b2_, a2_)) + (b2_ >= 0 ? 0 : 360),
1047 dh_cond = h2_ - h1_ > 180 ? 1 : (h2_ - h1_ < -180 ? 2 : 0),
1048 dh_ = dh_cond == 0 ? h2_ - h1_ : (dh_cond == 1 ? h2_ - h1_ - 360 : h2_ + 360 - h1_),
1049 dL_ = L2_ - L1_,
1050 dL = dL_,
1051 dC_ = C2_ - C1_,
1052 dC = dC_,
1053 dH_ = 2 * Math.sqrt(C1_ * C2_) * Math.sin(jsapi.math.rad(dh_ / 2)),
1054 dH = dH_,
1055 L__avg = jsapi.math.avg(L1_, L2_),
1056 C__avg = jsapi.math.avg(C1_, C2_),
1057 h__avg_cond = C1_ * C2_ == 0 ? 3 : (Math.abs(h2_ - h1_) <= 180 ? 0 : (h2_ + h1_ < 360 ? 1 : 2)),
1058 h__avg = h__avg_cond == 3 ? h1_ + h2_ : (h__avg_cond == 0 ? jsapi.math.avg(h1_, h2_) : (h__avg_cond == 1 ? jsapi.math.avg(h1_, h2_) + 180 : jsapi.math.avg(h1_, h2_) - 180)),
1059 AB = Math.pow(L__avg - 50, 2), // (L'_ave-50)^2
1060 S_L = 1 + .015 * AB / Math.sqrt(20 + AB),
1061 S_C = 1 + .045 * C__avg,
1062 T = 1 - .17 * Math.cos(jsapi.math.rad(h__avg - 30)) + .24 * Math.cos(jsapi.math.rad(2 * h__avg)) + .32 * Math.cos(jsapi.math.rad(3 * h__avg + 6))
1063 - .2 * Math.cos(jsapi.math.rad(4 * h__avg - 63)),
1064 S_H = 1 + .015 * C__avg * T,
1065 dTheta = 30 * Math.exp(-1 * Math.pow((h__avg - 275) / 25, 2)),
1066 R_C = 2 * Math.sqrt(Math.pow(C__avg, 7) / (Math.pow(C__avg, 7) + pow25_7)),
1067 R_T = -Math.sin(jsapi.math.rad(2 * dTheta)) * R_C,
1068 AJ = dL_ / S_L / k_L, // dL' / k_L / S_L
1069 AK = dC_ / S_C / k_C, // dC' / k_C / S_C
1070 AL = dH_ / S_H / k_H, // dH' / k_H / S_H
1071 dLw = AJ,
1072 dCw = AK,
1073 dHw = AL,
1074 dE = Math.sqrt(Math.pow(AJ, 2) + Math.pow(AK, 2) + Math.pow(AL, 2) + R_T * AK * AL);
1075
1076 if (debug) {
1077 r = (C1 + "|" + C2 + "|" + C_avg + "|" + G + "|" + L1_ + "|" + a1_ + "|" + b1_ + "|" + L2_ + "|" + a2_ + "|" + b2_ + "|" + C1_ + "|" + C2_ + "|" + h1_ + "|" + h2_ + "|" + dh_ + "|" + dL_ + "|" + dC_ + "|" + dH_ + "|" + L__avg + "|" + C__avg + "|" + h__avg + "|" + AB + "|" + S_L + "|" + S_C + "|" + T + "|" + S_H + "|" + dTheta + "|" + R_C + "|" + R_T + "|" + AJ + "|" + AK + "|" + AL + "|" + dE + "|" + dh_cond + "|" + h__avg_cond).split("|");
1078 alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1079 t = [];
1080 n = alpha.indexOf("G");
1081 for (i = 0; i < r.length; i ++) {
1082 a = i + n < alpha.length ? alpha[i + n] : "A" + alpha[i + n - alpha.length];
1083 t.push(a + ": " + r[i]);
1084 }
1085 return t.join("\n");
1086 };
1087
1088 break;
1089 case "ictcp":
1090 // Incoming L*a*b* values can match these criteria:
1091 // - Relative to D50 (explicit). White a* b* != 0.
1092 // No chromatic adaptation necessary, converting to XYZ yields
1093 // original illuminant relative values. 'D50' white must be given.
1094 // - Relative to given whitepoint XYZ. White a* b* == 0.
1095 // Chromatic adaptation necessary.
1096 // - Relative to D50 (implicit). White a* b* == 0.
1097 // Chromatic adaptation necessary, set white to 'null'.
1098 var XYZ1 = jsapi.math.color.Lab2XYZ(L1, a1, b1, white),
1099 XYZ2 = jsapi.math.color.Lab2XYZ(L2, a2, b2, white),
1100 XYZ1a = white == 'D50' ? XYZ1 : jsapi.math.color.adapt(XYZ1[0], XYZ1[1], XYZ1[2], white, "D65", cat),
1101 XYZ2a = white == 'D50' ? XYZ2 : jsapi.math.color.adapt(XYZ2[0], XYZ2[1], XYZ2[2], white, "D65", cat),
1102 //XYZ1a = XYZ1,
1103 //XYZ2a = XYZ2,
1104 s1 = l1 / 10000,
1105 s2 = l2 / 10000,
1106 ICtCp1 = jsapi.math.color.XYZ2ICtCp(XYZ1a[0] * s1, XYZ1a[1] * s1, XYZ1a[2] * s1),
1107 ICtCp2 = jsapi.math.color.XYZ2ICtCp(XYZ2a[0] * s2, XYZ2a[1] * s2, XYZ2a[2] * s2),
1108 I1 = ICtCp1[0], Ct1 = ICtCp1[1], Cp1 = ICtCp1[2],
1109 I2 = ICtCp2[0], Ct2 = ICtCp2[1], Cp2 = ICtCp2[2],
1110 L1 = I1,
1111 L2 = I2,
1112 a1 = Math.sqrt(0.25 * Math.pow(Ct1, 2)) * 240,
1113 b1 = Cp1 * 240,
1114 a2 = Math.sqrt(0.25 * Math.pow(Ct2, 2)) * 240,
1115 b2 = Cp2 * 240,
1116 dL = (I2 - I1) * 480,
1117 C1 = Math.sqrt(0.25 * Math.pow(Ct1, 2) + Math.pow(Cp1, 2)),
1118 C2 = Math.sqrt(0.25 * Math.pow(Ct2, 2) + Math.pow(Cp2, 2)),
1119 dC = C2 - C1,
1120 dH = 0.25 * Math.pow(Ct2 - Ct1, 2) + Math.pow(Cp2 - Cp1, 2) - Math.pow(dC, 2),
1121 dH = dH > 0 ? Math.sqrt(dH) * 240 : 0,
1122 dC = dC * 240,
1123 dLw = dL,
1124 dCw = dC,
1125 dHw = dH,
1126 dE = Math.sqrt(4 * Math.pow(I2 - I1, 2) + 0.25 * Math.pow(Ct2 - Ct1, 2) + Math.pow(Cp2 - Cp1, 2)) * 240; // Normalization per Pytlarz
1127 break;
1128 default:
1129 var dL = L2 - L1,
1130 C1 = Math.sqrt(Math.pow(a1, 2) + Math.pow(b1, 2)),
1131 C2 = Math.sqrt(Math.pow(a2, 2) + Math.pow(b2, 2)),
1132 dC = C2 - C1,
1133 dH2 = Math.pow(a1 - a2, 2) + Math.pow(b1 - b2, 2) - Math.pow(dC, 2),
1134 dH = dH2 > 0 ? Math.sqrt(dH2) : 0,
1135 dLw = dL,
1136 dCw = dC,
1137 dHw = dH,
1138 dE = Math.sqrt(Math.pow(dL, 2) + Math.pow(a1 - a2, 2) + Math.pow(b1 - b2, 2));
1139 if (isNaN(dH)) {
1140 if (window.location.href.indexOf("?debug")>-1) alert('a1: ' + a1 + '\na2: ' + a2 + '\nMath.pow(a1 - a2, 2): ' + Math.pow(a1 - a2, 2) + '\nb1: ' + b1 + '\nb2: ' + b2 + '\nMath.pow(b1 - b2, 2): ' + Math.pow(b1 - b2, 2) + '\ndC: ' + dC + '\nMath.pow(dC, 2): ' + Math.pow(dC, 2) + '\nMath.pow(a1 - a2, 2) + Math.pow(b1 - b2, 2) - Math.pow(dC, 2): ' + (Math.pow(a1 - a2, 2) + Math.pow(b1 - b2, 2) - Math.pow(dC, 2)));
1141 }
1142 };
1143
1144 return {
1145 E: dE,
1146 L: dL,
1147 C: dC,
1148 H: dH,
1149 a: a1 - a2,
1150 b: b1 - b2,
1151 Ch: Math.sqrt(Math.pow(a1 - a2, 2) + Math.pow(b1 - b2, 2)),
1152 // Weighted
1153 Lw: dLw,
1154 Cw: dCw,
1155 Hw: dHw
1156 };
1157 };