replace this:
var hash;
if (document.location.hash)
  var hash = (document.location.hash).charAt(1);

with:
var hash;
if (document.location.hash)
  hash = document.location.hash.slice(1);

Maybe you want slice(1) because charAt(1) only returns 1 character and
slice(1) would return the hole hash without the "#"

On 23 Sep., 11:45, "Jörn Zaefferer" <[EMAIL PROTECTED]>
wrote:
> You can replace .css({display:'block'}) with .show() and
> .css({display:'none'}) with .hide().
>
> Using document.location.hash.chartAt(1) will cut off any id with more
> then one character, removing charAt(1) should make that much more
> flexible.
>
> Jörn
>
> On Tue, Sep 23, 2008 at 10:27 AM, hcvitto <[EMAIL PROTECTED]> wrote:
>
> > hi
> > i wrote my first (pretty useless:) plugin but i'm not sure what to
> > think about it, it just looks like it has "too much words"!!
>
> > Here's the plugin code (it's to make a glossary)
>
> > (function($){
> >        $.fn.glossario = function(options){
> >                                        var defaults = {
> >                                                stile: 'mark'
> >                                        };
> >                                        var options = $.extend(defaults, 
> > options);
> >                                        var classe = options.stile;
> >                                        var hash;
> >                                        if (document.location.hash)
> >                                                var hash = 
> > (document.location.hash).charAt(1);
> >                                        return this.each(function() {
> >                                                var obj = $(this);
> >                                                var anchors = 
> > obj.children("a");
> >                                                
> > obj.children('dl').css({display:'none'});
> >                                                if (hash) {
> >                                                        
> > obj.children('a[href=#' + hash + ']').addClass(classe);
> >                                                        
> > obj.children('dl[id=' + hash + ']').css({display:'block'});
> >                                                } else {
> >                                                        
> > obj.children('a:first').addClass(classe);
> >                                                        
> > obj.children('dl:first').css({display:'block'});
> >                                                }
> >                                                anchors.click(function(){
> >                                                        var id = 
> > $(this).attr('href').charAt(1);
> >                                                        if 
> > (!($(this).hasClass(classe))){
> >                                                                
> > anchors.removeClass(classe);
> >                                                                
> > $(this).addClass(classe);
>
> > obj.children('dl').css({display:'none'}).end().children('dl[id=' + id
> > + ']').fadeIn();
> >                                                        }
> >                                                        return false;
> >                                                });
> >                                        });
> >                                };
> > })(jQuery);
>
> > $("#glossario").glossario();
>
> > <div id="glossario"><a href="#a">A</a> <a href="#b">B</a>  ...  <span
> > class="no_link">Z</span>
> >        <dl id="a">
> >          <dt>A word</dt>
> >          <dd>A word meaning</dd>
> >          <dt>A word</dt>
> >          <dd>A word meaning</dd>
> >        </dl>
> >        <dl id="b">
> >         <dt>B word</dt>
> >          <dd>B word meaning</dd>
> >          <dt>B word</dt>
> >          <dd>B word meaning</dd>
> >        </dl>
> >        <dl id="c">
> >          <dt>Bear market</dt>
> >          <dd>Mercato orso, ossia ribassista.</dd>
> >          <dt>Benchmark</dt>
> >          <dd>Parametro di riferimento utilizzato per la valutazione
> > dei risultati di un fondo o di una gestione.</dd>
> >        </dl>
> >        ...
> >      </div>
>
> > Any suggestion or feedback?
>
> > Thanks Vitto

Reply via email to