Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / history / js / history.js
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
8 (function ($, Drupal, drupalSettings, storage) {
9   var currentUserID = parseInt(drupalSettings.user.uid, 10);
10
11   var thirtyDaysAgo = Math.round(new Date().getTime() / 1000) - 30 * 24 * 60 * 60;
12
13   var embeddedLastReadTimestamps = false;
14   if (drupalSettings.history && drupalSettings.history.lastReadTimestamps) {
15     embeddedLastReadTimestamps = drupalSettings.history.lastReadTimestamps;
16   }
17
18   Drupal.history = {
19     fetchTimestamps: function fetchTimestamps(nodeIDs, callback) {
20       if (embeddedLastReadTimestamps) {
21         callback();
22         return;
23       }
24
25       $.ajax({
26         url: Drupal.url('history/get_node_read_timestamps'),
27         type: 'POST',
28         data: { 'node_ids[]': nodeIDs },
29         dataType: 'json',
30         success: function success(results) {
31           for (var nodeID in results) {
32             if (results.hasOwnProperty(nodeID)) {
33               storage.setItem('Drupal.history.' + currentUserID + '.' + nodeID, results[nodeID]);
34             }
35           }
36           callback();
37         }
38       });
39     },
40     getLastRead: function getLastRead(nodeID) {
41       if (embeddedLastReadTimestamps && embeddedLastReadTimestamps[nodeID]) {
42         return parseInt(embeddedLastReadTimestamps[nodeID], 10);
43       }
44       return parseInt(storage.getItem('Drupal.history.' + currentUserID + '.' + nodeID) || 0, 10);
45     },
46     markAsRead: function markAsRead(nodeID) {
47       $.ajax({
48         url: Drupal.url('history/' + nodeID + '/read'),
49         type: 'POST',
50         dataType: 'json',
51         success: function success(timestamp) {
52           if (embeddedLastReadTimestamps && embeddedLastReadTimestamps[nodeID]) {
53             return;
54           }
55
56           storage.setItem('Drupal.history.' + currentUserID + '.' + nodeID, timestamp);
57         }
58       });
59     },
60     needsServerCheck: function needsServerCheck(nodeID, contentTimestamp) {
61       if (contentTimestamp < thirtyDaysAgo) {
62         return false;
63       }
64
65       if (embeddedLastReadTimestamps && embeddedLastReadTimestamps[nodeID]) {
66         return contentTimestamp > parseInt(embeddedLastReadTimestamps[nodeID], 10);
67       }
68
69       var minLastReadTimestamp = parseInt(storage.getItem('Drupal.history.' + currentUserID + '.' + nodeID) || 0, 10);
70       return contentTimestamp > minLastReadTimestamp;
71     }
72   };
73 })(jQuery, Drupal, drupalSettings, window.localStorage);