2014-03-17 08:07:53 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the MediaWiki extension MultimediaViewer.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MultimediaViewer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
( function ( mw, $, oo ) {
|
|
|
|
// Shortcut for prototype later
|
|
|
|
var SP;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents the file reuse dialog and link to open it.
|
|
|
|
* @class mw.mmv.ui.reuse.Share
|
|
|
|
* @extends mw.mmv.ui.reuse.Tab
|
|
|
|
* @param {jQuery} $container
|
|
|
|
*/
|
|
|
|
function Share( $container ) {
|
2014-04-07 17:37:42 +00:00
|
|
|
Share['super'].call( this, $container );
|
2014-03-17 08:07:53 +00:00
|
|
|
|
2014-04-14 23:22:28 +00:00
|
|
|
/**
|
|
|
|
* @property {mw.mmv.routing.Router} router -
|
|
|
|
*/
|
|
|
|
this.router = new mw.mmv.routing.Router();
|
|
|
|
|
2014-03-17 08:07:53 +00:00
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
oo.inheritClass( Share, mw.mmv.ui.reuse.Tab );
|
|
|
|
SP = Share.prototype;
|
|
|
|
|
|
|
|
SP.init = function () {
|
2014-06-04 21:12:52 +00:00
|
|
|
this.$pane.addClass( 'mw-mmv-share-pane' )
|
2014-03-17 08:07:53 +00:00
|
|
|
.appendTo( this.$container );
|
|
|
|
|
|
|
|
this.pageInput = new oo.ui.TextInputWidget( {
|
2014-03-31 21:33:12 +00:00
|
|
|
classes: [ 'mw-mmv-share-page' ],
|
2014-03-17 08:07:53 +00:00
|
|
|
readOnly: true
|
|
|
|
} );
|
|
|
|
|
2014-03-19 22:35:55 +00:00
|
|
|
this.pageInput.$element.find( 'input' )
|
|
|
|
.prop( 'placeholder', mw.message( 'multimediaviewer-reuse-loading-placeholder' ).text() );
|
|
|
|
|
2014-03-17 08:07:53 +00:00
|
|
|
this.$pageLink = $( '<a>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-share-page-link' )
|
2014-03-17 08:07:53 +00:00
|
|
|
.prop( 'alt', mw.message( 'multimediaviewer-link-to-page' ).text() )
|
|
|
|
.prop( 'target', '_blank' )
|
|
|
|
.html( ' ' )
|
|
|
|
.appendTo( this.$pane );
|
|
|
|
|
|
|
|
this.pageInput.$element.appendTo( this.$pane );
|
|
|
|
|
2014-03-26 13:34:44 +00:00
|
|
|
this.$explanation = $( '<div>' )
|
2014-03-31 21:33:12 +00:00
|
|
|
.addClass( 'mw-mmv-shareembed-explanation' )
|
2014-03-26 13:34:44 +00:00
|
|
|
.text( mw.message( 'multimediaviewer-share-explanation' ).text() )
|
|
|
|
.appendTo( this.$pane );
|
|
|
|
|
2014-03-17 08:07:53 +00:00
|
|
|
this.$pane.appendTo( this.$container );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows the pane.
|
|
|
|
*/
|
|
|
|
SP.show = function () {
|
2014-04-07 17:37:42 +00:00
|
|
|
this.constructor['super'].prototype.show.call( this );
|
2014-03-19 22:35:55 +00:00
|
|
|
this.select();
|
2014-03-17 08:07:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
* @param {mw.mmv.model.Image} image
|
|
|
|
*/
|
|
|
|
SP.set = function ( image ) {
|
2014-04-14 23:22:28 +00:00
|
|
|
var route = new mw.mmv.routing.ThumbnailRoute( image.title ),
|
|
|
|
url = this.router.createHashedUrl( route, image.descriptionUrl );
|
|
|
|
|
2014-03-17 08:07:53 +00:00
|
|
|
this.pageInput.setValue( url );
|
2014-03-19 22:35:55 +00:00
|
|
|
|
|
|
|
this.select();
|
|
|
|
|
2014-03-17 08:07:53 +00:00
|
|
|
this.$pageLink.prop( 'href', url );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
SP.empty = function () {
|
|
|
|
this.pageInput.setValue( '' );
|
|
|
|
this.$pageLink.prop( 'href', null );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
SP.attach = function() {
|
|
|
|
var $input = this.pageInput.$element.find( 'input' );
|
|
|
|
|
2014-05-21 21:41:39 +00:00
|
|
|
$input.on( 'focus', this.selectAllOnEvent );
|
2014-03-19 22:35:55 +00:00
|
|
|
// Disable partial text selection inside the textbox
|
2014-05-21 21:41:39 +00:00
|
|
|
$input.on( 'mousedown click', this.onlyFocus );
|
2014-03-17 08:07:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
SP.unattach = function() {
|
2014-05-21 21:41:39 +00:00
|
|
|
var $input = this.pageInput.$element.find( 'input' );
|
|
|
|
|
2014-04-07 17:37:42 +00:00
|
|
|
this.constructor['super'].prototype.unattach.call( this );
|
2014-03-17 08:07:53 +00:00
|
|
|
|
2014-05-21 21:41:39 +00:00
|
|
|
$input.off( 'focus mousedown click' );
|
2014-03-17 08:07:53 +00:00
|
|
|
};
|
|
|
|
|
2014-03-19 22:35:55 +00:00
|
|
|
/**
|
|
|
|
* Selects the text in the readonly textbox by triggering a focus event.
|
|
|
|
*/
|
|
|
|
SP.select = function () {
|
|
|
|
this.pageInput.$element.focus();
|
|
|
|
};
|
|
|
|
|
2014-03-17 08:07:53 +00:00
|
|
|
|
|
|
|
mw.mmv.ui.reuse.Share = Share;
|
|
|
|
}( mediaWiki, jQuery, OO ) );
|