Merge "Add .jshintrc"

This commit is contained in:
jenkins-bot 2013-04-17 23:03:39 +00:00 committed by Gerrit Code Review
commit aa315ebd90
4 changed files with 70 additions and 31 deletions

31
.jshintrc Normal file
View file

@ -0,0 +1,31 @@
{
/* Common */
// Enforcing
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"latedef": true,
"newcap": true,
"noarg": true,
"noempty": true,
"nonew": true,
"quotmark": "single",
"trailing": true,
"undef": true,
"unused": true,
// Legacy
"onevar": true,
/* Local */
// Environment
"browser": true,
"predef": [
"jQuery",
"QUnit",
"mediaWiki"
]
}

View file

@ -1,4 +1,5 @@
( function ( $, mw ) { ( function ( $, mw ) {
/*global alert */
'use strict'; 'use strict';
mw.echo = { mw.echo = {
@ -12,8 +13,7 @@
* reload the page. * reload the page.
*/ */
'dismiss': function( notification ) { 'dismiss': function( notification ) {
var _this = this, var $notification = $( notification ),
$notification = $( notification ),
eventCategory = $notification.attr( 'data-notification-category' ), eventCategory = $notification.attr( 'data-notification-category' ),
prefName = '', prefName = '',
prefs = [], prefs = [],
@ -26,21 +26,21 @@
} }
} ); } );
prefRequest = { prefRequest = {
'action': 'options', action: 'options',
'change': prefs.join( '|' ), change: prefs.join( '|' ),
'token': mw.echo.optionsToken, token: mw.echo.optionsToken,
'format': 'json' format: 'json'
}; };
$.ajax( { $.ajax( {
type: 'post', type: 'post',
url: mw.util.wikiScript( 'api' ), url: mw.util.wikiScript( 'api' ),
data: prefRequest, data: prefRequest,
dataType: 'json', dataType: 'json',
success: function( data ) { success: function () {
// If we're on the Notifications archive page, just refresh the page // If we're on the Notifications archive page, just refresh the page
if ( mw.config.get( 'wgCanonicalNamespace' ) === 'Special' if ( mw.config.get( 'wgCanonicalNamespace' ) === 'Special' &&
&& mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Notifications' ) mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Notifications'
{ ) {
window.location.reload(); window.location.reload();
} else { } else {
eventCategory = $notification.attr( 'data-notification-category' ); eventCategory = $notification.attr( 'data-notification-category' );
@ -59,8 +59,10 @@
* First we have to retrieve the options token. * First we have to retrieve the options token.
*/ */
'setOptionsToken': function( callback, notification ) { 'setOptionsToken': function( callback, notification ) {
var _this = this; var tokenRequest,
var tokenRequest = { _this = this;
tokenRequest = {
'action': 'tokens', 'action': 'tokens',
'type' : 'options', 'type' : 'options',
'format': 'json' 'format': 'json'
@ -74,7 +76,7 @@
data: tokenRequest, data: tokenRequest,
dataType: 'json', dataType: 'json',
success: function( data ) { success: function( data ) {
if ( typeof data.tokens.optionstoken === 'undefined' ) { if ( data.tokens.optionstoken === undefined ) {
alert( mw.msg( 'echo-error-token' ) ); alert( mw.msg( 'echo-error-token' ) );
} else { } else {
_this.optionsToken = data.tokens.optionstoken; _this.optionsToken = data.tokens.optionstoken;
@ -111,11 +113,12 @@
'setUpDismissability' : function( notification ) { 'setUpDismissability' : function( notification ) {
var $dismissButton, var $dismissButton,
$cancelButton, $cancelButton,
$closebox,
_this = this, _this = this,
$notification = $( notification ); $notification = $( notification );
// Add dismiss box // Add dismiss box
var $closebox = $( '<div/>' ) $closebox = $( '<div/>' )
.addClass( 'mw-echo-close-box' ) .addClass( 'mw-echo-close-box' )
.css( 'display', 'none' ) .css( 'display', 'none' )
.click( function() { .click( function() {
@ -129,7 +132,7 @@
.addClass( 'mw-echo-dismiss-button' ) .addClass( 'mw-echo-dismiss-button' )
.addClass( 'ui-button-blue' ) .addClass( 'ui-button-blue' )
.button( { .button( {
icons: { primary: "ui-icon-closethick" } icons: { primary: 'ui-icon-closethick' }
} ) } )
.click( function () { .click( function () {
_this.setOptionsToken( _this.dismiss, $notification ); _this.setOptionsToken( _this.dismiss, $notification );

View file

@ -22,19 +22,21 @@
.badge( newCount, true, true ); .badge( newCount, true, true );
} }
mw.echo.overlay.notification_count = newCount; mw.echo.overlay.notificationCount = newCount;
}, },
'configuration' : mw.config.get( 'wgEchoOverlayConfiguration' ), 'configuration' : mw.config.get( 'wgEchoOverlayConfiguration' ),
'buildOverlay' : function( callback ) { 'buildOverlay' : function( callback ) {
var $overlay = $( '<div></div>' ).addClass( 'mw-echo-overlay' ), var notificationLimit,
$overlay = $( '<div></div>' ).addClass( 'mw-echo-overlay' ),
$link = $( '#pt-notifications a' ), $link = $( '#pt-notifications a' ),
$prefLink = $( '#pt-preferences a' ), $prefLink = $( '#pt-preferences a' ),
count = 0; count = 0,
var Api = new mw.Api(); Api = new mw.Api();
// Set notification limit based on height of the window // Set notification limit based on height of the window
var notificationLimit = Math.floor( ( $( window ).height() - 134 ) / 90 ); notificationLimit = Math.floor( ( $( window ).height() - 134 ) / 90 );
if ( notificationLimit < 1 ) { if ( notificationLimit < 1 ) {
notificationLimit = 1; notificationLimit = 1;
@ -55,12 +57,13 @@
unreadTotalCount = result.query.notifications.count, unreadTotalCount = result.query.notifications.count,
$title = $( '<div class="mw-echo-overlay-title"></div>' ), $title = $( '<div class="mw-echo-overlay-title"></div>' ),
$ul = $( '<ul class="mw-echo-notifications"></ul>' ), $ul = $( '<ul class="mw-echo-notifications"></ul>' ),
titleText = ''; titleText = '',
$overlayFooter;
$ul.css( 'max-height', notificationLimit * 95 + 'px' ); $ul.css( 'max-height', notificationLimit * 95 + 'px' );
$.each( notifications.index, function( index, id ) { $.each( notifications.index, function( index, id ) {
var data = notifications.list[id]; var data = notifications.list[id],
var $li = $( '<li></li>' ) $li = $( '<li></li>' )
.data( 'details', data ) .data( 'details', data )
.data( 'id', id ) .data( 'id', id )
.attr( 'data-notification-category', data.category ) .attr( 'data-notification-category', data.category )
@ -96,7 +99,7 @@
$ul.appendTo( $overlay ); $ul.appendTo( $overlay );
} }
var $overlayFooter = $( '<div/>' ) $overlayFooter = $( '<div/>' )
.attr( 'id', 'mw-echo-overlay-footer' ); .attr( 'id', 'mw-echo-overlay-footer' );
// add link to notifications archive // add link to notifications archive
@ -143,10 +146,10 @@
} }
}; };
mw.echo.overlay.notification_count = mw.echo.overlay.configuration['notification-count']; mw.echo.overlay.notificationCount = mw.echo.overlay.configuration['notification-count'];
$( function() { $( function() {
mw.echo.overlay.updateCount( mw.echo.overlay.notification_count ); mw.echo.overlay.updateCount( mw.echo.overlay.notificationCount );
var $link = $( '#pt-notifications a' ); var $link = $( '#pt-notifications a' );
if ( ! $link.length ) { if ( ! $link.length ) {
@ -154,8 +157,10 @@
} }
$link.click( function( e ) { $link.click( function( e ) {
var $target, $overlay;
e.preventDefault(); e.preventDefault();
var $target = $( e.target ); $target = $( e.target );
// If the user clicked on the overlay or any child, // If the user clicked on the overlay or any child,
// ignore the click // ignore the click
if ( $target.hasClass( 'mw-echo-overlay' ) || if ( $target.hasClass( 'mw-echo-overlay' ) ||
@ -164,7 +169,7 @@
return; return;
} }
var $overlay = $( '.mw-echo-overlay' ); $overlay = $( '.mw-echo-overlay' );
if ( $overlay.length ) { if ( $overlay.length ) {
$overlay.fadeOut( 'fast', $overlay.fadeOut( 'fast',

View file

@ -161,7 +161,7 @@
}, },
'onSuccess': function() { 'onSuccess': function() {
if ( this.moreData == '0' ) { if ( this.moreData === '0' ) {
$( '#mw-echo-more' ).hide(); $( '#mw-echo-more' ).hide();
} }
this.processing = false; this.processing = false;