Refactor Cite extension JavaScript and make it pass Jshint

Moved the scripts and the CSS into the modules folder directly
(like almost all other extensions do), added a .jshintrc to not have
jenkins shout at this change and minor stuff.

After this change Cite will no longer work with anything older than
PHP 5.3!

Change-Id: I1c87af794f2a9894fb0d82a5bd97bd2182f028e1
This commit is contained in:
Marius Hoch 2013-08-17 20:21:42 +02:00
parent cce95414f6
commit 847a09be11
7 changed files with 51 additions and 16 deletions

1
.jshintignore Normal file
View file

@ -0,0 +1 @@
modules/jquery.tooltip/jquery.tooltip.js

34
.jshintrc Normal file
View file

@ -0,0 +1,34 @@
{
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"supernew": true,
"shadow": true,
"noarg": true,
"noempty": true,
"nonew": true,
"quotmark": false, // sometimes double quotes make sense, e.g. "foo's" is better readable than 'foo\'s'
"trailing": true,
"undef": true,
"unused": "vars", // we want to allow unused function parameters
"laxbreak": true,
"laxcomma": false,
"onevar": false,
"bitwise": false,
"forin": false,
"regexp": false,
"strict": true,
"scripturl": true,
// Environment
"browser": true,
// Globals
"predef": [
"jQuery",
"mediaWiki"
]
}

View file

@ -28,10 +28,10 @@ $wgExtensionCredits['parserhook'][] = array(
'descriptionmsg' => 'cite-desc',
'url' => 'https://www.mediawiki.org/wiki/Extension:Cite/Cite.php'
);
$wgParserTestFiles[] = dirname( __FILE__ ) . "/citeParserTests.txt";
$wgParserTestFiles[] = dirname( __FILE__ ) . "/citeCatTreeParserTests.txt";
$wgExtensionMessagesFiles['Cite'] = dirname( __FILE__ ) . "/Cite.i18n.php";
$wgAutoloadClasses['Cite'] = dirname( __FILE__ ) . "/Cite_body.php";
$wgParserTestFiles[] = __DIR__ . "/citeParserTests.txt";
$wgParserTestFiles[] = __DIR__ . "/citeCatTreeParserTests.txt";
$wgExtensionMessagesFiles['Cite'] = __DIR__ . "/Cite.i18n.php";
$wgAutoloadClasses['Cite'] = __DIR__ . "/Cite_body.php";
$wgSpecialPageGroups['Cite'] = 'pagetools';
define( 'CITE_DEFAULT_GROUP', '' );
@ -66,13 +66,12 @@ function wfCite( $parser ) {
// Resources
$citeResourceTemplate = array(
'localBasePath' => dirname(__FILE__) . '/modules',
'localBasePath' => __DIR__ . '/modules',
'remoteExtPath' => 'Cite/modules'
);
$wgResourceModules['ext.cite'] = $citeResourceTemplate + array(
'styles' => array(),
'scripts' => 'ext.cite/ext.cite.js',
$wgResourceModules['ext.cite.popups'] = $citeResourceTemplate + array(
'scripts' => 'ext.cite.popups.js',
'position' => 'bottom',
'dependencies' => array(
'jquery.tooltip',
@ -87,7 +86,7 @@ $wgResourceModules['jquery.tooltip'] = $citeResourceTemplate + array(
/* Add RTL fix for the cite <sup> elements */
$wgResourceModules['ext.rtlcite'] = $citeResourceTemplate + array(
'styles' => 'ext.rtlcite/ext.rtlcite.css',
'styles' => 'ext.rtlcite.css',
'position' => 'top',
);
@ -100,7 +99,7 @@ function wfCiteBeforePageDisplay( $out, &$sk ) {
global $wgCiteEnablePopups;
if ( $wgCiteEnablePopups ) {
$out->addModules( 'ext.cite' );
$out->addModules( 'ext.cite.popups' );
}
/* RTL support quick-fix module */

View file

@ -22,7 +22,7 @@ $wgExtensionCredits['specialpage'][] = array(
'url' => 'https://www.mediawiki.org/wiki/Extension:Cite/Special:Cite.php'
);
$dir = dirname( __FILE__ ) . '/';
$dir = __DIR__ . '/';
# Internationalisation file
$wgExtensionMessagesFiles['SpecialCite'] = $dir . 'SpecialCite.i18n.php';
$wgExtensionMessagesFiles['SpecialCiteAliases'] = $dir . 'SpecialCite.alias.php';
@ -35,12 +35,12 @@ $wgAutoloadClasses['SpecialCite'] = $dir . 'SpecialCite_body.php';
// Resources
$citeResourceTemplate = array(
'localBasePath' => dirname(__FILE__) . '/modules',
'localBasePath' => __DIR__ . '/modules',
'remoteExtPath' => 'Cite/modules'
);
$wgResourceModules['ext.specialcite'] = $citeResourceTemplate + array(
'styles' => 'ext.specialcite/ext.specialcite.css',
'styles' => 'ext.specialcite.css',
'scripts' => array(),
'position' => 'bottom',
);

View file

@ -1,6 +1,8 @@
( function($) {
( function( $ ) {
'use strict';
$( function() {
$('.biblio-cite-link,sup.reference a').tooltip({
$( '.biblio-cite-link,sup.reference a' ).tooltip( {
bodyHandler: function() {
return $( '#' + this.hash.substr(1) + ' > .reference-text' )
.html();
@ -8,5 +10,4 @@
showURL : false
} );
} );
} )( jQuery );