Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
hide on background click
24th March, 20:26
Post: #1
hide on background click
I'm bringing up a qtip:

JS Code
$(selector).qtip({ 
            content: {
                  text:"some content"
                  ,title: {
                     text: "<strong>some title</strong>"
                     ,button: "[X]"
                  }
            }
            ,show: { solo: true,when: { event: 'click' } }
            ,hide: { 
               <span style="font-weight: bold;">when: {   event: 'click' }</span>
               ,effect: { type: 'fade' }
            }
            ,position: {
                 corner: {
                     target: 'topRight',
                     tooltip: 'topLeft'
                }
            }
            ,style:{border: { radius: 5 },
                   name: 'dark'}
         });


I would like the qtip to disappear by either
  • a) click the close button (which works now),
  • b) clicking the element that spawned it (which works intermittently)
  • or c) clicking anywhere else on the page (which doesn't work)


Can anyone help me acheive this? Is something wrong in my declaration?
Find all posts by this user
Quote this message in a reply
25th March, 01:59
Post: #2
hide on background click
Hi rseshadr,

I'm actually using that exact setup for my documentation page examples. Here's the the code that will do it for you (Although probably not the best way to do):

JS Code
$('selector').qtip({
   hide: {
      when: {
         target: $(document.body).children().not( $(self) ),
         event: 'mousedown'
      }
   },
   show: {
      solo: true,
      event: 'click'
   }
});

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
25th March, 21:55
Post: #3
hide on background click
craig Wrote:Hi rseshadr,

I'm actually using that exact setup for my documentation page examples. Here's the the code that will do it for you (Although probably not the best way to do):

JS Code
$('selector').qtip({
   hide: {
      when: {
         target: $(document.body).children().not( $(self) ),
         event: 'mousedown'
      }
   },
   show: {
      solo: true,
      event: 'click'
   }
});

Craig, thanks for the quick reply, this works but not quite fully...
  • Clicking on the spawning element causes the tip not to toggle (disappear), but toggles twice (it reappears)Another issue is that my content is in an iFrame, and unfortunately clicks outside the frame also aren't captured


As it stands I think I'm going to leave my tip functionality as-is, but I will request a feature to be able to configure a tooltip to toggle on click of it's target element.
Find all posts by this user
Quote this message in a reply
25th March, 22:16
Post: #4
hide on background click
reshadr,

Looking over your code I noticed you've got both hide and show set to a click event, which at the moment isn't supported very well. This is probably the reason you're experiencing the toggling twice etc. Try changing one to mouseup/down and try different combinations, that should fix it for now until beta4 is released.

In regards to the iframe, clicks outside the frame? You mean when you click anywhere else on the document it doesn't hide?

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
26th March, 13:26
Post: #5
hide on background click
I am having a related problem and I thought I would add to this thread rather than creating my own.

I too want a tip that disappears when the user clicks anywhere outside of the tooltip. But in my case, my application makes extensive use of AJAX to load new content onto the page as the user interacts with the site. This leads to two problems with the "hide.when.target=$(document.body).children().not($(self))" solution:

(1) That solution registers an event handler on lots of DOM elements for closing each tooltip as it gets opened. If the user opens a bunch of tooltips the number of event handlers in the event handler chains will grow. Since in my application the user stays on the same page for a longer period of time (as new content is dynamically added and moved) I fear that the number of event handlers will grow to the point where performance becomes a problem. However, I have not actually observed this problem -- perhaps I am worrying unnecessarily.

(2) The existing infrastructure registers the event handlers at the time that the tooltip is created. Any page elements which get added afterward will NOT have event handlers, and clicking on these will not close the tooltip. This problem is actually preventing my application from working.

Ideally, I would want a single event handler for mousedowns anywhere which closed any open tooltips which did not contain the click. I would also be perfectly happy with using "hide.when.target=$(document.body).children().not($(self))" if I could get the code to run and the event handlers to be registered EVERY time the tooltip is displayed and removed when it is hidden (instead of being registered the FIRST time the tooltip is displayed). But I would strongly prefer not to modify or monkeypatch qTip (after all, I'd like to receive updates in the future!).

Any suggestions?
Visit this user's website Find all posts by this user
Quote this message in a reply
27th March, 06:02
Post: #6
hide on background click
mcherm, craig,
Wouldn't that event-bubbling request from a different thread resolve this issue?
Find all posts by this user
Quote this message in a reply
27th March, 07:26
Post: #7
hide on background click
Quite right rseshadr, and I was ahead of you on this one! Wink

I just implemented an 'unfocus' hide event type in beta4, which will allow you to hide tooltips when elements other than the tooltip and target element are clicked, without the need to bind excessive DOM handlers. This is a step towards the event delegation I want to implement library wide in 1.1.

Releasing beta4 on the 28th guys so be patient! Just polishing off the demos and documentation section updates and then it will be all yours!

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
27th March, 12:47
Post: #8
hide on background click
That's fabulous! Thank you Craig.
Visit this user's website Find all posts by this user
Quote this message in a reply
31st March, 01:03
Post: #9
hide on background click
Hi Craig,

That's really great! I was about to implement that to my code when I found this post. Are you releasing beta4 on the next few days?

Thanks,

-Alessandro
Find all posts by this user
Quote this message in a reply
7th April, 16:49
Post: #10
hide on background click
Update to this thread regarding the beta 4:

This code now breaks in beta4:
JS Code
hide: { when: { target: $(document.body).children().not( $(self) ), event: 'mousedown' } },


It will hide when clicking anywhere outside the tip, but it will NOT hide when you reclick the item that brings up the tip. Instead the tip hides and reshows. In beta3 it would hide when clicking the item that calls the tip.

Suggestions Craig?
Find all posts by this user
Quote this message in a reply
7th April, 16:53
Post: #11
hide on background click
Hi xpand2,

This is now a native event in Beta4, which hides the tooltip when it loses focus e.g. anywhere except the tooltip is clicked:
JS Code
hide: 'unfocus'

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
7th April, 17:46
Post: #12
hide on background click
Beautiful! I love it! Thanks for the great work Craig
Find all posts by this user
Quote this message in a reply
30th April, 19:32
Post: #13
hide on background click
Newb Question:

Where the heck do you put those lines of code for the hide effect to work?

I have this in the head tag of my page, and it doesn't work.

JS Code
<script>
 
        $(document).ready(function() {
            $("#findGroup").simpletip({ 
                persistent: true, 
                content:  '<asp:Image ID="cardExample" ImageUrl="images/card_examples.jpg" runat="server" o<strong></strong>nclick="close();"/>',
                position: 'right',
                hide: 'unfocus'
                });
         });
</script>


What I really want to do is that when someone clicks the image that is my content the qtip closes. I tried to use the images onclick event to call a javascript funtion that then uses API calls to close it. But the onclick event never gets fired or doesn't call my function. Any ideas?

Thanks in advance.
Find all posts by this user
Quote this message in a reply
1st May, 12:48
Post: #14
hide on background click
Hi huangjd,

Think you're a little confused as to what project this forum is geared towards. You're using Simpletip, the old library which I no longer actively develop for. The above code is for qtip only. Try updating to qTip first here: http://craigsworks.com/projects/qtip/download/

The equivalent code for the qTip project is this:
JS Code
<script>
$(document).ready(function() {
   $("#findGroup").qtip({ 
       content:  '<asp:Image ID="cardExample" ImageUrl="images/card_examples.jpg" runat="server" o<strong></strong>nclick="close();"/>',
       show: 'click',
       hide: 'unfocus',
       position: {
          corner: {
             tooltip: 'leftMiddle',
             target: 'rightMiddle'
          }
       }
    });
});
</script>

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
1st May, 18:49
Post: #15
hide on background click
Haha, that's funny. I accidentally downloaded simpletip and didn't even realize it.

One little problem, the unfocus is not what I want. How do I close the tooltip when the foreground ( the tooltip itself, or in my case the image) is clicked on. I've tried a number of things but can't seem to get it to work.
Find all posts by this user
Quote this message in a reply
1st May, 20:05
Post: #16
hide on background click
Specify you're show target as your image:
JS Code
$('#findGroup').each(function()
{
   $(this).qtip({ 
       content:  '<asp:Image ID="cardExample" ImageUrl="images/card_examples.jpg" runat="server" o<strong></strong>nclick="close();"/>',
       show: {
          when: {
             event: 'click',
             target: $(this).children('img')
          }
       },
       hide: 'unfocus',
       position: {
          corner: {
             tooltip: 'leftMiddle',
             target: 'rightMiddle'
          }
       }
    });
});

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
2nd May, 14:21
Post: #17
hide on background click
Don't you mean, the hide target should be the image? I had tried that already and can't get it to work. And your example doesn't do the trick either.

Also, why did you change the outer function from:
$(document).ready(function() {

to:
$('#findGroup').each(function()


To me it looks like it's doing the same thing just a different way. Is that correct?
Find all posts by this user
Quote this message in a reply
2nd May, 23:12
Post: #18
hide on background click
Yeah that's what I meant, but the outer function isn't changed , I just forgot to include the document.ready part. The .each function allows you to access each elements properties via the this statement, so its needed for the fix to work.

JS Code
$(document).ready(function(){
$('#findGroup').each(function()
{
   $(this).qtip({ 
       content:  '<asp:Image ID="cardExample" ImageUrl="images/card_examples.jpg" runat="server" o<strong></strong>nclick="close();"/>',
       show: {
          when: {
             event: 'click',
             target: $(this).children('img')
          }
       },
       hide: 'unfocus',
       position: {
          corner: {
             tooltip: 'leftMiddle',
             target: 'rightMiddle'
          }
       }
    });
});
});

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
3rd May, 15:29
Post: #19
hide on background click
Couldn't you just make the hide target the qtip itself?

JS Code
hide: {
          when: {
             event: 'click',
             target: $(this)
          }
       }


Also, the code provided still doesn't work. Is it because the image is being wrapped in numerous divs?

JS Code
<div class="qtip qtip-defaults qtip-active" style="-moz-border-radius-topleft: 0pt; -moz-border-radius-topright: 0pt; -moz-border-radius-bottomright: 0pt; -moz-border-radius-bottomleft: 0pt; position: absolute; width: 250px; display: block; top: 467.5px; left: 402px; z-index: 6000;" qtip="0">
<div class="qtip-wrapper" style="overflow: hidden; position: relative; text-align: left;">
<div class="qtip-contentWrapper" style="border: 1px solid rgb(211, 211, 211); background: white none repeat scroll 0% 0%; overflow: hidden; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div class="qtip-content qtip-content" style="padding: 5px 9px; background: white none repeat scroll 0% 0%; overflow: hidden; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; color: rgb(17, 17, 17); text-align: left;">
<img id="cardExample" style="border-width: 0px;" src="images/card_examples.jpg"/>
</div>
</div>
</div>
</div>
Find all posts by this user
Quote this message in a reply
5th May, 17:50
Post: #20
hide on background click
Hi huangjd,

Sorry it took so lnog to get back to you, been very busy these past couple of days! Here's the code which should work for you.

JS Code
$(document).ready(function(){
   $('#findGroup').each(function()
   {
      $(this).qtip({ 
         content:  '<asp:Image ID="cardExample" ImageUrl="images/card_examples.jpg" runat="server" o<strong></strong>nclick="close();"/>',
         position: {
            corner: {
               tooltip: 'leftMiddle',
               target: 'rightMiddle'
            }
         },
         show: 'click',
         hide: 'click',
         api: {
            onRender: function()
            {
               var self = this;
 
               // Assign the hide method to a click event on the content
               self.elements.content.bind('click' self.hide);
            }
         }
      });
   });
});

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
15th November, 19:04
Post: #21
RE: hide on background click
Hi Craig,

I am using hide: 'unfocus' to close the qTip by clicking outside of it and this works fine. But not on an iPad.

Your help is very appreciated.

Thanks.
Thilo
Find all posts by this user
Quote this message in a reply
16th November, 19:46
Post: #22
RE: hide on background click
Unfortunately iPads are a bit tricky to develop for as... well I don't have one Wink Do click events fire normally on an iPad?

Craig Thompson
Web Developer / Designer
Craigsworks
http://www.craigsworks.com
Visit this user's website Find all posts by this user
Quote this message in a reply
24th November, 11:08
Post: #23
RE: hide on background click
click events fire just fine.

In fact I do have the same issue on iTouch and iPhone. You might have one of those ;-)

So it is only possible to close the qTip by clicking on my closing icon which is quite small. and when I zoom to click it the qTip centres itself again and moves out of view.
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  hide on unfocus in build 55 bradw2k 1 95 20th January 17:03
Last Post: Craig
  Changing HTML Content on Click & Remove/Reinit qTips ifthatdoesntdoit 5 862 17th November 09:46
Last Post: ifthatdoesntdoit
  [Solved] can't get background to work drm 2 349 21st October 20:33
Last Post: drm
  [Solved] Is there an easier way to show/hide tooltips dynamically? gloosemo 1 399 17th October 15:58
Last Post: Craig
  [Solved] Incorrect behavior on first click? fred_tededmondsson 16 1,043 20th September 17:49
Last Post: fred_tededmondsson
  [Solved] Hide tooltip when clicked dabd 10 806 23rd August 18:55
Last Post: dabd
  onLoad and then hide after 10 seconds mediaslave 3 1,774 16th June 17:02
Last Post: weber
  Can't not open any links after click a qTip popup thienthans 3 841 22nd April 20:12
Last Post: Craig
  [Solved] Have an onClick show qtip but then allow the underlying click to fire rickcr 2 2,659 26th January 22:42
Last Post: Gaurav
  Show/Hide according to dynamic content ? Lyreco 5 1,096 19th January 12:19
Last Post: Craig



User(s) browsing this thread: 1 Guest(s)