plugins/gallery/tagging.js
changeset 25 d9f37d2ea2cf
parent 24 7f3bd3030ae9
child 35 1dd30d7bf29f
--- a/plugins/gallery/tagging.js	Sun Feb 17 15:21:47 2008 -0500
+++ b/plugins/gallery/tagging.js	Sat Feb 23 16:02:15 2008 -0500
@@ -361,8 +361,17 @@
   }
 }
 
-var snapr_tags_onload = function()
+// Don't fire the tag init until JS init *and* image are finished.
+// Thanks to pmccullough for pointing out this race condition.
+var snapr_lock_onload_js = true;
+var snapr_lock_onload_img = true;
+
+var snapr_tags_onload_real = function()
 {
+  // make sure we aren't waiting...
+  if ( snapr_lock_onload_img || snapr_lock_onload_js )
+    return false;
+  
   // add the new box
   var parent_obj = document.getElementById('snapr_preview_img').parentNode;
   var id = parent_obj.getAttribute('snapr:imgid');
@@ -371,5 +380,11 @@
   ajaxPost(makeUrlNS('Gallery', id), 'ajax=true&act=get_tags', snapr_process_ajax_tag_packet);
 }
 
+var snapr_tags_onload = function()
+{
+  snapr_lock_onload_js = false;
+  snapr_tags_onload_real();
+}
+
 addOnloadHook(snapr_tags_onload);