Merge "build: Add csshint, jshint and jscs to math extension"

This commit is contained in:
jenkins-bot 2015-09-14 22:30:31 +00:00 committed by Gerrit Code Review
commit f99b77c98e
11 changed files with 133 additions and 58 deletions

13
.csslintrc Normal file
View File

@ -0,0 +1,13 @@
{
"adjoining-classes": false,
"box-model": false,
"box-sizing": false,
"fallback-colors": false,
"important": false,
"outline-none": false,
"qualified-headings": false,
"unique-headings": false,
"universal-selector": false,
"unqualified-attributes": false,
"gradients": false
}

21
.jscsrc Normal file
View File

@ -0,0 +1,21 @@
{
"preset": "wikimedia",
"jsDoc": {
"checkAnnotations": {
"preset": "jsduck5",
"extra": {
"this": true,
"source": true,
"see": true
}
},
"checkTypes": "strictNativeCase",
"checkParamNames": true,
"checkRedundantAccess": true,
"checkRedundantReturns": true,
"requireNewlineAfterDescription": true,
"requireParamTypes": true,
"requireReturnTypes": true
}
}

25
.jshintrc Normal file
View File

@ -0,0 +1,25 @@
{
// Enforcing
"bitwise": true,
"eqeqeq": true,
"freeze": true,
"latedef": true,
"noarg": true,
"nonew": true,
"undef": true,
"unused": true,
"strict": false,
// Relaxing
"es5": false,
// Environment
"browser": true,
"jquery": true,
"globals": {
"mediaWiki": false,
"OO": false,
"ve": false
}
}

View File

@ -2,6 +2,10 @@
module.exports = function ( grunt ) {
grunt.loadNpmTasks( 'grunt-banana-checker' );
grunt.loadNpmTasks( 'grunt-jsonlint' );
grunt.loadNpmTasks( 'grunt-contrib-csslint' );
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
grunt.loadNpmTasks( 'grunt-contrib-watch' );
grunt.loadNpmTasks( 'grunt-jscs' );
grunt.initConfig( {
banana: {
@ -12,9 +16,43 @@ module.exports = function ( grunt ) {
'**/*.json',
'!node_modules/**'
]
},
csslint: {
options: {
csslintrc: '.csslintrc'
},
all: 'modules/VisualEditor/*.css'
},
jshint: {
options: {
jshintrc: true
},
all: [
'*.js',
'modules/**/*.js'
]
},
watch: {
files: [
'.{csslintrc,jscsrc,jshintignore,jshintrc}',
'<%= jshint.all %>',
'<%= csslint.all %>'
],
tasks: 'test'
},
jscs: {
fix: {
options: {
fix: true
},
src: '<%= jshint.all %>'
},
main: {
src: '<%= jshint.all %>'
}
}
} );
grunt.registerTask( 'test', [ 'jsonlint', 'banana' ] );
grunt.registerTask( 'test', [ 'jshint', 'jscs:main', 'csslint', 'jsonlint', 'banana' ] );
grunt.registerTask( 'default', 'test' );
};

View File

@ -1,31 +0,0 @@
{
"predef": [
"mediaWiki",
"jQuery"
],
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"forin": false,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonew": true,
"quotmark": "single",
"regexp": false,
"undef": true,
"unused": true,
"strict": false,
"trailing": true,
"smarttabs": true,
"browser": true,
"nomen": true,
"onevar": true
}

View File

@ -55,7 +55,7 @@ ve.ce.MWMathNode.prototype.afterRender = function () {
if ( this.$element.is( 'span.tex' ) ) {
// MathJax
MathJax.Hub.Queue(
[ 'Typeset', MathJax.Hub, this.$element[0] ],
[ 'Typeset', MathJax.Hub, this.$element[ 0 ] ],
[ this, this.emit, 'rerender' ]
);
} else {

View File

@ -45,6 +45,8 @@ ve.ui.MWMathInspector.static.dir = 'ltr';
* @inheritdoc
*/
ve.ui.MWMathInspector.prototype.initialize = function () {
var inputField, displayField, idField;
// Parent method
ve.ui.MWMathInspector.super.prototype.initialize.call( this );
@ -71,18 +73,18 @@ ve.ui.MWMathInspector.prototype.initialize = function () {
this.idInput = new OO.ui.TextInputWidget();
var inputField = new OO.ui.FieldLayout( this.input, {
align: 'top',
label: ve.msg( 'math-visualeditor-mwmathinspector-title' )
} ),
displayField = new OO.ui.FieldLayout( this.displaySelect, {
align: 'top',
label: ve.msg( 'math-visualeditor-mwmathinspector-display' )
} ),
idField = new OO.ui.FieldLayout( this.idInput, {
align: 'top',
label: ve.msg( 'math-visualeditor-mwmathinspector-id' )
} );
inputField = new OO.ui.FieldLayout( this.input, {
align: 'top',
label: ve.msg( 'math-visualeditor-mwmathinspector-title' )
} );
displayField = new OO.ui.FieldLayout( this.displaySelect, {
align: 'top',
label: ve.msg( 'math-visualeditor-mwmathinspector-display' )
} );
idField = new OO.ui.FieldLayout( this.idInput, {
align: 'top',
label: ve.msg( 'math-visualeditor-mwmathinspector-id' )
} );
// Initialization
this.$content.addClass( 've-ui-mwMathInspector-content' );
@ -115,11 +117,13 @@ ve.ui.MWMathInspector.prototype.getTeardownProcess = function ( data ) {
* @inheritdoc
*/
ve.ui.MWMathInspector.prototype.updateMwData = function ( mwData ) {
var display, id;
// Parent method
ve.ui.MWMathInspector.super.prototype.updateMwData.call( this, mwData );
var display = this.displaySelect.getSelectedItem().getData(),
id = this.idInput.getValue();
display = this.displaySelect.getSelectedItem().getData();
id = this.idInput.getValue();
mwData.attrs.display = display !== 'default' ? display : undefined;
mwData.attrs.id = id || undefined;

View File

@ -32,6 +32,6 @@ ve.ui.toolFactory.register( ve.ui.MWMathInspectorTool );
ve.ui.commandRegistry.register(
new ve.ui.Command(
'math', 'window', 'open',
{ args: ['math'], supportedSelections: ['linear'] }
{ args: [ 'math' ], supportedSelections: [ 'linear' ] }
)
);

View File

@ -1,6 +1,7 @@
( function ( mw ) {
var iconPath;
if ( mw.toolbar ) {
var iconPath = mw.config.get( 'wgExtensionAssetsPath' ) + '/Math/images/';
iconPath = mw.config.get( 'wgExtensionAssetsPath' ) + '/Math/images/';
mw.toolbar.addButton( {
imageFile: iconPath + 'button_math.png',
speedTip: mw.msg( 'math_tip' ),

View File

@ -3,7 +3,7 @@
var img, url;
// If MathPlayer is installed we show the MathML rendering.
if (navigator.userAgent.indexOf('MathPlayer') > -1) {
if ( navigator.userAgent.indexOf( 'MathPlayer' ) > -1 ) {
$( '.mwe-math-mathml-a11y' ).removeClass( 'mwe-math-mathml-a11y' );
$( '.mwe-math-fallback-image-inline, .mwe-math-fallback-image-display' ).css( 'display', 'none' );
return;
@ -11,18 +11,18 @@
// We verify whether SVG as <img> is supported and otherwise use the
// PNG fallback. See https://github.com/Modernizr/Modernizr/blob/master/feature-detects/svg/asimg.js
if (!document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1')) {
$( '.mwe-math-fallback-image-inline, .mwe-math-fallback-image-display' ).each(function() {
if ( !document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' ) ) {
$( '.mwe-math-fallback-image-inline, .mwe-math-fallback-image-display' ).each( function () {
// Create a new PNG image to use as the fallback.
img = document.createElement('img');
url = this.style.backgroundImage.match(/url\('?([^']*)'?\)/)[1];
img.setAttribute( 'src', url.replace('mode=' + 'mathml', 'mode=' + 'png') );
img.setAttribute( 'class', 'tex mwe-math-fallback-image-' + ($( this ).hasClass('mwe-math-fallback-image-inline') ? 'inline' : 'display') );
img = document.createElement( 'img' );
url = this.style.backgroundImage.match( /url\('?([^']*)'?\)/ )[ 1 ];
img.setAttribute( 'src', url.replace( 'mode=' + 'mathml', 'mode=' + 'png' ) );
img.setAttribute( 'class', 'tex mwe-math-fallback-image-' + ( $( this ).hasClass( 'mwe-math-fallback-image-inline' ) ? 'inline' : 'display' ) );
img.setAttribute( 'aria-hidden', 'true' );
this.parentNode.insertBefore( img, this );
// Hide the SVG fallback.
$( this ).css( 'display', 'none' );
});
} );
}
}( jQuery ) );

View File

@ -7,6 +7,10 @@
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-banana-checker": "0.2.2",
"grunt-jsonlint": "1.0.4"
"grunt-jsonlint": "1.0.4",
"grunt-contrib-csslint": "0.5.0",
"grunt-contrib-jshint": "0.11.3",
"grunt-contrib-watch": "0.6.1",
"grunt-jscs": "2.1.0"
}
}