r107093 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107092‎ | r107093 | r107094 >
Date:19:16, 22 December 2011
Author:rmoen
Status:resolved (Comments)
Tags:
Comment:
added method to remove item from array by value to solve bug with reloading item, follow up r107081
Modified paths:
  • /trunk/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js
@@ -36,7 +36,7 @@
3737 loadItem: function( $item ) {
3838 var props = mah.getItemProperties( $item );
3939
40 - //only inject once per item id to preveny copy & paste of hook in pages
 40+ //only inject once per item id to prevent loading mutiple of the same hook
4141 if( $.inArray( props.item, mah.ids ) === -1 ) {
4242 mah.ids.push(props.item);
4343
@@ -93,6 +93,7 @@
9494 url: mw.util.wikiScript( 'api' ),
9595 data: apiRequest,
9696 success: function () {
 97+ mah.ids.removeItemByValue(props.item);
9798 mah.loadItem( $item );
9899 },
99100 dataType: 'json'
@@ -118,6 +119,21 @@
119120 $item = $( this ).parent().parent();
120121 mah.markItem( $item, 'unmark' );
121122 } );
 123+
 124+ /*
 125+ * function removeItemByValue
 126+ * removes an item from array by value
 127+ */
 128+ Array.prototype.removeItemByValue= function(){
 129+ var what, a= arguments, L= a.length, ax;
 130+ while(L && this.length){
 131+ what= a[--L];
 132+ while((ax= this.indexOf(what))!= -1){
 133+ this.splice(ax, 1);
 134+ }
 135+ }
 136+ return this;
 137+ };
122138
123139 // Initialize MarkAsHelpful
124140 mah.init();

Follow-up revisions

RevisionCommit summaryAuthorDate
r107102reworked last commit to filter prior to load method, fix ie7 cache problem wi...rmoen19:57, 22 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107081added gender support for x thinks this helpful. follow up r106743rmoen18:10, 22 December 2011

Comments

#Comment by Catrope (talk | contribs)   19:28, 22 December 2011

Please don't add stuff to Array.prototype . You should be able to fix this bug by just removing the duplication guard, it looks like it's unnecessary. Or use an object like var used = {}; used[123] = true; if ( id in used ) ....

#Comment by Nikerabbit (talk | contribs)   13:53, 23 December 2011

Did you really mean r107081?

Status & tagging log