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 */ |
3 | 3 | /* |
4 | 4 | * Utilities |
5 | 5 | */ |
— | — | @@ -10,24 +10,44 @@ |
11 | 11 | /* Initialisation */ |
12 | 12 | 'initialised' : false, |
13 | 13 | 'init' : function () { |
14 | | - if (this.initialised === false){ |
| 14 | + if (this.initialised === false) { |
15 | 15 | this.initialised = true; |
16 | 16 | |
17 | 17 | |
18 | 18 | // Set tooltipAccessKeyPrefix |
19 | | - if ( is_opera ) { |
| 19 | + if (is_opera) { |
20 | 20 | this.tooltipAccessKeyPrefix = 'shift-esc-'; |
21 | | - } else if ( is_chrome ) { |
| 21 | + } else if (is_chrome) { |
22 | 22 | 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) { |
24 | 24 | 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)) { |
28 | 27 | this.tooltipAccessKeyPrefix = 'ctrl-'; |
29 | | - } else if ( is_ff2 ) { |
| 28 | + } else if (is_ff2) { |
30 | 29 | this.tooltipAccessKeyPrefix = 'alt-shift-'; |
31 | 30 | } |
| 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 | + }); |
32 | 52 | |
33 | 53 | |
34 | 54 | return true; |
— | — | @@ -59,7 +79,16 @@ |
60 | 80 | return this.rawurlencode(str).replace(/%20/g, '_').replace(/%3A/g, ':').replace(/%2F/g, '/'); |
61 | 81 | }, |
62 | 82 | |
| 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 | + }, |
63 | 91 | |
| 92 | + |
64 | 93 | /** |
65 | 94 | * Grabs the url parameter value for the given parameter |
66 | 95 | * Returns null if not found |
— | — | @@ -80,7 +109,7 @@ |
81 | 110 | /** |
82 | 111 | * Converts special characters to their HTML entities |
83 | 112 | * |
84 | | - * @param String str text to escape |
| 113 | + * @param String str text to escape |
85 | 114 | * @param Bool quotes if true escapes single and double quotes aswell (by default false) |
86 | 115 | */ |
87 | 116 | 'htmlEscape' : function (str, quotes) { |
— | — | @@ -126,7 +155,7 @@ |
127 | 156 | $nodes = $(nodeList); |
128 | 157 | } else { |
129 | 158 | // 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'); |
131 | 160 | |
132 | 161 | // these are rare enough that no such optimization is needed |
133 | 162 | this.updateTooltipAccessKeys($('input')); |
— | — | @@ -137,7 +166,7 @@ |
138 | 167 | $nodes.each(function (i) { |
139 | 168 | var tip = $(this).attr('title'); |
140 | 169 | 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]"); |
142 | 171 | $(this).attr('title', tip); |
143 | 172 | } |
144 | 173 | }); |
— | — | @@ -157,13 +186,13 @@ |
158 | 187 | * |
159 | 188 | * @example mw.util.addPortletLink('p-tb', 'http://mediawiki.org/', 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org ', 'm', '#t-print') |
160 | 189 | * |
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.) |
162 | 191 | * @param String href link URL |
163 | 192 | * @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-') |
165 | 194 | * @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 |
168 | 197 | * |
169 | 198 | * @return Node the DOM node of the new item (a LI element) or null |
170 | 199 | */ |