r55001 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55000‎ | r55001 | r55002 >
Date:10:02, 14 August 2009
Author:werdna
Status:deferred
Tags:
Comment:
Convert LiquidThreads JS to use jQuery. Now the reply forms slide in and out!
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/View.php (modified) (history)
  • /trunk/extensions/LiquidThreads/lqt.js (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/TalkpageView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/pages/TalkpageView.php
@@ -240,7 +240,11 @@
241241
242242 global $wgRequest;
243243 if ( $this->methodApplies( 'talkpage_new_thread' ) ) {
 244+ $params = array( 'class' => 'lqt-new-thread lqt-edit-form',
 245+ 'style' => 'display: none;');
 246+ $this->output->addHTML( Xml::openElement( 'div', $params ) );
244247 $this->showNewThreadForm();
 248+ $this->output->addHTML( Xml::closeElement( 'div' ) );
245249 } else {
246250 $this->showTalkpageViewOptions( $article );
247251 $newThreadLink = $this->talkpageLink( $this->title,
@@ -250,6 +254,9 @@
251255 array( 'known' ) );
252256
253257 $this->output->addHTML( Xml::tags( 'strong', null, $newThreadLink ) );
 258+
 259+ $this->output->addHTML( Xml::tags( 'div',
 260+ array( 'class' => 'lqt-new-thread lqt-edit-form' ), '' ) );
254261 }
255262
256263 $this->showSearchBox();
Index: trunk/extensions/LiquidThreads/lqt.js
@@ -1,82 +1,48 @@
22 var liquidThreads = {
33 'handleReplyLink' : function(e) {
4 - var link;
5 - if (!e) e = window.event;
6 - if (e.target) link = e.target;
7 - else if (e.srcElement) link = e.srcElement;
8 - if (link.nodeType == 3) // defeat Safari bug
9 - link = link.parentNode;
10 - link = link.parentNode; // Get the enclosing li.
 4+ e.preventDefault();
115
126 var prefixLength = "lqt-reply-id-".length;
13 - var thread_id = link.id.substring( prefixLength );
14 - var container = document.getElementById( 'lqt_thread_id_'+thread_id );
15 - var footer_cmds = getElementsByClassName( container, '*', 'lqt-thread-toolbar' )[0];
 7+ var replyLI = $j(this).closest('.lqt-command-reply')[0];
 8+ var thread_id = replyLI.id.substring( prefixLength );
 9+ var container = $j( '#lqt_thread_id_'+thread_id );
1610 var query = '&lqt_method=reply&lqt_operand='+thread_id;
1711
18 - liquidThreads.injectEditForm( query, container, footer_cmds.nextSibling, e.preload );
19 -
20 - if (e.preventDefault)
21 - e.preventDefault();
 12+ var replyDiv = $j(container).find('.lqt-reply-form')[0];
2213
 14+ liquidThreads.injectEditForm( query, replyDiv, e.preload );
 15+
2316 return false;
2417 },
2518
2619 'handleNewLink' : function(e) {
27 - var link;
28 - if (!e) e = window.event;
29 - if (e.target) link = e.target;
30 - else if (e.srcElement) link = e.srcElement;
31 - if (link.nodeType == 3) // defeat Safari bug
32 - link = link.parentNode;
33 -
 20+ e.preventDefault();
 21+
3422 var query = '&lqt_method=talkpage_new_thread';
35 - var container = document.getElementById( 'bodyContent' );
3623
37 - liquidThreads.injectEditForm( query, container, link.parentNode.nextSibling );
 24+ var container = $j('.lqt-new-thread' );
3825
39 - if (e.preventDefault)
40 - e.preventDefault();
 26+ liquidThreads.injectEditForm( query, container );
4127
4228 return false;
4329 },
4430
45 - 'injectEditForm' : function(query, container, before, preload) {
46 - var x = sajax_init_object();
47 - var url = wgServer+wgScript+'?title='+encodeURIComponent(wgPageName)+
48 - query+'&lqt_inline=1'
49 - x.open( 'get', url, true );
50 -
51 - x.onreadystatechange =
52 - function() {
53 - if (x.readyState != 4)
54 - return;
 31+ 'injectEditForm' : function(query, container, preload) {
 32+ var url = wgServer+wgScript+'?lqt_inline=1&title='+encodeURIComponent(wgPageName)+
 33+ query
5534
56 - if ( liquidThreads.currentEditForm ) {
57 - var f = liquidThreads.currentEditForm;
58 - f.parentNode.removeChild( f );
59 - }
60 -
61 - var result = x.responseText;
62 - var replyDiv = document.createElement( 'div' );
63 - replyDiv.className = 'lqt_ajax_reply_form'
64 - replyDiv.innerHTML = result;
65 -
66 - if (before) {
67 - container.insertBefore( replyDiv, before );
68 - } else {
69 - container.appendChild( replyDiv );
70 - }
71 -
72 - liquidThreads.currentEditForm = replyDiv;
73 -
74 - if (preload) {
75 - var textbox = document.getElementById( 'wpTextbox1' );
76 - textbox.value = preload;
77 - }
78 - };
 35+ $j('.lqt-reply-form').not(container).slideUp('slow');
 36+ $j('.lqt-reply-form').not(container).empty();
7937
80 - x.send( null );
 38+ $j(container).load(wgServer+wgScript, 'title='+encodeURIComponent(wgPageName)+
 39+ query+'&lqt_inline=1',
 40+ function() {
 41+ if (preload) {
 42+ $j("textarea", container)[0].value = preload;
 43+ }
 44+
 45+ $j(container).slideDown('slow');
 46+ } );
8147 },
8248
8349 //From http://clipmarks.com/clipmark/CEFC94CB-94D6-4495-A7AA-791B7355E284/
@@ -137,17 +103,8 @@
138104 },
139105
140106 'doQuote' : function(e) {
141 - if (!e) e = window.event;
142107 e.preventDefault();
143108
144 - var button;
145 - if (e.target) button = e.target;
146 - else if (e.srcElement) button = e.srcElement;
147 - if (button.nodeType == 3) // defeat Safari bug
148 - button = button.parentNode;
149 -
150 - var thread = button;
151 -
152109 // Get the post node
153110 // Keep walking up until we hit the thread node.
154111 while (thread.id.substr(0,13) != 'lqt_thread_id') {
@@ -185,54 +142,48 @@
186143 },
187144
188145 'showQuoteButtons' : function() {
189 - var elems = getElementsByClassName( document, 'div', 'lqt-thread-header-rhs' );
 146+ var elems = $j('div.lqt-thread-header-rhs');
190147
191 - var length = elems.length;
192 - for( var i = 0; i<length; ++i ) {
193 - var quoteButton = document.createElement( 'span' );
 148+ elems.each( function(i) {
 149+ var quoteButton = $j('<span></span>' );
194150 quoteButton.className = 'lqt-header-quote';
195151
196 - var text = wgLqtMessages['lqt-quote'];
197 - var textNode = document.createTextNode( text );
 152+ var link = $j('<a href="#"></a>');
 153+ link.append( wgLqtMessages['lqt-quote'] );
 154+ quoteButton.append( link );
198155
199 - var link = document.createElement( 'a' );
200 - link.href='#';
201 - link.appendChild( textNode );
202 - quoteButton.appendChild( link );
 156+ quoteButton.click( liquidThreads.doQuote );
203157
204 - addHandler( quoteButton, 'click', liquidThreads.doQuote );
205 -
206 - elems[i].insertBefore( quoteButton, elems[i].firstChild );
207 - elems[i].insertBefore( document.createTextNode( '|' ), quoteButton.nextSibling );
208 - }
 158+ this.prepend( '|' );
 159+ this.prepend( quoteButton );
 160+ } );
209161 }
210162 }
211163
212 -addOnloadHook( function() {
 164+js2AddOnloadHook( function() {
213165 // Find all the reply links
214 - var threadContainers = getElementsByClassName( document, 'div', 'lqt_thread' );
 166+ var threadContainers = $j('div.lqt_thread');
215167 var prefixLength = "lqt_thread_id_".length;
216168
217 - for( var i = 0; i < threadContainers.length; ++i ) {
218 - var container = threadContainers[i];
219 - var replyLI = getElementsByClassName( container, '*', 'lqt-command-reply' )[0];
220 - var threadId = container.id.substring( prefixLength );
 169+ threadContainers.each( function(i) {
 170+ var replyLI = $j(this).find( '.lqt-command-reply' );
 171+ var threadId = this.id.substring( prefixLength );
221172
222173 if (!replyLI) {
223 - continue;
 174+ return;
224175 }
225176
226 - replyLI.id = "lqt-reply-id-"+threadId;
227 - var replyLink = replyLI.firstChild;
 177+ replyLI[0].id = "lqt-reply-id-"+threadId;
 178+ var replyLink = replyLI.find('a');
228179
229 - addHandler( replyLink, 'click', liquidThreads.handleReplyLink );
230 - }
 180+ replyLink.click( liquidThreads.handleReplyLink );
 181+ } );
231182
232183 // Update the new thread link
233 - var newThreadLink = getElementsByClassName( document, 'a', 'lqt_start_discussion' )[0];
 184+ var newThreadLink = $j('a.lqt_start_discussion');
234185
235186 if (newThreadLink) {
236 - addHandler( newThreadLink, 'click', liquidThreads.handleNewLink );
 187+ newThreadLink.click( liquidThreads.handleNewLink );
237188 }
238189
239190 // Show quote buttons
Index: trunk/extensions/LiquidThreads/classes/View.php
@@ -851,6 +851,11 @@
852852 $this->output->addHTML( $html );
853853 $this->showReplyForm( $thread );
854854 $html = $this->unindent( $thread );
 855+ } else {
 856+ $html .= Xml::tags( 'div',
 857+ array( 'class' => 'lqt-reply-form lqt-edit-form',
 858+ 'style' => 'display: none;' ),
 859+ '' );
855860 }
856861
857862 $this->output->addHTML( $html );

Status & tagging log