I wrote a little jquery plugin for tabs, what do more or less the same as the tabs.js shipped with Joomla. It works so far, but if there is some inline js in one of the tabs the plugin fails.
For example if there is a email addy what is cloaked by Joomla, the document.write from the cloaking script just rewrites the page and it goes blank and only shows the mail.
So I tried some other piece of js
Code:
<script id="myscripttag">
var new = document.createElement('p');
new.id = 'new-el';
new.appendChild(document.createTextNode('lets test this!'));
var scr = document.getElementById('myscripttag');
scr.parentNode.insertBefore(new, scr);
</script>
what fails with: Uncaught TypeError: Cannot read property 'parentNode' of null
As a side note: It`s not a conflict mootools vs jQuery - mootools is complete disabled,
also the above little code works if I disable the jquery plugin and also works when mootools is enabled, so what is the problem with jquery/my code.
here the plugin code
Code:
(function($)
{
$.fn.jwtabs = function(opts) {
var options = $.extend({}, $.fn.jwtabs.defOptions, opts);
var titles = this.children(options.titleSelector);
var descriptions = this.children(options.descriptionSelector);
var storageName = 'jpanetabs_' + this.attr('id');
$('<div/>').addClass('current').append(descriptions).insertAfter(this);
if (options.useStorage) {
if (typeof(Storage) !== 'undefined') options.display = (+sessionStorage.getItem(storageName));
}
if (options.display === null || options.display === 'undefined') {
options.display = 0;
}
titles.each(function(i, e) {
$(this).click({tab: i}, function(e) {
hideAllBut(e.data.tab);
});
});
hideAllBut(options.display);
function hideAllBut(but) {
for (var i = 0, l = titles.length; i < l; i++) {
if (i !== but) {
titles.eq(i).addClass('closed').removeClass('open');
descriptions.eq(i).removeClass('current').slideUp();
} else {
titles.eq(i).addClass('open').removeClass('closed');
descriptions.eq(i).addClass('current').slideDown();
}
}
if (options.useStorage) {
if (typeof(Storage) !== 'undefined') sessionStorage.setItem(storageName, but);
}
}
return this;
};
$.fn.jwtabs.defOptions = {
display: 0,
useStorage: true,
titleSelector: 'dt',
descriptionSelector: 'dd'
};
})(jQuery);