javascript/taggr.js
author terom
Sun, 20 Jan 2008 01:07:02 +0000
changeset 24 001f52cd057e
parent 23 10841abbc01f
child 25 4b3cf12848c2
permissions -rw-r--r--
tagging/untagging should now work fully in taggr
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
     1
/*
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
     2
 * dir-list manipulation
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
     3
 */
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     4
function toggle_dir (header_a_tag) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     5
    var div = Element.next(header_a_tag);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     6
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     7
    if (div._have_contents) {
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
     8
        if (div.visible()) {
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     9
            Effect.BlindUp(div, {duration: 0.5});
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    10
            func = hide_tag_image;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    11
        } else {
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    12
            Effect.BlindDown(div, {duration: 0.5});
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    13
            func = show_tag_image;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    14
        }
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    15
        
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    16
        Element.up(header_a_tag)._images.each(function(key){
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    17
            $("img_" + key)._tags.each(function(tag){
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    18
                func(tag, key);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    19
            });
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    20
        });
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    21
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    22
    } else {
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
        new Ajax.Updater(div, "taggr2.py", {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    25
            parameters: {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    26
                act: "dirlist",
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    27
                path: div.id,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    28
            },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    29
            method: 'get',
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    30
            onSuccess: function () {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    31
                Effect.BlindDown(div, {duration: 0.5});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    32
                div._have_contents = true;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    33
            }
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
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    38
var g_last_select;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    39
function image_click (img, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    40
    var updiv = img.up(2);
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    41
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    42
    if (img.hasClassName("selection")) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    43
        img.removeClassName("selection");
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    44
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    45
    } else if (ev.shiftKey && g_last_select && g_last_select.up(2) == updiv) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    46
        var from = Math.min(img._offset, g_last_select._offset);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    47
        var to = Math.max(img._offset, g_last_select._offset);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    48
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    49
        for (var i = from; i <= to; i++) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    50
            $("img_" + updiv._images[i]).addClassName("selection");
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    51
        }
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    52
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    53
        g_last_select = img;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    54
    } else {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    55
        
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    56
        g_last_select = img;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    57
        img.addClassName("selection");
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    58
    }
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    59
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    60
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    61
function selection_clear () {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    62
    $$(".selection").each(function(e){
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    63
        e.removeClassName("selection");
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    64
    });
23
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
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    67
/*
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    68
 * image-loading callback
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    69
 */
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    70
function image_info (img, offset, key, tags) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    71
    img._key = key;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    72
    img._tags = $A(tags);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    73
    img._offset = offset;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    74
    
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    75
    img._tags.each(function(tag){
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    76
        if (!$('tag_' + tag + '_images'))
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    77
            new_tag(tag);
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    78
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    79
        tag_add_image(img, null, tag, false);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    80
    });
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    81
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    82
    var dir = img.up(2);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    83
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    84
    if (!dir._images)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    85
        dir._images = new Array();
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    86
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    87
    dir._images.push(img._key);
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    88
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    89
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    90
/*
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    91
 * tag list manipulation code
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    92
 */
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    93
function _tag_name (tag_name) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    94
    var tag_name_p = Builder.node("p", {id:"tag_" + tag_name + "_name", className: "draggable tag_name"}, [tag_name]);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    95
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    96
    tag_name_p._tag = tag_name;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    97
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
    98
    return tag_name_p;
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    99
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   100
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   101
function new_tag (tag_name) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   102
    var tag_images = Builder.node("td", {className:"tag_images", id:"tag_" + tag_name + "_images"});
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   103
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   104
    tag_images._tag = tag_name;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   105
    tag_images._visibleCount = 0;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   106
    tag_images._images = new Array();
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   107
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   108
    var tag_row = Builder.node("tr", {className:"tag_row", id:"tag_" + tag_name}, [
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   109
        Builder.node("td", {className:"tag", id:"tag_" + tag_name + "_tags"}, [
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   110
            _tag_name(tag_name)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   111
        ]),
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   112
        tag_images
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   113
    ]);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   114
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   115
    tag_row._tag = tag_name;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   116
    tag_row._tags = new Array(tag_name);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   117
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   118
    $("tag_table").appendChild(tag_row);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   119
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   120
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   121
function tag_add_tag (new_tag, tag) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   122
    var tag_row = $("tag_" + tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   123
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   124
    if (tag_row._tags.indexOf(new_tag) != -1)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   125
        return false;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   126
    
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   127
    tag_row._tags.push(new_tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   128
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   129
    $("tag_" + tag + "_tags").appendChild(_tag_name(new_tag));
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   130
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   131
/*
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   132
    new Ajax.Request("taggr2.py", {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   133
        parameters: {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   134
            act: 'tag',
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   135
            tag: new_tag,
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   136
            img: $("tag_" + tag + "_images")._images,
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   137
        },
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   138
        method: 'get'
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   139
    });
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   140
*/
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   141
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   142
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   143
function tag_remove_tag (tag_name) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   144
    var tag_row = $("tag_" + tag_name + "_name").up(1);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   145
    array_remove(tag_row._tags, tag_name);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   146
    
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   147
    $("tag_" + tag_row._tag + "_tags").removeChild($("tag_" + tag_name + "_name"));
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   148
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   149
    if (tag_row._tags.length == 0)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   150
        $("tag_table").removeChild(tag_row);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   151
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   152
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   153
function get_tag (tag_name, postfix) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   154
    return $("tag_" + $("tag_" + tag_name).up(1)._tag + "_" + postfix);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   155
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   156
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   157
function tag_add_image (orig_img, copy_img, tag, saveToDB) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   158
    var tag_images = $('tag_' + tag + '_images');
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   159
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   160
    if (tag_images._images.indexOf(orig_img._key) != -1)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   161
        return false;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   162
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   163
    if (!copy_img)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   164
        copy_img = image_copy(orig_img);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   165
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   166
    tag_images._images.push(orig_img._key)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   167
    orig_img._tags.push(tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   168
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   169
    copy_img.id = "tag_" + tag + "_img_" + orig_img._key
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   170
    copy_img._tag = tag;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   171
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   172
    tag_images.appendChild(copy_img);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   173
    tag_images._visibleCount++;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   174
    
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   175
    if (saveToDB) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   176
        new Ajax.Request("taggr2.py", {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   177
            parameters: {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   178
                act: 'tag',
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   179
                img: orig_img._key,
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   180
                tag: tag,
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   181
            },
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   182
            method: 'get'
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   183
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   184
        });
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   185
    }
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   186
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   187
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   188
function tag_add_images (images, tag_name) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   189
    var tag_images = $('tag_' + tag_name + '_images');
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   190
    var copy_img, img_keys = new Array();
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   191
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   192
    images.each(function(orig_img){
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   193
        tag_add_image(orig_img, null, tag_name, false);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   194
        img_keys.push(orig_img._key);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   195
    });
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   196
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   197
    new Ajax.Request("taggr2.py", {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   198
        parameters: {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   199
            act: 'tag',
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   200
            img: img_keys,
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   201
            tag: tag_name,
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   202
        },
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   203
        method: 'get'
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   204
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   205
    });
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   206
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   207
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   208
function tag_remove_image (img_key, tag_name) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   209
    var tag_images = $("tag_" + tag_name + "_images");
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   210
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   211
    tag_images.removeChild($("tag_" + tag_name + "_img_" + img_key));
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   212
    array_remove(tag_images._images, img_key);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   213
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   214
    if (tag_images._images.length == 0)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   215
        $("tag_" + tag_name).hide();
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   216
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   217
    new Ajax.Request("taggr2.py", {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   218
        parameters: {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   219
            act: 'untag',
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   220
            img: img_key,
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   221
            tag: tag_name,
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   222
        },
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   223
        method: 'get',
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   224
    });
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   225
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   226
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   227
function hide_tag_image (tag, img) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   228
    $("tagimg_" + tag + "_" + img).hide();
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   229
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   230
    if (--$("tag_" + tag + "_images")._visibleCount == 0)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   231
        $("tag_" + tag).hide();
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   232
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   233
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   234
function show_tag_image (tag, img) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   235
    $("tagimg_" + tag + "_" + img).hide();
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   236
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   237
    if ($("tag_" + tag + "_images")._visibleCount++ == 0)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   238
         $("tag_" + tag).show();
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   239
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   240
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   241
/*
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   242
 * Frontend image drag code
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   243
 */
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   244
var g_ghost;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   245
function drag_start (e) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   246
    if (e.hasClassName("image") || e.hasClassName("tag_image"))
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   247
        g_ghost = image_copy(e);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   248
    else {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   249
        var name;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   250
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   251
        if (e.hasClassName("tag_name"))
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   252
            name = e._tag;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   253
        else
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   254
            name = $F($('new_tag'));
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   255
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   256
        g_ghost = Builder.node("span", {className: 'dragged'}, [name]);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   257
    }
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   258
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   259
    $('taggr').appendChild(g_ghost);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   260
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   261
    g_ghost.style.position = "absolute";
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   262
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   263
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   264
function drag_move (e, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   265
    g_ghost.style.left = ev.pointerX() - g_offset.left + "px";
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   266
    g_ghost.style.top = ev.pointerY() - g_offset.top + "px";
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   267
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   268
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   269
function drag_end_drop (e, s, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   270
    g_ghost.style.position = "static";
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   271
    $('taggr').removeChild(g_ghost);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   272
    
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   273
    if (e.hasClassName("image") || e.hasClassName("tag_image")) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   274
        var selection = $$(".selection");
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   275
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   276
        if (selection.length)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   277
            tag_add_images($$(".selection"), s._tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   278
        else
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   279
            tag_add_image(e, g_ghost, s._tag, true);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   280
            
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   281
/*
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   282
        if (!tag_add_image(e, g_ghost, s._tag, true))
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   283
            // it was already in there
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   284
            Effect.Shake("tagimg_" + s._tag + "_" + g_ghost._key);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   285
*/            
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   286
    } else if (e.hasClassName("tag_name")) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   287
        null;   // breakpoint
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   288
    } else {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   289
        tag_add_tag($F($('new_tag')), s._tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   290
    }
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   291
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   292
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   293
function drag_end_fail (e, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   294
    if (e.hasClassName("tag_image")) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   295
        tag_remove_image(e._key, e._tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   296
        $('taggr').removeChild(g_ghost);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   297
    } else if (e.hasClassName("tag_name")) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   298
        tag_remove_tag(e._tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   299
    } else {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   300
        $('taggr').removeChild(g_ghost);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   301
    }
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   302
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   303
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   304
function drag_cleanup (e, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   305
    g_ghost = null;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   306
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   307
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   308
function drag_hover (e, s, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   309
    s.addClassName("hover");
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   310
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   311
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   312
function drag_unhover (e, s, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   313
    s.removeClassName("hover");
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   314
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   315
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   316
/*
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   317
 * Backend image click/drag code
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   318
 */
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   319
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   320
var g_drag, g_hover, g_start, g_offset, g_targets;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   321
function check_mouse_down (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   322
    var e = ev.element();
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   323
    
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   324
    if (!ev.isLeftClick())
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   325
        return true;
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   326
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   327
    if (e.hasClassName("image") || e.hasClassName("draggable") || e.hasClassName("tag_image")) {
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   328
        g_drag = e;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   329
        g_start = false;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   330
        
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   331
        var offset = e.cumulativeOffset();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   332
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   333
        g_offset = {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   334
            'left': ev.pointerX() - offset.left,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   335
            'top': ev.pointerY() - offset.top
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   336
        };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   337
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   338
        g_hover = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   339
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   340
        g_targets = $$(".tag_row");
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   341
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   342
    } else if (e.hasClassName("directory_link")) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   343
        toggle_dir(e);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   344
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   345
    } else {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   346
        return true;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   347
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   348
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   349
    ev.stop();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   350
    return false;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   351
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   352
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   353
function check_mouse_up (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   354
    if (g_drag) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   355
        if (g_start) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   356
            if (g_hover) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   357
                drag_unhover(g_drag, g_hover, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   358
                drag_end_drop(g_drag, g_hover, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   359
            } else
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   360
                drag_end_fail(g_drag, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   361
            
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   362
            drag_cleanup(g_drag);
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   363
        } else if (g_drag.hasClassName("image") || g_drag.hasClassName("tag_image")) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   364
            // in case image_click blocks and we get a mouse_move during it
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   365
            var tmp = g_drag;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   366
            g_drag = null;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   367
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   368
            image_click(tmp, ev);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   369
        }
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   370
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   371
        g_start = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   372
        g_drag = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   373
        g_hover = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   374
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   375
        ev.stop();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   376
        return false;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   377
    }   
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   378
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   379
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   380
function check_mouse_move (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   381
    if (g_drag) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   382
        if (!g_start) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   383
            drag_start(g_drag);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   384
            g_start = true;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   385
        }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   386
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   387
        drag_move(g_drag, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   388
        
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   389
        Position.prepare();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   390
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   391
        var px = ev.pointerX();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   392
        var py = ev.pointerY();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   393
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   394
        if (g_hover) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   395
            if (!Position.withinIncludingScrolloffsets(g_hover, px, py)) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   396
                drag_unhover(g_drag, g_hover, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   397
                g_hover = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   398
            }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   399
        } else {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   400
            for (var i=0;i<g_targets.length;i++)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   401
                if (Position.withinIncludingScrolloffsets(g_targets[i], px, py)) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   402
                    drag_hover(g_drag, g_targets[i], ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   403
                    g_hover = g_targets[i];
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   404
                    break;
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   405
                }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   406
        }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   407
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   408
        ev.stop();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   409
        return false;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   410
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   411
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   412
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   413
function check_drag_hover (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   414
    if (g_start) {
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   415
        var e = ev.element();
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   416
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   417
        if (e.hasClassName("tag_row")) {
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   418
            drag_hover(g_drag, e, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   419
            g_hover = e;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   420
        }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   421
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   422
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   423
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   424
function check_drag_nohover (ev) {
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   425
    if (g_start) {
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   426
        var e = ev.element();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   427
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   428
        if (g_hover && e == g_hover) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   429
            drag_unhover(g_drag, g_hover, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   430
            g_hover = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   431
        }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   432
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   433
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   434
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   435
/* 
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   436
 * utility code
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   437
 */
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   438
function image_copy (img) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   439
    copy = Builder.node("img", {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   440
        src: img.src,
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   441
        className: "tag_image",
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   442
    });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   443
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   444
    copy._key = img._key;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   445
    copy._tags = img._tags;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   446
    
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   447
    return copy;
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   448
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   449
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   450
function array_remove (a, i) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   451
    a.splice(a.indexOf(i), 1);
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   452
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   453
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   454
/*
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   455
 * events
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   456
 */
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   457
Event.observe(document, "mousedown", check_mouse_down);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   458
Event.observe(document, "mouseup", check_mouse_up);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   459
Event.observe(document, "mousemove", check_mouse_move);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   460
Event.observe(document, "mouseover", check_drag_hover);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   461
Event.observe(document, "mouseout", check_drag_nohover);
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   462
Event.observe(document, "dragenter", check_drag_hover);     // worth a try...
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   463
Event.observe(document, "dragexit", check_drag_nohover);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   464