2009-08-07 23:58:57 +08:00
|
|
|
(function ($) {
|
2009-10-17 16:02:18 -06:00
|
|
|
|
|
|
|
|
// Fade in action status message background color
|
2009-10-22 22:01:02 -06:00
|
|
|
$.fn.gallery_show_message = function() {
|
2009-05-26 03:59:35 +00:00
|
|
|
return this.each(function(i){
|
2009-10-22 22:01:02 -06:00
|
|
|
$(this).hide().fadeIn(3000)
|
2009-05-26 03:59:35 +00:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2009-09-27 22:49:46 -06:00
|
|
|
// Make the height of all items the same as the tallest item within the set
|
|
|
|
|
$.fn.equal_heights = function() {
|
|
|
|
|
var tallest_height = 0;
|
|
|
|
|
$(this).each(function(){
|
|
|
|
|
if ($(this).height() > tallest_height) {
|
|
|
|
|
tallest_height = $(this).height();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return $(this).height(tallest_height);
|
|
|
|
|
};
|
|
|
|
|
|
2009-08-08 01:33:11 +08:00
|
|
|
// Vertically align a block element's content
|
2009-08-07 11:53:40 -07:00
|
|
|
$.fn.gallery_valign = function(container) {
|
2009-05-26 03:59:35 +00:00
|
|
|
return this.each(function(i){
|
|
|
|
|
if (container == null) {
|
|
|
|
|
container = 'div';
|
|
|
|
|
}
|
2009-10-04 00:27:22 -06:00
|
|
|
$(this).html("<" + container + " class=\"g-valign\">" + $(this).html() + "</" + container + ">");
|
|
|
|
|
var el = $(this).children(container + ".g-valign");
|
2009-05-26 03:59:35 +00:00
|
|
|
var elh = $(el).height();
|
|
|
|
|
var ph = $(this).height();
|
|
|
|
|
var nh = (ph - elh) / 2;
|
|
|
|
|
$(el).css('margin-top', nh);
|
|
|
|
|
});
|
|
|
|
|
};
|
2009-07-30 06:00:10 -07:00
|
|
|
|
2009-08-08 01:33:11 +08:00
|
|
|
// Get the viewport size
|
2009-08-07 11:53:40 -07:00
|
|
|
$.gallery_get_viewport_size = function() {
|
2009-07-30 06:00:10 -07:00
|
|
|
return {
|
|
|
|
|
width : function() {
|
2009-07-31 05:27:53 -07:00
|
|
|
return $(window).width();
|
2009-07-30 06:00:10 -07:00
|
|
|
},
|
|
|
|
|
height : function() {
|
2009-07-31 05:27:53 -07:00
|
|
|
return $(window).height();
|
2009-07-30 06:00:10 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
2009-08-07 23:58:57 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Toggle the processing indicator, both large and small
|
2009-10-04 00:27:22 -06:00
|
|
|
* @param elementID Target ID, including #, to apply .g-loading-size
|
2009-08-07 23:58:57 +08:00
|
|
|
*/
|
2009-08-07 11:53:40 -07:00
|
|
|
$.fn.gallery_show_loading = function() {
|
2009-08-07 23:58:57 +08:00
|
|
|
return this.each(function(i){
|
|
|
|
|
var size;
|
|
|
|
|
switch ($(this).attr("id")) {
|
2009-09-30 22:49:36 -06:00
|
|
|
case "#g-dialog":
|
2009-10-04 00:27:22 -06:00
|
|
|
case "#g-panel":
|
|
|
|
|
size = "large";
|
2009-08-07 23:58:57 +08:00
|
|
|
break;
|
|
|
|
|
default:
|
2009-10-04 00:27:22 -06:00
|
|
|
size = "small";
|
2009-08-07 23:58:57 +08:00
|
|
|
break;
|
|
|
|
|
}
|
2009-10-04 00:27:22 -06:00
|
|
|
$(this).toggleClass("g-loading" + size);
|
2009-08-07 23:58:57 +08:00
|
|
|
});
|
|
|
|
|
};
|
2009-08-09 11:31:31 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reduce the width of an image if it's wider than its parent container
|
2009-08-09 22:51:21 -06:00
|
|
|
* @param elementID The image container's ID
|
2009-08-09 11:31:31 -06:00
|
|
|
*/
|
2009-08-09 23:10:02 -06:00
|
|
|
$.fn.gallery_fit_photo = function() {
|
2009-08-10 23:11:31 -06:00
|
|
|
return this.each(function(i) {
|
|
|
|
|
var container_width = $(this).width();
|
|
|
|
|
var photo = $(this).gallery_get_photo();
|
|
|
|
|
var photo_width = photo.width();
|
|
|
|
|
if (container_width < photo_width) {
|
|
|
|
|
var proportion = container_width / photo_width;
|
|
|
|
|
photo.width(container_width);
|
|
|
|
|
photo.height(proportion * photo.height());
|
|
|
|
|
}
|
|
|
|
|
});
|
2009-08-09 11:31:31 -06:00
|
|
|
};
|
|
|
|
|
|
2009-08-09 22:51:21 -06:00
|
|
|
/**
|
|
|
|
|
* Get a thumbnail or resize photo within a container
|
|
|
|
|
* @param elementID The image container's ID
|
|
|
|
|
* @return object
|
|
|
|
|
*/
|
|
|
|
|
$.fn.gallery_get_photo = function() {
|
2009-12-31 18:13:25 -08:00
|
|
|
var photo = $(this).find("img,object").filter(function() {
|
|
|
|
|
return this.id.match(/g-(photo|movie)-id-\d+/);
|
2009-08-09 22:51:21 -06:00
|
|
|
});
|
|
|
|
|
return photo;
|
2009-08-10 10:49:50 -07:00
|
|
|
};
|
2009-08-09 22:51:21 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the sum of an element's height, margin-top, and margin-bottom
|
|
|
|
|
* @param elementID the element's ID
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
$.fn.gallery_height = function() {
|
|
|
|
|
var ht = $(this).height();
|
2009-08-20 07:06:36 +08:00
|
|
|
var mt = parseInt($(this).css("margin-top"));
|
|
|
|
|
var mb = parseInt($(this).css("margin-bottom"));
|
2009-08-09 22:51:21 -06:00
|
|
|
return ht + parseInt(mt) + parseInt(mb);
|
|
|
|
|
};
|
|
|
|
|
|
2009-08-09 23:08:18 -06:00
|
|
|
// Add hover state to buttons
|
|
|
|
|
$.fn.gallery_hover_init = function() {
|
|
|
|
|
$(".ui-state-default").hover(
|
|
|
|
|
function(){
|
|
|
|
|
$(this).addClass("ui-state-hover");
|
|
|
|
|
},
|
|
|
|
|
function(){
|
|
|
|
|
$(this).removeClass("ui-state-hover");
|
|
|
|
|
}
|
|
|
|
|
);
|
2009-08-10 10:49:50 -07:00
|
|
|
};
|
2009-08-09 23:08:18 -06:00
|
|
|
|
2009-08-10 23:05:05 -07:00
|
|
|
// Ajax handler for replacing an image, used in Ajax thumbnail rotation
|
|
|
|
|
$.gallery_replace_image = function(data, thumb) {
|
|
|
|
|
$(thumb).attr({src: data.src, width: data.width, height: data.height});
|
|
|
|
|
};
|
2009-08-11 00:40:14 -06:00
|
|
|
|
2009-10-17 16:02:18 -06:00
|
|
|
// Initialize context menus
|
2009-08-11 00:40:14 -06:00
|
|
|
$.fn.gallery_context_menu = function() {
|
2009-11-08 18:09:51 -07:00
|
|
|
if ($(".g-context-menu li").length) {
|
2009-10-04 00:27:22 -06:00
|
|
|
var hover_target = ".g-context-menu";
|
2009-09-21 21:56:27 -06:00
|
|
|
var in_progress = 0;
|
2009-09-26 15:44:34 -06:00
|
|
|
$(hover_target + " *").removeAttr('title');
|
|
|
|
|
$(hover_target + " ul").hide();
|
|
|
|
|
$(hover_target).hover(
|
2009-09-21 21:56:27 -06:00
|
|
|
function() {
|
|
|
|
|
if (in_progress == 0) {
|
|
|
|
|
$(this).find("ul").slideDown("fast", function() { in_progress = 1; });
|
2009-10-04 00:27:22 -06:00
|
|
|
$(this).find(".g-dialog-link").gallery_dialog();
|
|
|
|
|
$(this).find(".g-ajax-link").gallery_ajax();
|
2009-09-21 21:56:27 -06:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
function() {
|
2009-09-26 15:44:34 -06:00
|
|
|
$(this).find("ul").slideUp("slow", function() { in_progress = 0; });
|
2009-08-23 14:58:26 -06:00
|
|
|
}
|
2009-09-21 21:56:27 -06:00
|
|
|
);
|
|
|
|
|
}
|
2009-08-11 00:40:14 -06:00
|
|
|
};
|
|
|
|
|
|
2009-10-17 16:02:18 -06:00
|
|
|
// Size a container to fit within the browser window
|
2009-08-21 03:53:20 +08:00
|
|
|
$.gallery_auto_fit_window = function(imageWidth, imageHeight) {
|
|
|
|
|
var size = $.gallery_get_viewport_size();
|
|
|
|
|
var width = size.width() - 6,
|
|
|
|
|
height = size.height() - 6;
|
|
|
|
|
|
|
|
|
|
var ratio = width / imageWidth;
|
|
|
|
|
imageWidth *= ratio;
|
|
|
|
|
imageHeight *= ratio;
|
|
|
|
|
|
|
|
|
|
/* after scaling the width, check that the height fits */
|
|
|
|
|
if (imageHeight > height) {
|
2009-08-28 13:42:45 -06:00
|
|
|
ratio = height / imageHeight;
|
|
|
|
|
imageWidth *= ratio;
|
|
|
|
|
imageHeight *= ratio;
|
2009-08-21 03:53:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handle the case where the calculation is almost zero (2.14e-14)
|
|
|
|
|
return {
|
2009-08-28 13:42:45 -06:00
|
|
|
top: Number((height - imageHeight) / 2),
|
|
|
|
|
left: Number((width - imageWidth) / 2),
|
|
|
|
|
width: Number(imageWidth),
|
|
|
|
|
height: Number(imageHeight)
|
2009-08-21 03:53:20 +08:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2009-10-18 10:32:08 -06:00
|
|
|
// Initialize a short form. Short forms may contain only one text input.
|
|
|
|
|
$.fn.gallery_short_form = function() {
|
|
|
|
|
return this.each(function(i){
|
|
|
|
|
var label = $(this).find("label:first");
|
|
|
|
|
var input = $(this).find("input[type=text]:first");
|
|
|
|
|
var button = $(this).find("input[type=submit]");
|
|
|
|
|
|
|
|
|
|
$(".g-short-form").addClass("ui-helper-clearfix");
|
2009-11-17 14:07:21 -07:00
|
|
|
|
|
|
|
|
// Place button's on the left for RTL languages
|
|
|
|
|
if ($(".rtl").length) {
|
|
|
|
|
$(".g-short-form input[type=text]").addClass("ui-corner-right");
|
|
|
|
|
$(".g-short-form input[type=submit]").addClass("ui-state-default ui-corner-left");
|
|
|
|
|
} else {
|
|
|
|
|
$(".g-short-form input[type=text]").addClass("ui-corner-left");
|
|
|
|
|
$(".g-short-form input[type=submit]").addClass("ui-state-default ui-corner-right");
|
|
|
|
|
}
|
2009-10-18 10:32:08 -06:00
|
|
|
|
|
|
|
|
// Set the input value equal to label text
|
|
|
|
|
if (input.val() == "") {
|
|
|
|
|
input.val(label.html());
|
|
|
|
|
button.enable(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Attach event listeners to the input
|
|
|
|
|
input.bind("focus", function(e) {
|
|
|
|
|
// Empty input value if it equals it's label
|
|
|
|
|
if ($(this).val() == label.html()) {
|
|
|
|
|
$(this).val("");
|
|
|
|
|
}
|
|
|
|
|
button.enable(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
input.bind("blur", function(e){
|
|
|
|
|
// Reset the input value if it's empty
|
|
|
|
|
if ($(this).val() == "") {
|
|
|
|
|
$(this).val(label.html());
|
|
|
|
|
button.enable(false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2009-07-30 06:00:10 -07:00
|
|
|
})(jQuery);
|