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