PageSourceSearch

https://congoliver.github.io/js/src/even.js?v=2.10.2

js congoliver.github.io collected 2026-10-03 08:49:39 UTC 6,813 bytes, 260 lines download raw bytes

1(function (window) {
2  'use strict';
3
4  function Even(config) {
5    this.config = config;
6  }
7
8  Even.prototype.setup = function() {
9    var leancloud = this.config.leancloud;
10
11    this.navbar();
12    this.responsiveTable();
13
14    if (this.config.toc) {
15      this.scrollToc();
16      this.tocFollow();
17    }
18    if (this.config.fancybox) {
19      this.fancybox();
20    }
21    if (leancloud.app_id && leancloud.app_key) {
22      this.recordReadings();
23    }
24    if (this.config.pjax) {
25      this.pjax();
26    }
27    this.backToTop();
28  };
29
30  Even.prototype.navbar = function () {
31    var $nav = $('#mobile-navbar');
32    var $navIcon = $('.mobile-navbar-icon');
33
34    var slideout = new Slideout({
35      'panel': document.getElementById('mobile-panel'),
36      'menu': document.getElementById('mobile-menu'),
37      'padding': 180,
38      'tolerance': 70
39    });
40    slideout.disableTouch();
41
42    $navIcon.click(function () {
43      slideout.toggle();
44    });
45
46    slideout.on('beforeopen', function () {
47      $nav.addClass('fixed-open');
48      $navIcon.addClass('icon-click').removeClass('icon-out');
49    });
50
51    slideout.on('beforeclose', function () {
52      $nav.removeClass('fixed-open');
53      $navIcon.addClass('icon-out').removeClass('icon-click');
54    });
55
56    $('#mobile-panel').on('touchend', function () {
57      slideout.isOpen() && $navIcon.click();
58    });
59  };
60
61  Even.prototype.responsiveTable = function () {
62    var tables = $('.post-content > table')
63    tables.wrap('<div class="table-responsive">')
64  };
65
66  Even.prototype.scrollToc = function () {
67    var SPACING = 20;
68    var $toc = $('.post-toc');
69    var $footer = $('.post-footer');
70
71    if ($toc.length) {
72      var minScrollTop = $toc.offset().top - SPACING;
73      var maxScrollTop = $footer.offset().top - $toc.height() - SPACING;
74
75      var tocState = {
76        start: {
77          'position': 'absolute',
78          'top': minScrollTop
79        },
80        process: {
81          'position': 'fixed',
82          'top': SPACING
83        },
84        end: {
85          'position': 'absolute',
86          'top': maxScrollTop
87        }
88      }
89
90      $(window).scroll(function () {
91        var scrollTop = $(window).scrollTop();
92
93        if (scrollTop < minScrollTop) {
94          $toc.css(tocState.start);
95        } else if (scrollTop > maxScrollTop) {
96          $toc.css(tocState.end);
97        } else {
98          $toc.css(tocState.process);
99        }
100      })
101    }
102  };
103
104  Even.prototype.tocFollow = function () {
105    var HEADERFIX = 30;
106    var $toclink = $('.toc-link'),
107      $headerlink = $('.headerlink');
108
109    var headerlinkTop = $.map($headerlink, function (link) {
110      return $(link).offset().top;
111    });
112
113    $(window).scroll(function () {
114      var scrollTop = $(window).scrollTop();
115
116      for (var i = 0; i < $toclink.length; i++) {
117        var isLastOne = i + 1 === $toclink.length,
118          currentTop = headerlinkTop[i] - HEADERFIX,
119          nextTop = isLastOne ? Infinity : headerlinkTop[i + 1] - HEADERFIX;
120
121        if (currentTop < scrollTop && scrollTop <= nextTop) {
122          $($toclink[i]).addClass('active');
123        } else {
124          $($toclink[i]).removeClass('active');
125        }
126      }
127    });
128  };
129
130  Even.prototype.fancybox = function () {
131    if ($.fancybox) {
132      $('.post').each(function () {
133        $(this).find('img').each(function () {
134          var href = 'href="' + this.src + '"';
135          var title = 'title="' + this.alt + '"';
136          $(this).wrap('<a class="fancybox" ' + href + ' ' + title + '></a>');
137        });
138      });
139
140      $('.fancybox').fancybox({
141        openEffect: 'elastic',
142        closeEffect: 'elastic'
143      });
144    }
145  };
146
147  Even.prototype.recordReadings = function () {
148    if (typeof AV !== 'object') return;
149
150    var $visits = $('.post-visits');
151    var Counter = AV.Object.extend('Counter');
152    if ($visits.length === 1) {
153      addCounter(Counter);
154    } else {
155      showTime(Counter);
156    }
157
158    function updateVisits(dom, time) {
159      var readText = dom.text().replace(/(\d+)/i, time)
160      dom.text(readText);
161    }
162
163    function addCounter(Counter) {
164      var query = new AV.Query(Counter);
165
166      var url = $visits.data('url').trim();
167      var title = $visits.data('title').trim();
168
169      query.equalTo('url', url);
170      query.find().then(function (results) {
171        if (results.length > 0) {
172          var counter = results[0];
173          counter.save(null, {
174            fetchWhenSave: true
175          }).then(function (counter) {
176            counter.increment('time', 1);
177            return counter.save();
178          }).then(function (counter) {
179            updateVisits($visits, counter.get('time'));
180          });
181        } else {
182          var newcounter = new Counter();
183          newcounter.set('title', title);
184          newcounter.set('url', url);
185          newcounter.set('time', 1);
186
187          var acl = new AV.ACL();
188          acl.setWriteAccess('*', true)
189          acl.setReadAccess('*', true)
190          newcounter.setACL(acl)
191
192          newcounter.save().then(function () {
193            updateVisits($visits, newcounter.get('time'));
194          });
195        }
196      }, function (error) {
197        // eslint-disable-next-line
198        console.log('Error:' + error.code + " " + error.message);
199      });
200    }
201
202    function showTime(Counter) {
203      $visits.each(function () {
204        var $this = $(this);
205        var query = new AV.Query(Counter);
206        var url = $this.data('url').trim();
207
208        query.equalTo('url', url);
209        query.find().then(function (results) {
210          if (results.length === 0) {
211            updateVisits($this, 0);
212          } else {
213            var counter = results[0];
214            updateVisits($this, counter.get('time'));
215          }
216        }, function (error) {
217          // eslint-disable-next-line
218          console.log('Error:' + error.code + " " + error.message);
219        });
220      })
221    }
222  };
223
224  Even.prototype.pjax = function () {
225    if (location.hostname === 'localhost' || this.hasPjax) return;
226    this.hasPjax = true;
227
228    var that = this;
229    $(document).pjax('a', 'body', { fragment: 'body' });
230    $(document).on('pjax:send', function () {
231      NProgress.start();
232      $('body').addClass('hide-top');
233    });
234    $(document).on('pjax:complete', function () {
235      NProgress.done();
236      $('body').removeClass('hide-top');
237      that.setup();
238    });
239  };
240
241  Even.prototype.backToTop = function () {
242    var $backToTop = $('#back-to-top');
243
244    $(window).scroll(function () {
245      if ($(window).scrollTop() > 100) {
246        $backToTop.fadeIn(1000);
247      } else {
248        $backToTop.fadeOut(1000);
249      }
250    });
251
252    $backToTop.click(function () {
253      $('body,html').animate({ scrollTop: 0 });
254    });
255  };
256
257  var config = window.config;
258  var even = new Even(config);
259  even.setup();
260}(window))

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.