* language updates and fixes/enhancements to js/php merge system
[lhc/web/wiklou.git] / js2 / mwEmbed / mv_embed.js
1 /*
2 * ~mv_embed ~
3 * for details see: http://metavid.org/wiki/index.php/Mv_embed
4 *
5 * All Metavid Wiki code is Released under the GPL2
6 * for more info visit http://metavid.org/wiki/Code
7 *
8 * @url http://metavid.org
9 *
10 * parseUri:
11 * http://stevenlevithan.com/demo/parseuri/js/
12 *
13 * config values you can manually set the location of the mv_embed folder here
14 * (in cases where media will be hosted in a different place than the embedding page)
15 *
16 */
17 //fix multiple instances of mv_embed (ie include twice from two different servers)
18 var MV_DO_INIT=true;
19 if( MV_EMBED_VERSION ){
20 MV_DO_INIT=false;
21 }
22 //used to grab fresh copies of scripts. (should be changed on commit)
23 var MV_EMBED_VERSION = '1.0r19';
24
25 /*
26 * Configuration variables (can be set from some precceding script)
27 * set up mwConfig global overide any of the defaultMwConfig values:
28 * @@ more config valuse on the way ;)
29 */
30 var defaultMwConfig = {
31 'skin_name': 'kskin',
32 'video_size':'400x300'
33 }
34
35 if(!mwConfig)
36 var mwConfig = {};
37
38 //install the default config values for anything not set in mwConfig
39 checkDefaultMwConfig();
40
41 //whether or not to load java from an iframe.
42 //note: this is necessary for remote embedding because of java security model)
43 if(!mv_java_iframe)
44 var mv_java_iframe = true;
45
46 //for when useing mv_embed with script-loader in root mediawiki path
47 var mediaWiki_mvEmbed_path = 'js2/mwEmbed/';
48
49 var global_player_list = new Array(); //the global player list per page
50 var global_req_cb = new Array(); //the global request callback array
51 var _global = this; //global obj
52 var mv_init_done=false;
53 var global_cb_count =0;
54
55 /*parseUri class parses URIs:*/
56 var parseUri=function(d){var o=parseUri.options,value=o.parser[o.strictMode?"strict":"loose"].exec(d);for(var i=0,uri={};i<14;i++){uri[o.key[i]]=value[i]||""}uri[o.q.name]={};uri[o.key[12]].replace(o.q.parser,function(a,b,c){if(b)uri[o.q.name][b]=c});return uri};parseUri.options={strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};
57
58
59 //get mv_embed location if it has not been set
60 if( !mv_embed_path ){
61 var mv_embed_path = getMvEmbedPath();
62 }
63
64 //setup the skin path:
65 var mv_jquery_skin_path = mv_embed_path + 'jquery/jquery.ui/themes/base/';
66 var mv_skin_img_path = mv_embed_path + 'skins/' + mwConfig['skin_name'] + '/images/';
67 var mv_default_thumb_url = mv_skin_img_path + 'vid_default_thumb.jpg';
68
69
70 //init the global Msg if not already
71 if(!gMsg){var gMsg={};}
72
73 //laguage msg loader:
74 function loadGM( msgSet ){
75 for(var i in msgSet){
76 gMsg[ i ] = msgSet[i];
77 }
78 }
79
80 //all default msg in [English] should be overwritten by the CMS language msg system.
81 loadGM({
82 "loading_txt" : "loading <blink>...<\/blink>",
83 "loading_title" : "Loading...",
84 "size-gigabytes" : "$1 GB",
85 "size-megabytes" : "$1 MB",
86 "size-kilobytes" : "$1 K",
87 "size-bytes" : "$1 B"
88 });
89
90 /**
91 * AutoLoader paths (this should mirror the file: jsAutoloadLocalClasses.php )
92 * any file _not_ listed here won't be auto-loadable
93 * @path the path to the file (or set of files) with ending slash
94 * @gClasses the set of classes
95 * if an array $j.className become jquery.className.js
96 * if an asssociative object then key => value paris are used
97 */
98 if(typeof mvAutoLoadClasses == 'undefined')
99 mvAutoLoadClasses = {};
100
101 //the script that loads the classet
102 function lcPaths( classSet){
103 for(var i in classSet){
104 mvAutoLoadClasses[i] = classSet[i];
105 }
106 }
107
108 function mvGetClassPath(k){
109 if( mvAutoLoadClasses[k] ){
110 //js_log('got classpath:' + k + ' : '+ mvClassPaths[k]);
111 return mvAutoLoadClasses[k];
112 }else{
113 return js_error('could not find path for requested class ' + k );
114 }
115 }
116 if(typeof mvCssPaths == 'undefined')
117 mvCssPaths = {};
118
119 function lcCssPath(cssSet){
120 for(var i in cssSet){
121 mvCssPaths[i]= mv_embed_path + cssSet[i];
122 }
123 }
124
125 /*
126 * -- Load Class Paths --
127 *
128 * MUST BE VALID JSON (NOT JS)
129 * is used by the scriptloader to autoLoad classes (so we only define this once for php & javascript)
130 *
131 * this is more verbose than earlier version that compressed paths
132 * but its all good gziping help compress repetative path strings
133 * grouped by
134 *
135 * right now php AutoLoader only reads this mv_embed.js file
136 * in the future we could have multiple lcPath calls that php reads
137 * (if our autoloading class list becomes too long) just have to add thouse
138 * files to the jsAutoLoader file list.
139 */
140 lcPaths({
141 "mv_embed" : "mv_embed.js",
142 "window.jQuery" : "jquery/jquery-1.3.2.js",
143 "$j.fn.pngFix" : "jquery/plugins/jquery.pngFix.js",
144 "$j.fn.autocomplete": "jquery/plugins/jquery.autocomplete.js",
145 "$j.fn.hoverIntent" : "jquery/plugins/jquery.hoverIntent.js",
146 "$j.fn.datePicker" : "jquery/plugins/jquery.datePicker.js",
147 "$j.ui" : "jquery/jquery.ui/ui/ui.core.js",
148 "$j.fn.ColorPicker" : "libClipEdit/colorpicker/js/colorpicker.js",
149 "$j.Jcrop" : "libClipEdit/Jcrop/js/jquery.Jcrop.js",
150 "$j.fn.simpleUploadForm": "libAddMedia/simpleUploadForm.js",
151
152 "baseSkin" : "skins/baseSkin.js",
153 "kskin" : "skins/kskin/kskin.js",
154 "mvpcf" : "skins/mvpcf/mvpcf.js",
155
156 "$j.secureEvalJSON" : "jquery/plugins/jquery.secureEvalJSON.js",
157 "$j.cookie" : "jquery/plugins/jquery.cookie.js",
158 "$j.contextMenu" : "jquery/plugins/jquery.contextMenu.js",
159
160 "$j.effects.blind" : "jquery/jquery.ui/ui/effects.blind.js",
161 "$j.effects.drop" : "jquery/jquery.ui/ui/effects.drop.js",
162 "$j.effects.pulsate" : "jquery/jquery.ui/ui/effects.pulsate.js",
163 "$j.effects.transfer" : "jquery/jquery.ui/ui/effects.transfer.js",
164 "$j.ui.droppable" : "jquery/jquery.ui/ui/ui.droppable.js",
165 "$j.ui.slider" : "jquery/jquery.ui/ui/ui.slider.js",
166 "$j.effects.bounce" : "jquery/jquery.ui/ui/effects.bounce.js",
167 "$j.effects.explode" : "jquery/jquery.ui/ui/effects.explode.js",
168 "$j.effects.scale" : "jquery/jquery.ui/ui/effects.scale.js",
169 "$j.ui.datepicker" : "jquery/jquery.ui/ui/ui.datepicker.js",
170 "$j.ui.progressbar" : "jquery/jquery.ui/ui/ui.progressbar.js",
171 "$j.ui.sortable" : "jquery/jquery.ui/ui/ui.sortable.js",
172 "$j.effects.clip" : "jquery/jquery.ui/ui/effects.clip.js",
173 "$j.effects.fold" : "jquery/jquery.ui/ui/effects.fold.js",
174 "$j.effects.shake" : "jquery/jquery.ui/ui/effects.shake.js",
175 "$j.ui.dialog" : "jquery/jquery.ui/ui/ui.dialog.js",
176 "$j.ui.resizable" : "jquery/jquery.ui/ui/ui.resizable.js",
177 "$j.ui.tabs" : "jquery/jquery.ui/ui/ui.tabs.js",
178 "$j.effects.core" : "jquery/jquery.ui/ui/effects.core.js",
179 "$j.effects.highlight" : "jquery/jquery.ui/ui/effects.highlight.js",
180 "$j.effects.slide" : "jquery/jquery.ui/ui/effects.slide.js",
181 "$j.ui.accordion" : "jquery/jquery.ui/ui/ui.accordion.js",
182 "$j.ui.draggable" : "jquery/jquery.ui/ui/ui.draggable.js",
183 "$j.ui.selectable" : "jquery/jquery.ui/ui/ui.selectable.js",
184
185 "mvFirefogg" : "libAddMedia/mvFirefogg.js",
186 "mvAdvFirefogg" : "libAddMedia/mvAdvFirefogg.js",
187 "mvBaseUploadInterface" : "libAddMedia/mvBaseUploadInterface.js",
188 "remoteSearchDriver" : "libAddMedia/remoteSearchDriver.js",
189 "seqRemoteSearchDriver" : "libAddMedia/seqRemoteSearchDriver.js",
190
191 "baseRemoteSearch" : "libAddMedia/searchLibs/baseRemoteSearch.js",
192 "mediaWikiSearch" : "libAddMedia/searchLibs/mediaWikiSearch.js",
193 "metavidSearch" : "libAddMedia/searchLibs/metavidSearch.js",
194 "archiveOrgSearch" : "libAddMedia/searchLibs/archiveOrgSearch.js",
195 "baseRemoteSearch" : "libAddMedia/searchLibs/baseRemoteSearch.js",
196
197 "mvClipEdit" : "libClipEdit/mvClipEdit.js",
198
199 "embedVideo" : "libEmbedVideo/embedVideo.js",
200 "flashEmbed" : "libEmbedVideo/flashEmbed.js",
201 "genericEmbed" : "libEmbedVideo/genericEmbed.js",
202 "htmlEmbed" : "libEmbedVideo/htmlEmbed.js",
203 "javaEmbed" : "libEmbedVideo/javaEmbed.js",
204 "nativeEmbed" : "libEmbedVideo/nativeEmbed.js",
205 "quicktimeEmbed" : "libEmbedVideo/quicktimeEmbed.js",
206 "vlcEmbed" : "libEmbedVideo/vlcEmbed.js",
207
208 "mvPlayList" : "libSequencer/mvPlayList.js",
209 "mvSequencer" : "libSequencer/mvSequencer.js",
210 "mvFirefoggRender" : "libSequencer/mvFirefoggRender.js",
211 "mvTimedEffectsEdit": "libSequencer/mvTimedEffectsEdit.js",
212
213 "libTimedText" : "libTimedText/mvTextInterface.js"
214
215 });
216
217 //depencency mapping for css files for self contained included plugins:
218 lcCssPath({
219 '$j.Jcrop' : 'libClipEdit/Jcrop/css/jquery.Jcrop.css',
220 '$j.fn.ColorPicker' : 'libClipEdit/colorpicker/css/colorpicker.css'
221 })
222
223 /**
224 * Language Functions:
225 *
226 * These functions try to losely mirro the functionality of Language.php in mediaWiki
227 */
228 function gM( key , args ) {
229 var ms ='';
230 if ( key in gMsg ) {
231 ms = gMsg[ key ];
232 if(typeof args == 'object' || typeof args == 'array'){
233 for(var v in args){
234 //msg test replace arguments start at 1 insted of zero:
235 var rep = '\$'+ ( parseInt(v) + 1 );
236 ms = ms.replace( rep, args[v]);
237 }
238 }else if(typeof args =='string' || typeof args =='number'){
239 ms = ms.replace(/\$1/, args);
240 }
241 return ms;
242 } else{
243 //key is missing return indication:
244 return '&lt;' + key + '&gt;';
245 }
246 }
247 /*
248 * msgSet is either a string corresponding to a single msg to load
249 * or msgSet is an array with set of msg to load
250 */
251 function gMsgLoadRemote(msgSet, callback){
252 var ammessages = '';
253 if(typeof msgSet == 'object' ){
254 for(var i in msgSet){
255 ammessages += msgSet[i] + '|';
256 }
257 }else if(typeof msgSet == 'string'){
258 ammessages += msgSet;
259 }
260 if(ammessages == ''){
261 js_log('gMsgLoadRemote::no msg set requested');
262 return false;
263 }
264 do_api_req({
265 'data':{
266 'meta':'allmessages',
267 'ammessages':ammessages
268 }
269 },function(data){
270 if(data.query.allmessages){
271 var msgs = data.query.allmessages;
272 for(var i in msgs){
273 var ld = {};
274 ld[ msgs[i]['name'] ] = msgs[i]['*'];
275 loadGM( ld );
276 }
277 }
278 //load the result into local msg var
279 callback();
280 });
281 }
282
283 /**
284 * Format a size in bytes for output, using an appropriate
285 * unit (B, KB, MB or GB) according to the magnitude in question
286 *
287 * @param size Size to format
288 * @return string Plain text (not HTML)
289 */
290 function formatSize( size ) {
291 // For small sizes no decimal places necessary
292 var round = 0;
293 var msg = '';
294 if( size > 1024 ) {
295 size = size / 1024;
296 if( size > 1024 ) {
297 size = size / 1024;
298 // For MB and bigger two decimal places are smarter
299 round = 2;
300 if( size > 1024 ) {
301 size = size / 1024;
302 msg = 'size-gigabytes';
303 } else {
304 msg = 'size-megabytes';
305 }
306 } else {
307 msg = 'size-kilobytes';
308 }
309 } else {
310 msg = 'size-bytes';
311 }
312 //javascript does not let you do precession points in rounding
313 var p = Math.pow(10,round);
314 var size = Math.round( size * p ) / p;
315 //@@todo we need a formatNum and we need to request some special packaged info to deal with that case.
316 return gM( msg , size );
317 }
318
319 //gets the loading image:
320 function mv_get_loading_img( style , class_attr ){
321 var style_txt = (style)?style:'';
322 var class_attr = (class_attr)?'class="'+class_attr+'"':'class="mv_loading_img"';
323 return '<div '+class_attr+' style="' + style +'"></div>';
324 }
325
326 function mv_set_loading(target, load_id){
327 var id_attr = ( load_id )?' id="' + load_id + '" ':'';
328 $j(target).append('<div '+id_attr+' style="position:absolute;top:0px;left:0px;height:100%;width:100%;'+
329 'background-color:#FFF;">' +
330 mv_get_loading_img('top:30px;left:30px') +
331 '</div>');
332 }
333
334 /**
335 * mvJsLoader class handles initialization and js file loads
336 */
337 var mvJsLoader = {
338 libreq : {},
339 libs : {},
340 //base lib flags:
341 onReadyEvents:new Array(),
342 doneReadyEvents:false,
343 jQueryCheckFlag:false,
344 //to keep consistency across threads:
345 ptime:0,
346 ctime:0,
347 load_error:false, //load error flag (false by default)
348 load_time:0,
349 callbacks:new Array(),
350 cur_path: null,
351 missing_path : null,
352 doLoad:function(loadLibs, callback){
353 this.ctime++;
354 if( loadLibs && loadLibs.length!=0 ){ //setup this.libs:
355
356 //first check if we already have this lib loaded
357 var all_libs_loaded=true;
358 for(var i=0; i< loadLibs.length; i++){
359 //check if the lib is already loaded:
360 if( ! this.checkObjPath( loadLibs[i] ) ){
361 all_libs_loaded=false;
362 }
363 }
364 if( all_libs_loaded ){
365 js_log('all libs already loaded skipping... load req');
366 callback();
367 return ;
368 }
369 //do a check for any css we may need and get it:
370 for(var i=0; i< loadLibs.length; i++){
371 if( typeof mvCssPaths[ loadLibs[i] ] != 'undefined' ){
372 loadExternalCss( mvCssPaths[ loadLibs[i] ]);
373 }
374 }
375
376 //check if we should use the script loader to combine all the requests into one:
377 if( typeof mwSlScript != 'undefined' ){
378 var class_set = '';
379 var last_class = '';
380 var coma = '';
381 for(var i=0; i< loadLibs.length; i++){
382 var curLib = loadLibs[i];
383 //only add if not included yet:
384 if( ! this.checkObjPath( curLib ) ){
385 class_set+=coma + curLib ;
386 last_class=curLib;
387 coma=',';
388 }
389 }
390 var puri = parseUri( getMvEmbedURL() );
391 if( (getMvEmbedURL().indexOf('://')!=-1) && puri.host != parseUri( document.URL).host){
392 mwSlScript = puri.protocol + '://' + puri.authority + mwSlScript;
393 }
394
395 var dbug_attr = (puri.queryKey['debug'])?'&debug=true':'';
396 this.libs[ last_class ] = mwSlScript + '?class=' + class_set +
397 '&urid=' + getMvUniqueReqId() + dbug_attr;
398
399 }else{
400 //do many requests:
401 for(var i=0; i< loadLibs.length; i++){
402 var curLib = loadLibs[i];
403 if(curLib){
404 var libLoc = mvGetClassPath(curLib);
405 // do a direct load of the file (pass along unique request id from request or mv_embed Version )
406 var qmark = (libLoc.indexOf('?')!==true)?'?':'&';
407 this.libs[curLib] = mv_embed_path + libLoc + qmark + 'urid='+ getMvUniqueReqId();
408 }
409 }
410 }
411 }
412 if( callback ){
413 this.callbacks.push(callback);
414 }
415 if( this.checkLoading() ){
416 if( this.load_time++ > 1000){ //time out after ~80seconds
417 js_error( gM('error_load_lib') + this.missing_path );
418 this.load_error=true;
419 }else{
420 setTimeout( 'mvJsLoader.doLoad()', 20 );
421 }
422 }else{
423 //js_log('checkLoading passed run callbacks');
424 //only do callback if we are in the same instance (weird concurency issue)
425 var cb_count=0;
426 for(var i=0; i < this.callbacks.length; i++)
427 cb_count++;
428 //js_log('REST LIBS: loading is: '+ loading + ' run callbacks: '+cb_count +' p:'+ this.ptime +' c:'+ this.ctime);
429 //reset the libs
430 this.libs={};
431 //js_log('done loading do call: ' + this.callbacks[0] );
432 while( this.callbacks.length !=0 ){
433 if( this.ptime== ( this.ctime-1) ){ //enforce thread consistency
434 this.callbacks.pop()();
435 //func = this.callbacks.pop();
436 //js_log(' run: '+this.ctime+ ' p: ' + this.ptime + ' ' +loading+ ' :'+ func);
437 //func();
438 }else{
439 //re-issue doLoad ( ptime will be set to ctime so we should catch up)
440 setTimeout( 'mvJsLoader.doLoad()', 25 );
441 break;
442 }
443 }
444 }
445 this.ptime=this.ctime;
446 },
447 doLoadFullPaths:function(loadObj, callback){
448
449 },
450 doLoadDepMode:function(loadChain, callback){
451 //firefox executes js ~in-order of it being included~ so just directly issue request:
452 if( $j.browser.firefox ){
453 var loadSet = [];
454 for(var i=0; i< loadChain.length;i++){
455 for(var j=0;j<loadChain[i].length;j++){
456 loadSet.push(loadChain[i][j]);
457 }
458 }
459 mvJsLoader.doLoad(loadSet, callback);
460 }else{
461 //safari and IE tend to execute out of order so load with dependenciy checks
462 mvJsLoader.doLoad(loadChain.shift(),function(){
463 if(loadChain.length!=0){
464 mvJsLoader.doLoadDepMode(loadChain, callback);
465 }else{
466 callback();
467 }
468 });
469 } },
470 checkLoading:function(){
471 var loading=0;
472 var i=null;
473 for(var i in this.libs){ //for in loop oky on object
474 if( !this.checkObjPath( i ) ){
475 if(!this.libreq[i]){
476 loadExternalJs( this.libs[i] );
477 }
478
479 this.libreq[i]=1;
480 //js_log("has not yet loaded: " + i);
481 loading=1;
482 }
483 }
484 return loading;
485 },
486 checkObjPath:function( libVar ){
487 if(!libVar)
488 return false;
489 var objPath = libVar.split('.')
490 var cur_path ='';
491 for(var p=0; p < objPath.length; p++){
492 cur_path = (cur_path=='')?cur_path+objPath[p]:cur_path+'.'+objPath[p];
493 eval( 'var ptest = typeof ( '+ cur_path + ' ); ');
494 if( ptest == 'undefined'){
495 this.missing_path = cur_path;
496 return false;
497 }
498 }
499 this.cur_path = cur_path;
500 return true;
501 },
502 /**
503 * checks for jQuery and adds the $j noConflict var
504 */
505 jQueryCheck:function(callback){
506 //skip stuff if $j is already loaded:
507 if(_global['$j'] && callback)
508 callback();
509 var _this = this;
510 //load jquery
511 _this.doLoad([
512 'window.jQuery'
513 ],function(){
514 _global['$j'] = jQuery.noConflict();
515 //set up ajax to not send dynamic urls for loading scripts (we control that with the scriptLoader)
516 $j.ajaxSetup({
517 cache: true
518 });
519 js_log('jquery loaded');
520 //setup mvEmbed jquery bindigns:
521 mv_jqueryBindings();
522 //run the callback
523 if(callback){
524 callback();
525 }
526 });
527 },
528 embedVideoCheck:function( callback ){
529 var _this = this;
530 js_log('embedVideoCheck:');
531 //set videonojs to loading
532 //issue a style sheet request get both mv_embed and jquery styles:
533 loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css' );
534 loadExternalCss( mv_embed_path + 'skins/'+mwConfig['skin_name']+'/styles.css');
535
536 //make sure we have jQuery
537 _this.jQueryCheck(function(){
538 $j('.videonojs').html( gM('loading_txt') );
539 var depReq = [
540 [
541 '$j.ui',
542 'embedVideo',
543 '$j.cookie'
544 ],
545 [
546 '$j.ui.slider'
547 ]
548 ];
549 //add png fix if needed:
550 if($j.browser.msie || $j.browser.version < 7)
551 depReq[0].push( '$j.fn.pngFix' );
552
553 _this.doLoadDepMode(depReq,function(){
554 embedTypes.init();
555 callback();
556 $j('.videonojs').remove();
557 });
558 });
559 },
560 addLoadEvent:function(fn){
561 this.onReadyEvents.push(fn);
562 },
563 //checks the jQuery flag (this way when remote embeding we don't load jQuery
564 // unless js2AddOnloadHook was used or there is video on the page
565 runQuededFunctions:function(){
566 var _this = this;
567 this.doneReadyEvents=true;
568 if(this.jQueryCheckFlag){
569 this.jQueryCheck(function(){
570 _this.runReadyEvents();
571 });
572 }else{
573 this.runReadyEvents();
574 }
575 },
576 runReadyEvents:function(){
577 js_log("runReadyEvents");
578 while( this.onReadyEvents.length ){
579 this.onReadyEvents.shift()();
580 }
581 }
582
583 }
584 //load an external JS (similar to jquery .require plugin)
585 //but checks for object availability rather than load state
586
587 /*********** INITIALIZATION CODE *************
588 * this will get called when DOM is ready
589 *********************************************/
590 /* jQuery .ready does not work when jQuery is loaded dynamically
591 * for an example of the problem see:1.1.3 working:http://pastie.caboo.se/92588
592 * and >= 1.1.4 not working: http://pastie.caboo.se/92595
593 * $j(document).ready( function(){ */
594 function mwdomReady(force){
595 js_log('f:mwdomReady:');
596 if( !force && mv_init_done ){
597 js_log("mv_init_done already done do nothing...");
598 return false;
599 }
600 mv_init_done=true;
601 //handle the execution of Queded function with jQuery "ready"
602
603 //check if this page does have video or playlist
604 var e = [
605 document.getElementsByTagName("video"),
606 document.getElementsByTagName("audio"),
607 document.getElementsByTagName("playlist")
608 ];
609 if(e[0].length!=0 || e[1].length!=0 || e[2].length!=0){
610 js_log('we have items to rewrite');
611
612 //load libs and proccess:
613 mvJsLoader.embedVideoCheck(function(){
614 //run any queded global events:
615 mv_video_embed( function(){
616 mvJsLoader.runQuededFunctions();
617 });
618 });
619 }else{
620 //if we already have jQuery make sure its loaded into its proper context $j
621 //run any queded global events:
622 mvJsLoader.runQuededFunctions();
623 }
624 }
625 //js2AddOnloadHook: ensure jQuery and the DOM are ready:
626 function js2AddOnloadHook( func ) {
627 //make sure the skin/style sheets are avaliable always:
628 loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css' );
629 loadExternalCss( mv_embed_path + 'skins/'+mwConfig['skin_name']+'/styles.css');
630
631 //if we have already run the dom ready just run the function directly:
632 if( mvJsLoader.doneReadyEvents ){
633 //make sure jQuery is there:
634 mvJsLoader.jQueryCheck(function(){
635 func();
636 });
637 }else{
638 //if using js2AddOnloadHook we need to get jQuery into place (if its not already included)
639 mvJsLoader.jQueryCheckFlag = true;
640 mvJsLoader.addLoadEvent( func );
641 };
642 }
643 //depreciated mwAddOnloadHook in favor of js2 naming (for clear seperation of js2 code from old mw code
644 var mwAddOnloadHook = js2AddOnloadHook;
645 /*
646 * this function allows for targeted rewriting
647 */
648 function rewrite_by_id( vid_id, ready_callback ){
649 js_log('f:rewrite_by_id: ' + vid_id);
650 //force a recheck of the dom for playlist or video element:
651 mvJsLoader.embedVideoCheck(function(){
652 mv_video_embed(ready_callback, vid_id );
653 });
654 }
655 //depricated in favor of updates to oggHanlder
656 function rewrite_for_oggHanlder( vidIdList ){
657 for(var i = 0; i < vidIdList.length ; i++){
658 var vidId = vidIdList[i];
659 js_log('looking at vid: ' + i +' ' + vidId);
660 //grab the thumbnail and src video
661 var pimg = $j('#'+vidId + ' img');
662 var poster_attr = 'poster = "' + pimg.attr('src') + '" ';
663 var pwidth = pimg.attr('width');
664 var pheight = pimg.attr('height');
665
666 var type_attr = '';
667 //check for audio
668 if( pwidth=='22' && pheight=='22'){
669 pwidth='400';
670 pheight='300';
671 type_attr = 'type="audio/ogg"';
672 poster_attr = '';
673 }
674
675 //parsed values:
676 var src = '';
677 var duration = '';
678
679 var re = new RegExp( /videoUrl(&quot;:?\s*)*([^&]*)/ );
680 src = re.exec( $j('#'+vidId).html() )[2];
681
682 var re = new RegExp( /length(&quot;:?\s*)*([^&]*)/ );
683 duration = re.exec( $j('#'+vidId).html() )[2];
684
685 var re = new RegExp( /offset(&quot;:?\s*)*([^&]*)/ );
686 offset = re.exec( $j('#'+vidId).html() )[2];
687 var offset_attr = (offset)? 'startOffset="'+ offset + '"': '';
688
689 if( src ){
690 //replace the top div with mv_embed based player:
691 var vid_html = '<video id="vid_' + i +'" '+
692 'src="' + src + '" ' +
693 poster_attr + ' ' +
694 type_attr + ' ' +
695 offset_attr + ' ' +
696 'duration="' + duration + '" ' +
697 'style="width:' + pwidth + 'px;height:' +
698 pheight + 'px;"></video>';
699 //js_log("video html: " + vid_html);
700 $j('#'+vidId).html( vid_html );
701 }
702
703 //rewrite that video id:
704 rewrite_by_id('vid_' + i);
705 }
706 }
707
708
709 /*********** INITIALIZATION CODE *************
710 * set DOM ready callback to init_mv_embed
711 *********************************************/
712 // for Mozilla browsers
713 if (document.addEventListener ) {
714 document.addEventListener("DOMContentLoaded", function(){mwdomReady()}, false);
715 }else{
716 //backup "onload" method in case on DOMContentLoaded does not exist
717 window.onload = function(){ mwdomReady() };
718 }
719 /*
720 * should depreciate and use jquery.ui.dialog instead
721 */
722 function mv_write_modal(content, speed){
723 $j('#modalbox,#mv_overlay').remove();
724 $j('body').append('<div id="modalbox" style="background:#DDD;border:3px solid #666666;font-size:115%;'+
725 'top:30px;left:20px;right:20px;bottom:30px;position:fixed;z-index:100;">'+
726 content +
727 '</div>'+
728 '<div id="mv_overlay" style="background:#000;cursor:wait;height:100%;left:0;position:fixed;'+
729 'top:0;width:100%;z-index:5;filter:alpha(opacity=60);-moz-opacity: 0.6;'+
730 'opacity: 0.6;"/>');
731 $j('#modalbox,#mv_overlay').show( speed );
732 }
733 function mv_remove_modal(speed){
734 $j('#modalbox,#mv_overlay').remove( speed);
735 }
736
737 /*
738 * stores all the mwEmbed jQuery specific bindings
739 * (setup after jQuery is avaliable)
740 * lets you call rewrites in a jquery "way"
741 *
742 * @@ eventually we should refactor mwCode over to jQuery style plugins
743 * and mv_embed.js will just hanndle dependency mapping and loading.
744 *
745 */
746 function mv_jqueryBindings(){
747 js_log('mv_jqueryBindings');
748 (function($) {
749 $.fn.addMediaWiz = function( iObj, callback ){
750 //first set the cursor for the button to "loading"
751 $j(this.selector).css('cursor','wait').attr('title', gM('loading_title'));
752
753 iObj['target_invocation'] = this.selector;
754
755 //load the mv_embed_base skin:
756 loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css' );
757 loadExternalCss( mv_embed_path + 'skins/'+mwConfig['skin_name']+'/styles.css' );
758 //load all the req libs:
759 mvJsLoader.jQueryCheck(function(){
760 //load with staged dependeinces (for ie and safari that don't execute in order)
761 mvJsLoader.doLoadDepMode([
762 [ 'remoteSearchDriver',
763 '$j.cookie',
764 '$j.ui'
765 ],[
766 '$j.ui.resizable',
767 '$j.ui.draggable',
768 '$j.ui.dialog',
769 '$j.ui.tabs',
770 '$j.ui.sortable'
771 ]
772 ], function(){
773 iObj['instance_name']= 'rsdMVRS';
774 _global['rsdMVRS'] = new remoteSearchDriver( iObj );
775 if( callback ){
776 callback( _global['rsdMVRS'] );
777 }
778 });
779 });
780 }
781 $.fn.sequencer = function( iObj, callback){
782 //debugger;
783 iObj['target_sequence_container'] = this.selector;
784 //issue a request to get the css file (if not already included):
785 loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css');
786 loadExternalCss( mv_embed_path+'skins/'+mwConfig['skin_name']+'/mv_sequence.css');
787 //make sure we have the required mv_embed libs (they are not loaded when no video element is on the page)
788 mvJsLoader.embedVideoCheck(function(){
789 //load playlist object and then jquery ui stuff:
790 mvJsLoader.doLoadDepMode([
791 [
792 'mvPlayList',
793 '$j.ui',
794 '$j.contextMenu',
795 '$j.secureEvalJSON',
796 'mvSequencer'
797 ],
798 [
799 '$j.ui.accordion',
800 '$j.ui.dialog',
801 '$j.ui.droppable',
802 '$j.ui.draggable',
803 '$j.ui.progressbar',
804 '$j.ui.sortable',
805 '$j.ui.resizable',
806 '$j.ui.slider',
807 '$j.ui.tabs'
808 ]
809 ], function(){
810 js_log('calling new mvSequencer');
811 //init the sequence object (it will take over from there) no more than one mvSeq obj for now:
812 if(!_global['mvSeq']){
813 _global['mvSeq'] = new mvSequencer(iObj);
814 }else{
815 js_log('mvSeq already init');
816 }
817 });
818 });
819 }
820 /*
821 * the firefogg jquery function:
822 * @@note this firefogg envocation could be made to work more like real jquery plugins
823 */
824 $.fn.firefogg = function( iObj, callback ) {
825 if(!iObj)
826 iObj={};
827 //add base theme css:
828 loadExternalCss( mv_jquery_skin_path + 'jquery-ui-1.7.1.custom.css');
829 loadExternalCss( mv_embed_path + 'skins/'+mwConfig['skin_name']+'/styles.css' );
830
831 //check if we already have firefogg loaded (the call just updates properties for that element)
832 var sElm = $j(this.selector).get(0);
833 if(sElm['firefogg']){
834 if(sElm['firefogg']=='loading'){
835 js_log("Error: called firefogg operations on Firefogg selector that is not done loading");
836 return false;
837 }
838 //update properties:
839 for(var i in iObj){
840 js_log("firefogg::updated: "+ i + ' to '+ iObj[i]);
841 sElm['firefogg'][i] = iObj[i];
842 }
843 return sElm['firefogg'];
844 }else{
845 //avoid concurency
846 sElm['firefogg'] = 'loading';
847 }
848 //add the selector:
849 iObj['selector'] = this.selector;
850
851 var loadSet = [
852 [
853 'mvBaseUploadInterface',
854 'mvFirefogg',
855 '$j.ui'
856 ],
857 [
858 '$j.ui.progressbar',
859 '$j.ui.dialog'
860 ]
861 ];
862 if( iObj.encoder_interface ){
863 loadSet.push([
864 'mvAdvFirefogg',
865 '$j.cookie',
866 '$j.ui.accordion',
867 '$j.ui.slider',
868 '$j.ui.datepicker'
869 ]);
870 }
871 //make sure we have everything loaded that we need:
872 mvJsLoader.doLoadDepMode( loadSet, function(){
873 js_log('firefogg libs loaded. target select:' + iObj.selector);
874 //select interface provicer based on if we want to include the encoder interface or not:
875 if(iObj.encoder_interface){
876 var myFogg = new mvAdvFirefogg( iObj );
877 }else{
878 var myFogg = new mvFirefogg( iObj );
879 }
880 if(myFogg){
881 myFogg.doRewrite( callback );
882 var selectorElement = $j( iObj.selector ).get(0);
883 selectorElement['firefogg']=myFogg;
884 }
885 });
886 }
887 //takes a input player as the selector and exposes basic rendering controls
888 $.fn.firefoggRender = function( iObj, callback ){
889 //check if we already have render loaded then just pass on updates/actions
890 var sElm = $j(this.selector).get(0);
891 if(sElm['fogg_render']){
892 if(sElm['fogg_render']=='loading'){
893 js_log("Error: called firefoggRender while loading");
894 return false;
895 }
896 //call or update the property:
897 }
898 sElm['fogg_render']='loading';
899 //add the selector:
900 iObj['player_target'] = this.selector;
901 mvJsLoader.doLoad([
902 'mvFirefogg',
903 'mvFirefoggRender'
904 ],function(){
905 sElm['fogg_render']= new mvFirefoggRender( iObj );
906 if( callback && typeof callback == 'function' )
907 callback( sElm['fogg_render'] );
908 });
909 }
910
911 $.fn.baseUploadInterface = function(iObj){
912 mvJsLoader.doLoadDepMode([
913 [
914 'mvBaseUploadInterface',
915 '$j.ui',
916 ],
917 [
918 '$j.ui.progressbar',
919 '$j.ui.dialog'
920 ]
921 ],function(){
922 myUp = new mvBaseUploadInterface( iObj );
923 myUp.setupForm();
924 });
925 }
926
927 //shortcut to a themed button:
928 $.btnHtml = function(msg, className, iconId, opt){
929 if(!opt)
930 opt = {};
931 var href = (opt.href)?opt.href:'#';
932 var target_attr = (opt.target)?' target="' + opt.target + '" ':'';
933 var style_attr = (opt.style)?' style="'+opt.style +'" ':'';
934 return '<a href="' + href + '" ' + target_attr + style_attr +' class="ui-state-default ui-corner-all ui-icon_link ' +
935 className + '"><span class="ui-icon ui-icon-' + iconId + '" />' +
936 msg + '</a>';
937 }
938 //shortcut to bind hover state:
939 $.fn.btnBind = function(){
940 $j(this).hover(
941 function(){
942 $j(this).addClass('ui-state-hover');
943 },
944 function(){
945 $j(this).removeClass('ui-state-hover');
946 }
947 )
948 return this;
949 }
950
951 })(jQuery);
952 }
953 /*
954 * utility functions:
955 */
956 //simple url re-writer for rewriting urls (could probably be refactored into an inline regular expresion)
957 function getURLParamReplace( url, opt ){
958 var pSrc = parseUri( url );
959 if(pSrc.protocol != '' ){
960 var new_url = pSrc.protocol +'://'+ pSrc.authority + pSrc.path +'?';
961 }else{
962 var new_url = pSrc.path +'?';
963 }
964 var amp = '';
965 for(var key in pSrc.queryKey){
966 var val = pSrc.queryKey[ key ];
967 //do override if requested
968 if( opt[ key ] )
969 val = opt[ key ];
970 new_url+= amp + key + '=' + val;
971 amp = '&';
972 };
973 //add any vars that did were not originally there:
974 for(var i in opt){
975 if(!pSrc.queryKey[i]){
976 new_url+=amp + i + '=' + opt[i];
977 amp = '&';
978 }
979 }
980 return new_url;
981 }
982 /**
983 * seconds2npt given a float seconds returns npt format response:
984 * @param float seconds
985 * @param boolean if we should show ms or not.
986 */
987 function seconds2npt(sec, show_ms){
988 if( isNaN( sec ) ){
989 //js_log("warning: trying to get npt time on NaN:" + sec);
990 return '0:0:0';
991 }
992 var hours = Math.floor(sec/ 3600);
993 var minutes = Math.floor((sec/60) % 60);
994 var seconds = sec % 60;
995 //round the second amount requested significant digits
996 if(show_ms){
997 seconds = Math.round( seconds * 1000 ) / 1000;
998 }else{
999 seconds = Math.round( seconds );
1000 }
1001 if(seconds <10 )
1002 seconds = '0'+ seconds;
1003 if(minutes < 10 )
1004 minutes = '0' + minutes;
1005
1006 return hours+":"+minutes+":"+seconds;
1007 }
1008 /*
1009 * takes hh:mm:ss,ms or hh:mm:ss.ms input returns number of seconds
1010 */
1011 function npt2seconds( npt_str ){
1012 if(!npt_str){
1013 //js_log('npt2seconds:not valid ntp:'+ntp);
1014 return false;
1015 }
1016 //strip npt: time definition if present
1017 npt_str = npt_str.replace('npt:', '');
1018
1019 times = npt_str.split(':');
1020 if(times.length!=3){
1021 js_log('error: npt2seconds on ' + npt_str);
1022 return false;
1023 }
1024 //sometimes the comma is used inplace of pereid for ms
1025 times[2] = times[2].replace(/,\s?/,'.');
1026 //return seconds float (ie take seconds float value if present):
1027 return parseInt(times[0]*3600)+parseInt(times[1]*60)+parseFloat(times[2]);
1028 }
1029 /*
1030 * simple helper to grab a edit token
1031 *
1032 * @param title the wiki page title you want to edit )
1033 * @param api_url 'optional' the target api url
1034 * @param callback the callback function to pass the token or "false" to
1035 */
1036 function get_mw_token( title, api_url, callback){
1037 js_log(':get_mw_token:');
1038 if(!title && wgUserName){
1039 title = 'User:' + wgUserName;
1040 }
1041 var reqObj = {
1042 'action':'query',
1043 'prop':'info',
1044 'intoken':'edit',
1045 'titles':title
1046 };
1047 do_api_req( {
1048 'data': reqObj,
1049 'url' : api_url
1050 },function(data){
1051 for(var i in data.query.pages){
1052 if(data.query.pages[i]['edittoken']){
1053 if(typeof callback == 'function')
1054 callback ( data.query.pages[i]['edittoken'] );
1055 }
1056 }
1057 //no token found:
1058 return false;
1059 }
1060 );
1061 }
1062 //does a remote or local api request based on request url
1063 //@param options: url, data, cbParam, callback
1064 function do_api_req( options, callback ){
1065 if(typeof options.data != 'object'){
1066 return js_error('Error: request paramaters must be an object');;
1067 }
1068 //gennerate the url if its missing:
1069 if( typeof options.url == 'undefined' || options.url === false){
1070 if(!wgServer || ! wgScriptPath){
1071 return js_error('Error: no api url for api request');;
1072 }
1073 //update to api.php (if index.php was in the wgScript path):
1074 options.url = mwGetLocalApiUrl();
1075 }
1076 if( typeof options.data == 'undefined' )
1077 options.data = {};
1078
1079 //force format to json (if not already set)
1080 options.data['format'] = 'json';
1081
1082 //if action not set assume query
1083 if(!options.data['action'])
1084 options.data['action']='query';
1085
1086 js_log('do api req: ' + options.url +'?' + jQuery.param(options.data) );
1087 //build request string:
1088 if( parseUri( document.URL ).host == parseUri( options.url ).host ){
1089 //local request do api request directly
1090 $j.ajax({
1091 type: "POST",
1092 url: options.url,
1093 data: options.data,
1094 dataType:'json', //api requests _should_ always return JSON data:
1095 async: false,
1096 success:function(data){
1097 callback( data );
1098 },
1099 error:function(e){
1100 js_error( ' error' + e +' in getting: ' + options.url);
1101 }
1102 });
1103 }else{
1104 //set the callback param if not already set:
1105 if( typeof options.jsonCB == 'undefined')
1106 options.jsonCB = 'callback';
1107
1108 var req_url = options.url;
1109 var paramAnd = (req_url.indexOf('?')==-1)?'?':'&';
1110 //put all the values into the GET req:
1111 for(var i in options.data){
1112 req_url += paramAnd + encodeURIComponent( i ) + '=' + encodeURIComponent( options.data[i] );
1113 paramAnd ='&';
1114 }
1115 var fname = 'mycpfn_' + ( global_cb_count++ );
1116 _global[ fname ] = callback;
1117 req_url += '&' + options.jsonCB + '=' + fname;
1118 loadExternalJs( req_url );
1119 }
1120 }
1121 function mwGetLocalApiUrl(url){
1122 if (wgServer && wgScriptPath){
1123 return wgServer + wgScriptPath + '/api.php';
1124 }
1125 return false;
1126 }
1127 //grab wiki form error for wiki html page proccessing (should be depricated)
1128 function grabWikiFormError ( result_page ){
1129 var res = {};
1130 sp = result_page.indexOf('<span class="error">');
1131 if(sp!=-1){
1132 se = result_page.indexOf('</span>', sp);
1133 res.error_txt = result_page.substr(sp, (sp-se)) + '</span>';
1134 }else{
1135 //look for warning:
1136 sp = result_page.indexOf('<ul class="warning">')
1137 if(sp != -1){
1138 se = result_page.indexOf('</ul>', sp);
1139 res.error_txt = result_page.substr(sp, (se-sp)) + '</ul>';
1140 //try and add the ignore form item:
1141 sfp = result_page.indexOf('<form method="post"');
1142 if(sfp!=-1){
1143 sfe = result_page.indexOf('</form>', sfp);
1144 res.form_txt = result_page.substr(sfp, ( sfe - sfp )) + '</form>';
1145 }
1146 }else{
1147 //one more error type check:
1148 sp = result_page.indexOf('class="mw-warning-with-logexcerpt">')
1149 if(sp!=-1){
1150 se = result_page.indexOf('</div>', sp);
1151 res.error_txt = result_page.substr(sp, ( se - sp )) + '</div>';
1152 }
1153 }
1154 }
1155 return res;
1156 }
1157 //do a "normal" request
1158 function do_request(req_url, callback){
1159 js_log('do_request::req_url:' + req_url + ' != ' + parseUri( req_url).host);
1160 //if we are doing a request to the same domain or relative link do a normal GET:
1161 if( parseUri(document.URL).host == parseUri(req_url).host ||
1162 req_url.indexOf('://') == -1 ){ //relative url
1163 //do a direct request:
1164 $j.ajax({
1165 type: "GET",
1166 url:req_url,
1167 async: false,
1168 success:function(data){
1169 callback( data );
1170 }
1171 });
1172 }else{
1173 //get data via DOM injection with callback
1174 global_req_cb.push(callback);
1175 //prepend json_ to feed_format if not already requesting json format
1176 if( req_url.indexOf("feed_format=")!=-1 && req_url.indexOf("feed_format=json")==-1)
1177 req_url = req_url.replace(/feed_format=/, 'feed_format=json_');
1178 loadExternalJs( req_url + '&cb=mv_jsdata_cb&cb_inx=' + (global_req_cb.length-1));
1179 }
1180 }
1181
1182 function mv_jsdata_cb(response){
1183 js_log('f:mv_jsdata_cb:'+ response['cb_inx']);
1184 //run the callback from the global req cb object:
1185 if( !global_req_cb[response['cb_inx']] ){
1186 js_log('missing req cb index');
1187 return false;
1188 }
1189 if( !response['pay_load'] ){
1190 js_log("missing pay load");
1191 return false;
1192 }
1193 //switch on content type:
1194 switch(response['content-type']){
1195 case 'text/plain':
1196 break;
1197 case 'text/xml':
1198 if(typeof response['pay_load'] == 'string'){
1199 //js_log('load string:'+"\n"+ response['pay_load']);
1200 //debugger;
1201 //attempt to parse as xml for IE
1202 if( $j.browser.msie ){
1203 var xmldata=new ActiveXObject("Microsoft.XMLDOM");
1204 xmldata.async="false";
1205 xmldata.loadXML(response['pay_load']);
1206 }else{ //for others (firefox, safari etc)
1207 try{
1208 var xmldata = (new DOMParser()).parseFromString(response['pay_load'], "text/xml");
1209 }catch(e) {
1210 js_log('XML parse ERROR: ' + e.message);
1211 }
1212 }
1213 //@@todo hanndle xml parser errors
1214 if(xmldata)response['pay_load']=xmldata;
1215 }
1216 break
1217 default:
1218 js_log('bad response type' + response['content-type']);
1219 return false;
1220 break;
1221 }
1222 global_req_cb[response['cb_inx']]( response['pay_load'] );
1223 }
1224 //load external js via dom injection
1225 function loadExternalJs( url, callback ){
1226 js_log('load js: '+ url);
1227 //if(window['$j']) //use jquery call:
1228 /*$j.ajax({
1229 type: "GET",
1230 url: url,
1231 dataType: 'script',
1232 cache: true
1233 });*/
1234 // else{
1235 var e = document.createElement("script");
1236 e.setAttribute('src', url);
1237 e.setAttribute('type', "text/javascript");
1238 /*if(callback)
1239 e.onload = callback;
1240 */
1241 //e.setAttribute('defer', true);
1242 document.getElementsByTagName("head")[0].appendChild(e);
1243 // }
1244 }
1245 function styleSheetPresent(url){
1246 style_elements = document.getElementsByTagName('link');
1247 if( style_elements.length > 0) {
1248 for(i = 0; i < style_elements.length; i++) {
1249 if(style_elements[i].href == url)
1250 return true;
1251 }
1252 }
1253 return false;
1254 }
1255 function loadExternalCss(url){
1256 //if could have script loader group thes css request
1257 //but debatable it may hurt more than it helps with caching and all
1258 if(typeof url =='object'){
1259 for(var i in url){
1260 loadExternalCss ( url[i] );
1261 }
1262 return ;
1263 }
1264
1265 if( url.indexOf('?') == -1 ){
1266 url+='?'+getMvUniqueReqId();
1267 }
1268 if(!styleSheetPresent(url) ){
1269 js_log('load css: ' + url);
1270 var e = document.createElement("link");
1271 e.href = url;
1272 e.type = "text/css";
1273 e.rel = 'stylesheet';
1274 document.getElementsByTagName("head")[0].appendChild(e);
1275 }
1276 }
1277 function getMvEmbedURL(){
1278 if( _global['mv_embed_url'] )
1279 return _global['mv_embed_url'];
1280 var js_elements = document.getElementsByTagName("script");
1281 for(var i=0; i < js_elements.length; i++){
1282 //check for normal mv_embed.js and or script loader
1283 var src = js_elements[i].getAttribute("src");
1284 if( src ){
1285 if( src.indexOf('mv_embed.js') !=-1 || (
1286 ( src.indexOf('mwScriptLoader.php') != -1 || src.indexOf('jsScriptLoader.php') != -1 )
1287 && src.indexOf('mv_embed') != -1) ){ //(check for class=mv_embed script_loader call)
1288 _global['mv_embed_url'] = src;
1289 return src;
1290 }
1291 }
1292 }
1293 js_error('Error: getMvEmbedURL failed to get Embed Path');
1294 return false;
1295 }
1296 //gets a unique request id to ensure fresh javascript
1297 function getMvUniqueReqId(){
1298 if( _global['urid'] )
1299 return _global['urid'];
1300 var mv_embed_url = getMvEmbedURL();
1301 //if we have a uri retun that:
1302 var urid = parseUri( mv_embed_url).queryKey['urid']
1303 if( urid ){
1304 _global['urid'] = urid;
1305 return urid;
1306 }
1307 //if in debug mode get a fresh unique request key:
1308 if( parseUri( mv_embed_url ).queryKey['debug'] == 'true'){
1309 var d = new Date();
1310 var urid = d.getTime();
1311 _global['urid'] = urid;
1312 return urid;
1313 }
1314 //else just return the mv_embed version;
1315 return MV_EMBED_VERSION;
1316 }
1317 /*
1318 * sets the global mv_embed path based on the scripts location
1319 */
1320 function getMvEmbedPath(){
1321 if( _global['mv_embed_path'])
1322 return _global['mv_embed_path'];
1323 var mv_embed_url = getMvEmbedURL();
1324 if( mv_embed_url.indexOf('mv_embed.js') !== -1 ){
1325 mv_embed_path = mv_embed_url.substr(0, mv_embed_url.indexOf('mv_embed.js'));
1326 }else if(mv_embed_url.indexOf('mwScriptLoader.php')!==-1){
1327 //script load is in the root of mediaWiki so include the default mv_embed extention path (if using the script loader)
1328 mv_embed_path = mv_embed_url.substr(0, mv_embed_url.indexOf('mwScriptLoader.php')) + mediaWiki_mvEmbed_path ;
1329 }else{
1330 mv_embed_path = mv_embed_url.substr(0, mv_embed_url.indexOf('jsScriptLoader.php'));
1331 }
1332 //absolute the url (if relative) (if we don't have mv_embed path)
1333 if( mv_embed_path.indexOf('://') == -1){
1334 var pURL = parseUri( document.URL );
1335 if(mv_embed_path.charAt(0)=='/'){
1336 mv_embed_path = pURL.protocol + '://' + pURL.authority + mv_embed_path;
1337 }else{
1338 //relative:
1339 if(mv_embed_path==''){
1340 mv_embed_path = pURL.protocol + '://' + pURL.authority + pURL.directory + mv_embed_path;
1341 }
1342 }
1343 }
1344 _global['mv_embed_path'] = mv_embed_path;
1345 return mv_embed_path;
1346 }
1347
1348 if (typeof DOMParser == "undefined") {
1349 DOMParser = function () {}
1350 DOMParser.prototype.parseFromString = function (str, contentType) {
1351 if (typeof ActiveXObject != "undefined") {
1352 var d = new ActiveXObject("MSXML.DomDocument");
1353 d.loadXML(str);
1354 return d;
1355 } else if (typeof XMLHttpRequest != "undefined") {
1356 var req = new XMLHttpRequest;
1357 req.open("GET", "data:" + (contentType || "application/xml") +
1358 ";charset=utf-8," + encodeURIComponent(str), false);
1359 if (req.overrideMimeType) {
1360 req.overrideMimeType(contentType);
1361 }
1362 req.send(null);
1363 return req.responseXML;
1364 }
1365 }
1366 }
1367 /*
1368 * utility functions:
1369 */
1370 function js_log(string){
1371 if( window.console ){
1372 window.console.log(string);
1373 }else{
1374 /*
1375 * IE and non-firebug debug:
1376 */
1377 /*var log_elm = document.getElementById('mv_js_log');
1378 if(!log_elm){
1379 document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML +
1380 '<div style="position:absolute;z-index:500;top:0px;left:0px;right:0px;height:10px;">'+
1381 '<textarea id="mv_js_log" cols="120" rows="5"></textarea>'+
1382 '</div>';
1383
1384 var log_elm = document.getElementById('mv_js_log');
1385 }
1386 if(log_elm){
1387 log_elm.value+=string+"\n";
1388 }*/
1389 }
1390 return false;
1391 }
1392
1393 function checkDefaultMwConfig(){
1394 for(var i in defaultMwConfig){
1395 if(typeof(mwConfig[i])=='undefined'){
1396 mwConfig[i] =defaultMwConfig[i];
1397 }
1398 }
1399 }
1400
1401 function js_error(string){
1402 alert(string);
1403 return false;
1404 }