-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjssor.js
executable file
·2775 lines (2220 loc) · 89.1 KB
/
jssor.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
/*
* Jssor 19.0
* http://www.jssor.com/
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/MIT
*
* TERMS OF USE - Jssor
*
* Copyright 2014 Jssor
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*! Jssor */
//$JssorDebug$
var $JssorDebug$ = new function () {
this.$DebugMode = true;
// Methods
this.$Log = function (msg, important) {
var console = window.console || {};
var debug = this.$DebugMode;
if (debug && console.log) {
console.log(msg);
} else if (debug && important) {
alert(msg);
}
};
this.$Error = function (msg, e) {
var console = window.console || {};
var debug = this.$DebugMode;
if (debug && console.error) {
console.error(msg);
} else if (debug) {
alert(msg);
}
if (debug) {
// since we're debugging, fail fast by crashing
throw e || new Error(msg);
}
};
this.$Fail = function (msg) {
throw new Error(msg);
};
this.$Assert = function (value, msg) {
var debug = this.$DebugMode;
if (debug) {
if (!value)
throw new Error("Assert failed " + msg || "");
}
};
this.$Trace = function (msg) {
var console = window.console || {};
var debug = this.$DebugMode;
if (debug && console.log) {
console.log(msg);
}
};
this.$Execute = function (func) {
var debug = this.$DebugMode;
if (debug)
func();
};
this.$LiveStamp = function (obj, id) {
var debug = this.$DebugMode;
if (debug) {
var stamp = document.createElement("DIV");
stamp.setAttribute("id", id);
obj.$Live = stamp;
}
};
this.$C_AbstractProperty = function () {
/// <summary>
/// Tells compiler the property is abstract, it should be implemented by subclass.
/// </summary>
throw new Error("The property is abstract, it should be implemented by subclass.");
};
this.$C_AbstractMethod = function () {
/// <summary>
/// Tells compiler the method is abstract, it should be implemented by subclass.
/// </summary>
throw new Error("The method is abstract, it should be implemented by subclass.");
};
function C_AbstractClass(instance) {
/// <summary>
/// Tells compiler the class is abstract, it should be implemented by subclass.
/// </summary>
if (instance.constructor === C_AbstractClass.caller)
throw new Error("Cannot create instance of an abstract class.");
}
this.$C_AbstractClass = C_AbstractClass;
};
//$JssorEasing$
var $JssorEasing$ = window.$JssorEasing$ = {
$EaseSwing: function (t) {
return -Math.cos(t * Math.PI) / 2 + .5;
},
$EaseLinear: function (t) {
return t;
},
$EaseInQuad: function (t) {
return t * t;
},
$EaseOutQuad: function (t) {
return -t * (t - 2);
},
$EaseInOutQuad: function (t) {
return (t *= 2) < 1 ? 1 / 2 * t * t : -1 / 2 * (--t * (t - 2) - 1);
},
$EaseInCubic: function (t) {
return t * t * t;
},
$EaseOutCubic: function (t) {
return (t -= 1) * t * t + 1;
},
$EaseInOutCubic: function (t) {
return (t *= 2) < 1 ? 1 / 2 * t * t * t : 1 / 2 * ((t -= 2) * t * t + 2);
},
$EaseInQuart: function (t) {
return t * t * t * t;
},
$EaseOutQuart: function (t) {
return -((t -= 1) * t * t * t - 1);
},
$EaseInOutQuart: function (t) {
return (t *= 2) < 1 ? 1 / 2 * t * t * t * t : -1 / 2 * ((t -= 2) * t * t * t - 2);
},
$EaseInQuint: function (t) {
return t * t * t * t * t;
},
$EaseOutQuint: function (t) {
return (t -= 1) * t * t * t * t + 1;
},
$EaseInOutQuint: function (t) {
return (t *= 2) < 1 ? 1 / 2 * t * t * t * t * t : 1 / 2 * ((t -= 2) * t * t * t * t + 2);
},
$EaseInSine: function (t) {
return 1 - Math.cos(t * Math.PI / 2);
},
$EaseOutSine: function (t) {
return Math.sin(t * Math.PI / 2);
},
$EaseInOutSine: function (t) {
return -1 / 2 * (Math.cos(Math.PI * t) - 1);
},
$EaseInExpo: function (t) {
return t == 0 ? 0 : Math.pow(2, 10 * (t - 1));
},
$EaseOutExpo: function (t) {
return t == 1 ? 1 : -Math.pow(2, -10 * t) + 1;
},
$EaseInOutExpo: function (t) {
return t == 0 || t == 1 ? t : (t *= 2) < 1 ? 1 / 2 * Math.pow(2, 10 * (t - 1)) : 1 / 2 * (-Math.pow(2, -10 * --t) + 2);
},
$EaseInCirc: function (t) {
return -(Math.sqrt(1 - t * t) - 1);
},
$EaseOutCirc: function (t) {
return Math.sqrt(1 - (t -= 1) * t);
},
$EaseInOutCirc: function (t) {
return (t *= 2) < 1 ? -1 / 2 * (Math.sqrt(1 - t * t) - 1) : 1 / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1);
},
$EaseInElastic: function (t) {
if (!t || t == 1)
return t;
var p = .3, s = .075;
return -(Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * 2 * Math.PI / p));
},
$EaseOutElastic: function (t) {
if (!t || t == 1)
return t;
var p = .3, s = .075;
return Math.pow(2, -10 * t) * Math.sin((t - s) * 2 * Math.PI / p) + 1;
},
$EaseInOutElastic: function (t) {
if (!t || t == 1)
return t;
var p = .45, s = .1125;
return (t *= 2) < 1 ? -.5 * Math.pow(2, 10 * (t -= 1)) * Math.sin((t - s) * 2 * Math.PI / p) : Math.pow(2, -10 * (t -= 1)) * Math.sin((t - s) * 2 * Math.PI / p) * .5 + 1;
},
$EaseInBack: function (t) {
var s = 1.70158;
return t * t * ((s + 1) * t - s);
},
$EaseOutBack: function (t) {
var s = 1.70158;
return (t -= 1) * t * ((s + 1) * t + s) + 1;
},
$EaseInOutBack: function (t) {
var s = 1.70158;
return (t *= 2) < 1 ? 1 / 2 * t * t * (((s *= 1.525) + 1) * t - s) : 1 / 2 * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2);
},
$EaseInBounce: function (t) {
return 1 - $JssorEasing$.$EaseOutBounce(1 - t)
},
$EaseOutBounce: function (t) {
return t < 1 / 2.75 ? 7.5625 * t * t : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + .75 : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + .9375 : 7.5625 * (t -= 2.625 / 2.75) * t + .984375;
},
$EaseInOutBounce: function (t) {
return t < 1 / 2 ? $JssorEasing$.$EaseInBounce(t * 2) * .5 : $JssorEasing$.$EaseOutBounce(t * 2 - 1) * .5 + .5;
},
$EaseGoBack: function (t) {
return 1 - Math.abs((t *= 2) - 1);
},
$EaseInWave: function (t) {
return 1 - Math.cos(t * Math.PI * 2)
},
$EaseOutWave: function (t) {
return Math.sin(t * Math.PI * 2);
},
$EaseOutJump: function (t) {
return 1 - (((t *= 2) < 1) ? (t = 1 - t) * t * t : (t -= 1) * t * t);
},
$EaseInJump: function (t) {
return ((t *= 2) < 1) ? t * t * t : (t = 2 - t) * t * t;
}
};
var $JssorDirection$ = window.$JssorDirection$ = {
$TO_LEFT: 0x0001,
$TO_RIGHT: 0x0002,
$TO_TOP: 0x0004,
$TO_BOTTOM: 0x0008,
$HORIZONTAL: 0x0003,
$VERTICAL: 0x000C,
//$LEFTRIGHT: 0x0003,
//$TOPBOTOM: 0x000C,
//$TOPLEFT: 0x0005,
//$TOPRIGHT: 0x0006,
//$BOTTOMLEFT: 0x0009,
//$BOTTOMRIGHT: 0x000A,
//$AROUND: 0x000F,
$GetDirectionHorizontal: function (direction) {
return direction & 0x0003;
},
$GetDirectionVertical: function (direction) {
return direction & 0x000C;
},
//$ChessHorizontal: function (direction) {
// return (~direction & 0x0003) + (direction & 0x000C);
//},
//$ChessVertical: function (direction) {
// return (~direction & 0x000C) + (direction & 0x0003);
//},
//$IsToLeft: function (direction) {
// return (direction & 0x0003) == 0x0001;
//},
//$IsToRight: function (direction) {
// return (direction & 0x0003) == 0x0002;
//},
//$IsToTop: function (direction) {
// return (direction & 0x000C) == 0x0004;
//},
//$IsToBottom: function (direction) {
// return (direction & 0x000C) == 0x0008;
//},
$IsHorizontal: function (direction) {
return direction & 0x0003;
},
$IsVertical: function (direction) {
return direction & 0x000C;
}
};
var $JssorKeyCode$ = {
$BACKSPACE: 8,
$COMMA: 188,
$DELETE: 46,
$DOWN: 40,
$END: 35,
$ENTER: 13,
$ESCAPE: 27,
$HOME: 36,
$LEFT: 37,
$NUMPAD_ADD: 107,
$NUMPAD_DECIMAL: 110,
$NUMPAD_DIVIDE: 111,
$NUMPAD_ENTER: 108,
$NUMPAD_MULTIPLY: 106,
$NUMPAD_SUBTRACT: 109,
$PAGE_DOWN: 34,
$PAGE_UP: 33,
$PERIOD: 190,
$RIGHT: 39,
$SPACE: 32,
$TAB: 9,
$UP: 38
};
// $Jssor$ is a static class, so make it singleton instance
var $Jssor$ = window.$Jssor$ = new function () {
var _This = this;
//#region Constants
var REGEX_WHITESPACE_GLOBAL = /\S+/g;
var ROWSER_OTHER = -1;
var ROWSER_UNKNOWN = 0;
var BROWSER_IE = 1;
var BROWSER_FIREFOX = 2;
var BROWSER_SAFARI = 3;
var BROWSER_CHROME = 4;
var BROWSER_OPERA = 5;
//var arrActiveX = ["Msxml2.XMLHTTP", "Msxml3.XMLHTTP", "Microsoft.XMLHTTP"];
//#endregion
//#region Variables
var _Device;
var _Browser = 0;
var _BrowserRuntimeVersion = 0;
var _BrowserEngineVersion = 0;
var _BrowserJavascriptVersion = 0;
var _WebkitVersion = 0;
var _Navigator = navigator;
var _AppName = _Navigator.appName;
var _AppVersion = _Navigator.appVersion;
var _UserAgent = _Navigator.userAgent;
var _DocElmt = document.documentElement;
var _TransformProperty;
//#endregion
function Device() {
if (!_Device) {
_Device = { $Touchable: "ontouchstart" in window || "createTouch" in document };
var msPrefix;
if ((_Navigator.pointerEnabled || (msPrefix = _Navigator.msPointerEnabled))) {
_Device.$TouchActionAttr = msPrefix ? "msTouchAction" : "touchAction";
}
}
return _Device;
}
function DetectBrowser(browser) {
if (!_Browser) {
_Browser = -1;
if (_AppName == "Microsoft Internet Explorer" &&
!!window.attachEvent && !!window.ActiveXObject) {
var ieOffset = _UserAgent.indexOf("MSIE");
_Browser = BROWSER_IE;
_BrowserEngineVersion = ParseFloat(_UserAgent.substring(ieOffset + 5, _UserAgent.indexOf(";", ieOffset)));
//check IE javascript version
/*@cc_on
_BrowserJavascriptVersion = @_jscript_version;
@*/
// update: for intranet sites and compat view list sites, IE sends
// an IE7 User-Agent to the server to be interoperable, and even if
// the page requests a later IE version, IE will still report the
// IE7 UA to JS. we should be robust to self
//var docMode = document.documentMode;
//if (typeof docMode !== "undefined") {
// _BrowserRuntimeVersion = docMode;
//}
_BrowserRuntimeVersion = document.documentMode || _BrowserEngineVersion;
}
else if (_AppName == "Netscape" && !!window.addEventListener) {
var ffOffset = _UserAgent.indexOf("Firefox");
var saOffset = _UserAgent.indexOf("Safari");
var chOffset = _UserAgent.indexOf("Chrome");
var webkitOffset = _UserAgent.indexOf("AppleWebKit");
if (ffOffset >= 0) {
_Browser = BROWSER_FIREFOX;
_BrowserRuntimeVersion = ParseFloat(_UserAgent.substring(ffOffset + 8));
}
else if (saOffset >= 0) {
var slash = _UserAgent.substring(0, saOffset).lastIndexOf("/");
_Browser = (chOffset >= 0) ? BROWSER_CHROME : BROWSER_SAFARI;
_BrowserRuntimeVersion = ParseFloat(_UserAgent.substring(slash + 1, saOffset));
}
else {
//(/Trident.*rv[ :]*11\./i
var match = /Trident\/.*rv:([0-9]{1,}[\.0-9]{0,})/i.exec(_UserAgent);
if (match) {
_Browser = BROWSER_IE;
_BrowserRuntimeVersion = _BrowserEngineVersion = ParseFloat(match[1]);
}
}
if (webkitOffset >= 0)
_WebkitVersion = ParseFloat(_UserAgent.substring(webkitOffset + 12));
}
else {
var match = /(opera)(?:.*version|)[ \/]([\w.]+)/i.exec(_UserAgent);
if (match) {
_Browser = BROWSER_OPERA;
_BrowserRuntimeVersion = ParseFloat(match[2]);
}
}
}
return browser == _Browser;
}
function IsBrowserIE() {
return DetectBrowser(BROWSER_IE);
}
function IsBrowserIeQuirks() {
return IsBrowserIE() && (_BrowserRuntimeVersion < 6 || document.compatMode == "BackCompat"); //Composite to "CSS1Compat"
}
function IsBrowserFireFox() {
return DetectBrowser(BROWSER_FIREFOX);
}
function IsBrowserSafari() {
return DetectBrowser(BROWSER_SAFARI);
}
function IsBrowserChrome() {
return DetectBrowser(BROWSER_CHROME);
}
function IsBrowserOpera() {
return DetectBrowser(BROWSER_OPERA);
}
function IsBrowserBadTransform() {
return IsBrowserSafari() && (_WebkitVersion > 534) && (_WebkitVersion < 535);
}
function IsBrowserIe9Earlier() {
return IsBrowserIE() && _BrowserRuntimeVersion < 9;
}
function GetTransformProperty(elmt) {
if (!_TransformProperty) {
// Note that in some versions of IE9 it is critical that
// msTransform appear in this list before MozTransform
Each(['transform', 'WebkitTransform', 'msTransform', 'MozTransform', 'OTransform'], function (property) {
if (elmt.style[property] != undefined) {
_TransformProperty = property;
return true;
}
});
_TransformProperty = _TransformProperty || "transform";
}
return _TransformProperty;
}
// Helpers
function getOffsetParent(elmt, isFixed) {
// IE and Opera "fixed" position elements don't have offset parents.
// regardless, if it's fixed, its offset parent is the body.
if (isFixed && elmt != document.body) {
return document.body;
} else {
return elmt.offsetParent;
}
}
function toString(obj) {
return {}.toString.call(obj);
}
// [[Class]] -> type pairs
var _Class2type;
function GetClass2Type() {
if (!_Class2type) {
_Class2type = {};
Each(["Boolean", "Number", "String", "Function", "Array", "Date", "RegExp", "Object"], function (name) {
_Class2type["[object " + name + "]"] = name.toLowerCase();
});
}
return _Class2type;
}
function Each(obj, callback) {
if (toString(obj) == "[object Array]") {
for (var i = 0; i < obj.length; i++) {
if (callback(obj[i], i, obj)) {
return true;
}
}
}
else {
for (var name in obj) {
if (callback(obj[name], name, obj)) {
return true;
}
}
}
}
function Type(obj) {
return obj == null ? String(obj) : GetClass2Type()[toString(obj)] || "object";
}
function IsNotEmpty(obj) {
for(var name in obj)
return true;
}
function IsPlainObject(obj) {
// Not plain objects:
// - Any object or value whose internal [[Class]] property is not "[object Object]"
// - DOM nodes
// - window
try {
return Type(obj) == "object"
&& !obj.nodeType
&& obj != obj.window
&& (!obj.constructor || { }.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf"));
}
catch (e) { }
}
function Point(x, y) {
return { x: x, y: y };
}
function Delay(code, delay) {
setTimeout(code, delay || 0);
}
function RemoveByReg(str, reg) {
var m = reg.exec(str);
if (m) {
var header = str.substr(0, m.index);
var tailer = str.substr(m.lastIndex + 1, str.length - (m.lastIndex + 1));
str = header + tailer;
}
return str;
}
function BuildNewCss(oldCss, removeRegs, replaceValue) {
var css = (!oldCss || oldCss == "inherit") ? "" : oldCss;
Each(removeRegs, function (removeReg) {
var m = removeReg.exec(css);
if (m) {
var header = css.substr(0, m.index);
var tailer = css.substr(m.lastIndex + 1, css.length - (m.lastIndex + 1));
css = header + tailer;
}
});
css = replaceValue + (css.indexOf(" ") != 0 ? " " : "") + css;
return css;
}
function SetStyleFilterIE(elmt, value) {
if (_BrowserRuntimeVersion < 9) {
elmt.style.filter = value;
}
}
function SetStyleMatrixIE(elmt, matrix, offset) {
//matrix is not for ie9+ running in ie8- mode
if (_BrowserJavascriptVersion < 9) {
var oldFilterValue = elmt.style.filter;
var matrixReg = new RegExp(/[\s]*progid:DXImageTransform\.Microsoft\.Matrix\([^\)]*\)/g);
var matrixValue = matrix ? "progid:DXImageTransform.Microsoft.Matrix(" + "M11=" + matrix[0][0] + ", M12=" + matrix[0][1] + ", M21=" + matrix[1][0] + ", M22=" + matrix[1][1] + ", SizingMethod='auto expand')" : "";
var newFilterValue = BuildNewCss(oldFilterValue, [matrixReg], matrixValue);
SetStyleFilterIE(elmt, newFilterValue);
_This.$CssMarginTop(elmt, offset.y);
_This.$CssMarginLeft(elmt, offset.x);
}
}
// Methods
_This.$Device = Device;
_This.$IsBrowserIE = IsBrowserIE;
_This.$IsBrowserIeQuirks = IsBrowserIeQuirks;
_This.$IsBrowserFireFox = IsBrowserFireFox;
_This.$IsBrowserSafari = IsBrowserSafari;
_This.$IsBrowserChrome = IsBrowserChrome;
_This.$IsBrowserOpera = IsBrowserOpera;
_This.$IsBrowserBadTransform = IsBrowserBadTransform;
_This.$IsBrowserIe9Earlier = IsBrowserIe9Earlier;
_This.$BrowserVersion = function () {
return _BrowserRuntimeVersion;
};
_This.$BrowserEngineVersion = function () {
return _BrowserEngineVersion || _BrowserRuntimeVersion;
};
_This.$WebKitVersion = function () {
DetectBrowser();
return _WebkitVersion;
};
_This.$Delay = Delay;
_This.$Inherit = function (instance, baseClass) {
baseClass.call(instance);
return Extend({}, instance);
};
function Construct(instance) {
instance.constructor === Construct.caller && instance.$Construct && instance.$Construct.apply(instance, Construct.caller.arguments);
}
_This.$Construct = Construct;
_This.$GetElement = function (elmt) {
if (_This.$IsString(elmt)) {
elmt = document.getElementById(elmt);
}
return elmt;
};
function GetEvent(event) {
return event || window.event;
}
_This.$GetEvent = GetEvent;
_This.$EvtSrc = function (event) {
event = GetEvent(event);
return event.target || event.srcElement || document;
};
_This.$EvtTarget = function (event) {
event = GetEvent(event);
return event.relatedTarget || event.toElement;
};
_This.$EvtWhich = function (event) {
event = GetEvent(event);
return event.which || [0, 1, 3, 0, 2][event.button] || event.charCode || event.keyCode;
};
_This.$MousePosition = function (event) {
event = GetEvent(event);
//var body = document.body;
return {
x: event.pageX || event.clientX/* + (_DocElmt.scrollLeft || body.scrollLeft || 0) - (_DocElmt.clientLeft || body.clientLeft || 0)*/ || 0,
y: event.pageY || event.clientY/* + (_DocElmt.scrollTop || body.scrollTop || 0) - (_DocElmt.clientTop || body.clientTop || 0)*/ || 0
};
};
_This.$PageScroll = function () {
var body = document.body;
return {
x: (window.pageXOffset || _DocElmt.scrollLeft || body.scrollLeft || 0) - (_DocElmt.clientLeft || body.clientLeft || 0),
y: (window.pageYOffset || _DocElmt.scrollTop || body.scrollTop || 0) - (_DocElmt.clientTop || body.clientTop || 0)
};
};
_This.$WindowSize = function () {
var body = document.body;
return {
x: body.clientWidth || _DocElmt.clientWidth,
y: body.clientHeight || _DocElmt.clientHeight
};
};
//_This.$GetElementPosition = function (elmt) {
// elmt = _This.$GetElement(elmt);
// var result = Point();
// // technique from:
// // http://www.quirksmode.org/js/findpos.html
// // with special check for "fixed" elements.
// while (elmt) {
// result.x += elmt.offsetLeft;
// result.y += elmt.offsetTop;
// var isFixed = _This.$GetElementStyle(elmt).position == "fixed";
// if (isFixed) {
// result = result.$Plus(_This.$PageScroll(window));
// }
// elmt = getOffsetParent(elmt, isFixed);
// }
// return result;
//};
//_This.$GetMouseScroll = function (event) {
// event = GetEvent(event);
// var delta = 0; // default value
// // technique from:
// // http://blog.paranoidferret.com/index.php/2007/10/31/javascript-tutorial-the-scroll-wheel/
// if (typeof (event.wheelDelta) == "number") {
// delta = event.wheelDelta;
// } else if (typeof (event.detail) == "number") {
// delta = event.detail * -1;
// } else {
// $JssorDebug$.$Fail("Unknown event mouse scroll, no known technique.");
// }
// // normalize value to [-1, 1]
// return delta ? delta / Math.abs(delta) : 0;
//};
//_This.$MakeAjaxRequest = function (url, callback) {
// var async = typeof (callback) == "function";
// var req = null;
// if (async) {
// var actual = callback;
// var callback = function () {
// Delay($Jssor$.$CreateCallback(null, actual, req), 1);
// };
// }
// if (window.ActiveXObject) {
// for (var i = 0; i < arrActiveX.length; i++) {
// try {
// req = new ActiveXObject(arrActiveX[i]);
// break;
// } catch (e) {
// continue;
// }
// }
// } else if (window.XMLHttpRequest) {
// req = new XMLHttpRequest();
// }
// if (!req) {
// $JssorDebug$.$Fail("Browser doesn't support XMLHttpRequest.");
// }
// if (async) {
// req.onreadystatechange = function () {
// if (req.readyState == 4) {
// // prevent memory leaks by breaking circular reference now
// req.onreadystatechange = new Function();
// callback();
// }
// };
// }
// try {
// req.open("GET", url, async);
// req.send(null);
// } catch (e) {
// $JssorDebug$.$Log(e.name + " while making AJAX request: " + e.message);
// req.onreadystatechange = null;
// req = null;
// if (async) {
// callback();
// }
// }
// return async ? null : req;
//};
//_This.$ParseXml = function (string) {
// var xmlDoc = null;
// if (window.ActiveXObject) {
// try {
// xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
// xmlDoc.async = false;
// xmlDoc.loadXML(string);
// } catch (e) {
// $JssorDebug$.$Log(e.name + " while parsing XML (ActiveX): " + e.message);
// }
// } else if (window.DOMParser) {
// try {
// var parser = new DOMParser();
// xmlDoc = parser.parseFromString(string, "text/xml");
// } catch (e) {
// $JssorDebug$.$Log(e.name + " while parsing XML (DOMParser): " + e.message);
// }
// } else {
// $JssorDebug$.$Fail("Browser doesn't support XML DOM.");
// }
// return xmlDoc;
//};
function Css(elmt, name, value) {
/// <summary>
/// access css
/// $Jssor$.$Css(elmt, name); //get css value
/// $Jssor$.$Css(elmt, name, value); //set css value
/// </summary>
/// <param name="elmt" type="HTMLElement">
/// the element to access css
/// </param>
/// <param name="name" type="String">
/// the name of css property
/// </param>
/// <param name="value" optional="true">
/// the value to set
/// </param>
if (value != undefined) {
elmt.style[name] = value;
}
else {
var style = elmt.currentStyle || elmt.style;
value = style[name];
if (value == "" && window.getComputedStyle) {
style = elmt.ownerDocument.defaultView.getComputedStyle(elmt, null);
style && (value = style.getPropertyValue(name) || style[name]);
}
return value;
}
}
function CssN(elmt, name, value, isDimensional) {
/// <summary>
/// access css as numeric
/// $Jssor$.$CssN(elmt, name); //get css value
/// $Jssor$.$CssN(elmt, name, value); //set css value
/// </summary>
/// <param name="elmt" type="HTMLElement">
/// the element to access css
/// </param>
/// <param name="name" type="String">
/// the name of css property
/// </param>
/// <param name="value" type="Number" optional="true">
/// the value to set
/// </param>
if (value != undefined) {
isDimensional && (value += "px");
Css(elmt, name, value);
}
else {
return ParseFloat(Css(elmt, name));
}
}
function CssP(elmt, name, value) {
/// <summary>
/// access css in pixel as numeric, like 'top', 'left', 'width', 'height'
/// $Jssor$.$CssP(elmt, name); //get css value
/// $Jssor$.$CssP(elmt, name, value); //set css value
/// </summary>
/// <param name="elmt" type="HTMLElement">
/// the element to access css
/// </param>
/// <param name="name" type="String">
/// the name of css property
/// </param>
/// <param name="value" type="Number" optional="true">
/// the value to set
/// </param>
return CssN(elmt, name, value, true);
}
function CssProxy(name, numericOrDimension) {
/// <summary>
/// create proxy to access css, CssProxy(name[, numericOrDimension]);
/// </summary>
/// <param name="elmt" type="HTMLElement">
/// the element to access css
/// </param>
/// <param name="numericOrDimension" type="Number" optional="true">
/// not set: access original css, 1: access css as numeric, 2: access css in pixel as numeric
/// </param>
var isDimensional = numericOrDimension & 2;
var cssAccessor = numericOrDimension ? CssN : Css;
return function (elmt, value) {
return cssAccessor(elmt, name, value, isDimensional);
};
}
function GetStyleOpacity(elmt) {
if (IsBrowserIE() && _BrowserEngineVersion < 9) {
var match = /opacity=([^)]*)/.exec(elmt.style.filter || "");
return match ? (ParseFloat(match[1]) / 100) : 1;
}
else
return ParseFloat(elmt.style.opacity || "1");
}
function SetStyleOpacity(elmt, opacity, ie9EarlierForce) {
if (IsBrowserIE() && _BrowserEngineVersion < 9) {
//var filterName = "filter"; // _BrowserEngineVersion < 8 ? "filter" : "-ms-filter";
var finalFilter = elmt.style.filter || "";
// for CSS filter browsers (IE), remove alpha filter if it's unnecessary.
// update: doing _This always since IE9 beta seems to have broken the
// behavior if we rely on the programmatic filters collection.
var alphaReg = new RegExp(/[\s]*alpha\([^\)]*\)/g);
// important: note the lazy star! _This protects against
// multiple filters; we don't want to delete the other ones.
// update: also trimming extra whitespace around filter.
var ieOpacity = Math.round(100 * opacity);
var alphaFilter = "";
if (ieOpacity < 100 || ie9EarlierForce) {
alphaFilter = "alpha(opacity=" + ieOpacity + ") ";
}
var newFilterValue = BuildNewCss(finalFilter, [alphaReg], alphaFilter);
SetStyleFilterIE(elmt, newFilterValue);
}
else {
elmt.style.opacity = opacity == 1 ? "" : Math.round(opacity * 100) / 100;
}
}
function SetStyleTransformInternal(elmt, transform) {
var rotate = transform.$Rotate || 0;
var scale = transform.$Scale == undefined ? 1 : transform.$Scale;
if (IsBrowserIe9Earlier()) {
var matrix = _This.$CreateMatrix(rotate / 180 * Math.PI, scale, scale);
SetStyleMatrixIE(elmt, (!rotate && scale == 1) ? null : matrix, _This.$GetMatrixOffset(matrix, transform.$OriginalWidth, transform.$OriginalHeight));
}
else {
//rotate(15deg) scale(.5) translateZ(0)
var transformProperty = GetTransformProperty(elmt);
if (transformProperty) {
var transformValue = "rotate(" + rotate % 360 + "deg) scale(" + scale + ")";
//needed for touch device, no need for desktop device
if (IsBrowserChrome() && _WebkitVersion > 535 && "ontouchstart" in window)
transformValue += " perspective(2000px)";