javascript/taggr.js
author terom
Thu, 17 Jan 2008 01:56:04 +0000
changeset 23 10841abbc01f
child 24 001f52cd057e
permissions -rw-r--r--
taggr2, which is starting to shape up
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     1
function toggle_dir (header_a_tag) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     2
    var div = Element.next(header_a_tag);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     3
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     4
    if (div._have_contents) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     5
        if (div.visible())
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     6
            Effect.BlindUp(div, {duration: 0.5});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     7
        else
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     8
            Effect.BlindDown(div, {duration: 0.5});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     9
    } else {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    10
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    11
        new Ajax.Updater(div, "taggr2.py", {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    12
            parameters: {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    13
                act: "dirlist",
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    14
                path: div.id,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    15
            },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    16
            method: 'get',
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    17
            onSuccess: function () {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    18
                Effect.BlindDown(div, {duration: 0.5});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    19
                div._have_contents = true;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    20
            }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    21
        });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    22
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    23
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    24
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    25
function new_tag (tag_name) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    26
    var tag_images = Builder.node("td", {className:"tag_images"});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    27
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    28
    $("tag_table").appendChild(
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    29
        Builder.node("tr", [
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    30
            Builder.node("td", {className:"tag"}, [
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    31
                tag_name
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    32
            ]),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    33
            tag_images
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    34
        ])
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    35
    );
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    36
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    37
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    38
function image_dropped (img, tag, e) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    39
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    40
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    41
function image_loaded (img) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    42
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    43
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    44
function image_click (img, ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    45
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    46
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    47
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    48
function init () {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    49
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    50
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    51
var g_drag, g_hover, g_start, g_offset, g_targets;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    52
function check_mouse_down (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    53
    var e = ev.element();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    54
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    55
    if (e.hasClassName("image")) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    56
        g_drag = e;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    57
        g_start = false;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    58
        
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    59
        var offset = e.cumulativeOffset();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    60
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    61
        g_offset = {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    62
            'left': ev.pointerX() - offset.left,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    63
            'top': ev.pointerY() - offset.top
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    64
        };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    65
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    66
        g_hover = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    67
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    68
        g_targets = $$(".tag_images");
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    69
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    70
    } else if (e.hasClassName("directory_link")) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    71
        toggle_dir(e);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    72
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    73
    } else {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    74
        return true;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    75
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    76
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    77
    ev.stop();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    78
    return false;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    79
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    80
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    81
function check_mouse_up (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    82
    if (g_drag) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    83
        if (g_start) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    84
            if (g_hover) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    85
                drag_unhover(g_drag, g_hover, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    86
                drag_end_drop(g_drag, g_hover, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    87
            } else
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    88
                drag_end_fail(g_drag, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    89
            
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    90
            drag_cleanup(g_drag);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    91
        } else
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    92
            image_click(g_drag, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    93
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    94
        g_start = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    95
        g_drag = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    96
        g_hover = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    97
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    98
        ev.stop();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    99
        return false;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   100
    }   
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   101
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   102
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   103
function check_mouse_move (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   104
    if (g_drag) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   105
        if (!g_start) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   106
            drag_start(g_drag);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   107
            g_start = true;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   108
        }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   109
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   110
        drag_move(g_drag, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   111
        
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   112
        Position.prepare();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   113
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   114
        var px = ev.pointerX();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   115
        var py = ev.pointerY();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   116
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   117
        if (g_hover) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   118
            if (!Position.withinIncludingScrolloffsets(g_hover, px, py)) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   119
                drag_unhover(g_drag, g_hover, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   120
                g_hover = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   121
            }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   122
        } else {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   123
            for (var i=0;i<g_targets.length;i++)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   124
                if (Position.withinIncludingScrolloffsets(g_targets[i], px, py)) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   125
                    drag_hover(g_drag, g_targets[i], ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   126
                    g_hover = g_targets[i];
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   127
                }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   128
        }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   129
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   130
        ev.stop();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   131
        return false;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   132
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   133
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   134
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   135
function check_drag_hover (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   136
        var e = ev.element();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   137
    if (g_start) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   138
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   139
        if (e.hasClassName("tag_images")) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   140
            drag_hover(g_drag, e, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   141
            g_hover = e;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   142
        }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   143
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   144
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   145
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   146
function check_drag_nohover (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   147
        var e = ev.element();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   148
    if (g_start) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   149
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   150
        if (g_hover && e == g_hover) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   151
            drag_unhover(g_drag, g_hover, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   152
            g_hover = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   153
        }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   154
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   155
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   156
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   157
var g_ghost;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   158
function drag_start (e) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   159
    g_ghost = Builder.node("img", {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   160
        src: e.src
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   161
    });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   162
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   163
    g_ghost._key = e.id;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   164
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   165
    $('taggr').appendChild(g_ghost);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   166
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   167
    g_ghost.style.position = "absolute";
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   168
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   169
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   170
function drag_move (e, ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   171
    g_ghost.style.left = ev.pointerX() - g_offset.left + "px";
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   172
    g_ghost.style.top = ev.pointerY() - g_offset.top + "px";
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   173
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   174
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   175
function drag_end_drop (e, s, ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   176
    if (!s.images)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   177
        s.images = new Array();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   178
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   179
    if (s.images.indexOf(g_ghost._key) != -1)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   180
        return drag_end_fail();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   181
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   182
    g_ghost.id = s.id + "_" + g_ghost._key
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   183
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   184
    s.images.push(g_ghost._key)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   185
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   186
    $('taggr').removeChild(g_ghost);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   187
    s.appendChild(g_ghost);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   188
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   189
    g_ghost.style.position = "static";
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   190
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   191
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   192
function drag_end_fail (e, ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   193
    $('taggr').removeChild(g_ghost);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   194
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   195
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   196
function drag_cleanup (e, ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   197
    g_ghost = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   198
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   199
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   200
function drag_hover (e, s, ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   201
    s.addClassName("hover");
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   202
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   203
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   204
function drag_unhover (e, s, ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   205
    s.removeClassName("hover");
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   206
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   207
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   208
Event.observe(window, "load", init);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   209
Event.observe(document, "mousedown", check_mouse_down);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   210
Event.observe(document, "mouseup", check_mouse_up);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   211
Event.observe(document, "mousemove", check_mouse_move);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   212
Event.observe(document, "mouseover", check_drag_hover);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   213
Event.observe(document, "mouseout", check_drag_nohover);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   214
Event.observe(document, "dragenter", check_drag_hover);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   215
Event.observe(document, "dragexit", check_drag_nohover);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   216
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   217