Skip to content
This repository has been archived by the owner on Jun 14, 2020. It is now read-only.

Commit

Permalink
Added ability to use function as title.text, with first argument the API
Browse files Browse the repository at this point in the history
  • Loading branch information
Craga89 committed Jan 13, 2011
1 parent 45739bc commit 7f215df
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 110 deletions.
2 changes: 1 addition & 1 deletion dist/jquery.qtip.css
Expand Up @@ -9,7 +9,7 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
* Date: Wed Jan 12 22:29:27 2011 +0000
* Date: Thu Jan 13 09:18:01 2011 +0000
*/

/* Fluid class for determining actual width in IE */
Expand Down
64 changes: 41 additions & 23 deletions dist/jquery.qtip.js
Expand Up @@ -9,7 +9,7 @@
* http://en.wikipedia.org/wiki/MIT_License
* http://en.wikipedia.org/wiki/GNU_General_Public_License
*
* Date: Wed Jan 12 22:29:27 2011 +0000
* Date: Thu Jan 13 09:18:01 2011 +0000
*/

"use strict"; // Enable ECMAScript "strict" operation for this function. See more: http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/
Expand Down Expand Up @@ -280,7 +280,6 @@ function QTip(target, options, id)
elems.title = $('<div />', {
'id': id,
'class': uitooltip + '-title',
'html': options.content.title.text,
'aria-atomic': TRUE
})
)
Expand Down Expand Up @@ -314,49 +313,55 @@ function QTip(target, options, id)

function updateTitle(content)
{
var elem = self.elements.title;

// Make sure tooltip is rendered and if not, return
if(!self.rendered) { return FALSE; }
if(!self.rendered || !content) { return FALSE; }

// If title isn't already created, create it now
if(!self.elements.title && content) {
createTitle();
self.reposition();
// Use function to parse content
if($.isFunction(content)) {
content = content.call(target, self) || '';
}
else if(!content) {
removeTitle();

// Append new content if its a DOM array and show it if hidden
if(content.jquery && content.length > 0) {
elem.empty().append(content.css({ display: 'block' }));
}
else {
// Set the new content
self.elements.title.html(content);

// Content is a regular string, insert the new content
else { elem.html(content); }

// Redraw and reposition
self.redraw();
if(self.rendered === TRUE) {
self.reposition(self.cache.event);
}
}

function updateContent(content)
{
var elements = self.elements;
var elem = self.elements.content;

// Make sure tooltip is rendered and content is defined. If not return
if(!self.rendered || !content) { return FALSE; }

// Use function to parse content
if($.isFunction(content)) {
content = content.call(target, self);
content = content.call(target, self) || '';
}

// Append new content if its a DOM array and show it if hidden
if(content.jquery && content.length > 0) {
elements.content.empty().append(content.css({ display: 'block' }));
elem.empty().append(content.css({ display: 'block' }));
}

// Content is a regular string, insert the new content
else {
elements.content.html(content);
}
else { elem.html(content); }

// Insert into 'fx' queue our image dimension checker which will halt the showing of the tooltip until image dimensions can be detected
tooltip.queue('fx', function(next) {
// Find all content images without dimensions
var images = $('img:not([height]):not([width])', self.elements.content);
var images = $('img:not([height]):not([width])', elem);

// Update tooltip width and position when all images are loaded
function imageLoad(img) {
Expand Down Expand Up @@ -621,6 +626,8 @@ function QTip(target, options, id)
if(self.rendered) { return FALSE; } // If tooltip has already been rendered, exit

var elements = self.elements,
content = options.content.text,
title = options.content.title.text,
callback = $.Event('tooltiprender');

// Add ARIA attributes to target
Expand Down Expand Up @@ -659,9 +666,12 @@ function QTip(target, options, id)
// Set rendered status
self.rendered = TRUE;

// Setup title and update content
if(options.content.title.text) { createTitle(); }
updateContent(options.content.text);
// Update title and content
if(title) {
createTitle();
updateTitle(title);
}
updateContent(content);

// Initialize 'render' plugins
$.each($.fn.qtip.plugins, function() {
Expand Down Expand Up @@ -749,7 +759,15 @@ function QTip(target, options, id)

// Content checks
'^content.text$': function(){ updateContent(value); },
'^content.title.text$': function(){ updateTitle(value); },
'^content.title.text$': function() {
// Remove title if content is null
if(!value) { return removeTitle(); }

// If title isn't already created, create it now
if(!self.elements.title && value) { createTitle(); }

updateTitle(value);
},
'^content.title.button$': function(){ updateButton(value); },

// Position checks
Expand Down

0 comments on commit 7f215df

Please sign in to comment.