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

Commit

Permalink
Removed preload functionality from ajax plugin in favour of core func…
Browse files Browse the repository at this point in the history
…tionality that prevents positioning issues directly by using img.load callbacks
  • Loading branch information
Craga89 committed Nov 4, 2010
1 parent 521a042 commit fb6ae22
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 118 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 Nov 3 22:48:32 2010 +0000
* Date: Wed Nov 3 22:50:59 2010 +0000
*/

.ui-tooltip-accessible{
Expand Down
49 changes: 23 additions & 26 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 Nov 3 22:48:32 2010 +0000
* Date: Wed Nov 3 22:50:59 2010 +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 @@ -346,7 +346,9 @@ function QTip(target, options, id)
}

function updateContent(content)
{
{
var images;

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

Expand All @@ -365,16 +367,28 @@ function QTip(target, options, id)
self.elements.content.html(content);
}

// Update tooltip width and position
updateWidth();
if(self.rendered === TRUE) {
self.reposition(self.cache.event);
// Update tooltip width and position when all images are loaded
function imageLoad() {
if(--images < 1) {
updateWidth();
if(self.rendered === TRUE) {
self.reposition(self.cache.event);
}
}
}

// Assign the load callback to all images to prevent positioning errors
images = $('img', self.elements.content).each(function() {
$(this).load(imageLoad);
var src = this.src; this.src = ''; this.src = src; // Trigger onload even if image is cached
}).length;

// If no images were found, run imageLoad directly
if(images === 0) { imageLoad(); }

return self;
}


function assignEvents(show, hide, tooltip, doc)
{
var namespace = '.qtip-'+id,
Expand Down Expand Up @@ -1512,8 +1526,6 @@ $.fn.qtip.defaults = {
}
};

var PRELOAD = $();

function Ajax(qTip)
{
var self = this;
Expand Down Expand Up @@ -1552,9 +1564,8 @@ function Ajax(qTip)
if(result === FALSE){ return; }
}

// Update content and remove preloaded iamges if present
// Update content
qTip.set('content.text', content);
PRELOAD.remove();

}
function errorHandler(xhr, status, error)
Expand Down Expand Up @@ -1587,17 +1598,6 @@ function Ajax(qTip)
self.init();
}

function preloadImages(url) {
var id = 'qtip-preload';

if(!$('#'+id).length) {
$('<div id="'+id+'" class="ui-tooltip-accessible" />').appendTo(document.body);
}

if(!PRELOAD.length) {
PRELOAD = $('<div />').appendTo('#'+id).load(url + ' img');
}
}

$.fn.qtip.plugins.ajax = function(qTip)
{
Expand Down Expand Up @@ -1628,8 +1628,6 @@ $.fn.qtip.plugins.ajax.sanitize = function(options)
if(typeof opts !== 'object') { options.content.ajax = { url: opts }; }
if(options.content.text === FALSE) { options.content.text = 'Loading...'; }
opts.once = !!opts.once;
opts.preload = !!opts.preload;
if(opts.preload) { preloadImages(opts.url); } // Preload images if enabled
}
catch (e) {}
};
Expand All @@ -1638,8 +1636,7 @@ $.fn.qtip.plugins.ajax.sanitize = function(options)
$.extend(TRUE, $.fn.qtip.defaults, {
content: {
ajax: {
once: TRUE,
preload: FALSE
once: TRUE
}
}
});// Tip coordinates calculator
Expand Down

0 comments on commit fb6ae22

Please sign in to comment.