by Soulmonster February 19th 2015, 10:44 am
Ange Tuteur wrote:Try taking off the script tags, and wrapping the code with jQuery's document ready event.
- Code:
$(function() {
var data = {
"L. sebae" : 'Revs-trygg: <img align="right" src="http://i624.photobucket.com/albums/tt328/SoulMonster/Bars/Hard.jpg" /><br>Fóring: <img align="right" src="http://i624.photobucket.com/albums/tt328/SoulMonster/Bars/Easy.jpg" /><br>Farlig: <img align="right" src="http://i624.photobucket.com/albums/tt328/SoulMonster/Bars/Easy.jpg" /><br>Hardførhet: <img align="right" src="http://i624.photobucket.com/albums/tt328/SoulMonster/Bars/Average.jpg" /><br>Aggressivitet: <img align="right" src="http://i624.photobucket.com/albums/tt328/SoulMonster/Bars/Easy.jpg" /><br><strong>Vanskelighet: </strong><img align="right" src="http://i624.photobucket.com/albums/tt328/SoulMonster/Bars/Hard.jpg" /><br>Volum: <em>>5000 liter</em>.<br><hr><em><strong><div align="center"><a href="/h386-viktig" target="_blank">Forklaring</a></strong></div></em>',
};
var cells = document.getElementById('data-table').getElementsByTagName('td'), i = 0, c;
for(; (c = cells[i++]); ) {
var id = c.getAttribute('rel');
if(data[id]) {
var x = document.createElement('div');
x.className = 'popup-data';
x.innerHTML = data[id];
c.appendChild(x);
}
}
});
Thanks. I did this and the script still messes with the Lastest Posts widget (no scroll and extended in length), see:
http://www.saltvannsprat.com/But strangely enough, not on this page where the script works (!):
http://www.saltvannsprat.com/h439-a-snappere See picture below where the popup appears when hovering over the cell and where the Latest Posts widget scrolls and is its normal size:
But unfortunately, the script does not work in content embedded with AJAX as seen when you use the menu and choose the option "snappere", as I do on the picture below. So here I am embedding the same page as the one above, but now when hovering over the cell (red circle) the popup does not appear (!).
EDIT: It's when I hook off "in all the pages" that it messes with Lastest Topics. Unfortunately, I have to hook off that for it to work on the HTML page where the script is supposed to work. If there was an option to only make the script work on HTML pages and the menu, then that would be a step forward. I could call it from every HTML page, I assume, but then I need to use the JS ID and it changes every time I modify the script (add extra var data), which would make it impractical since I will have to update 50+ pages.
EDIT2: Thanks to LG I was able to make teh script work smoothly for all pages except those embedded with AJAX. The trick was to replace line 7 with this:
- Code:
var cells = document.getElementById('fisketabell'), i = 0, c;
if(!cells) return;
cells = cells.getElementsByTagName('td');
But all this still doesn't help me much unless I can get it to work on the content embedded with AJAX