Index: trunk/extensions/FlaggedRevs/presentation/modules/flaggedrevs.js |
— | — | @@ -3,164 +3,210 @@ |
4 | 4 | * @author Aaron Schulz |
5 | 5 | * @author Krinkle <krinklemail@gmail.com> 2011 |
6 | 6 | */ |
| 7 | +( function( $ ) { |
7 | 8 | |
8 | | -window.FlaggedRevs = { |
| 9 | +var fr = { |
9 | 10 | /* Dropdown collapse timer */ |
10 | 11 | 'boxCollapseTimer': null, |
11 | 12 | |
12 | 13 | /* Startup function */ |
13 | 14 | 'init': function() { |
14 | 15 | // Enables rating detail box |
15 | | - var toggle = $('#mw-fr-revisiontoggle'); |
| 16 | + var toggle = $( '#mw-fr-revisiontoggle' ); |
| 17 | + |
16 | 18 | if ( toggle.length ) { |
17 | | - toggle.css('display','inline'); /* show toggle control */ |
18 | | - FlaggedRevs.hideBoxDetails(); /* hide the initially displayed ratings */ |
| 19 | + toggle.css( 'display', 'inline' ); // show toggle control |
| 20 | + fr.hideBoxDetails(); // hide the initially displayed ratings |
19 | 21 | } |
| 22 | + |
20 | 23 | // Bar UI: Toggle the box when the toggle is clicked |
21 | | - $('.fr-toggle-symbol#mw-fr-revisiontoggle').click( FlaggedRevs.toggleBoxDetails ); |
| 24 | + $( '.fr-toggle-symbol#mw-fr-revisiontoggle' ).click( fr.toggleBoxDetails ); |
| 25 | + |
22 | 26 | // Simple UI: Show the box on mouseOver |
23 | | - $('.fr-toggle-arrow#mw-fr-revisiontoggle').mouseover( FlaggedRevs.onBoxMouseOver ); |
24 | | - $('.flaggedrevs_short#mw-fr-revisiontag').mouseout( FlaggedRevs.onBoxMouseOut ); |
25 | | - |
| 27 | + $( '.fr-toggle-arrow#mw-fr-revisiontoggle' ).mouseover( fr.onBoxMouseOver ); |
| 28 | + $( '.flaggedrevs_short#mw-fr-revisiontag' ).mouseout( fr.onBoxMouseOut ); |
| 29 | + |
26 | 30 | // Enables diff detail box and toggle |
27 | | - toggle = $('#mw-fr-difftoggle'); |
| 31 | + toggle = $( '#mw-fr-difftoggle' ); |
28 | 32 | if ( toggle.length ) { |
29 | | - toggle.css('display','inline'); /* show toggle control */ |
30 | | - $('#mw-fr-stablediff').hide(); |
| 33 | + toggle.css( 'display', 'inline' ); // show toggle control |
| 34 | + $( '#mw-fr-stablediff' ).hide(); |
31 | 35 | } |
32 | | - toggle.children('a').click( FlaggedRevs.toggleDiff ); |
33 | | - |
| 36 | + toggle.children( 'a' ).click( fr.toggleDiff ); |
| 37 | + |
34 | 38 | // Enables log detail box and toggle |
35 | | - toggle = $('#mw-fr-logtoggle'); |
| 39 | + toggle = $( '#mw-fr-logtoggle' ); |
36 | 40 | if ( toggle.length ) { |
37 | | - toggle.css('display','inline'); /* show toggle control */ |
38 | | - $('#mw-fr-logexcerpt').hide(); |
| 41 | + toggle.css( 'display', 'inline' ); // show toggle control |
| 42 | + $( '#mw-fr-logexcerpt' ).hide(); |
39 | 43 | } |
40 | | - toggle.children('a').click( FlaggedRevs.toggleLog ); |
41 | | - |
| 44 | + toggle.children( 'a' ).click( fr.toggleLog ); |
| 45 | + |
42 | 46 | // Enables changing of save button when "review this" checkbox changes |
43 | | - $('#wpReviewEdit').click( FlaggedRevs.updateSaveButton ); |
| 47 | + $( '#wpReviewEdit' ).click( fr.updateSaveButton ); |
44 | 48 | }, |
45 | 49 | |
46 | 50 | /* Expands flag info box details */ |
47 | 51 | 'showBoxDetails': function() { |
48 | | - $('#mw-fr-revisiondetails').css('display','block'); |
| 52 | + $( '#mw-fr-revisiondetails' ).css( 'display', 'block' ); |
49 | 53 | }, |
50 | 54 | |
51 | 55 | /* Collapses flag info box details */ |
52 | | - 'hideBoxDetails': function( event ) { |
53 | | - $('#mw-fr-revisiondetails').css('display','none'); |
| 56 | + 'hideBoxDetails': function() { |
| 57 | + $( '#mw-fr-revisiondetails' ).css( 'display', 'none' ); |
54 | 58 | }, |
55 | 59 | |
56 | | - /* Toggles flag info box details for (+/-) control */ |
57 | | - 'toggleBoxDetails': function() { |
58 | | - var toggle = $('#mw-fr-revisiontoggle'); |
59 | | - var ratings = $('#mw-fr-revisiondetails'); |
| 60 | + /** |
| 61 | + * Toggles flag info box details for (+/-) control |
| 62 | + * @context {jQuery} |
| 63 | + * @param e {jQuery.Event} |
| 64 | + */ |
| 65 | + 'toggleBoxDetails': function( e ) { |
| 66 | + var toggle = $( '#mw-fr-revisiontoggle' ), |
| 67 | + ratings = $( '#mw-fr-revisiondetails' ); |
| 68 | + |
60 | 69 | if ( toggle.length && ratings.length ) { |
61 | 70 | // Collapsed -> expand |
62 | | - if ( ratings.css('display') == 'none' ) { |
63 | | - FlaggedRevs.showBoxDetails(); |
64 | | - toggle.text( mw.msg('revreview-toggle-hide') ); |
| 71 | + if ( ratings.css( 'display' ) === 'none' ) { |
| 72 | + fr.showBoxDetails(); |
| 73 | + toggle.text( mw.msg( 'revreview-toggle-hide' ) ); |
65 | 74 | // Expanded -> collapse |
66 | 75 | } else { |
67 | | - FlaggedRevs.hideBoxDetails(); |
68 | | - toggle.text( mw.msg('revreview-toggle-show') ); |
| 76 | + fr.hideBoxDetails(); |
| 77 | + toggle.text( mw.msg( 'revreview-toggle-show' ) ); |
69 | 78 | } |
70 | 79 | } |
71 | 80 | }, |
72 | 81 | |
73 | | - /* Expands flag info box details on mouseOver */ |
74 | | - 'onBoxMouseOver': function( event ) { |
75 | | - window.clearTimeout( FlaggedRevs.boxCollapseTimer ); |
76 | | - FlaggedRevs.boxCollapseTimer = null; |
77 | | - FlaggedRevs.showBoxDetails(); |
| 82 | + /** |
| 83 | + * Expands flag info box details on mouseOver |
| 84 | + * @context {jQuery} |
| 85 | + * @param e {jQuery.Event} |
| 86 | + */ |
| 87 | + 'onBoxMouseOver': function( e ) { |
| 88 | + window.clearTimeout( fr.boxCollapseTimer ); |
| 89 | + fr.boxCollapseTimer = null; |
| 90 | + fr.showBoxDetails(); |
78 | 91 | }, |
79 | 92 | |
80 | | - /* Hides flag info box details on mouseOut *except* for event bubbling */ |
81 | | - 'onBoxMouseOut': function( event ) { |
82 | | - if ( !FlaggedRevs.isMouseOutBubble( event, 'mw-fr-revisiontag' ) ) { |
83 | | - FlaggedRevs.boxCollapseTimer = window.setTimeout( FlaggedRevs.hideBoxDetails, 150 ); |
| 93 | + /** |
| 94 | + * Hides flag info box details on mouseOut *except* for event bubbling |
| 95 | + * @context {jQuery} |
| 96 | + * @param e {jQuery.Event} |
| 97 | + */ |
| 98 | + 'onBoxMouseOut': function( e ) { |
| 99 | + if ( !fr.isMouseOutBubble( e, 'mw-fr-revisiontag' ) ) { |
| 100 | + fr.boxCollapseTimer = window.setTimeout( fr.hideBoxDetails, 150 ); |
84 | 101 | } |
85 | 102 | }, |
86 | 103 | |
87 | | - /* Checks if mouseOut event is for a child of parentId */ |
88 | | - 'isMouseOutBubble': function( event, parentId ) { |
89 | | - var toNode = null; |
90 | | - if ( event.relatedTarget !== undefined ) { |
91 | | - toNode = event.relatedTarget; // FF/Opera/Safari |
92 | | - } else { |
93 | | - toNode = event.toElement; // IE |
94 | | - } |
| 104 | + /** |
| 105 | + * Checks if mouseOut event is for a child of parentId |
| 106 | + * @param e {jQuery.Event} |
| 107 | + * @param parentId {String} |
| 108 | + * @return {Boolean} True if given event object originated from a (direct or indirect) |
| 109 | + * child element of an element with an id of parentId. |
| 110 | + */ |
| 111 | + 'isMouseOutBubble': function( e, parentId ) { |
| 112 | + var toNode = e.relatedTarget; |
| 113 | + |
95 | 114 | if ( toNode ) { |
96 | 115 | var nextParent = toNode.parentNode; |
97 | 116 | while ( nextParent ) { |
98 | | - if ( nextParent.id == parentId ) { |
99 | | - return true; // event bubbling |
| 117 | + if ( nextParent.id === parentId ) { |
| 118 | + return true; |
100 | 119 | } |
101 | | - nextParent = nextParent.parentNode; // next up |
| 120 | + // next up |
| 121 | + nextParent = nextParent.parentNode; |
102 | 122 | } |
103 | 123 | } |
104 | 124 | return false; |
105 | 125 | }, |
106 | 126 | |
107 | | - /* Toggles diffs */ |
108 | | - 'toggleDiff': function() { |
109 | | - var diff = $('#mw-fr-stablediff'); |
110 | | - var toggle = $('#mw-fr-difftoggle'); |
| 127 | + /** |
| 128 | + * Toggles diffs |
| 129 | + * @context {jQuery} |
| 130 | + * @param e {jQuery.Event} |
| 131 | + */ |
| 132 | + 'toggleDiff': function( e ) { |
| 133 | + var diff = $( '#mw-fr-stablediff' ), |
| 134 | + toggle = $( '#mw-fr-difftoggle' ); |
| 135 | + |
111 | 136 | if ( diff.length && toggle.length ) { |
112 | | - if ( diff.css('display') == 'none' ) { |
| 137 | + if ( diff.css( 'display' ) === 'none' ) { |
113 | 138 | diff.show( 'slow' ); |
114 | | - toggle.children('a').text( mw.msg('revreview-diff-toggle-hide') ); |
| 139 | + toggle.children( 'a' ).text( mw.msg( 'revreview-diff-toggle-hide' ) ); |
115 | 140 | } else { |
116 | 141 | diff.hide( 'slow' ); |
117 | | - toggle.children('a').text( mw.msg('revreview-diff-toggle-show') ); |
| 142 | + toggle.children( 'a' ).text( mw.msg( 'revreview-diff-toggle-show' ) ); |
118 | 143 | } |
119 | 144 | } |
120 | 145 | }, |
121 | 146 | |
122 | | - /* Toggles log excerpts */ |
123 | | - 'toggleLog': function() { |
124 | | - var log = $('#mw-fr-logexcerpt'); |
125 | | - var toggle = $('#mw-fr-logtoggle'); |
| 147 | + /** |
| 148 | + * Toggles log excerpts |
| 149 | + * @context {jQuery} |
| 150 | + * @param e {jQuery.Event} |
| 151 | + */ |
| 152 | + 'toggleLog': function( e ) { |
| 153 | + var hideMsg, showMsg, |
| 154 | + log = $( '#mw-fr-logexcerpt' ), |
| 155 | + toggle = $( '#mw-fr-logtoggle' ); |
| 156 | + |
126 | 157 | if ( log.length && toggle.length ) { |
127 | 158 | // Two different message sets used here... |
128 | | - if ( toggle.hasClass('fr-logtoggle-details') ) { |
129 | | - var hideMsg = mw.msg('revreview-log-details-hide'); |
130 | | - var showMsg = mw.msg('revreview-log-details-show'); |
| 159 | + if ( toggle.hasClass( 'fr-logtoggle-details' ) ) { |
| 160 | + hideMsg = mw.msg( 'revreview-log-details-hide' ); |
| 161 | + showMsg = mw.msg( 'revreview-log-details-show' ); |
131 | 162 | } else { |
132 | | - var hideMsg = mw.msg('revreview-log-toggle-hide'); |
133 | | - var showMsg = mw.msg('revreview-log-toggle-show'); |
| 163 | + hideMsg = mw.msg( 'revreview-log-toggle-hide' ); |
| 164 | + showMsg = mw.msg( 'revreview-log-toggle-show' ); |
134 | 165 | } |
135 | | - if ( log.css('display') == 'none' ) { |
| 166 | + |
| 167 | + if ( log.css( 'display' ) === 'none' ) { |
136 | 168 | log.show(); |
137 | | - toggle.children('a').text( hideMsg ); |
| 169 | + toggle.children( 'a' ).text( hideMsg ); |
138 | 170 | } else { |
139 | 171 | log.hide(); |
140 | | - toggle.children('a').text( showMsg ); |
| 172 | + toggle.children( 'a' ).text( showMsg ); |
141 | 173 | } |
142 | 174 | } |
143 | 175 | }, |
144 | 176 | |
145 | | - /* Update save button when "review this" checkbox changes */ |
| 177 | + /** |
| 178 | + * Update save button when "review this" checkbox changes |
| 179 | + * @context {jQuery} |
| 180 | + * @param e {jQuery.Event} |
| 181 | + */ |
146 | 182 | 'updateSaveButton': function() { |
147 | | - var save = $('#wpSave'); |
148 | | - var checkbox = $('#wpReviewEdit'); |
149 | | - if ( save.length && checkbox.length ) { |
| 183 | + var $save = $( '#wpSave' ), |
| 184 | + $checkbox = $( '#wpReviewEdit' ); |
| 185 | + |
| 186 | + if ( $save.length && $checkbox.length ) { |
150 | 187 | // Review pending changes |
151 | | - if ( checkbox.attr('checked') ) { |
152 | | - save.val( mw.msg('savearticle') ); |
153 | | - save.attr( 'title', |
154 | | - mw.msg('tooltip-save') + ' [' + mw.msg('accesskey-save') + ']' ); |
| 188 | + if ( $checkbox.prop( 'checked' ) ) { |
| 189 | + $save |
| 190 | + .val( mw.msg( 'savearticle' ) ) |
| 191 | + .attr( 'title', |
| 192 | + mw.msg( 'tooltip-save' ) + ' [' + mw.msg( 'accesskey-save' ) + ']' |
| 193 | + ); |
155 | 194 | // Submit for review |
156 | 195 | } else { |
157 | | - save.val( mw.msg('revreview-submitedit') ); |
158 | | - save.attr( 'title', |
159 | | - mw.msg('revreview-submitedit-title') + ' [' + mw.msg('accesskey-save') + ']' ); |
| 196 | + $save |
| 197 | + .val( mw.msg( 'revreview-submitedit' ) ) |
| 198 | + .attr( 'title', |
| 199 | + mw.msg( 'revreview-submitedit-title' ) + ' [' + mw.msg( 'accesskey-save' ) + ']' |
| 200 | + ); |
160 | 201 | } |
161 | 202 | } |
162 | | - mw.util.updateTooltipAccessKeys( [ save ] ); // update accesskey in save.title |
| 203 | + mw.util.updateTooltipAccessKeys( [ $save ] ); // update accesskey in save.title |
163 | 204 | } |
164 | 205 | }; |
165 | 206 | |
166 | 207 | // Perform some onload (which is when this script is included) events: |
167 | | -FlaggedRevs.init(); |
| 208 | +fr.init(); |
| 209 | + |
| 210 | +// Expose globally |
| 211 | +window.FlaggedRevs = fr; |
| 212 | + |
| 213 | +})( jQuery ); |
\ No newline at end of file |