, not first child of it. Makes it much easier to apply sane CSS.
$cluetipOuter = $('
').append($cluetipInner).prepend($cluetipTitle);
$cluetip = $('
')
.attr({'id': 'cluetip'})
.css({position: 'absolute'})
.append($cluetipOuter)
.appendTo('body')
.hide();
$('

')
.attr({'id': 'cluetip-waitimage'})
.css({position: 'absolute', zIndex: '1001'})
.appendTo('body')
.hide();
}
if (defaults.pngFix && msie6) {
var image = $(this).css('backgroundImage');
if (image.match(/^url\(["']?(.*\.png)["']?\)$/i)) {
image = RegExp.$1;
$cluetip.css({
'zoom': '1',
'backgroundImage': 'none',
'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale, src='" + image + "')"
});
}
}
var $this = $(this);
var tipAttribute = $this.attr(defaults.attribute);
if (!tipAttribute && !defaults.splitTitle) return true;
// if hideLocal is set to true, initially hide the local content that will be displayed in the clueTip
if (defaults.local && defaults.hideLocal) { $(tipAttribute).hide(); }
// vertical measurement variables
var tipHeight, wHeight;
var sTop, offTop, posY;
// horizontal measurement variables
var tipWidth = parseInt(defaults.width, 10);
var offWidth = this.offsetWidth;
var offLeft, posX, winWidth;
// parse the title
var tipParts,
tipTitle = (defaults.attribute != 'title') ? $this.attr(defaults.titleAttribute) : '';
if (defaults.splitTitle) {
tipParts = tipTitle.split(defaults.splitTitle);
tipTitle = tipParts.shift();
}
var localContent;
// close cluetip and reset title attribute if one exists
var cluetipClose = function() {
$cluetipOuter
//.css('backgroundImage', 'url(' + defaults.waitImage + ')')
.children().empty().end()
.parent().hide();
if (tipTitle) {
$this.attr('title', tipTitle);
}
};
// get dimensions and options for cluetip and prepare it to be shown
var cluetipShow = function(bpY) {
if ($this.css('display') == 'block') {
$cluetip.css({top: (bpY - 10) + 'px'});
}
else {
$cluetip.css({top: posY + 'px'});
}
if (defaults.truncate) {
var $truncloaded = $cluetipInner.text().slice(0,defaults.truncate) + '...';
$cluetipInner.html($truncloaded);
}
// CHANGED: (v0.7) fixed positioning glitch when using the truncate option
tipHeight = $cluetip.outerHeight();
if ( posY + tipHeight > sTop + wHeight ) {
if (tipHeight >= wHeight) {
$cluetip.css({top: (sTop) + 'px'});
} else {
$cluetip.css({top: (sTop + wHeight - tipHeight - 10) + 'px'});
}
}
// CHANGED: (v0.7) added alternate theme based on Cody Lindley's jTip and demo files to show it (alt-demo...)
if (defaults.arrows) {
var bgPos = '0 0';
var bgY = (posY - parseInt($cluetip.css('top'), 10)) + 'px';
if ($cluetip.is('.clue-left')) {
bgPos = $this.css('display') != 'block' && posX >=0 ? '100% ' + bgY : '100% 0';
} else if ($cluetip.is('.clue-right')) {
bgPos = $this.css('display') != 'block' && posX >=0 ? '0 ' + bgY : '0 0';
}
$cluetip.css({backgroundPosition: bgPos});
}
if (defaults.sticky) {
var $closeLink = $('
' + defaults.closeText + '');
(defaults.closePosition == 'bottom') ? $closeLink.css('display','block').appendTo($cluetipInner) : $closeLink.css('display','block').prependTo($cluetipInner);
$closeLink.click(function() {
cluetipClose();
return false;
});
}
if (tipTitle) {
$cluetipTitle.show().html(tipTitle);
} else {
$cluetipTitle.hide();
}
$cluetip.show();
};
/***************************************
* ACTIVATION
****************************************/
// activate by click
if (defaults.activation == 'click'||defaults.activation == 'toggle') {
$this.toggle(function(event) {
activate(event);
this.blur();
return false;
}, function(event) {
inactivate(event);
this.blur();
return false;
});
// activate by hover
// clicking is returned false if cluetip url is same as href url
} else {
$this.click(function() {
if (tipAttribute == $this.attr('href')) {
return false;
}
});
$this[($.fn.hoverIntent) && defaults.hoverIntent ? 'hoverIntent' : 'hover'](function(event) {
activate(event);
}, function(event) {
inactivate(event);
});
}
//activate clueTip
var activate = function(event) {
if (tipAttribute == $this.attr('href')) {
$this.css('cursor', 'help');
}
if (tipTitle) {
$this.removeAttr('title');
}
if (defaults.hoverClass) {
$this.addClass(defaults.hoverClass);
}
sTop = $(document).scrollTop();
offTop = $this.offset().top;
offLeft = $this.offset().left;
// CHANGED: (v0.7) changed $(document).width() to the more appropriate $(window).width() for positioning clueTip x coordinate
winWidth = $(window).width();
posX = (offWidth > offLeft && offLeft > tipWidth)
|| offLeft + offWidth + tipWidth > winWidth
? offLeft - tipWidth - 15
: offWidth + offLeft + 15;
posY = offTop;
$cluetip.css({width: defaults.width});
// CHANGED: (v0.7)
now gets class="clue-left" if positioned to the left of the hovered element and class="clue-right" if positioned to the right. Useful for styling the clueTip differently based on where it displays
if ($this.css('display') != 'block' && posX >=0) {
$cluetip.css({left: posX + 'px'});
posX < offLeft ? $cluetip.addClass('clue-left').removeClass('clue-right')
: $cluetip.addClass('clue-right').removeClass('clue-left');
} else {
if (event.pageX + tipWidth > winWidth) {
$cluetip.css({left: (event.pageX - tipWidth - 30) + 'px'})
.addClass('clue-left').removeClass('clue-right');
} else {
$cluetip.css({left: (event.pageX + 30) + 'px'})
.addClass('clue-right').removeClass('clue-left');
}
var pY = event.pageY;
}
wHeight = $(window).height();
/***************************************
* load the title attribute only (or user-selected attribute).
* clueTip title is the string before the first delimiter
* subsequent delimiters place clueTip body text on separate lines
***************************************/
if (tipParts) {
for (var i=0; i < tipParts.length; i++){
if (i == 0) {
$cluetipInner.html(tipParts[i]);
} else {
$cluetipInner.append('
' + tipParts[i] + '
');
}
};
cluetipShow(pY);
/***************************************
* load external file via ajax
***************************************/
} else if (!defaults.local && tipAttribute.indexOf('#') != 0) {
if (cluetipContents) {
$cluetipInner.html(cluetipContents);
cluetipShow(pY);
}
else {
var ajaxSettings = defaults.ajaxSettings;
ajaxSettings.url = tipAttribute;
ajaxSettings.beforeSend = function() {
$('#cluetip-waitimage')
.css({top: posY, left: posX+(tipWidth/2)})
.show();
};
ajaxSettings.success = function(data) {
cluetipContents = defaults.ajaxProcess(data);
$cluetipInner.html(cluetipContents);
cluetipShow(pY);
$('#cluetip-waitimage').hide();
};
$.ajax(ajaxSettings);
}
/***************************************
* load an element from the same page
***************************************/
} else if (defaults.local && tipAttribute.indexOf('#') == 0){
var localContent = $(tipAttribute).html();
$cluetipInner.html(localContent);
cluetipShow(pY);
}
};
// on mouseout...
var inactivate = function() {
if (defaults.sticky == false) {
cluetipClose();
};
if (defaults.hoverClass) {
$this.removeClass(defaults.hoverClass);
}
};
});
};
})(jQuery);