r75546 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75545‎ | r75546 | r75547 >
Date:15:02, 27 October 2010
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
moved jQuery.fn.enableCheckboxShiftClick to it's own file and renamed to jQuery.fn.checkboxShiftClick
Modified paths:
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/jquery/jquery.checkboxShiftClick.js (added) (history)
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.checkboxShiftClick.js
@@ -0,0 +1,27 @@
 2+/**
 3+ * jQuery checkboxShiftClick
 4+ *
 5+ * This will enable checkboxes to be checked or unchecked in a row by clicking one, holding shift and clicking another one
 6+ *
 7+ * @author Krinkle <krinklemail@gmail.com>
 8+ * @license GPL v2
 9+ */
 10+
 11+jQuery.fn.checkboxShiftClick = function( text ) {
 12+ var prevCheckbox = null;
 13+ var $box = this;
 14+ // When our boxes are clicked..
 15+ $box.click(function (e) {
 16+ // And one has been clicked before...
 17+ if (prevCheckbox !== null && e.shiftKey) {
 18+ // Check or uncheck this one and all in-between checkboxes
 19+ $box.slice(
 20+ Math.min($box.index(prevCheckbox), $box.index(e.target)),
 21+ Math.max($box.index(prevCheckbox), $box.index(e.target)) + 1
 22+ ).attr({checked: e.target.checked ? 'checked' : ''});
 23+ }
 24+ // Either way, update the prevCheckbox variable to the one clicked now
 25+ prevCheckbox = e.target;
 26+ });
 27+ return $box;
 28+};
\ No newline at end of file
Property changes on: trunk/phase3/resources/jquery/jquery.checkboxShiftClick.js
___________________________________________________________________
Added: svn:eol-style
129 + native
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js
@@ -26,22 +26,6 @@
2727 this.tooltipAccessKeyPrefix = 'alt-shift-';
2828 }
2929
30 - // Setup CheckboxShiftClick
31 - $.fn.enableCheckboxShiftClick = function () {
32 - var prevCheckbox = null;
33 - var $box = this;
34 - $box.click(function (e) {
35 - if (prevCheckbox !== null && e.shiftKey) {
36 - $box.slice(
37 - Math.min($box.index(prevCheckbox), $box.index(e.target)),
38 - Math.max($box.index(prevCheckbox), $box.index(e.target)) + 1
39 - ).attr({checked: e.target.checked ? 'checked' : ''});
40 - }
41 - prevCheckbox = e.target;
42 - });
43 - return $box;
44 - };
45 -
4630 // Prototype enhancements
4731 if (typeof String.prototype.ucFirst === 'undefined') {
4832 String.prototype.ucFirst = function () {
@@ -53,7 +37,7 @@
5438 $(function () {
5539
5640 // Enable CheckboxShiftClick
57 - $('input[type=checkbox]:not(.noshiftselect)').enableCheckboxShiftClick();
 41+ $('input[type=checkbox]:not(.noshiftselect)').checkboxShiftClick();
5842
5943 // Fill bodyContant var
6044 if ($('#bodyContent').length) {
Index: trunk/phase3/resources/Resources.php
@@ -35,6 +35,9 @@
3636 'jquery.autoEllipsis' => new ResourceLoaderFileModule(
3737 array( 'scripts' => 'resources/jquery/jquery.autoEllipsis.js' )
3838 ),
 39+ 'jquery.checkboxShiftClick' => new ResourceLoaderFileModule(
 40+ array( 'scripts' => 'resources/jquery/jquery.checkboxShiftClick.js' )
 41+ ),
3942 'jquery.client' => new ResourceLoaderFileModule(
4043 array( 'scripts' => 'resources/jquery/jquery.client.js' )
4144 ),
@@ -378,6 +381,7 @@
379382 ) ),
380383 'mediawiki.util' => new ResourceLoaderFileModule( array(
381384 'scripts' => 'resources/mediawiki.util/mediawiki.util.js',
 385+ 'dependencies' => 'jquery.checkboxShiftClick',
382386 'debugScripts' => 'resources/mediawiki.util/mediawiki.util.test.js',
383387 ) ),
384388

Comments

#Comment by Krinkle (talk | contribs)   15:04, 27 October 2010

The script originally added in r75287.

Status & tagging log