mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-09-25 03:09:40 +00:00
Merge "A bunch of description fixes"
This commit is contained in:
commit
d245703241
|
@ -88,6 +88,7 @@ $wgResourceModules['ext.multimediaViewer.lightboxinterface'] = array_merge( arra
|
|||
'dependencies' => array(
|
||||
'oojs',
|
||||
'multilightbox.interface',
|
||||
'ext.multimediaViewer.ui.description',
|
||||
),
|
||||
), $moduleInfoMMV );
|
||||
|
||||
|
@ -119,6 +120,27 @@ $wgResourceModules['ext.multimediaViewer.base'] = array_merge( array(
|
|||
),
|
||||
), $moduleInfoMMV );
|
||||
|
||||
$wgResourceModules['ext.multimediaViewer.ui'] = array_merge( array(
|
||||
'scripts' => array(
|
||||
'ext.multimediaViewer.ui.js',
|
||||
),
|
||||
|
||||
'dependencies' => array(
|
||||
'ext.multimediaViewer.base',
|
||||
),
|
||||
), $moduleInfoMMV );
|
||||
|
||||
$wgResourceModules['ext.multimediaViewer.ui.description'] = array_merge( array(
|
||||
'scripts' => array(
|
||||
'ext.multimediaViewer.ui.description.js',
|
||||
),
|
||||
|
||||
'dependencies' => array(
|
||||
'ext.multimediaViewer.ui',
|
||||
'oojs',
|
||||
),
|
||||
), $moduleInfoMMV );
|
||||
|
||||
$wgResourceModules['ext.multimediaViewer'] = array_merge( array(
|
||||
'scripts' => array(
|
||||
'ext.multimediaViewer.js',
|
||||
|
|
|
@ -121,6 +121,7 @@ class MultimediaViewerHooks {
|
|||
'tests/qunit/ext.multimediaViewer.dataModel.test.js',
|
||||
'tests/qunit/ext.multimediaViewer.dataProvider.test.js',
|
||||
'tests/qunit/ext.multimediaViewer.lightboxinterface.test.js',
|
||||
'tests/qunit/ext.multimediaViewer.ui.description.test.js',
|
||||
'tests/qunit/lightboximage.test.js',
|
||||
'tests/qunit/lightboxinterface.test.js',
|
||||
'tests/qunit/multilightbox.test.js',
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"../resources/ext.multimediaViewer/ext.multimediaViewer.js",
|
||||
"../resources/ext.multimediaViewer/ext.multimediaViewer.lightboxinterface.js",
|
||||
"../resources/ext.multimediaViewer/ext.multimediaViewer.lightboximage.js",
|
||||
"../resources/ext.multimediaViewer/ext.multimediaViewer.dataModel.js"
|
||||
"../resources/ext.multimediaViewer/ext.multimediaViewer.dataModel.js",
|
||||
"../resources/ext.multimediaViewer/ext.multimediaViewer.ui.description.js",
|
||||
"../resources/ext.multimediaViewer/ext.multimediaViewer.ui.js"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -277,10 +277,20 @@ body.mobile .mw-mlb-controls,
|
|||
.mw-mlb-title-para,
|
||||
.mw-mlb-credit,
|
||||
.mw-mlb-image-desc,
|
||||
.mw-mlb-description-backup,
|
||||
.mw-mlb-mmv-about-links {
|
||||
padding-left: 20px;
|
||||
}
|
||||
|
||||
.mw-mlb-image-desc-div.empty .mw-mlb-image-desc {
|
||||
color: rgb(136, 136, 136);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.mw-mlb-description-backup.empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mw-mlb-mmv-about-links {
|
||||
font-size: 0.8em;
|
||||
padding: 20px;
|
||||
|
|
|
@ -208,36 +208,8 @@
|
|||
|
||||
MMVP = MultimediaViewer.prototype;
|
||||
|
||||
/**
|
||||
* Helper function for whitelisting HTML to only keep links and text. Works in-place.
|
||||
* @param {jQuery} $el
|
||||
*/
|
||||
MMVP.whitelistHtml = function ( $el ) {
|
||||
var child, $prev, $child = $el.children().first();
|
||||
|
||||
while ( $child && $child.length ) {
|
||||
child = $child.get( 0 );
|
||||
|
||||
if ( child.nodeType !== child.ELEMENT_NODE ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.whitelistHtml( $child );
|
||||
|
||||
if ( !$child.is( 'a' ) ) {
|
||||
$prev = $child.prev();
|
||||
$child.replaceWith( $child.contents() );
|
||||
} else {
|
||||
$prev = $child;
|
||||
}
|
||||
|
||||
if ( $prev && $prev.length === 1 ) {
|
||||
$child = $prev.next();
|
||||
} else {
|
||||
$child = $el.children().first();
|
||||
}
|
||||
}
|
||||
};
|
||||
// TODO FIXME HACK delete this when other UI elements have been shifted away.
|
||||
MMVP.whitelistHtml = mw.mmv.ui.Element.prototype.whitelistHtml;
|
||||
|
||||
/**
|
||||
* Create an image object for the lightbox to use.
|
||||
|
@ -542,14 +514,6 @@
|
|||
|
||||
ui.$datetimeLi.toggleClass( 'empty', !imageData.uploadDateTime && !imageData.creationDateTime );
|
||||
|
||||
if ( imageData.description ) {
|
||||
this.whitelistHtml( ui.$imageDesc.empty().append( $.parseHTML( imageData.description ) ) );
|
||||
} else {
|
||||
ui.$imageDesc.append( mw.message( 'multimediaviewer-desc-nil' ).text() );
|
||||
}
|
||||
|
||||
ui.$imageDescDiv.toggleClass( 'empty', !imageData.description );
|
||||
|
||||
if ( imageData.source ) {
|
||||
this.whitelistHtml( ui.$source.empty().append( $.parseHTML( imageData.source ) ) );
|
||||
}
|
||||
|
@ -577,17 +541,7 @@
|
|||
|
||||
ui.$credit.toggleClass( 'empty', !imageData.source && !imageData.author );
|
||||
|
||||
ui.$imageDescDiv.toggleClass( 'empty', !imageData.description && !caption );
|
||||
|
||||
if ( caption ) {
|
||||
this.whitelistHtml( ui.$imageDesc.append( $.parseHTML( caption ) ) );
|
||||
|
||||
if ( imageData.description ) {
|
||||
this.whitelistHtml( ui.$imageBackupDesc.append( $.parseHTML( imageData.description ) ) );
|
||||
}
|
||||
} else if ( imageData.description ) {
|
||||
this.whitelistHtml( ui.$imageDesc.append( $.parseHTML( imageData.description ) ) );
|
||||
}
|
||||
ui.description.set( imageData.description, caption );
|
||||
|
||||
msgname = 'multimediaviewer-license-' + ( imageData.license || '' );
|
||||
|
||||
|
|
|
@ -41,9 +41,8 @@
|
|||
|
||||
this.$license.empty().addClass( 'empty' );
|
||||
|
||||
this.$imageDesc.empty();
|
||||
this.$imageDescDiv.addClass( 'empty' );
|
||||
this.$imageBackupDesc.empty();
|
||||
this.description.empty();
|
||||
|
||||
this.$title.empty();
|
||||
this.$credit.empty().addClass( 'empty' );
|
||||
|
||||
|
@ -248,13 +247,7 @@
|
|||
};
|
||||
|
||||
LIP.initializeImageDesc = function () {
|
||||
this.$imageDescDiv = $( '<div>' )
|
||||
.addClass( 'mw-mlb-image-desc-div empty' )
|
||||
.appendTo( this.$imageMetadata );
|
||||
|
||||
this.$imageDesc = $( '<p>' )
|
||||
.addClass( 'mw-mlb-image-desc' )
|
||||
.appendTo( this.$imageDescDiv );
|
||||
this.description = new mw.mmv.ui.Description( this.$imageMetadata );
|
||||
};
|
||||
|
||||
LIP.initializeImageLinks = function () {
|
||||
|
@ -266,10 +259,6 @@
|
|||
.addClass( 'mw-mlb-image-links' )
|
||||
.appendTo( this.$imageLinkDiv );
|
||||
|
||||
this.$imageBackupDesc = $( '<p>' )
|
||||
.addClass( 'mw-mlb-description-backup' )
|
||||
.appendTo( this.$imageLinkDiv );
|
||||
|
||||
this.initializeRepoLink();
|
||||
this.initializeDatetime();
|
||||
this.initializeUploader();
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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 ) {
|
||||
/**
|
||||
* @class mw.mmv.ui.Description
|
||||
* @extends mw.mmv.ui.Element
|
||||
* @constructor
|
||||
* @inheritdoc
|
||||
*/
|
||||
function Description( $container ) {
|
||||
mw.mmv.ui.Element.call( this, $container );
|
||||
|
||||
this.$imageDescDiv = $( '<div>' )
|
||||
.addClass( 'mw-mlb-image-desc-div empty' )
|
||||
.appendTo( this.$container );
|
||||
|
||||
this.$imageDesc = $( '<p>' )
|
||||
.addClass( 'mw-mlb-image-desc' )
|
||||
.appendTo( this.$imageDescDiv );
|
||||
|
||||
this.$imageCaption = $( '<p>' )
|
||||
.addClass( 'mw-mlb-description-backup empty' )
|
||||
.appendTo( this.$imageDescDiv );
|
||||
}
|
||||
|
||||
oo.inheritClass( Description, mw.mmv.ui.Element );
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @inheritdoc
|
||||
* @param {string} text The text of the description
|
||||
* @param {string} [caption] The text of the caption
|
||||
*/
|
||||
Description.prototype.set = function ( text, caption ) {
|
||||
this.$imageDescDiv.toggleClass( 'empty', !text && !caption );
|
||||
this.$imageCaption.toggleClass( 'empty', !caption );
|
||||
this.$imageDesc.toggleClass( 'empty', !text );
|
||||
|
||||
if ( caption ) {
|
||||
this.whitelistHtml( this.$imageCaption.empty().append( $.parseHTML( caption ) ) );
|
||||
}
|
||||
|
||||
if ( text ) {
|
||||
this.whitelistHtml( this.$imageDesc.empty().append( $.parseHTML( text ) ) );
|
||||
} else {
|
||||
this.$imageDesc.empty().append( mw.message( 'multimediaviewer-desc-nil' ).text() );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @inheritdoc
|
||||
*/
|
||||
Description.prototype.empty = function () {
|
||||
this.$imageDesc.empty();
|
||||
this.$imageDescDiv.addClass( 'empty' );
|
||||
this.$imageCaption.empty().addClass( 'empty' );
|
||||
};
|
||||
|
||||
mw.mmv.ui.Description = Description;
|
||||
}( mediaWiki, jQuery, OO ) );
|
79
resources/ext.multimediaViewer/ext.multimediaViewer.ui.js
Normal file
79
resources/ext.multimediaViewer/ext.multimediaViewer.ui.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* 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 ) {
|
||||
/**
|
||||
* @class mw.mmv.ui.Element
|
||||
* @abstract
|
||||
* Represents a UI element.
|
||||
* @constructor
|
||||
* @param {jQuery} $container
|
||||
*/
|
||||
function Element( $container ) {
|
||||
/** @property {jQuery} $container The element that contains the UI element. */
|
||||
this.$container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method
|
||||
* Helper function for whitelisting HTML to only keep links and text. Works in-place.
|
||||
* @param {jQuery} $el
|
||||
*/
|
||||
Element.prototype.whitelistHtml = function ( $el ) {
|
||||
var child, $prev, $child = $el.children().first();
|
||||
|
||||
while ( $child && $child.length ) {
|
||||
child = $child.get( 0 );
|
||||
|
||||
if ( child.nodeType !== child.ELEMENT_NODE ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.whitelistHtml( $child );
|
||||
|
||||
if ( !$child.is( 'a' ) ) {
|
||||
$prev = $child.prev();
|
||||
$child.replaceWith( $child.contents() );
|
||||
} else {
|
||||
$prev = $child;
|
||||
}
|
||||
|
||||
if ( $prev && $prev.length === 1 ) {
|
||||
$child = $prev.next();
|
||||
} else {
|
||||
$child = $el.children().first();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @abstract
|
||||
* Sets the data for the element.
|
||||
*/
|
||||
Element.prototype.set = function () {};
|
||||
|
||||
/**
|
||||
* @method
|
||||
* @abstract
|
||||
* Empties the element.
|
||||
*/
|
||||
Element.prototype.empty = function () {};
|
||||
|
||||
mw.mmv.ui = {};
|
||||
mw.mmv.ui.Element = Element;
|
||||
}( mediaWiki ) );
|
|
@ -1,19 +1,16 @@
|
|||
( function ( mw, $ ) {
|
||||
var thingsShouldBeEmptied = [
|
||||
'$license',
|
||||
'$imageDesc',
|
||||
'$title',
|
||||
'$credit',
|
||||
'$username',
|
||||
'$location',
|
||||
'$repo',
|
||||
'$datetime',
|
||||
'$imageBackupDesc'
|
||||
'$datetime'
|
||||
],
|
||||
|
||||
thingsShouldHaveEmptyClass = [
|
||||
'$license',
|
||||
'$imageDescDiv',
|
||||
'$credit',
|
||||
'$usernameLi',
|
||||
'$locationLi',
|
||||
|
|
40
tests/qunit/ext.multimediaViewer.ui.description.test.js
Normal file
40
tests/qunit/ext.multimediaViewer.ui.description.test.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
( function ( mw, $ ) {
|
||||
QUnit.module( 'ext.multimediaViewer.ui.description', QUnit.newMwEnvironment() );
|
||||
|
||||
QUnit.test( 'Sanity test, object creation and UI construction', 4, function ( assert ) {
|
||||
var description = new mw.mmv.ui.Description( $( '#qunit-fixture' ) );
|
||||
|
||||
assert.ok( description, 'Image description UI element is created' );
|
||||
assert.strictEqual( description.$imageDescDiv.length, 1, 'Image description div is created' );
|
||||
assert.strictEqual( description.$imageDesc.length, 1, 'Image description element is created' );
|
||||
assert.strictEqual( description.$imageCaption.length, 1, 'Image caption div is created' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Setting data in different combinations works well', 7, function ( assert ) {
|
||||
var description = new mw.mmv.ui.Description( $( '#qunit-fixture' ) );
|
||||
|
||||
description.set( '' );
|
||||
assert.strictEqual( description.$imageDescDiv.hasClass( 'empty' ), true, 'Image description div is marked empty when needed' );
|
||||
|
||||
description.set( 'blah' );
|
||||
assert.strictEqual( description.$imageDescDiv.hasClass( 'empty' ), false, 'Image description div is not marked empty incorrectly' );
|
||||
assert.strictEqual( description.$imageDesc.text(), 'blah', 'Image description text is set correctly' );
|
||||
assert.strictEqual( description.$imageCaption.hasClass( 'empty' ), true, 'Image caption is empty when not set' );
|
||||
|
||||
description.set( 'foo', 'bar' );
|
||||
assert.strictEqual( description.$imageDescDiv.hasClass( 'empty' ), false, 'Image description div is not marked empty incorrectly' );
|
||||
assert.strictEqual( description.$imageCaption.text(), 'bar', 'Image caption text is set correctly' );
|
||||
assert.strictEqual( description.$imageCaption.hasClass( 'empty' ), false, 'Image caption is not marked empty when set' );
|
||||
} );
|
||||
|
||||
QUnit.test( 'Emptying data works as expected', 4, function ( assert ) {
|
||||
var description = new mw.mmv.ui.Description( $( '#qunit-fixture' ) );
|
||||
|
||||
description.set( 'foo', 'bar' );
|
||||
description.empty();
|
||||
assert.strictEqual( description.$imageDescDiv.hasClass( 'empty' ), true, 'Image description div is marked empty when emptied' );
|
||||
assert.strictEqual( description.$imageCaption.hasClass( 'empty' ), true, 'Image caption is marked empty when emptied' );
|
||||
assert.strictEqual( description.$imageDesc.text(), '', 'Image description text is emptied correctly' );
|
||||
assert.strictEqual( description.$imageCaption.text(), '', 'Image caption text is emptied correctly' );
|
||||
} );
|
||||
}( mediaWiki, jQuery ) );
|
Loading…
Reference in a new issue