Index: branches/MwEmbedStandAlone/modules/TimedText/remotes/RemoteMwTimedText.js |
— | — | @@ -7,7 +7,8 @@ |
8 | 8 | |
9 | 9 | mw.addMessageKeys( [ |
10 | 10 | "mwe-timedtext-language-subtitles-for-clip", |
11 | | - "mwe-timedtext-language-no-subtitles-for-clip" |
| 11 | + "mwe-timedtext-language-no-subtitles-for-clip", |
| 12 | + "mwe-timedtext-all-subtitles" |
12 | 13 | ]); |
13 | 14 | |
14 | 15 | RemoteMwTimedText = function( options ) { |
— | — | @@ -52,20 +53,32 @@ |
53 | 54 | var _this = this; |
54 | 55 | // Load the player module: |
55 | 56 | mw.load( 'EmbedPlayer', function() { |
| 57 | + var width = ( resource.width > 500 )? 500 : resource.width; |
| 58 | + var height = width * ( resource.height / resource.width ); |
56 | 59 | // Add the embed code: ( jquery wrapping of "video" fails ) |
57 | | - $j( _this.target ).append( |
58 | | - $j( '<div class="videoLoading">').html( |
59 | | - '<video id="timed-text-player-embed" '+ |
60 | | - 'style="width:' + resource.width + 'px;height:' + resource.height + 'px;" '+ |
61 | | - 'class="kskin" ' + //We need to centrally store this config somewhere |
62 | | - 'poster="' + resource.poster + '" ' + |
63 | | - 'src="' + resource.src + '" ' + |
64 | | - 'apiTitleKey="' + resource.apiTitleKey + '" >' + |
65 | | - '</video><br><br><br><br>' |
66 | | - ) |
| 60 | + $j( _this.target ).empty().append( |
| 61 | + $j('<video />').attr({ |
| 62 | + 'id': "timed-text-player-embed", |
| 63 | + 'poster': resource.poster, |
| 64 | + 'src': resource.src, |
| 65 | + 'durationHint' : resource.duration, |
| 66 | + 'apiTitleKey' : resource.apiTitleKey |
| 67 | + }) |
| 68 | + .css({ |
| 69 | + 'width' : width + 'px', |
| 70 | + 'height' : height + 'px' |
| 71 | + }) |
| 72 | + .addClass( 'kskin' ) |
| 73 | + , |
| 74 | + $j('<div />').css({ |
| 75 | + 'position' : 'relative', |
| 76 | + 'left' : '510px', |
| 77 | + 'top' : -height + 'px' |
| 78 | + }) |
| 79 | + .append( _this.orgBody ) |
67 | 80 | ); |
68 | | - $j('.videoLoading').hide(); |
69 | | - // embed the player with the pre-selected langauge: |
| 81 | + |
| 82 | + // embed the player with the pre-selected language: |
70 | 83 | _this.embedPlayerLang(); |
71 | 84 | }); |
72 | 85 | }, |
— | — | @@ -135,35 +148,21 @@ |
136 | 149 | // Get all the embed details: |
137 | 150 | var request = { |
138 | 151 | 'titles' : 'File:' + fileTitle, |
139 | | - 'prop' : 'imageinfo|revisions', |
140 | | - 'iiprop' : 'url|mime|size', |
| 152 | + 'prop' : 'imageinfo|revisions|redirects', |
| 153 | + 'iiprop' : 'url|mime|size|metadata', |
141 | 154 | 'iiurlwidth' : mw.getConfig( 'EmbedPlayer.DefaultSize').split('x').pop(), |
142 | 155 | 'rvprop' : 'content' |
143 | 156 | } |
144 | 157 | // (only works for commons right now) |
145 | | - mw.getJSON( request, function( data ) { |
| 158 | + mw.getJSON( request, function( data ) { |
146 | 159 | // Check for "page not found" |
147 | 160 | if( data.query.pages['-1'] ) { |
148 | 161 | //restore content: |
149 | 162 | $j(_this.target).html( _this.orgBody ); |
150 | 163 | return ; |
151 | 164 | } |
152 | | - // Check for redirect |
153 | 165 | for ( var i in data.query.pages ) { |
154 | | - var page = data.query.pages[i]; |
155 | | - if ( page.revisions[0]['*'] && page.revisions[0]['*'].indexOf( '#REDIRECT' ) === 0 ) { |
156 | | - var re = new RegExp( /[^\[]*\[\[([^\]]*)/ ); |
157 | | - var pt = page.revisions[0]['*'].match( re ); |
158 | | - if ( pt[1] ) { |
159 | | - mw.log( 'found redirect tyring: ' + pt[1] ) |
160 | | - _this.embedByTitle( pt[1], callback); |
161 | | - return ; |
162 | | - } else { |
163 | | - mw.log( 'Error: getTitleResource could not process redirect' ); |
164 | | - callback( false ); |
165 | | - return false; |
166 | | - } |
167 | | - } |
| 166 | + var page = data.query.pages[i]; |
168 | 167 | mw.log( "should process data result" ); |
169 | 168 | // Else process the result |
170 | 169 | var resource = _this.getResource( page ); |
— | — | @@ -176,7 +175,7 @@ |
177 | 176 | * Get the embed code from response resource and sends it a callback |
178 | 177 | */ |
179 | 178 | getResource: function( page ) { |
180 | | - return { |
| 179 | + var resource = { |
181 | 180 | 'apiTitleKey' : page.title.replace(/File:/ig, '' ), |
182 | 181 | 'link' : page.imageinfo[0].descriptionurl, |
183 | 182 | 'poster' : page.imageinfo[0].thumburl, |
— | — | @@ -184,5 +183,13 @@ |
185 | 184 | 'width' : page.imageinfo[0].width, |
186 | 185 | 'height': page.imageinfo[0].height |
187 | 186 | }; |
| 187 | + // check metadata for length: |
| 188 | + for( var i=0; page.imageinfo[0].metadata.length < i ; i++ ){ |
| 189 | + var meta = page.imageinfo[0].metadata[i]; |
| 190 | + if( meta.name == 'length' ){ |
| 191 | + resource.duration = meta.value; |
| 192 | + } |
| 193 | + } |
| 194 | + return resource; |
188 | 195 | } |
189 | 196 | }; |