plugins/gallery/tagging.js
author Dan Fuhry <dan@enanocms.org>
Sun, 19 Sep 2010 03:51:00 -0400
changeset 45 740bbe1f4dd5
parent 42 7c6e2e97aa08
permissions -rw-r--r--
So yeah, new uploader broke on everything but zip files. Fixed that.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
     1
function snapr_add_tag()
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
     2
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
     3
	var image = document.getElementById('snapr_preview_img');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
     4
	image.parentNode.onclick = function(e)
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
     5
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
     6
		canvas_click(this);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
     7
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
     8
	image.parentNode.setAttribute('canvas:oncomplete', 'snapr_process_canvas_add(this);');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
     9
	image.parentNode.setAttribute('canvas:oncancel', 'obj.onclick = null;');
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    10
}
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    11
24
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
    12
function snapr_process_canvas_add(obj, tag_data)
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    13
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    14
	obj.onclick = null;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    15
	var abs_x = $dynano(obj).Left() + obj.canvas.left;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    16
	var abs_y = $dynano(obj).Top()  + obj.canvas.top;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    17
	var height = obj.canvas.height + 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    18
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    19
	var entry_div = document.createElement('div');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    20
	entry_div.className = 'snapr_tag_entry';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    21
	entry_div.style.position = 'absolute';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    22
	entry_div.style.top = String(abs_y + height) + 'px';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    23
	entry_div.style.left = String(abs_x)+ 'px';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    24
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    25
	entry_div.appendChild(document.createTextNode('Enter a tag:'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    26
	entry_div.appendChild(document.createElement('br'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    27
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    28
	var ta = document.createElement('textarea');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    29
	ta.rows = '7';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    30
	ta.cols = '30';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    31
	if ( typeof(tag_data) == 'string' )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    32
		ta.value = tag_data;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    33
	entry_div.appendChild(ta);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    34
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    35
	entry_div.appendChild(document.createElement('br'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    36
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    37
	var a_add = document.createElement('a');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    38
	a_add.href = '#';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    39
	a_add.onclick = function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    40
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    41
		var el = this.previousSibling;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    42
		while ( el.tagName != 'TEXTAREA' )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    43
			el = el.previousSibling;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    44
		
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    45
		snapr_finalize_canvas_add(this.parentNode, this.parentNode.parentNode.canvas, el.value);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    46
		return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    47
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    48
	a_add.appendChild(document.createTextNode('Add tag'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    49
	entry_div.appendChild(a_add);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    50
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    51
	entry_div.appendChild(document.createTextNode(' | '));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    52
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    53
	var a_cancel = document.createElement('a');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    54
	a_cancel.href = '#';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    55
	a_cancel.onclick = function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    56
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    57
		snapr_finalize_canvas_cancel(this.parentNode);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    58
		return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    59
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    60
	a_cancel.appendChild(document.createTextNode('Cancel'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    61
	entry_div.appendChild(a_cancel);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    62
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    63
	obj.appendChild(entry_div);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    64
	ta.focus();
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    65
}
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    66
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    67
function snapr_finalize_canvas_add(obj, canvas_data, tag)
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    68
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    69
	// add the new box
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    70
	var id = obj.parentNode.getAttribute('snapr:imgid');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    71
	if ( !id )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    72
		return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    73
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    74
	// destroy form, etc.
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    75
	var parent = obj.parentNode;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    76
	parent.removeChild(parent.canvas_box_obj);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    77
	parent.removeChild(obj);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    78
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    79
	var canvas_json = toJSONString(canvas_data);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    80
	ajaxPost(makeUrlNS('Gallery', id), 'ajax=true&act=add_tag&tag=' + ajaxEscape(tag) + '&canvas_params=' + ajaxEscape(canvas_json), snapr_process_ajax_tag_packet);
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    81
}
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    82
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    83
function snapr_finalize_canvas_cancel(obj)
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    84
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    85
	var parent = obj.parentNode;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    86
	parent.removeChild(parent.canvas_box_obj);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    87
	parent.removeChild(obj);
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    88
}
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
    89
24
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
    90
function snapr_finalize_canvas_edit_cancel(obj)
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
    91
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    92
	var old_value = obj.getElementsByTagName('textarea')[0];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    93
	old_value = old_value.OriginalValue;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    94
	var canvas = obj.parentNode;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    95
	var canvas_data = canvas.canvas;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    96
	var note_id = canvas.tag_id;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    97
	var auth_delete = canvas.auth_delete;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    98
	var parent = canvas.parentNode;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
    99
	canvas.removeChild(obj);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   100
	parent.removeChild(canvas);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   101
	// redraw the note
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   102
	snapr_draw_note(parent, old_value, canvas_data, note_id, false, auth_delete);
24
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   103
}
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   104
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   105
function snapr_finalize_canvas_edit_delete(obj)
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   106
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   107
	var old_value = obj.getElementsByTagName('textarea')[0];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   108
	old_value = old_value.OriginalValue;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   109
	var canvas = obj.parentNode;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   110
	var canvas_data = canvas.canvas;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   111
	var note_id = canvas.tag_id;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   112
	var auth_delete = canvas.auth_delete;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   113
	var parent = canvas.parentNode;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   114
	canvas.removeChild(obj);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   115
	parent.removeChild(canvas);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   116
	// redraw the note
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   117
	var note = snapr_draw_note(parent, old_value, canvas_data, note_id, false, auth_delete);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   118
	// now nuke it
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   119
	snapr_nuke_tag(note);
24
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   120
}
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   121
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   122
function snapr_draw_note(obj, tag, canvas_data, note_id, initial_hide, auth_delete)
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   123
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   124
	var newbox = canvas_create_box(obj, canvas_data.left, canvas_data.top, canvas_data.width, canvas_data.height);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   125
	newbox.tag_id = note_id;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   126
	newbox.canvas = canvas_data;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   127
	newbox.auth_delete = auth_delete;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   128
	obj.onmouseover = function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   129
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   130
		var boxen = this.getElementsByTagName('div');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   131
		for ( var i = 0; i < boxen.length; i++ )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   132
			if ( boxen[i].className == 'canvasbox' )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   133
				boxen[i].style.display = 'block';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   134
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   135
	obj.onmouseout = function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   136
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   137
		var boxen = this.getElementsByTagName('div');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   138
		for ( var i = 0; i < boxen.length; i++ )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   139
			if ( boxen[i].className == 'canvasbox' )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   140
				boxen[i].style.display = 'none';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   141
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   142
	newbox.onmouseover = function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   143
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   144
		this.style.borderColor = '#FFFF00';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   145
		this.firstChild.style.borderColor = '#000000';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   146
		snapr_display_note(this.noteObj);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   147
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   148
	newbox.onmouseout = function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   149
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   150
		this.style.borderColor = '#000000';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   151
		this.firstChild.style.borderColor = '#FFFFFF';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   152
		snapr_hide_note(this.noteObj);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   153
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   154
	if ( auth_delete )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   155
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   156
		/*
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   157
		var p = document.createElement('p');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   158
		p.style.cssFloat = 'right';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   159
		p.style.styleFloat = 'right';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   160
		p.style.fontWeight = 'bold';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   161
		p.style.margin = '5px';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   162
		var a_del = document.createElement('a');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   163
		a_del.style.color = '#FF0000';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   164
		a_del.href = '#';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   165
		a_del.onclick = function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   166
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   167
			snapr_nuke_tag(this.parentNode.parentNode.parentNode);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   168
			return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   169
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   170
		a_del.appendChild(document.createTextNode('[X]'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   171
		p.appendChild(a_del);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   172
		newbox.firstChild.appendChild(p);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   173
		*/
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   174
		newbox.style.cursor = 'pointer';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   175
		newbox.onclick = function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   176
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   177
			snapr_run_tag_editor(this);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   178
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   179
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   180
	var abs_x = $dynano(newbox).Left();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   181
	var abs_y = $dynano(newbox).Top() + $dynano(newbox).Height() + 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   182
	var noteObj = document.createElement('div');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   183
	newbox.noteObj = noteObj;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   184
	noteObj.className = 'snapr_tag';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   185
	noteObj.style.display = 'none';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   186
	noteObj.style.position = 'absolute';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   187
	noteObj.style.top = abs_y + 'px';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   188
	noteObj.style.left = abs_x + 'px';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   189
	noteObj.style.zIndex = '100';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   190
	var re = new RegExp(unescape('%0A'), 'g');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   191
	noteObj.innerHTML = tag.replace(re, "<br />\n");
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   192
	obj.appendChild(noteObj);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   193
	if ( initial_hide )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   194
		newbox.style.display = 'none';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   195
	return newbox;
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   196
}
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   197
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   198
function snapr_display_note(note)
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   199
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   200
	//domObjChangeOpac(0, note);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   201
	note.style.display = 'block';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   202
	//domOpacity(note, 0, 100, 500);
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   203
}
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   204
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   205
function snapr_hide_note(note)
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   206
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   207
	//domOpacity(note, 100, 0, 500);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   208
	//setTimeout(function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   209
	//  {
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   210
			note.style.display = 'none';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   211
	//  }, 600);
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   212
}
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   213
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   214
function snapr_nuke_tag(obj)
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   215
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   216
	// add the new box
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   217
	var parent_obj = document.getElementById('snapr_preview_img').parentNode;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   218
	var id = parent_obj.getAttribute('snapr:imgid');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   219
	if ( !id )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   220
		return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   221
	ajaxPost(makeUrlNS('Gallery', id), 'ajax=true&act=del_tag&tag_id=' + obj.tag_id, snapr_process_ajax_tag_packet);
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   222
}
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   223
24
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   224
function snapr_run_tag_editor(obj)
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   225
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   226
	obj.onclick = null;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   227
	var abs_x = $dynano(obj).Left();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   228
	var abs_y = $dynano(obj).Top();
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   229
	var height = $dynano(obj).Height() + 2;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   230
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   231
	var value = obj.nextSibling.innerHTML;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   232
	var regex = new RegExp('<br>', 'g');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   233
	value = value.replace(regex, '');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   234
	obj.parentNode.removeChild(obj.nextSibling);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   235
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   236
	var entry_div = document.createElement('div');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   237
	entry_div.className = 'snapr_tag_entry';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   238
	entry_div.style.position = 'absolute';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   239
	entry_div.style.top = String(height) + 'px';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   240
	entry_div.style.left = '0px';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   241
	entry_div.style.zIndex = '100';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   242
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   243
	entry_div.appendChild(document.createTextNode('Enter a tag:'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   244
	entry_div.appendChild(document.createElement('br'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   245
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   246
	var ta = document.createElement('textarea');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   247
	ta.rows = '7';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   248
	ta.cols = '30';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   249
	ta.value = value;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   250
	ta.style.backgroundColor = '#FFFFFF';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   251
	ta.style.borderWidth = '0';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   252
	ta.style.color = '#000000';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   253
	ta.OriginalValue = value;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   254
	entry_div.appendChild(ta);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   255
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   256
	entry_div.appendChild(document.createElement('br'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   257
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   258
	var a_add = document.createElement('a');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   259
	a_add.href = '#';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   260
	a_add.onclick = function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   261
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   262
		snapr_finalize_canvas_edit(this.parentNode.parentNode, this.parentNode.getElementsByTagName('textarea')[0]['value'], this.parentNode);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   263
		return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   264
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   265
	a_add.appendChild(document.createTextNode('Save tag'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   266
	entry_div.appendChild(a_add);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   267
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   268
	entry_div.appendChild(document.createTextNode(' | '));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   269
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   270
	var a_cancel = document.createElement('a');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   271
	a_cancel.href = '#';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   272
	a_cancel.onclick = function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   273
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   274
		snapr_finalize_canvas_edit_cancel(this.parentNode);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   275
		return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   276
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   277
	a_cancel.appendChild(document.createTextNode('Cancel'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   278
	entry_div.appendChild(a_cancel);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   279
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   280
	entry_div.appendChild(document.createTextNode(' | '));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   281
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   282
	var a_del = document.createElement('a');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   283
	a_del.href = '#';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   284
	a_del.onclick = function()
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   285
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   286
		snapr_finalize_canvas_edit_delete(this.parentNode);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   287
		return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   288
	}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   289
	a_del.style.color = '#FF0000';
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   290
	a_del.appendChild(document.createTextNode('Delete'));
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   291
	entry_div.appendChild(a_del);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   292
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   293
	obj.appendChild(entry_div);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   294
	ta.focus();
24
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   295
}
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   296
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   297
function snapr_finalize_canvas_edit(canvas, value, editor)
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   298
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   299
	var canvas_data = canvas.canvas;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   300
	var note_id = canvas.tag_id;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   301
	var parent = canvas.parentNode;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   302
	canvas.removeChild(editor);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   303
	parent.removeChild(canvas);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   304
	// send the edit across the 'net
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   305
	var parent_obj = document.getElementById('snapr_preview_img').parentNode;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   306
	var id = parent_obj.getAttribute('snapr:imgid');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   307
	if ( !id )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   308
		return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   309
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   310
	var canvas_json = toJSONString(canvas_data);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   311
	ajaxPost(makeUrlNS('Gallery', id), 'ajax=true&act=edit_tag&tag=' + ajaxEscape(value) + '&canvas_params=' + ajaxEscape(canvas_json) + '&tag_id=' + note_id, snapr_process_ajax_tag_packet);
24
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   312
}
7f3bd3030ae9 Changed deletion method and added editing functionality for tags
Dan
parents: 18
diff changeset
   313
35
1dd30d7bf29f Fixed some javascript bugs in Enano 1.1.6
Dan
parents: 25
diff changeset
   314
function snapr_process_ajax_tag_packet(ajax)
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   315
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   316
	if ( ajax.readyState == 4 && ajax.status == 200 )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   317
	{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   318
		var response = String(ajax.responseText + '');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   319
		if ( response.substr(0, 1) != '[' && response.substr(0, 1) != '{' )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   320
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   321
			new messagebox(MB_OK|MB_ICONSTOP, 'JSON response invalid', 'Received unexpected response:<pre>' + response + '</pre>');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   322
			return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   323
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   324
		response = parseJSON(response);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   325
		if ( response.mode )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   326
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   327
			if ( response.mode == 'error' )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   328
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   329
				alert(response.error);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   330
				return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   331
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   332
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   333
		var parent_obj = document.getElementById('snapr_preview_img').parentNode;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   334
		for ( var i = 0; i < response.length; i++ )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   335
		{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   336
			var packet = response[i];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   337
			switch(packet.mode)
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   338
			{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   339
				case 'add':
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   340
					snapr_draw_note(parent_obj, packet.tag, packet.canvas_data, packet.note_id, packet.initial_hide, packet.auth_delete);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   341
					break;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   342
				case 'remove':
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   343
					// Server requested to remove a tag
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   344
					var divs = parent_obj.getElementsByTagName('div');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   345
					for ( var i = 0; i < divs.length; i++ )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   346
					{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   347
						var box = divs[i];
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   348
						if ( box.className == 'canvasbox' )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   349
						{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   350
							if ( box.tag_id == packet.note_id )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   351
							{
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   352
								// You. We have orders to shoot. Stand in front of wall.
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   353
								var sibling = box.nextSibling;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   354
								var parent = box.parentNode;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   355
								// BLAM.
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   356
								parent.removeChild(sibling);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   357
								parent.removeChild(box);
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   358
								break;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   359
							}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   360
						}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   361
					}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   362
					break;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   363
			}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   364
		}
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   365
	}
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   366
}
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   367
25
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 24
diff changeset
   368
// Don't fire the tag init until JS init *and* image are finished.
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 24
diff changeset
   369
// Thanks to pmccullough for pointing out this race condition.
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 24
diff changeset
   370
var snapr_lock_onload_js = true;
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 24
diff changeset
   371
var snapr_lock_onload_img = true;
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 24
diff changeset
   372
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 24
diff changeset
   373
var snapr_tags_onload_real = function()
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   374
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   375
	// make sure we aren't waiting...
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   376
	if ( snapr_lock_onload_img || snapr_lock_onload_js )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   377
		return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   378
	
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   379
	// add the new box
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   380
	var parent_obj = document.getElementById('snapr_preview_img').parentNode;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   381
	var id = parent_obj.getAttribute('snapr:imgid');
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   382
	if ( !id )
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   383
		return false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   384
	ajaxPost(makeUrlNS('Gallery', id), 'ajax=true&act=get_tags', snapr_process_ajax_tag_packet);
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   385
}
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   386
25
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 24
diff changeset
   387
var snapr_tags_onload = function()
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 24
diff changeset
   388
{
42
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   389
	snapr_lock_onload_js = false;
7c6e2e97aa08 Added AJAX file upload support.
Dan Fuhry <dan@enanocms.org>
parents: 35
diff changeset
   390
	snapr_tags_onload_real();
25
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 24
diff changeset
   391
}
d9f37d2ea2cf Fixed race condition on canvas init (caused boxes to appear off by ~320px); fixed JSON response of null when row[img_tags] is NULL
Dan
parents: 24
diff changeset
   392
18
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   393
addOnloadHook(snapr_tags_onload);
c1c398349651 Added initial support for notes (aka tags) on images, done completely (including initial load of metadata) with AJAX. They're not fixed at 100x100 like on Facebook either.
Dan
parents:
diff changeset
   394