summaryrefslogtreecommitdiff
path: root/modules/organize/js/organize.js
blob: e84afd031b0691691775c8271b83de559011d436 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
(function($) {
  $.fn.organize = function(options) {
    var size = $.getViewportSize();
    var height = size.height() - 100;     // Leave 50 pixels on the top and bottom of the dialog
    var width = size.width() - 100;       // Leave 50 pixels on the left and right of the dialog
    var opts = $.extend({}, $.fn.organize.defaults, {width: width, height: height}, options);
    return this.each(function() {
      $(this).click(function(event) {
        var href = event.target.href;
        var size = $.getViewportSize();

        $("body").append('<div id="gOrganizeDialog"></div>');

        $("#gOrganizeDialog").dialog(opts);
        // Pass the approx height and width of the thumb grid to optimize thumb retrieval
        $.get(href, _init);
        return false;
      });
    });
  };

  $.fn.organize.defaults = {
    autoOpen: false,
    modal: true,
    resizable: false,
    minWidth: 600,
    minHeight: 500,
    position: "center",
    close: function () {
      $("#gOrganizeDialog").trigger("organize_close");
      $("#gOrganizeDialog").dialog("destroy").remove();
    },
    zIndex: 75
  };

  /**
   * Dynamically initialize the organize dialog when it is displayed
   */
  function _init(data) {

    // Deal with ui.jquery bug: http://dev.jqueryui.com/ticket/4475
    $(".sf-menu li.sfHover ul").css("z-index", 70);

    $("#gOrganizeDialog").html(data);
    $("#gOrganizeDialog").dialog("open");

    var heightMicroThumbPanel = $("#gOrganizeDialog").innerHeight();
    heightMicroThumbPanel -= 2 * parseFloat($("#gOrganizeDialog").css("padding-bottom"));
    heightMicroThumbPanel -= $("#gMessage").outerHeight();
    heightMicroThumbPanel = Math.floor(heightMicroThumbPanel);
    $("#gOrganizeTreeContainer").height(heightMicroThumbPanel);

    heightMicroThumbPanel -= $("#gOrganizeEditDrawerHandle").outerHeight();
    $("#gMicroThumbPanel").height(heightMicroThumbPanel);

    if ($("#gOrganizeDialog h1").length) {
      $("#gOrganizeDialog").dialog('option', 'title', $("#gOrganizeDialog h1:eq(0)").html());
    } else if ($("#gOrganizeDialog fieldset legend").length) {
      $("#gOrganizeDialog").dialog('option', 'title', $("#gOrganizeDialog fieldset legend:eq(0)").html());
    }

    $("#gOrganizeDialog #gMicroThumbDone").click(_dialog_close);
    $("#gOrganizeDialog").bind("organize_close", function(target) {
      $.gallery_reload();
    });

    //$(".gOrganizeBranch .ui-icon").click(organizeToggleChildren);
    //$(".gBranchText").droppable(treeDroppable);
    //$(".gBranchText").click(organizeOpenFolder);
    //retrieveMicroThumbs(item_id);
    //showLoading("#gOrganizeDialog");

    //$("#gMicroThumbPanel").droppable(thumbDroppable);
    //$("#gMicroThumbPanel").selectable(selectable);
    //$("#gOrganizeEditDrawerHandle a").click(drawerHandleButtonsClick);

    $(window).bind("resize", _size_dialog);
  };

  /**
   * Dynamically initialize the organize dialog when it is displayed
   */
  function _size_dialog(event) {
    var size = $.getViewportSize();
    var h = $("#gOrganizeDialog").dialog("option", "minHeight");
    var sh = size.height() - 100;
    var height  = Math.max(sh, h);
    var w = $("#gOrganizeDialog").dialog("option", "minWidth");
    var sw = size.width() - 100;
    var width = Math.max(w, sw);

    $("#gOrganizeDialog").parent().css("height", height);
    $("#gOrganizeDialog").parent().css("width", width);
    $("#gOrganizeDialog").parent().css("left", "50px");
    $("#gOrganizeDialog").parent().css("top", "50px");

    var heightMicroThumbPanel = height - 50;
    heightMicroThumbPanel -= 2 * parseFloat($("#gOrganizeDialog").css("padding-bottom"));
    heightMicroThumbPanel -= $("#gMessage").outerHeight();
    heightMicroThumbPanel = Math.floor(heightMicroThumbPanel);
    $("#gOrganizeTreeContainer").height(heightMicroThumbPanel);

    heightMicroThumbPanel -= $("#gOrganizeEditDrawerHandle").outerHeight();
    $("#gMicroThumbPanel").height(heightMicroThumbPanel);
  };

  function _dialog_close(event) {
    event.preventDefault();
    $("#gOrganizeDialog").dialog("close");
  };

})(jQuery);

$("document").ready(function() {
  $("#gOrganizeLink").organize();
});