PageSourceSearch

https://cdnv2.netkeiba.com/img.race/common/js/jquery.colorbox.js?2019073001

js netkeiba.com collected 2026-10-02 02:31:58 UTC 38,764 bytes, 1,156 lines download raw bytes

vendor: 38,764 bytes, lines 1-1156
1/*!
2	Colorbox 1.6.3
3	license: MIT
4	http://www.jacklmoore.com/colorbox
5*/
6(function($, document, window) {
7    var
8        // Default settings object.
9        // See http://jacklmoore.com/colorbox for details.
10        defaults = {
11            // data sources
12            html: false,
13            photo: false,
14            iframe: false,
15            inline: false,
16
17            // behavior and appearance
18            transition: "elastic",
19            speed: 300,
20            fadeOut: 300,
21            width: false,
22            initialWidth: "600",
23            innerWidth: false,
24            maxWidth: false,
25            height: false,
26            initialHeight: "450",
27            innerHeight: false,
28            maxHeight: false,
29            scalePhotos: true,
30            scrolling: true,
31            opacity: 0.9,
32            preloading: true,
33            className: false,
34            overlayClose: true,
35            escKey: true,
36            arrowKey: true,
37            top: false,
38            bottom: false,
39            left: false,
40            right: false,
41            fixed: false,
42            data: undefined,
43            closeButton: true,
44            fastIframe: true,
45            open: false,
46            reposition: true,
47            loop: true,
48            slideshow: false,
49            slideshowAuto: true,
50            slideshowSpeed: 2500,
51            slideshowStart: "start slideshow",
52            slideshowStop: "stop slideshow",
53            photoRegex: /\.(gif|png|jp(e|g|eg)|bmp|ico|webp|jxr|svg)((#|\?).*)?$/i,
54
55            // alternate image paths for high-res displays
56            retinaImage: false,
57            retinaUrl: false,
58            retinaSuffix: '@2x.$1',
59
60            // internationalization
61            current: "image {current} of {total}",
62            previous: "previous",
63            next: "next",
64            close: "close",
65            xhrError: "This content failed to load.",
66            imgError: "This image failed to load.",
67
68            // accessbility
69            returnFocus: true,
70            trapFocus: true,
71
72            // callbacks
73            onOpen: false,
74            onLoad: false,
75            onComplete: false,
76            onCleanup: false,
77            onClosed: false,
78
79            rel: function() {
80                return this.rel;
81            },
82            href: function() {
83                // using this.href would give the absolute url, when the href may have been inteded as a selector (e.g. '#container')
84                return $(this).attr('href');
85            },
86            title: function() {
87                return this.title;
88            },
89            createImg: function() {
90                var img = new Image();
91                var attrs = $(this).data('cbox-img-attrs');
92
93                if (typeof attrs === 'object') {
94                    $.each(attrs, function(key, val) {
95                        img[key] = val;
96                    });
97                }
98
99                return img;
100            },
101            createIframe: function() {
102                var iframe = document.createElement('iframe');
103                var attrs = $(this).data('cbox-iframe-attrs');
104
105                if (typeof attrs === 'object') {
106                    $.each(attrs, function(key, val) {
107                        iframe[key] = val;
108                    });
109                }
110
111                if ('frameBorder' in iframe) {
112                    iframe.frameBorder = 0;
113                }
114                if ('allowTransparency' in iframe) {
115                    iframe.allowTransparency = "true";
116                }
117                iframe.name = (new Date()).getTime(); // give the iframe a unique name to prevent caching
118                iframe.allowFullscreen = true;
119
120                return iframe;
121            }
122        },
123
124        // Abstracting the HTML and event identifiers for easy rebranding
125        colorbox = 'colorbox',
126        prefix = 'cbox',
127        boxElement = prefix + 'Element',
128
129        // Events
130        event_open = prefix + '_open',
131        event_load = prefix + '_load',
132        event_complete = prefix + '_complete',
133        event_cleanup = prefix + '_cleanup',
134        event_closed = prefix + '_closed',
135        event_purge = prefix + '_purge',
136
137        // Cached jQuery Object Variables
138        $overlay,
139        $box,
140        $wrap,
141        $content,
142        $topBorder,
143        $leftBorder,
144        $rightBorder,
145        $bottomBorder,
146        $related,
147        $window,
148        $loaded,
149        $loadingBay,
150        $loadingOverlay,
151        $title,
152        $current,
153        $slideshow,
154        $next,
155        $prev,
156        $close,
157        $groupControls,
158        $events = $('<a/>'), // $({}) would be prefered, but there is an issue with jQuery 1.4.2
159
160        // Variables for cached values or use across multiple functions
161        settings,
162        interfaceHeight,
163        interfaceWidth,
164        loadedHeight,
165        loadedWidth,
166        index,
167        photo,
168        open,
169        active,
170        closing,
171        loadingTimer,
172        publicMethod,
173        div = "div",
174        requests = 0,
175        previousCSS = {},
176        init;
177
178    // ****************
179    // HELPER FUNCTIONS
180    // ****************
181
182    // Convenience function for creating new jQuery objects
183    function $tag(tag, id, css) {
184        var element = document.createElement(tag);
185
186        if (id) {
187            element.id = prefix + id;
188        }
189
190        if (css) {
191            element.style.cssText = css;
192        }
193
194        return $(element);
195    }
196
197    // Get the window height using innerHeight when available to avoid an issue with iOS
198    // http://bugs.jquery.com/ticket/6724
199    function winheight() {
200        return window.innerHeight ? window.innerHeight : $(window).height();
201    }
202
203    function Settings(element, options) {
204        if (options !== Object(options)) {
205            options = {};
206        }
207
208        this.cache = {};
209        this.el = element;
210
211        this.value = function(key) {
212            var dataAttr;
213
214            if (this.cache[key] === undefined) {
215                dataAttr = $(this.el).attr('data-cbox-' + key);
216
217                if (dataAttr !== undefined) {
218                    this.cache[key] = dataAttr;
219                } else if (options[key] !== undefined) {
220                    this.cache[key] = options[key];
221                } else if (defaults[key] !== undefined) {
222                    this.cache[key] = defaults[key];
223                }
224            }
225
226            return this.cache[key];
227        };
228
229        this.get = function(key) {
230            var value = this.value(key);
231            return $.isFunction(value) ? value.call(this.el, this) : value;
232        };
233    }
234
235    // Determine the next and previous members in a group.
236    function getIndex(increment) {
237        var
238            max = $related.length,
239            newIndex = (index + increment) % max;
240
241        return (newIndex < 0) ? max + newIndex : newIndex;
242    }
243
244    // Convert '%' and 'px' values to integers
245    function setSize(size, dimension) {
246        return Math.round((/%/.test(size) ? ((dimension === 'x' ? $window.width() : winheight()) / 100) : 1) * parseInt(size, 10));
247    }
248
249    // Checks an href to see if it is a photo.
250    // There is a force photo option (photo: true) for hrefs that cannot be matched by the regex.
251    function isImage(settings, url) {
252        return settings.get('photo') || settings.get('photoRegex').test(url);
253    }
254
255    function retinaUrl(settings, url) {
256        return settings.get('retinaUrl') && window.devicePixelRatio > 1 ? url.replace(settings.get('photoRegex'), settings.get('retinaSuffix')) : url;
257    }
258
259    function trapFocus(e) {
260        if ('contains' in $box[0] && !$box[0].contains(e.target) && e.target !== $overlay[0]) {
261            e.stopPropagation();
262            $box.focus();
263        }
264    }
265
266    function setClass(str) {
267        if (setClass.str !== str) {
268            $box.add($overlay).removeClass(setClass.str).addClass(str);
269            setClass.str = str;
270        }
271    }
272
273    function getRelated(rel) {
274        index = 0;
275
276        if (rel && rel !== false && rel !== 'nofollow') {
277            $related = $('.' + boxElement).filter(function() {
278                var options = $.data(this, colorbox);
279                var settings = new Settings(this, options);
280                return (settings.get('rel') === rel);
281            });
282            index = $related.index(settings.el);
283
284            // Check direct calls to Colorbox.
285            if (index === -1) {
286                $related = $related.add(settings.el);
287                index = $related.length - 1;
288            }
289        } else {
290            $related = $(settings.el);
291        }
292    }
293
294    function trigger(event) {
295        // for external use
296        $(document).trigger(event);
297        // for internal use
298        $events.triggerHandler(event);
299    }
300
301    var slideshow = (function() {
302        var active,
303            className = prefix + "Slideshow_",
304            click = "click." + prefix,
305            timeOut;
306
307        function clear() {
308            clearTimeout(timeOut);
309        }
310
311        function set() {
312            if (settings.get('loop') || $related[index + 1]) {
313                clear();
314                timeOut = setTimeout(publicMethod.next, settings.get('slideshowSpeed'));
315            }
316        }
317
318        function start() {
319            $slideshow
320                .html(settings.get('slideshowStop'))
321                .unbind(click)
322                .one(click, stop);
323
324            $events
325                .bind(event_complete, set)
326                .bind(event_load, clear);
327
328            $box.removeClass(className + "off").addClass(className + "on");
329        }
330
331        function stop() {
332            clear();
333
334            $events
335                .unbind(event_complete, set)
336                .unbind(event_load, clear);
337
338            $slideshow
339                .html(settings.get('slideshowStart'))
340                .unbind(click)
341                .one(click, function() {
342                    publicMethod.next();
343                    start();
344                });
345
346            $box.removeClass(className + "on").addClass(className + "off");
347        }
348
349        function reset() {
350            active = false;
351            $slideshow.hide();
352            clear();
353            $events
354                .unbind(event_complete, set)
355                .unbind(event_load, clear);
356            $box.removeClass(className + "off " + className + "on");
357        }
358
359        return function() {
360            if (active) {
361                if (!settings.get('slideshow')) {
362                    $events.unbind(event_cleanup, reset);
363                    reset();
364                }
365            } else {
366                if (settings.get('slideshow') && $related[1]) {
367                    active = true;
368                    $events.one(event_cleanup, reset);
369                    if (settings.get('slideshowAuto')) {
370                        start();
371                    } else {
372                        stop();
373                    }
374                    $slideshow.show();
375                }
376            }
377        };
378
379    }());
380
381
382    function launch(element) {
383        var options;
384
385        if (!closing) {
386
387            options = $(element).data(colorbox);
388
389            settings = new Settings(element, options);
390
391            getRelated(settings.get('rel'));
392
393            if (!open) {
394                open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
395
396                setClass(settings.get('className'));
397
398                // Show colorbox so the sizes can be calculated in older versions of jQuery
399                $box.css({
400                    visibility: 'hidden',
401                    display: 'block',
402                    opacity: ''
403                });
404
405                $loaded = $tag(div, 'LoadedContent', 'width:0; height:0; overflow:hidden; visibility:hidden');
406                $content.css({
407                    width: '',
408                    height: ''
409                }).append($loaded);
410
411                // Cache values needed for size calculations
412                interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();
413                interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width();
414                loadedHeight = $loaded.outerHeight(true);
415                loadedWidth = $loaded.outerWidth(true);
416
417                // Opens inital empty Colorbox prior to content being loaded.
418                var initialWidth = setSize(settings.get('initialWidth'), 'x');
419                var initialHeight = setSize(settings.get('initialHeight'), 'y');
420                var maxWidth = settings.get('maxWidth');
421                var maxHeight = settings.get('maxHeight');
422
423                settings.w = Math.max((maxWidth !== false ? Math.min(initialWidth, setSize(maxWidth, 'x')) : initialWidth) - loadedWidth - interfaceWidth, 0);
424                settings.h = Math.max((maxHeight !== false ? Math.min(initialHeight, setSize(maxHeight, 'y')) : initialHeight) - loadedHeight - interfaceHeight, 0);
425
426                $loaded.css({
427                    width: '',
428                    height: settings.h
429                });
430                publicMethod.position();
431
432                trigger(event_open);
433                settings.get('onOpen');
434
435                $groupControls.add($title).hide();
436
437                $box.focus();
438
439                if (settings.get('trapFocus')) {
440                    // Confine focus to the modal
441                    // Uses event capturing that is not supported in IE8-
442                    if (document.addEventListener) {
443
444                        document.addEventListener('focus', trapFocus, true);
445
446                        $events.one(event_closed, function() {
447                            document.removeEventListener('focus', trapFocus, true);
448                        });
449                    }
450                }
451
452                // Return focus on closing
453                if (settings.get('returnFocus')) {
454                    $events.one(event_closed, function() {
455                        $(settings.el).focus();
456                    });
457                }
458            }
459
460            var opacity = parseFloat(settings.get('opacity'));
461            $overlay.css({
462                opacity: opacity === opacity ? opacity : '',
463                cursor: settings.get('overlayClose') ? 'pointer' : '',
464                visibility: 'visible'
465            }).show();
466
467            if (settings.get('closeButton')) {
468                $close.html(settings.get('close')).appendTo($content);
469            } else {
470                $close.appendTo('<div/>'); // replace with .detach() when dropping jQuery < 1.4
471            }
472
473            load();
474        }
475    }
476
477    // Colorbox's markup needs to be added to the DOM prior to being called
478    // so that the browser will go ahead and load the CSS background images.
479    function appendHTML() {
480        if (!$box) {
481            init = false;
482            $window = $(window);
483            $box = $tag(div).attr({
484                id: colorbox,
485                'class': $.support.opacity === false ? prefix + 'IE' : '', // class for optional IE8 & lower targeted CSS.
486                role: 'dialog',
487                tabindex: '-1'
488            }).hide();
489            $overlay = $tag(div, "Overlay").hide();
490            $loadingOverlay = $([$tag(div, "LoadingOverlay")[0], $tag(div, "LoadingGraphic")[0]]);
491            $wrap = $tag(div, "Wrapper");
492            $content = $tag(div, "Content").append(
493                $title = $tag(div, "Title"),
494                $current = $tag(div, "Current"),
495                $prev = $('<button type="button"/>').attr({
496                    id: prefix + 'Previous'
497                }),
498                $next = $('<button type="button"/>').attr({
499                    id: prefix + 'Next'
500                }),
501                $slideshow = $tag('button', "Slideshow"),
502                $loadingOverlay
503            );
504
505            $close = $('<button type="button"/>').attr({
506                id: prefix + 'Close'
507            });
508
509            $wrap.append( // The 3x3 Grid that makes up Colorbox
510                $tag(div).append(
511                    $tag(div, "TopLeft"),
512                    $topBorder = $tag(div, "TopCenter"),
513                    $tag(div, "TopRight")
514                ),
515                $tag(div, false, 'clear:left').append(
516                    $leftBorder = $tag(div, "MiddleLeft"),
517                    $content,
518                    $rightBorder = $tag(div, "MiddleRight")
519                ),
520                $tag(div, false, 'clear:left').append(
521                    $tag(div, "BottomLeft"),
522                    $bottomBorder = $tag(div, "BottomCenter"),
523                    $tag(div, "BottomRight")
524                )
525            ).find('div div').css({
526                'float': 'left'
527            });
528
529            $loadingBay = $tag(div, false, 'position:absolute; width:9999px; visibility:hidden; display:none; max-width:none;');
530
531            $groupControls = $next.add($prev).add($current).add($slideshow);
532        }
533        if (document.body && !$box.parent().length) {
534            $(document.body).append($overlay, $box.append($wrap, $loadingBay));
535        }
536    }
537
538    // Add Colorbox's event bindings
539    function addBindings() {
540        function clickHandler(e) {
541            // ignore non-left-mouse-clicks and clicks modified with ctrl / command, shift, or alt.
542            // See: http://jacklmoore.com/notes/click-events/
543            if (!(e.which > 1 || e.shiftKey || e.altKey || e.metaKey || e.ctrlKey)) {
544                e.preventDefault();
545                launch(this);
546            }
547        }
548
549        if ($box) {
550            if (!init) {
551                init = true;
552
553                // Anonymous functions here keep the public method from being cached, thereby allowing them to be redefined on the fly.
554                $next.click(function() {
555                    publicMethod.next();
556                });
557                $prev.click(function() {
558                    publicMethod.prev();
559                });
560                $close.click(function() {
561                    publicMethod.close();
562                });
563                $overlay.click(function() {
564                    if (settings.get('overlayClose')) {
565                        publicMethod.close();
566                    }
567                });
568
569                // Key Bindings
570                $(document).bind('keydown.' + prefix, function(e) {
571                    var key = e.keyCode;
572                    if (open && settings.get('escKey') && key === 27) {
573                        e.preventDefault();
574                        publicMethod.close();
575                    }
576                    if (open && settings.get('arrowKey') && $related[1] && !e.altKey) {
577                        if (key === 37) {
578                            e.preventDefault();
579                            $prev.click();
580                        } else if (key === 39) {
581                            e.preventDefault();
582                            $next.click();
583                        }
584                    }
585                });
586
587                if ($.isFunction($.fn.on)) {
588                    // For jQuery 1.7+
589                    $(document).on('click.' + prefix, '.' + boxElement, clickHandler);
590                } else {
591                    // For jQuery 1.3.x -> 1.6.x
592                    // This code is never reached in jQuery 1.9, so do not contact me about 'live' being removed.
593                    // This is not here for jQuery 1.9, it's here for legacy users.
594                    $('.' + boxElement).on('click.' + prefix, clickHandler);
595                }
596            }
597            return true;
598        }
599        return false;
600    }
601
602    // Don't do anything if Colorbox already exists.
603    if ($[colorbox]) {
604        return;
605    }
606
607    // Append the HTML when the DOM loads
608    $(appendHTML);
609
610
611    // ****************
612    // PUBLIC FUNCTIONS
613    // Usage format: $.colorbox.close();
614    // Usage from within an iframe: parent.jQuery.colorbox.close();
615    // ****************
616
617    publicMethod = $.fn[colorbox] = $[colorbox] = function(options, callback) {
618        var settings;
619        var $obj = this;
620
621        options = options || {};
622
623        if ($.isFunction($obj)) { // assume a call to $.colorbox
624            $obj = $('<a/>');
625            options.open = true;
626        }
627
628        if (!$obj[0]) { // colorbox being applied to empty collection
629            return $obj;
630        }
631
632        appendHTML();
633
634        if (addBindings()) {
635
636            if (callback) {
637                options.onComplete = callback;
638            }
639
640            $obj.each(function() {
641                var old = $.data(this, colorbox) || {};
642                $.data(this, colorbox, $.extend(old, options));
643            }).addClass(boxElement);
644
645            settings = new Settings($obj[0], options);
646
647            if (settings.get('open')) {
648                launch($obj[0]);
649            }
650        }
651
652        return $obj;
653    };
654
655    publicMethod.position = function(speed, loadedCallback) {
656        var
657            css,
658            top = 0,
659            left = 0,
660            offset = $box.offset(),
661            scrollTop,
662            scrollLeft;
663
664        $window.unbind('resize.' + prefix);
665
666        // remove the modal so that it doesn't influence the document width/height
667        $box.css({
668            top: -9e4,
669            left: -9e4
670        });
671
672        scrollTop = $window.scrollTop();
673        scrollLeft = $window.scrollLeft();
674
675        if (settings.get('fixed')) {
676            offset.top -= scrollTop;
677            offset.left -= scrollLeft;
678            $box.css({
679                position: 'fixed'
680            });
681        } else {
682            top = scrollTop;
683            left = scrollLeft;
684            $box.css({
685                position: 'absolute'
686            });
687        }
688
689        // keeps the top and left positions within the browser's viewport.
690        if (settings.get('right') !== false) {
691            left += Math.max($window.width() - settings.w - loadedWidth - interfaceWidth - setSize(settings.get('right'), 'x'), 0);
692        } else if (settings.get('left') !== false) {
693            left += setSize(settings.get('left'), 'x');
694        } else {
695            left += Math.round(Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2);
696        }
697
698        if (settings.get('bottom') !== false) {
699            top += Math.max(winheight() - settings.h - loadedHeight - interfaceHeight - setSize(settings.get('bottom'), 'y'), 0);
700        } else if (settings.get('top') !== false) {
701            top += setSize(settings.get('top'), 'y');
702        } else {
703            top += Math.round(Math.max(winheight() - settings.h - loadedHeight - interfaceHeight, 0) / 2);
704        }
705
706        $box.css({
707            top: offset.top,
708            left: offset.left,
709            visibility: 'visible'
710        });
711
712        // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
713        // but it has to be shrank down around the size of div#colorbox when it's done.  If not,
714        // it can invoke an obscure IE bug when using iframes.
715        $wrap[0].style.width = $wrap[0].style.height = "9999px";
716
717        function modalDimensions() {
718            $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = (parseInt($box[0].style.width, 10) - interfaceWidth) + 'px';
719            $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = (parseInt($box[0].style.height, 10) - interfaceHeight) + 'px';
720        }
721
722        css = {
723            width: settings.w + loadedWidth + interfaceWidth,
724            height: settings.h + loadedHeight + interfaceHeight,
725            top: top,
726            left: left
727        };
728
729        // setting the speed to 0 if the content hasn't changed size or position
730        if (speed) {
731            var tempSpeed = 0;
732            $.each(css, function(i) {
733                if (css[i] !== previousCSS[i]) {
734                    tempSpeed = speed;
735                    return;
736                }
737            });
738            speed = tempSpeed;
739        }
740
741        previousCSS = css;
742
743        if (!speed) {
744            $box.css(css);
745        }
746
747        $box.dequeue().animate(css, {
748            duration: speed || 0,
749            complete: function() {
750                modalDimensions();
751
752                active = false;
753
754                // shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
755                $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
756                $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
757
758                if (settings.get('reposition')) {
759                    setTimeout(function() { // small delay before binding onresize due to an IE8 bug.
760                        $window.bind('resize.' + prefix, publicMethod.position);
761                    }, 1);
762                }
763
764                if ($.isFunction(loadedCallback)) {
765                    loadedCallback();
766                }
767            },
768            step: modalDimensions
769        });
770    };
771
772    publicMethod.resize = function(options) {
773        var scrolltop;
774
775        if (open) {
776            options = options || {};
777
778            if (options.width) {
779                settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
780            }
781
782            if (options.innerWidth) {
783                settings.w = setSize(options.innerWidth, 'x');
784            }
785
786            $loaded.css({
787                width: settings.w
788            });
789
790            if (options.height) {
791                settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
792            }
793
794            if (options.innerHeight) {
795                settings.h = setSize(options.innerHeight, 'y');
796            }
797
798            if (!options.innerHeight && !options.height) {
799                scrolltop = $loaded.scrollTop();
800                $loaded.css({
801                    height: "auto"
802                });
803                settings.h = $loaded.height();
804            }
805
806            $loaded.css({
807                height: settings.h
808            });
809
810            if (scrolltop) {
811                $loaded.scrollTop(scrolltop);
812            }
813
814            publicMethod.position(settings.get('transition') === "none" ? 0 : settings.get('speed'));
815        }
816    };
817
818    publicMethod.prep = function(object) {
819        if (!open) {
820            return;
821        }
822
823        var callback, speed = settings.get('transition') === "none" ? 0 : settings.get('speed');
824
825        $loaded.remove();
826
827        $loaded = $tag(div, 'LoadedContent').append(object);
828
829        function getWidth() {
830            settings.w = settings.w || $loaded.width();
831            settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
832            return settings.w;
833        }
834
835        function getHeight() {
836            settings.h = settings.h || $loaded.height();
837            settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
838            return settings.h;
839        }
840
841        $loaded.hide()
842            .appendTo($loadingBay.show()) // content has to be appended to the DOM for accurate size calculations.
843            .css({
844                width: getWidth(),
845                overflow: settings.get('scrolling') ? 'auto' : 'hidden'
846            })
847            .css({
848                height: getHeight()
849            }) // sets the height independently from the width in case the new width influences the value of height.
850            .prependTo($content);
851
852        $loadingBay.hide();
853
854        // floating the IMG removes the bottom line-height and fixed a problem where IE miscalculates the width of the parent element as 100% of the document width.
855
856        $(photo).css({
857            'float': 'none'
858        });
859
860        setClass(settings.get('className'));
861
862        callback = function() {
863            var total = $related.length,
864                iframe,
865                complete;
866
867            if (!open) {
868                return;
869            }
870
871            function removeFilter() { // Needed for IE8 in versions of jQuery prior to 1.7.2
872                if ($.support.opacity === false) {
873                    $box[0].style.removeAttribute('filter');
874                }
875            }
876
877            complete = function() {
878                clearTimeout(loadingTimer);
879                $loadingOverlay.hide();
880                trigger(event_complete);
881                settings.get('onComplete');
882            };
883
884
885            $title.html(settings.get('title')).show();
886            $loaded.show();
887
888            if (total > 1) { // handle grouping
889                if (typeof settings.get('current') === "string") {
890                    $current.html(settings.get('current').replace('{current}', index + 1).replace('{total}', total)).show();
891                }
892
893                $next[(settings.get('loop') || index < total - 1) ? "show" : "hide"]().html(settings.get('next'));
894                $prev[(settings.get('loop') || index) ? "show" : "hide"]().html(settings.get('previous'));
895
896                slideshow();
897
898                // Preloads images within a rel group
899                if (settings.get('preloading')) {
900                    $.each([getIndex(-1), getIndex(1)], function() {
901                        var img,
902                            i = $related[this],
903                            settings = new Settings(i, $.data(i, colorbox)),
904                            src = settings.get('href');
905
906                        if (src && isImage(settings, src)) {
907                            src = retinaUrl(settings, src);
908                            img = document.createElement('img');
909                            img.src = src;
910                        }
911                    });
912                }
913            } else {
914                $groupControls.hide();
915            }
916
917            if (settings.get('iframe')) {
918
919                iframe = settings.get('createIframe');
920
921                if (!settings.get('scrolling')) {
922                    iframe.scrolling = "no";
923                }
924
925                $(iframe)
926                    .attr({
927                        src: settings.get('href'),
928                        'class': prefix + 'Iframe'
929                    })
930                    .one('load', complete)
931                    .appendTo($loaded);
932
933                $events.one(event_purge, function() {
934                    iframe.src = "//about:blank";
935                });
936
937                if (settings.get('fastIframe')) {
938                    $(iframe).trigger('load');
939                }
940            } else {
941                complete();
942            }
943
944            if (settings.get('transition') === 'fade') {
945                $box.fadeTo(speed, 1, removeFilter);
946            } else {
947                removeFilter();
948            }
949        };
950
951        if (settings.get('transition') === 'fade') {
952            $box.fadeTo(speed, 0, function() {
953                publicMethod.position(0, callback);
954            });
955        } else {
956            publicMethod.position(speed, callback);
957        }
958    };
959
960    function load() {
961        var href, setResize, prep = publicMethod.prep,
962            $inline, request = ++requests;
963
964        active = true;
965
966        photo = false;
967
968        trigger(event_purge);
969        trigger(event_load);
970        settings.get('onLoad');
971
972        settings.h = settings.get('height') ?
973            setSize(settings.get('height'), 'y') - loadedHeight - interfaceHeight :
974            settings.get('innerHeight') && setSize(settings.get('innerHeight'), 'y');
975
976        settings.w = settings.get('width') ?
977            setSize(settings.get('width'), 'x') - loadedWidth - interfaceWidth :
978            settings.get('innerWidth') && setSize(settings.get('innerWidth'), 'x');
979
980        // Sets the minimum dimensions for use in image scaling
981        settings.mw = settings.w;
982        settings.mh = settings.h;
983
984        // Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
985        // If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
986        if (settings.get('maxWidth')) {
987            settings.mw = setSize(settings.get('maxWidth'), 'x') - loadedWidth - interfaceWidth;
988            settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
989        }
990        if (settings.get('maxHeight')) {
991            settings.mh = setSize(settings.get('maxHeight'), 'y') - loadedHeight - interfaceHeight;
992            settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
993        }
994
995        href = settings.get('href');
996
997        loadingTimer = setTimeout(function() {
998            $loadingOverlay.show();
999        }, 100);
1000
1001        if (settings.get('inline')) {
1002            var $target = $(href);
1003            // Inserts an empty placeholder where inline content is being pulled from.
1004            // An event is bound to put inline content back when Colorbox closes or loads new content.
1005            $inline = $('<div>').hide().insertBefore($target);
1006
1007            $events.one(event_purge, function() {
1008                $inline.replaceWith($target);
1009            });
1010
1011            prep($target);
1012        } else if (settings.get('iframe')) {
1013            // IFrame element won't be added to the DOM until it is ready to be displayed,
1014            // to avoid problems with DOM-ready JS that might be trying to run in that iframe.
1015            prep(" ");
1016        } else if (settings.get('html')) {
1017            prep(settings.get('html'));
1018        } else if (isImage(settings, href)) {
1019
1020            href = retinaUrl(settings, href);
1021
1022            photo = settings.get('createImg');
1023
1024            $(photo)
1025                .addClass(prefix + 'Photo')
1026                .bind('error.' + prefix, function() {
1027                    prep($tag(div, 'Error').html(settings.get('imgError')));
1028                })
1029                .one('load', function() {
1030                    if (request !== requests) {
1031                        return;
1032                    }
1033
1034                    // A small pause because some browsers will occassionaly report a
1035                    // img.width and img.height of zero immediately after the img.onload fires
1036                    setTimeout(function() {
1037                        var percent;
1038
1039                        if (settings.get('retinaImage') && window.devicePixelRatio > 1) {
1040                            photo.height = photo.height / window.devicePixelRatio;
1041                            photo.width = photo.width / window.devicePixelRatio;
1042                        }
1043
1044                        if (settings.get('scalePhotos')) {
1045                            setResize = function() {
1046                                photo.height -= photo.height * percent;
1047                                photo.width -= photo.width * percent;
1048                            };
1049                            if (settings.mw && photo.width > settings.mw) {
1050                                percent = (photo.width - settings.mw) / photo.width;
1051                                setResize();
1052                            }
1053                            if (settings.mh && photo.height > settings.mh) {
1054                                percent = (photo.height - settings.mh) / photo.height;
1055                                setResize();
1056                            }
1057                        }
1058
1059                        if (settings.h) {
1060                            photo.style.marginTop = Math.max(settings.mh - photo.height, 0) / 2 + 'px';
1061                        }
1062
1063                        if ($related[1] && (settings.get('loop') || $related[index + 1])) {
1064                            photo.style.cursor = 'pointer';
1065
1066                            $(photo).bind('click.' + prefix, function() {
1067                                publicMethod.next();
1068                            });
1069                        }
1070
1071                        photo.style.width = photo.width + 'px';
1072                        photo.style.height = photo.height + 'px';
1073                        prep(photo);
1074                    }, 1);
1075                });
1076
1077            photo.src = href;
1078
1079        } else if (href) {
1080            $loadingBay.load(href, settings.get('data'), function(data, status) {
1081                if (request === requests) {
1082                    prep(status === 'error' ? $tag(div, 'Error').html(settings.get('xhrError')) : $(this).contents());
1083                }
1084            });
1085        }
1086    }
1087
1088    // Navigates to the next page/image in a set.
1089    publicMethod.next = function() {
1090        if (!active && $related[1] && (settings.get('loop') || $related[index + 1])) {
1091            index = getIndex(1);
1092            launch($related[index]);
1093        }
1094    };
1095
1096    publicMethod.prev = function() {
1097        if (!active && $related[1] && (settings.get('loop') || index)) {
1098            index = getIndex(-1);
1099            launch($related[index]);
1100        }
1101    };
1102
1103    // Note: to use this within an iframe use the following format: parent.jQuery.colorbox.close();
1104    publicMethod.close = function() {
1105        if (open && !closing) {
1106
1107            closing = true;
1108            open = false;
1109            trigger(event_cleanup);
1110            settings.get('onCleanup');
1111            $window.unbind('.' + prefix);
1112            $overlay.fadeTo(settings.get('fadeOut') || 0, 0);
1113
1114            $box.stop().fadeTo(settings.get('fadeOut') || 0, 0, function() {
1115                $box.hide();
1116                $overlay.hide();
1117                trigger(event_purge);
1118                $loaded.remove();
1119
1120                setTimeout(function() {
1121                    closing = false;
1122                    trigger(event_closed);
1123                    settings.get('onClosed');
1124                }, 1);
1125            });
1126        }
1127    };
1128
1129    // Removes changes Colorbox made to the document, but does not remove the plugin.
1130    publicMethod.remove = function() {
1131        if (!$box) {
1132            return;
1133        }
1134
1135        $box.stop();
1136        $[colorbox].close();
1137        $box.stop(false, true).remove();
1138        $overlay.remove();
1139        closing = false;
1140        $box = null;
1141        $('.' + boxElement)
1142            .removeData(colorbox)
1143            .removeClass(boxElement);
1144
1145        $(document).unbind('click.' + prefix).unbind('keydown.' + prefix);
1146    };
1147
1148    // A method for fetching the current element Colorbox is referencing.
1149    // returns a jQuery object.
1150    publicMethod.element = function() {
1151        return $(settings.el);
1152    };
1153
1154    publicMethod.settings = defaults;
1155
1156}(jQuery, document, 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.