This repository has been archived by the owner on Dec 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PIE_uncompressed.htc
3713 lines (3267 loc) · 135 KB
/
PIE_uncompressed.htc
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
<!--
PIE: CSS3 rendering for IE
Version 1.0beta4
http://css3pie.com
Dual-licensed for use under the Apache License Version 2.0 or the General Public License (GPL) Version 2.
-->
<PUBLIC:COMPONENT lightWeight="true">
<PUBLIC:ATTACH EVENT="oncontentready" FOR="element" ONEVENT="init()" />
<PUBLIC:ATTACH EVENT="ondocumentready" FOR="element" ONEVENT="init()" />
<PUBLIC:ATTACH EVENT="ondetach" FOR="element" ONEVENT="cleanup()" />
<script type="text/javascript">
var doc = element.document;var PIE = window['PIE'];
if( !PIE ) {
PIE = window['PIE'] = {
CSS_PREFIX: '-pie-',
STYLE_PREFIX: 'Pie',
CLASS_PREFIX: 'pie_',
tableCellTags: {
'TD': 1,
'TH': 1
}
};
// Force the background cache to be used. No reason it shouldn't be.
try {
doc.execCommand( 'BackgroundImageCache', false, true );
} catch(e) {}
/*
* IE version detection approach by James Padolsey, with modifications -- from
* http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/
*/
PIE.ieVersion = function(){
var v = 4,
div = doc.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
) {}
return v;
}();
// Detect IE6
if( PIE.ieVersion === 6 ) {
// IE6 can't access properties with leading dash, but can without it.
PIE.CSS_PREFIX = PIE.CSS_PREFIX.replace( /^-/, '' );
}
// Detect IE8
PIE.ieDocMode = doc.documentMode || PIE.ieVersion;
/**
* Utility functions
*/
(function() {
var vmlCreatorDoc,
idNum = 0,
imageSizes = {};
PIE.Util = {
/**
* To create a VML element, it must be created by a Document which has the VML
* namespace set. Unfortunately, if you try to add the namespace programatically
* into the main document, you will get an "Unspecified error" when trying to
* access document.namespaces before the document is finished loading. To get
* around this, we create a DocumentFragment, which in IE land is apparently a
* full-fledged Document. It allows adding namespaces immediately, so we add the
* namespace there and then have it create the VML element.
* @param {string} tag The tag name for the VML element
* @return {Element} The new VML element
*/
createVmlElement: function( tag ) {
var vmlPrefix = 'css3vml';
if( !vmlCreatorDoc ) {
vmlCreatorDoc = doc.createDocumentFragment();
vmlCreatorDoc.namespaces.add( vmlPrefix, 'urn:schemas-microsoft-com:vml' );
}
return vmlCreatorDoc.createElement( vmlPrefix + ':' + tag );
},
/**
* Generate and return a unique ID for a given object. The generated ID is stored
* as a property of the object for future reuse.
* @param {Object} obj
*/
getUID: function( obj ) {
return obj && obj[ '_pieId' ] || ( obj[ '_pieId' ] = ++idNum );
},
/**
* Simple utility for merging objects
* @param {Object} obj1 The main object into which all others will be merged
* @param {...Object} var_args Other objects which will be merged into the first, in order
*/
merge: function( obj1 ) {
var i, len, p, objN, args = arguments;
for( i = 1, len = args.length; i < len; i++ ) {
objN = args[i];
for( p in objN ) {
if( objN.hasOwnProperty( p ) ) {
obj1[ p ] = objN[ p ];
}
}
}
return obj1;
},
/**
* Execute a callback function, passing it the dimensions of a given image once
* they are known.
* @param {string} src The source URL of the image
* @param {function({w:number, h:number})} func The callback function to be called once the image dimensions are known
* @param {Object} ctx A context object which will be used as the 'this' value within the executed callback function
*/
withImageSize: function( src, func, ctx ) {
var size = imageSizes[ src ], img, queue;
if( size ) {
// If we have a queue, add to it
if( Object.prototype.toString.call( size ) === '[object Array]' ) {
size.push( [ func, ctx ] );
}
// Already have the size cached, call func right away
else {
func.call( ctx, size );
}
} else {
queue = imageSizes[ src ] = [ [ func, ctx ] ]; //create queue
img = new Image();
img.onload = function() {
size = imageSizes[ src ] = { w: img.width, h: img.height };
for( var i = 0, len = queue.length; i < len; i++ ) {
queue[ i ][ 0 ].call( queue[ i ][ 1 ], size );
}
img.onload = null;
};
img.src = src;
}
}
};
})();/**
*
*/
PIE.Observable = function() {
/**
* List of registered observer functions
*/
this.observers = [];
/**
* Hash of function ids to their position in the observers list, for fast lookup
*/
this.indexes = {};
};
PIE.Observable.prototype = {
observe: function( fn ) {
var id = PIE.Util.getUID( fn ),
indexes = this.indexes,
observers = this.observers;
if( !( id in indexes ) ) {
indexes[ id ] = observers.length;
observers.push( fn );
}
},
unobserve: function( fn ) {
var id = PIE.Util.getUID( fn ),
indexes = this.indexes;
if( id && id in indexes ) {
delete this.observers[ indexes[ id ] ];
delete indexes[ id ];
}
},
fire: function() {
var o = this.observers,
i = o.length;
while( i-- ) {
o[ i ] && o[ i ]();
}
}
};/*
* Simple heartbeat timer - this is a brute-force workaround for syncing issues caused by IE not
* always firing the onmove and onresize events when elements are moved or resized. We check a few
* times every second to make sure the elements have the correct position and size. See Element.js
* which adds heartbeat listeners based on the custom -pie-poll flag, which defaults to true in IE8
* and false elsewhere.
*/
PIE.Heartbeat = new PIE.Observable();
PIE.Heartbeat.run = function() {
var me = this;
if( !me.running ) {
setInterval( function() { me.fire() }, 250 );
me.running = 1;
}
};
/**
* Create an observable listener for the onbeforeunload event
*/
PIE.OnBeforeUnload = new PIE.Observable();
window.attachEvent( 'onbeforeunload', function() { PIE.OnBeforeUnload.fire(); } );
/**
* Attach an event which automatically gets detached onbeforeunload
*/
PIE.OnBeforeUnload.attachManagedEvent = function( target, name, handler ) {
target.attachEvent( name, handler );
this.observe( function() {
target.detachEvent( name, handler );
} );
};/**
* Create a single observable listener for window resize events.
*/
(function() {
PIE.OnResize = new PIE.Observable();
function resized() {
PIE.OnResize.fire();
}
PIE.OnBeforeUnload.attachManagedEvent( window, 'onresize', resized );
})();
/**
* Create a single observable listener for scroll events. Used for lazy loading based
* on the viewport, and for fixed position backgrounds.
*/
(function() {
PIE.OnScroll = new PIE.Observable();
function scrolled() {
PIE.OnScroll.fire();
}
PIE.OnBeforeUnload.attachManagedEvent( window, 'onscroll', scrolled );
PIE.OnResize.observe( scrolled );
})();
/**
* Listen for printing events, destroy all active PIE instances when printing, and
* restore them afterward.
*/
(function() {
var elements;
function beforePrint() {
elements = PIE.Element.destroyAll();
}
function afterPrint() {
if( elements ) {
for( var i = 0, len = elements.length; i < len; i++ ) {
PIE[ 'attach' ]( elements[i] );
}
elements = 0;
}
}
PIE.OnBeforeUnload.attachManagedEvent( window, 'onbeforeprint', beforePrint );
PIE.OnBeforeUnload.attachManagedEvent( window, 'onafterprint', afterPrint );
})();/**
* Wrapper for length and percentage style values. The value is immutable. A singleton instance per unique
* value is returned from PIE.getLength() - always use that instead of instantiating directly.
* @constructor
* @param {string} val The CSS string representing the length. It is assumed that this will already have
* been validated as a valid length or percentage syntax.
*/
PIE.Length = (function() {
var lengthCalcEl = doc.createElement( 'length-calc' ),
parent = doc.documentElement,
s = lengthCalcEl.style,
conversions = {},
units = [ 'mm', 'cm', 'in', 'pt', 'pc' ],
i = units.length,
instances = {};
s.position = 'absolute';
s.top = s.left = '-9999px';
parent.appendChild( lengthCalcEl );
while( i-- ) {
lengthCalcEl.style.width = '100' + units[i];
conversions[ units[i] ] = lengthCalcEl.offsetWidth / 100;
}
parent.removeChild( lengthCalcEl );
function Length( val ) {
this.val = val;
}
Length.prototype = {
/**
* Regular expression for matching the length unit
* @private
*/
unitRE: /(px|em|ex|mm|cm|in|pt|pc|%)$/,
/**
* Get the numeric value of the length
* @return {number} The value
*/
getNumber: function() {
var num = this.num,
UNDEF;
if( num === UNDEF ) {
num = this.num = parseFloat( this.val );
}
return num;
},
/**
* Get the unit of the length
* @return {string} The unit
*/
getUnit: function() {
var unit = this.unit,
m;
if( !unit ) {
m = this.val.match( this.unitRE );
unit = this.unit = ( m && m[0] ) || 'px';
}
return unit;
},
/**
* Determine whether this is a percentage length value
* @return {boolean}
*/
isPercentage: function() {
return this.getUnit() === '%';
},
/**
* Resolve this length into a number of pixels.
* @param {Element} el - the context element, used to resolve font-relative values
* @param {(function():number|number)=} pct100 - the number of pixels that equal a 100% percentage. This can be either a number or a
* function which will be called to return the number.
*/
pixels: function( el, pct100 ) {
var num = this.getNumber(),
unit = this.getUnit();
switch( unit ) {
case "px":
return num;
case "%":
return num * ( typeof pct100 === 'function' ? pct100() : pct100 ) / 100;
case "em":
return num * this.getEmPixels( el );
case "ex":
return num * this.getEmPixels( el ) / 2;
default:
return num * conversions[ unit ];
}
},
/**
* The em and ex units are relative to the font-size of the current element,
* however if the font-size is set using non-pixel units then we get that value
* rather than a pixel conversion. To get around this, we keep a floating element
* with width:1em which we insert into the target element and then read its offsetWidth.
* But if the font-size *is* specified in pixels, then we use that directly to avoid
* the expensive DOM manipulation.
* @param el
*/
getEmPixels: function( el ) {
var fs = el.currentStyle.fontSize,
px;
if( fs.indexOf( 'px' ) > 0 ) {
return parseFloat( fs );
} else {
lengthCalcEl.style.width = '1em';
el.appendChild( lengthCalcEl );
px = lengthCalcEl.offsetWidth;
if( lengthCalcEl.parentNode === el ) { //not sure how this could be false but it sometimes is
el.removeChild( lengthCalcEl );
}
return px;
}
}
};
/**
* Retrieve a PIE.Length instance for the given value. A shared singleton instance is returned for each unique value.
* @param {string} val The CSS string representing the length. It is assumed that this will already have
* been validated as a valid length or percentage syntax.
*/
PIE.getLength = function( val ) {
return instances[ val ] || ( instances[ val ] = new Length( val ) );
};
return Length;
})();
/**
* Wrapper for a CSS3 bg-position value. Takes up to 2 position keywords and 2 lengths/percentages.
* @constructor
* @param {Array.<PIE.Tokenizer.Token>} tokens The tokens making up the background position value.
*/
PIE.BgPosition = (function() {
var length_fifty = PIE.getLength( '50%' ),
vert_idents = { 'top': 1, 'center': 1, 'bottom': 1 },
horiz_idents = { 'left': 1, 'center': 1, 'right': 1 };
function BgPosition( tokens ) {
this.tokens = tokens;
}
BgPosition.prototype = {
/**
* Normalize the values into the form:
* [ xOffsetSide, xOffsetLength, yOffsetSide, yOffsetLength ]
* where: xOffsetSide is either 'left' or 'right',
* yOffsetSide is either 'top' or 'bottom',
* and x/yOffsetLength are both PIE.Length objects.
* @return {Array}
*/
getValues: function() {
if( !this._values ) {
var tokens = this.tokens,
len = tokens.length,
Tokenizer = PIE.Tokenizer,
identType = Tokenizer.Type,
length_zero = PIE.getLength( '0' ),
type_ident = identType.IDENT,
type_length = identType.LENGTH,
type_percent = identType.PERCENT,
type, value,
vals = [ 'left', length_zero, 'top', length_zero ];
// If only one value, the second is assumed to be 'center'
if( len === 1 ) {
tokens.push( new Tokenizer.Token( type_ident, 'center' ) );
len++;
}
// Two values - CSS2
if( len === 2 ) {
// If both idents, they can appear in either order, so switch them if needed
if( type_ident & ( tokens[0].tokenType | tokens[1].tokenType ) &&
tokens[0].tokenValue in vert_idents && tokens[1].tokenValue in horiz_idents ) {
tokens.push( tokens.shift() );
}
if( tokens[0].tokenType & type_ident ) {
if( tokens[0].tokenValue === 'center' ) {
vals[1] = length_fifty;
} else {
vals[0] = tokens[0].tokenValue;
}
}
else if( tokens[0].isLengthOrPercent() ) {
vals[1] = PIE.getLength( tokens[0].tokenValue );
}
if( tokens[1].tokenType & type_ident ) {
if( tokens[1].tokenValue === 'center' ) {
vals[3] = length_fifty;
} else {
vals[2] = tokens[1].tokenValue;
}
}
else if( tokens[1].isLengthOrPercent() ) {
vals[3] = PIE.getLength( tokens[1].tokenValue );
}
}
// Three or four values - CSS3
else {
// TODO
}
this._values = vals;
}
return this._values;
},
/**
* Find the coordinates of the background image from the upper-left corner of the background area.
* Note that these coordinate values are not rounded.
* @param {Element} el
* @param {number} width - the width for percentages (background area width minus image width)
* @param {number} height - the height for percentages (background area height minus image height)
* @return {Object} { x: Number, y: Number }
*/
coords: function( el, width, height ) {
var vals = this.getValues(),
pxX = vals[1].pixels( el, width ),
pxY = vals[3].pixels( el, height );
return {
x: vals[0] === 'right' ? width - pxX : pxX,
y: vals[2] === 'bottom' ? height - pxY : pxY
};
}
};
return BgPosition;
})();
/**
* Wrapper for angle values; handles conversion to degrees from all allowed angle units
* @constructor
* @param {string} val The raw CSS value for the angle. It is assumed it has been pre-validated.
*/
PIE.Angle = (function() {
function Angle( val ) {
this.val = val;
}
Angle.prototype = {
unitRE: /[a-z]+$/i,
/**
* @return {string} The unit of the angle value
*/
getUnit: function() {
return this._unit || ( this._unit = this.val.match( this.unitRE )[0].toLowerCase() );
},
/**
* Get the numeric value of the angle in degrees.
* @return {number} The degrees value
*/
degrees: function() {
var deg = this._deg, u, n;
if( deg === undefined ) {
u = this.getUnit();
n = parseFloat( this.val, 10 );
deg = this._deg = ( u === 'deg' ? n : u === 'rad' ? n / Math.PI * 180 : u === 'grad' ? n / 400 * 360 : u === 'turn' ? n * 360 : 0 );
}
return deg;
}
};
return Angle;
})();/**
* Abstraction for colors values. Allows detection of rgba values. A singleton instance per unique
* value is returned from PIE.getColor() - always use that instead of instantiating directly.
* @constructor
* @param {string} val The raw CSS string value for the color
*/
PIE.Color = (function() {
var instances = {};
function Color( val ) {
this.val = val;
}
/**
* Regular expression for matching rgba colors and extracting their components
* @type {RegExp}
*/
Color.rgbaRE = /\s*rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d+|\d*\.\d+)\s*\)\s*/;
Color.names = {
"aliceblue":"F0F8FF", "antiquewhite":"FAEBD7", "aqua":"0FF",
"aquamarine":"7FFFD4", "azure":"F0FFFF", "beige":"F5F5DC",
"bisque":"FFE4C4", "black":"000", "blanchedalmond":"FFEBCD",
"blue":"00F", "blueviolet":"8A2BE2", "brown":"A52A2A",
"burlywood":"DEB887", "cadetblue":"5F9EA0", "chartreuse":"7FFF00",
"chocolate":"D2691E", "coral":"FF7F50", "cornflowerblue":"6495ED",
"cornsilk":"FFF8DC", "crimson":"DC143C", "cyan":"0FF",
"darkblue":"00008B", "darkcyan":"008B8B", "darkgoldenrod":"B8860B",
"darkgray":"A9A9A9", "darkgreen":"006400", "darkkhaki":"BDB76B",
"darkmagenta":"8B008B", "darkolivegreen":"556B2F", "darkorange":"FF8C00",
"darkorchid":"9932CC", "darkred":"8B0000", "darksalmon":"E9967A",
"darkseagreen":"8FBC8F", "darkslateblue":"483D8B", "darkslategray":"2F4F4F",
"darkturquoise":"00CED1", "darkviolet":"9400D3", "deeppink":"FF1493",
"deepskyblue":"00BFFF", "dimgray":"696969", "dodgerblue":"1E90FF",
"firebrick":"B22222", "floralwhite":"FFFAF0", "forestgreen":"228B22",
"fuchsia":"F0F", "gainsboro":"DCDCDC", "ghostwhite":"F8F8FF",
"gold":"FFD700", "goldenrod":"DAA520", "gray":"808080",
"green":"008000", "greenyellow":"ADFF2F", "honeydew":"F0FFF0",
"hotpink":"FF69B4", "indianred":"CD5C5C", "indigo":"4B0082",
"ivory":"FFFFF0", "khaki":"F0E68C", "lavender":"E6E6FA",
"lavenderblush":"FFF0F5", "lawngreen":"7CFC00", "lemonchiffon":"FFFACD",
"lightblue":"ADD8E6", "lightcoral":"F08080", "lightcyan":"E0FFFF",
"lightgoldenrodyellow":"FAFAD2", "lightgreen":"90EE90", "lightgrey":"D3D3D3",
"lightpink":"FFB6C1", "lightsalmon":"FFA07A", "lightseagreen":"20B2AA",
"lightskyblue":"87CEFA", "lightslategray":"789", "lightsteelblue":"B0C4DE",
"lightyellow":"FFFFE0", "lime":"0F0", "limegreen":"32CD32",
"linen":"FAF0E6", "magenta":"F0F", "maroon":"800000",
"mediumauqamarine":"66CDAA", "mediumblue":"0000CD", "mediumorchid":"BA55D3",
"mediumpurple":"9370D8", "mediumseagreen":"3CB371", "mediumslateblue":"7B68EE",
"mediumspringgreen":"00FA9A", "mediumturquoise":"48D1CC", "mediumvioletred":"C71585",
"midnightblue":"191970", "mintcream":"F5FFFA", "mistyrose":"FFE4E1",
"moccasin":"FFE4B5", "navajowhite":"FFDEAD", "navy":"000080",
"oldlace":"FDF5E6", "olive":"808000", "olivedrab":"688E23",
"orange":"FFA500", "orangered":"FF4500", "orchid":"DA70D6",
"palegoldenrod":"EEE8AA", "palegreen":"98FB98", "paleturquoise":"AFEEEE",
"palevioletred":"D87093", "papayawhip":"FFEFD5", "peachpuff":"FFDAB9",
"peru":"CD853F", "pink":"FFC0CB", "plum":"DDA0DD",
"powderblue":"B0E0E6", "purple":"800080", "red":"F00",
"rosybrown":"BC8F8F", "royalblue":"4169E1", "saddlebrown":"8B4513",
"salmon":"FA8072", "sandybrown":"F4A460", "seagreen":"2E8B57",
"seashell":"FFF5EE", "sienna":"A0522D", "silver":"C0C0C0",
"skyblue":"87CEEB", "slateblue":"6A5ACD", "slategray":"708090",
"snow":"FFFAFA", "springgreen":"00FF7F", "steelblue":"4682B4",
"tan":"D2B48C", "teal":"008080", "thistle":"D8BFD8",
"tomato":"FF6347", "turquoise":"40E0D0", "violet":"EE82EE",
"wheat":"F5DEB3", "white":"FFF", "whitesmoke":"F5F5F5",
"yellow":"FF0", "yellowgreen":"9ACD32"
};
Color.prototype = {
/**
* @private
*/
parse: function() {
if( !this._color ) {
var me = this,
v = me.val,
vLower,
m = v.match( Color.rgbaRE );
if( m ) {
me._color = 'rgb(' + m[1] + ',' + m[2] + ',' + m[3] + ')';
me._alpha = parseFloat( m[4] );
}
else {
if( ( vLower = v.toLowerCase() ) in Color.names ) {
v = '#' + Color.names[vLower];
}
me._color = v;
me._alpha = ( v === 'transparent' ? 0 : 1 );
}
}
},
/**
* Retrieve the value of the color in a format usable by IE natively. This will be the same as
* the raw input value, except for rgba values which will be converted to an rgb value.
* @param {Element} el The context element, used to get 'currentColor' keyword value.
* @return {string} Color value
*/
colorValue: function( el ) {
this.parse();
return this._color === 'currentColor' ? el.currentStyle.color : this._color;
},
/**
* Retrieve the alpha value of the color. Will be 1 for all values except for rgba values
* with an alpha component.
* @return {number} The alpha value, from 0 to 1.
*/
alpha: function() {
this.parse();
return this._alpha;
}
};
/**
* Retrieve a PIE.Color instance for the given value. A shared singleton instance is returned for each unique value.
* @param {string} val The CSS string representing the color. It is assumed that this will already have
* been validated as a valid color syntax.
*/
PIE.getColor = function(val) {
return instances[ val ] || ( instances[ val ] = new Color( val ) );
};
return Color;
})();/**
* A tokenizer for CSS value strings.
* @constructor
* @param {string} css The CSS value string
*/
PIE.Tokenizer = (function() {
function Tokenizer( css ) {
this.css = css;
this.ch = 0;
this.tokens = [];
this.tokenIndex = 0;
}
/**
* Enumeration of token type constants.
* @enum {number}
*/
var Type = Tokenizer.Type = {
ANGLE: 1,
CHARACTER: 2,
COLOR: 4,
DIMEN: 8,
FUNCTION: 16,
IDENT: 32,
LENGTH: 64,
NUMBER: 128,
OPERATOR: 256,
PERCENT: 512,
STRING: 1024,
URL: 2048
};
/**
* A single token
* @constructor
* @param {number} type The type of the token - see PIE.Tokenizer.Type
* @param {string} value The value of the token
*/
Tokenizer.Token = function( type, value ) {
this.tokenType = type;
this.tokenValue = value;
};
Tokenizer.Token.prototype = {
isLength: function() {
return this.tokenType & Type.LENGTH || ( this.tokenType & Type.NUMBER && this.tokenValue === '0' );
},
isLengthOrPercent: function() {
return this.isLength() || this.tokenType & Type.PERCENT;
}
};
Tokenizer.prototype = {
whitespace: /\s/,
number: /^[\+\-]?(\d*\.)?\d+/,
url: /^url\(\s*("([^"]*)"|'([^']*)'|([!#$%&*-~]*))\s*\)/i,
ident: /^\-?[_a-z][\w-]*/i,
string: /^("([^"]*)"|'([^']*)')/,
operator: /^[\/,]/,
hash: /^#[\w]+/,
hashColor: /^#([\da-f]{6}|[\da-f]{3})/i,
unitTypes: {
'px': Type.LENGTH, 'em': Type.LENGTH, 'ex': Type.LENGTH,
'mm': Type.LENGTH, 'cm': Type.LENGTH, 'in': Type.LENGTH,
'pt': Type.LENGTH, 'pc': Type.LENGTH,
'deg': Type.ANGLE, 'rad': Type.ANGLE, 'grad': Type.ANGLE
},
colorNames: {
'aqua':1, 'black':1, 'blue':1, 'fuchsia':1, 'gray':1, 'green':1, 'lime':1, 'maroon':1,
'navy':1, 'olive':1, 'purple':1, 'red':1, 'silver':1, 'teal':1, 'white':1, 'yellow': 1,
'currentColor': 1
},
colorFunctions: {
'rgb': 1, 'rgba': 1, 'hsl': 1, 'hsla': 1
},
/**
* Advance to and return the next token in the CSS string. If the end of the CSS string has
* been reached, null will be returned.
* @param {boolean} forget - if true, the token will not be stored for the purposes of backtracking with prev().
* @return {PIE.Tokenizer.Token}
*/
next: function( forget ) {
var css, ch, firstChar, match, val,
me = this;
function newToken( type, value ) {
var tok = new Tokenizer.Token( type, value );
if( !forget ) {
me.tokens.push( tok );
me.tokenIndex++;
}
return tok;
}
function failure() {
me.tokenIndex++;
return null;
}
// In case we previously backed up, return the stored token in the next slot
if( this.tokenIndex < this.tokens.length ) {
return this.tokens[ this.tokenIndex++ ];
}
// Move past leading whitespace characters
while( this.whitespace.test( this.css.charAt( this.ch ) ) ) {
this.ch++;
}
if( this.ch >= this.css.length ) {
return failure();
}
ch = this.ch;
css = this.css.substring( this.ch );
firstChar = css.charAt( 0 );
switch( firstChar ) {
case '#':
if( match = css.match( this.hashColor ) ) {
this.ch += match[0].length;
return newToken( Type.COLOR, match[0] );
}
break;
case '"':
case "'":
if( match = css.match( this.string ) ) {
this.ch += match[0].length;
return newToken( Type.STRING, match[2] || match[3] || '' );
}
break;
case "/":
case ",":
this.ch++;
return newToken( Type.OPERATOR, firstChar );
case 'u':
if( match = css.match( this.url ) ) {
this.ch += match[0].length;
return newToken( Type.URL, match[2] || match[3] || match[4] || '' );
}
}
// Numbers and values starting with numbers
if( match = css.match( this.number ) ) {
val = match[0];
this.ch += val.length;
// Check if it is followed by a unit
if( css.charAt( val.length ) === '%' ) {
this.ch++;
return newToken( Type.PERCENT, val + '%' );
}
if( match = css.substring( val.length ).match( this.ident ) ) {
val += match[0];
this.ch += match[0].length;
return newToken( this.unitTypes[ match[0].toLowerCase() ] || Type.DIMEN, val );
}
// Plain ol' number
return newToken( Type.NUMBER, val );
}
// Identifiers
if( match = css.match( this.ident ) ) {
val = match[0];
this.ch += val.length;
// Named colors
if( val.toLowerCase() in PIE.Color.names || val === 'currentColor' ) {
return newToken( Type.COLOR, val );
}
// Functions
if( css.charAt( val.length ) === '(' ) {
this.ch++;
// Color values in function format: rgb, rgba, hsl, hsla
if( val.toLowerCase() in this.colorFunctions ) {
function isNum( tok ) {
return tok && tok.tokenType & Type.NUMBER;
}
function isNumOrPct( tok ) {
return tok && ( tok.tokenType & ( Type.NUMBER | Type.PERCENT ) );
}
function isValue( tok, val ) {
return tok && tok.tokenValue === val;
}
function next() {
return me.next( 1 );
}
if( ( val.charAt(0) === 'r' ? isNumOrPct( next() ) : isNum( next() ) ) &&
isValue( next(), ',' ) &&
isNumOrPct( next() ) &&
isValue( next(), ',' ) &&
isNumOrPct( next() ) &&
( val === 'rgb' || val === 'hsa' || (
isValue( next(), ',' ) &&
isNum( next() )
) ) &&
isValue( next(), ')' ) ) {
return newToken( Type.COLOR, this.css.substring( ch, this.ch ) );
}
return failure();
}
return newToken( Type.FUNCTION, val );
}
// Other identifier
return newToken( Type.IDENT, val );
}
// Standalone character
this.ch++;
return newToken( Type.CHARACTER, firstChar );
},
/**
* Determine whether there is another token
* @return {boolean}
*/
hasNext: function() {
var next = this.next();
this.prev();
return !!next;
},
/**
* Back up and return the previous token
* @return {PIE.Tokenizer.Token}
*/
prev: function() {
return this.tokens[ this.tokenIndex-- - 2 ];
},
/**
* Retrieve all the tokens in the CSS string
* @return {Array.<PIE.Tokenizer.Token>}
*/
all: function() {
while( this.next() ) {}
return this.tokens;
},
/**
* Return a list of tokens from the current position until the given function returns
* true. The final token will not be included in the list.
* @param {function():boolean} func - test function
* @param {boolean} require - if true, then if the end of the CSS string is reached
* before the test function returns true, null will be returned instead of the
* tokens that have been found so far.
* @return {Array.<PIE.Tokenizer.Token>}
*/
until: function( func, require ) {
var list = [], t, hit;
while( t = this.next() ) {
if( func( t ) ) {
hit = true;
this.prev();
break;
}
list.push( t );
}
return require && !hit ? null : list;
}
};
return Tokenizer;
})();/**
* Handles calculating, caching, and detecting changes to size and position of the element.
* @constructor
* @param {Element} el the target element
*/
PIE.BoundsInfo = function( el ) {
this.targetElement = el;
};
PIE.BoundsInfo.prototype = {
_locked: 0,
positionChanged: function() {
var last = this._lastBounds,
bounds;
return !last || ( ( bounds = this.getBounds() ) && ( last.x !== bounds.x || last.y !== bounds.y ) );
},
sizeChanged: function() {
var last = this._lastBounds,
bounds;
return !last || ( ( bounds = this.getBounds() ) && ( last.w !== bounds.w || last.h !== bounds.h ) );
},
getLiveBounds: function() {
var rect = this.targetElement.getBoundingClientRect();
return {
x: rect.left,
y: rect.top,
w: rect.right - rect.left,
h: rect.bottom - rect.top
};
},
getBounds: function() {
return this._locked ?
( this._lockedBounds || ( this._lockedBounds = this.getLiveBounds() ) ) :
this.getLiveBounds();
},
hasBeenQueried: function() {
return !!this._lastBounds;
},
lock: function() {
++this._locked;
},
unlock: function() {
if( !--this._locked ) {
if( this._lockedBounds ) this._lastBounds = this._lockedBounds;
this._lockedBounds = null;
}
}
};