PageSourceSearch

https://www.oum.ru/render/js/ajax.js?17371168517365

js oum.ru collected 2026-10-02 07:36:01 UTC 7,365 bytes, 247 lines download raw bytes

1$.ajaxNav = (function() {
2
3  var containerSelector = '.ajax-container',
4      contentSelector = '.ajax-content',
5      triggerContainerSelector = '.ajax-trigger-container',
6      triggerSelector = '.ajax-trigger',
7      pagerSelector = '.ajax-pager',
8      itemSelector = '.ajax-item';
9
10  var ready = false,
11      navigating = false,
12      getUrlParams = null,
13      isNavReady = null,
14      firstPage = null,
15      initialUrl = true;
16
17  var getFirst = function(c) {
18    return c.find(pagerSelector+' .pagination__page--start');
19  };
20
21  var getFirstPage = function(f) {
22    return parseInt(f.text(), 10) || 1;
23  };
24
25  var processResult = function(c, a) {
26    if (a) c.find(itemSelector).addClass('lazyload').attr('data-expand', -20);
27  };
28
29  var afterAppend = function(c) {
30    if ($.favorites) $.favorites.init(c).catch(_c);
31    $.scroll.progress.update();
32  };
33
34  var onNavigate = function(o) {
35    self.container.addClass('navigating started');
36    return fetchRequest(o.url).then(fetchJquery).then((el) => {
37      const content = self.container.find(contentSelector);
38      if (o.scroll && !o.append) self.container.scrollTo();
39      const c = el.hasClass(contentSelector.substring(1)) ? el : el.find(contentSelector);
40      processResult(c, o.append);
41      if (!o.append) content.empty();
42      const items = c.children().get();
43      content.append(items);
44      firstPage = getFirstPage(getFirst(self.container));
45      var nav1 = self.container.find(pagerSelector);
46      var nav2 = el.find(pagerSelector);
47      (nav1.length ? nav1.replaceWith(nav2) : content.after(nav2));
48      triggerResize();
49      return { container: el, items: $(items) };
50    }).catch(() => null).then((res) => {
51      self.container.removeClass('navigating started');
52      return res;
53    });
54  };
55
56  var self = {
57    container: null,
58    pageSize: 0,
59    pageIndex: 0,
60    getPageIndex: function(p) {
61      return 'PAGEN_1' in p ? parseInt(p.PAGEN_1, 10) : 1;
62    },
63    getParamsFromUrl: function(url) {
64      var a = url.split('?');
65      return a.length > 1 ? $.page.params.parse(a[1]) : {};
66    },
67    currentUrl: null,
68    getCurrentUrl: function(p) {
69      p = p || getUrlParams();
70      if ('pager' in p) {
71        if (p.pager && self.pageIndex > 1) p.PAGEN_1 = self.pageIndex;
72        delete p.pager;
73      }
74      delete p.clear_cache;
75      delete p.back_url_admin;
76      delete p.pager_mode;
77      var s = $.page.params.getString(p);
78      if (s.length) s = '?'+s;
79      s = window.location.origin+window.location.pathname+s;
80      if (initialUrl) {
81        s += window.location.hash;
82        initialUrl = false;
83      }
84      return s;
85    },
86  };
87
88  var onInit = function(options) {
89    var o = $.extend({
90      pageSize: 20,
91      getUrlParams: $.page.params.get,
92      setUrlParams: $.noop,
93      isNavReady: () => true,
94      onNavigate: null,
95      navigateNow: false,
96      histoty: true
97    }, options);
98    getUrlParams = o.getUrlParams;
99    isNavReady = o.isNavReady;
100    if (o.onNavigate) onNavigate = o.onNavigate;
101    self.pageSize = o.pageSize;
102    self.pageIndex = self.getPageIndex($.page.params.get());
103    self.currentUrl = self.getCurrentUrl();
104    return o;
105  };
106
107  var makeNavOptions = function(options) {
108    return $.extend({
109      params: false,
110      url: false,
111      page: 0,
112      pop: false,
113      scroll: false,
114      append: false,
115      trigger: null,
116      history: true
117    }, options);
118  };
119
120  var infiniteMode = $.page.params.has('infinite');
121  if (infiniteMode) {
122    self.canNavigate = function(data) {
123      return ready;
124    };
125    self.navigate = $.noop;
126    self.navigateHistory = $.noop;
127    self.navigated = null;
128    self.init = function(options) {
129     if (ready) return;
130      ready = true;
131      onInit(options);
132      loadScript({ src: 'infinite.bundle.js?v3', rel: true }).then(() => {
133        initInfiniteScroll({
134          content: contentSelector,
135          pager: pagerSelector,
136          before: processResult,
137          after: afterAppend
138        });
139      });
140    };
141  } else {
142    self.canNavigate = function(data) {
143      return (!navigating && isNavReady(data));
144    };
145    self.navigate = function(options) {
146      var o = makeNavOptions(options);
147      if (o.page > 0) self.pageIndex = o.page;
148      if (!o.url) o.url = self.getCurrentUrl(o.params);
149      if (ready && o.url == self.currentUrl) return Promise.resolve(false);
150      if (o.history && !history.pushState) {
151        window.location.assign(o.url);
152        return Promise.resolve(false);
153      }
154      navigating = true;
155      return onNavigate(o).then((res) => {
156        if (res && res.container.length) {
157          if (o.history && !o.pop) history.pushState({ url: o.url }, document.title, o.url);
158          self.currentUrl = o.url;
159          if (o.trigger) {
160            o.trigger.closest(triggerContainerSelector).find(triggerSelector).removeClass('active');
161            o.trigger.addClass('active');
162          }
163          if (o.append && firstPage) getFirst(self.container).text(firstPage);
164          if (self.navigated) self.navigated(o);
165          afterAppend(res.items);
166        } else if (!res || !res.container) {
167          $.notify.error();
168        }
169        navigating = false;
170        return res;
171      });
172    };
173    self.navigateHistory = function(options) {
174      var o = $.extend({
175        url: false,
176        force: false
177      }, options);
178      if (!o.url) o.url = self.getCurrentUrl();
179      if (history.replaceState) {
180        history.replaceState({ url: o.url }, document.title, o.url);
181        return;
182      }
183      if (o.force) window.location.assign(o.url);
184    };
185    self.navigated = null;
186    self.init = function(options) {
187      if (ready) return;
188      var o = onInit(options);
189      if (o.history) {
190        window.onpopstate = function(e) {
191          if (!e.state) return;
192          var p = $.page.params.parse(e.state.url.split('?')[1]);
193          o.setUrlParams(p);
194          self.navigate({ url: e.state.url, params: p, pop: true });
195        };
196        self.navigateHistory({ url: self.currentUrl });
197      }
198      if (o.navigateNow) self.navigate({ pop: true });
199      ready = true;
200    };
201  }
202
203  onDocumentReady(function() {
204
205    self.container = $(containerSelector);
206
207    var s = itemSelector.substr(1);
208    self.container.on('lazybeforeunveil', function(e) {
209      if (!$.mq.motion || !e.target.classList.contains(s)) return;
210      var d = (Math.random() * 0.3 + 0.4) + 's';
211      e.target.style.WebkitAnimationDuration = d;
212      e.target.style.animationDuration = d;
213      e.target.classList.add('ajax-animate');
214    });
215
216    if (infiniteMode) {
217      self.init();
218      return;
219    }
220
221    if (self.container.hasClass('search-page')) return;
222
223    self.container.on('click', triggerSelector, function(e) {
224      e.preventDefault();
225      var t = $(this);
226      if (t.hasClass('active')) return;
227      var h = ('href' in this.dataset) ? this.dataset.href : (this.hasAttribute('href') ? this.href : false);
228      if (!h || h == '#') return;
229      var p = self.getParamsFromUrl(h);
230      var o = {
231        params: p,
232        page: self.getPageIndex(p),
233        scroll: true,
234        append: 'pager_mode' in p && p.pager_mode == 'append',
235        trigger: t
236      };
237      if ('url' in this.dataset) o.url = this.dataset.url;
238      self.navigate(o);
239    });
240
241    self.init();
242
243  });
244
245  return self;
246
247})();

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.