r104861 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104860‎ | r104861 | r104862 >
Date:15:28, 1 December 2011
Author:rsterbin
Status:deferred
Tags:
Comment:
Consolidated tooltip building into its own helper method
Cleaned up fold marking and rearranged methods for clarity
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/modules/jquery.articleFeedbackv5/jquery.articleFeedbackv5.js
@@ -133,7 +133,7 @@
134134 $.articleFeedbackv5.feedbackId = 0;
135135
136136 // }}}
137 - // {{{ Templates shared by multiple buckets/ctas
 137+ // {{{ Templates
138138
139139 $.articleFeedbackv5.templates = {
140140
@@ -245,14 +245,9 @@
246246 // Start up the block to return
247247 var $block = $( $.articleFeedbackv5.currentBucket().templates.block );
248248
249 - // Add the help tooltip to the title
250 - $block.find( '.title-wrap' )
251 - .append( $.articleFeedbackv5.templates.helpToolTip )
252 - .append( $.articleFeedbackv5.templates.clear );
 249+ // Add the help button
 250+ $.articleFeedbackv5.addHelpButton( $block );
253251
254 - // Start out the tooltip hidden
255 - $block.find( '.articleFeedbackv5-tooltip' ).hide();
256 -
257252 // Fill in the disclosure text
258253 $block.find( '.articlefeedbackv5-shared-on-feedback' )
259254 .html( $.articleFeedbackv5.buildLink(
@@ -295,11 +290,6 @@
296291 */
297292 bindEvents: function ( $block ) {
298293
299 - // Tooltip
300 - $block.find( '.articleFeedbackv5-tooltip-trigger' ).click( function () {
301 - $.articleFeedbackv5.find( '.articleFeedbackv5-tooltip' ).toggle();
302 - } );
303 -
304294 // Enable submission and switch out the comment default on toggle selection
305295 $block.find( '.articleFeedbackv5-button-placeholder' )
306296 .click( function ( e ) {
@@ -514,17 +504,11 @@
515505 $tag.appendTo( $( this ) );
516506 }
517507 $( $.articleFeedbackv5.templates.clear ).appendTo( $( this ) );
518 -
519508 } );
520509
521 - // Add the help tooltip to the title
522 - $block.find( '.title-wrap' )
523 - .append( $.articleFeedbackv5.templates.helpToolTip )
524 - .append( $.articleFeedbackv5.templates.clear );
 510+ // Add the help button
 511+ $.articleFeedbackv5.addHelpButton( $block );
525512
526 - // Start out the tooltip hidden
527 - $block.find( '.articleFeedbackv5-tooltip' ).hide();
528 -
529513 // Fill in the disclosure text
530514 $block.find( '.articlefeedbackv5-shared-on-feedback' )
531515 .html( $.articleFeedbackv5.buildLink(
@@ -567,11 +551,6 @@
568552 */
569553 bindEvents: function ( $block ) {
570554
571 - // Tooltip
572 - $block.find( '.articleFeedbackv5-tooltip-trigger' ).click( function () {
573 - $.articleFeedbackv5.find( '.articleFeedbackv5-tooltip' ).toggle();
574 - } );
575 -
576555 // Enable submission and switch out the comment default on toggle selection
577556 $block.find( '.articleFeedbackv5-tags li' )
578557 .click( function ( e ) {
@@ -775,14 +754,9 @@
776755 // Start up the block to return
777756 var $block = $( $.articleFeedbackv5.currentBucket().templates.block );
778757
779 - // Add the help tooltip to the title
780 - $block.find( '.title-wrap' )
781 - .append( $.articleFeedbackv5.templates.helpToolTip )
782 - .append( $.articleFeedbackv5.templates.clear );
 758+ // Add the help button
 759+ $.articleFeedbackv5.addHelpButton( $block );
783760
784 - // Start out the tooltip hidden
785 - $block.find( '.articleFeedbackv5-tooltip' ).hide();
786 -
787761 // Fill in the rating clear title
788762 var clear_msg = mw.msg( 'articlefeedbackv5-bucket3-clear-rating' );
789763 $block.find( '.articleFeedback-rating-clear' )
@@ -835,11 +809,6 @@
836810 */
837811 bindEvents: function ( $block ) {
838812
839 - // Tooltip
840 - $block.find( '.articleFeedbackv5-tooltip-trigger' ).click( function () {
841 - $.articleFeedbackv5.$holder.find( '.articleFeedbackv5-tooltip' ).toggle();
842 - } );
843 -
844813 // Set up rating behavior
845814 var rlabel = $block.find( '.articleFeedbackv5-rating-label' );
846815 rlabel.hover( function () {
@@ -1040,14 +1009,9 @@
10411010 // Start up the block to return
10421011 var $block = $( $.articleFeedbackv5.currentBucket().templates.block );
10431012
1044 - // Add the help tooltip to the title
1045 - $block.find( '.title-wrap' )
1046 - .append( $.articleFeedbackv5.templates.helpToolTip )
1047 - .append( $.articleFeedbackv5.templates.clear );
 1013+ // Add the help button
 1014+ $.articleFeedbackv5.addHelpButton( $block );
10481015
1049 - // Start out the tooltip hidden
1050 - $block.find( '.articleFeedbackv5-tooltip' ).hide();
1051 -
10521016 // Fill in the learn to edit link
10531017 $block.find( '.articleFeedbackv5-learn-to-edit' )
10541018 .attr( 'href', mw.config.get( 'wgArticleFeedbackv5LearnToEdit' ) );
@@ -1073,23 +1037,6 @@
10741038 .addClass( 'ui-button-blue' )
10751039
10761040 return $block;
1077 - },
1078 -
1079 - // }}}
1080 - // {{{ bindEvents
1081 -
1082 - /**
1083 - * Binds any events
1084 - *
1085 - * @param $block element the form block
1086 - */
1087 - bindEvents: function ( $block ) {
1088 -
1089 - // Tooltip
1090 - $block.find( '.articleFeedbackv5-tooltip-trigger' ).click( function () {
1091 - $.articleFeedbackv5.$holder.find( '.articleFeedbackv5-tooltip' ).toggle();
1092 - } );
1093 -
10941041 }
10951042
10961043 // }}}
@@ -1842,6 +1789,8 @@
18431790 // }}}
18441791 // {{{ Initialization
18451792
 1793+ // {{{ init
 1794+
18461795 /**
18471796 * Initializes the object
18481797 *
@@ -1870,6 +1819,9 @@
18711820 } );
18721821 };
18731822
 1823+ // }}}
 1824+ // {{{ selectBucket
 1825+
18741826 /**
18751827 * Chooses a bucket and loads the appropriate form
18761828 *
@@ -1909,8 +1861,12 @@
19101862 };
19111863
19121864 // }}}
 1865+
 1866+ // }}}
19131867 // {{{ Utility methods
19141868
 1869+ // {{{ prefix
 1870+
19151871 /**
19161872 * Utility method: Prefixes a key for cookies or events with extension and
19171873 * version information
@@ -1923,6 +1879,9 @@
19241880 return 'ext.articleFeedbackv5@' + version + '-' + key;
19251881 };
19261882
 1883+ // }}}
 1884+ // {{{ currentBucket
 1885+
19271886 /**
19281887 * Utility method: Get the current bucket
19291888 *
@@ -1932,6 +1891,9 @@
19331892 return $.articleFeedbackv5.buckets[$.articleFeedbackv5.bucketId];
19341893 };
19351894
 1895+ // }}}
 1896+ // {{{ currentCTA
 1897+
19361898 /**
19371899 * Utility method: Get the current CTA
19381900 *
@@ -1941,7 +1903,31 @@
19421904 return $.articleFeedbackv5.ctas[$.articleFeedbackv5.ctaId];
19431905 };
19441906
 1907+ // }}}
 1908+ // {{{ addHelpButton
 1909+
19451910 /**
 1911+ * Utility method: add a help button to the titlebar (with bound event)
 1912+ *
 1913+ * @param Element $block the form block
 1914+ */
 1915+ $.articleFeedbackv5.addHelpButton = function ( $block ) {
 1916+ // Add the help tooltip to the title
 1917+ $block.find( '.title-wrap' )
 1918+ .append( $.articleFeedbackv5.templates.helpToolTip )
 1919+ .append( $.articleFeedbackv5.templates.clear );
 1920+ // Start out the tooltip hidden
 1921+ $block.find( '.articleFeedbackv5-tooltip' ).hide();
 1922+ // Toogle on click
 1923+ $block.find( '.articleFeedbackv5-tooltip-trigger' ).click( function () {
 1924+ $.articleFeedbackv5.find( '.articleFeedbackv5-tooltip' ).toggle();
 1925+ } );
 1926+ };
 1927+
 1928+ // }}}
 1929+ // {{{ buildLink
 1930+
 1931+ /**
19461932 * Utility method: Build a link from a href and message keys for the full
19471933 * text (with $1 where the link goes) and link text
19481934 *
@@ -1977,6 +1963,9 @@
19781964 return full;
19791965 };
19801966
 1967+ // }}}
 1968+ // {{{ enableSubmission
 1969+
19811970 /**
19821971 * Utility method: Enables or disables submission of the form
19831972 *
@@ -1994,6 +1983,9 @@
19951984 }
19961985 };
19971986
 1987+ // }}}
 1988+ // {{{ find
 1989+
19981990 /**
19991991 * Utility method: Find an element, whether it's in the dialog or not
20001992 *
@@ -2009,8 +2001,12 @@
20102002 };
20112003
20122004 // }}}
2013 - // {{{ Form loading methods
20142005
 2006+ // }}}
 2007+ // {{{ Process methods
 2008+
 2009+ // {{{ loadForm
 2010+
20152011 /**
20162012 * Build the form and load it into the document
20172013 */
@@ -2065,7 +2061,7 @@
20662062 };
20672063
20682064 // }}}
2069 - // {{{ Form submission methods
 2065+ // {{{ submitForm
20702066
20712067 /**
20722068 * Submits the form
@@ -2163,54 +2159,29 @@
21642160 };
21652161
21662162 // }}}
2167 - // {{{ Outside interaction methods
 2163+ // {{{ showCTA
21682164
21692165 /**
2170 - * Sets the link ID
2171 - *
2172 - * @param int linkId the link ID
 2166+ * Shows a CTA
21732167 */
2174 - $.articleFeedbackv5.setLinkId = function ( linkId ) {
2175 - var knownLinks = { '0': true, '1': true, '2': true, '3': true, '4': true };
2176 - if ( linkId in knownLinks ) {
2177 - $.articleFeedbackv5.linkId = linkId + '';
 2168+ $.articleFeedbackv5.showCTA = function () {
 2169+ var cta = $.articleFeedbackv5.currentCTA();
 2170+ if ( !( 'build' in cta ) ) {
 2171+ return;
21782172 }
2179 - };
2180 -
2181 - /**
2182 - * Opens the feedback tool as a modal window
2183 - *
2184 - * @param linkId string the link ID to set on open
2185 - */
2186 - $.articleFeedbackv5.openAsModal = function ( linkId ) {
2187 - $.articleFeedbackv5.setLinkId( linkId );
2188 - if ( !$.articleFeedbackv5.isLoaded ) {
2189 - $.articleFeedbackv5.loadForm();
 2173+ var $block = cta.build();
 2174+ if ( 'bindEvents' in cta ) {
 2175+ cta.bindEvents( $block );
21902176 }
2191 - if ( !$.articleFeedbackv5.inDialog ) {
2192 - $inner = $.articleFeedbackv5.$holder.find( '.articleFeedbackv5-panel' ).detach();
2193 - $.articleFeedbackv5.$dialog.append( $inner );
2194 - $.articleFeedbackv5.setLinkId( linkId );
2195 - $.articleFeedbackv5.$dialog.dialog( 'open' );
2196 - $.articleFeedbackv5.inDialog = true;
2197 - }
 2177+ $.articleFeedbackv5.$holder.html( $block );
21982178 };
21992179
2200 - /**
2201 - * Closes the feedback tool as a modal window
2202 - */
2203 - $.articleFeedbackv5.closeAsModal = function () {
2204 - if ( $.articleFeedbackv5.inDialog ) {
2205 - $.articleFeedbackv5.setLinkId( '0' );
2206 - $inner = $.articleFeedbackv5.$dialog.find( '.articleFeedbackv5-panel' ).detach();
2207 - $.articleFeedbackv5.$holder.append( $inner );
2208 - $.articleFeedbackv5.inDialog = false;
2209 - }
2210 - };
2211 -
22122180 // }}}
 2181+ // }}}
22132182 // {{{ UI methods
22142183
 2184+ // {{{ markShowstopperError
 2185+
22152186 /**
22162187 * Marks a showstopper error
22172188 *
@@ -2233,6 +2204,9 @@
22342205 veil.show();
22352206 };
22362207
 2208+ // }}}
 2209+ // {{{ lockForm
 2210+
22372211 /**
22382212 * Locks the form
22392213 */
@@ -2242,6 +2216,9 @@
22432217 $.articleFeedbackv5.$holder.find( '.articleFeedbackv5-lock' ).show();
22442218 };
22452219
 2220+ // }}}
 2221+ // {{{ unlockForm
 2222+
22462223 /**
22472224 * Unlocks the form
22482225 */
@@ -2252,25 +2229,65 @@
22532230 };
22542231
22552232 // }}}
2256 - // {{{ CTA methods
22572233
 2234+ // }}}
 2235+ // {{{ Outside interaction methods
 2236+
 2237+ // {{{ setLinkId
 2238+
22582239 /**
2259 - * Shows a CTA
 2240+ * Sets the link ID
 2241+ *
 2242+ * @param int linkId the link ID
22602243 */
2261 - $.articleFeedbackv5.showCTA = function () {
2262 - var cta = $.articleFeedbackv5.currentCTA();
2263 - if ( !( 'build' in cta ) ) {
2264 - return;
 2244+ $.articleFeedbackv5.setLinkId = function ( linkId ) {
 2245+ var knownLinks = { '0': true, '1': true, '2': true, '3': true, '4': true };
 2246+ if ( linkId in knownLinks ) {
 2247+ $.articleFeedbackv5.linkId = linkId + '';
22652248 }
2266 - var $block = cta.build();
2267 - if ( 'bindEvents' in cta ) {
2268 - cta.bindEvents( $block );
 2249+ };
 2250+
 2251+ // }}}
 2252+ // {{{ openAsModal
 2253+
 2254+ /**
 2255+ * Opens the feedback tool as a modal window
 2256+ *
 2257+ * @param linkId string the link ID to set on open
 2258+ */
 2259+ $.articleFeedbackv5.openAsModal = function ( linkId ) {
 2260+ $.articleFeedbackv5.setLinkId( linkId );
 2261+ if ( !$.articleFeedbackv5.isLoaded ) {
 2262+ $.articleFeedbackv5.loadForm();
22692263 }
2270 - $.articleFeedbackv5.$holder.html( $block );
 2264+ if ( !$.articleFeedbackv5.inDialog ) {
 2265+ $inner = $.articleFeedbackv5.$holder.find( '.articleFeedbackv5-panel' ).detach();
 2266+ $.articleFeedbackv5.$dialog.append( $inner );
 2267+ $.articleFeedbackv5.setLinkId( linkId );
 2268+ $.articleFeedbackv5.$dialog.dialog( 'open' );
 2269+ $.articleFeedbackv5.inDialog = true;
 2270+ }
22712271 };
22722272
22732273 // }}}
 2274+ // {{{ closeAsModal
22742275
 2276+ /**
 2277+ * Closes the feedback tool as a modal window
 2278+ */
 2279+ $.articleFeedbackv5.closeAsModal = function () {
 2280+ if ( $.articleFeedbackv5.inDialog ) {
 2281+ $.articleFeedbackv5.setLinkId( '0' );
 2282+ $inner = $.articleFeedbackv5.$dialog.find( '.articleFeedbackv5-panel' ).detach();
 2283+ $.articleFeedbackv5.$holder.append( $inner );
 2284+ $.articleFeedbackv5.inDialog = false;
 2285+ }
 2286+ };
 2287+
 2288+ // }}}
 2289+
 2290+ // }}}
 2291+
22752292 // }}}
22762293 // {{{ articleFeedbackv5 plugin
22772294

Status & tagging log