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