r65564 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65563‎ | r65564 | r65565 >
Date:08:40, 27 April 2010
Author:jojo
Status:ok
Tags:
Comment:
refactoring: use $ instead of jQuery. replace sajax_* w/ jQuery calls
Modified paths:
  • /trunk/extensions/Collection/js/bookcreator.js (modified) (history)
  • /trunk/extensions/Collection/js/collection.js (modified) (history)
  • /trunk/extensions/Collection/js/suggest.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Collection/js/bookcreator.js
@@ -21,23 +21,31 @@
2222
2323 (function($) {
2424
 25+var script_url = wgServer + ((wgScript == null) ? (wgScriptPath + "/index.php") : wgScript);
 26+
2527 function refreshBookCreatorBox(hint, oldid) {
26 - sajax_request_type = 'GET';
27 - sajax_do_call('wfAjaxCollectionGetBookCreatorBoxContent', [hint, oldid], function(xhr) {
28 - $('#coll-book_creator_box').html(xhr.responseText);
29 - });
 28+ $.get(script_url, {
 29+ 'action': 'ajax',
 30+ 'rs': 'wfAjaxCollectionGetBookCreatorBoxContent',
 31+ 'rsargs[]': [hint, oldid]
 32+ }, function(result) {
 33+ $('#coll-book_creator_box').html(result);
 34+ });
3035 }
3136
3237 function collectionCall(func, args) {
3338 var hint = args.shift();
34 - sajax_request_type = 'POST';
35 - sajax_do_call('wfAjaxCollection' + func, args, function() {
 39+ $.post(script_url, {
 40+ 'action': 'ajax',
 41+ 'rs': 'wfAjaxCollection' + func,
 42+ 'rsargs[]': args
 43+ }, function(result) {
3644 var oldid = null;
3745 if (args.length == 3) {
3846 oldid = args[2];
3947 }
4048 refreshBookCreatorBox(hint, oldid);
41 - });
 49+ });
4250 }
4351
4452 window.collectionCall = collectionCall; // public
@@ -49,7 +57,6 @@
5058 var visible = false;
5159 var show_soon_timeout = null;
5260 var get_data_xhr = null;
53 -var script_url = wgServer + ((wgScript == null) ? (wgScriptPath + "/index.php") : wgScript);
5461 var current_link = null;
5562 var title = null;
5663
Index: trunk/extensions/Collection/js/collection.js
@@ -19,10 +19,8 @@
2020 * http://www.gnu.org/copyleft/gpl.html
2121 */
2222
23 -(function() {
 23+(function($) {
2424
25 -var jQuery = collection_jQuery;
26 -
2725 /******************************************************************************/
2826
2927 var requiredVersion = '1.4';
@@ -45,20 +43,28 @@
4644 return txt;
4745 }
4846
 47+function req(func, args, callback) {
 48+ $.post(script_url, {
 49+ 'action': 'ajax',
 50+ 'rs': 'wfAjaxCollection' + func,
 51+ 'rsargs[]': args
 52+ }, callback);
 53+}
 54+
4955 var script_url = wgServer +
5056 ((wgScript == null) ? (wgScriptPath + "/index.php") : wgScript);
5157
5258 /******************************************************************************/
5359
5460 function getMWServeStatus() {
55 - jQuery.getJSON(script_url, {
 61+ $.getJSON(script_url, {
5662 'action': 'ajax',
5763 'rs': 'wfAjaxGetMWServeStatus',
5864 'rsargs[]': [collection_id, writer]
5965 }, function(result) {
6066 if (result.state == 'progress' ) {
6167 if ( result.status.progress ) {
62 - jQuery('#renderingProgress').html('' + result.status.progress);
 68+ $('#renderingProgress').html('' + result.status.progress);
6369 }
6470 if (result.status.status) {
6571 var status = result.status.status;
@@ -67,7 +73,7 @@
6874 } else if (result.status.page) {
6975 status += gettext('#renderingPage', result.status.page);
7076 }
71 - jQuery('#renderingStatus').html(gettext('#renderingStatusText', status));
 77+ $('#renderingStatus').html(gettext('#renderingStatusText', status));
7278 }
7379 setTimeout(getMWServeStatus, 500);
7480 } else {
@@ -80,13 +86,12 @@
8187
8288 function clear_collection() {
8389 if (confirm(gettext('#clearCollectionConfirmText'))) {
84 - sajax_request_type = "POST";
85 - sajax_do_call('wfAjaxCollectionClear',
 90+ req('Clear',
8691 [],
87 - function(xhr) {
88 - refresh_list(xhr);
89 - sajax_do_call('wfAjaxCollectionGetBookCreatorBoxContent', ['showbook', null], function(xhr2) {
90 - jQuery('#coll-book_creator_box').html(xhr2.responseText);
 92+ function(result) {
 93+ refresh_list(result);
 94+ req('GetBookCreatorBoxContent', ['showbook', null], function(result2) {
 95+ $('#coll-book_creator_box').html(result2);
9196 });
9297 });
9398 }
@@ -96,10 +101,7 @@
97102 function create_chapter() {
98103 var name = prompt(gettext('#newChapterText'));
99104 if (name) {
100 - sajax_request_type = "POST";
101 - sajax_do_call('wfAjaxCollectionAddChapter',
102 - [name],
103 - refresh_list);
 105+ req('AddChapter', [name], refresh_list);
104106 }
105107 return false;
106108 }
@@ -107,109 +109,103 @@
108110 function rename_chapter(index, old_name) {
109111 var new_name = prompt(gettext('#renameChapterText'), old_name);
110112 if (new_name) {
111 - sajax_request_type = "POST";
112 - sajax_do_call('wfAjaxCollectionRenameChapter',
113 - [index, new_name],
114 - refresh_list);
 113+ req('RenameChapter', [index, new_name], refresh_list);
115114 }
116115 return false;
117116 }
118117
119118 function remove_item(index) {
120 - sajax_request_type = "POST";
121 - sajax_do_call('wfAjaxCollectionRemoveItem',
 119+ req('RemoveItem',
122120 [index],
123 - function(xhr) {
124 - refresh_list(xhr);
125 - sajax_do_call('wfAjaxCollectionGetBookCreatorBoxContent', ['showbook', null], function(xhr2) {
126 - jQuery('#coll-book_creator_box').html(xhr2.responseText);
 121+ function(result) {
 122+ refresh_list(result);
 123+ req('GetBookCreatorBoxContent', ['showbook', null], function(result2) {
 124+ $('#coll-book_creator_box').html(result2);
127125 });
128126 });
129127 return false;
130128 }
131129
132130 function set_titles() {
133 - sajax_request_type = "POST";
134 - sajax_do_call('wfAjaxCollectionSetTitles',
135 - [jQuery('#titleInput').val(), jQuery('#subtitleInput').val()], function() {});
 131+ req('SetTitles',
 132+ [$('#titleInput').val(), $('#subtitleInput').val()], function() {});
136133 return false;
137134 }
138135
139136 function set_sorting(items_string) {
140 - sajax_request_type = "POST";
141 - sajax_do_call('wfAjaxCollectionSetSorting', [items_string], refresh_list);
 137+ req('SetSorting', [items_string], refresh_list);
142138 return false;
143139 }
144140
145141 function update_save_button() {
146 - if (!jQuery('#saveButton').length) {
 142+ if (!$('#saveButton').length) {
147143 return;
148144 }
149 - if (jQuery('#collectionList .article').length == 0) {
150 - jQuery('#saveButton').attr('disabled', 'disabled');
 145+ if ($('#collectionList .article').length == 0) {
 146+ $('#saveButton').attr('disabled', 'disabled');
151147 return;
152148 }
153 - if (!jQuery('#communityCollTitle').length || jQuery('#personalCollType:checked').val()) {
154 - jQuery('#personalCollTitle').attr('disabled', '');
155 - jQuery('#communityCollTitle').attr('disabled', 'disabled');
156 - if (!jQuery.trim(jQuery('#personalCollTitle').val())) {
157 - jQuery('#saveButton').attr('disabled', 'disabled');
 149+ if (!$('#communityCollTitle').length || $('#personalCollType:checked').val()) {
 150+ $('#personalCollTitle').attr('disabled', '');
 151+ $('#communityCollTitle').attr('disabled', 'disabled');
 152+ if (!$.trim($('#personalCollTitle').val())) {
 153+ $('#saveButton').attr('disabled', 'disabled');
158154 return;
159155 }
160 - } else if (!jQuery('#personalCollTitle').length || jQuery('#communityCollType:checked').val()) {
161 - jQuery('#communityCollTitle').attr('disabled', '');
162 - jQuery('#personalCollTitle').attr('disabled', 'disabled');
163 - if (!jQuery.trim(jQuery('#communityCollTitle').val())) {
164 - jQuery('#saveButton').attr('disabled', 'disabled');
 156+ } else if (!$('#personalCollTitle').length || $('#communityCollType:checked').val()) {
 157+ $('#communityCollTitle').attr('disabled', '');
 158+ $('#personalCollTitle').attr('disabled', 'disabled');
 159+ if (!$.trim($('#communityCollTitle').val())) {
 160+ $('#saveButton').attr('disabled', 'disabled');
165161 return;
166162 }
167163 }
168 - jQuery('#saveButton').attr('disabled', '');
 164+ $('#saveButton').attr('disabled', '');
169165 }
170166
171167 function make_sortable() {
172 - jQuery('#collectionList').sortable({
 168+ $('#collectionList').sortable({
173169 axis: 'y',
174170 update: function(evt, ui) {
175 - set_sorting(jQuery('#collectionList').sortable('serialize'));
 171+ set_sorting($('#collectionList').sortable('serialize'));
176172 }
177173 });
178 - jQuery('#collectionList .sortableitem').css('cursor', 'move');
 174+ $('#collectionList .sortableitem').css('cursor', 'move');
179175 }
180176
181 -function refresh_list(xhr) {
182 - jQuery('#collectionListContainer').html(xhr.responseText);
183 - jQuery('.makeVisible').css('display', 'inline');
 177+function refresh_list(html) {
 178+ $('#collectionListContainer').html(html);
 179+ $('.makeVisible').css('display', 'inline');
184180 make_sortable();
185 - if (jQuery('#collectionList .article').length == 0) {
186 - jQuery('#downloadButton').attr('disabled', 'disabled');
187 - jQuery('input.order').attr('disabled', 'disabled');
 181+ if ($('#collectionList .article').length == 0) {
 182+ $('#downloadButton').attr('disabled', 'disabled');
 183+ $('input.order').attr('disabled', 'disabled');
188184 } else {
189 - jQuery('#downloadButton').attr('disabled', '');
190 - jQuery('input.order').attr('disabled', '');
 185+ $('#downloadButton').attr('disabled', '');
 186+ $('input.order').attr('disabled', '');
191187 }
192188 update_save_button();
193189 }
194190
195191 function toggle_order_info(flag) {
196192 if (flag) {
197 - jQuery('#coll-more_info').css('display', 'none');
198 - jQuery('#coll-order_info').css('display', 'block');
199 - jQuery('#coll-hide_info').css('display', 'block');
 193+ $('#coll-more_info').css('display', 'none');
 194+ $('#coll-order_info').css('display', 'block');
 195+ $('#coll-hide_info').css('display', 'block');
200196 } else {
201 - jQuery('#coll-more_info').css('display', 'block');
202 - jQuery('#coll-order_info').css('display', 'none');
203 - jQuery('#coll-hide_info').css('display', 'none');
 197+ $('#coll-more_info').css('display', 'block');
 198+ $('#coll-order_info').css('display', 'none');
 199+ $('#coll-hide_info').css('display', 'none');
204200 }
205201 }
206202
207 -jQuery(function() {
 203+$(function() {
208204 if (requiredVersion != wgCollectionVersion) {
209205 alert('ERROR: Version mismatch between Javascript and PHP code. Contact admin to fix the installation of Collection extension for MediaWiki.');
210206 return;
211207 }
212 - if (jQuery('#collectionList').length) {
213 - jQuery('.makeVisible').css('display', 'inline');
 208+ if ($('#collectionList').length) {
 209+ $('.makeVisible').css('display', 'inline');
214210 window.coll_create_chapter = create_chapter;
215211 window.coll_remove_item = remove_item;
216212 window.coll_rename_chapter = rename_chapter;
@@ -218,18 +214,18 @@
219215 toggle_order_info(false);
220216 update_save_button();
221217 make_sortable();
222 - jQuery('#personalCollTitle').keyup(update_save_button);
223 - jQuery('#personalCollTitle').change(update_save_button);
224 - jQuery('#communityCollTitle').keyup(update_save_button);
225 - jQuery('#communityCollTitle').change(update_save_button);
226 - jQuery('#personalCollType').change(update_save_button);
227 - jQuery('#communityCollType').change(update_save_button);
228 - jQuery('#titleInput').change(set_titles);
229 - jQuery('#subtitleInput').change(set_titles);
 218+ $('#personalCollTitle').keyup(update_save_button);
 219+ $('#personalCollTitle').change(update_save_button);
 220+ $('#communityCollTitle').keyup(update_save_button);
 221+ $('#communityCollTitle').change(update_save_button);
 222+ $('#personalCollType').change(update_save_button);
 223+ $('#communityCollType').change(update_save_button);
 224+ $('#titleInput').change(set_titles);
 225+ $('#subtitleInput').change(set_titles);
230226 }
231227 if (typeof collection_rendering != 'undefined') {
232228 getMWServeStatus();
233229 }
234230 });
235231
236 -})();
 232+})(collection_jQuery);
Index: trunk/extensions/Collection/js/suggest.js
@@ -1,21 +1,19 @@
2 -(function() {
 2+(function($) {
33
4 -var jQuery = collection_jQuery;
5 -
64 var script_url = wgServer +
75 ((wgScript == null) ? (wgScriptPath + "/index.php") : wgScript);
86
97 function set_status(html) {
108 if (html) {
11 - jQuery('#collectionSuggestStatus').css('visibility', 'visible').html(html);
 9+ $('#collectionSuggestStatus').css('visibility', 'visible').html(html);
1210 } else {
13 - jQuery('#collectionSuggestStatus').css('visibility', 'hidden').html(' ');
 11+ $('#collectionSuggestStatus').css('visibility', 'hidden').html(' ');
1412 }
1513 }
1614
1715 function collectionSuggestCall(func, args) {
1816 set_status('...');
19 - jQuery.post(script_url, {
 17+ $.post(script_url, {
2018 'action': 'ajax',
2119 'rs': 'wfAjaxCollectionSuggest' + func,
2220 'rsargs[]': args
@@ -25,16 +23,20 @@
2624 } else {
2725 set_status(result.last_action);
2826 }
29 - jQuery('#collectionSuggestions').html(result.suggestions_html);
30 - jQuery('#collectionMembers').html(result.members_html);
31 - jQuery('#coll-num_pages').text(result.num_pages);
32 - sajax_do_call('wfAjaxCollectionGetBookCreatorBoxContent', ['suggest', null], function(xhr) {
33 - jQuery('#coll-book_creator_box').html(xhr.responseText);
 27+ $('#collectionSuggestions').html(result.suggestions_html);
 28+ $('#collectionMembers').html(result.members_html);
 29+ $('#coll-num_pages').text(result.num_pages);
 30+ $.get(script_url, {
 31+ 'action': 'ajax',
 32+ 'rs': 'wfAjaxCollectionGetBookCreatorBoxContent',
 33+ 'rsargs[]': ['suggest', null]
 34+ }, function(result) {
 35+ $('#coll-book_creator_box').html(result);
3436 });
3537 }, 'json');
3638 }
3739
3840 window.collectionSuggestCall = collectionSuggestCall;
3941
40 -})();
 42+})(collection_jQuery);
4143

Status & tagging log