summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-04-19 18:33:35 +0000
committerTim Almdal <tnalmdal@shaw.ca>2009-04-19 18:33:35 +0000
commit663c38a7e85eb58f2526d2fe7ac9aa6c040bf44d (patch)
treeaf0033f3ecc554d5298e4e333a5d2cd639acfcf5 /modules
parentf1a9ac807ce32d68dac9b43ae0123390dc30e70f (diff)
Continue javascript code cleanup
Diffstat (limited to 'modules')
-rw-r--r--modules/organize/js/organize.js272
1 files changed, 133 insertions, 139 deletions
diff --git a/modules/organize/js/organize.js b/modules/organize/js/organize.js
index 70f18d48..953fef07 100644
--- a/modules/organize/js/organize.js
+++ b/modules/organize/js/organize.js
@@ -8,153 +8,164 @@ var height;
// JQuery UI Widgets
// Draggable
var draggable = {
- cancel: ".gMicroThumbContainer:not(.ui-selected)",
- handle: ".gMicroThumbContainer.ui-selected",
- zindex: 2000,
- helper: function(event, ui) {
- $("#gMicroThumbPanel").append("<div id=\"gDragHelper\"><ul></ul></div>");
- var beginTop = event.pageY;
- var beginLeft = event.pageX;
- var zindex = $(".gMicroThumbContainer").draggable("option", "zindex");
- $("#gDragHelper").css('top', event.pageY - 22.5);
- $("#gDragHelper").css('left', event.pageX + 22.5);
- var placeHolder = $(this).clone();
- $(placeHolder).attr("id", "gPlaceHolder");
- $(placeHolder).css("visibility", "hidden");
- $(placeHolder).removeClass("ui-selected");
- $(placeHolder).removeClass("ui-draggable");
- $(this).after(placeHolder);
+ cancel: ".gMicroThumbContainer:not(.ui-selected)",
+ handle: ".gMicroThumbContainer.ui-selected",
+ zindex: 2000,
+ helper: function(event, ui) {
+ $("#gMicroThumbPanel").append("<div id=\"gDragHelper\"><ul></ul></div>");
+ var beginTop = event.pageY;
+ var beginLeft = event.pageX;
+ var zindex = $(".gMicroThumbContainer").draggable("option", "zindex");
+ $("#gDragHelper").css('top', event.pageY - 22.5);
+ $("#gDragHelper").css('left', event.pageX + 22.5);
+ var placeHolder = $(this).clone();
+ $(placeHolder).attr("id", "gPlaceHolder");
+ $(placeHolder).css("visibility", "hidden");
+ $(placeHolder).removeClass("ui-selected");
+ $(placeHolder).removeClass("ui-draggable");
+ $(this).after(placeHolder);
- $("li.ui-selected").each(function(i) {
- var clone = $(this).clone();
- $(clone).attr("id", "drag_clone_" + $(this).attr("ref"));
- $("#gDragHelper ul").append(clone);
- $(clone).css("position", "absolute");
- $(clone).css("top", beginTop);
- $(clone).css("left", beginLeft);
- $(clone).css("z-index", zindex--);
- $(this).hide();
+ $("li.ui-selected").each(function(i) {
+ var clone = $(this).clone();
+ $(clone).attr("id", "drag_clone_" + $(this).attr("ref"));
+ $("#gDragHelper ul").append(clone);
+ $(clone).css("position", "absolute");
+ $(clone).css("top", beginTop);
+ $(clone).css("left", beginLeft);
+ $(clone).css("z-index", zindex--);
+ $(this).hide();
- var children = $(clone).find(".gMicroThumb .gThumbnail");
- var width = new String(children.css("width")).replace(/[^0-9]/g,"") * .5;
- height = new String(children.css("height")).replace(/[^0-9]/g,"") * .5;
- var marginTop = new String(children.css("margin-top")).replace(/[^\.0-9]/g,"") * .5;
- children.attr("width", width);
- children.attr("height", height);
- children.css("margin-top", marginTop);
- if (i < 9) {
- beginTop -= 5;
- beginLeft += 5;
- }
- });
- return $("#gDragHelper");
- },
- stop: function(event) {
- $(".gMicroThumbContainer.ui-selected").css("z-index", null);
- $("#gDragHelper").remove();
- $("#gPlaceHolder").remove();
+ var children = $(clone).find(".gMicroThumb .gThumbnail");
+ var width = new String(children.css("width")).replace(/[^0-9]/g,"") * .5;
+ height = new String(children.css("height")).replace(/[^0-9]/g,"") * .5;
+ var marginTop = new String(children.css("margin-top")).replace(/[^\.0-9]/g,"") * .5;
+ children.attr("width", width);
+ children.attr("height", height);
+ children.css("margin-top", marginTop);
+ if (i < 9) {
+ beginTop -= 5;
+ beginLeft += 5;
}
- };
+ });
+ return $("#gDragHelper");
+ },
+ stop: function(event) {
+ $(".gMicroThumbContainer.ui-selected").css("z-index", null);
+ $("#gDragHelper").remove();
+ $("#gPlaceHolder").remove();
+ }
+};
// Droppable
var droppable = {
- tolerance: "pointer",
- drop: function(event, ui) {
- $("#gDragHelper").hide();
- var dropTarget;
- if (event.pageX < $("#gMicroThumbGrid li:visible:first").offset().left ||
- event.pageY < $("#gMicroThumbGrid li:visible:first").offset().top) {
- dropTarget = 1;
- } else if (event.pageX > $("#gMicroThumbGrid li:visible:last").offset().left + 100 ||
- event.pageY > $("#gMicroThumbGrid li:visible:last").offset().top + 100) {
- dropTarget = 2;
- } else {
- dropTarget = 0;
- }
- $("#gDragHelper li").each(function(i) {
- switch (dropTarget) {
- case 0:
- $("#gPlaceHolder").before($("#thumb_" + $(this).attr("ref")).show());
- break;
- case 1:
- $("#gMicroThumbGrid").prepend($("#thumb_" + $(this).attr("ref")).show());
- break;
- case 2:
- $("#gMicroThumbGrid").append($("#thumb_" + $(this).attr("ref")).show());
- break;
- }
- });
+ tolerance: "pointer",
+ drop: function(event, ui) {
+ $("#gDragHelper").hide();
+ var dropTarget;
+ if (event.pageX < $("#gMicroThumbGrid li:visible:first").offset().left ||
+ event.pageY < $("#gMicroThumbGrid li:visible:first").offset().top) {
+ dropTarget = 1;
+ } else if (event.pageX > $("#gMicroThumbGrid li:visible:last").offset().left + 100 ||
+ event.pageY > $("#gMicroThumbGrid li:visible:last").offset().top + 100) {
+ dropTarget = 2;
+ } else {
+ dropTarget = 0;
+ }
+ $("#gDragHelper li").each(function(i) {
+ switch (dropTarget) {
+ case 0:
+ $("#gPlaceHolder").before($("#thumb_" + $(this).attr("ref")).show());
+ break;
+ case 1:
+ $("#gMicroThumbGrid").prepend($("#thumb_" + $(this).attr("ref")).show());
+ break;
+ case 2:
+ $("#gMicroThumbGrid").append($("#thumb_" + $(this).attr("ref")).show());
+ break;
}
- };
+ });
+ }
+};
// Selectable
var selectable = {
- count: 0,
- filter: ".gMicroThumbContainer",
- selected: function(event, ui) {
- /*
- * Count the number of selected items if it is greater than 1,
- * then click won't be called so we need to remove the gSelecting
- * class in the stop event.
- */
- var count = $("#gMicroThumbGrid").selectable("option", "count") + 1;
- $("#gMicroThumbGrid").selectable("option", "count", count);
- $(ui.selected).addClass("gSelecting");
- },
- stop: function(event) {
- var count = $("#gMicroThumbGrid").selectable("option", "count");
- if (count > 1) {
- $(".gMicroThumbContainer.gSelecting").removeClass("gSelecting");
- }
- $("#gMicroThumbGrid").selectable("option", "count", 0);
+ count: 0,
+ filter: ".gMicroThumbContainer",
+ selected: function(event, ui) {
+ /*
+ * Count the number of selected items if it is greater than 1,
+ * then click won't be called so we need to remove the gSelecting
+ * class in the stop event.
+ */
+ var count = $("#gMicroThumbGrid").selectable("option", "count") + 1;
+ $("#gMicroThumbGrid").selectable("option", "count", count);
+ $(ui.selected).addClass("gSelecting");
+ },
+ stop: function(event) {
+ var count = $("#gMicroThumbGrid").selectable("option", "count");
+ if (count > 1) {
+ $(".gMicroThumbContainer.gSelecting").removeClass("gSelecting");
}
- };
+ $("#gMicroThumbGrid").selectable("option", "count", 0);
+ }
+};
// **************************************************************************
// Event Handlers
// MicroThumbContainer click
var onMicroThumbContainerClick = function(event) {
- if ($(this).hasClass("gSelecting")) {
- $(this).removeClass("gSelecting");
- } else {
- $(this).removeClass("ui-selected");
- }
- };
+ if ($(this).hasClass("gSelecting")) {
+ $(this).removeClass("gSelecting");
+ } else {
+ $(this).removeClass("ui-selected");
+ }
+};
// MicroThumbContainer mousemove
var onMicroThumbContainerMousemove = function(event) {
- if ($("#gDragHelper").length > 0 && $(this).attr("id") != "gPlaceHolder") {
- if (event.pageX < this.offsetLeft + this.offsetWidth / 2) {
- $(this).before($("#gPlaceHolder"));
- } else {
- $(this).after($("#gPlaceHolder"));
- }
- var container = $("#gMicroThumbPanel").get(0);
- var scrollHeight = container.scrollHeight;
- var scrollTop = container.scrollTop;
- var height = $(container).height();
- if (event.pageY > height + scrollTop) {
- container.scrollTop = this.offsetTop;
- } else if (event.pageY < scrollTop) {
- container.scrollTop -= height;
- }
- }
- };
+ if ($("#gDragHelper").length > 0 && $(this).attr("id") != "gPlaceHolder") {
+ if (event.pageX < this.offsetLeft + this.offsetWidth / 2) {
+ $(this).before($("#gPlaceHolder"));
+ } else {
+ $(this).after($("#gPlaceHolder"));
+ }
+ var container = $("#gMicroThumbPanel").get(0);
+ var scrollHeight = container.scrollHeight;
+ var scrollTop = container.scrollTop;
+ var height = $(container).height();
+ if (event.pageY > height + scrollTop) {
+ container.scrollTop = this.offsetTop;
+ } else if (event.pageY < scrollTop) {
+ container.scrollTop -= height;
+ }
+ }
+};
+
+// Select All and Deselect All click
+function toggleSelectAll(event) {
+ if ($(this).attr("id") == "gMicroThumbSelectAll") {
+ $(".gMicroThumbContainer").addClass("ui-selected");
+ $("#gMicroThumbSelectAll").hide();
+ $("#gMicroThumbUnselectAll").show();
+ } else {
+ $(".gMicroThumbContainer").removeClass("ui-selected");
+ $("#gMicroThumbSelectAll").show();
+ $("#gMicroThumbUnselectAll").hide();
+ }
+}
// **************************************************************************
// AJAX Callbacks
// MicroThumbContainer click
var getMicroThumbsCallback = function(json, textStatus) {
+ if (json.count > 0) {
$("#gMicroThumbGrid").append(json.data);
- if (json.count == 0) {
- return;
- }
retrieveMicroThumbs();
$(".gMicroThumbContainer").click(onMicroThumbContainerClick);
$(".gMicroThumbContainer").mousemove(onMicroThumbContainerMousemove);
- $(".gMicroThumbContainer").draggable(draggable);
- $("#gMicroThumbPanel").droppable(droppable);
- };
+ $(".gMicroThumbContainer").draggable(draggable);
+ }
+};
// **************************************************************************
/**
@@ -192,15 +203,10 @@ function organize_dialog_init() {
retrieveMicroThumbs(item_id);
//showLoading("#gDialog");
- $("#gMicroThumbSelectAll").click(function(event) {
- selectAll(true);
- event.preventDefault();
- });
- $("#gMicroThumbUnselectAll").click(function(event) {
- selectAll(false);
- event.preventDefault();
- });
+ $("#gMicroThumbSelectAll").click(toggleSelectAll);
+ $("#gMicroThumbUnselectAll").click(toggleSelectAll);
+ $("#gMicroThumbPanel").droppable(droppable);
$("#gMicroThumbGrid").selectable(selectable);
}
@@ -251,18 +257,6 @@ function organizeOpenFolder(event) {
event.preventDefault();
}
-function selectAll(select) {
- if (select) {
- $(".gMicroThumbContainer").addClass("ui-selected");
- $("#gMicroThumbSelectAll").hide();
- $("#gMicroThumbUnselectAll").show();
- } else {
- $(".gMicroThumbContainer").removeClass("ui-selected");
- $("#gMicroThumbSelectAll").show();
- $("#gMicroThumbUnselectAll").hide();
- }
-}
-
function getViewportSize() {
return {
width : function() {