Index: trunk/extensions/Reviews/resources/jquery.reviewRating.js |
— | — | @@ -10,7 +10,7 @@ |
11 | 11 | |
12 | 12 | var settings = $.extend( { |
13 | 13 | |
14 | | - } ); |
| 14 | + }, options ); |
15 | 15 | |
16 | 16 | return this.each( function() { |
17 | 17 | |
Index: trunk/extensions/Reviews/resources/jquery.reviewState.js |
— | — | @@ -6,89 +6,95 @@ |
7 | 7 | * @author Jeroen De Dauw <jeroendedauw at gmail dot com> |
8 | 8 | */ |
9 | 9 | |
10 | | -(function( $, mw ) { $.fn.reviewState = function() { |
| 10 | +(function( $, mw ) { $.fn.reviewState = function( options ) { |
11 | 11 | |
12 | | - var _this = this; |
13 | | - var $this = $( _this ); |
| 12 | + var settings = $.extend( { |
| 13 | + |
| 14 | + }, options ); |
14 | 15 | |
15 | | - this.linksForState = null; |
| 16 | + return this.each( function() { |
16 | 17 | |
17 | | - this.updateStateLinks = function( id, state ) { |
18 | | - $this.text( '' ); |
| 18 | + var _this = this; |
| 19 | + var $this = $( _this ); |
19 | 20 | |
20 | | - $this.attr( { |
21 | | - 'data-review-state': state |
22 | | - } ); |
| 21 | + this.linksForState = null; |
23 | 22 | |
24 | | - for ( i in this.linksForState[state] ) { |
25 | | - if ( this.linksForState[state].hasOwnProperty( i ) ) { |
26 | | - var targetState = this.linksForState[state][i]; |
27 | | - var isFirst = $this.text() === ''; |
28 | | - |
29 | | - if ( isFirst ) { |
30 | | - $this.append( mw.msg( 'reviews-state-' + state ), ' (' ); |
31 | | - } |
32 | | - else { |
33 | | - $this.append( ' | ' ); |
34 | | - } |
35 | | - |
36 | | - $this.append( $( '<a>' ).attr( { |
37 | | - 'class': 'review-flag-link', |
38 | | - 'data-target': targetState |
39 | | - } ).text( mw.msg( 'reviews-pager-change-' + targetState ) ).click( this.onLinkClick ) ); |
40 | | - } |
41 | | - } |
42 | | - |
43 | | - if ( this.linksForState[state].length > 0 ) { |
44 | | - $this.append( ')' ); |
45 | | - } |
46 | | - }; |
47 | | - |
48 | | - this.onLinkClick = function() { |
49 | | - var state = $this.attr( 'data-review-state' ); |
50 | | - var id = $this.attr( 'data-review-id' ); |
51 | | - var targetState = $( this ).attr( 'data-target' ); |
52 | | - |
53 | | - if ( confirm( mw.msg( 'reviews-pager-confirm-' + targetState ) ) ) { |
54 | | - var requestArgs = { |
55 | | - 'action': 'flagreviews', |
56 | | - 'format': 'json', |
57 | | - 'token': mw.user.tokens.get( 'editToken' ), |
58 | | - 'state': targetState, |
59 | | - 'ids': id |
60 | | - }; |
| 23 | + this.updateStateLinks = function( id, state ) { |
| 24 | + $this.text( '' ); |
61 | 25 | |
62 | | - $this.text( mw.msg( 'reviews-pager-updating' ) ); |
| 26 | + $this.attr( { |
| 27 | + 'data-review-state': state |
| 28 | + } ); |
63 | 29 | |
64 | | - $.post( |
65 | | - wgScriptPath + '/api.php', |
66 | | - requestArgs, |
67 | | - function( data ) { |
68 | | - if ( data.hasOwnProperty( 'success' ) && data.success ) { |
69 | | - _this.updateStateLinks( id, targetState ); |
| 30 | + for ( i in this.linksForState[state] ) { |
| 31 | + if ( this.linksForState[state].hasOwnProperty( i ) ) { |
| 32 | + var targetState = this.linksForState[state][i]; |
| 33 | + var isFirst = $this.text() === ''; |
| 34 | + |
| 35 | + if ( isFirst ) { |
| 36 | + $this.append( mw.msg( 'reviews-state-' + state ), ' (' ); |
70 | 37 | } |
71 | 38 | else { |
72 | | - // TODO |
73 | | - alert( 'Could not change the state of the review' ); |
74 | | - |
75 | | - _this.updateStateLinks( id, state ); |
| 39 | + $this.append( ' | ' ); |
76 | 40 | } |
| 41 | + |
| 42 | + $this.append( $( '<a>' ).attr( { |
| 43 | + 'class': 'review-flag-link', |
| 44 | + 'data-target': targetState |
| 45 | + } ).text( mw.msg( 'reviews-pager-change-' + targetState ) ).click( this.onLinkClick ) ); |
77 | 46 | } |
| 47 | + } |
| 48 | + |
| 49 | + if ( this.linksForState[state].length > 0 ) { |
| 50 | + $this.append( ')' ); |
| 51 | + } |
| 52 | + }; |
| 53 | + |
| 54 | + this.onLinkClick = function() { |
| 55 | + var state = $this.attr( 'data-review-state' ); |
| 56 | + var id = $this.attr( 'data-review-id' ); |
| 57 | + var targetState = $( this ).attr( 'data-target' ); |
| 58 | + |
| 59 | + if ( confirm( mw.msg( 'reviews-pager-confirm-' + targetState ) ) ) { |
| 60 | + var requestArgs = { |
| 61 | + 'action': 'flagreviews', |
| 62 | + 'format': 'json', |
| 63 | + 'token': mw.user.tokens.get( 'editToken' ), |
| 64 | + 'state': targetState, |
| 65 | + 'ids': id |
| 66 | + }; |
| 67 | + |
| 68 | + $this.text( mw.msg( 'reviews-pager-updating' ) ); |
| 69 | + |
| 70 | + $.post( |
| 71 | + wgScriptPath + '/api.php', |
| 72 | + requestArgs, |
| 73 | + function( data ) { |
| 74 | + if ( data.hasOwnProperty( 'success' ) && data.success ) { |
| 75 | + _this.updateStateLinks( id, targetState ); |
| 76 | + } |
| 77 | + else { |
| 78 | + // TODO |
| 79 | + alert( 'Could not change the state of the review' ); |
| 80 | + |
| 81 | + _this.updateStateLinks( id, state ); |
| 82 | + } |
| 83 | + } |
| 84 | + ); |
| 85 | + } |
| 86 | + }; |
| 87 | + |
| 88 | + this.setup = function() { |
| 89 | + this.linksForState = $.parseJSON( $this.attr( 'data-review-states' ) ); |
| 90 | + |
| 91 | + this.updateStateLinks( |
| 92 | + $this.attr( 'data-review-id' ), |
| 93 | + $this.attr( 'data-review-state' ) |
78 | 94 | ); |
79 | | - } |
80 | | - }; |
81 | | - |
82 | | - this.setup = function() { |
83 | | - this.linksForState = $.parseJSON( $this.attr( 'data-review-states' ) ); |
| 95 | + }; |
84 | 96 | |
85 | | - this.updateStateLinks( |
86 | | - $this.attr( 'data-review-id' ), |
87 | | - $this.attr( 'data-review-state' ) |
88 | | - ); |
89 | | - }; |
90 | | - |
91 | | - this.setup(); |
| 97 | + this.setup(); |
92 | 98 | |
93 | | - return this; |
| 99 | + }); |
94 | 100 | |
95 | 101 | }; })( window.jQuery, window.mediaWiki ); |
Index: trunk/extensions/Reviews/resources/reviews.pager.js |
— | — | @@ -10,10 +10,7 @@ |
11 | 11 | |
12 | 12 | $( document ).ready( function() { |
13 | 13 | |
14 | | - $.each( $( '.reviews-state-controls' ), function( i, e ) { |
15 | | - $( e ).reviewState(); |
16 | | - } ); |
17 | | - |
| 14 | + $( '.reviews-state-controls' ).reviewState(); |
18 | 15 | $( '.review-rating-display' ).reviewRating(); |
19 | 16 | |
20 | 17 | } ); |
Index: trunk/extensions/Reviews/resources/reviews.special.js |
— | — | @@ -10,9 +10,7 @@ |
11 | 11 | |
12 | 12 | $( document ).ready( function() { |
13 | 13 | |
14 | | - $.each( $( '.reviews-state-controls' ), function( i, e ) { |
15 | | - $( e ).reviewState(); |
16 | | - } ); |
| 14 | + $( '.reviews-state-controls' ).reviewState(); |
17 | 15 | |
18 | 16 | $( '.reviews-delete-button' ).button().click( function() { |
19 | 17 | if ( confirm( mw.msg( 'reviews-reviews-delete-confirm' ) ) ) { |