Ticket #6541: shiftcheckbox.diff

File shiftcheckbox.diff, 4.4 KB (added by sillybean, 3 months ago)

restores ability to select consecutive checkboxes by shift-clicking

Line 
1Index: wp-includes/js/jquery/jquery.shiftcheckbox.js
2===================================================================
3--- wp-includes/js/jquery/jquery.shiftcheckbox.js       (revision 0)
4+++ wp-includes/js/jquery/jquery.shiftcheckbox.js       (revision 0)
5@@ -0,0 +1,83 @@
6+/**
7+ * JQuery shiftcheckbox plugin
8+ *
9+ * shiftcheckbox provides a simpler and faster way to select/unselect multiple checkboxes within a given range with just two clicks.
10+ * Inspired from GMail checkbox functionality
11+ *
12+ * Just call $('.<class-name>').shiftcheckbox() in $(document).ready
13+ *
14+ * @name shiftcheckbox
15+ * @type jquery
16+ * @cat Plugin/Form
17+ * @return JQuery
18+ *
19+ * @URL http://www.sanisoft.com/blog/2009/07/02/jquery-shiftcheckbox-plugin
20+ *
21+ * Copyright (c) 2009 Aditya Mooley <adityamooley@sanisoft.com>
22+ * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses
23+ */
24+
25+(function ($) {
26+    $.fn.shiftcheckbox = function()
27+    {
28+        var prevChecked = null;
29+
30+        selectorStr = this;
31+
32+        $(selectorStr).bind("click", handleClick);
33+    };
34+
35+    function handleClick(event)
36+    {
37+        var val = this.value;
38+        var checkStatus = this.checked;
39+        //get the checkbox number which the user has checked
40+
41+        //check whether user has pressed shift
42+        if (event.shiftKey) {
43+            if (prevChecked != 'null') {
44+                //get the current checkbox number
45+                var ind = 0, found = 0, currentChecked;
46+                currentChecked = getSelected(val);
47+
48+                ind = 0;
49+                if (currentChecked < prevChecked) {
50+                    $(selectorStr).each(function(i) {
51+                        if (ind >= currentChecked && ind <= prevChecked) {
52+                            this.checked = checkStatus;
53+                        }
54+                        ind++;
55+                    });
56+                } else {
57+                    $(selectorStr).each(function(i) {
58+                        if (ind >= prevChecked && ind <= currentChecked) {
59+                            this.checked = checkStatus;
60+                        }
61+                        ind++;
62+                    });
63+                }
64+
65+                prevChecked = currentChecked;
66+            }
67+        } else {
68+            if (checkStatus) {
69+                prevChecked = getSelected(val);
70+            }
71+        }
72+    };
73+
74+    function getSelected(val)
75+    {
76+        var ind = 0, found = 0, checkedIndex;
77+
78+        $(selectorStr).each(function(i) {
79+            if (val == this.value && found != 1) {
80+                checkedIndex = ind;
81+                found = 1;
82+            }
83+            ind++;
84+        });
85+
86+        return checkedIndex;
87+    };
88+})(jQuery);
89\ No newline at end of file
90Index: wp-includes/script-loader.php
91===================================================================
92--- wp-includes/script-loader.php       (revision 23386)
93+++ wp-includes/script-loader.php       (working copy)
94@@ -185,6 +185,7 @@
95        $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array('jquery', 'jquery-hotkeys'), false, 1 );
96        $scripts->add( 'jquery-touch-punch', "/wp-includes/js/jquery/jquery.ui.touch-punch.js", array('jquery-ui-widget', 'jquery-ui-mouse'), '0.2.2', 1 );
97        $scripts->add( 'jquery-masonry', "/wp-includes/js/jquery/jquery.masonry.min.js", array('jquery'), '2.1.05', 1 );
98+       $scripts->add( 'jquery-shiftcheckbox', "/wp-includes/js/jquery/jquery.shiftcheckbox.min.js", array('jquery'), false, 1 );
99 
100        $scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20121105', 1 );
101        did_action( 'init' ) && $scripts->localize( 'thickbox', 'thickboxL10n', array(
102Index: wp-admin/js/common.js
103===================================================================
104--- wp-admin/js/common.js       (revision 23386)
105+++ wp-admin/js/common.js       (working copy)
106@@ -326,6 +326,8 @@
107                        return false;
108                });
109        });
110+       
111+       $('th.check-column input').shiftcheckbox();
112 
113        $('#default-password-nag-no').click( function() {
114                setUserSetting('default_password_nag', 'hide');
115Index: wp-admin/admin-header.php
116===================================================================
117--- wp-admin/admin-header.php   (revision 23386)
118+++ wp-admin/admin-header.php   (working copy)
119@@ -45,6 +45,7 @@
120 wp_enqueue_style( 'colors' );
121 wp_enqueue_style( 'ie' );
122 wp_enqueue_script('utils');
123+wp_enqueue_script( 'jquery-shiftcheckbox' );
124 
125 $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
126 ?>