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

Commit

Permalink
Add deferred support via content.deferred
Browse files Browse the repository at this point in the history
  • Loading branch information
Craga89 committed Nov 15, 2012
1 parent 7e6cc23 commit 4e6c8bc
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 14 deletions.
24 changes: 20 additions & 4 deletions dist/basic/jquery.qtip.js
Expand Up @@ -58,7 +58,7 @@
function sanitizeOptions(opts)
{
var invalid = function(a) { return a === NULL || 'object' !== typeof a; },
invalidContent = function(c) { return !$.isFunction(c) && ((!c && !c.attr) || c.length < 1 || ('object' === typeof c && !c.jquery)); };
invalidContent = function(c) { return !$.isFunction(c) && ((!c && !c.attr) || c.length < 1 || ('object' === typeof c && !c.jquery && !c.then)); };

if(!opts || 'object' !== typeof opts) { return FALSE; }

Expand Down Expand Up @@ -302,7 +302,16 @@ function QTip(target, options, id, attr)
}
}

function updateContent(content, reposition)
function deferredContent(deferred)
{
if(deferred && $.isFunction(deferred.done)) {
deferred.done(function(c) {
updateContent(c, null, FALSE);
});
}
}

function updateContent(content, reposition, checkDeferred)
{
var elem = elements.content;

Expand All @@ -314,6 +323,11 @@ function QTip(target, options, id, attr)
content = content.call(target, cache.event, self) || '';
}

// Handle deferred content
if(checkDeferred !== FALSE) {
deferredContent(options.content.deferred);
}

// 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' }));
Expand Down Expand Up @@ -650,7 +664,8 @@ function QTip(target, options, id, attr)
},

// Content checks
'^content.text$': function(obj, o, v){ updateContent(v); },
'^content.text$': function(obj, o, v) { updateContent(options.content.text); },
'^content.deferred$': function(obj, o, v) { deferredContent(options.content.deferred); },
'^content.title.text$': function(obj, o, v) {
// Remove title if content is null
if(!v) { return removeTitle(); }
Expand Down Expand Up @@ -774,7 +789,7 @@ function QTip(target, options, id, attr)
else { createButton(); }

// Set proper rendered flag and update content if not a callback function (called in toggle)
if(!$.isFunction(text)) { updateContent(text, FALSE); }
if(!$.isFunction(text) || text.then) { updateContent(text, FALSE); }
self.rendered = TRUE;

// Setup widget classes
Expand Down Expand Up @@ -1703,6 +1718,7 @@ QTIP.defaults = {
content: {
text: TRUE,
attr: 'title',
deferred: FALSE,
title: {
text: FALSE,
button: FALSE
Expand Down

0 comments on commit 4e6c8bc

Please sign in to comment.