webshims-rails 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/lib/webshims-rails/version.rb +2 -2
  2. data/vendor/assets/javascripts/webshims/extras/custom-validity.js +261 -261
  3. data/vendor/assets/javascripts/webshims/extras/modernizr-custom.js +534 -534
  4. data/vendor/assets/javascripts/webshims/extras/mousepress.js +60 -60
  5. data/vendor/assets/javascripts/webshims/minified/extras/custom-validity.js +1 -1
  6. data/vendor/assets/javascripts/webshims/minified/polyfiller.js +24 -24
  7. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/README +82 -82
  8. data/vendor/assets/javascripts/webshims/minified/shims/combos/1.js +35 -34
  9. data/vendor/assets/javascripts/webshims/minified/shims/combos/10.js +79 -82
  10. data/vendor/assets/javascripts/webshims/minified/shims/combos/11.js +45 -44
  11. data/vendor/assets/javascripts/webshims/minified/shims/combos/12.js +43 -42
  12. data/vendor/assets/javascripts/webshims/minified/shims/combos/13.js +28 -27
  13. data/vendor/assets/javascripts/webshims/minified/shims/combos/15.js +4 -4
  14. data/vendor/assets/javascripts/webshims/minified/shims/combos/16.js +57 -59
  15. data/vendor/assets/javascripts/webshims/minified/shims/combos/17.js +64 -66
  16. data/vendor/assets/javascripts/webshims/minified/shims/combos/18.js +53 -54
  17. data/vendor/assets/javascripts/webshims/minified/shims/combos/19.js +64 -66
  18. data/vendor/assets/javascripts/webshims/minified/shims/combos/2.js +72 -73
  19. data/vendor/assets/javascripts/webshims/minified/shims/combos/20.js +42 -46
  20. data/vendor/assets/javascripts/webshims/minified/shims/combos/21.js +52 -50
  21. data/vendor/assets/javascripts/webshims/minified/shims/combos/22.js +55 -59
  22. data/vendor/assets/javascripts/webshims/minified/shims/combos/23.js +66 -64
  23. data/vendor/assets/javascripts/webshims/minified/shims/combos/24.js +80 -82
  24. data/vendor/assets/javascripts/webshims/minified/shims/combos/25.js +60 -59
  25. data/vendor/assets/javascripts/webshims/minified/shims/combos/26.js +79 -81
  26. data/vendor/assets/javascripts/webshims/minified/shims/combos/27.js +101 -104
  27. data/vendor/assets/javascripts/webshims/minified/shims/combos/3.js +94 -95
  28. data/vendor/assets/javascripts/webshims/minified/shims/combos/4.js +26 -29
  29. data/vendor/assets/javascripts/webshims/minified/shims/combos/5.js +33 -36
  30. data/vendor/assets/javascripts/webshims/minified/shims/combos/59.js +51 -54
  31. data/vendor/assets/javascripts/webshims/minified/shims/combos/6.js +27 -28
  32. data/vendor/assets/javascripts/webshims/minified/shims/combos/7.js +27 -28
  33. data/vendor/assets/javascripts/webshims/minified/shims/combos/8.js +39 -38
  34. data/vendor/assets/javascripts/webshims/minified/shims/combos/9.js +65 -68
  35. data/vendor/assets/javascripts/webshims/minified/shims/details.js +4 -4
  36. data/vendor/assets/javascripts/webshims/minified/shims/dom-extend.js +23 -22
  37. data/vendor/assets/javascripts/webshims/minified/shims/form-core.js +19 -22
  38. data/vendor/assets/javascripts/webshims/minified/shims/form-datalist.js +14 -14
  39. data/vendor/assets/javascripts/webshims/minified/shims/form-number-date-api.js +9 -9
  40. data/vendor/assets/javascripts/webshims/minified/shims/form-number-date-ui.js +18 -19
  41. data/vendor/assets/javascripts/webshims/minified/shims/form-shim-extend.js +45 -43
  42. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-de.txt +33 -33
  43. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-en.txt +34 -34
  44. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-core.js +12 -12
  45. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-jaris.js +23 -0
  46. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-native-fix.js +1 -1
  47. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-swf.js +26 -30
  48. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-yt.js +3 -3
  49. data/vendor/assets/javascripts/webshims/minified/shims/styles/shim.css +689 -686
  50. data/vendor/assets/javascripts/webshims/minified/shims/swf/JarisFLVPlayer.swf +0 -0
  51. data/vendor/assets/javascripts/webshims/minified/shims/track-ui.js +9 -9
  52. data/vendor/assets/javascripts/webshims/minified/shims/track.js +21 -21
  53. data/vendor/assets/javascripts/webshims/polyfiller.js +1191 -1175
  54. data/vendor/assets/javascripts/webshims/shims/combos/1.js +1754 -1714
  55. data/vendor/assets/javascripts/webshims/shims/combos/10.js +3247 -3320
  56. data/vendor/assets/javascripts/webshims/shims/combos/11.js +1633 -1588
  57. data/vendor/assets/javascripts/webshims/shims/combos/12.js +1636 -1591
  58. data/vendor/assets/javascripts/webshims/shims/combos/13.js +1100 -1058
  59. data/vendor/assets/javascripts/webshims/shims/combos/14.js +476 -476
  60. data/vendor/assets/javascripts/webshims/shims/combos/15.js +316 -314
  61. data/vendor/assets/javascripts/webshims/shims/combos/16.js +2094 -2104
  62. data/vendor/assets/javascripts/webshims/shims/combos/17.js +2258 -2267
  63. data/vendor/assets/javascripts/webshims/shims/combos/18.js +1380 -1364
  64. data/vendor/assets/javascripts/webshims/shims/combos/19.js +2239 -2247
  65. data/vendor/assets/javascripts/webshims/shims/combos/2.js +2339 -2294
  66. data/vendor/assets/javascripts/webshims/shims/combos/20.js +1493 -1606
  67. data/vendor/assets/javascripts/webshims/shims/combos/21.js +1733 -1635
  68. data/vendor/assets/javascripts/webshims/shims/combos/22.js +2295 -2408
  69. data/vendor/assets/javascripts/webshims/shims/combos/23.js +2269 -2168
  70. data/vendor/assets/javascripts/webshims/shims/combos/24.js +2775 -2780
  71. data/vendor/assets/javascripts/webshims/shims/combos/25.js +1505 -1456
  72. data/vendor/assets/javascripts/webshims/shims/combos/26.js +2111 -2115
  73. data/vendor/assets/javascripts/webshims/shims/combos/27.js +3264 -3331
  74. data/vendor/assets/javascripts/webshims/shims/combos/3.js +3020 -2970
  75. data/vendor/assets/javascripts/webshims/shims/combos/4.js +770 -822
  76. data/vendor/assets/javascripts/webshims/shims/combos/5.js +1025 -1077
  77. data/vendor/assets/javascripts/webshims/shims/combos/59.js +1706 -1753
  78. data/vendor/assets/javascripts/webshims/shims/combos/6.js +444 -433
  79. data/vendor/assets/javascripts/webshims/shims/combos/7.js +699 -688
  80. data/vendor/assets/javascripts/webshims/shims/combos/8.js +1488 -1445
  81. data/vendor/assets/javascripts/webshims/shims/combos/9.js +2445 -2518
  82. data/vendor/assets/javascripts/webshims/shims/details.js +148 -146
  83. data/vendor/assets/javascripts/webshims/shims/dom-extend.js +952 -912
  84. data/vendor/assets/javascripts/webshims/shims/es5.js +802 -802
  85. data/vendor/assets/javascripts/webshims/shims/excanvas.js +924 -924
  86. data/vendor/assets/javascripts/webshims/shims/form-core.js +606 -659
  87. data/vendor/assets/javascripts/webshims/shims/form-datalist.js +681 -676
  88. data/vendor/assets/javascripts/webshims/shims/form-message.js +164 -163
  89. data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +255 -255
  90. data/vendor/assets/javascripts/webshims/shims/form-number-date-api.js +383 -383
  91. data/vendor/assets/javascripts/webshims/shims/form-number-date-ui.js +61 -50
  92. data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +1569 -1472
  93. data/vendor/assets/javascripts/webshims/shims/geolocation.js +168 -168
  94. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ar.js +32 -32
  95. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ch-ZN.js +32 -32
  96. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-de.txt +33 -33
  97. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-el.js +32 -32
  98. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-en.txt +34 -34
  99. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-es.js +31 -31
  100. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-fr.js +32 -32
  101. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-he.js +32 -32
  102. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-hi.js +32 -32
  103. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-hu.js +32 -32
  104. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-it.js +32 -32
  105. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ja.js +32 -32
  106. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-nl.js +32 -32
  107. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-pt-PT.js +32 -32
  108. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-ru.js +31 -31
  109. data/vendor/assets/javascripts/webshims/shims/i18n/errormessages-sv.js +32 -32
  110. data/vendor/assets/javascripts/webshims/shims/json-storage.js +308 -308
  111. data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +536 -533
  112. data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +861 -0
  113. data/vendor/assets/javascripts/webshims/shims/mediaelement-native-fix.js +98 -98
  114. data/vendor/assets/javascripts/webshims/shims/mediaelement-swf.js +957 -1073
  115. data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +543 -543
  116. data/vendor/assets/javascripts/webshims/shims/styles/shim.css +689 -686
  117. data/vendor/assets/javascripts/webshims/shims/swf/JarisFLVPlayer.swf +0 -0
  118. data/vendor/assets/javascripts/webshims/shims/track-ui.js +9 -8
  119. data/vendor/assets/javascripts/webshims/shims/track.js +17 -11
  120. metadata +6 -6
  121. data/vendor/assets/javascripts/webshims/minified/shims/form-native-fix.js +0 -7
  122. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/README +0 -62
  123. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/README +0 -82
  124. data/vendor/assets/javascripts/webshims/shims/form-native-fix.js +0 -261
@@ -1,2409 +1,2296 @@
1
- // vim: ts=4 sts=4 sw=4 expandtab
2
- // -- kriskowal Kris Kowal Copyright (C) 2009-2011 MIT License
3
- // -- tlrobinson Tom Robinson Copyright (C) 2009-2010 MIT License (Narwhal Project)
4
- // -- dantman Daniel Friesen Copyright (C) 2010 XXX TODO License or CLA
5
- // -- fschaefer Florian Schäfer Copyright (C) 2010 MIT License
6
- // -- Gozala Irakli Gozalishvili Copyright (C) 2010 MIT License
7
- // -- kitcambridge Kit Cambridge Copyright (C) 2011 MIT License
8
- // -- kossnocorp Sasha Koss XXX TODO License or CLA
9
- // -- bryanforbes Bryan Forbes XXX TODO License or CLA
10
- // -- killdream Quildreen Motta Copyright (C) 2011 MIT Licence
11
- // -- michaelficarra Michael Ficarra Copyright (C) 2011 3-clause BSD License
12
- // -- sharkbrainguy Gerard Paapu Copyright (C) 2011 MIT License
13
- // -- bbqsrc Brendan Molloy XXX TODO License or CLA
14
- // -- iwyg XXX TODO License or CLA
15
- // -- DomenicDenicola Domenic Denicola XXX TODO License or CLA
16
- // -- xavierm02 Montillet Xavier XXX TODO License or CLA
17
- // -- Raynos Raynos XXX TODO License or CLA
18
- // -- samsonjs Sami Samhuri XXX TODO License or CLA
19
- // -- rwldrn Rick Waldron Copyright (C) 2011 MIT License
20
- // -- lexer Alexey Zakharov XXX TODO License or CLA
21
-
22
- /*!
23
- Copyright (c) 2009, 280 North Inc. http://280north.com/
24
- MIT License. http://github.com/280north/narwhal/blob/master/README.md
25
- */
26
-
27
- (function (undefined) {
28
-
29
- /**
30
- * Brings an environment as close to ECMAScript 5 compliance
31
- * as is possible with the facilities of erstwhile engines.
32
- *
33
- * ES5 Draft
34
- * http://www.ecma-international.org/publications/files/drafts/tc39-2009-050.pdf
35
- *
36
- * NOTE: this is a draft, and as such, the URL is subject to change. If the
37
- * link is broken, check in the parent directory for the latest TC39 PDF.
38
- * http://www.ecma-international.org/publications/files/drafts/
39
- *
40
- * Previous ES5 Draft
41
- * http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
42
- * This is a broken link to the previous draft of ES5 on which most of the
43
- * numbered specification references and quotes herein were taken. Updating
44
- * these references and quotes to reflect the new document would be a welcome
45
- * volunteer project.
46
- *
47
- * @module
48
- */
49
-
50
- /*whatsupdoc*/
51
-
52
- // Shortcut to an often accessed properties, in order to avoid multiple
53
- // dereference that costs universally.
54
- // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
55
- // us it in defining shortcuts.
56
- var call = Function.prototype.call;
57
- var prototypeOfArray = Array.prototype;
58
- var prototypeOfObject = Object.prototype;
59
- var slice = prototypeOfArray.slice;
60
- var owns;
61
- var toString;
62
-
63
- // ES-5 15.3.4.5
64
- // http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
65
-
66
- if (!Function.prototype.bind) {
67
- Function.prototype.bind = function (that) { // .length is 1
68
- // 1. Let Target be the this value.
69
- var target = this;
70
- // 2. If IsCallable(Target) is false, throw a TypeError exception.
71
- if (typeof target != "function")
72
- throw new TypeError(); // TODO message
73
- // 3. Let A be a new (possibly empty) internal list of all of the
74
- // argument values provided after thisArg (arg1, arg2 etc), in order.
75
- // XXX slicedArgs will stand in for "A" if used
76
- var args = slice.call(arguments, 1); // for normal call
77
- // 4. Let F be a new native ECMAScript object.
78
- // 9. Set the [[Prototype]] internal property of F to the standard
79
- // built-in Function prototype object as specified in 15.3.3.1.
80
- // 10. Set the [[Call]] internal property of F as described in
81
- // 15.3.4.5.1.
82
- // 11. Set the [[Construct]] internal property of F as described in
83
- // 15.3.4.5.2.
84
- // 12. Set the [[HasInstance]] internal property of F as described in
85
- // 15.3.4.5.3.
86
- // 13. The [[Scope]] internal property of F is unused and need not
87
- // exist.
88
- var bound = function () {
89
-
90
- if (this instanceof bound) {
91
- // 15.3.4.5.2 [[Construct]]
92
- // When the [[Construct]] internal method of a function object,
93
- // F that was created using the bind function is called with a
94
- // list of arguments ExtraArgs the following steps are taken:
95
- // 1. Let target be the value of F's [[TargetFunction]]
96
- // internal property.
97
- // 2. If target has no [[Construct]] internal method, a
98
- // TypeError exception is thrown.
99
- // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
100
- // property.
101
- // 4. Let args be a new list containing the same values as the
102
- // list boundArgs in the same order followed by the same
103
- // values as the list ExtraArgs in the same order.
104
-
105
- var F = function(){};
106
- F.prototype = target.prototype;
107
- var self = new F;
108
-
109
- var result = target.apply(
110
- self,
111
- args.concat(slice.call(arguments))
112
- );
113
- if (result !== null && Object(result) === result)
114
- return result;
115
- return self;
116
-
117
- } else {
118
- // 15.3.4.5.1 [[Call]]
119
- // When the [[Call]] internal method of a function object, F,
120
- // which was created using the bind function is called with a
121
- // this value and a list of arguments ExtraArgs the following
122
- // steps are taken:
123
- // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
124
- // property.
125
- // 2. Let boundThis be the value of F's [[BoundThis]] internal
126
- // property.
127
- // 3. Let target be the value of F's [[TargetFunction]] internal
128
- // property.
129
- // 4. Let args be a new list containing the same values as the list
130
- // boundArgs in the same order followed by the same values as
131
- // the list ExtraArgs in the same order. 5. Return the
132
- // result of calling the [[Call]] internal method of target
133
- // providing boundThis as the this value and providing args
134
- // as the arguments.
135
-
136
- // equiv: target.call(this, ...boundArgs, ...args)
137
- return target.apply(
138
- that,
139
- args.concat(slice.call(arguments))
140
- );
141
-
142
- }
143
-
144
- };
145
- // XXX bound.length is never writable, so don't even try
146
- //
147
- // 16. The length own property of F is given attributes as specified in
148
- // 15.3.5.1.
149
- // TODO
150
- // 17. Set the [[Extensible]] internal property of F to true.
151
- // TODO
152
- // 18. Call the [[DefineOwnProperty]] internal method of F with
153
- // arguments "caller", PropertyDescriptor {[[Value]]: null,
154
- // [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
155
- // false}, and false.
156
- // TODO
157
- // 19. Call the [[DefineOwnProperty]] internal method of F with
158
- // arguments "arguments", PropertyDescriptor {[[Value]]: null,
159
- // [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
160
- // false}, and false.
161
- // TODO
162
- // NOTE Function objects created using Function.prototype.bind do not
163
- // have a prototype property.
164
- // XXX can't delete it in pure-js.
165
- return bound;
166
- };
167
- }
168
-
169
- toString = call.bind(prototypeOfObject.toString);
170
- owns = call.bind(prototypeOfObject.hasOwnProperty);
171
-
172
-
173
- //
174
- // Array
175
- // =====
176
- //
177
-
178
- // ES5 15.4.3.2
179
- if (!Array.isArray) {
180
- Array.isArray = function (obj) {
181
- return toString(obj) == "[object Array]";
182
- };
183
- }
184
-
185
- // The IsCallable() check in the Array functions
186
- // has been replaced with a strict check on the
187
- // internal class of the object to trap cases where
188
- // the provided function was actually a regular
189
- // expression literal, which in V8 and
190
- // JavaScriptCore is a typeof "function". Only in
191
- // V8 are regular expression literals permitted as
192
- // reduce parameters, so it is desirable in the
193
- // general case for the shim to match the more
194
- // strict and common behavior of rejecting regular
195
- // expressions.
196
-
197
- // ES5 15.4.4.18
198
- // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/foreach
199
- if (!Array.prototype.forEach) {
200
- Array.prototype.forEach = function (fun /*, thisp*/) {
201
- var self = toObject(this),
202
- thisp = arguments[1],
203
- i = 0,
204
- length = self.length >>> 0;
205
-
206
- // If no callback function or if callback is not a callable function
207
- if (toString(fun) != "[object Function]") {
208
- throw new TypeError(); // TODO message
209
- }
210
-
211
- while (i < length) {
212
- if (i in self) {
213
- // Invoke the callback function with call, passing arguments:
214
- // context, property value, property key, thisArg object context
215
- fun.call(thisp, self[i], i, self);
216
- }
217
- i++;
218
- }
219
- };
220
- }
221
-
222
- // ES5 15.4.4.19
223
- // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
224
- if (!Array.prototype.map) {
225
- Array.prototype.map = function (fun /*, thisp*/) {
226
- var self = toObject(this),
227
- length = self.length >>> 0,
228
- result = Array(length),
229
- thisp = arguments[1];
230
-
231
- // If no callback function or if callback is not a callable function
232
- if (toString(fun) != "[object Function]") {
233
- throw new TypeError(); // TODO message
234
- }
235
-
236
- for (var i = 0; i < length; i++) {
237
- if (i in self)
238
- result[i] = fun.call(thisp, self[i], i, self);
239
- }
240
- return result;
241
- };
242
- }
243
-
244
- // ES5 15.4.4.20
245
- if (!Array.prototype.filter) {
246
- Array.prototype.filter = function (fun /*, thisp */) {
247
- var self = toObject(this),
248
- length = self.length >>> 0,
249
- result = [],
250
- thisp = arguments[1];
251
-
252
- // If no callback function or if callback is not a callable function
253
- if (toString(fun) != "[object Function]") {
254
- throw new TypeError(); // TODO message
255
- }
256
-
257
- for (var i = 0; i < length; i++) {
258
- if (i in self && fun.call(thisp, self[i], i, self))
259
- result.push(self[i]);
260
- }
261
- return result;
262
- };
263
- }
264
-
265
- // ES5 15.4.4.16
266
- if (!Array.prototype.every) {
267
- Array.prototype.every = function (fun /*, thisp */) {
268
- var self = toObject(this),
269
- length = self.length >>> 0,
270
- thisp = arguments[1];
271
-
272
- // If no callback function or if callback is not a callable function
273
- if (toString(fun) != "[object Function]") {
274
- throw new TypeError(); // TODO message
275
- }
276
-
277
- for (var i = 0; i < length; i++) {
278
- if (i in self && !fun.call(thisp, self[i], i, self))
279
- return false;
280
- }
281
- return true;
282
- };
283
- }
284
-
285
- // ES5 15.4.4.17
286
- // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
287
- if (!Array.prototype.some) {
288
- Array.prototype.some = function (fun /*, thisp */) {
289
- var self = toObject(this),
290
- length = self.length >>> 0,
291
- thisp = arguments[1];
292
-
293
- // If no callback function or if callback is not a callable function
294
- if (toString(fun) != "[object Function]") {
295
- throw new TypeError(); // TODO message
296
- }
297
-
298
- for (var i = 0; i < length; i++) {
299
- if (i in self && fun.call(thisp, self[i], i, self))
300
- return true;
301
- }
302
- return false;
303
- };
304
- }
305
-
306
- // ES5 15.4.4.21
307
- // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
308
- if (!Array.prototype.reduce) {
309
- Array.prototype.reduce = function (fun /*, initial*/) {
310
- var self = toObject(this),
311
- length = self.length >>> 0;
312
-
313
- // If no callback function or if callback is not a callable function
314
- if (toString(fun) != "[object Function]") {
315
- throw new TypeError(); // TODO message
316
- }
317
-
318
- // no value to return if no initial value and an empty array
319
- if (!length && arguments.length == 1)
320
- throw new TypeError(); // TODO message
321
-
322
- var i = 0;
323
- var result;
324
- if (arguments.length >= 2) {
325
- result = arguments[1];
326
- } else {
327
- do {
328
- if (i in self) {
329
- result = self[i++];
330
- break;
331
- }
332
-
333
- // if array contains no values, no initial value to return
334
- if (++i >= length)
335
- throw new TypeError(); // TODO message
336
- } while (true);
337
- }
338
-
339
- for (; i < length; i++) {
340
- if (i in self)
341
- result = fun.call(void 0, result, self[i], i, self);
342
- }
343
-
344
- return result;
345
- };
346
- }
347
-
348
- // ES5 15.4.4.22
349
- // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
350
- if (!Array.prototype.reduceRight) {
351
- Array.prototype.reduceRight = function (fun /*, initial*/) {
352
- var self = toObject(this),
353
- length = self.length >>> 0;
354
-
355
- // If no callback function or if callback is not a callable function
356
- if (toString(fun) != "[object Function]") {
357
- throw new TypeError(); // TODO message
358
- }
359
-
360
- // no value to return if no initial value, empty array
361
- if (!length && arguments.length == 1)
362
- throw new TypeError(); // TODO message
363
-
364
- var result, i = length - 1;
365
- if (arguments.length >= 2) {
366
- result = arguments[1];
367
- } else {
368
- do {
369
- if (i in self) {
370
- result = self[i--];
371
- break;
372
- }
373
-
374
- // if array contains no values, no initial value to return
375
- if (--i < 0)
376
- throw new TypeError(); // TODO message
377
- } while (true);
378
- }
379
-
380
- do {
381
- if (i in this)
382
- result = fun.call(void 0, result, self[i], i, self);
383
- } while (i--);
384
-
385
- return result;
386
- };
387
- }
388
-
389
- // ES5 15.4.4.14
390
- // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
391
- if (!Array.prototype.indexOf) {
392
- Array.prototype.indexOf = function (sought /*, fromIndex */ ) {
393
- var self = toObject(this),
394
- length = self.length >>> 0;
395
-
396
- if (!length)
397
- return -1;
398
-
399
- var i = 0;
400
- if (arguments.length > 1)
401
- i = toInteger(arguments[1]);
402
-
403
- // handle negative indices
404
- i = i >= 0 ? i : length - Math.abs(i);
405
- for (; i < length; i++) {
406
- if (i in self && self[i] === sought) {
407
- return i;
408
- }
409
- }
410
- return -1;
411
- };
412
- }
413
-
414
- // ES5 15.4.4.15
415
- if (!Array.prototype.lastIndexOf) {
416
- Array.prototype.lastIndexOf = function (sought /*, fromIndex */) {
417
- var self = toObject(this),
418
- length = self.length >>> 0;
419
-
420
- if (!length)
421
- return -1;
422
- var i = length - 1;
423
- if (arguments.length > 1)
424
- i = toInteger(arguments[1]);
425
- // handle negative indices
426
- i = i >= 0 ? i : length - Math.abs(i);
427
- for (; i >= 0; i--) {
428
- if (i in self && sought === self[i])
429
- return i;
430
- }
431
- return -1;
432
- };
433
- }
434
-
435
- //
436
- // Array
437
- // =====
438
- //
439
-
440
- // ES5 15.4.4.12
441
- // http://es5.github.com/#x15.4.4.12
442
- // Default value for second param
443
- // [bugfix, ielt9, old browsers]
444
- // IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
445
- if([1,2].splice(0).length != 2) {
446
- var _origArraySplice = Array.prototype.splice;
447
-
448
- Array.prototype.splice = function(start, deleteCount) {
449
- if(!arguments.length)return [];
450
-
451
- return _origArraySplice.apply(this, [
452
- start === void 0 ? 0 : start,
453
- deleteCount === void 0 ? (this.length - start) : deleteCount
454
- ].concat(slice.call(arguments, 2)))
455
- };
456
- }
457
-
458
- //
459
- // Object
460
- // ======
461
- //
462
-
463
-
464
- // ES5 15.2.3.14
465
- // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
466
- if (!Object.keys) {
467
-
468
- var hasDontEnumBug = true,
469
- dontEnums = [
470
- "toString",
471
- "toLocaleString",
472
- "valueOf",
473
- "hasOwnProperty",
474
- "isPrototypeOf",
475
- "propertyIsEnumerable",
476
- "constructor"
477
- ],
478
- dontEnumsLength = dontEnums.length;
479
-
480
- for (var key in {"toString": null})
481
- hasDontEnumBug = false;
482
-
483
- Object.keys = function keys(object) {
484
-
485
- if ((typeof object != "object" && typeof object != "function") || object === null)
486
- throw new TypeError("Object.keys called on a non-object");
487
-
488
- var keys = [];
489
- for (var name in object) {
490
- if (owns(object, name)) {
491
- keys.push(name);
492
- }
493
- }
494
-
495
- if (hasDontEnumBug) {
496
- for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
497
- var dontEnum = dontEnums[i];
498
- if (owns(object, dontEnum)) {
499
- keys.push(dontEnum);
500
- }
501
- }
502
- }
503
-
504
- return keys;
505
- };
506
-
507
- }
508
-
509
- //
510
- // Date
511
- // ====
512
- //
513
-
514
- // ES5 15.9.5.43
515
- // Format a Date object as a string according to a simplified subset of the ISO 8601
516
- // standard as defined in 15.9.1.15.
517
- if (!Date.prototype.toISOString) {
518
- Date.prototype.toISOString = function toISOString() {
519
- var result, length, value;
520
- if (!isFinite(this))
521
- throw new RangeError;
522
-
523
- // the date time string format is specified in 15.9.1.15.
524
- result = [this.getUTCFullYear(), this.getUTCMonth() + 1, this.getUTCDate(),
525
- this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
526
-
527
- length = result.length;
528
- while (length--) {
529
- value = result[length];
530
- // pad months, days, hours, minutes, and seconds to have two digits.
531
- if (value < 10)
532
- result[length] = "0" + value;
533
- }
534
- // pad milliseconds to have three digits.
535
- return result.slice(0, 3).join("-") + "T" + result.slice(3).join(":") + "." +
536
- ("000" + this.getUTCMilliseconds()).slice(-3) + "Z";
537
- }
538
- }
539
-
540
- // ES5 15.9.4.4
541
- if (!Date.now) {
542
- Date.now = function now() {
543
- return new Date().getTime();
544
- };
545
- }
546
-
547
- // ES5 15.9.5.44
548
- if (!Date.prototype.toJSON) {
549
- Date.prototype.toJSON = function toJSON(key) {
550
- // This function provides a String representation of a Date object for
551
- // use by JSON.stringify (15.12.3). When the toJSON method is called
552
- // with argument key, the following steps are taken:
553
-
554
- // 1. Let O be the result of calling ToObject, giving it the this
555
- // value as its argument.
556
- // 2. Let tv be ToPrimitive(O, hint Number).
557
- // 3. If tv is a Number and is not finite, return null.
558
- // XXX
559
- // 4. Let toISO be the result of calling the [[Get]] internal method of
560
- // O with argument "toISOString".
561
- // 5. If IsCallable(toISO) is false, throw a TypeError exception.
562
- if (typeof this.toISOString != "function")
563
- throw new TypeError(); // TODO message
564
- // 6. Return the result of calling the [[Call]] internal method of
565
- // toISO with O as the this value and an empty argument list.
566
- return this.toISOString();
567
-
568
- // NOTE 1 The argument is ignored.
569
-
570
- // NOTE 2 The toJSON function is intentionally generic; it does not
571
- // require that its this value be a Date object. Therefore, it can be
572
- // transferred to other kinds of objects for use as a method. However,
573
- // it does require that any such object have a toISOString method. An
574
- // object is free to use the argument key to filter its
575
- // stringification.
576
- };
577
- }
578
-
579
-
580
- //
581
- // String
582
- // ======
583
- //
584
-
585
- // ES5 15.5.4.20
586
- var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
587
- "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
588
- "\u2029\uFEFF";
589
- if (!String.prototype.trim || ws.trim()) {
590
- // http://blog.stevenlevithan.com/archives/faster-trim-javascript
591
- // http://perfectionkills.com/whitespace-deviations/
592
- ws = "[" + ws + "]";
593
- var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
594
- trimEndRegexp = new RegExp(ws + ws + "*$");
595
- String.prototype.trim = function trim() {
596
- return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
597
- };
598
- }
599
-
600
- // ES5 15.5.4.14
601
- // http://es5.github.com/#x15.5.4.14
602
- // [bugfix, chrome]
603
- // If separator is undefined, then the result array contains just one String, which is the this value (converted to a String). If limit is not undefined, then the output array is truncated so that it contains no more than limit elements.
604
- // "0".split(undefined, 0) -> []
605
- if("0".split(void 0, 0).length) {
606
- var oldSplit = String.prototype.split;
607
- String.prototype.split = function(separator, limit) {
608
- if(separator === void 0 && limit === 0)return [];
609
- return oldSplit.apply(this, arguments);
610
- }
611
- }
612
-
613
- // ECMA-262, 3rd B.2.3
614
- // Note an ECMAScript standart, although ECMAScript 3rd Edition has a non-normative section suggesting uniform semantics
615
- // and it should be normalized across all browsers
616
- // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
617
- if("".substr && "0b".substr(-1) !== "b") {
618
- var oldSubstr = String.prototype.substr;
619
- /**
620
- * Get the substring of a string
621
- * @param {integer} start where to start the substring
622
- * @param {integer} length how many characters to return
623
- * @return {string}
624
- */
625
- String.prototype.substr = function(start, length) {
626
- return oldSubstr.call(this, start < 0 ? (start = this.length + start) < 0 ? 0 : start : start, length);
627
- }
628
- }
629
-
630
- //
631
- // Util
632
- // ======
633
- //
634
-
635
- // http://jsperf.com/to-integer
636
- var toInteger = function (n) {
637
- n = +n;
638
- if (n !== n) // isNaN
639
- n = -1;
640
- else if (n !== 0 && n !== (1/0) && n !== -(1/0))
641
- n = (n > 0 || -1) * Math.floor(Math.abs(n));
642
- return n;
643
- };
644
-
645
- var prepareString = "a"[0] != "a",
646
- // ES5 9.9
647
- toObject = function (o) {
648
- if (o == null) { // this matches both null and undefined
649
- throw new TypeError(); // TODO message
650
- }
651
- // If the implementation doesn't support by-index access of
652
- // string characters (ex. IE < 7), split the string
653
- if (prepareString && typeof o == "string" && o) {
654
- return o.split("");
655
- }
656
- return Object(o);
657
- };
658
-
659
- })();
660
-
661
-
662
-
663
- (function($, shims){
664
- var defineProperty = 'defineProperty';
665
- var advancedObjectProperties = !!(Object.create && Object.defineProperties && Object.getOwnPropertyDescriptor);
666
- //safari5 has defineProperty-interface, but it can't be used on dom-object
667
- //only do this test in non-IE browsers, because this hurts dhtml-behavior in some IE8 versions
668
- if (advancedObjectProperties && !$.browser.msie && Object[defineProperty] && Object.prototype.__defineGetter__) {
669
- (function(){
670
- try {
671
- var foo = document.createElement('foo');
672
- Object[defineProperty](foo, 'bar', {
673
- get: function(){
674
- return true;
675
- }
676
- });
677
- advancedObjectProperties = !!foo.bar;
678
- }
679
- catch (e) {
680
- advancedObjectProperties = false;
681
- }
682
- foo = null;
683
- })();
684
- }
685
-
686
- Modernizr.objectAccessor = !!((advancedObjectProperties || (Object.prototype.__defineGetter__ && Object.prototype.__lookupSetter__)) && (!$.browser.opera || shims.browserVersion >= 11));
687
- Modernizr.advancedObjectProperties = advancedObjectProperties;
688
-
689
- if((!advancedObjectProperties || !Object.create || !Object.defineProperties || !Object.getOwnPropertyDescriptor || !Object.defineProperty)){
690
- var call = Function.prototype.call;
691
- var prototypeOfObject = Object.prototype;
692
- var owns = call.bind(prototypeOfObject.hasOwnProperty);
693
-
694
- shims.objectCreate = function(proto, props, opts, no__proto__){
695
- var o;
696
- var f = function(){};
697
-
698
- f.prototype = proto;
699
- o = new f();
700
-
701
- if(!no__proto__ && !('__proto__' in o) && !Modernizr.objectAccessor){
702
- o.__proto__ = proto;
703
- }
704
-
705
- if(props){
706
- shims.defineProperties(o, props);
707
- }
708
-
709
- if(opts){
710
- o.options = jQuery.extend(true, {}, o.options || {}, opts);
711
- opts = o.options;
712
- }
713
-
714
- if(o._create && jQuery.isFunction(o._create)){
715
- o._create(opts);
716
- }
717
- return o;
718
- };
719
-
720
- shims.defineProperties = function(object, props){
721
- for (var name in props) {
722
- if (owns(props, name)) {
723
- shims.defineProperty(object, name, props[name]);
724
- }
725
- }
726
- return object;
727
- };
728
-
729
- var descProps = ['configurable', 'enumerable', 'writable'];
730
- shims.defineProperty = function(proto, property, descriptor){
731
- if(typeof descriptor != "object" || descriptor === null){return proto;}
732
-
733
- if(owns(descriptor, "value")){
734
- proto[property] = descriptor.value;
735
- return proto;
736
- }
737
-
738
- if(proto.__defineGetter__){
739
- if (typeof descriptor.get == "function") {
740
- proto.__defineGetter__(property, descriptor.get);
741
- }
742
- if (typeof descriptor.set == "function"){
743
- proto.__defineSetter__(property, descriptor.set);
744
- }
745
- }
746
- return proto;
747
- };
748
-
749
- shims.getPrototypeOf = function (object) {
750
- return Object.getPrototypeOf && Object.getPrototypeOf(object) || object.__proto__ || object.constructor && object.constructor.prototype;
751
- };
752
-
753
- //based on http://www.refactory.org/s/object_getownpropertydescriptor/view/latest
754
- shims.getOwnPropertyDescriptor = function(obj, prop){
755
- if (typeof obj !== "object" && typeof obj !== "function" || obj === null){
756
- throw new TypeError("Object.getOwnPropertyDescriptor called on a non-object");
757
- }
758
- var descriptor;
759
- if(Object.defineProperty && Object.getOwnPropertyDescriptor){
760
- try{
761
- descriptor = Object.getOwnPropertyDescriptor(obj, prop);
762
- return descriptor;
763
- } catch(e){}
764
- }
765
- descriptor = {
766
- configurable: true,
767
- enumerable: true,
768
- writable: true,
769
- value: undefined
770
- };
771
- var getter = obj.__lookupGetter__ && obj.__lookupGetter__(prop),
772
- setter = obj.__lookupSetter__ && obj.__lookupSetter__(prop)
773
- ;
774
-
775
- if (!getter && !setter) { // not an accessor so return prop
776
- if(!owns(obj, prop)){
777
- return;
778
- }
779
- descriptor.value = obj[prop];
780
- return descriptor;
781
- }
782
-
783
- // there is an accessor, remove descriptor.writable; populate descriptor.get and descriptor.set
784
- delete descriptor.writable;
785
- delete descriptor.value;
786
- descriptor.get = descriptor.set = undefined;
787
-
788
- if(getter){
789
- descriptor.get = getter;
790
- }
791
-
792
- if(setter){
793
- descriptor.set = setter;
794
- }
795
-
796
- return descriptor;
797
- };
798
-
799
- }
800
- })(jQuery, jQuery.webshims);
801
-
802
-
803
- (function($, Modernizr, webshims){
804
- "use strict";
805
- var hasNative = Modernizr.audio && Modernizr.video;
806
- var supportsLoop = false;
807
- var options = webshims.cfg.mediaelement;
808
- var bugs = webshims.bugs;
809
- var loadSwf = function(){
810
- webshims.ready('mediaelement-swf', function(){
811
- if(!webshims.mediaelement.createSWF){
812
- webshims.modules["mediaelement-swf"].test = $.noop;
813
- webshims.reTest(["mediaelement-swf"], hasNative);
814
- }
815
- });
816
- };
817
- var hasSwf;
818
- if(hasNative){
819
- var videoElem = document.createElement('video');
820
- Modernizr.videoBuffered = ('buffered' in videoElem);
821
- supportsLoop = ('loop' in videoElem);
822
-
823
- webshims.capturingEvents(['play', 'playing', 'waiting', 'paused', 'ended', 'durationchange', 'loadedmetadata', 'canplay', 'volumechange']);
824
-
825
- if(!Modernizr.videoBuffered){
826
- webshims.addPolyfill('mediaelement-native-fix', {
827
- f: 'mediaelement',
828
- test: Modernizr.videoBuffered,
829
- d: ['dom-support']
830
- });
831
-
832
- webshims.reTest('mediaelement-native-fix');
833
- }
834
- }
835
-
836
- if(hasNative && !options.preferFlash){
837
- var switchOptions = function(e){
838
- var parent = e.target.parentNode;
839
- if(!options.preferFlash && ($(e.target).is('audio, video') || (parent && $('source:last', parent)[0] == e.target)) ){
840
- webshims.ready('DOM mediaelement', function(){
841
- if(hasSwf){
842
- loadSwf();
843
- }
844
- webshims.ready('WINDOWLOAD mediaelement-swf', function(){
845
- setTimeout(function(){
846
- if(hasSwf && !options.preferFlash && webshims.mediaelement.createSWF && !$(e.target).closest('audio, video').is('.nonnative-api-active')){
847
- options.preferFlash = true;
848
- document.removeEventListener('error', switchOptions, true);
849
- $('audio, video').mediaLoad();
850
- webshims.info("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.src);
851
- } else if(!hasSwf){
852
- document.removeEventListener('error', switchOptions, true);
853
- }
854
- }, 20);
855
- });
856
- });
857
- }
858
- };
859
- document.addEventListener('error', switchOptions, true);
860
- $('audio, video').each(function(){
861
- if(this.error){
862
- switchOptions({target: this});
863
- }
864
- });
865
- }
866
-
867
- bugs.track = false;
868
-
869
- if(Modernizr.track){
870
- (function(){
871
-
872
- if(!bugs.track){
873
- bugs.track = typeof $('<track />')[0].readyState != 'number';
874
- }
875
-
876
- if(!bugs.track){
877
- try {
878
- new TextTrackCue(2, 3, '');
879
- } catch(e){
880
- bugs.track = true;
881
- }
882
- }
883
-
884
- var trackOptions = webshims.cfg.track;
885
- var trackListener = function(e){
886
- $(e.target).filter('track').each(changeApi);
887
- };
888
- var changeApi = function(){
889
- if(bugs.track || (!trackOptions.override && $.prop(this, 'readyState') == 3)){
890
- trackOptions.override = true;
891
- webshims.reTest('track');
892
- document.removeEventListener('error', trackListener, true);
893
- if(this && $.nodeName(this, 'track')){
894
- webshims.error("track support was overwritten. Please check your vtt including your vtt mime-type");
895
- } else {
896
- webshims.info("track support was overwritten. due to bad browser support");
897
- }
898
- }
899
- };
900
- var detectTrackError = function(){
901
- document.addEventListener('error', trackListener, true);
902
-
903
- if(bugs.track){
904
- changeApi();
905
- } else {
906
- $('track').each(changeApi);
907
- }
908
- };
909
- if(!trackOptions.override){
910
- if(webshims.isReady('track')){
911
- detectTrackError();
912
- } else {
913
- $(detectTrackError);
914
- }
915
- }
916
- })();
917
-
918
- }
919
-
920
- webshims.register('mediaelement-core', function($, webshims, window, document, undefined){
921
- hasSwf = swfobject.hasFlashPlayerVersion('9.0.115');
922
-
923
- var mediaelement = webshims.mediaelement;
924
-
925
- var getSrcObj = function(elem, nodeName){
926
- elem = $(elem);
927
- var src = {src: elem.attr('src') || '', elem: elem, srcProp: elem.prop('src')};
928
- if(!src.src){return src;}
929
- var tmp = elem.attr('type');
930
- if(tmp){
931
- src.type = tmp;
932
- src.container = $.trim(tmp.split(';')[0]);
933
- } else {
934
- if(!nodeName){
935
- nodeName = elem[0].nodeName.toLowerCase();
936
- if(nodeName == 'source'){
937
- nodeName = (elem.closest('video, audio')[0] || {nodeName: 'video'}).nodeName.toLowerCase();
938
- }
939
- }
940
- tmp = mediaelement.getTypeForSrc(src.src, nodeName );
941
-
942
- if(tmp){
943
- src.type = tmp;
944
- src.container = tmp;
945
- }
946
- }
947
- tmp = elem.attr('media');
948
- if(tmp){
949
- src.media = tmp;
950
- }
951
- return src;
952
- };
953
-
954
-
955
-
956
- var hasYt = !hasSwf && ('postMessage' in window) && hasNative;
957
-
958
- var loadYt = (function(){
959
- var loaded;
960
- return function(){
961
- if(loaded || !hasYt){return;}
962
- loaded = true;
963
- webshims.loader.loadScript("https://www.youtube.com/player_api");
964
- $(function(){
965
- webshims.polyfill("mediaelement-yt");
966
- });
967
- };
968
- })();
969
- var loadThird = function(){
970
- if(hasSwf){
971
- loadSwf();
972
- } else {
973
- loadYt();
974
- }
975
- };
976
-
977
- webshims.addPolyfill('mediaelement-yt', {
978
- test: !hasYt,
979
- d: ['dom-support']
980
- });
981
-
982
- mediaelement.mimeTypes = {
983
- audio: {
984
- //ogm shouldn´t be used!
985
- 'audio/ogg': ['ogg','oga', 'ogm'],
986
- 'audio/ogg;codecs="opus"': 'opus',
987
- 'audio/mpeg': ['mp2','mp3','mpga','mpega'],
988
- 'audio/mp4': ['mp4','mpg4', 'm4r', 'm4a', 'm4p', 'm4b', 'aac'],
989
- 'audio/wav': ['wav'],
990
- 'audio/3gpp': ['3gp','3gpp'],
991
- 'audio/webm': ['webm'],
992
- 'audio/fla': ['flv', 'f4a', 'fla'],
993
- 'application/x-mpegURL': ['m3u8', 'm3u']
994
- },
995
- video: {
996
- //ogm shouldn´t be used!
997
- 'video/ogg': ['ogg','ogv', 'ogm'],
998
- 'video/mpeg': ['mpg','mpeg','mpe'],
999
- 'video/mp4': ['mp4','mpg4', 'm4v'],
1000
- 'video/quicktime': ['mov','qt'],
1001
- 'video/x-msvideo': ['avi'],
1002
- 'video/x-ms-asf': ['asf', 'asx'],
1003
- 'video/flv': ['flv', 'f4v'],
1004
- 'video/3gpp': ['3gp','3gpp'],
1005
- 'video/webm': ['webm'],
1006
- 'application/x-mpegURL': ['m3u8', 'm3u'],
1007
- 'video/MP2T': ['ts']
1008
- }
1009
- }
1010
- ;
1011
-
1012
- mediaelement.mimeTypes.source = $.extend({}, mediaelement.mimeTypes.audio, mediaelement.mimeTypes.video);
1013
-
1014
- mediaelement.getTypeForSrc = function(src, nodeName){
1015
- if(src.indexOf('youtube.com/watch?') != -1 || src.indexOf('youtube.com/v/') != -1){
1016
- return 'video/youtube';
1017
- }
1018
- src = src.split('?')[0].split('.');
1019
- src = src[src.length - 1];
1020
- var mt;
1021
-
1022
- $.each(mediaelement.mimeTypes[nodeName], function(mimeType, exts){
1023
- if(exts.indexOf(src) !== -1){
1024
- mt = mimeType;
1025
- return false;
1026
- }
1027
- });
1028
- return mt;
1029
- };
1030
-
1031
-
1032
- mediaelement.srces = function(mediaElem, srces){
1033
- mediaElem = $(mediaElem);
1034
- if(!srces){
1035
- srces = [];
1036
- var nodeName = mediaElem[0].nodeName.toLowerCase();
1037
- var src = getSrcObj(mediaElem, nodeName);
1038
-
1039
- if(!src.src){
1040
-
1041
- $('source', mediaElem).each(function(){
1042
- src = getSrcObj(this, nodeName);
1043
- if(src.src){srces.push(src);}
1044
- });
1045
- } else {
1046
- srces.push(src);
1047
- }
1048
- return srces;
1049
- } else {
1050
- mediaElem.removeAttr('src').removeAttr('type').find('source').remove();
1051
- if(!$.isArray(srces)){
1052
- srces = [srces];
1053
- }
1054
- srces.forEach(function(src){
1055
- var source = document.createElement('source');
1056
- if(typeof src == 'string'){
1057
- src = {src: src};
1058
- }
1059
- source.setAttribute('src', src.src);
1060
- if(src.type){
1061
- source.setAttribute('type', src.type);
1062
- }
1063
- if(src.media){
1064
- source.setAttribute('media', src.media);
1065
- }
1066
- mediaElem.append(source);
1067
- });
1068
-
1069
- }
1070
- };
1071
-
1072
-
1073
- $.fn.loadMediaSrc = function(srces, poster){
1074
- return this.each(function(){
1075
- if(poster !== undefined){
1076
- $(this).removeAttr('poster');
1077
- if(poster){
1078
- $.attr(this, 'poster', poster);
1079
- }
1080
- }
1081
- mediaelement.srces(this, srces);
1082
- $(this).mediaLoad();
1083
- });
1084
- };
1085
-
1086
- mediaelement.swfMimeTypes = ['video/3gpp', 'video/x-msvideo', 'video/quicktime', 'video/x-m4v', 'video/mp4', 'video/m4p', 'video/x-flv', 'video/flv', 'audio/mpeg', 'audio/aac', 'audio/mp4', 'audio/x-m4a', 'audio/m4a', 'audio/mp3', 'audio/x-fla', 'audio/fla', 'youtube/flv', 'jwplayer/jwplayer', 'video/youtube'];
1087
-
1088
- mediaelement.canThirdPlaySrces = function(mediaElem, srces){
1089
- var ret = '';
1090
- if(hasSwf || hasYt){
1091
- mediaElem = $(mediaElem);
1092
- srces = srces || mediaelement.srces(mediaElem);
1093
- $.each(srces, function(i, src){
1094
- if(src.container && src.src && ((hasSwf && mediaelement.swfMimeTypes.indexOf(src.container) != -1) || (hasYt && src.container == 'video/youtube'))){
1095
- ret = src;
1096
- return false;
1097
- }
1098
- });
1099
-
1100
- }
1101
-
1102
- return ret;
1103
- };
1104
-
1105
- var nativeCanPlayType = {};
1106
- mediaelement.canNativePlaySrces = function(mediaElem, srces){
1107
- var ret = '';
1108
- if(hasNative){
1109
- mediaElem = $(mediaElem);
1110
- var nodeName = (mediaElem[0].nodeName || '').toLowerCase();
1111
- if(!nativeCanPlayType[nodeName]){return ret;}
1112
- srces = srces || mediaelement.srces(mediaElem);
1113
-
1114
- $.each(srces, function(i, src){
1115
- if(src.type && nativeCanPlayType[nodeName].prop._supvalue.call(mediaElem[0], src.type) ){
1116
- ret = src;
1117
- return false;
1118
- }
1119
- });
1120
- }
1121
- return ret;
1122
- };
1123
-
1124
- mediaelement.setError = function(elem, message){
1125
- if(!message){
1126
- message = "can't play sources";
1127
- }
1128
-
1129
- $(elem).pause().data('mediaerror', message);
1130
- webshims.warn('mediaelementError: '+ message);
1131
- setTimeout(function(){
1132
- if($(elem).data('mediaerror')){
1133
- $(elem).trigger('mediaerror');
1134
- }
1135
- }, 1);
1136
- };
1137
-
1138
- var handleThird = (function(){
1139
- var requested;
1140
- return function( mediaElem, ret, data ){
1141
- webshims.ready(hasSwf ? 'mediaelement-swf' : 'mediaelement-yt', function(){
1142
- if(mediaelement.createSWF){
1143
- mediaelement.createSWF( mediaElem, ret, data );
1144
- } else if(!requested) {
1145
- requested = true;
1146
- loadThird();
1147
- //readd to ready
1148
- handleThird( mediaElem, ret, data );
1149
- }
1150
- });
1151
- if(!requested && hasYt && !mediaelement.createSWF){
1152
- loadYt();
1153
- }
1154
- };
1155
- })();
1156
-
1157
- var stepSources = function(elem, data, useSwf, _srces, _noLoop){
1158
- var ret;
1159
- if(useSwf || (useSwf !== false && data && data.isActive == 'third')){
1160
- ret = mediaelement.canThirdPlaySrces(elem, _srces);
1161
- if(!ret){
1162
- if(_noLoop){
1163
- mediaelement.setError(elem, false);
1164
- } else {
1165
- stepSources(elem, data, false, _srces, true);
1166
- }
1167
- } else {
1168
- handleThird(elem, ret, data);
1169
- }
1170
- } else {
1171
- ret = mediaelement.canNativePlaySrces(elem, _srces);
1172
- if(!ret){
1173
- if(_noLoop){
1174
- mediaelement.setError(elem, false);
1175
- if(data && data.isActive == 'third') {
1176
- mediaelement.setActive(elem, 'html5', data);
1177
- }
1178
- } else {
1179
- stepSources(elem, data, true, _srces, true);
1180
- }
1181
- } else if(data && data.isActive == 'third') {
1182
- mediaelement.setActive(elem, 'html5', data);
1183
- }
1184
- }
1185
- };
1186
- var stopParent = /^(?:embed|object|datalist)$/i;
1187
- var selectSource = function(elem, data){
1188
- var baseData = webshims.data(elem, 'mediaelementBase') || webshims.data(elem, 'mediaelementBase', {});
1189
- var _srces = mediaelement.srces(elem);
1190
- var parent = elem.parentNode;
1191
-
1192
- clearTimeout(baseData.loadTimer);
1193
- $.data(elem, 'mediaerror', false);
1194
-
1195
- if(!_srces.length || !parent || parent.nodeType != 1 || stopParent.test(parent.nodeName || '')){return;}
1196
- data = data || webshims.data(elem, 'mediaelement');
1197
- stepSources(elem, data, options.preferFlash || undefined, _srces);
1198
- };
1199
-
1200
-
1201
- $(document).bind('ended', function(e){
1202
- var data = webshims.data(e.target, 'mediaelement');
1203
- if( supportsLoop && (!data || data.isActive == 'html5') && !$.prop(e.target, 'loop')){return;}
1204
- setTimeout(function(){
1205
- if( $.prop(e.target, 'paused') || !$.prop(e.target, 'loop') ){return;}
1206
- $(e.target).prop('currentTime', 0).play();
1207
- }, 1);
1208
-
1209
- });
1210
- if(!supportsLoop){
1211
- webshims.defineNodeNamesBooleanProperty(['audio', 'video'], 'loop');
1212
- }
1213
-
1214
- ['audio', 'video'].forEach(function(nodeName){
1215
- var supLoad = webshims.defineNodeNameProperty(nodeName, 'load', {
1216
- prop: {
1217
- value: function(){
1218
- var data = webshims.data(this, 'mediaelement');
1219
- selectSource(this, data);
1220
- if(hasNative && (!data || data.isActive == 'html5') && supLoad.prop._supvalue){
1221
- supLoad.prop._supvalue.apply(this, arguments);
1222
- }
1223
- }
1224
- }
1225
- });
1226
- nativeCanPlayType[nodeName] = webshims.defineNodeNameProperty(nodeName, 'canPlayType', {
1227
- prop: {
1228
- value: function(type){
1229
- var ret = '';
1230
- if(hasNative && nativeCanPlayType[nodeName].prop._supvalue){
1231
- ret = nativeCanPlayType[nodeName].prop._supvalue.call(this, type);
1232
- if(ret == 'no'){
1233
- ret = '';
1234
- }
1235
- }
1236
- if(!ret && hasSwf){
1237
- type = $.trim((type || '').split(';')[0]);
1238
- if(mediaelement.swfMimeTypes.indexOf(type) != -1){
1239
- ret = 'maybe';
1240
- }
1241
- }
1242
- return ret;
1243
- }
1244
- }
1245
- });
1246
- });
1247
- webshims.onNodeNamesPropertyModify(['audio', 'video'], ['src', 'poster'], {
1248
- set: function(){
1249
- var elem = this;
1250
- var baseData = webshims.data(elem, 'mediaelementBase') || webshims.data(elem, 'mediaelementBase', {});
1251
- clearTimeout(baseData.loadTimer);
1252
- baseData.loadTimer = setTimeout(function(){
1253
- selectSource(elem);
1254
- elem = null;
1255
- }, 9);
1256
- }
1257
- });
1258
-
1259
- var initMediaElements = function(){
1260
-
1261
- webshims.addReady(function(context, insertedElement){
1262
- $('video, audio', context)
1263
- .add(insertedElement.filter('video, audio'))
1264
- .each(function(){
1265
- if($.browser.msie && webshims.browserVersion > 8 && $.prop(this, 'paused') && !$.prop(this, 'readyState') && $(this).is('audio[preload="none"][controls]:not([autoplay])')){
1266
- $(this).prop('preload', 'metadata').mediaLoad();
1267
- } else {
1268
- selectSource(this);
1269
- }
1270
-
1271
-
1272
-
1273
- if(hasNative){
1274
- var bufferTimer;
1275
- var lastBuffered;
1276
- var elem = this;
1277
- var getBufferedString = function(){
1278
- var buffered = $.prop(elem, 'buffered');
1279
- if(!buffered){return;}
1280
- var bufferString = "";
1281
- for(var i = 0, len = buffered.length; i < len;i++){
1282
- bufferString += buffered.end(i);
1283
- }
1284
- return bufferString;
1285
- };
1286
- var testBuffer = function(){
1287
- var buffered = getBufferedString();
1288
- if(buffered != lastBuffered){
1289
- lastBuffered = buffered;
1290
- $(elem).triggerHandler('progress');
1291
- }
1292
- };
1293
-
1294
- $(this)
1295
- .bind('play loadstart progress', function(e){
1296
- if(e.type == 'progress'){
1297
- lastBuffered = getBufferedString();
1298
- }
1299
- clearTimeout(bufferTimer);
1300
- bufferTimer = setTimeout(testBuffer, 999);
1301
- })
1302
- .bind('emptied stalled mediaerror abort suspend', function(e){
1303
- if(e.type == 'emptied'){
1304
- lastBuffered = false;
1305
- }
1306
- clearTimeout(bufferTimer);
1307
- })
1308
- ;
1309
- }
1310
-
1311
- })
1312
- ;
1313
- });
1314
- };
1315
-
1316
- if(Modernizr.track && !bugs.track){
1317
- webshims.defineProperty(TextTrack.prototype, 'shimActiveCues', {
1318
- get: function(){
1319
- return this._shimActiveCues || this.activeCues;
1320
- }
1321
- });
1322
- }
1323
- //set native implementation ready, before swf api is retested
1324
- if(hasNative){
1325
- webshims.isReady('mediaelement-core', true);
1326
- initMediaElements();
1327
- webshims.ready('WINDOWLOAD mediaelement', loadThird);
1328
- } else {
1329
- webshims.ready('mediaelement-swf', initMediaElements);
1330
- }
1331
- $(function(){
1332
- webshims.loader.loadList(['track-ui']);
1333
- });
1334
-
1335
- });
1336
- })(jQuery, Modernizr, jQuery.webshims);/*
1337
- * todos:
1338
- * - decouple muted/volume (needs improvement)
1339
- * - implement video <-> flashcanvas pro API
1340
- * - improve buffered-property with youtube/rtmp
1341
- * - use jwplayer5 api instead of old flash4 api
1342
- */
1343
-
1344
- jQuery.webshims.register('mediaelement-swf', function($, webshims, window, document, undefined, options){
1345
- "use strict";
1346
- var SENDEVENT = 'sendEvent';
1347
- var mediaelement = webshims.mediaelement;
1348
- var swfobject = window.swfobject;
1349
- var hasNative = Modernizr.audio && Modernizr.video;
1350
- var hasFlash = swfobject.hasFlashPlayerVersion('9.0.115');
1351
- var loadedSwf = 0;
1352
- var getProps = {
1353
- paused: true,
1354
- ended: false,
1355
- currentSrc: '',
1356
- duration: window.NaN,
1357
-
1358
- readyState: 0,
1359
- networkState: 0,
1360
- videoHeight: 0,
1361
- videoWidth: 0,
1362
- error: null,
1363
- buffered: {
1364
- start: function(index){
1365
- if(index){
1366
- webshims.error('buffered index size error');
1367
- return;
1368
- }
1369
- return 0;
1370
- },
1371
- end: function(index){
1372
- if(index){
1373
- webshims.error('buffered index size error');
1374
- return;
1375
- }
1376
- return 0;
1377
- },
1378
- length: 0
1379
- }
1380
- };
1381
- var getPropKeys = Object.keys(getProps);
1382
-
1383
- var getSetProps = {
1384
- currentTime: 0,
1385
- volume: 1,
1386
- muted: false
1387
- };
1388
- var getSetPropKeys = Object.keys(getSetProps);
1389
-
1390
- var playerStateObj = $.extend({
1391
- isActive: 'html5',
1392
- activating: 'html5',
1393
- wasSwfReady: false,
1394
- _bufferedEnd: 0,
1395
- _bufferedStart: 0,
1396
- _metadata: false,
1397
- _durationCalcs: -1,
1398
- _callMeta: false,
1399
- currentTime: 0,
1400
- _ppFlag: undefined
1401
- }, getProps, getSetProps);
1402
-
1403
- var idRep = /^jwplayer-/;
1404
- var getSwfDataFromID = function(id){
1405
-
1406
- var elem = document.getElementById(id.replace(idRep, ''));
1407
- if(!elem){return;}
1408
- var data = webshims.data(elem, 'mediaelement');
1409
- return data.isActive == 'third' ? data : null;
1410
- };
1411
-
1412
-
1413
- var getSwfDataFromElem = function(elem){
1414
- try {
1415
- (elem.nodeName);
1416
- } catch(er){
1417
- return null;
1418
- }
1419
- var data = webshims.data(elem, 'mediaelement');
1420
- return (data && data.isActive== 'third') ? data : null;
1421
- };
1422
-
1423
- var trigger = function(elem, evt){
1424
- evt = $.Event(evt);
1425
- evt.preventDefault();
1426
- $.event.trigger(evt, undefined, elem);
1427
- };
1428
-
1429
- var playerSwfPath = options.playerPath || webshims.cfg.basePath + "jwplayer/" + (options.playerName || "player.swf");
1430
- var jwplugin = options.pluginPath || webshims.cfg.basePath +'swf/jwwebshims.swf';
1431
-
1432
- webshims.extendUNDEFProp(options.jwParams, {
1433
- allowscriptaccess: 'always',
1434
- allowfullscreen: 'true',
1435
- wmode: 'transparent'
1436
- });
1437
- webshims.extendUNDEFProp(options.jwVars, {
1438
- screencolor: 'ffffffff'
1439
- });
1440
- webshims.extendUNDEFProp(options.jwAttrs, {
1441
- bgcolor: '#000000'
1442
- });
1443
-
1444
- var getDuration = function(data, obj){
1445
- var curDuration = data.duration;
1446
- if(curDuration && data._durationCalcs > 0){return;}
1447
- try {
1448
- data.duration = data.jwapi.getPlaylist()[0].duration;
1449
- if(!data.duration || data.duration <= 0 || data.duration === data._lastDuration){
1450
- data.duration = curDuration;
1451
- }
1452
- } catch(er){}
1453
- if(data.duration && data.duration != data._lastDuration){
1454
- trigger(data._elem, 'durationchange');
1455
- if(data._elemNodeName == 'audio' || data._callMeta){
1456
- mediaelement.jwEvents.Model.META($.extend({duration: data.duration}, obj), data);
1457
- }
1458
- data._durationCalcs--;
1459
- } else {
1460
- data._durationCalcs++;
1461
- }
1462
- };
1463
- var setReadyState = function(readyState, data){
1464
- if(readyState < 3){
1465
- clearTimeout(data._canplaythroughTimer);
1466
- }
1467
- if(readyState >= 3 && data.readyState < 3){
1468
- data.readyState = readyState;
1469
- trigger(data._elem, 'canplay');
1470
- clearTimeout(data._canplaythroughTimer);
1471
- data._canplaythroughTimer = setTimeout(function(){
1472
- setReadyState(4, data);
1473
- }, 4000);
1474
- }
1475
- if(readyState >= 4 && data.readyState < 4){
1476
- data.readyState = readyState;
1477
- trigger(data._elem, 'canplaythrough');
1478
- }
1479
- data.readyState = readyState;
1480
- };
1481
-
1482
- $.extend($.event.customEvent, {
1483
- updatemediaelementdimensions: true,
1484
- flashblocker: true,
1485
- swfstageresize: true,
1486
- mediaelementapichange: true
1487
- });
1488
-
1489
- mediaelement.jwEvents = {
1490
- View: {
1491
-
1492
- PLAY: function(obj){
1493
- var data = getSwfDataFromID(obj.id);
1494
- if(!data || data.stopPlayPause){return;}
1495
- data._ppFlag = true;
1496
- if(data.paused == obj.state){
1497
- data.paused = !obj.state;
1498
- if(data.ended){
1499
- data.ended = false;
1500
- }
1501
- trigger(data._elem, obj.state ? 'play' : 'pause');
1502
- }
1503
- }
1504
- },
1505
- Model: {
1506
-
1507
- BUFFER: function(obj){
1508
- var data = getSwfDataFromID(obj.id);
1509
- if(!data || !('percentage' in obj) || data._bufferedEnd == obj.percentage){return;}
1510
- data.networkState = (obj.percentage == 100) ? 1 : 2;
1511
- if(isNaN(data.duration) || (obj.percentage > 5 && obj.percentage < 25) || (obj.percentage === 100)){
1512
- getDuration(data, obj);
1513
- }
1514
-
1515
- if(data.ended){
1516
- data.ended = false;
1517
- }
1518
- if(!data.duration){
1519
- return;
1520
- }
1521
- if(obj.percentage > 2 && obj.percentage < 20){
1522
- setReadyState(3, data);
1523
- } else if(obj.percentage > 20){
1524
- setReadyState(4, data);
1525
- }
1526
- if(data._bufferedEnd && (data._bufferedEnd > obj.percentage)){
1527
- data._bufferedStart = data.currentTime || 0;
1528
- }
1529
-
1530
- data._bufferedEnd = obj.percentage;
1531
- data.buffered.length = 1;
1532
- if(obj.percentage == 100){
1533
- data.networkState = 1;
1534
- setReadyState(4, data);
1535
- }
1536
- $.event.trigger('progress', undefined, data._elem, true);
1537
- },
1538
- META: function(obj, data){
1539
-
1540
- data = data && data.networkState ? data : getSwfDataFromID(obj.id);
1541
-
1542
- if(!data){return;}
1543
- if( !('duration' in obj) ){
1544
- data._callMeta = true;
1545
- return;
1546
- }
1547
-
1548
- if( data._metadata && (!obj.height || data.videoHeight == obj.height) && (obj.duration === data.duration) ){return;}
1549
-
1550
- data._metadata = true;
1551
-
1552
- var oldDur = data.duration;
1553
- if(obj.duration){
1554
- data.duration = obj.duration;
1555
- }
1556
- data._lastDuration = data.duration;
1557
- if(obj.height || obj.width){
1558
- data.videoHeight = obj.height || 0;
1559
- data.videoWidth = obj.width || 0;
1560
- }
1561
- if(!data.networkState){
1562
- data.networkState = 2;
1563
- }
1564
- if(data.readyState < 1){
1565
- setReadyState(1, data);
1566
- }
1567
- if(data.duration && oldDur !== data.duration){
1568
- trigger(data._elem, 'durationchange');
1569
- }
1570
-
1571
- trigger(data._elem, 'loadedmetadata');
1572
- },
1573
- TIME: function(obj){
1574
- var data = getSwfDataFromID(obj.id);
1575
- if(!data || data.currentTime === obj.position){return;}
1576
- data.currentTime = obj.position;
1577
- if(data.duration && data.duration < data.currentTime){
1578
- getDuration(data, obj);
1579
- }
1580
- if(data.readyState < 2){
1581
- setReadyState(2, data);
1582
- }
1583
- if(data.ended){
1584
- data.ended = false;
1585
- }
1586
- trigger(data._elem, 'timeupdate');
1587
-
1588
- },
1589
- STATE: function(obj){
1590
- var data = getSwfDataFromID(obj.id);
1591
- if(!data){return;}
1592
- switch(obj.newstate) {
1593
- case 'BUFFERING':
1594
-
1595
- if(data.ended){
1596
- data.ended = false;
1597
- }
1598
- setReadyState(1, data);
1599
- trigger(data._elem, 'waiting');
1600
- break;
1601
- case 'PLAYING':
1602
- data.paused = false;
1603
- data._ppFlag = true;
1604
- if(!data.duration){
1605
- getDuration(data, obj);
1606
- }
1607
- if(data.readyState < 3){
1608
- setReadyState(3, data);
1609
- }
1610
- if(data.ended){
1611
- data.ended = false;
1612
- }
1613
- trigger(data._elem, 'playing');
1614
- break;
1615
- case 'PAUSED':
1616
- if(!data.paused && !data.stopPlayPause){
1617
- data.paused = true;
1618
- data._ppFlag = true;
1619
- trigger(data._elem, 'pause');
1620
- }
1621
- break;
1622
- case 'COMPLETED':
1623
- if(data.readyState < 4){
1624
- setReadyState(4, data);
1625
- }
1626
- data.ended = true;
1627
- trigger(data._elem, 'ended');
1628
- break;
1629
- }
1630
- }
1631
- }
1632
- ,Controller: {
1633
-
1634
- ERROR: function(obj){
1635
- var data = getSwfDataFromID(obj.id);
1636
- if(!data){return;}
1637
- mediaelement.setError(data._elem, obj.message);
1638
- },
1639
- SEEK: function(obj){
1640
- var data = getSwfDataFromID(obj.id);
1641
- if(!data){return;}
1642
- if(data.ended){
1643
- data.ended = false;
1644
- }
1645
- if(data.paused){
1646
- try {
1647
- data.jwapi[SENDEVENT]('play', 'false');
1648
- } catch(er){}
1649
- }
1650
- if(data.currentTime != obj.position){
1651
- data.currentTime = obj.position;
1652
- trigger(data._elem, 'timeupdate');
1653
- }
1654
-
1655
-
1656
- },
1657
- VOLUME: function(obj){
1658
- var data = getSwfDataFromID(obj.id);
1659
- if(!data){return;}
1660
- var newVolume = obj.percentage / 100;
1661
- if(data.volume == newVolume){return;}
1662
- data.volume = newVolume;
1663
- trigger(data._elem, 'volumechange');
1664
- },
1665
- MUTE: function(obj){
1666
- if(obj.state){return;}
1667
- var data = getSwfDataFromID(obj.id);
1668
- if(!data){return;}
1669
- if(data.muted == obj.state){return;}
1670
- data.muted = obj.state;
1671
- trigger(data._elem, 'volumechange');
1672
- }
1673
- }
1674
- };
1675
-
1676
- var initEvents = function(data){
1677
- var passed = true;
1678
- $.each(mediaelement.jwEvents, function(mvcName, evts){
1679
- $.each(evts, function(evtName){
1680
- try {
1681
- data.jwapi['add'+ mvcName +'Listener'](evtName, 'jQuery.webshims.mediaelement.jwEvents.'+ mvcName +'.'+ evtName);
1682
- } catch(er){
1683
- passed = false;
1684
- return false;
1685
- }
1686
- });
1687
- });
1688
- return passed;
1689
- };
1690
-
1691
- var workActionQueue = function(data){
1692
- var actionLen = data.actionQueue.length;
1693
- var i = 0;
1694
- var operation;
1695
- if(actionLen && data.isActive == 'third'){
1696
- while(data.actionQueue.length && actionLen > i){
1697
- i++;
1698
- operation = data.actionQueue.shift();
1699
- data.jwapi[operation.fn].apply(data.jwapi, operation.args);
1700
- }
1701
- }
1702
- if(data.actionQueue.length){
1703
- data.actionQueue = [];
1704
- }
1705
- };
1706
- var startAutoPlay = function(data){
1707
- if(!data){return;}
1708
- if( (data._ppFlag === undefined && ($.prop(data._elem, 'autoplay')) || !data.paused)){
1709
- setTimeout(function(){
1710
- if(data.isActive == 'third' && (data._ppFlag === undefined || !data.paused)){
1711
- try {
1712
- $(data._elem).play();
1713
- } catch(er){}
1714
- }
1715
- }, 1);
1716
- }
1717
- };
1718
-
1719
- var startIntrinsicDimension = function(data){
1720
- if(!data || data._elemNodeName != 'video'){return;}
1721
- var img;
1722
- var widthAuto;
1723
- var heightAuto;
1724
- var lastIntrinsicSize = {};
1725
- var shadowElem;
1726
- var errorTimer;
1727
- var blockResize;
1728
- var lastSize;
1729
- var setSize = function(width, height){
1730
- if(!height || !width || height < 1 || width < 1 || data.isActive != 'third'){return;}
1731
- if(img){
1732
- img.remove();
1733
- img = false;
1734
- }
1735
- lastIntrinsicSize.width = width;
1736
- lastIntrinsicSize.height = height;
1737
- clearTimeout(errorTimer);
1738
- widthAuto = data._elem.style.width == 'auto';
1739
- heightAuto = data._elem.style.height == 'auto';
1740
-
1741
- if(!widthAuto && !heightAuto){return;}
1742
- var curSize;
1743
- shadowElem = shadowElem || $(data._elem).getShadowElement();
1744
- var cur;
1745
- if(widthAuto && !heightAuto){
1746
- cur = shadowElem.height();
1747
- width *= cur / height;
1748
- height = cur;
1749
- } else if(!widthAuto && heightAuto){
1750
- cur = shadowElem.width();
1751
- height *= cur / width;
1752
- width = cur;
1753
- }
1754
- blockResize = true;
1755
- setTimeout(function(){
1756
- blockResize = false;
1757
- }, 9);
1758
-
1759
- shadowElem.css({width: width, height: height});
1760
- };
1761
- var setPosterSrc = function(){
1762
- if(data.isActive != 'third' || ($.prop(data._elem, 'readyState') && $.prop(this, 'videoWidth'))){return;}
1763
- var posterSrc = $.prop(data._elem, 'poster');
1764
- if(!posterSrc){return;}
1765
- widthAuto = data._elem.style.width == 'auto';
1766
- heightAuto = data._elem.style.height == 'auto';
1767
- if(!widthAuto && !heightAuto){return;}
1768
- if(img){
1769
- img.remove();
1770
- img = false;
1771
- }
1772
- img = $('<img style="position: absolute; height: auto; width: auto; top: 0px; left: 0px; visibility: hidden;" />');
1773
- img
1774
- .bind('load error alreadycomplete', function(e){
1775
- clearTimeout(errorTimer);
1776
-
1777
- var elem = this;
1778
- var width = elem.naturalWidth || elem.width || elem.offsetWidth;
1779
- var height = elem.naturalHeight || elem.height || elem.offsetHeight;
1780
-
1781
- if(height && width){
1782
- setSize(width, height);
1783
- elem = null;
1784
- } else {
1785
- setTimeout(function(){
1786
- width = elem.naturalWidth || elem.width || elem.offsetWidth;
1787
- height = elem.naturalHeight || elem.height || elem.offsetHeight;
1788
- setSize(width, height);
1789
- if(img){
1790
- img.remove();
1791
- img = false;
1792
- }
1793
- elem = null;
1794
- }, 9);
1795
- }
1796
- $(this).unbind();
1797
- })
1798
- .prop('src', posterSrc)
1799
- .appendTo('body')
1800
- .each(function(){
1801
- if(this.complete || this.error){
1802
- $(this).triggerHandler('alreadycomplete');
1803
- } else {
1804
- clearTimeout(errorTimer);
1805
- errorTimer = setTimeout(function(){
1806
- $(data._elem).triggerHandler('error');
1807
- }, 9999);
1808
- }
1809
- })
1810
- ;
1811
- };
1812
-
1813
- $(data._elem)
1814
- .bind('loadedmetadata', function(){
1815
- setSize($.prop(this, 'videoWidth'), $.prop(this, 'videoHeight'));
1816
- })
1817
- .bind('emptied', setPosterSrc)
1818
- .bind('swfstageresize updatemediaelementdimensions', function(){
1819
- if(blockResize){return;}
1820
- setSize(lastIntrinsicSize.width, lastIntrinsicSize.height);
1821
- })
1822
- .bind('emptied', function(){
1823
- lastIntrinsicSize = {};
1824
- })
1825
- .triggerHandler('swfstageresize')
1826
- ;
1827
-
1828
- setPosterSrc();
1829
- if($.prop(data._elem, 'readyState')){
1830
- setSize($.prop(data._elem, 'videoWidth'), $.prop(data._elem, 'videoHeight'));
1831
- }
1832
- };
1833
-
1834
- mediaelement.playerResize = function(id){
1835
- if(!id){return;}
1836
- var elem = document.getElementById(id.replace(idRep, ''));
1837
-
1838
- if(elem){
1839
- $(elem).triggerHandler('swfstageresize');
1840
- }
1841
- elem = null;
1842
- };
1843
-
1844
-
1845
- $(document).bind('emptied', function(e){
1846
- var data = getSwfDataFromElem(e.target);
1847
- startAutoPlay(data);
1848
- });
1849
-
1850
- var localConnectionTimer;
1851
- mediaelement.jwPlayerReady = function(jwData){
1852
- var data = getSwfDataFromID(jwData.id);
1853
- var passed = true;
1854
- var i = 0;
1855
- var doneFn = function(){
1856
- if(i > 9){return;}
1857
- i++;
1858
- if(initEvents(data)){
1859
- if(!data.wasSwfReady){
1860
- var version = parseFloat( jwData.version, 10);
1861
- if(version < 5.1 || version >= 6){
1862
- webshims.warn('mediaelement-swf is only testet with jwplayer 5.6+');
1863
- }
1864
- } else {
1865
- $(data._elem).mediaLoad();
1866
-
1867
- }
1868
- data.wasSwfReady = true;
1869
- data.tryedReframeing = 0;
1870
- workActionQueue(data);
1871
- startAutoPlay(data);
1872
- } else {
1873
- clearTimeout(data.reframeTimer);
1874
- data.reframeTimer = setTimeout(doneFn, 9 * i);
1875
- if(i > 2 && data.tryedReframeing < 9){
1876
- data.tryedReframeing++;
1877
- data.shadowElem.css({overflow: 'visible'});
1878
- setTimeout(function(){
1879
- data.shadowElem.css({overflow: 'hidden'});
1880
- }, 16);
1881
- }
1882
- }
1883
- };
1884
- if(!data || !data.jwapi){return;}
1885
- if(!data.tryedReframeing){
1886
- data.tryedReframeing = 0;
1887
- }
1888
- clearTimeout(localConnectionTimer);
1889
- data.jwData = jwData;
1890
- data.shadowElem.removeClass('flashblocker-assumed');
1891
- $.prop(data._elem, 'volume', data.volume);
1892
- $.prop(data._elem, 'muted', data.muted);
1893
- doneFn();
1894
-
1895
- };
1896
-
1897
- var addMediaToStopEvents = $.noop;
1898
- if(hasNative){
1899
- var stopEvents = {
1900
- play: 1,
1901
- playing: 1
1902
- };
1903
- var hideEvtArray = ['play', 'pause', 'playing', 'canplay', 'progress', 'waiting', 'ended', 'loadedmetadata', 'durationchange', 'emptied'];
1904
- var hidevents = hideEvtArray.map(function(evt){
1905
- return evt +'.webshimspolyfill';
1906
- }).join(' ');
1907
-
1908
- var hidePlayerEvents = function(event){
1909
- var data = webshims.data(event.target, 'mediaelement');
1910
- if(!data){return;}
1911
- var isNativeHTML5 = ( event.originalEvent && event.originalEvent.type === event.type );
1912
- if( isNativeHTML5 == (data.activating == 'third') ){
1913
- event.stopImmediatePropagation();
1914
- if(stopEvents[event.type] && data.isActive != data.activating){
1915
- $(event.target).pause();
1916
- }
1917
- }
1918
- };
1919
-
1920
- addMediaToStopEvents = function(elem){
1921
- $(elem)
1922
- .unbind(hidevents)
1923
- .bind(hidevents, hidePlayerEvents)
1924
- ;
1925
- hideEvtArray.forEach(function(evt){
1926
- webshims.moveToFirstEvent(elem, evt);
1927
- });
1928
- };
1929
- addMediaToStopEvents(document);
1930
- }
1931
-
1932
-
1933
- mediaelement.setActive = function(elem, type, data){
1934
- if(!data){
1935
- data = webshims.data(elem, 'mediaelement');
1936
- }
1937
- if(!data || data.isActive == type){return;}
1938
- if(type != 'html5' && type != 'third'){
1939
- webshims.warn('wrong type for mediaelement activating: '+ type);
1940
- }
1941
- var shadowData = webshims.data(elem, 'shadowData');
1942
- data.activating = type;
1943
- $(elem).pause();
1944
- data.isActive = type;
1945
- if(type == 'third'){
1946
- shadowData.shadowElement = shadowData.shadowFocusElement = data.shadowElem[0];
1947
- $(elem).addClass('swf-api-active nonnative-api-active').hide().getShadowElement().show();
1948
- } else {
1949
- $(elem).removeClass('swf-api-active nonnative-api-active').show().getShadowElement().hide();
1950
- shadowData.shadowElement = shadowData.shadowFocusElement = false;
1951
- }
1952
- $(elem).trigger('mediaelementapichange');
1953
- };
1954
-
1955
-
1956
-
1957
- var resetSwfProps = (function(){
1958
- var resetProtoProps = ['_bufferedEnd', '_bufferedStart', '_metadata', '_ppFlag', 'currentSrc', 'currentTime', 'duration', 'ended', 'networkState', 'paused', 'videoHeight', 'videoWidth', '_callMeta', '_durationCalcs'];
1959
- var len = resetProtoProps.length;
1960
- return function(data){
1961
-
1962
- if(!data){return;}
1963
- var lenI = len;
1964
- var networkState = data.networkState;
1965
- setReadyState(0, data);
1966
- while(--lenI){
1967
- delete data[resetProtoProps[lenI]];
1968
- }
1969
- data.actionQueue = [];
1970
- data.buffered.length = 0;
1971
- if(networkState){
1972
- trigger(data._elem, 'emptied');
1973
- }
1974
- };
1975
- })();
1976
-
1977
- var setElementDimension = function(data, hasControls){
1978
- var elem = data._elem;
1979
- var box = data.shadowElem;
1980
- $(elem)[hasControls ? 'addClass' : 'removeClass']('webshims-controls');
1981
- if(data._elemNodeName == 'audio' && !hasControls){
1982
- box.css({width: 0, height: 0});
1983
- } else {
1984
- box.css({
1985
- width: elem.style.width || $(elem).width(),
1986
- height: elem.style.height || $(elem).height()
1987
- });
1988
- }
1989
- };
1990
-
1991
- mediaelement.createSWF = function( elem, canPlaySrc, data ){
1992
- if(!hasFlash){
1993
- setTimeout(function(){
1994
- $(elem).mediaLoad(); //<- this should produce a mediaerror
1995
- }, 1);
1996
- return;
1997
- }
1998
-
1999
- if(loadedSwf < 1){
2000
- loadedSwf = 1;
2001
- } else {
2002
- loadedSwf++;
2003
- }
2004
- var vars = $.extend({}, options.jwVars, {
2005
- image: $.prop(elem, 'poster') || '',
2006
- file: canPlaySrc.srcProp
2007
- });
2008
- var elemVars = $(elem).data('jwvars') || {};
2009
-
2010
- if(!data){
2011
- data = webshims.data(elem, 'mediaelement');
2012
- }
2013
-
2014
- if(data && data.swfCreated){
2015
- mediaelement.setActive(elem, 'third', data);
2016
- resetSwfProps(data);
2017
- data.currentSrc = canPlaySrc.srcProp;
2018
- $.extend(vars, elemVars);
2019
- options.changeJW(vars, elem, canPlaySrc, data, 'load');
2020
- queueSwfMethod(elem, SENDEVENT, ['LOAD', vars]);
2021
- return;
2022
- }
2023
-
2024
-
2025
- var hasControls = $.prop(elem, 'controls');
2026
- var elemId = 'jwplayer-'+ webshims.getID(elem);
2027
- var params = $.extend(
2028
- {},
2029
- options.jwParams,
2030
- $(elem).data('jwparams')
2031
- );
2032
- var elemNodeName = elem.nodeName.toLowerCase();
2033
- var attrs = $.extend(
2034
- {},
2035
- options.jwAttrs,
2036
- {
2037
- name: elemId,
2038
- id: elemId
2039
- },
2040
- $(elem).data('jwattrs')
2041
- );
2042
- var box = $('<div class="polyfill-'+ (elemNodeName) +' polyfill-mediaelement" id="wrapper-'+ elemId +'"><div id="'+ elemId +'"></div>')
2043
- .css({
2044
- position: 'relative',
2045
- overflow: 'hidden'
2046
- })
2047
- ;
2048
- data = webshims.data(elem, 'mediaelement', webshims.objectCreate(playerStateObj, {
2049
- actionQueue: {
2050
- value: []
2051
- },
2052
- shadowElem: {
2053
- value: box
2054
- },
2055
- _elemNodeName: {
2056
- value: elemNodeName
2057
- },
2058
- _elem: {
2059
- value: elem
2060
- },
2061
- currentSrc: {
2062
- value: canPlaySrc.srcProp
2063
- },
2064
- swfCreated: {
2065
- value: true
2066
- },
2067
- buffered: {
2068
- value: {
2069
- start: function(index){
2070
- if(index >= data.buffered.length){
2071
- webshims.error('buffered index size error');
2072
- return;
2073
- }
2074
- return 0;
2075
- },
2076
- end: function(index){
2077
- if(index >= data.buffered.length){
2078
- webshims.error('buffered index size error');
2079
- return;
2080
- }
2081
- return ( (data.duration - data._bufferedStart) * data._bufferedEnd / 100) + data._bufferedStart;
2082
- },
2083
- length: 0
2084
- }
2085
- }
2086
- }));
2087
-
2088
- setElementDimension(data, hasControls);
2089
-
2090
- box.insertBefore(elem);
2091
-
2092
- if(hasNative){
2093
- $.extend(data, {volume: $.prop(elem, 'volume'), muted: $.prop(elem, 'muted')});
2094
- }
2095
-
2096
- $.extend(vars,
2097
- {
2098
- id: elemId,
2099
- controlbar: hasControls ? options.jwVars.controlbar || (elemNodeName == 'video' ? 'over' : 'bottom') : (elemNodeName == 'video') ? 'none' : 'bottom',
2100
- icons: ''+ (hasControls && elemNodeName == 'video')
2101
- },
2102
- elemVars,
2103
- {playerready: 'jQuery.webshims.mediaelement.jwPlayerReady'}
2104
- );
2105
- if(vars.plugins){
2106
- vars.plugins += ','+jwplugin;
2107
- } else {
2108
- vars.plugins = jwplugin;
2109
- }
2110
-
2111
-
2112
- webshims.addShadowDom(elem, box);
2113
-
2114
- addMediaToStopEvents(elem);
2115
-
2116
- mediaelement.setActive(elem, 'third', data);
2117
-
2118
- options.changeJW(vars, elem, canPlaySrc, data, 'embed');
2119
-
2120
- $(elem).bind('updatemediaelementdimensions updateshadowdom', function(){
2121
- setElementDimension(data, $.prop(elem, 'controls'));
2122
- });
2123
-
2124
- startIntrinsicDimension(data);
2125
-
2126
- swfobject.embedSWF(playerSwfPath, elemId, "100%", "100%", "9.0.0", false, vars, params, attrs, function(swfData){
2127
-
2128
- if(swfData.success){
2129
- data.jwapi = swfData.ref;
2130
-
2131
- if(!hasControls){
2132
- $(swfData.ref).attr('tabindex', '-1').css('outline', 'none');
2133
- }
2134
- setTimeout(function(){
2135
- if((!swfData.ref.parentNode && box[0].parentNode) || swfData.ref.style.display == "none"){
2136
- box.addClass('flashblocker-assumed');
2137
- $(elem).trigger('flashblocker');
2138
- webshims.warn("flashblocker assumed");
2139
- }
2140
- $(swfData.ref).css({'minHeight': '2px', 'minWidth': '2px', display: 'block'});
2141
- }, 9);
2142
- if(!localConnectionTimer){
2143
- clearTimeout(localConnectionTimer);
2144
- localConnectionTimer = setTimeout(function(){
2145
- var flash = $(swfData.ref);
2146
- if(flash[0].offsetWidth > 1 && flash[0].offsetHeight > 1 && location.protocol.indexOf('file:') === 0){
2147
- webshims.error("Add your local development-directory to the local-trusted security sandbox: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html");
2148
- } else if(flash[0].offsetWidth < 2 || flash[0].offsetHeight < 2) {
2149
- webshims.warn("JS-SWF connection can't be established on hidden or unconnected flash objects");
2150
- }
2151
- flash = null;
2152
- }, 8000);
2153
- }
2154
- }
2155
- });
2156
- };
2157
-
2158
-
2159
- var queueSwfMethod = function(elem, fn, args, data){
2160
- data = data || getSwfDataFromElem(elem);
2161
- if(data){
2162
- if(data.jwapi && data.jwapi[fn]){
2163
- data.jwapi[fn].apply(data.jwapi, args || []);
2164
- } else {
2165
- //todo add to queue
2166
- data.actionQueue.push({fn: fn, args: args});
2167
- if(data.actionQueue.length > 10){
2168
- setTimeout(function(){
2169
- if(data.actionQueue.length > 5){
2170
- data.actionQueue.shift();
2171
- }
2172
- }, 99);
2173
- }
2174
- }
2175
- return data;
2176
- }
2177
- return false;
2178
- };
2179
-
2180
- ['audio', 'video'].forEach(function(nodeName){
2181
- var descs = {};
2182
- var mediaSup;
2183
- var createGetProp = function(key){
2184
- if(nodeName == 'audio' && (key == 'videoHeight' || key == 'videoWidth')){return;}
2185
-
2186
- descs[key] = {
2187
- get: function(){
2188
- var data = getSwfDataFromElem(this);
2189
- if(data){
2190
- return data[key];
2191
- } else if(hasNative && mediaSup[key].prop._supget) {
2192
- return mediaSup[key].prop._supget.apply(this);
2193
- } else {
2194
- return playerStateObj[key];
2195
- }
2196
- },
2197
- writeable: false
2198
- };
2199
- };
2200
- var createGetSetProp = function(key, setFn){
2201
- createGetProp(key);
2202
- delete descs[key].writeable;
2203
- descs[key].set = setFn;
2204
- };
2205
-
2206
- createGetSetProp('volume', function(v){
2207
- var data = getSwfDataFromElem(this);
2208
- if(data){
2209
- v *= 100;
2210
- if(!isNaN(v)){
2211
- var muted = data.muted;
2212
- if(v < 0 || v > 100){
2213
- webshims.error('volume greater or less than allowed '+ (v / 100));
2214
- }
2215
-
2216
- queueSwfMethod(this, SENDEVENT, ['VOLUME', v], data);
2217
- if(muted){
2218
- try {
2219
- data.jwapi.sendEvent('mute', 'true');
2220
- } catch(er){}
2221
- }
2222
- v /= 100;
2223
- if(data.volume == v || data.isActive != 'third'){return;}
2224
- data.volume = v;
2225
- trigger(data._elem, 'volumechange');
2226
- data = null;
2227
- }
2228
- } else if(mediaSup.volume.prop._supset) {
2229
- return mediaSup.volume.prop._supset.apply(this, arguments);
2230
- }
2231
- });
2232
-
2233
- createGetSetProp('muted', function(m){
2234
- var data = getSwfDataFromElem(this);
2235
- if(data){
2236
- m = !!m;
2237
- queueSwfMethod(this, SENDEVENT, ['mute', ''+m], data);
2238
- if(data.muted == m || data.isActive != 'third'){return;}
2239
- data.muted = m;
2240
- trigger(data._elem, 'volumechange');
2241
- data = null;
2242
- } else if(mediaSup.muted.prop._supset) {
2243
- return mediaSup.muted.prop._supset.apply(this, arguments);
2244
- }
2245
- });
2246
-
2247
-
2248
- createGetSetProp('currentTime', function(t){
2249
- var data = getSwfDataFromElem(this);
2250
- if(data){
2251
- t *= 1;
2252
- if (!isNaN(t)) {
2253
- if(data.paused){
2254
- clearTimeout(data.stopPlayPause);
2255
- data.stopPlayPause = setTimeout(function(){
2256
- data.paused = true;
2257
- data.stopPlayPause = false;
2258
- }, 50);
2259
- }
2260
- queueSwfMethod(this, SENDEVENT, ['SEEK', '' + t], data);
2261
-
2262
- if(data.paused){
2263
- if(data.readyState > 0){
2264
- data.currentTime = t;
2265
- trigger(data._elem, 'timeupdate');
2266
- }
2267
- try {
2268
- data.jwapi[SENDEVENT]('play', 'false');
2269
- } catch(er){}
2270
-
2271
- }
2272
- }
2273
-
2274
- } else if(mediaSup.currentTime.prop._supset) {
2275
- return mediaSup.currentTime.prop._supset.apply(this, arguments);
2276
- }
2277
- });
2278
-
2279
- ['play', 'pause'].forEach(function(fn){
2280
- descs[fn] = {
2281
- value: function(){
2282
- var data = getSwfDataFromElem(this);
2283
- if(data){
2284
- if(data.stopPlayPause){
2285
- clearTimeout(data.stopPlayPause);
2286
- }
2287
- queueSwfMethod(this, SENDEVENT, ['play', fn == 'play'], data);
2288
- setTimeout(function(){
2289
- if(data.isActive == 'third'){
2290
- data._ppFlag = true;
2291
- if(data.paused != (fn != 'play')){
2292
- data.paused = fn != 'play';
2293
- trigger(data._elem, fn);
2294
- }
2295
- }
2296
- }, 1);
2297
- } else if(mediaSup[fn].prop._supvalue) {
2298
- return mediaSup[fn].prop._supvalue.apply(this, arguments);
2299
- }
2300
- }
2301
- };
2302
- });
2303
-
2304
- getPropKeys.forEach(createGetProp);
2305
-
2306
- webshims.onNodeNamesPropertyModify(nodeName, 'controls', function(val, boolProp){
2307
- var data = getSwfDataFromElem(this);
2308
- $(this)[boolProp ? 'addClass' : 'removeClass']('webshims-controls');
2309
-
2310
- if(data){
2311
- try {
2312
- queueSwfMethod(this, boolProp ? 'showControls' : 'hideControls', [nodeName], data);
2313
- } catch(er){
2314
- webshims.warn("you need to generate a crossdomain.xml");
2315
- }
2316
- if(nodeName == 'audio'){
2317
- setElementDimension(data, boolProp);
2318
- }
2319
- $(data.jwapi).attr('tabindex', boolProp ? '0' : '-1');
2320
- }
2321
- });
2322
-
2323
- mediaSup = webshims.defineNodeNameProperties(nodeName, descs, 'prop');
2324
- });
2325
-
2326
- if(hasFlash){
2327
- var oldClean = $.cleanData;
2328
- var gcBrowser = $.browser.msie && webshims.browserVersion < 9;
2329
- var flashNames = {
2330
- object: 1,
2331
- OBJECT: 1
2332
- };
2333
- $.cleanData = function(elems){
2334
- var i, len, prop;
2335
- if(elems && (len = elems.length) && loadedSwf){
2336
-
2337
- for(i = 0; i < len; i++){
2338
- if(flashNames[elems[i].nodeName]){
2339
- if(SENDEVENT in elems[i]){
2340
- loadedSwf--;
2341
- try {
2342
- elems[i][SENDEVENT]('play', false);
2343
- } catch(er){}
2344
- }
2345
- if(gcBrowser){
2346
- try {
2347
- for (prop in elems[i]) {
2348
- if (typeof elems[i][prop] == "function") {
2349
- elems[i][prop] = null;
2350
- }
2351
- }
2352
- } catch(er){}
2353
- }
2354
- }
2355
- }
2356
-
2357
- }
2358
- return oldClean.apply(this, arguments);
2359
- };
2360
- }
2361
-
2362
- if(!hasNative){
2363
-
2364
- ['poster', 'src'].forEach(function(prop){
2365
- webshims.defineNodeNamesProperty(prop == 'src' ? ['audio', 'video', 'source'] : ['video'], prop, {
2366
- //attr: {},
2367
- reflect: true,
2368
- propType: 'src'
2369
- });
2370
- });
2371
-
2372
-
2373
- ['autoplay', 'controls'].forEach(function(name){
2374
- webshims.defineNodeNamesBooleanProperty(['audio', 'video'], name);
2375
- });
2376
-
2377
- webshims.defineNodeNamesProperties(['audio', 'video'], {
2378
- HAVE_CURRENT_DATA: {
2379
- value: 2
2380
- },
2381
- HAVE_ENOUGH_DATA: {
2382
- value: 4
2383
- },
2384
- HAVE_FUTURE_DATA: {
2385
- value: 3
2386
- },
2387
- HAVE_METADATA: {
2388
- value: 1
2389
- },
2390
- HAVE_NOTHING: {
2391
- value: 0
2392
- },
2393
- NETWORK_EMPTY: {
2394
- value: 0
2395
- },
2396
- NETWORK_IDLE: {
2397
- value: 1
2398
- },
2399
- NETWORK_LOADING: {
2400
- value: 2
2401
- },
2402
- NETWORK_NO_SOURCE: {
2403
- value: 3
2404
- }
2405
-
2406
- }, 'prop');
2407
- }
2408
-
1
+ // vim: ts=4 sts=4 sw=4 expandtab
2
+ // -- kriskowal Kris Kowal Copyright (C) 2009-2011 MIT License
3
+ // -- tlrobinson Tom Robinson Copyright (C) 2009-2010 MIT License (Narwhal Project)
4
+ // -- dantman Daniel Friesen Copyright (C) 2010 XXX TODO License or CLA
5
+ // -- fschaefer Florian Schäfer Copyright (C) 2010 MIT License
6
+ // -- Gozala Irakli Gozalishvili Copyright (C) 2010 MIT License
7
+ // -- kitcambridge Kit Cambridge Copyright (C) 2011 MIT License
8
+ // -- kossnocorp Sasha Koss XXX TODO License or CLA
9
+ // -- bryanforbes Bryan Forbes XXX TODO License or CLA
10
+ // -- killdream Quildreen Motta Copyright (C) 2011 MIT Licence
11
+ // -- michaelficarra Michael Ficarra Copyright (C) 2011 3-clause BSD License
12
+ // -- sharkbrainguy Gerard Paapu Copyright (C) 2011 MIT License
13
+ // -- bbqsrc Brendan Molloy XXX TODO License or CLA
14
+ // -- iwyg XXX TODO License or CLA
15
+ // -- DomenicDenicola Domenic Denicola XXX TODO License or CLA
16
+ // -- xavierm02 Montillet Xavier XXX TODO License or CLA
17
+ // -- Raynos Raynos XXX TODO License or CLA
18
+ // -- samsonjs Sami Samhuri XXX TODO License or CLA
19
+ // -- rwldrn Rick Waldron Copyright (C) 2011 MIT License
20
+ // -- lexer Alexey Zakharov XXX TODO License or CLA
21
+
22
+ /*!
23
+ Copyright (c) 2009, 280 North Inc. http://280north.com/
24
+ MIT License. http://github.com/280north/narwhal/blob/master/README.md
25
+ */
26
+
27
+ (function (undefined) {
28
+
29
+ /**
30
+ * Brings an environment as close to ECMAScript 5 compliance
31
+ * as is possible with the facilities of erstwhile engines.
32
+ *
33
+ * ES5 Draft
34
+ * http://www.ecma-international.org/publications/files/drafts/tc39-2009-050.pdf
35
+ *
36
+ * NOTE: this is a draft, and as such, the URL is subject to change. If the
37
+ * link is broken, check in the parent directory for the latest TC39 PDF.
38
+ * http://www.ecma-international.org/publications/files/drafts/
39
+ *
40
+ * Previous ES5 Draft
41
+ * http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
42
+ * This is a broken link to the previous draft of ES5 on which most of the
43
+ * numbered specification references and quotes herein were taken. Updating
44
+ * these references and quotes to reflect the new document would be a welcome
45
+ * volunteer project.
46
+ *
47
+ * @module
48
+ */
49
+
50
+ /*whatsupdoc*/
51
+
52
+ // Shortcut to an often accessed properties, in order to avoid multiple
53
+ // dereference that costs universally.
54
+ // _Please note: Shortcuts are defined after `Function.prototype.bind` as we
55
+ // us it in defining shortcuts.
56
+ var call = Function.prototype.call;
57
+ var prototypeOfArray = Array.prototype;
58
+ var prototypeOfObject = Object.prototype;
59
+ var slice = prototypeOfArray.slice;
60
+ var owns;
61
+ var toString;
62
+
63
+ // ES-5 15.3.4.5
64
+ // http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
65
+
66
+ if (!Function.prototype.bind) {
67
+ Function.prototype.bind = function (that) { // .length is 1
68
+ // 1. Let Target be the this value.
69
+ var target = this;
70
+ // 2. If IsCallable(Target) is false, throw a TypeError exception.
71
+ if (typeof target != "function")
72
+ throw new TypeError(); // TODO message
73
+ // 3. Let A be a new (possibly empty) internal list of all of the
74
+ // argument values provided after thisArg (arg1, arg2 etc), in order.
75
+ // XXX slicedArgs will stand in for "A" if used
76
+ var args = slice.call(arguments, 1); // for normal call
77
+ // 4. Let F be a new native ECMAScript object.
78
+ // 9. Set the [[Prototype]] internal property of F to the standard
79
+ // built-in Function prototype object as specified in 15.3.3.1.
80
+ // 10. Set the [[Call]] internal property of F as described in
81
+ // 15.3.4.5.1.
82
+ // 11. Set the [[Construct]] internal property of F as described in
83
+ // 15.3.4.5.2.
84
+ // 12. Set the [[HasInstance]] internal property of F as described in
85
+ // 15.3.4.5.3.
86
+ // 13. The [[Scope]] internal property of F is unused and need not
87
+ // exist.
88
+ var bound = function () {
89
+
90
+ if (this instanceof bound) {
91
+ // 15.3.4.5.2 [[Construct]]
92
+ // When the [[Construct]] internal method of a function object,
93
+ // F that was created using the bind function is called with a
94
+ // list of arguments ExtraArgs the following steps are taken:
95
+ // 1. Let target be the value of F's [[TargetFunction]]
96
+ // internal property.
97
+ // 2. If target has no [[Construct]] internal method, a
98
+ // TypeError exception is thrown.
99
+ // 3. Let boundArgs be the value of F's [[BoundArgs]] internal
100
+ // property.
101
+ // 4. Let args be a new list containing the same values as the
102
+ // list boundArgs in the same order followed by the same
103
+ // values as the list ExtraArgs in the same order.
104
+
105
+ var F = function(){};
106
+ F.prototype = target.prototype;
107
+ var self = new F;
108
+
109
+ var result = target.apply(
110
+ self,
111
+ args.concat(slice.call(arguments))
112
+ );
113
+ if (result !== null && Object(result) === result)
114
+ return result;
115
+ return self;
116
+
117
+ } else {
118
+ // 15.3.4.5.1 [[Call]]
119
+ // When the [[Call]] internal method of a function object, F,
120
+ // which was created using the bind function is called with a
121
+ // this value and a list of arguments ExtraArgs the following
122
+ // steps are taken:
123
+ // 1. Let boundArgs be the value of F's [[BoundArgs]] internal
124
+ // property.
125
+ // 2. Let boundThis be the value of F's [[BoundThis]] internal
126
+ // property.
127
+ // 3. Let target be the value of F's [[TargetFunction]] internal
128
+ // property.
129
+ // 4. Let args be a new list containing the same values as the list
130
+ // boundArgs in the same order followed by the same values as
131
+ // the list ExtraArgs in the same order. 5. Return the
132
+ // result of calling the [[Call]] internal method of target
133
+ // providing boundThis as the this value and providing args
134
+ // as the arguments.
135
+
136
+ // equiv: target.call(this, ...boundArgs, ...args)
137
+ return target.apply(
138
+ that,
139
+ args.concat(slice.call(arguments))
140
+ );
141
+
142
+ }
143
+
144
+ };
145
+ // XXX bound.length is never writable, so don't even try
146
+ //
147
+ // 16. The length own property of F is given attributes as specified in
148
+ // 15.3.5.1.
149
+ // TODO
150
+ // 17. Set the [[Extensible]] internal property of F to true.
151
+ // TODO
152
+ // 18. Call the [[DefineOwnProperty]] internal method of F with
153
+ // arguments "caller", PropertyDescriptor {[[Value]]: null,
154
+ // [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
155
+ // false}, and false.
156
+ // TODO
157
+ // 19. Call the [[DefineOwnProperty]] internal method of F with
158
+ // arguments "arguments", PropertyDescriptor {[[Value]]: null,
159
+ // [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
160
+ // false}, and false.
161
+ // TODO
162
+ // NOTE Function objects created using Function.prototype.bind do not
163
+ // have a prototype property.
164
+ // XXX can't delete it in pure-js.
165
+ return bound;
166
+ };
167
+ }
168
+
169
+ toString = call.bind(prototypeOfObject.toString);
170
+ owns = call.bind(prototypeOfObject.hasOwnProperty);
171
+
172
+
173
+ //
174
+ // Array
175
+ // =====
176
+ //
177
+
178
+ // ES5 15.4.3.2
179
+ if (!Array.isArray) {
180
+ Array.isArray = function (obj) {
181
+ return toString(obj) == "[object Array]";
182
+ };
183
+ }
184
+
185
+ // The IsCallable() check in the Array functions
186
+ // has been replaced with a strict check on the
187
+ // internal class of the object to trap cases where
188
+ // the provided function was actually a regular
189
+ // expression literal, which in V8 and
190
+ // JavaScriptCore is a typeof "function". Only in
191
+ // V8 are regular expression literals permitted as
192
+ // reduce parameters, so it is desirable in the
193
+ // general case for the shim to match the more
194
+ // strict and common behavior of rejecting regular
195
+ // expressions.
196
+
197
+ // ES5 15.4.4.18
198
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/foreach
199
+ if (!Array.prototype.forEach) {
200
+ Array.prototype.forEach = function (fun /*, thisp*/) {
201
+ var self = toObject(this),
202
+ thisp = arguments[1],
203
+ i = 0,
204
+ length = self.length >>> 0;
205
+
206
+ // If no callback function or if callback is not a callable function
207
+ if (toString(fun) != "[object Function]") {
208
+ throw new TypeError(); // TODO message
209
+ }
210
+
211
+ while (i < length) {
212
+ if (i in self) {
213
+ // Invoke the callback function with call, passing arguments:
214
+ // context, property value, property key, thisArg object context
215
+ fun.call(thisp, self[i], i, self);
216
+ }
217
+ i++;
218
+ }
219
+ };
220
+ }
221
+
222
+ // ES5 15.4.4.19
223
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
224
+ if (!Array.prototype.map) {
225
+ Array.prototype.map = function (fun /*, thisp*/) {
226
+ var self = toObject(this),
227
+ length = self.length >>> 0,
228
+ result = Array(length),
229
+ thisp = arguments[1];
230
+
231
+ // If no callback function or if callback is not a callable function
232
+ if (toString(fun) != "[object Function]") {
233
+ throw new TypeError(); // TODO message
234
+ }
235
+
236
+ for (var i = 0; i < length; i++) {
237
+ if (i in self)
238
+ result[i] = fun.call(thisp, self[i], i, self);
239
+ }
240
+ return result;
241
+ };
242
+ }
243
+
244
+ // ES5 15.4.4.20
245
+ if (!Array.prototype.filter) {
246
+ Array.prototype.filter = function (fun /*, thisp */) {
247
+ var self = toObject(this),
248
+ length = self.length >>> 0,
249
+ result = [],
250
+ thisp = arguments[1];
251
+
252
+ // If no callback function or if callback is not a callable function
253
+ if (toString(fun) != "[object Function]") {
254
+ throw new TypeError(); // TODO message
255
+ }
256
+
257
+ for (var i = 0; i < length; i++) {
258
+ if (i in self && fun.call(thisp, self[i], i, self))
259
+ result.push(self[i]);
260
+ }
261
+ return result;
262
+ };
263
+ }
264
+
265
+ // ES5 15.4.4.16
266
+ if (!Array.prototype.every) {
267
+ Array.prototype.every = function (fun /*, thisp */) {
268
+ var self = toObject(this),
269
+ length = self.length >>> 0,
270
+ thisp = arguments[1];
271
+
272
+ // If no callback function or if callback is not a callable function
273
+ if (toString(fun) != "[object Function]") {
274
+ throw new TypeError(); // TODO message
275
+ }
276
+
277
+ for (var i = 0; i < length; i++) {
278
+ if (i in self && !fun.call(thisp, self[i], i, self))
279
+ return false;
280
+ }
281
+ return true;
282
+ };
283
+ }
284
+
285
+ // ES5 15.4.4.17
286
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
287
+ if (!Array.prototype.some) {
288
+ Array.prototype.some = function (fun /*, thisp */) {
289
+ var self = toObject(this),
290
+ length = self.length >>> 0,
291
+ thisp = arguments[1];
292
+
293
+ // If no callback function or if callback is not a callable function
294
+ if (toString(fun) != "[object Function]") {
295
+ throw new TypeError(); // TODO message
296
+ }
297
+
298
+ for (var i = 0; i < length; i++) {
299
+ if (i in self && fun.call(thisp, self[i], i, self))
300
+ return true;
301
+ }
302
+ return false;
303
+ };
304
+ }
305
+
306
+ // ES5 15.4.4.21
307
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
308
+ if (!Array.prototype.reduce) {
309
+ Array.prototype.reduce = function (fun /*, initial*/) {
310
+ var self = toObject(this),
311
+ length = self.length >>> 0;
312
+
313
+ // If no callback function or if callback is not a callable function
314
+ if (toString(fun) != "[object Function]") {
315
+ throw new TypeError(); // TODO message
316
+ }
317
+
318
+ // no value to return if no initial value and an empty array
319
+ if (!length && arguments.length == 1)
320
+ throw new TypeError(); // TODO message
321
+
322
+ var i = 0;
323
+ var result;
324
+ if (arguments.length >= 2) {
325
+ result = arguments[1];
326
+ } else {
327
+ do {
328
+ if (i in self) {
329
+ result = self[i++];
330
+ break;
331
+ }
332
+
333
+ // if array contains no values, no initial value to return
334
+ if (++i >= length)
335
+ throw new TypeError(); // TODO message
336
+ } while (true);
337
+ }
338
+
339
+ for (; i < length; i++) {
340
+ if (i in self)
341
+ result = fun.call(void 0, result, self[i], i, self);
342
+ }
343
+
344
+ return result;
345
+ };
346
+ }
347
+
348
+ // ES5 15.4.4.22
349
+ // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
350
+ if (!Array.prototype.reduceRight) {
351
+ Array.prototype.reduceRight = function (fun /*, initial*/) {
352
+ var self = toObject(this),
353
+ length = self.length >>> 0;
354
+
355
+ // If no callback function or if callback is not a callable function
356
+ if (toString(fun) != "[object Function]") {
357
+ throw new TypeError(); // TODO message
358
+ }
359
+
360
+ // no value to return if no initial value, empty array
361
+ if (!length && arguments.length == 1)
362
+ throw new TypeError(); // TODO message
363
+
364
+ var result, i = length - 1;
365
+ if (arguments.length >= 2) {
366
+ result = arguments[1];
367
+ } else {
368
+ do {
369
+ if (i in self) {
370
+ result = self[i--];
371
+ break;
372
+ }
373
+
374
+ // if array contains no values, no initial value to return
375
+ if (--i < 0)
376
+ throw new TypeError(); // TODO message
377
+ } while (true);
378
+ }
379
+
380
+ do {
381
+ if (i in this)
382
+ result = fun.call(void 0, result, self[i], i, self);
383
+ } while (i--);
384
+
385
+ return result;
386
+ };
387
+ }
388
+
389
+ // ES5 15.4.4.14
390
+ // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
391
+ if (!Array.prototype.indexOf) {
392
+ Array.prototype.indexOf = function (sought /*, fromIndex */ ) {
393
+ var self = toObject(this),
394
+ length = self.length >>> 0;
395
+
396
+ if (!length)
397
+ return -1;
398
+
399
+ var i = 0;
400
+ if (arguments.length > 1)
401
+ i = toInteger(arguments[1]);
402
+
403
+ // handle negative indices
404
+ i = i >= 0 ? i : length - Math.abs(i);
405
+ for (; i < length; i++) {
406
+ if (i in self && self[i] === sought) {
407
+ return i;
408
+ }
409
+ }
410
+ return -1;
411
+ };
412
+ }
413
+
414
+ // ES5 15.4.4.15
415
+ if (!Array.prototype.lastIndexOf) {
416
+ Array.prototype.lastIndexOf = function (sought /*, fromIndex */) {
417
+ var self = toObject(this),
418
+ length = self.length >>> 0;
419
+
420
+ if (!length)
421
+ return -1;
422
+ var i = length - 1;
423
+ if (arguments.length > 1)
424
+ i = toInteger(arguments[1]);
425
+ // handle negative indices
426
+ i = i >= 0 ? i : length - Math.abs(i);
427
+ for (; i >= 0; i--) {
428
+ if (i in self && sought === self[i])
429
+ return i;
430
+ }
431
+ return -1;
432
+ };
433
+ }
434
+
435
+ //
436
+ // Array
437
+ // =====
438
+ //
439
+
440
+ // ES5 15.4.4.12
441
+ // http://es5.github.com/#x15.4.4.12
442
+ // Default value for second param
443
+ // [bugfix, ielt9, old browsers]
444
+ // IE < 9 bug: [1,2].splice(0).join("") == "" but should be "12"
445
+ if([1,2].splice(0).length != 2) {
446
+ var _origArraySplice = Array.prototype.splice;
447
+
448
+ Array.prototype.splice = function(start, deleteCount) {
449
+ if(!arguments.length)return [];
450
+
451
+ return _origArraySplice.apply(this, [
452
+ start === void 0 ? 0 : start,
453
+ deleteCount === void 0 ? (this.length - start) : deleteCount
454
+ ].concat(slice.call(arguments, 2)))
455
+ };
456
+ }
457
+
458
+ //
459
+ // Object
460
+ // ======
461
+ //
462
+
463
+
464
+ // ES5 15.2.3.14
465
+ // http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
466
+ if (!Object.keys) {
467
+
468
+ var hasDontEnumBug = true,
469
+ dontEnums = [
470
+ "toString",
471
+ "toLocaleString",
472
+ "valueOf",
473
+ "hasOwnProperty",
474
+ "isPrototypeOf",
475
+ "propertyIsEnumerable",
476
+ "constructor"
477
+ ],
478
+ dontEnumsLength = dontEnums.length;
479
+
480
+ for (var key in {"toString": null})
481
+ hasDontEnumBug = false;
482
+
483
+ Object.keys = function keys(object) {
484
+
485
+ if ((typeof object != "object" && typeof object != "function") || object === null)
486
+ throw new TypeError("Object.keys called on a non-object");
487
+
488
+ var keys = [];
489
+ for (var name in object) {
490
+ if (owns(object, name)) {
491
+ keys.push(name);
492
+ }
493
+ }
494
+
495
+ if (hasDontEnumBug) {
496
+ for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
497
+ var dontEnum = dontEnums[i];
498
+ if (owns(object, dontEnum)) {
499
+ keys.push(dontEnum);
500
+ }
501
+ }
502
+ }
503
+
504
+ return keys;
505
+ };
506
+
507
+ }
508
+
509
+ //
510
+ // Date
511
+ // ====
512
+ //
513
+
514
+ // ES5 15.9.5.43
515
+ // Format a Date object as a string according to a simplified subset of the ISO 8601
516
+ // standard as defined in 15.9.1.15.
517
+ if (!Date.prototype.toISOString) {
518
+ Date.prototype.toISOString = function toISOString() {
519
+ var result, length, value;
520
+ if (!isFinite(this))
521
+ throw new RangeError;
522
+
523
+ // the date time string format is specified in 15.9.1.15.
524
+ result = [this.getUTCFullYear(), this.getUTCMonth() + 1, this.getUTCDate(),
525
+ this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
526
+
527
+ length = result.length;
528
+ while (length--) {
529
+ value = result[length];
530
+ // pad months, days, hours, minutes, and seconds to have two digits.
531
+ if (value < 10)
532
+ result[length] = "0" + value;
533
+ }
534
+ // pad milliseconds to have three digits.
535
+ return result.slice(0, 3).join("-") + "T" + result.slice(3).join(":") + "." +
536
+ ("000" + this.getUTCMilliseconds()).slice(-3) + "Z";
537
+ }
538
+ }
539
+
540
+ // ES5 15.9.4.4
541
+ if (!Date.now) {
542
+ Date.now = function now() {
543
+ return new Date().getTime();
544
+ };
545
+ }
546
+
547
+ // ES5 15.9.5.44
548
+ if (!Date.prototype.toJSON) {
549
+ Date.prototype.toJSON = function toJSON(key) {
550
+ // This function provides a String representation of a Date object for
551
+ // use by JSON.stringify (15.12.3). When the toJSON method is called
552
+ // with argument key, the following steps are taken:
553
+
554
+ // 1. Let O be the result of calling ToObject, giving it the this
555
+ // value as its argument.
556
+ // 2. Let tv be ToPrimitive(O, hint Number).
557
+ // 3. If tv is a Number and is not finite, return null.
558
+ // XXX
559
+ // 4. Let toISO be the result of calling the [[Get]] internal method of
560
+ // O with argument "toISOString".
561
+ // 5. If IsCallable(toISO) is false, throw a TypeError exception.
562
+ if (typeof this.toISOString != "function")
563
+ throw new TypeError(); // TODO message
564
+ // 6. Return the result of calling the [[Call]] internal method of
565
+ // toISO with O as the this value and an empty argument list.
566
+ return this.toISOString();
567
+
568
+ // NOTE 1 The argument is ignored.
569
+
570
+ // NOTE 2 The toJSON function is intentionally generic; it does not
571
+ // require that its this value be a Date object. Therefore, it can be
572
+ // transferred to other kinds of objects for use as a method. However,
573
+ // it does require that any such object have a toISOString method. An
574
+ // object is free to use the argument key to filter its
575
+ // stringification.
576
+ };
577
+ }
578
+
579
+
580
+ //
581
+ // String
582
+ // ======
583
+ //
584
+
585
+ // ES5 15.5.4.20
586
+ var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
587
+ "\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
588
+ "\u2029\uFEFF";
589
+ if (!String.prototype.trim || ws.trim()) {
590
+ // http://blog.stevenlevithan.com/archives/faster-trim-javascript
591
+ // http://perfectionkills.com/whitespace-deviations/
592
+ ws = "[" + ws + "]";
593
+ var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
594
+ trimEndRegexp = new RegExp(ws + ws + "*$");
595
+ String.prototype.trim = function trim() {
596
+ return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
597
+ };
598
+ }
599
+
600
+ // ES5 15.5.4.14
601
+ // http://es5.github.com/#x15.5.4.14
602
+ // [bugfix, chrome]
603
+ // If separator is undefined, then the result array contains just one String, which is the this value (converted to a String). If limit is not undefined, then the output array is truncated so that it contains no more than limit elements.
604
+ // "0".split(undefined, 0) -> []
605
+ if("0".split(void 0, 0).length) {
606
+ var oldSplit = String.prototype.split;
607
+ String.prototype.split = function(separator, limit) {
608
+ if(separator === void 0 && limit === 0)return [];
609
+ return oldSplit.apply(this, arguments);
610
+ }
611
+ }
612
+
613
+ // ECMA-262, 3rd B.2.3
614
+ // Note an ECMAScript standart, although ECMAScript 3rd Edition has a non-normative section suggesting uniform semantics
615
+ // and it should be normalized across all browsers
616
+ // [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
617
+ if("".substr && "0b".substr(-1) !== "b") {
618
+ var oldSubstr = String.prototype.substr;
619
+ /**
620
+ * Get the substring of a string
621
+ * @param {integer} start where to start the substring
622
+ * @param {integer} length how many characters to return
623
+ * @return {string}
624
+ */
625
+ String.prototype.substr = function(start, length) {
626
+ return oldSubstr.call(this, start < 0 ? (start = this.length + start) < 0 ? 0 : start : start, length);
627
+ }
628
+ }
629
+
630
+ //
631
+ // Util
632
+ // ======
633
+ //
634
+
635
+ // http://jsperf.com/to-integer
636
+ var toInteger = function (n) {
637
+ n = +n;
638
+ if (n !== n) // isNaN
639
+ n = -1;
640
+ else if (n !== 0 && n !== (1/0) && n !== -(1/0))
641
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
642
+ return n;
643
+ };
644
+
645
+ var prepareString = "a"[0] != "a",
646
+ // ES5 9.9
647
+ toObject = function (o) {
648
+ if (o == null) { // this matches both null and undefined
649
+ throw new TypeError(); // TODO message
650
+ }
651
+ // If the implementation doesn't support by-index access of
652
+ // string characters (ex. IE < 7), split the string
653
+ if (prepareString && typeof o == "string" && o) {
654
+ return o.split("");
655
+ }
656
+ return Object(o);
657
+ };
658
+
659
+ })();
660
+
661
+
662
+
663
+ (function($, shims){
664
+ var defineProperty = 'defineProperty';
665
+ var advancedObjectProperties = !!(Object.create && Object.defineProperties && Object.getOwnPropertyDescriptor);
666
+ //safari5 has defineProperty-interface, but it can't be used on dom-object
667
+ //only do this test in non-IE browsers, because this hurts dhtml-behavior in some IE8 versions
668
+ if (advancedObjectProperties && !$.browser.msie && Object[defineProperty] && Object.prototype.__defineGetter__) {
669
+ (function(){
670
+ try {
671
+ var foo = document.createElement('foo');
672
+ Object[defineProperty](foo, 'bar', {
673
+ get: function(){
674
+ return true;
675
+ }
676
+ });
677
+ advancedObjectProperties = !!foo.bar;
678
+ }
679
+ catch (e) {
680
+ advancedObjectProperties = false;
681
+ }
682
+ foo = null;
683
+ })();
684
+ }
685
+
686
+ Modernizr.objectAccessor = !!((advancedObjectProperties || (Object.prototype.__defineGetter__ && Object.prototype.__lookupSetter__)) && (!$.browser.opera || shims.browserVersion >= 11));
687
+ Modernizr.advancedObjectProperties = advancedObjectProperties;
688
+
689
+ if((!advancedObjectProperties || !Object.create || !Object.defineProperties || !Object.getOwnPropertyDescriptor || !Object.defineProperty)){
690
+ var call = Function.prototype.call;
691
+ var prototypeOfObject = Object.prototype;
692
+ var owns = call.bind(prototypeOfObject.hasOwnProperty);
693
+
694
+ shims.objectCreate = function(proto, props, opts, no__proto__){
695
+ var o;
696
+ var f = function(){};
697
+
698
+ f.prototype = proto;
699
+ o = new f();
700
+
701
+ if(!no__proto__ && !('__proto__' in o) && !Modernizr.objectAccessor){
702
+ o.__proto__ = proto;
703
+ }
704
+
705
+ if(props){
706
+ shims.defineProperties(o, props);
707
+ }
708
+
709
+ if(opts){
710
+ o.options = jQuery.extend(true, {}, o.options || {}, opts);
711
+ opts = o.options;
712
+ }
713
+
714
+ if(o._create && jQuery.isFunction(o._create)){
715
+ o._create(opts);
716
+ }
717
+ return o;
718
+ };
719
+
720
+ shims.defineProperties = function(object, props){
721
+ for (var name in props) {
722
+ if (owns(props, name)) {
723
+ shims.defineProperty(object, name, props[name]);
724
+ }
725
+ }
726
+ return object;
727
+ };
728
+
729
+ var descProps = ['configurable', 'enumerable', 'writable'];
730
+ shims.defineProperty = function(proto, property, descriptor){
731
+ if(typeof descriptor != "object" || descriptor === null){return proto;}
732
+
733
+ if(owns(descriptor, "value")){
734
+ proto[property] = descriptor.value;
735
+ return proto;
736
+ }
737
+
738
+ if(proto.__defineGetter__){
739
+ if (typeof descriptor.get == "function") {
740
+ proto.__defineGetter__(property, descriptor.get);
741
+ }
742
+ if (typeof descriptor.set == "function"){
743
+ proto.__defineSetter__(property, descriptor.set);
744
+ }
745
+ }
746
+ return proto;
747
+ };
748
+
749
+ shims.getPrototypeOf = function (object) {
750
+ return Object.getPrototypeOf && Object.getPrototypeOf(object) || object.__proto__ || object.constructor && object.constructor.prototype;
751
+ };
752
+
753
+ //based on http://www.refactory.org/s/object_getownpropertydescriptor/view/latest
754
+ shims.getOwnPropertyDescriptor = function(obj, prop){
755
+ if (typeof obj !== "object" && typeof obj !== "function" || obj === null){
756
+ throw new TypeError("Object.getOwnPropertyDescriptor called on a non-object");
757
+ }
758
+ var descriptor;
759
+ if(Object.defineProperty && Object.getOwnPropertyDescriptor){
760
+ try{
761
+ descriptor = Object.getOwnPropertyDescriptor(obj, prop);
762
+ return descriptor;
763
+ } catch(e){}
764
+ }
765
+ descriptor = {
766
+ configurable: true,
767
+ enumerable: true,
768
+ writable: true,
769
+ value: undefined
770
+ };
771
+ var getter = obj.__lookupGetter__ && obj.__lookupGetter__(prop),
772
+ setter = obj.__lookupSetter__ && obj.__lookupSetter__(prop)
773
+ ;
774
+
775
+ if (!getter && !setter) { // not an accessor so return prop
776
+ if(!owns(obj, prop)){
777
+ return;
778
+ }
779
+ descriptor.value = obj[prop];
780
+ return descriptor;
781
+ }
782
+
783
+ // there is an accessor, remove descriptor.writable; populate descriptor.get and descriptor.set
784
+ delete descriptor.writable;
785
+ delete descriptor.value;
786
+ descriptor.get = descriptor.set = undefined;
787
+
788
+ if(getter){
789
+ descriptor.get = getter;
790
+ }
791
+
792
+ if(setter){
793
+ descriptor.set = setter;
794
+ }
795
+
796
+ return descriptor;
797
+ };
798
+
799
+ }
800
+ })(jQuery, jQuery.webshims);
801
+
802
+
803
+ (function($, Modernizr, webshims){
804
+ "use strict";
805
+ var hasNative = Modernizr.audio && Modernizr.video;
806
+ var supportsLoop = false;
807
+ var options = webshims.cfg.mediaelement;
808
+ var bugs = webshims.bugs;
809
+ var swfType = options.player == 'jwplayer' ? 'mediaelement-swf' : 'mediaelement-jaris'
810
+ var loadSwf = function(){
811
+ webshims.ready(swfType, function(){
812
+ if(!webshims.mediaelement.createSWF){
813
+ webshims.mediaelement.loadSwf = true;
814
+ webshims.reTest([swfType], hasNative);
815
+ }
816
+ });
817
+ };
818
+ var hasSwf;
819
+ if(hasNative){
820
+ var videoElem = document.createElement('video');
821
+ Modernizr.videoBuffered = ('buffered' in videoElem);
822
+ supportsLoop = ('loop' in videoElem);
823
+
824
+ webshims.capturingEvents(['play', 'playing', 'waiting', 'paused', 'ended', 'durationchange', 'loadedmetadata', 'canplay', 'volumechange']);
825
+
826
+ if(!Modernizr.videoBuffered){
827
+ webshims.addPolyfill('mediaelement-native-fix', {
828
+ f: 'mediaelement',
829
+ test: Modernizr.videoBuffered,
830
+ d: ['dom-support']
831
+ });
832
+
833
+ webshims.reTest('mediaelement-native-fix');
834
+ }
835
+ }
836
+
837
+ if(hasNative && !options.preferFlash){
838
+ var switchOptions = function(e){
839
+ var parent = e.target.parentNode;
840
+ if(!options.preferFlash && ($(e.target).is('audio, video') || (parent && $('source:last', parent)[0] == e.target)) ){
841
+ webshims.ready('DOM mediaelement', function(){
842
+ if(hasSwf){
843
+ loadSwf();
844
+ }
845
+ webshims.ready('WINDOWLOAD '+swfType, function(){
846
+ setTimeout(function(){
847
+ if(hasSwf && !options.preferFlash && webshims.mediaelement.createSWF && !$(e.target).closest('audio, video').is('.nonnative-api-active')){
848
+ options.preferFlash = true;
849
+ document.removeEventListener('error', switchOptions, true);
850
+ $('audio, video').mediaLoad();
851
+ webshims.info("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.src);
852
+ } else if(!hasSwf){
853
+ document.removeEventListener('error', switchOptions, true);
854
+ }
855
+ }, 20);
856
+ });
857
+ });
858
+ }
859
+ };
860
+ document.addEventListener('error', switchOptions, true);
861
+ $('audio, video').each(function(){
862
+ if(this.error){
863
+ switchOptions({target: this});
864
+ }
865
+ });
866
+ }
867
+
868
+ bugs.track = false;
869
+
870
+ if(Modernizr.track){
871
+ (function(){
872
+
873
+ if(!bugs.track){
874
+ bugs.track = typeof $('<track />')[0].readyState != 'number';
875
+ }
876
+
877
+ if(!bugs.track){
878
+ try {
879
+ new TextTrackCue(2, 3, '');
880
+ } catch(e){
881
+ bugs.track = true;
882
+ }
883
+ }
884
+
885
+ var trackOptions = webshims.cfg.track;
886
+ var trackListener = function(e){
887
+ $(e.target).filter('track').each(changeApi);
888
+ };
889
+ var changeApi = function(){
890
+ if(bugs.track || (!trackOptions.override && $.prop(this, 'readyState') == 3)){
891
+ trackOptions.override = true;
892
+ webshims.reTest('track');
893
+ document.removeEventListener('error', trackListener, true);
894
+ if(this && $.nodeName(this, 'track')){
895
+ webshims.error("track support was overwritten. Please check your vtt including your vtt mime-type");
896
+ } else {
897
+ webshims.info("track support was overwritten. due to bad browser support");
898
+ }
899
+ }
900
+ };
901
+ var detectTrackError = function(){
902
+ document.addEventListener('error', trackListener, true);
903
+
904
+ if(bugs.track){
905
+ changeApi();
906
+ } else {
907
+ $('track').each(changeApi);
908
+ }
909
+ };
910
+ if(!trackOptions.override){
911
+ if(webshims.isReady('track')){
912
+ detectTrackError();
913
+ } else {
914
+ $(detectTrackError);
915
+ }
916
+ }
917
+ })();
918
+
919
+ }
920
+
921
+ webshims.register('mediaelement-core', function($, webshims, window, document, undefined){
922
+ hasSwf = swfobject.hasFlashPlayerVersion('9.0.115');
923
+
924
+ var mediaelement = webshims.mediaelement;
925
+
926
+ var getSrcObj = function(elem, nodeName){
927
+ elem = $(elem);
928
+ var src = {src: elem.attr('src') || '', elem: elem, srcProp: elem.prop('src')};
929
+ if(!src.src){return src;}
930
+ var tmp = elem.attr('type');
931
+ if(tmp){
932
+ src.type = tmp;
933
+ src.container = $.trim(tmp.split(';')[0]);
934
+ } else {
935
+ if(!nodeName){
936
+ nodeName = elem[0].nodeName.toLowerCase();
937
+ if(nodeName == 'source'){
938
+ nodeName = (elem.closest('video, audio')[0] || {nodeName: 'video'}).nodeName.toLowerCase();
939
+ }
940
+ }
941
+ tmp = mediaelement.getTypeForSrc(src.src, nodeName );
942
+
943
+ if(tmp){
944
+ src.type = tmp;
945
+ src.container = tmp;
946
+ }
947
+ }
948
+ tmp = elem.attr('media');
949
+ if(tmp){
950
+ src.media = tmp;
951
+ }
952
+ return src;
953
+ };
954
+
955
+
956
+
957
+ var hasYt = !hasSwf && ('postMessage' in window) && hasNative;
958
+
959
+ var loadYt = (function(){
960
+ var loaded;
961
+ return function(){
962
+ if(loaded || !hasYt){return;}
963
+ loaded = true;
964
+ webshims.loader.loadScript("https://www.youtube.com/player_api");
965
+ $(function(){
966
+ webshims.polyfill("mediaelement-yt");
967
+ });
968
+ };
969
+ })();
970
+ var loadThird = function(){
971
+ if(hasSwf){
972
+ loadSwf();
973
+ } else {
974
+ loadYt();
975
+ }
976
+ };
977
+
978
+ webshims.addPolyfill('mediaelement-yt', {
979
+ test: !hasYt,
980
+ d: ['dom-support']
981
+ });
982
+
983
+ mediaelement.mimeTypes = {
984
+ audio: {
985
+ //ogm shouldn´t be used!
986
+ 'audio/ogg': ['ogg','oga', 'ogm'],
987
+ 'audio/ogg;codecs="opus"': 'opus',
988
+ 'audio/mpeg': ['mp2','mp3','mpga','mpega'],
989
+ 'audio/mp4': ['mp4','mpg4', 'm4r', 'm4a', 'm4p', 'm4b', 'aac'],
990
+ 'audio/wav': ['wav'],
991
+ 'audio/3gpp': ['3gp','3gpp'],
992
+ 'audio/webm': ['webm'],
993
+ 'audio/fla': ['flv', 'f4a', 'fla'],
994
+ 'application/x-mpegURL': ['m3u8', 'm3u']
995
+ },
996
+ video: {
997
+ //ogm shouldn´t be used!
998
+ 'video/ogg': ['ogg','ogv', 'ogm'],
999
+ 'video/mpeg': ['mpg','mpeg','mpe'],
1000
+ 'video/mp4': ['mp4','mpg4', 'm4v'],
1001
+ 'video/quicktime': ['mov','qt'],
1002
+ 'video/x-msvideo': ['avi'],
1003
+ 'video/x-ms-asf': ['asf', 'asx'],
1004
+ 'video/flv': ['flv', 'f4v'],
1005
+ 'video/3gpp': ['3gp','3gpp'],
1006
+ 'video/webm': ['webm'],
1007
+ 'application/x-mpegURL': ['m3u8', 'm3u'],
1008
+ 'video/MP2T': ['ts']
1009
+ }
1010
+ }
1011
+ ;
1012
+
1013
+ mediaelement.mimeTypes.source = $.extend({}, mediaelement.mimeTypes.audio, mediaelement.mimeTypes.video);
1014
+
1015
+ mediaelement.getTypeForSrc = function(src, nodeName){
1016
+ if(src.indexOf('youtube.com/watch?') != -1 || src.indexOf('youtube.com/v/') != -1){
1017
+ return 'video/youtube';
1018
+ }
1019
+ src = src.split('?')[0].split('.');
1020
+ src = src[src.length - 1];
1021
+ var mt;
1022
+
1023
+ $.each(mediaelement.mimeTypes[nodeName], function(mimeType, exts){
1024
+ if(exts.indexOf(src) !== -1){
1025
+ mt = mimeType;
1026
+ return false;
1027
+ }
1028
+ });
1029
+ return mt;
1030
+ };
1031
+
1032
+
1033
+ mediaelement.srces = function(mediaElem, srces){
1034
+ mediaElem = $(mediaElem);
1035
+ if(!srces){
1036
+ srces = [];
1037
+ var nodeName = mediaElem[0].nodeName.toLowerCase();
1038
+ var src = getSrcObj(mediaElem, nodeName);
1039
+
1040
+ if(!src.src){
1041
+
1042
+ $('source', mediaElem).each(function(){
1043
+ src = getSrcObj(this, nodeName);
1044
+ if(src.src){srces.push(src);}
1045
+ });
1046
+ } else {
1047
+ srces.push(src);
1048
+ }
1049
+ return srces;
1050
+ } else {
1051
+ mediaElem.removeAttr('src').removeAttr('type').find('source').remove();
1052
+ if(!$.isArray(srces)){
1053
+ srces = [srces];
1054
+ }
1055
+ srces.forEach(function(src){
1056
+ var source = document.createElement('source');
1057
+ if(typeof src == 'string'){
1058
+ src = {src: src};
1059
+ }
1060
+ source.setAttribute('src', src.src);
1061
+ if(src.type){
1062
+ source.setAttribute('type', src.type);
1063
+ }
1064
+ if(src.media){
1065
+ source.setAttribute('media', src.media);
1066
+ }
1067
+ mediaElem.append(source);
1068
+ });
1069
+
1070
+ }
1071
+ };
1072
+
1073
+
1074
+ $.fn.loadMediaSrc = function(srces, poster){
1075
+ return this.each(function(){
1076
+ if(poster !== undefined){
1077
+ $(this).removeAttr('poster');
1078
+ if(poster){
1079
+ $.attr(this, 'poster', poster);
1080
+ }
1081
+ }
1082
+ mediaelement.srces(this, srces);
1083
+ $(this).mediaLoad();
1084
+ });
1085
+ };
1086
+
1087
+ mediaelement.swfMimeTypes = ['video/3gpp', 'video/x-msvideo', 'video/quicktime', 'video/x-m4v', 'video/mp4', 'video/m4p', 'video/x-flv', 'video/flv', 'audio/mpeg', 'audio/aac', 'audio/mp4', 'audio/x-m4a', 'audio/m4a', 'audio/mp3', 'audio/x-fla', 'audio/fla', 'youtube/flv', 'jwplayer/jwplayer', 'video/youtube'];
1088
+
1089
+ mediaelement.canThirdPlaySrces = function(mediaElem, srces){
1090
+ var ret = '';
1091
+ if(hasSwf || hasYt){
1092
+ mediaElem = $(mediaElem);
1093
+ srces = srces || mediaelement.srces(mediaElem);
1094
+ $.each(srces, function(i, src){
1095
+ if(src.container && src.src && ((hasSwf && mediaelement.swfMimeTypes.indexOf(src.container) != -1) || (hasYt && src.container == 'video/youtube'))){
1096
+ ret = src;
1097
+ return false;
1098
+ }
1099
+ });
1100
+
1101
+ }
1102
+
1103
+ return ret;
1104
+ };
1105
+
1106
+ var nativeCanPlayType = {};
1107
+ mediaelement.canNativePlaySrces = function(mediaElem, srces){
1108
+ var ret = '';
1109
+ if(hasNative){
1110
+ mediaElem = $(mediaElem);
1111
+ var nodeName = (mediaElem[0].nodeName || '').toLowerCase();
1112
+ if(!nativeCanPlayType[nodeName]){return ret;}
1113
+ srces = srces || mediaelement.srces(mediaElem);
1114
+
1115
+ $.each(srces, function(i, src){
1116
+ if(src.type && nativeCanPlayType[nodeName].prop._supvalue.call(mediaElem[0], src.type) ){
1117
+ ret = src;
1118
+ return false;
1119
+ }
1120
+ });
1121
+ }
1122
+ return ret;
1123
+ };
1124
+
1125
+ mediaelement.setError = function(elem, message){
1126
+ if(!message){
1127
+ message = "can't play sources";
1128
+ }
1129
+
1130
+ $(elem).pause().data('mediaerror', message);
1131
+ webshims.warn('mediaelementError: '+ message);
1132
+ setTimeout(function(){
1133
+ if($(elem).data('mediaerror')){
1134
+ $(elem).trigger('mediaerror');
1135
+ }
1136
+ }, 1);
1137
+ };
1138
+
1139
+ var handleThird = (function(){
1140
+ var requested;
1141
+ return function( mediaElem, ret, data ){
1142
+ webshims.ready(hasSwf ? swfType : 'mediaelement-yt', function(){
1143
+ if(mediaelement.createSWF){
1144
+ mediaelement.createSWF( mediaElem, ret, data );
1145
+ } else if(!requested) {
1146
+ requested = true;
1147
+ loadThird();
1148
+ //readd to ready
1149
+ handleThird( mediaElem, ret, data );
1150
+ }
1151
+ });
1152
+ if(!requested && hasYt && !mediaelement.createSWF){
1153
+ loadYt();
1154
+ }
1155
+ };
1156
+ })();
1157
+
1158
+ var stepSources = function(elem, data, useSwf, _srces, _noLoop){
1159
+ var ret;
1160
+ if(useSwf || (useSwf !== false && data && data.isActive == 'third')){
1161
+ ret = mediaelement.canThirdPlaySrces(elem, _srces);
1162
+ if(!ret){
1163
+ if(_noLoop){
1164
+ mediaelement.setError(elem, false);
1165
+ } else {
1166
+ stepSources(elem, data, false, _srces, true);
1167
+ }
1168
+ } else {
1169
+ handleThird(elem, ret, data);
1170
+ }
1171
+ } else {
1172
+ ret = mediaelement.canNativePlaySrces(elem, _srces);
1173
+ if(!ret){
1174
+ if(_noLoop){
1175
+ mediaelement.setError(elem, false);
1176
+ if(data && data.isActive == 'third') {
1177
+ mediaelement.setActive(elem, 'html5', data);
1178
+ }
1179
+ } else {
1180
+ stepSources(elem, data, true, _srces, true);
1181
+ }
1182
+ } else if(data && data.isActive == 'third') {
1183
+ mediaelement.setActive(elem, 'html5', data);
1184
+ }
1185
+ }
1186
+ };
1187
+ var stopParent = /^(?:embed|object|datalist)$/i;
1188
+ var selectSource = function(elem, data){
1189
+ var baseData = webshims.data(elem, 'mediaelementBase') || webshims.data(elem, 'mediaelementBase', {});
1190
+ var _srces = mediaelement.srces(elem);
1191
+ var parent = elem.parentNode;
1192
+
1193
+ clearTimeout(baseData.loadTimer);
1194
+ $.data(elem, 'mediaerror', false);
1195
+
1196
+ if(!_srces.length || !parent || parent.nodeType != 1 || stopParent.test(parent.nodeName || '')){return;}
1197
+ data = data || webshims.data(elem, 'mediaelement');
1198
+ stepSources(elem, data, options.preferFlash || undefined, _srces);
1199
+ };
1200
+
1201
+
1202
+ $(document).on('ended', function(e){
1203
+ var data = webshims.data(e.target, 'mediaelement');
1204
+ if( supportsLoop && (!data || data.isActive == 'html5') && !$.prop(e.target, 'loop')){return;}
1205
+ setTimeout(function(){
1206
+ if( $.prop(e.target, 'paused') || !$.prop(e.target, 'loop') ){return;}
1207
+ $(e.target).prop('currentTime', 0).play();
1208
+ }, 1);
1209
+
1210
+ });
1211
+ if(!supportsLoop){
1212
+ webshims.defineNodeNamesBooleanProperty(['audio', 'video'], 'loop');
1213
+ }
1214
+
1215
+ ['audio', 'video'].forEach(function(nodeName){
1216
+ var supLoad = webshims.defineNodeNameProperty(nodeName, 'load', {
1217
+ prop: {
1218
+ value: function(){
1219
+ var data = webshims.data(this, 'mediaelement');
1220
+ selectSource(this, data);
1221
+ if(hasNative && (!data || data.isActive == 'html5') && supLoad.prop._supvalue){
1222
+ supLoad.prop._supvalue.apply(this, arguments);
1223
+ }
1224
+ }
1225
+ }
1226
+ });
1227
+ nativeCanPlayType[nodeName] = webshims.defineNodeNameProperty(nodeName, 'canPlayType', {
1228
+ prop: {
1229
+ value: function(type){
1230
+ var ret = '';
1231
+ if(hasNative && nativeCanPlayType[nodeName].prop._supvalue){
1232
+ ret = nativeCanPlayType[nodeName].prop._supvalue.call(this, type);
1233
+ if(ret == 'no'){
1234
+ ret = '';
1235
+ }
1236
+ }
1237
+ if(!ret && hasSwf){
1238
+ type = $.trim((type || '').split(';')[0]);
1239
+ if(mediaelement.swfMimeTypes.indexOf(type) != -1){
1240
+ ret = 'maybe';
1241
+ }
1242
+ }
1243
+ return ret;
1244
+ }
1245
+ }
1246
+ });
1247
+ });
1248
+ webshims.onNodeNamesPropertyModify(['audio', 'video'], ['src', 'poster'], {
1249
+ set: function(){
1250
+ var elem = this;
1251
+ var baseData = webshims.data(elem, 'mediaelementBase') || webshims.data(elem, 'mediaelementBase', {});
1252
+ clearTimeout(baseData.loadTimer);
1253
+ baseData.loadTimer = setTimeout(function(){
1254
+ selectSource(elem);
1255
+ elem = null;
1256
+ }, 9);
1257
+ }
1258
+ });
1259
+
1260
+ var initMediaElements = function(){
1261
+
1262
+ webshims.addReady(function(context, insertedElement){
1263
+ $('video, audio', context)
1264
+ .add(insertedElement.filter('video, audio'))
1265
+ .each(function(){
1266
+ if($.browser.msie && webshims.browserVersion > 8 && $.prop(this, 'paused') && !$.prop(this, 'readyState') && $(this).is('audio[preload="none"][controls]:not([autoplay])')){
1267
+ $(this).prop('preload', 'metadata').mediaLoad();
1268
+ } else {
1269
+ selectSource(this);
1270
+ }
1271
+
1272
+
1273
+
1274
+ if(hasNative){
1275
+ var bufferTimer;
1276
+ var lastBuffered;
1277
+ var elem = this;
1278
+ var getBufferedString = function(){
1279
+ var buffered = $.prop(elem, 'buffered');
1280
+ if(!buffered){return;}
1281
+ var bufferString = "";
1282
+ for(var i = 0, len = buffered.length; i < len;i++){
1283
+ bufferString += buffered.end(i);
1284
+ }
1285
+ return bufferString;
1286
+ };
1287
+ var testBuffer = function(){
1288
+ var buffered = getBufferedString();
1289
+ if(buffered != lastBuffered){
1290
+ lastBuffered = buffered;
1291
+ $(elem).triggerHandler('progress');
1292
+ }
1293
+ };
1294
+
1295
+ $(this)
1296
+ .on({
1297
+ 'play loadstart progress': function(e){
1298
+ if(e.type == 'progress'){
1299
+ lastBuffered = getBufferedString();
1300
+ }
1301
+ clearTimeout(bufferTimer);
1302
+ bufferTimer = setTimeout(testBuffer, 999);
1303
+ },
1304
+ 'emptied stalled mediaerror abort suspend': function(e){
1305
+ if(e.type == 'emptied'){
1306
+ lastBuffered = false;
1307
+ }
1308
+ clearTimeout(bufferTimer);
1309
+ }
1310
+ })
1311
+ ;
1312
+ }
1313
+
1314
+ })
1315
+ ;
1316
+ });
1317
+ };
1318
+
1319
+ if(Modernizr.track && !bugs.track){
1320
+ webshims.defineProperty(TextTrack.prototype, 'shimActiveCues', {
1321
+ get: function(){
1322
+ return this._shimActiveCues || this.activeCues;
1323
+ }
1324
+ });
1325
+ }
1326
+ //set native implementation ready, before swf api is retested
1327
+ if(hasNative){
1328
+ webshims.isReady('mediaelement-core', true);
1329
+ initMediaElements();
1330
+ webshims.ready('WINDOWLOAD mediaelement', loadThird);
1331
+ } else {
1332
+ webshims.ready(swfType, initMediaElements);
1333
+ }
1334
+ $(function(){
1335
+ webshims.loader.loadList(['track-ui']);
1336
+ });
1337
+
1338
+ });
1339
+ })(jQuery, Modernizr, jQuery.webshims);/*
1340
+ * todos:
1341
+ * - decouple muted/volume (needs improvement)
1342
+ * - implement video <-> flashcanvas pro API
1343
+ * - improve buffered-property with youtube/rtmp
1344
+ * - use jwplayer5 api instead of old flash4 api
1345
+ */
1346
+
1347
+ jQuery.webshims.register('mediaelement-swf', function($, webshims, window, document, undefined, options){
1348
+ "use strict";
1349
+ var SENDEVENT = 'sendEvent';
1350
+ var mediaelement = webshims.mediaelement;
1351
+ var swfobject = window.swfobject;
1352
+ var hasNative = Modernizr.audio && Modernizr.video;
1353
+ var hasFlash = swfobject.hasFlashPlayerVersion('9.0.115');
1354
+ var loadedSwf = 0;
1355
+ var getProps = {
1356
+ paused: true,
1357
+ ended: false,
1358
+ currentSrc: '',
1359
+ duration: window.NaN,
1360
+
1361
+ readyState: 0,
1362
+ networkState: 0,
1363
+ videoHeight: 0,
1364
+ videoWidth: 0,
1365
+ error: null,
1366
+ buffered: {
1367
+ start: function(index){
1368
+ if(index){
1369
+ webshims.error('buffered index size error');
1370
+ return;
1371
+ }
1372
+ return 0;
1373
+ },
1374
+ end: function(index){
1375
+ if(index){
1376
+ webshims.error('buffered index size error');
1377
+ return;
1378
+ }
1379
+ return 0;
1380
+ },
1381
+ length: 0
1382
+ }
1383
+ };
1384
+ var getPropKeys = Object.keys(getProps);
1385
+
1386
+ var getSetProps = {
1387
+ currentTime: 0,
1388
+ volume: 1,
1389
+ muted: false
1390
+ };
1391
+ var getSetPropKeys = Object.keys(getSetProps);
1392
+
1393
+ var playerStateObj = $.extend({
1394
+ isActive: 'html5',
1395
+ activating: 'html5',
1396
+ wasSwfReady: false,
1397
+ _bufferedEnd: 0,
1398
+ _bufferedStart: 0,
1399
+ _metadata: false,
1400
+ _durationCalcs: -1,
1401
+ _callMeta: false,
1402
+ currentTime: 0,
1403
+ _ppFlag: undefined
1404
+ }, getProps, getSetProps);
1405
+
1406
+ var idRep = /^jwplayer-/;
1407
+ var getSwfDataFromID = function(id){
1408
+
1409
+ var elem = document.getElementById(id.replace(idRep, ''));
1410
+ if(!elem){return;}
1411
+ var data = webshims.data(elem, 'mediaelement');
1412
+ return data.isActive == 'third' ? data : null;
1413
+ };
1414
+
1415
+
1416
+ var getSwfDataFromElem = function(elem){
1417
+ try {
1418
+ (elem.nodeName);
1419
+ } catch(er){
1420
+ return null;
1421
+ }
1422
+ var data = webshims.data(elem, 'mediaelement');
1423
+ return (data && data.isActive== 'third') ? data : null;
1424
+ };
1425
+
1426
+ var trigger = function(elem, evt){
1427
+ evt = $.Event(evt);
1428
+ evt.preventDefault();
1429
+ $.event.trigger(evt, undefined, elem);
1430
+ };
1431
+
1432
+ var playerSwfPath = options.playerPath || webshims.cfg.basePath + "jwplayer/" + (options.playerName || "player.swf");
1433
+ var jwplugin = options.pluginPath || webshims.cfg.basePath +'swf/jwwebshims.swf';
1434
+
1435
+ webshims.extendUNDEFProp(options.params, {
1436
+ allowscriptaccess: 'always',
1437
+ allowfullscreen: 'true',
1438
+ wmode: 'transparent'
1439
+ });
1440
+ webshims.extendUNDEFProp(options.vars, {
1441
+ screencolor: 'ffffffff'
1442
+ });
1443
+ webshims.extendUNDEFProp(options.attrs, {
1444
+ bgcolor: '#000000'
1445
+ });
1446
+
1447
+ var getDuration = function(data, obj){
1448
+ var curDuration = data.duration;
1449
+ if(curDuration && data._durationCalcs > 0){return;}
1450
+ try {
1451
+ data.duration = data.jwapi.getPlaylist()[0].duration;
1452
+ if(!data.duration || data.duration <= 0 || data.duration === data._lastDuration){
1453
+ data.duration = curDuration;
1454
+ }
1455
+ } catch(er){}
1456
+ if(data.duration && data.duration != data._lastDuration){
1457
+ trigger(data._elem, 'durationchange');
1458
+ if(data._elemNodeName == 'audio' || data._callMeta){
1459
+ mediaelement.jwEvents.Model.META($.extend({duration: data.duration}, obj), data);
1460
+ }
1461
+ data._durationCalcs--;
1462
+ } else {
1463
+ data._durationCalcs++;
1464
+ }
1465
+ };
1466
+ var setReadyState = function(readyState, data){
1467
+ if(readyState < 3){
1468
+ clearTimeout(data._canplaythroughTimer);
1469
+ }
1470
+ if(readyState >= 3 && data.readyState < 3){
1471
+ data.readyState = readyState;
1472
+ trigger(data._elem, 'canplay');
1473
+ clearTimeout(data._canplaythroughTimer);
1474
+ data._canplaythroughTimer = setTimeout(function(){
1475
+ setReadyState(4, data);
1476
+ }, 4000);
1477
+ }
1478
+ if(readyState >= 4 && data.readyState < 4){
1479
+ data.readyState = readyState;
1480
+ trigger(data._elem, 'canplaythrough');
1481
+ }
1482
+ data.readyState = readyState;
1483
+ };
1484
+
1485
+ $.extend($.event.customEvent, {
1486
+ updatemediaelementdimensions: true,
1487
+ flashblocker: true,
1488
+ swfstageresize: true,
1489
+ mediaelementapichange: true
1490
+ });
1491
+
1492
+ mediaelement.jwEvents = {
1493
+ View: {
1494
+
1495
+ PLAY: function(obj){
1496
+ var data = getSwfDataFromID(obj.id);
1497
+ if(!data || data.stopPlayPause){return;}
1498
+ data._ppFlag = true;
1499
+ if(data.paused == obj.state){
1500
+ data.paused = !obj.state;
1501
+ if(data.ended){
1502
+ data.ended = false;
1503
+ }
1504
+ trigger(data._elem, obj.state ? 'play' : 'pause');
1505
+ }
1506
+ }
1507
+ },
1508
+ Model: {
1509
+
1510
+ BUFFER: function(obj){
1511
+ var data = getSwfDataFromID(obj.id);
1512
+ if(!data || !('percentage' in obj) || data._bufferedEnd == obj.percentage){return;}
1513
+ data.networkState = (obj.percentage == 100) ? 1 : 2;
1514
+ if(isNaN(data.duration) || (obj.percentage > 5 && obj.percentage < 25) || (obj.percentage === 100)){
1515
+ getDuration(data, obj);
1516
+ }
1517
+
1518
+ if(data.ended){
1519
+ data.ended = false;
1520
+ }
1521
+ if(!data.duration){
1522
+ return;
1523
+ }
1524
+ if(obj.percentage > 2 && obj.percentage < 20){
1525
+ setReadyState(3, data);
1526
+ } else if(obj.percentage > 20){
1527
+ setReadyState(4, data);
1528
+ }
1529
+ if(data._bufferedEnd && (data._bufferedEnd > obj.percentage)){
1530
+ data._bufferedStart = data.currentTime || 0;
1531
+ }
1532
+
1533
+ data._bufferedEnd = obj.percentage;
1534
+ data.buffered.length = 1;
1535
+ if(obj.percentage == 100){
1536
+ data.networkState = 1;
1537
+ setReadyState(4, data);
1538
+ }
1539
+ $.event.trigger('progress', undefined, data._elem, true);
1540
+ },
1541
+ META: function(obj, data){
1542
+
1543
+ data = data && data.networkState ? data : getSwfDataFromID(obj.id);
1544
+
1545
+ if(!data){return;}
1546
+ if( !('duration' in obj) ){
1547
+ data._callMeta = true;
1548
+ return;
1549
+ }
1550
+
1551
+ if( data._metadata && (!obj.height || data.videoHeight == obj.height) && (obj.duration === data.duration) ){return;}
1552
+
1553
+ data._metadata = true;
1554
+
1555
+ var oldDur = data.duration;
1556
+ if(obj.duration){
1557
+ data.duration = obj.duration;
1558
+ }
1559
+ data._lastDuration = data.duration;
1560
+ if(obj.height || obj.width){
1561
+ data.videoHeight = obj.height || 0;
1562
+ data.videoWidth = obj.width || 0;
1563
+ }
1564
+ if(!data.networkState){
1565
+ data.networkState = 2;
1566
+ }
1567
+ if(data.readyState < 1){
1568
+ setReadyState(1, data);
1569
+ }
1570
+ if(data.duration && oldDur !== data.duration){
1571
+ trigger(data._elem, 'durationchange');
1572
+ }
1573
+
1574
+ trigger(data._elem, 'loadedmetadata');
1575
+ },
1576
+ TIME: function(obj){
1577
+ var data = getSwfDataFromID(obj.id);
1578
+ if(!data || data.currentTime === obj.position){return;}
1579
+ data.currentTime = obj.position;
1580
+ if(data.duration && data.duration < data.currentTime){
1581
+ getDuration(data, obj);
1582
+ }
1583
+ if(data.readyState < 2){
1584
+ setReadyState(2, data);
1585
+ }
1586
+ if(data.ended){
1587
+ data.ended = false;
1588
+ }
1589
+ trigger(data._elem, 'timeupdate');
1590
+
1591
+ },
1592
+ STATE: function(obj){
1593
+ var data = getSwfDataFromID(obj.id);
1594
+ if(!data){return;}
1595
+ switch(obj.newstate) {
1596
+ case 'BUFFERING':
1597
+
1598
+ if(data.ended){
1599
+ data.ended = false;
1600
+ }
1601
+ setReadyState(1, data);
1602
+ trigger(data._elem, 'waiting');
1603
+ break;
1604
+ case 'PLAYING':
1605
+ data.paused = false;
1606
+ data._ppFlag = true;
1607
+ if(!data.duration){
1608
+ getDuration(data, obj);
1609
+ }
1610
+ if(data.readyState < 3){
1611
+ setReadyState(3, data);
1612
+ }
1613
+ if(data.ended){
1614
+ data.ended = false;
1615
+ }
1616
+ trigger(data._elem, 'playing');
1617
+ break;
1618
+ case 'PAUSED':
1619
+ if(!data.paused && !data.stopPlayPause){
1620
+ data.paused = true;
1621
+ data._ppFlag = true;
1622
+ trigger(data._elem, 'pause');
1623
+ }
1624
+ break;
1625
+ case 'COMPLETED':
1626
+ if(data.readyState < 4){
1627
+ setReadyState(4, data);
1628
+ }
1629
+ data.ended = true;
1630
+ trigger(data._elem, 'ended');
1631
+ break;
1632
+ }
1633
+ }
1634
+ }
1635
+ ,Controller: {
1636
+
1637
+ ERROR: function(obj){
1638
+ var data = getSwfDataFromID(obj.id);
1639
+ if(!data){return;}
1640
+ mediaelement.setError(data._elem, obj.message);
1641
+ },
1642
+ SEEK: function(obj){
1643
+ var data = getSwfDataFromID(obj.id);
1644
+ if(!data){return;}
1645
+ if(data.ended){
1646
+ data.ended = false;
1647
+ }
1648
+ if(data.paused){
1649
+ try {
1650
+ data.jwapi[SENDEVENT]('play', 'false');
1651
+ } catch(er){}
1652
+ }
1653
+ if(data.currentTime != obj.position){
1654
+ data.currentTime = obj.position;
1655
+ trigger(data._elem, 'timeupdate');
1656
+ }
1657
+
1658
+
1659
+ },
1660
+ VOLUME: function(obj){
1661
+ var data = getSwfDataFromID(obj.id);
1662
+ if(!data){return;}
1663
+ var newVolume = obj.percentage / 100;
1664
+ if(data.volume == newVolume){return;}
1665
+ data.volume = newVolume;
1666
+ trigger(data._elem, 'volumechange');
1667
+ },
1668
+ MUTE: function(obj){
1669
+ if(obj.state){return;}
1670
+ var data = getSwfDataFromID(obj.id);
1671
+ if(!data){return;}
1672
+ if(data.muted == obj.state){return;}
1673
+ data.muted = obj.state;
1674
+ trigger(data._elem, 'volumechange');
1675
+ }
1676
+ }
1677
+ };
1678
+
1679
+ var initEvents = function(data){
1680
+ var passed = true;
1681
+ $.each(mediaelement.jwEvents, function(mvcName, evts){
1682
+ $.each(evts, function(evtName){
1683
+ try {
1684
+ data.jwapi['add'+ mvcName +'Listener'](evtName, 'jQuery.webshims.mediaelement.jwEvents.'+ mvcName +'.'+ evtName);
1685
+ } catch(er){
1686
+ passed = false;
1687
+ return false;
1688
+ }
1689
+ });
1690
+ });
1691
+ return passed;
1692
+ };
1693
+
1694
+ var workActionQueue = function(data){
1695
+ var actionLen = data.actionQueue.length;
1696
+ var i = 0;
1697
+ var operation;
1698
+ if(actionLen && data.isActive == 'third'){
1699
+ while(data.actionQueue.length && actionLen > i){
1700
+ i++;
1701
+ operation = data.actionQueue.shift();
1702
+ data.jwapi[operation.fn].apply(data.jwapi, operation.args);
1703
+ }
1704
+ }
1705
+ if(data.actionQueue.length){
1706
+ data.actionQueue = [];
1707
+ }
1708
+ };
1709
+ var startAutoPlay = function(data){
1710
+ if(!data){return;}
1711
+ if( (data._ppFlag === undefined && ($.prop(data._elem, 'autoplay')) || !data.paused)){
1712
+ setTimeout(function(){
1713
+ if(data.isActive == 'third' && (data._ppFlag === undefined || !data.paused)){
1714
+ try {
1715
+ $(data._elem).play();
1716
+ } catch(er){}
1717
+ }
1718
+ }, 1);
1719
+ }
1720
+ };
1721
+
1722
+
1723
+ mediaelement.playerResize = function(id){
1724
+ if(!id){return;}
1725
+ var elem = document.getElementById(id.replace(idRep, ''));
1726
+
1727
+ if(elem){
1728
+ $(elem).triggerHandler('swfstageresize');
1729
+ }
1730
+ elem = null;
1731
+ };
1732
+
1733
+
1734
+ $(document).on('emptied', function(e){
1735
+ var data = getSwfDataFromElem(e.target);
1736
+ startAutoPlay(data);
1737
+ });
1738
+
1739
+ var localConnectionTimer;
1740
+ mediaelement.jwPlayerReady = function(jwData){
1741
+ var data = getSwfDataFromID(jwData.id);
1742
+ var passed = true;
1743
+ var i = 0;
1744
+ var doneFn = function(){
1745
+ if(i > 9){return;}
1746
+ i++;
1747
+ if(initEvents(data)){
1748
+ if(!data.wasSwfReady){
1749
+ var version = parseFloat( jwData.version, 10);
1750
+ if(version < 5.1 || version >= 6){
1751
+ webshims.warn('mediaelement-swf is only testet with jwplayer 5.6+');
1752
+ }
1753
+ } else {
1754
+ $(data._elem).mediaLoad();
1755
+
1756
+ }
1757
+ data.wasSwfReady = true;
1758
+ data.tryedReframeing = 0;
1759
+ workActionQueue(data);
1760
+ startAutoPlay(data);
1761
+ } else {
1762
+ clearTimeout(data.reframeTimer);
1763
+ data.reframeTimer = setTimeout(doneFn, 9 * i);
1764
+ if(i > 2 && data.tryedReframeing < 9){
1765
+ data.tryedReframeing++;
1766
+ data.shadowElem.css({overflow: 'visible'});
1767
+ setTimeout(function(){
1768
+ data.shadowElem.css({overflow: 'hidden'});
1769
+ }, 16);
1770
+ }
1771
+ }
1772
+ };
1773
+ if(!data || !data.jwapi){return;}
1774
+ if(!data.tryedReframeing){
1775
+ data.tryedReframeing = 0;
1776
+ }
1777
+ clearTimeout(localConnectionTimer);
1778
+ data.jwData = jwData;
1779
+ data.shadowElem.removeClass('flashblocker-assumed');
1780
+ $.prop(data._elem, 'volume', data.volume);
1781
+ $.prop(data._elem, 'muted', data.muted);
1782
+ doneFn();
1783
+
1784
+ };
1785
+
1786
+ var addMediaToStopEvents = $.noop;
1787
+ if(hasNative){
1788
+ var stopEvents = {
1789
+ play: 1,
1790
+ playing: 1
1791
+ };
1792
+ var hideEvtArray = ['play', 'pause', 'playing', 'canplay', 'progress', 'waiting', 'ended', 'loadedmetadata', 'durationchange', 'emptied'];
1793
+ var hidevents = hideEvtArray.map(function(evt){
1794
+ return evt +'.webshimspolyfill';
1795
+ }).join(' ');
1796
+
1797
+ var hidePlayerEvents = function(event){
1798
+ var data = webshims.data(event.target, 'mediaelement');
1799
+ if(!data){return;}
1800
+ var isNativeHTML5 = ( event.originalEvent && event.originalEvent.type === event.type );
1801
+ if( isNativeHTML5 == (data.activating == 'third') ){
1802
+ event.stopImmediatePropagation();
1803
+ if(stopEvents[event.type] && data.isActive != data.activating){
1804
+ $(event.target).pause();
1805
+ }
1806
+ }
1807
+ };
1808
+
1809
+ addMediaToStopEvents = function(elem){
1810
+ $(elem)
1811
+ .off(hidevents)
1812
+ .on(hidevents, hidePlayerEvents)
1813
+ ;
1814
+ hideEvtArray.forEach(function(evt){
1815
+ webshims.moveToFirstEvent(elem, evt);
1816
+ });
1817
+ };
1818
+ addMediaToStopEvents(document);
1819
+ }
1820
+
1821
+
1822
+ mediaelement.setActive = function(elem, type, data){
1823
+ if(!data){
1824
+ data = webshims.data(elem, 'mediaelement');
1825
+ }
1826
+ if(!data || data.isActive == type){return;}
1827
+ if(type != 'html5' && type != 'third'){
1828
+ webshims.warn('wrong type for mediaelement activating: '+ type);
1829
+ }
1830
+ var shadowData = webshims.data(elem, 'shadowData');
1831
+ data.activating = type;
1832
+ $(elem).pause();
1833
+ data.isActive = type;
1834
+ if(type == 'third'){
1835
+ shadowData.shadowElement = shadowData.shadowFocusElement = data.shadowElem[0];
1836
+ $(elem).addClass('swf-api-active nonnative-api-active').hide().getShadowElement().show();
1837
+ } else {
1838
+ $(elem).removeClass('swf-api-active nonnative-api-active').show().getShadowElement().hide();
1839
+ shadowData.shadowElement = shadowData.shadowFocusElement = false;
1840
+ }
1841
+ $(elem).trigger('mediaelementapichange');
1842
+ };
1843
+
1844
+
1845
+
1846
+ var resetSwfProps = (function(){
1847
+ var resetProtoProps = ['_bufferedEnd', '_bufferedStart', '_metadata', '_ppFlag', 'currentSrc', 'currentTime', 'duration', 'ended', 'networkState', 'paused', 'videoHeight', 'videoWidth', '_callMeta', '_durationCalcs'];
1848
+ var len = resetProtoProps.length;
1849
+ return function(data){
1850
+
1851
+ if(!data){return;}
1852
+ var lenI = len;
1853
+ var networkState = data.networkState;
1854
+ setReadyState(0, data);
1855
+ while(--lenI){
1856
+ delete data[resetProtoProps[lenI]];
1857
+ }
1858
+ data.actionQueue = [];
1859
+ data.buffered.length = 0;
1860
+ if(networkState){
1861
+ trigger(data._elem, 'emptied');
1862
+ }
1863
+ };
1864
+ })();
1865
+
1866
+ var setElementDimension = function(data, hasControls){
1867
+ var elem = data._elem;
1868
+ var box = data.shadowElem;
1869
+ $(elem)[hasControls ? 'addClass' : 'removeClass']('webshims-controls');
1870
+ if(data._elemNodeName == 'audio' && !hasControls){
1871
+ box.css({width: 0, height: 0});
1872
+ } else {
1873
+ box.css({
1874
+ width: elem.style.width || $(elem).width(),
1875
+ height: elem.style.height || $(elem).height()
1876
+ });
1877
+ }
1878
+ };
1879
+
1880
+ mediaelement.createSWF = function( elem, canPlaySrc, data ){
1881
+ if(!hasFlash){
1882
+ setTimeout(function(){
1883
+ $(elem).mediaLoad(); //<- this should produce a mediaerror
1884
+ }, 1);
1885
+ return;
1886
+ }
1887
+
1888
+ if(loadedSwf < 1){
1889
+ loadedSwf = 1;
1890
+ } else {
1891
+ loadedSwf++;
1892
+ }
1893
+ var vars = $.extend({}, options.vars, {
1894
+ image: $.prop(elem, 'poster') || '',
1895
+ file: canPlaySrc.srcProp
1896
+ });
1897
+ var elemVars = $(elem).data('vars') || {};
1898
+
1899
+ if(!data){
1900
+ data = webshims.data(elem, 'mediaelement');
1901
+ }
1902
+
1903
+ if(data && data.swfCreated){
1904
+ mediaelement.setActive(elem, 'third', data);
1905
+ resetSwfProps(data);
1906
+ data.currentSrc = canPlaySrc.srcProp;
1907
+ $.extend(vars, elemVars);
1908
+ options.changeSWF(vars, elem, canPlaySrc, data, 'load');
1909
+ queueSwfMethod(elem, SENDEVENT, ['LOAD', vars]);
1910
+ return;
1911
+ }
1912
+
1913
+
1914
+ var hasControls = $.prop(elem, 'controls');
1915
+ var elemId = 'jwplayer-'+ webshims.getID(elem);
1916
+ var params = $.extend(
1917
+ {},
1918
+ options.params,
1919
+ $(elem).data('params')
1920
+ );
1921
+ var elemNodeName = elem.nodeName.toLowerCase();
1922
+ var attrs = $.extend(
1923
+ {},
1924
+ options.attrs,
1925
+ {
1926
+ name: elemId,
1927
+ id: elemId
1928
+ },
1929
+ $(elem).data('attrs')
1930
+ );
1931
+ var box = $('<div class="polyfill-'+ (elemNodeName) +' polyfill-mediaelement" id="wrapper-'+ elemId +'"><div id="'+ elemId +'"></div>')
1932
+ .css({
1933
+ position: 'relative',
1934
+ overflow: 'hidden'
1935
+ })
1936
+ ;
1937
+ data = webshims.data(elem, 'mediaelement', webshims.objectCreate(playerStateObj, {
1938
+ actionQueue: {
1939
+ value: []
1940
+ },
1941
+ shadowElem: {
1942
+ value: box
1943
+ },
1944
+ _elemNodeName: {
1945
+ value: elemNodeName
1946
+ },
1947
+ _elem: {
1948
+ value: elem
1949
+ },
1950
+ currentSrc: {
1951
+ value: canPlaySrc.srcProp
1952
+ },
1953
+ swfCreated: {
1954
+ value: true
1955
+ },
1956
+ buffered: {
1957
+ value: {
1958
+ start: function(index){
1959
+ if(index >= data.buffered.length){
1960
+ webshims.error('buffered index size error');
1961
+ return;
1962
+ }
1963
+ return 0;
1964
+ },
1965
+ end: function(index){
1966
+ if(index >= data.buffered.length){
1967
+ webshims.error('buffered index size error');
1968
+ return;
1969
+ }
1970
+ return ( (data.duration - data._bufferedStart) * data._bufferedEnd / 100) + data._bufferedStart;
1971
+ },
1972
+ length: 0
1973
+ }
1974
+ }
1975
+ }));
1976
+
1977
+ setElementDimension(data, hasControls);
1978
+
1979
+ box.insertBefore(elem);
1980
+
1981
+ if(hasNative){
1982
+ $.extend(data, {volume: $.prop(elem, 'volume'), muted: $.prop(elem, 'muted')});
1983
+ }
1984
+
1985
+ $.extend(vars,
1986
+ {
1987
+ id: elemId,
1988
+ controlbar: hasControls ? options.vars.controlbar || (elemNodeName == 'video' ? 'over' : 'bottom') : (elemNodeName == 'video') ? 'none' : 'bottom',
1989
+ icons: ''+ (hasControls && elemNodeName == 'video')
1990
+ },
1991
+ elemVars,
1992
+ {playerready: 'jQuery.webshims.mediaelement.jwPlayerReady'}
1993
+ );
1994
+ if(vars.plugins){
1995
+ vars.plugins += ','+jwplugin;
1996
+ } else {
1997
+ vars.plugins = jwplugin;
1998
+ }
1999
+
2000
+
2001
+ webshims.addShadowDom(elem, box);
2002
+
2003
+ addMediaToStopEvents(elem);
2004
+
2005
+ mediaelement.setActive(elem, 'third', data);
2006
+
2007
+ options.changeSWF(vars, elem, canPlaySrc, data, 'embed');
2008
+
2009
+ $(elem).on('updatemediaelementdimensions updateshadowdom', function(){
2010
+ setElementDimension(data, $.prop(elem, 'controls'));
2011
+ });
2012
+
2013
+
2014
+ swfobject.embedSWF(playerSwfPath, elemId, "100%", "100%", "9.0.0", false, vars, params, attrs, function(swfData){
2015
+
2016
+ if(swfData.success){
2017
+ data.jwapi = swfData.ref;
2018
+
2019
+ if(!hasControls){
2020
+ $(swfData.ref).attr('tabindex', '-1').css('outline', 'none');
2021
+ }
2022
+ setTimeout(function(){
2023
+ if((!swfData.ref.parentNode && box[0].parentNode) || swfData.ref.style.display == "none"){
2024
+ box.addClass('flashblocker-assumed');
2025
+ $(elem).trigger('flashblocker');
2026
+ webshims.warn("flashblocker assumed");
2027
+ }
2028
+ $(swfData.ref).css({'minHeight': '2px', 'minWidth': '2px', display: 'block'});
2029
+ }, 9);
2030
+ if(!localConnectionTimer){
2031
+ clearTimeout(localConnectionTimer);
2032
+ localConnectionTimer = setTimeout(function(){
2033
+ var flash = $(swfData.ref);
2034
+ if(flash[0].offsetWidth > 1 && flash[0].offsetHeight > 1 && location.protocol.indexOf('file:') === 0){
2035
+ webshims.error("Add your local development-directory to the local-trusted security sandbox: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html");
2036
+ } else if(flash[0].offsetWidth < 2 || flash[0].offsetHeight < 2) {
2037
+ webshims.warn("JS-SWF connection can't be established on hidden or unconnected flash objects");
2038
+ }
2039
+ flash = null;
2040
+ }, 8000);
2041
+ }
2042
+ }
2043
+ });
2044
+ };
2045
+
2046
+
2047
+ var queueSwfMethod = function(elem, fn, args, data){
2048
+ data = data || getSwfDataFromElem(elem);
2049
+ if(data){
2050
+ if(data.jwapi && data.jwapi[fn]){
2051
+ data.jwapi[fn].apply(data.jwapi, args || []);
2052
+ } else {
2053
+ //todo add to queue
2054
+ data.actionQueue.push({fn: fn, args: args});
2055
+ if(data.actionQueue.length > 10){
2056
+ setTimeout(function(){
2057
+ if(data.actionQueue.length > 5){
2058
+ data.actionQueue.shift();
2059
+ }
2060
+ }, 99);
2061
+ }
2062
+ }
2063
+ return data;
2064
+ }
2065
+ return false;
2066
+ };
2067
+
2068
+ ['audio', 'video'].forEach(function(nodeName){
2069
+ var descs = {};
2070
+ var mediaSup;
2071
+ var createGetProp = function(key){
2072
+ if(nodeName == 'audio' && (key == 'videoHeight' || key == 'videoWidth')){return;}
2073
+
2074
+ descs[key] = {
2075
+ get: function(){
2076
+ var data = getSwfDataFromElem(this);
2077
+ if(data){
2078
+ return data[key];
2079
+ } else if(hasNative && mediaSup[key].prop._supget) {
2080
+ return mediaSup[key].prop._supget.apply(this);
2081
+ } else {
2082
+ return playerStateObj[key];
2083
+ }
2084
+ },
2085
+ writeable: false
2086
+ };
2087
+ };
2088
+ var createGetSetProp = function(key, setFn){
2089
+ createGetProp(key);
2090
+ delete descs[key].writeable;
2091
+ descs[key].set = setFn;
2092
+ };
2093
+
2094
+ createGetSetProp('volume', function(v){
2095
+ var data = getSwfDataFromElem(this);
2096
+ if(data){
2097
+ v *= 100;
2098
+ if(!isNaN(v)){
2099
+ var muted = data.muted;
2100
+ if(v < 0 || v > 100){
2101
+ webshims.error('volume greater or less than allowed '+ (v / 100));
2102
+ }
2103
+
2104
+ queueSwfMethod(this, SENDEVENT, ['VOLUME', v], data);
2105
+ if(muted){
2106
+ try {
2107
+ data.jwapi.sendEvent('mute', 'true');
2108
+ } catch(er){}
2109
+ }
2110
+ v /= 100;
2111
+ if(data.volume == v || data.isActive != 'third'){return;}
2112
+ data.volume = v;
2113
+ trigger(data._elem, 'volumechange');
2114
+ data = null;
2115
+ }
2116
+ } else if(mediaSup.volume.prop._supset) {
2117
+ return mediaSup.volume.prop._supset.apply(this, arguments);
2118
+ }
2119
+ });
2120
+
2121
+ createGetSetProp('muted', function(m){
2122
+ var data = getSwfDataFromElem(this);
2123
+ if(data){
2124
+ m = !!m;
2125
+ queueSwfMethod(this, SENDEVENT, ['mute', ''+m], data);
2126
+ if(data.muted == m || data.isActive != 'third'){return;}
2127
+ data.muted = m;
2128
+ trigger(data._elem, 'volumechange');
2129
+ data = null;
2130
+ } else if(mediaSup.muted.prop._supset) {
2131
+ return mediaSup.muted.prop._supset.apply(this, arguments);
2132
+ }
2133
+ });
2134
+
2135
+
2136
+ createGetSetProp('currentTime', function(t){
2137
+ var data = getSwfDataFromElem(this);
2138
+ if(data){
2139
+ t *= 1;
2140
+ if (!isNaN(t)) {
2141
+ if(data.paused){
2142
+ clearTimeout(data.stopPlayPause);
2143
+ data.stopPlayPause = setTimeout(function(){
2144
+ data.paused = true;
2145
+ data.stopPlayPause = false;
2146
+ }, 50);
2147
+ }
2148
+ queueSwfMethod(this, SENDEVENT, ['SEEK', '' + t], data);
2149
+
2150
+ if(data.paused){
2151
+ if(data.readyState > 0){
2152
+ data.currentTime = t;
2153
+ trigger(data._elem, 'timeupdate');
2154
+ }
2155
+ try {
2156
+ data.jwapi[SENDEVENT]('play', 'false');
2157
+ } catch(er){}
2158
+
2159
+ }
2160
+ }
2161
+
2162
+ } else if(mediaSup.currentTime.prop._supset) {
2163
+ return mediaSup.currentTime.prop._supset.apply(this, arguments);
2164
+ }
2165
+ });
2166
+
2167
+ ['play', 'pause'].forEach(function(fn){
2168
+ descs[fn] = {
2169
+ value: function(){
2170
+ var data = getSwfDataFromElem(this);
2171
+ if(data){
2172
+ if(data.stopPlayPause){
2173
+ clearTimeout(data.stopPlayPause);
2174
+ }
2175
+ queueSwfMethod(this, SENDEVENT, ['play', fn == 'play'], data);
2176
+ setTimeout(function(){
2177
+ if(data.isActive == 'third'){
2178
+ data._ppFlag = true;
2179
+ if(data.paused != (fn != 'play')){
2180
+ data.paused = fn != 'play';
2181
+ trigger(data._elem, fn);
2182
+ }
2183
+ }
2184
+ }, 1);
2185
+ } else if(mediaSup[fn].prop._supvalue) {
2186
+ return mediaSup[fn].prop._supvalue.apply(this, arguments);
2187
+ }
2188
+ }
2189
+ };
2190
+ });
2191
+
2192
+ getPropKeys.forEach(createGetProp);
2193
+
2194
+ webshims.onNodeNamesPropertyModify(nodeName, 'controls', function(val, boolProp){
2195
+ var data = getSwfDataFromElem(this);
2196
+ $(this)[boolProp ? 'addClass' : 'removeClass']('webshims-controls');
2197
+
2198
+ if(data){
2199
+ try {
2200
+ queueSwfMethod(this, boolProp ? 'showControls' : 'hideControls', [nodeName], data);
2201
+ } catch(er){
2202
+ webshims.warn("you need to generate a crossdomain.xml");
2203
+ }
2204
+ if(nodeName == 'audio'){
2205
+ setElementDimension(data, boolProp);
2206
+ }
2207
+ $(data.jwapi).attr('tabindex', boolProp ? '0' : '-1');
2208
+ }
2209
+ });
2210
+
2211
+ mediaSup = webshims.defineNodeNameProperties(nodeName, descs, 'prop');
2212
+ });
2213
+
2214
+ if(hasFlash){
2215
+ var oldClean = $.cleanData;
2216
+ var gcBrowser = $.browser.msie && webshims.browserVersion < 9;
2217
+ var flashNames = {
2218
+ object: 1,
2219
+ OBJECT: 1
2220
+ };
2221
+ $.cleanData = function(elems){
2222
+ var i, len, prop;
2223
+ if(elems && (len = elems.length) && loadedSwf){
2224
+
2225
+ for(i = 0; i < len; i++){
2226
+ if(flashNames[elems[i].nodeName]){
2227
+ if(SENDEVENT in elems[i]){
2228
+ loadedSwf--;
2229
+ try {
2230
+ elems[i][SENDEVENT]('play', false);
2231
+ } catch(er){}
2232
+ }
2233
+ if(gcBrowser){
2234
+ try {
2235
+ for (prop in elems[i]) {
2236
+ if (typeof elems[i][prop] == "function") {
2237
+ elems[i][prop] = null;
2238
+ }
2239
+ }
2240
+ } catch(er){}
2241
+ }
2242
+ }
2243
+ }
2244
+
2245
+ }
2246
+ return oldClean.apply(this, arguments);
2247
+ };
2248
+ }
2249
+
2250
+ if(!hasNative){
2251
+
2252
+ ['poster', 'src'].forEach(function(prop){
2253
+ webshims.defineNodeNamesProperty(prop == 'src' ? ['audio', 'video', 'source'] : ['video'], prop, {
2254
+ //attr: {},
2255
+ reflect: true,
2256
+ propType: 'src'
2257
+ });
2258
+ });
2259
+
2260
+
2261
+ ['autoplay', 'controls'].forEach(function(name){
2262
+ webshims.defineNodeNamesBooleanProperty(['audio', 'video'], name);
2263
+ });
2264
+
2265
+ webshims.defineNodeNamesProperties(['audio', 'video'], {
2266
+ HAVE_CURRENT_DATA: {
2267
+ value: 2
2268
+ },
2269
+ HAVE_ENOUGH_DATA: {
2270
+ value: 4
2271
+ },
2272
+ HAVE_FUTURE_DATA: {
2273
+ value: 3
2274
+ },
2275
+ HAVE_METADATA: {
2276
+ value: 1
2277
+ },
2278
+ HAVE_NOTHING: {
2279
+ value: 0
2280
+ },
2281
+ NETWORK_EMPTY: {
2282
+ value: 0
2283
+ },
2284
+ NETWORK_IDLE: {
2285
+ value: 1
2286
+ },
2287
+ NETWORK_LOADING: {
2288
+ value: 2
2289
+ },
2290
+ NETWORK_NO_SOURCE: {
2291
+ value: 3
2292
+ }
2293
+
2294
+ }, 'prop');
2295
+ }
2409
2296
  });