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 04:11:15 +00:00
|
|
|
save_paths($(".tree-title.ui-selected").parents("li:first").attr("ref"));
|
2009-12-12 17:39:18 +00:00
|
|
|
} else {
|
|
|
|
ajaxifyLoginForm(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2009-12-16 19:51:45 +00:00
|
|
|
console.group("ajaxifyLoginForm");
|
2009-12-12 17:39:18 +00:00
|
|
|
initializeDetail(obj);
|
2009-12-16 19:51:45 +00:00
|
|
|
save_paths($(".tree-title.ui-selected").parents("li:first").attr("ref"));
|
|
|
|
console.groupEnd();
|
2009-12-12 17:39:18 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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-16 19:51:45 +00:00
|
|
|
$("#center a.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-16 19:51:45 +00:00
|
|
|
get_detail(path, function(path) {
|
2009-12-15 20:23:32 +00:00
|
|
|
var album = $("#album_tree [ref='" + path + "']");
|
|
|
|
if (album.length > 0) {
|
2009-12-17 04:11:15 +00:00
|
|
|
$(".tree-title.ui-selected").removeClass("ui-selected");
|
2009-12-15 20:23:32 +00:00
|
|
|
$(".tree-title", album).addClass("ui-selected");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
2009-12-12 17:39:18 +00:00
|
|
|
});
|
2009-12-15 20:23:32 +00:00
|
|
|
|
2009-12-16 19:51:45 +00:00
|
|
|
$("#center a.child-link").live("click", function(event) {
|
|
|
|
$(".thumb-grid-cell.ui-selected").removeClass("ui-selected");
|
|
|
|
$(this).parents("li:first").addClass("ui-selected");
|
2009-12-17 04:11:15 +00:00
|
|
|
_set_navigation_buttons($(".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() {
|
|
|
|
if ($(this).parent("a").hasClass("ui-state-disabled")) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-12-17 04:11:15 +00:00
|
|
|
var selected = $(".thumb-grid-cell.ui-selected");
|
|
|
|
switch ($(this).attr("ref")) {
|
|
|
|
case "parent":
|
2009-12-16 19:51:45 +00:00
|
|
|
get_detail($("span", this).attr("ref"));
|
2009-12-17 04:11:15 +00:00
|
|
|
break;
|
|
|
|
case "first":
|
|
|
|
case "previous":
|
|
|
|
case "next":
|
|
|
|
case "last":
|
|
|
|
if (selected.length == 0) {
|
|
|
|
get_detail($("span", this).attr("ref"));
|
|
|
|
} else {
|
|
|
|
selected.removeClass("ui-selected");
|
|
|
|
switch ($(this).attr("ref")) {
|
|
|
|
case "first":
|
|
|
|
$(".thumb-grid-cell:first").addClass("ui-selected");
|
|
|
|
break;
|
|
|
|
case "previous":
|
|
|
|
selected.prev().addClass("ui-selected");
|
|
|
|
break;
|
|
|
|
case "next":
|
|
|
|
selected.next().addClass("ui-selected");
|
|
|
|
break;
|
|
|
|
case "last":
|
|
|
|
$(".thumb-grid-cell:last").addClass("ui-selected");
|
|
|
|
_set_navigation_buttons();
|
|
|
|
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-12 17:39:18 +00:00
|
|
|
};
|
2009-12-16 19:51:45 +00:00
|
|
|
|
|
|
|
function set_selected_thumb() {
|
|
|
|
if ($(".thumb-grid-cell.ui-selected").length == 0) {
|
|
|
|
$(".thumb-grid-cell:first").addClass("ui-selected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_detail(path, callback) {
|
|
|
|
$.get("/g3_client/index.php/g3_client/detail", {path: path}, function(data, textStatus) {
|
|
|
|
console.group("get_detail.get callback");
|
|
|
|
$("#wc-detail").html(data);
|
|
|
|
set_selected_thumb();
|
|
|
|
save_paths(path);
|
2009-12-17 04:11:15 +00:00
|
|
|
if (callback) {
|
2009-12-16 19:51:45 +00:00
|
|
|
callback(path);
|
|
|
|
}
|
|
|
|
console.groupEnd();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function save_paths(path) {
|
|
|
|
_paths[path] = [];
|
|
|
|
$(".thumb-grid-cell").each(function(i) {
|
2009-12-17 04:11:15 +00:00
|
|
|
_paths[path][i] = $(this).attr("ref");
|
2009-12-16 19:51:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
console.dir(_paths);
|
|
|
|
enable_toolbar_buttons(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
function enable_toolbar_buttons(path) {
|
|
|
|
if (path != "") {
|
|
|
|
$(".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");
|
|
|
|
}
|
|
|
|
$(".wc-toolbar .ui-icon-eject").attr("ref", _get_parent_path(path));
|
|
|
|
$(".wc-toolbar .ui-icon-pencil").attr("ref", path);
|
|
|
|
|
|
|
|
_set_navigation_buttons();
|
|
|
|
}
|
|
|
|
|
|
|
|
function _get_parent_path(path) {
|
|
|
|
var idx = path.lastIndexOf("/");
|
|
|
|
return idx != -1 ? path.substring(0, idx) : "";
|
|
|
|
}
|
|
|
|
|
|
|
|
function _set_navigation_buttons() {
|
|
|
|
var selected_path = $(".thumb-grid-cell.ui-selected").attr("ref");
|
|
|
|
if (selected_path == undefined) { // not found must be photo or movie
|
|
|
|
selected_path = $("#wc-detail div:first").attr("ref");
|
|
|
|
}
|
|
|
|
var parent_path = _get_parent_path(selected_path);
|
|
|
|
console.log("path: " + selected_path + "; parent_path: " + parent_path);
|
|
|
|
var paths = _paths[parent_path];
|
|
|
|
console.group("parent path");
|
|
|
|
console.dir(paths);
|
|
|
|
console.groupEnd();
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
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 04:11:15 +00:00
|
|
|
console.log("found path: " + paths[i]);
|
2009-12-16 19:51:45 +00:00
|
|
|
}
|
2009-12-12 17:39:18 +00:00
|
|
|
})(jQuery);
|