2 * a library for doing remote media searches
4 * initial targeted archives are:
11 "add_media_wizard": "Add Media Wizard",
12 "mv_media_search" : "Media Search",
13 "rsd_box_layout" : "Box layout",
14 "rsd_list_layout" : "List Layout",
15 "rsd_results_desc" : "Results ",
16 "rsd_results_next" : "next ",
17 "rsd_results_prev" : "previous ",
18 "rsd_no_results" : "No search results for <b>$1</b>",
20 "mv_upload" : "Upload",
21 "rsd_layout" : "Layout:",
22 "rsd_resource_edit" : "Edit Resource: $1",
23 "resource_description_page": "Resource Description Page",
24 "rsd_local_resource_title": "Local Resource Title",
25 "rsd_do_insert": "Do Insert",
27 "cc_title": "Creative Commons",
28 "cc_by_title": "Attribution",
29 "cc_nc_title": "Noncommercial",
30 "cc_nd_title": "No Derivative Works",
31 "cc_sa_title": "Share Alike",
32 "cc_pd_title": "Public Domain",
33 "unknown_license": "Unknown License",
34 "no_import_by_url": "This User or Wiki <b>can not</b> import assets from remote URLs. </p><p> Do you need to Login? </p><p> If permissions are set you may have to enable $wgAllowCopyUploads, <a href=\"http://www.mediawiki.org/wiki/Manual:$wgAllowCopyUploads\">more info</a></p>",
35 "results_from": "Results from <a href=\"$1\" target=\"_new\" >$2</a>"
37 var default_remote_search_options
= {
38 'profile':'mediawiki_edit',
39 'target_container':null, //the div that will hold the search interface
40 //if using a modeal dialog (instead of target_container) how close to the edge of the window should we go:
41 'modal_edge_padding':'20px',
43 'target_invocation': null, //the button or link that will invoke the search interface
45 'default_provider_id':'all', //all or one of the content_providers ids
48 'local_wiki_api_url':null,
50 //can be 'api', 'form', 'autodetect', 'remote_link'
51 'import_url_mode': 'autodetect',
55 'target_textbox':null,
56 'target_render_area': null, //where output render should go:
57 'instance_name': null, //a globally accessible callback instance name
58 'default_query':null, //default search query
59 //specific to sequence profile
61 'cFileNS':'File', //what is the cannonical namespace for images
62 //@@todo (should get that from the api or inpage vars)
64 'enable_upload_tab':true // if we want to enable an uploads tab:
66 if(typeof wgServer
== 'undefined')
68 if(typeof wgScriptPath
== 'undefined')
70 if(typeof stylepath
== 'undefined')
74 * base remoteSearch Driver interface
76 var remoteSearchDriver = function(iObj
){
77 return this.init( iObj
);
79 remoteSearchDriver
.prototype = {
80 results_cleared
:false,
81 //here we define the set of possible media content providers:
84 'title': 'Select Providers'
87 'title': 'Advanced Options'
91 * sets the default display item:
92 * can be any content_providers key or 'all'
94 disp_item
: 'wiki_commons',
95 /** the default content providers list.
97 * (should be note that special tabs like "upload" and "combined" don't go into the content proviers list:
99 * @@todo we will want to load more per user-preference and per category lookup
102 /*content_providers documentation:
103 * @@todo we should move the bulk of the configuration to each file
106 @enabled: whether the search provider can be selected
107 @checked: whether the search provider will show up as seleatable tab (todo: user prefrence)
108 @d: default: if the current cp should be displayed (only one should be the default)
109 @title: the title of the search provider
110 @desc: can use html... todo: need to localize
111 @api_url: the url to query against given the library type:
112 @lib: the search library to use corresponding to the
113 search object ie: 'mediaWiki' = new mediaWikiSearchSearch()
114 @tab_img: the tab image (if set to false use title text)
115 if === "ture" use standard location skin/images/{cp_id}_tab.png
116 if === string use as url for image
118 @linkback_icon default is: /wiki/skins/common/images/magnify-clip.png
120 //domain insert: two modes: simple config or domain list:
121 @local : if the content provider assets need to be imported or not.
122 @local_domains : sets of domains for which the content is local
123 //@@todo should query wgForeignFileRepos setting maybe interwikimap from the api
128 'title' : 'This Wiki',
129 'desc' : '(should be updated with the proper text) maybe import from some config value',
130 'api_url': wgServer
+ wgScriptPath
+ '/api.php',
138 'title' :'Wikimedia Commons',
139 'desc' : 'Wikimedia Commons is a media file repository making available public domain '+
140 'and freely-licensed educational media content (images, sound and video clips) to all.',
141 'homepage': 'http://commons.wikimedia.org/wiki/Main_Page',
142 'api_url':'http://commons.wikimedia.org/w/api.php',
144 'resource_prefix': 'WC_', //prefix on imported resources (not applicable if the repository is local)
146 //list all the domains where commons is local?
147 // probably should set this some other way by doing an api query
148 // or by seeding this config when calling the remote search?
149 'local_domains': ['wikimedia','wikipedia','wikibooks'],
150 //specific to wiki commons config:
151 'search_title':false, //disable title search
152 //set up default range limit
160 'title' : 'Archive.org',
161 'desc' : 'The Internet Archive, a digital library of cultural artifacts',
162 'homepage':'http://www.archive.org/about/about.php',
164 'api_url':'http://homeserver7.us.archive.org:8983/solr/select',
165 'lib' : 'archiveOrg',
167 'resource_prefix': 'AO_',
173 'title' :'Metavid.org',
174 'homepage':'http://metavid.org',
175 'desc' : 'Metavid hosts thousands of hours of US house and senate floor proceedings',
176 'api_url':'http://metavid.org/w/index.php?title=Special:MvExportSearch',
178 'local' :false, //if local set to true we can use local
179 'resource_prefix': 'MV_', //what prefix to use on imported resources
181 'local_domains': ['metavid'], // if the domain name contains metavid
182 // no need to import metavid content to metavid sites
184 'stream_import_key': 'mv_ogg_low_quality', // which stream to import, could be mv_ogg_high_quality
185 //or flash stream, see ROE xml for keys
187 'remote_embed_ext': false, //if running the remoteEmbed extension no need to copy local
188 //syntax will be [remoteEmbed:roe_url link title]
192 //define the licenses
193 // ... this will get complicated quick...
194 // (just look at complexity for creative commons without exessive "duplicate data")
195 // ie cc_by could be "by/3.0/us/" or "by/2.1/jp/" to infinitum...
196 // some complexity should be negated by license equivalances.
198 // but we will have to abstract into another class let content providers provide license urls
199 // and we have to clone the license object and allow local overrides
202 //for now only support creative commons type licenses
203 //used page: http://creativecommons.org/licenses/
205 'base_img_url':'http://upload.wikimedia.org/wikipedia/commons/thumb/',
206 'base_license_url': 'http://creativecommons.org/licenses/',
209 'by-sa': 'by-sa/3.0/',
210 'by-nc-nd': 'by-nc-nd/3.0/',
211 'by-nc': 'by-nc/3.0/',
212 'by-nd': 'by-nd/3.0/',
213 'by-nc-sa': 'by-nc-sa/3.0/',
214 'by-sa': 'by-nc/3.0',
215 'pd': 'publicdomain/'
219 'im':'1/11/Cc-by_new_white.svg/20px-Cc-by_new_white.svg.png'
222 'im':'2/2f/Cc-nc_white.svg/20px-Cc-nc_white.svg.png'
225 'im':'b/b3/Cc-nd_white.svg/20px-Cc-nd_white.svg.png'
228 'im':'d/df/Cc-sa_white.svg/20px-Cc-sa_white.svg.png'
231 'im':'5/51/Cc-pd-new_white.svg/20px-Cc-pd-new_white.svg.png'
238 * @param license_key the license key (ie "by-sa" or "by-nc-sa" etc)
240 getlicenseImgSet: function( licenseObj
){
241 //js_log('output images: '+ imgs);
242 return '<div class="rsd_license" title="'+ licenseObj
.title
+ '" >' +
243 '<a target="_new" href="'+ licenseObj
.lurl
+'" ' +
244 'title="' + licenseObj
.title
+ '">'+
245 licenseObj
.img_html
+
250 * getLicenceKeyFromKey
251 * @param license_key the key of the license (must be defined in: this.licenses.cc.licenses)
253 getLicenceFromKey:function( license_key
, force_url
){
254 if( typeof( this.licenses
.cc
.licenses
[ license_key
]) == 'undefined')
255 return js_error('could not find:' + license_key
);
256 //set the current license pointer:
257 var cl
= this.licenses
.cc
;
258 var title
= gM('cc_title');
260 var license_set
= license_key
.split('-');
261 for(var i
=0;i
< license_set
.length
; i
++){
262 lkey
= license_set
[i
];
263 title
+= ' ' + gM( 'cc_' + lkey
+ '_title');
264 imgs
+='<img class="license_desc" width="20" src="' + cl
.base_img_url
+
265 cl
.license_img
[ lkey
].im
+ '">';
267 var url
= (force_url
) ? force_url
: cl
.base_license_url
+ cl
.licenses
[ license_key
];
276 * getLicenceKeyFromUrl
277 * @param licence_url the url of the license
279 getLicenceFromUrl: function( license_url
){
280 js_log("getLicenceFromUrl::" + license_url
);
281 //first do a direct lookup check:
282 for(var i
in this.licenses
.cc
.licenses
){
283 var lkey
= this.licenses
.cc
.licenses
[i
].split('/')[0];
285 if( parseUri(license_url
).path
.indexOf('/'+ lkey
+'/') != -1){
286 return this.getLicenceFromKey( i
, license_url
);
289 //could not find it return unknown_license
291 'title' : gM('unknown_license'),
292 'img_html' : '<span>' + gM('unknown_license') + '</span>',
296 //some default layout values:
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 result_display_mode
: 'box', //box or list
307 init: function( iObj
){
309 js_log('remoteSearchDriver:init');
310 for( var i
in default_remote_search_options
) {
314 this[ i
] = default_remote_search_options
[i
];
317 //update the base text:
318 if(_this
.target_textbox
)
319 _this
.getTexboxSelection();
321 //set up the content provider config:
323 for(var cpc
in cpconfig
){
324 for(var cinx
in this.cpconfig
[cpc
]){
325 if( this.content_providers
[cpc
] )
326 this.content_providers
[ cpc
][ cinx
] = this.cpconfig
[cpc
][ cinx
];
330 //set up the default model config:
334 'top' : this.modal_edge_padding
,
335 'left' : this.modal_edge_padding
,
336 'right' : this.modal_edge_padding
,
337 'bottom': this.modal_edge_padding
341 //set up the target invocation:
342 if( $j(this.target_invocation
).length
==0 ){
343 js_log("RemoteSearchDriver:: no target invocation provided (will have to run your own doInitDisplay() )");
345 $j(this.target_invocation
).css('cursor','pointer').attr('title', gM('add_media_wizard')).click(function(){
346 _this
.doInitDisplay();
350 doInitDisplay:function(){
352 //setup the parent container:
355 this.init_interface_html();
357 this.add_interface_bindings();
359 //update the target bining to just unhide the dialog:
360 $j(this.target_invocation
).unbind().click(function(){
362 //update the base text:
363 if(_this
.target_textbox
)
364 _this
.getTexboxSelection();
366 $j(_this
.target_container
).dialog('open').parent('.ui-dialog').css( _this
.dmodalCss
);
369 //gets the in and out points for insert position or grabs the selected text for search
370 getTexboxSelection:function(){
371 //update the caretPos
374 //if we have highlighted text use that as the query: (would be fun to add context menu once we have rich editor in-place)
375 if( this.caret_pos
.selection
)
376 this.default_query
= this.caret_pos
.selection
379 getCaretPos:function(){
381 var txtarea
= $j(this.target_textbox
).get(0);
382 var getTextCusorStartPos = function (o
){
383 if (o
.createTextRange
) {
384 var r
= document
.selection
.createRange().duplicate()
385 r
.moveEnd('character', o
.value
.length
)
386 if (r
.text
== '') return o
.value
.length
387 return o
.value
.lastIndexOf(r
.text
)
388 } else return o
.selectionStart
390 var getTextCusorEndPos = function (o
){
391 if (o
.createTextRange
) {
392 var r
= document
.selection
.createRange().duplicate();
393 r
.moveStart('character', -o
.value
.length
);
394 return r
.text
.length
;
396 return o
.selectionEnd
399 this.caret_pos
.s
= getTextCusorStartPos( txtarea
);
400 this.caret_pos
.e
= getTextCusorEndPos( txtarea
);
401 this.caret_pos
.text
= txtarea
.value
;
402 if(this.caret_pos
.s
&& this.caret_pos
.e
&&
403 (this.caret_pos
.s
!= this.caret_pos
.e
))
404 this.caret_pos
.selection
= this.caret_pos
.text
.substring(this.caret_pos
.s
, this.caret_pos
.e
).replace(/ /g
, '\xa0') || '\xa0';
406 js_log('got caret_pos:' + this.caret_pos
.s
);
407 //restore text value: (creating textRanges sometimes screws with the text content)
408 $j(this.target_textbox
).val(this.caret_pos
.text
);
410 init_modal:function(){
411 js_log("init_modal");
413 //add the parent target_container if not provided or missing
414 if(!_this
.target_container
|| $j(_this
.target_container
).length
==0){
415 $j('body').append('<div id="rsd_modal_target" style="position:absolute;top:30px;left:0px;bottom:45px;right:0px" title="' + gM('add_media_wizard') + '" ></div>');
416 _this
.target_container
= '#rsd_modal_target';
417 js_log('appended: #rsd_modal_target' + $j(_this
.target_container
).attr('id'));
418 js_log('added target id:' + $j(_this
.target_container
).attr('id'));
420 //layout = _this.getMaxModalLayout();
421 $j(_this
.target_container
).dialog({
427 //just a place-holder
431 js_log('closed modal');
433 }).css({'height':'100%'}).parent('.ui-dialog').css( _this
.dmodalCss
)
434 //@@bind on resize to disable css dialog to update dmodelCss
435 .bind('resizestart', function(event
, ui
) {
436 _this
.dmodalCss
= {};
439 //bind on drag to remove preset style as well
440 .bind('dragstart', function(event
, ui
) {
441 _this
.dmodalCss
= {};
444 //update the child position: (some of this should be pushed up-stream via dialog config options
445 $j(_this
.target_container
+'~ .ui-dialog-buttonpane').css({
446 'position':'absolute',
451 //re add cancel button
452 _this
.cancelClipEditCB();
453 js_log('done setup of target_container: ' + $j(_this
.target_container
+'~ .ui-dialog-buttonpane').length
);
456 /*var resizeTimer = false;
457 $j(window).bind('resize', function() {
458 var adjustModal = function(){
459 var layout = _this.getMaxModalLayout();
460 //js_log("should adjust: h " + layout.h + ' width:' + layout.w);
461 $j(_this.target_container).dialog('option', 'width', layout.w);
462 $j(_this.target_container).dialog('option', 'height', layout.h);
464 if (resizeTimer) clearTimeout(resizeTimer);
465 var resizeTimer = setTimeout(adjustModal, 100);
469 getMaxModalLayout:function(border
){
472 //js_log('setting h:' + (parseInt( $j(document).height() ) - parseInt(border*2)) + ' from:' + $j(document).height() );
474 'h': parseInt( $j(document
).height() ) - parseInt(border
*4),
475 'w': parseInt( $j(document
).width() ) - parseInt(border
*2),
480 //sets up the initial html interface
481 init_interface_html:function(){
482 js_log('init_interface_html');
484 var dq
= (this.default_query
)? this.default_query
: '';
485 js_log('f::init_interface_html');
487 var o
= '<div class="rsd_control_container" style="width:100%">' +
488 '<form id="rsd_form" action="javascript:return false;" method="GET">'+
489 '<input class="ui-widget-content ui-corner-all" type="text" tabindex="1" value="' + dq
+ '" maxlength="512" id="rsd_q" name="rsd_q" '+
490 'size="20" autocomplete="off"/> '+
491 $j
.btnHtml( gM('mv_media_search'), 'rms_search_button', 'search') +
493 //close up the control container:
496 //search provider tabs based on "checked" and "enabled" and "combined tab"
497 o
+='<div id="rsd_results_container" style="top:0px;bottom:0px;left:0px;right:0px;"></div>';
498 $j(this.target_container
).html( o
);
501 $j(this.target_container
+ ' .rms_search_button').btnBind().click(function(){
507 //run the default search:
508 if( this.default_query
)
511 add_interface_bindings:function(){
513 js_log("f:add_interface_bindings:");
516 $j('#mso_selprovider,#mso_selprovider_close').unbind().click(function(){
517 if($j('#rsd_options_bar:hidden').length
!=0 ){
518 $j('#rsd_options_bar').animate({
523 $j('#rsd_options_bar').animate({
526 }, "normal", function(){
532 $j('#rsd_form').unbind().submit(function(){
534 //don't submit the form
538 doUploadInteface:function(){
540 mv_set_loading('#tab-upload');
541 $j('#tab-upload').html('upload interface goes here ;)');
543 //todo include firefogg support:
544 /*mvJsLoader.doLoad( [
547 _this.cUpLoader = new mvUploader({
548 'target_div': '#tab-upload',
549 'upload_done_action:': function( rTitle){
551 mv_set_loading('#tab-upload');
552 //do a direct api query for resource info (to build rObj
553 _this.getResourceFromTitle( rTitle, function(rObj){
554 //call resource Edit:
555 _this.resourceEdit( rObj );
561 runSearch: function(){
562 js_log("f:runSearch::" + this.disp_item
);
564 var draw_direct_flag
= true;
565 if(!this.content_providers
[this.disp_item
]) {
566 js_log("can't run search for:" + this.disp_item
);
569 cp
= this.content_providers
[this.disp_item
];
571 //check if we need to update:
572 if( typeof cp
.sObj
!= 'undefined' ){
573 if(cp
.sObj
.last_query
== $j('#rsd_q').val() && cp
.sObj
.last_offset
== cp
.offset
){
574 js_log('last query is: ' + cp
.sObj
.last_query
+ ' matches: ' + $j('#rsd_q').val() );
576 js_log('last query is: ' + cp
.sObj
.last_query
+ ' not match: ' + $j('#rsd_q').val() );
577 draw_direct_flag
= false;
580 draw_direct_flag
= false;
582 if( !draw_direct_flag
){
583 //set the content to loading while we do the search:
584 $j('#tab-' + this.disp_item
).html( mv_get_loading_img() );
586 //make sure the search library is loaded and issue the search request
587 this.getLibSearchResults( cp
);
590 //issue a api request & cache the result
591 //this check can be avoided by setting the this.import_url_mode = 'api' | 'form' | insted of 'autodetect' or 'none'
592 checkForCopyURLSupport:function ( callback
){
594 js_log('checkForCopyURLSupport:: ');
595 //see if we already have the import mode:
596 if( this.import_url_mode
!= 'autodetect'){
597 js_log('import mode: ' + _this
.import_url_mode
);
600 //if we don't have the local wiki api defined we can't auto-detect use "link"
601 if(!_this
.local_wiki_api_url
){
602 js_log('import mode: remote link (no import_wiki_api_url)');
603 _this
.import_url_mode
= 'remote_link';
606 if( this.import_url_mode
== 'autodetect' ){
608 'data': { 'action':'paraminfo', 'modules':'upload' },
609 'url': _this
.local_wiki_api_url
611 if( typeof data
.paraminfo
.modules
[0].classname
== 'undefined'){
612 //@@todo would be nice if API permission on: action=query&meta=userinfo&uiprop=rights
613 // upload_by_url property reflected if $wgAllowCopyUploads config value .. oh well.
617 url
: wgArticlePath
.replace( '$1', 'Special:Upload' ), //@@todo may have problems in localized special pages
618 //(could hit meta=siteinfo & specialpagealiases )
619 // but might be overkill for now cuz we want to switch to new-upload branch soon.
620 success: function( form_html
){
621 if( form_html
.indexOf( 'wpUploadFileURL' ) != -1){
622 _this
.import_url_mode
= 'form';
624 _this
.import_url_mode
= 'none';
626 js_log('import mode: ' + _this
.import_url_mode
);
630 js_log('error in getting Special:Upload page');
631 _this
.import_url_mode
= 'none';
633 js_log('import mode: ' + _this
.import_url_mode
);
638 for( var i
in data
.paraminfo
.modules
[0].parameters
){
639 var pname
= data
.paraminfo
.modules
[0].parameters
[i
].name
;
640 if( pname
== 'url' ){
641 js_log( 'Autodetect Upload Mode: api: copy by url:: ' );
642 //check permission too:
643 _this
.checkForCopyURLPermission(function( canCopyUrl
){
645 _this
.import_url_mode
= 'api';
646 js_log('import mode: ' + _this
.import_url_mode
);
649 _this
.import_url_mode
= 'none';
650 js_log('import mode: ' + _this
.import_url_mode
);
662 * checkForCopyURLPermission:
663 * not really nessesary the api request to upload will return apopprirate error if the user lacks permission. or $wgAllowCopyUploads is set to false
664 * (use this function if we want to issue a warning up front)
666 checkForCopyURLPermission:function( callback
){
670 'data':{ 'action' : 'query', 'meta' : 'userinfo', 'uiprop' : 'rights' },
671 'url': _this
.local_wiki_api_url
,
674 for( var i
in data
.query
.userinfo
.rights
){
675 var right
= data
.query
.userinfo
.rights
[i
];
676 //js_log('checking: ' + right ) ;
677 if(right
== 'upload_by_url'){
679 return true; //break out of the function
685 getLibSearchResults:function( cp
){
688 //first check if we should even run the search at all (can we import / insert into the page? )
689 if( !this.checkRepoLocal( cp
) && this.import_url_mode
== 'autodetect' ){
690 //cp is not local check if we can support the import mode:
691 this.checkForCopyURLSupport( function(){
692 _this
.getLibSearchResults( cp
);
695 }else if( !this.checkRepoLocal( cp
) && this.import_url_mode
== 'none'){
696 if( this.disp_item
== 'combined' ){
697 //combined results are harder to error handle just ignore that repo
698 cp
.sObj
.loading
= false;
700 $j('#tab-' + this.disp_item
).html( '<div style="padding:10px">'+ gM('no_import_by_url') +'</div>');
704 //set up the library req:
709 js_log("loaded .. disp is: " + _this
.disp_item
);
710 //else we need to run the search:
711 var iObj
= {'cp':cp
, 'rsd':_this
};
712 eval('cp.sObj = new '+cp
.lib
+'Search( iObj );');
714 js_log('Error: could not find search lib for ' + cp_id
);
716 //inherit defaults if not set:
717 cp
.limit
= (cp
.limit
) ? cp
.limit
: cp
.sObj
.limit
;
718 cp
.offset
= (cp
.offset
) ? cp
.offset
: cp
.sObj
.offset
;
721 cp
.sObj
.getSearchResults();
722 _this
.checkResultsDone();
725 /* check for all the results to finish */
726 checkResultsDone: function(){
727 //js_log('rsd:checkResultsDone');
729 var loading_done
= true;
731 for(var cp_id
in this.content_providers
){
732 var cp
= this.content_providers
[ cp_id
];
733 if(typeof cp
['sObj'] != 'undefined'){
734 if( cp
.sObj
.loading
)
739 this.drawOutputResults();
741 //make sure the instance name is up-to-date refrence to _this;
742 eval( _this
.instance_name
+ ' = _this');
743 setTimeout( _this
.instance_name
+ '.checkResultsDone()', 50);
746 drawTabs: function(){
748 //add the tabs to the rsd_results container:
749 var o
='<div id="rsd_tabs_container" style="width:100%;">';
750 var selected_tab
= 0;
754 for(var cp_id
in this.content_providers
){
755 var cp
= this.content_providers
[cp_id
];
756 if( cp
.enabled
&& cp
.checked
){
757 //add selected default if set
758 if( this.disp_item
== cp_id
)
761 o
+='<li class="rsd_cp_tab">';
762 o
+='<a id="rsd_tab_' + cp_id
+ '" href="#tab-' + cp_id
+ '">';
763 if(cp
.tab_img
=== true){
764 o
+='<img alt="' + cp
.title
+'" src="' + mv_skin_img_path
+ 'remote_cp/' + cp_id
+ '_tab.png">';
772 tabc
+='<div id="tab-'+ cp_id
+'" class="rsd_results"/>';
775 //do an upload tab if enabled:
776 if( this.enable_upload_tab
){
777 o
+='<li class="rsd_cp_tab" ><a id="rsd_tab_upload" href="#tab-upload">' + gM('upload') + '</a></li>';
778 tabc
+='<div id="tab-upload" />';
781 //output the tab content containers:
783 o
+='</div>'; //close tab container
785 //output the respective results holders
786 $j('#rsd_results_container').html(o
);
787 //setup bindings for tabs make them sortable: (@@todo remember order)
788 js_log('selected tab is: ' + selected_tab
);
789 $j("#rsd_tabs_container").tabs({
790 selected
:selected_tab
,
791 select: function(event
, ui
) {
792 _this
.selectTab( $j(ui
.tab
).attr('id').replace('rsd_tab_', '') );
795 }).find(".ui-tabs-nav").sortable({axis
:'x'});
797 /*$j('.rsd_cp_tab').click(function(){
798 _this.selectTab( $j(this).attr('id').replace(/rsd_tab_/, '') );
801 //setup key binding (no longer nessesary tabs provide this functionality)
802 /*$j().keyup(function(e){
803 js_log('keyup on : ' +e.which );
804 //if escape pressed clear the interface:
811 getResourceFromTitle:function( rTitle
, callback
){
815 'titles': _this
.cFileNS
+ ':' + rTitle
819 'url':this.local_wiki_api_url
821 //@@todo propogate the rObj
826 //@@todo we could load the id with the content provider id to find the object faster...
827 getResourceFromId:function( rid
){
828 //js_log('getResourceFromId:' + rid );
829 //strip out /res/ if preset:
830 rid
= rid
.replace(/res_/, '');
831 for(var cp_id
in this.content_providers
){
832 cp
= this.content_providers
[ cp_id
];
833 if(rid
.indexOf( cp_id
) != -1){
834 rid
= rid
.replace( cp_id
+ '_','');
836 for(var rInx
in cp
.sObj
.resultsObj
){
838 return cp
.sObj
.resultsObj
[rInx
];
843 js_log("ERROR: could not find " + rid
);
846 drawOutputResults: function(){
847 js_log('f:drawOutputResults::' + this.disp_item
);
851 var cp_id
= this.disp_item
;
852 var cp
= this.content_providers
[this.disp_item
];
854 //empty the existing results:
855 $j('#tab-' + cp_id
).empty();
857 //output the results bar / controls
858 _this
.setResultBarControl();
860 var drawResultCount
=0;
862 //output all the results for the current disp_item
863 if( typeof cp
['sObj'] != 'undefined' ){
864 $j
.each(cp
.sObj
.resultsObj
, function(rInx
, rItem
){
865 if( _this
.result_display_mode
== 'box' ){
866 o
+='<div id="mv_result_' + rInx
+ '" class="mv_clip_box_result" style="width:' +
867 _this
.thumb_width
+ 'px;height:'+ (_this
.thumb_width
-20) +'px;position:relative;">';
868 //check for missing poster types for audio
869 if( rItem
.mime
=='audio/ogg' && !rItem
.poster
){
870 rItem
.poster
= mv_skin_img_path
+ 'sound_music_icon-80.png';
872 //get a thumb with proper resolution transform if possible:
873 o
+='<img title="'+rItem
.title
+'" class="rsd_res_item" id="res_' + cp_id
+ '_' + rInx
+
874 '" style="width:' + _this
.thumb_width
+ 'px;" src="' +
875 cp
.sObj
.getImageTransform( rItem
, {'width':_this
.thumb_width
} )
877 //add a linkback to resource page in upper right:
879 o
+='<a target="_new" style="position:absolute;top:0px;right:0px" title="' +
880 gM('resource_description_page') +
881 '" href="' + rItem
.link
+ '"><img src="http://upload.wikimedia.org/wikipedia/commons/6/6b/Magnify-clip.png"></a>';
882 //add license icons if present
884 o
+= _this
.getlicenseImgSet( rItem
.license
);
886 }else if(_this
.result_display_mode
== 'list'){
887 o
+='<div id="mv_result_' + rInx
+ '" class="mv_clip_list_result" style="width:90%">';
888 o
+='<img title="'+rItem
.title
+'" class="rsd_res_item" id="res_' + cp_id
+ '_' + rInx
+'" style="float:left;width:' +
889 _this
.thumb_width
+ 'px;" src="' +
890 cp
.sObj
.getImageTransform( rItem
, {'width':_this
.thumb_width
} )
892 //add license icons if present
894 o
+= _this
.getlicenseImgSet( rItem
.license
);
897 o
+='<div style="clear:both" />';
902 js_log('append to: ' + '#tab-' + cp_id
);
903 //put in the tab output (plus clear the output)
904 $j('#tab-' + cp_id
).append( o
+ '<div style="clear:both"/>');
907 js_log( ' drawResultCount :: ' + drawResultCount
+ ' append: ' + $j('#rsd_q').val() );
909 //remove any old search res
910 $j('#rsd_no_search_res').remove();
911 if( drawResultCount
== 0 )
912 $j('#tab-' + cp_id
).append( '<span style="padding:10px">' + gM( 'rsd_no_results', $j('#rsd_q').val() ) + '</span>');
914 this.addResultBindings();
916 addResultBindings:function(){
918 $j('.mv_clip_'+_this
.result_display_mode
+'_result').hover(function(){
919 $j(this).addClass('mv_clip_'+_this
.result_display_mode
+'_result_over');
920 //also set the animated image if avaliable
921 var res_id
= $j(this).children('.rsd_res_item').attr('id');
922 var rObj
= _this
.getResourceFromId( res_id
);
923 if( rObj
.poster_ani
)
924 $j('#' + res_id
).attr('src', rObj
.poster_ani
);
926 $j(this).removeClass('mv_clip_'+_this
.result_display_mode
+'_result_over');
927 var res_id
= $j(this).children('.rsd_res_item').attr('id');
928 var rObj
= _this
.getResourceFromId( res_id
);
929 //restore the original (non animated)
930 if( rObj
.poster_ani
)
931 $j('#' + res_id
).attr('src', rObj
.poster
);
933 //resource click action: (bring up the resource editor)
934 $j('.rsd_res_item').unbind().click(function(){
935 var rObj
= _this
.getResourceFromId( $j(this).attr("id") );
936 _this
.resourceEdit( rObj
, this );
939 resourceEdit:function( rObj
, rsdElement
){
940 js_log('f:resourceEdit:' + rObj
.title
);
942 //remove any existing resource edit interface:
943 $j('#rsd_resource_edit').remove();
944 //set the media type:
945 if(rObj
.mime
.indexOf('image')!=-1){
946 //set width to default image_edit_width
947 var maxWidth
= _this
.image_edit_width
;
948 var mediaType
= 'image';
949 }else if(rObj
.mime
.indexOf('audio')!=-1){
950 var maxWidth
= _this
.video_edit_width
;
951 var mediaType
= 'audio';
953 //set to default video size:
954 var maxWidth
= _this
.video_edit_width
;
955 var mediaType
= 'video';
957 //so that transcripts show ontop
958 var overflow_style
= ( mediaType
=='video' )?'':'overflow:auto;';
959 //append to the top level of model window:
960 $j( _this
.target_container
).append('<div id="rsd_resource_edit" '+
961 'style="position:absolute;top:0px;left:0px;bottom:85px;right:4px;background-color:#FFF;">' +
962 '<div id="clip_edit_disp" style="position:absolute;' + overflow_style
+ 'width:100%;height:100%;padding:5px;'+
963 'width:' + (maxWidth
) + 'px;" >' +
964 mv_get_loading_img('position:absolute;top:30px;left:30px') +
966 '<div id="clip_edit_ctrl" class="ui-widget ui-widget-content ui-corner-all" style="position:absolute;'+
967 'left:' + ( maxWidth
+ 10 ) +'px;top:5px;bottom:10px;right:0px;overflow:auto;padding:5px;">'+
968 mv_get_loading_img() +
971 //update add media wizard title:
972 $j( _this
.target_container
).dialog( 'option', 'title', gM('add_media_wizard')+': '+ gM('rsd_resource_edit', rObj
.title
) );
973 js_log('did append to: '+ _this
.target_container
);
975 $j('#rsd_resource_edit').css('opacity',0);
977 $j('#rsd_edit_img').remove();//remove any existing rsd_edit_img
979 //left side holds the image right size the controls /
980 $j(rsdElement
).clone().attr('id', 'rsd_edit_img').appendTo('#clip_edit_disp').css({
981 'position':'absolute',
989 //assume we keep aspect ratio for the thumbnail that we clicked:
990 var tRatio
= $j(rsdElement
).height() / $j(rsdElement
).width();
992 var tRatio
= 1; //set ratio to 1 if the width of the thumbnail can't be found for some reason
994 js_log('set from ' + $j('#rsd_edit_img').width()+'x'+ $j('#rsd_edit_img').height() + ' to init thumbimage to ' + maxWidth
+ ' x ' + parseInt( tRatio
* maxWidth
) );
995 //scale up image and to swap with high res version
996 $j('#rsd_edit_img').animate({
1000 'width': maxWidth
+ 'px',
1001 'height': parseInt( tRatio
* maxWidth
) + 'px'
1002 }, "slow"); // do it slow to give it a chance to finish loading the HQ version
1004 if( mediaType
== 'image' ){
1005 _this
.loadHQImg(rObj
, {'width':maxWidth
}, 'rsd_edit_img', function(){
1006 $j('.mv_loading_img').remove();
1009 //also fade in the container:
1010 $j('#rsd_resource_edit').animate({
1012 'background-color':'#FFF',
1015 js_log('do load the media editor:');
1016 //do load the media Editor
1017 _this
.doMediaEdit( rObj
, mediaType
);
1019 loadHQImg:function(rObj
, size
, target_img_id
, callback
){
1020 //get the HQ image url:
1021 rObj
.pSobj
.getImageObj( rObj
, size
, function( imObj
){
1022 rObj
['edit_url'] = imObj
.url
;
1024 js_log("edit url: " + rObj
.edit_url
);
1026 rObj
['width'] = imObj
.width
;
1027 rObj
['height'] = imObj
.height
;
1029 //see if we need to animate some transition
1030 var newSize
= false;
1031 if( size
.width
!= imObj
.width
){
1032 js_log('loadHQImg:size mismatch: ' + size
.width
+ ' != ' + imObj
.width
);
1034 'width':imObj
.width
+ 'px',
1035 'height':imObj
.height
+ 'px'
1037 //set the target id to the new size:
1038 $j('#'+target_img_id
).animate( newSize
);
1040 js_log('using req size: ' + imObj
.width
+ 'x' + imObj
.height
);
1041 $j('#'+target_img_id
).animate( {'width':imObj
.width
+'px', 'height' : imObj
.height
+ 'px'});
1043 //don't swap it in until its loaded:
1044 var img
= new Image();
1045 // load the image image:
1046 $j(img
).load(function () {
1047 $j('#'+target_img_id
).attr('src', rObj
.edit_url
);
1048 //let the caller know we are done and what size we ended up with:
1050 }).error(function () {
1051 js_log("Error with: " + rObj
.edit_url
);
1052 }).attr('src', rObj
.edit_url
);
1055 cancelClipEditCB:function(){
1057 var b_target
= _this
.target_container
+ '~ .ui-dialog-buttonpane';
1058 $j('#rsd_resource_edit').remove();
1059 js_log("should update: " + b_target
+ ' with: cancel');
1060 $j(b_target
).html( $j
.btnHtml( 'Cancel' , 'mv_cancel_rsd', 'close'))
1061 .children('.mv_cancel_rsd')
1064 $j( _this
.target_container
).dialog('close');
1068 /*set-up the control actions for clipEdit with relevent callbacks */
1069 getClipEditControlActions:function(){
1072 'insert' :function(rObj
){
1073 _this
.insertResource(rObj
);
1075 'preview':function(rObj
){
1076 _this
.previewResource( rObj
)
1078 'cancel' :function(){
1079 _this
.cancelClipEditCB()
1083 //loads the media editor:
1084 doMediaEdit:function( rObj
, mediaType
){
1087 'rObj':rObj
, //the resource object
1088 'parent_ct':'rsd_modal_target',
1089 'clip_disp_ct':'clip_edit_disp',
1090 'control_ct': 'clip_edit_ctrl',
1091 'media_type': mediaType
,
1093 'controlActionsCb':_this
.getClipEditControlActions()
1096 var clibs
= ['mvClipEdit'];
1097 if( mediaType
== 'image'){
1098 //display the mvClipEdit obj once we are done loading:
1099 mvJsLoader
.doLoad( clibs
, function(){
1100 //run the image clip tools
1101 _this
.cEdit
= new mvClipEdit( mvClipInit
);
1104 if( mediaType
== 'video' || mediaType
== 'audio'){
1105 //get any additonal embedding helper meta data prior to doing the acutal embed
1106 // normally this meta should be provided in the search result (but archive.org has a seperate query for more meida meta)
1107 rObj
.pSobj
.getEmbedTimeMeta( rObj
, function(){
1108 //make sure we have the embedVideo libs:
1109 mvJsLoader
.embedVideoCheck( function(){
1110 js_log('append html: ' + rObj
.pSobj
.getEmbedHTML( rObj
, {id
:'embed_vid'}) );
1111 $j('#clip_edit_disp').html(
1112 rObj
.pSobj
.getEmbedHTML( rObj
, {id
:'embed_vid'})
1115 rewrite_by_id('embed_vid',function(){
1116 //grab any information that we got from the ROE xml or parsed from the media file
1117 rObj
.pSobj
.getEmbedObjParsedInfo( rObj
, 'embed_vid' );
1118 //add the re-sizable to the doLoad request:
1119 clibs
.push( '$j.ui.resizable');
1120 clibs
.push( '$j.fn.hoverIntent');
1121 mvJsLoader
.doLoad(clibs
, function(){
1122 //make sure the rsd_edit_img is hidden:
1123 $j('#rsd_edit_img').remove();
1124 //run the image clip tools
1125 _this
.cEdit
= new mvClipEdit( mvClipInit
);
1132 checkRepoLocal:function( cp
){
1136 //check if we can embed the content locally per a domain name check:
1137 var local_host
= parseUri( this.local_wiki_api_url
).host
;
1138 if( cp
.local_domains
) {
1139 for(var i
=0;i
< cp
.local_domains
.length
; i
++){
1140 var ld
= cp
.local_domains
[i
];
1141 if( local_host
.indexOf( ld
) != -1)
1149 checkImportResource:function( rObj
, cir_callback
){
1150 //@@todo get the localized File/Image namespace name or do a general {NS}:Title
1151 var cp
= rObj
.pSobj
.cp
;
1154 //update base target_resource_title:
1155 rObj
.target_resource_title
= rObj
.titleKey
.replace(/File:|Image:/,'')
1157 //check if local repository
1158 //or if import mode if just "linking" (we should alaredy have the 'url'
1160 if( this.checkRepoLocal( cp
) || this.import_url_mode
== 'remote_link'){
1161 //local repo jump directly to check Import Resource callback:
1162 cir_callback( rObj
);
1164 //update target_resource_title with resource repository prefix:
1165 rObj
.target_resource_title
= cp
.resource_prefix
+ rObj
.target_resource_title
;
1167 //check if the resource is not already on this wiki
1170 'titles': _this
.cFileNS
+ ':' + rObj
.target_resource_title
,
1171 'prop' : 'imageinfo',
1178 'url':this.local_wiki_api_url
1180 var found_title
= false;
1181 for(var i
in data
.query
.pages
){
1182 if( i
!= '-1' && i
!= '-2' ){
1183 js_log('found title: ' + i
+ ':' + data
.query
.pages
[i
]['title']);
1184 found_title
=data
.query
.pages
[i
]['title'];
1185 //update to local src
1186 rObj
.local_src
= data
.query
.pages
[i
]['imageinfo'][0].url
;
1187 //@@todo maybe update poster too?
1188 rObj
.local_poster
= data
.query
.pages
[i
]['imageinfo'][0].thumburl
;
1192 js_log("checkImportResource:found title:" + found_title
);
1193 //resource is already present (or resource with same name is already present)
1194 rObj
.target_resource_title
= found_title
.replace(/File:|Image:/,'');
1195 cir_callback( rObj
);
1197 js_log("resource not present: update:"+ _this
.cFileNS
+ ':' + rObj
.target_resource_title
);
1199 //update the rObj with import info
1200 rObj
.pSobj
.updateDataForImport( rObj
);
1202 //setup the resource description from resource description:
1203 var wt
= '{{Information '+"\n"+
1204 '|Description= ' + rObj
.pSobj
.getImportResourceDescWiki( rObj
);
1205 //output person and bill info if
1206 wt
+='|Source=' + '[' + $j
.trim( rObj
.link
) + ' Original Source]'+ "\n";
1209 wt
+='|Author=' + rObj
.author
+"\n";
1212 wt
+='|Date=' + rObj
.date
+"\n";
1214 //add the Permision info:
1215 wt
+='|Permission=' + rObj
.pSobj
.getPermissionWikiTag( rObj
) +"\n";
1217 if( rObj
.other_versions
)
1218 wt
+='|other_versions=' + rObj
.other_versions
+ "\n";
1221 //get any extra categories or helpful links
1222 wt
+= rObj
.pSobj
.getExtraResourceDescWiki( rObj
);
1225 $j('#rsd_resource_import').remove();//remove any old resource imports
1226 //@@ show user dialog to import the resource
1227 $j( _this
.target_container
).append('<div id="rsd_resource_import" '+
1228 'class="ui-state-highlight ui-widget-content ui-state-error" ' +
1229 'style="position:absolute;top:50px;left:50px;right:50px;bottom:50px;z-index:5">' +
1230 '<h3 style="color:red">Resource: <span style="color:black">' + rObj
.title
+ '</span> needs to be imported</h3>'+
1231 '<div id="rsd_preview_import_container" style="position:absolute;width:50%;bottom:0px;left:0px;overflow:auto;top:30px;">' +
1232 rObj
.pSobj
.getEmbedHTML( rObj
, {'id': _this
.target_container
+ '_rsd_pv_vid', 'max_height':'200','only_poster':true} )+ //get embedHTML with small thumb:
1233 '<br style="clear both">'+
1234 '<strong>Resource Page Description:</strong>'+
1235 '<div id="rsd_import_desc" syle="display:inline;">'+
1236 mv_get_loading_img('position:absolute;top:5px;left:5px') +
1239 '<div id="rds_edit_import_container" style="position:absolute;left:50%;' +
1240 'bottom:0px;top:30px;right:0px;overflow:auto;">'+
1241 '<strong>Local Resource Title:</strong><br>'+
1242 '<input type="text" size="30" value="' + rObj
.target_resource_title
+ '" readonly="true"><br>'+
1243 '<strong>Edit WikiText Resource Description:</strong>(will be replaced by forms soon)' +
1244 '<textarea id="rsd_import_ta" id="mv_img_desc" style="width:90%;" rows="8" cols="50">' +
1247 '<input type="checkbox" value="true" id="wpWatchthis" name="wpWatchthis" tabindex="7"/>' +
1248 '<label for="wpWatchthis">Watch this page</label><br><br><br>' +
1250 $j
.btnHtml('Do Import Resource', 'rsd_import_doimport', 'check' ) + ' ' +
1252 $j
.btnHtml('Update Preview', 'rsd_import_apreview', 'refresh' ) + '<div style="clear:both;height:20px;"/>' +
1254 $j
.btnHtml('Cancel Import', 'rsd_import_acancel', 'close' ) + ' ' +
1257 //output the rendered and non-renderd version of description for easy swiching:
1261 rewrite_by_id(_this
.target_container
+ '_rsd_pv_vid');
1262 //load the preview text:
1263 _this
.getParsedWikiText( wt
, _this
.cFileNS
+':'+ rObj
.target_resource_title
, function( o
){
1264 $j('#rsd_import_desc').html(o
);
1267 $j( _this
.target_container
+ ' .rsd_import_apreview').btnBind().click(function(){
1268 /*$j('#rsd_import_desc').show().html(
1269 mv_get_loading_img()
1271 //load the preview text:
1272 _this
.getParsedWikiText( $j('#rsd_import_ta').val(), _this
.cFileNS
+':'+ rObj
.target_resource_title
, function( o
){
1273 js_log('got updated preivew: ');
1274 $j('#rsd_import_desc').html(o
);
1277 $j(_this
.target_container
+ ' .rsd_import_doimport').btnBind().click(function(){
1278 //check import mode:
1279 if(_this
.import_url_mode
=='form'){
1280 _this
.doImportSpecialPage( rObj
, cir_callback
);
1281 }else if( _this
.import_url_mode
=='api'){
1282 _this
.doImportAPI( rObj
, cir_callback
);
1284 js_log("Error: import mode is not form or API (can not copy asset)");
1287 $j( _this
.target_container
+ ' .rsd_import_acancel').btnBind().click(function(){
1288 $j('#rsd_resource_import').fadeOut("fast",function(){
1297 doImportAPI:function(rObj
, cir_callback
){
1299 //baseUploadInterface
1301 'mvBaseUploadInterface',
1305 //initicate a download similar to url copy:
1306 myUp
= new mvBaseUploadInterface({
1307 'api_url' : _this
.local_wiki_api_url
,
1308 'done_upload_cb':function(){
1309 //we have finished the upload:
1311 //close up the rsd_resource_import
1312 $j('#rsd_resource_import').remove();
1313 //run the parent callback:
1317 //set the edit token if we have it handy
1318 _this
.getEditToken(function( token
){
1319 myUp
.etoken
= token
;
1322 'filename' : rObj
.target_resource_title
,
1323 'comment' : $j('#rsd_import_ta').val()
1330 getEditToken:function(callback
){
1331 //first try the page form:
1332 var etoken
= $j("input[name='wpEditToken']").val();
1337 //@@todo try to load over ajax if( _this.local_wiki_api_url ) is set
1338 // (your on the api domain but are inserting from a normal page view)
1339 if( _this
.local_wiki_api_url
){
1344 * doImportSpecialPage
1345 * can be depricated once we support upload api support is widespred.
1347 doImportSpecialPage:function(rObj
, cir_callback
){
1351 'data': { 'action':'query',
1354 'titles': rObj
.titleKey
1356 'url':_this
.local_wiki_api_url
1358 //could recheck if it has been created in the mean time
1359 if( data
.query
.pages
[-1] ){
1360 var editToken
= data
.query
.pages
[-1]['edittoken'];
1362 //@@todo give an ajax login or be more friendly in some way:
1363 js_error("You don't have permission to upload (are you logged in?)");
1365 $j('#modalbox').fadeOut("normal",function(){
1367 $j('#mv_overlay').remove();
1370 //not sure if we can do remote url uploads (so just do a local post)
1371 js_log('got token for new page:' +editToken
);
1373 'wpSourceType' :'web',
1374 'wpUploadFileURL' : rObj
.src
,
1375 'wpDestFile' : rObj
.target_resource_title
,
1376 'wpUploadDescription' : $j('#rsd_import_ta').val(),
1377 'wpWatchthis' : $j('#wpWatchthis').val(),
1378 'wpUpload' : 'Upload file'
1381 $j('#rsd_resource_import').append('<div id="rsd_import_progress"'+
1382 'style="position:absolute;top:0px;'+
1383 'left:0px;width:100%;height:100%;'+
1384 'z-index:5;background:#FFF;overflow:auto;">'+
1385 '<div style="position:absolute;left:30%;right:30%"><h3>Importing Asset</h3><br>' +
1386 mv_get_loading_img('','mv_loading_bar_img') +
1390 $j
.post(wgArticlePath
.replace(/\$1/,'Special:Upload'),
1393 //@@todo this will be replaced once we add upload image support to the api.
1395 //very basic test to see if we got passed to the image page:
1396 //@@todo more normalization stuff
1397 var sstring
='var wgPageName = "' + _this
.cFileNS
+ ':' + rObj
.target_resource_title
.replace(/ /g
,'_') +'"';
1398 if(data
.indexOf( sstring
) !=-1){
1399 js_log('found: ' + sstring
);
1400 $j('#rsd_resource_import').remove();
1401 cir_callback( rObj
);
1403 js_log("Error or warning: (did not find: \"" + sstring
+ ' in output' );
1404 pos_etitle
= '<h1 class="firstHeading">';
1405 var error_txt
= form_txt
= '';
1406 var res
= grabWikiFormError( data
);
1409 error_txt
= res
.error_txt
;
1412 form_txt
= res
.form_txt
;
1414 js_log( 'error text is: ' + error_txt
);
1415 $j( '#rsd_resource_import' ).html( '<h3>Error</h3>' + error_txt
+ '<br>' + form_txt
+
1417 '<a href="#" id="rsd_import_error" >Cancel import</a>'
1419 //set up cancel action:
1420 $j('#rsd_import_error').click(function(){
1421 $j('#rsd_resource_import').remove();
1432 previewResource:function( rObj
){
1434 this.checkImportResource( rObj
, function(){
1435 //put another window ontop:
1436 $j( _this
.target_container
).append('<div id="rsd_preview_display"' +
1437 'style="position:absolute;overflow:hidden;z-index:4;top:0px;bottom:75px;right:0px;left:0px;background-color:#FFF;">' +
1438 mv_get_loading_img('top:30px;left:30px') +
1441 var bPlaneTarget
= _this
.target_container
+'~ .ui-dialog-buttonpane';
1442 var pTitle
= $j( _this
.target_container
).dialog('option', 'title');
1445 $j( _this
.target_container
).dialog('option', 'title', 'Preview Insert of Resource: ' + rObj
.title
);
1447 //update buttons preview:
1448 $j(bPlaneTarget
).html( $j
.btnHtml( gM('rsd_do_insert'), 'preview_do_insert', 'check') + ' ' )
1449 .children('.preview_do_insert')
1451 _this
.insertResource( rObj
);
1453 //update cancel button
1454 $j(bPlaneTarget
).append('<a href="#" class="preview_close">Do More Modification</a>')
1455 .children('.preview_close')
1457 $j('#rsd_preview_display').remove();
1459 $j( _this
.target_container
).dialog('option', 'title', pTitle
);
1460 //restore buttons (from the clipEdit object::)
1461 _this
.cEdit
.updateInsertControlActions();
1464 //update the preview_wtext
1465 _this
.updatePreviewText( rObj
);
1466 _this
.getParsedWikiText(_this
.preview_wtext
, _this
.target_title
,
1468 $j('#rsd_preview_display').html( phtml
);
1469 //update the display of video tag items (if any)
1475 updatePreviewText:function( rObj
){
1478 if(_this
.import_url_mode
=='remote_link'){
1479 _this
.cur_embed_code
= rObj
.pSobj
.getEmbedHTML(rObj
);
1481 _this
.cur_embed_code
= rObj
.pSobj
.getEmbedWikiCode( rObj
);
1484 //insert at start if textInput cursor has not been set (ie == length)
1485 if( _this
.caret_pos
&& _this
.caret_pos
.text
){
1486 if( _this
.caret_pos
.text
.length
== _this
.caret_pos
.s
)
1487 _this
.caret_pos
.s
=0;
1488 _this
.preview_wtext
= _this
.caret_pos
.text
.substring(0, _this
.caret_pos
.s
) +
1489 _this
.cur_embed_code
+
1490 _this
.caret_pos
.text
.substring( _this
.caret_pos
.s
);
1492 _this
.preview_wtext
= $j(_this
.target_textbox
).val() + _this
.cur_embed_code
;
1494 //check for missing </refrences>
1495 if( _this
.preview_wtext
.indexOf('<references/>') ==-1 && _this
.preview_wtext
.indexOf('<ref>') != -1 )
1496 _this
.preview_wtext
= _this
.preview_wtext
+ '<references/>';
1498 getParsedWikiText:function( wikitext
, title
, callback
){
1500 'data':{'action':'parse',
1503 'url':this.local_wiki_api_url
1505 callback( data
.parse
.text
['*'] );
1509 insertResource:function( rObj
){
1510 js_log('insertResource: ' + rObj
.title
);
1512 //dobule check that the resource is present:
1513 this.checkImportResource( rObj
, function(){
1514 _this
.updatePreviewText( rObj
);
1515 $j(_this
.target_textbox
).val( _this
.preview_wtext
);
1517 //update the render area (if present)
1518 if(_this
.target_render_area
&& _this
.cur_embed_code
){
1519 //output with some padding:
1520 $j(_this
.target_render_area
).append( _this
.cur_embed_code
+ '<div style="clear:both;height:10px">')
1521 //update if its video or audio:
1522 if( rObj
.mime
.indexOf('audio')!=-1 ||
1523 rObj
.mime
.indexOf('video')!=-1 ||
1524 rObj
.mime
.indexOf('/ogg') !=-1){
1525 mvJsLoader
.embedVideoCheck(function(){
1533 closeAll:function(){
1535 js_log("close all");
1536 $j('#rsd_resource_preview').remove();
1537 $j('#rsd_resource_edit').remove();
1538 $j(_this
.target_container
).dialog('close');
1540 setResultBarControl:function( ){
1542 var box_dark_url
= mv_skin_img_path
+ 'box_layout_icon_dark.png';
1543 var box_light_url
= mv_skin_img_path
+ 'box_layout_icon.png';
1544 var list_dark_url
= mv_skin_img_path
+ 'list_layout_icon_dark.png';
1545 var list_light_url
= mv_skin_img_path
+ 'list_layout_icon.png';
1548 if( this.content_providers
[this.disp_item
] ){
1549 var cp
= this.content_providers
[this.disp_item
];
1550 about_desc
='<span style="position:relative;top:0px;font-style:italic;">' +
1551 '<i>' + gM('results_from', cp
.homepage
, cp
.title
) + '</i></span>';
1552 $j('#tab-'+this.disp_item
).append( '<div id="rds_results_bar">'+
1553 '<span style="float:left;top:0px;font-style:italic;">'+
1554 gM('rsd_layout')+' '+
1555 '<img id="msc_box_layout" ' +
1556 'title = "' + gM('rsd_box_layout') + '" '+
1557 'src = "' + ( (_this
.result_display_mode
=='box')?box_dark_url
:box_light_url
) + '" ' +
1558 'style="width:20px;height:20px;cursor:pointer;"> ' +
1559 '<img id="msc_list_layout" '+
1560 'title = "' + gM('rsd_list_layout') + '" '+
1561 'src = "' + ( (_this
.result_display_mode
=='list')?list_dark_url
:list_light_url
) + '" '+
1562 'style="width:20px;height:20px;cursor:pointer;">'+
1565 '<span id="rsd_paging_ctrl" style="float:right;"></span>'+
1568 //get paging with bindings:
1569 this.getPaging('#rsd_paging_ctrl');
1571 $j('#msc_box_layout').hover(function(){
1572 $j(this).attr("src", box_dark_url
);
1574 $j(this).attr("src", ( (_this
.result_display_mode
=='box')?box_dark_url
:box_light_url
) );
1575 }).click(function(){
1576 $j(this).attr("src", box_dark_url
);
1577 $j('#msc_list_layout').attr("src", list_light_url
);
1578 _this
.setDispMode('box');
1581 $j('#msc_list_layout').hover(function(){
1582 $j(this).attr("src", list_dark_url
);
1584 $j(this).attr("src", ( (_this
.result_display_mode
=='list')?list_dark_url
:list_light_url
) );
1585 }).click(function(){
1586 $j(this).attr("src", list_dark_url
);
1587 $j('#msc_box_layout').attr("src", box_light_url
);
1588 _this
.setDispMode('list');
1592 getPaging:function(target
){
1594 var cp_id
= this.disp_item
;
1595 var cp
= this.content_providers
[ this.disp_item
];
1596 //js_log('getPaging:'+ cp_id + ' len: ' + cp.sObj.num_results);
1597 var to_num
= ( cp
.limit
> cp
.sObj
.num_results
)?
1598 (cp
.offset
+ cp
.sObj
.num_results
):
1599 (cp
.offset
+ cp
.limit
);
1600 var out
= gM('rsd_results_desc') + ' ' + (cp
.offset
+1) + ' to ' + to_num
;
1601 //check if we have more results (next prev link)
1602 if( cp
.offset
>= cp
.limit
)
1603 out
+=' <a href="#" id="rsd_pprev">' + gM('rsd_results_prev') + ' ' + cp
.limit
+ '</a>';
1605 if( cp
.sObj
.more_results
)
1606 out
+=' <a href="#" id="rsd_pnext">' + gM('rsd_results_next') + ' ' + cp
.limit
+ '</a>';
1608 $j(target
).html(out
);
1610 $j('#rsd_pnext').click(function(){
1611 cp
.offset
+= cp
.limit
;
1614 $j('#rsd_pprev').click(function(){
1615 cp
.offset
-= cp
.limit
;
1624 selectTab:function( selected_cp_id
){
1625 js_log('select tab: ' + selected_cp_id
);
1626 this.disp_item
= selected_cp_id
;
1627 if( this.disp_item
== 'upload' ){
1628 this.doUploadInteface();
1630 //update the search results:
1634 setDispMode:function(mode
){
1635 js_log('setDispMode:' + mode
);
1636 this.result_display_mode
=mode
;
1637 //run /update search display:
1638 this.drawOutputResults();