Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/includes/MwEmbedResourceManager.php |
— | — | @@ -49,7 +49,7 @@ |
50 | 50 | // Check for module loader: |
51 | 51 | if( is_file( $fullResourcePath . '/' . $moduleName . '.loader.js' )){ |
52 | 52 | $resourceList[ $moduleName . '.loader' ] = array( |
53 | | - 'loaderScript' => $moduleName . '.loader.js' |
| 53 | + 'loaderScripts' => $moduleName . '.loader.js' |
54 | 54 | ); |
55 | 55 | } |
56 | 56 | |
— | — | @@ -66,7 +66,6 @@ |
67 | 67 | */ |
68 | 68 | public static function registerModules( &$resourceLoader ) { |
69 | 69 | global $IP; |
70 | | - print_r( self::$moduleSet ); |
71 | 70 | // Register all the resources with the resource loader |
72 | 71 | foreach( self::$moduleSet as $path => $modules ) { |
73 | 72 | foreach ( $modules as $name => $resources ) { |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/includes/MwEmbedMediaWikiStubs.php |
— | — | @@ -161,6 +161,20 @@ |
162 | 162 | public static function linkedScript( $url ) { |
163 | 163 | return '<script src="' . htmlspecialchars( $url) . '" type="text/javascript"></script>'; |
164 | 164 | } |
| 165 | + /** |
| 166 | + * Output a <script> tag with the given contents. TODO: do some useful |
| 167 | + * escaping as well, like if $contents contains literal '</script>' or (for |
| 168 | + * XML) literal "]]>". |
| 169 | + * |
| 170 | + * @param $contents string JavaScript |
| 171 | + * @return string Raw HTML |
| 172 | + */ |
| 173 | + public static function inlineScript( $contents ) { |
| 174 | + if ( preg_match( '/[<&]/', $contents ) ) { |
| 175 | + $contents = "/*<![CDATA[*/$contents/*]]>*/"; |
| 176 | + } |
| 177 | + return '<script type"text/javascript">'. $contents . '</script>'; |
| 178 | + } |
165 | 179 | } |
166 | 180 | |
167 | 181 | |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/includes/MwEmbedResourceLoaderStartUpModule.php |
— | — | @@ -30,7 +30,21 @@ |
31 | 31 | } |
32 | 32 | return $this->fileDeps[$skin];*/ |
33 | 33 | } |
| 34 | + /** |
| 35 | + * mwEmbedStartup is dependent on mwEmbedSupport |
| 36 | + */ |
| 37 | + public function getStartupModuleList(){ |
| 38 | + // Startup modules don't respect dependency manually add 'jquery.triggerQueueCallback', 'mwEmbedSupport' |
| 39 | + return array( 'jquery', 'mediawiki', 'mwEmbedSupport' ); |
| 40 | + } |
34 | 41 | |
| 42 | + public function getScript( ResourceLoaderContext $context ) { |
| 43 | + $out = parent::getScript( $context ); |
| 44 | + // Append mediaWiki.loader.go() for stand alone context: |
| 45 | + $out.= Xml::encodeJsCall( 'document.write', array( Html::inlineScript( "mediaWiki.loader.go();" ) ) ); |
| 46 | + return $out; |
| 47 | + } |
| 48 | + |
35 | 49 | protected function getConfig( $context ) { |
36 | 50 | // @@todo set all the configuration variables |
37 | 51 | $vars = array(); |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/includes/resourceloader/ResourceLoaderStartUpModule.php |
— | — | @@ -150,12 +150,11 @@ |
151 | 151 | if ( $context->getOnly() === 'scripts' ) { |
152 | 152 | // Get the latest version |
153 | 153 | $version = 0; |
154 | | - $modules = $this->getStartupModuleList(); |
| 154 | + $modules = $this->getStartupModuleList(); |
155 | 155 | foreach( $modules as $moduleName){ |
156 | | - $version = max( $version, $context->getResourceLoader()->getModule( 'jquery' )->getModifiedTime( $context ) ); |
157 | | - } |
158 | | - |
159 | | - // Build load query for jquery and mediawiki modules |
| 156 | + $version = max( $version, $context->getResourceLoader()->getModule( $moduleName )->getModifiedTime( $context ) ); |
| 157 | + } |
| 158 | + // Build load query for StartupModules |
160 | 159 | $query = array( |
161 | 160 | 'modules' => implode( '|', $modules ), |
162 | 161 | 'only' => 'scripts', |
— | — | @@ -180,11 +179,11 @@ |
181 | 180 | $out .= "if ( mwIsCompatible() ) {\n" . |
182 | 181 | "\t" . Xml::encodeJsCall( 'document.write', array( $scriptTag ) ) . |
183 | 182 | "}\n" . |
184 | | - "delete isCompatible;"; |
| 183 | + "delete mwIsCompatible;"; |
185 | 184 | } |
186 | 185 | return $out; |
187 | 186 | } |
188 | | - private function getStartupModuleList(){ |
| 187 | + public function getStartupModuleList(){ |
189 | 188 | return array( 'jquery', 'mediawiki' ); |
190 | 189 | } |
191 | 190 | public function getModifiedTime( ResourceLoaderContext $context ) { |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/modules/MwEmbedSupport/mwEmbed.core.js |
— | — | @@ -1,433 +0,0 @@ |
2 | | -// Add support for html5 / mwEmbed elements to IE |
3 | | -// For discussion and comments, see: http://remysharp.com/2009/01/07/html5-enabling-script/ |
4 | | -'video audio source track'.replace(/\w+/g,function( n ){ document.createElement( n ) } ); |
5 | | - |
6 | | -/** |
7 | | - * mwEmbed.core includes shared mwEmbed utilities |
8 | | - * |
9 | | - * @license |
10 | | - * mwEmbed |
11 | | - * Dual licensed under the MIT or GPL Version 2 licenses. |
12 | | - * |
13 | | - * @copyright (C) 2010 Kaltura |
14 | | - * @author Michael Dale ( michael.dale at kaltura.com ) |
15 | | - * |
16 | | - * @url http://www.kaltura.org/project/HTML5_Video_Media_JavaScript_Library |
17 | | - * |
18 | | - * Libraries used include code license in headers |
19 | | - */ |
20 | | - |
21 | | - |
22 | | -( function( mw, $ ) { |
23 | | - |
24 | | - /** |
25 | | - * Set the mwEmbedVersion |
26 | | - */ |
27 | | - window.MW_EMBED_VERSION = '1.1g'; |
28 | | - |
29 | | - // Globals to pre-set ready functions in dynamic loading of mwEmbed |
30 | | - if( typeof window.preMwEmbedReady == 'undefined'){ |
31 | | - window.preMwEmbedReady = []; |
32 | | - } |
33 | | - // Globals to pre-set config values in dynamic loading of mwEmbed |
34 | | - if( typeof window.preMwEmbedConfig == 'undefined') { |
35 | | - window.preMwEmbedConfig = []; |
36 | | - } |
37 | | - |
38 | | - /** |
39 | | - * Enables pages to target a "interfaces ready" state. |
40 | | - * |
41 | | - * TODO make it work! |
42 | | - * |
43 | | - * This is different from jQuery(document).ready() ( jQuery ready is not |
44 | | - * friendly with dynamic includes and not friendly with core interface |
45 | | - * asynchronous build out. ) |
46 | | - * |
47 | | - * @param {Function} |
48 | | - * callback Function to run once DOM and jQuery are ready |
49 | | - */ |
50 | | - var mwOnLoadFunctions = []; // Setup the local mwOnLoadFunctions array: |
51 | | - var mwReadyFlag = false; // mw Ready flag ( set once mwEmbed is ready ) |
52 | | - mw.ready = function( callback ) { |
53 | | - if( mwReadyFlag === false ) { |
54 | | - // Add the callbcak to the onLoad function stack |
55 | | - mwOnLoadFunctions.push ( callback ); |
56 | | - } else { |
57 | | - // If mwReadyFlag is already "true" issue the callback directly: |
58 | | - callback(); |
59 | | - } |
60 | | - }; |
61 | | - |
62 | | - // add a domReady setup infterface trigger |
63 | | - SetupInterface |
64 | | - /** |
65 | | - * Runs all the queued functions called by mwEmbedSetup |
66 | | - */ |
67 | | - mw.runReadyFunctions = function ( ) { |
68 | | - mw.log('mw.runReadyFunctions: ' + mwOnLoadFunctions.length ); |
69 | | - // Run any pre-setup ready functions |
70 | | - while( preMwEmbedReady.length ){ |
71 | | - preMwEmbedReady.shift()(); |
72 | | - } |
73 | | - // Run all the queued functions: |
74 | | - while( mwOnLoadFunctions.length ) { |
75 | | - mwOnLoadFunctions.shift()(); |
76 | | - } |
77 | | - // Sets mwReadyFlag to true so that future mw.ready run the |
78 | | - // callback directly |
79 | | - mwReadyFlag = true; |
80 | | - |
81 | | - }; |
82 | | - |
83 | | - /** |
84 | | - * Aliased functions |
85 | | - * |
86 | | - * Wrap mediaWiki functionality while we port over the libraries |
87 | | - */ |
88 | | - mw.setConfig = function( name, value ){ |
89 | | - mediaWiki.config.set( name, value ); |
90 | | - }; |
91 | | - mw.getConfig = function( name, value ){ |
92 | | - mediaWiki.config.get( name, value ); |
93 | | - }; |
94 | | - mw.setDefaultConfig = function( name, value ){ |
95 | | - if( ! mediaWiki.config.get( name ) ){ |
96 | | - mediaWiki.config.set( name, value ); |
97 | | - } |
98 | | - }; |
99 | | - mw.load = function( resources, callback ){ |
100 | | - mediaWiki.using( resources, callback, function(){ |
101 | | - // failed to load |
102 | | - }); |
103 | | - }; |
104 | | - |
105 | | - /** |
106 | | - * Merge in a configuration value: |
107 | | - */ |
108 | | - mw.mergeConfig = function( name, value ){ |
109 | | - if( typeof name == 'object' ) { |
110 | | - $j.each( name, function( inx, val) { |
111 | | - mw.mergeConfig( inx, val ); |
112 | | - }); |
113 | | - return ; |
114 | | - } |
115 | | - // Check if we should "merge" the config |
116 | | - if( typeof value == 'object' && typeof mw.getConfig( name ) == 'object' ) { |
117 | | - if ( value.constructor.toString().indexOf("Array") != -1 && |
118 | | - mw.getConfig( name ).constructor.toString().indexOf("Array") != -1 |
119 | | - ){ |
120 | | - // merge in the array |
121 | | - mw.setConfig( name, $j.merge( mw.getConfig( name ), value ) ); |
122 | | - } else { |
123 | | - mw.setConfig( name, value ); |
124 | | - } |
125 | | - return ; |
126 | | - } |
127 | | - // else do a normal setConfig |
128 | | - mw.setConfig( name, value ); |
129 | | - }; |
130 | | - |
131 | | - /** |
132 | | - * Utility Functions |
133 | | - * |
134 | | - * TOOD some of these utility functions are used in the upload Wizard, break them out into |
135 | | - * associated files. |
136 | | - */ |
137 | | - |
138 | | - /** |
139 | | - * Given a float number of seconds, returns npt format response. ( ignore |
140 | | - * days for now ) |
141 | | - * |
142 | | - * @param {Float} |
143 | | - * sec Seconds |
144 | | - * @param {Boolean} |
145 | | - * show_ms If milliseconds should be displayed. |
146 | | - * @return {Float} String npt format |
147 | | - */ |
148 | | - mw.seconds2npt = function( sec, show_ms ) { |
149 | | - if ( isNaN( sec ) ) { |
150 | | - mw.log("Warning: trying to get npt time on NaN:" + sec); |
151 | | - return '0:00:00'; |
152 | | - } |
153 | | - |
154 | | - var tm = mw.seconds2Measurements( sec ) |
155 | | - |
156 | | - // Round the number of seconds to the required number of significant |
157 | | - // digits |
158 | | - if ( show_ms ) { |
159 | | - tm.seconds = Math.round( tm.seconds * 1000 ) / 1000; |
160 | | - } else { |
161 | | - tm.seconds = Math.round( tm.seconds ); |
162 | | - } |
163 | | - if ( tm.seconds < 10 ){ |
164 | | - tm.seconds = '0' + tm.seconds; |
165 | | - } |
166 | | - if( tm.hours == 0 ){ |
167 | | - hoursStr = '' |
168 | | - } else { |
169 | | - if ( tm.minutes < 10 ) |
170 | | - tm.minutes = '0' + tm.minutes; |
171 | | - |
172 | | - hoursStr = tm.hours + ":"; |
173 | | - } |
174 | | - return hoursStr + tm.minutes + ":" + tm.seconds; |
175 | | - } |
176 | | - |
177 | | - /** |
178 | | - * Given seconds return array with 'days', 'hours', 'min', 'seconds' |
179 | | - * |
180 | | - * @param {float} |
181 | | - * sec Seconds to be converted into time measurements |
182 | | - */ |
183 | | - mw.seconds2Measurements = function ( sec ){ |
184 | | - var tm = {}; |
185 | | - tm.days = Math.floor( sec / ( 3600 * 24 ) ) |
186 | | - tm.hours = Math.floor( sec / 3600 ); |
187 | | - tm.minutes = Math.floor( ( sec / 60 ) % 60 ); |
188 | | - tm.seconds = sec % 60; |
189 | | - return tm; |
190 | | - } |
191 | | - |
192 | | - /** |
193 | | - * Take hh:mm:ss,ms or hh:mm:ss.ms input, return the number of seconds |
194 | | - * |
195 | | - * @param {String} |
196 | | - * npt_str NPT time string |
197 | | - * @return {Float} Number of seconds |
198 | | - */ |
199 | | - mw.npt2seconds = function ( npt_str ) { |
200 | | - if ( !npt_str ) { |
201 | | - // mw.log('npt2seconds:not valid ntp:'+ntp); |
202 | | - return 0; |
203 | | - } |
204 | | - // Strip {npt:}01:02:20 or 32{s} from time if present |
205 | | - npt_str = npt_str.replace( /npt:|s/g, '' ); |
206 | | - |
207 | | - var hour = 0; |
208 | | - var min = 0; |
209 | | - var sec = 0; |
210 | | - |
211 | | - times = npt_str.split( ':' ); |
212 | | - if ( times.length == 3 ) { |
213 | | - sec = times[2]; |
214 | | - min = times[1]; |
215 | | - hour = times[0]; |
216 | | - } else if ( times.length == 2 ) { |
217 | | - sec = times[1]; |
218 | | - min = times[0]; |
219 | | - } else { |
220 | | - sec = times[0]; |
221 | | - } |
222 | | - // Sometimes a comma is used instead of period for ms |
223 | | - sec = sec.replace( /,\s?/, '.' ); |
224 | | - // Return seconds float |
225 | | - return parseInt( hour * 3600 ) + parseInt( min * 60 ) + parseFloat( sec ); |
226 | | - } |
227 | | - |
228 | | - /** |
229 | | - * addLoaderDialog small helper for displaying a loading dialog |
230 | | - * |
231 | | - * @param {String} |
232 | | - * dialogHtml text Html of the loader msg |
233 | | - */ |
234 | | - mw.addLoaderDialog = function( dialogHtml ) { |
235 | | - $dialog = mw.addDialog( { |
236 | | - 'title' : dialogHtml, |
237 | | - 'content' : dialogHtml + '<br>' + |
238 | | - $j('<div />') |
239 | | - .loadingSpinner() |
240 | | - .html() |
241 | | - }); |
242 | | - return $dialog; |
243 | | - } |
244 | | - |
245 | | - |
246 | | - |
247 | | - /** |
248 | | - * Add a (temporary) dialog window: |
249 | | - * |
250 | | - * @param {Object} with following keys: |
251 | | - * title: {String} Title string for the dialog |
252 | | - * content: {String} to be inserted in msg box |
253 | | - * buttons: {Object} A button object for the dialog Can be a string |
254 | | - * for the close button |
255 | | - * any jquery.ui.dialog option |
256 | | - */ |
257 | | - mw.addDialog = function ( options ) { |
258 | | - // Remove any other dialog |
259 | | - $j( '#mwTempLoaderDialog' ).remove(); |
260 | | - |
261 | | - if( !options){ |
262 | | - options = {}; |
263 | | - } |
264 | | - |
265 | | - // Extend the default options with provided options |
266 | | - var options = $j.extend({ |
267 | | - 'bgiframe': true, |
268 | | - 'draggable': true, |
269 | | - 'resizable': false, |
270 | | - 'modal': true |
271 | | - }, options ); |
272 | | - |
273 | | - if( ! options.title || ! options.content ){ |
274 | | - mw.log("Error: mwEmbed addDialog missing required options ( title, content ) ") |
275 | | - return ; |
276 | | - } |
277 | | - |
278 | | - // Append the dialog div on top: |
279 | | - $j( 'body' ).append( |
280 | | - $j('<div />') |
281 | | - .attr( { |
282 | | - 'id' : "mwTempLoaderDialog", |
283 | | - 'title' : options.title |
284 | | - }) |
285 | | - .css({ |
286 | | - 'display': 'none' |
287 | | - }) |
288 | | - .append( options.content ) |
289 | | - ); |
290 | | - |
291 | | - // Build the uiRequest |
292 | | - var uiRequest = [ '$j.ui.dialog' ]; |
293 | | - if( options.draggable ){ |
294 | | - uiRequest.push( '$j.ui.draggable' ) |
295 | | - } |
296 | | - if( options.resizable ){ |
297 | | - uiRequest.push( '$j.ui.resizable' ); |
298 | | - } |
299 | | - |
300 | | - // Special button string |
301 | | - if ( typeof options.buttons == 'string' ) { |
302 | | - var buttonMsg = options.buttons; |
303 | | - buttons = { }; |
304 | | - options.buttons[ buttonMsg ] = function() { |
305 | | - $j( this ).dialog( 'close' ); |
306 | | - } |
307 | | - } |
308 | | - |
309 | | - // Load the dialog resources |
310 | | - mw.load([ |
311 | | - [ |
312 | | - '$j.ui' |
313 | | - ], |
314 | | - uiRequest |
315 | | - ], function() { |
316 | | - $j( '#mwTempLoaderDialog' ).dialog( options ); |
317 | | - } ); |
318 | | - return $j( '#mwTempLoaderDialog' ); |
319 | | - } |
320 | | - |
321 | | - /** |
322 | | - * Close the loader dialog created with addLoaderDialog |
323 | | - */ |
324 | | - mw.closeLoaderDialog = function() { |
325 | | - $j( '#mwTempLoaderDialog' ).dialog( 'destroy' ).remove(); |
326 | | - }; |
327 | | - |
328 | | - // MOVE TO jquery.client |
329 | | - // move to jquery.client |
330 | | - mw.isIphone = function(){ |
331 | | - return ( navigator.userAgent.indexOf('iPhone') != -1 && ! mw.isIpad() ); |
332 | | - }; |
333 | | - // Uses hack described at: |
334 | | - // http://www.bdoran.co.uk/2010/07/19/detecting-the-iphone4-and-resolution-with-javascript-or-php/ |
335 | | - mw.isIphone4 = function(){ |
336 | | - return ( mw.isIphone() && ( window.devicePixelRatio && window.devicePixelRatio >= 2 ) ); |
337 | | - }; |
338 | | - mw.isIpod = function(){ |
339 | | - return ( navigator.userAgent.indexOf('iPod') != -1 ); |
340 | | - }; |
341 | | - mw.isIpad = function(){ |
342 | | - return ( navigator.userAgent.indexOf('iPad') != -1 ); |
343 | | - }; |
344 | | - // Android 2 has some restrictions vs other mobile platforms |
345 | | - mw.isAndroid2 = function(){ |
346 | | - return ( navigator.userAgent.indexOf( 'Android 2.') != -1 ); |
347 | | - }; |
348 | | - |
349 | | - /** |
350 | | - * Fallforward system by default prefers flash. |
351 | | - * |
352 | | - * This is separate from the EmbedPlayer library detection to provide |
353 | | - * package loading control NOTE: should be phased out in favor of browser |
354 | | - * feature detection where possible |
355 | | - * |
356 | | - */ |
357 | | - mw.isHTML5FallForwardNative = function(){ |
358 | | - if( mw.isMobileHTML5() ){ |
359 | | - return true; |
360 | | - } |
361 | | - // Check for url flag to force html5: |
362 | | - if( document.URL.indexOf('forceMobileHTML5') != -1 ){ |
363 | | - return true; |
364 | | - } |
365 | | - // Fall forward native: |
366 | | - // if the browser supports flash ( don't use html5 ) |
367 | | - if( mw.supportsFlash() ){ |
368 | | - return false; |
369 | | - } |
370 | | - // No flash return true if the browser supports html5 video tag with |
371 | | - // basic support for canPlayType: |
372 | | - if( mw.supportsHTML5() ){ |
373 | | - return true; |
374 | | - } |
375 | | - |
376 | | - return false; |
377 | | - } |
378 | | - |
379 | | - mw.isMobileHTML5 = function(){ |
380 | | - // Check for a mobile html5 user agent: |
381 | | - if ( mw.isIphone() || |
382 | | - mw.isIpod() || |
383 | | - mw.isIpad() || |
384 | | - mw.isAndroid2() |
385 | | - ){ |
386 | | - return true; |
387 | | - } |
388 | | - return false; |
389 | | - }; |
390 | | - mw.supportsHTML5 = function(){ |
391 | | - // Blackberry is evil in its response to canPlayType calls. |
392 | | - if( navigator.userAgent.indexOf('BlackBerry') != -1 ){ |
393 | | - return false ; |
394 | | - } |
395 | | - var dummyvid = document.createElement( "video" ); |
396 | | - if( dummyvid.canPlayType ) { |
397 | | - return true; |
398 | | - } |
399 | | - return false; |
400 | | - } |
401 | | - |
402 | | - mw.supportsFlash = function(){ |
403 | | - // Check if the client does not have flash and has the video tag |
404 | | - if ( navigator.mimeTypes && navigator.mimeTypes.length > 0 ) { |
405 | | - for ( var i = 0; i < navigator.mimeTypes.length; i++ ) { |
406 | | - var type = navigator.mimeTypes[i].type; |
407 | | - var semicolonPos = type.indexOf( ';' ); |
408 | | - if ( semicolonPos > -1 ) { |
409 | | - type = type.substr( 0, semicolonPos ); |
410 | | - } |
411 | | - if (type == 'application/x-shockwave-flash' ) { |
412 | | - // flash is installed |
413 | | - return true; |
414 | | - } |
415 | | - } |
416 | | - } |
417 | | - |
418 | | - // for IE: |
419 | | - var hasObj = true; |
420 | | - if( typeof ActiveXObject != 'undefined' ){ |
421 | | - try { |
422 | | - var obj = new ActiveXObject( 'ShockwaveFlash.ShockwaveFlash' ); |
423 | | - } catch ( e ) { |
424 | | - hasObj = false; |
425 | | - } |
426 | | - if( hasObj ){ |
427 | | - return true; |
428 | | - } |
429 | | - } |
430 | | - return false; |
431 | | - }; |
432 | | - |
433 | | - |
434 | | -} )( mediaWiki, jQuery ); |
\ No newline at end of file |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/modules/MwEmbedSupport/MwEmbedSupport.php |
— | — | @@ -1,7 +1,21 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | return array( |
5 | | - |
| 5 | + "mwEmbedSupport" => array( |
| 6 | + 'scripts' => array( |
| 7 | + "mwEmbedSupport.js", |
| 8 | + ), |
| 9 | + 'dependencies' => array( |
| 10 | + // jQuery dependencies: |
| 11 | + 'jquery.triggerQueueCallback', |
| 12 | + ), |
| 13 | + 'messageFile' => 'MwEmbedSupport.i18n.php', |
| 14 | + ), |
| 15 | + 'jquery.menu' => array( |
| 16 | + 'scripts' => 'jquery.menu/jquery.menu.js', |
| 17 | + 'styles' => 'jquery.menu/jquery.menu.css' |
| 18 | + ), |
| 19 | + "jquery.triggerQueueCallback" => array( 'scripts'=> "jquery/jquery.triggerQueueCallback.js" ), |
6 | 20 | ) |
7 | 21 | |
8 | 22 | ?> |
Index: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/modules/MwEmbedSupport/mwEmbedSupport.js |
— | — | @@ -0,0 +1,432 @@ |
| 2 | +// Add support for html5 / mwEmbed elements to IE |
| 3 | +// For discussion and comments, see: http://remysharp.com/2009/01/07/html5-enabling-script/ |
| 4 | +'video audio source track'.replace(/\w+/g,function( n ){ document.createElement( n ) } ); |
| 5 | + |
| 6 | +/** |
| 7 | + * mwEmbedSupport includes shared mwEmbed utilities that either |
| 8 | + * wrap core mediawiki functionality or support legacy mwEmbed module code |
| 9 | + * |
| 10 | + * @license |
| 11 | + * mwEmbed |
| 12 | + * Dual licensed under the MIT or GPL Version 2 licenses. |
| 13 | + * |
| 14 | + * @copyright (C) 2010 Kaltura |
| 15 | + * @author Michael Dale ( michael.dale at kaltura.com ) |
| 16 | + * |
| 17 | + * @url http://www.kaltura.org/project/HTML5_Video_Media_JavaScript_Library |
| 18 | + * |
| 19 | + * Libraries used include code license in headers |
| 20 | + * |
| 21 | + * @dependency |
| 22 | + */ |
| 23 | +alert('wtf'); |
| 24 | + |
| 25 | +( function( mw, $ ) { |
| 26 | + |
| 27 | + /** |
| 28 | + * Set the mwEmbedVersion |
| 29 | + */ |
| 30 | + window.MW_EMBED_VERSION = '1.1g'; |
| 31 | + |
| 32 | + // Globals to pre-set ready functions in dynamic loading of mwEmbed |
| 33 | + if( typeof window.preMwEmbedReady == 'undefined'){ |
| 34 | + window.preMwEmbedReady = []; |
| 35 | + } |
| 36 | + // Globals to pre-set config values in dynamic loading of mwEmbed |
| 37 | + if( typeof window.preMwEmbedConfig == 'undefined') { |
| 38 | + window.preMwEmbedConfig = []; |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * Enables javascript to target a "interfaces ready" state. |
| 43 | + * |
| 44 | + * mw.ready is equivalent to calling: |
| 45 | + * $j(mw).bind( 'InterfacesReady', callback ); |
| 46 | + * |
| 47 | + * This is different from jQuery(document).ready() ( jQuery ready is not |
| 48 | + * friendly with dynamic includes and not friendly with core interface |
| 49 | + * asynchronous build out. ) This allows an interface to do async calls and be globally ready |
| 50 | + * |
| 51 | + * For example making <video> tags on the page have a video api even if the browser |
| 52 | + * does not support html5. |
| 53 | + * |
| 54 | + * @param {Function} |
| 55 | + * callback Function to run once DOM and jQuery are ready |
| 56 | + */ |
| 57 | + mw.ready = function( callback ) { |
| 58 | + if( mw.interfacesReadyFlag === false ) { |
| 59 | + // Add the callbcak to the onLoad function stack |
| 60 | + $j( mw ).bind( 'InterfacesReady', callback ); |
| 61 | + } else { |
| 62 | + // If mwReadyFlag is already "true" issue the callback directly: |
| 63 | + callback(); |
| 64 | + } |
| 65 | + }; |
| 66 | + |
| 67 | + // mw.interfacesReadyFlag ( set to true once interfaces are ready ) |
| 68 | + mw.interfacesReadyFlag = false; |
| 69 | + |
| 70 | + // Once interfaces are ready update the mwReadyFlag |
| 71 | + $j( mw ).bind('InterfacesReady', function(){ mw.interfacesReadyFlag = true } ); |
| 72 | + |
| 73 | + // Once the DOM is ready start setting up interfaces |
| 74 | + $j( document ).ready(function(){ |
| 75 | + $j( mw ).triggerQueueCallback('SetupInterface', function(){ |
| 76 | + // All interfaces have been setup trigger InterfacesReady event |
| 77 | + $j( mw ).trigger( 'InterfacesReady' ); |
| 78 | + }); |
| 79 | + }); |
| 80 | + |
| 81 | + |
| 82 | + /** |
| 83 | + * Aliased functions |
| 84 | + * |
| 85 | + * Wrap mediaWiki functionality while we port over the libraries |
| 86 | + */ |
| 87 | + mw.setConfig = function( name, value ){ |
| 88 | + mediaWiki.config.set( name, value ); |
| 89 | + }; |
| 90 | + mw.getConfig = function( name, value ){ |
| 91 | + mediaWiki.config.get( name, value ); |
| 92 | + }; |
| 93 | + mw.setDefaultConfig = function( name, value ){ |
| 94 | + if( ! mediaWiki.config.get( name ) ){ |
| 95 | + mediaWiki.config.set( name, value ); |
| 96 | + } |
| 97 | + }; |
| 98 | + mw.load = function( resources, callback ){ |
| 99 | + mediaWiki.using( resources, callback, function(){ |
| 100 | + // failed to load |
| 101 | + }); |
| 102 | + }; |
| 103 | + |
| 104 | + /** |
| 105 | + * Merge in a configuration value: |
| 106 | + */ |
| 107 | + mw.mergeConfig = function( name, value ){ |
| 108 | + if( typeof name == 'object' ) { |
| 109 | + $j.each( name, function( inx, val) { |
| 110 | + mw.mergeConfig( inx, val ); |
| 111 | + }); |
| 112 | + return ; |
| 113 | + } |
| 114 | + // Check if we should "merge" the config |
| 115 | + if( typeof value == 'object' && typeof mw.getConfig( name ) == 'object' ) { |
| 116 | + if ( value.constructor.toString().indexOf("Array") != -1 && |
| 117 | + mw.getConfig( name ).constructor.toString().indexOf("Array") != -1 |
| 118 | + ){ |
| 119 | + // merge in the array |
| 120 | + mw.setConfig( name, $j.merge( mw.getConfig( name ), value ) ); |
| 121 | + } else { |
| 122 | + mw.setConfig( name, value ); |
| 123 | + } |
| 124 | + return ; |
| 125 | + } |
| 126 | + // else do a normal setConfig |
| 127 | + mw.setConfig( name, value ); |
| 128 | + }; |
| 129 | + |
| 130 | + /** |
| 131 | + * Utility Functions |
| 132 | + * |
| 133 | + * TOOD some of these utility functions are used in the upload Wizard, break them out into |
| 134 | + * associated files. |
| 135 | + */ |
| 136 | + |
| 137 | + /** |
| 138 | + * Given a float number of seconds, returns npt format response. ( ignore |
| 139 | + * days for now ) |
| 140 | + * |
| 141 | + * @param {Float} |
| 142 | + * sec Seconds |
| 143 | + * @param {Boolean} |
| 144 | + * show_ms If milliseconds should be displayed. |
| 145 | + * @return {Float} String npt format |
| 146 | + */ |
| 147 | + mw.seconds2npt = function( sec, show_ms ) { |
| 148 | + if ( isNaN( sec ) ) { |
| 149 | + mw.log("Warning: trying to get npt time on NaN:" + sec); |
| 150 | + return '0:00:00'; |
| 151 | + } |
| 152 | + |
| 153 | + var tm = mw.seconds2Measurements( sec ) |
| 154 | + |
| 155 | + // Round the number of seconds to the required number of significant |
| 156 | + // digits |
| 157 | + if ( show_ms ) { |
| 158 | + tm.seconds = Math.round( tm.seconds * 1000 ) / 1000; |
| 159 | + } else { |
| 160 | + tm.seconds = Math.round( tm.seconds ); |
| 161 | + } |
| 162 | + if ( tm.seconds < 10 ){ |
| 163 | + tm.seconds = '0' + tm.seconds; |
| 164 | + } |
| 165 | + if( tm.hours == 0 ){ |
| 166 | + hoursStr = '' |
| 167 | + } else { |
| 168 | + if ( tm.minutes < 10 ) |
| 169 | + tm.minutes = '0' + tm.minutes; |
| 170 | + |
| 171 | + hoursStr = tm.hours + ":"; |
| 172 | + } |
| 173 | + return hoursStr + tm.minutes + ":" + tm.seconds; |
| 174 | + } |
| 175 | + |
| 176 | + /** |
| 177 | + * Given seconds return array with 'days', 'hours', 'min', 'seconds' |
| 178 | + * |
| 179 | + * @param {float} |
| 180 | + * sec Seconds to be converted into time measurements |
| 181 | + */ |
| 182 | + mw.seconds2Measurements = function ( sec ){ |
| 183 | + var tm = {}; |
| 184 | + tm.days = Math.floor( sec / ( 3600 * 24 ) ) |
| 185 | + tm.hours = Math.floor( sec / 3600 ); |
| 186 | + tm.minutes = Math.floor( ( sec / 60 ) % 60 ); |
| 187 | + tm.seconds = sec % 60; |
| 188 | + return tm; |
| 189 | + } |
| 190 | + |
| 191 | + /** |
| 192 | + * Take hh:mm:ss,ms or hh:mm:ss.ms input, return the number of seconds |
| 193 | + * |
| 194 | + * @param {String} |
| 195 | + * npt_str NPT time string |
| 196 | + * @return {Float} Number of seconds |
| 197 | + */ |
| 198 | + mw.npt2seconds = function ( npt_str ) { |
| 199 | + if ( !npt_str ) { |
| 200 | + // mw.log('npt2seconds:not valid ntp:'+ntp); |
| 201 | + return 0; |
| 202 | + } |
| 203 | + // Strip {npt:}01:02:20 or 32{s} from time if present |
| 204 | + npt_str = npt_str.replace( /npt:|s/g, '' ); |
| 205 | + |
| 206 | + var hour = 0; |
| 207 | + var min = 0; |
| 208 | + var sec = 0; |
| 209 | + |
| 210 | + times = npt_str.split( ':' ); |
| 211 | + if ( times.length == 3 ) { |
| 212 | + sec = times[2]; |
| 213 | + min = times[1]; |
| 214 | + hour = times[0]; |
| 215 | + } else if ( times.length == 2 ) { |
| 216 | + sec = times[1]; |
| 217 | + min = times[0]; |
| 218 | + } else { |
| 219 | + sec = times[0]; |
| 220 | + } |
| 221 | + // Sometimes a comma is used instead of period for ms |
| 222 | + sec = sec.replace( /,\s?/, '.' ); |
| 223 | + // Return seconds float |
| 224 | + return parseInt( hour * 3600 ) + parseInt( min * 60 ) + parseFloat( sec ); |
| 225 | + } |
| 226 | + |
| 227 | + /** |
| 228 | + * addLoaderDialog small helper for displaying a loading dialog |
| 229 | + * |
| 230 | + * @param {String} |
| 231 | + * dialogHtml text Html of the loader msg |
| 232 | + */ |
| 233 | + mw.addLoaderDialog = function( dialogHtml ) { |
| 234 | + $dialog = mw.addDialog( { |
| 235 | + 'title' : dialogHtml, |
| 236 | + 'content' : dialogHtml + '<br>' + |
| 237 | + $j('<div />') |
| 238 | + .loadingSpinner() |
| 239 | + .html() |
| 240 | + }); |
| 241 | + return $dialog; |
| 242 | + } |
| 243 | + |
| 244 | + |
| 245 | + |
| 246 | + /** |
| 247 | + * Add a (temporary) dialog window: |
| 248 | + * |
| 249 | + * @param {Object} with following keys: |
| 250 | + * title: {String} Title string for the dialog |
| 251 | + * content: {String} to be inserted in msg box |
| 252 | + * buttons: {Object} A button object for the dialog Can be a string |
| 253 | + * for the close button |
| 254 | + * any jquery.ui.dialog option |
| 255 | + */ |
| 256 | + mw.addDialog = function ( options ) { |
| 257 | + // Remove any other dialog |
| 258 | + $j( '#mwTempLoaderDialog' ).remove(); |
| 259 | + |
| 260 | + if( !options){ |
| 261 | + options = {}; |
| 262 | + } |
| 263 | + |
| 264 | + // Extend the default options with provided options |
| 265 | + var options = $j.extend({ |
| 266 | + 'bgiframe': true, |
| 267 | + 'draggable': true, |
| 268 | + 'resizable': false, |
| 269 | + 'modal': true |
| 270 | + }, options ); |
| 271 | + |
| 272 | + if( ! options.title || ! options.content ){ |
| 273 | + mw.log("Error: mwEmbed addDialog missing required options ( title, content ) ") |
| 274 | + return ; |
| 275 | + } |
| 276 | + |
| 277 | + // Append the dialog div on top: |
| 278 | + $j( 'body' ).append( |
| 279 | + $j('<div />') |
| 280 | + .attr( { |
| 281 | + 'id' : "mwTempLoaderDialog", |
| 282 | + 'title' : options.title |
| 283 | + }) |
| 284 | + .css({ |
| 285 | + 'display': 'none' |
| 286 | + }) |
| 287 | + .append( options.content ) |
| 288 | + ); |
| 289 | + |
| 290 | + // Build the uiRequest |
| 291 | + var uiRequest = [ '$j.ui.dialog' ]; |
| 292 | + if( options.draggable ){ |
| 293 | + uiRequest.push( '$j.ui.draggable' ) |
| 294 | + } |
| 295 | + if( options.resizable ){ |
| 296 | + uiRequest.push( '$j.ui.resizable' ); |
| 297 | + } |
| 298 | + |
| 299 | + // Special button string |
| 300 | + if ( typeof options.buttons == 'string' ) { |
| 301 | + var buttonMsg = options.buttons; |
| 302 | + buttons = { }; |
| 303 | + options.buttons[ buttonMsg ] = function() { |
| 304 | + $j( this ).dialog( 'close' ); |
| 305 | + } |
| 306 | + } |
| 307 | + |
| 308 | + // Load the dialog resources |
| 309 | + mw.load([ |
| 310 | + [ |
| 311 | + '$j.ui' |
| 312 | + ], |
| 313 | + uiRequest |
| 314 | + ], function() { |
| 315 | + $j( '#mwTempLoaderDialog' ).dialog( options ); |
| 316 | + } ); |
| 317 | + return $j( '#mwTempLoaderDialog' ); |
| 318 | + } |
| 319 | + |
| 320 | + /** |
| 321 | + * Close the loader dialog created with addLoaderDialog |
| 322 | + */ |
| 323 | + mw.closeLoaderDialog = function() { |
| 324 | + $j( '#mwTempLoaderDialog' ).dialog( 'destroy' ).remove(); |
| 325 | + }; |
| 326 | + |
| 327 | + // MOVE TO jquery.client |
| 328 | + // move to jquery.client |
| 329 | + mw.isIphone = function(){ |
| 330 | + return ( navigator.userAgent.indexOf('iPhone') != -1 && ! mw.isIpad() ); |
| 331 | + }; |
| 332 | + // Uses hack described at: |
| 333 | + // http://www.bdoran.co.uk/2010/07/19/detecting-the-iphone4-and-resolution-with-javascript-or-php/ |
| 334 | + mw.isIphone4 = function(){ |
| 335 | + return ( mw.isIphone() && ( window.devicePixelRatio && window.devicePixelRatio >= 2 ) ); |
| 336 | + }; |
| 337 | + mw.isIpod = function(){ |
| 338 | + return ( navigator.userAgent.indexOf('iPod') != -1 ); |
| 339 | + }; |
| 340 | + mw.isIpad = function(){ |
| 341 | + return ( navigator.userAgent.indexOf('iPad') != -1 ); |
| 342 | + }; |
| 343 | + // Android 2 has some restrictions vs other mobile platforms |
| 344 | + mw.isAndroid2 = function(){ |
| 345 | + return ( navigator.userAgent.indexOf( 'Android 2.') != -1 ); |
| 346 | + }; |
| 347 | + |
| 348 | + /** |
| 349 | + * Fallforward system by default prefers flash. |
| 350 | + * |
| 351 | + * This is separate from the EmbedPlayer library detection to provide |
| 352 | + * package loading control NOTE: should be phased out in favor of browser |
| 353 | + * feature detection where possible |
| 354 | + * |
| 355 | + */ |
| 356 | + mw.isHTML5FallForwardNative = function(){ |
| 357 | + if( mw.isMobileHTML5() ){ |
| 358 | + return true; |
| 359 | + } |
| 360 | + // Check for url flag to force html5: |
| 361 | + if( document.URL.indexOf('forceMobileHTML5') != -1 ){ |
| 362 | + return true; |
| 363 | + } |
| 364 | + // Fall forward native: |
| 365 | + // if the browser supports flash ( don't use html5 ) |
| 366 | + if( mw.supportsFlash() ){ |
| 367 | + return false; |
| 368 | + } |
| 369 | + // No flash return true if the browser supports html5 video tag with |
| 370 | + // basic support for canPlayType: |
| 371 | + if( mw.supportsHTML5() ){ |
| 372 | + return true; |
| 373 | + } |
| 374 | + |
| 375 | + return false; |
| 376 | + } |
| 377 | + |
| 378 | + mw.isMobileHTML5 = function(){ |
| 379 | + // Check for a mobile html5 user agent: |
| 380 | + if ( mw.isIphone() || |
| 381 | + mw.isIpod() || |
| 382 | + mw.isIpad() || |
| 383 | + mw.isAndroid2() |
| 384 | + ){ |
| 385 | + return true; |
| 386 | + } |
| 387 | + return false; |
| 388 | + }; |
| 389 | + mw.supportsHTML5 = function(){ |
| 390 | + // Blackberry is evil in its response to canPlayType calls. |
| 391 | + if( navigator.userAgent.indexOf('BlackBerry') != -1 ){ |
| 392 | + return false ; |
| 393 | + } |
| 394 | + var dummyvid = document.createElement( "video" ); |
| 395 | + if( dummyvid.canPlayType ) { |
| 396 | + return true; |
| 397 | + } |
| 398 | + return false; |
| 399 | + } |
| 400 | + |
| 401 | + mw.supportsFlash = function(){ |
| 402 | + // Check if the client does not have flash and has the video tag |
| 403 | + if ( navigator.mimeTypes && navigator.mimeTypes.length > 0 ) { |
| 404 | + for ( var i = 0; i < navigator.mimeTypes.length; i++ ) { |
| 405 | + var type = navigator.mimeTypes[i].type; |
| 406 | + var semicolonPos = type.indexOf( ';' ); |
| 407 | + if ( semicolonPos > -1 ) { |
| 408 | + type = type.substr( 0, semicolonPos ); |
| 409 | + } |
| 410 | + if (type == 'application/x-shockwave-flash' ) { |
| 411 | + // flash is installed |
| 412 | + return true; |
| 413 | + } |
| 414 | + } |
| 415 | + } |
| 416 | + |
| 417 | + // for IE: |
| 418 | + var hasObj = true; |
| 419 | + if( typeof ActiveXObject != 'undefined' ){ |
| 420 | + try { |
| 421 | + var obj = new ActiveXObject( 'ShockwaveFlash.ShockwaveFlash' ); |
| 422 | + } catch ( e ) { |
| 423 | + hasObj = false; |
| 424 | + } |
| 425 | + if( hasObj ){ |
| 426 | + return true; |
| 427 | + } |
| 428 | + } |
| 429 | + return false; |
| 430 | + }; |
| 431 | + |
| 432 | + |
| 433 | +} )( mediaWiki, jQuery ); |
\ No newline at end of file |
Property changes on: branches/MwEmbedStandAloneRL1_17/MwEmbedStandAlone/modules/MwEmbedSupport/mwEmbedSupport.js |
___________________________________________________________________ |
Added: svn:mime-type |
1 | 434 | + text/plain |