2015-08-18 00:00:26 +00:00
/ * *
2018-11-23 12:29:20 +00:00
* DO NOT EDIT THIS FILE .
* See the following change record for more information ,
* https : //www.drupal.org/node/2815083
* @ preserve
* * /
2015-08-18 00:00:26 +00:00
2016-04-20 16:56:34 +00:00
( function ( $ , Drupal , drupalSettings ) {
2015-08-18 00:00:26 +00:00
function hide ( $placeholder ) {
2018-11-23 12:29:20 +00:00
return $placeholder . closest ( '.comment-new-comments' ) . prev ( ) . addClass ( 'last' ) . end ( ) . hide ( ) ;
2015-08-18 00:00:26 +00:00
}
function remove ( $placeholder ) {
hide ( $placeholder ) . remove ( ) ;
}
function show ( $placeholder ) {
2018-11-23 12:29:20 +00:00
return $placeholder . closest ( '.comment-new-comments' ) . prev ( ) . removeClass ( 'last' ) . end ( ) . show ( ) ;
2015-08-18 00:00:26 +00:00
}
function processNodeNewCommentLinks ( $placeholders ) {
var $placeholdersToUpdate = { } ;
var fieldName = 'comment' ;
2018-11-23 12:29:20 +00:00
var $placeholder = void 0 ;
2015-08-18 00:00:26 +00:00
$placeholders . each ( function ( index , placeholder ) {
$placeholder = $ ( placeholder ) ;
var timestamp = parseInt ( $placeholder . attr ( 'data-history-node-last-comment-timestamp' ) , 10 ) ;
fieldName = $placeholder . attr ( 'data-history-node-field-name' ) ;
var nodeID = $placeholder . closest ( '[data-history-node-id]' ) . attr ( 'data-history-node-id' ) ;
var lastViewTimestamp = Drupal . history . getLastRead ( nodeID ) ;
if ( timestamp > lastViewTimestamp ) {
$placeholdersToUpdate [ nodeID ] = $placeholder ;
2018-11-23 12:29:20 +00:00
} else {
remove ( $placeholder ) ;
}
2015-08-18 00:00:26 +00:00
} ) ;
var nodeIDs = Object . keys ( $placeholdersToUpdate ) ;
if ( nodeIDs . length === 0 ) {
return ;
}
function render ( results ) {
2018-11-23 12:29:20 +00:00
Object . keys ( results || { } ) . forEach ( function ( nodeID ) {
if ( $placeholdersToUpdate . hasOwnProperty ( nodeID ) ) {
$placeholdersToUpdate [ nodeID ] . attr ( 'href' , results [ nodeID ] . first _new _comment _link ) . text ( Drupal . formatPlural ( results [ nodeID ] . new _comment _count , '1 new comment' , '@count new comments' ) ) . removeClass ( 'hidden' ) ;
2015-08-18 00:00:26 +00:00
show ( $placeholdersToUpdate [ nodeID ] ) ;
}
2018-11-23 12:29:20 +00:00
} ) ;
2015-08-18 00:00:26 +00:00
}
if ( drupalSettings . comment && drupalSettings . comment . newCommentsLinks ) {
render ( drupalSettings . comment . newCommentsLinks . node [ fieldName ] ) ;
2018-11-23 12:29:20 +00:00
} else {
2015-08-18 00:00:26 +00:00
$ . ajax ( {
url : Drupal . url ( 'comments/render_new_comments_node_links' ) ,
type : 'POST' ,
2018-11-23 12:29:20 +00:00
data : { 'node_ids[]' : nodeIDs , field _name : fieldName } ,
2015-08-18 00:00:26 +00:00
dataType : 'json' ,
success : render
} ) ;
}
}
2018-11-23 12:29:20 +00:00
Drupal . behaviors . nodeNewCommentsLink = {
attach : function attach ( context ) {
var nodeIDs = [ ] ;
var $placeholders = $ ( context ) . find ( '[data-history-node-last-comment-timestamp]' ) . once ( 'history' ) . filter ( function ( ) {
var $placeholder = $ ( this ) ;
var lastCommentTimestamp = parseInt ( $placeholder . attr ( 'data-history-node-last-comment-timestamp' ) , 10 ) ;
var nodeID = $placeholder . closest ( '[data-history-node-id]' ) . attr ( 'data-history-node-id' ) ;
if ( Drupal . history . needsServerCheck ( nodeID , lastCommentTimestamp ) ) {
nodeIDs . push ( nodeID ) ;
hide ( $placeholder ) ;
return true ;
}
remove ( $placeholder ) ;
return false ;
} ) ;
if ( $placeholders . length === 0 ) {
return ;
}
Drupal . history . fetchTimestamps ( nodeIDs , function ( ) {
processNodeNewCommentLinks ( $placeholders ) ;
} ) ;
}
} ;
} ) ( jQuery , Drupal , drupalSettings ) ;