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

Commit

Permalink
clone() will now correctly rab cached title attributes. Also updated …
Browse files Browse the repository at this point in the history
….attr() to correctly update qTip content if title attribute was used originally. So calling .attr('title', 'foo') is now equivilent to .qtip('content.text', 'foo') for those tooltips with content.text unset and content.attr set to 'title'.
  • Loading branch information
Craga89 committed Jan 19, 2011
1 parent e562916 commit dc8053a
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 80 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 19 13:03:40 2011 +0000
* Date: Wed Jan 19 13:16:32 2011 +0000
*/

/* Fluid class for determining actual width in IE */
Expand Down
53 changes: 45 additions & 8 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 19 13:03:40 2011 +0000
* Date: Wed Jan 19 13:16:32 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 @@ -122,7 +122,7 @@ function sanitizeOptions(opts)
/*
* Core plugin implementation
*/
function QTip(target, options, id)
function QTip(target, options, id, attr)
{
// Declare this reference
var self = this,
Expand All @@ -141,7 +141,8 @@ function QTip(target, options, id)
event: {},
target: NULL,
disabled: FALSE,
lastFocus: docBody
lastFocus: docBody,
attr: attr
};

/*
Expand Down Expand Up @@ -1271,7 +1272,7 @@ function QTip(target, options, id)
// Initialization method
function init(id, opts)
{
var obj, posOptions,
var obj, posOptions, usedAttr,

// Setup element references
elem = $(this),
Expand Down Expand Up @@ -1299,6 +1300,7 @@ function init(id, opts)
// Grab from supplied attribute if available
if(config.content.attr !== FALSE && elem.attr(config.content.attr)) {
config.content.text = elem.attr(config.content.attr);
usedAttr = config.content.attr;
}

// No valid content was found, abort render
Expand Down Expand Up @@ -1335,7 +1337,7 @@ function init(id, opts)
}

// Initialize the tooltip and add API reference
obj = new QTip(elem, config, id);
obj = new QTip(elem, config, id, usedAttr);
$.data(this, 'qtip', obj);

// Catch remove events on target element to destroy redundant tooltip
Expand Down Expand Up @@ -1475,9 +1477,44 @@ $.fn.qtip.bind = function(opts, event)
// Override some of the core jQuery methods for library-specific purposes
$.each({
/* Allow other plugins to successfully retrieve the title of an element with a qTip applied */
attr: function(attr) {
var api = $.data(this, 'qtip');
return (arguments.length === 1 && attr === 'title' && api && api.rendered === TRUE) ? $.data(this, 'oldtitle') : NULL;
attr: function(attr, val) {
var self = this[0],
api = $.data(self, 'qtip');

if(attr === 'title') {
if(arguments.length === 1) {
return $.data(self, 'oldtitle');
}
else {
// If qTip is rendered and title was originally used as content, update it
if(api && api.rendered && api.options.content.attr === 'title' && api.cache.attr) {
api.set('content.text', val);
}
return $.data(self, 'oldtitle', val);
}
}
},

/* Allow clone to correctly retrieve cached title attributes */
clone: function(keepData) {
var titles = $([]), elem;

// Re-add cached titles before we clone
$('*', this).each(function() {
var oldtitle = $.data(this, 'oldtitle');
if(oldtitle) {
$.attr(this, 'title', oldtitle);
titles = titles.add(this);
}
});

// Clone our element using the real clone method
elem = $.fn.Oldclone.apply(this, arguments);

// Remove the old titles again
titles.removeAttr('title');

return elem;
},

/*
Expand Down

0 comments on commit dc8053a

Please sign in to comment.