b2evolution PHP Cross Reference Blogging Systems

Source: /rsc/js/colorbox/jquery.colorbox.js - 926 lines - 27472 bytes - Summary - Text - Print

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

title

Description

title

Description

title

Description

title

title

Body