Index: branches/js2-work/phase3/js2/mwEmbed/libEmbedPlayer/embedPlayer.js |
— | — | @@ -1266,7 +1266,7 @@ |
1267 | 1267 | if ( this.roe && this.media_element.sources.length == 0 ) { |
1268 | 1268 | mw.log( 'checkPlayerSources: loading external data' ); |
1269 | 1269 | this.loading_external_data = true; |
1270 | | - do_request( this.roe, function( data ){ |
| 1270 | + mw.getMvJsonUrl( this.roe, function( data ){ |
1271 | 1271 | // Continue |
1272 | 1272 | _this.media_element.addROE( data ); |
1273 | 1273 | mw.log( 'added_roe::' + _this.media_element.sources.length ); |
— | — | @@ -1658,8 +1658,7 @@ |
1659 | 1659 | ) |
1660 | 1660 | // now load roe if run the showNextPrevLinks |
1661 | 1661 | if ( this.roe && this.media_element.addedROEData == false ) { |
1662 | | - do_request( this.roe, function( data ) |
1663 | | - { |
| 1662 | + mw.getMvJsonUrl( this.roe, function( data ){ |
1664 | 1663 | _this.media_element.addROE( data ); |
1665 | 1664 | _this.getNextPrevLinks(); |
1666 | 1665 | } ); |
— | — | @@ -1718,7 +1717,7 @@ |
1719 | 1718 | mw.log( 'anno data found in cache: ' + request_key ); |
1720 | 1719 | this.showNextPrevLinks(); |
1721 | 1720 | } else { |
1722 | | - do_request( new_anno_track_url, function( cmml_data ) { |
| 1721 | + mw.getMvJsonUrl( new_anno_track_url, function( cmml_data ) { |
1723 | 1722 | mw.log( 'raw response: ' + cmml_data ); |
1724 | 1723 | if ( typeof cmml_data == 'string' ) { |
1725 | 1724 | var parser = new DOMParser(); |
— | — | @@ -2154,7 +2153,7 @@ |
2155 | 2154 | if ( ! this.linkback && this.roe && this.media_element.addedROEData == false ) { |
2156 | 2155 | var _this = this; |
2157 | 2156 | this.displayHTML( gM( 'mwe-loading_txt' ) ); |
2158 | | - do_request( this.roe, function( data ) { |
| 2157 | + mw.getMvJsonUrl( this.roe, function( data ) { |
2159 | 2158 | _this.media_element.addROE( data ); |
2160 | 2159 | _this.doLinkBack(); |
2161 | 2160 | } ); |
— | — | @@ -2422,7 +2421,7 @@ |
2423 | 2422 | if ( this.roe && this.media_element.addedROEData == false ) { |
2424 | 2423 | var _this = this; |
2425 | 2424 | $target.html( gM( 'loading_txt' ) ); |
2426 | | - do_request( this.roe, function( data ) { |
| 2425 | + mw.getMvJsonUrl( this.roe, function( data ) { |
2427 | 2426 | _this.media_element.addROE( data ); |
2428 | 2427 | $target.html( getShowVideoDownload() ); |
2429 | 2428 | } ); |
Index: branches/js2-work/phase3/js2/mwEmbed/libSequencer/mvPlayList.js |
— | — | @@ -302,7 +302,7 @@ |
303 | 303 | var pl_parent = this; |
304 | 304 | this.makeURLAbsolute(); |
305 | 305 | if ( this.src != null ) { |
306 | | - do_request( this.src, function( data ) { |
| 306 | + mw.getMvJsonUrl( this.src, function( data ) { |
307 | 307 | pl_parent.data = data; |
308 | 308 | pl_parent.getSourceType(); |
309 | 309 | } ); |
Index: branches/js2-work/phase3/js2/mwEmbed/mwEmbed.js |
— | — | @@ -1130,17 +1130,29 @@ |
1131 | 1131 | mw.log("run getJSON: " + url + ' data: ' + data); |
1132 | 1132 | // Pass off the jQuery getJSON request: |
1133 | 1133 | $j.getJSON( url, data, callback ); |
1134 | | - } |
1135 | | - |
1136 | | - |
| 1134 | + } |
| 1135 | + |
1137 | 1136 | /** |
| 1137 | + * Metavid spefic helper funtion will be factored out eventually. |
| 1138 | + * @param roe_url to be updated |
| 1139 | + */ |
| 1140 | + $.getMvJsonUrl = function( roe_url , callback){ |
| 1141 | + if ( mw.parseUri( document.URL ).host == mw.parseUri( roe_url ).host || |
| 1142 | + roe_url.indexOf( '://' ) == -1 ){ |
| 1143 | + $j.get( roe_url, callback ); |
| 1144 | + } else { |
| 1145 | + $j.getJSON( roe_url + '&feed_format=json&cb=?&cb_inx=1', callback ); |
| 1146 | + } |
| 1147 | + |
| 1148 | + } |
| 1149 | + /** |
1138 | 1150 | * Simple api helper to grab an edit token |
1139 | 1151 | * |
1140 | 1152 | * @param title The wiki page title you want to edit |
1141 | 1153 | * @param {String} [api_url] The target API URL |
1142 | 1154 | * @param {callback} callback Function to pass the token to |
1143 | 1155 | */ |
1144 | | - mw.getToken( title, api_url, callback ) { |
| 1156 | + $.getToken = function( title, api_url, callback ) { |
1145 | 1157 | if( typeof api_url == 'function' ) |
1146 | 1158 | callback = api_url; |
1147 | 1159 | if( typeof title == 'function') |
— | — | @@ -2499,65 +2511,11 @@ |
2500 | 2512 | } |
2501 | 2513 | } )( jQuery ); |
2502 | 2514 | } |
2503 | | -/* |
2504 | | -* Utility functions: |
| 2515 | + |
| 2516 | +/** |
| 2517 | +* Utility functions that override globals |
2505 | 2518 | */ |
2506 | 2519 | |
2507 | | -// Do a metavid callback request: |
2508 | | -// NOTE: this contains metavid specific local vs remote api remapping will be removed shortly |
2509 | | -// this should be depreciated and we should use "$j.get" or an api call |
2510 | | -// (we should not mix the two request types) |
2511 | | -function do_request( req_url, callback ) { |
2512 | | - mw.log( 'do_request::req_url:' + mw.parseUri( document.URL ) + ' != ' + mw.parseUri( req_url ).host ); |
2513 | | - // If we are doing a request to the same domain or relative link, do a normal GET |
2514 | | - if ( mw.parseUri( document.URL ).host == mw.parseUri( req_url ).host || |
2515 | | - req_url.indexOf( '://' ) == -1 ){ // if its a relative url go directly as well |
2516 | | - // Do a direct request |
2517 | | - $j.ajax( { |
2518 | | - type: "GET", |
2519 | | - url: req_url, |
2520 | | - async: false, |
2521 | | - success: function( data ) { |
2522 | | - callback( data ); |
2523 | | - } |
2524 | | - } ); |
2525 | | - } else { |
2526 | | - // Get data via DOM injection with callback |
2527 | | - global_req_cb.push( callback ); |
2528 | | - // Prepend json_ to feed_format if not already requesting json format (metavid specific) |
2529 | | - if ( req_url.indexOf( "feed_format=" ) != -1 && req_url.indexOf( "feed_format=json" ) == -1 ) |
2530 | | - req_url = req_url.replace( /feed_format=/, 'feed_format=json_' ); |
2531 | | - $j.getScript( req_url + '&cb=mv_jsdata_cb&cb_inx=' + ( global_req_cb.length -1 ) ); |
2532 | | - } |
2533 | | -} |
2534 | | - |
2535 | | -function mv_jsdata_cb( response ) { |
2536 | | - mw.log( 'f:mv_jsdata_cb:' + response['cb_inx'] ); |
2537 | | - // Run the callback from the global request callback object |
2538 | | - if ( !global_req_cb[response['cb_inx']] ) { |
2539 | | - mw.log( 'missing req cb index' ); |
2540 | | - return false; |
2541 | | - } |
2542 | | - if ( !response['pay_load'] ) { |
2543 | | - mw.log( "missing pay load" ); |
2544 | | - return false; |
2545 | | - } |
2546 | | - switch( response['content-type'] ) { |
2547 | | - case 'text/plain': |
2548 | | - break; |
2549 | | - case 'text/xml': |
2550 | | - if ( typeof response['pay_load'] == 'string' ) { |
2551 | | - response['pay_load'] = mw.parseXML( response['pay_load'] ); |
2552 | | - } |
2553 | | - break |
2554 | | - default: |
2555 | | - mw.log( 'bad response type' + response['content-type'] ); |
2556 | | - return false; |
2557 | | - break; |
2558 | | - } |
2559 | | - global_req_cb[response['cb_inx']]( response['pay_load'] ); |
2560 | | -} |
2561 | | - |
2562 | 2520 | if ( typeof DOMParser == "undefined" ) { |
2563 | 2521 | DOMParser = function () { } |
2564 | 2522 | DOMParser.prototype.parseFromString = function ( str, contentType ) { |
— | — | @@ -2577,7 +2535,4 @@ |
2578 | 2536 | } |
2579 | 2537 | } |
2580 | 2538 | } |
2581 | | -/* |
2582 | | -* Utility functions |
2583 | | -*/ |
2584 | 2539 | |
Index: branches/js2-work/phase3/js2/mwEmbed/libTimedText/mvTextInterface.js |
— | — | @@ -40,8 +40,7 @@ |
41 | 41 | if ( !this.pe.media_element.addedROEData ) { |
42 | 42 | $j( '#mv_txt_load_' + _this.pe.id ).show(); // show the loading icon |
43 | 43 | if ( _this.pe.roe ) { |
44 | | - do_request( _this.pe.roe, function( data ) |
45 | | - { |
| 44 | + mw.getMvJsonUrl( _this.pe.roe, function( data ){ |
46 | 45 | _this.pe.media_element.addROE( data ); |
47 | 46 | _this.getParseTimedText_rowReady(); |
48 | 47 | } ); |
— | — | @@ -568,7 +567,7 @@ |
569 | 568 | // check for urls without time keys: |
570 | 569 | if ( typeof pcurl.queryKey['t'] == 'undefined' ) { |
571 | 570 | // in which case just get the full time req: |
572 | | - do_request( this.getSRC(), function( data ) { |
| 571 | + mw.getMvJsonUrl( this.getSRC(), function( data ) { |
573 | 572 | _this.doParse( data ); |
574 | 573 | _this.loaded = true; |
575 | 574 | callback(); |
— | — | @@ -592,7 +591,7 @@ |
593 | 592 | url += 't=' + mw.seconds2npt( req_time[0] ) + '/' + mw.seconds2npt( req_time[1] ) + '&'; |
594 | 593 | } |
595 | 594 | } ); |
596 | | - do_request( url, function( data ) { |
| 595 | + mw.getMvJsonUrl( url, function( data ) { |
597 | 596 | mw.log( "load track clip count:" + data.getElementsByTagName( 'clip' ).length ); |
598 | 597 | _this.doParse( data ); |
599 | 598 | _this.loaded = true; |
— | — | @@ -625,7 +624,7 @@ |
626 | 625 | var _this = this; |
627 | 626 | mw.log( 'textSRT: loading : ' + _this.getSRC() ); |
628 | 627 | if ( _this.getSRC() ) { |
629 | | - do_request( _this.getSRC() , function( data ) { |
| 628 | + mw.getMvJsonUrl( _this.getSRC() , function( data ) { |
630 | 629 | _this.doParse( data ); |
631 | 630 | _this.loaded = true; |
632 | 631 | callback(); |