Index: trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/baseRemoteSearch.js |
— | — | @@ -5,7 +5,7 @@ |
6 | 6 | loadGM( { |
7 | 7 | "mwe-imported_from" : "$1 imported from [$2 $3]. See the original [$4 resource page] for more information.", |
8 | 8 | "mwe-import-description" : "$1, imported from $2" |
9 | | -} ) |
| 9 | +} ); |
10 | 10 | |
11 | 11 | /* |
12 | 12 | * rsd_default_rss_item_mapping |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | 'desc' : 'description', |
35 | 35 | // multiple items |
36 | 36 | 'category' : '.media:category@label|url' |
37 | | -} |
| 37 | +}; |
38 | 38 | |
39 | 39 | var baseRemoteSearch = function( iObj ) { |
40 | 40 | return this.init( iObj ); |
— | — | @@ -114,6 +114,10 @@ |
115 | 115 | // Add pointer to parent search obj:( this.cp.limit )? this.cp.limit : this.limit, |
116 | 116 | |
117 | 117 | rObj['pSobj'] = _this; |
| 118 | + |
| 119 | + // Set target_resource_title |
| 120 | + _this.updateTargetResourceTitle( rObj ); |
| 121 | + |
118 | 122 | // add the result to the result set: |
119 | 123 | _this.resultsObj[ inx ] = rObj; |
120 | 124 | _this.num_results++; |
— | — | @@ -283,7 +287,7 @@ |
284 | 288 | return ''; |
285 | 289 | }, |
286 | 290 | /** |
287 | | - * Get the licence wikiText tag for a given resource Object. |
| 291 | + * Get the license wikiText tag for a given resource Object. |
288 | 292 | * |
289 | 293 | * By default license permission wiki text is cc based template mapping |
290 | 294 | * (does not confirm the templates actually exist) |
— | — | @@ -370,7 +374,7 @@ |
371 | 375 | * Updates / normalizes the target_resource_title |
372 | 376 | */ |
373 | 377 | updateTargetResourceTitle:function( rObj ) { |
374 | | - rObj.target_resource_title = rObj.titleKey.replace( / File: | Image: / , '' ); |
| 378 | + rObj.target_resource_title = rObj.titleKey.replace( /^(File:|Image:)/ , '' ); |
375 | 379 | rObj.target_resource_title = this.cp.resource_prefix + rObj.target_resource_title; |
376 | 380 | } |
377 | 381 | } |
Index: trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/archiveOrgSearch.js |
— | — | @@ -83,7 +83,7 @@ |
84 | 84 | 'src' : _this.downloadUrl + resource.identifier + '/format=Ogg+video', |
85 | 85 | 'mime' : 'application/ogg', |
86 | 86 | // Set the license: (rsd is a pointer to the parent remoteSearchDriver ) |
87 | | - 'license' : this.rsd.getLicenceFromUrl( resource.licenseurl ), |
| 87 | + 'license' : this.rsd.getLicenseFromUrl( resource.licenseurl ), |
88 | 88 | 'pSobj' :_this |
89 | 89 | |
90 | 90 | }; |
— | — | @@ -127,4 +127,4 @@ |
128 | 128 | return '<video ' + id_attr + ' src="' + src + '" poster="' + rObj.poster + '" type="video/ogg"></video>'; |
129 | 129 | } |
130 | 130 | } |
131 | | -} |
\ No newline at end of file |
| 131 | +} |
Index: trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/metavidSearch.js |
— | — | @@ -66,7 +66,7 @@ |
67 | 67 | rObj['stream_name'] = proe.queryKey['stream_name']; |
68 | 68 | |
69 | 69 | // All metavid content is public domain: |
70 | | - rObj['license'] = _this.rsd.getLicenceFromKey( 'pd' ); |
| 70 | + rObj['license'] = _this.rsd.getLicenseFromKey( 'pd' ); |
71 | 71 | |
72 | 72 | // Transform the title into a wiki_safe title: |
73 | 73 | rObj['titleKey'] = _this.getTitleKey( rObj ); |
Index: trunk/phase3/js2/mwEmbed/libAddMedia/searchLibs/flickrSearch.js |
— | — | @@ -19,10 +19,10 @@ |
20 | 20 | dtUrl : 'http://www.flickr.com/photos/', |
21 | 21 | // @@todo probably would be good to read the api-key from configuration |
22 | 22 | apikey : '2867787a545cc66c0bce6f2e57aca1d1', |
23 | | - // What licence we are interested in |
24 | | - _licence_keys: '4,5,7,8', |
| 23 | + // What license we are interested in |
| 24 | + _license_keys: '4,5,7,8', |
25 | 25 | _srctypes: ['t', 'sq', 's', 'm', 'o'], |
26 | | - licenceMap: { |
| 26 | + licenseMap: { |
27 | 27 | '4' : 'http://creativecommons.org/licenses/by/3.0/', |
28 | 28 | '5' : 'http://creativecommons.org/licenses/by-sa/3.0/', |
29 | 29 | '7' : 'http://www.flickr.com/commons/usage/', |
— | — | @@ -53,7 +53,7 @@ |
54 | 54 | var reqObj = { |
55 | 55 | 'method':'flickr.photos.search', |
56 | 56 | 'format':'json', |
57 | | - 'license':this._licence_keys, |
| 57 | + 'license':this._license_keys, |
58 | 58 | 'api_key':this.apikey, |
59 | 59 | 'per_page': this.cp.limit, |
60 | 60 | 'page' : this.cp.offset, |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | } |
84 | 84 | for ( var resource_id in data.photos.photo ) { |
85 | 85 | var sourceResource = data.photos.photo[ resource_id ]; |
86 | | - var rObj = _this.getResourceObjet( sourceResource ); |
| 86 | + var rObj = _this.getResourceObject( sourceResource ); |
87 | 87 | _this.resultsObj[ resource_id ] = rObj; |
88 | 88 | } |
89 | 89 | } |
— | — | @@ -90,7 +90,7 @@ |
91 | 91 | /** |
92 | 92 | * Gets an individual resource object from a given source Resource |
93 | 93 | */ |
94 | | - getResourceObjet: function( resource ){ |
| 94 | + getResourceObject: function( resource ){ |
95 | 95 | var _this = this; |
96 | 96 | var rObj = { |
97 | 97 | 'titleKey' : resource.title + '.jpg', |
— | — | @@ -101,7 +101,7 @@ |
102 | 102 | 'thumbheight': resource.height_t, |
103 | 103 | 'desc' : resource.title, |
104 | 104 | // Set the license |
105 | | - 'license' : this.rsd.getLicenceFromUrl( _this.licenceMap[ resource.license ] ), |
| 105 | + 'license' : this.rsd.getLicenceFromUrl( _this.licenseMap[ resource.license ] ), |
106 | 106 | 'pSobj' : _this, |
107 | 107 | // Assume image/jpeg for flickr response |
108 | 108 | 'mime' : 'image/jpeg' |
— | — | @@ -169,4 +169,4 @@ |
170 | 170 | return 's'; |
171 | 171 | |
172 | 172 | } |
173 | | -} |
\ No newline at end of file |
| 173 | +} |
Index: trunk/phase3/js2/mwEmbed/libAddMedia/remoteSearchDriver.js |
— | — | @@ -1,6 +1,6 @@ |
2 | 2 | /* |
3 | 3 | * remoteSearchDriver |
4 | | - * Provides a base interface for the Add-Media-Wizard |
| 4 | + * Provides a base interface for the Add-Media-Wizard |
5 | 5 | * supporting remote searching of http archives for free images/audio/video assets |
6 | 6 | */ |
7 | 7 | |
— | — | @@ -51,60 +51,59 @@ |
52 | 52 | "mwe-ftype-oga" : "Ogg audio file", |
53 | 53 | "mwe-ftype-ogg" : "Ogg video file", |
54 | 54 | "mwe-ftype-unk" : "Unknown file format", |
55 | | - |
| 55 | + |
56 | 56 | "rsd-wiki_commons-title": "Wikimedia Commons", |
57 | 57 | "rsd-wiki_commons": "Wikimedia Commons, an archive of freely-licensed educational media content (images, sound and video clips)", |
58 | | - |
| 58 | + |
59 | 59 | "rsd-this_wiki-title" : "This wiki", |
60 | 60 | "rsd-this_wiki-desc" : "The local wiki install", |
61 | | - |
| 61 | + |
62 | 62 | "rsd-archive_org-title": "Archive.org", |
63 | 63 | "rsd-archive_org-desc" : "The Internet Archive, a digital library of cultural artifacts", |
64 | | - |
| 64 | + |
65 | 65 | "rsd-flickr-title" : "Flickr.com", |
66 | 66 | "rsd-flickr-desc" : "Flickr.com, a online photo sharing site", |
67 | 67 | "rsd-metavid-title" : "Metavid.org", |
68 | 68 | "rsd-metavid-desc" : "Metavid.org, a community archive of US House and Senate floor proceedings" |
69 | | - |
| 69 | + |
70 | 70 | } ); |
71 | 71 | |
72 | 72 | var default_remote_search_options = { |
73 | | - 'profile':'mediawiki_edit', |
74 | | - 'target_container':null, // the div that will hold the search interface |
| 73 | + 'profile': 'mediawiki_edit', |
| 74 | + 'target_container': null, // the div that will hold the search interface |
75 | 75 | |
76 | | - 'target_invocation': null, // the button or link that will invoke the search interface |
| 76 | + 'target_invoke_button': null, // the button or link that will invoke the search interface |
77 | 77 | |
78 | | - 'default_provider_id':'all', // all or one of the content_providers ids |
| 78 | + 'default_provider_id': 'all', // all or one of the content_providers ids |
79 | 79 | |
80 | | - 'caret_pos':null, |
81 | | - 'local_wiki_api_url':null, |
| 80 | + 'local_wiki_api_url': null, |
82 | 81 | |
83 | 82 | // Can be 'api', 'autodetect', 'remote_link' |
84 | 83 | 'import_url_mode': 'api', |
85 | 84 | |
86 | | - 'target_title':null, |
87 | | - |
| 85 | + 'target_title': null, |
| 86 | + |
88 | 87 | // Edit tools (can be an array of tools or keyword 'all') |
89 | | - 'enabled_tools' : 'all', |
90 | | - |
| 88 | + 'enabled_tools': 'all', |
91 | 89 | |
92 | | - 'target_textbox':null, |
| 90 | + |
| 91 | + 'target_textbox': null, |
93 | 92 | 'target_render_area': null, // where output render should go: |
94 | 93 | 'instance_name': null, // a globally accessible callback instance name |
95 | | - 'default_query':null, // default search query |
| 94 | + 'default_query': null, // default search query |
96 | 95 | |
97 | 96 | // Specific to sequence profile |
98 | | - 'p_seq':null, |
99 | | - 'cFileNS':'File', // What is the canonical namespace prefix for images |
100 | | - // @@todo (should get that from the api or in-page vars) |
| 97 | + 'p_seq': null, |
| 98 | + 'cFileNS': 'File', // What is the canonical namespace prefix for images |
| 99 | + // @@todo (should get that from the api or in-page vars) |
101 | 100 | |
102 | 101 | 'upload_api_target': 'local', // can be local or the url or remote |
103 | | - 'upload_api_name' : null, |
| 102 | + 'upload_api_name': null, |
104 | 103 | 'upload_api_proxy_frame': null, // a page that will request mw.proxy.server |
105 | 104 | |
106 | | - 'enabled_cps':'all', // can be keyword 'all' or an array of enabled content provider keys |
| 105 | + 'enabled_providers': 'all', // can be keyword 'all' or an array of enabled content provider keys |
107 | 106 | |
108 | | - 'disp_item':null // sets the default display item: |
| 107 | + 'currentProvider': null // sets the default display item: |
109 | 108 | } |
110 | 109 | |
111 | 110 | if ( typeof wgServer == 'undefined' ) |
— | — | @@ -115,14 +114,20 @@ |
116 | 115 | stylepath = ''; |
117 | 116 | |
118 | 117 | /* |
119 | | - * Base remoteSearch Driver interface |
| 118 | + * Base remoteSearch Driver interface |
120 | 119 | */ |
121 | 120 | var remoteSearchDriver = function( iObj ) { |
122 | 121 | return this.init( iObj ); |
123 | 122 | } |
| 123 | + |
124 | 124 | remoteSearchDriver.prototype = { |
125 | | - results_cleared:false, |
| 125 | + results_cleared: false, |
| 126 | + |
| 127 | + caretPos: null, // lazy initialised |
| 128 | + textboxValue: null, // lazy initialised |
| 129 | + |
126 | 130 | // here we define the set of possible media content providers: |
| 131 | + // FIXME: unused |
127 | 132 | main_search_options: { |
128 | 133 | 'selprovider': { |
129 | 134 | 'title': 'Select Providers' |
— | — | @@ -131,6 +136,7 @@ |
132 | 137 | 'title': 'Advanced Options' |
133 | 138 | } |
134 | 139 | }, |
| 140 | + |
135 | 141 | /** the default content providers list. |
136 | 142 | * |
137 | 143 | * (should be note that special tabs like "upload" and "combined" don't go into the content providers list: |
— | — | @@ -145,15 +151,15 @@ |
146 | 152 | |
147 | 153 | @enabled: whether the search provider can be selected |
148 | 154 | @checked: whether the search provider will show up as selectable tab |
149 | | - @d: default: if the current cp should be displayed (only one should be the default) |
150 | | - @title: the title of the search provider |
151 | | - @desc: can use html |
| 155 | + @default: default: if the current cp should be displayed (only one should be the default) |
| 156 | + @title: the title of the search provider |
| 157 | + @desc: can use html |
152 | 158 | @api_url: the url to query against given the library type: |
153 | | - @lib: the search library to use corresponding to the |
154 | | - search object ie: 'mediaWiki' = new mediaWikiSearchSearch() |
| 159 | + @lib: the search library to use corresponding to the |
| 160 | + search object ie: 'mediaWiki' = new mediaWikiSearchSearch() |
155 | 161 | @tab_img: the tab image (if set to false use title text) |
156 | | - if === "ture" use standard location skin/images/{cp_id}_tab.png |
157 | | - if === string use as url for image |
| 162 | + if === "true" use standard location skin/images/{cp_id}_tab.png |
| 163 | + if === string use as url for image |
158 | 164 | |
159 | 165 | @linkback_icon default is: /wiki/skins/common/images/magnify-clip.png |
160 | 166 | |
— | — | @@ -162,160 +168,85 @@ |
163 | 169 | @local_domains : sets of domains for which the content is local |
164 | 170 | //@@todo should query wgForeignFileRepos setting maybe interwikimap from the api |
165 | 171 | */ |
166 | | - |
| 172 | + |
167 | 173 | 'this_wiki': { |
168 | 174 | 'enabled': 1, |
169 | 175 | 'checked': 1, |
170 | | - 'api_url': ( wgServer && wgScriptPath ) ? wgServer + wgScriptPath + '/api.php': null, |
171 | | - 'lib' : 'mediaWiki', |
172 | | - 'local' : true, |
| 176 | + 'api_url': ( wgServer && wgScriptPath ) ? |
| 177 | + wgServer + wgScriptPath + '/api.php' : null, |
| 178 | + 'lib': 'mediaWiki', |
| 179 | + 'local': true, |
173 | 180 | 'tab_img': false |
174 | 181 | }, |
175 | 182 | 'wiki_commons': { |
176 | 183 | 'enabled': 1, |
177 | 184 | 'checked': 1, |
178 | 185 | 'homepage': 'http://commons.wikimedia.org/wiki/Main_Page', |
179 | | - 'api_url':'http://commons.wikimedia.org/w/api.php', |
180 | | - 'lib' :'mediaWiki', |
| 186 | + 'api_url': 'http://commons.wikimedia.org/w/api.php', |
| 187 | + 'lib': 'mediaWiki', |
181 | 188 | 'resource_prefix': 'WC_', // prefix on imported resources (not applicable if the repository is local) |
182 | 189 | |
183 | 190 | // if we should check for shared repository asset ( generally only applicable to commons ) |
184 | | - 'check_shared':true, |
| 191 | + 'check_shared': true, |
185 | 192 | |
186 | 193 | // list all the domains where commons is local? |
187 | 194 | // probably should set this some other way by doing an api query |
188 | 195 | // or by seeding this config when calling the remote search? |
189 | | - 'local_domains': ['wikimedia', 'wikipedia', 'wikibooks'], |
| 196 | + 'local_domains': [ 'wikimedia', 'wikipedia', 'wikibooks' ], |
190 | 197 | // specific to wiki commons config: |
191 | | - 'search_title':false, // disable title search |
192 | | - 'tab_img':true |
| 198 | + 'search_title': false, // disable title search |
| 199 | + 'tab_img': true |
193 | 200 | }, |
194 | 201 | 'archive_org': { |
195 | | - 'enabled':1, |
196 | | - 'checked':1, |
197 | | - 'homepage':'http://www.archive.org/about/about.php', |
| 202 | + 'enabled': 1, |
| 203 | + 'checked': 1, |
| 204 | + 'homepage': 'http://www.archive.org/about/about.php', |
198 | 205 | |
199 | | - 'api_url':'http://homeserver7.us.archive.org:8983/solr/select', |
200 | | - 'lib' : 'archiveOrg', |
201 | | - 'local' : false, |
| 206 | + 'api_url': 'http://homeserver7.us.archive.org:8983/solr/select', |
| 207 | + 'lib': 'archiveOrg', |
| 208 | + 'local': false, |
202 | 209 | 'resource_prefix': 'AO_', |
203 | | - 'tab_img':true |
| 210 | + 'tab_img': true |
204 | 211 | }, |
205 | 212 | 'flickr': { |
206 | | - 'enabled':1, |
207 | | - 'checked':1, |
208 | | - 'homepage':'http://www.flickr.com/about/', |
| 213 | + 'enabled': 1, |
| 214 | + 'checked': 1, |
| 215 | + 'homepage': 'http://www.flickr.com/about/', |
209 | 216 | |
210 | | - 'api_url':'http://www.flickr.com/services/rest/', |
211 | | - 'lib' : 'flickr', |
212 | | - 'local' : false, |
213 | | - // Just prefix with Flickr_ for now. |
| 217 | + 'api_url': 'http://www.flickr.com/services/rest/', |
| 218 | + 'lib': 'flickr', |
| 219 | + 'local': false, |
| 220 | + // Just prefix with Flickr_ for now. |
214 | 221 | 'resource_prefix': 'Flickr_', |
215 | | - 'tab_img':true |
| 222 | + 'tab_img': true |
216 | 223 | }, |
217 | 224 | 'metavid': { |
218 | | - 'enabled' : 1, |
219 | | - 'checked' : 1, |
220 | | - 'homepage':'http://metavid.org/wiki/Metavid_Overview', |
221 | | - 'api_url':'http://metavid.org/w/index.php?title=Special:MvExportSearch', |
222 | | - 'lib' : 'metavid', |
223 | | - 'local' :false, // if local set to true we can use local |
| 225 | + 'enabled': 1, |
| 226 | + 'checked': 1, |
| 227 | + 'homepage': 'http://metavid.org/wiki/Metavid_Overview', |
| 228 | + 'api_url': 'http://metavid.org/w/index.php?title=Special:MvExportSearch', |
| 229 | + 'lib': 'metavid', |
| 230 | + 'local': false, // if local set to true we can use local |
224 | 231 | 'resource_prefix': 'MV_', // what prefix to use on imported resources |
225 | 232 | |
226 | 233 | 'local_domains': ['metavid'], // if the domain name contains metavid |
227 | | - // no need to import metavid content to metavid sites |
| 234 | + // no need to import metavid content to metavid sites |
228 | 235 | |
229 | 236 | 'stream_import_key': 'mv_ogg_low_quality', // which stream to import, could be mv_ogg_high_quality |
230 | | - // or flash stream, see ROE xml for keys |
| 237 | + // or flash stream, see ROE xml for keys |
231 | 238 | |
232 | 239 | 'remote_embed_ext': false, // if running the remoteEmbed extension no need to copy local |
233 | | - // syntax will be [remoteEmbed:roe_url link title] |
234 | | - 'tab_img':true |
| 240 | + // syntax will be [remoteEmbed:roe_url link title] |
| 241 | + 'tab_img': true |
235 | 242 | }, |
236 | 243 | // special cp "upload" |
237 | 244 | 'upload': { |
238 | | - 'enabled':1, |
239 | | - 'checked':1, |
240 | | - 'title' :'Upload' |
| 245 | + 'enabled': 1, |
| 246 | + 'checked': 1, |
| 247 | + 'title': 'Upload' |
241 | 248 | } |
242 | 249 | }, |
243 | | - // some default layout values: |
244 | | - thumb_width : 80, |
245 | | - image_edit_width : 400, |
246 | | - video_edit_width : 400, |
247 | | - insert_text_pos : 0, // insert at the start (will be overwritten by the user cursor pos) |
248 | | - result_display_mode : 'box', // box or list |
249 | 250 | |
250 | | - cUpLoader : null, |
251 | | - cEdit : null, |
252 | | - proxySetupDone : null, |
253 | | - dmodalCss : { }, |
254 | | - |
255 | | - init: function( options ) { |
256 | | - var _this = this; |
257 | | - js_log( 'remoteSearchDriver:init' ); |
258 | | - //add in a local "id" refrence top each cp: |
259 | | - for(var cp_id in this.content_providers){ |
260 | | - this.content_providers[ cp_id ].id = cp_id; |
261 | | - } |
262 | | - |
263 | | - // merge in the options: |
264 | | - // @@todo for cleaner config we should set _this.opt to the provided options) |
265 | | - $j.extend( _this, default_remote_search_options, options ); |
266 | | - |
267 | | - // Quick fix for cases where people put ['all'] instead of 'all' for enabled_cps |
268 | | - if ( _this.enabled_cps.length == 1 && _this.enabled_cps[0] == 'all' ) |
269 | | - _this.enabled_cps = 'all'; |
270 | | - |
271 | | - // modify the content provider config based on options: |
272 | | - for ( var i in this.content_providers ) { |
273 | | - if ( _this.enabled_cps == 'all' && !this.disp_item ) { |
274 | | - this.disp_item = i; |
275 | | - // end the for loop (no need to idorate if enabled_cps == 'all' |
276 | | - break; |
277 | | - } else { |
278 | | - if ( $j.inArray( i, _this.enabled_cps ) != -1 ) { |
279 | | - // if no default display set to first enabled cp: |
280 | | - if ( !this.disp_item ) |
281 | | - this.disp_item = i; |
282 | | - this.content_providers[i].enabled = true; |
283 | | - } else { |
284 | | - if ( _this.enabled_cps != 'all' ) { |
285 | | - this.content_providers[i].enabled = false; |
286 | | - } |
287 | | - } |
288 | | - } |
289 | | - } |
290 | | - |
291 | | - // set the upload target name if unset |
292 | | - if ( _this.upload_api_target == 'local' && ! _this.upload_api_name && typeof wgSiteName != 'undefined' ) |
293 | | - _this.upload_api_name = wgSiteName; |
294 | | - |
295 | | - // if the upload_api_proxy_frame is set _this.upload_api_target to "proxy" |
296 | | - if ( _this.upload_api_proxy_frame ) |
297 | | - _this.upload_api_target = 'proxy'; |
298 | | - |
299 | | - // map "local" to the local api |
300 | | - if ( _this.upload_api_target == 'local' ) { |
301 | | - if ( ! _this.local_wiki_api_url ) { |
302 | | - $j( '#tab-upload' ).html( gM( 'rsd_config_error', 'missing_local_api_url' ) ); |
303 | | - return false; |
304 | | - } else { |
305 | | - _this.upload_api_target = _this.local_wiki_api_url; |
306 | | - } |
307 | | - } |
308 | | - |
309 | | - // set up the target invocation: |
310 | | - if ( $j( this.target_invocation ).length == 0 ) { |
311 | | - js_log( "RemoteSearchDriver:: no target invocation provided (will have to run your own doInitDisplay() )" ); |
312 | | - } else { |
313 | | - if ( this.target_invocation ) { |
314 | | - $j( this.target_invocation ).css( 'cursor', 'pointer' ).attr( 'title', gM( 'mwe-add_media_wizard' ) ).click( function() { |
315 | | - _this.doInitDisplay(); |
316 | | - } ); |
317 | | - } |
318 | | - } |
319 | | - }, |
320 | 251 | // define the licenses |
321 | 252 | // ... this will get complicated quick... |
322 | 253 | // (just look at complexity for creative commons without excessive "duplicate data") |
— | — | @@ -331,7 +262,7 @@ |
332 | 263 | 'cc': { |
333 | 264 | 'base_img_url':'http://upload.wikimedia.org/wikipedia/commons/thumb/', |
334 | 265 | 'base_license_url': 'http://creativecommons.org/licenses/', |
335 | | - 'licenses':[ |
| 266 | + 'licenses': [ |
336 | 267 | 'by', |
337 | 268 | 'by-sa', |
338 | 269 | 'by-nc-nd', |
— | — | @@ -341,377 +272,541 @@ |
342 | 273 | 'by-sa', |
343 | 274 | 'pd' |
344 | 275 | ], |
345 | | - 'license_img': { |
| 276 | + 'license_images': { |
346 | 277 | 'by': { |
347 | | - 'im':'1/11/Cc-by_new_white.svg/20px-Cc-by_new_white.svg.png' |
| 278 | + 'image_url': '1/11/Cc-by_new_white.svg/20px-Cc-by_new_white.svg.png' |
348 | 279 | }, |
349 | 280 | 'nc': { |
350 | | - 'im':'2/2f/Cc-nc_white.svg/20px-Cc-nc_white.svg.png' |
| 281 | + 'image_url': '2/2f/Cc-nc_white.svg/20px-Cc-nc_white.svg.png' |
351 | 282 | }, |
352 | 283 | 'nd': { |
353 | | - 'im':'b/b3/Cc-nd_white.svg/20px-Cc-nd_white.svg.png' |
| 284 | + 'image_url': 'b/b3/Cc-nd_white.svg/20px-Cc-nd_white.svg.png' |
354 | 285 | }, |
355 | 286 | 'sa': { |
356 | | - 'im':'d/df/Cc-sa_white.svg/20px-Cc-sa_white.svg.png' |
| 287 | + 'image_url': 'd/df/Cc-sa_white.svg/20px-Cc-sa_white.svg.png' |
357 | 288 | }, |
358 | 289 | 'pd': { |
359 | | - 'im':'5/51/Cc-pd-new_white.svg/20px-Cc-pd-new_white.svg.png' |
| 290 | + 'image_url': '5/51/Cc-pd-new_white.svg/20px-Cc-pd-new_white.svg.png' |
360 | 291 | } |
361 | 292 | } |
362 | 293 | } |
363 | 294 | }, |
| 295 | + |
| 296 | + // some default layout values: |
| 297 | + thumb_width: 80, |
| 298 | + image_edit_width: 400, |
| 299 | + video_edit_width: 400, |
| 300 | + insert_text_pos: 0, // insert at the start (will be overwritten by the user cursor pos) |
| 301 | + displayMode : 'box', // box or list |
| 302 | + |
| 303 | + cUpLoader: null, |
| 304 | + clipEdit: null, |
| 305 | + proxySetupDone: null, |
| 306 | + dmodalCss: {}, |
| 307 | + |
| 308 | + init: function( options ) { |
| 309 | + var _this = this; |
| 310 | + js_log( 'remoteSearchDriver:init' ); |
| 311 | + // Add in a local "id" reference to each provider |
| 312 | + for ( var cp_id in this.content_providers ) { |
| 313 | + this.content_providers[ cp_id ].id = cp_id; |
| 314 | + } |
| 315 | + |
| 316 | + // Merge in the options |
| 317 | + // @@todo for cleaner config we should set _this.opt to the provided options |
| 318 | + $j.extend( _this, default_remote_search_options, options ); |
| 319 | + |
| 320 | + // Quick fix for cases where people put ['all'] instead of 'all' for enabled_providers |
| 321 | + if ( _this.enabled_providers.length == 1 && _this.enabled_providers[0] == 'all' ) |
| 322 | + _this.enabled_providers = 'all'; |
| 323 | + |
| 324 | + // Set up content_providers |
| 325 | + for ( var provider in this.content_providers ) { |
| 326 | + if ( _this.enabled_providers == 'all' && !this.currentProvider ) { |
| 327 | + this.currentProvider = provider; |
| 328 | + break; |
| 329 | + } else { |
| 330 | + if ( $j.inArray( provider, _this.enabled_providers ) != -1 ) { |
| 331 | + // This provider is enabled |
| 332 | + this.content_providers[provider].enabled = true; |
| 333 | + // Set the current provider to the first enabled one |
| 334 | + if ( !this.currentProvider ) { |
| 335 | + this.currentProvider = provider; |
| 336 | + } |
| 337 | + } else { |
| 338 | + // This provider is disabled |
| 339 | + if ( _this.enabled_providers != 'all' ) { |
| 340 | + this.content_providers[provider].enabled = false; |
| 341 | + } |
| 342 | + } |
| 343 | + } |
| 344 | + } |
| 345 | + |
| 346 | + // Set the upload target name if unset |
| 347 | + if ( _this.upload_api_target == 'local' |
| 348 | + && ! _this.upload_api_name |
| 349 | + && typeof wgSiteName != 'undefined' ) |
| 350 | + { |
| 351 | + _this.upload_api_name = wgSiteName; |
| 352 | + } |
| 353 | + |
| 354 | + // Set the target to "proxy" if a proxy frame is configured |
| 355 | + if ( _this.upload_api_proxy_frame ) |
| 356 | + _this.upload_api_target = 'proxy'; |
| 357 | + |
| 358 | + // Set up the local API upload URL |
| 359 | + if ( _this.upload_api_target == 'local' ) { |
| 360 | + if ( ! _this.local_wiki_api_url ) { |
| 361 | + $j( '#tab-upload' ).html( gM( 'rsd_config_error', 'missing_local_api_url' ) ); |
| 362 | + return false; |
| 363 | + } else { |
| 364 | + _this.upload_api_target = _this.local_wiki_api_url; |
| 365 | + } |
| 366 | + } |
| 367 | + |
| 368 | + // Set up the "add media wizard" button, which invokes this object |
| 369 | + if ( $j( this.target_invoke_button ).length == 0 ) { |
| 370 | + js_log( "RemoteSearchDriver:: no target invocation provided " + |
| 371 | + "(will have to run your own createUI() )" ); |
| 372 | + } else { |
| 373 | + if ( this.target_invoke_button ) { |
| 374 | + $j( this.target_invoke_button ) |
| 375 | + .css( 'cursor', 'pointer' ) |
| 376 | + .attr( 'title', gM( 'mwe-add_media_wizard' ) ) |
| 377 | + .click( function() { |
| 378 | + _this.createUI(); |
| 379 | + } ); |
| 380 | + } |
| 381 | + } |
| 382 | + }, |
| 383 | + |
364 | 384 | /* |
365 | | - * getlicenseImgSet |
| 385 | + * getLicenseIconHtml |
366 | 386 | * @param license_key the license key (ie "by-sa" or "by-nc-sa" etc) |
367 | 387 | */ |
368 | | - getlicenseImgSet: function( licenseObj ) { |
| 388 | + getLicenseIconHtml: function( licenseObj ) { |
369 | 389 | // js_log('output images: '+ imgs); |
370 | 390 | return '<div class="rsd_license" title="' + licenseObj.title + '" >' + |
371 | | - '<a target="_new" href="' + licenseObj.lurl + '" ' + |
372 | | - 'title="' + licenseObj.title + '">' + |
373 | | - licenseObj.img_html + |
374 | | - '</a>' + |
375 | | - '</div>'; |
| 391 | + '<a target="_new" href="' + licenseObj.lurl + '" ' + |
| 392 | + 'title="' + licenseObj.title + '">' + |
| 393 | + licenseObj.img_html + |
| 394 | + '</a>' + |
| 395 | + '</div>'; |
376 | 396 | }, |
| 397 | + |
377 | 398 | /* |
378 | | - * getLicenceKeyFromKey |
| 399 | + * getLicenseKeyFromKey |
379 | 400 | * @param license_key the key of the license (must be defined in: this.licenses.cc.licenses) |
380 | 401 | */ |
381 | | - getLicenceFromKey:function( license_key , force_url ) { |
| 402 | + getLicenseFromKey: function( license_key, force_url ) { |
382 | 403 | // set the current license pointer: |
383 | 404 | var cl = this.licenses.cc; |
384 | 405 | var title = gM( 'mwe-cc_title' ); |
385 | 406 | var imgs = ''; |
386 | 407 | var license_set = license_key.split( '-' ); |
387 | 408 | for ( var i = 0; i < license_set.length; i++ ) { |
388 | | - var lkey = license_set[i]; |
389 | | - if ( ! cl.license_img[ lkey ] ) { |
| 409 | + var lkey = license_set[i]; |
| 410 | + if ( !cl.license_images[ lkey ] ) { |
390 | 411 | js_log( "MISSING::" + lkey ); |
391 | 412 | } |
392 | | - |
| 413 | + |
393 | 414 | title += ' ' + gM( 'mwe-cc_' + lkey + '_title' ); |
394 | | - imgs += '<img class="license_desc" width="20" src="' |
395 | | - + cl.base_img_url + cl.license_img[ lkey ].im + '">'; |
| 415 | + imgs += '<img class="license_desc" width="20" src="' + |
| 416 | + cl.base_img_url + cl.license_images[ lkey ].image_url + '">'; |
396 | 417 | } |
397 | 418 | var url = ( force_url ) ? force_url : cl.base_license_url + cl.licenses[ license_key ]; |
398 | 419 | return { |
399 | | - 'title' : title, |
400 | | - 'img_html' : imgs, |
401 | | - 'key' : license_key, |
402 | | - 'lurl' : url |
| 420 | + 'title': title, |
| 421 | + 'img_html': imgs, |
| 422 | + 'key': license_key, |
| 423 | + 'lurl': url |
403 | 424 | }; |
404 | 425 | }, |
| 426 | + |
405 | 427 | /* |
406 | | - * getLicenceKeyFromUrl |
407 | | - * @param licence_url the url of the license |
| 428 | + * getLicenseKeyFromUrl |
| 429 | + * @param license_url the url of the license |
408 | 430 | */ |
409 | | - getLicenceFromUrl: function( license_url ) { |
| 431 | + getLicenseFromUrl: function( license_url ) { |
410 | 432 | // check for some pre-defined url types: |
411 | 433 | if ( license_url == 'http://www.usa.gov/copyright.shtml' || |
412 | 434 | license_url == 'http://creativecommons.org/licenses/publicdomain' ) |
413 | | - return this.getLicenceFromKey( 'pd' , license_url ); |
414 | | - |
415 | | - |
416 | | - // js_log("getLicenceFromUrl::" + license_url); |
| 435 | + return this.getLicenseFromKey( 'pd' , license_url ); |
| 436 | + |
| 437 | + |
| 438 | + // js_log("getLicenseFromUrl::" + license_url); |
417 | 439 | // first do a direct lookup check: |
418 | 440 | for ( var j = 0; j < this.licenses.cc.licenses.length; j++ ) { |
419 | 441 | var jL = this.licenses.cc.licenses[ j ]; |
420 | | - // special 'pd' case: |
| 442 | + // special 'pd' case: |
421 | 443 | if ( jL == 'pd' ) { |
422 | 444 | var keyCheck = 'publicdomain'; |
423 | 445 | } else { |
424 | 446 | var keyCheck = jL; |
425 | 447 | } |
426 | 448 | if ( mw.parseUri( license_url ).path.indexOf( '/' + keyCheck + '/' ) != -1 ) { |
427 | | - return this.getLicenceFromKey( jL , license_url ); |
| 449 | + return this.getLicenseFromKey( jL , license_url ); |
428 | 450 | } |
429 | | - }; |
| 451 | + } |
430 | 452 | // Could not find it return mwe-unknown_license |
431 | 453 | return { |
432 | | - 'title' : gM( 'mwe-unknown_license' ), |
433 | | - 'img_html' : '<span>' + gM( 'mwe-unknown_license' ) + '</span>', |
434 | | - 'lurl' : license_url |
| 454 | + 'title': gM( 'mwe-unknown_license' ), |
| 455 | + 'img_html': '<span>' + gM( 'mwe-unknown_license' ) + '</span>', |
| 456 | + 'lurl': license_url |
435 | 457 | }; |
436 | 458 | }, |
| 459 | + |
437 | 460 | /** |
438 | 461 | * getTypeIcon |
439 | 462 | * @param str mime type of the requested file |
440 | 463 | */ |
441 | | - getTypeIcon:function( mimetype ) { |
| 464 | + getTypeIcon: function( mimetype ) { |
442 | 465 | var typestr = 'unk'; |
443 | | - switch( mimetype ) { |
| 466 | + switch ( mimetype ) { |
444 | 467 | case 'image/svg+xml': |
445 | 468 | typestr = 'svg'; |
446 | | - break; |
| 469 | + break; |
447 | 470 | case 'image/jpeg': |
448 | 471 | typestr = 'jpg' |
449 | | - break; |
| 472 | + break; |
450 | 473 | case 'image/png': |
451 | 474 | typestr = 'png'; |
452 | | - break; |
| 475 | + break; |
453 | 476 | case 'audio/ogg': |
454 | 477 | typestr = 'oga'; |
455 | 478 | case 'video/ogg': |
456 | 479 | case 'application/ogg': |
457 | 480 | typestr = 'ogg'; |
458 | | - break; |
| 481 | + break; |
459 | 482 | } |
460 | | - |
| 483 | + |
461 | 484 | if ( typestr == 'unk' ) { |
462 | 485 | js_log( "unkown ftype: " + mimetype ); |
463 | 486 | return ''; |
464 | 487 | } |
465 | | - |
466 | | - return '<div class="rsd_file_type ui-corner-all ui-state-default ui-widget-content" title="' + gM( 'mwe-ftype-' + typestr ) + '">' + |
467 | | - typestr + |
468 | | - '</div>' |
| 488 | + |
| 489 | + return '<div ' + |
| 490 | + 'class="rsd_file_type ui-corner-all ui-state-default ui-widget-content" ' + |
| 491 | + 'title="' + gM( 'mwe-ftype-' + typestr ) + '">' + |
| 492 | + typestr + |
| 493 | + '</div>'; |
469 | 494 | }, |
470 | | - doInitDisplay:function() { |
| 495 | + |
| 496 | + createUI: function() { |
471 | 497 | var _this = this; |
472 | | - |
473 | | - // try and get the text selection: |
474 | | - _this.getTexboxSelection(); |
475 | | - |
| 498 | + |
| 499 | + this.clearTextboxCache(); |
476 | 500 | // setup the parent container: |
477 | | - this.init_modal(); |
| 501 | + this.createDialogContainer(); |
478 | 502 | // fill in the html: |
479 | | - this.init_interface_html(); |
| 503 | + this.initDialog(); |
480 | 504 | // bind actions: |
481 | 505 | this.add_interface_bindings(); |
482 | 506 | |
483 | 507 | // update the target binding to just un-hide the dialog: |
484 | | - if ( this.target_invocation ) { |
485 | | - $j( this.target_invocation ).unbind().click( function() { |
486 | | - js_log( "doInitDisplay:target_invocation: click doReDisp" ); |
487 | | - _this.doReDisplay(); |
488 | | - } ); |
489 | | - } |
| 508 | + if ( this.target_invoke_button ) { |
| 509 | + $j( this.target_invoke_button ) |
| 510 | + .unbind() |
| 511 | + .click( function() { |
| 512 | + js_log( "createUI:target_invoke_button: click showDialog" ); |
| 513 | + _this.showDialog(); |
| 514 | + } ); |
| 515 | + } |
490 | 516 | }, |
491 | | - doReDisplay: function() { |
| 517 | + |
| 518 | + showDialog: function() { |
492 | 519 | var _this = this; |
493 | | - js_log( "doReDisplay::" ); |
494 | | - // update the base text: |
495 | | - _this.getTexboxSelection(); |
496 | | - if ( _this.default_query != $j( '#rsd_q' ).val() ) { |
497 | | - $j( '#rsd_q' ).val( _this.default_query ); |
498 | | - _this.runSearch(); |
| 520 | + js_log( "showDialog::" ); |
| 521 | + _this.clearTextboxCache(); |
| 522 | + var query = _this.getDefaultQuery(); |
| 523 | + if ( query != $j( '#rsd_q' ).val() ) { |
| 524 | + $j( '#rsd_q' ).val( query ); |
| 525 | + _this.showCurrentTab(); |
499 | 526 | } |
500 | 527 | // $j(_this.target_container).dialog("open"); |
501 | 528 | $j( _this.target_container ).parents( '.ui-dialog' ).fadeIn( 'slow' ); |
502 | 529 | // re-center the dialog: |
503 | 530 | $j( _this.target_container ).dialog( 'option', 'position', 'center' ); |
504 | 531 | }, |
505 | | - // gets the in and out points for insert position or grabs the selected text for search |
506 | | - getTexboxSelection:function() { |
507 | | - if ( this.target_textbox ) { |
508 | | - // get the selection text: |
509 | | - var ts = $j( this.target_textbox ).textSelection(); |
510 | | - if ( ts != '' ) { |
511 | | - this.default_query = ts; |
| 532 | + |
| 533 | + clearTextboxCache: function() { |
| 534 | + this.caretPos = null; |
| 535 | + this.textboxValue = null; |
| 536 | + this.default_query = null; |
| 537 | + }, |
| 538 | + |
| 539 | + getCaretPos: function() { |
| 540 | + if ( this.caretPos == null ) { |
| 541 | + if ( this.target_textbox ) { |
| 542 | + this.caretPos = $j( this.target_textbox ).getCaretPosition(); |
| 543 | + } else { |
| 544 | + this.caretPos = false; |
512 | 545 | } |
513 | | - // get the caretPos / value |
514 | | - this.caret_pos = { }; |
515 | | - this.caret_pos.text = $j( this.target_textbox ).val(); |
516 | | - this.caret_pos.s = $j( this.target_textbox ).getCaretPosition(); |
517 | 546 | } |
| 547 | + return this.caretPos; |
518 | 548 | }, |
519 | | - init_modal:function() { |
520 | | - js_log( "init_modal" ); |
| 549 | + |
| 550 | + getTextboxValue: function() { |
| 551 | + if ( this.textboxValue == null ) { |
| 552 | + if ( this.target_textbox ) { |
| 553 | + this.textboxValue = $j( this.target_textbox ).val(); |
| 554 | + } else { |
| 555 | + this.textboxValue = ''; |
| 556 | + } |
| 557 | + } |
| 558 | + return this.textboxValue; |
| 559 | + }, |
| 560 | + |
| 561 | + getDefaultQuery: function() { |
| 562 | + if ( this.default_query == null ) { |
| 563 | + if ( this.target_textbox ) { |
| 564 | + var ts = $j( this.target_textbox ).textSelection(); |
| 565 | + if ( ts != '' ) { |
| 566 | + this.default_query = ts; |
| 567 | + } else { |
| 568 | + this.default_query = ''; |
| 569 | + } |
| 570 | + } |
| 571 | + } |
| 572 | + return this.default_query; |
| 573 | + }, |
| 574 | + |
| 575 | + createDialogContainer: function() { |
| 576 | + js_log( "createDialogContainer" ); |
521 | 577 | var _this = this; |
522 | 578 | // add the parent target_container if not provided or missing |
523 | | - if ( !_this.target_container || $j( _this.target_container ).length == 0 ) { |
524 | | - _this.target_container = '#rsd_modal_target'; |
525 | | - $j( 'body' ).append( '<div id="rsd_modal_target" style="position:absolute;top:3em;left:0px;bottom:3em;right:0px;" title="' + gM( 'mwe-add_media_wizard' ) + '" ></div>' ); |
526 | | - // js_log('appended: #rsd_modal_target' + $j(_this.target_container).attr('id')); |
527 | | - // js_log('added target id:' + $j(_this.target_container).attr('id')); |
528 | | - // get layout |
529 | | - js_log( 'width: ' + $j( window ).width() + ' height: ' + $j( window ).height() ); |
530 | | - var cBtn = { }; |
531 | | - cBtn[ gM( 'mwe-cancel' ) ] = function() { |
532 | | - _this.cancelClipEditCB(); |
| 579 | + if ( _this.target_container && $j( _this.target_container ).length != 0 ) { |
| 580 | + js_log( 'dialog already exists' ); |
| 581 | + return; |
| 582 | + } |
| 583 | + |
| 584 | + _this.target_container = '#rsd_modal_target'; |
| 585 | + $j( 'body' ).append( |
| 586 | + '<div ' + |
| 587 | + 'id="rsd_modal_target" ' + |
| 588 | + 'style="position:absolute;top:3em;left:0px;bottom:3em;right:0px;" ' + |
| 589 | + 'title="' + gM( 'mwe-add_media_wizard' ) + '" >' + |
| 590 | + '</div>' ); |
| 591 | + // js_log('appended: #rsd_modal_target' + $j(_this.target_container).attr('id')); |
| 592 | + // js_log('added target id:' + $j(_this.target_container).attr('id')); |
| 593 | + // get layout |
| 594 | + js_log( 'width: ' + $j( window ).width() + ' height: ' + $j( window ).height() ); |
| 595 | + var cBtn = {}; |
| 596 | + cBtn[ gM( 'mwe-cancel' ) ] = function() { |
| 597 | + _this.onCancelClipEdit(); |
| 598 | + } |
| 599 | + |
| 600 | + $j( _this.target_container ).dialog( { |
| 601 | + bgiframe: true, |
| 602 | + autoOpen: true, |
| 603 | + modal: true, |
| 604 | + draggable: false, |
| 605 | + resizable: false, |
| 606 | + buttons: cBtn, |
| 607 | + close: function() { |
| 608 | + // if we are 'editing' a item close that |
| 609 | + // @@todo maybe prompt the user? |
| 610 | + _this.onCancelClipEdit(); |
| 611 | + $j( this ).parents( '.ui-dialog' ).fadeOut( 'slow' ); |
533 | 612 | } |
534 | | - |
535 | | - $j( _this.target_container ).dialog( { |
536 | | - bgiframe: true, |
537 | | - autoOpen: true, |
538 | | - modal: true, |
539 | | - draggable:false, |
540 | | - resizable:false, |
541 | | - buttons:cBtn, |
542 | | - close: function() { |
543 | | - // if we are 'editing' a item close that |
544 | | - // @@todo maybe prompt the user? |
545 | | - _this.cancelClipEditCB(); |
546 | | - $j( this ).parents( '.ui-dialog' ).fadeOut( 'slow' ); |
547 | | - } |
548 | | - } ); |
| 613 | + } ); |
| 614 | + $j( _this.target_container ).dialogFitWindow(); |
| 615 | + $j( window ).resize( function() { |
549 | 616 | $j( _this.target_container ).dialogFitWindow(); |
550 | | - $j( window ).resize( function() { |
551 | | - $j( _this.target_container ).dialogFitWindow(); |
552 | | - } ); |
553 | | - |
554 | | - // add cancel callback and updated button with icon |
555 | | - _this.cancelClipEditCB(); |
556 | | - } |
| 617 | + } ); |
| 618 | + |
| 619 | + // add cancel callback and updated button with icon |
| 620 | + _this.onCancelClipEdit(); |
557 | 621 | }, |
| 622 | + |
558 | 623 | // sets up the initial html interface |
559 | | - init_interface_html:function() { |
560 | | - js_log( 'init_interface_html' ); |
| 624 | + initDialog: function() { |
| 625 | + js_log( 'initDialog' ); |
561 | 626 | var _this = this; |
562 | | - var dq = ( this.default_query ) ? this.default_query : ''; |
563 | | - js_log( 'f::init_interface_html' ); |
| 627 | + js_log( 'f::initDialog' ); |
564 | 628 | |
565 | 629 | var o = '<div class="rsd_control_container" style="width:100%">' + |
566 | | - '<form id="rsd_form" action="javascript:return false;" method="GET">' + |
567 | | - '<input class="ui-widget-content ui-corner-all" type="text" tabindex="1" value="' + dq + '" maxlength="512" id="rsd_q" name="rsd_q" ' + |
568 | | - 'size="20" autocomplete="off" />' + |
569 | | - $j.btnHtml( gM( 'mwe-media_search' ), 'rms_search_button', 'search' ) + |
570 | | - '</form>'; |
| 630 | + '<form id="rsd_form" action="javascript:return false;" method="GET">' + |
| 631 | + '<input ' + |
| 632 | + 'class="ui-widget-content ui-corner-all" ' + |
| 633 | + 'type="text" ' + |
| 634 | + 'tabindex="1" ' + |
| 635 | + 'value="' + this.getDefaultQuery() + '" ' + |
| 636 | + 'maxlength="512" ' + |
| 637 | + 'id="rsd_q" ' + |
| 638 | + 'name="rsd_q" ' + |
| 639 | + 'size="20" ' + |
| 640 | + 'autocomplete="off" />' + |
| 641 | + $j.btnHtml( gM( 'mwe-media_search' ), 'rms_search_button', 'search' ) + |
| 642 | + '</form>'; |
571 | 643 | // close up the control container: |
572 | 644 | o += '</div>'; |
573 | | - |
| 645 | + |
574 | 646 | // search provider tabs based on "checked" and "enabled" and "combined tab" |
575 | | - o += '<div id="rsd_results_container" style="top:0px;bottom:0px;left:0px;right:0px;"></div>'; |
| 647 | + o += '<div ' + |
| 648 | + 'id="rsd_results_container" ' + |
| 649 | + 'style="top:0px;bottom:0px;left:0px;right:0px;">' + |
| 650 | + '</div>'; |
576 | 651 | $j( this.target_container ).html( o ); |
577 | 652 | // add simple styles: |
578 | 653 | $j( this.target_container + ' .rms_search_button' ).btnBind().click( function() { |
579 | | - _this.runSearch(); |
| 654 | + _this.showCurrentTab(); |
580 | 655 | } ); |
581 | 656 | |
582 | 657 | // draw the tabs: |
583 | | - this.drawTabs(); |
| 658 | + this.createTabs(); |
584 | 659 | // run the default search: |
585 | | - if ( this.default_query ) |
586 | | - this.runSearch(); |
587 | | - }, |
588 | | - add_interface_bindings:function() { |
589 | | - var _this = this; |
590 | | - js_log( "f:add_interface_bindings:" ); |
| 660 | + if ( this.getDefaultQuery() ) |
| 661 | + this.showCurrentTab(); |
591 | 662 | |
592 | | - |
593 | | - $j( '#mso_selprovider,#mso_selprovider_close' ).unbind().click( function() { |
594 | | - if ( $j( '#rsd_options_bar:hidden' ).length != 0 ) { |
595 | | - $j( '#rsd_options_bar' ).animate( { |
596 | | - 'height':'110px', |
597 | | - 'opacity':1 |
598 | | - }, "normal" ); |
599 | | - } else { |
600 | | - $j( '#rsd_options_bar' ).animate( { |
601 | | - 'height':'0px', |
602 | | - 'opacity':0 |
603 | | - }, "normal", function() { |
604 | | - $j( this ).hide(); |
605 | | - } ); |
606 | | - } |
607 | | - } ); |
| 663 | + // Add bindings |
| 664 | + $j( '#mso_selprovider,#mso_selprovider_close' ) |
| 665 | + .unbind() |
| 666 | + .click( function() { |
| 667 | + if ( $j( '#rsd_options_bar:hidden' ).length != 0 ) { |
| 668 | + $j( '#rsd_options_bar' ).animate( { |
| 669 | + 'height': '110px', |
| 670 | + 'opacity': 1 |
| 671 | + }, "normal" ); |
| 672 | + } else { |
| 673 | + $j( '#rsd_options_bar' ).animate( { |
| 674 | + 'height': '0px', |
| 675 | + 'opacity': 0 |
| 676 | + }, "normal", function() { |
| 677 | + $j( this ).hide(); |
| 678 | + } ); |
| 679 | + } |
| 680 | + } ); |
608 | 681 | // set form bindings |
609 | | - $j( '#rsd_form' ).unbind().submit( function() { |
610 | | - _this.runSearch(); |
611 | | - // don't submit the form |
612 | | - return false; |
613 | | - } ); |
| 682 | + $j( '#rsd_form' ) |
| 683 | + .unbind() |
| 684 | + .submit( function() { |
| 685 | + _this.showCurrentTab(); |
| 686 | + // don't submit the form |
| 687 | + return false; |
| 688 | + } ); |
614 | 689 | }, |
615 | | - doUploadInteface:function() { |
616 | | - js_log( "doUploadInteface::" ); |
| 690 | + |
| 691 | + showUploadTab: function() { |
| 692 | + js_log( "showUploadTab::" ); |
617 | 693 | var _this = this; |
618 | 694 | // set it to loading: |
619 | 695 | mv_set_loading( '#tab-upload' ); |
620 | 696 | // do things async to keep interface snappy |
621 | | - setTimeout( function() { |
622 | | - // check if we need to setup the proxy:: |
623 | | - if ( _this.upload_api_target == 'proxy' ) { |
624 | | - _this.setupProxy( function() { |
625 | | - _this.getUploadForm(); |
626 | | - } ); |
627 | | - } else { |
628 | | - _this.getUploadForm(); |
629 | | - } |
630 | | - }, 1 ); |
| 697 | + setTimeout( |
| 698 | + function() { |
| 699 | + // check if we need to setup the proxy:: |
| 700 | + if ( _this.upload_api_target == 'proxy' ) { |
| 701 | + _this.setupProxy( function() { |
| 702 | + _this.showUploadForm(); |
| 703 | + } ); |
| 704 | + } else { |
| 705 | + _this.showUploadForm(); |
| 706 | + } |
| 707 | + }, |
| 708 | + 1 ); |
631 | 709 | }, |
632 | | - getUploadForm:function() { |
| 710 | + |
| 711 | + showUploadForm: function() { |
633 | 712 | var _this = this; |
634 | 713 | mvJsLoader.doLoad( ['$j.fn.simpleUploadForm'], function() { |
635 | 714 | // get extends info about the file |
636 | | - var cp = _this.content_providers['this_wiki']; |
637 | | - |
| 715 | + var provider = _this.content_providers['this_wiki']; |
| 716 | + |
638 | 717 | // check for "this_wiki" enabled |
639 | | - /*if(!cp.enabled){ |
640 | | - $j('#tab-upload').html('error this_wiki not enabled (can\'t get uploaded file info)'); |
| 718 | + /*if(!provider.enabled){ |
| 719 | + $j('#tab-upload') |
| 720 | + .html('error this_wiki not enabled (can\'t get uploaded file info)'); |
641 | 721 | return false; |
642 | 722 | }*/ |
643 | | - |
644 | | - // load this_wiki search system to grab the rObj |
645 | | - _this.loadSearchLib( cp, function() { |
646 | | - // do basic layout form on left upload "bin" on right |
647 | | - $j( '#tab-upload' ).html( '<table>' + |
648 | | - '<tr>' + |
649 | | - '<td valign="top" style="width:350px; padding-right: 12px;">' + |
650 | | - '<h4>' + gM( 'mwe-upload_a_file', _this.upload_api_name ) + '</h4>' + |
651 | | - '<div id="upload_form">' + |
652 | | - mv_get_loading_img() + |
653 | | - '</div>' + |
654 | | - '</td>' + |
655 | | - '<td valign="top" id="upload_bin_cnt">' + |
656 | | - '<h4>' + gM( 'mwe-your_recent_uploads', _this.upload_api_name ) + '</h4>' + |
657 | | - '<div id="upload_bin">' + |
658 | | - mv_get_loading_img() + |
659 | | - '</div>' + |
660 | | - '</td>' + |
661 | | - '</tr>' + |
662 | | - '</table>' ); |
663 | | - |
664 | | - |
665 | | - // fill in the user page: |
666 | | - if ( typeof wgUserName != 'undefined' && wgUserName ) { |
667 | | - // load the upload bin with anything the current user has uploaded |
668 | | - cp.sObj.getUserRecentUploads( wgUserName, function() { |
669 | | - _this.drawOutputResults(); |
670 | | - } ); |
671 | | - } else { |
672 | | - $j( '#upload_bin_cnt' ).empty(); |
673 | | - } |
674 | | - |
675 | | - // deal with the api form upload form directly: |
676 | | - $j( '#upload_form' ).simpleUploadForm( { |
677 | | - "api_target" : _this.upload_api_target, |
678 | | - "ondone_cb" : function( resultData ) { |
679 | | - var wTitle = resultData['filename']; |
680 | | - // add a loading div |
681 | | - _this.addResourceEditLoader(); |
682 | | - // @@note: we have most of what we need in resultData imageinfo |
683 | | - cp.sObj.addByTitle( wTitle, function( rObj ) { |
684 | | - // Redraw ( with added result if new ) |
685 | | - _this.drawOutputResults(); |
686 | | - // Pull up resource editor: |
687 | | - _this.resourceEdit( rObj, $j( '#res_upload__' + rObj.id ).get( 0 ) ); |
688 | | - } ); |
689 | | - // Return false to close progress window: |
690 | | - return false; |
691 | | - } |
| 723 | + |
| 724 | + // load this_wiki search system to grab the resource |
| 725 | + _this.loadSearchLib( provider, function() { |
| 726 | + _this.showUploadForm_internal( provider ); |
| 727 | + } ); |
| 728 | + } ); |
| 729 | + }, |
| 730 | + |
| 731 | + showUploadForm_internal: function( provider ) { |
| 732 | + var _this = this; |
| 733 | + var uploadMsg = gM( 'mwe-upload_a_file', _this.upload_api_name ); |
| 734 | + var recentUploadsMsg = gM( 'mwe-your_recent_uploads', _this.upload_api_name ); |
| 735 | + // do basic layout form on left upload "bin" on right |
| 736 | + $j( '#tab-upload' ).html( |
| 737 | + '<table>' + |
| 738 | + '<tr>' + |
| 739 | + '<td valign="top" style="width:350px; padding-right: 12px;">' + |
| 740 | + '<h4>' + uploadMsg + '</h4>' + |
| 741 | + '<div id="upload_form">' + |
| 742 | + mv_get_loading_img() + |
| 743 | + '</div>' + |
| 744 | + '</td>' + |
| 745 | + '<td valign="top" id="upload_bin_cnt">' + |
| 746 | + '<h4>' + recentUploadsMsg + '</h4>' + |
| 747 | + '<div id="upload_bin">' + |
| 748 | + mv_get_loading_img() + |
| 749 | + '</div>' + |
| 750 | + '</td>' + |
| 751 | + '</tr>' + |
| 752 | + '</table>' ); |
| 753 | + |
| 754 | + |
| 755 | + // fill in the user page: |
| 756 | + if ( typeof wgUserName != 'undefined' && wgUserName ) { |
| 757 | + // load the upload bin with anything the current user has uploaded |
| 758 | + provider.sObj.getUserRecentUploads( wgUserName, function() { |
| 759 | + _this.showResults(); |
| 760 | + } ); |
| 761 | + } else { |
| 762 | + $j( '#upload_bin_cnt' ).empty(); |
| 763 | + } |
| 764 | + |
| 765 | + // deal with the api form upload form directly: |
| 766 | + $j( '#upload_form' ).simpleUploadForm( { |
| 767 | + "api_target" : _this.upload_api_target, |
| 768 | + "ondone_cb": function( resultData ) { |
| 769 | + var wTitle = resultData['filename']; |
| 770 | + // add a loading div |
| 771 | + _this.addResourceEditLoader(); |
| 772 | + // @@note: we have most of what we need in resultData imageinfo |
| 773 | + provider.sObj.addByTitle( wTitle, function( resource ) { |
| 774 | + // Redraw ( with added result if new ) |
| 775 | + _this.showResults(); |
| 776 | + // Pull up resource editor: |
| 777 | + _this.showResourceEditor( resource, $j( '#res_upload__' + resource.id ).get( 0 ) ); |
692 | 778 | } ); |
693 | | - } ); // load searchLibs |
694 | | - } ); // load simpleUploadForm |
| 779 | + // Return false to close progress window: |
| 780 | + return false; |
| 781 | + } |
| 782 | + } ); |
695 | 783 | }, |
696 | | - runSearch: function( restPage ) { |
697 | | - js_log( "f:runSearch::" + this.disp_item ); |
698 | 784 | |
699 | | - var draw_direct_flag = true; |
700 | | - |
701 | | - // check if its the special upload tab case: |
702 | | - if ( this.disp_item == 'upload' ) { |
703 | | - this.doUploadInteface(); |
704 | | - return true; |
| 785 | + showCurrentTab: function() { |
| 786 | + if ( this.currentProvider == 'upload' ) { |
| 787 | + this.showUploadTab(); |
| 788 | + } else { |
| 789 | + this.showSearchTab( this.currentProvider, false ); |
705 | 790 | } |
706 | | - |
707 | | - // else do runSearch |
708 | | - var cp = this.content_providers[this.disp_item]; |
| 791 | + } |
709 | 792 | |
| 793 | + showSearchTab: function( providerName, resetPaging ) { |
| 794 | + js_log( "f:showSearchTab::" + providerName ); |
| 795 | + |
| 796 | + var draw_direct_flag = true; |
| 797 | + |
| 798 | + // else do showSearchTab |
| 799 | + var provider = this.content_providers[providerName]; |
| 800 | + |
710 | 801 | // check if we need to update: |
711 | | - if ( typeof cp.sObj != 'undefined' ) { |
712 | | - if ( cp.sObj.last_query == $j( '#rsd_q' ).val() && cp.sObj.last_offset == cp.offset ) { |
713 | | - js_log( 'last query is: ' + cp.sObj.last_query + ' matches: ' + $j( '#rsd_q' ).val() ); |
| 802 | + if ( typeof provider.sObj != 'undefined' ) { |
| 803 | + if ( provider.sObj.last_query == $j( '#rsd_q' ).val() |
| 804 | + && provider.sObj.last_offset == provider.offset ) |
| 805 | + { |
| 806 | + js_log( 'last query is: ' + provider.sObj.last_query + |
| 807 | + ' matches: ' + $j( '#rsd_q' ).val() ); |
714 | 808 | } else { |
715 | | - js_log( 'last query is: ' + cp.sObj.last_query + ' not match: ' + $j( '#rsd_q' ).val() ); |
| 809 | + js_log( 'last query is: ' + provider.sObj.last_query + |
| 810 | + ' not match: ' + $j( '#rsd_q' ).val() ); |
716 | 811 | draw_direct_flag = false; |
717 | 812 | } |
718 | 813 | } else { |
— | — | @@ -719,23 +814,25 @@ |
720 | 815 | } |
721 | 816 | if ( !draw_direct_flag ) { |
722 | 817 | // see if we should reset the paging |
723 | | - if ( restPage ) { |
724 | | - cp.sObj.offset = cp.offset = 0; |
| 818 | + if ( resetPaging ) { |
| 819 | + provider.sObj.offset = provider.offset = 0; |
725 | 820 | } |
726 | | - |
| 821 | + |
727 | 822 | // set the content to loading while we do the search: |
728 | | - $j( '#tab-' + this.disp_item ).html( mv_get_loading_img() ); |
| 823 | + $j( '#tab-' + providerName ).html( mv_get_loading_img() ); |
729 | 824 | |
730 | 825 | // Make sure the search library is loaded and issue the search request |
731 | | - this.getLibSearchResults( cp ); |
| 826 | + this.getLibSearchResults( provider ); |
732 | 827 | } |
733 | 828 | }, |
| 829 | + |
734 | 830 | // Issue a api request & cache the result |
735 | | - // this check can be avoided by setting the this.import_url_mode = 'api' | 'form' | instead of 'autodetect' or 'none' |
736 | | - checkForCopyURLSupport:function ( callback ) { |
| 831 | + // this check can be avoided by setting the |
| 832 | + // this.import_url_mode = 'api' | 'form' | instead of 'autodetect' or 'none' |
| 833 | + checkForCopyURLSupport: function ( callback ) { |
737 | 834 | var _this = this; |
738 | 835 | js_log( 'checkForCopyURLSupport:: ' ); |
739 | | - |
| 836 | + |
740 | 837 | // See if we already have the import mode: |
741 | 838 | if ( this.import_url_mode != 'autodetect' ) { |
742 | 839 | js_log( 'import mode: ' + _this.import_url_mode ); |
— | — | @@ -748,117 +845,132 @@ |
749 | 846 | callback(); |
750 | 847 | } |
751 | 848 | if ( this.import_url_mode == 'autodetect' ) { |
752 | | - do_api_req( { |
753 | | - 'url': _this.upload_api_target, |
754 | | - 'data': { |
755 | | - 'action':'paraminfo', |
756 | | - 'modules':'upload' |
757 | | - } |
758 | | - }, function( data ) { |
759 | | - // jump right into api checks: |
760 | | - for ( var i in data.paraminfo.modules[0].parameters ) { |
761 | | - var pname = data.paraminfo.modules[0].parameters[i].name; |
762 | | - if ( pname == 'url' ) { |
763 | | - js_log( 'Autodetect Upload Mode: api: copy by url:: ' ); |
764 | | - // check permission too: |
765 | | - _this.checkForCopyURLPermission( function( canCopyUrl ) { |
766 | | - if ( canCopyUrl ) { |
767 | | - _this.import_url_mode = 'api'; |
768 | | - js_log( 'import mode: ' + _this.import_url_mode ); |
769 | | - callback(); |
770 | | - } else { |
771 | | - _this.import_url_mode = 'none'; |
772 | | - js_log( 'import mode: ' + _this.import_url_mode ); |
773 | | - callback(); |
774 | | - } |
775 | | - } ); |
776 | | - break; |
| 849 | + do_api_req( |
| 850 | + { |
| 851 | + 'url': _this.upload_api_target, |
| 852 | + 'data': { |
| 853 | + 'action': 'paraminfo', |
| 854 | + 'modules': 'upload' |
777 | 855 | } |
| 856 | + }, function( data ) { |
| 857 | + // jump right into api checks: |
| 858 | + for ( var i in data.paraminfo.modules[0].parameters ) { |
| 859 | + var pname = data.paraminfo.modules[0].parameters[i].name; |
| 860 | + if ( pname == 'url' ) { |
| 861 | + js_log( 'Autodetect Upload Mode: api: copy by url:: ' ); |
| 862 | + // check permission too: |
| 863 | + _this.checkForCopyURLPermission( function( canCopyUrl ) { |
| 864 | + if ( canCopyUrl ) { |
| 865 | + _this.import_url_mode = 'api'; |
| 866 | + js_log( 'import mode: ' + _this.import_url_mode ); |
| 867 | + callback(); |
| 868 | + } else { |
| 869 | + _this.import_url_mode = 'none'; |
| 870 | + js_log( 'import mode: ' + _this.import_url_mode ); |
| 871 | + callback(); |
| 872 | + } |
| 873 | + } ); |
| 874 | + break; |
| 875 | + } |
| 876 | + } |
778 | 877 | } |
779 | | - } ); |
| 878 | + ); |
780 | 879 | } |
781 | 880 | }, |
| 881 | + |
782 | 882 | /* |
783 | 883 | * checkForCopyURLPermission: |
784 | | - * not really necessary the api request to upload will return appropriate error if the user lacks permission. or $wgAllowCopyUploads is set to false |
| 884 | + * not really necessary the api request to upload will return appropriate error |
| 885 | + * if the user lacks permission. or $wgAllowCopyUploads is set to false |
785 | 886 | * (use this function if we want to issue a warning up front) |
786 | 887 | */ |
787 | | - checkForCopyURLPermission:function( callback ) { |
| 888 | + checkForCopyURLPermission: function( callback ) { |
788 | 889 | var _this = this; |
789 | 890 | // do api check: |
790 | | - do_api_req( { |
| 891 | + do_api_req( |
| 892 | + { |
791 | 893 | 'data': { 'action' : 'query', 'meta' : 'userinfo', 'uiprop' : 'rights' }, |
792 | 894 | 'url': _this.upload_api_target, |
793 | 895 | 'userinfo' : true |
794 | | - }, function( data ) { |
795 | | - for ( var i in data.query.userinfo.rights ) { |
796 | | - var right = data.query.userinfo.rights[i]; |
797 | | - // js_log('checking: ' + right ) ; |
798 | | - if ( right == 'upload_by_url' ) { |
799 | | - callback( true ); |
800 | | - return true; // break out of the function |
| 896 | + }, function( data ) { |
| 897 | + for ( var i in data.query.userinfo.rights ) { |
| 898 | + var right = data.query.userinfo.rights[i]; |
| 899 | + // js_log('checking: ' + right ) ; |
| 900 | + if ( right == 'upload_by_url' ) { |
| 901 | + callback( true ); |
| 902 | + return true; // break out of the function |
| 903 | + } |
801 | 904 | } |
802 | | - } |
803 | | - callback( false ); |
804 | | - } ); |
| 905 | + callback( false ); |
| 906 | + } |
| 907 | + ); |
805 | 908 | }, |
806 | | - getLibSearchResults:function( cp ) { |
| 909 | + |
| 910 | + getLibSearchResults: function( provider ) { |
807 | 911 | var _this = this; |
808 | 912 | |
809 | | - // first check if we should even run the search at all (can we import / insert into the page? ) |
810 | | - if ( !this.checkRepoLocal( cp ) && this.import_url_mode == 'autodetect' ) { |
811 | | - // cp is not local check if we can support the import mode: |
| 913 | + // first check if we should even run the search at all (can we import / insert |
| 914 | + // into the page? ) |
| 915 | + if ( !this.isProviderLocal( provider ) && this.import_url_mode == 'autodetect' ) { |
| 916 | + // provider is not local check if we can support the import mode: |
812 | 917 | this.checkForCopyURLSupport( function() { |
813 | | - _this.getLibSearchResults( cp ); |
| 918 | + _this.getLibSearchResults( provider ); |
814 | 919 | } ); |
815 | 920 | return false; |
816 | | - } else if ( !this.checkRepoLocal( cp ) && this.import_url_mode == 'none' ) { |
817 | | - if ( this.disp_item == 'combined' ) { |
| 921 | + } else if ( !this.isProviderLocal( provider ) && this.import_url_mode == 'none' ) { |
| 922 | + if ( this.currentProvider == 'combined' ) { |
818 | 923 | // combined results are harder to error handle just ignore that repo |
819 | | - cp.sObj.loading = false; |
| 924 | + provider.sObj.loading = false; |
820 | 925 | } else { |
821 | | - $j( '#tab-' + this.disp_item ).html( '<div style="padding:10px">' + gM( 'mwe-no_import_by_url' ) + '</div>' ); |
| 926 | + $j( '#tab-' + this.currentProvider ).html( |
| 927 | + '<div style="padding:10px">' + |
| 928 | + gM( 'mwe-no_import_by_url' ) + |
| 929 | + '</div>' ); |
822 | 930 | } |
823 | 931 | return false; |
824 | 932 | } |
825 | | - _this.loadSearchLib( cp, function() { |
| 933 | + _this.loadSearchLib( provider, function() { |
826 | 934 | // Do the search |
827 | | - cp.sObj.getSearchResults(); |
828 | | - _this.checkResultsDone(); |
| 935 | + provider.sObj.getSearchResults(); |
| 936 | + _this.waitForResults( function() { |
| 937 | + this.showResults(); |
| 938 | + } ); |
829 | 939 | } ); |
830 | 940 | }, |
831 | | - loadSearchLib:function( cp, callback ) { |
| 941 | + |
| 942 | + loadSearchLib: function( provider, callback ) { |
832 | 943 | var _this = this; |
833 | 944 | // set up the library req: |
834 | 945 | mvJsLoader.doLoad( [ |
835 | 946 | 'baseRemoteSearch', |
836 | | - cp.lib + 'Search' |
| 947 | + provider.lib + 'Search' |
837 | 948 | ], function() { |
838 | | - js_log( "loaded lib:: " + cp.lib ); |
| 949 | + js_log( "loaded lib:: " + provider.lib ); |
839 | 950 | // else we need to run the search: |
840 | | - var iObj = { |
841 | | - 'cp' : cp, |
842 | | - 'rsd' : _this |
| 951 | + var options = { |
| 952 | + 'provider': provider, |
| 953 | + 'rsd': _this |
843 | 954 | }; |
844 | | - eval( 'cp.sObj = new ' + cp.lib + 'Search( iObj );' ); |
845 | | - if ( !cp.sObj ) { |
| 955 | + eval( 'provider.sObj = new ' + provider.lib + 'Search( options );' ); |
| 956 | + if ( !provider.sObj ) { |
846 | 957 | js_log( 'Error: could not find search lib for ' + cp_id ); |
847 | 958 | return false; |
848 | 959 | } |
849 | 960 | |
850 | 961 | // inherit defaults if not set: |
851 | | - cp.limit = ( cp.limit ) ? cp.limit : cp.sObj.limit; |
852 | | - cp.offset = ( cp.offset ) ? cp.offset : cp.sObj.offset; |
| 962 | + provider.limit = provider.limit ? provider.limit : provider.sObj.limit; |
| 963 | + provider.offset = provider.offset ? provider.offset : provider.sObj.offset; |
853 | 964 | callback(); |
854 | 965 | } ); |
855 | 966 | }, |
| 967 | + |
856 | 968 | /* check for all the results to finish */ |
857 | | - checkResultsDone: function() { |
858 | | - // js_log('rsd:checkResultsDone'); |
| 969 | + waitForResults: function( callback ) { |
| 970 | + // js_log('rsd:waitForResults'); |
859 | 971 | var _this = this; |
860 | 972 | var loading_done = true; |
861 | 973 | |
862 | | - for ( var cp_id in this.content_providers ) { |
| 974 | + for ( var cp_id in this.content_providers ) { |
863 | 975 | var cp = this.content_providers[ cp_id ]; |
864 | 976 | if ( typeof cp['sObj'] != 'undefined' ) { |
865 | 977 | if ( cp.sObj.loading ) |
— | — | @@ -866,666 +978,826 @@ |
867 | 979 | } |
868 | 980 | } |
869 | 981 | if ( loading_done ) { |
870 | | - this.drawOutputResults(); |
| 982 | + callback(); |
871 | 983 | } else { |
872 | | - // make sure the instance name is up-to-date refrerance to _this; |
873 | | - eval( _this.instance_name + ' = _this' ); |
874 | | - setTimeout( _this.instance_name + '.checkResultsDone()', 50 ); |
| 984 | + setTimeout( |
| 985 | + function() { |
| 986 | + _this.waitForResults( callback ); |
| 987 | + }, |
| 988 | + 50 |
| 989 | + ); |
875 | 990 | } |
876 | 991 | }, |
877 | | - drawTabs: function() { |
| 992 | + |
| 993 | + createTabs: function() { |
878 | 994 | var _this = this; |
879 | 995 | // add the tabs to the rsd_results container: |
880 | | - var o = '<div id="rsd_tabs_container" style="width:100%;">'; |
| 996 | + var s = '<div id="rsd_tabs_container" style="width:100%;">'; |
881 | 997 | var selected_tab = 0; |
882 | | - var inx = 0; |
883 | | - o += '<ul>'; |
884 | | - var tabc = ''; |
885 | | - for ( var cp_id in this.content_providers ) { |
886 | | - var cp = this.content_providers[cp_id]; |
887 | | - if ( cp.enabled && cp.checked && cp.api_url ) { |
888 | | - // add selected default if set |
889 | | - if ( this.disp_item == cp_id ) |
890 | | - selected_tab = inx; |
| 998 | + var index = 0; |
| 999 | + s += '<ul>'; |
| 1000 | + var content = ''; |
| 1001 | + for ( var providerName in this.content_providers ) { |
| 1002 | + var provider = this.content_providers[providerName]; |
| 1003 | + var tabImage = mv_embed_path + '/skins/common/remote_cp/' + providerName + '_tab.png'; |
| 1004 | + if ( provider.enabled && provider.checked && provider.api_url ) { |
| 1005 | + // add selected default if set |
| 1006 | + if ( this.currentProvider == providerName ) |
| 1007 | + selected_tab = index; |
891 | 1008 | |
892 | | - o += '<li class="rsd_cp_tab">'; |
893 | | - o += '<a id="rsd_tab_' + cp_id + '" href="#tab-' + cp_id + '">'; |
894 | | - if ( cp.tab_img === true ) { |
895 | | - o += '<img alt="' + gM( 'rsd-' + cp_id + '-title' ) + '" src="' + mv_embed_path + '/skins/common/remote_cp/' + cp_id + '_tab.png">'; |
896 | | - } else { |
897 | | - o += gM( 'rsd-' + cp_id + '-title' ); |
898 | | - } |
899 | | - o += '</a>'; |
900 | | - o += '</li>'; |
901 | | - inx++; |
902 | | - } |
903 | | - tabc += '<div id="tab-' + cp_id + '" class="rsd_results"/>'; |
904 | | - |
| 1009 | + s += '<li class="rsd_cp_tab">'; |
| 1010 | + s += '<a id="rsd_tab_' + providerName + '" href="#tab-' + providerName + '">'; |
| 1011 | + if ( provider.tab_img === true ) { |
| 1012 | + s += '<img alt="' + gM( 'rsd-' + providerName + '-title' ) + '" ' + |
| 1013 | + 'src="' + tabImage + '">'; |
| 1014 | + } else { |
| 1015 | + s += gM( 'rsd-' + providerName + '-title' ); |
| 1016 | + } |
| 1017 | + s += '</a>'; |
| 1018 | + s += '</li>'; |
| 1019 | + index++; |
905 | 1020 | } |
906 | | - // Do an upload tab if enabled: |
907 | | - if ( this.content_providers['upload'].enabled ) { |
908 | | - o += '<li class="rsd_cp_tab" ><a id="rsd_tab_upload" href="#tab-upload">' + gM( 'mwe-upload_tab' ) + '</a></li>'; |
909 | | - tabc += '<div id="tab-upload" />'; |
910 | | - if ( this.disp_item == 'upload' ) |
911 | | - selected_tab = inx++; |
912 | | - } |
913 | | - o += '</ul>'; |
914 | | - // Output the tab content containers: |
915 | | - o += tabc; |
916 | | - o += '</div>'; // close tab container |
| 1021 | + content += '<div id="tab-' + providerName + '" class="rsd_results"/>'; |
| 1022 | + } |
| 1023 | + // Do an upload tab if enabled: |
| 1024 | + if ( this.content_providers['upload'].enabled ) { |
| 1025 | + s += '<li class="rsd_cp_tab" >' + |
| 1026 | + '<a id="rsd_tab_upload" href="#tab-upload">' + |
| 1027 | + gM( 'mwe-upload_tab' ) + |
| 1028 | + '</a></li>'; |
| 1029 | + content += '<div id="tab-upload" />'; |
| 1030 | + if ( this.currentProvider == 'upload' ) |
| 1031 | + selected_tab = index++; |
| 1032 | + } |
| 1033 | + s += '</ul>'; |
| 1034 | + // Output the tab content containers: |
| 1035 | + s += content; |
| 1036 | + s += '</div>'; // close tab container |
917 | 1037 | |
918 | 1038 | // Output the respective results holders |
919 | | - $j( '#rsd_results_container' ).html( o ); |
| 1039 | + $j( '#rsd_results_container' ).html( s ); |
920 | 1040 | // Setup bindings for tabs make them sortable: (@@todo remember order) |
921 | 1041 | js_log( 'selected tab is: ' + selected_tab ); |
922 | | - $j( "#rsd_tabs_container" ).tabs( { |
923 | | - selected:selected_tab, |
924 | | - select: function( event, ui ) { |
925 | | - _this.selectTab( $j( ui.tab ).attr( 'id' ).replace( 'rsd_tab_', '' ) ); |
926 | | - } |
927 | | - // Add sorting |
928 | | - } ).find( ".ui-tabs-nav" ).sortable( { axis:'x' } ); |
929 | | - // @@todo store sorted repo |
| 1042 | + $j( "#rsd_tabs_container" ) |
| 1043 | + .tabs( { |
| 1044 | + selected: selected_tab, |
| 1045 | + select: function( event, ui ) { |
| 1046 | + _this.selectTab( $j( ui.tab ).attr( 'id' ).replace( 'rsd_tab_', '' ) ); |
| 1047 | + } |
| 1048 | + }) |
| 1049 | + // Add sorting |
| 1050 | + .find( ".ui-tabs-nav" ).sortable( { axis: 'x' } ); |
| 1051 | + // @@todo store sorted repo |
| 1052 | + }, |
930 | 1053 | |
931 | | - }, |
932 | 1054 | // Resource title |
933 | | - getResourceFromTitle : function( rTitle , callback ) { |
| 1055 | + getResourceFromTitle: function( title, callback ) { |
934 | 1056 | var _this = this; |
935 | 1057 | reqObj = { |
936 | | - 'action':'query', |
937 | | - 'titles': _this.cFileNS + ':' + rTitle |
| 1058 | + 'action': 'query', |
| 1059 | + 'titles': _this.cFileNS + ':' + title |
938 | 1060 | }; |
939 | 1061 | do_api_req( { |
940 | | - 'data':reqObj, |
941 | | - 'url':this.local_wiki_api_url |
| 1062 | + 'data': reqObj, |
| 1063 | + 'url': this.local_wiki_api_url |
942 | 1064 | }, function( data ) { |
943 | | - // @@todo propagate the rObj |
944 | | - var rObj = { }; |
| 1065 | + // @@todo propagate the resource |
| 1066 | + var resource = {}; |
945 | 1067 | } |
946 | 1068 | ); |
947 | 1069 | }, |
| 1070 | + |
948 | 1071 | // @@todo we could load the id with the content provider id to find the object faster... |
949 | | - getResourceFromId:function( rid ) { |
950 | | - //js_log('getResourceFromId:' + rid ); |
951 | | - // strip out /res/ if preset: |
952 | | - rid = rid.replace( /res_/, '' ); |
953 | | - // js_log("looking at: " + rid); |
954 | | - p = rid.split( '__' ); |
955 | | - var cp_id = p[0]; |
956 | | - var rid = p[1]; |
957 | | - |
958 | | - // Set the upload helper cp_id (to render recent uploads by this user) |
959 | | - if ( cp_id == 'upload' ) |
960 | | - cp_id = 'this_wiki'; |
| 1072 | + getResourceFromId: function( id ) { |
| 1073 | + var parts = id.replace( /^res_/, '' ).split( '__' ); |
| 1074 | + var providerName = parts[0]; |
| 1075 | + var resIndex = parts[1]; |
961 | 1076 | |
962 | | - var cp = this.content_providers[cp_id]; |
963 | | - if ( cp && cp['sObj'] && cp.sObj.resultsObj[rid] ) { |
964 | | - return cp.sObj.resultsObj[rid]; |
| 1077 | + // Set the upload helper providerName (to render recent uploads by this user) |
| 1078 | + if ( providerName == 'upload' ) |
| 1079 | + providerName = 'this_wiki'; |
| 1080 | + |
| 1081 | + var provider = this.content_providers[providerName]; |
| 1082 | + if ( provider && provider['sObj'] && provider.sObj.resultsObj[resIndex] ) { |
| 1083 | + return provider.sObj.resultsObj[resIndex]; |
965 | 1084 | } |
966 | | - js_log( "ERROR: could not find " + rid ); |
| 1085 | + js_log( "ERROR: could not find " + resIndex ); |
967 | 1086 | return false; |
968 | 1087 | }, |
969 | | - drawOutputResults: function() { |
970 | | - js_log( 'f:drawOutputResults::' + this.disp_item ); |
| 1088 | + |
| 1089 | + showResults: function() { |
| 1090 | + js_log( 'f:showResults::' + this.currentProvider ); |
971 | 1091 | var _this = this; |
972 | 1092 | var o = ''; |
973 | | - |
974 | | - var cp_id = this.disp_item; |
975 | | - var tab_target = ''; |
976 | | - if ( this.disp_item == 'upload' ) { |
977 | | - tab_target = '#upload_bin'; |
978 | | - var cp = _this.content_providers['this_wiki']; |
| 1093 | + var tabSelector = ''; |
| 1094 | + |
| 1095 | + if ( this.currentProvider == 'upload' ) { |
| 1096 | + tabSelector = '#upload_bin'; |
| 1097 | + var provider = _this.content_providers['this_wiki']; |
979 | 1098 | } else { |
980 | | - var cp = this.content_providers[this.disp_item]; |
981 | | - tab_target = '#tab-' + cp_id; |
982 | | - // Output the results bar / controls |
| 1099 | + var provider = this.content_providers[this.currentProvider]; |
| 1100 | + tabSelector = '#tab-' + this.currentProvider; |
| 1101 | + // Output the results bar / controls |
983 | 1102 | } |
984 | 1103 | // Empty the existing results: |
985 | | - $j( tab_target ).empty(); |
986 | | - // @@todo give the user upload control love |
987 | | - if ( this.disp_item != 'upload' ) { |
988 | | - _this.setResultBarControl(); |
| 1104 | + $j( tabSelector ).empty(); |
| 1105 | + // @@todo give the user upload control love |
| 1106 | + if ( this.currentProvider != 'upload' ) { |
| 1107 | + _this.showResultsHeader(); |
989 | 1108 | } |
990 | | - |
991 | | - var drawResultCount = 0; |
992 | 1109 | |
993 | | - // Output all the results for the current disp_item |
994 | | - if ( typeof cp['sObj'] != 'undefined' ) { |
995 | | - $j.each( cp.sObj.resultsObj, function( rInx, rItem ) { |
996 | | - if ( _this.result_display_mode == 'box' ) { |
997 | | - o += '<div id="mv_result_' + rInx + '" class="mv_clip_box_result" style="width:' + |
998 | | - _this.thumb_width + 'px;height:' + ( _this.thumb_width - 20 ) + 'px;position:relative;">'; |
999 | | - // Check for missing poster types for audio |
1000 | | - if ( rItem.mime == 'audio/ogg' && !rItem.poster ) { |
1001 | | - rItem.poster = mv_skin_img_path + 'sound_music_icon-80.png'; |
1002 | | - } |
1003 | | - // Get a thumb with proper resolution transform if possible: |
1004 | | - o += '<img title="' + rItem.title + '" class="rsd_res_item" id="res_' + cp_id + '__' + rInx + |
1005 | | - '" style="width:' + _this.thumb_width + 'px;" src="' + |
1006 | | - cp.sObj.getImageTransform( rItem, { 'width' : _this.thumb_width } ) |
1007 | | - + '">'; |
1008 | | - // Add a linkback to resource page in upper right: |
1009 | | - if ( rItem.link ) |
1010 | | - o += '<div class="rsd_linkback ui-corner-all ui-state-default ui-widget-content" >' + |
1011 | | - '<a target="_new" title="' + gM( 'mwe-resource_description_page' ) + |
1012 | | - '" href="' + rItem.link + '">' + gM( 'mwe-link' ) + '</a>' + |
1013 | | - '</div>'; |
1014 | | - |
1015 | | - // Add file type icon if known |
1016 | | - if ( rItem.mime ) { |
1017 | | - o += _this.getTypeIcon( rItem.mime ); |
1018 | | - } |
1019 | | - |
1020 | | - // Add license icons if present |
1021 | | - if ( rItem.license ) |
1022 | | - o += _this.getlicenseImgSet( rItem.license ); |
1023 | | - |
1024 | | - o += '</div>'; |
1025 | | - } else if ( _this.result_display_mode == 'list' ) { |
1026 | | - o += '<div id="mv_result_' + rInx + '" class="mv_clip_list_result" style="width:90%">'; |
1027 | | - o += '<img title="' + rItem.title + '" class="rsd_res_item" id="res_' + cp_id + '__' + rInx + '" style="float:left;width:' + |
1028 | | - _this.thumb_width + 'px;" src="' + |
1029 | | - cp.sObj.getImageTransform( rItem, { 'width':_this.thumb_width } ) |
1030 | | - + '">'; |
1031 | | - // Add license icons if present |
1032 | | - if ( rItem.license ) |
1033 | | - o += _this.getlicenseImgSet( rItem.license ); |
| 1110 | + var numResults = 0; |
1034 | 1111 | |
1035 | | - o += rItem.desc ; |
1036 | | - o += '<div style="clear:both" />'; |
1037 | | - o += '</div>'; |
1038 | | - } |
1039 | | - drawResultCount++; |
| 1112 | + // Output all the results for the current currentProvider |
| 1113 | + if ( typeof provider['sObj'] != 'undefined' ) { |
| 1114 | + $j.each( provider.sObj.resultsObj, function( resIndex, resource ) { |
| 1115 | + o += _this.getResultHtml( provider, resIndex, resource ); |
| 1116 | + numResults++; |
1040 | 1117 | } ); |
1041 | 1118 | js_log( 'append to: ' + '#tab-' + cp_id ); |
1042 | 1119 | // Put in the tab output (plus clear the output) |
1043 | | - $j( tab_target ).append( o + '<div style="clear:both"/>' ); |
| 1120 | + $j( tabSelector ).append( o + '<div style="clear:both"/>' ); |
1044 | 1121 | } |
1045 | 1122 | |
1046 | | - js_log( 'did drawResultCount :: ' + drawResultCount + ' append: ' + $j( '#rsd_q' ).val() ); |
| 1123 | + js_log( 'did numResults :: ' + numResults + |
| 1124 | + ' append: ' + $j( '#rsd_q' ).val() ); |
1047 | 1125 | |
1048 | 1126 | // Remove any old search res |
1049 | 1127 | $j( '#rsd_no_search_res' ).remove(); |
1050 | | - if ( drawResultCount == 0 ) |
1051 | | - $j( '#tab-' + cp_id ).append( '<span style="padding:10px">' + gM( 'rsd_no_results', $j( '#rsd_q' ).val() ) + '</span>' ); |
1052 | | - |
| 1128 | + if ( numResults == 0 ) { |
| 1129 | + $j( '#tab-' + cp_id ).append( |
| 1130 | + '<span style="padding:10px">' + |
| 1131 | + gM( 'rsd_no_results', $j( '#rsd_q' ).val() ) + |
| 1132 | + '</span>' ); |
| 1133 | + } |
1053 | 1134 | this.addResultBindings(); |
1054 | 1135 | }, |
1055 | | - addResultBindings:function() { |
| 1136 | + |
| 1137 | + getResultHtml: function( provider, resIndex, resource ) { |
| 1138 | + var o = ''; |
| 1139 | + if ( this.displayMode == 'box' ) { |
| 1140 | + o += '<div id="mv_result_' + resIndex + '" ' + |
| 1141 | + 'class="mv_clip_box_result" ' + |
| 1142 | + 'style="' + |
| 1143 | + 'width:' + this.thumb_width + 'px;' + |
| 1144 | + 'height:' + ( this.thumb_width - 20 ) + 'px;' + |
| 1145 | + 'position:relative;">'; |
| 1146 | + // Check for missing poster types for audio |
| 1147 | + if ( resource.mime == 'audio/ogg' && !resource.poster ) { |
| 1148 | + resource.poster = mv_skin_img_path + 'sound_music_icon-80.png'; |
| 1149 | + } |
| 1150 | + // Get a thumb with proper resolution transform if possible: |
| 1151 | + var thumbUrl = provider.sObj.getImageTransform( resource, |
| 1152 | + { 'width' : this.thumb_width } ); |
| 1153 | + |
| 1154 | + o += '<img title="' + resource.title + '" ' + |
| 1155 | + 'class="rsd_res_item" id="res_' + cp_id + '__' + resIndex + '" ' + |
| 1156 | + 'style="width:' + this.thumb_width + 'px;" ' + |
| 1157 | + 'src="' + thumbUrl + '">'; |
| 1158 | + // Add a linkback to resource page in upper right: |
| 1159 | + if ( resource.link ) { |
| 1160 | + o += '<div class="' + |
| 1161 | + 'rsd_linkback ui-corner-all ui-state-default ui-widget-content" >' + |
| 1162 | + '<a target="_new" title="' + gM( 'mwe-resource_description_page' ) + |
| 1163 | + '" href="' + resource.link + '">' + gM( 'mwe-link' ) + '</a>' + |
| 1164 | + '</div>'; |
| 1165 | + } |
| 1166 | + |
| 1167 | + // Add file type icon if known |
| 1168 | + if ( resource.mime ) { |
| 1169 | + o += this.getTypeIcon( resource.mime ); |
| 1170 | + } |
| 1171 | + |
| 1172 | + // Add license icons if present |
| 1173 | + if ( resource.license ) |
| 1174 | + o += this.getLicenseIconHtml( resource.license ); |
| 1175 | + |
| 1176 | + o += '</div>'; |
| 1177 | + } else if ( this.displayMode == 'list' ) { |
| 1178 | + o += '<div id="mv_result_' + resIndex + '" class="mv_clip_list_result" style="width:90%">'; |
| 1179 | + o += |
| 1180 | + '<img ' + |
| 1181 | + 'title="' + resource.title + '" ' + |
| 1182 | + 'class="rsd_res_item" id="res_' + cp_id + '__' + resIndex + '" ' + |
| 1183 | + 'style="float:left;width:' + this.thumb_width + 'px;" ' + |
| 1184 | + 'src="' + provider.sObj.getImageTransform( resource, { 'width': this.thumb_width } ) + '">'; |
| 1185 | + // Add license icons if present |
| 1186 | + if ( resource.license ) |
| 1187 | + o += this.getLicenseIconHtml( resource.license ); |
| 1188 | + |
| 1189 | + o += resource.desc ; |
| 1190 | + o += '<div style="clear:both" />'; |
| 1191 | + o += '</div>'; |
| 1192 | + } |
| 1193 | + return o; |
| 1194 | + } |
| 1195 | + |
| 1196 | + addResultBindings: function() { |
1056 | 1197 | var _this = this; |
1057 | | - $j( '.mv_clip_' + _this.result_display_mode + '_result' ).hover( function() { |
1058 | | - $j( this ).addClass( 'mv_clip_' + _this.result_display_mode + '_result_over' ); |
1059 | | - // Also set the animated image if available |
1060 | | - var res_id = $j( this ).children( '.rsd_res_item' ).attr( 'id' ); |
1061 | | - var rObj = _this.getResourceFromId( res_id ); |
1062 | | - if ( rObj.poster_ani ) |
1063 | | - $j( '#' + res_id ).attr( 'src', rObj.poster_ani ); |
1064 | | - }, function() { |
1065 | | - $j( this ).removeClass( 'mv_clip_' + _this.result_display_mode + '_result_over' ); |
1066 | | - var res_id = $j( this ).children( '.rsd_res_item' ).attr( 'id' ); |
1067 | | - var rObj = _this.getResourceFromId( res_id ); |
1068 | | - // Restore the original (non animated) |
1069 | | - if ( rObj.poster_ani ) |
1070 | | - $j( '#' + res_id ).attr( 'src', rObj.poster ); |
1071 | | - } ); |
| 1198 | + $j( '.mv_clip_' + _this.displayMode + '_result' ).hover( |
| 1199 | + function() { |
| 1200 | + $j( this ).addClass( 'mv_clip_' + _this.displayMode + '_result_over' ); |
| 1201 | + // Also set the animated image if available |
| 1202 | + var res_id = $j( this ).children( '.rsd_res_item' ).attr( 'id' ); |
| 1203 | + var resource = _this.getResourceFromId( res_id ); |
| 1204 | + if ( resource.poster_ani ) |
| 1205 | + $j( '#' + res_id ).attr( 'src', resource.poster_ani ); |
| 1206 | + }, function() { |
| 1207 | + $j( this ).removeClass( |
| 1208 | + 'mv_clip_' + _this.displayMode + '_result_over' ); |
| 1209 | + var res_id = $j( this ).children( '.rsd_res_item' ).attr( 'id' ); |
| 1210 | + var resource = _this.getResourceFromId( res_id ); |
| 1211 | + // Restore the original (non animated) |
| 1212 | + if ( resource.poster_ani ) |
| 1213 | + $j( '#' + res_id ).attr( 'src', resource.poster ); |
| 1214 | + } |
| 1215 | + ); |
1072 | 1216 | // Resource click action: (bring up the resource editor) |
1073 | 1217 | $j( '.rsd_res_item' ).unbind().click( function() { |
1074 | | - var rObj = _this.getResourceFromId( $j( this ).attr( "id" ) ); |
1075 | | - _this.resourceEdit( rObj, this ); |
| 1218 | + var resource = _this.getResourceFromId( $j( this ).attr( "id" ) ); |
| 1219 | + _this.showResourceEditor( resource, this ); |
1076 | 1220 | } ); |
1077 | 1221 | }, |
1078 | | - addResourceEditLoader:function( maxWidth, overflow_style ) { |
| 1222 | + |
| 1223 | + addResourceEditLoader: function( maxWidth, overflowStyle ) { |
1079 | 1224 | var _this = this; |
1080 | | - if ( !maxWidth )maxWidth = 400; |
1081 | | - if ( !overflow_style )overflow_style = 'overflow:auto;'; |
| 1225 | + if ( !maxWidth ) maxWidth = 400; |
| 1226 | + if ( !overflowStyle ) overflowStyle = 'overflow:auto;'; |
1082 | 1227 | // Remove any old instance: |
1083 | 1228 | $j( _this.target_container ).find( '#rsd_resource_edit' ).remove(); |
1084 | | - |
| 1229 | + |
1085 | 1230 | // Hide the results container |
1086 | 1231 | $j( '#rsd_results_container' ).hide(); |
1087 | | - |
| 1232 | + |
1088 | 1233 | var pt = $j( _this.target_container ).html(); |
1089 | 1234 | // Add the edit layout window with loading place holders |
1090 | | - $j( _this.target_container ).append( '<div id="rsd_resource_edit" ' + |
1091 | | - 'style="position:absolute;top:0px;left:0px;bottom:0px;right:4px;background-color:#FFF;"> ' + |
1092 | | - '<div id="clip_edit_ctrl" class="ui-widget ui-widget-content ui-corner-all" style="position:absolute;' + |
1093 | | - 'left:2px;top:5px;bottom:10px;width:' + ( maxWidth + 5 ) + 'px;overflow:auto;padding:5px;" >' + |
1094 | | - '</div>' + |
1095 | | - '<div id="clip_edit_disp" class="ui-widget ui-widget-content ui-corner-all"' + |
1096 | | - 'style="position:absolute;' + overflow_style + ';left:' + ( maxWidth + 20 ) + 'px;right:0px;top:5px;bottom:10px;padding:5px;" >' + |
1097 | | - mv_get_loading_img( 'position:absolute;top:30px;left:30px' ) + |
1098 | | - '</div>' + |
1099 | | - '</div>' ); |
| 1235 | + $j( _this.target_container ).append( |
| 1236 | + '<div id="rsd_resource_edit" ' + |
| 1237 | + 'style="position:absolute;top:0px;left:0px;' + |
| 1238 | + 'bottom:0px;right:4px;background-color:#FFF;"> ' + |
| 1239 | + '<div id="clip_edit_ctrl" ' + |
| 1240 | + 'class="ui-widget ui-widget-content ui-corner-all" ' + |
| 1241 | + 'style="position:absolute;left:2px;top:5px;bottom:10px;' + |
| 1242 | + 'width:' + ( maxWidth + 5 ) + 'px;overflow:auto;padding:5px;" >' + |
| 1243 | + '</div>' + |
| 1244 | + '<div id="clip_edit_disp" ' + |
| 1245 | + 'class="ui-widget ui-widget-content ui-corner-all"' + |
| 1246 | + 'style="position:absolute;' + overflowStyle + ';' + |
| 1247 | + 'left:' + ( maxWidth + 20 ) + 'px;right:0px;top:5px;bottom:10px;' + |
| 1248 | + 'padding:5px;" >' + |
| 1249 | + mv_get_loading_img( 'position:absolute;top:30px;left:30px' ) + |
| 1250 | + '</div>' + |
| 1251 | + '</div>' ); |
1100 | 1252 | }, |
1101 | | - resourceEdit:function( rObj, rsdElement ) { |
1102 | | - js_log( 'f:resourceEdit:' + rObj.title ); |
1103 | | - var _this = this; |
1104 | | - // Remove any existing resource edit interface: |
1105 | | - $j( '#rsd_resource_edit' ).remove(); |
1106 | | - // set the media type: |
1107 | | - if ( rObj.mime.indexOf( 'image' ) != -1 ) { |
1108 | | - // Set width to default image_edit_width |
1109 | | - var maxWidth = _this.image_edit_width; |
1110 | | - var mediaType = 'image'; |
1111 | | - } else if ( rObj.mime.indexOf( 'audio' ) != -1 ) { |
1112 | | - var maxWidth = _this.video_edit_width; |
1113 | | - var mediaType = 'audio'; |
| 1253 | + |
| 1254 | + getEditWidth: function( resource ) { |
| 1255 | + var mediaType = this.getMediaType( resource ); |
| 1256 | + if ( mediaType == 'image' ) { |
| 1257 | + return resource.image_edit_width; |
1114 | 1258 | } else { |
1115 | | - // Set to default video size: |
1116 | | - var maxWidth = _this.video_edit_width; |
1117 | | - var mediaType = 'video'; |
| 1259 | + return resource.video_edit_width; |
1118 | 1260 | } |
1119 | | - // So that transcripts show ontop |
1120 | | - var overflow_style = ( mediaType == 'video' ) ? '':'overflow:auto;'; |
| 1261 | + }, |
| 1262 | + |
| 1263 | + getMediaType: function( resource ) { |
| 1264 | + if ( resource.mime.indexOf( 'image' ) != -1 ) { |
| 1265 | + return 'image'; |
| 1266 | + } else if ( resource.mime.indexOf( 'audio' ) != -1 ) { |
| 1267 | + return 'audio'; |
| 1268 | + } else { |
| 1269 | + return 'video'; |
| 1270 | + } |
| 1271 | + }, |
| 1272 | + |
| 1273 | + removeResourceEditor: function() { |
| 1274 | + $j( '#rsd_resource_edit' ).remove(); |
| 1275 | + $j( '#rsd_resource_edit' ).css( 'opacity', 0 ); |
| 1276 | + $j( '#rsd_edit_img' ).remove(); |
| 1277 | + } |
| 1278 | + |
| 1279 | + showResourceEditor: function( resource, rsdElement ) { |
| 1280 | + js_log( 'f:showResourceEditor:' + resource.title ); |
| 1281 | + var _this = this; |
| 1282 | + |
| 1283 | + // Remove any existing resource edit interface |
| 1284 | + _this.removeResourceEditor(); |
| 1285 | + |
| 1286 | + var mediaType = _this.getMediaType( resource ); |
| 1287 | + var maxWidth = _this.getEditWidth( resource ); |
| 1288 | + |
| 1289 | + // So that transcripts show on top |
| 1290 | + var overflow_style = ( mediaType == 'video' ) ? '' : 'overflow:auto;'; |
1121 | 1291 | // Append to the top level of model window: |
1122 | 1292 | _this.addResourceEditLoader( maxWidth, overflow_style ); |
1123 | 1293 | // update add media wizard title: |
1124 | | - $j( _this.target_container ).dialog( 'option', 'title', gM( 'mwe-add_media_wizard' ) + ': ' + gM( 'rsd_resource_edit', rObj.title ) ); |
| 1294 | + var dialogTitle = gM( 'mwe-add_media_wizard' ) + ': ' + |
| 1295 | + gM( 'rsd_resource_edit', resource.title ); |
| 1296 | + $j( _this.target_container ).dialog( 'option', 'title', dialogTitle ); |
1125 | 1297 | js_log( 'did append to: ' + _this.target_container ); |
1126 | 1298 | |
1127 | | - $j( '#rsd_resource_edit' ).css( 'opacity', 0 ); |
| 1299 | + // Left side holds the image right size the controls / |
| 1300 | + $j( rsdElement ) |
| 1301 | + .clone() |
| 1302 | + .attr( 'id', 'rsd_edit_img' ) |
| 1303 | + .appendTo( '#clip_edit_disp' ) |
| 1304 | + .css( { |
| 1305 | + 'position':'absolute', |
| 1306 | + 'top':'40%', |
| 1307 | + 'left':'20%', |
| 1308 | + 'cursor':'default', |
| 1309 | + 'opacity':0 |
| 1310 | + } ); |
1128 | 1311 | |
1129 | | - $j( '#rsd_edit_img' ).remove();// remove any existing rsd_edit_img |
1130 | | - |
1131 | | - // Left side holds the image right size the controls / |
1132 | | - $j( rsdElement ). clone ().attr( 'id', 'rsd_edit_img' ).appendTo( '#clip_edit_disp' ).css( { |
1133 | | - 'position':'absolute', |
1134 | | - 'top':'40%', |
1135 | | - 'left':'20%', |
1136 | | - 'cursor':'default', |
1137 | | - 'opacity':0 |
1138 | | - } ); |
1139 | | - |
1140 | | - // Try and keep aspect ratio for the thumbnail that we clicked: |
| 1312 | + // Try and keep aspect ratio for the thumbnail that we clicked: |
1141 | 1313 | var tRatio = $j( rsdElement ).height() / $j( rsdElement ).width(); |
1142 | 1314 | |
1143 | | - if (! tRatio ) |
1144 | | - var tRatio = 1; // set ratio to 1 if tRatio did not work. |
1145 | | - |
1146 | | - js_log( 'Set from ' + tRatio + ' to init thumbimage to ' + maxWidth + ' x ' + parseInt( tRatio * maxWidth ) ); |
| 1315 | + if ( !tRatio ) { |
| 1316 | + var tRatio = 1; // set ratio to 1 if tRatio did not work. |
| 1317 | + } |
| 1318 | + js_log( 'Set from ' + tRatio + ' to init thumbimage to ' + |
| 1319 | + maxWidth + ' x ' + parseInt( tRatio * maxWidth ) ); |
1147 | 1320 | // Scale up image and to swap with high res version |
1148 | | - $j( '#rsd_edit_img' ).animate( { |
1149 | | - 'opacity':1, |
1150 | | - 'top':'5px', |
1151 | | - 'left':'5px', |
1152 | | - 'width': maxWidth + 'px', |
1153 | | - 'height': parseInt( tRatio * maxWidth ) + 'px' |
1154 | | - }, "slow" ); // Do it slow to give it a chance to finish loading the HQ version |
| 1321 | + $j( '#rsd_edit_img' ).animate( |
| 1322 | + { |
| 1323 | + 'opacity': 1, |
| 1324 | + 'top': '5px', |
| 1325 | + 'left': '5px', |
| 1326 | + 'width': maxWidth + 'px', |
| 1327 | + 'height': parseInt( tRatio * maxWidth ) + 'px' |
| 1328 | + }, |
| 1329 | + "slow" ); // Do it slow to give it a chance to finish loading the high quality version |
1155 | 1330 | |
1156 | 1331 | if ( mediaType == 'image' ) { |
1157 | | - _this.loadHQImg( rObj, { 'width':maxWidth }, 'rsd_edit_img', function() { |
1158 | | - $j( '.mv_loading_img' ).remove(); |
1159 | | - } ); |
| 1332 | + _this.loadHighQualityImage( |
| 1333 | + resource, |
| 1334 | + { 'width': maxWidth }, |
| 1335 | + 'rsd_edit_img', |
| 1336 | + function() { |
| 1337 | + $j( '.mv_loading_img' ).remove(); |
| 1338 | + } |
| 1339 | + ); |
1160 | 1340 | } |
1161 | 1341 | // Also fade in the container: |
1162 | 1342 | $j( '#rsd_resource_edit' ).animate( { |
1163 | | - 'opacity':1, |
1164 | | - 'background-color':'#FFF', |
1165 | | - 'z-index':99 |
| 1343 | + 'opacity': 1, |
| 1344 | + 'background-color': '#FFF', |
| 1345 | + 'z-index': 99 |
1166 | 1346 | } ); |
1167 | | - // Do load the media Editor |
1168 | | - _this.doMediaEdit( rObj , mediaType ); |
| 1347 | + |
| 1348 | + // Show the editor itself |
| 1349 | + if ( mediaType == 'image' ) { |
| 1350 | + _this.showImageEditor( resource ); |
| 1351 | + } else if ( mediaType == 'video' || mediaType == 'audio' ) { |
| 1352 | + _this.showVideoEditor( resource ); |
| 1353 | + } |
1169 | 1354 | }, |
1170 | | - loadHQImg:function( rObj, size, target_img_id, callback ) { |
1171 | | - // Get the HQ image url: |
1172 | | - rObj.pSobj.getImageObj( rObj, size, function( imObj ) { |
1173 | | - rObj['edit_url'] = imObj.url; |
1174 | 1355 | |
1175 | | - js_log( "edit url: " + rObj.edit_url ); |
1176 | | - // Update the rObj |
1177 | | - rObj['width'] = imObj.width; |
1178 | | - rObj['height'] = imObj.height; |
| 1356 | + loadHighQualityImage: function( resource, size, target_img_id, callback ) { |
| 1357 | + // Get the high quality image url: |
| 1358 | + resource.pSobj.getImageObj( resource, size, function( imObj ) { |
| 1359 | + resource['edit_url'] = imObj.url; |
1179 | 1360 | |
| 1361 | + js_log( "edit url: " + resource.edit_url ); |
| 1362 | + // Update the resource |
| 1363 | + resource['width'] = imObj.width; |
| 1364 | + resource['height'] = imObj.height; |
| 1365 | + |
1180 | 1366 | // See if we need to animate some transition |
1181 | 1367 | if ( size.width != imObj.width ) { |
1182 | | - js_log( 'loadHQImg:size mismatch: ' + size.width + ' != ' + imObj.width ); |
| 1368 | + js_log( 'loadHighQualityImage:size mismatch: ' + size.width + ' != ' + imObj.width ); |
1183 | 1369 | // Set the target id to the new size: |
1184 | 1370 | $j( '#' + target_img_id ).animate( { |
1185 | | - 'width':imObj.width + 'px', |
1186 | | - 'height':imObj.height + 'px' |
1187 | | - } ); |
| 1371 | + 'width': imObj.width + 'px', |
| 1372 | + 'height': imObj.height + 'px' |
| 1373 | + }); |
1188 | 1374 | } else { |
1189 | 1375 | js_log( 'using req size: ' + imObj.width + 'x' + imObj.height ); |
1190 | | - $j( '#' + target_img_id ).animate( { 'width':imObj.width + 'px', 'height' : imObj.height + 'px' } ); |
| 1376 | + $j( '#' + target_img_id ).animate( { |
| 1377 | + 'width': imObj.width + 'px', |
| 1378 | + 'height': imObj.height + 'px' |
| 1379 | + }); |
1191 | 1380 | } |
1192 | 1381 | // Don't swap it in until its loaded: |
1193 | 1382 | var img = new Image(); |
1194 | 1383 | // Load the image image: |
1195 | 1384 | $j( img ).load( function () { |
1196 | | - $j( '#' + target_img_id ).attr( 'src', rObj.edit_url ); |
| 1385 | + $j( '#' + target_img_id ).attr( 'src', resource.edit_url ); |
1197 | 1386 | // Let the caller know we are done and what size we ended up with: |
1198 | 1387 | callback(); |
1199 | 1388 | } ).error( function () { |
1200 | | - js_log( "Error with: " + rObj.edit_url ); |
1201 | | - } ).attr( 'src', rObj.edit_url ); |
1202 | | - } ); |
| 1389 | + js_log( "Error with: " + resource.edit_url ); |
| 1390 | + } ).attr( 'src', resource.edit_url ); |
| 1391 | + } ); |
1203 | 1392 | }, |
1204 | | - cancelClipEditCB:function() { |
| 1393 | + |
| 1394 | + onCancelClipEdit: function() { |
1205 | 1395 | var _this = this; |
1206 | | - js_log( 'cancelClipEditCB' ); |
1207 | | - var b_target = _this.target_container + '~ .ui-dialog-buttonpane'; |
| 1396 | + js_log( 'onCancelClipEdit' ); |
| 1397 | + var b_target = _this.target_container + '~ .ui-dialog-buttonpane'; |
1208 | 1398 | $j( '#rsd_resource_edit' ).remove(); |
1209 | 1399 | // Remove preview if its 'on' |
1210 | 1400 | $j( '#rsd_preview_display' ).remove(); |
1211 | 1401 | // Restore the resource container: |
1212 | 1402 | $j( '#rsd_results_container' ).show(); |
1213 | | - |
| 1403 | + |
1214 | 1404 | // Restore the title: |
1215 | 1405 | $j( _this.target_container ).dialog( 'option', 'title', gM( 'mwe-add_media_wizard' ) ); |
1216 | 1406 | js_log( "should update: " + b_target + ' with: cancel' ); |
1217 | | - // Restore the buttons: |
1218 | | - $j( b_target ).html( $j.btnHtml( gM( 'mwe-cancel' ) , 'mv_cancel_rsd', 'close' ) ) |
| 1407 | + // Restore the buttons: |
| 1408 | + $j( b_target ) |
| 1409 | + .html( $j.btnHtml( gM( 'mwe-cancel' ) , 'mv_cancel_rsd', 'close' ) ) |
1219 | 1410 | .children( '.mv_cancel_rsd' ) |
1220 | 1411 | .btnBind() |
1221 | 1412 | .click( function() { |
1222 | 1413 | $j( _this.target_container ).dialog( 'close' ); |
1223 | 1414 | } ); |
1224 | 1415 | }, |
1225 | | - /* getClipEditControlActions |
1226 | | - * Set-up the control actions for clipEdit with relevant callbacks |
1227 | | - */ |
1228 | | - getClipEditControlActions:function( cp ) { |
| 1416 | + |
| 1417 | + /** |
| 1418 | + * Get the control actions for clipEdit with relevant callbacks |
| 1419 | + */ |
| 1420 | + getClipEditControlActions: function( provider ) { |
1229 | 1421 | var _this = this; |
1230 | | - var cConf = { }; |
| 1422 | + var actions = { }; |
1231 | 1423 | |
1232 | | - cConf['insert'] = function( rObj ) { |
1233 | | - _this.insertResource( rObj ); |
| 1424 | + actions['insert'] = function( resource ) { |
| 1425 | + _this.insertResource( resource ); |
1234 | 1426 | } |
1235 | 1427 | // If not directly inserting the resource is support a preview option: |
1236 | 1428 | if ( _this.import_url_mode != 'remote_link' ) { |
1237 | | - cConf['preview'] = function( rObj ) { |
1238 | | - _this.previewResource( rObj ) |
| 1429 | + actions['preview'] = function( resource ) { |
| 1430 | + _this.showPreview( resource ) |
1239 | 1431 | }; |
1240 | 1432 | } |
1241 | | - cConf['cancel'] = function() { |
1242 | | - _this.cancelClipEditCB() |
| 1433 | + actions['cancel'] = function() { |
| 1434 | + _this.onCancelClipEdit() |
1243 | 1435 | } |
1244 | | - return cConf; |
| 1436 | + return actions; |
1245 | 1437 | }, |
1246 | | - // Loads the media editor: |
1247 | | - doMediaEdit:function( rObj , mediaType ) { |
| 1438 | + |
| 1439 | + getClipEditOptions: function( resource ) { |
| 1440 | + return { |
| 1441 | + 'rObj': resource, |
| 1442 | + 'parent_ct': 'rsd_modal_target', |
| 1443 | + 'clip_disp_ct': 'clip_edit_disp', |
| 1444 | + 'control_ct': 'clip_edit_ctrl', |
| 1445 | + 'media_type': this.getMediaType( resource ), |
| 1446 | + 'p_rsdObj': this, |
| 1447 | + 'controlActionsCb': this.getClipEditControlActions( resource.pSobj.cp ), |
| 1448 | + 'enabled_tools': this.enabled_tools |
| 1449 | + }; |
| 1450 | + }, |
| 1451 | + |
| 1452 | + /** |
| 1453 | + * Internal function called by showResourceEditor() to show an image editor |
| 1454 | + */ |
| 1455 | + showImageEditor: function( resource ) { |
1248 | 1456 | var _this = this; |
1249 | | - var cp = rObj.pSobj.cp; |
1250 | | - js_log( 'remoteSearchDriver::doMediaEdit: ' + mediaType ); |
1251 | | - |
1252 | | - var mvClipInit = { |
1253 | | - 'rObj' : rObj, // the resource object |
1254 | | - 'parent_ct' : 'rsd_modal_target', |
1255 | | - 'clip_disp_ct' : 'clip_edit_disp', |
1256 | | - 'control_ct' : 'clip_edit_ctrl', |
1257 | | - 'media_type' : mediaType, |
1258 | | - 'p_rsdObj' : _this, |
1259 | | - 'controlActionsCb' : _this.getClipEditControlActions( cp ), |
1260 | | - 'enabled_tools' : _this.enabled_tools |
1261 | | - }; |
1262 | | - // Set the base clip edit lib class req set: |
1263 | | - var clibs = ['mvClipEdit']; |
1264 | | - |
1265 | | - if ( mediaType == 'image' ) { |
1266 | | - // Display the mvClipEdit obj once we are done loading: |
1267 | | - mvJsLoader.doLoad( clibs, function() { |
1268 | | - // Run the image clip tools |
1269 | | - _this.cEdit = new mvClipEdit( mvClipInit ); |
1270 | | - } ); |
1271 | | - } else if ( mediaType == 'video' || mediaType == 'audio' ) { |
1272 | | - js_log( 'media type:: ' + mediaType ); |
1273 | | - // Get any additional embedding helper meta data prior to doing the actual embed |
1274 | | - // normally this meta should be provided in the search result (but archive.org has another query for more media meta) |
1275 | | - rObj.pSobj.addResourceInfoCallback( rObj, function() { |
1276 | | - // Make sure we have the embedVideo libs: |
1277 | | - var runFlag = false; |
1278 | | - mvJsLoader.embedVideoCheck( function() { |
1279 | | - // Strange concurrency issue with callbacks |
1280 | | - // @@todo try and figure out why this callback is fired twice |
1281 | | - if ( !runFlag ) { |
1282 | | - runFlag = true; |
1283 | | - } else { |
1284 | | - js_log( 'Error: embedVideoCheck run twice' ); |
1285 | | - return false; |
1286 | | - } |
1287 | | - js_log( 'append html: ' + rObj.pSobj.getEmbedHTML( rObj, { id:'embed_vid' } ) ); |
1288 | | - $j( '#clip_edit_disp' ).html( |
1289 | | - rObj.pSobj.getEmbedHTML( rObj, { |
1290 | | - id : 'embed_vid' |
1291 | | - } ) |
1292 | | - ); |
1293 | | - js_log( "about to call rewrite_by_id::embed_vid" ); |
1294 | | - // Rewrite by id |
1295 | | - rewrite_by_id( 'embed_vid', function() { |
1296 | | - // Grab information avaliable from the embed instance |
1297 | | - rObj.pSobj.addResourceInfoFromEmbedInstance( rObj, 'embed_vid' ); |
1298 | | - |
1299 | | - // Add the re-sizable to the doLoad request: |
1300 | | - clibs.push( '$j.ui.resizable' ); |
1301 | | - clibs.push( '$j.fn.hoverIntent' ); |
1302 | | - mvJsLoader.doLoad( clibs, function() { |
1303 | | - // Make sure the rsd_edit_img is removed: |
1304 | | - $j( '#rsd_edit_img' ).remove(); |
1305 | | - // Run the image clip tools |
1306 | | - _this.cEdit = new mvClipEdit( mvClipInit ); |
1307 | | - } ); |
| 1457 | + var options = _this.getClipEditOptions( resource ); |
| 1458 | + // Display the mvClipEdit obj once we are done loading: |
| 1459 | + mvJsLoader.doLoad( clibs, function() { |
| 1460 | + // Run the image clip tools |
| 1461 | + _this.clipEdit = new mvClipEdit( options ); |
| 1462 | + } ); |
| 1463 | + }, |
| 1464 | + |
| 1465 | + /** |
| 1466 | + * Internal function called by showResourceEditor() to show a video or audio |
| 1467 | + * editor. |
| 1468 | + */ |
| 1469 | + showVideoEditor: function( resource ) { |
| 1470 | + var _this = this; |
| 1471 | + var options = _this.getClipEditOptions( resource ); |
| 1472 | + var mediaType = this.getMediaType( resource ); |
| 1473 | + |
| 1474 | + js_log( 'media type:: ' + mediaType ); |
| 1475 | + // Get any additional embedding helper meta data prior to doing the actual embed |
| 1476 | + // normally this meta should be provided in the search result |
| 1477 | + // (but archive.org has another query for more media meta) |
| 1478 | + resource.pSobj.addResourceInfoCallback( resource, function() { |
| 1479 | + // Make sure we have the embedVideo libs: |
| 1480 | + var runFlag = false; |
| 1481 | + mvJsLoader.embedVideoCheck( function() { |
| 1482 | + // Strange concurrency issue with callbacks |
| 1483 | + // @@todo try and figure out why this callback is fired twice |
| 1484 | + if ( !runFlag ) { |
| 1485 | + runFlag = true; |
| 1486 | + } else { |
| 1487 | + js_log( 'Error: embedVideoCheck run twice' ); |
| 1488 | + return false; |
| 1489 | + } |
| 1490 | + var embedHtml = resource.pSobj.getEmbedHTML( resource, |
| 1491 | + { id : 'embed_vid' } ); |
| 1492 | + js_log( 'append html: ' + embedHtml ); |
| 1493 | + $j( '#clip_edit_disp' ).html( embedHtml ); |
| 1494 | + js_log( "about to call rewrite_by_id::embed_vid" ); |
| 1495 | + // Rewrite by id |
| 1496 | + rewrite_by_id( 'embed_vid', function() { |
| 1497 | + // Grab information avaliable from the embed instance |
| 1498 | + resource.pSobj.addResourceInfoFromEmbedInstance( resource, 'embed_vid' ); |
| 1499 | + |
| 1500 | + // Add the re-sizable to the doLoad request: |
| 1501 | + clibs.push( '$j.ui.resizable' ); |
| 1502 | + clibs.push( '$j.fn.hoverIntent' ); |
| 1503 | + mvJsLoader.doLoad( clibs, function() { |
| 1504 | + // Make sure the rsd_edit_img is removed: |
| 1505 | + $j( '#rsd_edit_img' ).remove(); |
| 1506 | + // Run the image clip tools |
| 1507 | + _this.clipEdit = new mvClipEdit( options ); |
1308 | 1508 | } ); |
1309 | 1509 | } ); |
1310 | 1510 | } ); |
1311 | | - } |
| 1511 | + } ); |
1312 | 1512 | }, |
1313 | | - checkRepoLocal:function( cp ) { |
1314 | | - if ( cp.local ) { |
| 1513 | + |
| 1514 | + isProviderLocal: function( provider ) { |
| 1515 | + if ( provider.local ) { |
1315 | 1516 | return true; |
1316 | 1517 | } else { |
1317 | 1518 | // Check if we can embed the content locally per a domain name check: |
1318 | | - var local_host = mw.parseUri( this.local_wiki_api_url ).host; |
1319 | | - if ( cp.local_domains ) { |
1320 | | - for ( var i = 0; i < cp.local_domains.length; i++ ) { |
1321 | | - var ld = cp.local_domains[i]; |
1322 | | - if ( local_host.indexOf( ld ) != -1 ) |
1323 | | - return true; |
| 1519 | + var localHost = mw.parseUri( this.local_wiki_api_url ).host; |
| 1520 | + if ( provider.local_domains ) { |
| 1521 | + for ( var i = 0; i < provider.local_domains.length; i++ ) { |
| 1522 | + var domain = provider.local_domains[i]; |
| 1523 | + if ( localHost.indexOf( domain ) != -1 ) |
| 1524 | + return true; |
1324 | 1525 | } |
1325 | 1526 | } |
1326 | 1527 | return false; |
1327 | 1528 | } |
1328 | 1529 | }, |
1329 | | - checkImportResource:function( rObj, cir_callback ) { |
| 1530 | + |
| 1531 | + /** |
| 1532 | + * Check if the file is either a local upload, or if it has already been |
| 1533 | + * imported under the standard filename scheme. |
| 1534 | + * |
| 1535 | + * Calls the callback with two parameters: |
| 1536 | + * callback( resource, status ) |
| 1537 | + * |
| 1538 | + * resource: a resource object pointing to the local file if there is one, |
| 1539 | + * or false if not |
| 1540 | + * |
| 1541 | + * status: may be 'local', 'shared', 'imported' or 'missing' |
| 1542 | + */ |
| 1543 | + isFileLocallyAvailable: function( resource, callback ) { |
1330 | 1544 | var _this = this; |
1331 | | - // Add a loader ontop: |
| 1545 | + // Add a loader on top |
1332 | 1546 | $j.addLoaderDialog( gM( 'mwe-checking-resource' ) ); |
1333 | | - // Extend the callback with close dialog |
1334 | | - var org_cir_callback = cir_callback; |
1335 | | - cir_callback = function( rObj ) { |
1336 | | - var cat = org_cir_callback; |
| 1547 | + |
| 1548 | + // Extend the callback, closing the loader dialog before chaining |
| 1549 | + myCallback = function( newRes, status ) { |
1337 | 1550 | $j.closeLoaderDialog(); |
1338 | | - if ( typeof org_cir_callback == 'function' ) { |
1339 | | - org_cir_callback( rObj ); |
| 1551 | + if ( typeof callback == 'function' ) { |
| 1552 | + callback( newRes, status ); |
1340 | 1553 | } |
1341 | 1554 | } |
| 1555 | + |
1342 | 1556 | // @@todo get the localized File/Image namespace name or do a general {NS}:Title |
1343 | | - var cp = rObj.pSobj.cp; |
| 1557 | + var provider = resource.pSobj.cp; |
1344 | 1558 | var _this = this; |
1345 | 1559 | |
| 1560 | + // Clone the resource |
| 1561 | + var proto = {}; |
| 1562 | + proto.prototype = resource; |
| 1563 | + var myRes = new proto; |
| 1564 | + |
1346 | 1565 | // Update base target_resource_title: |
1347 | | - rObj.target_resource_title = rObj.titleKey.replace( /File:|Image:/ , '' ) |
| 1566 | + myRes.target_resource_title = myRes.titleKey.replace( /^(File:|Image:)/ , '' ) |
1348 | 1567 | |
1349 | 1568 | // check if local repository |
1350 | 1569 | // or if import mode if just "linking" (we should already have the 'url' |
1351 | 1570 | |
1352 | | - if ( this.checkRepoLocal( cp ) || this.import_url_mode == 'remote_link' ) { |
1353 | | - // Local repo jump directly to check Import Resource callback: |
1354 | | - cir_callback( rObj ); |
| 1571 | + if ( this.isProviderLocal( provider ) || this.import_url_mode == 'remote_link' ) { |
| 1572 | + // Local repo, jump directly to the callback: |
| 1573 | + myCallback( myRes, 'local' ); |
1355 | 1574 | } else { |
1356 | | - // Check if the file is local (can be shared repo) |
1357 | | - if ( cp.check_shared ) { |
1358 | | - _this.checkForFile( rObj.target_resource_title, function( imagePage ) { |
| 1575 | + // Check if the file is local (can be shared repo) |
| 1576 | + if ( provider.check_shared ) { |
| 1577 | + _this.findFileInLocalWiki( myRes.target_resource_title, function( imagePage ) { |
1359 | 1578 | if ( imagePage && imagePage['imagerepository'] == 'shared' ) { |
1360 | | - cir_callback( rObj ); |
| 1579 | + myCallback( myRes, 'shared' ); |
1361 | 1580 | } else { |
1362 | | - _this.checkPrefixNameImport( rObj, cir_callback ); |
| 1581 | + _this.isFileAlreadyImported( myRes, myCallback ); |
1363 | 1582 | } |
1364 | 1583 | } ); |
1365 | 1584 | } else { |
1366 | | - _this.checkPrefixNameImport( rObj, cir_callback ); |
| 1585 | + _this.isFileAlreadyImported( myRes, myCallback ); |
1367 | 1586 | } |
1368 | 1587 | } |
1369 | 1588 | }, |
1370 | | - checkPrefixNameImport: function( rObj, cir_callback ) { |
1371 | | - js_log( '::checkPrefixNameImport:: ' ); |
1372 | | - var cp = rObj.pSobj.cp; |
| 1589 | + |
| 1590 | + /** |
| 1591 | + * Check if the file is already imported with this extension's filename scheme |
| 1592 | + * |
| 1593 | + * Calls the callback with two parameters: |
| 1594 | + * callback( resource, status ) |
| 1595 | + * |
| 1596 | + * If the image is found, the status will be 'imported' and the resource |
| 1597 | + * will be the new local resource. |
| 1598 | + * |
| 1599 | + * If the image is not found, the status will be 'missing' and the resource |
| 1600 | + * will be false. |
| 1601 | + */ |
| 1602 | + isFileAlreadyImported: function( resource, callback ) { |
| 1603 | + js_log( '::isFileAlreadyImported:: ' ); |
1373 | 1604 | var _this = this; |
| 1605 | + |
| 1606 | + // Clone the resource |
| 1607 | + var proto = {}; |
| 1608 | + proto.prototype = resource; |
| 1609 | + var myRes = new proto; |
| 1610 | + |
| 1611 | + var provider = myRes.pSobj.cp; |
| 1612 | + |
1374 | 1613 | // update target_resource_title with resource repository prefix: |
1375 | | - rObj.target_resource_title = cp.resource_prefix + rObj.target_resource_title; |
1376 | | - // check if the file exists: |
1377 | | - _this.checkForFile( rObj.target_resource_title, function( imagePage ) { |
| 1614 | + myRes.target_resource_title = provider.resource_prefix + myRes.target_resource_title; |
| 1615 | + // check if the file exists: |
| 1616 | + _this.findFileInLocalWiki( myRes.target_resource_title, function( imagePage ) { |
1378 | 1617 | if ( imagePage ) { |
1379 | 1618 | // update to local src |
1380 | | - rObj.local_src = imagePage['imageinfo'][0].url; |
| 1619 | + myRes.local_src = imagePage['imageinfo'][0].url; |
1381 | 1620 | // @@todo maybe update poster too? |
1382 | | - rObj.local_poster = imagePage['imageinfo'][0].thumburl; |
1383 | | - // update the title: |
1384 | | - rObj.target_resource_title = imagePage.title.replace(/File:|Image:/ , '' ); |
1385 | | - cir_callback( rObj ); |
| 1621 | + myRes.local_poster = imagePage['imageinfo'][0].thumburl; |
| 1622 | + // update the title: |
| 1623 | + myRes.target_resource_title = imagePage.title.replace(/^(File:|Image:)/ , '' ); |
| 1624 | + callback( myRes, 'imported' ); |
1386 | 1625 | } else { |
1387 | | - // close the dialog and display the import interface: |
1388 | | - $j.closeLoaderDialog(); |
1389 | | - _this.doImportInterface( rObj, cir_callback ); |
| 1626 | + callback( false, 'missing' ); |
1390 | 1627 | } |
1391 | 1628 | } ); |
1392 | 1629 | }, |
1393 | | - doImportInterface : function( rObj, callback ) { |
| 1630 | + |
| 1631 | + showImportUI: function( resource, callback ) { |
1394 | 1632 | var _this = this; |
1395 | | - js_log( "doImportInterface:: update:" + _this.cFileNS + ':' + rObj.target_resource_title ); |
| 1633 | + js_log( "showImportUI:: update:" + _this.cFileNS + ':' + |
| 1634 | + resource.target_resource_title ); |
1396 | 1635 | |
1397 | 1636 | // setup the resource description from resource description: |
1398 | | - var wt = '{{Information ' + "\n"; |
| 1637 | + // FIXME: i18n, namespace |
| 1638 | + var desc = '{{Information ' + "\n"; |
1399 | 1639 | |
1400 | | - if ( rObj.desc ) { |
1401 | | - wt += '|Description= ' + rObj.desc + "\n"; |
| 1640 | + if ( resource.desc ) { |
| 1641 | + desc += '|Description= ' + resource.desc + "\n"; |
1402 | 1642 | } else { |
1403 | | - wt += '|Description= ' + gM( 'mwe-missing_desc_see_source', rObj.link ) + "\n"; |
| 1643 | + desc += '|Description= ' + gM( 'mwe-missing_desc_see_source', resource.link ) + "\n"; |
1404 | 1644 | } |
1405 | 1645 | |
1406 | 1646 | // output search specific info |
1407 | | - wt += '|Source=' + rObj.pSobj.getImportResourceDescWiki( rObj ) + "\n"; |
| 1647 | + desc += '|Source=' + resource.pSobj.getImportResourceDescWiki( resource ) + "\n"; |
1408 | 1648 | |
1409 | | - if ( rObj.author ) |
1410 | | - wt += '|Author=' + rObj.author + "\n"; |
| 1649 | + if ( resource.author ) |
| 1650 | + desc += '|Author=' + resource.author + "\n"; |
1411 | 1651 | |
1412 | | - if ( rObj.date ) |
1413 | | - wt += '|Date=' + rObj.date + "\n"; |
| 1652 | + if ( resource.date ) |
| 1653 | + desc += '|Date=' + resource.date + "\n"; |
1414 | 1654 | |
1415 | 1655 | // add the Permision info: |
1416 | | - wt += '|Permission=' + rObj.pSobj.getPermissionWikiTag( rObj ) + "\n"; |
| 1656 | + desc += '|Permission=' + resource.pSobj.getPermissionWikiTag( resource ) + "\n"; |
1417 | 1657 | |
1418 | | - if ( rObj.other_versions ) |
1419 | | - wt += '|other_versions=' + rObj.other_versions + "\n"; |
| 1658 | + if ( resource.other_versions ) |
| 1659 | + desc += '|other_versions=' + resource.other_versions + "\n"; |
1420 | 1660 | |
1421 | | - wt += '}}'; |
| 1661 | + desc += '}}'; |
1422 | 1662 | |
1423 | 1663 | // get any extra categories or helpful links |
1424 | | - wt += rObj.pSobj.getExtraResourceDescWiki( rObj ); |
| 1664 | + desc += resource.pSobj.getExtraResourceDescWiki( resource ); |
1425 | 1665 | |
1426 | 1666 | |
1427 | 1667 | $j( '#rsd_resource_import' ).remove();// remove any old resource imports |
1428 | 1668 | |
1429 | 1669 | // @@ show user dialog to import the resource |
1430 | | - $j( _this.target_container ).append( '<div id="rsd_resource_import" ' + |
1431 | | - 'class="ui-widget-content" style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;z-index:5">' + |
1432 | | - '<h3 style="color:red;padding:5px;">' + gM( 'mwe-resource-needs-import', [rObj.title, _this.upload_api_name] ) + '</h3>' + |
1433 | | - '<div id="rsd_preview_import_container" style="position:absolute;width:50%;bottom:0px;left:5px;overflow:auto;top:30px;">' + |
1434 | | - rObj.pSobj.getEmbedHTML( rObj, { |
1435 | | - 'id': _this.target_container + '_rsd_pv_vid', |
1436 | | - 'max_height':'220', |
1437 | | - 'only_poster':true |
1438 | | - } ) + // get embedHTML with small thumb: |
1439 | | - '<br style="clear both"/>' + |
1440 | | - '<strong>' + gM( 'mwe-resource_page_desc' ) + '</strong>' + |
1441 | | - '<div id="rsd_import_desc" style="display:inline;">' + |
1442 | | - mv_get_loading_img( 'position:absolute;top:5px;left:5px' ) + |
1443 | | - '</div>' + |
1444 | | - '</div>' + |
1445 | | - '<div id="rds_edit_import_container" style="position:absolute;left:50%;' + |
1446 | | - 'bottom:0px;top:30px;right:0px;overflow:auto;">' + |
1447 | | - '<strong>' + gM( 'mwe-local_resource_title' ) + '</strong><br>' + |
1448 | | - '<input type="text" size="30" value="' + rObj.target_resource_title + '" /></br>' + |
1449 | | - '<strong>' + gM( 'mwe-edit_resource_desc' ) + '</strong>' + |
1450 | | - '<textarea id="rsd_import_ta" id="mv_img_desc" style="width:90%;" rows="8" cols="50">' + |
1451 | | - wt + |
1452 | | - '</textarea></br>' + |
1453 | | - '<input type="checkbox" value="true" id="wpWatchthis" name="wpWatchthis" tabindex="7" />' + |
1454 | | - '<label for="wpWatchthis">' + gM( 'mwe-watch_this_page' ) + '</label></br></br></br>' + |
1455 | | - $j.btnHtml( gM( 'mwe-update_preview' ), 'rsd_import_apreview', 'refresh' ) + ' ' + |
1456 | | - '</div>' + |
1457 | | - // output the rendered and non-rendered version of description for easy switching: |
1458 | | - '</div>' ); |
1459 | | - var bPlaneTarget = _this.target_container + '~ .ui-dialog-buttonpane'; |
1460 | | - $j( bPlaneTarget ).html ( |
1461 | | - // add the btns to the bottom: |
1462 | | - $j.btnHtml( gM( 'mwe-do_import_resource' ), 'rsd_import_doimport', 'check' ) + ' ' + |
| 1670 | + $j( _this.target_container ).append( |
| 1671 | + '<div id="rsd_resource_import" ' + |
| 1672 | + 'class="ui-widget-content" ' + |
| 1673 | + 'style="position:absolute;top:0px;left:0px;right:0px;bottom:0px;z-index:5">' + |
| 1674 | + '<h3 style="color:red;padding:5px;">' + |
| 1675 | + gM( 'mwe-resource-needs-import', [resource.title, _this.upload_api_name] ) + |
| 1676 | + '</h3>' + |
| 1677 | + '<div id="rsd_preview_import_container" ' + |
| 1678 | + 'style="position:absolute;width:50%;bottom:0px;left:5px;' + |
| 1679 | + 'overflow:auto;top:30px;">' + |
| 1680 | + resource.pSobj.getEmbedHTML( resource, { |
| 1681 | + 'id': _this.target_container + '_rsd_pv_vid', |
| 1682 | + 'max_height': '220', |
| 1683 | + 'only_poster': true |
| 1684 | + } ) + // get embedHTML with small thumb: |
| 1685 | + '<br style="clear both"/>' + |
| 1686 | + '<strong>' + gM( 'mwe-resource_page_desc' ) + '</strong>' + |
| 1687 | + '<div id="rsd_import_desc" style="display:inline;">' + |
| 1688 | + mv_get_loading_img( 'position:absolute;top:5px;left:5px' ) + |
| 1689 | + '</div>' + |
| 1690 | + '</div>' + |
| 1691 | + '<div id="rds_edit_import_container" ' + |
| 1692 | + 'style="position:absolute; ' + |
| 1693 | + 'left:50%;bottom:0px;top:30px;right:0px;overflow:auto;">' + |
| 1694 | + '<strong>' + gM( 'mwe-local_resource_title' ) + '</strong>' + |
| 1695 | + // FIXME: invalid HTML, <br> must be empty |
| 1696 | + '<br/>' + |
| 1697 | + '<input type="text" size="30" value="' + resource.target_resource_title + '" />' + |
| 1698 | + '<br/>' + |
| 1699 | + '<strong>' + gM( 'mwe-edit_resource_desc' ) + '</strong>' + |
| 1700 | + // FIXME: invalid HTML, two id attributes |
| 1701 | + '<textarea id="rsd_import_ta" id="mv_img_desc" ' + |
| 1702 | + 'style="width:90%;" rows="8" cols="50">' + |
| 1703 | + desc + |
| 1704 | + '</textarea>' + |
| 1705 | + '<br/>' + |
| 1706 | + '<input type="checkbox" value="true" id="wpWatchthis" ' + |
| 1707 | + 'name="wpWatchthis" tabindex="7" />' + |
| 1708 | + '<label for="wpWatchthis">' + gM( 'mwe-watch_this_page' ) + '</label> ' + |
| 1709 | + '<br/><br/><br/>' + |
| 1710 | + $j.btnHtml( gM( 'mwe-update_preview' ), 'rsd_import_apreview', 'refresh' ) + |
| 1711 | + ' ' + |
| 1712 | + '</div>' + |
| 1713 | + // output the rendered and non-rendered version of description for easy switching: |
| 1714 | + '</div>' ); |
| 1715 | + var buttonPaneSelector = _this.target_container + '~ .ui-dialog-buttonpane'; |
| 1716 | + $j( buttonPaneSelector ).html ( |
| 1717 | + // add the btns to the bottom: |
| 1718 | + $j.btnHtml( gM( 'mwe-do_import_resource' ), 'rsd_import_doimport', 'check' ) + |
| 1719 | + ' ' + |
1463 | 1720 | $j.btnHtml( gM( 'mwe-cancel_import' ), 'rsd_import_acancel', 'close' ) + ' ' |
1464 | 1721 | ); |
1465 | | - |
| 1722 | + |
1466 | 1723 | // add hover: |
1467 | 1724 | |
1468 | | - // update video tag (if a video) |
1469 | | - if ( rObj.mime.indexOf( 'video/' ) !== -1 ) |
| 1725 | + // update video tag (if a video) |
| 1726 | + if ( resource.mime.indexOf( 'video/' ) !== -1 ) |
1470 | 1727 | rewrite_by_id( $j( _this.target_container ).attr( 'id' ) + '_rsd_pv_vid' ); |
1471 | | - |
| 1728 | + |
1472 | 1729 | // load the preview text: |
1473 | | - _this.getParsedWikiText( wt, _this.cFileNS + ':' + rObj.target_resource_title, function( o ) { |
1474 | | - $j( '#rsd_import_desc' ).html( o ); |
1475 | | - } ); |
| 1730 | + _this.parse( |
| 1731 | + desc, _this.cFileNS + ':' + resource.target_resource_title, |
| 1732 | + function( descHtml ) { |
| 1733 | + $j( '#rsd_import_desc' ).html( descHtml ); |
| 1734 | + } |
| 1735 | + ); |
1476 | 1736 | // add bindings: |
1477 | | - $j( _this.target_container + ' .rsd_import_apreview' ).btnBind().click( function() { |
1478 | | - js_log( " Do preview asset update" ); |
1479 | | - $j( '#rsd_import_desc' ).html( mv_get_loading_img() ); |
1480 | | - // load the preview text: |
1481 | | - _this.getParsedWikiText( $j( '#rsd_import_ta' ).val(), _this.cFileNS + ':' + rObj.target_resource_title, function( o ) { |
1482 | | - js_log( 'got updated preview: ' ); |
1483 | | - $j( '#rsd_import_desc' ).html( o ); |
| 1737 | + $j( _this.target_container + ' .rsd_import_apreview' ) |
| 1738 | + .btnBind() |
| 1739 | + .click( function() { |
| 1740 | + js_log( " Do preview asset update" ); |
| 1741 | + $j( '#rsd_import_desc' ).html( mv_get_loading_img() ); |
| 1742 | + // load the preview text: |
| 1743 | + _this.parse( |
| 1744 | + $j( '#rsd_import_ta' ).val(), |
| 1745 | + _this.cFileNS + ':' + resource.target_resource_title, |
| 1746 | + function( o ) { |
| 1747 | + js_log( 'got updated preview: ' ); |
| 1748 | + $j( '#rsd_import_desc' ).html( o ); |
| 1749 | + } |
| 1750 | + ); |
1484 | 1751 | } ); |
1485 | | - } ); |
1486 | | - $j( bPlaneTarget + ' .rsd_import_doimport' ).btnBind().click( function() { |
1487 | | - js_log( "do import asset:" + _this.import_url_mode ); |
1488 | | - // check import mode: |
1489 | | - if ( _this.import_url_mode == 'api' ) { |
1490 | | - if ( _this.upload_api_target == 'proxy' ) { ; |
1491 | | - _this.setupProxy( function() { |
1492 | | - _this.doImportAPI( rObj , callback ); |
1493 | | - } ); |
| 1752 | + |
| 1753 | + $j( buttonPaneSelector + ' .rsd_import_doimport' ) |
| 1754 | + .btnBind() |
| 1755 | + .click( function() { |
| 1756 | + js_log( "do import asset:" + _this.import_url_mode ); |
| 1757 | + // check import mode: |
| 1758 | + if ( _this.import_url_mode == 'api' ) { |
| 1759 | + if ( _this.upload_api_target == 'proxy' ) { |
| 1760 | + _this.setupProxy( function() { |
| 1761 | + _this.doApiImport( resource, callback ); |
| 1762 | + } ); |
| 1763 | + } else { |
| 1764 | + _this.doApiImport( resource, callback ); |
| 1765 | + } |
1494 | 1766 | } else { |
1495 | | - _this.doImportAPI( rObj , callback ); |
| 1767 | + js_log( "Error: import mode is not form or API (can not copy asset)" ); |
1496 | 1768 | } |
1497 | | - } else { |
1498 | | - js_log( "Error: import mode is not form or API (can not copy asset)" ); |
1499 | | - } |
1500 | | - } ); |
1501 | | - $j( bPlaneTarget + ' .rsd_import_acancel' ).btnBind().click( function() { |
1502 | | - $j( '#rsd_resource_import' ).fadeOut( "fast", function() { |
1503 | | - $j( this ).remove(); |
1504 | | - // restore buttons (from the clipEdit object::) |
1505 | | - _this.cEdit.updateInsertControlActions(); |
1506 | | - $j( bPlaneTarget ).removeClass( 'ui-state-error' ); |
1507 | 1769 | } ); |
1508 | | - } ); |
| 1770 | + $j( buttonPaneSelector + ' .rsd_import_acancel' ) |
| 1771 | + .btnBind() |
| 1772 | + .click( function() { |
| 1773 | + $j( '#rsd_resource_import' ).fadeOut( "fast", function() { |
| 1774 | + $j( this ).remove(); |
| 1775 | + // restore buttons (from the clipEdit object::) |
| 1776 | + _this.clipEdit.updateInsertControlActions(); |
| 1777 | + $j( buttonPaneSelector ).removeClass( 'ui-state-error' ); |
| 1778 | + } ); |
| 1779 | + } ); |
1509 | 1780 | }, |
1510 | | - /** |
| 1781 | + |
| 1782 | + /** |
1511 | 1783 | * Sets up the proxy for the remote inserts |
1512 | 1784 | */ |
1513 | | - setupProxy:function( callback ) { |
| 1785 | + setupProxy: function( callback ) { |
1514 | 1786 | var _this = this; |
1515 | | - |
| 1787 | + |
1516 | 1788 | if ( _this.proxySetupDone ) { |
1517 | 1789 | if ( callback ) |
1518 | 1790 | callback(); |
1519 | | - return ; |
| 1791 | + return; |
1520 | 1792 | } |
1521 | 1793 | // setup the the proxy via $j.apiProxy loader: |
1522 | | - if ( ! _this.upload_api_proxy_frame ) { |
| 1794 | + if ( !_this.upload_api_proxy_frame ) { |
1523 | 1795 | js_log( "Error:: remote api but no proxy frame target" ); |
1524 | 1796 | return false; |
1525 | 1797 | } else { |
1526 | 1798 | $j.apiProxy( |
1527 | 1799 | 'client', |
1528 | 1800 | { |
1529 | | - 'server_frame' : _this.upload_api_proxy_frame |
| 1801 | + 'server_frame': _this.upload_api_proxy_frame |
1530 | 1802 | }, function() { |
1531 | 1803 | _this.proxySetupDone = true |
1532 | 1804 | if ( callback ) |
— | — | @@ -1534,31 +1806,35 @@ |
1535 | 1807 | ); |
1536 | 1808 | } |
1537 | 1809 | }, |
1538 | | - checkForFile:function( fName, callback ) { |
1539 | | - js_log( "checkForFile::" + fName ); |
| 1810 | + |
| 1811 | + findFileInLocalWiki: function( fName, callback ) { |
| 1812 | + js_log( "findFileInLocalWiki::" + fName ); |
1540 | 1813 | var _this = this; |
1541 | 1814 | reqObj = { |
1542 | | - 'action':'query', |
1543 | | - 'titles': _this.cFileNS + ':' + fName, |
1544 | | - 'prop' : 'imageinfo', |
1545 | | - 'iiprop' : 'url', |
1546 | | - 'iiurlwidth': '400' |
| 1815 | + 'action': 'query', |
| 1816 | + 'titles': _this.cFileNS + ':' + fName, |
| 1817 | + 'prop': 'imageinfo', |
| 1818 | + 'iiprop': 'url', |
| 1819 | + 'iiurlwidth': '400' |
1547 | 1820 | }; |
1548 | 1821 | // first check the api for imagerepository |
1549 | | - do_api_req( { |
1550 | | - 'data':reqObj, |
1551 | | - 'url':this.local_wiki_api_url |
| 1822 | + do_api_req( |
| 1823 | + { |
| 1824 | + 'data': reqObj, |
| 1825 | + 'url': this.local_wiki_api_url |
1552 | 1826 | }, function( data ) { |
1553 | 1827 | if ( data.query.pages ) { |
1554 | 1828 | for ( var i in data.query.pages ) { |
1555 | 1829 | for ( var j in data.query.pages[i] ) { |
1556 | | - if ( j == 'missing' && data.query.pages[i].imagerepository != 'shared' ) { |
| 1830 | + if ( j == 'missing' |
| 1831 | + && data.query.pages[i].imagerepository != 'shared' ) |
| 1832 | + { |
1557 | 1833 | js_log( fName + " not found" ); |
1558 | 1834 | callback( false ); |
1559 | | - return ; |
| 1835 | + return; |
1560 | 1836 | } |
1561 | 1837 | } |
1562 | | - // else page is found: |
| 1838 | + // else page is found: |
1563 | 1839 | js_log( fName + " found" ); |
1564 | 1840 | callback( data.query.pages[i] ); |
1565 | 1841 | } |
— | — | @@ -1566,54 +1842,57 @@ |
1567 | 1843 | } |
1568 | 1844 | ); |
1569 | 1845 | }, |
1570 | | - doImportAPI:function( rObj, cir_callback ) { |
| 1846 | + |
| 1847 | + doApiImport: function( resource, callback ) { |
1571 | 1848 | var _this = this; |
1572 | | - js_log( ":doImportAPI:" ); |
| 1849 | + js_log( ":doApiImport:" ); |
1573 | 1850 | $j.addLoaderDialog( gM( 'mwe-importing_asset' ) ); |
1574 | 1851 | // baseUploadInterface |
1575 | | - mvJsLoader.doLoad( [ |
1576 | | - 'mvBaseUploadInterface', |
1577 | | - '$j.ui.progressbar' |
1578 | | - ], function() { |
1579 | | - js_log( 'mvBaseUploadInterface ready' ); |
1580 | | - // initiate a upload object ( similar to url copy ): |
1581 | | - myUp = new mvBaseUploadInterface( { |
1582 | | - 'api_url' : _this.upload_api_target, |
1583 | | - 'done_upload_cb':function() { |
1584 | | - js_log( 'doImportAPI:: run callback::' ); |
1585 | | - // we have finished the upload: |
| 1852 | + mvJsLoader.doLoad( |
| 1853 | + [ |
| 1854 | + 'mvBaseUploadInterface', |
| 1855 | + '$j.ui.progressbar' |
| 1856 | + ], |
| 1857 | + function() { |
| 1858 | + js_log( 'mvBaseUploadInterface ready' ); |
| 1859 | + // initiate a upload object ( similar to url copy ): |
| 1860 | + var uploader = new mvBaseUploadInterface( { |
| 1861 | + 'api_url' : _this.upload_api_target, |
| 1862 | + 'done_upload_cb':function() { |
| 1863 | + js_log( 'doApiImport:: run callback::' ); |
| 1864 | + // we have finished the upload: |
1586 | 1865 | |
1587 | | - // close up the rsd_resource_import |
1588 | | - $j( '#rsd_resource_import' ).remove(); |
1589 | | - // return the parent callback: |
1590 | | - return cir_callback(); |
1591 | | - } |
1592 | | - } ); |
1593 | | - // get the edit token if we have it handy |
1594 | | - _this.getEditToken( function( token ) { |
1595 | | - myUp.etoken = token; |
1596 | | - |
1597 | | - // close the loader now that we are ready to present the progress dialog:: |
1598 | | - $j.closeLoaderDialog(); |
1599 | | - |
1600 | | - myUp.doHttpUpload( { |
1601 | | - 'url' : rObj.src, |
1602 | | - 'filename' : rObj.target_resource_title, |
1603 | | - 'comment' : $j( '#rsd_import_ta' ).val() |
| 1866 | + // close up the rsd_resource_import |
| 1867 | + $j( '#rsd_resource_import' ).remove(); |
| 1868 | + // return the parent callback: |
| 1869 | + return callback(); |
| 1870 | + } |
1604 | 1871 | } ); |
1605 | | - } ) |
| 1872 | + // get the edit token if we have it handy |
| 1873 | + _this.getEditToken( function( token ) { |
| 1874 | + uploader.editToken = token; |
1606 | 1875 | |
| 1876 | + // close the loader now that we are ready to present the progress dialog:: |
| 1877 | + $j.closeLoaderDialog(); |
1607 | 1878 | |
1608 | | - } ); |
| 1879 | + uploader.doHttpUpload( { |
| 1880 | + 'url': resource.src, |
| 1881 | + 'filename': resource.target_resource_title, |
| 1882 | + 'comment': $j( '#rsd_import_ta' ).val() |
| 1883 | + } ); |
| 1884 | + } ) |
| 1885 | + } |
| 1886 | + ); |
1609 | 1887 | }, |
1610 | | - getEditToken:function( callback ) { |
| 1888 | + |
| 1889 | + getEditToken: function( callback ) { |
1611 | 1890 | var _this = this; |
1612 | 1891 | if ( _this.upload_api_target != 'proxy' ) { |
1613 | 1892 | // (if not a proxy) first try to get the token from the page: |
1614 | | - var etoken = $j( "input[name='wpEditToken']" ).val(); |
1615 | | - if ( etoken ) { |
1616 | | - callback( etoken ); |
1617 | | - return ; |
| 1893 | + var editToken = $j( "input[name='wpEditToken']" ).val(); |
| 1894 | + if ( editToken ) { |
| 1895 | + callback( editToken ); |
| 1896 | + return; |
1618 | 1897 | } |
1619 | 1898 | } |
1620 | 1899 | // @@todo try to load over ajax if( _this.local_wiki_api_url ) is set |
— | — | @@ -1622,41 +1901,54 @@ |
1623 | 1902 | callback( token ); |
1624 | 1903 | } ); |
1625 | 1904 | }, |
1626 | | - previewResource:function( rObj ) { |
| 1905 | + |
| 1906 | + showPreview: function( resource ) { |
1627 | 1907 | var _this = this; |
1628 | | - this.checkImportResource( rObj, function() { |
| 1908 | + this.isFileLocallyAvailable( resource, function( newRes, status ) { |
| 1909 | + if ( status === 'missing' ) { |
| 1910 | + _this.showImportUI( resource, callback ); |
| 1911 | + return; |
| 1912 | + } |
| 1913 | + |
1629 | 1914 | // put another window ontop: |
1630 | | - $j( _this.target_container ).append( '<div id="rsd_preview_display"' + |
1631 | | - 'style="position:absolute;overflow:hidden;z-index:4;top:0px;bottom:0px;right:0px;left:0px;background-color:#FFF;">' + |
1632 | | - mv_get_loading_img( 'top:30px;left:30px' ) + |
1633 | | - '</div>' ); |
| 1915 | + $j( _this.target_container ).append( |
| 1916 | + '<div id="rsd_preview_display"' + |
| 1917 | + 'style="position:absolute;overflow:hidden;z-index:4;' + |
| 1918 | + 'top:0px;bottom:0px;right:0px;left:0px;background-color:#FFF;">' + |
| 1919 | + mv_get_loading_img( 'top:30px;left:30px' ) + |
| 1920 | + '</div>' ); |
1634 | 1921 | |
1635 | | - var bPlaneTarget = _this.target_container + '~ .ui-dialog-buttonpane'; |
1636 | | - var pTitle = $j( _this.target_container ).dialog( 'option', 'title' ); |
| 1922 | + var buttonPaneSelector = _this.target_container + '~ .ui-dialog-buttonpane'; |
| 1923 | + var origTitle = $j( _this.target_container ).dialog( 'option', 'title' ); |
1637 | 1924 | |
1638 | 1925 | // update title: |
1639 | | - $j( _this.target_container ).dialog( 'option', 'title', gM( 'mwe-preview_insert_resource', rObj.title ) ); |
| 1926 | + $j( _this.target_container ).dialog( 'option', 'title', |
| 1927 | + gM( 'mwe-preview_insert_resource', newRes.title ) ); |
1640 | 1928 | |
1641 | 1929 | // update buttons preview: |
1642 | | - $j( bPlaneTarget ).html( $j.btnHtml( gM( 'rsd_do_insert' ), 'preview_do_insert', 'check' ) + ' ' ) |
| 1930 | + $j( buttonPaneSelector ) |
| 1931 | + .html( |
| 1932 | + $j.btnHtml( gM( 'rsd_do_insert' ), 'preview_do_insert', 'check' ) + ' ' ) |
1643 | 1933 | .children( '.preview_do_insert' ) |
1644 | 1934 | .click( function() { |
1645 | | - _this.insertResource( rObj ); |
| 1935 | + _this.insertResource( newRes ); |
1646 | 1936 | } ); |
1647 | 1937 | // update cancel button |
1648 | | - $j( bPlaneTarget ).append( '<a href="#" class="preview_close">Do More Modification</a>' ) |
| 1938 | + $j( buttonPaneSelector ) |
| 1939 | + .append( '<a href="#" class="preview_close">Do More Modification</a>' ) |
1649 | 1940 | .children( '.preview_close' ) |
1650 | 1941 | .click( function() { |
1651 | 1942 | $j( '#rsd_preview_display' ).remove(); |
1652 | 1943 | // restore title: |
1653 | | - $j( _this.target_container ).dialog( 'option', 'title', pTitle ); |
| 1944 | + $j( _this.target_container ).dialog( 'option', 'title', origTitle ); |
1654 | 1945 | // restore buttons (from the clipEdit object::) |
1655 | | - _this.cEdit.updateInsertControlActions(); |
| 1946 | + _this.clipEdit.updateInsertControlActions(); |
1656 | 1947 | } ); |
1657 | 1948 | |
1658 | | - // update the preview_wtext |
1659 | | - _this.updatePreviewText( rObj ); |
1660 | | - _this.getParsedWikiText( _this.preview_wtext, _this.target_title, |
| 1949 | + // Get the preview wikitext |
| 1950 | + _this.parse( |
| 1951 | + _this.getPreviewText( newRes ), |
| 1952 | + _this.target_title, |
1661 | 1953 | function( phtml ) { |
1662 | 1954 | $j( '#rsd_preview_display' ).html( phtml ); |
1663 | 1955 | // update the display of video tag items (if any) |
— | — | @@ -1665,58 +1957,79 @@ |
1666 | 1958 | ); |
1667 | 1959 | } ); |
1668 | 1960 | }, |
1669 | | - updatePreviewText:function( rObj ) { |
1670 | | - var _this = this; |
1671 | 1961 | |
1672 | | - if ( _this.import_url_mode == 'remote_link' ) { |
1673 | | - _this.cur_embed_code = rObj.pSobj.getEmbedHTML( rObj ); |
| 1962 | + getEmbedCode: function( resource ) { |
| 1963 | + if ( this.import_url_mode == 'remote_link' ) { |
| 1964 | + return resource.pSobj.getEmbedHTML( resource ); |
1674 | 1965 | } else { |
1675 | | - _this.cur_embed_code = rObj.pSobj.getEmbedWikiCode( rObj ); |
| 1966 | + return resource.pSobj.getEmbedWikiCode( resource ); |
1676 | 1967 | } |
| 1968 | + }, |
1677 | 1969 | |
| 1970 | + getPreviewText: function( resource ) { |
| 1971 | + var _this = this; |
| 1972 | + var text; |
| 1973 | + |
1678 | 1974 | // insert at start if textInput cursor has not been set (ie == length) |
1679 | | - if ( _this.caret_pos && _this.caret_pos.text ) { |
1680 | | - if ( _this.caret_pos.text.length == _this.caret_pos.s ) |
1681 | | - _this.caret_pos.s = 0; |
1682 | | - _this.preview_wtext = _this.caret_pos.text.substring( 0, _this.caret_pos.s ) + |
1683 | | - _this.cur_embed_code + |
1684 | | - _this.caret_pos.text.substring( _this.caret_pos.s ); |
| 1975 | + var insertPos = _this.getCaretPos(); |
| 1976 | + var originalText = _this.getTextboxValue(); |
| 1977 | + var embedCode = _this.getEmbedCode( resource ); |
| 1978 | + if ( insertPos !== false && originalText ) { |
| 1979 | + if ( originalText.length == insertPos ) { |
| 1980 | + insertPos = 0; |
| 1981 | + } |
| 1982 | + text = originalText.substring( 0, insertPos ) + |
| 1983 | + embedCode + originalText.substring( insertPos ); |
1685 | 1984 | } else { |
1686 | | - _this.preview_wtext = $j( _this.target_textbox ).val() + _this.cur_embed_code; |
| 1985 | + text = $j( _this.target_textbox ).val() + embedCode; |
1687 | 1986 | } |
1688 | | - // check for missing </refrences> |
1689 | | - if ( _this.preview_wtext.indexOf( '<references/>' ) == -1 && _this.preview_wtext.indexOf( '<ref>' ) != -1 ) |
1690 | | - _this.preview_wtext = _this.preview_wtext + '<references/>'; |
| 1987 | + // check for missing </references> |
| 1988 | + if ( text.indexOf( '<references/>' ) == -1 && text.indexOf( '<ref>' ) != -1 ) { |
| 1989 | + text = text + '<references/>'; |
| 1990 | + } |
| 1991 | + return text; |
1691 | 1992 | }, |
1692 | | - getParsedWikiText:function( wikitext, title, callback ) { |
1693 | | - do_api_req( { |
1694 | | - 'data': { 'action':'parse', |
1695 | | - 'text':wikitext |
1696 | | - }, |
1697 | | - 'url':this.local_wiki_api_url |
| 1993 | + |
| 1994 | + parse: function( wikitext, title, callback ) { |
| 1995 | + do_api_req( |
| 1996 | + { |
| 1997 | + 'data': { |
| 1998 | + 'action': 'parse', |
| 1999 | + 'text': wikitext |
| 2000 | + }, |
| 2001 | + 'url': this.local_wiki_api_url |
1698 | 2002 | }, function( data ) { |
1699 | 2003 | callback( data.parse.text['*'] ); |
1700 | 2004 | } |
1701 | 2005 | ); |
1702 | 2006 | }, |
1703 | | - insertResource:function( rObj ) { |
1704 | | - js_log( 'insertResource: ' + rObj.title ); |
1705 | | - |
1706 | | - var _this = this |
1707 | | - // dobule check that the resource is present: |
1708 | | - this.checkImportResource( rObj, function() { |
1709 | | - _this.updatePreviewText( rObj ); |
1710 | | - $j( _this.target_textbox ).val( _this.preview_wtext ); |
1711 | 2007 | |
| 2008 | + insertResource: function( resource ) { |
| 2009 | + js_log( 'insertResource: ' + resource.title ); |
| 2010 | + |
| 2011 | + var _this = this; |
| 2012 | + // double check that the resource is present: |
| 2013 | + this.isFileLocallyAvailable( resource, function( newRes, status ) { |
| 2014 | + if ( status === 'missing' ) { |
| 2015 | + _this.showImportUI( resource, callback ); |
| 2016 | + return; |
| 2017 | + } |
| 2018 | + |
| 2019 | + $j( _this.target_textbox ).val( _this.getPreviewText( newRes ) ); |
| 2020 | + _this.clearTextboxCache(); |
| 2021 | + |
1712 | 2022 | // update the render area (if present) |
1713 | | - if ( _this.target_render_area && _this.cur_embed_code ) { |
| 2023 | + var embedCode = _this.getEmbedCode( newRes ); |
| 2024 | + if ( _this.target_render_area && embedCode ) { |
1714 | 2025 | // output with some padding: |
1715 | | - $j( _this.target_render_area ).append( _this.cur_embed_code + '<div style="clear:both;height:10px">' ) |
1716 | | - |
| 2026 | + $j( _this.target_render_area ) |
| 2027 | + .append( embedCode + '<div style="clear:both;height:10px">' ) |
| 2028 | + |
1717 | 2029 | // update the player if video or audio: |
1718 | | - if ( rObj.mime.indexOf( 'audio' ) != -1 || |
1719 | | - rObj.mime.indexOf( 'video' ) != -1 || |
1720 | | - rObj.mime.indexOf( '/ogg' ) != -1 ) { |
| 2030 | + if ( newRes.mime.indexOf( 'audio' ) != -1 || |
| 2031 | + newRes.mime.indexOf( 'video' ) != -1 || |
| 2032 | + newRes.mime.indexOf( '/ogg' ) != -1 ) |
| 2033 | + { |
1721 | 2034 | mvJsLoader.embedVideoCheck( function() { |
1722 | 2035 | mv_video_embed(); |
1723 | 2036 | } ); |
— | — | @@ -1725,131 +2038,159 @@ |
1726 | 2039 | _this.closeAll(); |
1727 | 2040 | } ); |
1728 | 2041 | }, |
1729 | | - closeAll:function() { |
1730 | | - var _this = this; |
1731 | | - js_log( "close all:: " + _this.target_container ); |
1732 | | - _this.cancelClipEditCB(); |
1733 | | - // Give a chance for the events to complete |
1734 | | - // (somehow at least in firefox a rare condition occurs where |
1735 | | - // the modal of the edit-box stick around even after the |
1736 | | - // close request has been issued. ) |
1737 | | - setTimeout(function(){ |
1738 | | - $j( _this.target_container ).dialog( 'close' ); |
1739 | | - },10); |
| 2042 | + |
| 2043 | + closeAll: function() { |
| 2044 | + var _this = this; |
| 2045 | + js_log( "close all:: " + _this.target_container ); |
| 2046 | + _this.onCancelClipEdit(); |
| 2047 | + // Give a chance for the events to complete |
| 2048 | + // (somehow at least in firefox a rare condition occurs where |
| 2049 | + // the modal of the edit-box stick around even after the |
| 2050 | + // close request has been issued. ) |
| 2051 | + setTimeout( |
| 2052 | + function() { |
| 2053 | + $j( _this.target_container ).dialog( 'close' ); |
| 2054 | + }, 10 |
| 2055 | + ); |
1740 | 2056 | }, |
1741 | | - setResultBarControl:function( ) { |
| 2057 | + |
| 2058 | + showResultsHeader: function() { |
1742 | 2059 | var _this = this; |
1743 | | - var box_dark_url = mv_skin_img_path + 'box_layout_icon_dark.png'; |
1744 | | - var box_light_url = mv_skin_img_path + 'box_layout_icon.png'; |
1745 | | - var list_dark_url = mv_skin_img_path + 'list_layout_icon_dark.png'; |
1746 | | - var list_light_url = mv_skin_img_path + 'list_layout_icon.png'; |
| 2060 | + var darkBoxUrl = mv_skin_img_path + 'box_layout_icon_dark.png'; |
| 2061 | + var lightBoxUrl = mv_skin_img_path + 'box_layout_icon.png'; |
| 2062 | + var darkListUrl = mv_skin_img_path + 'list_layout_icon_dark.png'; |
| 2063 | + var lightListUrl = mv_skin_img_path + 'list_layout_icon.png'; |
1747 | 2064 | |
1748 | | - var about_desc = ''; |
1749 | | - if ( this.content_providers[ this.disp_item ] ) { |
1750 | | - var cp = this.content_providers[this.disp_item]; |
1751 | | - about_desc = '<span style="position:relative;top:0px;font-style:italic;">' + |
1752 | | - '<i>' + gM( 'mwe-results_from', [ cp.homepage, gM( 'rsd-' + this.disp_item + '-title' ) ] ) + '</i></span>'; |
1753 | | - $j( '#tab-' + this.disp_item ).append( '<div id="rds_results_bar">' + |
1754 | | - '<span style="float:left;top:0px;font-style:italic;">' + |
1755 | | - gM( 'rsd_layout' ) + ' ' + |
1756 | | - '<img id="msc_box_layout" ' + |
1757 | | - 'title = "' + gM( 'rsd_box_layout' ) + '" ' + |
1758 | | - 'src = "' + ( ( _this.result_display_mode == 'box' ) ? box_dark_url:box_light_url ) + '" ' + |
1759 | | - 'style="width:20px;height:20px;cursor:pointer;"> ' + |
1760 | | - '<img id="msc_list_layout" ' + |
1761 | | - 'title = "' + gM( 'rsd_list_layout' ) + '" ' + |
1762 | | - 'src = "' + ( ( _this.result_display_mode == 'list' ) ? list_dark_url:list_light_url ) + '" ' + |
1763 | | - 'style="width:20px;height:20px;cursor:pointer;">' + |
1764 | | - about_desc + |
1765 | | - '</span>' + |
1766 | | - '<span id="rsd_paging_ctrl" style="float:right;"></span>' + |
1767 | | - '</div>' |
1768 | | - ); |
1769 | | - // Get paging with bindings: |
1770 | | - this.getPaging( '#rsd_paging_ctrl' ); |
| 2065 | + if ( !this.content_providers[ this.currentProvider ] ) { |
| 2066 | + return; |
| 2067 | + } |
| 2068 | + var cp = this.content_providers[this.currentProvider]; |
| 2069 | + var resultsFromMsg = gM( 'mwe-results_from', |
| 2070 | + [ cp.homepage, gM( 'rsd-' + this.currentProvider + '-title' ) ] ); |
| 2071 | + var defaultBoxUrl, defaultListUrl; |
| 2072 | + if ( _this.displayMode == 'box' ) { |
| 2073 | + defaultBoxUrl = darkBoxUrl; |
| 2074 | + defaultListUrl = lightListUrl; |
| 2075 | + } else { |
| 2076 | + defaultBoxUrl = lightBoxUrl; |
| 2077 | + defaultListUrl = darkListUrl; |
| 2078 | + } |
1771 | 2079 | |
1772 | | - $j( '#msc_box_layout' ).hover( function() { |
1773 | | - $j( this ).attr( "src", box_dark_url ); |
1774 | | - }, function() { |
1775 | | - $j( this ).attr( "src", ( ( _this.result_display_mode == 'box' ) ? box_dark_url:box_light_url ) ); |
1776 | | - } ).click( function() { |
1777 | | - $j( this ).attr( "src", box_dark_url ); |
1778 | | - $j( '#msc_list_layout' ).attr( "src", list_light_url ); |
1779 | | - _this.setDispMode( 'box' ); |
| 2080 | + var about_desc = '<span style="position:relative;top:0px;font-style:italic;">' + |
| 2081 | + '<i>' + resultsFromMsg + '</i></span>'; |
| 2082 | + |
| 2083 | + $j( '#tab-' + this.currentProvider ).append( '<div id="rds_results_bar">' + |
| 2084 | + '<span style="float:left;top:0px;font-style:italic;">' + |
| 2085 | + gM( 'rsd_layout' ) + ' ' + |
| 2086 | + '<img id="msc_box_layout" ' + |
| 2087 | + 'title = "' + gM( 'rsd_box_layout' ) + '" ' + |
| 2088 | + 'src = "' + defaultBoxUrl + '" ' + |
| 2089 | + 'style="width:20px;height:20px;cursor:pointer;"> ' + |
| 2090 | + '<img id="msc_list_layout" ' + |
| 2091 | + 'title = "' + gM( 'rsd_list_layout' ) + '" ' + |
| 2092 | + 'src = "' + defaultListUrl + '" ' + |
| 2093 | + 'style="width:20px;height:20px;cursor:pointer;">' + |
| 2094 | + about_desc + |
| 2095 | + '</span>' + |
| 2096 | + '<span id="rsd_paging_ctrl" style="float:right;"></span>' + |
| 2097 | + '</div>' |
| 2098 | + ); |
| 2099 | + |
| 2100 | + // Get paging with bindings: |
| 2101 | + this.showPagingHeader( '#rsd_paging_ctrl' ); |
| 2102 | + |
| 2103 | + $j( '#msc_box_layout' ) |
| 2104 | + .hover( |
| 2105 | + function() { |
| 2106 | + $j( this ).attr( "src", darkBoxUrl ); |
| 2107 | + }, |
| 2108 | + function() { |
| 2109 | + $j( this ).attr( "src", defaultBoxUrl ); |
| 2110 | + } ) |
| 2111 | + .click( function() { |
| 2112 | + $j( this ).attr( "src", darkBoxUrl ); |
| 2113 | + $j( '#msc_list_layout' ).attr( "src", lightListUrl ); |
| 2114 | + _this.setDisplayMode( 'box' ); |
1780 | 2115 | } ); |
1781 | 2116 | |
1782 | | - $j( '#msc_list_layout' ).hover( function() { |
1783 | | - $j( this ).attr( "src", list_dark_url ); |
1784 | | - }, function() { |
1785 | | - $j( this ).attr( "src", ( ( _this.result_display_mode == 'list' ) ? list_dark_url:list_light_url ) ); |
1786 | | - } ).click( function() { |
1787 | | - $j( this ).attr( "src", list_dark_url ); |
1788 | | - $j( '#msc_box_layout' ).attr( "src", box_light_url ); |
1789 | | - _this.setDispMode( 'list' ); |
| 2117 | + $j( '#msc_list_layout' ) |
| 2118 | + .hover( |
| 2119 | + function() { |
| 2120 | + $j( this ).attr( "src", darkListUrl ); |
| 2121 | + }, |
| 2122 | + function() { |
| 2123 | + $j( this ).attr( "src", defaultListUrl ); |
| 2124 | + } ) |
| 2125 | + .click( function() { |
| 2126 | + $j( this ).attr( "src", darkListUrl ); |
| 2127 | + $j( '#msc_box_layout' ).attr( "src", lightBoxUrl ); |
| 2128 | + _this.setDisplayMode( 'list' ); |
1790 | 2129 | } ); |
1791 | | - } |
1792 | 2130 | }, |
1793 | | - getPaging:function( target ) { |
| 2131 | + |
| 2132 | + showPagingHeader: function( target ) { |
1794 | 2133 | var _this = this; |
1795 | | - var cp_id = this.disp_item; |
1796 | | - if ( this.disp_item == 'upload' ) { |
1797 | | - var cp = _this.content_providers['this_wiki']; |
| 2134 | + if ( _this.currentProvider == 'upload' ) { |
| 2135 | + var provider = _this.content_providers['this_wiki']; |
1798 | 2136 | } else { |
1799 | | - var cp = this.content_providers[ this.disp_item ]; |
| 2137 | + var provider = _this.content_providers[ _this.currentProvider ]; |
1800 | 2138 | } |
1801 | | - js_log( 'getPaging:' + cp_id + ' len: ' + cp.sObj.num_results ); |
1802 | | - var to_num = ( cp.limit > cp.sObj.num_results ) ? |
1803 | | - ( parseInt( cp.offset ) + parseInt( cp.sObj.num_results ) ): |
1804 | | - ( parseInt( cp.offset ) + parseInt( cp.limit ) ); |
| 2139 | + var search = provider.sObj; |
| 2140 | + js_log( 'showPagingHeader:' + _this.currentProvider + ' len: ' + search.num_results ); |
| 2141 | + var to_num = ( provider.limit > search.num_results ) ? |
| 2142 | + ( parseInt( provider.offset ) + parseInt( search.num_results ) ) : |
| 2143 | + ( parseInt( provider.offset ) + parseInt( provider.limit ) ); |
1805 | 2144 | var out = ''; |
1806 | | - |
| 2145 | + |
1807 | 2146 | // @@todo we should instead support the wiki number format template system instead of inline calls |
1808 | | - if ( cp.sObj.num_results != 0 ) { |
1809 | | - if ( cp.sObj.num_results > cp.limit ) { |
1810 | | - out += gM( 'rsd_results_desc_total', [( cp.offset + 1 ), to_num, mw.lang.formatNumber( cp.sObj.num_results )] ); |
| 2147 | + if ( search.num_results != 0 ) { |
| 2148 | + if ( search.num_results > provider.limit ) { |
| 2149 | + out += gM( 'rsd_results_desc_total', [( provider.offset + 1 ), to_num, |
| 2150 | + mw.lang.formatNumber( search.num_results )] ); |
1811 | 2151 | } else { |
1812 | | - out += gM( 'rsd_results_desc', [( cp.offset + 1 ), to_num] ); |
| 2152 | + out += gM( 'rsd_results_desc', [( provider.offset + 1 ), to_num] ); |
1813 | 2153 | } |
1814 | 2154 | } |
1815 | 2155 | // check if we have more results (next prev link) |
1816 | | - if ( cp.offset >= cp.limit ) |
1817 | | - out += ' <a href="#" id="rsd_pprev">' + gM( 'rsd_results_prev' ) + ' ' + cp.limit + '</a>'; |
| 2156 | + if ( provider.offset >= provider.limit ) { |
| 2157 | + out += ' <a href="#" id="rsd_pprev">' + gM( 'rsd_results_prev' ) + ' ' + provider.limit + '</a>'; |
| 2158 | + } |
1818 | 2159 | |
1819 | | - if ( cp.sObj.more_results ) |
1820 | | - out += ' <a href="#" id="rsd_pnext">' + gM( 'rsd_results_next' ) + ' ' + cp.limit + '</a>'; |
| 2160 | + if ( search.more_results ) { |
| 2161 | + out += ' <a href="#" id="rsd_pnext">' + gM( 'rsd_results_next' ) + ' ' + provider.limit + '</a>'; |
| 2162 | + } |
1821 | 2163 | |
1822 | 2164 | $j( target ).html( out ); |
1823 | | - |
| 2165 | + |
1824 | 2166 | // set bindings |
1825 | 2167 | $j( '#rsd_pnext' ).click( function() { |
1826 | | - cp.offset += cp.limit; |
1827 | | - _this.runSearch( false ); |
| 2168 | + provider.offset += provider.limit; |
| 2169 | + _this.showCurrentTab(); |
1828 | 2170 | } ); |
1829 | | - |
| 2171 | + |
1830 | 2172 | $j( '#rsd_pprev' ).click( function() { |
1831 | | - cp.offset -= cp.limit; |
1832 | | - if ( cp.offset < 0 ) |
1833 | | - cp.offset = 0; |
1834 | | - _this.runSearch( false ); |
| 2173 | + provider.offset -= provider.limit; |
| 2174 | + if ( provider.offset < 0 ) |
| 2175 | + provider.offset = 0; |
| 2176 | + _this.showCurrentTab(); |
1835 | 2177 | } ); |
| 2178 | + }, |
1836 | 2179 | |
1837 | | - return; |
1838 | | - |
1839 | | - }, |
1840 | | - selectTab:function( selected_cp_id ) { |
1841 | | - js_log( 'select tab: ' + selected_cp_id ); |
1842 | | - this.disp_item = selected_cp_id; |
1843 | | - if ( this.disp_item == 'upload' ) { |
1844 | | - this.doUploadInteface(); |
| 2180 | + selectTab: function( provider ) { |
| 2181 | + js_log( 'select tab: ' + provider ); |
| 2182 | + this.currentProvider = provider; |
| 2183 | + if ( this.currentProvider == 'upload' ) { |
| 2184 | + this.showUploadTab(); |
1845 | 2185 | } else { |
1846 | 2186 | // update the search results: |
1847 | | - this.runSearch(); |
| 2187 | + this.showCurrentTab(); |
1848 | 2188 | } |
1849 | 2189 | }, |
1850 | | - setDispMode:function( mode ) { |
1851 | | - js_log( 'setDispMode:' + mode ); |
1852 | | - this.result_display_mode = mode; |
| 2190 | + |
| 2191 | + setDisplayMode: function( mode ) { |
| 2192 | + js_log( 'setDisplayMode:' + mode ); |
| 2193 | + this.displayMode = mode; |
1853 | 2194 | // run /update search display: |
1854 | | - this.drawOutputResults(); |
| 2195 | + this.showResults(); |
1855 | 2196 | } |
1856 | 2197 | }; |
Index: trunk/phase3/js2/mwEmbed/libAddMedia/simpleUploadForm.js |
— | — | @@ -6,9 +6,9 @@ |
7 | 7 | |
8 | 8 | loadGM( { |
9 | 9 | "mwe-select_file" : "Select file", |
10 | | - "mwe-more_licence_options" : "For more licence options, view the <a href=\"$1\">normal upload page<\/a>", |
| 10 | + "mwe-more_license_options" : "For more license options, view the <a href=\"$1\">normal upload page<\/a>", |
11 | 11 | "mwe-select_ownwork" : "I am uploading entirely my own work, and licencing it under:", |
12 | | - "mwe-licence_cc-by-sa" : "Creative Commons Share Alike (3.0)", |
| 12 | + "mwe-license_cc-by-sa" : "Creative Commons Share Alike (3.0)", |
13 | 13 | "mwe-upload" : "Upload file", |
14 | 14 | "mwe-destfilename" : "Destination filename:", |
15 | 15 | "mwe-summary" : "Summary", |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | |
21 | 21 | var default_form_options = { |
22 | 22 | 'enable_fogg' : true, |
23 | | - 'licence_options' : ['cc-by-sa'], |
| 23 | + 'license_options': ['cc-by-sa'], |
24 | 24 | 'api_target' : false, |
25 | 25 | 'ondone_cb' : null |
26 | 26 | }; |
— | — | @@ -75,7 +75,7 @@ |
76 | 76 | '<div style="clear:both;"></div>' + '<p>' + |
77 | 77 | |
78 | 78 | gM( 'mwe-select_ownwork' ) + '<br>' + |
79 | | - '<input type="checkbox" id="wpLicence" name="wpLicence" value="cc-by-sa">' + gM( 'mwe-licence_cc-by-sa' ) + '</p>' + |
| 79 | + '<input type="checkbox" id="wpLicence" name="wpLicence" value="cc-by-sa">' + gM( 'mwe-license_cc-by-sa' ) + '</p>' + |
80 | 80 | |
81 | 81 | '<input type="submit" accesskey="s" value="' + gM( 'mwe-upload' ) + '" name="wpUploadBtn" id="wpUploadBtn" tabindex="9"/>' + |
82 | 82 | // close the form and div |
— | — | @@ -87,7 +87,7 @@ |
88 | 88 | // by default dissable: |
89 | 89 | $j( '#wpUploadBtn' ).attr( 'disabled', 'disabled' ); |
90 | 90 | |
91 | | - // set up basic licence binding: |
| 91 | + // set up basic license binding: |
92 | 92 | $j( '#wpLicence' ).click( function() { |
93 | 93 | if ( $j( this ).is( ':checked' ) ) { |
94 | 94 | $j( '#wpUploadBtn' ).removeAttr( 'disabled' ); |
Index: trunk/phase3/js2/mwEmbed/libSequencer/mvSequencer.js |
— | — | @@ -160,7 +160,7 @@ |
161 | 161 | 'seqRemoteSearchDriver' |
162 | 162 | ], function() { |
163 | 163 | this_seq.mySearch = new seqRemoteSearchDriver( this_seq ); |
164 | | - this_seq.mySearch.doInitDisplay(); |
| 164 | + this_seq.mySearch.createUI(); |
165 | 165 | } ); |
166 | 166 | } |
167 | 167 | }, |
Index: trunk/phase3/js2/mwEmbed/mv_embed.js |
— | — | @@ -1355,7 +1355,7 @@ |
1356 | 1356 | js_log( ".addMediaWiz call" ); |
1357 | 1357 | // check if already loaded: |
1358 | 1358 | if ( _global['rsdMVRS'] ) { |
1359 | | - _global['rsdMVRS'].doReDisplay(); |
| 1359 | + _global['rsdMVRS'].showDialog(); |
1360 | 1360 | if ( callback ) |
1361 | 1361 | callback( _global['rsdMVRS'] ); |
1362 | 1362 | return ; |
— | — | @@ -1367,7 +1367,7 @@ |
1368 | 1368 | // close the dialog |
1369 | 1369 | $.closeLoaderDialog(); |
1370 | 1370 | // do the add-media-wizard display |
1371 | | - amwObj.doInitDisplay(); |
| 1371 | + amwObj.createUI(); |
1372 | 1372 | // call the parent callback: |
1373 | 1373 | if ( callback ) |
1374 | 1374 | callback( _global['rsdMVRS'] ); |
— | — | @@ -1378,7 +1378,7 @@ |
1379 | 1379 | // First set the cursor for the button to "loading" |
1380 | 1380 | $j( this.selector ).css( 'cursor', 'wait' ).attr( 'title', gM( 'mwe-loading_txt' ) ); |
1381 | 1381 | // set the target: |
1382 | | - iObj['target_invocation'] = this.selector; |
| 1382 | + iObj['target_invoke_button'] = this.selector; |
1383 | 1383 | } |
1384 | 1384 | |
1385 | 1385 | // Load the mv_embed_base skin: |