r57389 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57388‎ | r57389 | r57390 >
Date:15:36, 5 October 2009
Author:werdna
Status:deferred
Tags:
Comment:
LiquidThreads: Turn watch / unwatch links AJAX-y. Replaces the link with a spinner while working, and then transparently refreshes just the top-level thread commands when it is done
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/View.php (modified) (history)
  • /trunk/extensions/LiquidThreads/lqt.css (modified) (history)
  • /trunk/extensions/LiquidThreads/lqt.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/lqt.css
@@ -488,3 +488,11 @@
489489 .mw-lqt-newmessages-left {
490490 width: 10em ;
491491 }
 492+
 493+.lqt-command-working {
 494+ padding: 10px !important;
 495+ margin-right: 0.6em;
 496+ background-image: url(../../skins/common/images/spinner.gif);
 497+ background-position: middle middle;
 498+ background-repeat: no-repeat;
 499+}
Index: trunk/extensions/LiquidThreads/classes/View.php
@@ -672,7 +672,7 @@
673673 wfLoadExtensionMessages( 'LiquidThreads' );
674674
675675 $messages = array( 'lqt-quote-intro', 'lqt-quote', 'lqt-ajax-updated',
676 - 'lqt-ajax-update-link' );
 676+ 'lqt-ajax-update-link', 'watch', 'unwatch' );
677677 $data = array();
678678
679679 foreach( $messages as $msg ) {
@@ -911,8 +911,10 @@
912912 $commands_html = "";
913913 } else {
914914 $lis = $this->listItemsForCommands( $this->topLevelThreadCommands( $thread ) );
 915+ $id = 'lqt-threadlevel-commands-'.$thread->id();
915916 $commands_html = Xml::tags( 'ul',
916 - array( 'class' => 'lqt_threadlevel_commands' ),
 917+ array( 'class' => 'lqt_threadlevel_commands',
 918+ 'id' => $id ),
917919 $lis );
918920 }
919921
@@ -1067,7 +1069,13 @@
10681070 wfTimestamp( TS_MW, $thread->modified() ),
10691071 array( 'id' => 'lqt-thread-modified-'.$thread->id(),
10701072 'class' => 'lqt-thread-modified' ) );
1071 - }
 1073+ }
 1074+
 1075+ // Add the thread's title
 1076+ $html .= Xml::hidden( 'lqt-thread-title-'.$thread->id(),
 1077+ $thread->title()->getPrefixedText(),
 1078+ array( 'id' => 'lqt-thread-title-'.$thread->id(),
 1079+ 'class' => 'lqt-thread-title-metadata' ) );
10721080
10731081 // Flush output to display thread
10741082 $this->output->addHTML( $html );
Index: trunk/extensions/LiquidThreads/lqt.js
@@ -485,6 +485,44 @@
486486 }, 'json' );
487487
488488 $j(this).remove();
 489+ },
 490+
 491+ 'asyncWatch' : function(e) {
 492+ var button = $j(this);
 493+ var tlcOffset = "lqt-threadlevel-commands-".length;
 494+
 495+ // Find the title of the thread
 496+ var threadLevelCommands = button.closest('.lqt_threadlevel_commands');
 497+ var threadID = threadLevelCommands.attr('id').substring( tlcOffset );
 498+ var title = $j('#lqt-thread-title-'+threadID).val();
 499+
 500+ // Check if we're watching or unwatching.
 501+ var action = '';
 502+ if ( button.hasClass( 'lqt-command-watch' ) ) {
 503+ button.removeClass( 'lqt-command-watch' );
 504+ action = 'watch';
 505+ } else if ( button.hasClass( 'lqt-command-unwatch' ) ) {
 506+ button.removeClass( 'lqt-command-unwatch' );
 507+ action = 'unwatch';
 508+ }
 509+
 510+ // Replace the watch link with a spinner
 511+ button.empty().addClass( 'lqt-command-working' );
 512+
 513+ // Do the AJAX call.
 514+ var apiParams = { 'action' : 'watch', 'title' : title, 'format' : 'json' };
 515+
 516+ if (action == 'unwatch') {
 517+ apiParams.unwatch = 'yes';
 518+ }
 519+
 520+ $j.get( wgScriptPath+'/api'+wgScriptExtension, apiParams,
 521+ function( data ) {
 522+ threadLevelCommands.load( window.location.href+' '+
 523+ '#'+threadLevelCommands.attr('id')+' > *' );
 524+ }, 'json' );
 525+
 526+ e.preventDefault();
489527 }
490528 }
491529
@@ -529,6 +567,10 @@
530568 liquidThreads.setupThread( this );
531569 } );
532570
 571+ // Live bind for unwatch/watch stuff.
 572+ $j('.lqt-command-watch').live( 'click', liquidThreads.asyncWatch );
 573+ $j('.lqt-command-unwatch').live( 'click', liquidThreads.asyncWatch );
 574+
533575 // Set up periodic update checking
534576 setInterval( liquidThreads.checkForUpdates, 60000 );
535577 } );

Follow-up revisions

RevisionCommit summaryAuthorDate
r57395Merge r57388 and r57389 (LiquidThreads AJAX watching)werdna19:35, 5 October 2009

Status & tagging log