2010-10-04 22:16:18 +00:00
|
|
|
/*
|
|
|
|
|
* JavaScript for Special:Preferences
|
|
|
|
|
*/
|
2011-01-31 19:33:16 +00:00
|
|
|
( function( $, mw ) {
|
2010-10-04 22:16:18 +00:00
|
|
|
|
2010-10-06 19:05:59 +00:00
|
|
|
$( '#prefsubmit' ).attr( 'id', 'prefcontrol' );
|
2010-10-04 22:16:18 +00:00
|
|
|
$( '#preferences' )
|
|
|
|
|
.addClass( 'jsprefs' )
|
|
|
|
|
.before( $( '<ul id="preftoc"></ul>' ) )
|
2010-10-06 19:05:59 +00:00
|
|
|
.children( 'fieldset' )
|
2011-01-10 04:47:38 +00:00
|
|
|
.hide()
|
|
|
|
|
.addClass( 'prefsection' )
|
|
|
|
|
.children( 'legend' )
|
|
|
|
|
.addClass( 'mainLegend' )
|
Three small fixes to mediawiki.specials.preferences.js
* Moving class-adder from mousedown() to click().
Mousedown also fires when opening the contextmenu (right-click). If I right-clicked, say, preftab-4 to open in a new tab, it would work (thanks to r81573), but it would also trigger the 'selected'-class on that tab (which is wrong and out-of-sync since click() did not and should not fire). This behaviour was the case in Safari 5/Firefox 3 (Mac) and Chrome (Windows). Moving it to click() should not have any affect on the behaviour in other browsers.
Test it at: http://api.jquery.com/mousedown/
* Wrapping the hash-jump in a document.ready function.
This module is enclosed in a self-executing anonymous function to enforce private scope passing mediaWiki and jQuery. Although that, (<code>(function($,mw){ /* ... */ })(jQuery,mediaWiki);</code>) may look like a shortcut for jQuery(document).ready(), it is not. (Because both <code>;</code> and <code>jQuery(function{ /* ... */ });</code> look alike and are shortcuts). Anyway, wrapping it now to avoid it jumping too early.
* Using second argument of .each(), which is a reference to 'this'
By using that (named) variable instead there's no confusion with the other 'this' inside the click event binder – which refers to the then-clicked element (the anchor tag) rather than the legend-element.
2011-02-06 03:31:32 +00:00
|
|
|
.each( function( i, legend ) {
|
|
|
|
|
$(legend).parent().attr( 'id', 'prefsection-' + i );
|
2011-01-10 04:47:38 +00:00
|
|
|
if ( i === 0 ) {
|
Three small fixes to mediawiki.specials.preferences.js
* Moving class-adder from mousedown() to click().
Mousedown also fires when opening the contextmenu (right-click). If I right-clicked, say, preftab-4 to open in a new tab, it would work (thanks to r81573), but it would also trigger the 'selected'-class on that tab (which is wrong and out-of-sync since click() did not and should not fire). This behaviour was the case in Safari 5/Firefox 3 (Mac) and Chrome (Windows). Moving it to click() should not have any affect on the behaviour in other browsers.
Test it at: http://api.jquery.com/mousedown/
* Wrapping the hash-jump in a document.ready function.
This module is enclosed in a self-executing anonymous function to enforce private scope passing mediaWiki and jQuery. Although that, (<code>(function($,mw){ /* ... */ })(jQuery,mediaWiki);</code>) may look like a shortcut for jQuery(document).ready(), it is not. (Because both <code>;</code> and <code>jQuery(function{ /* ... */ });</code> look alike and are shortcuts). Anyway, wrapping it now to avoid it jumping too early.
* Using second argument of .each(), which is a reference to 'this'
By using that (named) variable instead there's no confusion with the other 'this' inside the click event binder – which refers to the then-clicked element (the anchor tag) rather than the legend-element.
2011-02-06 03:31:32 +00:00
|
|
|
$(legend).parent().show();
|
2011-01-10 04:47:38 +00:00
|
|
|
}
|
|
|
|
|
$( '#preftoc' ).append(
|
|
|
|
|
$( '<li></li>' )
|
|
|
|
|
.addClass( i === 0 ? 'selected' : null )
|
|
|
|
|
.append(
|
|
|
|
|
$( '<a></a>')
|
Three small fixes to mediawiki.specials.preferences.js
* Moving class-adder from mousedown() to click().
Mousedown also fires when opening the contextmenu (right-click). If I right-clicked, say, preftab-4 to open in a new tab, it would work (thanks to r81573), but it would also trigger the 'selected'-class on that tab (which is wrong and out-of-sync since click() did not and should not fire). This behaviour was the case in Safari 5/Firefox 3 (Mac) and Chrome (Windows). Moving it to click() should not have any affect on the behaviour in other browsers.
Test it at: http://api.jquery.com/mousedown/
* Wrapping the hash-jump in a document.ready function.
This module is enclosed in a self-executing anonymous function to enforce private scope passing mediaWiki and jQuery. Although that, (<code>(function($,mw){ /* ... */ })(jQuery,mediaWiki);</code>) may look like a shortcut for jQuery(document).ready(), it is not. (Because both <code>;</code> and <code>jQuery(function{ /* ... */ });</code> look alike and are shortcuts). Anyway, wrapping it now to avoid it jumping too early.
* Using second argument of .each(), which is a reference to 'this'
By using that (named) variable instead there's no confusion with the other 'this' inside the click event binder – which refers to the then-clicked element (the anchor tag) rather than the legend-element.
2011-02-06 03:31:32 +00:00
|
|
|
.text( $(legend).text() )
|
2011-02-05 21:54:56 +00:00
|
|
|
.attr( 'id', 'preftab-' + i + '-tab' )
|
|
|
|
|
.attr( 'href', '#preftab-' + i ) // Use #preftab-N instead of #prefsection-N to avoid jumping on click
|
Three small fixes to mediawiki.specials.preferences.js
* Moving class-adder from mousedown() to click().
Mousedown also fires when opening the contextmenu (right-click). If I right-clicked, say, preftab-4 to open in a new tab, it would work (thanks to r81573), but it would also trigger the 'selected'-class on that tab (which is wrong and out-of-sync since click() did not and should not fire). This behaviour was the case in Safari 5/Firefox 3 (Mac) and Chrome (Windows). Moving it to click() should not have any affect on the behaviour in other browsers.
Test it at: http://api.jquery.com/mousedown/
* Wrapping the hash-jump in a document.ready function.
This module is enclosed in a self-executing anonymous function to enforce private scope passing mediaWiki and jQuery. Although that, (<code>(function($,mw){ /* ... */ })(jQuery,mediaWiki);</code>) may look like a shortcut for jQuery(document).ready(), it is not. (Because both <code>;</code> and <code>jQuery(function{ /* ... */ });</code> look alike and are shortcuts). Anyway, wrapping it now to avoid it jumping too early.
* Using second argument of .each(), which is a reference to 'this'
By using that (named) variable instead there's no confusion with the other 'this' inside the click event binder – which refers to the then-clicked element (the anchor tag) rather than the legend-element.
2011-02-06 03:31:32 +00:00
|
|
|
.click( function() {
|
2011-01-10 04:47:38 +00:00
|
|
|
$(this).parent().parent().find( 'li' ).removeClass( 'selected' );
|
Three small fixes to mediawiki.specials.preferences.js
* Moving class-adder from mousedown() to click().
Mousedown also fires when opening the contextmenu (right-click). If I right-clicked, say, preftab-4 to open in a new tab, it would work (thanks to r81573), but it would also trigger the 'selected'-class on that tab (which is wrong and out-of-sync since click() did not and should not fire). This behaviour was the case in Safari 5/Firefox 3 (Mac) and Chrome (Windows). Moving it to click() should not have any affect on the behaviour in other browsers.
Test it at: http://api.jquery.com/mousedown/
* Wrapping the hash-jump in a document.ready function.
This module is enclosed in a self-executing anonymous function to enforce private scope passing mediaWiki and jQuery. Although that, (<code>(function($,mw){ /* ... */ })(jQuery,mediaWiki);</code>) may look like a shortcut for jQuery(document).ready(), it is not. (Because both <code>;</code> and <code>jQuery(function{ /* ... */ });</code> look alike and are shortcuts). Anyway, wrapping it now to avoid it jumping too early.
* Using second argument of .each(), which is a reference to 'this'
By using that (named) variable instead there's no confusion with the other 'this' inside the click event binder – which refers to the then-clicked element (the anchor tag) rather than the legend-element.
2011-02-06 03:31:32 +00:00
|
|
|
$(this).parent().addClass( 'selected' )
|
2011-01-10 04:47:38 +00:00
|
|
|
$( '#preferences > fieldset' ).hide();
|
|
|
|
|
$( '#prefsection-' + i ).show();
|
|
|
|
|
} )
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
);
|
2010-10-28 21:01:56 +00:00
|
|
|
|
2011-02-05 21:54:56 +00:00
|
|
|
// If we've reloaded the page or followed an open-in-new-window,
|
|
|
|
|
// make the selected tab visible.
|
Three small fixes to mediawiki.specials.preferences.js
* Moving class-adder from mousedown() to click().
Mousedown also fires when opening the contextmenu (right-click). If I right-clicked, say, preftab-4 to open in a new tab, it would work (thanks to r81573), but it would also trigger the 'selected'-class on that tab (which is wrong and out-of-sync since click() did not and should not fire). This behaviour was the case in Safari 5/Firefox 3 (Mac) and Chrome (Windows). Moving it to click() should not have any affect on the behaviour in other browsers.
Test it at: http://api.jquery.com/mousedown/
* Wrapping the hash-jump in a document.ready function.
This module is enclosed in a self-executing anonymous function to enforce private scope passing mediaWiki and jQuery. Although that, (<code>(function($,mw){ /* ... */ })(jQuery,mediaWiki);</code>) may look like a shortcut for jQuery(document).ready(), it is not. (Because both <code>;</code> and <code>jQuery(function{ /* ... */ });</code> look alike and are shortcuts). Anyway, wrapping it now to avoid it jumping too early.
* Using second argument of .each(), which is a reference to 'this'
By using that (named) variable instead there's no confusion with the other 'this' inside the click event binder – which refers to the then-clicked element (the anchor tag) rather than the legend-element.
2011-02-06 03:31:32 +00:00
|
|
|
// On document ready:
|
|
|
|
|
$( function() {
|
|
|
|
|
var hash = window.location.hash;
|
|
|
|
|
if( hash.match( /^#preftab-[\d]+$/ ) ) {
|
|
|
|
|
var $tab = $( hash + '-tab' );
|
|
|
|
|
$tab.click();
|
|
|
|
|
}
|
|
|
|
|
} );
|
2011-02-05 21:54:56 +00:00
|
|
|
|
2011-01-09 18:36:05 +00:00
|
|
|
/**
|
|
|
|
|
* Given an email validity status (true, false, null) update the label CSS class
|
|
|
|
|
*/
|
2011-01-10 04:40:57 +00:00
|
|
|
var updateMailValidityLabel = function( mail ) {
|
|
|
|
|
var isValid = mw.util.validateEmail( mail ),
|
|
|
|
|
$label = $( '#mw-emailaddress-validity' );
|
2011-01-09 18:36:05 +00:00
|
|
|
|
2011-01-10 04:40:57 +00:00
|
|
|
// We allow empty address
|
|
|
|
|
if( isValid === null ) {
|
|
|
|
|
$label.text( '' ).removeClass( 'valid invalid' );
|
2011-01-09 18:36:05 +00:00
|
|
|
|
2011-01-10 04:40:57 +00:00
|
|
|
// Valid
|
|
|
|
|
} else if ( isValid ) {
|
|
|
|
|
$label.text( mw.msg( 'email-address-validity-valid' ) ).addClass( 'valid' ).removeClass( 'invalid' );
|
2010-10-29 20:44:26 +00:00
|
|
|
|
2011-01-10 04:40:57 +00:00
|
|
|
// Not valid
|
|
|
|
|
} else {
|
|
|
|
|
$label.text( mw.msg( 'email-address-validity-invalid' ) ).addClass( 'invalid' ).removeClass( 'valid' );
|
|
|
|
|
}
|
2010-10-29 20:44:26 +00:00
|
|
|
};
|
2011-01-10 04:40:57 +00:00
|
|
|
|
|
|
|
|
// Lame tip to let user know if its email is valid. See bug 22449
|
|
|
|
|
// Only bind once for 'blur' so that the user can fill it in without errors
|
|
|
|
|
// After that look at every keypress for direct feedback if it was invalid onblur
|
|
|
|
|
$( '#mw-input-wpemailaddress' ).one( 'blur', function() {
|
|
|
|
|
if ( $( '#mw-emailaddress-validity' ).length === 0 ) {
|
|
|
|
|
$(this).after( '<label for="mw-input-wpemailaddress" id="mw-emailaddress-validity"></label>' );
|
|
|
|
|
}
|
|
|
|
|
updateMailValidityLabel( $(this).val() );
|
|
|
|
|
$(this).keyup( function() {
|
|
|
|
|
updateMailValidityLabel( $(this).val() );
|
|
|
|
|
} );
|
|
|
|
|
} );
|
2011-01-31 19:33:16 +00:00
|
|
|
} )( jQuery, mediaWiki );
|