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

Commit

Permalink
Introduced a few more optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Craga89 committed Jan 19, 2011
1 parent dc8053a commit ec56527
Show file tree
Hide file tree
Showing 6 changed files with 120 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 19 13:16:32 2011 +0000
* Date: Wed Jan 19 14:31:31 2011 +0000
*/

/* Fluid class for determining actual width in IE */
Expand Down
51 changes: 28 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 19 13:16:32 2011 +0000
* Date: Wed Jan 19 14:31:31 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 All @@ -30,7 +30,9 @@
disabled = 'ui-state-disabled',
selector = 'div.qtip.'+uitooltip,
focusClass = uitooltip + '-focus',
hideOffset = '-31000px';
hideOffset = '-31000px',
replaceSuffix = '_replacedByqTip',
oldtitle = 'oldtitle';


// Option object sanitizer
Expand Down Expand Up @@ -643,7 +645,7 @@ function QTip(target, options, id, attr)
callback = $.Event('tooltiprender');

// Add ARIA attributes to target
target.attr({ 'aria-describedby': tooltipID });
$.attr(target[0], 'aria-describedby', tooltipID);

// Create tooltip element
tooltip = elements.tooltip = $('<div/>')
Expand Down Expand Up @@ -807,7 +809,7 @@ function QTip(target, options, id, attr)

// Style checks
'^style.classes$': function() {
tooltip.attr('class', uitooltip + ' qtip ui-helper-reset ' + value);
$.attr(tooltip[0], 'class', uitooltip + ' qtip ui-helper-reset ' + value);
},
'^style.widget|content.title': setWidget,

Expand Down Expand Up @@ -882,7 +884,7 @@ function QTip(target, options, id, attr)
if(callback.isDefaultPrevented()){ return self; }

// Set ARIA hidden status attribute
tooltip.attr('aria-hidden', !!!state);
$.attr(tooltip[0], 'aria-hidden', !!!state);

// Execute state specific properties
if(state) {
Expand Down Expand Up @@ -1153,7 +1155,7 @@ function QTip(target, options, id, attr)

// Set tooltip position class
tooltip.attr('class', function(i, val) {
return $(this).attr('class').replace(/ui-tooltip-pos-\w+/i, '');
return $.attr(this, 'class').replace(/ui-tooltip-pos-\w+/i, '');
})
.addClass(uitooltip + '-pos-' + my.abbreviation());

Expand Down Expand Up @@ -1226,7 +1228,7 @@ function QTip(target, options, id, attr)

if(self.rendered) {
tooltip.toggleClass(c, state);
tooltip.attr('aria-disabled', state);
$.attr(tooltip[0], 'aria-disabled', state);
}
else {
self.cache.disabled = !!state;
Expand All @@ -1237,7 +1239,8 @@ function QTip(target, options, id, attr)

destroy: function()
{
var oldtitle = $.data(target[0], 'oldtitle');
var t = target[0],
oldtitle = $.data(t, oldtitle);

// Destroy tooltip and any associated plugins if rendered
if(self.rendered) {
Expand All @@ -1254,11 +1257,11 @@ function QTip(target, options, id, attr)
unassignEvents(1, 1, 1, 1);

// Remove api object
target.removeData('qtip');
$.removeData(t, 'qtip');

// Reset old title attribute if removed
if(oldtitle) {
target.attr('title', oldtitle);
$.attr(t, 'title', oldtitle);
}

// Remove ARIA attributse
Expand All @@ -1272,7 +1275,7 @@ function QTip(target, options, id, attr)
// Initialization method
function init(id, opts)
{
var obj, posOptions, usedAttr,
var obj, posOptions, attr, usedAttr,

// Setup element references
elem = $(this),
Expand All @@ -1289,17 +1292,18 @@ function init(id, opts)

// Merge in our sanitized metadata and remove metadata object so we don't interfere with other metadata calls
config = $.extend(TRUE, {}, $.fn.qtip.defaults, opts, sanitizeOptions(metadata5 || metadata));
elem.removeData('metadata');
$.removeData(this, 'metadata');

// Re-grab our positioning options now we've merged our metadata
posOptions = config.position;

// Setup missing content if none is detected
if('boolean' === typeof config.content.text) {

var attr = $.attr(this, config.content.attr);

// Grab from supplied attribute if available
if(config.content.attr !== FALSE && elem.attr(config.content.attr)) {
config.content.text = elem.attr(config.content.attr);
if(config.content.attr !== FALSE && attr) {
config.content.text = attr;
usedAttr = config.content.attr;
}

Expand Down Expand Up @@ -1331,8 +1335,8 @@ function init(id, opts)
}

// Remove title attribute and store it if present
if(elem.attr('title')) {
$.data(this, 'oldtitle', elem.attr('title'));
if($.attr(this, 'title')) {
$.data(this, oldtitle, $.attr(this, 'title'));
elem.removeAttr('title');
}

Expand Down Expand Up @@ -1483,14 +1487,14 @@ $.each({

if(attr === 'title') {
if(arguments.length === 1) {
return $.data(self, 'oldtitle');
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);
return $.data(self, oldtitle, val);
}
}
},
Expand All @@ -1501,15 +1505,15 @@ $.each({

// Re-add cached titles before we clone
$('*', this).each(function() {
var oldtitle = $.data(this, 'oldtitle');
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);
elem = $.fn['clone'+replaceSuffix].apply(this, arguments);

// Remove the old titles again
titles.removeAttr('title');
Expand All @@ -1535,9 +1539,10 @@ $.each({
},
function(name, func) {
if(!func) { return TRUE; }
$.fn['Old'+name] = $.fn[name];

var old = $.fn[name+replaceSuffix] = $.fn[name];
$.fn[name] = function() {
return func.apply(this, arguments) || $.fn['Old'+name].apply(this, arguments);
return func.apply(this, arguments) || old.apply(this, arguments);
};
});

Expand Down

0 comments on commit ec56527

Please sign in to comment.