r75287 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75286‎ | r75287 | r75288 >
Date:20:12, 23 October 2010
Author:krinkle
Status:ok (Comments)
Tags:
Comment:
added mw.util.getWikilink and ported enableCheckboxShiftClick to jQuery
Modified paths:
  • /trunk/phase3/resources/mediawiki/mediawiki.util.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki/mediawiki.util.js
@@ -1,4 +1,4 @@
2 -/*jslint white: true, browser: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true */
 2+/*jslint white: true, browser: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true */
33 /*
44 * Utilities
55 */
@@ -10,24 +10,44 @@
1111 /* Initialisation */
1212 'initialised' : false,
1313 'init' : function () {
14 - if (this.initialised === false){
 14+ if (this.initialised === false) {
1515 this.initialised = true;
1616
1717
1818 // Set tooltipAccessKeyPrefix
19 - if ( is_opera ) {
 19+ if (is_opera) {
2020 this.tooltipAccessKeyPrefix = 'shift-esc-';
21 - } else if ( is_chrome ) {
 21+ } else if (is_chrome) {
2222 this.tooltipAccessKeyPrefix = is_chrome_mac ? 'ctrl-option-' : 'alt-';
23 - } else if ( !is_safari_win && is_safari && webkit_version > 526 ) {
 23+ } else if (!is_safari_win && is_safari && webkit_version > 526) {
2424 this.tooltipAccessKeyPrefix = 'ctrl-alt-';
25 - } else if ( !is_safari_win && ( is_safari
26 - || clientPC.indexOf('mac') != -1
27 - || clientPC.indexOf('konqueror') != -1 ) ) {
 25+ } else if (!is_safari_win &&
 26+ (is_safari || clientPC.indexOf('mac') !== -1 || clientPC.indexOf('konqueror') !== -1)) {
2827 this.tooltipAccessKeyPrefix = 'ctrl-';
29 - } else if ( is_ff2 ) {
 28+ } else if (is_ff2) {
3029 this.tooltipAccessKeyPrefix = 'alt-shift-';
3130 }
 31+
 32+ // Setup CheckboxShiftClick
 33+ $.fn.enableCheckboxShiftClick = function () {
 34+ var prevCheckbox = null;
 35+ var $box = this;
 36+ $box.click(function (e) {
 37+ if (prevCheckbox !== null && e.shiftKey) {
 38+ $box.slice(
 39+ Math.min($box.index(prevCheckbox), $box.index(e.target)),
 40+ Math.max($box.index(prevCheckbox), $box.index(e.target)) + 1
 41+ ).attr({checked: e.target.checked ? 'checked' : ''});
 42+ }
 43+ prevCheckbox = e.target;
 44+ });
 45+ return $box;
 46+ };
 47+
 48+ // Any initialisation after the DOM is ready
 49+ $(function () {
 50+ $('input[type=checkbox]:not(.noshiftselect)').enableCheckboxShiftClick();
 51+ });
3252
3353
3454 return true;
@@ -59,7 +79,16 @@
6080 return this.rawurlencode(str).replace(/%20/g, '_').replace(/%3A/g, ':').replace(/%2F/g, '/');
6181 },
6282
 83+ /**
 84+ * Get the full url to a pagename
 85+ *
 86+ * @param String str pagename to link to
 87+ */
 88+ 'getWikilink' : function (str) {
 89+ return wgServer + wgArticlePath.replace('$1', this.wikiUrlencode(str));
 90+ },
6391
 92+
6493 /**
6594 * Grabs the url parameter value for the given parameter
6695 * Returns null if not found
@@ -80,7 +109,7 @@
81110 /**
82111 * Converts special characters to their HTML entities
83112 *
84 - * @param String str text to escape
 113+ * @param String str text to escape
85114 * @param Bool quotes if true escapes single and double quotes aswell (by default false)
86115 */
87116 'htmlEscape' : function (str, quotes) {
@@ -126,7 +155,7 @@
127156 $nodes = $(nodeList);
128157 } else {
129158 // Rather than scanning all links, just
130 - $("#column-one a, #mw-head a, #mw-panel a, #p-logo a");
 159+ $('#column-one a, #mw-head a, #mw-panel a, #p-logo a');
131160
132161 // these are rare enough that no such optimization is needed
133162 this.updateTooltipAccessKeys($('input'));
@@ -137,7 +166,7 @@
138167 $nodes.each(function (i) {
139168 var tip = $(this).attr('title');
140169 if (!!tip && mw.util.tooltipAccessKeyRegexp.exec(tip)) {
141 - tip = tip.replace(mw.util.tooltipAccessKeyRegexp, '[' + tooltipAccessKeyPrefix + "$5]");
 170+ tip = tip.replace(mw.util.tooltipAccessKeyRegexp, '[' + mw.util.tooltipAccessKeyPrefix + "$5]");
142171 $(this).attr('title', tip);
143172 }
144173 });
@@ -157,13 +186,13 @@
158187 *
159188 * @example mw.util.addPortletLink('p-tb', 'http://mediawiki.org/', 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org ', 'm', '#t-print')
160189 *
161 - * @param String portlet id of the target portlet ("p-cactions" or "p-personal" etc.)
 190+ * @param String portlet id of the target portlet ('p-cactions' or 'p-personal' etc.)
162191 * @param String href link URL
163192 * @param String text link text (will be automatically lowercased by CSS for p-cactions in Monobook)
164 - * @param String id id of the new item, should be unique and preferably have the appropriate prefix ("ca-", "pt-", "n-" or "t-")
 193+ * @param String id id of the new item, should be unique and preferably have the appropriate prefix ('ca-', 'pt-', 'n-' or 't-')
165194 * @param String tooltip text to show when hovering over the link, without accesskey suffix
166 - * @param String accesskey accesskey to activate this link (one character, try to avoid conflicts)
167 - * @param mixed nextnode DOM node or jQuery-selector of the item that the new item should be added before, should be another item in the same list
 195+ * @param String accesskey accesskey to activate this link (one character, try to avoid conflicts. Use $('[accesskey=x').get() in the console to see if 'x' is already used.
 196+ * @param mixed nextnode DOM node or jQuery-selector of the item that the new item should be added before, should be another item in the same list will be ignored if not the so
168197 *
169198 * @return Node the DOM node of the new item (a LI element) or null
170199 */

Follow-up revisions

RevisionCommit summaryAuthorDate
r91660Removing calls to deprecated functionality in favor of the new versions. Old ...krinkle17:52, 7 July 2011

Comments

#Comment by Catrope (talk | contribs)   12:47, 27 October 2010
+				$.fn.enableCheckboxShiftClick = function () {
+					var prevCheckbox = null;
+					var $box = this;
+					$box.click(function (e) {
+						if (prevCheckbox !== null && e.shiftKey) {
+							$box.slice(
+							  Math.min($box.index(prevCheckbox), $box.index(e.target)),
+							  Math.max($box.index(prevCheckbox), $box.index(e.target)) + 1
+							).attr({checked: e.target.checked ? 'checked' : ''});
+						}
+						prevCheckbox = e.target;
+					});
+					return $box;
+				};

You should put this plugin in its own file and have mw.util depend on it.

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

Done in r75546.

Status & tagging log