Index: trunk/extensions/MwEmbedSupport/MwEmbedModules/MwEmbedSupport/mwEmbedSupport.js |
— | — | @@ -1,428 +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 | | - * 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 | | - * @dependencies |
22 | | - */ |
23 | | - |
24 | | -( function( mw, $ ) { |
25 | | - |
26 | | - /** |
27 | | - * Set the mwEmbedVersion |
28 | | - */ |
29 | | - window.MW_EMBED_VERSION = '1.1g'; |
30 | | - |
31 | | - // Globals to pre-set ready functions in dynamic loading of mwEmbed |
32 | | - if( typeof window.preMwEmbedReady == 'undefined'){ |
33 | | - window.preMwEmbedReady = []; |
34 | | - } |
35 | | - // Globals to pre-set config values in dynamic loading of mwEmbed |
36 | | - if( typeof window.preMwEmbedConfig == 'undefined') { |
37 | | - window.preMwEmbedConfig = []; |
38 | | - } |
39 | | - |
40 | | - /** |
41 | | - * Enables javascript modules and pages to target a "interfaces ready" state. |
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. ) This allows core interface components to do async conditional |
46 | | - * load calls, and trigger a ready event once the javascript interface build out is complete |
47 | | - * |
48 | | - * For example making <video> tags on the page have a video api even if the browser |
49 | | - * does not support html5 requires dynamic loading that can only happen once the page dom is |
50 | | - * ready |
51 | | - * |
52 | | - * @param {Function} |
53 | | - * callback Function to run once DOM and jQuery are ready |
54 | | - */ |
55 | | - // mw.interfacesReadyFlag ( set to true once interfaces are ready ) |
56 | | - mw.interfacesReadyFlag = false; |
57 | | - |
58 | | - mw.ready = function( callback ) { |
59 | | - if( mw.interfacesReadyFlag === false ) { |
60 | | - // Add the callbcak to the onLoad function stack |
61 | | - $( mw ).bind( 'InterfacesReady', callback ); |
62 | | - } else { |
63 | | - // If mwReadyFlag is already "true" issue the callback directly: |
64 | | - callback(); |
65 | | - } |
66 | | - }; |
67 | | - // Once interfaces are ready update the mwReadyFlag |
68 | | - $( mw ).bind('InterfacesReady', function(){ mw.interfacesReadyFlag = true; } ); |
69 | | - |
70 | | - // Once the DOM is ready start setting up interfaces |
71 | | - $( document ).ready(function(){ |
72 | | - $( mw ).triggerQueueCallback('SetupInterface', function(){ |
73 | | - // All interfaces have been setup trigger InterfacesReady event |
74 | | - $( mw ).trigger( 'InterfacesReady' ); |
75 | | - }); |
76 | | - }); |
77 | | - |
78 | | - |
79 | | - /** |
80 | | - * Aliased functions |
81 | | - * |
82 | | - * Wrap mediaWiki functionality while we port over the libraries |
83 | | - */ |
84 | | - mw.setConfig = function( name, value ){ |
85 | | - mediaWiki.config.set( name, value ); |
86 | | - }; |
87 | | - mw.getConfig = function( name, value ){ |
88 | | - return mediaWiki.config.get( name, value ); |
89 | | - }; |
90 | | - mw.setDefaultConfig = function( name, value ){ |
91 | | - if( mediaWiki.config.get( name ) === null ){ |
92 | | - mediaWiki.config.set( name, value ); |
93 | | - } |
94 | | - }; |
95 | | - /** |
96 | | - * Aliased load function |
97 | | - */ |
98 | | - mw.load = function( resources, callback ){ |
99 | | - mediaWiki.loader.using( resources, callback, function(){ |
100 | | - // failed to load |
101 | | - mw.log("Failed to load resources:" + resources ); |
102 | | - }); |
103 | | - }; |
104 | | - |
105 | | - /** |
106 | | - * legacy support to get the mwEmbed resource path: |
107 | | - */ |
108 | | - mw.getMwEmbedPath = function(){ |
109 | | - if ( mediaWiki.config.get( 'wgLoadScript' ) ){ |
110 | | - return mediaWiki.config.get( 'wgLoadScript' ).replace('load.php', ''); |
111 | | - } |
112 | | - return false; |
113 | | - }; |
114 | | - |
115 | | - /** |
116 | | - * Merge in a configuration value: |
117 | | - */ |
118 | | - mw.mergeConfig = function( name, value ){ |
119 | | - if( typeof name == 'object' ) { |
120 | | - $j.each( name, function( inx, val) { |
121 | | - mw.mergeConfig( inx, val ); |
122 | | - }); |
123 | | - return ; |
124 | | - } |
125 | | - var existingValue = mediaWiki.config.get( name ); |
126 | | - if( !existingValue || typeof existingValue == 'string'){ |
127 | | - mw.setConfig( name, value ); |
128 | | - return ; |
129 | | - } |
130 | | - if( typeof mediaWiki.config.get( name ) == 'object' ){ |
131 | | - if( $.isArray( existingValue) && $.isArray( value ) ){ |
132 | | - for( var i =0; i < value.length ; i ++ ){ |
133 | | - existingValue.push( value[i] ); |
134 | | - } |
135 | | - mw.setConfig( name, $.unique( existingValue ) ); |
136 | | - } else { |
137 | | - mw.setConfig( name, $.extend( {}, existingValue, value) ); |
138 | | - } |
139 | | - return ; |
140 | | - } |
141 | | - }; |
142 | | - |
143 | | - /** |
144 | | - * Check if an object is empty or if its an empty string. |
145 | | - * |
146 | | - * @param {Object} object Object to be checked |
147 | | - * @return {Boolean} |
148 | | - */ |
149 | | - mw.isEmpty = function( obj ) { |
150 | | - if( typeof obj === 'string' ) { |
151 | | - if( obj === '' ) return true; |
152 | | - // Non empty string: |
153 | | - return false; |
154 | | - } |
155 | | - |
156 | | - // If an array check length: |
157 | | - if( Object.prototype.toString.call( obj ) === "[object Array]" |
158 | | - && obj.length === 0 ) { |
159 | | - return true; |
160 | | - } |
161 | | - |
162 | | - // Else check as an obj: |
163 | | - for( var i in obj ) { return false; } |
164 | | - |
165 | | - // Else obj is empty: |
166 | | - return true; |
167 | | - }; |
168 | | - |
169 | | - /** |
170 | | - * Opposite of mw.isEmpty |
171 | | - * |
172 | | - * @param {Object} object Object to be checked |
173 | | - * @return {Boolean} |
174 | | - */ |
175 | | - mw.isFull = function( obj ) { |
176 | | - return ! mw.isEmpty( obj ); |
177 | | - }; |
178 | | - |
179 | | - /** |
180 | | - * Check if something is defined |
181 | | - * (inlineable?) |
182 | | - * @param {Object} |
183 | | - * @return boolean |
184 | | - */ |
185 | | - mw.isDefined = function( obj ) { |
186 | | - return typeof obj !== 'undefined'; |
187 | | - }; |
188 | | - |
189 | | - |
190 | | - /** |
191 | | - * Upper-case the first letter of a string. |
192 | | - * @param string |
193 | | - * @return string with first letter uppercased. |
194 | | - */ |
195 | | - mw.ucfirst = function( s ) { |
196 | | - return s.substring(0,1).toUpperCase() + s.substr(1); |
197 | | - }; |
198 | | - |
199 | | - /** |
200 | | - * gM ( get Message ) in js2 conflated jQuery return type with string return type |
201 | | - * Do a legacy check for input parameters and call the correct function. |
202 | | - * |
203 | | - * TODO Replace with new Neil's new parser functions |
204 | | - */ |
205 | | - window.gM = function( key, args ){ |
206 | | - var paramaters = []; |
207 | | - if( $.isArray( args ) ){ |
208 | | - paramaters = args; |
209 | | - } else { |
210 | | - paramaters = $.makeArray( arguments ).slice(1); |
211 | | - } |
212 | | - |
213 | | - var needsSpecialSwap = function( o ) { |
214 | | - return ( typeof o === 'function' || o instanceof jQuery ); |
215 | | - }; |
216 | | - |
217 | | - var getSwapId = function( index ) { |
218 | | - return 'mw_message_swap_index_' + key + '_' + index; |
219 | | - }; |
220 | | - |
221 | | - var doSpecialSwap = false; |
222 | | - |
223 | | - var text = mediaWiki.messages.get( key ); |
224 | | - if( !text){ |
225 | | - return '<' + key + '>'; |
226 | | - } |
227 | | - |
228 | | - // replace links: |
229 | | - text = text.replace( /\[(\S+)\s+([^\]]*)\]/g, function( matched, link, linkText ) { |
230 | | - var indexIdAttribute = ''; |
231 | | - // Check if the link is a swap index or just a string |
232 | | - if( link[0] == '$' ){ |
233 | | - var index = parseInt( link.replace(/\$/,''), 10 ) - 1; |
234 | | - // If the parameter is a text string directly replace it |
235 | | - if( typeof paramaters[ index ] == 'string' ){ |
236 | | - link = paramaters[ index ]; |
237 | | - } else if ( needsSpecialSwap( paramaters[ index ] ) ) { |
238 | | - link = '#'; |
239 | | - indexIdAttribute = ' id="' + getSwapId( index ) + '" '; |
240 | | - doSpecialSwap = true; |
241 | | - } else { |
242 | | - throw new Error( 'Cannot substitute parameter with unrecognized type ' + typeof paramaters[index] ); |
243 | | - } |
244 | | - } |
245 | | - |
246 | | - return '<a href="' + link + '" ' + indexIdAttribute + '>' + linkText + '</a>'; |
247 | | - }); |
248 | | - |
249 | | - // Swap $1 replacements (not in a link): |
250 | | - text = text.replace( /\$(\d+)/g, function( matched, indexString ) { |
251 | | - var index = parseInt( indexString, 10 ) - 1; |
252 | | - // Check the paramaters type |
253 | | - if( paramaters[index] && needsSpecialSwap( paramaters[index] ) ) { |
254 | | - doSpecialSwap = true; |
255 | | - return '<span id="' + getSwapId( index ) + '></span>'; |
256 | | - } else { |
257 | | - // directly swap in the index or a missing index indicator ( $1{int} |
258 | | - return index in paramaters ? paramaters[index] : '$' + match; |
259 | | - } |
260 | | - } ); |
261 | | - |
262 | | - // Create a parser object with default set of options: |
263 | | - var parsedText = new mediaWiki.language.parser( text, {} ); |
264 | | - // Get the html representation of wikitext ( all that messages deal with right now ) |
265 | | - text = parsedText.getHTML(); |
266 | | - |
267 | | - // If the parameters are jQuery objects or functions, we should now "swap" those objects in. |
268 | | - if( doSpecialSwap ) { |
269 | | - // Add bindings to swap index and return binded html jQuery objects |
270 | | - for( var index=0; index < paramaters.length; index++ ) { |
271 | | - var parameter = paramaters[index]; |
272 | | - var $swapTarget = this.find( '#' + getSwapId( index ) ); |
273 | | - if ( ! $swapTarget.length ) { |
274 | | - continue; |
275 | | - } |
276 | | - |
277 | | - // if parameter was a function, simply add it to the click handler |
278 | | - if( typeof parameter == 'function' ){ |
279 | | - $swapTarget.click( parameter ); |
280 | | - } |
281 | | - |
282 | | - // if parameter was a jQuery object, make it "wrap around" the text we have |
283 | | - if( parameter instanceof jQuery ){ |
284 | | - // make the jQuery parameter contain the same text as the swap target |
285 | | - parameter.text( $swapTarget.text() ); |
286 | | - // replace the swap target with the jQuery parameter |
287 | | - $swapTarget.replaceWith( parameter ); |
288 | | - } |
289 | | - } |
290 | | - } |
291 | | - |
292 | | - return text; |
293 | | - }; |
294 | | - |
295 | | - /** |
296 | | - * Utility Functions |
297 | | - */ |
298 | | - |
299 | | - /** |
300 | | - * A version comparison utility function Handles version of types |
301 | | - * {Major}.{MinorN}.{Patch} |
302 | | - * |
303 | | - * Note this just handles version numbers not patch letters. |
304 | | - * |
305 | | - * @param {String} |
306 | | - * minVersion Minnium version needed |
307 | | - * @param {String} |
308 | | - * clientVersion Client version to be checked |
309 | | - * |
310 | | - * @return true if the version is at least of minVersion false if the |
311 | | - * version is less than minVersion |
312 | | - */ |
313 | | - mw.versionIsAtLeast = function( minVersion, clientVersion ) { |
314 | | - var minVersionParts = minVersion.split('.'); |
315 | | - var clientVersionParts = clientVersion.split('.'); |
316 | | - for( var i =0; i < minVersionParts.length; i++ ) { |
317 | | - if( parseInt( clientVersionParts[i] ) > parseInt( minVersionParts[i] ) ) { |
318 | | - return true; |
319 | | - } |
320 | | - if( parseInt( clientVersionParts[i] ) < parseInt( minVersionParts[i] ) ) { |
321 | | - return false; |
322 | | - } |
323 | | - } |
324 | | - // Same version: |
325 | | - return true; |
326 | | - }; |
327 | | - |
328 | | - |
329 | | - /** |
330 | | - * addLoaderDialog small helper for displaying a loading dialog |
331 | | - * |
332 | | - * @param {String} |
333 | | - * dialogHtml text Html of the loader msg |
334 | | - */ |
335 | | - mw.addLoaderDialog = function( dialogHtml ) { |
336 | | - if( !dialogHtml ){ |
337 | | - dialogHtml = gM('mwe-loading'); |
338 | | - } |
339 | | - $dialog = mw.addDialog({ |
340 | | - 'title' : dialogHtml, |
341 | | - 'content' : dialogHtml + '<br>' + |
342 | | - $('<div />') |
343 | | - .loadingSpinner() |
344 | | - .html() |
345 | | - }); |
346 | | - return $dialog; |
347 | | - }; |
348 | | - |
349 | | - |
350 | | - |
351 | | - /** |
352 | | - * Add a dialog window: |
353 | | - * |
354 | | - * @param {Object} with following keys: |
355 | | - * title: {String} Title string for the dialog |
356 | | - * content: {String} to be inserted in msg box |
357 | | - * buttons: {Object} A button object for the dialog Can be a string |
358 | | - * for the close button |
359 | | - * any jquery.ui.dialog option |
360 | | - */ |
361 | | - mw.addDialog = function ( options ) { |
362 | | - // Remove any other dialog |
363 | | - $( '#mweDialog' ).remove(); |
364 | | - |
365 | | - if( !options){ |
366 | | - options = {}; |
367 | | - } |
368 | | - |
369 | | - // Extend the default options with provided options |
370 | | - var options = $j.extend({ |
371 | | - 'bgiframe': true, |
372 | | - 'draggable': true, |
373 | | - 'resizable': false, |
374 | | - 'modal': true |
375 | | - }, options ); |
376 | | - |
377 | | - if( ! options.title || ! options.content ){ |
378 | | - mw.log("Error: mwEmbed addDialog missing required options ( title, content ) "); |
379 | | - return ; |
380 | | - } |
381 | | - |
382 | | - // Append the dialog div on top: |
383 | | - $( 'body' ).append( |
384 | | - $('<div />') |
385 | | - .attr( { |
386 | | - 'id' : "mweDialog", |
387 | | - 'title' : options.title |
388 | | - }) |
389 | | - .css({ |
390 | | - 'display': 'none' |
391 | | - }) |
392 | | - .append( options.content ) |
393 | | - ); |
394 | | - |
395 | | - // Build the uiRequest |
396 | | - var uiRequest = [ 'jquery.ui.dialog' ]; |
397 | | - if( options.draggable ){ |
398 | | - uiRequest.push( 'jquery.ui.draggable' ); |
399 | | - } |
400 | | - if( options.resizable ){ |
401 | | - uiRequest.push( 'jquery.ui.resizable' ); |
402 | | - } |
403 | | - |
404 | | - // Special button string |
405 | | - if ( typeof options.buttons == 'string' ) { |
406 | | - var buttonMsg = options.buttons; |
407 | | - buttons = { }; |
408 | | - options.buttons[ buttonMsg ] = function() { |
409 | | - $( this ).dialog( 'close' ); |
410 | | - }; |
411 | | - } |
412 | | - |
413 | | - // Load the dialog resources |
414 | | - mw.load(uiRequest, function() { |
415 | | - $( '#mweDialog' ).dialog( options ); |
416 | | - } ); |
417 | | - |
418 | | - return $( '#mweDialog' ); |
419 | | - }; |
420 | | - |
421 | | - /** |
422 | | - * Close the loader dialog created with addLoaderDialog |
423 | | - */ |
424 | | - mw.closeLoaderDialog = function() { |
425 | | - $( '#mweDialog' ).dialog( 'destroy' ).remove(); |
426 | | - }; |
427 | | - |
428 | | - |
429 | | -} )( mediaWiki, jQuery ); |
\ No newline at end of file |