Ignore:
Timestamp:
Apr 2, 2011, 11:53:02 AM (13 years ago)
Author:
patdenice
Message:

Update colorbox to 1.3.16

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/lightbox/js/jquery.colorbox.js

    r7949 r9976  
    1 // ColorBox v1.3.14 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
    2 // Copyright (c) 2010 Jack Moore - jack@colorpowered.com
     1// ColorBox v1.3.16 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+
     2// Copyright (c) 2011 Jack Moore - jack@colorpowered.com
    33// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
    4 (function ($, window) {
    5        
     4(function ($, document, window) {
    65        var
    76        // ColorBox Default Settings.   
     
    2322                html: false,
    2423                iframe: false,
     24                fastIframe: true,
    2525                photo: false,
    2626                href: false,
     
    6262        event_closed = prefix + '_closed',
    6363        event_purge = prefix + '_purge',
    64         event_loaded = prefix + '_loaded',
    6564       
    6665        // Special Handling for IE
     
    8988        $prev,
    9089        $close,
     90        $groupControls,
    9191
    9292        // Variables for cached values or use across multiple functions
     93        settings = {},
    9394        interfaceHeight,
    9495        interfaceWidth,
     
    9798        element,
    9899        index,
    99         settings,
     100        photo,
    100101        open,
    101102        active,
     
    110111
    111112        // jQuery object generator to reduce code size
    112         function $div(id, css) {
    113                 id = id ? ' id="' + prefix + id + '"' : '';
    114                 css = css ? ' style="' + css + '"' : '';
    115                 return $('<div' + id + css + '/>');
     113        function $div(id, cssText) {
     114                var div = document.createElement('div');
     115                if (id) {
     116            div.id = prefix + id;
     117        }
     118                div.style.cssText = cssText || false;
     119                return $(div);
    116120        }
    117121
     
    136140                }
    137141                settings.rel = settings.rel || element.rel || 'nofollow';
    138                 settings.href = settings.href || $(element).attr('href');
     142                settings.href = $.trim(settings.href || $(element).attr('href'));
    139143                settings.title = settings.title || element.title;
    140                 return settings;
    141144        }
    142145
     
    198201                        element = elem;
    199202                       
    200                         settings = process($.extend({}, $.data(element, colorbox)));
     203                        process($.extend(settings, $.data(element, colorbox)));
    201204                       
    202205                        $related = $(element);
     
    249252                                        $window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () {
    250253                                                $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()});
    251                                         }).trigger('scroll.' + event_ie6);
     254                                        }).trigger('resize.' + event_ie6);
    252255                                }
    253256                               
    254257                                trigger(event_open, settings.onOpen);
    255258                               
    256                                 $current.add($prev).add($next).add($slideshow).add($title).hide();
     259                                $groupControls.add($title).hide();
    257260                               
    258261                                $close.html(settings.close).show();
     
    311314                // Create & Append jQuery Objects
    312315                $window = $(window);
    313                 $box = $div().attr({id: colorbox, 'class': isIE ? prefix + 'IE' : ''});
     316                $box = $div().attr({id: colorbox, 'class': isIE ? prefix + (isIE6 ? 'IE6' : 'IE') : ''});
    314317                $overlay = $div("Overlay", isIE6 ? 'position:absolute' : '').hide();
    315318               
     
    363366                $box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide();
    364367               
    365                 // Setup button events.
    366                 $next.click(publicMethod.next);
    367                 $prev.click(publicMethod.prev);
    368                 $close.click(publicMethod.close);
     368                // Setup button events.
     369                $next.click(function () {
     370                        publicMethod.next();
     371                });
     372                $prev.click(function () {
     373                        publicMethod.prev();
     374                });
     375                $close.click(function () {
     376                        publicMethod.close();
     377                });
     378               
     379                $groupControls = $next.add($prev).add($current).add($slideshow);
    369380               
    370381                // Adding the 'hover' class allowed the browser to load the hover-state
     
    387398               
    388399                // Set Navigation Key Bindings
    389                 $(document).bind("keydown", function (e) {
    390                         if (open && settings.escKey && e.keyCode === 27) {
     400                $(document).bind('keydown.' + prefix, function (e) {
     401                        var key = e.keyCode;
     402                        if (open && settings.escKey && key === 27) {
    391403                                e.preventDefault();
    392404                                publicMethod.close();
    393405                        }
    394                         if (open && settings.arrowKey && !active && $related[1]) {
    395                                 if (e.keyCode === 37 && (index || settings.loop)) {
     406                        if (open && settings.arrowKey && $related[1]) {
     407                                if (key === 37) {
    396408                                        e.preventDefault();
    397409                                        $prev.click();
    398                                 } else if (e.keyCode === 39 && (index < $related.length - 1 || settings.loop)) {
     410                                } else if (key === 39) {
    399411                                        e.preventDefault();
    400412                                        $next.click();
     
    485497                }
    486498               
    487                 var photo,
    488                 speed = settings.transition === "none" ? 0 : settings.speed;
     499                var speed = settings.transition === "none" ? 0 : settings.speed;
    489500               
    490501                $window.unbind('resize.' + prefix);
     
    512523               
    513524                // 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.
    514                 $('#' + prefix + 'Photo').css({cssFloat: 'none', marginLeft: 'auto', marginRight: 'auto'});
    515                
     525                //$(photo).css({'float': 'none', marginLeft: 'auto', marginRight: 'auto'});
     526               
     527                $(photo).css({'float': 'none'});
     528               
    516529                // Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay.
    517530                if (isIE6) {
     
    522535                        });
    523536                }
    524                                
     537               
    525538                function setPosition(s) {
    526                         var prev, prevSrc, next, nextSrc, total = $related.length, loop = settings.loop;
    527539                        publicMethod.position(s, function () {
    528                                 function defilter() {
    529                                         if (isIE) {
    530                                                 //IE adds a filter when ColorBox fades in and out that can cause problems if the loaded content contains transparent pngs.
    531                                                 $box[0].style.filter = false;
    532                                         }
    533                                 }
     540                                var prev, prevSrc, next, nextSrc, total = $related.length, iframe, complete;
    534541                               
    535542                                if (!open) {
    536543                                        return;
    537544                                }
     545                               
     546                                complete = function () {
     547                                        $loadingOverlay.hide();
     548                                        trigger(event_complete, settings.onComplete);
     549                                };
    538550                               
    539551                                if (isIE) {
     
    544556                                }
    545557                               
    546                                 $loaded.show();
    547                                
    548                                 trigger(event_loaded);
    549                                
    550                                 $title.show().html(settings.title);
     558                                $title.html(settings.title).add($loaded).show();
    551559                               
    552560                                if (total > 1) { // handle grouping
     
    555563                                        }
    556564                                       
    557                                         $next[(loop || index < total - 1) ? "show" : "hide"]().html(settings.next);
    558                                         $prev[(loop || index) ? "show" : "hide"]().html(settings.previous);
     565                                        $next[(settings.loop || index < total - 1) ? "show" : "hide"]().html(settings.next);
     566                                        $prev[(settings.loop || index) ? "show" : "hide"]().html(settings.previous);
    559567                                       
    560568                                        prev = index ? $related[index - 1] : $related[total - 1];
     
    581589                                                }
    582590                                        }
    583                                 }
    584                                
    585                                 $loadingOverlay.hide();
     591                                } else {
     592                                        $groupControls.hide();
     593                                }
     594                               
     595                                if (settings.iframe) {
     596                                        iframe = $('<iframe/>').addClass(prefix + 'Iframe')[0];
     597                                       
     598                                        if (settings.fastIframe) {
     599                                                complete();
     600                                        } else {
     601                                                $(iframe).load(complete);
     602                                        }
     603                                        iframe.name = prefix + (+new Date());
     604                                        iframe.src = settings.href;
     605                                       
     606                                        if (!settings.scrolling) {
     607                                                iframe.scrolling = "no";
     608                                        }
     609                                       
     610                                        if (isIE) {
     611                        iframe.frameBorder=0;
     612                                                iframe.allowTransparency = "true";
     613                                        }
     614                                       
     615                                        $(iframe).appendTo($loaded).one(event_purge, function () {
     616                                                iframe.src = "//about:blank";
     617                                        });
     618                                } else {
     619                                        complete();
     620                                }
    586621                               
    587622                                if (settings.transition === 'fade') {
    588623                                        $box.fadeTo(speed, 1, function () {
    589                                                 defilter();
     624                                                $box[0].style.filter = "";
    590625                                        });
    591626                                } else {
    592                                         defilter();
     627                     $box[0].style.filter = "";
    593628                                }
    594629                               
     
    596631                                        publicMethod.position(0);
    597632                                });
    598                                
    599                                 trigger(event_complete, settings.onComplete);
    600633                        });
    601634                }
     
    611644
    612645        publicMethod.load = function (launched) {
    613                 var href, img, setResize, prep = publicMethod.prep;
     646                var href, setResize, prep = publicMethod.prep;
    614647               
    615648                active = true;
     649               
     650                photo = false;
     651               
    616652                element = $related[index];
    617653               
    618654                if (!launched) {
    619                         settings = process($.extend({}, $.data(element, colorbox)));
     655                        process($.extend(settings, $.data(element, colorbox)));
    620656                }
    621657               
     
    661697                        // IFrame element won't be added to the DOM until it is ready to be displayed,
    662698                        // to avoid problems with DOM-ready JS that might be trying to run in that iframe.
    663                         $box.one(event_loaded, function () {
    664                                 var $iframe = $("<iframe name='" + new Date().getTime() + "' frameborder=0" + (settings.scrolling ? "" : " scrolling='no'") + (isIE ? " allowtransparency='true'" : '') + " style='width:100%; height:100%; border:0; display:block;'/>");
    665                                 $iframe[0].src = settings.href;
    666                                 $iframe.appendTo($loaded).one(event_purge, function () {
    667                                         $iframe[0].src = '//about:blank';
    668                                 });
    669                         });
    670                        
    671699                        prep(" ");
    672700                } else if (settings.html) {
    673701                        prep(settings.html);
    674702                } else if (isImage(href)) {
    675                         img = new Image();
    676                         img.onload = function () {
     703                        $(photo = new Image())
     704                        .addClass(prefix + 'Photo')
     705                        .error(function () {
     706                                settings.title = false;
     707                                prep($div('Error').text('This image could not be loaded'));
     708                        })
     709                        .load(function () {
    677710                                var percent;
    678                                 img.onload = null;
    679                                 img.id = prefix + 'Photo';
    680                                 $(img).css({border: 'none', display: 'block', cssFloat: 'left'});
     711                                photo.onload = null; //stops animated gifs from firing the onload repeatedly.
     712                               
    681713                                if (settings.scalePhotos) {
    682714                                        setResize = function () {
    683                                                 img.height -= img.height * percent;
    684                                                 img.width -= img.width * percent;       
     715                                                photo.height -= photo.height * percent;
     716                                                photo.width -= photo.width * percent;   
    685717                                        };
    686                                         if (settings.mw && img.width > settings.mw) {
    687                                                 percent = (img.width - settings.mw) / img.width;
     718                                        if (settings.mw && photo.width > settings.mw) {
     719                                                percent = (photo.width - settings.mw) / photo.width;
    688720                                                setResize();
    689721                                        }
    690                                         if (settings.mh && img.height > settings.mh) {
    691                                                 percent = (img.height - settings.mh) / img.height;
     722                                        if (settings.mh && photo.height > settings.mh) {
     723                                                percent = (photo.height - settings.mh) / photo.height;
    692724                                                setResize();
    693725                                        }
     
    695727                               
    696728                                if (settings.h) {
    697                                         img.style.marginTop = Math.max(settings.h - img.height, 0) / 2 + 'px';
     729                                        photo.style.marginTop = Math.max(settings.h - photo.height, 0) / 2 + 'px';
    698730                                }
    699731                               
    700732                                if ($related[1] && (index < $related.length - 1 || settings.loop)) {
    701                                         $(img).css({cursor: 'pointer'}).click(publicMethod.next);
     733                                        photo.style.cursor = 'pointer';
     734                                        photo.onclick = function () {
     735                                                publicMethod.next();
     736                                        };
    702737                                }
    703738                               
    704739                                if (isIE) {
    705                                         img.style.msInterpolationMode = 'bicubic';
    706                                 }
    707                                
    708                                 setTimeout(function () { // Chrome will sometimes report a 0 by 0 size if there isn't pause in execution
    709                                         prep(img);
     740                                        photo.style.msInterpolationMode = 'bicubic';
     741                                }
     742                               
     743                                setTimeout(function () { // A pause because Chrome will sometimes report a 0 by 0 size otherwise.
     744                                        prep(photo);
    710745                                }, 1);
    711                         };
    712                        
    713                         setTimeout(function () { // Opera 10.6+ will sometimes load the src before the onload function is set
    714                                 img.src = href;
    715                         }, 1); 
     746                        });
     747                       
     748                        setTimeout(function () { // A pause because Opera 10.6+ will sometimes not run the onload function otherwise.
     749                                photo.src = href;
     750                        }, 1);
    716751                } else if (href) {
    717752                        $loadingBay.load(href, function (data, status, xhr) {
    718                                 prep(status === 'error' ? 'Request unsuccessful: ' + xhr.statusText : $(this).children());
     753                                prep(status === 'error' ? $div('Error').text('Request unsuccessful: ' + xhr.statusText) : $(this).contents());
    719754                        });
    720755                }
    721756        };
    722 
     757       
    723758        // Navigates to the next page/image in a set.
    724759        publicMethod.next = function () {
    725                 if (!active) {
     760                if (!active && $related[1] && (index < $related.length - 1 || settings.loop)) {
    726761                        index = index < $related.length - 1 ? index + 1 : 0;
    727762                        publicMethod.load();
     
    730765       
    731766        publicMethod.prev = function () {
    732                 if (!active) {
     767                if (!active && $related[1] && (index || settings.loop)) {
    733768                        index = index ? index - 1 : $related.length - 1;
    734769                        publicMethod.load();
     
    739774        publicMethod.close = function () {
    740775                if (open && !closing) {
     776                       
    741777                        closing = true;
    742778                       
     
    747783                        $window.unbind('.' + prefix + ' .' + event_ie6);
    748784                       
    749                         $overlay.fadeTo('fast', 0);
    750                        
    751                         $box.stop().fadeTo('fast', 0, function () {
     785                        $overlay.fadeTo(200, 0);
     786                       
     787                        $box.stop().fadeTo(300, 0, function () {
     788                               
     789                                $box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide();
    752790                               
    753791                                trigger(event_purge);
    754792                               
    755793                                $loaded.remove();
    756                                
    757                                 $box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide();
    758794                               
    759795                                setTimeout(function () {
     
    776812        $(publicMethod.init);
    777813
    778 }(jQuery, this));
     814}(jQuery, document, this));
Note: See TracChangeset for help on using the changeset viewer.