PageSourceSearch

https://jidelna.zsgvitkov.cz:9998/js/jquery.lighter.js

js zsgvitkov.cz collected 2026-10-06 21:18:50 UTC 8,181 bytes, 293 lines download raw bytes

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