javascript/taggr.js
author terom
Sun, 20 Jan 2008 01:52:00 +0000
changeset 25 4b3cf12848c2
parent 24 001f52cd057e
permissions -rw-r--r--
tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
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) {
25
4b3cf12848c2 tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents: 24
diff changeset
   102
    if ($("tag_" + tag_name)) {
4b3cf12848c2 tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents: 24
diff changeset
   103
        $("tag_" + tag_name).show().scrollTo();
4b3cf12848c2 tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents: 24
diff changeset
   104
    }
4b3cf12848c2 tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents: 24
diff changeset
   105
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   106
    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
   107
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   108
    tag_images._tag = tag_name;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   109
    tag_images._visibleCount = 0;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   110
    tag_images._images = new Array();
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
    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
   113
        Builder.node("td", {className:"tag", id:"tag_" + tag_name + "_tags"}, [
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   114
            _tag_name(tag_name)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   115
        ]),
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   116
        tag_images
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
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   119
    tag_row._tag = tag_name;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   120
    tag_row._tags = new Array(tag_name);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   121
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   122
    $("tag_table").appendChild(tag_row);
25
4b3cf12848c2 tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents: 24
diff changeset
   123
4b3cf12848c2 tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents: 24
diff changeset
   124
    return true;
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   125
}
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
function tag_add_tag (new_tag, tag) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   128
    var tag_row = $("tag_" + tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   129
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   130
    if (tag_row._tags.indexOf(new_tag) != -1)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   131
        return false;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   132
    
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   133
    tag_row._tags.push(new_tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   134
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   135
    $("tag_" + tag + "_tags").appendChild(_tag_name(new_tag));
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   136
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
    new Ajax.Request("taggr2.py", {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   139
        parameters: {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   140
            act: 'tag',
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   141
            tag: new_tag,
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   142
            img: $("tag_" + tag + "_images")._images,
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   143
        },
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   144
        method: 'get'
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   145
    });
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
}
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
function tag_remove_tag (tag_name) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   150
    var tag_row = $("tag_" + tag_name + "_name").up(1);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   151
    array_remove(tag_row._tags, tag_name);
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
    $("tag_" + tag_row._tag + "_tags").removeChild($("tag_" + tag_name + "_name"));
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   154
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   155
    if (tag_row._tags.length == 0)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   156
        $("tag_table").removeChild(tag_row);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   157
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   158
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   159
function get_tag (tag_name, postfix) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   160
    return $("tag_" + $("tag_" + tag_name).up(1)._tag + "_" + postfix);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   161
}
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
function tag_add_image (orig_img, copy_img, tag, saveToDB) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   164
    var tag_images = $('tag_' + tag + '_images');
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
    if (tag_images._images.indexOf(orig_img._key) != -1)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   167
        return false;
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
    if (!copy_img)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   170
        copy_img = image_copy(orig_img);
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._images.push(orig_img._key)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   173
    orig_img._tags.push(tag);
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
    copy_img.id = "tag_" + tag + "_img_" + orig_img._key
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   176
    copy_img._tag = tag;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   177
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   178
    tag_images.appendChild(copy_img);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   179
    tag_images._visibleCount++;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   180
    
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   181
    if (saveToDB) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   182
        new Ajax.Request("taggr2.py", {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   183
            parameters: {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   184
                act: 'tag',
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   185
                img: orig_img._key,
25
4b3cf12848c2 tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents: 24
diff changeset
   186
                tag: $("tag_" + tag)._tags,
24
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
            method: 'get'
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   189
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   190
        });
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
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   193
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   194
function tag_add_images (images, tag_name) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   195
    var tag_images = $('tag_' + tag_name + '_images');
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   196
    var copy_img, img_keys = new Array();
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   197
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   198
    images.each(function(orig_img){
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   199
        tag_add_image(orig_img, null, tag_name, false);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   200
        img_keys.push(orig_img._key);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   201
    });
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
    new Ajax.Request("taggr2.py", {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   204
        parameters: {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   205
            act: 'tag',
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   206
            img: img_keys,
25
4b3cf12848c2 tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents: 24
diff changeset
   207
            tag: $("tag_" + tag_name)._tags,
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   208
        },
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   209
        method: 'get'
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
    });
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   212
}
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
function tag_remove_image (img_key, tag_name) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   215
    var tag_images = $("tag_" + tag_name + "_images");
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
    tag_images.removeChild($("tag_" + tag_name + "_img_" + img_key));
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   218
    array_remove(tag_images._images, img_key);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   219
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   220
    if (tag_images._images.length == 0)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   221
        $("tag_" + tag_name).hide();
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
    new Ajax.Request("taggr2.py", {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   224
        parameters: {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   225
            act: 'untag',
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   226
            img: img_key,
25
4b3cf12848c2 tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents: 24
diff changeset
   227
            tag: $("tag_" + tag_name)._tags,
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   228
        },
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   229
        method: 'get',
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   230
    });
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   231
}
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
function hide_tag_image (tag, img) {
25
4b3cf12848c2 tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents: 24
diff changeset
   234
    $("tag_" + tag + "_img_" + img).hide();
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   235
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   236
    if (--$("tag_" + tag + "_images")._visibleCount == 0)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   237
        $("tag_" + tag).hide();
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   238
}
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
function show_tag_image (tag, img) {
25
4b3cf12848c2 tweaks/bugfixes (e.g. support adding multiple tags to an image at once)
terom
parents: 24
diff changeset
   241
    $("tag_" + tag + "_img_" + img).show();
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   242
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   243
    if ($("tag_" + tag + "_images")._visibleCount++ == 0)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   244
         $("tag_" + tag).show();
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   245
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   246
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   247
/*
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   248
 * Frontend image drag code
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   249
 */
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   250
var g_ghost;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   251
function drag_start (e) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   252
    if (e.hasClassName("image") || e.hasClassName("tag_image"))
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   253
        g_ghost = image_copy(e);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   254
    else {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   255
        var name;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   256
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   257
        if (e.hasClassName("tag_name"))
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   258
            name = e._tag;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   259
        else
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   260
            name = $F($('new_tag'));
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   261
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   262
        g_ghost = Builder.node("span", {className: 'dragged'}, [name]);
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
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   265
    $('taggr').appendChild(g_ghost);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   266
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   267
    g_ghost.style.position = "absolute";
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
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   270
function drag_move (e, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   271
    g_ghost.style.left = ev.pointerX() - g_offset.left + "px";
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   272
    g_ghost.style.top = ev.pointerY() - g_offset.top + "px";
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   273
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   274
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   275
function drag_end_drop (e, s, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   276
    g_ghost.style.position = "static";
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   277
    $('taggr').removeChild(g_ghost);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   278
    
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   279
    if (e.hasClassName("image") || e.hasClassName("tag_image")) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   280
        var selection = $$(".selection");
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 (selection.length)
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   283
            tag_add_images($$(".selection"), s._tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   284
        else
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   285
            tag_add_image(e, g_ghost, s._tag, true);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   286
            
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   287
/*
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   288
        if (!tag_add_image(e, g_ghost, s._tag, true))
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   289
            // it was already in there
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   290
            Effect.Shake("tagimg_" + s._tag + "_" + g_ghost._key);
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
    } else if (e.hasClassName("tag_name")) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   293
        null;   // breakpoint
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   294
    } else {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   295
        tag_add_tag($F($('new_tag')), s._tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   296
    }
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   297
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   298
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   299
function drag_end_fail (e, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   300
    if (e.hasClassName("tag_image")) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   301
        tag_remove_image(e._key, e._tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   302
        $('taggr').removeChild(g_ghost);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   303
    } else if (e.hasClassName("tag_name")) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   304
        tag_remove_tag(e._tag);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   305
    } else {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   306
        $('taggr').removeChild(g_ghost);
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
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   309
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   310
function drag_cleanup (e, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   311
    g_ghost = null;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   312
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   313
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   314
function drag_hover (e, s, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   315
    s.addClassName("hover");
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
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   318
function drag_unhover (e, s, ev) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   319
    s.removeClassName("hover");
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   320
}
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   321
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   322
/*
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   323
 * Backend image click/drag code
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   324
 */
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   325
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   326
var g_drag, g_hover, g_start, g_offset, g_targets;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   327
function check_mouse_down (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   328
    var e = ev.element();
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   329
    
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   330
    if (!ev.isLeftClick())
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   331
        return true;
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   332
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   333
    if (e.hasClassName("image") || e.hasClassName("draggable") || e.hasClassName("tag_image")) {
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   334
        g_drag = e;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   335
        g_start = false;
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
        var offset = e.cumulativeOffset();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   338
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   339
        g_offset = {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   340
            'left': ev.pointerX() - offset.left,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   341
            'top': ev.pointerY() - offset.top
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   342
        };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   343
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   344
        g_hover = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   345
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   346
        g_targets = $$(".tag_row");
23
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
    } else if (e.hasClassName("directory_link")) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   349
        toggle_dir(e);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   350
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   351
    } else {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   352
        return true;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   353
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   354
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   355
    ev.stop();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   356
    return false;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   357
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   358
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   359
function check_mouse_up (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   360
    if (g_drag) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   361
        if (g_start) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   362
            if (g_hover) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   363
                drag_unhover(g_drag, g_hover, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   364
                drag_end_drop(g_drag, g_hover, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   365
            } else
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   366
                drag_end_fail(g_drag, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   367
            
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   368
            drag_cleanup(g_drag);
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   369
        } 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
   370
            // 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
   371
            var tmp = g_drag;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   372
            g_drag = null;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   373
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   374
            image_click(tmp, ev);
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   375
        }
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   376
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   377
        g_start = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   378
        g_drag = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   379
        g_hover = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   380
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   381
        ev.stop();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   382
        return false;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   383
    }   
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   384
}
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
function check_mouse_move (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   387
    if (g_drag) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   388
        if (!g_start) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   389
            drag_start(g_drag);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   390
            g_start = true;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   391
        }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   392
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   393
        drag_move(g_drag, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   394
        
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   395
        Position.prepare();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   396
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   397
        var px = ev.pointerX();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   398
        var py = ev.pointerY();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   399
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   400
        if (g_hover) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   401
            if (!Position.withinIncludingScrolloffsets(g_hover, px, py)) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   402
                drag_unhover(g_drag, g_hover, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   403
                g_hover = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   404
            }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   405
        } else {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   406
            for (var i=0;i<g_targets.length;i++)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   407
                if (Position.withinIncludingScrolloffsets(g_targets[i], px, py)) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   408
                    drag_hover(g_drag, g_targets[i], ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   409
                    g_hover = g_targets[i];
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   410
                    break;
23
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
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   414
        ev.stop();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   415
        return false;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   416
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   417
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   418
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   419
function check_drag_hover (ev) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   420
    if (g_start) {
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   421
        var e = ev.element();
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   422
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   423
        if (e.hasClassName("tag_row")) {
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   424
            drag_hover(g_drag, e, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   425
            g_hover = e;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   426
        }
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
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   429
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   430
function check_drag_nohover (ev) {
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   431
    if (g_start) {
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   432
        var e = ev.element();
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
        if (g_hover && e == g_hover) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   435
            drag_unhover(g_drag, g_hover, ev);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   436
            g_hover = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   437
        }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   438
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   439
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   440
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   441
/* 
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   442
 * utility code
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   443
 */
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   444
function image_copy (img) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   445
    copy = Builder.node("img", {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   446
        src: img.src,
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   447
        className: "tag_image",
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
    copy._key = img._key;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   451
    copy._tags = img._tags;
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   452
    
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   453
    return copy;
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   454
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   455
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   456
function array_remove (a, i) {
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   457
    a.splice(a.indexOf(i), 1);
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   458
}
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   459
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   460
/*
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   461
 * events
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   462
 */
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   463
Event.observe(document, "mousedown", check_mouse_down);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   464
Event.observe(document, "mouseup", check_mouse_up);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   465
Event.observe(document, "mousemove", check_mouse_move);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   466
Event.observe(document, "mouseover", check_drag_hover);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   467
Event.observe(document, "mouseout", check_drag_nohover);
24
001f52cd057e tagging/untagging should now work fully in taggr
terom
parents: 23
diff changeset
   468
Event.observe(document, "dragenter", check_drag_hover);     // worth a try...
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   469
Event.observe(document, "dragexit", check_drag_nohover);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   470