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,1733 +1,2074 @@
1
- if(!Modernizr.formvalidation || jQuery.webshims.bugs.bustedValidity){
2
- jQuery.webshims.register('form-shim-extend', function($, webshims, window, document){
3
- "use strict";
4
- webshims.inputTypes = webshims.inputTypes || {};
5
- //some helper-functions
6
- var cfg = webshims.cfg.forms;
7
- var isSubmit;
8
-
9
- var isNumber = function(string){
10
- return (typeof string == 'number' || (string && string == string * 1));
11
- },
12
- typeModels = webshims.inputTypes,
13
- checkTypes = {
14
- radio: 1,
15
- checkbox: 1
16
- },
17
- getType = function(elem){
18
- return (elem.getAttribute('type') || elem.type || '').toLowerCase();
19
- }
20
- ;
21
-
22
- //API to add new input types
23
- webshims.addInputType = function(type, obj){
24
- typeModels[type] = obj;
25
- };
26
-
27
- //contsrain-validation-api
28
- var validityPrototype = {
29
- customError: false,
30
-
31
- typeMismatch: false,
32
- rangeUnderflow: false,
33
- rangeOverflow: false,
34
- stepMismatch: false,
35
- tooLong: false,
36
- patternMismatch: false,
37
- valueMissing: false,
38
-
39
- valid: true
40
- };
1
+ (function($){
2
+ if(navigator.geolocation){return;}
3
+ var domWrite = function(){
4
+ setTimeout(function(){
5
+ throw('document.write is overwritten by geolocation shim. This method is incompatible with this plugin');
6
+ }, 1);
7
+ },
8
+ id = 0
9
+ ;
10
+ var geoOpts = $.webshims.cfg.geolocation || {};
11
+ navigator.geolocation = (function(){
12
+ var pos;
13
+ var api = {
14
+ getCurrentPosition: function(success, error, opts){
15
+ var locationAPIs = 2,
16
+ errorTimer,
17
+ googleTimer,
18
+ calledEnd,
19
+ endCallback = function(){
20
+ if(calledEnd){return;}
21
+ if(pos){
22
+ calledEnd = true;
23
+ success($.extend({timestamp: new Date().getTime()}, pos));
24
+ resetCallback();
25
+ if(window.JSON && window.sessionStorage){
26
+ try{
27
+ sessionStorage.setItem('storedGeolocationData654321', JSON.stringify(pos));
28
+ } catch(e){}
29
+ }
30
+ } else if(error && !locationAPIs) {
31
+ calledEnd = true;
32
+ resetCallback();
33
+ error({ code: 2, message: "POSITION_UNAVAILABLE"});
34
+ }
35
+ },
36
+ googleCallback = function(){
37
+ locationAPIs--;
38
+ getGoogleCoords();
39
+ endCallback();
40
+ },
41
+ resetCallback = function(){
42
+ $(document).unbind('google-loader', resetCallback);
43
+ clearTimeout(googleTimer);
44
+ clearTimeout(errorTimer);
45
+ },
46
+ getGoogleCoords = function(){
47
+ if(pos || !window.google || !google.loader || !google.loader.ClientLocation){return false;}
48
+ var cl = google.loader.ClientLocation;
49
+ pos = {
50
+ coords: {
51
+ latitude: cl.latitude,
52
+ longitude: cl.longitude,
53
+ altitude: null,
54
+ accuracy: 43000,
55
+ altitudeAccuracy: null,
56
+ heading: parseInt('NaN', 10),
57
+ velocity: null
58
+ },
59
+ //extension similiar to FF implementation
60
+ address: $.extend({streetNumber: '', street: '', premises: '', county: '', postalCode: ''}, cl.address)
61
+ };
62
+ return true;
63
+ },
64
+ getInitCoords = function(){
65
+ if(pos){return;}
66
+ getGoogleCoords();
67
+ if(pos || !window.JSON || !window.sessionStorage){return;}
68
+ try{
69
+ pos = sessionStorage.getItem('storedGeolocationData654321');
70
+ pos = (pos) ? JSON.parse(pos) : false;
71
+ if(!pos.coords){pos = false;}
72
+ } catch(e){
73
+ pos = false;
74
+ }
75
+ }
76
+ ;
77
+
78
+ getInitCoords();
79
+
80
+ if(!pos){
81
+ if(geoOpts.confirmText && !confirm(geoOpts.confirmText.replace('{location}', location.hostname))){
82
+ if(error){
83
+ error({ code: 1, message: "PERMISSION_DENIED"});
84
+ }
85
+ return;
86
+ }
87
+ $.ajax({
88
+ url: 'http://freegeoip.net/json/',
89
+ dataType: 'jsonp',
90
+ cache: true,
91
+ jsonp: 'callback',
92
+ success: function(data){
93
+ locationAPIs--;
94
+ if(!data){return;}
95
+ pos = pos || {
96
+ coords: {
97
+ latitude: data.latitude,
98
+ longitude: data.longitude,
99
+ altitude: null,
100
+ accuracy: 43000,
101
+ altitudeAccuracy: null,
102
+ heading: parseInt('NaN', 10),
103
+ velocity: null
104
+ },
105
+ //extension similiar to FF implementation
106
+ address: {
107
+ city: data.city,
108
+ country: data.country_name,
109
+ countryCode: data.country_code,
110
+ county: "",
111
+ postalCode: data.zipcode,
112
+ premises: "",
113
+ region: data.region_name,
114
+ street: "",
115
+ streetNumber: ""
116
+ }
117
+ };
118
+ endCallback();
119
+ },
120
+ error: function(){
121
+ locationAPIs--;
122
+ endCallback();
123
+ }
124
+ });
125
+ clearTimeout(googleTimer);
126
+ if (!window.google || !window.google.loader) {
127
+ googleTimer = setTimeout(function(){
128
+ //destroys document.write!!!
129
+ if (geoOpts.destroyWrite) {
130
+ document.write = domWrite;
131
+ document.writeln = domWrite;
132
+ }
133
+ $(document).one('google-loader', googleCallback);
134
+ $.webshims.loader.loadScript('http://www.google.com/jsapi', false, 'google-loader');
135
+ }, 800);
136
+ } else {
137
+ locationAPIs--;
138
+ }
139
+ } else {
140
+ setTimeout(endCallback, 1);
141
+ return;
142
+ }
143
+ if(opts && opts.timeout){
144
+ errorTimer = setTimeout(function(){
145
+ resetCallback();
146
+ if(error) {
147
+ error({ code: 3, message: "TIMEOUT"});
148
+ }
149
+ }, opts.timeout);
150
+ } else {
151
+ errorTimer = setTimeout(function(){
152
+ locationAPIs = 0;
153
+ endCallback();
154
+ }, 10000);
155
+ }
156
+ },
157
+ clearWatch: $.noop
158
+ };
159
+ api.watchPosition = function(a, b, c){
160
+ api.getCurrentPosition(a, b, c);
161
+ id++;
162
+ return id;
163
+ };
164
+ return api;
165
+ })();
166
+
167
+ $.webshims.isReady('geolocation', true);
168
+ })(jQuery);
41
169
 
42
- var isPlaceholderOptionSelected = function(select){
43
- if(select.type == 'select-one' && select.size < 2){
44
- var option = $('> option:first-child', select);
45
- return !!option.prop('selected');
46
- }
47
- return false;
48
- };
170
+ jQuery.webshims.register('details', function($, webshims, window, doc, undefined, options){
171
+ var isInterActiveSummary = function(summary){
172
+ var details = $(summary).parent('details');
173
+ if(details[0] && details.children(':first').get(0) === summary){
174
+ return details;
175
+ }
176
+ };
177
+
178
+ var bindDetailsSummary = function(summary, details){
179
+ summary = $(summary);
180
+ details = $(details);
181
+ var oldSummary = $.data(details[0], 'summaryElement');
182
+ $.data(summary[0], 'detailsElement', details);
183
+ if(!oldSummary || summary[0] !== oldSummary[0]){
184
+ if(oldSummary){
185
+ if(oldSummary.hasClass('fallback-summary')){
186
+ oldSummary.remove();
187
+ } else {
188
+ oldSummary
189
+ .unbind('.summaryPolyfill')
190
+ .removeData('detailsElement')
191
+ .removeAttr('role')
192
+ .removeAttr('tabindex')
193
+ .removeAttr('aria-expanded')
194
+ .removeClass('summary-button')
195
+ .find('span.details-open-indicator')
196
+ .remove()
197
+ ;
198
+ }
199
+ }
200
+ $.data(details[0], 'summaryElement', summary);
201
+ details.prop('open', details.prop('open'));
202
+ }
203
+ };
204
+ var getSummary = function(details){
205
+ var summary = $.data(details, 'summaryElement');
206
+ if(!summary){
207
+ summary = $('> summary:first-child', details);
208
+ if(!summary[0]){
209
+ $(details).prependPolyfill('<summary class="fallback-summary">'+ options.text +'</summary>');
210
+ summary = $.data(details, 'summaryElement');
211
+ } else {
212
+ bindDetailsSummary(summary, details);
213
+ }
214
+ }
215
+ return summary;
216
+ };
217
+
218
+ // var isOriginalPrevented = function(e){
219
+ // var src = e.originalEvent;
220
+ // if(!src){return e.isDefaultPrevented();}
221
+ //
222
+ // return src.defaultPrevented || src.returnValue === false ||
223
+ // src.getPreventDefault && src.getPreventDefault();
224
+ // };
225
+
226
+ webshims.createElement('summary', function(){
227
+ var details = isInterActiveSummary(this);
228
+ if(!details || $.data(this, 'detailsElement')){return;}
229
+ var timer;
230
+ var stopNativeClickTest;
231
+ var tabindex = $.attr(this, 'tabIndex') || '0';
232
+ bindDetailsSummary(this, details);
233
+ $(this)
234
+ .on({
235
+ 'focus.summaryPolyfill': function(){
236
+ $(this).addClass('summary-has-focus');
237
+ },
238
+ 'blur.summaryPolyfill': function(){
239
+ $(this).removeClass('summary-has-focus');
240
+ },
241
+ 'mouseenter.summaryPolyfill': function(){
242
+ $(this).addClass('summary-has-hover');
243
+ },
244
+ 'mouseleave.summaryPolyfill': function(){
245
+ $(this).removeClass('summary-has-hover');
246
+ },
247
+ 'click.summaryPolyfill': function(e){
248
+ var details = isInterActiveSummary(this);
249
+ if(details){
250
+ if(!stopNativeClickTest && e.originalEvent){
251
+ stopNativeClickTest = true;
252
+ e.stopImmediatePropagation();
253
+ e.preventDefault();
254
+ $(this).trigger('click');
255
+ stopNativeClickTest = false;
256
+ return false;
257
+ } else {
258
+ clearTimeout(timer);
259
+
260
+ timer = setTimeout(function(){
261
+ if(!e.isDefaultPrevented()){
262
+ details.prop('open', !details.prop('open'));
263
+ }
264
+ }, 0);
265
+ }
266
+ }
267
+ },
268
+ 'keydown.summaryPolyfill': function(e){
269
+ if( (e.keyCode == 13 || e.keyCode == 32) && !e.isDefaultPrevented()){
270
+ stopNativeClickTest = true;
271
+ e.preventDefault();
272
+ $(this).trigger('click');
273
+ stopNativeClickTest = false;
274
+ }
275
+ }
276
+ })
277
+ .attr({tabindex: tabindex, role: 'button'})
278
+ .prepend('<span class="details-open-indicator" />')
279
+ ;
280
+ webshims.moveToFirstEvent(this, 'click');
281
+ });
282
+
283
+ var initDetails;
284
+ webshims.defineNodeNamesBooleanProperty('details', 'open', function(val){
285
+ var summary = $($.data(this, 'summaryElement'));
286
+ if(!summary){return;}
287
+ var action = (val) ? 'removeClass' : 'addClass';
288
+ var details = $(this);
289
+ if (!initDetails && options.animate){
290
+ details.stop().css({width: '', height: ''});
291
+ var start = {
292
+ width: details.width(),
293
+ height: details.height()
294
+ };
295
+ }
296
+ summary.attr('aria-expanded', ''+val);
297
+ details[action]('closed-details-summary').children().not(summary[0])[action]('closed-details-child');
298
+ if(!initDetails && options.animate){
299
+ var end = {
300
+ width: details.width(),
301
+ height: details.height()
302
+ };
303
+ details.css(start).animate(end, {
304
+ complete: function(){
305
+ $(this).css({width: '', height: ''});
306
+ }
307
+ });
308
+ }
309
+
310
+ });
311
+ webshims.createElement('details', function(){
312
+ initDetails = true;
313
+ var summary = getSummary(this);
314
+ $.prop(this, 'open', $.prop(this, 'open'));
315
+ initDetails = false;
316
+ });
317
+ });
49
318
 
50
- var validityRules = {
51
- valueMissing: function(input, val, cache){
52
- if(!input.prop('required')){return false;}
53
- var ret = false;
54
- if(!('type' in cache)){
55
- cache.type = getType(input[0]);
56
- }
57
- if(cache.nodeName == 'select'){
58
- ret = (!val && (input[0].selectedIndex < 0 || isPlaceholderOptionSelected(input[0]) ));
59
- } else if(checkTypes[cache.type]){
60
- ret = (cache.type == 'checkbox') ? !input.is(':checked') : !webshims.modules["form-core"].getGroupElements(input).filter(':checked')[0];
319
+ jQuery.webshims.register('mediaelement-jaris', function($, webshims, window, document, undefined, options){
320
+ "use strict";
321
+
322
+ var mediaelement = webshims.mediaelement;
323
+ var swfmini = window.swfmini;
324
+ var hasNative = Modernizr.audio && Modernizr.video;
325
+ var hasFlash = swfmini.hasFlashPlayerVersion('9.0.115');
326
+ var loadedSwf = 0;
327
+ var getProps = {
328
+ paused: true,
329
+ ended: false,
330
+ currentSrc: '',
331
+ duration: window.NaN,
332
+ readyState: 0,
333
+ networkState: 0,
334
+ videoHeight: 0,
335
+ videoWidth: 0,
336
+ error: null,
337
+ buffered: {
338
+ start: function(index){
339
+ if(index){
340
+ webshims.error('buffered index size error');
341
+ return;
342
+ }
343
+ return 0;
344
+ },
345
+ end: function(index){
346
+ if(index){
347
+ webshims.error('buffered index size error');
348
+ return;
349
+ }
350
+ return 0;
351
+ },
352
+ length: 0
353
+ }
354
+ };
355
+ var getPropKeys = Object.keys(getProps);
356
+
357
+ var getSetProps = {
358
+ currentTime: 0,
359
+ volume: 1,
360
+ muted: false
361
+ };
362
+ var getSetPropKeys = Object.keys(getSetProps);
363
+
364
+ var playerStateObj = $.extend({
365
+ isActive: 'html5',
366
+ activating: 'html5',
367
+ wasSwfReady: false,
368
+ _bufferedEnd: 0,
369
+ _bufferedStart: 0,
370
+ currentTime: 0,
371
+ _ppFlag: undefined,
372
+ _calledMeta: false,
373
+ lastDuration: 0
374
+ }, getProps, getSetProps);
375
+
376
+ var idRep = /^jarisplayer-/;
377
+ var getSwfDataFromID = function(id){
378
+
379
+ var elem = document.getElementById(id.replace(idRep, ''));
380
+ if(!elem){return;}
381
+ var data = webshims.data(elem, 'mediaelement');
382
+ return data.isActive == 'third' ? data : null;
383
+ };
384
+
385
+
386
+ var getSwfDataFromElem = function(elem){
387
+ try {
388
+ (elem.nodeName);
389
+ } catch(er){
390
+ return null;
391
+ }
392
+ var data = webshims.data(elem, 'mediaelement');
393
+ return (data && data.isActive== 'third') ? data : null;
394
+ };
395
+
396
+ var trigger = function(elem, evt){
397
+ evt = $.Event(evt);
398
+ evt.preventDefault();
399
+ $.event.trigger(evt, undefined, elem);
400
+ };
401
+
402
+ var playerSwfPath = options.playerPath || webshims.cfg.basePath + "swf/" + (options.playerName || 'JarisFLVPlayer.swf');
403
+
404
+ webshims.extendUNDEFProp(options.params, {
405
+ allowscriptaccess: 'always',
406
+ allowfullscreen: 'true',
407
+ wmode: 'transparent',
408
+ allowNetworking: 'all'
409
+ });
410
+ webshims.extendUNDEFProp(options.vars, {
411
+ controltype: '1',
412
+ jsapi: '1'
413
+ });
414
+ webshims.extendUNDEFProp(options.attrs, {
415
+ bgcolor: '#000000'
416
+ });
417
+
418
+ var setReadyState = function(readyState, data){
419
+ if(readyState < 3){
420
+ clearTimeout(data._canplaythroughTimer);
421
+ }
422
+ if(readyState >= 3 && data.readyState < 3){
423
+ data.readyState = readyState;
424
+ trigger(data._elem, 'canplay');
425
+ if(!data.paused){
426
+ trigger(data._elem, 'playing');
427
+ }
428
+ clearTimeout(data._canplaythroughTimer);
429
+ data._canplaythroughTimer = setTimeout(function(){
430
+ setReadyState(4, data);
431
+ }, 4000);
432
+ }
433
+ if(readyState >= 4 && data.readyState < 4){
434
+ data.readyState = readyState;
435
+ trigger(data._elem, 'canplaythrough');
436
+ }
437
+ data.readyState = readyState;
438
+ };
439
+
440
+ $.extend($.event.customEvent, {
441
+ updatemediaelementdimensions: true,
442
+ flashblocker: true,
443
+ swfstageresize: true,
444
+ mediaelementapichange: true
445
+ });
446
+
447
+ mediaelement.jarisEvent = {};
448
+ var localConnectionTimer;
449
+ var onEvent = {
450
+ onPlayPause: function(jaris, data, override){
451
+ var playing, type;
452
+ if(override == null){
453
+ try {
454
+ playing = data.api.api_get("isPlaying");
455
+ } catch(e){}
61
456
  } else {
62
- ret = !(val);
457
+ playing = override;
63
458
  }
64
- return ret;
459
+ if(playing == data.paused){
460
+
461
+ data.paused = !playing;
462
+ type = data.paused ? 'pause' : 'play';
463
+ data._ppFlag = true;
464
+ trigger(data._elem, type);
465
+ if(data.readyState < 3){
466
+ setReadyState(3, data);
467
+ }
468
+ if(!data.paused){
469
+ trigger(data._elem, 'playing');
470
+ }
471
+ }
472
+ },
473
+ onNotBuffering: function(jaris, data){
474
+ setReadyState(3, data);
475
+ },
476
+ onDataInitialized: function(jaris, data){
477
+
478
+ var oldDur = data.duration;
479
+ var durDelta;
480
+ data.duration = jaris.duration;
481
+ if(oldDur == data.duration || isNaN(data.duration)){return;}
482
+
483
+ if(data._calledMeta && ((durDelta = Math.abs(data.lastDuration - data.duration)) < 2)){return;}
484
+
485
+
486
+
487
+ data.videoHeight = jaris.height;
488
+ data.videoWidth = jaris.width;
489
+
490
+ if(!data.networkState){
491
+ data.networkState = 2;
492
+ }
493
+ if(data.readyState < 1){
494
+ setReadyState(1, data);
495
+ }
496
+ clearTimeout(data._durationChangeTimer);
497
+ if(data._calledMeta && data.duration){
498
+ data._durationChangeTimer = setTimeout(function(){
499
+ data.lastDuration = data.duration;
500
+ trigger(data._elem, 'durationchange');
501
+ }, durDelta > 50 ? 0 : durDelta > 9 ? 9 : 99);
502
+ } else {
503
+ data.lastDuration = data.duration;
504
+ if(data.duration){
505
+ trigger(data._elem, 'durationchange');
506
+ }
507
+ if(!data._calledMeta){
508
+ trigger(data._elem, 'loadedmetadata');
509
+ }
510
+ }
511
+ data._calledMeta = true;
65
512
  },
66
- tooLong: function(){
67
- return false;
513
+ onBuffering: function(jaris, data){
514
+ if(data.ended){
515
+ data.ended = false;
516
+ }
517
+ setReadyState(1, data);
518
+ trigger(data._elem, 'waiting');
68
519
  },
69
- typeMismatch: function (input, val, cache){
70
- if(val === '' || cache.nodeName == 'select'){return false;}
71
- var ret = false;
72
- if(!('type' in cache)){
73
- cache.type = getType(input[0]);
520
+ onTimeUpdate: function(jaris, data){
521
+ if(data.ended){
522
+ data.ended = false;
523
+ }
524
+ if(data.readyState < 3){
525
+ setReadyState(3, data);
526
+ trigger(data._elem, 'playing');
74
527
  }
75
528
 
76
- if(typeModels[cache.type] && typeModels[cache.type].mismatch){
77
- ret = typeModels[cache.type].mismatch(val, input);
78
- } else if('validity' in input[0]){
79
- ret = input[0].validity.typeMismatch;
529
+ trigger(data._elem, 'timeupdate');
530
+ },
531
+ onProgress: function(jaris, data){
532
+ if(data.ended){
533
+ data.ended = false;
80
534
  }
81
- return ret;
535
+ if(!data.duration || isNaN(data.duration)){
536
+ return;
537
+ }
538
+ var percentage = jaris.loaded / jaris.total;
539
+ if(percentage > 0.02 && percentage < 0.2){
540
+ setReadyState(3, data);
541
+ } else if(percentage > 0.2){
542
+ if(percentage > 0.99){
543
+ data.networkState = 1;
544
+ }
545
+ setReadyState(4, data);
546
+ }
547
+ if(data._bufferedEnd && (data._bufferedEnd > percentage)){
548
+ data._bufferedStart = data.currentTime || 0;
549
+ }
550
+
551
+ data._bufferedEnd = percentage;
552
+ data.buffered.length = 1;
553
+
554
+ $.event.trigger('progress', undefined, data._elem, true);
555
+ },
556
+ onPlaybackFinished: function(jaris, data){
557
+ if(data.readyState < 4){
558
+ setReadyState(4, data);
559
+ }
560
+ data.ended = true;
561
+ trigger(data._elem, 'ended');
82
562
  },
83
- patternMismatch: function(input, val, cache) {
84
- if(val === '' || cache.nodeName == 'select'){return false;}
85
- var pattern = input.attr('pattern');
86
- if(!pattern){return false;}
87
- try {
88
- pattern = new RegExp('^(?:' + pattern + ')$');
89
- } catch(er){
90
- webshims.error('invalid pattern value: "'+ pattern +'" | '+ er);
91
- pattern = false;
92
- }
93
- if(!pattern){return false;}
94
- return !(pattern.test(val));
563
+ onVolumeChange: function(jaris, data){
564
+ if(data.volume != jaris.volume || data.muted != jaris.mute){
565
+ data.volume = jaris.volume;
566
+ data.muted = jaris.mute;
567
+ trigger(data._elem, 'volumechange');
568
+ }
569
+ },
570
+ ready: (function(){
571
+ var testAPI = function(data){
572
+ var passed = true;
573
+
574
+ try {
575
+ data.api.api_get('volume');
576
+ } catch(er){
577
+ passed = false;
578
+ }
579
+ return passed;
580
+ };
581
+
582
+ return function(jaris, data){
583
+ var i = 0;
584
+ var doneFn = function(){
585
+ if(i > 9){
586
+ data.tryedReframeing = 0;
587
+ return;
588
+ }
589
+ i++;
590
+
591
+ data.tryedReframeing++;
592
+ if(testAPI(data)){
593
+ data.wasSwfReady = true;
594
+ data.tryedReframeing = 0;
595
+ startAutoPlay(data);
596
+ workActionQueue(data);
597
+ } else if(data.tryedReframeing < 6) {
598
+ if(data.tryedReframeing < 3){
599
+ data.reframeTimer = setTimeout(doneFn, 9);
600
+ data.shadowElem.css({overflow: 'visible'});
601
+ setTimeout(function(){
602
+ data.shadowElem.css({overflow: 'hidden'});
603
+ }, 1);
604
+ } else {
605
+ data.shadowElem.css({overflow: 'hidden'});
606
+ $(data._elem).mediaLoad();
607
+ }
608
+ } else {
609
+ clearTimeout(data.reframeTimer);
610
+ webshims.error("reframing error");
611
+ }
612
+ };
613
+ if(!data || !data.api){return;}
614
+ if(!data.tryedReframeing){
615
+ data.tryedReframeing = 0;
616
+ }
617
+ clearTimeout(localConnectionTimer);
618
+ clearTimeout(data.reframeTimer);
619
+ data.shadowElem.removeClass('flashblocker-assumed');
620
+
621
+ if(!i){
622
+ doneFn();
623
+ } else {
624
+ data.reframeTimer = setTimeout(doneFn, 9);
625
+ }
626
+
627
+ };
628
+ })()
629
+ };
630
+
631
+ onEvent.onMute = onEvent.onVolumeChange;
632
+
633
+
634
+ var workActionQueue = function(data){
635
+ var actionLen = data.actionQueue.length;
636
+ var i = 0;
637
+ var operation;
638
+
639
+ if(actionLen && data.isActive == 'third'){
640
+ while(data.actionQueue.length && actionLen > i){
641
+ i++;
642
+ operation = data.actionQueue.shift();
643
+ try{
644
+ data.api[operation.fn].apply(data.api, operation.args);
645
+ } catch(er){
646
+ webshims.warn(er);
647
+ }
648
+ }
95
649
  }
96
- }
97
- ;
98
-
99
- webshims.addValidityRule = function(type, fn){
100
- validityRules[type] = fn;
101
- };
102
-
103
- $.event.special.invalid = {
104
- add: function(){
105
- $.event.special.invalid.setup.call(this.form || this);
106
- },
107
- setup: function(){
108
- var form = this.form || this;
109
- if( $.data(form, 'invalidEventShim') ){
110
- form = null;
111
- return;
650
+ if(data.actionQueue.length){
651
+ data.actionQueue = [];
112
652
  }
113
- $(form)
114
- .data('invalidEventShim', true)
115
- .on('submit', $.event.special.invalid.handler)
116
- ;
117
- webshims.moveToFirstEvent(form, 'submit');
118
- if(webshims.bugs.bustedValidity && $.nodeName(form, 'form')){
119
- (function(){
120
- var noValidate = form.getAttribute('novalidate');
121
- form.setAttribute('novalidate', 'novalidate');
122
- webshims.data(form, 'bustedNoValidate', (noValidate == null) ? null : noValidate);
123
- })();
653
+ };
654
+ var startAutoPlay = function(data){
655
+ if(!data){return;}
656
+ if( (data._ppFlag === undefined && ($.prop(data._elem, 'autoplay')) || !data.paused)){
657
+ setTimeout(function(){
658
+ if(data.isActive == 'third' && (data._ppFlag === undefined || !data.paused)){
659
+
660
+ try {
661
+ $(data._elem).play();
662
+ data._ppFlag = true;
663
+ } catch(er){}
664
+ }
665
+ }, 1);
124
666
  }
125
- form = null;
126
- },
127
- teardown: $.noop,
128
- handler: function(e, d){
129
-
130
- if( e.type != 'submit' || e.testedValidity || !e.originalEvent || !$.nodeName(e.target, 'form') || $.prop(e.target, 'noValidate') ){return;}
131
667
 
132
- isSubmit = true;
133
- e.testedValidity = true;
134
- var notValid = !($(e.target).checkValidity());
135
- if(notValid){
136
- e.stopImmediatePropagation();
137
- isSubmit = false;
138
- return false;
668
+ if(data.muted){
669
+ $.prop(data._elem, 'muted', true);
139
670
  }
140
- isSubmit = false;
141
- }
142
- };
143
-
144
- var addSubmitBubbles = function(form){
145
- if (!$.support.submitBubbles && form && typeof form == 'object' && !form._submit_attached ) {
146
-
147
- $.event.add( form, 'submit._submit', function( event ) {
148
- event._submit_bubble = true;
149
- });
671
+ if(data.volume != 1){
672
+ $.prop(data._elem, 'volume', data.volume);
673
+ }
674
+ };
675
+
676
+
677
+ var addMediaToStopEvents = $.noop;
678
+ if(hasNative){
679
+ var stopEvents = {
680
+ play: 1,
681
+ playing: 1
682
+ };
683
+ var hideEvtArray = ['play', 'pause', 'playing', 'canplay', 'progress', 'waiting', 'ended', 'loadedmetadata', 'durationchange', 'emptied'];
684
+ var hidevents = hideEvtArray.map(function(evt){
685
+ return evt +'.webshimspolyfill';
686
+ }).join(' ');
150
687
 
151
- form._submit_attached = true;
688
+ var hidePlayerEvents = function(event){
689
+ var data = webshims.data(event.target, 'mediaelement');
690
+ if(!data){return;}
691
+ var isNativeHTML5 = ( event.originalEvent && event.originalEvent.type === event.type );
692
+ if( isNativeHTML5 == (data.activating == 'third') ){
693
+ event.stopImmediatePropagation();
694
+ if(stopEvents[event.type] && data.isActive != data.activating){
695
+ $(event.target).pause();
696
+ }
697
+ }
698
+ };
699
+
700
+ addMediaToStopEvents = function(elem){
701
+ $(elem)
702
+ .off(hidevents)
703
+ .on(hidevents, hidePlayerEvents)
704
+ ;
705
+ hideEvtArray.forEach(function(evt){
706
+ webshims.moveToFirstEvent(elem, evt);
707
+ });
708
+ };
709
+ addMediaToStopEvents(document);
152
710
  }
153
- };
154
- if(!$.support.submitBubbles && $.event.special.submit){
155
- $.event.special.submit.setup = function() {
156
- // Only need this for delegated form submit events
157
- if ( $.nodeName( this, "form" ) ) {
158
- return false;
711
+
712
+
713
+ mediaelement.setActive = function(elem, type, data){
714
+ if(!data){
715
+ data = webshims.data(elem, 'mediaelement');
159
716
  }
160
-
161
- // Lazy-add a submit handler when a descendant form may potentially be submitted
162
- $.event.add( this, "click._submit keypress._submit", function( e ) {
163
- // Node name check avoids a VML-related crash in IE (#9807)
164
- var elem = e.target,
165
- form = $.nodeName( elem, 'input' ) || $.nodeName( elem, 'button' ) ? $.prop(elem, 'form') : undefined;
166
- addSubmitBubbles(form);
167
-
168
- });
169
- // return undefined since we don't need an event listener
717
+ if(!data || data.isActive == type){return;}
718
+ if(type != 'html5' && type != 'third'){
719
+ webshims.warn('wrong type for mediaelement activating: '+ type);
720
+ }
721
+ var shadowData = webshims.data(elem, 'shadowData');
722
+ data.activating = type;
723
+ $(elem).pause();
724
+ data.isActive = type;
725
+ if(type == 'third'){
726
+ shadowData.shadowElement = shadowData.shadowFocusElement = data.shadowElem[0];
727
+ $(elem).addClass('swf-api-active nonnative-api-active').hide().getShadowElement().show();
728
+ } else {
729
+ $(elem).removeClass('swf-api-active nonnative-api-active').show().getShadowElement().hide();
730
+ shadowData.shadowElement = shadowData.shadowFocusElement = false;
731
+ }
732
+ $(elem).trigger('mediaelementapichange');
170
733
  };
171
- }
172
-
173
- $.event.special.submit = $.event.special.submit || {setup: function(){return false;}};
174
- var submitSetup = $.event.special.submit.setup;
175
- $.extend($.event.special.submit, {
176
- setup: function(){
177
- if($.nodeName(this, 'form')){
178
- $(this).on('invalid', $.noop);
734
+
735
+
736
+
737
+ var resetSwfProps = (function(){
738
+ var resetProtoProps = ['_calledMeta', 'lastDuration', '_bufferedEnd', '_bufferedStart', '_ppFlag', 'currentSrc', 'currentTime', 'duration', 'ended', 'networkState', 'paused', 'videoHeight', 'videoWidth'];
739
+ var len = resetProtoProps.length;
740
+ return function(data){
741
+
742
+ if(!data){return;}
743
+ var lenI = len;
744
+ var networkState = data.networkState;
745
+ setReadyState(0, data);
746
+ clearTimeout(data._durationChangeTimer);
747
+ while(--lenI > -1){
748
+ delete data[resetProtoProps[lenI]];
749
+ }
750
+ data.actionQueue = [];
751
+ data.buffered.length = 0;
752
+ if(networkState){
753
+ trigger(data._elem, 'emptied');
754
+ }
755
+ };
756
+ })();
757
+
758
+ var setElementDimension = function(data, hasControls){
759
+ var elem = data._elem;
760
+ var box = data.shadowElem;
761
+ $(elem)[hasControls ? 'addClass' : 'removeClass']('webshims-controls');
762
+ if(data._elemNodeName == 'audio' && !hasControls){
763
+ box.css({width: 0, height: 0});
179
764
  } else {
180
- $('form', this).on('invalid', $.noop);
765
+ box.css({
766
+ width: elem.style.width || $(elem).width(),
767
+ height: elem.style.height || $(elem).height()
768
+ });
181
769
  }
182
- return submitSetup.apply(this, arguments);
183
- }
184
- });
185
-
186
- $(window).on('invalid', $.noop);
187
-
188
-
189
- webshims.addInputType('email', {
190
- mismatch: (function(){
191
- //taken from http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address
192
- var test = cfg.emailReg || /^[a-zA-Z0-9.!#$%&'*+-\/=?\^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
193
- return function(val){
194
- return !test.test(val);
770
+ };
771
+
772
+ var bufferSrc = (function(){
773
+ var preloads = {
774
+ '': 1,
775
+ 'auto': 1
195
776
  };
196
- })()
197
- });
198
-
199
- webshims.addInputType('url', {
200
- mismatch: (function(){
201
- //taken from scott gonzales
202
- var test = cfg.urlReg || /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i;
203
- return function(val){
204
- return !test.test(val);
777
+ return function(elem){
778
+ var preload = $.attr(elem, 'preload');
779
+ if(preload == null || preload == 'none' || $.prop(elem, 'autoplay')){
780
+ return false;
781
+ }
782
+ preload = $.prop(elem, 'preload');
783
+ return !!(preloads[preload] || (preload == 'metadata' && $(elem).is('.preload-in-doubt, video:not([poster])')));
205
784
  };
206
- })()
207
- });
208
-
209
- webshims.defineNodeNameProperty('input', 'type', {
210
- prop: {
211
- get: function(){
212
- var elem = this;
213
- var type = (elem.getAttribute('type') || '').toLowerCase();
214
- return (webshims.inputTypes[type]) ? type : elem.type;
215
- }
216
- }
217
- });
218
-
219
- // IDLs for constrain validation API
220
- //ToDo: add object to this list
221
- webshims.defineNodeNamesProperties(['button', 'fieldset', 'output'], {
222
- checkValidity: {
223
- value: function(){return true;}
224
- },
225
- willValidate: {
226
- value: false
227
- },
228
- setCustomValidity: {
229
- value: $.noop
785
+ })();
786
+
787
+ var regs = {
788
+ A: /&amp;/g,
789
+ a: /&/g,
790
+ e: /\=/g,
791
+ q: /\?/g
230
792
  },
231
- validity: {
232
- writeable: false,
233
- get: function(){
234
- return $.extend({}, validityPrototype);
793
+ replaceVar = function(val){
794
+ return (val.replace) ? val.replace(regs.A, '%26').replace(regs.a, '%26').replace(regs.e, '%3D').replace(regs.q, '%3F') : val;
795
+ };
796
+
797
+ mediaelement.createSWF = function( elem, canPlaySrc, data ){
798
+ if(!hasFlash){
799
+ setTimeout(function(){
800
+ $(elem).mediaLoad(); //<- this should produce a mediaerror
801
+ }, 1);
802
+ return;
235
803
  }
236
- }
237
- }, 'prop');
238
-
239
- var baseCheckValidity = function(elem){
240
- var e,
241
- v = $.prop(elem, 'validity')
242
- ;
243
- if(v){
244
- $.data(elem, 'cachedValidity', v);
245
- } else {
246
- return true;
247
- }
248
- if( !v.valid ){
249
- e = $.Event('invalid');
250
- var jElm = $(elem).trigger(e);
251
- if(isSubmit && !baseCheckValidity.unhandledInvalids && !e.isDefaultPrevented()){
252
- webshims.validityAlert.showFor(jElm);
253
- baseCheckValidity.unhandledInvalids = true;
804
+
805
+ if(loadedSwf < 1){
806
+ loadedSwf = 1;
807
+ } else {
808
+ loadedSwf++;
254
809
  }
255
- }
256
- $.removeData(elem, 'cachedValidity');
257
- return v.valid;
258
- };
259
- var rsubmittable = /^(?:select|textarea|input)/i;
260
- webshims.defineNodeNameProperty('form', 'checkValidity', {
261
- prop: {
262
- value: function(){
810
+ if(!data){
811
+ data = webshims.data(elem, 'mediaelement');
812
+ }
813
+
814
+ if($.attr(elem, 'height') || $.attr(elem, 'width')){
815
+ webshims.warn("width or height content attributes used. Webshims only uses CSS (computed styles or inline styles) to detect size of a video/audio");
816
+ }
817
+
818
+ var isRtmp = canPlaySrc.type == 'audio/rtmp' || canPlaySrc.type == 'video/rtmp';
819
+ var vars = $.extend({}, options.vars, {
820
+ poster: replaceVar($.attr(elem, 'poster') && $.prop(elem, 'poster') || ''),
821
+ source: replaceVar(canPlaySrc.streamId || canPlaySrc.srcProp),
822
+ server: replaceVar(canPlaySrc.server || '')
823
+ });
824
+ var elemVars = $(elem).data('vars') || {};
825
+
826
+
827
+
828
+ var hasControls = $.prop(elem, 'controls');
829
+ var elemId = 'jarisplayer-'+ webshims.getID(elem);
830
+
831
+ var params = $.extend(
832
+ {},
833
+ options.params,
834
+ $(elem).data('params')
835
+ );
836
+ var elemNodeName = elem.nodeName.toLowerCase();
837
+ var attrs = $.extend(
838
+ {},
839
+ options.attrs,
840
+ {
841
+ name: elemId,
842
+ id: elemId
843
+ },
844
+ $(elem).data('attrs')
845
+ );
846
+ var setDimension = function(){
847
+ setElementDimension(data, $.prop(elem, 'controls'));
848
+ };
849
+
850
+ var box;
851
+
852
+ if(data && data.swfCreated){
853
+ mediaelement.setActive(elem, 'third', data);
854
+
855
+ data.currentSrc = canPlaySrc.srcProp;
263
856
 
264
- var ret = true,
265
- elems = $($.prop(this, 'elements')).filter(function(){
266
- if(!rsubmittable.test(this.nodeName)){return false;}
267
- var shadowData = webshims.data(this, 'shadowData');
268
- return !shadowData || !shadowData.nativeElement || shadowData.nativeElement === this;
857
+ data.shadowElem.html('<div id="'+ elemId +'">');
858
+
859
+ data.api = false;
860
+ data.actionQueue = [];
861
+ box = data.shadowElem;
862
+ resetSwfProps(data);
863
+ } else {
864
+ box = $('<div class="polyfill-'+ (elemNodeName) +' polyfill-mediaelement" id="wrapper-'+ elemId +'"><div id="'+ elemId +'"></div>')
865
+ .css({
866
+ position: 'relative',
867
+ overflow: 'hidden'
269
868
  })
270
869
  ;
271
-
272
- baseCheckValidity.unhandledInvalids = false;
273
- for(var i = 0, len = elems.length; i < len; i++){
274
- if( !baseCheckValidity(elems[i]) ){
275
- ret = false;
870
+ data = webshims.data(elem, 'mediaelement', webshims.objectCreate(playerStateObj, {
871
+ actionQueue: {
872
+ value: []
873
+ },
874
+ shadowElem: {
875
+ value: box
876
+ },
877
+ _elemNodeName: {
878
+ value: elemNodeName
879
+ },
880
+ _elem: {
881
+ value: elem
882
+ },
883
+ currentSrc: {
884
+ value: canPlaySrc.srcProp
885
+ },
886
+ swfCreated: {
887
+ value: true
888
+ },
889
+ id: {
890
+ value: elemId.replace(/-/g, '')
891
+ },
892
+ buffered: {
893
+ value: {
894
+ start: function(index){
895
+ if(index >= data.buffered.length){
896
+ webshims.error('buffered index size error');
897
+ return;
898
+ }
899
+ return 0;
900
+ },
901
+ end: function(index){
902
+ if(index >= data.buffered.length){
903
+ webshims.error('buffered index size error');
904
+ return;
905
+ }
906
+ return ( (data.duration - data._bufferedStart) * data._bufferedEnd) + data._bufferedStart;
907
+ },
908
+ length: 0
909
+ }
276
910
  }
911
+ }));
912
+ setElementDimension(data, hasControls);
913
+
914
+ box.insertBefore(elem);
915
+
916
+ if(hasNative){
917
+ $.extend(data, {volume: $.prop(elem, 'volume'), muted: $.prop(elem, 'muted'), paused: $.prop(elem, 'paused')});
277
918
  }
278
- return ret;
919
+
920
+ webshims.addShadowDom(elem, box);
921
+ addMediaToStopEvents(elem);
922
+ mediaelement.setActive(elem, 'third', data);
923
+ $(elem).on('updatemediaelementdimensions', setDimension);
924
+ $(document).on('updateshadowdom', setDimension);
279
925
  }
280
- }
281
- });
282
-
283
- webshims.defineNodeNamesProperties(['input', 'textarea', 'select'], {
284
- checkValidity: {
285
- value: function(){
286
- baseCheckValidity.unhandledInvalids = false;
287
- return baseCheckValidity($(this).getNativeElement()[0]);
926
+
927
+ if(!mediaelement.jarisEvent[data.id]){
928
+ mediaelement.jarisEvent[data.id] = function(jaris){
929
+ if(jaris.type == 'ready'){
930
+ var onReady = function(){
931
+ if(data.api){
932
+ if(bufferSrc(elem)){
933
+ data.api.api_preload();
934
+ }
935
+ onEvent.ready(jaris, data);
936
+ }
937
+ };
938
+ if(data.api){
939
+ onReady();
940
+ } else {
941
+ setTimeout(onReady, 9);
942
+ }
943
+ } else {
944
+ data.currentTime = jaris.position;
945
+
946
+ if(data.api){
947
+ if(!data._calledMeta && isNaN(jaris.duration) && data.duration != jaris.duration && isNaN(data.duration)){
948
+ onEvent.onDataInitialized(jaris, data);
949
+ }
950
+
951
+ if(!data._ppFlag && jaris.type != 'onPlayPause'){
952
+ onEvent.onPlayPause(jaris, data);
953
+ }
954
+
955
+ if(onEvent[jaris.type]){
956
+ onEvent[jaris.type](jaris, data);
957
+ }
958
+ }
959
+ data.duration = jaris.duration;
960
+ }
961
+
962
+ };
288
963
  }
289
- },
290
- setCustomValidity: {
291
- value: function(error){
292
- $.removeData(this, 'cachedValidity');
293
- webshims.data(this, 'customvalidationMessage', ''+error);
964
+
965
+ $.extend(vars,
966
+ {
967
+ id: elemId,
968
+ evtId: data.id,
969
+ controls: ''+hasControls,
970
+ autostart: 'false',
971
+ nodename: elemNodeName
972
+ },
973
+ elemVars
974
+ );
975
+
976
+ if(isRtmp){
977
+ vars.streamtype = 'rtmp';
978
+ } else if(canPlaySrc.type == 'audio/mpeg' || canPlaySrc.type == 'audio/mp3'){
979
+ vars.type = 'audio';
980
+ vars.streamtype = 'file';
981
+ } else if(canPlaySrc.type == 'video/youtube'){
982
+ vars.streamtype = 'youtube';
294
983
  }
295
- },
296
- willValidate: {
297
- writeable: false,
298
- get: (function(){
299
- var types = {
300
- button: 1,
301
- reset: 1,
302
- hidden: 1,
303
- image: 1
984
+ options.changeSWF(vars, elem, canPlaySrc, data, 'embed');
985
+ clearTimeout(data.flashBlock);
986
+
987
+ swfmini.embedSWF(playerSwfPath, elemId, "100%", "100%", "9.0.115", false, vars, params, attrs, function(swfData){
988
+
989
+ if(swfData.success){
990
+
991
+ data.api = swfData.ref;
992
+
993
+ if(!hasControls){
994
+ $(swfData.ref).attr('tabindex', '-1').css('outline', 'none');
304
995
  }
305
- ;
306
- return function(){
307
- var elem = $(this).getNativeElement()[0];
308
- //elem.name && <- we don't use to make it easier for developers
309
- return !!(!elem.disabled && !elem.readOnly && !types[elem.type] );
996
+
997
+ data.flashBlock = setTimeout(function(){
998
+ if((!swfData.ref.parentNode && box[0].parentNode) || swfData.ref.style.display == "none"){
999
+ box.addClass('flashblocker-assumed');
1000
+ $(elem).trigger('flashblocker');
1001
+ webshims.warn("flashblocker assumed");
1002
+ }
1003
+ $(swfData.ref).css({'minHeight': '2px', 'minWidth': '2px', display: 'block'});
1004
+ }, 9);
1005
+
1006
+ if(!localConnectionTimer){
1007
+ clearTimeout(localConnectionTimer);
1008
+ localConnectionTimer = setTimeout(function(){
1009
+ var flash = $(swfData.ref);
1010
+ if(flash[0].offsetWidth > 1 && flash[0].offsetHeight > 1 && location.protocol.indexOf('file:') === 0){
1011
+ 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");
1012
+ } else if(flash[0].offsetWidth < 2 || flash[0].offsetHeight < 2) {
1013
+ webshims.warn("JS-SWF connection can't be established on hidden or unconnected flash objects");
1014
+ }
1015
+ flash = null;
1016
+ }, 8000);
1017
+ }
1018
+ }
1019
+ });
1020
+
1021
+ };
1022
+
1023
+
1024
+ var queueSwfMethod = function(elem, fn, args, data){
1025
+ data = data || getSwfDataFromElem(elem);
1026
+
1027
+ if(data){
1028
+ if(data.api && data.api[fn]){
1029
+ data.api[fn].apply(data.api, args || []);
1030
+ } else {
1031
+ //todo add to queue
1032
+ data.actionQueue.push({fn: fn, args: args});
1033
+
1034
+ if(data.actionQueue.length > 10){
1035
+ setTimeout(function(){
1036
+ if(data.actionQueue.length > 5){
1037
+ data.actionQueue.shift();
1038
+ }
1039
+ }, 99);
1040
+ }
1041
+ }
1042
+ return data;
1043
+ }
1044
+ return false;
1045
+ };
1046
+
1047
+ ['audio', 'video'].forEach(function(nodeName){
1048
+ var descs = {};
1049
+ var mediaSup;
1050
+ var createGetProp = function(key){
1051
+ if(nodeName == 'audio' && (key == 'videoHeight' || key == 'videoWidth')){return;}
1052
+
1053
+ descs[key] = {
1054
+ get: function(){
1055
+ var data = getSwfDataFromElem(this);
1056
+ if(data){
1057
+ return data[key];
1058
+ } else if(hasNative && mediaSup[key].prop._supget) {
1059
+ return mediaSup[key].prop._supget.apply(this);
1060
+ } else {
1061
+ return playerStateObj[key];
1062
+ }
1063
+ },
1064
+ writeable: false
310
1065
  };
311
- })()
312
- },
313
- validity: {
314
- writeable: false,
315
- get: function(){
316
- var jElm = $(this).getNativeElement();
317
- var elem = jElm[0];
318
- var validityState = $.data(elem, 'cachedValidity');
319
- if(validityState){
320
- return validityState;
321
- }
322
- validityState = $.extend({}, validityPrototype);
1066
+ };
1067
+ var createGetSetProp = function(key, setFn){
1068
+ createGetProp(key);
1069
+ delete descs[key].writeable;
1070
+ descs[key].set = setFn;
1071
+ };
1072
+
1073
+ createGetSetProp('volume', function(v){
1074
+ var data = getSwfDataFromElem(this);
1075
+ if(data){
1076
+ v *= 1;
1077
+ if(!isNaN(v)){
1078
+
1079
+ if(v < 0 || v > 1){
1080
+ webshims.error('volume greater or less than allowed '+ (v / 100));
1081
+ }
1082
+
1083
+ queueSwfMethod(this, 'api_volume', [v], data);
1084
+
1085
+
1086
+ if(data.volume != v){
1087
+ data.volume = v;
1088
+ trigger(data._elem, 'volumechange');
1089
+ }
1090
+ data = null;
1091
+ }
1092
+ } else if(mediaSup.volume.prop._supset) {
1093
+ return mediaSup.volume.prop._supset.apply(this, arguments);
1094
+ }
1095
+ });
1096
+
1097
+ createGetSetProp('muted', function(m){
1098
+ var data = getSwfDataFromElem(this);
1099
+ if(data){
1100
+ m = !!m;
1101
+ queueSwfMethod(this, 'api_muted', [m], data);
1102
+ if(data.muted != m){
1103
+ data.muted = m;
1104
+ trigger(data._elem, 'volumechange');
1105
+ }
1106
+ data = null;
1107
+ } else if(mediaSup.muted.prop._supset) {
1108
+ return mediaSup.muted.prop._supset.apply(this, arguments);
1109
+ }
1110
+ });
1111
+
1112
+
1113
+ createGetSetProp('currentTime', function(t){
1114
+ var data = getSwfDataFromElem(this);
1115
+ if(data){
1116
+ t *= 1;
1117
+ if (!isNaN(t)) {
1118
+ queueSwfMethod(this, 'api_seek', [t], data);
1119
+ }
1120
+
1121
+ } else if(mediaSup.currentTime.prop._supset) {
1122
+ return mediaSup.currentTime.prop._supset.apply(this, arguments);
1123
+ }
1124
+ });
1125
+
1126
+ ['play', 'pause'].forEach(function(fn){
1127
+ descs[fn] = {
1128
+ value: function(){
1129
+ var data = getSwfDataFromElem(this);
1130
+ if(data){
1131
+ if(data.stopPlayPause){
1132
+ clearTimeout(data.stopPlayPause);
1133
+ }
1134
+ queueSwfMethod(this, fn == 'play' ? 'api_play' : 'api_pause', [], data);
1135
+
1136
+ data._ppFlag = true;
1137
+ if(data.paused != (fn != 'play')){
1138
+ data.paused = fn != 'play';
1139
+ trigger(data._elem, fn);
1140
+ }
1141
+ } else if(mediaSup[fn].prop._supvalue) {
1142
+ return mediaSup[fn].prop._supvalue.apply(this, arguments);
1143
+ }
1144
+ }
1145
+ };
1146
+ });
1147
+
1148
+ getPropKeys.forEach(createGetProp);
1149
+
1150
+ webshims.onNodeNamesPropertyModify(nodeName, 'controls', function(val, boolProp){
1151
+ var data = getSwfDataFromElem(this);
1152
+ $(this)[boolProp ? 'addClass' : 'removeClass']('webshims-controls');
323
1153
 
324
- if( !$.prop(elem, 'willValidate') || elem.type == 'submit' ){
325
- return validityState;
1154
+ if(data){
1155
+ if(nodeName == 'audio'){
1156
+ setElementDimension(data, boolProp);
1157
+ }
1158
+ queueSwfMethod(this, 'api_controls', [boolProp], data);
326
1159
  }
327
- var val = jElm.val(),
328
- cache = {nodeName: elem.nodeName.toLowerCase()}
329
- ;
1160
+ });
1161
+
1162
+ webshims.onNodeNamesPropertyModify(nodeName, 'preload', function(val){
1163
+ var data = getSwfDataFromElem(this);
1164
+
330
1165
 
331
- validityState.customError = !!(webshims.data(elem, 'customvalidationMessage'));
332
- if( validityState.customError ){
333
- validityState.valid = false;
1166
+ if(data && bufferSrc(this)){
1167
+ queueSwfMethod(this, 'api_preload', [], data);
334
1168
  }
335
-
336
- $.each(validityRules, function(rule, fn){
337
- if (fn(jElm, val, cache)) {
338
- validityState[rule] = true;
339
- validityState.valid = false;
1169
+ });
1170
+
1171
+ mediaSup = webshims.defineNodeNameProperties(nodeName, descs, 'prop');
1172
+ });
1173
+
1174
+ if(hasFlash && $.cleanData){
1175
+ var oldClean = $.cleanData;
1176
+ var flashNames = {
1177
+ object: 1,
1178
+ OBJECT: 1
1179
+ };
1180
+
1181
+ $.cleanData = function(elems){
1182
+ var i, len, prop;
1183
+ if(elems && (len = elems.length) && loadedSwf){
1184
+
1185
+ for(i = 0; i < len; i++){
1186
+ if(flashNames[elems[i].nodeName]){
1187
+ if('api_pause' in elems[i]){
1188
+ loadedSwf--;
1189
+ try {
1190
+ elems[i].api_pause();
1191
+ } catch(er){}
1192
+ }
1193
+ }
340
1194
  }
341
- });
342
- $(this).getShadowFocusElement().attr('aria-invalid', validityState.valid ? 'false' : 'true');
343
- jElm = null;
344
- elem = null;
345
- return validityState;
346
- }
1195
+
1196
+ }
1197
+ return oldClean.apply(this, arguments);
1198
+ };
347
1199
  }
348
- }, 'prop');
349
1200
 
350
- webshims.defineNodeNamesBooleanProperty(['input', 'textarea', 'select'], 'required', {
351
- set: function(value){
352
- $(this).getShadowFocusElement().attr('aria-required', !!(value)+'');
353
- },
354
- initAttr: (Modernizr.localstorage)//only if we have aria-support
1201
+ if(!hasNative){
1202
+
1203
+ ['poster', 'src'].forEach(function(prop){
1204
+ webshims.defineNodeNamesProperty(prop == 'src' ? ['audio', 'video', 'source'] : ['video'], prop, {
1205
+ //attr: {},
1206
+ reflect: true,
1207
+ propType: 'src'
1208
+ });
1209
+ });
1210
+
1211
+ webshims.defineNodeNamesProperty(['audio', 'video'], 'preload', {
1212
+ reflect: true,
1213
+ propType: 'enumarated',
1214
+ defaultValue: '',
1215
+ limitedTo: ['', 'auto', 'metadata', 'none']
1216
+ });
1217
+
1218
+
1219
+ ['autoplay', 'controls'].forEach(function(name){
1220
+ webshims.defineNodeNamesBooleanProperty(['audio', 'video'], name);
1221
+ });
1222
+
1223
+ webshims.defineNodeNamesProperties(['audio', 'video'], {
1224
+ HAVE_CURRENT_DATA: {
1225
+ value: 2
1226
+ },
1227
+ HAVE_ENOUGH_DATA: {
1228
+ value: 4
1229
+ },
1230
+ HAVE_FUTURE_DATA: {
1231
+ value: 3
1232
+ },
1233
+ HAVE_METADATA: {
1234
+ value: 1
1235
+ },
1236
+ HAVE_NOTHING: {
1237
+ value: 0
1238
+ },
1239
+ NETWORK_EMPTY: {
1240
+ value: 0
1241
+ },
1242
+ NETWORK_IDLE: {
1243
+ value: 1
1244
+ },
1245
+ NETWORK_LOADING: {
1246
+ value: 2
1247
+ },
1248
+ NETWORK_NO_SOURCE: {
1249
+ value: 3
1250
+ }
1251
+
1252
+ }, 'prop');
1253
+ }
1254
+
1255
+
355
1256
  });
356
-
357
- webshims.reflectProperties(['input'], ['pattern']);
358
-
359
-
360
- if( !('maxLength' in document.createElement('textarea')) ){
361
- var constrainMaxLength = (function(){
362
- var timer;
363
- var curLength = 0;
364
- var lastElement = $([]);
365
- var max = 1e9;
366
- var constrainLength = function(){
367
- var nowValue = lastElement.prop('value');
368
- var nowLen = nowValue.length;
369
- if(nowLen > curLength && nowLen > max){
370
- nowLen = Math.max(curLength, max);
371
- lastElement.prop('value', nowValue.substr(0, nowLen ));
372
- }
373
- curLength = nowLen;
374
- };
375
- var remove = function(){
376
- clearTimeout(timer);
377
- lastElement.unbind('.maxlengthconstraint');
1257
+ jQuery.webshims.register('track', function($, webshims, window, document, undefined){
1258
+ "use strict";
1259
+ var mediaelement = webshims.mediaelement;
1260
+ var id = new Date().getTime();
1261
+ var ADDBACK = $.fn.addBack ? 'addBack' : 'andSelf';
1262
+ //descriptions are not really shown, but they are inserted into the dom
1263
+ var showTracks = {subtitles: 1, captions: 1, descriptions: 1};
1264
+ var notImplemented = function(){
1265
+ webshims.error('not implemented yet');
1266
+ };
1267
+ var dummyTrack = $('<track />');
1268
+ var supportTrackMod = Modernizr.ES5 && Modernizr.objectAccessor;
1269
+ var createEventTarget = function(obj){
1270
+ var eventList = {};
1271
+ obj.addEventListener = function(name, fn){
1272
+ if(eventList[name]){
1273
+ webshims.error('always use $.on to the shimed event: '+ name +' already bound fn was: '+ eventList[name] +' your fn was: '+ fn);
1274
+ }
1275
+ eventList[name] = fn;
1276
+
378
1277
  };
379
- return function(element, maxLength){
380
- remove();
381
- if(maxLength > -1){
382
- max = maxLength;
383
- curLength = $.prop(element, 'value').length;
384
- lastElement = $(element);
385
- lastElement.on({
386
- 'keydown.maxlengthconstraint keypress.maxlengthconstraint paste.maxlengthconstraint cut.maxlengthconstraint': function(e){
387
- setTimeout(constrainLength, 0);
388
- },
389
- 'keyup.maxlengthconstraint': constrainLength,
390
- 'blur.maxlengthconstraint': remove
391
- });
392
- timer = setInterval(constrainLength, 200);
1278
+ obj.removeEventListener = function(name, fn){
1279
+ if(eventList[name] && eventList[name] != fn){
1280
+ webshims.error('always use $.on/$.off to the shimed event: '+ name +' already bound fn was: '+ eventList[name] +' your fn was: '+ fn);
1281
+ }
1282
+ if(eventList[name]){
1283
+ delete eventList[name];
393
1284
  }
394
1285
  };
395
- })();
1286
+ return obj;
1287
+ };
396
1288
 
397
- constrainMaxLength.update = function(element, maxLength){
398
- if($(element).is(':focus')){
399
- if(!maxLength){
400
- maxLength = $.prop(element, 'maxlength');
1289
+ var cueListProto = {
1290
+ getCueById: function(id){
1291
+ var cue = null;
1292
+ for(var i = 0, len = this.length; i < len; i++){
1293
+ if(this[i].id === id){
1294
+ cue = this[i];
1295
+ break;
1296
+ }
401
1297
  }
402
- constrainMaxLength(element, maxLength);
1298
+ return cue;
403
1299
  }
404
1300
  };
1301
+ var numericModes = {
1302
+ 0: 'disabled',
1303
+ 1: 'hidden',
1304
+ 2: 'showing'
1305
+ };
405
1306
 
406
- $(document).on('focusin', function(e){
407
- var maxLength;
408
- if(e.target.nodeName == "TEXTAREA" && (maxLength = $.prop(e.target, 'maxlength')) > -1){
409
- constrainMaxLength(e.target, maxLength);
410
- }
411
- });
412
-
413
- webshims.defineNodeNameProperty('textarea', 'maxlength', {
414
- attr: {
415
- set: function(val){
416
- this.setAttribute('maxlength', ''+val);
417
- constrainMaxLength.update(this);
418
- },
419
- get: function(){
420
- var ret = this.getAttribute('maxlength');
421
- return ret == null ? undefined : ret;
422
- }
1307
+ var textTrackProto = {
1308
+ shimActiveCues: null,
1309
+ _shimActiveCues: null,
1310
+ activeCues: null,
1311
+ cues: null,
1312
+ kind: 'subtitles',
1313
+ label: '',
1314
+ language: '',
1315
+ mode: 'disabled',
1316
+ readyState: 0,
1317
+ oncuechange: null,
1318
+ toString: function() {
1319
+ return "[object TextTrack]";
423
1320
  },
424
- prop: {
425
- set: function(val){
426
- if(isNumber(val)){
427
- if(val < 0){
428
- throw('INDEX_SIZE_ERR');
429
- }
430
- val = parseInt(val, 10);
431
- this.setAttribute('maxlength', val);
432
- constrainMaxLength.update(this, val);
433
- return;
1321
+ addCue: function(cue){
1322
+ if(!this.cues){
1323
+ this.cues = mediaelement.createCueList();
1324
+ } else {
1325
+ var lastCue = this.cues[this.cues.length-1];
1326
+ if(lastCue && lastCue.startTime > cue.startTime){
1327
+ webshims.error("cue startTime higher than previous cue's startTime");
434
1328
  }
435
- this.setAttribute('maxlength', '0');
436
- constrainMaxLength.update(this, 0);
437
- },
438
- get: function(){
439
- var val = this.getAttribute('maxlength');
440
- return (isNumber(val) && val >= 0) ? parseInt(val, 10) : -1;
441
-
442
1329
  }
443
- }
444
- });
445
- webshims.defineNodeNameProperty('textarea', 'maxLength', {
446
- prop: {
447
- set: function(val){
448
- $.prop(this, 'maxlength', val);
449
- },
450
- get: function(){
451
- return $.prop(this, 'maxlength');
1330
+ if(cue.track && cue.track.removeCue){
1331
+ cue.track.removeCue(cue);
452
1332
  }
453
- }
454
- });
455
- }
456
-
457
-
458
-
459
- var submitterTypes = {submit: 1, button: 1, image: 1};
460
- var formSubmitterDescriptors = {};
461
- [
462
- {
463
- name: "enctype",
464
- limitedTo: {
465
- "application/x-www-form-urlencoded": 1,
466
- "multipart/form-data": 1,
467
- "text/plain": 1
468
- },
469
- defaultProp: "application/x-www-form-urlencoded",
470
- proptype: "enum"
471
- },
472
- {
473
- name: "method",
474
- limitedTo: {
475
- "get": 1,
476
- "post": 1
1333
+ cue.track = this;
1334
+ this.cues.push(cue);
477
1335
  },
478
- defaultProp: "get",
479
- proptype: "enum"
480
- },
481
- {
482
- name: "action",
483
- proptype: "url"
484
- },
485
- {
486
- name: "target"
487
- },
488
- {
489
- name: "novalidate",
490
- propName: "noValidate",
491
- proptype: "boolean"
492
- }
493
- ].forEach(function(desc){
494
- var propName = 'form'+ (desc.propName || desc.name).replace(/^[a-z]/, function(f){
495
- return f.toUpperCase();
496
- });
497
- var attrName = 'form'+ desc.name;
498
- var formName = desc.name;
499
- var eventName = 'click.webshimssubmittermutate'+formName;
500
-
501
- var changeSubmitter = function(){
502
- var elem = this;
503
- if( !('form' in elem) || !submitterTypes[elem.type] ){return;}
504
- var form = $.prop(elem, 'form');
505
- if(!form){return;}
506
- var attr = $.attr(elem, attrName);
507
- if(attr != null && ( !desc.limitedTo || attr.toLowerCase() === $.prop(elem, propName))){
508
-
509
- var oldAttr = $.attr(form, formName);
510
-
511
- $.attr(form, formName, attr);
512
- setTimeout(function(){
513
- if(oldAttr != null){
514
- $.attr(form, formName, oldAttr);
515
- } else {
516
- try {
517
- $(form).removeAttr(formName);
518
- } catch(er){
519
- form.removeAttribute(formName);
520
- }
1336
+ //ToDo: make it more dynamic
1337
+ removeCue: function(cue){
1338
+ var cues = this.cues || [];
1339
+ var i = 0;
1340
+ var len = cues.length;
1341
+ if(cue.track != this){
1342
+ webshims.error("cue not part of track");
1343
+ return;
1344
+ }
1345
+ for(; i < len; i++){
1346
+ if(cues[i] === cue){
1347
+ cues.splice(i, 1);
1348
+ cue.track = null;
1349
+ break;
521
1350
  }
522
- }, 9);
523
- }
1351
+ }
1352
+ if(cue.track){
1353
+ webshims.error("cue not part of track");
1354
+ return;
1355
+ }
1356
+ },
1357
+ DISABLED: 'disabled',
1358
+ OFF: 'disabled',
1359
+ HIDDEN: 'hidden',
1360
+ SHOWING: 'showing',
1361
+ ERROR: 3,
1362
+ LOADED: 2,
1363
+ LOADING: 1,
1364
+ NONE: 0
524
1365
  };
1366
+ var copyProps = ['kind', 'label', 'srclang'];
1367
+ var copyName = {srclang: 'language'};
525
1368
 
1369
+ var owns = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
526
1370
 
527
-
528
- switch(desc.proptype) {
529
- case "url":
530
- var urlForm = document.createElement('form');
531
- formSubmitterDescriptors[propName] = {
532
- prop: {
533
- set: function(value){
534
- $.attr(this, attrName, value);
535
- },
536
- get: function(){
537
- var value = $.attr(this, attrName);
538
- if(value == null){return '';}
539
- urlForm.setAttribute('action', value);
540
- return urlForm.action;
541
- }
542
- }
543
- };
544
- break;
545
- case "boolean":
546
- formSubmitterDescriptors[propName] = {
547
- prop: {
548
- set: function(val){
549
- val = !!val;
550
- if(val){
551
- $.attr(this, 'formnovalidate', 'formnovalidate');
552
- } else {
553
- $(this).removeAttr('formnovalidate');
554
- }
555
- },
556
- get: function(){
557
- return $.attr(this, 'formnovalidate') != null;
558
- }
559
- }
560
- };
561
- break;
562
- case "enum":
563
- formSubmitterDescriptors[propName] = {
564
- prop: {
565
- set: function(value){
566
- $.attr(this, attrName, value);
567
- },
568
- get: function(){
569
- var value = $.attr(this, attrName);
570
- return (!value || ( (value = value.toLowerCase()) && !desc.limitedTo[value] )) ? desc.defaultProp : value;
571
- }
572
- }
573
- };
574
- break;
575
- default:
576
- formSubmitterDescriptors[propName] = {
577
- prop: {
578
- set: function(value){
579
- $.attr(this, attrName, value);
580
- },
581
- get: function(){
582
- var value = $.attr(this, attrName);
583
- return (value != null) ? value : "";
584
- }
585
- }
586
- };
587
- }
588
-
589
-
590
- if(!formSubmitterDescriptors[attrName]){
591
- formSubmitterDescriptors[attrName] = {};
592
- }
593
- formSubmitterDescriptors[attrName].attr = {
594
- set: function(value){
595
- formSubmitterDescriptors[attrName].attr._supset.call(this, value);
596
- $(this).unbind(eventName).on(eventName, changeSubmitter);
597
- },
598
- get: function(){
599
- return formSubmitterDescriptors[attrName].attr._supget.call(this);
1371
+ var updateMediaTrackList = function(baseData, trackList){
1372
+ var removed = [];
1373
+ var added = [];
1374
+ var newTracks = [];
1375
+ var i, len;
1376
+ if(!baseData){
1377
+ baseData = webshims.data(this, 'mediaelementBase') || webshims.data(this, 'mediaelementBase', {});
600
1378
  }
601
- };
602
- formSubmitterDescriptors[attrName].initAttr = true;
603
- formSubmitterDescriptors[attrName].removeAttr = {
604
- value: function(){
605
- $(this).unbind(eventName);
606
- formSubmitterDescriptors[attrName].removeAttr._supvalue.call(this);
1379
+
1380
+ if(!trackList){
1381
+ baseData.blockTrackListUpdate = true;
1382
+ trackList = $.prop(this, 'textTracks');
1383
+ baseData.blockTrackListUpdate = false;
607
1384
  }
608
- };
609
- });
610
-
611
- webshims.defineNodeNamesProperties(['input', 'button'], formSubmitterDescriptors);
612
-
613
-
614
- if(!$.support.getSetAttribute && $('<form novalidate></form>').attr('novalidate') == null){
615
- webshims.defineNodeNameProperty('form', 'novalidate', {
616
- attr: {
617
- set: function(val){
618
- this.setAttribute('novalidate', ''+val);
619
- },
620
- get: function(){
621
- var ret = this.getAttribute('novalidate');
622
- return ret == null ? undefined : ret;
1385
+
1386
+ clearTimeout(baseData.updateTrackListTimer);
1387
+
1388
+ $('track', this).each(function(){
1389
+ var track = $.prop(this, 'track');
1390
+ newTracks.push(track);
1391
+ if(trackList.indexOf(track) == -1){
1392
+ added.push(track);
1393
+ }
1394
+ });
1395
+
1396
+ if(baseData.scriptedTextTracks){
1397
+ for(i = 0, len = baseData.scriptedTextTracks.length; i < len; i++){
1398
+ newTracks.push(baseData.scriptedTextTracks[i]);
1399
+ if(trackList.indexOf(baseData.scriptedTextTracks[i]) == -1){
1400
+ added.push(baseData.scriptedTextTracks[i]);
1401
+ }
623
1402
  }
624
1403
  }
625
- });
626
- } else if(webshims.bugs.bustedValidity){
627
-
628
- webshims.defineNodeNameProperty('form', 'novalidate', {
629
- attr: {
630
- set: function(val){
631
- webshims.data(this, 'bustedNoValidate', ''+val);
632
- },
633
- get: function(){
634
- var ret = webshims.data(this, 'bustedNoValidate');
635
- return ret == null ? undefined : ret;
1404
+
1405
+ for(i = 0, len = trackList.length; i < len; i++){
1406
+ if(newTracks.indexOf(trackList[i]) == -1){
1407
+ removed.push(trackList[i]);
636
1408
  }
637
- },
638
- removeAttr: {
639
- value: function(){
640
- webshims.data(this, 'bustedNoValidate', null);
1409
+ }
1410
+
1411
+ if(removed.length || added.length){
1412
+ trackList.splice(0);
1413
+
1414
+ for(i = 0, len = newTracks.length; i < len; i++){
1415
+ trackList.push(newTracks[i]);
1416
+ }
1417
+ for(i = 0, len = removed.length; i < len; i++){
1418
+ $([trackList]).triggerHandler($.Event({type: 'removetrack', track: removed[i]}));
1419
+ }
1420
+ for(i = 0, len = added.length; i < len; i++){
1421
+ $([trackList]).triggerHandler($.Event({type: 'addtrack', track: added[i]}));
1422
+ }
1423
+ if(baseData.scriptedTextTracks || removed.length){
1424
+ $(this).triggerHandler('updatetrackdisplay');
641
1425
  }
642
1426
  }
643
- });
1427
+ };
644
1428
 
645
- $.each(['rangeUnderflow', 'rangeOverflow', 'stepMismatch'], function(i, name){
646
- validityRules[name] = function(elem){
647
- return (elem[0].validity || {})[name] || false;
648
- };
649
- });
1429
+ var refreshTrack = function(track, trackData){
1430
+ if(!trackData){
1431
+ trackData = webshims.data(track, 'trackData');
1432
+ }
1433
+ if(trackData && !trackData.isTriggering){
1434
+ trackData.isTriggering = true;
1435
+ setTimeout(function(){
1436
+ if(!(trackData.track || {}).readyState){
1437
+ $(track).triggerHandler('checktrackmode');
1438
+ } else {
1439
+ $(track).closest('audio, video').triggerHandler('updatetrackdisplay');
1440
+ }
1441
+ trackData.isTriggering = false;
1442
+ }, 1);
1443
+ }
1444
+ };
650
1445
 
651
- }
652
-
653
- webshims.defineNodeNameProperty('form', 'noValidate', {
654
- prop: {
655
- set: function(val){
656
- val = !!val;
657
- if(val){
658
- $.attr(this, 'novalidate', 'novalidate');
659
- } else {
660
- $(this).removeAttr('novalidate');
661
- }
662
- },
663
- get: function(){
664
- return $.attr(this, 'novalidate') != null;
1446
+ var emptyDiv = $('<div />')[0];
1447
+ window.TextTrackCue = function(startTime, endTime, text){
1448
+ if(arguments.length != 3){
1449
+ webshims.error("wrong arguments.length for TextTrackCue.constructor");
665
1450
  }
666
- }
667
- });
668
-
669
- if(Modernizr.inputtypes.date && /webkit/i.test(navigator.userAgent)){
670
- (function(){
671
1451
 
672
- var noInputTriggerEvts = {updateInput: 1, input: 1},
673
- fixInputTypes = {
674
- date: 1,
675
- time: 1
676
- },
677
- noFocusEvents = {
678
- focusout: 1,
679
- blur: 1
680
- },
681
- changeEvts = {
682
- updateInput: 1,
683
- change: 1
684
- },
685
- observe = function(input){
686
- var timer,
687
- focusedin = true,
688
- lastInputVal = input.prop('value'),
689
- lastChangeVal = lastInputVal,
690
- trigger = function(e){
691
- //input === null
692
- if(!input){return;}
693
- var newVal = input.prop('value');
1452
+ this.startTime = startTime;
1453
+ this.endTime = endTime;
1454
+ this.text = text;
1455
+
1456
+ this.id = "";
1457
+ this.pauseOnExit = false;
1458
+
1459
+ createEventTarget(this);
1460
+ };
1461
+
1462
+ window.TextTrackCue.prototype = {
1463
+
1464
+ onenter: null,
1465
+ onexit: null,
1466
+ pauseOnExit: false,
1467
+ getCueAsHTML: function(){
1468
+ var lastText = "";
1469
+ var parsedText = "";
1470
+ var fragment = document.createDocumentFragment();
1471
+ var fn;
1472
+ if(!owns(this, 'getCueAsHTML')){
1473
+ fn = this.getCueAsHTML = function(){
1474
+ var i, len;
1475
+ if(lastText != this.text){
1476
+ lastText = this.text;
1477
+ parsedText = mediaelement.parseCueTextToHTML(lastText);
1478
+ emptyDiv.innerHTML = parsedText;
694
1479
 
695
- if(newVal !== lastInputVal){
696
- lastInputVal = newVal;
697
- if(!e || !noInputTriggerEvts[e.type]){
698
- input.trigger('input');
699
- }
1480
+ for(i = 0, len = emptyDiv.childNodes.length; i < len; i++){
1481
+ fragment.appendChild(emptyDiv.childNodes[i].cloneNode(true));
700
1482
  }
701
- if(e && changeEvts[e.type]){
702
- lastChangeVal = newVal;
703
- }
704
- if(!focusedin && newVal !== lastChangeVal){
705
- input.trigger('change');
706
- }
707
- },
708
- extraTimer,
709
- extraTest = function(){
710
- clearTimeout(extraTimer);
711
- extraTimer = setTimeout(trigger, 9);
712
- },
713
- unbind = function(e){
714
- clearInterval(timer);
715
- setTimeout(function(){
716
- if(e && noFocusEvents[e.type]){
717
- focusedin = false;
718
- }
719
- if(input){
720
- input.unbind('focusout blur', unbind).unbind('input change updateInput', trigger);
721
- trigger();
722
- }
723
- input = null;
724
- }, 1);
725
-
726
1483
  }
727
- ;
1484
+ return fragment.cloneNode(true);
1485
+ };
728
1486
 
729
- clearInterval(timer);
730
- timer = setInterval(trigger, 160);
731
- extraTest();
732
- input
733
- .off({
734
- 'focusout blur': unbind,
735
- 'input change updateInput': trigger
736
- })
737
- .on({
738
- 'focusout blur': unbind,
739
- 'input updateInput change': trigger
740
- })
741
- ;
742
1487
  }
743
- ;
744
- if($.event.customEvent){
745
- $.event.customEvent.updateInput = true;
746
- }
747
-
748
- (function(){
749
-
750
- var correctValue = function(elem){
751
- var i = 1;
752
- var len = 3;
753
- var abort, val;
754
- if(elem.type == 'date' && (isSubmit || !$(elem).is(':focus'))){
755
- val = elem.value;
756
- if(val && val.length < 10 && (val = val.split('-')) && val.length == len){
757
- for(; i < len; i++){
758
- if(val[i].length == 1){
759
- val[i] = '0'+val[i];
760
- } else if(val[i].length != 2){
761
- abort = true;
762
- break;
763
- }
764
- }
765
- if(!abort){
766
- val = val.join('-');
767
- $.prop(elem, 'value', val);
768
- return val;
769
- }
770
- }
771
- }
772
- };
773
- var inputCheckValidityDesc, formCheckValidityDesc, inputValueDesc, inputValidityDesc;
774
-
775
- inputCheckValidityDesc = webshims.defineNodeNameProperty('input', 'checkValidity', {
776
- prop: {
777
- value: function(){
778
- correctValue(this);
779
- return inputCheckValidityDesc.prop._supvalue.apply(this, arguments);
780
- }
781
- }
782
- });
783
-
784
- formCheckValidityDesc = webshims.defineNodeNameProperty('form', 'checkValidity', {
785
- prop: {
786
- value: function(){
787
- $('input', this).each(function(){
788
- correctValue(this);
789
- });
790
- return formCheckValidityDesc.prop._supvalue.apply(this, arguments);
791
- }
792
- }
793
- });
794
-
795
- inputValueDesc = webshims.defineNodeNameProperty('input', 'value', {
796
- prop: {
797
- set: function(){
798
- return inputValueDesc.prop._supset.apply(this, arguments);
799
- },
800
- get: function(){
801
- return correctValue(this) || inputValueDesc.prop._supget.apply(this, arguments);
802
- }
803
- }
804
- });
805
-
806
- inputValidityDesc = webshims.defineNodeNameProperty('input', 'validity', {
807
- prop: {
808
- writeable: false,
809
- get: function(){
810
- correctValue(this);
811
- return inputValidityDesc.prop._supget.apply(this, arguments);
812
- }
813
- }
814
- });
815
-
816
- $(document).on('change', function(e){
817
- correctValue(e.target);
818
- });
819
-
820
- })();
821
-
822
- $(document)
823
- .on('focusin', function(e){
824
- if( e.target && fixInputTypes[e.target.type] && !e.target.readOnly && !e.target.disabled ){
825
- observe($(e.target));
826
- }
827
- })
828
- ;
1488
+ return fn ? fn.apply(this, arguments) : fragment.cloneNode(true);
1489
+ },
1490
+ track: null,
829
1491
 
830
1492
 
831
- })();
832
- }
833
-
834
- webshims.addReady(function(context, contextElem){
835
- //start constrain-validation
836
- var focusElem;
837
- $('form', context)
838
- .add(contextElem.filter('form'))
839
- .bind('invalid', $.noop)
840
- ;
1493
+ id: ''
1494
+ //todo-->
1495
+ // ,
1496
+ // snapToLines: true,
1497
+ // line: 'auto',
1498
+ // size: 100,
1499
+ // position: 50,
1500
+ // vertical: '',
1501
+ // align: 'middle'
1502
+ };
841
1503
 
842
- try {
843
- if(context == document && !('form' in (document.activeElement || {}))) {
844
- focusElem = $('input[autofocus], select[autofocus], textarea[autofocus]', context).eq(0).getShadowFocusElement()[0];
845
- if (focusElem && focusElem.offsetHeight && focusElem.offsetWidth) {
846
- focusElem.focus();
847
- }
848
- }
849
- }
850
- catch (er) {}
851
1504
 
852
- });
853
-
854
- if(!Modernizr.formattribute || !Modernizr.fieldsetdisabled){
855
- (function(){
856
- (function(prop, undefined){
857
- $.prop = function(elem, name, value){
858
- var ret;
859
- if(elem && elem.nodeType == 1 && value === undefined && $.nodeName(elem, 'form') && elem.id){
860
- ret = document.getElementsByName(name);
861
- if(!ret || !ret.length){
862
- ret = document.getElementById(name);
863
- }
864
- if(ret){
865
- ret = $(ret).filter(function(){
866
- return $.prop(this, 'form') == elem;
867
- }).get();
868
- if(ret.length){
869
- return ret.length == 1 ? ret[0] : ret;
870
- }
1505
+
1506
+
1507
+
1508
+ mediaelement.createCueList = function(){
1509
+ return $.extend([], cueListProto);
1510
+ };
1511
+
1512
+ mediaelement.parseCueTextToHTML = (function(){
1513
+ var tagSplits = /(<\/?[^>]+>)/ig;
1514
+ var allowedTags = /^(?:c|v|ruby|rt|b|i|u)/;
1515
+ var regEnd = /\<\s*\//;
1516
+ var addToTemplate = function(localName, attribute, tag, html){
1517
+ var ret;
1518
+ if(regEnd.test(html)){
1519
+ ret = '</'+ localName +'>';
1520
+ } else {
1521
+ tag.splice(0, 1);
1522
+ ret = '<'+ localName +' '+ attribute +'="'+ (tag.join(' ').replace(/\"/g, '&#34;')) +'">';
1523
+ }
1524
+ return ret;
1525
+ };
1526
+ var replacer = function(html){
1527
+ var tag = html.replace(/[<\/>]+/ig,"").split(/[\s\.]+/);
1528
+ if(tag[0]){
1529
+ tag[0] = tag[0].toLowerCase();
1530
+ if(allowedTags.test(tag[0])){
1531
+ if(tag[0] == 'c'){
1532
+ html = addToTemplate('span', 'class', tag, html);
1533
+ } else if(tag[0] == 'v'){
1534
+ html = addToTemplate('q', 'title', tag, html);
871
1535
  }
1536
+ } else {
1537
+ html = "";
872
1538
  }
873
- return prop.apply(this, arguments);
874
- };
875
- })($.prop, undefined);
876
- var removeAddedElements = function(form){
877
- var elements = $.data(form, 'webshimsAddedElements');
878
- if(elements){
879
- elements.remove();
880
- $.removeData(form, 'webshimsAddedElements');
881
1539
  }
1540
+ return html;
882
1541
  };
883
- var rCRLF = /\r?\n/g,
884
- rinput = /^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,
885
- rselectTextarea = /^(?:select|textarea)/i;
886
1542
 
887
- if(!Modernizr.formattribute){
888
- webshims.defineNodeNamesProperty(['input', 'textarea', 'select', 'button', 'fieldset'], 'form', {
889
- prop: {
890
- get: function(){
891
- var form = webshims.contentAttr(this, 'form');
892
- if(form){
893
- form = document.getElementById(form);
894
- if(form && !$.nodeName(form, 'form')){
895
- form = null;
896
- }
897
- }
898
- return form || this.form;
899
- },
900
- writeable: false
901
- }
902
- });
903
-
904
-
905
- webshims.defineNodeNamesProperty(['form'], 'elements', {
906
- prop: {
907
- get: function(){
908
- var id = this.id;
909
- var elements = $.makeArray(this.elements);
910
- if(id){
911
- elements = $(elements).add('input[form="'+ id +'"], select[form="'+ id +'"], textarea[form="'+ id +'"], button[form="'+ id +'"], fieldset[form="'+ id +'"]').not('.webshims-visual-hide > *').get();
912
- }
913
- return elements;
914
- },
915
- writeable: false
1543
+ return function(cueText){
1544
+ return cueText.replace(tagSplits, replacer);
1545
+ };
1546
+ })();
1547
+
1548
+ mediaelement.loadTextTrack = function(mediaelem, track, trackData, _default){
1549
+ var loadEvents = 'play playing timeupdate updatetrackdisplay';
1550
+ var obj = trackData.track;
1551
+ var load = function(){
1552
+ var src = $.prop(track, 'src');
1553
+ var error;
1554
+ var ajax;
1555
+ if(obj.mode != 'disabled' && src && $.attr(track, 'src')){
1556
+ $(mediaelem).unbind(loadEvents, load);
1557
+ $(track).unbind('checktrackmode', load);
1558
+ if(!obj.readyState){
1559
+ error = function(){
1560
+ obj.readyState = 3;
1561
+ obj.cues = null;
1562
+ obj.activeCues = obj.shimActiveCues = obj._shimActiveCues = null;
1563
+ $(track).triggerHandler('error');
1564
+ };
1565
+ obj.readyState = 1;
1566
+ try {
1567
+ obj.cues = mediaelement.createCueList();
1568
+ obj.activeCues = obj.shimActiveCues = obj._shimActiveCues = mediaelement.createCueList();
1569
+ ajax = $.ajax({
1570
+ dataType: 'text',
1571
+ url: src,
1572
+ success: function(text){
1573
+ if(ajax.getResponseHeader('content-type') != 'text/vtt'){
1574
+ webshims.error('set the mime-type of your WebVTT files to text/vtt. see: http://dev.w3.org/html5/webvtt/#text/vtt');
1575
+ }
1576
+ mediaelement.parseCaptions(text, obj, function(cues){
1577
+ if(cues && 'length' in cues){
1578
+ obj.readyState = 2;
1579
+ $(track).triggerHandler('load');
1580
+ $(mediaelem).triggerHandler('updatetrackdisplay');
1581
+ } else {
1582
+ error();
1583
+ }
1584
+ });
1585
+
1586
+ },
1587
+ error: error
1588
+ });
1589
+ } catch(er){
1590
+ error();
1591
+ webshims.warn(er);
1592
+ }
916
1593
  }
917
- });
918
-
1594
+ }
1595
+ };
1596
+ obj.readyState = 0;
1597
+ obj.shimActiveCues = null;
1598
+ obj._shimActiveCues = null;
1599
+ obj.activeCues = null;
1600
+ obj.cues = null;
1601
+ $(mediaelem).unbind(loadEvents, load);
1602
+ $(track).unbind('checktrackmode', load);
1603
+ $(mediaelem).on(loadEvents, load);
1604
+ $(track).on('checktrackmode', load);
1605
+ if(_default){
1606
+ obj.mode = showTracks[obj.kind] ? 'showing' : 'hidden';
1607
+ load();
1608
+ }
1609
+ };
1610
+
1611
+ mediaelement.createTextTrack = function(mediaelem, track){
1612
+ var obj, trackData;
1613
+ if(track.nodeName){
1614
+ trackData = webshims.data(track, 'trackData');
919
1615
 
1616
+ if(trackData){
1617
+ refreshTrack(track, trackData);
1618
+ obj = trackData.track;
1619
+ }
1620
+ }
1621
+
1622
+ if(!obj){
1623
+ obj = createEventTarget(webshims.objectCreate(textTrackProto));
920
1624
 
921
- $(function(){
922
- var stopPropagation = function(e){
923
- e.stopPropagation();
924
- };
925
- $(document).on('submit', function(e){
926
-
927
- if(!e.isDefaultPrevented()){
928
- var form = e.target;
929
- var id = form.id;
930
- var elements;
931
-
932
-
933
- if(id){
934
- removeAddedElements(form);
935
-
936
- elements = $('input[form="'+ id +'"], select[form="'+ id +'"], textarea[form="'+ id +'"]')
937
- .filter(function(){
938
- return !this.disabled && this.name && this.form != form;
939
- })
940
- .clone()
941
- ;
942
- if(elements.length){
943
- $.data(form, 'webshimsAddedElements', $('<div class="webshims-visual-hide" />').append(elements).appendTo(form));
944
- setTimeout(function(){
945
- removeAddedElements(form);
946
- }, 9);
947
- }
948
- elements = null;
949
- }
1625
+ if(!supportTrackMod){
1626
+ copyProps.forEach(function(copyProp){
1627
+ var prop = $.prop(track, copyProp);
1628
+ if(prop){
1629
+ obj[copyName[copyProp] || copyProp] = prop;
950
1630
  }
951
1631
  });
1632
+ }
1633
+
1634
+
1635
+ if(track.nodeName){
952
1636
 
953
- $(document).on('click', function(e){
954
- if(!e.isDefaultPrevented() && $(e.target).is('input[type="submit"][form], button[form], input[type="button"][form], input[type="image"][form], input[type="reset"][form]')){
955
- var trueForm = $.prop(e.target, 'form');
956
- var formIn = e.target.form;
957
- var clone;
958
- if(trueForm && trueForm != formIn){
959
- clone = $(e.target)
960
- .clone()
961
- .removeAttr('form')
962
- .addClass('webshims-visual-hide')
963
- .on('click', stopPropagation)
964
- .appendTo(trueForm)
965
- ;
966
- if(formIn){
967
- e.preventDefault();
1637
+ if(supportTrackMod){
1638
+ copyProps.forEach(function(copyProp){
1639
+ webshims.defineProperty(obj, copyName[copyProp] || copyProp, {
1640
+ get: function(){
1641
+ return $.prop(track, copyProp);
968
1642
  }
969
- addSubmitBubbles(trueForm);
970
- clone.trigger('click');
971
- setTimeout(function(){
972
- clone.remove();
973
- clone = null;
974
- }, 9);
975
- }
976
- }
977
- });
978
- });
979
- }
980
-
981
- if(!Modernizr.fieldsetdisabled){
982
- webshims.defineNodeNamesProperty(['fieldset'], 'elements', {
983
- prop: {
984
- get: function(){
985
- //add listed elements without keygen, object, output
986
- return $('input, select, textarea, button, fieldset', this).get() || [];
987
- },
988
- writeable: false
1643
+ });
1644
+ });
1645
+ }
1646
+
1647
+ trackData = webshims.data(track, 'trackData', {track: obj});
1648
+ mediaelement.loadTextTrack(mediaelem, track, trackData, ($.prop(track, 'default') && $(track).siblings('track[default]')[ADDBACK]()[0] == track));
1649
+ } else {
1650
+ if(supportTrackMod){
1651
+ copyProps.forEach(function(copyProp){
1652
+ webshims.defineProperty(obj, copyName[copyProp] || copyProp, {
1653
+ value: track[copyProp],
1654
+ writeable: false
1655
+ });
1656
+ });
989
1657
  }
990
- });
1658
+ obj.cues = mediaelement.createCueList();
1659
+ obj.activeCues = obj._shimActiveCues = obj.shimActiveCues = mediaelement.createCueList();
1660
+ obj.mode = 'hidden';
1661
+ obj.readyState = 2;
1662
+ }
991
1663
  }
1664
+ return obj;
1665
+ };
1666
+
1667
+
1668
+ /*
1669
+ taken from:
1670
+ Captionator 0.5.1 [CaptionCrunch]
1671
+ Christopher Giffard, 2011
1672
+ Share and enjoy
1673
+
1674
+ https://github.com/cgiffard/Captionator
1675
+
1676
+ modified for webshims
1677
+ */
1678
+ mediaelement.parseCaptionChunk = (function(){
1679
+ // Set up timestamp parsers
1680
+ var WebVTTTimestampParser = /^(\d{2})?:?(\d{2}):(\d{2})\.(\d+)\s+\-\-\>\s+(\d{2})?:?(\d{2}):(\d{2})\.(\d+)\s*(.*)/;
1681
+ var GoogleTimestampParser = /^([\d\.]+)\s+\+([\d\.]+)\s*(.*)/;
1682
+ var WebVTTDEFAULTSCueParser = /^(DEFAULTS|DEFAULT)\s+\-\-\>\s+(.*)/g;
1683
+ var WebVTTSTYLECueParser = /^(STYLE|STYLES)\s+\-\-\>\s*\n([\s\S]*)/g;
1684
+ var WebVTTCOMMENTCueParser = /^(COMMENT|COMMENTS)\s+\-\-\>\s+(.*)/g;
992
1685
 
993
- $.fn.serializeArray = function() {
994
- return this.map(function(){
995
- var elements = $.prop(this, 'elements');
996
- return elements ? $.makeArray( elements ) : this;
997
- })
998
- .filter(function(){
999
- return this.name && !this.disabled &&
1000
- ( this.checked || rselectTextarea.test( this.nodeName ) ||
1001
- rinput.test( this.type ) );
1002
- })
1003
- .map(function( i, elem ){
1004
- var val = $( this ).val();
1005
-
1006
- return val == null ?
1007
- null :
1008
- $.isArray( val ) ?
1009
- $.map( val, function( val, i ){
1010
- return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
1011
- }) :
1012
- { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
1013
- }).get();
1014
- };
1686
+ return function(subtitleElement,objectCount){
1687
+ var cueDefaults = [];
1015
1688
 
1016
- })();
1017
- }
1689
+ var subtitleParts, timeIn, timeOut, html, timeData, subtitlePartIndex, cueSettings = "", id, specialCueData;
1690
+ var timestampMatch, tmpCue;
1018
1691
 
1019
- try {
1020
- document.querySelector(':checked');
1021
- } catch(er){
1022
- (function(){
1023
- var checkInputs = {
1024
- radio: 1,
1025
- checkbox: 1
1026
- };
1027
- var selectChange = function(){
1028
- var options = this.options || [];
1029
- var i, len, option;
1030
- for(i = 0, len = options.length; i < len; i++){
1031
- option = $(options[i]);
1032
- option[$.prop(options[i], 'selected') ? 'addClass' : 'removeClass']('prop-checked');
1692
+ // WebVTT Special Cue Logic
1693
+ if ((specialCueData = WebVTTDEFAULTSCueParser.exec(subtitleElement))) {
1694
+ // cueDefaults = specialCueData.slice(2).join("");
1695
+ // cueDefaults = cueDefaults.split(/\s+/g).filter(function(def) { return def && !!def.length; });
1696
+ return null;
1697
+ } else if ((specialCueData = WebVTTSTYLECueParser.exec(subtitleElement))) {
1698
+ return null;
1699
+ } else if ((specialCueData = WebVTTCOMMENTCueParser.exec(subtitleElement))) {
1700
+ return null; // At this stage, we don't want to do anything with these.
1033
1701
  }
1034
- };
1035
- var checkChange = function(){
1036
- var fn = $.prop(this, 'checked') ? 'addClass' : 'removeClass';
1037
- var className = this.className || '';
1038
- var parent;
1039
1702
 
1040
- //IE8- has problems to update styles, we help
1041
- if( (className.indexOf('prop-checked') == -1) == (fn == 'addClass')){
1042
- $(this)[fn]('prop-checked');
1043
- if((parent = this.parentNode)){
1044
- parent.className = parent.className;
1045
- }
1046
- }
1047
- };
1703
+ subtitleParts = subtitleElement.split(/\n/g);
1048
1704
 
1049
-
1050
- webshims.onNodeNamesPropertyModify('select', 'value', selectChange);
1051
- webshims.onNodeNamesPropertyModify('select', 'selectedIndex', selectChange);
1052
- webshims.onNodeNamesPropertyModify('option', 'selected', function(){
1053
- $(this).closest('select').each(selectChange);
1054
- });
1055
- webshims.onNodeNamesPropertyModify('input', 'checked', function(value, boolVal){
1056
- var type = this.type;
1057
- if(type == 'radio' && boolVal){
1058
- webshims.modules["form-core"].getGroupElements(this).each(checkChange);
1059
- } else if(checkInputs[type]) {
1060
- $(this).each(checkChange);
1705
+ // Trim off any blank lines (logically, should only be max. one, but loop to be sure)
1706
+ while (!subtitleParts[0].replace(/\s+/ig,"").length && subtitleParts.length > 0) {
1707
+ subtitleParts.shift();
1061
1708
  }
1062
- });
1063
1709
 
1064
- $(document).on('change', function(e){
1065
-
1066
- if(checkInputs[e.target.type]){
1067
- if(e.target.type == 'radio'){
1068
- webshims.modules["form-core"].getGroupElements(e.target).each(checkChange);
1069
- } else {
1070
- $(e.target)[$.prop(e.target, 'checked') ? 'addClass' : 'removeClass']('prop-checked');
1071
- }
1072
- } else if(e.target.nodeName.toLowerCase() == 'select'){
1073
- $(e.target).each(selectChange);
1710
+ if (subtitleParts[0].match(/^\s*[a-z0-9-\_]+\s*$/ig)) {
1711
+ // The identifier becomes the cue ID (when *we* load the cues from file. Programatically created cues can have an ID of whatever.)
1712
+ id = String(subtitleParts.shift().replace(/\s*/ig,""));
1074
1713
  }
1075
- });
1076
1714
 
1077
- webshims.addReady(function(context, contextElem){
1078
- $('option, input', context)
1079
- .add(contextElem.filter('option, input'))
1080
- .each(function(){
1081
- var prop;
1082
- if(checkInputs[this.type]){
1083
- prop = 'checked';
1084
- } else if(this.nodeName.toLowerCase() == 'option'){
1085
- prop = 'selected';
1086
- }
1087
- if(prop){
1088
- $(this)[$.prop(this, prop) ? 'addClass' : 'removeClass']('prop-checked');
1089
- }
1715
+ for (subtitlePartIndex = 0; subtitlePartIndex < subtitleParts.length; subtitlePartIndex ++) {
1716
+ var timestamp = subtitleParts[subtitlePartIndex];
1717
+
1718
+ if ((timestampMatch = WebVTTTimestampParser.exec(timestamp))) {
1090
1719
 
1091
- })
1092
- ;
1093
- });
1094
- })();
1095
- }
1096
-
1097
- (function(){
1098
- Modernizr.textareaPlaceholder = !!('placeholder' in $('<textarea />')[0]);
1099
- if(Modernizr.input.placeholder && Modernizr.textareaPlaceholder){return;}
1100
-
1101
- var isOver = (webshims.cfg.forms.placeholderType == 'over');
1102
- var isResponsive = (webshims.cfg.forms.responsivePlaceholder);
1103
- var polyfillElements = ['textarea'];
1104
- if(!Modernizr.input.placeholder){
1105
- polyfillElements.push('input');
1106
- }
1107
-
1108
- var setSelection = function(elem){
1109
- try {
1110
- if(elem.setSelectionRange){
1111
- elem.setSelectionRange(0, 0);
1112
- return true;
1113
- } else if(elem.createTextRange){
1114
- var range = elem.createTextRange();
1115
- range.collapse(true);
1116
- range.moveEnd('character', 0);
1117
- range.moveStart('character', 0);
1118
- range.select();
1119
- return true;
1120
- }
1121
- } catch(er){}
1122
- };
1123
-
1124
- var hidePlaceholder = function(elem, data, value, _onFocus){
1125
- if(value === false){
1126
- value = $.prop(elem, 'value');
1127
- }
1128
- if(!isOver && elem.type != 'password'){
1129
- if(!value && _onFocus && setSelection(elem)){
1130
- var selectTimer = setTimeout(function(){
1131
- setSelection(elem);
1132
- }, 9);
1133
- $(elem)
1134
- .off('.placeholderremove')
1135
- .on({
1136
- 'keydown.placeholderremove keypress.placeholderremove paste.placeholderremove input.placeholderremove': function(e){
1137
- if(e && (e.keyCode == 17 || e.keyCode == 16)){return;}
1138
- elem.value = $.prop(elem, 'value');
1139
- data.box.removeClass('placeholder-visible');
1140
- clearTimeout(selectTimer);
1141
- $(elem).unbind('.placeholderremove');
1142
- },
1143
- 'mousedown.placeholderremove drag.placeholderremove select.placeholderremove': function(e){
1144
- setSelection(elem);
1145
- clearTimeout(selectTimer);
1146
- selectTimer = setTimeout(function(){
1147
- setSelection(elem);
1148
- }, 9);
1149
- },
1150
- 'blur.placeholderremove': function(){
1151
- clearTimeout(selectTimer);
1152
- $(elem).unbind('.placeholderremove');
1153
- }
1154
- })
1155
- ;
1156
- return;
1720
+ // WebVTT
1721
+
1722
+ timeData = timestampMatch.slice(1);
1723
+
1724
+ timeIn = parseInt((timeData[0]||0) * 60 * 60,10) + // Hours
1725
+ parseInt((timeData[1]||0) * 60,10) + // Minutes
1726
+ parseInt((timeData[2]||0),10) + // Seconds
1727
+ parseFloat("0." + (timeData[3]||0)); // MS
1728
+
1729
+ timeOut = parseInt((timeData[4]||0) * 60 * 60,10) + // Hours
1730
+ parseInt((timeData[5]||0) * 60,10) + // Minutes
1731
+ parseInt((timeData[6]||0),10) + // Seconds
1732
+ parseFloat("0." + (timeData[7]||0)); // MS
1733
+ /*
1734
+ if (timeData[8]) {
1735
+ cueSettings = timeData[8];
1736
+ }
1737
+ */
1157
1738
  }
1158
- elem.value = value;
1159
- } else if(!value && _onFocus){
1160
- $(elem)
1161
- .off('.placeholderremove')
1162
- .on({
1163
- 'keydown.placeholderremove keypress.placeholderremove paste.placeholderremove input.placeholderremove': function(e){
1164
- if(e && (e.keyCode == 17 || e.keyCode == 16)){return;}
1165
- data.box.removeClass('placeholder-visible');
1166
- $(elem).unbind('.placeholderremove');
1167
- },
1168
- 'blur.placeholderremove': function(){
1169
- $(elem).unbind('.placeholderremove');
1170
- }
1171
- })
1172
- ;
1173
- return;
1739
+
1740
+ // We've got the timestamp - return all the other unmatched lines as the raw subtitle data
1741
+ subtitleParts = subtitleParts.slice(0,subtitlePartIndex).concat(subtitleParts.slice(subtitlePartIndex+1));
1742
+ break;
1174
1743
  }
1175
- data.box.removeClass('placeholder-visible');
1176
- },
1177
- showPlaceholder = function(elem, data, placeholderTxt){
1178
- if(placeholderTxt === false){
1179
- placeholderTxt = $.prop(elem, 'placeholder');
1744
+
1745
+ if (!timeIn && !timeOut) {
1746
+ // We didn't extract any time information. Assume the cue is invalid!
1747
+ webshims.warn("couldn't extract time information: "+[timeIn, timeOut, subtitleParts.join("\n"), id].join(' ; '));
1748
+ return null;
1180
1749
  }
1750
+ /*
1751
+ // Consolidate cue settings, convert defaults to object
1752
+ var compositeCueSettings =
1753
+ cueDefaults
1754
+ .reduce(function(previous,current,index,array){
1755
+ previous[current.split(":")[0]] = current.split(":")[1];
1756
+ return previous;
1757
+ },{});
1181
1758
 
1182
- if(!isOver && elem.type != 'password'){
1183
- elem.value = placeholderTxt;
1184
- }
1185
- data.box.addClass('placeholder-visible');
1186
- },
1187
- changePlaceholderVisibility = function(elem, value, placeholderTxt, data, type){
1188
- if(!data){
1189
- data = $.data(elem, 'placeHolder');
1190
- if(!data){return;}
1191
- }
1192
- $(elem).unbind('.placeholderremove');
1193
- if(type == 'focus' || (!type && $(elem).is(':focus'))){
1194
- if(elem.type == 'password' || isOver || $(elem).hasClass('placeholder-visible')){
1195
- hidePlaceholder(elem, data, '', true);
1759
+ // Loop through cue settings, replace defaults with cue specific settings if they exist
1760
+ compositeCueSettings =
1761
+ cueSettings
1762
+ .split(/\s+/g)
1763
+ .filter(function(set) { return set && !!set.length; })
1764
+ // Convert array to a key/val object
1765
+ .reduce(function(previous,current,index,array){
1766
+ previous[current.split(":")[0]] = current.split(":")[1];
1767
+ return previous;
1768
+ },compositeCueSettings);
1769
+
1770
+ // Turn back into string like the TextTrackCue constructor expects
1771
+ cueSettings = "";
1772
+ for (var key in compositeCueSettings) {
1773
+ if (compositeCueSettings.hasOwnProperty(key)) {
1774
+ cueSettings += !!cueSettings.length ? " " : "";
1775
+ cueSettings += key + ":" + compositeCueSettings[key];
1196
1776
  }
1197
- return;
1198
- }
1199
- if(value === false){
1200
- value = $.prop(elem, 'value');
1201
- }
1202
- if(value){
1203
- hidePlaceholder(elem, data, value);
1204
- return;
1205
- }
1206
- if(placeholderTxt === false){
1207
- placeholderTxt = $.attr(elem, 'placeholder') || '';
1208
- }
1209
- if(placeholderTxt && !value){
1210
- showPlaceholder(elem, data, placeholderTxt);
1211
- } else {
1212
- hidePlaceholder(elem, data, value);
1213
1777
  }
1214
- },
1215
- createPlaceholder = function(elem){
1216
- elem = $(elem);
1217
- var id = elem.prop('id'),
1218
- hasLabel = !!(elem.prop('title') || elem.attr('aria-labelledby'))
1219
- ;
1220
- if(!hasLabel && id){
1221
- hasLabel = !!( $('label[for="'+ id +'"]', elem[0].form)[0] );
1222
- }
1223
- if(!hasLabel){
1224
- if(!id){
1225
- id = $.webshims.getID(elem);
1226
- }
1227
- hasLabel = !!($('label #'+ id)[0]);
1778
+ */
1779
+ // The remaining lines are the subtitle payload itself (after removing an ID if present, and the time);
1780
+ html = subtitleParts.join("\n");
1781
+ tmpCue = new TextTrackCue(timeIn, timeOut, html);
1782
+ if(id){
1783
+ tmpCue.id = id;
1228
1784
  }
1229
- return $( hasLabel ? '<span class="placeholder-text"></span>' : '<label for="'+ id +'" class="placeholder-text"></label>');
1230
- },
1231
- pHolder = (function(){
1232
- var delReg = /\n|\r|\f|\t/g,
1233
- allowedPlaceholder = {
1234
- text: 1,
1235
- search: 1,
1236
- url: 1,
1237
- email: 1,
1238
- password: 1,
1239
- tel: 1,
1240
- number: 1
1241
- }
1242
- ;
1785
+ return tmpCue;
1786
+ };
1787
+ })();
1788
+
1789
+ mediaelement.parseCaptions = function(captionData, track, complete) {
1790
+ var subtitles = mediaelement.createCueList();
1791
+ var cue, lazyProcess, regWevVTT;
1792
+ var startDate;
1793
+ var isWEBVTT;
1794
+ if (captionData) {
1243
1795
 
1244
- return {
1245
- create: function(elem){
1246
- var data = $.data(elem, 'placeHolder');
1247
- var form;
1248
- var responsiveElem;
1249
- if(data){return data;}
1250
- data = $.data(elem, 'placeHolder', {});
1251
-
1252
- $(elem).on('focus.placeholder blur.placeholder', function(e){
1253
- changePlaceholderVisibility(this, false, false, data, e.type );
1254
- data.box[e.type == 'focus' ? 'addClass' : 'removeClass']('placeholder-focused');
1255
- });
1256
-
1257
- if((form = $.prop(elem, 'form'))){
1258
- $(form).on('reset.placeholder', function(e){
1259
- setTimeout(function(){
1260
- changePlaceholderVisibility(elem, false, false, data, e.type );
1261
- }, 0);
1262
- });
1263
- }
1264
-
1265
- if(elem.type == 'password' || isOver){
1266
- data.text = createPlaceholder(elem);
1267
- if(isResponsive || $(elem).is('.responsive-width') || (elem.currentStyle || {width: ''}).width.indexOf('%') != -1){
1268
- responsiveElem = true;
1269
- data.box = data.text;
1270
- } else {
1271
- data.box = $(elem)
1272
- .wrap('<span class="placeholder-box placeholder-box-'+ (elem.nodeName || '').toLowerCase() +' placeholder-box-'+$.css(elem, 'float')+'" />')
1273
- .parent()
1274
- ;
1796
+ regWevVTT = /^WEBVTT(\s*FILE)?/ig;
1797
+
1798
+ lazyProcess = function(i, len){
1799
+
1800
+ for(; i < len; i++){
1801
+ cue = captionData[i];
1802
+ if(regWevVTT.test(cue)){
1803
+ isWEBVTT = true;
1804
+ } else if(cue.replace(/\s*/ig,"").length){
1805
+ if(!isWEBVTT){
1806
+ webshims.error('please use WebVTT format. This is the standard');
1807
+ complete(null);
1808
+ break;
1275
1809
  }
1276
- data.text
1277
- .insertAfter(elem)
1278
- .on('mousedown.placeholder', function(){
1279
- changePlaceholderVisibility(this, false, false, data, 'focus');
1280
- try {
1281
- setTimeout(function(){
1282
- elem.focus();
1283
- }, 0);
1284
- } catch(e){}
1285
- return false;
1286
- })
1287
- ;
1288
-
1289
-
1290
- $.each(['lineHeight', 'fontSize', 'fontFamily', 'fontWeight'], function(i, style){
1291
- var prop = $.css(elem, style);
1292
- if(data.text.css(style) != prop){
1293
- data.text.css(style, prop);
1294
- }
1295
- });
1296
- $.each(['Left', 'Top'], function(i, side){
1297
- var size = (parseInt($.css(elem, 'padding'+ side), 10) || 0) + Math.max((parseInt($.css(elem, 'margin'+ side), 10) || 0), 0) + (parseInt($.css(elem, 'border'+ side +'Width'), 10) || 0);
1298
- data.text.css('padding'+ side, size);
1299
- });
1300
-
1301
- $(document)
1302
- .onTrigger('updateshadowdom', function(){
1303
- var height, width;
1304
- if((width = elem.offsetWidth) || (height = elem.offsetHeight)){
1305
- data.text
1306
- .css({
1307
- width: width,
1308
- height: height
1309
- })
1310
- .css($(elem).position())
1311
- ;
1312
- }
1313
- })
1314
- ;
1315
-
1316
- } else {
1317
- var reset = function(e){
1318
- if($(elem).hasClass('placeholder-visible')){
1319
- hidePlaceholder(elem, data, '');
1320
- if(e && e.type == 'submit'){
1321
- setTimeout(function(){
1322
- if(e.isDefaultPrevented()){
1323
- changePlaceholderVisibility(elem, false, false, data );
1324
- }
1325
- }, 9);
1326
- }
1327
- }
1328
- };
1329
-
1330
- $(window).on('beforeunload', reset);
1331
- data.box = $(elem);
1332
- if(form){
1333
- $(form).submit(reset);
1810
+ cue = mediaelement.parseCaptionChunk(cue, i);
1811
+ if(cue){
1812
+ track.addCue(cue);
1334
1813
  }
1335
1814
  }
1336
-
1337
- return data;
1338
- },
1339
- update: function(elem, val){
1340
- var type = ($.attr(elem, 'type') || $.prop(elem, 'type') || '').toLowerCase();
1341
- if(!allowedPlaceholder[type] && !$.nodeName(elem, 'textarea')){
1342
- webshims.error('placeholder not allowed on input[type="'+type+'"]');
1343
- if(type == 'date'){
1344
- webshims.error('but you can use data-placeholder for input[type="date"]');
1345
- }
1346
- return;
1815
+ if(startDate < (new Date().getTime()) - 30){
1816
+ i++;
1817
+ setTimeout(function(){
1818
+ startDate = new Date().getTime();
1819
+ lazyProcess(i, len);
1820
+ }, 90);
1821
+
1822
+ break;
1347
1823
  }
1348
-
1349
-
1350
- var data = pHolder.create(elem);
1351
- if(data.text){
1352
- data.text.text(val);
1824
+ }
1825
+ if(i >= len){
1826
+ if(!isWEBVTT){
1827
+ webshims.error('please use WebVTT format. This is the standard');
1353
1828
  }
1354
-
1355
- changePlaceholderVisibility(elem, false, val, data);
1829
+ complete(track.cues);
1356
1830
  }
1357
1831
  };
1358
- })()
1359
- ;
1832
+
1833
+ captionData = captionData.replace(/\r\n/g,"\n");
1834
+
1835
+ setTimeout(function(){
1836
+ captionData = captionData.replace(/\r/g,"\n");
1837
+ setTimeout(function(){
1838
+ startDate = new Date().getTime();
1839
+ captionData = captionData.split(/\n\n+/g);
1840
+ lazyProcess(0, captionData.length);
1841
+ }, 9);
1842
+ }, 9);
1843
+
1844
+ } else {
1845
+ webshims.error("Required parameter captionData not supplied.");
1846
+ }
1847
+ };
1848
+
1360
1849
 
1361
- $.webshims.publicMethods = {
1362
- pHolder: pHolder
1850
+ mediaelement.createTrackList = function(mediaelem, baseData){
1851
+ baseData = baseData || webshims.data(mediaelem, 'mediaelementBase') || webshims.data(mediaelem, 'mediaelementBase', {});
1852
+ if(!baseData.textTracks){
1853
+ baseData.textTracks = [];
1854
+ webshims.defineProperties(baseData.textTracks, {
1855
+ onaddtrack: {value: null},
1856
+ onremovetrack: {value: null}
1857
+ });
1858
+ createEventTarget(baseData.textTracks);
1859
+ }
1860
+ return baseData.textTracks;
1363
1861
  };
1364
- polyfillElements.forEach(function(nodeName){
1365
- var desc = webshims.defineNodeNameProperty(nodeName, 'placeholder', {
1366
- attr: {
1367
- set: function(val){
1368
- var elem = this;
1369
- webshims.contentAttr(elem, 'placeholder', val);
1370
- pHolder.update(elem, val);
1371
- },
1372
- get: function(){
1373
- return webshims.contentAttr(this, 'placeholder');
1374
- }
1375
- },
1376
- reflect: true,
1377
- initAttr: true
1378
- });
1379
- });
1380
1862
 
1863
+ if(!Modernizr.track){
1864
+ webshims.defineNodeNamesBooleanProperty(['track'], 'default');
1865
+ webshims.reflectProperties(['track'], ['srclang', 'label']);
1866
+
1867
+ webshims.defineNodeNameProperties('track', {
1868
+ src: {
1869
+ //attr: {},
1870
+ reflect: true,
1871
+ propType: 'src'
1872
+ }
1873
+ });
1874
+ }
1381
1875
 
1382
- polyfillElements.forEach(function(name){
1383
- var placeholderValueDesc = {};
1384
- var desc;
1385
- ['attr', 'prop'].forEach(function(propType){
1386
- placeholderValueDesc[propType] = {
1387
- set: function(val){
1388
- var elem = this;
1389
- var placeholder = webshims.contentAttr(elem, 'placeholder');
1390
-
1391
-
1392
- $.removeData(elem, 'cachedValidity');
1393
- var ret = desc[propType]._supset.call(elem, val);
1394
- if(placeholder && 'value' in elem){
1395
- changePlaceholderVisibility(elem, val, placeholder);
1876
+ webshims.defineNodeNameProperties('track', {
1877
+ kind: {
1878
+ attr: Modernizr.track ? {
1879
+ set: function(value){
1880
+ var trackData = webshims.data(this, 'trackData');
1881
+ this.setAttribute('data-kind', value);
1882
+ if(trackData){
1883
+ trackData.attrKind = value;
1396
1884
  }
1397
- return ret;
1398
1885
  },
1399
1886
  get: function(){
1400
- var elem = this;
1401
- return $(elem).hasClass('placeholder-visible') ? '' : desc[propType]._supget.call(elem);
1887
+ var trackData = webshims.data(this, 'trackData');
1888
+ if(trackData && ('attrKind' in trackData)){
1889
+ return trackData.attrKind;
1890
+ }
1891
+ return this.getAttribute('kind');
1402
1892
  }
1403
- };
1404
- });
1405
- desc = webshims.defineNodeNameProperty(name, 'value', placeholderValueDesc);
1893
+ } : {},
1894
+ reflect: true,
1895
+ propType: 'enumarated',
1896
+ defaultValue: 'subtitles',
1897
+ limitedTo: ['subtitles', 'captions', 'descriptions', 'chapters', 'metadata']
1898
+ }
1406
1899
  });
1407
1900
 
1408
- })();
1409
-
1410
- (function(){
1411
- var doc = document;
1412
- if( 'value' in document.createElement('output') ){return;}
1413
-
1414
- webshims.defineNodeNameProperty('output', 'value', {
1415
- prop: {
1416
- set: function(value){
1417
- var setVal = $.data(this, 'outputShim');
1418
- if(!setVal){
1419
- setVal = outputCreate(this);
1420
- }
1421
- setVal(value);
1422
- },
1423
- get: function(){
1424
- return webshims.contentAttr(this, 'value') || $(this).text() || '';
1901
+ $.each(copyProps, function(i, copyProp){
1902
+ var name = copyName[copyProp] || copyProp;
1903
+ webshims.onNodeNamesPropertyModify('track', copyProp, function(){
1904
+ var trackData = webshims.data(this, 'trackData');
1905
+ var track = this;
1906
+ if(trackData){
1907
+ if(copyProp == 'kind'){
1908
+ refreshTrack(this, trackData);
1425
1909
  }
1910
+ if(!supportTrackMod){
1911
+ trackData.track[name] = $.prop(this, copyProp);
1912
+ }
1913
+ clearTimeout(trackData.changedTrackPropTimer);
1914
+ trackData.changedTrackPropTimer = setTimeout(function(){
1915
+ $(track).trigger('updatesubtitlestate');
1916
+ }, 1);
1426
1917
  }
1427
1918
  });
1428
-
1429
-
1430
- webshims.onNodeNamesPropertyModify('input', 'value', function(value, boolVal, type){
1431
- if(type == 'removeAttr'){return;}
1432
- var setVal = $.data(this, 'outputShim');
1433
- if(setVal){
1434
- setVal(value);
1435
- }
1436
- });
1437
-
1438
- var outputCreate = function(elem){
1439
- if(elem.getAttribute('aria-live')){return;}
1440
- elem = $(elem);
1441
- var value = (elem.text() || '').trim();
1442
- var id = elem.attr('id');
1443
- var htmlFor = elem.attr('for');
1444
- var shim = $('<input class="output-shim" type="text" disabled name="'+ (elem.attr('name') || '')+'" value="'+value+'" style="display: none !important;" />').insertAfter(elem);
1445
- var form = shim[0].form || doc;
1446
- var setValue = function(val){
1447
- shim[0].value = val;
1448
- val = shim[0].value;
1449
- elem.text(val);
1450
- webshims.contentAttr(elem[0], 'value', val);
1451
- };
1452
-
1453
- elem[0].defaultValue = value;
1454
- webshims.contentAttr(elem[0], 'value', value);
1455
-
1456
- elem.attr({'aria-live': 'polite'});
1457
- if(id){
1458
- shim.attr('id', id);
1459
- elem.attr('aria-labelledby', webshims.getID($('label[for="'+id+'"]', form)));
1460
- }
1461
- if(htmlFor){
1462
- id = webshims.getID(elem);
1463
- htmlFor.split(' ').forEach(function(control){
1464
- control = document.getElementById(control);
1465
- if(control){
1466
- control.setAttribute('aria-controls', id);
1467
- }
1468
- });
1469
- }
1470
- elem.data('outputShim', setValue );
1471
- shim.data('outputShim', setValue );
1472
- return setValue;
1473
- };
1474
-
1475
- webshims.addReady(function(context, contextElem){
1476
- $('output', context).add(contextElem.filter('output')).each(function(){
1477
- outputCreate(this);
1478
- });
1479
- });
1480
-
1481
- /*
1482
- * Implements input event in all browsers
1483
- */
1484
- (function(){
1485
- var noInputTriggerEvts = {updateInput: 1, input: 1},
1486
- noInputTypes = {
1487
- radio: 1,
1488
- checkbox: 1,
1489
- submit: 1,
1490
- button: 1,
1491
- image: 1,
1492
- reset: 1,
1493
- file: 1
1494
-
1495
- //pro forma
1496
- ,color: 1
1497
- //,range: 1
1498
- },
1499
- observe = function(input){
1500
- var timer,
1501
- lastVal = input.prop('value'),
1502
- trigger = function(e){
1503
- //input === null
1504
- if(!input){return;}
1505
- var newVal = input.prop('value');
1506
-
1507
- if(newVal !== lastVal){
1508
- lastVal = newVal;
1509
- if(!e || !noInputTriggerEvts[e.type]){
1510
- webshims.triggerInlineForm && webshims.triggerInlineForm(input[0], 'input');
1511
- }
1512
- }
1513
- },
1514
- extraTimer,
1515
- extraTest = function(){
1516
- clearTimeout(extraTimer);
1517
- extraTimer = setTimeout(trigger, 9);
1518
- },
1519
- unbind = function(){
1520
- input.unbind('focusout', unbind).unbind('keyup keypress keydown paste cut', extraTest).unbind('input change updateInput', trigger);
1521
- clearInterval(timer);
1522
- setTimeout(function(){
1523
- trigger();
1524
- input = null;
1525
- }, 1);
1526
-
1527
- }
1528
- ;
1529
-
1530
- clearInterval(timer);
1531
- timer = setInterval(trigger, 99);
1532
- extraTest();
1533
- input.on({
1534
- 'keyup keypress keydown paste cut': extraTest,
1535
- focusout: unbind,
1536
- 'input updateInput change': trigger
1537
- });
1538
- }
1539
- ;
1540
- if($.event.customEvent){
1541
- $.event.customEvent.updateInput = true;
1542
- }
1543
-
1544
- $(doc)
1545
- .on('focusin', function(e){
1546
- if( e.target && e.target.type && !e.target.readOnly && !e.target.disabled && (e.target.nodeName || '').toLowerCase() == 'input' && !noInputTypes[e.target.type] ){
1547
- observe($(e.target));
1548
- }
1549
- })
1550
- ;
1551
- })();
1552
- })();
1553
-
1554
- }); //webshims.ready end
1555
- }//end formvalidation
1556
-
1557
- jQuery.webshims.register('form-message', function($, webshims, window, document, undefined, options){
1558
- "use strict";
1559
- var validityMessages = webshims.validityMessages;
1560
-
1561
- var implementProperties = (options.overrideMessages || options.customMessages) ? ['customValidationMessage'] : [];
1562
-
1563
- validityMessages['en'] = $.extend(true, {
1564
- typeMismatch: {
1565
- email: 'Please enter an email address.',
1566
- url: 'Please enter a URL.',
1567
- number: 'Please enter a number.',
1568
- date: 'Please enter a date.',
1569
- time: 'Please enter a time.',
1570
- range: 'Invalid input.',
1571
- "datetime-local": 'Please enter a datetime.'
1572
- },
1573
- rangeUnderflow: {
1574
- defaultMessage: 'Value must be greater than or equal to {%min}.'
1575
- },
1576
- rangeOverflow: {
1577
- defaultMessage: 'Value must be less than or equal to {%max}.'
1578
- },
1579
- stepMismatch: 'Invalid input.',
1580
- tooLong: 'Please enter at most {%maxlength} character(s). You entered {%valueLen}.',
1581
-
1582
- patternMismatch: 'Invalid input. {%title}',
1583
- valueMissing: {
1584
- defaultMessage: 'Please fill out this field.',
1585
- checkbox: 'Please check this box if you want to proceed.'
1586
- }
1587
- }, (validityMessages['en'] || validityMessages['en-US'] || {}));
1919
+ });
1588
1920
 
1589
1921
 
1590
- ['select', 'radio'].forEach(function(type){
1591
- if(typeof validityMessages['en'].valueMissing == 'object'){
1592
- validityMessages['en'].valueMissing[type] = 'Please select an option.';
1922
+ webshims.onNodeNamesPropertyModify('track', 'src', function(val){
1923
+ if(val){
1924
+ var data = webshims.data(this, 'trackData');
1925
+ var media;
1926
+ if(data){
1927
+ media = $(this).closest('video, audio');
1928
+ if(media[0]){
1929
+ mediaelement.loadTextTrack(media, this, data);
1930
+ }
1931
+ }
1593
1932
  }
1933
+
1594
1934
  });
1595
1935
 
1596
- ['date', 'time', 'datetime-local'].forEach(function(type){
1597
- if(typeof validityMessages['en'].rangeUnderflow == 'object'){
1598
- validityMessages.en.rangeUnderflow[type] = 'Value must be at or after {%min}.';
1599
- }
1600
- });
1601
- ['date', 'time', 'datetime-local'].forEach(function(type){
1602
- if(typeof validityMessages['en'].rangeOverflow == 'object'){
1603
- validityMessages.en.rangeOverflow[type] = 'Value must be at or before {%max}.';
1604
- }
1605
- });
1936
+ //
1606
1937
 
1607
- validityMessages['en-US'] = validityMessages['en-US'] || validityMessages['en'];
1608
- validityMessages[''] = validityMessages[''] || validityMessages['en-US'];
1609
-
1610
- validityMessages['de'] = $.extend(true, {
1611
- typeMismatch: {
1612
- email: '{%value} ist keine zulässige E-Mail-Adresse',
1613
- url: '{%value} ist keine zulässige Webadresse',
1614
- number: '{%value} ist keine Nummer!',
1615
- date: '{%value} ist kein Datum',
1616
- time: '{%value} ist keine Uhrzeit',
1617
- range: '{%value} ist keine Nummer!',
1618
- "datetime-local": '{%value} ist kein Datum-Uhrzeit Format.'
1938
+ webshims.defineNodeNamesProperties(['track'], {
1939
+ ERROR: {
1940
+ value: 3
1619
1941
  },
1620
- rangeUnderflow: {
1621
- defaultMessage: '{%value} ist zu niedrig. {%min} ist der unterste Wert, den Sie benutzen können.'
1942
+ LOADED: {
1943
+ value: 2
1622
1944
  },
1623
- rangeOverflow: {
1624
- defaultMessage: '{%value} ist zu hoch. {%max} ist der oberste Wert, den Sie benutzen können.'
1945
+ LOADING: {
1946
+ value: 1
1625
1947
  },
1626
- stepMismatch: 'Der Wert {%value} ist in diesem Feld nicht zulässig. Hier sind nur bestimmte Werte zulässig. {%title}',
1627
- tooLong: 'Der eingegebene Text ist zu lang! Sie haben {%valueLen} Zeichen eingegeben, dabei sind {%maxlength} das Maximum.',
1628
- patternMismatch: '{%value} hat für dieses Eingabefeld ein falsches Format! {%title}',
1629
- valueMissing: {
1630
- defaultMessage: 'Bitte geben Sie einen Wert ein',
1631
- checkbox: 'Bitte aktivieren Sie das Kästchen'
1948
+ NONE: {
1949
+ value: 0
1950
+ },
1951
+ readyState: {
1952
+ get: function(){
1953
+ return ($.prop(this, 'track') || {readyState: 0}).readyState;
1954
+ },
1955
+ writeable: false
1956
+ },
1957
+ track: {
1958
+ get: function(){
1959
+ return mediaelement.createTextTrack($(this).closest('audio, video')[0], this);
1960
+ },
1961
+ writeable: false
1632
1962
  }
1633
- }, (validityMessages['de'] || {}));
1963
+ }, 'prop');
1634
1964
 
1635
- ['select', 'radio'].forEach(function(type){
1636
- if(typeof validityMessages['de'].valueMissing == 'object'){
1637
- validityMessages['de'].valueMissing[type] = 'Bitte wählen Sie eine Option aus';
1965
+ webshims.defineNodeNamesProperties(['audio', 'video'], {
1966
+ textTracks: {
1967
+ get: function(){
1968
+ var media = this;
1969
+ var baseData = webshims.data(media, 'mediaelementBase') || webshims.data(media, 'mediaelementBase', {});
1970
+ var tracks = mediaelement.createTrackList(media, baseData);
1971
+ if(!baseData.blockTrackListUpdate){
1972
+ updateMediaTrackList.call(media, baseData, tracks);
1973
+ }
1974
+ return tracks;
1975
+ },
1976
+ writeable: false
1977
+ },
1978
+ addTextTrack: {
1979
+ value: function(kind, label, lang){
1980
+ var textTrack = mediaelement.createTextTrack(this, {
1981
+ kind: dummyTrack.prop('kind', kind || '').prop('kind'),
1982
+ label: label || '',
1983
+ srclang: lang || ''
1984
+ });
1985
+ var baseData = webshims.data(this, 'mediaelementBase') || webshims.data(this, 'mediaelementBase', {});
1986
+ if (!baseData.scriptedTextTracks) {
1987
+ baseData.scriptedTextTracks = [];
1988
+ }
1989
+ baseData.scriptedTextTracks.push(textTrack);
1990
+ updateMediaTrackList.call(this);
1991
+ return textTrack;
1992
+ }
1638
1993
  }
1639
- });
1994
+ }, 'prop');
1995
+
1640
1996
 
1641
- ['date', 'time', 'datetime-local'].forEach(function(type){
1642
- if(typeof validityMessages['de'].rangeUnderflow == 'object'){
1643
- validityMessages.de.rangeUnderflow[type] = '{%value} ist zu früh. {%min} ist die früheste Zeit, die Sie benutzen können.';
1644
- }
1645
- });
1646
- ['date', 'time', 'datetime-local'].forEach(function(type){
1647
- if(typeof validityMessages['de'].rangeOverflow == 'object'){
1648
- validityMessages.de.rangeOverflow[type] = '{%value} ist zu spät. {%max} ist die späteste Zeit, die Sie benutzen können.';
1997
+ $(document).on('emptied ended updatetracklist', function(e){
1998
+ if($(e.target).is('audio, video')){
1999
+ var baseData = webshims.data(e.target, 'mediaelementBase');
2000
+ if(baseData){
2001
+ clearTimeout(baseData.updateTrackListTimer);
2002
+ baseData.updateTrackListTimer = setTimeout(function(){
2003
+ updateMediaTrackList.call(e.target, baseData);
2004
+ }, 0);
2005
+ }
1649
2006
  }
1650
2007
  });
1651
2008
 
1652
- var currentValidationMessage = validityMessages[''];
1653
-
1654
-
1655
- webshims.createValidationMessage = function(elem, name){
1656
- var message = currentValidationMessage[name];
1657
- if(message && typeof message !== 'string'){
1658
- message = message[ $.prop(elem, 'type') ] || message[ (elem.nodeName || '').toLowerCase() ] || message[ 'defaultMessage' ];
2009
+ var getNativeReadyState = function(trackElem, textTrack){
2010
+ return textTrack.readyState || trackElem.readyState;
2011
+ };
2012
+ var stopOriginalEvent = function(e){
2013
+ if(e.originalEvent){
2014
+ e.stopImmediatePropagation();
1659
2015
  }
1660
- if(message){
1661
- ['value', 'min', 'max', 'title', 'maxlength', 'label'].forEach(function(attr){
1662
- if(message.indexOf('{%'+attr) === -1){return;}
1663
- var val = ((attr == 'label') ? $.trim($('label[for="'+ elem.id +'"]', elem.form).text()).replace(/\*$|:$/, '') : $.attr(elem, attr)) || '';
1664
- if(name == 'patternMismatch' && attr == 'title' && !val){
1665
- webshims.error('no title for patternMismatch provided. Always add a title attribute.');
2016
+ };
2017
+ var startTrackImplementation = function(){
2018
+ if(webshims.implement(this, 'track')){
2019
+ var shimedTrack = $.prop(this, 'track');
2020
+ var origTrack = this.track;
2021
+ var kind;
2022
+ var readyState;
2023
+ if(origTrack){
2024
+ kind = $.prop(this, 'kind');
2025
+ readyState = getNativeReadyState(this, origTrack);
2026
+ if (origTrack.mode || readyState) {
2027
+ shimedTrack.mode = numericModes[origTrack.mode] || origTrack.mode;
1666
2028
  }
1667
- message = message.replace('{%'+ attr +'}', val);
1668
- if('value' == attr){
1669
- message = message.replace('{%valueLen}', val.length);
2029
+ //disable track from showing + remove UI
2030
+ if(kind != 'descriptions'){
2031
+ origTrack.mode = (typeof origTrack.mode == 'string') ? 'disabled' : 0;
2032
+ this.kind = 'metadata';
2033
+ $(this).attr({kind: kind});
1670
2034
  }
1671
- });
2035
+
2036
+ }
2037
+ $(this).on('load error', stopOriginalEvent);
1672
2038
  }
1673
- return message || '';
1674
2039
  };
1675
-
1676
-
1677
- if(webshims.bugs.validationMessage || !Modernizr.formvalidation || webshims.bugs.bustedValidity){
1678
- implementProperties.push('validationMessage');
1679
- }
1680
-
1681
- webshims.activeLang({
1682
- langObj: validityMessages,
1683
- module: 'form-core',
1684
- callback: function(langObj){
1685
- currentValidationMessage = langObj;
1686
- }
1687
- });
1688
-
1689
- implementProperties.forEach(function(messageProp){
1690
- webshims.defineNodeNamesProperty(['fieldset', 'output', 'button'], messageProp, {
1691
- prop: {
1692
- value: '',
1693
- writeable: false
1694
- }
1695
- });
1696
- ['input', 'select', 'textarea'].forEach(function(nodeName){
1697
- var desc = webshims.defineNodeNameProperty(nodeName, messageProp, {
1698
- prop: {
1699
- get: function(){
1700
- var elem = this;
1701
- var message = '';
1702
- if(!$.prop(elem, 'willValidate')){
1703
- return message;
1704
- }
1705
-
1706
- var validity = $.prop(elem, 'validity') || {valid: 1};
1707
-
1708
- if(validity.valid){return message;}
1709
- message = webshims.getContentValidationMessage(elem, validity);
1710
-
1711
- if(message){return message;}
1712
-
1713
- if(validity.customError && elem.nodeName){
1714
- message = (Modernizr.formvalidation && !webshims.bugs.bustedValidity && desc.prop._supget) ? desc.prop._supget.call(elem) : webshims.data(elem, 'customvalidationMessage');
1715
- if(message){return message;}
1716
- }
1717
- $.each(validity, function(name, prop){
1718
- if(name == 'valid' || !prop){return;}
1719
-
1720
- message = webshims.createValidationMessage(elem, name);
1721
- if(message){
1722
- return false;
1723
- }
1724
- });
1725
- return message || '';
1726
- },
1727
- writeable: false
2040
+ webshims.addReady(function(context, insertedElement){
2041
+ var insertedMedia = insertedElement.filter('video, audio, track').closest('audio, video');
2042
+ $('video, audio', context)
2043
+ .add(insertedMedia)
2044
+ .each(function(){
2045
+ updateMediaTrackList.call(this);
2046
+ })
2047
+ .each(function(){
2048
+ if(Modernizr.track){
2049
+ var shimedTextTracks = $.prop(this, 'textTracks');
2050
+ var origTextTracks = this.textTracks;
2051
+ if(shimedTextTracks.length != origTextTracks.length){
2052
+ webshims.error("textTracks couldn't be copied");
2053
+ }
2054
+
2055
+ $('track', this).each(startTrackImplementation);
1728
2056
  }
1729
- });
2057
+ })
2058
+ ;
2059
+ insertedMedia.each(function(){
2060
+ var media = this;
2061
+ var baseData = webshims.data(media, 'mediaelementBase');
2062
+ if(baseData){
2063
+ clearTimeout(baseData.updateTrackListTimer);
2064
+ baseData.updateTrackListTimer = setTimeout(function(){
2065
+ updateMediaTrackList.call(media, baseData);
2066
+ }, 9);
2067
+ }
1730
2068
  });
1731
-
1732
2069
  });
2070
+
2071
+ if(Modernizr.track){
2072
+ $('video, audio').trigger('trackapichange');
2073
+ }
1733
2074
  });