Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic Content on first show, not page load
17th March, 00:09 (This post was last modified: 17th March 00:11 by hcosta.)
Post: #1
Dynamic Content on first show, not page load
I noticed that when I created a qTip with a content URL, that the AJAX call happened immediately. Not good for what I had in mind (user info tooltips on a forum, so it made lots of AJAX calls right as the page loaded), but I found a way (based on a suggestion from Craig) to make it only happen when the tooltip is actually shown the first time.

Put the URL you wish to load (or some piece of information you will use to generate the URL) in the ALT attribute of the link that will create the tooltip. I tried using a custom attribute, but IE7 choked on it, so I used ALT since it won't affect the behavior of an anchor tag; however, you could use a different attribute (like title).

Use this in the options when you call .qtip()

JS Code
content: {
   text: 'Loading...'
},
api: {
   beforeShow: function() {
      var url = this.elements.target.attr('alt');
      if (url != '') {
         this.loadContent(url);
      }
   },
   onContentLoad: function() {
      this.elements.target.attr('alt', '');
   }
}

Later,
TheOverbob
http://www.randomdeveloper.com
Visit this user's website Find all posts by this user
Quote this message in a reply
22nd July, 09:07
Post: #2
RE: Dynamic Content on first show, not page load
Hi this is mostly exact what i want, except i need to load an image async.

Do you have an idea how to realise this?

I have a page with many small images and want to show a tooltip with a larger images in it. but the "big images" should not be loaded with the page. they should load when the tooltip is shown.

can you help me? i'm not very familiar with javascript and ajax
Find all posts by this user
Quote this message in a reply
22nd July, 12:37
Post: #3
RE: Dynamic Content on first show, not page load
Try this:

JS Code
$('img.little').each(function() {
   var src = $(this).attr('src').replace('_little', '_big');
 
   $(this).qtip({
      content: '<img src="' + src + '" alt="" />'
   });

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
28th July, 07:45 (This post was last modified: 28th July 07:46 by GFEMajor.)
Post: #4
RE: Dynamic Content on first show, not page load
(22nd July 12:37)Craig Wrote:  Try this:

JS Code
$('img.little').each(function() {
   var src = $(this).attr('src').replace('_little', '_big');
 
   $(this).qtip({
      content: '<img src="' + src + '" alt="" />'
   });

Your code works perferkly, but is there a way to show a "loading" text while the image is loaded? So the user sees that the images is beeing loaded, like in the first example.
Find all posts by this user
Quote this message in a reply
28th July, 16:34
Post: #5
RE: Dynamic Content on first show, not page load
Give it's ALT attribute something... apart from that you'll need to hide the image and display something above it, but it's not a native feature unfortunately! qTip2 supports it though, so try there.

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 August, 10:35
Post: #6
RE: Dynamic Content on first show, not page load
Sorry, but i can't find such a feature in qTip2. Can you point it to me?
Find all posts by this user
Quote this message in a reply
2nd August, 13:01
Post: #7
RE: Dynamic Content on first show, not page load
Sorry I was half asleep when I wrote that response, what I meant by native feature was todo with Loading messages whilst AJAX content loads, but not I re-read you just want to load an image heh.

You could try something like so:
JS Code
$('.selector').qtip({
	content: 'Loading image...',
	events: {
		render: function(event, api) {
			// Might want to check this works cross browser, as some might not fire the 'load' callback under certain circumstances
			$('<img />', { src: 'blah.png' }).bind('load', function() {
				$(this).appendTo( api.elements.content.html('') );
			});
		}
	}
});

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
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Dynamic content from page variables kenswdev 0 418 9th February 18:06
Last Post: kenswdev
  [Solved] Displaying tooltip on page load/mouseover otherwise burghars 1 1,357 18th July 11:55
Last Post: Craig
  [Solved] modal with URL from another page? dod 2 1,502 2nd May 19:07
Last Post: Craig
  show fixed on the first time cyberziz 2 1,258 11th March 08:29
Last Post: cyberziz
  Load an HTML Page Within qTip Tooltip BruceBruce 3 3,336 19th January 12:17
Last Post: Craig
  [Solved] qTp modal dialog , on page load c0mrade 5 3,987 13th August 16:13
Last Post: mattsyk
  Tutorial: Dynamic content on first load using ajax Abrasive 0 4,825 28th June 05:44
Last Post: Abrasive
  how to load different content each time andufo 1 1,844 28th May 16:00
Last Post: andufo
  Callbacks fire on page load when they shouldn't anomalous 1 1,275 4th February 22:12
Last Post: anomalous
  How to show the tooltip programmatically? overthetop 2 2,215 30th November 10:29
Last Post: overthetop



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