2013-11-13 23:01:16 +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/>.
|
|
|
|
*/
|
|
|
|
|
2014-02-25 01:54:05 +00:00
|
|
|
( function ( mw, $ ) {
|
|
|
|
|
2013-12-10 19:54:07 +00:00
|
|
|
/**
|
2014-02-19 02:27:30 +00:00
|
|
|
* Represents an image on the page.
|
2014-02-25 02:28:49 +00:00
|
|
|
* @class mw.mmv.LightboxImage
|
2013-12-10 19:54:07 +00:00
|
|
|
* @constructor
|
|
|
|
* @param {string} fileLink Link to the file - generally a thumb URL
|
|
|
|
* @param {string} filePageLink Link to the File: page
|
|
|
|
* @param {mw.Title} fileTitle Represents the File: page
|
|
|
|
* @param {number} index Which number file this is
|
|
|
|
* @param {HTMLImageElement} thumb The thumbnail that represents this image on the page
|
|
|
|
* @param {string} [caption] The caption, if any.
|
|
|
|
*/
|
|
|
|
function LightboxImage( fileLink, filePageLink, fileTitle, index, thumb, caption ) {
|
2014-02-25 01:54:05 +00:00
|
|
|
/** @property {string} Link to the file - generally a thumb URL */
|
|
|
|
this.src = fileLink;
|
2013-12-10 19:54:07 +00:00
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} filePageLink URL to the image's file page */
|
2013-12-10 19:54:07 +00:00
|
|
|
this.filePageLink = filePageLink;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {mw.Title} filePageTitle Title of the image's file page */
|
2013-12-10 19:54:07 +00:00
|
|
|
this.filePageTitle = fileTitle;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {number} index What number this image is in the array of indexed images */
|
2013-12-10 19:54:07 +00:00
|
|
|
this.index = index;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {HTMLImageElement} thumbnail The <img> element that holds the already-loaded thumbnail of the image*/
|
2013-12-10 19:54:07 +00:00
|
|
|
this.thumbnail = thumb;
|
|
|
|
|
2014-01-22 00:22:43 +00:00
|
|
|
/** @property {string} caption The caption of the image, if any */
|
2013-12-10 19:54:07 +00:00
|
|
|
this.caption = caption;
|
2013-11-13 23:01:16 +00:00
|
|
|
}
|
|
|
|
|
2014-02-25 01:54:05 +00:00
|
|
|
var LIP = LightboxImage.prototype;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The URL of the image (in the size we intend use to display the it in the lightbox)
|
|
|
|
* @type {String}
|
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
LIP.src = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The URL of a placeholder while the image loads. Typically a smaller version of the image, which is already
|
|
|
|
* loaded in the browser.
|
|
|
|
* @type {String}
|
2014-02-25 02:28:49 +00:00
|
|
|
* @return {jQuery.Promise.<mw.mmv.LightboxImage, HTMLImageElement>}
|
2014-02-25 01:54:05 +00:00
|
|
|
* @protected
|
|
|
|
*/
|
|
|
|
LIP.initialSrc = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the image.
|
|
|
|
* FIXME we probably don't use this.
|
|
|
|
* @return {jQuery.Promise.<HTMLImageElement>}
|
|
|
|
*/
|
|
|
|
LIP.getImageElement = function () {
|
|
|
|
var ele,
|
|
|
|
$deferred = $.Deferred(),
|
|
|
|
image = this;
|
|
|
|
|
|
|
|
ele = new Image();
|
|
|
|
ele.addEventListener( 'error', $deferred.reject );
|
|
|
|
ele.addEventListener( 'load', function() { $deferred.resolve( image, ele ); } );
|
|
|
|
|
|
|
|
if ( this.src !== this.initialSrc ) {
|
|
|
|
ele.src = this.src;
|
|
|
|
} else {
|
|
|
|
// Don't display the thumb, pretend that we did load the image
|
|
|
|
// This is a workaround until we decide whether we want to display a nicer version of the thumb or not
|
|
|
|
$deferred.resolve( image, ele );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $deferred;
|
|
|
|
};
|
|
|
|
|
2014-02-25 02:28:49 +00:00
|
|
|
mw.mmv.LightboxImage = LightboxImage;
|
2014-02-25 01:54:05 +00:00
|
|
|
}( mediaWiki, jQuery ) );
|