This is basically a follow up on this question
I am trying to add custom tool tips to a jstree which show thumbnails of the image files if they mouse over them. It should use the node's a href value to mark up thumbnail and stick it in a tool tip. Referencing the above-mentioned post, I have managed to get it to show some arbitrary textual tool tip, but that is obviously not what I want.
If I were simply adding the tool tip to an img tag or an a tag by themselves, I doubt this would be an issue. But, I'm trying to create a custom tool tip for a link that's buried in a bunch of jstree node stuff.
For example:
.on('hover_node.jstree',function(e,data){
var $node = $("#" + data.node.id);
var url = $node.find('a').attr('href');
$("#" + data.node.id).prop('title', url);
})
does a fine job of ... just giving me a text tool tip. But I really don't know where to go from here, I have been beating my head against a wall for hours now, scouring the internet for viable solutions.
$(function () {
$(document).tooltip();
$('#treeView').jstree({
'core': {
'multiple': false,
'check_callback': true,
'data': {
'url': 'Temp/ajax.html',
'data': function (node) {
return { 'id': node.id };
}
}
},
'checkbox': {
'three_state': false,
'whole_node': false
},
'plugins': ["checkbox"]
}).on('hover_node.jstree',function(e,data){
var $node = $("#" + data.node.id);
var url = $node.find('a').attr('href');
$("#" + data.node.id).prop({ 'title': url, 'content': '<img src="' + url + '" alt=""/>' });
})
});
All I know is nothing I've tried has worked. I read all of the API docs for the JQuery tool tip plug in, but I'm still pretty new at this and it's become apparent that I won't be able to brute-force-and-ignorance my way into a solution.
UPDATE
So I have revised the code as follows:
.on('hover_node.jstree', function (e, data) {
var $node = $("#" + data.node.id);
var url = $node.find('a').attr('href');
if (url != '#') {
debugger
//get the mouse position
var x = $node.position().top + 20;
var y = $node.position().left;
$('.tooltip').css({ 'top': y + 'px', 'left': x + 'px' });
$('.tooltip').find('img').attr('src', url);
$('.tooltip').fadeIn(300, 'easeOutSine');
}
}).on('dehover_node.jstree', function () {
$('.tooltip').fadeOut(200);
});
and it works..ostensibly. NOW I need to actually figure out how to get the MOUSE POINTER coordinates, not the NODE coordinates. Every image I mouse over down the list, the tool tip shows further and further to the right. I'm figuring out a way to show it AT the mouse pointer.
LAST UPDATE
//assigning the right properties to the right
//variables would work wonders for my cause.
var x = $node.position().left;
var y = $node.position().top + 20;