Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function(a) {
- function j(e, m) {
- e = e.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
- var n = RegExp("[\\?&]" + e + "=([^&#]*)").exec(m);
- return n == null ? "" : n[1]
- }
- a.prettyPhoto = {
- version : "3.0"
- };
- a.fn.prettyPhoto = function(e) {
- function m(b) {
- $pp_pic_holder.find("#pp_full_res object,#pp_full_res embed").css("visibility", "hidden");
- $pp_pic_holder.find(".pp_fade").fadeOut(settings.animation_speed, function() {
- a(".pp_loaderIcon").show();
- b()
- })
- }
- function n(b) {
- if(set_position == b - 1) {
- $pp_pic_holder.find("a.pp_next").css("visibility", "hidden");
- $pp_pic_holder.find("a.pp_next").addClass("disabled").unbind("click")
- } else {
- $pp_pic_holder.find("a.pp_next").css("visibility", "visible");
- $pp_pic_holder.find("a.pp_next.disabled").removeClass("disabled").bind("click", function() {
- a.prettyPhoto.changePage("next");
- return false
- })
- }set_position == 0 ? $pp_pic_holder.find("a.pp_previous").css("visibility", "hidden").addClass("disabled").unbind("click") : $pp_pic_holder.find("a.pp_previous.disabled").css("visibility", "visible").removeClass("disabled").bind("click", function() {
- a.prettyPhoto.changePage("previous");
- return false
- });
- b > 1 ? a(".pp_nav").show() : a(".pp_nav").hide()
- }
- function f(b, d) {
- resized = false;
- u(b, d);
- imageWidth = b;
- imageHeight = d;
- if((k > g || l > h) && doresize && settings.allow_resize && !p) {
- resized = true;
- for( fitting = false; !fitting; ) {
- if(k > g) {
- imageWidth = g - 200;
- imageHeight = d / b * imageWidth
- } else if(l > h) {
- imageHeight = h - 200;
- imageWidth = b / d * imageHeight
- } else
- fitting = true;
- l = imageHeight;
- k = imageWidth
- }
- u(imageWidth, imageHeight)
- }
- return {
- width : Math.floor(imageWidth),
- height : Math.floor(imageHeight),
- containerHeight : Math.floor(l),
- containerWidth : Math.floor(k) + 40,
- contentHeight : Math.floor(q),
- contentWidth : Math.floor(v),
- resized : resized
- }
- }
- function u(b, d) {
- b = parseFloat(b);
- d = parseFloat(d);
- $pp_details = $pp_pic_holder.find(".pp_details");
- $pp_details.width(b);
- detailsHeight = parseFloat($pp_details.css("marginTop")) + parseFloat($pp_details.css("marginBottom"));
- $pp_details = $pp_details.clone().appendTo(a("body")).css({
- position : "absolute",
- top : -1E4
- });
- detailsHeight += $pp_details.height();
- detailsHeight = detailsHeight <= 34 ? 36 : detailsHeight;
- if(a.browser.msie && a.browser.version == 7)
- detailsHeight += 8;
- $pp_details.remove();
- q = d + detailsHeight;
- v = b;
- l = q + $ppt.height() + $pp_pic_holder.find(".pp_top").height() + $pp_pic_holder.find(".pp_bottom").height();
- k = b
- }
- function r(b) {
- return b.match(/youtube\.com\/watch/i) ? "youtube" : b.match(/vimeo\.com/i) ? "vimeo" : b.indexOf(".mov") != -1 ? "quicktime" : b.indexOf(".swf") != -1 ? "flash" : b.indexOf("iframe") != -1 ? "iframe" : b.indexOf("custom") != -1 ? "custom" : b.substr(0, 1) == "#" ? "inline" : "image"
- }
- function o() {
- if(doresize && typeof $pp_pic_holder != "undefined") {
- scroll_pos = w();
- titleHeight = $ppt.height();
- contentHeight = $pp_pic_holder.height();
- contentwidth = $pp_pic_holder.width();
- projectedTop = h / 2 + scroll_pos.scrollTop - contentHeight / 2;
- $pp_pic_holder.css({
- top : projectedTop,
- left : g / 2 + scroll_pos.scrollLeft - contentwidth / 2
- })
- }
- }
- function w() {
- if(self.pageYOffset)
- return {
- scrollTop : self.pageYOffset,
- scrollLeft : self.pageXOffset
- };
- else if(document.documentElement && document.documentElement.scrollTop)
- return {
- scrollTop : document.documentElement.scrollTop,
- scrollLeft : document.documentElement.scrollLeft
- };
- else if(document.body)
- return {
- scrollTop : document.body.scrollTop,
- scrollLeft : document.body.scrollLeft
- }
- }
- function x(b) {
- theRel = a(b).attr("rel");
- galleryRegExp = /\[(?:.*)\]/;
- pp_images = ( isSet = galleryRegExp.exec(theRel) ? true : false) ? jQuery.map(s, function(d) {
- if(a(d).attr("rel").indexOf(theRel) != -1)
- return a(d).attr("href")
- }) : a.makeArray(a(b).attr("href"));
- pp_titles = isSet ? jQuery.map(s, function(d) {
- if(a(d).attr("rel").indexOf(theRel) != -1)
- return a(d).find("img").attr("alt") ? a(d).find("img").attr("alt") : ""
- }) : a.makeArray(a(b).find("img").attr("alt"));
- pp_descriptions = isSet ? jQuery.map(s, function(d) {
- if(a(d).attr("rel").indexOf(theRel) != -1)
- return a(d).attr("title") ? a(d).attr("title") : ""
- }) : a.makeArray(a(b).attr("title"));
- a("body").append(settings.markup);
- $pp_pic_holder = a(".pp_pic_holder");
- $ppt = a(".ppt");
- $pp_overlay = a("div.pp_overlay");
- if(isSet && settings.overlay_gallery) {
- currentGalleryPage = 0;
- toInject = "";
- for( b = 0; b < pp_images.length; b++) {
- classname = /(.*?).(jpg|jpeg|png|gif)$/.exec(pp_images[b]) ? "" : "default";
- toInject += "<li class='" + classname + "'><a href='#'><img src='" + pp_images[b] + "' width='50' alt='' /></a></li>"
- }
- toInject = settings.gallery_markup.replace(/{gallery}/g, toInject);
- $pp_pic_holder.find("#pp_full_res").after(toInject);
- $pp_pic_holder.find(".pp_gallery .pp_arrow_next").click(function() {
- a.prettyPhoto.changeGalleryPage("next");
- a.prettyPhoto.stopSlideshow();
- return false
- });
- $pp_pic_holder.find(".pp_gallery .pp_arrow_previous").click(function() {
- a.prettyPhoto.changeGalleryPage("previous");
- a.prettyPhoto.stopSlideshow();
- return false
- });
- $pp_pic_holder.find(".pp_content").hover(function() {
- $pp_pic_holder.find(".pp_gallery:not(.disabled)").fadeIn()
- }, function() {
- $pp_pic_holder.find(".pp_gallery:not(.disabled)").fadeOut()
- });
- itemWidth = 57;
- $pp_pic_holder.find(".pp_gallery ul li").each(function(d) {
- a(this).css({
- position : "absolute",
- left : d * itemWidth
- });
- a(this).find("a").unbind("click").click(function() {
- a.prettyPhoto.changePage(d);
- a.prettyPhoto.stopSlideshow();
- return false
- })
- })
- }
- if(settings.slideshow) {
- $pp_pic_holder.find(".pp_nav").prepend('<a href="#" class="pp_play">Play</a>');
- $pp_pic_holder.find(".pp_nav .pp_play").click(function() {
- a.prettyPhoto.startSlideshow();
- return false
- })
- }
- $pp_pic_holder.attr("class", "pp_pic_holder " + settings.theme);
- $pp_overlay.css({
- opacity : 0,
- height : a(document).height(),
- width : a(document).width()
- }).bind("click", function() {
- settings.modal || a.prettyPhoto.close()
- });
- a("a.pp_close").bind("click", function() {
- a.prettyPhoto.close();
- return false
- });
- a("a.pp_expand").bind("click", function() {
- if(a(this).hasClass("pp_expand")) {
- a(this).removeClass("pp_expand").addClass("pp_contract");
- doresize = false
- } else {
- a(this).removeClass("pp_contract").addClass("pp_expand");
- doresize = true
- }
- m(function() {
- a.prettyPhoto.open()
- });
- return false
- });
- $pp_pic_holder.find(".pp_previous, .pp_nav .pp_arrow_previous").bind("click", function() {
- a.prettyPhoto.changePage("previous");
- a.prettyPhoto.stopSlideshow();
- return false
- });
- $pp_pic_holder.find(".pp_next, .pp_nav .pp_arrow_next").bind("click", function() {
- a.prettyPhoto.changePage("next");
- a.prettyPhoto.stopSlideshow();
- return false
- });
- o()
- }
- e = jQuery.extend({
- animation_speed : "fast",
- slideshow : false,
- autoplay_slideshow : false,
- opacity : 0.8,
- show_title : true,
- allow_resize : true,
- default_width : 500,
- default_height : 344,
- counter_separator_label : "/",
- theme : "facebook",
- hideflash : false,
- wmode : "opaque",
- autoplay : true,
- modal : false,
- overlay_gallery : true,
- keyboard_shortcuts : false,
- changepicturecallback : function() {
- },
- callback : function() {
- },
- markup : '<div class="pp_pic_holder"> <div class="ppt"> </div> <div class="pp_top"> <div class="pp_left"></div> <div class="pp_middle"></div> <div class="pp_right"></div> </div> <div class="pp_content_container"> <div class="pp_left"> <div class="pp_right"> <div class="pp_content"> <div class="pp_loaderIcon"></div> <div class="pp_fade"> <a href="#" class="pp_expand" title="Expand the image">Expand</a> <div class="pp_hoverContainer"> <a class="pp_next" href="#">next</a> <a class="pp_previous" href="#">previous</a> </div> <div id="pp_full_res"></div> <div class="pp_details clearfix"> <p class="pp_description"></p> <a class="pp_close" href="#">Close</a> <div class="pp_nav"> <a href="#" class="pp_arrow_previous">Previous</a> <p class="currentTextHolder">0/0</p> <a href="#" class="pp_arrow_next">Next</a> </div> </div> </div> </div> </div> </div> </div> <div class="pp_bottom"> <div class="pp_left"></div> <div class="pp_middle"></div> <div class="pp_right"></div> </div> </div> <div class="pp_overlay"></div>',
- gallery_markup : '<div class="pp_gallery"> <a href="#" class="pp_arrow_previous">Previous</a> <ul> {gallery} </ul> <a href="#" class="pp_arrow_next">Next</a> </div>',
- image_markup : '<img id="fullResImage" src="" />',
- flash_markup : '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="{width}" height="{height}"><param name="wmode" value="{wmode}" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="{path}" /><embed src="{path}" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="{width}" height="{height}" wmode="{wmode}"></embed></object>',
- quicktime_markup : '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="{height}" width="{width}"><param name="src" value="{path}"><param name="autoplay" value="{autoplay}"><param name="type" value="video/quicktime"><embed src="{path}" height="{height}" width="{width}" autoplay="{autoplay}" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>',
- iframe_markup : '<iframe src ="{path}" width="{width}" height="{height}" frameborder="no"></iframe>',
- inline_markup : '<div class="pp_inline clearfix">{content}</div>',
- custom_markup : ""
- }, e);
- var s = this, p = false, c, t, q, v, l, k, h = a(window).height(), g = a(window).width(), i;
- doresize = true;
- scroll_pos = w();
- a(window).unbind("resize").resize(function() {
- o();
- h = a(window).height();
- g = a(window).width();
- typeof $pp_overlay != "undefined" && $pp_overlay.height(a(document).height())
- });
- e.keyboard_shortcuts && a(document).unbind("keydown").keydown(function(b) {
- if( typeof $pp_pic_holder != "undefined")
- if($pp_pic_holder.is(":visible")) {
- switch(b.keyCode) {
- case 37:
- a.prettyPhoto.changePage("previous");
- break;
- case 39:
- a.prettyPhoto.changePage("next");
- break;
- case 27:
- settings.modal || a.prettyPhoto.close()
- }
- return false
- }
- });
- a.prettyPhoto.initialize = function() {
- settings = e;
- if(a.browser.msie && parseInt(a.browser.version) == 6)
- settings.theme = "light_square";
- x(this);
- settings.allow_resize && a(window).scroll(function() {
- o()
- });
- o();
- set_position = jQuery.inArray(a(this).attr("href"), pp_images);
- a.prettyPhoto.open();
- return false
- };
- a.prettyPhoto.open = function(b, d, y) {
- if( typeof settings == "undefined") {
- settings = e;
- if(a.browser.msie && a.browser.version == 6)
- settings.theme = "light_square";
- x(this);
- pp_images = a.makeArray(b);
- pp_titles = d ? a.makeArray(d) : a.makeArray("");
- pp_descriptions = y ? a.makeArray(y) : a.makeArray("");
- isSet = pp_images.length > 1 ? true : false;
- set_position = 0
- }a.browser.msie && a.browser.version == 6 && a("select").css("visibility", "hidden");
- settings.hideflash && a("object,embed").css("visibility", "hidden");
- n(a(pp_images).size());
- a(".pp_loaderIcon").show();
- $ppt.is(":hidden") && $ppt.css("opacity", 0).show();
- $pp_overlay.show().fadeTo(settings.animation_speed, settings.opacity);
- $pp_pic_holder.find(".currentTextHolder").text(set_position + 1 + settings.counter_separator_label + a(pp_images).size());
- $pp_pic_holder.find(".pp_description").show().html(unescape(pp_descriptions[set_position]));
- settings.show_title && pp_titles[set_position] != "" ? $ppt.html(unescape(pp_titles[set_position])) : $ppt.html(" ");
- movie_width = parseFloat(j("width", pp_images[set_position])) ? j("width", pp_images[set_position]) : settings.default_width.toString();
- movie_height = parseFloat(j("height", pp_images[set_position])) ? j("height", pp_images[set_position]) : settings.default_height.toString();
- if(movie_width.indexOf("%") != -1 || movie_height.indexOf("%") != -1) {
- movie_height = parseFloat(a(window).height() * parseFloat(movie_height) / 100 - 150);
- movie_width = parseFloat(a(window).width() * parseFloat(movie_width) / 100 - 150);
- p = true
- } else
- p = false;
- $pp_pic_holder.fadeIn(function() {
- imgPreloader = "";
- switch(r(pp_images[set_position])) {
- case "image":
- imgPreloader = new Image;
- nextImage = new Image;
- if(isSet && set_position > a(pp_images).size())
- nextImage.src = pp_images[set_position + 1];
- prevImage = new Image;
- if(isSet && pp_images[set_position - 1])
- prevImage.src = pp_images[set_position - 1];
- $pp_pic_holder.find("#pp_full_res")[0].innerHTML = settings.image_markup;
- $pp_pic_holder.find("#fullResImage").attr("src", pp_images[set_position]);
- imgPreloader.onload = function() {
- window.c = f(imgPreloader.width, imgPreloader.height);
- _showContent()
- };
- imgPreloader.onerror = function() {
- alert("Image cannot be loaded. Make sure the path is correct and image exist.");
- a.prettyPhoto.close()
- };
- imgPreloader.src = pp_images[set_position];
- break;
- case "youtube":
- window.c = f(movie_width, movie_height);
- movie = "http://www.youtube.com/v/" + j("v", pp_images[set_position]);
- if(settings.autoplay)
- movie += "&autoplay=1";
- toInject = settings.flash_markup.replace(/{width}/g, window.c.width).replace(/{height}/g, window.c.height).replace(/{wmode}/g, settings.wmode).replace(/{path}/g, movie);
- break;
- case "vimeo":
- window.c = f(movie_width, movie_height);
- movie_id = pp_images[set_position];
- movie = "http://player.vimeo.com/video/" + movie_id.match(/http:\/\/(www\.)?vimeo.com\/(\d+)/)[2] + "?title=0&byline=0&portrait=0";
- if(settings.autoplay)
- movie += "&autoplay=1;";
- vimeo_width = window.c.width + "/embed/?moog_width=" + window.c.width;
- toInject = settings.iframe_markup.replace(/{width}/g, vimeo_width).replace(/{height}/g, window.c.height).replace(/{path}/g, movie);
- break;
- case "quicktime":
- window.c = f(movie_width, movie_height);
- window.c.height += 15;
- window.c.contentHeight += 15;
- window.c.containerHeight += 15;
- toInject = settings.quicktime_markup.replace(/{width}/g, window.c.width).replace(/{height}/g, window.c.height).replace(/{wmode}/g, settings.wmode).replace(/{path}/g, pp_images[set_position]).replace(/{autoplay}/g, settings.autoplay);
- break;
- case "flash":
- window.c = f(movie_width, movie_height);
- flash_vars = pp_images[set_position];
- flash_vars = flash_vars.substring(pp_images[set_position].indexOf("flashvars") + 10, pp_images[set_position].length);
- filename = pp_images[set_position];
- filename = filename.substring(0, filename.indexOf("?"));
- toInject = settings.flash_markup.replace(/{width}/g, window.c.width).replace(/{height}/g, window.c.height).replace(/{wmode}/g, settings.wmode).replace(/{path}/g, filename + "?" + flash_vars);
- break;
- case "iframe":
- window.c = f(movie_width, movie_height);
- frame_url = pp_images[set_position];
- frame_url = frame_url.substr(0, frame_url.indexOf("iframe") - 1);
- toInject = settings.iframe_markup.replace(/{width}/g, window.c.width).replace(/{height}/g, window.c.height).replace(/{path}/g, frame_url);
- break;
- case "custom":
- window.c = f(movie_width, movie_height);
- toInject = settings.custom_markup;
- break;
- case "inline":
- myClone = a(pp_images[set_position]).clone().css({
- width : settings.default_width
- }).wrapInner('<div id="pp_full_res"><div class="pp_inline clearfix"></div></div>').appendTo(a("body"));
- window.c = f(a(myClone).width(), a(myClone).height());
- a(myClone).remove();
- toInject = settings.inline_markup.replace(/{content}/g, a(pp_images[set_position]).html())
- }
- if(!imgPreloader) {
- $pp_pic_holder.find("#pp_full_res")[0].innerHTML = toInject;
- _showContent()
- }
- });
- return false
- };
- a.prettyPhoto.changePage = function(b) {
- currentGalleryPage = 0;
- if(b == "previous") {
- set_position--;
- if(set_position < 0) {
- set_position = 0;
- return
- }
- } else if(b == "next") {
- set_position++;
- if(set_position > a(pp_images).size() - 1)
- set_position = 0
- } else
- set_position = b;
- doresize || ( doresize = true);
- a(".pp_contract").removeClass("pp_contract").addClass("pp_expand");
- m(function() {
- a.prettyPhoto.open()
- })
- };
- a.prettyPhoto.changeGalleryPage = function(b) {
- if(b == "next") {
- currentGalleryPage++;
- if(currentGalleryPage > totalPage)
- currentGalleryPage = 0
- } else if(b == "previous") {
- currentGalleryPage--;
- if(currentGalleryPage < 0)
- currentGalleryPage = totalPage
- } else
- currentGalleryPage = b;
- itemsToSlide = currentGalleryPage == totalPage ? pp_images.length - totalPage * itemsPerPage : itemsPerPage;
- $pp_pic_holder.find(".pp_gallery li").each(function(d) {
- a(this).animate({
- left : d * itemWidth - itemsToSlide * itemWidth * currentGalleryPage
- })
- })
- };
- a.prettyPhoto.startSlideshow = function() {
- if( typeof i == "undefined") {
- $pp_pic_holder.find(".pp_play").unbind("click").removeClass("pp_play").addClass("pp_pause").click(function() {
- a.prettyPhoto.stopSlideshow();
- return false
- });
- i = setInterval(a.prettyPhoto.startSlideshow, settings.slideshow)
- } else
- a.prettyPhoto.changePage("next")
- };
- a.prettyPhoto.stopSlideshow = function() {
- $pp_pic_holder.find(".pp_pause").unbind("click").removeClass("pp_pause").addClass("pp_play").click(function() {
- a.prettyPhoto.startSlideshow();
- return false
- });
- clearInterval(i);
- i = undefined
- };
- a.prettyPhoto.close = function() {
- clearInterval(i);
- $pp_pic_holder.stop().find("object,embed").css("visibility", "hidden");
- a("div.pp_pic_holder,div.ppt,.pp_fade").fadeOut(settings.animation_speed, function() {
- a(this).remove()
- });
- $pp_overlay.fadeOut(settings.animation_speed, function() {a.browser.msie && a.browser.version == 6 && a("select").css("visibility", "visible");
- settings.hideflash && a("object,embed").css("visibility", "visible");
- a(this).remove();
- a(window).unbind("scroll");
- settings.callback();
- doresize = true;
- t = false;
- delete settings
- })
- };
- _showContent = function() {
- a(".pp_loaderIcon").hide();
- $ppt.fadeTo(settings.animation_speed, 1);
- projectedTop = scroll_pos.scrollTop + (h / 2 - window.c.containerHeight / 2);
- if(projectedTop < 0)
- projectedTop = 0;
- $pp_pic_holder.find(".pp_content").animate({
- height : window.c.contentHeight
- }, settings.animation_speed);
- $pp_pic_holder.animate({
- top : projectedTop,
- left : g / 2 - window.c.containerWidth / 2,
- width : window.c.containerWidth
- }, settings.animation_speed, function() {
- $pp_pic_holder.find(".pp_hoverContainer,#fullResImage").height(window.c.height).width(window.c.width);
- $pp_pic_holder.find(".pp_fade").fadeIn(settings.animation_speed);
- isSet && r(pp_images[set_position]) == "image" ? $pp_pic_holder.find(".pp_hoverContainer").show() : $pp_pic_holder.find(".pp_hoverContainer").hide();
- window.c.resized && a("a.pp_expand,a.pp_contract").fadeIn(settings.animation_speed);
- settings.autoplay_slideshow && !i && !t && a.prettyPhoto.startSlideshow();
- settings.changepicturecallback();
- t = true
- });
- if(isSet && settings.overlay_gallery && r(pp_images[set_position]) == "image") {
- itemWidth = 57;
- navWidth = settings.theme == "facebook" ? 58 : 38;
- itemsPerPage = Math.floor((window.c.containerWidth - 100 - navWidth) / itemWidth);
- itemsPerPage = itemsPerPage < pp_images.length ? itemsPerPage : pp_images.length;
- totalPage = Math.ceil(pp_images.length / itemsPerPage) - 1;
- if(totalPage == 0) {
- navWidth = 0;
- $pp_pic_holder.find(".pp_gallery .pp_arrow_next,.pp_gallery .pp_arrow_previous").hide()
- } else
- $pp_pic_holder.find(".pp_gallery .pp_arrow_next,.pp_gallery .pp_arrow_previous").show();
- galleryWidth = itemsPerPage * itemWidth + navWidth;
- $pp_pic_holder.find(".pp_gallery").width(galleryWidth).css("margin-left", -(galleryWidth / 2));
- $pp_pic_holder.find(".pp_gallery ul").width(itemsPerPage * itemWidth).find("li.selected").removeClass("selected");
- goToPage = Math.floor(set_position / itemsPerPage) <= totalPage ? Math.floor(set_position / itemsPerPage) : totalPage;
- itemsPerPage ? $pp_pic_holder.find(".pp_gallery").hide().show().removeClass("disabled") : $pp_pic_holder.find(".pp_gallery").hide().addClass("disabled");
- a.prettyPhoto.changeGalleryPage(goToPage);
- $pp_pic_holder.find(".pp_gallery ul li:eq(" + set_position + ")").addClass("selected")
- } else {
- $pp_pic_holder.find(".pp_content").unbind("mouseenter mouseleave");
- $pp_pic_holder.find(".pp_gallery").hide()
- }
- };
- return this.unbind("click").click(a.prettyPhoto.initialize)
- }
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement