| 1 | /* |
| 2 | * This file is part of the MediaWiki extension MultimediaViewer. |
| 3 | * |
| 4 | * MultimediaViewer is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation, either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * MultimediaViewer is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with MultimediaViewer. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * Represents image width information. |
| 20 | * |
| 21 | * To utilize caching as much as possible, we use images which are displayed at a slightly |
| 22 | * different size than their screen size. The ThumbnailWidth model stores the various types of |
| 23 | * sizes and helps avoiding accidental incompatible assignments. (Think of it as a slightly |
| 24 | * overcomplicated Hungarian notation) |
| 25 | */ |
| 26 | class ThumbnailWidth { |
| 27 | /** |
| 28 | * @param {number} cssWidth width in CSS pixels |
| 29 | * @param {number} cssHeight height in CSS pixels |
| 30 | * @param {number} screen width in screen pixels |
| 31 | * @param {number} real width in real pixels |
| 32 | */ |
| 33 | constructor( cssWidth, cssHeight, screen, real ) { |
| 34 | if ( !cssWidth || !cssHeight || !screen || !real ) { |
| 35 | throw new Error( 'All parameters are required and cannot be empty or zero' ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Width of the thumbnail on the screen, in CSS pixels. This is the number which can be plugged |
| 40 | * into UI code like $element.width(x). |
| 41 | * |
| 42 | * @property {number} |
| 43 | */ |
| 44 | this.cssWidth = cssWidth; |
| 45 | |
| 46 | /** |
| 47 | * Height of the thumbnail on the screen, in CSS pixels. This is the number which can be plugged |
| 48 | * into UI code like $element.height(x). |
| 49 | * |
| 50 | * @property {number} |
| 51 | */ |
| 52 | this.cssHeight = cssHeight; |
| 53 | |
| 54 | /** |
| 55 | * Width of the thumbnail on the screen, in device pixels. On most devices this is the same as |
| 56 | * the CSS width, but devices with high pixel density displays have multiple screen pixels |
| 57 | * in a CSS pixel. |
| 58 | * |
| 59 | * This value is mostly used internally; for most purposes you will need one of the others. |
| 60 | * |
| 61 | * @property {number} |
| 62 | */ |
| 63 | this.screen = screen; |
| 64 | |
| 65 | /** |
| 66 | * "Real" width of the thumbnail. This is the number you need to use in API requests when |
| 67 | * obtaining the thumbnail URL. This is usually larger than the screen width, since |
| 68 | * downscaling images via CSS looks OK but upscaling them looks ugly. However, for images |
| 69 | * where the full size itself is very small, this can be smaller than the screen width, since |
| 70 | * we cannot create a thumbnail which is larger than the original image. (In such cases the |
| 71 | * image is just positioned to the center of the intended area and the space around it is |
| 72 | * left empty.) |
| 73 | * |
| 74 | * @property {number} |
| 75 | */ |
| 76 | this.real = real; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | module.exports = ThumbnailWidth; |