webshims-rails 0.4.7 → 1.10.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +15 -0
  2. data/lib/webshims-rails/version.rb +2 -2
  3. data/vendor/assets/javascripts/webshims/extras/custom-validity.js +1 -1
  4. data/vendor/assets/javascripts/webshims/extras/mousepress.js +1 -1
  5. data/vendor/assets/javascripts/webshims/polyfiller.js +197 -166
  6. data/vendor/assets/javascripts/webshims/shims/combos/1.js +1711 -1609
  7. data/vendor/assets/javascripts/webshims/shims/combos/10.js +2575 -2253
  8. data/vendor/assets/javascripts/webshims/shims/combos/11.js +2452 -1476
  9. data/vendor/assets/javascripts/webshims/shims/combos/12.js +1405 -1159
  10. data/vendor/assets/javascripts/webshims/shims/combos/13.js +1316 -963
  11. data/vendor/assets/javascripts/webshims/shims/combos/14.js +1862 -179
  12. data/vendor/assets/javascripts/webshims/shims/combos/15.js +4327 -287
  13. data/vendor/assets/javascripts/webshims/shims/combos/16.js +3887 -586
  14. data/vendor/assets/javascripts/webshims/shims/combos/17.js +2911 -2159
  15. data/vendor/assets/javascripts/webshims/shims/combos/18.js +3425 -1730
  16. data/vendor/assets/javascripts/webshims/shims/combos/19.js +2854 -1203
  17. data/vendor/assets/javascripts/webshims/shims/combos/2.js +3351 -2130
  18. data/vendor/assets/javascripts/webshims/shims/combos/20.js +2426 -581
  19. data/vendor/assets/javascripts/webshims/shims/combos/21.js +1915 -1574
  20. data/vendor/assets/javascripts/webshims/shims/combos/22.js +864 -2275
  21. data/vendor/assets/javascripts/webshims/shims/combos/23.js +609 -1811
  22. data/vendor/assets/javascripts/webshims/shims/combos/3.js +1655 -2736
  23. data/vendor/assets/javascripts/webshims/shims/combos/4.js +1037 -603
  24. data/vendor/assets/javascripts/webshims/shims/combos/5.js +3100 -773
  25. data/vendor/assets/javascripts/webshims/shims/combos/6.js +3631 -840
  26. data/vendor/assets/javascripts/webshims/shims/combos/7.js +3596 -1354
  27. data/vendor/assets/javascripts/webshims/shims/combos/8.js +1731 -188
  28. data/vendor/assets/javascripts/webshims/shims/combos/9.js +3243 -1431
  29. data/vendor/assets/javascripts/webshims/shims/dom-extend.js +107 -18
  30. data/vendor/assets/javascripts/webshims/shims/es5.js +1 -0
  31. data/vendor/assets/javascripts/webshims/shims/form-core.js +553 -464
  32. data/vendor/assets/javascripts/webshims/shims/form-datalist.js +160 -154
  33. data/vendor/assets/javascripts/webshims/shims/form-message.js +73 -49
  34. data/vendor/assets/javascripts/webshims/shims/form-native-extend.js +18 -1
  35. data/vendor/assets/javascripts/webshims/shims/form-number-date-api.js +161 -36
  36. data/vendor/assets/javascripts/webshims/shims/form-number-date-ui.js +2130 -813
  37. data/vendor/assets/javascripts/webshims/shims/form-shim-extend.js +206 -58
  38. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-ar.js → formcfg-ar.js} +30 -0
  39. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-ch-ZN.js → formcfg-ch-ZN.js} +31 -0
  40. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-de.txt → formcfg-de.txt} +50 -11
  41. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-el.js → formcfg-el.js} +31 -0
  42. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-en.txt → formcfg-en.txt} +44 -11
  43. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-es.js → formcfg-es.js} +31 -0
  44. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-fr.js → formcfg-fr.js} +31 -0
  45. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-he.js → formcfg-he.js} +31 -0
  46. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-hi.js → formcfg-hi.js} +31 -0
  47. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-hu.js → formcfg-hu.js} +31 -0
  48. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-it.js → formcfg-it.js} +31 -0
  49. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-ja.js → formcfg-ja.js} +31 -0
  50. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-nl.js → formcfg-nl.js} +31 -0
  51. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-pt-PT.js → formcfg-pt-PT.js} +31 -0
  52. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-ru.js → formcfg-ru.js} +31 -0
  53. data/vendor/assets/javascripts/webshims/shims/i18n/{errormessages-sv.js → formcfg-sv.js} +32 -0
  54. data/vendor/assets/javascripts/webshims/shims/json-storage.js +16 -10
  55. data/vendor/assets/javascripts/webshims/shims/mediaelement-core.js +155 -122
  56. data/vendor/assets/javascripts/webshims/shims/mediaelement-jaris.js +76 -41
  57. data/vendor/assets/javascripts/webshims/shims/mediaelement-yt.js +8 -16
  58. data/vendor/assets/javascripts/webshims/shims/range-ui.js +388 -0
  59. data/vendor/assets/javascripts/webshims/shims/styles/config.rb +12 -0
  60. data/vendor/assets/javascripts/webshims/shims/styles/forms.png +0 -0
  61. data/vendor/assets/javascripts/webshims/shims/styles/scss/shim.scss +1186 -0
  62. data/vendor/assets/javascripts/webshims/shims/styles/shim.css +868 -548
  63. data/vendor/assets/javascripts/webshims/shims/styles/vertical-range.png +0 -0
  64. data/vendor/assets/javascripts/webshims/shims/swf/JarisFLVPlayer.swf +0 -0
  65. data/vendor/assets/javascripts/webshims/shims/swfmini.js +497 -0
  66. data/vendor/assets/javascripts/webshims/shims/track-ui.js +3 -0
  67. data/vendor/assets/javascripts/webshims/shims/track.js +29 -29
  68. metadata +26 -125
  69. data/vendor/assets/javascripts/webshims/minified/extras/custom-validity.js +0 -1
  70. data/vendor/assets/javascripts/webshims/minified/extras/modernizr-custom.js +0 -1
  71. data/vendor/assets/javascripts/webshims/minified/extras/mousepress.js +0 -1
  72. data/vendor/assets/javascripts/webshims/minified/polyfiller.js +0 -1
  73. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/canvas2png.js +0 -1
  74. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/flashcanvas.js +0 -1
  75. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/flashcanvas.swf +0 -0
  76. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/proxy.php +0 -73
  77. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvas/save.php +0 -49
  78. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/canvas2png.js +0 -1
  79. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/flash10canvas.swf +0 -0
  80. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/flash9canvas.swf +0 -0
  81. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/flashcanvas.js +0 -1
  82. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/proxy.php +0 -73
  83. data/vendor/assets/javascripts/webshims/minified/shims/FlashCanvasPro/save.php +0 -49
  84. data/vendor/assets/javascripts/webshims/minified/shims/combos/1.js +0 -1
  85. data/vendor/assets/javascripts/webshims/minified/shims/combos/10.js +0 -1
  86. data/vendor/assets/javascripts/webshims/minified/shims/combos/11.js +0 -1
  87. data/vendor/assets/javascripts/webshims/minified/shims/combos/12.js +0 -1
  88. data/vendor/assets/javascripts/webshims/minified/shims/combos/13.js +0 -1
  89. data/vendor/assets/javascripts/webshims/minified/shims/combos/14.js +0 -1
  90. data/vendor/assets/javascripts/webshims/minified/shims/combos/15.js +0 -1
  91. data/vendor/assets/javascripts/webshims/minified/shims/combos/16.js +0 -1
  92. data/vendor/assets/javascripts/webshims/minified/shims/combos/17.js +0 -1
  93. data/vendor/assets/javascripts/webshims/minified/shims/combos/18.js +0 -1
  94. data/vendor/assets/javascripts/webshims/minified/shims/combos/19.js +0 -1
  95. data/vendor/assets/javascripts/webshims/minified/shims/combos/2.js +0 -1
  96. data/vendor/assets/javascripts/webshims/minified/shims/combos/20.js +0 -1
  97. data/vendor/assets/javascripts/webshims/minified/shims/combos/21.js +0 -1
  98. data/vendor/assets/javascripts/webshims/minified/shims/combos/22.js +0 -1
  99. data/vendor/assets/javascripts/webshims/minified/shims/combos/23.js +0 -1
  100. data/vendor/assets/javascripts/webshims/minified/shims/combos/24.js +0 -1
  101. data/vendor/assets/javascripts/webshims/minified/shims/combos/25.js +0 -1
  102. data/vendor/assets/javascripts/webshims/minified/shims/combos/26.js +0 -1
  103. data/vendor/assets/javascripts/webshims/minified/shims/combos/27.js +0 -1
  104. data/vendor/assets/javascripts/webshims/minified/shims/combos/3.js +0 -1
  105. data/vendor/assets/javascripts/webshims/minified/shims/combos/4.js +0 -1
  106. data/vendor/assets/javascripts/webshims/minified/shims/combos/5.js +0 -1
  107. data/vendor/assets/javascripts/webshims/minified/shims/combos/59.js +0 -1
  108. data/vendor/assets/javascripts/webshims/minified/shims/combos/6.js +0 -1
  109. data/vendor/assets/javascripts/webshims/minified/shims/combos/7.js +0 -1
  110. data/vendor/assets/javascripts/webshims/minified/shims/combos/8.js +0 -1
  111. data/vendor/assets/javascripts/webshims/minified/shims/combos/9.js +0 -1
  112. data/vendor/assets/javascripts/webshims/minified/shims/details.js +0 -1
  113. data/vendor/assets/javascripts/webshims/minified/shims/dom-extend.js +0 -1
  114. data/vendor/assets/javascripts/webshims/minified/shims/es5.js +0 -1
  115. data/vendor/assets/javascripts/webshims/minified/shims/excanvas.js +0 -1
  116. data/vendor/assets/javascripts/webshims/minified/shims/form-core.js +0 -1
  117. data/vendor/assets/javascripts/webshims/minified/shims/form-datalist.js +0 -1
  118. data/vendor/assets/javascripts/webshims/minified/shims/form-message.js +0 -1
  119. data/vendor/assets/javascripts/webshims/minified/shims/form-native-extend.js +0 -1
  120. data/vendor/assets/javascripts/webshims/minified/shims/form-number-date-api.js +0 -1
  121. data/vendor/assets/javascripts/webshims/minified/shims/form-number-date-ui.js +0 -1
  122. data/vendor/assets/javascripts/webshims/minified/shims/form-shim-extend.js +0 -1
  123. data/vendor/assets/javascripts/webshims/minified/shims/geolocation.js +0 -1
  124. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-ar.js +0 -1
  125. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-ch-ZN.js +0 -1
  126. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-de.txt +0 -33
  127. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-el.js +0 -1
  128. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-en.txt +0 -34
  129. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-es.js +0 -1
  130. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-fr.js +0 -1
  131. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-he.js +0 -1
  132. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-hi.js +0 -1
  133. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-hu.js +0 -1
  134. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-it.js +0 -1
  135. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-ja.js +0 -1
  136. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-nl.js +0 -1
  137. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-pt-PT.js +0 -1
  138. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-ru.js +0 -1
  139. data/vendor/assets/javascripts/webshims/minified/shims/i18n/errormessages-sv.js +0 -1
  140. data/vendor/assets/javascripts/webshims/minified/shims/json-storage.js +0 -1
  141. data/vendor/assets/javascripts/webshims/minified/shims/jwplayer/license.txt +0 -1
  142. data/vendor/assets/javascripts/webshims/minified/shims/jwplayer/player.swf +0 -0
  143. data/vendor/assets/javascripts/webshims/minified/shims/jwplayer/readme.html +0 -87
  144. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-core.js +0 -1
  145. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-jaris.js +0 -1
  146. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-native-fix.js +0 -1
  147. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-swf.js +0 -1
  148. data/vendor/assets/javascripts/webshims/minified/shims/mediaelement-yt.js +0 -1
  149. data/vendor/assets/javascripts/webshims/minified/shims/styles/details-arrows.png +0 -0
  150. data/vendor/assets/javascripts/webshims/minified/shims/styles/forms.png +0 -0
  151. data/vendor/assets/javascripts/webshims/minified/shims/styles/polyfill-loader.gif +0 -0
  152. data/vendor/assets/javascripts/webshims/minified/shims/styles/shim.css +0 -1
  153. data/vendor/assets/javascripts/webshims/minified/shims/swf/JarisFLVPlayer.swf +0 -0
  154. data/vendor/assets/javascripts/webshims/minified/shims/swf/jwwebshims.swf +0 -0
  155. data/vendor/assets/javascripts/webshims/minified/shims/swf/localStorage.swf +0 -0
  156. data/vendor/assets/javascripts/webshims/minified/shims/track-ui.js +0 -1
  157. data/vendor/assets/javascripts/webshims/minified/shims/track.js +0 -1
  158. data/vendor/assets/javascripts/webshims/shims/FlashCanvas/README +0 -62
  159. data/vendor/assets/javascripts/webshims/shims/FlashCanvasPro/README +0 -82
  160. data/vendor/assets/javascripts/webshims/shims/combos/24.js +0 -2872
  161. data/vendor/assets/javascripts/webshims/shims/combos/25.js +0 -2376
  162. data/vendor/assets/javascripts/webshims/shims/combos/26.js +0 -3009
  163. data/vendor/assets/javascripts/webshims/shims/combos/27.js +0 -4150
  164. data/vendor/assets/javascripts/webshims/shims/combos/59.js +0 -1747
  165. data/vendor/assets/javascripts/webshims/shims/jwplayer/license.txt +0 -1
  166. data/vendor/assets/javascripts/webshims/shims/jwplayer/player.swf +0 -0
  167. data/vendor/assets/javascripts/webshims/shims/jwplayer/readme.html +0 -87
  168. data/vendor/assets/javascripts/webshims/shims/mediaelement-swf.js +0 -972
@@ -1,2378 +1,967 @@
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
- if (advancedObjectProperties && Object[defineProperty] && Object.prototype.__defineGetter__) {
668
- (function(){
669
- try {
670
- var foo = document.createElement('foo');
671
- Object[defineProperty](foo, 'bar', {
672
- get: function(){
673
- return true;
674
- }
675
- });
676
- advancedObjectProperties = !!foo.bar;
677
- }
678
- catch (e) {
679
- advancedObjectProperties = false;
680
- }
681
- foo = null;
682
- })();
683
- }
684
-
685
- Modernizr.objectAccessor = !!((advancedObjectProperties || (Object.prototype.__defineGetter__ && Object.prototype.__lookupSetter__)));
686
- Modernizr.advancedObjectProperties = advancedObjectProperties;
687
-
688
- if((!advancedObjectProperties || !Object.create || !Object.defineProperties || !Object.getOwnPropertyDescriptor || !Object.defineProperty)){
689
- var call = Function.prototype.call;
690
- var prototypeOfObject = Object.prototype;
691
- var owns = call.bind(prototypeOfObject.hasOwnProperty);
692
-
693
- shims.objectCreate = function(proto, props, opts, no__proto__){
694
- var o;
695
- var f = function(){};
696
-
697
- f.prototype = proto;
698
- o = new f();
699
-
700
- if(!no__proto__ && !('__proto__' in o) && !Modernizr.objectAccessor){
701
- o.__proto__ = proto;
702
- }
703
-
704
- if(props){
705
- shims.defineProperties(o, props);
706
- }
707
-
708
- if(opts){
709
- o.options = jQuery.extend(true, {}, o.options || {}, opts);
710
- opts = o.options;
711
- }
712
-
713
- if(o._create && jQuery.isFunction(o._create)){
714
- o._create(opts);
715
- }
716
- return o;
717
- };
718
-
719
- shims.defineProperties = function(object, props){
720
- for (var name in props) {
721
- if (owns(props, name)) {
722
- shims.defineProperty(object, name, props[name]);
723
- }
724
- }
725
- return object;
726
- };
727
-
728
- var descProps = ['configurable', 'enumerable', 'writable'];
729
- shims.defineProperty = function(proto, property, descriptor){
730
- if(typeof descriptor != "object" || descriptor === null){return proto;}
731
-
732
- if(owns(descriptor, "value")){
733
- proto[property] = descriptor.value;
734
- return proto;
735
- }
736
-
737
- if(proto.__defineGetter__){
738
- if (typeof descriptor.get == "function") {
739
- proto.__defineGetter__(property, descriptor.get);
740
- }
741
- if (typeof descriptor.set == "function"){
742
- proto.__defineSetter__(property, descriptor.set);
743
- }
744
- }
745
- return proto;
746
- };
747
-
748
- shims.getPrototypeOf = function (object) {
749
- return Object.getPrototypeOf && Object.getPrototypeOf(object) || object.__proto__ || object.constructor && object.constructor.prototype;
750
- };
751
-
752
- //based on http://www.refactory.org/s/object_getownpropertydescriptor/view/latest
753
- shims.getOwnPropertyDescriptor = function(obj, prop){
754
- if (typeof obj !== "object" && typeof obj !== "function" || obj === null){
755
- throw new TypeError("Object.getOwnPropertyDescriptor called on a non-object");
756
- }
757
- var descriptor;
758
- if(Object.defineProperty && Object.getOwnPropertyDescriptor){
759
- try{
760
- descriptor = Object.getOwnPropertyDescriptor(obj, prop);
761
- return descriptor;
762
- } catch(e){}
763
- }
764
- descriptor = {
765
- configurable: true,
766
- enumerable: true,
767
- writable: true,
768
- value: undefined
769
- };
770
- var getter = obj.__lookupGetter__ && obj.__lookupGetter__(prop),
771
- setter = obj.__lookupSetter__ && obj.__lookupSetter__(prop)
772
- ;
773
-
774
- if (!getter && !setter) { // not an accessor so return prop
775
- if(!owns(obj, prop)){
776
- return;
777
- }
778
- descriptor.value = obj[prop];
779
- return descriptor;
780
- }
781
-
782
- // there is an accessor, remove descriptor.writable; populate descriptor.get and descriptor.set
783
- delete descriptor.writable;
784
- delete descriptor.value;
785
- descriptor.get = descriptor.set = undefined;
786
-
787
- if(getter){
788
- descriptor.get = getter;
789
- }
790
-
791
- if(setter){
792
- descriptor.set = setter;
793
- }
794
-
795
- return descriptor;
796
- };
797
-
798
- }
799
- })(jQuery, jQuery.webshims);
800
-
801
-
802
-
803
- (function($, Modernizr, webshims){
804
- "use strict";
805
- var hasNative = Modernizr.audio && Modernizr.video;
806
- var supportsLoop = false;
807
- var bugs = webshims.bugs;
808
-
809
- var loadSwf = function(){
810
- webshims.ready(swfType, function(){
811
- if(!webshims.mediaelement.createSWF){
812
- webshims.mediaelement.loadSwf = true;
813
- webshims.reTest([swfType], hasNative);
814
- }
815
- });
816
- };
817
- var options = webshims.cfg.mediaelement;
818
- var swfType = options && options.player == 'jwplayer' ? 'mediaelement-swf' : 'mediaelement-jaris';
819
- var hasSwf;
820
- if(!options){
821
- webshims.error("mediaelement wasn't implemented but loaded");
822
- return;
823
- }
824
- if(hasNative){
825
- var videoElem = document.createElement('video');
826
- Modernizr.videoBuffered = ('buffered' in videoElem);
827
- supportsLoop = ('loop' in videoElem);
828
-
829
- webshims.capturingEvents(['play', 'playing', 'waiting', 'paused', 'ended', 'durationchange', 'loadedmetadata', 'canplay', 'volumechange']);
830
-
831
- if(!Modernizr.videoBuffered){
832
- webshims.addPolyfill('mediaelement-native-fix', {
833
- f: 'mediaelement',
834
- test: Modernizr.videoBuffered,
835
- d: ['dom-support']
836
- });
837
-
838
- webshims.reTest('mediaelement-native-fix');
839
- }
840
- }
841
-
842
- if(hasNative && !options.preferFlash){
843
- var switchOptions = function(e){
844
- var parent = e.target.parentNode;
845
- if(!options.preferFlash && ($(e.target).is('audio, video') || (parent && $('source:last', parent)[0] == e.target)) ){
846
- webshims.ready('DOM mediaelement', function(){
847
- if(hasSwf){
848
- loadSwf();
1
+ jQuery.webshims.register('details', function($, webshims, window, doc, undefined, options){
2
+ var isInterActiveSummary = function(summary){
3
+ var details = $(summary).parent('details');
4
+ if(details[0] && details.children(':first').get(0) === summary){
5
+ return details;
6
+ }
7
+ };
8
+
9
+ var bindDetailsSummary = function(summary, details){
10
+ summary = $(summary);
11
+ details = $(details);
12
+ var oldSummary = $.data(details[0], 'summaryElement');
13
+ $.data(summary[0], 'detailsElement', details);
14
+ if(!oldSummary || summary[0] !== oldSummary[0]){
15
+ if(oldSummary){
16
+ if(oldSummary.hasClass('fallback-summary')){
17
+ oldSummary.remove();
18
+ } else {
19
+ oldSummary
20
+ .unbind('.summaryPolyfill')
21
+ .removeData('detailsElement')
22
+ .removeAttr('role')
23
+ .removeAttr('tabindex')
24
+ .removeAttr('aria-expanded')
25
+ .removeClass('summary-button')
26
+ .find('span.details-open-indicator')
27
+ .remove()
28
+ ;
29
+ }
30
+ }
31
+ $.data(details[0], 'summaryElement', summary);
32
+ details.prop('open', details.prop('open'));
33
+ }
34
+ };
35
+ var getSummary = function(details){
36
+ var summary = $.data(details, 'summaryElement');
37
+ if(!summary){
38
+ summary = $('> summary:first-child', details);
39
+ if(!summary[0]){
40
+ $(details).prependPolyfill('<summary class="fallback-summary">'+ options.text +'</summary>');
41
+ summary = $.data(details, 'summaryElement');
42
+ } else {
43
+ bindDetailsSummary(summary, details);
44
+ }
45
+ }
46
+ return summary;
47
+ };
48
+
49
+ // var isOriginalPrevented = function(e){
50
+ // var src = e.originalEvent;
51
+ // if(!src){return e.isDefaultPrevented();}
52
+ //
53
+ // return src.defaultPrevented || src.returnValue === false ||
54
+ // src.getPreventDefault && src.getPreventDefault();
55
+ // };
56
+
57
+ webshims.createElement('summary', function(){
58
+ var details = isInterActiveSummary(this);
59
+ if(!details || $.data(this, 'detailsElement')){return;}
60
+ var timer;
61
+ var stopNativeClickTest;
62
+ var tabindex = $.attr(this, 'tabIndex') || '0';
63
+ bindDetailsSummary(this, details);
64
+ $(this)
65
+ .on({
66
+ 'focus.summaryPolyfill': function(){
67
+ $(this).addClass('summary-has-focus');
68
+ },
69
+ 'blur.summaryPolyfill': function(){
70
+ $(this).removeClass('summary-has-focus');
71
+ },
72
+ 'mouseenter.summaryPolyfill': function(){
73
+ $(this).addClass('summary-has-hover');
74
+ },
75
+ 'mouseleave.summaryPolyfill': function(){
76
+ $(this).removeClass('summary-has-hover');
77
+ },
78
+ 'click.summaryPolyfill': function(e){
79
+ var details = isInterActiveSummary(this);
80
+ if(details){
81
+ if(!stopNativeClickTest && e.originalEvent){
82
+ stopNativeClickTest = true;
83
+ e.stopImmediatePropagation();
84
+ e.preventDefault();
85
+ $(this).trigger('click');
86
+ stopNativeClickTest = false;
87
+ return false;
88
+ } else {
89
+ clearTimeout(timer);
90
+
91
+ timer = setTimeout(function(){
92
+ if(!e.isDefaultPrevented()){
93
+ details.prop('open', !details.prop('open'));
94
+ }
95
+ }, 0);
96
+ }
849
97
  }
850
- webshims.ready('WINDOWLOAD '+swfType, function(){
851
- setTimeout(function(){
852
- if(hasSwf && !options.preferFlash && webshims.mediaelement.createSWF && !$(e.target).closest('audio, video').is('.nonnative-api-active')){
853
- options.preferFlash = true;
854
- document.removeEventListener('error', switchOptions, true);
855
- $('audio, video').each(function(){
856
- webshims.mediaelement.selectSource(this);
857
- });
858
- webshims.info("switching mediaelements option to 'preferFlash', due to an error with native player: "+e.target.src);
859
- } else if(!hasSwf){
860
- document.removeEventListener('error', switchOptions, true);
861
- }
862
- }, 20);
863
- });
864
- });
865
- }
866
- };
867
- document.addEventListener('error', switchOptions, true);
868
- $('audio, video').each(function(){
869
- if(this.error){
870
- switchOptions({target: this});
871
- }
872
- });
873
- }
874
-
875
-
876
- if(Modernizr.track && !bugs.track){
877
- (function(){
878
-
879
- if(!bugs.track){
880
- bugs.track = typeof $('<track />')[0].readyState != 'number';
881
- }
882
-
883
- if(!bugs.track){
884
- try {
885
- new TextTrackCue(2, 3, '');
886
- } catch(e){
887
- bugs.track = true;
888
- }
889
- }
890
-
891
- var trackOptions = webshims.cfg.track;
892
- var trackListener = function(e){
893
- $(e.target).filter('track').each(changeApi);
894
- };
895
- var changeApi = function(){
896
- if(bugs.track || (!trackOptions.override && $.prop(this, 'readyState') == 3)){
897
- trackOptions.override = true;
898
- webshims.reTest('track');
899
- document.removeEventListener('error', trackListener, true);
900
- if(this && $.nodeName(this, 'track')){
901
- webshims.error("track support was overwritten. Please check your vtt including your vtt mime-type");
902
- } else {
903
- webshims.info("track support was overwritten. due to bad browser support");
98
+ },
99
+ 'keydown.summaryPolyfill': function(e){
100
+ if( (e.keyCode == 13 || e.keyCode == 32) && !e.isDefaultPrevented()){
101
+ stopNativeClickTest = true;
102
+ e.preventDefault();
103
+ $(this).trigger('click');
104
+ stopNativeClickTest = false;
904
105
  }
905
106
  }
107
+ })
108
+ .attr({tabindex: tabindex, role: 'button'})
109
+ .prepend('<span class="details-open-indicator" />')
110
+ ;
111
+ webshims.moveToFirstEvent(this, 'click');
112
+ });
113
+
114
+ var initDetails;
115
+ webshims.defineNodeNamesBooleanProperty('details', 'open', function(val){
116
+ var summary = $($.data(this, 'summaryElement'));
117
+ if(!summary){return;}
118
+ var action = (val) ? 'removeClass' : 'addClass';
119
+ var details = $(this);
120
+ if (!initDetails && options.animate){
121
+ details.stop().css({width: '', height: ''});
122
+ var start = {
123
+ width: details.width(),
124
+ height: details.height()
906
125
  };
907
- var detectTrackError = function(){
908
- document.addEventListener('error', trackListener, true);
909
-
910
- if(bugs.track){
911
- changeApi();
912
- } else {
913
- $('track').each(changeApi);
914
- }
915
- };
916
- if(!trackOptions.override){
917
- if(webshims.isReady('track')){
918
- detectTrackError();
919
- } else {
920
- $(detectTrackError);
921
- }
922
- }
923
- })();
924
-
925
- }
926
-
927
- webshims.register('mediaelement-core', function($, webshims, window, document, undefined){
928
- hasSwf = swfobject.hasFlashPlayerVersion('9.0.115');
929
- $('html').addClass(hasSwf ? 'swf' : 'no-swf');
930
- var mediaelement = webshims.mediaelement;
931
- mediaelement.parseRtmp = function(data){
932
- var src = data.src.split('://');
933
- var paths = src[1].split('/');
934
- var i, len, found;
935
- data.server = src[0]+'://'+paths[0]+'/';
936
- data.streamId = [];
937
- for(i = 1, len = paths.length; i < len; i++){
938
- if(!found && paths[i].indexOf(':') !== -1){
939
- paths[i] = paths[i].split(':')[1];
940
- found = true;
941
- }
942
- if(!found){
943
- data.server += paths[i]+'/';
944
- } else {
945
- data.streamId.push(paths[i]);
946
- }
947
126
  }
948
- if(!data.streamId.length){
949
- webshims.error('Could not parse rtmp url');
950
- }
951
- data.streamId = data.streamId.join('/');
952
- };
953
- var getSrcObj = function(elem, nodeName){
954
- elem = $(elem);
955
- var src = {src: elem.attr('src') || '', elem: elem, srcProp: elem.prop('src')};
956
- var tmp;
957
-
958
- if(!src.src){return src;}
959
-
960
- tmp = elem.attr('data-server');
961
- if(tmp != null){
962
- src.server = tmp;
963
- }
964
-
965
- tmp = elem.attr('type');
966
- if(tmp){
967
- src.type = tmp;
968
- src.container = $.trim(tmp.split(';')[0]);
969
- } else {
970
- if(!nodeName){
971
- nodeName = elem[0].nodeName.toLowerCase();
972
- if(nodeName == 'source'){
973
- nodeName = (elem.closest('video, audio')[0] || {nodeName: 'video'}).nodeName.toLowerCase();
974
- }
975
- }
976
- if(src.server){
977
- src.type = nodeName+'/rtmp';
978
- src.container = nodeName+'/rtmp';
979
- } else {
980
-
981
- tmp = mediaelement.getTypeForSrc( src.src, nodeName, src );
982
-
983
- if(tmp){
984
- src.type = tmp;
985
- src.container = tmp;
127
+ summary.attr('aria-expanded', ''+val);
128
+ details[action]('closed-details-summary').children().not(summary[0])[action]('closed-details-child');
129
+ if(!initDetails && options.animate){
130
+ var end = {
131
+ width: details.width(),
132
+ height: details.height()
133
+ };
134
+ details.css(start).animate(end, {
135
+ complete: function(){
136
+ $(this).css({width: '', height: ''});
986
137
  }
987
- }
988
- }
989
- tmp = elem.attr('media');
990
- if(tmp){
991
- src.media = tmp;
992
- }
993
- if(src.type == 'audio/rtmp' || src.type == 'video/rtmp'){
994
- if(src.server){
995
- src.streamId = src.src;
996
- } else {
997
- mediaelement.parseRtmp(src);
998
- }
999
- }
1000
- return src;
1001
- };
1002
-
1003
-
1004
-
1005
- var hasYt = !hasSwf && ('postMessage' in window) && hasNative;
1006
-
1007
- var loadTrackUi = function(){
1008
- if(loadTrackUi.loaded){return;}
1009
- loadTrackUi.loaded = true;
1010
- $(function(){
1011
- webshims.loader.loadList(['track-ui']);
1012
- });
1013
- };
1014
- var loadYt = (function(){
1015
- var loaded;
1016
- return function(){
1017
- if(loaded || !hasYt){return;}
1018
- loaded = true;
1019
- webshims.loader.loadScript("https://www.youtube.com/player_api");
1020
- $(function(){
1021
- webshims.polyfill("mediaelement-yt");
1022
138
  });
1023
- };
1024
- })();
1025
- var loadThird = function(){
1026
- if(hasSwf){
1027
- loadSwf();
1028
- } else {
1029
- loadYt();
1030
- }
1031
- };
1032
-
1033
- webshims.addPolyfill('mediaelement-yt', {
1034
- test: !hasYt,
1035
- d: ['dom-support']
1036
- });
1037
-
1038
- mediaelement.mimeTypes = {
1039
- audio: {
1040
- //ogm shouldn´t be used!
1041
- 'audio/ogg': ['ogg','oga', 'ogm'],
1042
- 'audio/ogg;codecs="opus"': 'opus',
1043
- 'audio/mpeg': ['mp2','mp3','mpga','mpega'],
1044
- 'audio/mp4': ['mp4','mpg4', 'm4r', 'm4a', 'm4p', 'm4b', 'aac'],
1045
- 'audio/wav': ['wav'],
1046
- 'audio/3gpp': ['3gp','3gpp'],
1047
- 'audio/webm': ['webm'],
1048
- 'audio/fla': ['flv', 'f4a', 'fla'],
1049
- 'application/x-mpegURL': ['m3u8', 'm3u']
1050
- },
1051
- video: {
1052
- //ogm shouldn´t be used!
1053
- 'video/ogg': ['ogg','ogv', 'ogm'],
1054
- 'video/mpeg': ['mpg','mpeg','mpe'],
1055
- 'video/mp4': ['mp4','mpg4', 'm4v'],
1056
- 'video/quicktime': ['mov','qt'],
1057
- 'video/x-msvideo': ['avi'],
1058
- 'video/x-ms-asf': ['asf', 'asx'],
1059
- 'video/flv': ['flv', 'f4v'],
1060
- 'video/3gpp': ['3gp','3gpp'],
1061
- 'video/webm': ['webm'],
1062
- 'application/x-mpegURL': ['m3u8', 'm3u'],
1063
- 'video/MP2T': ['ts']
1064
- }
1065
- }
1066
- ;
1067
-
1068
- mediaelement.mimeTypes.source = $.extend({}, mediaelement.mimeTypes.audio, mediaelement.mimeTypes.video);
1069
-
1070
- mediaelement.getTypeForSrc = function(src, nodeName, data){
1071
- if(src.indexOf('youtube.com/watch?') != -1 || src.indexOf('youtube.com/v/') != -1){
1072
- return 'video/youtube';
1073
- }
1074
- if(src.indexOf('rtmp') === 0){
1075
- return nodeName+'/rtmp';
1076
139
  }
1077
- src = src.split('?')[0].split('.');
1078
- src = src[src.length - 1];
1079
- var mt;
1080
140
 
1081
- $.each(mediaelement.mimeTypes[nodeName], function(mimeType, exts){
1082
- if(exts.indexOf(src) !== -1){
1083
- mt = mimeType;
1084
- return false;
1085
- }
1086
- });
1087
- return mt;
1088
- };
1089
-
1090
-
1091
- mediaelement.srces = function(mediaElem, srces){
1092
- mediaElem = $(mediaElem);
1093
- if(!srces){
1094
- srces = [];
1095
- var nodeName = mediaElem[0].nodeName.toLowerCase();
1096
- var src = getSrcObj(mediaElem, nodeName);
141
+ });
142
+ webshims.createElement('details', function(){
143
+ initDetails = true;
144
+ var summary = getSummary(this);
145
+ $.prop(this, 'open', $.prop(this, 'open'));
146
+ initDetails = false;
147
+ });
148
+ });
149
+
150
+ jQuery.webshims.register('track', function($, webshims, window, document, undefined){
151
+ "use strict";
152
+ var mediaelement = webshims.mediaelement;
153
+ var id = new Date().getTime();
154
+ var ADDBACK = $.fn.addBack ? 'addBack' : 'andSelf';
155
+ //descriptions are not really shown, but they are inserted into the dom
156
+ var showTracks = {subtitles: 1, captions: 1, descriptions: 1};
157
+ var notImplemented = function(){
158
+ webshims.error('not implemented yet');
159
+ };
160
+ var dummyTrack = $('<track />');
161
+ var supportTrackMod = Modernizr.ES5 && Modernizr.objectAccessor;
162
+ var createEventTarget = function(obj){
163
+ var eventList = {};
164
+ obj.addEventListener = function(name, fn){
165
+ if(eventList[name]){
166
+ webshims.error('always use $.on to the shimed event: '+ name +' already bound fn was: '+ eventList[name] +' your fn was: '+ fn);
167
+ }
168
+ eventList[name] = fn;
1097
169
 
1098
- if(!src.src){
1099
-
1100
- $('source', mediaElem).each(function(){
1101
- src = getSrcObj(this, nodeName);
1102
- if(src.src){srces.push(src);}
1103
- });
1104
- } else {
1105
- srces.push(src);
170
+ };
171
+ obj.removeEventListener = function(name, fn){
172
+ if(eventList[name] && eventList[name] != fn){
173
+ webshims.error('always use $.on/$.off to the shimed event: '+ name +' already bound fn was: '+ eventList[name] +' your fn was: '+ fn);
1106
174
  }
1107
- return srces;
1108
- } else {
1109
- mediaElem.removeAttr('src').removeAttr('type').find('source').remove();
1110
- if(!$.isArray(srces)){
1111
- srces = [srces];
175
+ if(eventList[name]){
176
+ delete eventList[name];
1112
177
  }
1113
- srces.forEach(function(src){
1114
- var source = document.createElement('source');
1115
- if(typeof src == 'string'){
1116
- src = {src: src};
1117
- }
1118
- source.setAttribute('src', src.src);
1119
- if(src.type){
1120
- source.setAttribute('type', src.type);
1121
- }
1122
- if(src.media){
1123
- source.setAttribute('media', src.media);
1124
- }
1125
- mediaElem.append(source);
1126
- });
1127
-
1128
- }
178
+ };
179
+ return obj;
1129
180
  };
1130
181
 
1131
-
1132
- $.fn.loadMediaSrc = function(srces, poster){
1133
- return this.each(function(){
1134
- if(poster !== undefined){
1135
- $(this).removeAttr('poster');
1136
- if(poster){
1137
- $.attr(this, 'poster', poster);
182
+ var cueListProto = {
183
+ getCueById: function(id){
184
+ var cue = null;
185
+ for(var i = 0, len = this.length; i < len; i++){
186
+ if(this[i].id === id){
187
+ cue = this[i];
188
+ break;
1138
189
  }
1139
190
  }
1140
- mediaelement.srces(this, srces);
1141
- $(this).mediaLoad();
1142
- });
1143
- };
1144
-
1145
- 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', 'video/rtmp', 'audio/rtmp'];
1146
-
1147
- mediaelement.canThirdPlaySrces = function(mediaElem, srces){
1148
- var ret = '';
1149
- if(hasSwf || hasYt){
1150
- mediaElem = $(mediaElem);
1151
- srces = srces || mediaelement.srces(mediaElem);
1152
- $.each(srces, function(i, src){
1153
- if(src.container && src.src && ((hasSwf && mediaelement.swfMimeTypes.indexOf(src.container) != -1) || (hasYt && src.container == 'video/youtube'))){
1154
- ret = src;
1155
- return false;
1156
- }
1157
- });
1158
-
191
+ return cue;
1159
192
  }
1160
-
1161
- return ret;
1162
193
  };
1163
-
1164
- var nativeCanPlayType = {};
1165
- mediaelement.canNativePlaySrces = function(mediaElem, srces){
1166
- var ret = '';
1167
- if(hasNative){
1168
- mediaElem = $(mediaElem);
1169
- var nodeName = (mediaElem[0].nodeName || '').toLowerCase();
1170
- if(!nativeCanPlayType[nodeName]){return ret;}
1171
- srces = srces || mediaelement.srces(mediaElem);
1172
-
1173
- $.each(srces, function(i, src){
1174
- if(src.type && nativeCanPlayType[nodeName].prop._supvalue.call(mediaElem[0], src.type) ){
1175
- ret = src;
1176
- return false;
1177
- }
1178
- });
1179
- }
1180
- return ret;
194
+ var numericModes = {
195
+ 0: 'disabled',
196
+ 1: 'hidden',
197
+ 2: 'showing'
1181
198
  };
1182
199
 
1183
- mediaelement.setError = function(elem, message){
1184
- if(!message){
1185
- message = "can't play sources";
1186
- }
1187
-
1188
- $(elem).pause().data('mediaerror', message);
1189
- webshims.warn('mediaelementError: '+ message);
1190
- setTimeout(function(){
1191
- if($(elem).data('mediaerror')){
1192
- $(elem).trigger('mediaerror');
200
+ var textTrackProto = {
201
+ shimActiveCues: null,
202
+ _shimActiveCues: null,
203
+ activeCues: null,
204
+ cues: null,
205
+ kind: 'subtitles',
206
+ label: '',
207
+ language: '',
208
+ mode: 'disabled',
209
+ readyState: 0,
210
+ oncuechange: null,
211
+ toString: function() {
212
+ return "[object TextTrack]";
213
+ },
214
+ addCue: function(cue){
215
+ if(!this.cues){
216
+ this.cues = mediaelement.createCueList();
217
+ } else {
218
+ var lastCue = this.cues[this.cues.length-1];
219
+ if(lastCue && lastCue.startTime > cue.startTime){
220
+ webshims.error("cue startTime higher than previous cue's startTime");
221
+ }
1193
222
  }
1194
- }, 1);
1195
- };
1196
-
1197
- var handleThird = (function(){
1198
- var requested;
1199
- return function( mediaElem, ret, data ){
1200
- if(!requested){
1201
- loadTrackUi();
223
+ if(cue.track && cue.track.removeCue){
224
+ cue.track.removeCue(cue);
1202
225
  }
1203
- webshims.ready(hasSwf ? swfType : 'mediaelement-yt', function(){
1204
- if(mediaelement.createSWF){
1205
- mediaelement.createSWF( mediaElem, ret, data );
1206
- } else if(!requested) {
1207
- requested = true;
1208
- loadThird();
1209
- //readd to ready
1210
- handleThird( mediaElem, ret, data );
1211
- }
1212
- });
1213
- if(!requested && hasYt && !mediaelement.createSWF){
1214
- loadYt();
226
+ cue.track = this;
227
+ this.cues.push(cue);
228
+ },
229
+ //ToDo: make it more dynamic
230
+ removeCue: function(cue){
231
+ var cues = this.cues || [];
232
+ var i = 0;
233
+ var len = cues.length;
234
+ if(cue.track != this){
235
+ webshims.error("cue not part of track");
236
+ return;
1215
237
  }
1216
- };
1217
- })();
1218
-
1219
- var stepSources = function(elem, data, useSwf, _srces, _noLoop){
1220
- var ret;
1221
- if(useSwf || (useSwf !== false && data && data.isActive == 'third')){
1222
- ret = mediaelement.canThirdPlaySrces(elem, _srces);
1223
- if(!ret){
1224
- if(_noLoop){
1225
- mediaelement.setError(elem, false);
1226
- } else {
1227
- stepSources(elem, data, false, _srces, true);
238
+ for(; i < len; i++){
239
+ if(cues[i] === cue){
240
+ cues.splice(i, 1);
241
+ cue.track = null;
242
+ break;
1228
243
  }
1229
- } else {
1230
- handleThird(elem, ret, data);
1231
244
  }
1232
- } else {
1233
- ret = mediaelement.canNativePlaySrces(elem, _srces);
1234
- if(!ret){
1235
- if(_noLoop){
1236
- mediaelement.setError(elem, false);
1237
- if(data && data.isActive == 'third') {
1238
- mediaelement.setActive(elem, 'html5', data);
1239
- }
1240
- } else {
1241
- stepSources(elem, data, true, _srces, true);
1242
- }
1243
- } else if(data && data.isActive == 'third') {
1244
- mediaelement.setActive(elem, 'html5', data);
245
+ if(cue.track){
246
+ webshims.error("cue not part of track");
247
+ return;
1245
248
  }
1246
- }
1247
- };
1248
- var stopParent = /^(?:embed|object|datalist)$/i;
1249
- var selectSource = function(elem, data){
1250
- var baseData = webshims.data(elem, 'mediaelementBase') || webshims.data(elem, 'mediaelementBase', {});
1251
- var _srces = mediaelement.srces(elem);
1252
- var parent = elem.parentNode;
1253
-
1254
- clearTimeout(baseData.loadTimer);
1255
- $.data(elem, 'mediaerror', false);
1256
-
1257
- if(!_srces.length || !parent || parent.nodeType != 1 || stopParent.test(parent.nodeName || '')){return;}
1258
- data = data || webshims.data(elem, 'mediaelement');
1259
- stepSources(elem, data, options.preferFlash || undefined, _srces);
249
+ },
250
+ DISABLED: 'disabled',
251
+ OFF: 'disabled',
252
+ HIDDEN: 'hidden',
253
+ SHOWING: 'showing',
254
+ ERROR: 3,
255
+ LOADED: 2,
256
+ LOADING: 1,
257
+ NONE: 0
1260
258
  };
1261
- mediaelement.selectSource = selectSource;
259
+ var copyProps = ['kind', 'label', 'srclang'];
260
+ var copyName = {srclang: 'language'};
1262
261
 
1263
- $(document).on('ended', function(e){
1264
- var data = webshims.data(e.target, 'mediaelement');
1265
- if( supportsLoop && (!data || data.isActive == 'html5') && !$.prop(e.target, 'loop')){return;}
1266
- setTimeout(function(){
1267
- if( $.prop(e.target, 'paused') || !$.prop(e.target, 'loop') ){return;}
1268
- $(e.target).prop('currentTime', 0).play();
1269
- }, 1);
1270
-
1271
- });
1272
- if(!supportsLoop){
1273
- webshims.defineNodeNamesBooleanProperty(['audio', 'video'], 'loop');
1274
- }
262
+ var owns = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
1275
263
 
1276
- ['audio', 'video'].forEach(function(nodeName){
1277
- var supLoad = webshims.defineNodeNameProperty(nodeName, 'load', {
1278
- prop: {
1279
- value: function(){
1280
- var data = webshims.data(this, 'mediaelement');
1281
- selectSource(this, data);
1282
- if(hasNative && (!data || data.isActive == 'html5') && supLoad.prop._supvalue){
1283
- supLoad.prop._supvalue.apply(this, arguments);
1284
- }
1285
- }
1286
- }
1287
- });
1288
- nativeCanPlayType[nodeName] = webshims.defineNodeNameProperty(nodeName, 'canPlayType', {
1289
- prop: {
1290
- value: function(type){
1291
- var ret = '';
1292
- if(hasNative && nativeCanPlayType[nodeName].prop._supvalue){
1293
- ret = nativeCanPlayType[nodeName].prop._supvalue.call(this, type);
1294
- if(ret == 'no'){
1295
- ret = '';
1296
- }
1297
- }
1298
- if(!ret && hasSwf){
1299
- type = $.trim((type || '').split(';')[0]);
1300
- if(mediaelement.swfMimeTypes.indexOf(type) != -1){
1301
- ret = 'maybe';
1302
- }
1303
- }
1304
- return ret;
1305
- }
1306
- }
1307
- });
1308
- });
1309
- webshims.onNodeNamesPropertyModify(['audio', 'video'], ['src', 'poster'], {
1310
- set: function(){
1311
- var elem = this;
1312
- var baseData = webshims.data(elem, 'mediaelementBase') || webshims.data(elem, 'mediaelementBase', {});
1313
- clearTimeout(baseData.loadTimer);
1314
- baseData.loadTimer = setTimeout(function(){
1315
- selectSource(elem);
1316
- elem = null;
1317
- }, 9);
264
+ var updateMediaTrackList = function(baseData, trackList){
265
+ var removed = [];
266
+ var added = [];
267
+ var newTracks = [];
268
+ var i, len;
269
+ if(!baseData){
270
+ baseData = webshims.data(this, 'mediaelementBase') || webshims.data(this, 'mediaelementBase', {});
1318
271
  }
1319
- });
1320
-
1321
- var initMediaElements = function(){
1322
-
1323
- webshims.addReady(function(context, insertedElement){
1324
- var media = $('video, audio', context)
1325
- .add(insertedElement.filter('video, audio'))
1326
- .each(function(){
1327
- var data = webshims.data(this, 'mediaelement');
1328
-
1329
- if(hasNative && $.prop(this, 'paused') && !$.prop(this, 'readyState') && $(this).is('audio[preload="none"][controls]:not([autoplay])') && (!data || data.isActive == 'html5')){
1330
- //IE controls not visible bug
1331
- $(this).prop('preload', 'metadata').mediaLoad();
1332
- } else {
1333
- selectSource(this, data);
1334
- }
1335
-
1336
- if(hasNative){
1337
-
1338
- //FF progress bug
1339
- (function(){
1340
- var bufferTimer;
1341
- var lastBuffered;
1342
- var elem = this;
1343
- var getBufferedString = function(){
1344
- var buffered = $.prop(elem, 'buffered');
1345
- if(!buffered){return;}
1346
- var bufferString = "";
1347
- for(var i = 0, len = buffered.length; i < len;i++){
1348
- bufferString += buffered.end(i);
1349
- }
1350
- return bufferString;
1351
- };
1352
- var testBuffer = function(){
1353
- var buffered = getBufferedString();
1354
- if(buffered != lastBuffered){
1355
- lastBuffered = buffered;
1356
- $(elem).triggerHandler('progress');
1357
- }
1358
- };
1359
-
1360
- $(this)
1361
- .on({
1362
- 'play loadstart progress': function(e){
1363
- if(e.type == 'progress'){
1364
- lastBuffered = getBufferedString();
1365
- }
1366
- clearTimeout(bufferTimer);
1367
- bufferTimer = setTimeout(testBuffer, 999);
1368
- },
1369
- 'emptied stalled mediaerror abort suspend': function(e){
1370
- if(e.type == 'emptied'){
1371
- lastBuffered = false;
1372
- }
1373
- clearTimeout(bufferTimer);
1374
- }
1375
- })
1376
- ;
1377
- })();
1378
- }
1379
-
1380
- })
1381
- ;
1382
- if(!loadTrackUi.loaded && $('track', media).length){
1383
- loadTrackUi();
1384
- }
1385
- media = null;
1386
- });
1387
- };
1388
-
1389
- if(Modernizr.track && !bugs.track){
1390
- webshims.defineProperty(TextTrack.prototype, 'shimActiveCues', {
1391
- get: function(){
1392
- return this._shimActiveCues || this.activeCues;
1393
- }
1394
- });
1395
- }
1396
- //set native implementation ready, before swf api is retested
1397
- if(hasNative){
1398
- webshims.isReady('mediaelement-core', true);
1399
- initMediaElements();
1400
- webshims.ready('WINDOWLOAD mediaelement', loadThird);
1401
- } else {
1402
- webshims.ready(swfType, initMediaElements);
1403
- }
1404
- webshims.ready('WINDOWLOAD mediaelement', loadTrackUi);
1405
- });
1406
- })(jQuery, Modernizr, jQuery.webshims);
1407
- /*
1408
- * todos:
1409
- * - decouple muted/volume (needs improvement)
1410
- * - implement video <-> flashcanvas pro API
1411
- * - improve buffered-property with youtube/rtmp
1412
- * - use jwplayer5 api instead of old flash4 api
1413
- */
1414
-
1415
- jQuery.webshims.register('mediaelement-swf', function($, webshims, window, document, undefined, options){
1416
- "use strict";
1417
- var SENDEVENT = 'sendEvent';
1418
- var mediaelement = webshims.mediaelement;
1419
- var swfobject = window.swfobject;
1420
- var hasNative = Modernizr.audio && Modernizr.video;
1421
- var hasFlash = swfobject.hasFlashPlayerVersion('9.0.115');
1422
- var loadedSwf = 0;
1423
- var getProps = {
1424
- paused: true,
1425
- ended: false,
1426
- currentSrc: '',
1427
- duration: window.NaN,
1428
272
 
1429
- readyState: 0,
1430
- networkState: 0,
1431
- videoHeight: 0,
1432
- videoWidth: 0,
1433
- error: null,
1434
- buffered: {
1435
- start: function(index){
1436
- if(index){
1437
- webshims.error('buffered index size error');
1438
- return;
1439
- }
1440
- return 0;
1441
- },
1442
- end: function(index){
1443
- if(index){
1444
- webshims.error('buffered index size error');
1445
- return;
1446
- }
1447
- return 0;
1448
- },
1449
- length: 0
273
+ if(!trackList){
274
+ baseData.blockTrackListUpdate = true;
275
+ trackList = $.prop(this, 'textTracks');
276
+ baseData.blockTrackListUpdate = false;
1450
277
  }
1451
- };
1452
- var getPropKeys = Object.keys(getProps);
1453
-
1454
- var getSetProps = {
1455
- currentTime: 0,
1456
- volume: 1,
1457
- muted: false
1458
- };
1459
- var getSetPropKeys = Object.keys(getSetProps);
1460
-
1461
- var playerStateObj = $.extend({
1462
- isActive: 'html5',
1463
- activating: 'html5',
1464
- wasSwfReady: false,
1465
- _bufferedEnd: 0,
1466
- _bufferedStart: 0,
1467
- _metadata: false,
1468
- _durationCalcs: -1,
1469
- _callMeta: false,
1470
- currentTime: 0,
1471
- _ppFlag: undefined
1472
- }, getProps, getSetProps);
1473
-
1474
- var idRep = /^jwplayer-/;
1475
- var getSwfDataFromID = function(id){
1476
278
 
1477
- var elem = document.getElementById(id.replace(idRep, ''));
1478
- if(!elem){return;}
1479
- var data = webshims.data(elem, 'mediaelement');
1480
- return data.isActive == 'third' ? data : null;
1481
- };
1482
-
1483
-
1484
- var getSwfDataFromElem = function(elem){
1485
- try {
1486
- (elem.nodeName);
1487
- } catch(er){
1488
- return null;
1489
- }
1490
- var data = webshims.data(elem, 'mediaelement');
1491
- return (data && data.isActive== 'third') ? data : null;
1492
- };
1493
-
1494
- var trigger = function(elem, evt){
1495
- evt = $.Event(evt);
1496
- evt.preventDefault();
1497
- $.event.trigger(evt, undefined, elem);
1498
- };
1499
-
1500
- var playerSwfPath = options.playerPath || webshims.cfg.basePath + "jwplayer/" + (options.playerName || "player.swf");
1501
- var jwplugin = options.pluginPath || webshims.cfg.basePath +'swf/jwwebshims.swf';
1502
-
1503
- webshims.extendUNDEFProp(options.params, {
1504
- allowscriptaccess: 'always',
1505
- allowfullscreen: 'true',
1506
- wmode: 'transparent'
1507
- });
1508
- webshims.extendUNDEFProp(options.vars, {
1509
- screencolor: 'ffffffff'
1510
- });
1511
- webshims.extendUNDEFProp(options.attrs, {
1512
- bgcolor: '#000000'
1513
- });
1514
-
1515
- var getDuration = function(data, obj){
1516
- var curDuration = data.duration;
1517
- if(curDuration && data._durationCalcs > 0){return;}
1518
- try {
1519
- data.duration = data.jwapi.getPlaylist()[0].duration;
1520
- if(!data.duration || data.duration <= 0 || data.duration === data._lastDuration){
1521
- data.duration = curDuration;
1522
- }
1523
- } catch(er){}
1524
- if(data.duration && data.duration != data._lastDuration){
1525
- trigger(data._elem, 'durationchange');
1526
- if(data._elemNodeName == 'audio' || data._callMeta){
1527
- mediaelement.jwEvents.Model.META($.extend({duration: data.duration}, obj), data);
1528
- }
1529
- data._durationCalcs--;
1530
- } else {
1531
- data._durationCalcs++;
1532
- }
1533
- };
1534
- var setReadyState = function(readyState, data){
1535
- if(readyState < 3){
1536
- clearTimeout(data._canplaythroughTimer);
1537
- }
1538
- if(readyState >= 3 && data.readyState < 3){
1539
- data.readyState = readyState;
1540
- trigger(data._elem, 'canplay');
1541
- clearTimeout(data._canplaythroughTimer);
1542
- data._canplaythroughTimer = setTimeout(function(){
1543
- setReadyState(4, data);
1544
- }, 4000);
1545
- }
1546
- if(readyState >= 4 && data.readyState < 4){
1547
- data.readyState = readyState;
1548
- trigger(data._elem, 'canplaythrough');
1549
- }
1550
- data.readyState = readyState;
1551
- };
1552
-
1553
- $.extend($.event.customEvent, {
1554
- updatemediaelementdimensions: true,
1555
- flashblocker: true,
1556
- swfstageresize: true,
1557
- mediaelementapichange: true
1558
- });
1559
-
1560
- mediaelement.jwEvents = {
1561
- View: {
1562
-
1563
- PLAY: function(obj){
1564
- var data = getSwfDataFromID(obj.id);
1565
- if(!data || data.stopPlayPause){return;}
1566
- data._ppFlag = true;
1567
- if(data.paused == obj.state){
1568
- data.paused = !obj.state;
1569
- if(data.ended){
1570
- data.ended = false;
1571
- }
1572
- trigger(data._elem, obj.state ? 'play' : 'pause');
1573
- }
1574
- }
1575
- },
1576
- Model: {
1577
-
1578
- BUFFER: function(obj){
1579
- var data = getSwfDataFromID(obj.id);
1580
- if(!data || !('percentage' in obj) || data._bufferedEnd == obj.percentage){return;}
1581
- data.networkState = (obj.percentage == 100) ? 1 : 2;
1582
- if(isNaN(data.duration) || (obj.percentage > 5 && obj.percentage < 25) || (obj.percentage === 100)){
1583
- getDuration(data, obj);
1584
- }
1585
-
1586
- if(data.ended){
1587
- data.ended = false;
1588
- }
1589
- if(!data.duration){
1590
- return;
1591
- }
1592
- if(obj.percentage > 2 && obj.percentage < 20){
1593
- setReadyState(3, data);
1594
- } else if(obj.percentage > 20){
1595
- setReadyState(4, data);
1596
- }
1597
- if(data._bufferedEnd && (data._bufferedEnd > obj.percentage)){
1598
- data._bufferedStart = data.currentTime || 0;
1599
- }
1600
-
1601
- data._bufferedEnd = obj.percentage;
1602
- data.buffered.length = 1;
1603
- if(obj.percentage == 100){
1604
- data.networkState = 1;
1605
- setReadyState(4, data);
1606
- }
1607
- $.event.trigger('progress', undefined, data._elem, true);
1608
- },
1609
- META: function(obj, data){
1610
-
1611
- data = data && data.networkState ? data : getSwfDataFromID(obj.id);
1612
-
1613
- if(!data){return;}
1614
- if( !('duration' in obj) ){
1615
- data._callMeta = true;
1616
- return;
1617
- }
1618
-
1619
- if( data._metadata && (!obj.height || data.videoHeight == obj.height) && (obj.duration === data.duration) ){return;}
1620
-
1621
- data._metadata = true;
1622
-
1623
- var oldDur = data.duration;
1624
- if(obj.duration){
1625
- data.duration = obj.duration;
1626
- }
1627
- data._lastDuration = data.duration;
1628
- if(obj.height || obj.width){
1629
- data.videoHeight = obj.height || 0;
1630
- data.videoWidth = obj.width || 0;
1631
- }
1632
- if(!data.networkState){
1633
- data.networkState = 2;
1634
- }
1635
- if(data.readyState < 1){
1636
- setReadyState(1, data);
1637
- }
1638
- if(data.duration && oldDur !== data.duration){
1639
- trigger(data._elem, 'durationchange');
1640
- }
1641
-
1642
- trigger(data._elem, 'loadedmetadata');
1643
- },
1644
- TIME: function(obj){
1645
- var data = getSwfDataFromID(obj.id);
1646
- if(!data || data.currentTime === obj.position){return;}
1647
- data.currentTime = obj.position;
1648
- if(data.duration && data.duration < data.currentTime){
1649
- getDuration(data, obj);
1650
- }
1651
- if(data.readyState < 2){
1652
- setReadyState(2, data);
1653
- }
1654
- if(data.ended){
1655
- data.ended = false;
1656
- }
1657
- trigger(data._elem, 'timeupdate');
1658
-
1659
- },
1660
- STATE: function(obj){
1661
- var data = getSwfDataFromID(obj.id);
1662
- if(!data){return;}
1663
- switch(obj.newstate) {
1664
- case 'BUFFERING':
1665
-
1666
- if(data.ended){
1667
- data.ended = false;
1668
- }
1669
- setReadyState(1, data);
1670
- trigger(data._elem, 'waiting');
1671
- break;
1672
- case 'PLAYING':
1673
- data.paused = false;
1674
- data._ppFlag = true;
1675
- if(!data.duration){
1676
- getDuration(data, obj);
1677
- }
1678
- if(data.readyState < 3){
1679
- setReadyState(3, data);
1680
- }
1681
- if(data.ended){
1682
- data.ended = false;
1683
- }
1684
- trigger(data._elem, 'playing');
1685
- break;
1686
- case 'PAUSED':
1687
- if(!data.paused && !data.stopPlayPause){
1688
- data.paused = true;
1689
- data._ppFlag = true;
1690
- trigger(data._elem, 'pause');
1691
- }
1692
- break;
1693
- case 'COMPLETED':
1694
- if(data.readyState < 4){
1695
- setReadyState(4, data);
1696
- }
1697
- data.ended = true;
1698
- trigger(data._elem, 'ended');
1699
- break;
1700
- }
1701
- }
1702
- }
1703
- ,Controller: {
1704
-
1705
- ERROR: function(obj){
1706
- var data = getSwfDataFromID(obj.id);
1707
- if(!data){return;}
1708
- mediaelement.setError(data._elem, obj.message);
1709
- },
1710
- SEEK: function(obj){
1711
- var data = getSwfDataFromID(obj.id);
1712
- if(!data){return;}
1713
- if(data.ended){
1714
- data.ended = false;
1715
- }
1716
- if(data.paused){
1717
- try {
1718
- data.jwapi[SENDEVENT]('play', 'false');
1719
- } catch(er){}
1720
- }
1721
- if(data.currentTime != obj.position){
1722
- data.currentTime = obj.position;
1723
- trigger(data._elem, 'timeupdate');
1724
- }
1725
-
1726
-
1727
- },
1728
- VOLUME: function(obj){
1729
- var data = getSwfDataFromID(obj.id);
1730
- if(!data){return;}
1731
- var newVolume = obj.percentage / 100;
1732
- if(data.volume == newVolume){return;}
1733
- data.volume = newVolume;
1734
- trigger(data._elem, 'volumechange');
1735
- },
1736
- MUTE: function(obj){
1737
- if(obj.state){return;}
1738
- var data = getSwfDataFromID(obj.id);
1739
- if(!data){return;}
1740
- if(data.muted == obj.state){return;}
1741
- data.muted = obj.state;
1742
- trigger(data._elem, 'volumechange');
279
+ clearTimeout(baseData.updateTrackListTimer);
280
+
281
+ $('track', this).each(function(){
282
+ var track = $.prop(this, 'track');
283
+ newTracks.push(track);
284
+ if(trackList.indexOf(track) == -1){
285
+ added.push(track);
1743
286
  }
1744
- }
1745
- };
1746
-
1747
- var initEvents = function(data){
1748
- var passed = true;
1749
- $.each(mediaelement.jwEvents, function(mvcName, evts){
1750
- $.each(evts, function(evtName){
1751
- try {
1752
- data.jwapi['add'+ mvcName +'Listener'](evtName, 'jQuery.webshims.mediaelement.jwEvents.'+ mvcName +'.'+ evtName);
1753
- } catch(er){
1754
- passed = false;
1755
- return false;
1756
- }
1757
- });
1758
287
  });
1759
- return passed;
1760
- };
1761
-
1762
- var workActionQueue = function(data){
1763
- var actionLen = data.actionQueue.length;
1764
- var i = 0;
1765
- var operation;
1766
- if(actionLen && data.isActive == 'third'){
1767
- while(data.actionQueue.length && actionLen > i){
1768
- i++;
1769
- operation = data.actionQueue.shift();
1770
- data.jwapi[operation.fn].apply(data.jwapi, operation.args);
1771
- }
1772
- }
1773
- if(data.actionQueue.length){
1774
- data.actionQueue = [];
1775
- }
1776
- };
1777
- var startAutoPlay = function(data){
1778
- if(!data){return;}
1779
- if( (data._ppFlag === undefined && ($.prop(data._elem, 'autoplay')) || !data.paused)){
1780
- setTimeout(function(){
1781
- if(data.isActive == 'third' && (data._ppFlag === undefined || !data.paused)){
1782
- try {
1783
- $(data._elem).play();
1784
- } catch(er){}
1785
- }
1786
- }, 1);
1787
- }
1788
- };
1789
-
1790
-
1791
- mediaelement.playerResize = function(id){
1792
- if(!id){return;}
1793
- var elem = document.getElementById(id.replace(idRep, ''));
1794
288
 
1795
- if(elem){
1796
- $(elem).triggerHandler('swfstageresize');
1797
- }
1798
- elem = null;
1799
- };
1800
-
1801
-
1802
- $(document).on('emptied', function(e){
1803
- var data = getSwfDataFromElem(e.target);
1804
- startAutoPlay(data);
1805
- });
1806
-
1807
- var localConnectionTimer;
1808
- mediaelement.jwPlayerReady = function(jwData){
1809
- var data = getSwfDataFromID(jwData.id);
1810
- var passed = true;
1811
- var i = 0;
1812
- var doneFn = function(){
1813
- if(i > 9){return;}
1814
- i++;
1815
- if(initEvents(data)){
1816
- if(!data.wasSwfReady){
1817
- var version = parseFloat( jwData.version, 10);
1818
- if(version < 5.1 || version >= 6){
1819
- webshims.warn('mediaelement-swf is only testet with jwplayer 5.6+');
1820
- }
1821
- } else {
1822
- $(data._elem).mediaLoad();
1823
-
1824
- }
1825
- data.wasSwfReady = true;
1826
- data.tryedReframeing = 0;
1827
- workActionQueue(data);
1828
- startAutoPlay(data);
1829
- } else {
1830
- clearTimeout(data.reframeTimer);
1831
- data.reframeTimer = setTimeout(doneFn, 9 * i);
1832
- if(i > 2 && data.tryedReframeing < 9){
1833
- data.tryedReframeing++;
1834
- data.shadowElem.css({overflow: 'visible'});
1835
- setTimeout(function(){
1836
- data.shadowElem.css({overflow: 'hidden'});
1837
- }, 16);
289
+ if(baseData.scriptedTextTracks){
290
+ for(i = 0, len = baseData.scriptedTextTracks.length; i < len; i++){
291
+ newTracks.push(baseData.scriptedTextTracks[i]);
292
+ if(trackList.indexOf(baseData.scriptedTextTracks[i]) == -1){
293
+ added.push(baseData.scriptedTextTracks[i]);
1838
294
  }
1839
295
  }
1840
- };
1841
- if(!data || !data.jwapi){return;}
1842
- if(!data.tryedReframeing){
1843
- data.tryedReframeing = 0;
1844
296
  }
1845
- clearTimeout(localConnectionTimer);
1846
- data.jwData = jwData;
1847
- data.shadowElem.removeClass('flashblocker-assumed');
1848
- $.prop(data._elem, 'volume', data.volume);
1849
- $.prop(data._elem, 'muted', data.muted);
1850
- doneFn();
1851
297
 
1852
- };
1853
-
1854
- var addMediaToStopEvents = $.noop;
1855
- if(hasNative){
1856
- var stopEvents = {
1857
- play: 1,
1858
- playing: 1
1859
- };
1860
- var hideEvtArray = ['play', 'pause', 'playing', 'canplay', 'progress', 'waiting', 'ended', 'loadedmetadata', 'durationchange', 'emptied'];
1861
- var hidevents = hideEvtArray.map(function(evt){
1862
- return evt +'.webshimspolyfill';
1863
- }).join(' ');
1864
- var opposite = {
1865
- 'html5': 'third',
1866
- 'third': 'html5'
1867
- };
1868
- var hidePlayerEvents = function(event){
1869
- var data = webshims.data(event.target, 'mediaelement');
1870
- if(!data){return;}
1871
- var isNativeHTML5 = ( event.originalEvent && event.originalEvent.type === event.type );
1872
- if( isNativeHTML5 == (data.activating == 'third') ){
1873
- event.stopImmediatePropagation();
1874
- if(stopEvents[event.type]){
1875
- if(data.isActive != data.activating){
1876
- $(event.target).pause();
1877
- } else {
1878
- data.isActive = opposite[data.isActive];
1879
- $(event.target).pause();
1880
- data.isActive = opposite[data.isActive];
1881
- }
1882
- }
298
+ for(i = 0, len = trackList.length; i < len; i++){
299
+ if(newTracks.indexOf(trackList[i]) == -1){
300
+ removed.push(trackList[i]);
1883
301
  }
1884
- };
1885
-
1886
-
1887
- addMediaToStopEvents = function(elem){
1888
- $(elem)
1889
- .off(hidevents)
1890
- .on(hidevents, hidePlayerEvents)
1891
- ;
1892
- hideEvtArray.forEach(function(evt){
1893
- webshims.moveToFirstEvent(elem, evt);
1894
- });
1895
- };
1896
- addMediaToStopEvents(document);
1897
- }
1898
-
1899
-
1900
- mediaelement.setActive = function(elem, type, data){
1901
- if(!data){
1902
- data = webshims.data(elem, 'mediaelement');
1903
- }
1904
- if(!data || data.isActive == type){return;}
1905
- if(type != 'html5' && type != 'third'){
1906
- webshims.warn('wrong type for mediaelement activating: '+ type);
1907
- }
1908
- var shadowData = webshims.data(elem, 'shadowData');
1909
- data.activating = type;
1910
- $(elem).pause();
1911
- data.isActive = type;
1912
- if(type == 'third'){
1913
- shadowData.shadowElement = shadowData.shadowFocusElement = data.shadowElem[0];
1914
- $(elem).addClass('swf-api-active nonnative-api-active').hide().getShadowElement().show();
1915
- } else {
1916
- $(elem).removeClass('swf-api-active nonnative-api-active').show().getShadowElement().hide();
1917
- shadowData.shadowElement = shadowData.shadowFocusElement = false;
1918
302
  }
1919
- $(elem).trigger('mediaelementapichange');
1920
- };
1921
-
1922
-
1923
-
1924
- var resetSwfProps = (function(){
1925
- var resetProtoProps = ['_bufferedEnd', '_bufferedStart', '_metadata', '_ppFlag', 'currentSrc', 'currentTime', 'duration', 'ended', 'networkState', 'paused', 'videoHeight', 'videoWidth', '_callMeta', '_durationCalcs'];
1926
- var len = resetProtoProps.length;
1927
- return function(data){
303
+
304
+ if(removed.length || added.length){
305
+ trackList.splice(0);
1928
306
 
1929
- if(!data){return;}
1930
- var lenI = len;
1931
- var networkState = data.networkState;
1932
- setReadyState(0, data);
1933
- while(--lenI){
1934
- delete data[resetProtoProps[lenI]];
307
+ for(i = 0, len = newTracks.length; i < len; i++){
308
+ trackList.push(newTracks[i]);
1935
309
  }
1936
- data.actionQueue = [];
1937
- data.buffered.length = 0;
1938
- if(networkState){
1939
- trigger(data._elem, 'emptied');
310
+ for(i = 0, len = removed.length; i < len; i++){
311
+ $([trackList]).triggerHandler($.Event({type: 'removetrack', track: removed[i]}));
312
+ }
313
+ for(i = 0, len = added.length; i < len; i++){
314
+ $([trackList]).triggerHandler($.Event({type: 'addtrack', track: added[i]}));
315
+ }
316
+ if(baseData.scriptedTextTracks || removed.length){
317
+ $(this).triggerHandler('updatetrackdisplay');
1940
318
  }
1941
- };
1942
- })();
1943
-
1944
- var setElementDimension = function(data, hasControls){
1945
- var elem = data._elem;
1946
- var box = data.shadowElem;
1947
- $(elem)[hasControls ? 'addClass' : 'removeClass']('webshims-controls');
1948
- if(data._elemNodeName == 'audio' && !hasControls){
1949
- box.css({width: 0, height: 0});
1950
- } else {
1951
- box.css({
1952
- width: elem.style.width || $(elem).width(),
1953
- height: elem.style.height || $(elem).height()
1954
- });
1955
319
  }
1956
320
  };
1957
321
 
1958
- mediaelement.createSWF = function( elem, canPlaySrc, data ){
1959
- if(!hasFlash){
322
+ var refreshTrack = function(track, trackData){
323
+ if(!trackData){
324
+ trackData = webshims.data(track, 'trackData');
325
+ }
326
+ if(trackData && !trackData.isTriggering){
327
+ trackData.isTriggering = true;
1960
328
  setTimeout(function(){
1961
- $(elem).mediaLoad(); //<- this should produce a mediaerror
329
+ if(!(trackData.track || {}).readyState){
330
+ $(track).triggerHandler('checktrackmode');
331
+ } else {
332
+ $(track).closest('audio, video').triggerHandler('updatetrackdisplay');
333
+ }
334
+ trackData.isTriggering = false;
1962
335
  }, 1);
1963
- return;
1964
336
  }
1965
-
1966
- if(loadedSwf < 1){
1967
- loadedSwf = 1;
1968
- } else {
1969
- loadedSwf++;
337
+ };
338
+
339
+ var emptyDiv = $('<div />')[0];
340
+ window.TextTrackCue = function(startTime, endTime, text){
341
+ if(arguments.length != 3){
342
+ webshims.error("wrong arguments.length for TextTrackCue.constructor");
1970
343
  }
1971
- var vars = $.extend({}, options.vars, {
1972
- image: $.attr(elem, 'poster') && $.prop(elem, 'poster') || '',
1973
- file: canPlaySrc.streamId || canPlaySrc.srcProp
1974
- });
1975
- var elemVars = $(elem).data('vars') || {};
1976
344
 
1977
- if(canPlaySrc.server){
1978
- vars.streamer = canPlaySrc.server;
1979
- }
1980
- if(!data){
1981
- data = webshims.data(elem, 'mediaelement');
1982
- }
345
+ this.startTime = startTime;
346
+ this.endTime = endTime;
347
+ this.text = text;
1983
348
 
1984
- if(data && data.swfCreated){
1985
- mediaelement.setActive(elem, 'third', data);
1986
- resetSwfProps(data);
1987
- data.currentSrc = canPlaySrc.srcProp;
1988
- $.extend(vars, elemVars);
1989
- options.changeSWF(vars, elem, canPlaySrc, data, 'load');
1990
- queueSwfMethod(elem, SENDEVENT, ['LOAD', vars]);
1991
- return;
1992
- }
349
+ this.id = "";
350
+ this.pauseOnExit = false;
1993
351
 
352
+ createEventTarget(this);
353
+ };
354
+
355
+ window.TextTrackCue.prototype = {
1994
356
 
1995
- var hasControls = $.prop(elem, 'controls');
1996
- var elemId = 'jwplayer-'+ webshims.getID(elem);
1997
- var params = $.extend(
1998
- {},
1999
- options.params,
2000
- $(elem).data('params')
2001
- );
2002
- var elemNodeName = elem.nodeName.toLowerCase();
2003
- var attrs = $.extend(
2004
- {},
2005
- options.attrs,
2006
- {
2007
- name: elemId,
2008
- id: elemId
2009
- },
2010
- $(elem).data('attrs')
2011
- );
2012
- var box = $('<div class="polyfill-'+ (elemNodeName) +' polyfill-mediaelement" id="wrapper-'+ elemId +'"><div id="'+ elemId +'"></div>')
2013
- .css({
2014
- position: 'relative',
2015
- overflow: 'hidden'
2016
- })
2017
- ;
2018
- var setDimensions = function(){
2019
- setElementDimension(data, $.prop(elem, 'controls'));
2020
- };
2021
-
2022
- data = webshims.data(elem, 'mediaelement', webshims.objectCreate(playerStateObj, {
2023
- actionQueue: {
2024
- value: []
2025
- },
2026
- shadowElem: {
2027
- value: box
2028
- },
2029
- _elemNodeName: {
2030
- value: elemNodeName
2031
- },
2032
- _elem: {
2033
- value: elem
2034
- },
2035
- currentSrc: {
2036
- value: canPlaySrc.srcProp
2037
- },
2038
- swfCreated: {
2039
- value: true
2040
- },
2041
- buffered: {
2042
- value: {
2043
- start: function(index){
2044
- if(index >= data.buffered.length){
2045
- webshims.error('buffered index size error');
2046
- return;
2047
- }
2048
- return 0;
2049
- },
2050
- end: function(index){
2051
- if(index >= data.buffered.length){
2052
- webshims.error('buffered index size error');
2053
- return;
357
+ onenter: null,
358
+ onexit: null,
359
+ pauseOnExit: false,
360
+ getCueAsHTML: function(){
361
+ var lastText = "";
362
+ var parsedText = "";
363
+ var fragment = document.createDocumentFragment();
364
+ var fn;
365
+ if(!owns(this, 'getCueAsHTML')){
366
+ fn = this.getCueAsHTML = function(){
367
+ var i, len;
368
+ if(lastText != this.text){
369
+ lastText = this.text;
370
+ parsedText = mediaelement.parseCueTextToHTML(lastText);
371
+ emptyDiv.innerHTML = parsedText;
372
+
373
+ for(i = 0, len = emptyDiv.childNodes.length; i < len; i++){
374
+ fragment.appendChild(emptyDiv.childNodes[i].cloneNode(true));
2054
375
  }
2055
- return ( (data.duration - data._bufferedStart) * data._bufferedEnd / 100) + data._bufferedStart;
2056
- },
2057
- length: 0
2058
- }
376
+ }
377
+ return fragment.cloneNode(true);
378
+ };
379
+
2059
380
  }
2060
- }));
2061
-
2062
- setElementDimension(data, hasControls);
381
+ return fn ? fn.apply(this, arguments) : fragment.cloneNode(true);
382
+ },
383
+ track: null,
2063
384
 
2064
- box.insertBefore(elem);
2065
385
 
2066
- if(hasNative){
2067
- $.extend(data, {volume: $.prop(elem, 'volume'), muted: $.prop(elem, 'muted')});
2068
- }
386
+ id: ''
387
+ //todo-->
388
+ // ,
389
+ // snapToLines: true,
390
+ // line: 'auto',
391
+ // size: 100,
392
+ // position: 50,
393
+ // vertical: '',
394
+ // align: 'middle'
395
+ };
396
+
397
+
398
+
399
+
400
+
401
+ mediaelement.createCueList = function(){
402
+ return $.extend([], cueListProto);
403
+ };
404
+
405
+ mediaelement.parseCueTextToHTML = (function(){
406
+ var tagSplits = /(<\/?[^>]+>)/ig;
407
+ var allowedTags = /^(?:c|v|ruby|rt|b|i|u)/;
408
+ var regEnd = /\<\s*\//;
409
+ var addToTemplate = function(localName, attribute, tag, html){
410
+ var ret;
411
+ if(regEnd.test(html)){
412
+ ret = '</'+ localName +'>';
413
+ } else {
414
+ tag.splice(0, 1);
415
+ ret = '<'+ localName +' '+ attribute +'="'+ (tag.join(' ').replace(/\"/g, '&#34;')) +'">';
416
+ }
417
+ return ret;
418
+ };
419
+ var replacer = function(html){
420
+ var tag = html.replace(/[<\/>]+/ig,"").split(/[\s\.]+/);
421
+ if(tag[0]){
422
+ tag[0] = tag[0].toLowerCase();
423
+ if(allowedTags.test(tag[0])){
424
+ if(tag[0] == 'c'){
425
+ html = addToTemplate('span', 'class', tag, html);
426
+ } else if(tag[0] == 'v'){
427
+ html = addToTemplate('q', 'title', tag, html);
428
+ }
429
+ } else {
430
+ html = "";
431
+ }
432
+ }
433
+ return html;
434
+ };
2069
435
 
2070
- $.extend(vars,
2071
- {
2072
- id: elemId,
2073
- controlbar: hasControls ? options.vars.controlbar || (elemNodeName == 'video' ? 'over' : 'bottom') : (elemNodeName == 'video') ? 'none' : 'bottom',
2074
- icons: ''+ (hasControls && elemNodeName == 'video')
2075
- },
2076
- elemVars,
2077
- {playerready: 'jQuery.webshims.mediaelement.jwPlayerReady'}
2078
- );
2079
- if(vars.plugins){
2080
- vars.plugins += ','+jwplugin;
2081
- } else {
2082
- vars.plugins = jwplugin;
436
+ return function(cueText){
437
+ return cueText.replace(tagSplits, replacer);
438
+ };
439
+ })();
440
+
441
+ mediaelement.loadTextTrack = function(mediaelem, track, trackData, _default){
442
+ var loadEvents = 'play playing timeupdate updatetrackdisplay';
443
+ var obj = trackData.track;
444
+ var load = function(){
445
+ var src = $.prop(track, 'src');
446
+ var error;
447
+ var ajax;
448
+ if(obj.mode != 'disabled' && src && $.attr(track, 'src')){
449
+ $(mediaelem).unbind(loadEvents, load);
450
+ $(track).unbind('checktrackmode', load);
451
+ if(!obj.readyState){
452
+ error = function(){
453
+ obj.readyState = 3;
454
+ obj.cues = null;
455
+ obj.activeCues = obj.shimActiveCues = obj._shimActiveCues = null;
456
+ $(track).triggerHandler('error');
457
+ };
458
+ obj.readyState = 1;
459
+ try {
460
+ obj.cues = mediaelement.createCueList();
461
+ obj.activeCues = obj.shimActiveCues = obj._shimActiveCues = mediaelement.createCueList();
462
+ ajax = $.ajax({
463
+ dataType: 'text',
464
+ url: src,
465
+ success: function(text){
466
+ if(ajax.getResponseHeader('content-type') != 'text/vtt'){
467
+ webshims.error('set the mime-type of your WebVTT files to text/vtt. see: http://dev.w3.org/html5/webvtt/#text/vtt');
468
+ }
469
+ mediaelement.parseCaptions(text, obj, function(cues){
470
+ if(cues && 'length' in cues){
471
+ obj.readyState = 2;
472
+ $(track).triggerHandler('load');
473
+ $(mediaelem).triggerHandler('updatetrackdisplay');
474
+ } else {
475
+ error();
476
+ }
477
+ });
478
+
479
+ },
480
+ error: error
481
+ });
482
+ } catch(er){
483
+ error();
484
+ webshims.warn(er);
485
+ }
486
+ }
487
+ }
488
+ };
489
+ obj.readyState = 0;
490
+ obj.shimActiveCues = null;
491
+ obj._shimActiveCues = null;
492
+ obj.activeCues = null;
493
+ obj.cues = null;
494
+ $(mediaelem).unbind(loadEvents, load);
495
+ $(track).unbind('checktrackmode', load);
496
+ $(mediaelem).on(loadEvents, load);
497
+ $(track).on('checktrackmode', load);
498
+ if(_default){
499
+ obj.mode = showTracks[obj.kind] ? 'showing' : 'hidden';
500
+ load();
501
+ }
502
+ };
503
+
504
+ mediaelement.createTextTrack = function(mediaelem, track){
505
+ var obj, trackData;
506
+ if(track.nodeName){
507
+ trackData = webshims.data(track, 'trackData');
508
+
509
+ if(trackData){
510
+ refreshTrack(track, trackData);
511
+ obj = trackData.track;
512
+ }
2083
513
  }
2084
514
 
2085
-
2086
- webshims.addShadowDom(elem, box);
2087
-
2088
- addMediaToStopEvents(elem);
2089
-
2090
- mediaelement.setActive(elem, 'third', data);
2091
-
2092
- options.changeSWF(vars, elem, canPlaySrc, data, 'embed');
2093
-
2094
-
2095
- $(document).on('updateshadowdom', setDimensions);
2096
- $(elem).on('updatemediaelementdimensions', setDimensions);
2097
-
2098
-
2099
- swfobject.embedSWF(playerSwfPath, elemId, "100%", "100%", "9.0.0", false, vars, params, attrs, function(swfData){
515
+ if(!obj){
516
+ obj = createEventTarget(webshims.objectCreate(textTrackProto));
2100
517
 
2101
- if(swfData.success){
2102
- data.jwapi = swfData.ref;
2103
-
2104
- if(!hasControls){
2105
- $(swfData.ref).attr('tabindex', '-1').css('outline', 'none');
2106
- }
2107
- setTimeout(function(){
2108
- if((!swfData.ref.parentNode && box[0].parentNode) || swfData.ref.style.display == "none"){
2109
- box.addClass('flashblocker-assumed');
2110
- $(elem).trigger('flashblocker');
2111
- webshims.warn("flashblocker assumed");
518
+ if(!supportTrackMod){
519
+ copyProps.forEach(function(copyProp){
520
+ var prop = $.prop(track, copyProp);
521
+ if(prop){
522
+ obj[copyName[copyProp] || copyProp] = prop;
2112
523
  }
2113
- $(swfData.ref).css({'minHeight': '2px', 'minWidth': '2px', display: 'block'});
2114
- }, 9);
2115
- if(!localConnectionTimer){
2116
- clearTimeout(localConnectionTimer);
2117
- localConnectionTimer = setTimeout(function(){
2118
- var flash = $(swfData.ref);
2119
- if(flash[0].offsetWidth > 1 && flash[0].offsetHeight > 1 && location.protocol.indexOf('file:') === 0){
2120
- 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");
2121
- } else if(flash[0].offsetWidth < 2 || flash[0].offsetHeight < 2) {
2122
- webshims.warn("JS-SWF connection can't be established on hidden or unconnected flash objects");
2123
- }
2124
- flash = null;
2125
- }, 8000);
2126
- }
524
+ });
2127
525
  }
2128
- });
2129
- };
2130
-
2131
-
2132
- var queueSwfMethod = function(elem, fn, args, data){
2133
- data = data || getSwfDataFromElem(elem);
2134
- if(data){
2135
- if(data.jwapi && data.jwapi[fn]){
2136
- data.jwapi[fn].apply(data.jwapi, args || []);
526
+
527
+
528
+ if(track.nodeName){
529
+
530
+ if(supportTrackMod){
531
+ copyProps.forEach(function(copyProp){
532
+ webshims.defineProperty(obj, copyName[copyProp] || copyProp, {
533
+ get: function(){
534
+ return $.prop(track, copyProp);
535
+ }
536
+ });
537
+ });
538
+ }
539
+
540
+ trackData = webshims.data(track, 'trackData', {track: obj});
541
+ mediaelement.loadTextTrack(mediaelem, track, trackData, ($.prop(track, 'default') && $(track).siblings('track[default]')[ADDBACK]()[0] == track));
2137
542
  } else {
2138
- //todo add to queue
2139
- data.actionQueue.push({fn: fn, args: args});
2140
- if(data.actionQueue.length > 10){
2141
- setTimeout(function(){
2142
- if(data.actionQueue.length > 5){
2143
- data.actionQueue.shift();
2144
- }
2145
- }, 99);
543
+ if(supportTrackMod){
544
+ copyProps.forEach(function(copyProp){
545
+ webshims.defineProperty(obj, copyName[copyProp] || copyProp, {
546
+ value: track[copyProp],
547
+ writeable: false
548
+ });
549
+ });
2146
550
  }
551
+ obj.cues = mediaelement.createCueList();
552
+ obj.activeCues = obj._shimActiveCues = obj.shimActiveCues = mediaelement.createCueList();
553
+ obj.mode = 'hidden';
554
+ obj.readyState = 2;
2147
555
  }
2148
- return data;
2149
556
  }
2150
- return false;
557
+ return obj;
2151
558
  };
2152
559
 
2153
- ['audio', 'video'].forEach(function(nodeName){
2154
- var descs = {};
2155
- var mediaSup;
2156
- var createGetProp = function(key){
2157
- if(nodeName == 'audio' && (key == 'videoHeight' || key == 'videoWidth')){return;}
560
+
561
+ /*
562
+ taken from:
563
+ Captionator 0.5.1 [CaptionCrunch]
564
+ Christopher Giffard, 2011
565
+ Share and enjoy
566
+
567
+ https://github.com/cgiffard/Captionator
568
+
569
+ modified for webshims
570
+ */
571
+ mediaelement.parseCaptionChunk = (function(){
572
+ // Set up timestamp parsers
573
+ var WebVTTTimestampParser = /^(\d{2})?:?(\d{2}):(\d{2})\.(\d+)\s+\-\-\>\s+(\d{2})?:?(\d{2}):(\d{2})\.(\d+)\s*(.*)/;
574
+ var GoogleTimestampParser = /^([\d\.]+)\s+\+([\d\.]+)\s*(.*)/;
575
+ var WebVTTDEFAULTSCueParser = /^(DEFAULTS|DEFAULT)\s+\-\-\>\s+(.*)/g;
576
+ var WebVTTSTYLECueParser = /^(STYLE|STYLES)\s+\-\-\>\s*\n([\s\S]*)/g;
577
+ var WebVTTCOMMENTCueParser = /^(COMMENT|COMMENTS)\s+\-\-\>\s+(.*)/g;
578
+
579
+ return function(subtitleElement,objectCount){
580
+ var cueDefaults = [];
581
+
582
+ var subtitleParts, timeIn, timeOut, html, timeData, subtitlePartIndex, cueSettings = "", id, specialCueData;
583
+ var timestampMatch, tmpCue;
584
+
585
+ // WebVTT Special Cue Logic
586
+ if ((specialCueData = WebVTTDEFAULTSCueParser.exec(subtitleElement))) {
587
+ // cueDefaults = specialCueData.slice(2).join("");
588
+ // cueDefaults = cueDefaults.split(/\s+/g).filter(function(def) { return def && !!def.length; });
589
+ return null;
590
+ } else if ((specialCueData = WebVTTSTYLECueParser.exec(subtitleElement))) {
591
+ return null;
592
+ } else if ((specialCueData = WebVTTCOMMENTCueParser.exec(subtitleElement))) {
593
+ return null; // At this stage, we don't want to do anything with these.
594
+ }
2158
595
 
2159
- descs[key] = {
2160
- get: function(){
2161
- var data = getSwfDataFromElem(this);
2162
- if(data){
2163
- return data[key];
2164
- } else if(hasNative && mediaSup[key].prop._supget) {
2165
- return mediaSup[key].prop._supget.apply(this);
2166
- } else {
2167
- return playerStateObj[key];
2168
- }
2169
- },
2170
- writeable: false
2171
- };
2172
- };
2173
- var createGetSetProp = function(key, setFn){
2174
- createGetProp(key);
2175
- delete descs[key].writeable;
2176
- descs[key].set = setFn;
2177
- };
596
+ subtitleParts = subtitleElement.split(/\n/g);
2178
597
 
2179
- createGetSetProp('volume', function(v){
2180
- var data = getSwfDataFromElem(this);
2181
- if(data){
2182
- v *= 100;
2183
- if(!isNaN(v)){
2184
- var muted = data.muted;
2185
- if(v < 0 || v > 100){
2186
- webshims.error('volume greater or less than allowed '+ (v / 100));
2187
- }
2188
-
2189
- queueSwfMethod(this, SENDEVENT, ['VOLUME', v], data);
2190
- if(muted){
2191
- try {
2192
- data.jwapi.sendEvent('mute', 'true');
2193
- } catch(er){}
2194
- }
2195
- v /= 100;
2196
- if(data.volume == v || data.isActive != 'third'){return;}
2197
- data.volume = v;
2198
- trigger(data._elem, 'volumechange');
2199
- data = null;
2200
- }
2201
- } else if(mediaSup.volume.prop._supset) {
2202
- return mediaSup.volume.prop._supset.apply(this, arguments);
598
+ // Trim off any blank lines (logically, should only be max. one, but loop to be sure)
599
+ while (!subtitleParts[0].replace(/\s+/ig,"").length && subtitleParts.length > 0) {
600
+ subtitleParts.shift();
2203
601
  }
2204
- });
2205
602
 
2206
- createGetSetProp('muted', function(m){
2207
- var data = getSwfDataFromElem(this);
2208
- if(data){
2209
- m = !!m;
2210
- queueSwfMethod(this, SENDEVENT, ['mute', ''+m], data);
2211
- if(data.muted == m || data.isActive != 'third'){return;}
2212
- data.muted = m;
2213
- trigger(data._elem, 'volumechange');
2214
- data = null;
2215
- } else if(mediaSup.muted.prop._supset) {
2216
- return mediaSup.muted.prop._supset.apply(this, arguments);
603
+ if (subtitleParts[0].match(/^\s*[a-z0-9-\_]+\s*$/ig)) {
604
+ // The identifier becomes the cue ID (when *we* load the cues from file. Programatically created cues can have an ID of whatever.)
605
+ id = String(subtitleParts.shift().replace(/\s*/ig,""));
2217
606
  }
2218
- });
2219
607
 
2220
-
2221
- createGetSetProp('currentTime', function(t){
2222
- var data = getSwfDataFromElem(this);
2223
- if(data){
2224
- t *= 1;
2225
- if (!isNaN(t)) {
2226
- if(data.paused){
2227
- clearTimeout(data.stopPlayPause);
2228
- data.stopPlayPause = setTimeout(function(){
2229
- data.paused = true;
2230
- data.stopPlayPause = false;
2231
- }, 50);
2232
- }
2233
- queueSwfMethod(this, SENDEVENT, ['SEEK', '' + t], data);
608
+ for (subtitlePartIndex = 0; subtitlePartIndex < subtitleParts.length; subtitlePartIndex ++) {
609
+ var timestamp = subtitleParts[subtitlePartIndex];
610
+
611
+ if ((timestampMatch = WebVTTTimestampParser.exec(timestamp))) {
2234
612
 
2235
- if(data.paused){
2236
- if(data.readyState > 0){
2237
- data.currentTime = t;
2238
- trigger(data._elem, 'timeupdate');
2239
- }
2240
- try {
2241
- data.jwapi[SENDEVENT]('play', 'false');
2242
- } catch(er){}
2243
-
613
+ // WebVTT
614
+
615
+ timeData = timestampMatch.slice(1);
616
+
617
+ timeIn = parseInt((timeData[0]||0) * 60 * 60,10) + // Hours
618
+ parseInt((timeData[1]||0) * 60,10) + // Minutes
619
+ parseInt((timeData[2]||0),10) + // Seconds
620
+ parseFloat("0." + (timeData[3]||0)); // MS
621
+
622
+ timeOut = parseInt((timeData[4]||0) * 60 * 60,10) + // Hours
623
+ parseInt((timeData[5]||0) * 60,10) + // Minutes
624
+ parseInt((timeData[6]||0),10) + // Seconds
625
+ parseFloat("0." + (timeData[7]||0)); // MS
626
+ /*
627
+ if (timeData[8]) {
628
+ cueSettings = timeData[8];
2244
629
  }
630
+ */
2245
631
  }
2246
-
2247
- } else if(mediaSup.currentTime.prop._supset) {
2248
- return mediaSup.currentTime.prop._supset.apply(this, arguments);
632
+
633
+ // We've got the timestamp - return all the other unmatched lines as the raw subtitle data
634
+ subtitleParts = subtitleParts.slice(0,subtitlePartIndex).concat(subtitleParts.slice(subtitlePartIndex+1));
635
+ break;
2249
636
  }
2250
- });
2251
-
2252
- ['play', 'pause'].forEach(function(fn){
2253
- descs[fn] = {
2254
- value: function(){
2255
- var data = getSwfDataFromElem(this);
2256
- if(data){
2257
- if(data.stopPlayPause){
2258
- clearTimeout(data.stopPlayPause);
2259
- }
2260
- queueSwfMethod(this, SENDEVENT, ['play', fn == 'play'], data);
2261
- setTimeout(function(){
2262
- if(data.isActive == 'third'){
2263
- data._ppFlag = true;
2264
- if(data.paused != (fn != 'play')){
2265
- data.paused = fn != 'play';
2266
- trigger(data._elem, fn);
2267
- }
2268
- }
2269
- }, 1);
2270
- } else if(mediaSup[fn].prop._supvalue) {
2271
- return mediaSup[fn].prop._supvalue.apply(this, arguments);
2272
- }
2273
- }
2274
- };
2275
- });
2276
-
2277
- getPropKeys.forEach(createGetProp);
2278
-
2279
- webshims.onNodeNamesPropertyModify(nodeName, 'controls', function(val, boolProp){
2280
- var data = getSwfDataFromElem(this);
2281
- $(this)[boolProp ? 'addClass' : 'removeClass']('webshims-controls');
637
+
638
+ if (!timeIn && !timeOut) {
639
+ // We didn't extract any time information. Assume the cue is invalid!
640
+ webshims.warn("couldn't extract time information: "+[timeIn, timeOut, subtitleParts.join("\n"), id].join(' ; '));
641
+ return null;
642
+ }
643
+ /*
644
+ // Consolidate cue settings, convert defaults to object
645
+ var compositeCueSettings =
646
+ cueDefaults
647
+ .reduce(function(previous,current,index,array){
648
+ previous[current.split(":")[0]] = current.split(":")[1];
649
+ return previous;
650
+ },{});
2282
651
 
2283
- if(data){
2284
- try {
2285
- queueSwfMethod(this, boolProp ? 'showControls' : 'hideControls', [nodeName], data);
2286
- } catch(er){
2287
- webshims.warn("you need to generate a crossdomain.xml");
2288
- }
2289
- if(nodeName == 'audio'){
2290
- setElementDimension(data, boolProp);
652
+ // Loop through cue settings, replace defaults with cue specific settings if they exist
653
+ compositeCueSettings =
654
+ cueSettings
655
+ .split(/\s+/g)
656
+ .filter(function(set) { return set && !!set.length; })
657
+ // Convert array to a key/val object
658
+ .reduce(function(previous,current,index,array){
659
+ previous[current.split(":")[0]] = current.split(":")[1];
660
+ return previous;
661
+ },compositeCueSettings);
662
+
663
+ // Turn back into string like the TextTrackCue constructor expects
664
+ cueSettings = "";
665
+ for (var key in compositeCueSettings) {
666
+ if (compositeCueSettings.hasOwnProperty(key)) {
667
+ cueSettings += !!cueSettings.length ? " " : "";
668
+ cueSettings += key + ":" + compositeCueSettings[key];
2291
669
  }
2292
- $(data.jwapi).attr('tabindex', boolProp ? '0' : '-1');
2293
670
  }
2294
- });
2295
-
2296
- mediaSup = webshims.defineNodeNameProperties(nodeName, descs, 'prop');
2297
- });
2298
-
2299
- if(hasFlash && $.cleanData){
2300
- var oldClean = $.cleanData;
2301
- var flashNames = {
2302
- object: 1,
2303
- OBJECT: 1
671
+ */
672
+ // The remaining lines are the subtitle payload itself (after removing an ID if present, and the time);
673
+ html = subtitleParts.join("\n");
674
+ tmpCue = new TextTrackCue(timeIn, timeOut, html);
675
+ if(id){
676
+ tmpCue.id = id;
677
+ }
678
+ return tmpCue;
2304
679
  };
2305
- $.cleanData = function(elems){
2306
- var i, len, prop;
2307
- if(elems && (len = elems.length) && loadedSwf){
680
+ })();
681
+
682
+ mediaelement.parseCaptions = function(captionData, track, complete) {
683
+ var subtitles = mediaelement.createCueList();
684
+ var cue, lazyProcess, regWevVTT;
685
+ var startDate;
686
+ var isWEBVTT;
687
+ if (captionData) {
688
+
689
+ regWevVTT = /^WEBVTT(\s*FILE)?/ig;
690
+
691
+ lazyProcess = function(i, len){
2308
692
 
2309
- for(i = 0; i < len; i++){
2310
- if(flashNames[elems[i].nodeName]){
2311
- if(SENDEVENT in elems[i]){
2312
- loadedSwf--;
2313
- try {
2314
- elems[i][SENDEVENT]('play', false);
2315
- } catch(er){}
693
+ for(; i < len; i++){
694
+ cue = captionData[i];
695
+ if(regWevVTT.test(cue)){
696
+ isWEBVTT = true;
697
+ } else if(cue.replace(/\s*/ig,"").length){
698
+ if(!isWEBVTT){
699
+ webshims.error('please use WebVTT format. This is the standard');
700
+ complete(null);
701
+ break;
2316
702
  }
2317
- try {
2318
- for (prop in elems[i]) {
2319
- if (typeof elems[i][prop] == "function") {
2320
- elems[i][prop] = null;
2321
- }
2322
- }
2323
- } catch(er){}
703
+ cue = mediaelement.parseCaptionChunk(cue, i);
704
+ if(cue){
705
+ track.addCue(cue);
706
+ }
707
+ }
708
+ if(startDate < (new Date().getTime()) - 30){
709
+ i++;
710
+ setTimeout(function(){
711
+ startDate = new Date().getTime();
712
+ lazyProcess(i, len);
713
+ }, 90);
714
+
715
+ break;
2324
716
  }
2325
717
  }
2326
-
2327
- }
2328
- return oldClean.apply(this, arguments);
2329
- };
2330
- }
2331
-
2332
- if(!hasNative){
718
+ if(i >= len){
719
+ if(!isWEBVTT){
720
+ webshims.error('please use WebVTT format. This is the standard');
721
+ }
722
+ complete(track.cues);
723
+ }
724
+ };
725
+
726
+ captionData = captionData.replace(/\r\n/g,"\n");
727
+
728
+ setTimeout(function(){
729
+ captionData = captionData.replace(/\r/g,"\n");
730
+ setTimeout(function(){
731
+ startDate = new Date().getTime();
732
+ captionData = captionData.split(/\n\n+/g);
733
+ lazyProcess(0, captionData.length);
734
+ }, 9);
735
+ }, 9);
736
+
737
+ } else {
738
+ webshims.error("Required parameter captionData not supplied.");
739
+ }
740
+ };
741
+
742
+
743
+ mediaelement.createTrackList = function(mediaelem, baseData){
744
+ baseData = baseData || webshims.data(mediaelem, 'mediaelementBase') || webshims.data(mediaelem, 'mediaelementBase', {});
745
+ if(!baseData.textTracks){
746
+ baseData.textTracks = [];
747
+ webshims.defineProperties(baseData.textTracks, {
748
+ onaddtrack: {value: null},
749
+ onremovetrack: {value: null}
750
+ });
751
+ createEventTarget(baseData.textTracks);
752
+ }
753
+ return baseData.textTracks;
754
+ };
755
+
756
+ if(!Modernizr.track){
757
+ webshims.defineNodeNamesBooleanProperty(['track'], 'default');
758
+ webshims.reflectProperties(['track'], ['srclang', 'label']);
2333
759
 
2334
- ['poster', 'src'].forEach(function(prop){
2335
- webshims.defineNodeNamesProperty(prop == 'src' ? ['audio', 'video', 'source'] : ['video'], prop, {
760
+ webshims.defineNodeNameProperties('track', {
761
+ src: {
2336
762
  //attr: {},
2337
763
  reflect: true,
2338
764
  propType: 'src'
2339
- });
765
+ }
2340
766
  });
2341
-
2342
-
2343
- ['autoplay', 'controls'].forEach(function(name){
2344
- webshims.defineNodeNamesBooleanProperty(['audio', 'video'], name);
767
+ }
768
+
769
+ webshims.defineNodeNameProperties('track', {
770
+ kind: {
771
+ attr: Modernizr.track ? {
772
+ set: function(value){
773
+ var trackData = webshims.data(this, 'trackData');
774
+ this.setAttribute('data-kind', value);
775
+ if(trackData){
776
+ trackData.attrKind = value;
777
+ }
778
+ },
779
+ get: function(){
780
+ var trackData = webshims.data(this, 'trackData');
781
+ if(trackData && ('attrKind' in trackData)){
782
+ return trackData.attrKind;
783
+ }
784
+ return this.getAttribute('kind');
785
+ }
786
+ } : {},
787
+ reflect: true,
788
+ propType: 'enumarated',
789
+ defaultValue: 'subtitles',
790
+ limitedTo: ['subtitles', 'captions', 'descriptions', 'chapters', 'metadata']
791
+ }
792
+ });
793
+
794
+ $.each(copyProps, function(i, copyProp){
795
+ var name = copyName[copyProp] || copyProp;
796
+ webshims.onNodeNamesPropertyModify('track', copyProp, function(){
797
+ var trackData = webshims.data(this, 'trackData');
798
+ var track = this;
799
+ if(trackData){
800
+ if(copyProp == 'kind'){
801
+ refreshTrack(this, trackData);
802
+ }
803
+ if(!supportTrackMod){
804
+ trackData.track[name] = $.prop(this, copyProp);
805
+ }
806
+ clearTimeout(trackData.changedTrackPropTimer);
807
+ trackData.changedTrackPropTimer = setTimeout(function(){
808
+ $(track).trigger('updatesubtitlestate');
809
+ }, 1);
810
+ }
2345
811
  });
2346
-
2347
- webshims.defineNodeNamesProperties(['audio', 'video'], {
2348
- HAVE_CURRENT_DATA: {
2349
- value: 2
2350
- },
2351
- HAVE_ENOUGH_DATA: {
2352
- value: 4
2353
- },
2354
- HAVE_FUTURE_DATA: {
2355
- value: 3
2356
- },
2357
- HAVE_METADATA: {
2358
- value: 1
2359
- },
2360
- HAVE_NOTHING: {
2361
- value: 0
2362
- },
2363
- NETWORK_EMPTY: {
2364
- value: 0
812
+ });
813
+
814
+
815
+ webshims.onNodeNamesPropertyModify('track', 'src', function(val){
816
+ if(val){
817
+ var data = webshims.data(this, 'trackData');
818
+ var media;
819
+ if(data){
820
+ media = $(this).closest('video, audio');
821
+ if(media[0]){
822
+ mediaelement.loadTextTrack(media, this, data);
823
+ }
824
+ }
825
+ }
826
+
827
+ });
828
+
829
+ //
830
+
831
+ webshims.defineNodeNamesProperties(['track'], {
832
+ ERROR: {
833
+ value: 3
834
+ },
835
+ LOADED: {
836
+ value: 2
837
+ },
838
+ LOADING: {
839
+ value: 1
840
+ },
841
+ NONE: {
842
+ value: 0
843
+ },
844
+ readyState: {
845
+ get: function(){
846
+ return ($.prop(this, 'track') || {readyState: 0}).readyState;
2365
847
  },
2366
- NETWORK_IDLE: {
2367
- value: 1
848
+ writeable: false
849
+ },
850
+ track: {
851
+ get: function(){
852
+ return mediaelement.createTextTrack($(this).closest('audio, video')[0], this);
2368
853
  },
2369
- NETWORK_LOADING: {
2370
- value: 2
854
+ writeable: false
855
+ }
856
+ }, 'prop');
857
+
858
+ webshims.defineNodeNamesProperties(['audio', 'video'], {
859
+ textTracks: {
860
+ get: function(){
861
+ var media = this;
862
+ var baseData = webshims.data(media, 'mediaelementBase') || webshims.data(media, 'mediaelementBase', {});
863
+ var tracks = mediaelement.createTrackList(media, baseData);
864
+ if(!baseData.blockTrackListUpdate){
865
+ updateMediaTrackList.call(media, baseData, tracks);
866
+ }
867
+ return tracks;
2371
868
  },
2372
- NETWORK_NO_SOURCE: {
2373
- value: 3
869
+ writeable: false
870
+ },
871
+ addTextTrack: {
872
+ value: function(kind, label, lang){
873
+ var textTrack = mediaelement.createTextTrack(this, {
874
+ kind: dummyTrack.prop('kind', kind || '').prop('kind'),
875
+ label: label || '',
876
+ srclang: lang || ''
877
+ });
878
+ var baseData = webshims.data(this, 'mediaelementBase') || webshims.data(this, 'mediaelementBase', {});
879
+ if (!baseData.scriptedTextTracks) {
880
+ baseData.scriptedTextTracks = [];
881
+ }
882
+ baseData.scriptedTextTracks.push(textTrack);
883
+ updateMediaTrackList.call(this);
884
+ return textTrack;
885
+ }
886
+ }
887
+ }, 'prop');
888
+
889
+
890
+ $(document).on('emptied ended updatetracklist', function(e){
891
+ if($(e.target).is('audio, video')){
892
+ var baseData = webshims.data(e.target, 'mediaelementBase');
893
+ if(baseData){
894
+ clearTimeout(baseData.updateTrackListTimer);
895
+ baseData.updateTrackListTimer = setTimeout(function(){
896
+ updateMediaTrackList.call(e.target, baseData);
897
+ }, 0);
898
+ }
899
+ }
900
+ });
901
+
902
+ var getNativeReadyState = function(trackElem, textTrack){
903
+ return textTrack.readyState || trackElem.readyState;
904
+ };
905
+ var stopOriginalEvent = function(e){
906
+ if(e.originalEvent){
907
+ e.stopImmediatePropagation();
908
+ }
909
+ };
910
+ var startTrackImplementation = function(){
911
+ if(webshims.implement(this, 'track')){
912
+ var shimedTrack = $.prop(this, 'track');
913
+ var origTrack = this.track;
914
+ var kind;
915
+ var readyState;
916
+ if(origTrack){
917
+ kind = $.prop(this, 'kind');
918
+ readyState = getNativeReadyState(this, origTrack);
919
+ if (origTrack.mode || readyState) {
920
+ shimedTrack.mode = numericModes[origTrack.mode] || origTrack.mode;
921
+ }
922
+ //disable track from showing + remove UI
923
+ if(kind != 'descriptions'){
924
+ origTrack.mode = (typeof origTrack.mode == 'string') ? 'disabled' : 0;
925
+ this.kind = 'metadata';
926
+ $(this).attr({kind: kind});
927
+ }
928
+
2374
929
  }
930
+ $(this).on('load error', stopOriginalEvent);
931
+ }
932
+ };
933
+ webshims.addReady(function(context, insertedElement){
934
+ var insertedMedia = insertedElement.filter('video, audio, track').closest('audio, video');
935
+ $('video, audio', context)
936
+ .add(insertedMedia)
937
+ .each(function(){
938
+ updateMediaTrackList.call(this);
939
+ })
940
+ .each(function(){
941
+ if(Modernizr.track){
942
+ var shimedTextTracks = $.prop(this, 'textTracks');
943
+ var origTextTracks = this.textTracks;
944
+ if(shimedTextTracks.length != origTextTracks.length){
945
+ webshims.error("textTracks couldn't be copied");
946
+ }
2375
947
 
2376
- }, 'prop');
948
+ $('track', this).each(startTrackImplementation);
949
+ }
950
+ })
951
+ ;
952
+ insertedMedia.each(function(){
953
+ var media = this;
954
+ var baseData = webshims.data(media, 'mediaelementBase');
955
+ if(baseData){
956
+ clearTimeout(baseData.updateTrackListTimer);
957
+ baseData.updateTrackListTimer = setTimeout(function(){
958
+ updateMediaTrackList.call(media, baseData);
959
+ }, 9);
960
+ }
961
+ });
962
+ });
963
+
964
+ if(Modernizr.track){
965
+ $('video, audio').trigger('trackapichange');
2377
966
  }
2378
967
  });