~allgowik/allgowik/allgowik

« back to all changes in this revision

Viewing changes to extensions/TimedMediaHandler/resources/mw.MediaWikiPlayerSupport.js

  • Committer: aj at fsf
  • Date: 2012-05-15 08:09:05 UTC
  • Revision ID: aj@member.fsf.org-20120515080905-msv272j12sk1apf5
Updated from git to commit I94bb2433d8944670a046588d85a19b73ae3280dc .

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
( function( mw, $ ) {
2
 
        /** 
 
2
        /**
3
3
         * Merge in the default video attributes supported by embedPlayer:
4
4
         */
5
5
        mw.mergeConfig( 'EmbedPlayer.Attributes', {
6
6
                // A apiTitleKey for looking up subtitles, credits and related videos
7
7
                "data-mwtitle" : null,
8
 
        
 
8
 
9
9
                // The apiProvider where to lookup the title key
10
10
                "data-mwprovider" : null
11
11
        });
12
 
        
13
 
        // Add mediaWiki player support to target embedPlayer 
 
12
 
 
13
        // Add mediaWiki player support to target embedPlayer
14
14
        $( mw ).bind( 'newEmbedPlayerEvent', function( event, embedPlayer ){
15
15
                mw.addMediaWikiPlayerSupport( embedPlayer );
16
16
        });
17
 
        
 
17
 
18
18
        /**
19
19
         * Closure function wraps mediaWiki embedPlayer bindings
20
20
         */
21
21
        mw.addMediaWikiPlayerSupport = function( embedPlayer ){
22
 
                // Set some local variables: 
23
 
                if( ! embedPlayer['data-mwtitle'] ){                    
 
22
                // Set some local variables:
 
23
                if( ! embedPlayer['data-mwtitle'] ){
24
24
                        return false;
25
25
                } else {
26
26
                        var apiTitleKey = embedPlayer['data-mwtitle'];
27
 
                        // legacy support ( set as attribute ) 
 
27
                        // legacy support ( set as attribute )
28
28
                        embedPlayer.apiTitleKey = apiTitleKey;
29
29
                }
30
30
                // Set local apiProvider via config if not defined
32
32
                if( !apiProvider ){
33
33
                        apiProvider = mw.getConfig( 'EmbedPlayer.ApiProvider' );
34
34
                }
35
 
                
 
35
 
36
36
                /**
37
37
                 * Loads mediaWiki sources for a given embedPlayer
38
 
                 * @param {function} callback Function called once player sources have been added 
 
38
                 * @param {function} callback Function called once player sources have been added
39
39
                 */
40
40
                function loadPlayerSources( callback ){
41
41
                        // Setup the request
68
68
                                        return ;
69
69
                                }
70
70
                                var imageinfo = page.imageinfo[0];
71
 
                                
72
 
                                // TODO these should call public methods rather than update internals: 
73
 
                                
 
71
 
 
72
                                // TODO these should call public methods rather than update internals:
 
73
 
74
74
                                // Update the poster
75
75
                                embedPlayer.poster = imageinfo.thumburl;
76
76
 
98
98
                                callback();
99
99
                        });
100
100
                }
101
 
        
 
101
 
102
102
 
103
103
                /**
104
104
                * Build a clip credit from the resource wikiText page
108
108
                * @param {String} resourceHTML Resource wiki text page contents
109
109
                */
110
110
                function doCreditLine( resourceHTML, articleUrl ){
111
 
                        // Get the title string ( again a "Title" like js object could help out here. )                 
 
111
                        // Get the title string ( again a "Title" like js object could help out here. )
112
112
                        var titleStr = embedPlayer.apiTitleKey.replace(/_/g, ' ');
113
 
                        
 
113
 
114
114
                        // Setup the initial credits line:
115
 
                        var $creditLine = $( '<div />');                
116
 
                        
117
 
                        // Add the title: 
 
115
                        var $creditLine = $( '<div />');
 
116
 
 
117
                        // Add the title:
118
118
                        $creditLine.append(
119
119
                                $('<span>').html(
120
120
                                        gM( 'mwe-embedplayer-credit-title' ,
124
124
                                                                'href' : articleUrl,
125
125
                                                                'title' : titleStr
126
126
                                                        })
127
 
                                                        .text( titleStr )                                                       
 
127
                                                        .text( titleStr )
128
128
                                                ).html()
129
129
                                        )
130
130
                                )
131
131
                        );
132
 
                        
133
 
                        // Parse some data from the page info template if possible:                     
 
132
 
 
133
                        // Parse some data from the page info template if possible:
134
134
                        var $page = $( resourceHTML );
135
 
                        
 
135
 
136
136
                        // Look for author:
137
137
                        var $author = $page.find('#fileinfotpl_aut');
138
138
                        if( $author.length ){
139
 
                                // Get the real author sibling of fileinfotpl_aut 
 
139
                                // Get the real author sibling of fileinfotpl_aut
140
140
                                $author = $author.next().find('p');
141
141
                                // Remove white space:
142
142
                                $author.find('br').remove();
143
 
                                
144
 
                                // Update link to be absolute per page url context: 
 
143
 
 
144
                                // Update link to be absolute per page url context:
145
145
                                var $links = $author.find('a');
146
146
                                if( $links.length ) {
147
147
                                        var authUrl = $author.find('a').attr('href');
148
148
                                        authUrl = mw.absoluteUrl( authUrl,  articleUrl );
149
 
                                        $author.find('a').attr('href', 
 
149
                                        $author.find('a').attr('href',
150
150
                                                authUrl
151
151
                                        )
152
152
                                }
154
154
                                        gM('mwe-embedplayer-credit-author', $author.html() )
155
155
                                )
156
156
                        }
157
 
                        
 
157
 
158
158
                        // Look for date:
159
159
                        var $date =$page.find('#fileinfotpl_date');
160
160
                        if( $date.length ){
161
 
                                // Get the real date sibling of fileinfotpl_date 
 
161
                                // Get the real date sibling of fileinfotpl_date
162
162
                                $date = $date.next().find('p');
163
 
                                
 
163
 
164
164
                                // remove white space:
165
165
                                $date.find('br').remove();
166
166
                                $creditLine.append(  $( '<br />' ),
167
167
                                        gM('mwe-embedplayer-credit-date', $date.html() )
168
168
                                )
169
169
                        }
170
 
                        
 
170
 
171
171
 
172
172
                        // Build out the image and credit line
173
173
                        var imgWidth = ( embedPlayer.controlBuilder.getOverlayWidth() < 250 )? 45 : 120;
189
189
                                        $creditLine
190
190
                                );
191
191
                };
192
 
                
 
192
 
193
193
                /**
194
194
                 * Issues a request to populate the credits box
195
195
                 */
203
203
                        // Setup shortcuts:
204
204
                        var apiUrl = mw.getApiProviderURL( apiProvider );
205
205
                        var fileTitle = 'File:' + unescape( apiTitleKey).replace(/^File:|^Image:/, '');
206
 
                        
 
206
 
207
207
                        // Get the image page ( cache for 1 hour )
208
208
                        var request = {
209
209
                                'action': 'parse',
216
216
                                descUrl = apiUrl.replace( 'api.php', 'index.php');
217
217
                                descUrl+= '?title=' + fileTitle;
218
218
                                if ( data && data.parse && data.parse.text && data.parse.text['*'] ) {
219
 
                                        // TODO improve provider 'concept' to support page title link 
 
219
                                        // TODO improve provider 'concept' to support page title link
220
220
                                        $creditsCache = doCreditLine( data.parse.text['*'], descUrl );
221
221
                                } else {
222
222
                                        $creditsCache = doCreditLine( false, descUrl)
227
227
                };
228
228
                /**
229
229
                 * Adds embedPlayer Bindings
230
 
                 */                             
 
230
                 */
231
231
                // Show credits when requested
232
232
                $( embedPlayer ).bind('ShowCredits', function( event, $target, callback){
233
 
                        // Only request the credits once: 
234
 
                        showCredits( $target, callback);                        
 
233
                        // Only request the credits once:
 
234
                        showCredits( $target, callback);
235
235
                });
236
 
                                
 
236
 
237
237
                $( embedPlayer ).bind( 'checkPlayerSourcesEvent', function(event, callback){
238
238
                        // Only load source if none are available:
239
239
                        if( embedPlayer.mediaElement.sources.length == 0 ){
244
244
                        }
245
245
                });
246
246
                $( embedPlayer ).bind( 'getShareIframeSrc', function(event, callback){
247
 
                        // Check the embedPlayer title key: 
 
247
                        // Check the embedPlayer title key:
248
248
                        var title =  $( embedPlayer).attr( 'data-mwtitle');
249
249
                        // TODO Check the provider key and use that hosts title page entry point!
250
250
                        var provider =  $( embedPlayer).attr( 'data-mwprovider');
251
251
                        var iframeUrl = false;
252
252
                        if( mw.getConfig('wgServer') && mw.getConfig('wgArticlePath') ){
253
 
                                iframeUrl =  mw.getConfig('wgServer') + 
254
 
                                        mw.getConfig('wgArticlePath').replace( /\$1/, 'File:' + 
 
253
                                iframeUrl =  mw.getConfig('wgServer') +
 
254
                                        mw.getConfig('wgArticlePath').replace( /\$1/, 'File:' +
255
255
                                                unescape( embedPlayer.apiTitleKey ).replace( /^(File:|Image:)/ , '' ) ) +
256
256
                                        '?' + 'embedplayer=yes';
257
257
                        }
258
 
                        
 
258
 
259
259
                        callback( iframeUrl );
260
260
                });
261
261
        };
262
 
                
 
262
 
263
263
} )( window.mediaWiki, window.jQuery );