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