Hashar has submitted this change and it was merged.
Change subject: Add npm entry point and fix jshint errors
......................................................................
Add npm entry point and fix jshint errors
Bug: T63637
Change-Id: Ife260843eb746199dbfcff038f0279893a7eb6eb
---
M .gitignore
A .jshintignore
A .jshintrc
A Gruntfile.js
A package.json
M resources/ext.survey.answerSelector.js
M resources/ext.survey.js
M resources/ext.survey.special.survey.js
M resources/ext.survey.special.surveys.js
M resources/ext.survey.tag.js
M resources/jquery.survey.js
11 files changed, 144 insertions(+), 43 deletions(-)
Approvals:
Hashar: Verified; Looks good to me, approved
diff --git a/.gitignore b/.gitignore
index 9ab99ba..34f2522 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,5 @@
-.*
*~
*.kate-swp
.*.swp
-
-!.gitignore
-!.gitreview
+.project
+node_modules/**
diff --git a/.jshintignore b/.jshintignore
new file mode 100644
index 0000000..018476d
--- /dev/null
+++ b/.jshintignore
@@ -0,0 +1,3 @@
+resources/fancybox/**
+resources/jquery.numeric.js
+node_modules/**
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..6c87f5c
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,26 @@
+{
+ // Enforcing
+ "bitwise": true,
+ "eqeqeq": true,
+ "freeze": true,
+ "latedef": "nofunc",
+ "noarg": true,
+ "nonew": true,
+ "undef": true,
+ "unused": true,
+ "strict": false,
+
+ // Relaxing
+ "es5": false,
+
+ // Environment
+ "browser": true,
+ "jquery": true,
+
+ "globals": {
+ "mediaWiki": false,
+ "console": true,
+ "confirm": true,
+ "alert": true
+ }
+}
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000..d9daa46
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,32 @@
+/*jshint node:true */
+module.exports = function ( grunt ) {
+ grunt.loadNpmTasks( 'grunt-contrib-jshint' );
+ grunt.loadNpmTasks( 'grunt-jsonlint' );
+ grunt.loadNpmTasks( 'grunt-banana-checker' );
+
+ grunt.initConfig( {
+ jshint: {
+ options: {
+ jshintrc: true
+ },
+ all: [
+ '**/*.js',
+ '!node_modules/**',
+ '!resources/fancybox/**',
+ '!resources/jquery.numeric.js'
+ ]
+ },
+ banana: {
+ all: 'i18n/'
+ },
+ jsonlint: {
+ all: [
+ '**/*.json',
+ '!node_modules/**'
+ ]
+ }
+ } );
+
+ grunt.registerTask( 'test', [ 'jshint', 'jsonlint', 'banana' ] );
+ grunt.registerTask( 'default', 'test' );
+};
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..ec97d7b
--- /dev/null
+++ b/package.json
@@ -0,0 +1,12 @@
+{
+ "scripts": {
+ "test": "grunt test"
+ },
+ "devDependencies": {
+ "grunt": "0.4.5",
+ "grunt-cli": "0.1.13",
+ "grunt-banana-checker": "0.4.0",
+ "grunt-contrib-jshint": "1.0.0",
+ "grunt-jsonlint": "1.0.7"
+ }
+}
diff --git a/resources/ext.survey.answerSelector.js
b/resources/ext.survey.answerSelector.js
index 88f1afc..e43a5a6 100644
--- a/resources/ext.survey.answerSelector.js
+++ b/resources/ext.survey.answerSelector.js
@@ -6,11 +6,9 @@
* @author Jeroen De Dauw <jeroendedauw at gmail dot com>
*/
-(function( $, mw, survey ) {
+( function( $, mw, survey ) {
- survey.answerSelector = function( options ) {
- var _this = this;
-
+ survey.answerSelector = function( options ) {
var defaults = {
'visible': true,
'answers': []
@@ -52,4 +50,4 @@
};
-} )( jQuery, window.mediaWiki, window.survey );
+}( jQuery, mediaWiki, window.survey ) );
diff --git a/resources/ext.survey.js b/resources/ext.survey.js
index 6cf854b..85a3cc1 100644
--- a/resources/ext.survey.js
+++ b/resources/ext.survey.js
@@ -6,7 +6,9 @@
* @author Jeroen De Dauw <jeroendedauw at gmail dot com>
*/
-window.survey = new( function() {
+/*jshint supernew:true */
+
+window.survey = new( function( survey, $ ) {
this.log = function( message ) {
if ( mediaWiki.config.get( 'wgSurveyDebug' ) ) {
@@ -21,6 +23,7 @@
};
this.msg = function() {
+ var message;
if ( typeof mediaWiki === 'undefined' ) {
message = window.wgSurveyMessages[arguments[0]];
@@ -35,6 +38,8 @@
};
this.htmlSelect = function( options, value, attributes,
onChangeCallback ) {
+ var message;
+ var $select;
$select = $( '<select />' ).attr( attributes );
for ( message in options ) {
@@ -48,7 +53,7 @@
}
if ( typeof onChangeCallback !== 'undefined' ) {
- $select.change( function() { onChangeCallback( $( this
).val() ) } );
+ $select.change( function() { onChangeCallback( $( this
).val() ); } );
}
return $select;
@@ -56,11 +61,13 @@
this.htmlRadio = function( options, value, name, attributes ) {
var $radio = $( '<div />' ).attr( attributes );
+ var message;
$radio.html( '' );
for ( message in options ) {
var itemValue = options[message];
var id = name + itemValue;
+ var $input;
$input = $( '<input />' ).attr( {
'id': id,
@@ -90,7 +97,7 @@
this.RADIO = 3;
this.TEXTAREA = 4;
this.CHECK = 5;
- } );
+ }() );
this.typeHasAnswers = function( t ) {
return $.inArray( t, [ survey.question.type.RADIO,
survey.question.type.SELECT ] ) !== -1;
@@ -98,6 +105,7 @@
this.getTypeSelector = function( value, attributes,
onChangeCallback ) {
var options = [];
+ var msg;
var types = {
'text': survey.question.type.TEXT,
@@ -118,8 +126,6 @@
return survey.htmlSelect( options, parseInt( value ),
attributes, onChangeCallback );
};
- } );
+ }() );
-} )();
-
-
+}( window.survey, jQuery ) );
diff --git a/resources/ext.survey.special.survey.js
b/resources/ext.survey.special.survey.js
index 6586917..b4068dc 100644
--- a/resources/ext.survey.special.survey.js
+++ b/resources/ext.survey.special.survey.js
@@ -6,9 +6,11 @@
* @author Jeroen De Dauw <jeroendedauw at gmail dot com>
*/
-(function( $, mw, survey ) { $( document ).ready( function() {
+/*jshint -W061 */
+/*jshint -W007 */
- var _this = this;
+( function( $, mw, survey ) {
+ $( document ).ready( function() {
var $table = null;
var newQuestionNr = 0;
@@ -139,7 +141,7 @@
}
function removeQuestion( question ) {
- $( '#survey-question-div-' + question.id ).closest( 'tr'
).slideUp( 'fast', function() { $( this ).remove(); } )
+ $( '#survey-question-div-' + question.id ).closest( 'tr'
).slideUp( 'fast', function() { $( this ).remove(); } );
}
function onAddQuestionRequest() {
@@ -164,12 +166,13 @@
$table.append( '<tr><td colspan="2"><hr /></td></tr>' );
$( '.survey-question-data' ).each( function( index, domElement
) {
+ var $this;
$this = $( domElement );
addQuestion( {
'text': $this.attr( 'data-text' ),
'default': $this.attr( 'data-default' ),
- 'required': $this.attr( 'data-required' ) ==
'1',
+ 'required': $this.attr( 'data-required' ) ===
'1',
'id': $this.attr( 'data-id' ),
'type': $this.attr( 'data-type' ),
'answers': eval( $this.attr( 'data-answers' ) )
@@ -183,4 +186,5 @@
setup();
-} ); })( jQuery, window.mediaWiki, window.survey );
+} );
+}( jQuery, mediaWiki, window.survey ) );
diff --git a/resources/ext.survey.special.surveys.js
b/resources/ext.survey.special.surveys.js
index c5e3b05..3c1f887 100644
--- a/resources/ext.survey.special.surveys.js
+++ b/resources/ext.survey.special.surveys.js
@@ -6,11 +6,12 @@
* @author Jeroen De Dauw <jeroendedauw at gmail dot com>
*/
-(function( $ ) { $( document ).ready( function() {
+( function( $, mw ) {
+ $( document ).ready( function() {
function deleteSurvey( options, successCallback, failCallback ) {
$.post(
- wgScriptPath + '/api.php',
+ mw.config.get( 'wgScriptPath' ) + '/api.php',
{
'action': 'deletesurvey',
'format': 'json',
@@ -47,4 +48,6 @@
return false;
} );
-} ); })( jQuery );
\ No newline at end of file
+} );
+
+}( jQuery, mediaWiki ) );
diff --git a/resources/ext.survey.tag.js b/resources/ext.survey.tag.js
index 499898d..b9e0066 100644
--- a/resources/ext.survey.tag.js
+++ b/resources/ext.survey.tag.js
@@ -6,7 +6,7 @@
* @author Jeroen De Dauw <jeroendedauw at gmail dot com>
*/
-(function( $, survey ) {
+( function( $, survey ) {
function getCookieName( options ) {
return ( typeof options.id !== 'undefined' ) ?
@@ -95,4 +95,4 @@
} );
-})( jQuery, window.survey );
\ No newline at end of file
+}( jQuery, window.survey ) );
\ No newline at end of file
diff --git a/resources/jquery.survey.js b/resources/jquery.survey.js
index 867c27e..03c6999 100644
--- a/resources/jquery.survey.js
+++ b/resources/jquery.survey.js
@@ -6,7 +6,10 @@
* @author Jeroen De Dauw <jeroendedauw at gmail dot com>
*/
-( function ( $ ) { $.fn.mwSurvey = function( options ) {
+/*jshint -W087 */
+
+( function ( $, mw, survey ) {
+ $.fn.mwSurvey = function( options ) {
var _this = this;
this.options = options;
@@ -32,7 +35,7 @@
requestArgs[ 'su' + this.identifierType + 's' ] =
this.identifier;
$.getJSON(
- wgScriptPath + '/api.php',
+ mw.config.get( 'wgScriptPath' ) + '/api.php',
requestArgs,
function( data ) {
if ( data.surveys ) {
@@ -56,8 +59,12 @@
var $input;
var id = 'question-input-' + question.id;
+ var answers;
+
+ var i;
+
switch ( question.type ) {
- case type.TEXT: default:
+ case type.TEXT:
$input = $( '<input />' ).attr( {
'id': id,
'class': 'question-input survey-text'
@@ -71,7 +78,7 @@
} );
break;
case type.SELECT:
- var answers = {};
+ answers = {};
for ( i in question.answers ) {
answers[question.answers[i]] =
question.answers[i];
@@ -83,7 +90,7 @@
} );
break;
case type.RADIO:
- var answers = {};
+ answers = {};
for ( i in question.answers ) {
answers[question.answers[i]] =
question.answers[i];
@@ -114,7 +121,14 @@
'class': 'question-input survey-check'
} );
break;
+ default:
+ $input = $( '<input />' ).attr( {
+ 'id': id,
+ 'class': 'question-input survey-text'
+ } );
}
+
+ var $q;
$input.data( 'question-id', question.id );
@@ -124,8 +138,7 @@
if ( question.type === type.CHECK ) {
$q.prepend( $( '<label />' ).text( question.text
).attr( 'for', id ) );
- }
- else {
+ } else {
$q.prepend( $( '<p />' ).text( question.text ).attr(
'class', 'question-text' ) );
}
@@ -133,8 +146,8 @@
};
this.getSurveyQuestion = function( question ) {
- if ( survey.question.typeHasAnswers( question.type )
- && question.answers.length == 0 ) {
+ if ( survey.question.typeHasAnswers( question.type ) &&
+ question.answers.length === 0 ) {
survey.log( 'getSurveyQuestion: no answers for: ' +
question.id );
return '';
}
@@ -146,25 +159,26 @@
this.getSurveyQuestions = function( questions ) {
var $questions = $( '<div />' );
- for ( i in questions ) {
+ for ( var i in questions ) {
$questions.append( this.getSurveyQuestion( questions[i]
) );
}
return $questions;
};
- this.getAnswers = function( surveyId ) {
+ this.getAnswers = function() {
var answers = [];
for ( var i in this.inputs ) {
var $input = this.inputs[i].input;
var id = $input.data( 'question-id' );
+ var value;
if ( this.inputs[i].type === survey.question.type.RADIO
) {
- var value = $(
'input:radio[name=question-input-' + id + ']:checked' ).val();
+ value = $( 'input:radio[name=question-input-' +
id + ']:checked' ).val();
}
else {
- var value = $input.val();
+ value = $input.val();
}
answers.push( {
@@ -187,9 +201,9 @@
requestArgs[this.identifierType] = this.identifier;
$.post(
- wgScriptPath + '/api.php',
+ mw.config.get( 'wgScriptPath' ) + '/api.php',
requestArgs,
- function( data ) {
+ function() {
callback();
// TODO
}
@@ -201,6 +215,7 @@
};
this.showCompletion = function( surveyData ) {
+ var $div;
$div = $( '#survey-' + surveyData.id );
$div.html( $( '<p />' ).text( surveyData.thanks ) );
@@ -212,6 +227,7 @@
};
this.getSurveyBody = function( surveyData ) {
+ var $survey;
$survey = $( '<div />' );
$survey.append( $( '<h1 />' ).text( surveyData.title ) );
@@ -230,7 +246,7 @@
_this.submitSurvey(
surveyData.id,
function() {
- if ( surveyData.thanks
== '' ) {
+ if ( surveyData.thanks
=== '' ) {
_this.doCompletion();
} else {
_this.showCompletion( surveyData );
@@ -252,6 +268,8 @@
};
this.initSurvey = function( surveyData ) {
+ var $div;
+ var $link;
$div = $( '<div />' ).attr( {
'style': 'display:none'
} ).html( $( '<div />' ).attr( { 'id': 'survey-' +
surveyData.id } ).html( this.getSurveyBody( surveyData ) ) );
@@ -310,4 +328,5 @@
this.init();
-}; } )( jQuery );
+};
+}( jQuery, mediaWiki, window.survey ) );
--
To view, visit https://gerrit.wikimedia.org/r/271494
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ife260843eb746199dbfcff038f0279893a7eb6eb
Gerrit-PatchSet: 15
Gerrit-Project: mediawiki/extensions/Survey
Gerrit-Branch: master
Gerrit-Owner: Paladox <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Paladox <[email protected]>
Gerrit-Reviewer: Yaron Koren <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits