source: extensions/oAuth/include/test/examples/widget_authentication/widget/js/jquery.colorbox.js @ 20293

Last change on this file since 20293 was 20293, checked in by mistic100, 11 years ago

first commit of oAuth plugin, still in developpement

File size: 26.5 KB
Line 
1// ColorBox v1.3.17.1 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
2// Copyright (c) 2011 Jack Moore - jack@colorpowered.com
3// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
4(function ($, document, window) {
5        var
6        // ColorBox Default Settings.   
7        // See http://colorpowered.com/colorbox for details.
8        defaults = {
9                transition: "elastic",
10                speed: 300,
11                width: false,
12                initialWidth: "600",
13                innerWidth: false,
14                maxWidth: false,
15                height: false,
16                initialHeight: "450",
17                innerHeight: false,
18                maxHeight: false,
19                scalePhotos: true,
20                scrolling: true,
21                inline: false,
22                html: false,
23                iframe: false,
24                fastIframe: true,
25                photo: false,
26                href: false,
27                title: false,
28                rel: false,
29                opacity: 0.9,
30                preloading: true,
31                current: "image {current} of {total}",
32                previous: "previous",
33                next: "next",
34                close: "close",
35                open: false,
36                returnFocus: true,
37                loop: true,
38                slideshow: false,
39                slideshowAuto: true,
40                slideshowSpeed: 2500,
41                slideshowStart: "start slideshow",
42                slideshowStop: "stop slideshow",
43                onOpen: false,
44                onLoad: false,
45                onComplete: false,
46                onCleanup: false,
47                onClosed: false,
48                overlayClose: true,             
49                escKey: true,
50                arrowKey: true,
51        top: false,
52        bottom: false,
53        left: false,
54        right: false,
55        fixed: false,
56        data: false
57        },
58       
59        // Abstracting the HTML and event identifiers for easy rebranding
60        colorbox = 'colorbox',
61        prefix = 'cbox',
62       
63        // Events       
64        event_open = prefix + '_open',
65        event_load = prefix + '_load',
66        event_complete = prefix + '_complete',
67        event_cleanup = prefix + '_cleanup',
68        event_closed = prefix + '_closed',
69        event_purge = prefix + '_purge',
70       
71        // Special Handling for IE
72        isIE = $.browser.msie && !$.support.opacity, // Detects IE6,7,8.  IE9 supports opacity.  Feature detection alone gave a false positive on at least one phone browser and on some development versions of Chrome, hence the user-agent test.
73        isIE6 = isIE && $.browser.version < 7,
74        event_ie6 = prefix + '_IE6',
75
76        // Cached jQuery Object Variables
77        $overlay,
78        $box,
79        $wrap,
80        $content,
81        $topBorder,
82        $leftBorder,
83        $rightBorder,
84        $bottomBorder,
85        $related,
86        $window,
87        $loaded,
88        $loadingBay,
89        $loadingOverlay,
90        $title,
91        $current,
92        $slideshow,
93        $next,
94        $prev,
95        $close,
96        $groupControls,
97
98        // Variables for cached values or use across multiple functions
99        settings = {},
100        interfaceHeight,
101        interfaceWidth,
102        loadedHeight,
103        loadedWidth,
104        element,
105        index,
106        photo,
107        open,
108        active,
109        closing,
110    handler,
111    loadingTimer,
112       
113        publicMethod,
114        boxElement = prefix + 'Element';
115       
116        // ****************
117        // HELPER FUNCTIONS
118        // ****************
119
120        // jQuery object generator to reduce code size
121        function $div(id, cssText) { 
122                var div = document.createElement('div');
123                if (id) {
124            div.id = prefix + id;
125        }
126                div.style.cssText = cssText || '';
127                return $(div);
128        }
129
130        // Convert % values to pixels
131        function setSize(size, dimension) {
132                dimension = dimension === 'x' ? $window.width() : $window.height();
133                return (typeof size === 'string') ? Math.round((/%/.test(size) ? (dimension / 100) * parseInt(size, 10) : parseInt(size, 10))) : size;
134        }
135       
136        // Checks an href to see if it is a photo.
137        // There is a force photo option (photo: true) for hrefs that cannot be matched by this regex.
138        function isImage(url) {
139                return settings.photo || /\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(url);
140        }
141       
142        // Assigns function results to their respective settings.  This allows functions to be used as values.
143        function process(settings) {
144                for (var i in settings) {
145                        if ($.isFunction(settings[i]) && i.substring(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time.
146                            settings[i] = settings[i].call(element);
147                        }
148                }
149       
150                settings.rel = settings.rel || element.rel || 'nofollow';
151                settings.href = settings.href || $(element).attr('href');
152                settings.title = settings.title || element.title;
153       
154        if (typeof settings.href === "string") {
155            settings.href = $.trim(settings.href);
156        }
157        }
158
159        function trigger(event, callback) {
160                if (callback) {
161                        callback.call(element);
162                }
163                $.event.trigger(event);
164        }
165
166        // Slideshow functionality
167        function slideshow() {
168                var
169                timeOut,
170                className = prefix + "Slideshow_",
171                click = "click." + prefix,
172                start,
173                stop,
174                clear;
175               
176                if (settings.slideshow && $related[1]) {
177                        start = function () {
178                                $slideshow
179                                        .text(settings.slideshowStop)
180                                        .unbind(click)
181                                        .bind(event_complete, function () {
182                                                if (index < $related.length - 1 || settings.loop) {
183                                                        timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
184                                                }
185                                        })
186                                        .bind(event_load, function () {
187                                                clearTimeout(timeOut);
188                                        })
189                                        .one(click + ' ' + event_cleanup, stop);
190                                $box.removeClass(className + "off").addClass(className + "on");
191                                timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
192                        };
193                       
194                        stop = function () {
195                                clearTimeout(timeOut);
196                                $slideshow
197                                        .text(settings.slideshowStart)
198                                        .unbind([event_complete, event_load, event_cleanup, click].join(' '))
199                                        .one(click, start);
200                                $box.removeClass(className + "on").addClass(className + "off");
201                        };
202                       
203                        if (settings.slideshowAuto) {
204                                start();
205                        } else {
206                                stop();
207                        }
208                } else {
209            $box.removeClass(className + "off " + className + "on");
210        }
211        }
212
213        function launch(elem) {
214                if (!closing) {
215                       
216                        element = elem;
217                       
218                        process($.extend(settings, $.data(element, colorbox)));
219                       
220                        $related = $(element);
221                       
222                        index = 0;
223                       
224                        if (settings.rel !== 'nofollow') {
225                                $related = $('.' + boxElement).filter(function () {
226                                        var relRelated = $.data(this, colorbox).rel || this.rel;
227                                        return (relRelated === settings.rel);
228                                });
229                                index = $related.index(element);
230                               
231                                // Check direct calls to ColorBox.
232                                if (index === -1) {
233                                        $related = $related.add(element);
234                                        index = $related.length - 1;
235                                }
236                        }
237                       
238                        if (!open) {
239                                open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
240                               
241                                $box.show();
242                               
243                                if (settings.returnFocus) {
244                                        try {
245                                                element.blur();
246                                                $(element).one(event_closed, function () {
247                                                        try {
248                                                                this.focus();
249                                                        } catch (e) {
250                                                                // do nothing
251                                                        }
252                                                });
253                                        } catch (e) {
254                                                // do nothing
255                                        }
256                                }
257                               
258                                // +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5'
259                                $overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show();
260                               
261                                // Opens inital empty ColorBox prior to content being loaded.
262                                settings.w = setSize(settings.initialWidth, 'x');
263                                settings.h = setSize(settings.initialHeight, 'y');
264                                publicMethod.position(0);
265                               
266                                if (isIE6) {
267                                        $window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () {
268                                                $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()});
269                                        }).trigger('resize.' + event_ie6);
270                                }
271                               
272                                trigger(event_open, settings.onOpen);
273                               
274                                $groupControls.add($title).hide();
275                               
276                                $close.html(settings.close).show();
277                        }
278                       
279                        publicMethod.load(true);
280                }
281        }
282
283        // ****************
284        // PUBLIC FUNCTIONS
285        // Usage format: $.fn.colorbox.close();
286        // Usage from within an iframe: parent.$.fn.colorbox.close();
287        // ****************
288       
289        publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) {
290                var $this = this, autoOpen;
291               
292                if (!$this[0] && $this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit.
293                        return $this;
294                }
295               
296                options = options || {};
297               
298                if (callback) {
299                        options.onComplete = callback;
300                }
301               
302                if (!$this[0] || $this.selector === undefined) { // detects $.colorbox() and $.fn.colorbox()
303                        $this = $('<a/>');
304                        options.open = true; // assume an immediate open
305                }
306               
307                $this.each(function () {
308                        $.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options));
309                        $(this).addClass(boxElement);
310                });
311               
312                autoOpen = options.open;
313               
314                if ($.isFunction(autoOpen)) {
315                        autoOpen = autoOpen.call($this);
316                }
317               
318                if (autoOpen) {
319                        launch($this[0]);
320                }
321               
322                return $this;
323        };
324
325        // Initialize ColorBox: store common calculations, preload the interface graphics, append the html.
326        // This preps colorbox for a speedy open when clicked, and lightens the burdon on the browser by only
327        // having to run once, instead of each time colorbox is opened.
328        publicMethod.init = function () {
329                // Create & Append jQuery Objects
330                $window = $(window);
331                $box = $div().attr({id: colorbox, 'class': isIE ? prefix + (isIE6 ? 'IE6' : 'IE') : ''});
332                $overlay = $div("Overlay", isIE6 ? 'position:absolute' : '').hide();
333               
334                $wrap = $div("Wrapper");
335                $content = $div("Content").append(
336                        $loaded = $div("LoadedContent", 'width:0; height:0; overflow:hidden'),
337                        $loadingOverlay = $div("LoadingOverlay").add($div("LoadingGraphic")),
338                        $title = $div("Title"),
339                        $current = $div("Current"),
340                        $next = $div("Next"),
341                        $prev = $div("Previous"),
342                        $slideshow = $div("Slideshow").bind(event_open, slideshow),
343                        $close = $div("Close")
344                );
345                $wrap.append( // The 3x3 Grid that makes up ColorBox
346                        $div().append(
347                                $div("TopLeft"),
348                                $topBorder = $div("TopCenter"),
349                                $div("TopRight")
350                        ),
351                        $div(false, 'clear:left').append(
352                                $leftBorder = $div("MiddleLeft"),
353                                $content,
354                                $rightBorder = $div("MiddleRight")
355                        ),
356                        $div(false, 'clear:left').append(
357                                $div("BottomLeft"),
358                                $bottomBorder = $div("BottomCenter"),
359                                $div("BottomRight")
360                        )
361                ).children().children().css({'float': 'left'});
362               
363                $loadingBay = $div(false, 'position:absolute; width:9999px; visibility:hidden; display:none');
364               
365                $('body').prepend($overlay, $box.append($wrap, $loadingBay));
366               
367                $content.children()
368                .hover(function () {
369                        $(this).addClass('hover');
370                }, function () {
371                        $(this).removeClass('hover');
372                }).addClass('hover');
373               
374                // Cache values needed for size calculations
375                interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6
376                interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width();
377                loadedHeight = $loaded.outerHeight(true);
378                loadedWidth = $loaded.outerWidth(true);
379               
380                // Setting padding to remove the need to do size conversions during the animation step.
381                $box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide();
382               
383        // Setup button events.
384        $next.click(function () {
385            publicMethod.next();
386        });
387        $prev.click(function () {
388            publicMethod.prev();
389        });
390        $close.click(function () {
391            publicMethod.close();
392        });
393               
394                $groupControls = $next.add($prev).add($current).add($slideshow);
395               
396                // Adding the 'hover' class allowed the browser to load the hover-state
397                // background graphics.  The class can now can be removed.
398                $content.children().removeClass('hover');
399               
400
401
402       
403                $overlay.click(function () {
404                        if (settings.overlayClose) {
405                                publicMethod.close();
406                        }
407                });
408               
409                // Set Navigation Key Bindings
410                $(document).bind('keydown.' + prefix, function (e) {
411            var key = e.keyCode;
412                        if (open && settings.escKey && key === 27) {
413                                e.preventDefault();
414                                publicMethod.close();
415                        }
416                        if (open && settings.arrowKey && $related[1]) {
417                                if (key === 37) {
418                                        e.preventDefault();
419                                        $prev.click();
420                                } else if (key === 39) {
421                                        e.preventDefault();
422                                        $next.click();
423                                }
424                        }
425                });
426        };
427       
428        publicMethod.remove = function () {
429                $box.add($overlay).remove();
430                $('.' + boxElement).removeData(colorbox).removeClass(boxElement);
431        };
432
433        publicMethod.position = function (speed, loadedCallback) {
434        var animate_speed, top = 0, left = 0;
435       
436        // remove the modal so that it doesn't influence the document width/height       
437        $box.hide();
438       
439        if (settings.fixed && !isIE6) {
440            $box.css({position: 'fixed'});
441        } else {
442            top = $window.scrollTop();
443            left = $window.scrollLeft();
444            $box.css({position: 'absolute'});
445        }
446       
447                // keeps the top and left positions within the browser's viewport.
448        if (settings.right !== false) {
449            left += Math.max($window.width() - settings.w - loadedWidth - interfaceWidth - setSize(settings.right, 'x'), 0);
450        } else if (settings.left !== false) {
451            left += setSize(settings.left, 'x');
452        } else {
453            left += Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2;
454        }
455       
456        if (settings.bottom !== false) {
457            top += Math.max(document.documentElement.clientHeight - settings.h - loadedHeight - interfaceHeight - setSize(settings.bottom, 'y'), 0);
458        } else if (settings.top !== false) {
459            top += setSize(settings.top, 'y');
460        } else {
461            top += Math.max(document.documentElement.clientHeight - settings.h - loadedHeight - interfaceHeight, 0) / 2;
462        }
463       
464        $box.show();
465       
466                // setting the speed to 0 to reduce the delay between same-sized content.
467                animate_speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed;
468       
469                // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
470                // but it has to be shrank down around the size of div#colorbox when it's done.  If not,
471                // it can invoke an obscure IE bug when using iframes.
472                $wrap[0].style.width = $wrap[0].style.height = "9999px";
473               
474                function modalDimensions(that) {
475                        // loading overlay height has to be explicitly set for IE6.
476                        $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width;
477                        $loadingOverlay[0].style.height = $loadingOverlay[1].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height;
478                }
479               
480                $box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: top, left: left}, {
481                        duration: animate_speed,
482                        complete: function () {
483                                modalDimensions(this);
484                               
485                                active = false;
486                               
487                                // shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
488                                $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
489                                $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
490                               
491                                if (loadedCallback) {
492                                        loadedCallback();
493                                }
494                        },
495                        step: function () {
496                                modalDimensions(this);
497                        }
498                });
499        };
500
501        publicMethod.resize = function (options) {
502                if (open) {
503                        options = options || {};
504                       
505                        if (options.width) {
506                                settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
507                        }
508                        if (options.innerWidth) {
509                                settings.w = setSize(options.innerWidth, 'x');
510                        }
511                        $loaded.css({width: settings.w});
512                       
513                        if (options.height) {
514                                settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
515                        }
516                        if (options.innerHeight) {
517                                settings.h = setSize(options.innerHeight, 'y');
518                        }
519                        if (!options.innerHeight && !options.height) {                         
520                                var $child = $loaded.wrapInner("<div style='overflow:auto'></div>").children(); // temporary wrapper to get an accurate estimate of just how high the total content should be.
521                                settings.h = $child.height();
522                                $child.replaceWith($child.children()); // ditch the temporary wrapper div used in height calculation
523                        }
524                        $loaded.css({height: settings.h});
525                       
526                        publicMethod.position(settings.transition === "none" ? 0 : settings.speed);
527                }
528        };
529
530        publicMethod.prep = function (object) {
531                if (!open) {
532                        return;
533                }
534               
535                var speed = settings.transition === "none" ? 0 : settings.speed;
536               
537                $window.unbind('resize.' + prefix);
538                $loaded.remove();
539                $loaded = $div('LoadedContent').html(object);
540               
541                function getWidth() {
542                        settings.w = settings.w || $loaded.width();
543                        settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
544                        return settings.w;
545                }
546                function getHeight() {
547                        settings.h = settings.h || $loaded.height();
548                        settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
549                        return settings.h;
550                }
551               
552                $loaded.hide()
553                .appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
554                .css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'})
555                .css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
556                .prependTo($content);
557               
558                $loadingBay.hide();
559               
560                // 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.
561                //$(photo).css({'float': 'none', marginLeft: 'auto', marginRight: 'auto'});
562               
563        $(photo).css({'float': 'none'});
564       
565                // Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay.
566                if (isIE6) {
567                        $('select').not($box.find('select')).filter(function () {
568                                return this.style.visibility !== 'hidden';
569                        }).css({'visibility': 'hidden'}).one(event_cleanup, function () {
570                                this.style.visibility = 'inherit';
571                        });
572                }
573               
574                function setPosition(s) {
575                        publicMethod.position(s, function () {
576                                var prev, prevSrc, next, nextSrc, total = $related.length, iframe, complete;
577                               
578                                if (!open) {
579                                        return;
580                                }
581                               
582                function removeFilter() {
583                    if (isIE) {
584                        $box[0].style.removeAttribute('filter');
585                    }
586                }
587               
588                                complete = function () {
589                    clearTimeout(loadingTimer);
590                                        $loadingOverlay.hide();
591                                        trigger(event_complete, settings.onComplete);
592                                };
593                               
594                                if (isIE) {
595                                        //This fadeIn helps the bicubic resampling to kick-in.
596                                        if (photo) {
597                                                $loaded.fadeIn(100);
598                                        }
599                                }
600                               
601                                $title.html(settings.title).add($loaded).show();
602                               
603                                if (total > 1) { // handle grouping
604                                        if (typeof settings.current === "string") {
605                                                $current.html(settings.current.replace(/\{current\}/, index + 1).replace(/\{total\}/, total)).show();
606                                        }
607                                       
608                                        $next[(settings.loop || index < total - 1) ? "show" : "hide"]().html(settings.next);
609                                        $prev[(settings.loop || index) ? "show" : "hide"]().html(settings.previous);
610                                       
611                                        prev = index ? $related[index - 1] : $related[total - 1];
612                                        next = index < total - 1 ? $related[index + 1] : $related[0];
613                                       
614                                        if (settings.slideshow) {
615                                                $slideshow.show();
616                                        }
617                                       
618                                        // Preloads images within a rel group
619                                        if (settings.preloading) {
620                                                nextSrc = $.data(next, colorbox).href || next.href;
621                                                prevSrc = $.data(prev, colorbox).href || prev.href;
622                                               
623                                                nextSrc = $.isFunction(nextSrc) ? nextSrc.call(next) : nextSrc;
624                                                prevSrc = $.isFunction(prevSrc) ? prevSrc.call(prev) : prevSrc;
625                                               
626                                                if (isImage(nextSrc)) {
627                                                        $('<img/>')[0].src = nextSrc;
628                                                }
629                                               
630                                                if (isImage(prevSrc)) {
631                                                        $('<img/>')[0].src = prevSrc;
632                                                }
633                                        }
634                                } else {
635                                        $groupControls.hide();
636                                }
637                               
638                                if (settings.iframe) {
639                                        iframe = $('<iframe/>').addClass(prefix + 'Iframe')[0];
640                                       
641                                        if (settings.fastIframe) {
642                                                complete();
643                                        } else {
644                                                $(iframe).one('load', complete);
645                                        }
646                                        iframe.name = prefix + (+new Date());
647                                        iframe.src = settings.href;
648                                       
649                                        if (!settings.scrolling) {
650                                                iframe.scrolling = "no";
651                                        }
652                                       
653                                        if (isIE) {
654                        iframe.frameBorder = 0; 
655                                                iframe.allowTransparency = "true";
656                                        }
657                                       
658                                        $(iframe).appendTo($loaded).one(event_purge, function () {
659                                                iframe.src = "//about:blank";
660                                        });
661                                       
662                                        iframe.scrolling = "no";
663                                } else {
664                                        complete();
665                                }
666                               
667                                if (settings.transition === 'fade') {
668                                        $box.fadeTo(speed, 1, removeFilter);
669                                } else {
670                    removeFilter();
671                                }
672                               
673                                $window.bind('resize.' + prefix, function () {
674                                        publicMethod.position(0);
675                                });
676                        });
677                }
678               
679                if (settings.transition === 'fade') {
680                        $box.fadeTo(speed, 0, function () {
681                                setPosition(0);
682                        });
683                } else {
684                        setPosition(speed);
685                }
686        };
687
688        publicMethod.load = function (launched) {
689                var href, setResize, prep = publicMethod.prep;
690               
691                active = true;
692               
693                photo = false;
694               
695                element = $related[index];
696               
697                if (!launched) {
698                        process($.extend(settings, $.data(element, colorbox)));
699                }
700               
701                trigger(event_purge);
702               
703                trigger(event_load, settings.onLoad);
704               
705                settings.h = settings.height ?
706                                setSize(settings.height, 'y') - loadedHeight - interfaceHeight :
707                                settings.innerHeight && setSize(settings.innerHeight, 'y');
708               
709                settings.w = settings.width ?
710                                setSize(settings.width, 'x') - loadedWidth - interfaceWidth :
711                                settings.innerWidth && setSize(settings.innerWidth, 'x');
712               
713                // Sets the minimum dimensions for use in image scaling
714                settings.mw = settings.w;
715                settings.mh = settings.h;
716               
717                // Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
718                // If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
719                if (settings.maxWidth) {
720                        settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth;
721                        settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
722                }
723                if (settings.maxHeight) {
724                        settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight;
725                        settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
726                }
727               
728                href = settings.href;
729               
730        loadingTimer = setTimeout(function () {
731            $loadingOverlay.show();
732        }, 100);
733       
734                if (settings.inline) {
735                        // Inserts an empty placeholder where inline content is being pulled from.
736                        // An event is bound to put inline content back when ColorBox closes or loads new content.
737                        $div().hide().insertBefore($(href)[0]).one(event_purge, function () {
738                                $(this).replaceWith($loaded.children());
739                        });
740                        prep($(href));
741                } else if (settings.iframe) {
742                        // IFrame element won't be added to the DOM until it is ready to be displayed,
743                        // to avoid problems with DOM-ready JS that might be trying to run in that iframe.
744                        prep(" ");
745                } else if (settings.html) {
746                        prep(settings.html);
747                } else if (isImage(href)) {
748                        $(photo = new Image())
749                        .addClass(prefix + 'Photo')
750                        .error(function () {
751                                settings.title = false;
752                                prep($div('Error').text('This image could not be loaded'));
753                        })
754                        .load(function () {
755                                var percent;
756                                photo.onload = null; //stops animated gifs from firing the onload repeatedly.
757                               
758                                if (settings.scalePhotos) {
759                                        setResize = function () {
760                                                photo.height -= photo.height * percent;
761                                                photo.width -= photo.width * percent;   
762                                        };
763                                        if (settings.mw && photo.width > settings.mw) {
764                                                percent = (photo.width - settings.mw) / photo.width;
765                                                setResize();
766                                        }
767                                        if (settings.mh && photo.height > settings.mh) {
768                                                percent = (photo.height - settings.mh) / photo.height;
769                                                setResize();
770                                        }
771                                }
772                               
773                                if (settings.h) {
774                                        photo.style.marginTop = Math.max(settings.h - photo.height, 0) / 2 + 'px';
775                                }
776                               
777                                if ($related[1] && (index < $related.length - 1 || settings.loop)) {
778                                        photo.style.cursor = 'pointer';
779                                        photo.onclick = function () {
780                        publicMethod.next();
781                    };
782                                }
783                               
784                                if (isIE) {
785                                        photo.style.msInterpolationMode = 'bicubic';
786                                }
787                               
788                                setTimeout(function () { // A pause because Chrome will sometimes report a 0 by 0 size otherwise.
789                                        prep(photo);
790                                }, 1);
791                        });
792                       
793                        setTimeout(function () { // A pause because Opera 10.6+ will sometimes not run the onload function otherwise.
794                                photo.src = href;
795                        }, 1);
796                } else if (href) {
797                        $loadingBay.load(href, settings.data, function (data, status, xhr) {
798                                prep(status === 'error' ? $div('Error').text('Request unsuccessful: ' + xhr.statusText) : $(this).contents());
799                        });
800                }
801        };
802       
803        // Navigates to the next page/image in a set.
804        publicMethod.next = function () {
805                if (!active && $related[1] && (index < $related.length - 1 || settings.loop)) {
806                        index = index < $related.length - 1 ? index + 1 : 0;
807                        publicMethod.load();
808                }
809        };
810       
811        publicMethod.prev = function () {
812                if (!active && $related[1] && (index || settings.loop)) {
813                        index = index ? index - 1 : $related.length - 1;
814                        publicMethod.load();
815                }
816        };
817
818        // Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close();
819        publicMethod.close = function () {
820                if (open && !closing) {
821                       
822                        closing = true;
823                       
824                        open = false;
825                       
826                        trigger(event_cleanup, settings.onCleanup);
827                       
828                        $window.unbind('.' + prefix + ' .' + event_ie6);
829                       
830                        $overlay.fadeTo(200, 0);
831                       
832                        $box.stop().fadeTo(300, 0, function () {
833                 
834                                $box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide();
835                               
836                                trigger(event_purge);
837                               
838                                $loaded.remove();
839                               
840                                setTimeout(function () {
841                                        closing = false;
842                                        trigger(event_closed, settings.onClosed);
843                                }, 1);
844                        });
845                }
846        };
847
848        // A method for fetching the current element ColorBox is referencing.
849        // returns a jQuery object.
850        publicMethod.element = function () {
851                return $(element);
852        };
853
854        publicMethod.settings = defaults;
855   
856        // Bind the live event before DOM-ready for maximum performance in IE6 & 7.
857    handler = function (e) {
858        // checks to see if it was a non-left mouse-click and for clicks modified with ctrl, shift, or alt.
859        if (!((e.button !== 0 && typeof e.button !== 'undefined') || e.ctrlKey || e.shiftKey || e.altKey)) {
860            e.preventDefault();
861            launch(this);
862        }
863    };
864   
865    if ($.fn.delegate) {
866        $(document).delegate('.' + boxElement, 'click', handler);
867    } else {
868        $('.' + boxElement).live('click', handler);
869    }
870   
871        // Initializes ColorBox when the DOM has loaded
872        $(publicMethod.init);
873
874}(jQuery, document, this));
Note: See TracBrowser for help on using the repository browser.