From eea912192ec9661fe82639db9442586954f6932e Mon Sep 17 00:00:00 2001
From: Adrian Lang <lang@cosmocode.de>
Date: Fri, 19 Aug 2011 12:10:36 +0200
Subject: [PATCH] Fix popup DOM element sharing, simplify event handling

---
 lib/scripts/page.js | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/lib/scripts/page.js b/lib/scripts/page.js
index 189c1f148..f5d84e239 100644
--- a/lib/scripts/page.js
+++ b/lib/scripts/page.js
@@ -50,36 +50,24 @@ dw_page = {
      */
     insituPopup: function(target, popup_id) {
         // get or create the popup div
-        var $fndiv = jQuery('#popup_id');
+        var $fndiv = jQuery('#' + popup_id);
 
         // popup doesn't exist, yet -> create it
-        if(!$fndiv.length){
+        if($fndiv.length === 0){
             $fndiv = jQuery(document.createElement('div'))
                 .attr('id', popup_id)
                 .addClass('insitu-footnote JSpopup')
-                .mouseout(function(e){
-                    // autoclose on mouseout - ignoring bubbled up events
-                    //FIXME can this made simpler in jQuery?
-                    var p = e.relatedTarget || e.toElement;
-                    while (p && p !== this) {
-                        p = p.parentNode;
-                    }
-                    if (p === this) {
-                        return;
-                    }
-                    jQuery(this).hide();
-                });
-
+                .mouseleave(function () {jQuery(this).hide();});
             jQuery('div.dokuwiki:first').append($fndiv);
         }
 
-        $fndiv.position({
+        // position() does not support hidden elements
+        $fndiv.show().position({
             my: 'left top',
             at: 'left center',
             of: target
-        });
+        }).hide();
 
-        $fndiv.hide();
         return $fndiv;
     },
 
@@ -90,7 +78,7 @@ dw_page = {
      * @author Chris Smith <chris@jalakai.co.uk>
      */
     footnoteDisplay: function(e){
-        var $fndiv = dw_page.insituPopup(e.target, 'insitu__fn');
+        var $fndiv = dw_page.insituPopup(this, 'insitu__fn');
 
         // locate the footnote anchor element
         var $a = jQuery("#fn__" + e.target.id.substr(5));
-- 
GitLab