The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Thu Jun 14, 2012 9:38 am 
Joomla! Guru
Joomla! Guru

Joined: Sat Jan 21, 2006 8:42 pm
Posts: 925
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);


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 



Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group