Mercurial > hg > cmmr2012-drupal-site
comparison core/modules/tracker/js/tracker-history.js @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
4 * https://www.drupal.org/node/2815083 | 4 * https://www.drupal.org/node/2815083 |
5 * @preserve | 5 * @preserve |
6 **/ | 6 **/ |
7 | 7 |
8 (function ($, Drupal, window) { | 8 (function ($, Drupal, window) { |
9 Drupal.behaviors.trackerHistory = { | |
10 attach: function attach(context) { | |
11 var nodeIDs = []; | |
12 var $nodeNewPlaceholders = $(context).find('[data-history-node-timestamp]').once('history').filter(function () { | |
13 var nodeTimestamp = parseInt(this.getAttribute('data-history-node-timestamp'), 10); | |
14 var nodeID = this.getAttribute('data-history-node-id'); | |
15 if (Drupal.history.needsServerCheck(nodeID, nodeTimestamp)) { | |
16 nodeIDs.push(nodeID); | |
17 return true; | |
18 } | |
19 | |
20 return false; | |
21 }); | |
22 | |
23 var $newRepliesPlaceholders = $(context).find('[data-history-node-last-comment-timestamp]').once('history').filter(function () { | |
24 var lastCommentTimestamp = parseInt(this.getAttribute('data-history-node-last-comment-timestamp'), 10); | |
25 var nodeTimestamp = parseInt(this.previousSibling.previousSibling.getAttribute('data-history-node-timestamp'), 10); | |
26 | |
27 if (lastCommentTimestamp === nodeTimestamp) { | |
28 return false; | |
29 } | |
30 var nodeID = this.previousSibling.previousSibling.getAttribute('data-history-node-id'); | |
31 if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) { | |
32 if (nodeIDs.indexOf(nodeID) === -1) { | |
33 nodeIDs.push(nodeID); | |
34 } | |
35 return true; | |
36 } | |
37 | |
38 return false; | |
39 }); | |
40 | |
41 if ($nodeNewPlaceholders.length === 0 && $newRepliesPlaceholders.length === 0) { | |
42 return; | |
43 } | |
44 | |
45 Drupal.history.fetchTimestamps(nodeIDs, function () { | |
46 processNodeNewIndicators($nodeNewPlaceholders); | |
47 processNewRepliesIndicators($newRepliesPlaceholders); | |
48 }); | |
49 } | |
50 }; | |
51 | |
52 function processNodeNewIndicators($placeholders) { | 9 function processNodeNewIndicators($placeholders) { |
53 var newNodeString = Drupal.t('new'); | 10 var newNodeString = Drupal.t('new'); |
54 var updatedNodeString = Drupal.t('updated'); | 11 var updatedNodeString = Drupal.t('updated'); |
55 | 12 |
56 $placeholders.each(function (index, placeholder) { | 13 $placeholders.each(function (index, placeholder) { |
95 } | 52 } |
96 }); | 53 }); |
97 } | 54 } |
98 }); | 55 }); |
99 } | 56 } |
57 | |
58 Drupal.behaviors.trackerHistory = { | |
59 attach: function attach(context) { | |
60 var nodeIDs = []; | |
61 var $nodeNewPlaceholders = $(context).find('[data-history-node-timestamp]').once('history').filter(function () { | |
62 var nodeTimestamp = parseInt(this.getAttribute('data-history-node-timestamp'), 10); | |
63 var nodeID = this.getAttribute('data-history-node-id'); | |
64 if (Drupal.history.needsServerCheck(nodeID, nodeTimestamp)) { | |
65 nodeIDs.push(nodeID); | |
66 return true; | |
67 } | |
68 | |
69 return false; | |
70 }); | |
71 | |
72 var $newRepliesPlaceholders = $(context).find('[data-history-node-last-comment-timestamp]').once('history').filter(function () { | |
73 var lastCommentTimestamp = parseInt(this.getAttribute('data-history-node-last-comment-timestamp'), 10); | |
74 var nodeTimestamp = parseInt(this.previousSibling.previousSibling.getAttribute('data-history-node-timestamp'), 10); | |
75 | |
76 if (lastCommentTimestamp === nodeTimestamp) { | |
77 return false; | |
78 } | |
79 var nodeID = this.previousSibling.previousSibling.getAttribute('data-history-node-id'); | |
80 if (Drupal.history.needsServerCheck(nodeID, lastCommentTimestamp)) { | |
81 if (nodeIDs.indexOf(nodeID) === -1) { | |
82 nodeIDs.push(nodeID); | |
83 } | |
84 return true; | |
85 } | |
86 | |
87 return false; | |
88 }); | |
89 | |
90 if ($nodeNewPlaceholders.length === 0 && $newRepliesPlaceholders.length === 0) { | |
91 return; | |
92 } | |
93 | |
94 Drupal.history.fetchTimestamps(nodeIDs, function () { | |
95 processNodeNewIndicators($nodeNewPlaceholders); | |
96 processNewRepliesIndicators($newRepliesPlaceholders); | |
97 }); | |
98 } | |
99 }; | |
100 })(jQuery, Drupal, window); | 100 })(jQuery, Drupal, window); |