Index: trunk/extensions/MarkAsHelpful/modules/ext.markAsHelpful/ext.markAsHelpful.js |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | loadItem: function( $item ) { |
38 | 38 | var props = mah.getItemProperties( $item ); |
39 | 39 | |
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 |
41 | 41 | if( $.inArray( props.item, mah.ids ) === -1 ) { |
42 | 42 | mah.ids.push(props.item); |
43 | 43 | |
— | — | @@ -93,6 +93,7 @@ |
94 | 94 | url: mw.util.wikiScript( 'api' ), |
95 | 95 | data: apiRequest, |
96 | 96 | success: function () { |
| 97 | + mah.ids.removeItemByValue(props.item); |
97 | 98 | mah.loadItem( $item ); |
98 | 99 | }, |
99 | 100 | dataType: 'json' |
— | — | @@ -118,6 +119,21 @@ |
119 | 120 | $item = $( this ).parent().parent(); |
120 | 121 | mah.markItem( $item, 'unmark' ); |
121 | 122 | } ); |
| 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 | + }; |
122 | 138 | |
123 | 139 | // Initialize MarkAsHelpful |
124 | 140 | mah.init(); |