2009-12-12 17:39:18 +00:00
|
|
|
(function($) {
|
2009-12-16 19:51:45 +00:00
|
|
|
var _paths = [];
|
2009-12-12 17:39:18 +00:00
|
|
|
|
|
|
|
$.fn.gallery3_client = function() {
|
|
|
|
return this.each(function(i) {
|
|
|
|
ajaxifyLoginForm(this);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
function ajaxifyLoginForm(obj) {
|
|
|
|
var login = $(obj).find("#g-login-form form");
|
|
|
|
if (login.length > 0) {
|
|
|
|
$(login).ajaxForm({
|
|
|
|
dataType: "json",
|
|
|
|
beforeSubmit: function(formData, form, options) {
|
|
|
|
form.find(":submit")
|
|
|
|
.addClass("ui-state-disabled")
|
|
|
|
.attr("disabled", "disabled");
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
$(obj).html(data.content);
|
|
|
|
if (data.status == "ok") {
|
|
|
|
initializeDetail(obj);
|
2009-12-17 19:25:46 +00:00
|
|
|
} else {
|
2009-12-12 17:39:18 +00:00
|
|
|
ajaxifyLoginForm(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
initializeDetail(obj);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function initializeDetail(obj) {
|
|
|
|
$(".ui-icon-plus", obj).live("click", function (event) {
|
|
|
|
var siblings = $("~ ul", this);
|
|
|
|
if (siblings.length > 0) {
|
|
|
|
siblings.show();
|
|
|
|
$(this).removeClass("ui-icon-plus");
|
|
|
|
$(this).addClass("ui-icon-minus");
|
|
|
|
} else {
|
2009-12-16 19:51:45 +00:00
|
|
|
var parent = $(this).parents("li:first");
|
2009-12-12 17:39:18 +00:00
|
|
|
$.get("/g3_client/index.php/g3_client/albums",
|
|
|
|
{path: $(parent).attr("ref")},
|
|
|
|
function(data, textStatus) {
|
|
|
|
$(parent).replaceWith(data);
|
|
|
|
});
|
|
|
|
}
|
2009-12-15 20:23:32 +00:00
|
|
|
return false;
|
2009-12-12 17:39:18 +00:00
|
|
|
});
|
2009-12-15 20:23:32 +00:00
|
|
|
|
2009-12-12 17:39:18 +00:00
|
|
|
$(".ui-icon-minus", obj).live("click", function (event) {
|
|
|
|
$("~ ul", this).hide();
|
|
|
|
$(this).removeClass("ui-icon-minus");
|
|
|
|
$(this).addClass("ui-icon-plus");
|
2009-12-15 20:23:32 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
$("#center a.wc-child-link").live("dblclick", function(event) {
|
2009-12-15 20:23:32 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2009-12-16 19:51:45 +00:00
|
|
|
var path = $(this).parents("li:first").attr("ref");
|
2009-12-15 20:23:32 +00:00
|
|
|
var url = $(this).attr("href");
|
2009-12-17 19:25:46 +00:00
|
|
|
get_detail(path, _set_active_album);
|
2009-12-15 20:23:32 +00:00
|
|
|
return false;
|
2009-12-12 17:39:18 +00:00
|
|
|
});
|
2009-12-15 20:23:32 +00:00
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
$("#center a.wc-child-link").live("click", function(event) {
|
|
|
|
$(".wc-thumb-grid-cell.ui-selected").removeClass("ui-selected");
|
2009-12-16 19:51:45 +00:00
|
|
|
$(this).parents("li:first").addClass("ui-selected");
|
2009-12-17 19:25:46 +00:00
|
|
|
_set_navigation_buttons($(".wc-thumb-grid-cell.ui-selected").attr("ref"));
|
2009-12-15 20:23:32 +00:00
|
|
|
return false;
|
2009-12-12 17:39:18 +00:00
|
|
|
});
|
2009-12-16 19:51:45 +00:00
|
|
|
|
|
|
|
$(".wc-button").live("click", function() {
|
2009-12-17 19:25:46 +00:00
|
|
|
if ($(this).hasClass("ui-state-disabled")) {
|
2009-12-16 19:51:45 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-12-17 04:11:15 +00:00
|
|
|
switch ($(this).attr("ref")) {
|
|
|
|
case "parent":
|
2009-12-17 19:25:46 +00:00
|
|
|
get_detail($("span", this).attr("ref"), _set_active_album);
|
2009-12-17 04:11:15 +00:00
|
|
|
break;
|
|
|
|
case "first":
|
|
|
|
case "previous":
|
|
|
|
case "next":
|
|
|
|
case "last":
|
2009-12-17 19:25:46 +00:00
|
|
|
if (resource_type != "album") {
|
2009-12-17 04:11:15 +00:00
|
|
|
get_detail($("span", this).attr("ref"));
|
|
|
|
} else {
|
2009-12-17 19:25:46 +00:00
|
|
|
var selected = $(".wc-thumb-grid-cell.ui-selected");
|
2009-12-17 04:11:15 +00:00
|
|
|
selected.removeClass("ui-selected");
|
|
|
|
switch ($(this).attr("ref")) {
|
|
|
|
case "first":
|
2009-12-17 19:25:46 +00:00
|
|
|
$(".wc-thumb-grid-cell:first").addClass("ui-selected");
|
2009-12-17 04:11:15 +00:00
|
|
|
break;
|
|
|
|
case "previous":
|
|
|
|
selected.prev().addClass("ui-selected");
|
|
|
|
break;
|
|
|
|
case "next":
|
|
|
|
selected.next().addClass("ui-selected");
|
|
|
|
break;
|
|
|
|
case "last":
|
2009-12-17 19:25:46 +00:00
|
|
|
$(".wc-thumb-grid-cell:last").addClass("ui-selected");
|
2009-12-17 04:11:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
_set_navigation_buttons();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.group("process toolbar button click: " + $(this).attr("ref"));
|
|
|
|
console.log(($("span", this).attr("ref")));
|
|
|
|
console.groupEnd();
|
2009-12-16 19:51:45 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$(".tree-title", obj).live("click", function (event) {
|
|
|
|
get_detail($(this).parents("li:first").attr("ref"));
|
|
|
|
$(".ui-selected").removeClass("ui-selected");
|
2009-12-17 04:11:15 +00:00
|
|
|
$(this).addClass("ui-selected");
|
|
|
|
return false;
|
|
|
|
});
|
2009-12-16 19:51:45 +00:00
|
|
|
|
2009-12-12 17:39:18 +00:00
|
|
|
$("#album_tree [ref=''] .tree-title:first").addClass("ui-selected");
|
2009-12-16 19:51:45 +00:00
|
|
|
set_selected_thumb();
|
2009-12-17 19:25:46 +00:00
|
|
|
save_paths();
|
|
|
|
}
|
|
|
|
|
|
|
|
function _set_active_album(path) {
|
|
|
|
var album = $("#album_tree [ref='" + path + "']");
|
|
|
|
if (album.length > 0) {
|
|
|
|
$(".tree-title.ui-selected").removeClass("ui-selected");
|
|
|
|
$(".tree-title:first", album).addClass("ui-selected");
|
|
|
|
}
|
|
|
|
}
|
2009-12-16 19:51:45 +00:00
|
|
|
|
|
|
|
function set_selected_thumb() {
|
2009-12-17 19:25:46 +00:00
|
|
|
if ($(".wc-thumb-grid-cell.ui-selected").length == 0) {
|
|
|
|
$(".wc-thumb-grid-cell:first").addClass("ui-selected");
|
2009-12-16 19:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_detail(path, callback) {
|
|
|
|
$.get("/g3_client/index.php/g3_client/detail", {path: path}, function(data, textStatus) {
|
|
|
|
$("#wc-detail").html(data);
|
|
|
|
set_selected_thumb();
|
2009-12-17 19:25:46 +00:00
|
|
|
save_paths();
|
2009-12-17 04:11:15 +00:00
|
|
|
if (callback) {
|
2009-12-16 19:51:45 +00:00
|
|
|
callback(path);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
function save_paths() {
|
|
|
|
_paths[current_path] = [];
|
|
|
|
$(".wc-thumb-grid-cell").each(function(i) {
|
|
|
|
_paths[current_path][i] = $(this).attr("ref");
|
2009-12-16 19:51:45 +00:00
|
|
|
});
|
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
_set_navigation_buttons();
|
2009-12-16 19:51:45 +00:00
|
|
|
}
|
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
function _set_navigation_buttons() {
|
|
|
|
if (current_path != "") {
|
2009-12-16 19:51:45 +00:00
|
|
|
$(".wc-toolbar .ui-icon-eject").parent("a").removeClass("ui-state-disabled");
|
2009-12-17 04:11:15 +00:00
|
|
|
$(".wc-toolbar .ui-icon-trash").parent("a").removeClass("ui-state-disabled");
|
2009-12-16 19:51:45 +00:00
|
|
|
} else {
|
|
|
|
$(".wc-toolbar .ui-icon-eject").parent("a").addClass("ui-state-disabled");
|
2009-12-17 04:11:15 +00:00
|
|
|
$(".wc-toolbar .ui-icon-trash").parent("a").addClass("ui-state-disabled");
|
|
|
|
}
|
2009-12-17 19:25:46 +00:00
|
|
|
$(".wc-toolbar .ui-icon-eject").attr("ref", parent_path);
|
|
|
|
$(".wc-toolbar .ui-icon-pencil").attr("ref", current_path);
|
|
|
|
$(".wc-toolbar .ui-icon-trash").attr("ref", current_path);
|
|
|
|
$(".wc-toolbar #add-resource span")
|
|
|
|
.attr("ref", resource_type == "album" ? current_path : parent_path);
|
2009-12-17 04:11:15 +00:00
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
var paths = _paths[resource_type == "album" ? current_path : parent_path];
|
2009-12-17 04:11:15 +00:00
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
$(".wc-toolbar .ui-icon-pencil").attr("ref", current_path);
|
2009-12-17 04:11:15 +00:00
|
|
|
if (paths.length > 0) {
|
|
|
|
$(".wc-toolbar .ui-icon-seek-first").parent("a").removeClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-end").parent("a").removeClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-first").attr("ref", paths[0]);
|
|
|
|
$(".wc-toolbar .ui-icon-seek-end").attr("ref", paths[paths.length - 1]);
|
|
|
|
} else {
|
|
|
|
$(".wc-toolbar .ui-icon-seek-first").parent("a").addClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-end").parent("a").addClass("ui-state-disabled");
|
|
|
|
}
|
|
|
|
|
2009-12-17 19:25:46 +00:00
|
|
|
var selected_path =
|
|
|
|
resource_type == "album" ? $(".wc-thumb-grid-cell.ui-selected").attr("ref") : current_path;
|
2009-12-17 04:11:15 +00:00
|
|
|
var i = 0;
|
|
|
|
for (; i < paths.length; i++) {
|
|
|
|
if (paths[i] == selected_path) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
$(".wc-toolbar .ui-icon-seek-prev").parent("a").removeClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-prev").attr("ref", paths[i - 1]);
|
|
|
|
} else {
|
|
|
|
$(".wc-toolbar .ui-icon-seek-first").parent("a").addClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-prev").parent("a").addClass("ui-state-disabled");
|
|
|
|
}
|
|
|
|
if (i < paths.length - 1) {
|
|
|
|
$(".wc-toolbar .ui-icon-seek-next").parent("a").removeClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-next").attr("ref", paths[i + 1]);
|
|
|
|
} else {
|
|
|
|
$(".wc-toolbar .ui-icon-seek-next").parent("a").addClass("ui-state-disabled");
|
|
|
|
$(".wc-toolbar .ui-icon-seek-end").parent("a").addClass("ui-state-disabled");
|
2009-12-16 19:51:45 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-17 19:25:46 +00:00
|
|
|
})(jQuery);
|