PageSourceSearch

https://www.saskatoon.ca/modules/saskatoon_ca/saskatoon_real_time/js/realtime-feed.js?v=1.x

js saskatoon.ca collected 2026-10-01 11:28:58 UTC 3,326 bytes, 133 lines download raw bytes

1(function($, drupalSettings){
2  var requestInProgress = false;
3
4  function RealTimeFeed(options) {
5    this.options = options;
6    this.refreshInterval = this.options.refresh || 5000;
7    this.$el = this.options.el;
8    this.$el.on('click', '[data-action="toggle"]', $.proxy(this._handleClick, this));
9  }
10
11  /********
12   PUBLIC
13   *********/
14  RealTimeFeed.prototype.init = function() {
15    // setInterval($.proxy(this._poll, this), this.refreshInterval);
16     this._poll();
17  };
18
19  /********
20   PRIVATE
21   *********/
22  RealTimeFeed.prototype._poll = function() {
23    if (requestInProgress) {
24      return;
25    }
26    requestInProgress = true;
27    var dateCurrent = new Date();
28    var timestamp = dateCurrent.getTime();
29    var ajax = $.ajax({
30      url: '/' + drupalSettings.COS.realtimeFeedPath,
31      cache: false,
32    });
33    ajax.done($.proxy(this._pollDone, this));
34    ajax.fail($.proxy(this._pollFail, this));
35  };
36
37  RealTimeFeed.prototype._pollDone = function(data) {
38    this._replaceContent(data.markup);
39    this._replaceTicker();
40    requestInProgress = false;
41  };
42
43  RealTimeFeed.prototype._pollFail = function() {
44    requestInProgress = false;
45  };
46
47  RealTimeFeed.prototype._replaceContent = function(data) {
48    this.$el.find('.realtimefeed-content').replaceWith(data);
49  };
50
51  RealTimeFeed.prototype._replaceTicker = function() {
52
53    var $tabpanels = this.$el.find('[role="tabpanel"]');
54
55      this.$el.find('.realtimefeed-content section').each(function (index) {
56
57      var $icon, html;
58      var $srcItem = $(this).find('li:first-child');
59
60      if ($srcItem.length) {
61        // item found
62        $icon = $srcItem.find('i').clone();
63        if(!$icon.length){
64          //check for custom icon
65          $icon = $srcItem.find('.custom-icon-svg').clone();
66        }
67        if($srcItem.hasClass('twitter-item')){
68          html = $srcItem.find('.tweet-homepage-text').html();
69        } else{
70          html = $srcItem.find('.title').html();
71        }
72      } else {
73        // item not found
74        var icon = '';
75        switch (index) {
76          case 0:
77            icon = 'unknown';
78            break;
79          case 1:
80            icon = 'news';
81            break;
82          case 2:
83            icon = 'twitter';
84            break;
85        }
86        $icon = $('<i class="icon icon-'+icon+'" aria-hidden="true"></i>');
87        html = $(this).find('.title').text();
88      }
89
90      var $destItem = $tabpanels.eq(index).find('li');
91      $destItem.html(html);
92
93      $destItem.prepend($icon);
94
95      // add in class to first panel, so scrolls in
96      if (index === 0) {
97        $tabpanels.eq(index).addClass('in');
98      }
99    });
100  };
101
102  RealTimeFeed.prototype._handleClick = function(e) {
103
104    var $target = $(e.target);
105
106    // wetboew will trigger click on tab for carousel
107    if ($target.attr('role')) {
108      return;
109    }
110
111    // user clicked realtime-ticker link
112    if ($target.prop('tagName') === 'A') {
113      return;
114    }
115
116    // user clicked toggle
117    e.preventDefault();
118    var $delegate = $(e.delegateTarget);
119    $delegate.toggleClass('open');
120
121  };
122
123  $(function() {
124    $('.realtimefeed').each(function () {
125      var realTimeFeed = new RealTimeFeed({
126        refresh: 5000,
127        el: $(this)
128      });
129      realTimeFeed.init();
130    });
131  });
132
133})(jQuery, drupalSettings);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.