PageSourceSearch

https://congnghenano.vn/asset_desktop/js/jquery.lighter.js

js congnghenano.vn collected 2026-10-09 03:40:37 UTC 9,570 bytes, 323 lines download raw bytes

1// Generated by CoffeeScript 1.9.3
2
3/*
4jQuery Lighter
5Copyright 2015 Kevin Sylvestre
61.3.4
7 */
8
9(function() {
10  "use strict";
11  var $, Animation, Lighter, Slide,
12    bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
13
14  $ = jQuery;
15
16  Animation = (function() {
17    function Animation() {}
18
19    Animation.transitions = {
20      "webkitTransition": "webkitTransitionEnd",
21      "mozTransition": "mozTransitionEnd",
22      "oTransition": "oTransitionEnd",
23      "transition": "transitionend"
24    };
25
26    Animation.transition = function($el) {
27      var el, i, len, ref, result, type;
28      for (i = 0, len = $el.length; i < len; i++) {
29        el = $el[i];
30        ref = this.transitions;
31        for (type in ref) {
32          result = ref[type];
33          if (el.style[type] != null) {
34            return result;
35          }
36        }
37      }
38    };
39
40    Animation.execute = function($el, callback) {
41      var transition;
42      transition = this.transition($el);
43      if (transition != null) {
44        return $el.one(transition, callback);
45      } else {
46        return callback();
47      }
48    };
49
50    return Animation;
51
52  })();
53
54  Slide = (function() {
55    function Slide(url) {
56      this.url = url;
57    }
58
59    Slide.prototype.type = function() {
60      switch (false) {
61        case !this.url.match(/\.(webp|jpeg|jpg|jpe|gif|png|bmp)$/i):
62          return 'image';
63        default:
64          return 'unknown';
65      }
66    };
67
68    Slide.prototype.preload = function(callback) {
69      var image;
70      image = new Image();
71      image.src = this.url;
72      return image.onload = (function(_this) {
73        return function() {
74          _this.dimensions = {
75            width: image.width,
76            height: image.height
77          };
78          return callback(_this);
79        };
80      })(this);
81    };
82
83    Slide.prototype.$content = function() {
84      return $("<img />").attr({
85        src: this.url
86      });
87    };
88
89    return Slide;
90
91  })();
92
93  Lighter = (function() {
94    Lighter.namespace = "lighter";
95
96    Lighter.prototype.defaults = {
97      loading: '#{Lighter.namespace}-loading',
98      fetched: '#{Lighter.namespace}-fetched',
99      padding: 40,
100      dimensions: {
101        width: 480,
102        height: 480
103      },
104      template: "<div class='" + Lighter.namespace + " " + Lighter.namespace + "-fade'>\n  <div class='" + Lighter.namespace + "-container'>\n    <span class='" + Lighter.namespace + "-content'></span>\n    <a class='" + Lighter.namespace + "-close'>&times;</a>\n    <a class='" + Lighter.namespace + "-prev'>&lsaquo;</a>\n    <a class='" + Lighter.namespace + "-next'>&rsaquo;</a>\n  </div>\n  <div class='" + Lighter.namespace + "-spinner'>\n    <div class='" + Lighter.namespace + "-dot'></div>\n    <div class='" + Lighter.namespace + "-dot'></div>\n    <div class='" + Lighter.namespace + "-dot'></div>\n  </div>\n  <div class='" + Lighter.namespace + "-overlay'></div>\n</div>"
105    };
106
107    Lighter.lighter = function($target, options) {
108      var data;
109      if (options == null) {
110        options = {};
111      }
112      data = $target.data('_lighter');
113      if (!data) {
114        $target.data('_lighter', data = new Lighter($target, options));
115      }
116      return data;
117    };
118
119    Lighter.prototype.$ = function(selector) {
120      return this.$el.find(selector);
121    };
122
123    function Lighter($target, settings) {
124      if (settings == null) {
125        settings = {};
126      }
127      this.show = bind(this.show, this);
128      this.hide = bind(this.hide, this);
129      this.observe = bind(this.observe, this);
130      this.keyup = bind(this.keyup, this);
131      this.size = bind(this.size, this);
132      this.align = bind(this.align, this);
133      this.process = bind(this.process, this);
134      this.resize = bind(this.resize, this);
135      this.type = bind(this.type, this);
136      this.prev = bind(this.prev, this);
137      this.next = bind(this.next, this);
138      this.close = bind(this.close, this);
139      this.$ = bind(this.$, this);
140      this.$target = $target;
141      this.settings = $.extend({}, this.defaults, settings);
142      this.$el = $(this.settings.template);
143      this.$overlay = this.$("." + Lighter.namespace + "-overlay");
144      this.$content = this.$("." + Lighter.namespace + "-content");
145      this.$container = this.$("." + Lighter.namespace + "-container");
146      this.$close = this.$("." + Lighter.namespace + "-close");
147      this.$prev = this.$("." + Lighter.namespace + "-prev");
148      this.$next = this.$("." + Lighter.namespace + "-next");
149      this.$body = this.$("." + Lighter.namespace + "-body");
150      this.dimensions = this.settings.dimensions;
151      this.process();
152    }
153
154    Lighter.prototype.close = function(event) {
155      if (event != null) {
156        event.preventDefault();
157      }
158      if (event != null) {
159        event.stopPropagation();
160      }
161      return this.hide();
162    };
163
164    Lighter.prototype.next = function(event) {
165      if (event != null) {
166        event.preventDefault();
167      }
168      return event != null ? event.stopPropagation() : void 0;
169    };
170
171    Lighter.prototype.prev = function() {
172      if (typeof event !== "undefined" && event !== null) {
173        event.preventDefault();
174      }
175      return typeof event !== "undefined" && event !== null ? event.stopPropagation() : void 0;
176    };
177
178    Lighter.prototype.type = function(href) {
179      if (href == null) {
180        href = this.href();
181      }
182      return this.settings.type || (this.href().match(/\.(webp|jpeg|jpg|jpe|gif|png|bmp)$/i) ? "image" : void 0);
183    };
184
185    Lighter.prototype.resize = function(dimensions) {
186      this.dimensions = dimensions;
187      return this.align();
188    };
189
190    Lighter.prototype.process = function() {
191      var fetched, loading;
192      fetched = (function(_this) {
193        return function() {
194          return _this.$el.removeClass(Lighter.namespace + "-loading").addClass(Lighter.namespace + "-fetched");
195        };
196      })(this);
197      loading = (function(_this) {
198        return function() {
199          return _this.$el.removeClass(Lighter.namespace + "-fetched").addClass(Lighter.namespace + "-loading");
200        };
201      })(this);
202      this.slide = new Slide(this.$target.attr("href"));
203      loading();
204      return this.slide.preload((function(_this) {
205        return function(slide) {
206          _this.resize(slide.dimensions);
207          _this.$content.html(_this.slide.$content());
208          return fetched();
209        };
210      })(this));
211    };
212
213    Lighter.prototype.align = function() {
214      var size;
215      size = this.size();
216      return this.$container.css({
217        width: size.width,
218        height: size.height,
219        margin: "-" + (size.height / 2) + "px -" + (size.width / 2) + "px"
220      });
221    };
222
223    Lighter.prototype.size = function() {
224      var ratio;
225      ratio = Math.max(this.dimensions.height / ($(window).height() - this.settings.padding), this.dimensions.width / ($(window).width() - this.settings.padding));
226      return {
227        width: ratio > 1.0 ? Math.round(this.dimensions.width / ratio) : this.dimensions.width,
228        height: ratio > 1.0 ? Math.round(this.dimensions.height / ratio) : this.dimensions.height
229      };
230    };
231
232    Lighter.prototype.keyup = function(event) {
233      if (event.target.form != null) {
234        return;
235      }
236      if (event.which === 27) {
237        this.close();
238      }
239      if (event.which === 37) {
240        this.prev();
241      }
242      if (event.which === 39) {
243        return this.next();
244      }
245    };
246
247    Lighter.prototype.observe = function(method) {
248      if (method == null) {
249        method = 'on';
250      }
251      $(window)[method]("resize", this.align);
252      $(document)[method]("keyup", this.keyup);
253      this.$overlay[method]("click", this.close);
254      this.$close[method]("click", this.close);
255      this.$next[method]("click", this.next);
256      return this.$prev[method]("click", this.prev);
257    };
258
259    Lighter.prototype.hide = function() {
260      var alpha, omega;
261      alpha = (function(_this) {
262        return function() {
263          return _this.observe('off');
264        };
265      })(this);
266      omega = (function(_this) {
267        return function() {
268          return _this.$el.remove();
269        };
270      })(this);
271      alpha();
272      this.$el.position();
273      this.$el.addClass(Lighter.namespace + "-fade");
274      return Animation.execute(this.$el, omega);
275    };
276
277    Lighter.prototype.show = function() {
278      var alpha, omega;
279      omega = (function(_this) {
280        return function() {
281          return _this.observe('on');
282        };
283      })(this);
284      alpha = (function(_this) {
285        return function() {
286          return $(document.body).append(_this.$el);
287        };
288      })(this);
289      alpha();
290      this.$el.position();
291      this.$el.removeClass(Lighter.namespace + "-fade");
292      return Animation.execute(this.$el, omega);
293    };
294
295    return Lighter;
296
297  })();
298
299  $.fn.extend({
300    lighter: function(option) {
301      if (option == null) {
302        option = {};
303      }
304      return this.each(function() {
305        var $this, action, options;
306        $this = $(this);
307        options = $.extend({}, $.fn.lighter.defaults, typeof option === "object" && option);
308        action = typeof option === "string" ? option : option.action;
309        if (action == null) {
310          action = "show";
311        }
312        return Lighter.lighter($this, options)[action]();
313      });
314    }
315  });
316
317  $(document).on("click", "[data-lighter]", function(event) {
318    event.preventDefault();
319    event.stopPropagation();
320    return $(this).lighter();
321  });
322
323}).call(this);

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.