mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 17:51:09 +00:00
Merge "Set rootNode for items from in ThreadItemSet#newFromAnnotatedNodes"
This commit is contained in:
commit
58a9deb531
|
@ -51,10 +51,11 @@ OO.initClass( ThreadItem );
|
|||
* Create a new ThreadItem from a JSON serialization
|
||||
*
|
||||
* @param {string|Object} json JSON serialization or hash object
|
||||
* @param {HTMLElement} rootNode
|
||||
* @return {ThreadItem}
|
||||
* @throws {Error} Unknown ThreadItem type
|
||||
*/
|
||||
ThreadItem.static.newFromJSON = function ( json ) {
|
||||
ThreadItem.static.newFromJSON = function ( json, rootNode ) {
|
||||
// The page can be served from the HTTP cache (Varnish), and the JSON may be generated
|
||||
// by an older version of our PHP code. Code below must be able to handle that.
|
||||
// See ThreadItem::jsonSerialize() in PHP.
|
||||
|
@ -92,6 +93,8 @@ ThreadItem.static.newFromJSON = function ( json ) {
|
|||
item.name = hash.name;
|
||||
item.id = hash.id;
|
||||
|
||||
item.rootNode = rootNode;
|
||||
|
||||
var idEscaped = $.escapeSelector( item.id );
|
||||
var startMarker = document.getElementById( item.id );
|
||||
var endMarker = document.querySelector( '[data-mw-comment-end="' + idEscaped + '"]' );
|
||||
|
|
|
@ -21,11 +21,12 @@ OO.initClass( ThreadItemSet );
|
|||
* Created a ThreadItemSet from DOM nodes that have been annotated by the PHP CommentFormatter with
|
||||
* metadata about the thread structure.
|
||||
*
|
||||
* @param {HTMLElement} nodes
|
||||
* @param {HTMLElement[]} nodes
|
||||
* @param {HTMLElement} rootNode
|
||||
* @param {mw.dt.Parser} parser
|
||||
* @return {ThreadItemSet}
|
||||
*/
|
||||
ThreadItemSet.static.newFromAnnotatedNodes = function ( nodes, parser ) {
|
||||
ThreadItemSet.static.newFromAnnotatedNodes = function ( nodes, rootNode, parser ) {
|
||||
var result = new ThreadItemSet();
|
||||
|
||||
// The page can be served from the HTTP cache (Varnish), containing data-mw-comment generated
|
||||
|
@ -41,7 +42,7 @@ ThreadItemSet.static.newFromAnnotatedNodes = function ( nodes, parser ) {
|
|||
// Create ThreadItem objects with basic data
|
||||
for ( i = 0; i < nodes.length; i++ ) {
|
||||
var hash = JSON.parse( nodes[ i ].getAttribute( 'data-mw-comment' ) );
|
||||
item = ThreadItem.static.newFromJSON( hash );
|
||||
item = ThreadItem.static.newFromJSON( hash, rootNode );
|
||||
result.addThreadItem( item );
|
||||
|
||||
// Store info for second pass
|
||||
|
|
|
@ -254,7 +254,7 @@ function init( $container, state ) {
|
|||
var parser = new Parser( require( './parser/data.json' ) );
|
||||
|
||||
var commentNodes = $pageContainer[ 0 ].querySelectorAll( '[data-mw-comment]' );
|
||||
pageThreads = ThreadItemSet.static.newFromAnnotatedNodes( commentNodes, parser );
|
||||
pageThreads = ThreadItemSet.static.newFromAnnotatedNodes( commentNodes, $pageContainer[ 0 ], parser );
|
||||
|
||||
if ( featuresEnabled.topicsubscription ) {
|
||||
topicSubscriptions.initTopicSubscriptions( $container, pageThreads );
|
||||
|
|
Loading…
Reference in a new issue