PageSourceSearch

https://www.syfy.es/sites/all/modules/custom/pint_epg/js/pint_epg_schedule.js?ta8p3z

js syfy.es collected 2026-10-02 06:28:51 UTC 3,474 bytes, 116 lines download raw bytes

1/**
2 * @file
3 * Behavior for the live whats on ticker.
4 *
5 * @Author J.Pitt
6 *
7 * @date 14th September 2017
8 *
9 * Description & additional notes:
10 * - Ensures the whats on now in top left nav is always up-to-date
11 * on every page regardless of how long the page is cached for.
12 * - Allows for multiple instances.
13 * - Allows for server side JS settings to be passed in to override the ones here.
14 *
15 */
16(function ($) {
17  Drupal.behaviors.pintEpgSchedule = {
18    defaults : {
19      endpoint: '/ajax/whatson',
20      mainSelector: '.dule',
21      flagSelector: '.dule__flag',
22      flagWrapperSelector: '.dule__meta',
23      activeClass: 'is-active',
24      activeLineItemClass: 'dule--has-flag'
25    },
26
27    /**
28     * Main attach function.
29     */
30    attach: function (context, settings) {
31      $('body', context).once('pintEpgSchedule', function() {
32        Drupal.behaviors.pintEpgSchedule.setup(context, settings);
33      });
34    },
35
36    /**
37     * One-off setup function.
38     *
39     * Instantiates the behaviour and applies the default settings.
40     */
41    setup: function(context, settings) {
42      var _base = Drupal.behaviors.pintEpgSchedule;
43      var _settings = settings.pintEpgSchedule || {};
44
45      // Extend the current behaviour with default values.
46      // But override anything coming in from settings.
47      Drupal.settings.pintEpgSchedule = _settings = $.extend({}, _base.defaults, _settings);
48
49      // Cache our vars and instances.
50      _settings.$instances = $(_settings.mainSelector, context);
51      _settings.origin = document.location.pathname;
52      _settings.$flagElement = $(_settings.flagSelector, _settings.$instances);
53
54      // Update the instances on page load.
55      _base.updateInstances();
56    },
57
58    /**
59     * Main update instances function.
60     *
61     * Simply makes an un-cached ajax call to retrieve the whats on markup.
62     */
63    updateInstances: function() {
64      var _base = Drupal.behaviors.pintEpgSchedule;
65      var cachedData = _base.getCachedResponse();
66      if (cachedData !== 'undefined') {
67        _base.onSuccessSetResponseMarkup(cachedData);
68      } else {
69        $.ajax({
70          dataType: "json",
71          url: _base.getEndpoint(),
72          success: _base.onSuccessSetResponseMarkup
73        });
74      }
75    },
76
77    /**
78     * Ajax success response handler to set the whats on markup.
79     *
80     * @param data
81     */
82    onSuccessSetResponseMarkup: function(data) {
83      var _settings = Drupal.settings.pintEpgSchedule;
84      if (typeof data.epg_unique_id !== 'undefined') {
85        var $flag = _settings.$flagElement.detach();
86        _settings.$instances
87          .removeClass(_settings.activeClass)
88          .filter('[data-epg-id="' + data.epg_unique_id + '"]')
89          .addClass(_settings.activeClass)
90          .addClass(_settings.activeLineItemClass)
91          .find(_settings.flagWrapperSelector)
92          .append($flag);
93      }
94    },
95
96    /**
97     * Helper function to construct the ajax endpoint.
98     *
99     * @returns {string}
100     */
101    getEndpoint: function() {
102      return Drupal.settings.pintEpgSchedule.endpoint;
103    },
104
105    /**
106     * Get cached response from epg_whatson.js
107     */
108    getCachedResponse: function() {
109      if (typeof Drupal.settings.pintEpgSchedule.cachedResponses !== 'undefined') {
110        // Returns undefined by default.
111        return Drupal.settings.pintEpgSchedule.cachedResponses.slice(-1).pop();
112      }
113      return 'undefined';
114    }
115  };
116})(jQuery);

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.