Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] Load tips from external file... how?
4th January, 20:00 (This post was last modified: 4th January 20:01 by sparky672.)
Post: #1
[Solved] Load tips from external file... how?
Why am I finding this so difficult? I cannot locate a working example and I can't seem to figure out how to piece this together from the online documentation.

This is something I'd expect to see as a secondary default setup but I must be blind.

My tooltips are going to be way too long to embed inside all the "title" attributes. So I was thinking I'd simply store these in an external file and call them up as needed. Despite my best efforts, no matter how I try to call this file, nothing happens.

Can somebody point me to a working example?

Thank-you!
Find all posts by this user
Quote this message in a reply
4th January, 21:15
Post: #2
RE: Load tips from external file... how?
Update:

I finally figured out how to load the content of an external HTML file but I have absolutely no idea how to parse it! With one working example or demo, it's probably a snap... however I can't seem to find the forest through the trees.
Find all posts by this user
Quote this message in a reply
5th January, 16:23
Post: #3
RE: Load tips from external file... how?
Hmm sparky, not sure if this is quite what you're looking for but why not include the tip contents under a standard div class directly next to all your elements that need a tooltip? Like so:

HTML Code
<div rel="tooltip">I ahve a tooltip</div>
<div class="tooltipContent">
	Content for tooltip here
</div>

JS Code
$('[rel=tooltip] + .tooltipContent').each(function() {
	$(this).qtip({
		content: $(this)
	})
});

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
5th January, 16:32 (This post was last modified: 5th January 16:34 by sparky672.)
Post: #4
RE: Load tips from external file... how?
(5th January 16:23)Craig Wrote:  Hey sparky, it's just a case of using the dataFilter function and/or success handler:

JS Code
$('.selector').qtip({
	content: {
		ajax: {
			url: 'page.php', // Your page url
			data: { id: 3 }, // Random data
			dataFilter: function(content, type) {
				return content.replace('fish', 'dog'); // Random parsing
			}
		}
	}
});

Thank-you for the reply but I'm still confused by the example. Huh

In my remote file, I have this...

JS Code
<div id="one">This is tip #1, bla, bla</div>
<div id="two">This is tip #2, bla, bla</div>
<div id="three">This is tip #3, bla, bla</div>
<div id="four">This is tip #4, bla, bla</div>



Then in the HTML of the page using qTips...

<ul>
<li><a href="#" title="one">My Link to Tip 1</a></li>
<li><a href="#" title="two">My Link to Tip 2</a></li>
<li><a href="#" title="three">My Link to Tip 3</a></li>
<li><a href="#" title="four">My Link to Tip 4</a></li>
</ul>

Now I'm totally lost. How does the "content.replace" work?... I cannot seem to understand how to apply that line in your example to my situation.

I'm sure I'll feel stupid after you explain it...

Thank-you for all your hard work on qTip!
Find all posts by this user
Quote this message in a reply
5th January, 16:49
Post: #5
RE: [Solved] Load tips from external file... how?
Oh I see. You could do something along the lines of this:

JS Code
$('.selector').each(function() {
	$(this).qtip({
		content: 'Loading...',
		events: {
			render: function(event, api) {
				// Grab our tooltip id from the target element
				var id = api.elements.target.attr('title');
 
				// Load $('#<id>') from the tooltips.html page and replace the tooltip content with it
				api.elements.content.load('tooltips.html #'+title); 
			}
		}
	}
});

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
5th January, 16:57
Post: #6
RE: [Solved] Load tips from external file... how?
Cool!! Big Grin

I'll let you know how it works...

Seriously though... this should be a permanent part of your tutorials or documentation... all I kept thinking yesterday is about how nice it would be to have all the lengthy tips removed from the title attributes and stuck in their own single file. Plus, then I could include more HTML with the tip text rather than trying to embed/escape all that junk in the title attribute.

Alternatively, I was also thinking of converting my main tip file into it's own page so the user can see the "glossary" all in one place or individually via the tip. And the webmaster only has to edit one file when updating tips.
Find all posts by this user
Quote this message in a reply
5th January, 19:26
Post: #7
RE: [Solved] Load tips from external file... how?
That's a pretty neat idea. You could even use the metadata plugin to apply different options for each tip directly on the elements themselves! I'll definitely look into making this a tutorial.

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
5th January, 19:40 (This post was last modified: 5th January 19:48 by sparky672.)
Post: #8
RE: [Solved] Load tips from external file... how?
Sorry. This is not working. Sad

It just displays the title in a browser tooltip, not in a qTip...

JS Code
$('.selector').each(function() {
   $(this).qtip({
      content: 'Loading...',
      events: {
         render: function(event, api) {
            // Grab our tooltip id from the target element
            var id = api.elements.target.attr('title');
 
            // Load $('#<id>') from the tooltips.html page and replace the tooltip content with it
            api.elements.content.load('/ws/includes/tips.html #'+title); 
         }
      },
	position: {
		at: "top right",
		my: "bottom left"
	},
	hide: {
		effect: true
	},
	show: {
		effect: true
	},
	style: {
		tip: true,
		classes: "ui-tooltip-custom ui-tooltip-shadow ui-tooltip-rounded",
		tip: {
         corner: true,
         offset: 35
       }
	}
  });
});



Alternatively, this just displays "Loading..." in a qTip...

JS Code
$(document).each(function(){
   $('ul.subindex li a[title]').qtip({
      content: 'Loading...',
      events: {
         render: function(event, api) {
            // Grab our tooltip id from the target element
            var id = api.elements.target.attr('title');
 
            // Load $('#<id>') from the tooltips.html page and replace the tooltip content with it
            api.elements.content.load('/ws/includes/tips.html #'+title); 
         }
      },
	position: {
		at: "top right",
		my: "bottom left"
	},
	hide: {
		effect: true
	},
	show: {
		effect: true
	},
	style: {
		tip: true,
		classes: "ui-tooltip-custom ui-tooltip-shadow ui-tooltip-rounded",
		tip: {
         corner: true,
         offset: 35
       }
	}
  });
});
Find all posts by this user
Quote this message in a reply
5th January, 19:55
Post: #9
RE: [Solved] Load tips from external file... how?
Works fine as far as I can see... take a look: http://jsfiddle.net/fDavN/74/

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
5th January, 20:04 (This post was last modified: 5th January 20:21 by sparky672.)
Post: #10
RE: [Solved] Load tips from external file... how?
(5th January 19:55)Craig Wrote:  Works fine as far as I can see... take a look: http://jsfiddle.net/fDavN/74/

Ah! I found your typo... Tongue

api.elements.content.load('/ws/includes/tips.html #'+title);

should have been...

api.elements.content.load('/ws/includes/tips.html #'+id);

YES!... it is working now!! After beating on my head for two days... it's working. This is awesome... everything remotely stored in an HTML file.... neato!

THANK-YOU!!
For the reader: here is my working code altered slightly for jsfiddle to simulate the external file...

http://jsfiddle.net/JN3BG/
Find all posts by this user
Quote this message in a reply
5th January, 20:32
Post: #11
RE: [Solved] Load tips from external file... how?
Ah yes, I'll edit it with the fix. Great to see its working sparky, definitely a great idea. One fallback I can see however is that every tip will need atleast one AJAX call... perhaps you could include the tooltips file within the page itself i na hidden div, or even perhaps a hidden iframe. That way you can avoid it.

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
5th January, 20:38
Post: #12
RE: [Solved] Load tips from external file... how?
(5th January 20:32)Craig Wrote:  .... One fallback I can see however is that every tip will need atleast one AJAX call...

What is/are the downside(s) to this?

(5th January 20:32)Craig Wrote:  ...perhaps you could include the tooltips file within the page itself i na hidden div, or even perhaps a hidden iframe. That way you can avoid it.

If I do that, then it won't be able to double as an external glossary or FAQ page.
Find all posts by this user
Quote this message in a reply
5th January, 23:41
Post: #13
RE: [Solved] Load tips from external file... how?
Well mostly just load on the server. But then it depends if you've optimized it specifically for this (which I doubt Tongue). Using it in an iframe can still give you the same functionality, and still allows you to use it as a glossary since the iframe's content is just the external page you were calling in the .load() method.

Here's an example of this using an iframe:

HTML Code
<iframe src="tooltips.html" style="position: absolute; left: -1000px; top: -1000px;"></iframe>

JS Code
$(document).each(function(){
	$('ul.subindex li a[title]').qtip({
		content: 'Loading...',
		events: {
			render: function(event, api) {
				// Grab our tooltip id from the target element
				var selector = '#' + api.elements.target.attr('title'),
					iframe = $('iframe'),
					content = $(selector, iframe.contents());
 
				// Update our tooltip content (repositions automatically)
				api.set('content.text', content);
			}
		}
	});
});


This is probably a better solution, since it results in less code. Just make sure you're iframe content is in the same domain and is hidden from view and you're set! Plus no nasty AJAX call for every qTip on the page!

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
5th January, 23:46
Post: #14
RE: [Solved] Load tips from external file... how?
(5th January 23:41)Craig Wrote:  Well mostly just load on the server.
....

Plus no nasty AJAX call for every qTip on the page!

Thanks for that! Yeah, you're right... the iframe is loading from another file anyway so my idea can still be implemented.

I'm not sure how much load or what's really happening though... It seems like (with Safari anyway) that it's cached in the browser. First load of the first tip results in a little lag but then subsequent calls to the tips pop right up.

Your idea is better and I'll probably do it... I'm all about efficient code.
Find all posts by this user
Quote this message in a reply
6th January, 02:56
Post: #15
RE: [Solved] Load tips from external file... how?
Yeah the iframe idea is simply load-saving. You fetch all the tooltips at once instead of fetching the page each time a tooltip is opened, resulting in quite a significant bandwidth saving if the page is big.

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
9th January, 19:31
Post: #16
RE: [Solved] Load tips from external file... how?
(5th January 23:41)Craig Wrote:  Here's an example of this using an iframe:

HTML Code
<iframe src="tooltips.html" style="position: absolute; left: -1000px; top: -1000px;"></iframe>

JS Code
$(document).each(function(){
	$('ul.subindex li a[title]').qtip({
		content: 'Loading...',
		events: {
			render: function(event, api) {
				// Grab our tooltip id from the target element
				var selector = '#' + api.elements.target.attr('title'),
					iframe = $('iframe'),
					content = $(selector, iframe.contents());
 
				// Update our tooltip content (repositions automatically)
				api.set('content.text', content);
			}
		}
	});
});

I tried this and nothing happens. No qTip.
Find all posts by this user
Quote this message in a reply
11th January, 09:42
Post: #17
RE: [Solved] Load tips from external file... how?
Any errors sparky?

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
11th January, 15:41
Post: #18
RE: [Solved] Load tips from external file... how?
No errors. I put the iFrame line outside of my content but still inside the body. Hover does nothing... no qTip, just the default tooltip.

I was playing around with it. Instead of hiding the iframe, I just placed it inline and it strangely blocks my page content. I mean that I set the iframe to a fixed width of 100px square and I can see it, but everything downstream of it will not show on the page. (this is probably an HTML problem I had not enough time to investigate).

However, no matter where I placed it, no matter what size I made it, even if I placed it -10000 pixels off the page, the qTips will not show up.

One exception, when I place it AFTER the qTip JS, a blank qTip appears; but that's only because the JS is before the iframe.
Find all posts by this user
Quote this message in a reply
11th January, 17:42
Post: #19
RE: [Solved] Load tips from external file... how?
sparky, run your HTML through the W3C Validator to see if you've got any errors in there. Other than that it would be great if you could setup a jsFiddle test case with this.

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
11th January, 18:00
Post: #20
RE: [Solved] Load tips from external file... how?
(11th January 17:42)Craig Wrote:  sparky, run your HTML through the W3C Validator to see if you've got any errors in there. Other than that it would be great if you could setup a jsFiddle test case with this.

1. It's all green at the w3c validator.

2. Not really sure how to set this JSfiddle up correctly since the external tip file is stored on my server. Here it is but it doesn't work because I left the iframe "src" blank.

http://jsfiddle.net/BuQtu/
Find all posts by this user
Quote this message in a reply
12th January, 09:47
Post: #21
RE: [Solved] Load tips from external file... how?
Seems to be working great once the iframe src is set Smile http://jsfiddle.net/BuQtu/5/

Just have to make sure the iframe contents are on the same server due to Cross-Domain limitations.

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
12th January, 15:06
Post: #22
RE: [Solved] Load tips from external file... how?
(12th January 09:47)Craig Wrote:  Seems to be working great once the iframe src is set Smile http://jsfiddle.net/BuQtu/5/

JSfiddle not working great here. Sad I'm in both Safari (Mac) and Firefox (Mac). Just to be clear, I'm not talking about my page... the JSfiddle page itself (http://jsfiddle.net/BuQtu/5/) is not working in Safari or Firefox. I'm now seeing just an empty qTip popup. There are no errors and it does not say "loading..."

I've attached a screenshot from Firefox.

[Image: jsfiddle.th.jpg]

I recall seeing that condition on my page once too but it depended on where I placed the iframe code within the HTML.

(12th January 09:47)Craig Wrote:  Just have to make sure the iframe contents are on the same server due to Cross-Domain limitations.

they are.
Find all posts by this user
Quote this message in a reply
12th January, 15:24
Post: #23
RE: [Solved] Load tips from external file... how?
For some reason you need to hit "Run" again once it's loaded. Must be a fiddle-related script as you're normally not allowed to link directly to the resulting page (I'm an elite haxxor... Tongue)

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
12th January, 15:37
Post: #24
RE: [Solved] Load tips from external file... how?
(12th January 15:24)Craig Wrote:  For some reason you need to hit "Run" again once it's loaded. Must be a fiddle-related script as you're normally not allowed to link directly to the resulting page (I'm an elite haxxor... Tongue)

...hitting "Run" in Safari makes no difference here.

...it only works after hitting "Run" in Firefox.

So now after testing this exact code on my production page...

- seems to be working in IE8 and Firefox.
- does NOT work in Safari. (getting the empty qTip)
Find all posts by this user
Quote this message in a reply
12th January, 16:55
Post: #25
RE: [Solved] Load tips from external file... how?
sparky, any you getting any errors at ALL? Try and console.log() the iframe contents and see if its actually loading.

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
  Loading Tips from External File Only Works in Chrome eurotransient 2 52 16th May 15:06
Last Post: eurotransient
  [Solved] Unable to load an image in my qTip? itoad 2 282 15th March 07:29
Last Post: itoad
  [Solved] Alternating tool-tips positions MorVimmer 2 301 28th February 16:18
Last Post: MorVimmer
  [Solved] Tips not fading when roll out is completed. Comm-Tech 3 335 14th February 17:15
Last Post: Craig
  Arrows of my tips are not showing correctly abd2012 5 435 1st February 14:21
Last Post: Craig
  Multiple tool tips displayed sometimes Cyborg5001 1 394 4th January 22:46
Last Post: Craig
  [Solved] close all tips except one daviddd 2 323 15th December 19:31
Last Post: Craig
  Wordpress Generated Array -- How to Implement Tips for Each Result? WebmistressM 1 583 20th November 17:53
Last Post: WebmistressM
  [Solved] Tips & Tricks -> Global switch won't work mayid 1 556 10th November 18:12
Last Post: Craig
  Close all tooltips from an external function egrigolon 1 621 8th October 14:06
Last Post: Craig



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