PageSourceSearch

https://supersonic.com/wp-content/themes/ironsrc/js/feed.js?ver=20190101

js supersonic.com collected 2026-09-24 09:45:11 UTC 9,422 bytes, 313 lines download raw bytes

1(function($) {
2  if (!window.config)
3    return
4  window.feedUtils = {
5    paged: 1,
6    offset: config.posts_per_page,
7    container: $('#feed-container .feed-grid'),
8    btn: $('#feed-load-more'),
9    feed: config.feed,
10    modalClosed: Cookies('iron_modal_closed'),
11    remains: parseInt(config.posts_left),
12    category: config.category,
13    post_type: config.post_type,
14    tags_btn: $('.header_filters .feed-tags li.filter'),
15    tags: config.tags.split(','),
16    searchForm: $('#levelup_feed'),
17    search: config.search,
18    tagsArea: document.querySelector('ul.feed-tags'),
19    widgetsSet: [[2, 0], [1, 2], [0, 1]],
20    currentWidgetSet: 0,
21    firstRebuild: false,
22    manageCurrentWidgetSet: function() {
23      if(this.currentWidgetSet == 2) {
24        this.currentWidgetSet = 0;
25      }else {
26        this.currentWidgetSet++;
27      }
28      return;
29    },
30
31    getCor: function() {
32      var cor = config.feed === 'newsroom' ? -1 : 0
33      if (config.widgets) {
34        var w_count = JSON.parse(config.widgets).length
35        cor -= w_count
36      }
37
38      if (!config.search && this.paged === 1) {
39        cor += 1
40      }
41      return cor;
42    },
43
44    getPostsObject: function(data) {
45
46      var postsConf = {
47        w_pos: this.paged === 1 ? config.widgets : null,
48        action: config.action,
49        nonce: config.nonce,
50        slug: config.slug,
51        feed: this.feed,
52        count: this.offset,
53        category: this.category,
54        post_type: this.post_type,
55        tags: this.tags.join(','),
56        search: this.search,
57        offset: (this.paged * this.offset) + this.getCor()
58      };
59
60      if (typeof data === 'object') {
61        for(var item in data) {
62          postsConf[item] = data[item];
63        }
64      }
65
66      return postsConf;
67    },
68    loadMore: function() {
69      var postsConfig = this.getPostsObject({
70        w_pos: JSON.stringify(this.widgetsSet[this.currentWidgetSet])
71      });
72      this.manageCurrentWidgetSet();
73      this.getPosts(postsConfig);
74      return false;
75    },
76    getPosts: function(data) {
77      window.toggleIronLoader(true);
78
79      $.ajax({
80        type: 'POST',
81        url: config.ajax_url,
82        success: this.handleResponse.bind(this),
83        data: data
84      });
85    },
86    handleSearchForm: function(e) {
87      e.preventDefault();
88      var formData = this.searchForm.serializeArray()[0];
89      this.search = formData.value;
90      var postsConfig = this.getPostsObject({
91        rebuildDOM: true,
92        offset: 0
93      });
94      window.history.replaceState('', '', this.updateQueryStringParameter(window.location.href, 'search', this.search));
95      this.paged = 0;
96      this.getPosts(postsConfig);
97      return false;
98    },
99    getQueryStringParams: function(param) {
100      var urlParams = new URLSearchParams(window.location.search);
101      return urlParams.get(param) || '';
102    },
103    manageTags: function(e) {
104      var target = $(e.target);
105
106      this.paged = 0;
107
108      this[(target.hasClass('selected')) ? 'removeTag' : 'setTag'](target);
109
110      var postsConfig = this.getPostsObject({
111        tags: this.tags.slice().join(','),
112        rebuildDOM: true,
113        offset: 0,
114        w_pos: []
115      });
116
117      this.manageCurrentWidgetSet();
118      window.history.replaceState('', '', this.updateQueryStringParameter(window.location.href, 'tags', this.tags.slice().join(',')));
119
120      this.getPosts(postsConfig);
121      this.selectedInside();
122      return false;
123    },
124    setTag: function(target) {
125
126      var tag = target.data('tag');
127      if(this.tags.includes(tag)) return;
128      target.addClass('selected');
129      this.tags.push(tag);
130
131    },
132    removeTag: function(target) {
133      var tag = target.data('tag');
134      if(!this.tags.includes(tag)) return;
135      target.removeClass('selected');
136      var index = this.tags.indexOf(tag);
137      if (index !== -1) {
138        this.tags.splice(index, 1);
139      }
140    },
141    manageTagView: function() {
142      var show_more = document.querySelector('.show_more');
143      var tagsModal = show_more.querySelector('ul');
144      var windowWidth = window.innerWidth;
145
146      if(windowWidth >= 768 && windowWidth < 870) {
147
148        if(windowWidth - tagsModal.getBoundingClientRect().left > 30) {
149          tagsModal.classList.add('left')
150        }else {
151          tagsModal.classList.remove('left')
152        }
153      }
154
155      if(windowWidth < 768) {
156        tagsModal.style.left = (show_more.offsetLeft * -1) + 'px';
157      }
158    },
159    manageTagViewCards: function(e) {
160      var list = e.target.querySelector('ul');
161      list.classList.remove('left');
162      if(e.target.offsetLeft == 0) {
163        list.classList.add('left');
164      }
165    },
166    selectedInside: function() {
167      var selected_count = this.tagsArea.querySelectorAll('li.show_more li.selected').length;
168      selected_count = (selected_count == 0) ? '' : '(+'+selected_count+')';
169      this.tagsArea.querySelector('span.selected_inside').innerHTML = selected_count;
170    },
171    updateQueryStringParameter: function(uri, key, value) {
172      var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
173      var separator = uri.indexOf('?') !== -1 ? "&" : "?";
174      if (uri.match(re)) {
175        return uri.replace(re, '$1' + key + "=" + value + '$2');
176      }
177      else {
178        return uri + separator + key + "=" + value;
179      }
180    },
181
182    feedTags: function() {
183      var tags = this.tags;
184      document.querySelectorAll('.feed-tags li.filter').forEach(function (item) {
185        if(tags.indexOf(item.dataset.tag) != -1) {
186          item.classList.add('selected');
187        }else{
188          item.classList.remove('selected');
189        }
190      })
191    },
192    resetAll: function (){
193      this.tags = [];
194      this.tagsArea.querySelectorAll('.filter').forEach(function (item) {
195        item.classList.remove('selected');
196      })
197
198      var postsConfig = this.getPostsObject({
199        rebuildDOM: true,
200        offset: 0,
201        tags: this.tags,
202      });
203      window.history.replaceState('', '', this.updateQueryStringParameter(window.location.href, 'tags', ''));
204
205      this.getPosts(postsConfig);
206      this.selectedInside();
207      return;
208    },
209    toggleBtn: function() {
210      if (this.remains > 0)
211        this.btn.removeClass('hide')
212      else
213        this.btn.addClass('hide')
214    },
215    toggleTagsModal: function(e) {
216      $(e.target).toggleClass('opened');
217      this.manageTagView();
218      if(!$(e.target).hasClass('opened')) $(e.target).find('ul').css('left', '');
219    },
220    // ajax response handler
221    handleResponse: function(r) {
222      window.toggleIronLoader(false)
223      if (!r.data.success)
224        console.log(r.data)
225        if(r.data.rebuildDOM) {
226          $('#feed-container .sticky-post').remove();
227          if(!this.firstRebuild) this.offset++;
228          this.firstRebuild = true;
229          this.container.html(r.data.posts) ;
230        } else {
231          this.container.append(r.data.posts)
232        }
233
234      $('.feed-grid .show_more').on('click', this.toggleTagsModal.bind(this));
235
236
237      this.remains = parseInt(r.data.remains) - (this.paged * parseInt(config.posts_per_page));
238      this.paged++
239      this.toggleBtn()
240    },
241
242    updateProgress: function() {
243      var scrollPercent = Math.round(100 * $(window).scrollTop() / ($(document).height() - $(window).height()));
244
245      $('#process-perc').text(scrollPercent)
246      this.progress.find('.progress').css({width: scrollPercent + '%'})
247
248      if (scrollPercent === 100)
249        this.bindReachedBottom()
250    },
251
252    subscribeModalClosed: function() {
253      Cookies.set('iron_modal_closed', true)
254      this.modalClosed = true
255    },
256
257    bindReachedBottom: function() {
258      if (this.feed === 'levelup' && !this.modalClosed) {
259        this.modalClosed = true
260        window.toggleModal('subscribe-modal')
261      }
262    },
263
264    // on document ready
265    init: function() {
266      this.btn.on('click', this.loadMore.bind(this));
267      this.tags_btn.on('click', this.manageTags.bind(this));
268      this.searchForm.on('submit', this.handleSearchForm.bind(this));
269      $('.show_more').on('click', this.toggleTagsModal.bind(this));
270      $('.reset_all').on('click', this.resetAll.bind(this))
271      $('.tags_footer .close_tag_modal').click(function(e) {
272        $(this).closest('.show_more').click();
273      })
274      // this.tags_btn.on('click', this.setTag.bind(this))
275      this.toggleBtn();
276      this.progress = $('#reading-progress');
277      window.subscribeModalClosed = this.subscribeModalClosed.bind(this);
278
279
280      var manageTagView = this.manageTagView.bind(this);
281      manageTagView();
282      window.addEventListener('resize', function(event) {
283        manageTagView();
284      }, true);
285      var manageTagViewCards = this.manageTagViewCards;
286      document.querySelectorAll('.feed-grid .show_more').forEach(function (item) {
287
288        item.addEventListener('click', manageTagViewCards)
289      });
290
291      if (!this.progress.length)
292        return
293
294      $(window).on('scroll', this.updateProgress.bind(this));
295
296    }
297  }
298
299  $(document).ready(window.feedUtils.init.bind(window.feedUtils))
300})(jQuery)
301
302window.openFeedVideo = function() {
303  var $th  = jQuery(this)
304  var code = $th.data('code')
305  var modal = 'generic-video-modal'
306  var title = $th.attr('title')
307
308  jQuery(window.scModals[modal]).find('.sc-media-trigger-modal').html(code)
309  jQuery(window.scModals[modal]).find('.sc_modal_title').text(title)
310  window.toggleModal(modal)
311
312  return false
313}

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.