/
css.js
1233 lines (1103 loc) · 35 KB
/
css.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* <title>PointedEars' DOM Library: CSS</title>
* @version $Id$
* @requires dom.js
* @recommends collection.js
*
* @section Copyright & Disclaimer
*
* @author
* (C) 2005-2013 Thomas Lahn <js@PointedEars.de>
*
* @partof PointedEars' JavaScript Extensions (JSX)
*
* JSX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JSX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with JSX. If not, see <http://www.gnu.org/licenses/>.
*/
if (typeof jsx == "undefined")
{
/**
* @namespace
*/
var jsx = {};
}
if (typeof jsx.dom == "undefined")
{
if (typeof jsx.importFrom == "function")
{
jsx.importFrom(jsx.absPath("../dom.js", jsx.importFrom.lastImport));
}
else
{
/**
* @namespace
*/
jsx.dom = {};
}
}
/**
* @type jsx.dom.css
* @memberOf __jsx.dom.css
* @namespace
*/
jsx.dom.css = (/** @constructor */ function () {
var _jsx_object = jsx.object;
var _LENGTH = 1;
var _COLOR = 5;
var _FLOAT = 7;
var _TRANSFORM = 8;
return {
/**
* @memberOf jsx.dom.css
*/
version: "0.1.$Revision$",
/**
* Supported CSS data types. Properties include:
* <dl>
* <dt><code>NUMBER</code></dt>
* <dd></dd>
*
* <dt><code>LENGTH</code></dt>
* <dd></dd>
*
* <dt><code>PERCENTAGE</code></dt>
* <dd></dd>
*
* <dt><code>URI</code></dt>
* <dd>Uniform Resource Identifier or URI-reference (see RFC 3986),
* enclosed in <code>url(…)</code></dd>
*
* <dt><code>COUNTER</code></dt>
* <dd>CSS counter</dd>
*
* <dt><code>COLOR</code></dt>
* <dd>Color in RGB(A) or HSV format</dd>
*
* <dt><code>STRING</code></dt>
* <dd>Unicode string</dd>
* </dl>
*
* @namespace
*/
types: {
/**
* Numeric scalar value
*/
NUMBER: 0,
/**
* Length given relative in <code>em</code> (width of the
* M square) or <code>ex</code> (height of the x square),
* or absolute in <code>in</code> (inches), <code>cm</code>
* (centimeters), <code>mm</code> (millimeters), <code>pt</code>
* (points), <code>pc</code> (picas), or <code>px</code>
* (pixels).
*/
LENGTH: _LENGTH,
/**
* Length given in percentage of the parent
*/
PERCENTAGE: 2,
/**
* Uniform Resource Identifier or URI-reference (see RFC 3986),
* enclosed in <code>url(…)</code>.
*/
URI: 3,
/**
* CSS counter
*/
COUNTER: 4,
/**
* Color given in RGB(A) or HSV format
*/
COLOR: _COLOR,
/**
* String of Unicode characters
*/
STRING: 6,
/**
* List of transformations
*/
FLOAT: _FLOAT,
/**
* List of transformations
*/
TRANSFORM: _TRANSFORM
},
prefixedProperties: {
transition: true,
animation: true
},
/**
* Property name prefixes
*/
prefixes: {
camelized: ["Moz", "Ms", "O", "Webkit", ""],
uncamelized: ["-moz-", "-ms-", "-o-", "-webkit-", ""]
},
/**
* Provides information about the type of a CSS property and its relation
* to other CSS properties
*
* @namespace
*/
propertyInfo: {
"float": {
type: _FLOAT,
aliases: ["cssFloat", "styleFloat"]
},
left: {
type: _LENGTH,
correspondsTo: "top"
},
top: {
type: _LENGTH,
correspondsTo: "left"
},
right: {
type: _LENGTH,
correspondsTo: "bottom"
},
bottom: {
type: _LENGTH,
correspondsTo: "right"
},
width: {
type: _LENGTH,
correspondsTo: "height"
},
height: {
type: _LENGTH,
correspondsTo: "width"
},
color: {
type: _COLOR
},
/* FIXME */
backgroundColor: {
type: _COLOR
},
"background-color": {
type: _COLOR
},
transform: {
type: _TRANSFORM
}
},
/**
* @function
*/
camelize: (function () {
if (typeof jsx.map != "undefined" && typeof jsx.map.Map == "function")
{
var cache = new jsx.map.Map();
}
else
{
var prefix = " ", suffix = "";
cache = _jsx_object.getDataObject();
cache.get = function (s) {
return _jsx_object.getProperty(this, prefix + s + suffix, false);
};
cache.put = function (s, v) {
this[prefix + s + suffix] = v;
};
}
function f (match, p1)
{
return p1.toUpperCase();
}
var rxHyphenated = /-([a-z])/gi;
/**
* @param {String} sProperty
* @return {string}
* <var>sProperty</var> with all hyphen-minuses followed by an
* ASCII letter replaced by the letter's uppercase counterpart
*/
return function (sProperty) {
var p;
if ((p = cache.get(sProperty, false)))
{
return p;
}
var s2 = sProperty.replace(rxHyphenated, f);
cache.put(sProperty, s2);
return s2;
};
})(),
/**
* @function
*/
uncamelize: (function () {
if (typeof jsx.map != "undefined" && typeof jsx.map.Map == "function")
{
var cache = new jsx.map.Map();
}
else
{
var prefix = " ", suffix = "";
cache = _jsx_object.getDataObject();
cache.get = function (s) {
return _jsx_object.getProperty(this, prefix + s + suffix, false);
};
cache.put = function (s, v) {
this[prefix + s + suffix] = v;
};
}
function f (match)
{
return "-" + match.toLowerCase();
}
var rxUppercase = /[A-Z]/g;
/**
* @param {String} sProperty
* @return {string}
* <var>sProperty</var> with all capital ASCII letters replaced
* by the letter's lowercase counterpart, and preceded by a
* hyphen-minus.
*/
return function (sProperty) {
var p;
if ((p = cache.get(sProperty, false)))
{
return p;
}
var s2 = sProperty.replace(rxUppercase, f);
cache.put(sProperty, s2);
return s2;
};
})(),
/**
* Returns the computed style of an {@link Element} or the
* computed value of an <code>Element</code>'s style property.
*
* @function
*/
getComputedStyle: (function () {
var _isMethod = _jsx_object.isMethod;
var _defaultView;
/**
* @param {Element} oElement
* Element for which the computed style should be retrieved.
* @param {string} sPseudoEl
* The name of the pseudo-element, such as ":first-child".
* Use <code>null</code> (default) for the element itself.
* @param {string} sProperty
* The property name in CSS or script syntax (names are mapped
* automatically according to the feature used). If not passed
* or empty, the entire computed style is returned.
* @return {CSSStyleDeclaration|currentStyle|string|null}
* The return value depends on both the passed arguments
* and the capabilities of the user agent:
*
* If the UA supports either ViewCSS::getComputedStyle()
* from W3C DOM Level 2 CSS or MSHTML's currentStyle
* property, then
* a) if <var>sProperty</var> was passed, the value of the
* CSS property with name <var>sProperty</vr> is returned;
* it is a string if the property is supported;
* b) if <var>cssProperty</var> was not passed, the corresponding
* style object is returned
*
* However, MSHTML's currentStyle does not support pseudo-elements.
* If you attempt to retrieve pseudo-element's computed style,
* <code>null</code> is returned (without error).
*
* If the UA supports neither of the above, <code>null</code>
* is returned.
*/
function _getComputedStyle (oElement, sPseudoEl, sProperty)
{
var computedStyle;
if (_isMethod(document, "defaultView", "getComputedStyle")
&& (typeof _defaultView != "undefined" || (_defaultView = document.defaultView)))
{
computedStyle = _defaultView.getComputedStyle(oElement, sPseudoEl || null);
}
else
{
if (sPseudoEl)
{
return null;
}
computedStyle = oElement.currentStyle;
}
if (typeof computedStyle != "undefined")
{
if (!sProperty)
{
return computedStyle;
}
return jsx.dom.css.getStyleProperty({style: computedStyle}, sProperty);
}
return null;
}
return _getComputedStyle;
}())
};
})();
/**
* Retrieves the value of a style property of an {@link Element}.
*
* @author
* (C) 2005, 2013 Thomas Lahn <js@PointedEars.de>
* @partof
* http://pointedears.de/scripts/dom/css.js
*/
jsx.dom.css.getStyleProperty = (function () {
var _isHostMethod = jsx.object.isHostMethod;
var _camelize = jsx.dom.css.camelize;
var _uncamelize = jsx.dom.css.uncamelize;
var _prefixedProperties = jsx.dom.css.prefixedProperties;
var _prefixes = jsx.dom.css.prefixes;
var _propertyInfo = jsx.dom.css.propertyInfo;
/**
* @param {Element} oElement
* Reference to the element object whose style is to be retrieved.
* @param {String} sPropertyName
* Name of the style property whose value is to be retrieved.
* Both camelCased and dash-property names are supported.
* Mapping to supported prefix properties is done automatically,
* i. e. <code>"transition"</code> would cause
* <code>"-webkit-transition"</code> to be retrieved if
* the former but not <code>"transition"</code> was available.
* If the <code>style</code> property is available on the element,
* the faster property-accessor approach is attempted first,
* then the slower setProperty() call.
* Otherwise <code>"visibility"</code> is used instead
* (fallback for the NN4 DOM).
* @return {string|null}
* <code>null</code> if no matching object exists or if the
* DOM does not provide for retrieval of the property value.
*/
function _getStyleProperty (oElement, sPropertyName)
{
if (oElement)
{
/* TODO: Needed for NN4 DOM as well? */
var camelized_name = _camelize(sPropertyName);
if (typeof oElement.style != "undefined")
{
var style = oElement.style;
var thisPropertyInfo = _propertyInfo[camelized_name];
var thisAliases = thisPropertyInfo && thisPropertyInfo.aliases;
if (thisAliases)
{
for (var i = thisAliases.length; i--;)
{
var alias = thisAliases[i];
if (typeof style[alias] != "undefined")
{
return style[alias];
}
}
return null;
}
if (_prefixedProperties[sPropertyName])
{
for (i = _prefixes.camelized.length; i--;)
{
var prefix = _prefixes.camelized[i];
var prefixed_name = (prefix
? prefix
+ camelized_name.charAt(0).toUpperCase()
+ camelized_name.substring(1)
: camelized_name);
if (typeof style[prefixed_name] != "undefined")
{
return style[prefixed_name];
}
}
return null;
}
if (typeof style[camelized_name] != "undefined")
{
return style[camelized_name];
}
/* If the quick, backwards-compatible method failed for some reason */
if (_isHostMethod(style, "getPropertyValue"))
{
var uncamelized_name = _uncamelize(sPropertyName);
/* NOTE: Works because of no dash-properties in _prefixedProperties */
if (_prefixedProperties[sPropertyName])
{
for (i = _prefixes.uncamelized.length; i--;)
{
var value = style.getPropertyValue(
_prefixes.uncamelized[i] + uncamelized_name);
if (value)
{
return value;
}
}
return null;
}
return style.getPropertyValue(uncamelized_name);
}
}
else
{
if (camelized_name == "display")
{
camelized_name = "visibility";
}
if (typeof oElement[camelized_name] != "undefined")
{
return oElement[camelized_name];
}
}
}
return null;
}
return _getStyleProperty;
}());
/**
* Determines whether an {@link Element} has a style property.
*
* @author
* (C) 2006 Thomas Lahn <js@PointedEars.de>
* @partof
* http://pointedears.de/scripts/dom/css.js
* @param {HTMLElement} oElement
* Reference to the element object which style property is to be retrieved.
* @param {string} sPropertyName
* Name of the style property which is to be checked.
* If "display", and there is no
* <code>style[<var>sPropertyName</var>]</code> property,
* "visibility" is used instead (fallback for the NN4 DOM).
* @return {boolean}
* <code>false</code> if no matching object exists or if the
* DOM does not provide for retrieval of the property value;
* <code>true</code> otherwise.
*/
jsx.dom.hasStyleProperty = function (oElement, sPropertyName) {
return (jsx.dom.css.getStyleProperty(oElement, sPropertyName) != null);
};
/**
* Sets the value of a style property of an {@link Element}.
*
* @function
* @author
* (C) 2003-2013 Thomas Lahn <js@PointedEars.de>
* @partof
* http://pointedears.de/scripts/dom/css.js
*/
jsx.dom.css.setStyleProperty = (function () {
var _isHostMethod = jsx.object.isHostMethod;
var _camelize = jsx.dom.css.camelize;
var _uncamelize = jsx.dom.css.uncamelize;
var _prefixedProperties = jsx.dom.css.prefixedProperties;
var _prefixes = jsx.dom.css.prefixes;
var _propertyInfo = jsx.dom.css.propertyInfo;
/**
* @param {Element} oElement
* Reference to the element object whose style is to be modified.
* @param {string} sPropertyName
* Name of the style property whose value should be set.
* Both camelCased and dash-property names are supported.
* Mapping to supported prefix properties is done automatically,
* i. e. <code>"transition"</code> would cause only
* <code>"-webkit-transition"</code> to be set if the former
* but not <code>"transition"</code> was available.
* If the <code>style</code> property is available on the element,
* the faster property-accessor approach is attempted first,
* then the slower setProperty() call.
* If <code>"display"</code>, and there is no <code>style</code>
* property, and <code>altValue</code> was provided, "visibility"
* is used instead (fallback for the NN4 DOM).
* @param propValue
* Value of the style property to be set.
* @param {_} altValue (optional)
* Alternative value to be set if the the style property is a
* property of the object itself instead of its `style' property.
* Fallback for the NN4 DOM.
* @return {boolean}
* <code>false</code> if no such object exists, the
* DOM does not provide for setting the property value,
* or if the assignment failed (invalid value).
* CAVEAT: Some property values are normalized by the DOM API
* when read; test before using the return value as a discriminator.
*/
function _setStyleProperty (oElement, sPropertyName, propValue, altValue)
{
if (oElement)
{
/* TODO: Needed for NN4 DOM as well? */
var camelized_name = _camelize(sPropertyName);
if (typeof oElement.style != "undefined")
{
var style = oElement.style;
var thisPropertyInfo = _propertyInfo[camelized_name];
var thisAliases = thisPropertyInfo && thisPropertyInfo.aliases;
if (thisAliases)
{
for (var i = thisAliases.length; i--;)
{
var alias = thisAliases[i];
if (typeof style[alias] != "undefined")
{
style[alias] = propValue;
return (String(style[alias]).toLowerCase()
== String(propValue).toLowerCase());
}
}
return false;
}
if (_prefixedProperties[sPropertyName])
{
var len;
for (i = 0, len = _prefixes.camelized.length; i < len; ++i)
{
var prefix = _prefixes.camelized[i];
var prefixed_name = (prefix
? prefix
+ camelized_name.charAt(0).toUpperCase()
+ camelized_name.substring(1)
: camelized_name);
if (typeof style[prefixed_name] != "undefined")
{
style[prefixed_name] = propValue;
}
}
return (String(style[prefixed_name]).toLowerCase()
== String(propValue).toLowerCase());
}
if (typeof style[camelized_name] != "undefined")
{
style[camelized_name] = propValue;
return (String(style[camelized_name]).toLowerCase()
== String(propValue).toLowerCase());
}
/* If the quick, backwards-compatible method failed for some reason */
if (_isHostMethod(style, "setProperty"))
{
var uncamelized_name = _uncamelize(sPropertyName);
/* NOTE: Works because of no dash-properties in _prefixedProperties */
if (_prefixedProperties[sPropertyName])
{
for (i = 0, len = _prefixes.uncamelized.length; i < len; ++i)
{
style.setProperty(
_prefixes.uncamelized[i] + uncamelized_name,
propValue);
}
if (!_isHostMethod(style, "getPropertyValue"))
{
return true;
}
return (String(style.getPropertyValue(sPropertyName)).toLowerCase()
== String(propValue).toLowerCase());
}
style.setProperty(uncamelized_name, propValue);
return (String(style.getPropertyValue(uncamelized_name)).toLowerCase()
== String(propValue).toLowerCase());
}
}
else
{
/* NN4 DOM */
if (camelized_name == "display" && altValue)
{
camelized_name = "visibility";
}
if (typeof oElement[camelized_name] != "undefined")
{
var newValue = (altValue || propValue);
oElement[camelized_name] = newValue;
return (String(oElement[camelized_name]).toLowerCase()
== String(newValue).toLowerCase());
}
}
}
return false;
}
return _setStyleProperty;
}());
/**
* Resets a style property to its inherited value
*
* @param {Element} oElement
* @param {String} sPropertyName
* @return {boolean}
* @see jsx.dom.css.setStyleProperty()
*/
jsx.dom.css.resetStyleProperty = function (oElement, sPropertyName) {
return jsx.dom.css.setStyleProperty(oElement, sPropertyName, "");
};
/**
* Retrieves the rendering state or (dis)allows rendering of a DOM object.
*
* @author
* (C) 2004-2006 Thomas Lahn <dhtml.js@PointedEars.de>
* @partof
* http://pointedears.de/scripts/dhtml.js
* @param {HTMLElement} oElement
* Reference to the DOM object to be rendered or not.
* @param {boolean} bShow
* Renders the object referenced by <code>o</code> if
* <code>true</code>, does not render it if <code>false</code>.
* Note that not to render an element is different from
* hiding it, as the space it would take up is then no
* longer reserved.
*
* If this argument is omitted, the current property value is returned.
* @return {boolean}
* When retrieving: <code>true</code> if visible, <code>false</code>
* otherwise; when setting: <code>true</code> if successful,
* <code>false</code> otherwise.
* @see #visible
*/
jsx.dom.display = function (oElement, bShow) {
var result;
if (oElement)
{
if (arguments.length > 1)
{
result = jsx.dom.css.setStyleProperty(oElement, "display",
bShow ? "" : "none",
bShow ? "show" : "hide");
}
else
{
result = /^(\s*|show)$/.test(jsx.dom.css.getStyleProperty(oElement, "display"));
}
}
return result;
};
/**
* Retrieves or sets the visibility of a DOM object.
*
* @author
* (C) 2004-2006 Thomas Lahn <dhtml.js@PointedEars.de>
* @partof
* http://pointedears.de/scripts/dhtml.js
* @param {HTMLElement} oElement
* Reference to the DOM object to be either shown or hidden.
* @param {Boolean} bVisible (optional)
* Shows the object referenced by <code>o</code> if <code>true</code>,
* hides it if <code>false</code>. Note that hiding an element is
* different from not rendering it, as the space it takes up is still
* reserved.
*
* If this argument is omitted, the current property value is returned.
* @return {boolean}
* When retrieving: <code>true</code> if visible, <code>false</code>
* otherwise; when setting: <code>true</code> if successful,
* <code>false</code> otherwise.
* @see #display
*/
jsx.dom.visibility = jsx.dom.visible = function (oElement, bVisible) {
var result;
if (oElement)
{
if (arguments.length > 1)
{
result = jsx.dom.css.setStyleProperty(oElement, "visibility",
bVisible ? "visible" : "hidden",
bVisible ? "show" : "hide");
}
else
{
result = /^(visible|show)$/.test(
jsx.dom.css.getStyleProperty(oElement, "visibility"));
}
}
return result;
};
/**
* @param {Number|String} imgID
* @param {boolean} state (optional)
* A true-value for the mouseover effect, the mouseout effect otherwise.
* @return {boolean}
* The return value of {@link #setStyleProperty} for setting the
* borderColor of the image
*/
jsx.dom.hoverImg = function (imgID, state) {
var img = null;
if (document.images)
{
img = document.images[imgID];
}
var me = arguments.callee;
return jsx.dom.css.setStyleProperty(img, "borderColor",
(state ? me.clMouseover : me.clMouseout));
};
jsx.dom.hoverImg.clMouseout = "#000";
jsx.dom.hoverImg.clMouseover = "#fff";
jsx.dom.getAbsPos = function (oNode) {
/* TODO: One initialization for all properties? */
var result = {};
result.x = result.y = 0;
result.toString = function () {
return "{x: " + this.x + ", y: " + this.y + "}";
};
if (oNode.offsetParent)
{
while (oNode.offsetParent)
{
result.x += oNode.offsetLeft;
result.y += oNode.offsetTop;
oNode = oNode.offsetParent;
}
}
else if (typeof oNode.x != "undefined"
&& typeof oNode.y != "undefined")
{
result.x += oNode.x;
result.y += oNode.y;
}
return result;
};
/**
* @namespace
*/
jsx.dom.css.selectors = {
ID: "#{nmchar}+"
.replace(/\{nmchar\}/, "[_a-z0-9-]|{nonascii}|{escape}")
.replace(/\{nonascii\}/g, "[\\xA0-\\xFF]")
.replace(/\{escape\}/g, "{unicode}|\\\\[^\\r\\n\\f0-9a-f]")
.replace(/\{unicode\}/g, "\\\\{h}{1,6}(\\r\\n|[ \\t\\r\\n\\f])?")
.replace(/\{h\}/g, "[0-9a-f]"),
CLASS: "\\.IDENT"
.replace(/IDENT/, "-?{nmstart}{nmchar}*")
.replace(/\{nmstart\}/, "[_a-z]|{nonascii}|{escape}")
.replace(/\{nmchar\}/, "[_a-z0-9-]|{nonascii}|{escape}")
.replace(/\{nonascii\}/g, "[\\xA0-\\xFF]")
.replace(/\{escape\}/g, "{unicode}|\\\\[^\\r\\n\\f0-9a-f]")
.replace(/\{unicode\}/g, "\\\\{h}{1,6}(\\r\\n|[ \\t\\r\\n\\f])?")
.replace(/\{h\}/g, "[0-9a-f]"),
ATTRIBUTE: "\\[\\s*(IDENT\\|)?IDENT\\s*((=|INCLUDES|DASHMATCH)\\s*(IDENT|STRING)\\s*)?\\]"
.replace(/IDENT/g, "-?{nmstart}{nmchar}*")
.replace(/INCLUDES/, "~=")
.replace(/DASHMATCH/, "\\|=")
.replace(/STRING/, "{string1}|{string2}")
.replace(/\{string1\}/, '"([^\\n\\r\\f\\\\"]|\\\\{nl}|{escape})*"')
.replace(/\{string2\}/, "'([^\\n\\r\\f\\\\']|\\\\{nl}|{escape})*'")
.replace(/\{nl\}/g, "(\\n|\\r\n|\\r|\\f)")
.replace(/\{nmstart\}/g, "[_a-z]|{nonascii}|{escape}")
.replace(/\{nmchar\}/g, "[_a-z0-9-]|{nonascii}|{escape}")
.replace(/\{nonascii\}/g, "[\\xA0-\\xFF]")
.replace(/\{escape\}/g, "{unicode}|\\\\[^\\r\\n\\f0-9a-f]")
.replace(/\{unicode\}/g, "\\\\{h}{1,6}(\\r\\n|[ \\t\\r\\n\\f])?")
.replace(/\{h\}/g, "[0-9a-f]"),
PSEUDOCLASS: ":(link|visited|hover|active|focus|target|lang"
+ "|enabled|disabled|checked|indeterminate"
+ "|root|nth-child|nth-last-child|nth-of-type|nth-last-of-type"
+ "|first-child|last-child|first-of-type|last-of-type"
+ "|only-child|only-of-type|empty|not)\\b",
ELEMENT: "(^|\\s)((IDENT|\\*)\\|)?IDENT"
.replace(/IDENT/g, "-?{nmstart}{nmchar}*")
.replace(/\{nmstart\}/g, "[_a-z]|{nonascii}|{escape}")
.replace(/\{nmchar\}/g, "[_a-z0-9-]|{nonascii}|{escape}")
.replace(/\{nonascii\}/g, "[\\xA0-\\xFF]")
.replace(/\{escape\}/g, "{unicode}|\\\\[^\\r\\n\\f0-9a-f]")
.replace(/\{escape\}/g, "{unicode}|\\\\[^\\r\\n\\f0-9a-f]")
.replace(/\{unicode\}/g, "\\\\{h}{1,6}(\\r\\n|[ \\t\\r\\n\\f])?")
.replace(/\{h\}/g, "[0-9a-f]"),
PSEUDOELEMENT: "::?(first-line|first-letter|before|after)\\b"
};
/**
* A <code>RuleList</code> object encapsulates
* all CSS selectors linked to from a document in a
* {@link Collection}.
*
* @constructor
* @param {Object} oDocument (optional)
* Object reference to override the default
* <code>document</code> object reference.
* @return {jsx.dom.css.RuleList}
*/
jsx.dom.css.RuleList = function (oDocument) {
arguments.callee._super.call(this);
this.document = oDocument || document;
this.get();
};
jsx.dom.css.RuleList.extend(jsx.Collection, {
/**
* @type Document
*/
document: null,
/**
* Populates the collection with the selectors
* of the document.
*
* @memberOf jsx.dom.css.RuleList#prototype
* @param {Object} oDocument (optional)
* Object reference to override the default
* <code>document</code> object reference.
* @return {boolean}
*/
get: function (oDocument) {
if (oDocument)
{
this.document = oDocument;
}
this.clear();
var d, oSheets;
if ((d = this.document) && (oSheets = d.styleSheets))
{
for (var i = 0, oRules; i < oSheets.length; i++)
{
var oSheet = oSheets[i];
if ((oRules = oSheet.cssRules || oSheet.rules))
{
for (var j = 0; j < oRules.length; j++)
{
this.add(oRules[j], oRules[j].selectorText);
}
}
}
return true;
}
return false;
},
/**
* Returns a reference to the first rule
* with a simple selector.
*
* @param {String} sSelector
* Simple selector
* @return {CSSStyleRule|Null}
*/
findBySimpleSelector: function (sSelector) {
var
i = this.iterator(),
s;
while ((s = i.next()) != null)
{
if ((new RegExp("(^|\\s)" + sSelector + "([+>\\s]|$)")).test(s.value.selectorText))
{
return s.value;
}
}
return null;
}
});
jsx.dom.css.findRules = (function () {
var a = [];
var _slice = a.slice;
var _concat = a.concat;
function toArray (obj)
{
return _slice.call(obj || a);
}
return function (selector, exactMatch) {
var prefix = "(^|\\s)";
if (exactMatch)
{
prefix = "^\\s*";
}