MarkTraceur has uploaded a new change for review.
https://gerrit.wikimedia.org/r/86777
Change subject: jshint fixes for mw.UploadWizardDeed.js
......................................................................
jshint fixes for mw.UploadWizardDeed.js
Bug: 47161
Change-Id: I66a32316613a0779a7ca3a5b77698cacca1ba11f
---
M resources/mw.UploadWizardDeed.js
1 file changed, 115 insertions(+), 123 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard
refs/changes/77/86777/1
diff --git a/resources/mw.UploadWizardDeed.js b/resources/mw.UploadWizardDeed.js
index f82959a..b9e3c6c 100644
--- a/resources/mw.UploadWizardDeed.js
+++ b/resources/mw.UploadWizardDeed.js
@@ -29,7 +29,6 @@
}
mw.UploadWizardDeed = function() {
- var _this = this;
// prevent from instantiating directly?
return false;
};
@@ -67,28 +66,29 @@
mw.UploadWizardDeedOwnWork = function( uploadCount, api ) {
uploadCount = uploadCount ? uploadCount : 1;
- var _this = new mw.UploadWizardDeed();
+ var licenseInputDiv,
+ deed = new mw.UploadWizardDeed(),
+ ownWork = mw.UploadWizard.config.licensing.ownWork;
- _this.authorInput = $( '<input type="text" />' )
- .attr( { name: "author" } )
+ deed.authorInput = $( '<input type="text" />' )
+ .attr( { name: 'author' } )
.addClass( 'mwe-upwiz-sign' );
- var ownWork = mw.UploadWizard.config.licensing.ownWork;
- _this.showCustomDiv = ownWork.licenses.length > 1;
+ deed.showCustomDiv = ownWork.licenses.length > 1;
- if ( _this.showCustomDiv ) {
- var licenseInputDiv = $( '<div
class="mwe-upwiz-deed-license"></div>' );
+ if ( deed.showCustomDiv ) {
+ licenseInputDiv = $( '<div
class="mwe-upwiz-deed-license"></div>' );
- _this.licenseInput = new mw.UploadWizardLicenseInput(
+ deed.licenseInput = new mw.UploadWizardLicenseInput(
licenseInputDiv,
undefined,
mw.UploadWizard.config.licensing.ownWork,
- _this.uploadCount,
+ deed.uploadCount,
api
);
}
- return $.extend( _this, {
+ return $.extend( deed, {
name: 'ownwork',
@@ -99,13 +99,13 @@
valid: function() {
// n.b. valid() has side effects and both should be
called every time the function is called.
// do not short-circuit.
- var formValid = _this.$form.valid();
- var licenseInputValid = !_this.showCustomDiv ||
_this.licenseInput.valid();
+ var formValid = this.$form.valid(),
+ licenseInputValid = !this.showCustomDiv ||
this.licenseInput.valid();
return formValid && licenseInputValid;
},
getLicenseWikiText: function() {
- var defaultLicense;
+ var defaultLicense,
defaultType =
mw.UploadWizard.config.licensing.defaultType;
if ( defaultType === 'ownwork' ) {
@@ -114,7 +114,7 @@
defaultLicense =
mw.UploadWizard.config.licensing.ownWork.licenses[0];
}
- if ( _this.showCustomDiv &&
this.licenseInput.getWikiText() !== '' ) {
+ if ( this.showCustomDiv &&
this.licenseInput.getWikiText() !== '' ) {
return this.licenseInput.getWikiText();
}
else {
@@ -133,10 +133,10 @@
// XXX do we need to escape authorInput, or is wikitext a
feature here?
// what about scripts?
getAuthorWikiText: function() {
- var author = $( _this.authorInput ).val();
+ var author = $( this.authorInput ).val();
if ( author === '' ) {
- author = _this.$authorInput2.val();
+ author = this.$authorInput2.val();
}
if ( author.indexOf( '[' ) >= 0 || author.indexOf( '{'
) >= 0 ) {
@@ -148,14 +148,12 @@
setFormFields: function( $selector ) {
- _this.$selector = $selector;
- var languageCode = mw.config.get( 'wgUserLanguage' );
-
- _this.$form = $( '<form />' );
-
- _this.$authorInput2 = $( '<input type="text" />'
).attr( { name: "author2" } ).addClass( 'mwe-upwiz-sign' );
-
- var defaultLicense,
+ this.$selector = $selector;
+ var $customDiv, $formFields, $toggler, rules, messages,
defaultLicense,
+ defaultLicenseURL, defaultLicenseMsg,
defaultLicenseExplainMsg,
+ defaultLicenseLink, $standardDiv, $crossfader,
+ thisDeed = this,
+ languageCode = mw.config.get( 'wgUserLanguage'
),
defaultType =
mw.UploadWizard.config.licensing.defaultType;
if ( defaultType === 'ownwork' ) {
@@ -164,20 +162,18 @@
defaultLicense =
mw.UploadWizard.config.licensing.ownWork.licenses[0];
}
- var defaultLicenseURL =
mw.UploadWizard.config.licenses[defaultLicense].url === undefined ?
- '#missing license URL' :
-
mw.UploadWizard.config.licenses[defaultLicense].url + 'deed.' + languageCode;
-
- var defaultLicenseMsg =
'mwe-upwiz-source-ownwork-assert-' + defaultLicense;
- var defaultLicenseExplainMsg =
'mwe-upwiz-source-ownwork-' + defaultLicense + '-explain';
- var defaultLicenseLink = $( '<a>' ).attr( { 'target':
'_blank', 'href': defaultLicenseURL } );
-
- var $standardDiv = $( '<div />' ).append(
+ defaultLicenseURL =
mw.UploadWizard.config.licenses[defaultLicense].url === undefined ?
+ '#missing license URL' :
+
mw.UploadWizard.config.licenses[defaultLicense].url + 'deed.' + languageCode;
+ defaultLicenseMsg = 'mwe-upwiz-source-ownwork-assert-'
+ defaultLicense;
+ defaultLicenseExplainMsg = 'mwe-upwiz-source-ownwork-'
+ defaultLicense + '-explain';
+ defaultLicenseLink = $( '<a>' ).attr( { 'target':
'_blank', 'href': defaultLicenseURL } );
+ $standardDiv = $( '<div />' ).append(
$( '<label for="author2" generated="true"
class="mwe-validator-error" style="display:block;" />' ),
$( '<p></p>' ).msg(
defaultLicenseMsg,
uploadCount,
- _this.$authorInput2,
+ this.$authorInput2,
defaultLicenseLink
),
$( '<p class="mwe-small-print"></p>' ).msg(
@@ -185,31 +181,34 @@
uploadCount
)
);
+ $crossfader = $( '<div />' ).append( $standardDiv );
- var $crossfader = $( '<div />' ).append( $standardDiv );
- if ( _this.showCustomDiv ) {
- var $customDiv = $('<div />').append(
+ this.$form = $( '<form />' );
+ this.$authorInput2 = $( '<input type="text" />' ).attr(
{ name: 'author2' } ).addClass( 'mwe-upwiz-sign' );
+
+ if ( this.showCustomDiv ) {
+ $customDiv = $('<div />').append(
$( '<label for="author"
generated="true" class="mwe-validator-error" style="display:block;" />' ),
$( '<p></p>' ).msg(
'mwe-upwiz-source-ownwork-assert-custom',
uploadCount,
- _this.authorInput ),
+ this.authorInput ),
licenseInputDiv
);
$crossfader.append( $customDiv );
}
- var $formFields = $( '<div
class="mwe-upwiz-deed-form-internal" />' )
+ $formFields = $( '<div
class="mwe-upwiz-deed-form-internal" />' )
.append( $crossfader );
- var $toggler = $( '<p class="mwe-more-options"
style="text-align: right"></p>' )
+ $toggler = $( '<p class="mwe-more-options"
style="text-align: right"></p>' )
.append( $( '<a />' )
.msg( 'mwe-upwiz-license-show-all' )
.click( function() {
- _this.formValidator.resetForm();
+
thisDeed.formValidator.resetForm();
if ( $crossfader.data(
'crossfadeDisplay' ).get(0) === $customDiv.get(0) ) {
-
_this.licenseInput.setDefaultValues();
+
thisDeed.licenseInput.setDefaultValues();
$crossfader.morphCrossfade( $standardDiv );
$( this ).msg(
'mwe-upwiz-license-show-all' );
} else {
@@ -218,7 +217,7 @@
}
} ) );
- if ( _this.showCustomDiv ) {
+ if ( this.showCustomDiv ) {
$formFields.append( $toggler );
}
@@ -231,8 +230,8 @@
value: mw.config.get( 'wgUserName' )
} )
.keyup( function() {
- var thisInput = this;
- var thisVal = $( thisInput ).val();
+ var thisInput = this,
+ thisVal = $( thisInput ).val();
$.each( $formFields.find(
'.mwe-upwiz-sign' ), function( i, input ) {
if (thisInput !== input) {
$( input ).val( thisVal
);
@@ -240,15 +239,15 @@
} );
} );
- _this.$form.append( $formFields );
- $selector.append( _this.$form );
+ this.$form.append( $formFields );
+ $selector.append( this.$form );
// done after added to the DOM, so there are true
heights
$crossfader.morphCrossfader();
- var rules = {
+ rules = {
author2: {
- required: function( element ) {
+ required: function() {
return $crossfader.data(
'crossfadeDisplay' ).get(0) === $standardDiv.get(0);
},
minlength:
mw.UploadWizard.config.minAuthorLength,
@@ -256,7 +255,7 @@
}
};
- var messages = {
+ messages = {
author2: {
required: mw.message(
'mwe-upwiz-error-signature-blank' ).escaped(),
minlength: mw.message(
'mwe-upwiz-error-signature-too-short', mw.UploadWizard.config.minAuthorLength
).escaped(),
@@ -264,12 +263,12 @@
}
};
- if ( _this.showCustomDiv ) {
+ if ( this.showCustomDiv ) {
// choose default licenses
- _this.licenseInput.setDefaultValues();
+ this.licenseInput.setDefaultValues();
rules.author = {
- required: function( element ) {
+ required: function() {
return $crossfader.data(
'crossfadeDisplay' ).get(0) === $customDiv.get(0);
},
minlength:
mw.UploadWizard.config.minAuthorLength,
@@ -284,7 +283,7 @@
}
// and finally, make it validatable
- _this.formValidator = _this.$form.validate( {
+ this.formValidator = this.$form.validate( {
rules: rules,
messages: messages
} );
@@ -296,10 +295,7 @@
}
} );
}
-
-
} );
-
};
/**
@@ -308,38 +304,36 @@
* @param {mw.Api} api object - useful for doing previews
*/
mw.UploadWizardDeedThirdParty = function( uploadCount, api ) {
- var _this, licenseInputDiv;
+ var licenseInputDiv,
+ deed = new mw.UploadWizardDeed();
- _this = new mw.UploadWizardDeed();
-
- _this.uploadCount = uploadCount ? uploadCount : 1;
- _this.sourceInput = $('<textarea class="mwe-source mwe-long-textarea"
name="source" rows="1" cols="40"></textarea>' )
+ deed.uploadCount = uploadCount ? uploadCount : 1;
+ deed.sourceInput = $('<textarea class="mwe-source mwe-long-textarea"
name="source" rows="1" cols="40"></textarea>' )
.growTextArea();
- _this.authorInput = $('<textarea class="mwe-author mwe-long-textarea"
name="author" rows="1" cols="40"></textarea>' )
+ deed.authorInput = $('<textarea class="mwe-author mwe-long-textarea"
name="author" rows="1" cols="40"></textarea>' )
.growTextArea();
licenseInputDiv = $( '<div
class="mwe-upwiz-deed-license-groups"></div>' );
- _this.licenseInput = new mw.UploadWizardLicenseInput(
+ deed.licenseInput = new mw.UploadWizardLicenseInput(
licenseInputDiv,
undefined,
mw.UploadWizard.config.licensing.thirdParty,
- _this.uploadCount,
+ deed.uploadCount,
api
);
- _this.licenseInput.setDefaultValues();
+ deed.licenseInput.setDefaultValues();
-
- return $.extend( _this, mw.UploadWizardDeed.prototype, {
+ return $.extend( deed, mw.UploadWizardDeed.prototype, {
name: 'thirdparty',
setFormFields: function( $selector ) {
var $defaultLicense, defaultLicense, defaultLicenseNum,
defaultType,
- _this = this;
- _this.$form = $( '<form />' );
+ $formFields = $( '<div
class="mwe-upwiz-deed-form-internal" />' );
+
+ this.$form = $( '<form />' );
defaultType =
mw.UploadWizard.config.licensing.defaultType;
- var $formFields = $( '<div
class="mwe-upwiz-deed-form-internal" />' );
- if ( _this.uploadCount > 1 ) {
+ if ( this.uploadCount > 1 ) {
$formFields.append( $( '<div />' ).msg(
'mwe-upwiz-source-thirdparty-custom-multiple-intro' ) );
}
@@ -348,17 +342,17 @@
$( '<label for="source" generated="true"
class="mwe-validator-error" style="display:block;" />' ),
$( '<div class="mwe-upwiz-thirdparty-fields"
/>' )
.append( $( '<label for="source" />'
).text( mw.message( 'mwe-upwiz-source' ).text() ).addHint( 'source' ),
- _this.sourceInput ),
+ this.sourceInput ),
$( '<label for="author" generated="true"
class="mwe-validator-error" style="display:block;" />' ),
$( '<div class="mwe-upwiz-thirdparty-fields"
/>' )
.append( $( '<label for="author" />'
).text( mw.message( 'mwe-upwiz-author' ).text() ).addHint( 'author' ),
- _this.authorInput ),
+ this.authorInput ),
$( '<div class="mwe-upwiz-thirdparty-license"
/>' )
- .append( $( '<div></div>' ).msg(
'mwe-upwiz-source-thirdparty-cases', _this.uploadCount ) )
+ .append( $( '<div></div>' ).msg(
'mwe-upwiz-source-thirdparty-cases', this.uploadCount ) )
.append( licenseInputDiv )
);
- _this.$form.validate( {
+ this.$form.validate( {
rules: {
source: { required: true,
minlength:
mw.UploadWizard.config.minSourceLength,
@@ -381,9 +375,9 @@
}
} );
- _this.$form.append( $formFields );
+ this.$form.append( $formFields );
- $selector.append( _this.$form );
+ $selector.append( this.$form );
if ( defaultType === 'thirdparty' ) {
defaultLicense =
mw.UploadWizard.config.licensing.thirdParty.defaults[0];
@@ -410,8 +404,8 @@
valid: function() {
// n.b. valid() has side effects and both should be
called every time the function is called.
// do not short-circuit.
- var formValid = _this.$form.valid();
- var licenseInputValid = _this.licenseInput.valid();
+ var formValid = this.$form.valid(),
+ licenseInputValid = this.licenseInput.valid();
return formValid && licenseInputValid;
}
} );
@@ -426,65 +420,65 @@
* @param {Array[UploadWizardDeed]} deeds
* @param {Array[UploadWizardUpload]} uploads that this applies to (this is
just to make deleting and plurals work)
*/
-mw.UploadWizardDeedChooser = function( selector, deeds, uploads, api ) {
- var _this = this;
- _this.$selector = $( selector );
- _this.uploads = uploads === undefined ? [] : uploads;
+mw.UploadWizardDeedChooser = function( selector, deeds, uploads ) {
+ var chooser = this;
+ this.$selector = $( selector );
+ this.uploads = uploads === undefined ? [] : uploads;
- _this.$errorEl = $( '<div class="mwe-error"></div>' );
- _this.$selector.append( _this.$errorEl );
+ this.$errorEl = $( '<div class="mwe-error"></div>' );
+ this.$selector.append( this.$errorEl );
// name for radio button set
mw.UploadWizardDeedChooser.prototype.widgetCount++;
- _this.name = 'deedChooser' +
mw.UploadWizardDeedChooser.prototype.widgetCount.toString();
+ this.name = 'deedChooser' +
mw.UploadWizardDeedChooser.prototype.widgetCount.toString();
- _this.onLayoutReady = function() {};
+ this.onLayoutReady = function() {};
$.each( deeds, function ( i, deed ) {
- var id = _this.name + '-' + deed.name;
- var $deedInterface = $(
- '<div class="mwe-upwiz-deed mwe-upwiz-deed-' +
deed.name + '">' +
- '<div class="mwe-upwiz-deed-option-title">' +
- '<span class="mwe-upwiz-deed-header">' +
- '<input id="' + id +'" name="'
+ _this.name + '" type="radio" value="' + deed.name + ' /">' +
- '<label for="' + id + '"
class="mwe-upwiz-deed-name">' +
- mw.message(
'mwe-upwiz-source-' + deed.name, _this.uploads.length ).escaped() +
- '</label>' +
- '</span>' +
- '</div>' +
- '<div class="mwe-upwiz-deed-form"></div>' +
- '</div>'
- );
+ var id = chooser.name + '-' + deed.name,
+ $deedInterface = $(
+ '<div class="mwe-upwiz-deed mwe-upwiz-deed-' +
deed.name + '">' +
+ '<div
class="mwe-upwiz-deed-option-title">' +
+ '<span
class="mwe-upwiz-deed-header">' +
+ '<input id="' + id +'"
name="' + chooser.name + '" type="radio" value="' + deed.name + ' /">' +
+ '<label for="' + id +
'" class="mwe-upwiz-deed-name">' +
+ mw.message(
'mwe-upwiz-source-' + deed.name, chooser.uploads.length ).escaped() +
+ '</label>' +
+ '</span>' +
+ '</div>' +
+ '<div
class="mwe-upwiz-deed-form"></div>' +
+ '</div>'
+ );
- var $deedSelector = _this.$selector.append( $deedInterface );
+ chooser.$selector.append( $deedInterface );
deed.setFormFields( $deedInterface.find( '.mwe-upwiz-deed-form'
) );
- var selectDeedFunction = function() {
- _this.choose( deed );
- _this.selectDeedInterface( $deedInterface );
+ function selectDeedFunction() {
+ chooser.choose( deed );
+ chooser.selectDeedInterface( $deedInterface );
$deedInterface.find( 'span.mwe-upwiz-deed-header input'
).attr( 'checked', true );
- };
+ }
- if ( deeds.length == 1 ) {
- _this.onLayoutReady = selectDeedFunction;
+ if ( deeds.length === 1 ) {
+ chooser.onLayoutReady = selectDeedFunction;
}
else {
if ( mw.UploadWizard.config.licensing.defaultType ===
deed.name ) {
- _this.onLayoutReady = selectDeedFunction;
+ chooser.onLayoutReady = selectDeedFunction;
}
$deedInterface.find( 'span.mwe-upwiz-deed-header input'
).click( function() {
if ( $( this ).is( ':checked' ) ) {
- _this.choose( deed );
- _this.selectDeedInterface(
$deedInterface );
+ chooser.choose( deed );
+ chooser.selectDeedInterface(
$deedInterface );
}
} );
}
} );
// deselect all deeds
- _this.deselectDeedInterface( this.$selector.find( '.mwe-upwiz-deed' ) );
+ this.deselectDeedInterface( this.$selector.find( '.mwe-upwiz-deed' ) );
};
@@ -500,13 +494,12 @@
* @return boolean; true if valid, false if not
*/
valid: function() {
- var _this = this;
// we assume there is always a deed available, even if it's
just the null deed.
- var valid = _this.deed.valid();
+ var valid = this.deed.valid();
// the only time we need to set an error message is if the null
deed is selected.
// otherwise, we can assume that the widgets have already added
error messages.
if (valid) {
- _this.hideError();
+ this.hideError();
}
return valid;
},
@@ -528,8 +521,7 @@
choose: function( deed ) {
- var _this = this;
- _this.deed = deed;
+ this.deed = deed;
$( '#mwe-upwiz-stepdiv-deeds .mwe-upwiz-button-next' ).show();
},
@@ -539,12 +531,12 @@
deselectDeedInterface: function( $deedSelector ) {
$deedSelector.removeClass( 'selected' );
$.each( $deedSelector.find( '.mwe-upwiz-deed-form' ), function(
i, form ) {
- var $form = $( form );
- $.each( $form.find(".mwe-upwiz-hint"), function( i,
hint ) {
- $( hint ).tipsy("hide");
+ var $form = $( form ),
+ originalResetForm = $.fn.resetForm;
+ $.each( $form.find('.mwe-upwiz-hint'), function( i,
hint ) {
+ $( hint ).tipsy('hide');
} );
// Remove errors
- var originalResetForm = $.fn.resetForm;
if ( originalResetForm ) {
// Make sure that $validator.resetForm() resets
only the errors, not the form fields!
$.fn.resetForm = function() { };
--
To view, visit https://gerrit.wikimedia.org/r/86777
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I66a32316613a0779a7ca3a5b77698cacca1ba11f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: MarkTraceur <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits