diff --git a/plugins/shopping_cart/controllers/shopping_cart_plugin_profile_controller.rb b/plugins/shopping_cart/controllers/shopping_cart_plugin_profile_controller.rb index 7615491..56d14fb 100644 --- a/plugins/shopping_cart/controllers/shopping_cart_plugin_profile_controller.rb +++ b/plugins/shopping_cart/controllers/shopping_cart_plugin_profile_controller.rb @@ -1,6 +1,7 @@ include ActionView::Helpers::NumberHelper class ShoppingCartPluginProfileController < ProfileController + append_view_path File.join(File.dirname(__FILE__) + '/../views') def add session[:cart] = { :enterprise_id => profile.id, :items => {} } if session[:cart].nil? @@ -79,6 +80,30 @@ class ShoppingCartPluginProfileController < ProfileController }.to_json end + def buy + render :layout => false + end + + def send_request + begin + #implement send email here + render :text => { + :ok => true, + :message => _('Request sent successfully. Check your email.'), + :error => {:code => 0} + }.to_json + rescue + render :text => { + :ok => false, + :message => _('Your request failed.'), + :error => { + :code => 6, + :message => _('Send request failed.') + } + }.to_json + end + end + private def validate_same_enterprise @@ -86,9 +111,9 @@ class ShoppingCartPluginProfileController < ProfileController render :text => { :ok => false, :error => { - :code => 1, - :message => _("Can't join items from different enterprises.") - } + :code => 1, + :message => _("Can't join items from different enterprises.") + } }.to_json return false end @@ -100,9 +125,9 @@ class ShoppingCartPluginProfileController < ProfileController render :text => { :ok => false, :error => { - :code => 2, - :message => _("There is no cart.") - } + :code => 2, + :message => _("There is no cart.") + } }.to_json return false end @@ -116,9 +141,9 @@ class ShoppingCartPluginProfileController < ProfileController render :text => { :ok => false, :error => { - :code => 3, - :message => _("This enterprise doesn't have this product.") - } + :code => 3, + :message => _("This enterprise doesn't have this product.") + } }.to_json return nil end @@ -130,9 +155,9 @@ class ShoppingCartPluginProfileController < ProfileController render :text => { :ok => false, :error => { - :code => 4, - :message => _("The cart doesn't have this product.") - } + :code => 4, + :message => _("The cart doesn't have this product.") + } }.to_json return false end @@ -144,9 +169,9 @@ class ShoppingCartPluginProfileController < ProfileController render :text => { :ok => false, :error => { - :code => 5, - :message => _("Invalid quantity.") - } + :code => 5, + :message => _("Invalid quantity.") + } }.to_json return false end diff --git a/plugins/shopping_cart/lib/shopping_cart_plugin.rb b/plugins/shopping_cart/lib/shopping_cart_plugin.rb index 1636b20..279cd77 100644 --- a/plugins/shopping_cart/lib/shopping_cart_plugin.rb +++ b/plugins/shopping_cart/lib/shopping_cart_plugin.rb @@ -27,7 +27,7 @@ class ShoppingCartPlugin < Noosfero::Plugin end def js_files - ['cart.js'] + ['cart.js', 'colorbox/jquery.colorbox.js'] end def body_beginning diff --git a/plugins/shopping_cart/public/cart.js b/plugins/shopping_cart/public/cart.js index d24c79c..91828bb 100644 --- a/plugins/shopping_cart/public/cart.js +++ b/plugins/shopping_cart/public/cart.js @@ -7,12 +7,14 @@ function Cart(config) { this.itemsBox = $("#cart1 .cart-items"); this.items = {}; this.visible = false; + $(".cart-buy", this.cartElem).button({ icons: { primary: 'ui-icon-cart'} }); if (config.hasProducts) { $(this.cartElem).show(); this.enterprise = config.enterprise; + $(".cart-buy", this.cartElem).colorbox({href: '/profile/' + this.enterprise + '/plugins/shopping_cart/buy'}); this.listProducts(); } - $(".cart-buy", this.cartElem).button({ icons: { primary: 'ui-icon-cart'} }); + } (function($){ @@ -239,6 +241,43 @@ function Cart(config) { }); } + Cart.send_request = function(button) { + var params = {}; + params['name'] = $('#name', button.parentNode).val(); + params['email'] = $('#email', button.parentNode).val(); + params['contact_phone'] = $('#contact_phone', button.parentNode).val(); + params['address'] = $('#address', button.parentNode).val(); + Cart.instance.send_request(params); + } + + Cart.prototype.send_request = function(p) { + params = "?"; + for( var attribute in p ) { + var value = p[attribute]; + params += attribute+'='+value+'&'; + } + params = params.substring(0, params.length-1); + var me = this; + $.ajax({ + url: '/profile/'+ me.enterprise +'/plugins/shopping_cart/send_request'+params, + dataType: 'json', + success: function(data, status, ajax){ + if ( !data.ok ) display_notice(data.error.message); + else { + me.clean(); + display_notice(data.message); + } + }, + cache: false, + error: function(ajax, status, errorThrown) { + alert('Remove item - HTTP '+status+': '+errorThrown); + }, + complete: function() { + $.colorbox.close(); + } + }); + } + $(function(){ $('.cart-add-item').button({ icons: { primary: 'ui-icon-cart'} }) }); diff --git a/plugins/shopping_cart/public/colorbox/colorbox.css b/plugins/shopping_cart/public/colorbox/colorbox.css new file mode 100644 index 0000000..bd1ffd1 --- /dev/null +++ b/plugins/shopping_cart/public/colorbox/colorbox.css @@ -0,0 +1,82 @@ +/* + ColorBox Core Style: + The following CSS is consistent between example themes and should not be altered. +*/ +#colorbox, #cboxOverlay, #cboxWrapper{position:absolute; top:0; left:0; z-index:9999; overflow:hidden;} +#cboxOverlay{position:fixed; width:100%; height:100%;} +#cboxMiddleLeft, #cboxBottomLeft{clear:left;} +#cboxContent{position:relative;} +#cboxLoadedContent{overflow:auto;} +#cboxTitle{margin:0;} +#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%;} +#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;} +.cboxPhoto{float:left; margin:auto; border:0; display:block;} +.cboxIframe{width:100%; height:100%; display:block; border:0;} + +/* + User Style: + Change the following styles to modify the appearance of ColorBox. They are + ordered & tabbed in a way that represents the nesting of the generated HTML. +*/ +#cboxOverlay{background:url(images/overlay.png) repeat 0 0;} +#colorbox{} + #cboxTopLeft{width:21px; height:21px; background:url(images/controls.png) no-repeat -100px 0;} + #cboxTopRight{width:21px; height:21px; background:url(images/controls.png) no-repeat -129px 0;} + #cboxBottomLeft{width:21px; height:21px; background:url(images/controls.png) no-repeat -100px -29px;} + #cboxBottomRight{width:21px; height:21px; background:url(images/controls.png) no-repeat -129px -29px;} + #cboxMiddleLeft{width:21px; background:url(images/controls.png) left top repeat-y;} + #cboxMiddleRight{width:21px; background:url(images/controls.png) right top repeat-y;} + #cboxTopCenter{height:21px; background:url(images/border.png) 0 0 repeat-x;} + #cboxBottomCenter{height:21px; background:url(images/border.png) 0 -29px repeat-x;} + #cboxContent{background:#fff; overflow:hidden;} + #cboxError{padding:50px; border:1px solid #ccc;} + #cboxLoadedContent{margin-bottom:28px;} + #cboxTitle{position:absolute; bottom:4px; left:0; text-align:center; width:100%; color:#949494;} + #cboxCurrent{position:absolute; bottom:4px; left:58px; color:#949494;} + #cboxSlideshow{position:absolute; bottom:4px; right:30px; color:#0092ef;} + #cboxPrevious{position:absolute; bottom:0; left:0; background:url(images/controls.png) no-repeat -75px 0; width:25px; height:25px; text-indent:-9999px;} + #cboxPrevious.hover{background-position:-75px -25px;} + #cboxNext{position:absolute; bottom:0; left:27px; background:url(images/controls.png) no-repeat -50px 0; width:25px; height:25px; text-indent:-9999px;} + #cboxNext.hover{background-position:-50px -25px;} + #cboxLoadingOverlay{background:url(images/loading_background.png) no-repeat center center;} + #cboxLoadingGraphic{background:url(images/loading.gif) no-repeat center center;} + #cboxClose{position:absolute; bottom:0; right:0; background:url(images/controls.png) no-repeat -25px 0; width:25px; height:25px; text-indent:-9999px;} + #cboxClose.hover{background-position:-25px -25px;} + +/* + The following fixes a problem where IE7+ replaces a PNG's alpha transparency with a black fill + when an alpha filter (opacity change) is set on the element or ancestor element. +*/ +.cboxIE #cboxTopLeft, +.cboxIE #cboxTopCenter, +.cboxIE #cboxTopRight, +.cboxIE #cboxBottomLeft, +.cboxIE #cboxBottomCenter, +.cboxIE #cboxBottomRight, +.cboxIE #cboxMiddleLeft, +.cboxIE #cboxMiddleRight { + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF); +} + +/* + The following provides PNG transparency support for IE6 +*/ +.cboxIE6 #cboxTopLeft{background:url(images/ie6/borderTopLeft.png);} +.cboxIE6 #cboxTopCenter{background:url(images/ie6/borderTopCenter.png);} +.cboxIE6 #cboxTopRight{background:url(images/ie6/borderTopRight.png);} +.cboxIE6 #cboxBottomLeft{background:url(images/ie6/borderBottomLeft.png);} +.cboxIE6 #cboxBottomCenter{background:url(images/ie6/borderBottomCenter.png);} +.cboxIE6 #cboxBottomRight{background:url(images/ie6/borderBottomRight.png);} +.cboxIE6 #cboxMiddleLeft{background:url(images/ie6/borderMiddleLeft.png);} +.cboxIE6 #cboxMiddleRight{background:url(images/ie6/borderMiddleRight.png);} + +.cboxIE6 #cboxTopLeft, +.cboxIE6 #cboxTopCenter, +.cboxIE6 #cboxTopRight, +.cboxIE6 #cboxBottomLeft, +.cboxIE6 #cboxBottomCenter, +.cboxIE6 #cboxBottomRight, +.cboxIE6 #cboxMiddleLeft, +.cboxIE6 #cboxMiddleRight { + _behavior: expression(this.src = this.src ? this.src : this.currentStyle.backgroundImage.split('"')[1], this.style.background = "none", this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + this.src + ", sizingMethod='scale')"); +} diff --git a/plugins/shopping_cart/public/colorbox/images/border.png b/plugins/shopping_cart/public/colorbox/images/border.png new file mode 100644 index 0000000..f463a10 Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/border.png differ diff --git a/plugins/shopping_cart/public/colorbox/images/controls.png b/plugins/shopping_cart/public/colorbox/images/controls.png new file mode 100644 index 0000000..9257176 Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/controls.png differ diff --git a/plugins/shopping_cart/public/colorbox/images/ie6/borderBottomCenter.png b/plugins/shopping_cart/public/colorbox/images/ie6/borderBottomCenter.png new file mode 100644 index 0000000..0d4475e Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/ie6/borderBottomCenter.png differ diff --git a/plugins/shopping_cart/public/colorbox/images/ie6/borderBottomLeft.png b/plugins/shopping_cart/public/colorbox/images/ie6/borderBottomLeft.png new file mode 100644 index 0000000..2775eba Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/ie6/borderBottomLeft.png differ diff --git a/plugins/shopping_cart/public/colorbox/images/ie6/borderBottomRight.png b/plugins/shopping_cart/public/colorbox/images/ie6/borderBottomRight.png new file mode 100644 index 0000000..f7f5137 Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/ie6/borderBottomRight.png differ diff --git a/plugins/shopping_cart/public/colorbox/images/ie6/borderMiddleLeft.png b/plugins/shopping_cart/public/colorbox/images/ie6/borderMiddleLeft.png new file mode 100644 index 0000000..a2d63d1 Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/ie6/borderMiddleLeft.png differ diff --git a/plugins/shopping_cart/public/colorbox/images/ie6/borderMiddleRight.png b/plugins/shopping_cart/public/colorbox/images/ie6/borderMiddleRight.png new file mode 100644 index 0000000..fd7c3e8 Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/ie6/borderMiddleRight.png differ diff --git a/plugins/shopping_cart/public/colorbox/images/ie6/borderTopCenter.png b/plugins/shopping_cart/public/colorbox/images/ie6/borderTopCenter.png new file mode 100644 index 0000000..2937a9c Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/ie6/borderTopCenter.png differ diff --git a/plugins/shopping_cart/public/colorbox/images/ie6/borderTopLeft.png b/plugins/shopping_cart/public/colorbox/images/ie6/borderTopLeft.png new file mode 100644 index 0000000..f9d458b Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/ie6/borderTopLeft.png differ diff --git a/plugins/shopping_cart/public/colorbox/images/ie6/borderTopRight.png b/plugins/shopping_cart/public/colorbox/images/ie6/borderTopRight.png new file mode 100644 index 0000000..74b8583 Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/ie6/borderTopRight.png differ diff --git a/plugins/shopping_cart/public/colorbox/images/loading.gif b/plugins/shopping_cart/public/colorbox/images/loading.gif new file mode 100644 index 0000000..b4695d8 Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/loading.gif differ diff --git a/plugins/shopping_cart/public/colorbox/images/loading_background.png b/plugins/shopping_cart/public/colorbox/images/loading_background.png new file mode 100644 index 0000000..6ae83e6 Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/loading_background.png differ diff --git a/plugins/shopping_cart/public/colorbox/images/overlay.png b/plugins/shopping_cart/public/colorbox/images/overlay.png new file mode 100644 index 0000000..53ea98f Binary files /dev/null and b/plugins/shopping_cart/public/colorbox/images/overlay.png differ diff --git a/plugins/shopping_cart/public/colorbox/jquery.colorbox.js b/plugins/shopping_cart/public/colorbox/jquery.colorbox.js new file mode 100644 index 0000000..51ad367 --- /dev/null +++ b/plugins/shopping_cart/public/colorbox/jquery.colorbox.js @@ -0,0 +1,814 @@ +// ColorBox v1.3.16 - a full featured, light-weight, customizable lightbox based on jQuery 1.3+ +// Copyright (c) 2011 Jack Moore - jack@colorpowered.com +// Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php +(function ($, document, window) { + var + // ColorBox Default Settings. + // See http://colorpowered.com/colorbox for details. + defaults = { + transition: "elastic", + speed: 300, + width: false, + initialWidth: "600", + innerWidth: false, + maxWidth: false, + height: false, + initialHeight: "450", + innerHeight: false, + maxHeight: false, + scalePhotos: true, + scrolling: true, + inline: false, + html: false, + iframe: false, + fastIframe: true, + photo: false, + href: false, + title: false, + rel: false, + opacity: 0.9, + preloading: true, + current: "image {current} of {total}", + previous: "previous", + next: "next", + close: "close", + open: false, + returnFocus: true, + loop: true, + slideshow: false, + slideshowAuto: true, + slideshowSpeed: 2500, + slideshowStart: "start slideshow", + slideshowStop: "stop slideshow", + onOpen: false, + onLoad: false, + onComplete: false, + onCleanup: false, + onClosed: false, + overlayClose: true, + escKey: true, + arrowKey: true + }, + + // Abstracting the HTML and event identifiers for easy rebranding + colorbox = 'colorbox', + prefix = 'cbox', + + // Events + event_open = prefix + '_open', + event_load = prefix + '_load', + event_complete = prefix + '_complete', + event_cleanup = prefix + '_cleanup', + event_closed = prefix + '_closed', + event_purge = prefix + '_purge', + + // Special Handling for IE + isIE = $.browser.msie && !$.support.opacity, // feature detection alone gave a false positive on at least one phone browser and on some development versions of Chrome. + isIE6 = isIE && $.browser.version < 7, + event_ie6 = prefix + '_IE6', + + // Cached jQuery Object Variables + $overlay, + $box, + $wrap, + $content, + $topBorder, + $leftBorder, + $rightBorder, + $bottomBorder, + $related, + $window, + $loaded, + $loadingBay, + $loadingOverlay, + $title, + $current, + $slideshow, + $next, + $prev, + $close, + $groupControls, + + // Variables for cached values or use across multiple functions + settings = {}, + interfaceHeight, + interfaceWidth, + loadedHeight, + loadedWidth, + element, + index, + photo, + open, + active, + closing = false, + + publicMethod, + boxElement = prefix + 'Element'; + + // **************** + // HELPER FUNCTIONS + // **************** + + // jQuery object generator to reduce code size + function $div(id, cssText) { + var div = document.createElement('div'); + if (id) { + div.id = prefix + id; + } + div.style.cssText = cssText || false; + return $(div); + } + + // Convert % values to pixels + function setSize(size, dimension) { + dimension = dimension === 'x' ? $window.width() : $window.height(); + return (typeof size === 'string') ? Math.round((/%/.test(size) ? (dimension / 100) * parseInt(size, 10) : parseInt(size, 10))) : size; + } + + // Checks an href to see if it is a photo. + // There is a force photo option (photo: true) for hrefs that cannot be matched by this regex. + function isImage(url) { + return settings.photo || /\.(gif|png|jpg|jpeg|bmp)(?:\?([^#]*))?(?:#(\.*))?$/i.test(url); + } + + // Assigns function results to their respective settings. This allows functions to be used as values. + function process(settings) { + for (var i in settings) { + 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. + settings[i] = settings[i].call(element); + } + } + settings.rel = settings.rel || element.rel || 'nofollow'; + settings.href = $.trim(settings.href || $(element).attr('href')); + settings.title = settings.title || element.title; + } + + function trigger(event, callback) { + if (callback) { + callback.call(element); + } + $.event.trigger(event); + } + + // Slideshow functionality + function slideshow() { + var + timeOut, + className = prefix + "Slideshow_", + click = "click." + prefix, + start, + stop, + clear; + + if (settings.slideshow && $related[1]) { + start = function () { + $slideshow + .text(settings.slideshowStop) + .unbind(click) + .bind(event_complete, function () { + if (index < $related.length - 1 || settings.loop) { + timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed); + } + }) + .bind(event_load, function () { + clearTimeout(timeOut); + }) + .one(click + ' ' + event_cleanup, stop); + $box.removeClass(className + "off").addClass(className + "on"); + timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed); + }; + + stop = function () { + clearTimeout(timeOut); + $slideshow + .text(settings.slideshowStart) + .unbind([event_complete, event_load, event_cleanup, click].join(' ')) + .one(click, start); + $box.removeClass(className + "on").addClass(className + "off"); + }; + + if (settings.slideshowAuto) { + start(); + } else { + stop(); + } + } + } + + function launch(elem) { + if (!closing) { + + element = elem; + + process($.extend(settings, $.data(element, colorbox))); + + $related = $(element); + + index = 0; + + if (settings.rel !== 'nofollow') { + $related = $('.' + boxElement).filter(function () { + var relRelated = $.data(this, colorbox).rel || this.rel; + return (relRelated === settings.rel); + }); + index = $related.index(element); + + // Check direct calls to ColorBox. + if (index === -1) { + $related = $related.add(element); + index = $related.length - 1; + } + } + + if (!open) { + open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys. + + $box.show(); + + if (settings.returnFocus) { + try { + element.blur(); + $(element).one(event_closed, function () { + try { + this.focus(); + } catch (e) { + // do nothing + } + }); + } catch (e) { + // do nothing + } + } + + // +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5' + $overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show(); + + // Opens inital empty ColorBox prior to content being loaded. + settings.w = setSize(settings.initialWidth, 'x'); + settings.h = setSize(settings.initialHeight, 'y'); + publicMethod.position(0); + + if (isIE6) { + $window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () { + $overlay.css({width: $window.width(), height: $window.height(), top: $window.scrollTop(), left: $window.scrollLeft()}); + }).trigger('resize.' + event_ie6); + } + + trigger(event_open, settings.onOpen); + + $groupControls.add($title).hide(); + + $close.html(settings.close).show(); + } + + publicMethod.load(true); + } + } + + // **************** + // PUBLIC FUNCTIONS + // Usage format: $.fn.colorbox.close(); + // Usage from within an iframe: parent.$.fn.colorbox.close(); + // **************** + + publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) { + var $this = this, autoOpen; + + if (!$this[0] && $this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit. + return $this; + } + + options = options || {}; + + if (callback) { + options.onComplete = callback; + } + + if (!$this[0] || $this.selector === undefined) { // detects $.colorbox() and $.fn.colorbox() + $this = $(''); + options.open = true; // assume an immediate open + } + + $this.each(function () { + $.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options)); + $(this).addClass(boxElement); + }); + + autoOpen = options.open; + + if ($.isFunction(autoOpen)) { + autoOpen = autoOpen.call($this); + } + + if (autoOpen) { + launch($this[0]); + } + + return $this; + }; + + // Initialize ColorBox: store common calculations, preload the interface graphics, append the html. + // This preps colorbox for a speedy open when clicked, and lightens the burdon on the browser by only + // having to run once, instead of each time colorbox is opened. + publicMethod.init = function () { + // Create & Append jQuery Objects + $window = $(window); + $box = $div().attr({id: colorbox, 'class': isIE ? prefix + (isIE6 ? 'IE6' : 'IE') : ''}); + $overlay = $div("Overlay", isIE6 ? 'position:absolute' : '').hide(); + + $wrap = $div("Wrapper"); + $content = $div("Content").append( + $loaded = $div("LoadedContent", 'width:0; height:0; overflow:hidden'), + $loadingOverlay = $div("LoadingOverlay").add($div("LoadingGraphic")), + $title = $div("Title"), + $current = $div("Current"), + $next = $div("Next"), + $prev = $div("Previous"), + $slideshow = $div("Slideshow").bind(event_open, slideshow), + $close = $div("Close") + ); + $wrap.append( // The 3x3 Grid that makes up ColorBox + $div().append( + $div("TopLeft"), + $topBorder = $div("TopCenter"), + $div("TopRight") + ), + $div(false, 'clear:left').append( + $leftBorder = $div("MiddleLeft"), + $content, + $rightBorder = $div("MiddleRight") + ), + $div(false, 'clear:left').append( + $div("BottomLeft"), + $bottomBorder = $div("BottomCenter"), + $div("BottomRight") + ) + ).children().children().css({'float': 'left'}); + + $loadingBay = $div(false, 'position:absolute; width:9999px; visibility:hidden; display:none'); + + $('body').prepend($overlay, $box.append($wrap, $loadingBay)); + + $content.children() + .hover(function () { + $(this).addClass('hover'); + }, function () { + $(this).removeClass('hover'); + }).addClass('hover'); + + // Cache values needed for size calculations + interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6 + interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width(); + loadedHeight = $loaded.outerHeight(true); + loadedWidth = $loaded.outerWidth(true); + + // Setting padding to remove the need to do size conversions during the animation step. + $box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth}).hide(); + + // Setup button events. + $next.click(function () { + publicMethod.next(); + }); + $prev.click(function () { + publicMethod.prev(); + }); + $close.click(function () { + publicMethod.close(); + }); + + $groupControls = $next.add($prev).add($current).add($slideshow); + + // Adding the 'hover' class allowed the browser to load the hover-state + // background graphics. The class can now can be removed. + $content.children().removeClass('hover'); + + $('.' + boxElement).live('click', function (e) { + // checks to see if it was a non-left mouse-click and for clicks modified with ctrl, shift, or alt. + if (!((e.button !== 0 && typeof e.button !== 'undefined') || e.ctrlKey || e.shiftKey || e.altKey)) { + e.preventDefault(); + launch(this); + } + }); + + $overlay.click(function () { + if (settings.overlayClose) { + publicMethod.close(); + } + }); + + // Set Navigation Key Bindings + $(document).bind('keydown.' + prefix, function (e) { + var key = e.keyCode; + if (open && settings.escKey && key === 27) { + e.preventDefault(); + publicMethod.close(); + } + if (open && settings.arrowKey && $related[1]) { + if (key === 37) { + e.preventDefault(); + $prev.click(); + } else if (key === 39) { + e.preventDefault(); + $next.click(); + } + } + }); + }; + + publicMethod.remove = function () { + $box.add($overlay).remove(); + $('.' + boxElement).die('click').removeData(colorbox).removeClass(boxElement); + }; + + publicMethod.position = function (speed, loadedCallback) { + var + animate_speed, + // keeps the top and left positions within the browser's viewport. + posTop = Math.max(document.documentElement.clientHeight - settings.h - loadedHeight - interfaceHeight, 0) / 2 + $window.scrollTop(), + posLeft = Math.max($window.width() - settings.w - loadedWidth - interfaceWidth, 0) / 2 + $window.scrollLeft(); + + // setting the speed to 0 to reduce the delay between same-sized content. + animate_speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed; + + // this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly, + // but it has to be shrank down around the size of div#colorbox when it's done. If not, + // it can invoke an obscure IE bug when using iframes. + $wrap[0].style.width = $wrap[0].style.height = "9999px"; + + function modalDimensions(that) { + // loading overlay height has to be explicitly set for IE6. + $topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width; + $loadingOverlay[0].style.height = $loadingOverlay[1].style.height = $content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height; + } + + $box.dequeue().animate({width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: posTop, left: posLeft}, { + duration: animate_speed, + complete: function () { + modalDimensions(this); + + active = false; + + // shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation. + $wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px"; + $wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px"; + + if (loadedCallback) { + loadedCallback(); + } + }, + step: function () { + modalDimensions(this); + } + }); + }; + + publicMethod.resize = function (options) { + if (open) { + options = options || {}; + + if (options.width) { + settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth; + } + if (options.innerWidth) { + settings.w = setSize(options.innerWidth, 'x'); + } + $loaded.css({width: settings.w}); + + if (options.height) { + settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight; + } + if (options.innerHeight) { + settings.h = setSize(options.innerHeight, 'y'); + } + if (!options.innerHeight && !options.height) { + var $child = $loaded.wrapInner("
").children(); // temporary wrapper to get an accurate estimate of just how high the total content should be. + settings.h = $child.height(); + $child.replaceWith($child.children()); // ditch the temporary wrapper div used in height calculation + } + $loaded.css({height: settings.h}); + + publicMethod.position(settings.transition === "none" ? 0 : settings.speed); + } + }; + + publicMethod.prep = function (object) { + if (!open) { + return; + } + + var speed = settings.transition === "none" ? 0 : settings.speed; + + $window.unbind('resize.' + prefix); + $loaded.remove(); + $loaded = $div('LoadedContent').html(object); + + function getWidth() { + settings.w = settings.w || $loaded.width(); + settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w; + return settings.w; + } + function getHeight() { + settings.h = settings.h || $loaded.height(); + settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h; + return settings.h; + } + + $loaded.hide() + .appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations. + .css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'}) + .css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height. + .prependTo($content); + + $loadingBay.hide(); + + // 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. + //$(photo).css({'float': 'none', marginLeft: 'auto', marginRight: 'auto'}); + + $(photo).css({'float': 'none'}); + + // Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay. + if (isIE6) { + $('select').not($box.find('select')).filter(function () { + return this.style.visibility !== 'hidden'; + }).css({'visibility': 'hidden'}).one(event_cleanup, function () { + this.style.visibility = 'inherit'; + }); + } + + function setPosition(s) { + publicMethod.position(s, function () { + var prev, prevSrc, next, nextSrc, total = $related.length, iframe, complete; + + if (!open) { + return; + } + + complete = function () { + $loadingOverlay.hide(); + trigger(event_complete, settings.onComplete); + }; + + if (isIE) { + //This fadeIn helps the bicubic resampling to kick-in. + if (photo) { + $loaded.fadeIn(100); + } + } + + $title.html(settings.title).add($loaded).show(); + + if (total > 1) { // handle grouping + if (typeof settings.current === "string") { + $current.html(settings.current.replace(/\{current\}/, index + 1).replace(/\{total\}/, total)).show(); + } + + $next[(settings.loop || index < total - 1) ? "show" : "hide"]().html(settings.next); + $prev[(settings.loop || index) ? "show" : "hide"]().html(settings.previous); + + prev = index ? $related[index - 1] : $related[total - 1]; + next = index < total - 1 ? $related[index + 1] : $related[0]; + + if (settings.slideshow) { + $slideshow.show(); + } + + // Preloads images within a rel group + if (settings.preloading) { + nextSrc = $.data(next, colorbox).href || next.href; + prevSrc = $.data(prev, colorbox).href || prev.href; + + nextSrc = $.isFunction(nextSrc) ? nextSrc.call(next) : nextSrc; + prevSrc = $.isFunction(prevSrc) ? prevSrc.call(prev) : prevSrc; + + if (isImage(nextSrc)) { + $('