enyo / opentip

Opentip is an open source javascript tooltip based on the protoype framework.
http://www.opentip.org
1.25k stars 401 forks source link

No way to remove permanently opentips #74

Open l0co opened 10 years ago

l0co commented 10 years ago

My usecase is to use opentips in fully ajaxed application (only one page refresh at start, then ajax - no reloads). But I don't want tips, but rather the help layer triggered by the help button that shows tips aligned to elements on demand. For such usage I need to instantiate all opentips on request, and remove them on help close action. For this I would need the opentips completely killed when I close all this stuff (clear dom elements, remove listeners, remove them from buffers). I believe here is a working patch doing this for 2.4.6:

Index: opentip-native.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- opentip-native.js   (revision 543)
+++ opentip-native.js   (revision )
@@ -596,10 +596,17 @@
         _this.setCss3Style(_this.container, {
           transitionDuration: "0s"
         });
-        if (_this.options.removeElementsOnHide) {
+        if (_this.options.removeElementsOnHide || _this.options.removePermanentlyOnHide) {
           _this.debug("Removing HTML elements.");
           _this.adapter.remove(_this.container);
           delete _this.container;
+          if (_this.options.removePermanentlyOnHide) {
+            for (var i=0; i<Opentip.tips.length; i++)
+                if (Opentip.tips[i].id==_this.id) {
+                    Opentip.tips.splice(i, 1);
+                    break;
+                }
+          }
           return delete _this.tooltipElement;
         }
       }, hideDelay);
@@ -1552,6 +1559,7 @@
     hideTriggers: [],
     hideOn: null,
     removeElementsOnHide: false,
+    removePermanentlyOnHide: false,
     offset: [0, 0],
     containInViewport: true,
     autoOffset: true,
\ No newline at end of file
jaunetajabe commented 10 years ago

Hi, have you found how to delete all tooltip content from DOM? thanks

l0co commented 10 years ago

I no longer remember this case well, but doesn't this patch do it exactly?

RyanBrainerd commented 8 years ago

I am using the latest version and even with removeElementsOnHide: true, my dynamic layout would keep adding tooltips on top of each other after each of my renders. I tried to delete the data from each element, I tried to delete the Opentips.tip array, and it woudln't get rid of the duplicate opentips. I don't know where they are being stored, but this finally allowed me to programatically clear them all out so I only had one set of opentips on every render update in my app:

// clear all old opentips while (Opentip.tips.length > 0) { Opentip.tips.shift().deactivate(); }

...

// when iterating over DOM elements, clear data bound to each individual element $(this).data('opentips', []);

It would be really convenient to provide a method to do this automatically?