PageSourceSearch

https://www.moj.gov.tw/Content/main/vendor/slick/slick-lightbox.js

js moj.gov.tw collected 2026-09-24 08:28:19 UTC 15,200 bytes, 319 lines download raw bytes

1'use strict';
2(function($) {
3    var MyTitle = "";
4    //不同語系
5    var weblang = $('html').attr('lang');
6    if (weblang.substring(0, 2) == 'zh') {
7        MyTitle = "關閉視窗";
8    } else if (weblang.substring(0, 2) == 'en') {
9        MyTitle = "close";
10    }
11    var SlickLightbox, defaults;
12    SlickLightbox = function() {
13        /*
14  The core class.
15   */
16        function SlickLightbox(element, options1) {
17            var slickLightbox;
18            this.options = options1;
19            /* Binds the plugin. */
20            this.$element = $(element);
21            this.didInit = false;
22            slickLightbox = this;
23            this.$element.on('click.slickLightbox', this.options.itemSelector, function(e) {
24                var $clickedItem, $items;
25                e.preventDefault();
26                $clickedItem = $(this);
27                if (typeof slickLightbox.options.shouldOpen === 'function') {
28                    if (!slickLightbox.options.shouldOpen(slickLightbox, $clickedItem, e)) {
29                        return;
30                    }
31                }
32                $items = slickLightbox.filterOutSlickClones(slickLightbox.$element.find(slickLightbox.options.itemSelector));
33                return slickLightbox.init($items.index($clickedItem));
34            });
35        }
36        SlickLightbox.prototype.init = function(index) {
37            /* Creates the lightbox, opens it, binds events and calls `slick`. Accepts `index` of the element, that triggered it (so that we know, on which slide to start slick). */
38            this.didInit = true;
39            this.detectIE();
40            this.createModal();
41            this.bindEvents();
42            this.initSlick(index);
43            return this.open();
44        };
45        SlickLightbox.prototype.createModalItems = function() {
46            /* Creates individual slides to be used with slick. If `options.images` array is specified, it uses it's contents, otherwise loops through elements' `options.itemSelector`. */
47            var $items, createItem, links;
48            if (this.options.images) {
49                links = $.map(this.options.images, function(img) {
50                    return '<div class="slick-lightbox-slick-item"><div class="slick-lightbox-slick-item-inner"><img class="slick-lightbox-slick-img" src="' + img + '" /></div></div>';
51                });
52            } else {
53                createItem = function(_this) {
54                    return function(el) {
55                        var caption, src;
56                        caption = _this.getElementCaption(el);
57                        src = _this.getElementSrc(el);
58                        return '<div class="slick-lightbox-slick-item"><div class="slick-lightbox-slick-item-inner"><img class="slick-lightbox-slick-img" src="' + src + '" />' + caption + '</div></div>';
59                    };
60                }(this);
61                $items = this.filterOutSlickClones(this.$element.find(this.options.itemSelector));
62                links = $.map($items, createItem);
63            }
64            return links;
65        };
66        SlickLightbox.prototype.createModal = function() {
67            /* Creates a `slick`-friendly modal. */
68            var html, links;
69            links = this.createModalItems();
70            html = '<div class="slick-lightbox slick-lightbox-hide-init' + (this.isIE ? ' slick-lightbox-ie' : '') + '" style="background: ' + this.options.background + ';">\n  <div class="slick-lightbox-inner">\n    <div class="slick-lightbox-slick slick-caption-' + this.options.captionPosition + '">' + links.join('') + '</div>\n  <div>\n<div>';
71            this.$modalElement = $(html);
72            this.$parts = {};
73            this.$parts['closeButton'] = $(this.options.layouts.closeButton).attr('title', MyTitle);
74            this.$modalElement.find('.slick-lightbox-inner').append(this.$parts['closeButton']);
75            return $('body').append(this.$modalElement);
76        };
77        SlickLightbox.prototype.initSlick = function(index) {
78            /* Runs slick by default, using `options.slick` if provided. If `options.slick` is a function, it gets fired instead of us initializing slick. Merges in initialSlide option. */
79            var additional;
80            additional = { initialSlide: index };
81            if (this.options.slick != null) {
82                if (typeof this.options.slick === 'function') {
83                    this.slick = this.options.slick(this.$modalElement);
84                } else {
85                    this.slick = this.$modalElement.find('.slick-lightbox-slick').slick($.extend({}, this.options.slick, additional));
86                }
87            } else {
88                this.slick = this.$modalElement.find('.slick-lightbox-slick').slick(additional);
89            }
90            return this.$modalElement.trigger('init.slickLightbox');
91        };
92        SlickLightbox.prototype.open = function() {
93            /* Opens the lightbox. */
94            if (this.options.useHistoryApi) {
95                this.writeHistory();
96            }
97            this.$element.trigger('show.slickLightbox');
98            setTimeout(function(_this) {
99                return function() {
100                    return _this.$element.trigger('shown.slickLightbox');
101                };
102            }(this), this.getTransitionDuration());
103            return this.$modalElement.removeClass('slick-lightbox-hide-init');
104        };
105        SlickLightbox.prototype.close = function() {
106            /* Closes the lightbox and destroys it, maintaining the original element bindings. */
107            this.$element.trigger('hide.slickLightbox');
108            setTimeout(function(_this) {
109                return function() {
110                    return _this.$element.trigger('hidden.slickLightbox');
111                };
112            }(this), this.getTransitionDuration());
113            this.$modalElement.addClass('slick-lightbox-hide');
114            return this.destroy();
115        };
116        SlickLightbox.prototype.bindEvents = function() {
117            /* Binds global events. */
118            var resizeSlides;
119            resizeSlides = function(_this) {
120                return function() {
121                    var h;
122                    h = _this.$modalElement.find('.slick-lightbox-inner').height();
123                    _this.$modalElement.find('.slick-lightbox-slick-item').height(h);
124                    return _this.$modalElement.find('.slick-lightbox-slick-img, .slick-lightbox-slick-item-inner').css('max-height', Math.round(_this.options.imageMaxHeight * h));
125                };
126            }(this);
127            $(window).on('orientationchange.slickLightbox resize.slickLightbox', resizeSlides);
128            if (this.options.useHistoryApi) {
129                $(window).on('popstate.slickLightbox', function(_this) {
130                    return function() {
131                        return _this.close();
132                    };
133                }(this));
134            }
135            this.$modalElement.on('init.slickLightbox', resizeSlides);
136            this.$modalElement.on('destroy.slickLightbox', function(_this) {
137                return function() {
138                    return _this.destroy();
139                };
140            }(this));
141            this.$element.on('destroy.slickLightbox', function(_this) {
142                return function() {
143                    return _this.destroy(true);
144                };
145            }(this));
146            this.$parts['closeButton'].on('click.slickLightbox touchstart.slickLightbox', function(_this) {
147                return function(e) {
148                    e.preventDefault();
149                    return _this.close();
150                };
151            }(this));
152            if (this.options.closeOnEscape || this.options.navigateByKeyboard) {
153                $(document).on('keydown.slickLightbox', function(_this) {
154                    return function(e) {
155                        var code;
156                        code = e.keyCode ? e.keyCode : e.which;
157                        if (_this.options.navigateByKeyboard) {
158                            if (code === 37) {
159                                _this.slideSlick('left');
160                            } else if (code === 39) {
161                                _this.slideSlick('right');
162                            }
163                        }
164                        if (_this.options.closeOnEscape) {
165                            if (code === 27) {
166                                return _this.close();
167                            }
168                        }
169                    };
170                }(this));
171            }
172            if (this.options.closeOnBackdropClick) {
173                this.$modalElement.on('click.slickLightbox touchstart.slickLightbox', '.slick-lightbox-slick-img', function(e) {
174                    return e.stopPropagation();
175                });
176                return this.$modalElement.on('click.slickLightbox', '.slick-lightbox-slick-item', function(_this) {
177                    return function(e) {
178                        e.preventDefault();
179                        return _this.close();
180                    };
181                }(this));
182            }
183        };
184        SlickLightbox.prototype.slideSlick = function(direction) {
185            /* Moves the slick prev or next. */
186            if (direction === 'left') {
187                return this.slick.slick('slickPrev');
188            } else {
189                return this.slick.slick('slickNext');
190            }
191        };
192        SlickLightbox.prototype.detectIE = function() {
193            /* Detects usage of IE8 and lower. */
194            var ieversion;
195            this.isIE = false;
196            if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
197                ieversion = new Number(RegExp.$1);
198                if (ieversion < 9) {
199                    return this.isIE = true;
200                }
201            }
202        };
203        SlickLightbox.prototype.getElementCaption = function(el) {
204            /* Returns caption for each slide based on the type of `options.caption`. */
205            var c;
206            if (!this.options.caption) {
207                return '';
208            }
209            c = function() {
210                switch (typeof this.options.caption) {
211                    case 'function':
212                        return this.options.caption(el);
213                    case 'string':
214                        return $(el).data(this.options.caption);
215                }
216            }.call(this);
217            return '<span class="slick-lightbox-slick-caption">' + c + '</span>';
218        };
219        SlickLightbox.prototype.getElementSrc = function(el) {
220            /* Returns src for each slide image based on the type of `options.src`. */
221            switch (typeof this.options.src) {
222                case 'function':
223                    return this.options.src(el);
224                case 'string':
225                    return $(el).attr(this.options.src);
226                default:
227                    return el.href;
228            }
229        };
230        SlickLightbox.prototype.unbindEvents = function() {
231            /* Unbinds global events. */
232            $(window).off('.slickLightbox');
233            $(document).off('.slickLightbox');
234            return this.$modalElement.off('.slickLightbox');
235        };
236        SlickLightbox.prototype.destroy = function(unbindAnchors) {
237            if (unbindAnchors == null) {
238                unbindAnchors = false;
239            }
240            /* Destroys the lightbox and unbinds global events. If `true` is passed as an argument, unbinds the original element as well. */
241            if (this.didInit) {
242                this.unbindEvents();
243                setTimeout(function(_this) {
244                    return function() {
245                        return _this.$modalElement.remove();
246                    };
247                }(this), this.options.destroyTimeout);
248            }
249            if (unbindAnchors) {
250                this.$element.off('.slickLightbox');
251                return this.$element.off('.slickLightbox', this.options.itemSelector);
252            }
253        };
254        SlickLightbox.prototype.destroyPrevious = function() {
255            /* Destroys lightboxes currently in DOM. */
256            return $('body').children('.slick-lightbox').trigger('destroy.slickLightbox');
257        };
258        SlickLightbox.prototype.getTransitionDuration = function() {
259            /* Detects the transition duration to know when to remove stuff from DOM etc. */
260            var duration;
261            if (this.transitionDuration) {
262                return this.transitionDuration;
263            }
264            duration = this.$modalElement.css('transition-duration');
265            if (typeof duration === 'undefined') {
266                return this.transitionDuration = 500;
267            } else {
268                return this.transitionDuration = duration.indexOf('ms') > -1 ? parseFloat(duration) : parseFloat(duration) * 1000;
269            }
270        };
271        SlickLightbox.prototype.writeHistory = function() {
272            /* Writes an empty state to the history API if supported. */
273            return typeof history !== 'undefined' && history !== null ? typeof history.pushState === 'function' ? history.pushState(null, null, '') : void 0 : void 0;
274        };
275        SlickLightbox.prototype.filterOutSlickClones = function($items) {
276            /* Removes all slick clones from the set of elements. Only does so, if the target element is a slick slider. */
277            if (!this.$element.hasClass('slick-slider')) {
278                return $items;
279            }
280            return $items = $items.filter(function() {
281                var $item;
282                $item = $(this);
283                return !$item.hasClass('slick-cloned') && $item.parents('.slick-cloned').length === 0;
284            });
285        };
286        return SlickLightbox;
287    }();
288    defaults = {
289        background: 'rgba(0,0,0,.8)',
290        closeOnEscape: true,
291        closeOnBackdropClick: true,
292        destroyTimeout: 500,
293        itemSelector: 'a',
294        navigateByKeyboard: true,
295        src: false,
296        caption: false,
297        captionPosition: 'dynamic',
298        images: false,
299        slick: {},
300        useHistoryApi: false,
301        layouts: { closeButton: '<button type="button" class="slick-lightbox-close" title="' + MyTitle + '"></button>' },
302        shouldOpen: null,
303        imageMaxHeight: 0.9
304    };
305    $.fn.slickLightbox = function(options) {
306        /* Fires the plugin. */
307        options = $.extend({}, defaults, options);
308        $(this).each(function() {
309            return this.slickLightbox = new SlickLightbox(this, options);
310        });
311        return this;
312    };
313    $.fn.unslickLightbox = function() {
314        /* Removes everything. */
315        return $(this).trigger('destroy.slickLightbox').each(function() {
316            return this.slickLightbox = null;
317        });
318    };
319}(jQuery));

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.