views:

28

answers:

2

Using jquery fitted* plugin, if I put a rel ="external" on the clickable area is successfully opened in new tab, but clicking on the link opens 2 times, how to fix this?

for example: i have:

<p>
text <a rel="external" href="/link">text2</a>
</p>

text opens perfectly one time, but clicking in text2 the link opens two times

the code is:

if(typeof jQuery != 'undefined') {
    jQuery(function($) {
        $.fn.extend({
            fitted: function(options) {
                var settings = $.extend({}, $.fn.fitted.defaults, options);

                return this.each(
                    function() {

                        var $t = $(this);
                        var o = $.metadata ? $.extend({}, settings, $t.metadata()) : settings;

                        if($t.find(':has(a)')) {
                            /**
                            * Find the first Anchor
                            * @var object $a
                            */
                            var $a = $t.find('a:first');

                            /**
                            * Get the Anchor Attributes
                            */
                            var href = $a.attr('href');
                            var title = $a.attr('title');

                            /**
                            * Setup the Container
                            * Add the 'container' class defined in settings
                            * @event hover
                            * @event click
                            */
                            $t.addClass(o['class']['container']).hover(
                                function(){
                                    /**
                                    * Hovered Element
                                    */
                                    $h = $(this);

                                    /**
                                    * Add the 'hover' class defined in settings
                                    */
                                    $h.addClass(o['class']['hover']);

                                    /**
                                    * Add the Title Attribute if the option is set, and it's not empty
                                    */
                                    if(typeof o['title'] != 'undefined' && o['title']===true && title != '') {
                                        $h.attr('title',title);
                                    }

                                    /**
                                    * Set the Status bar string if the option is set
                                    */
                                    if(typeof o['status'] != 'undefined' && o['status']===true) {
                                        if($.browser.safari) {
                                            /**
                                            * Safari Formatted Status bar string
                                            */
                                            window.status = 'Go to "' + href + '"';
                                        }
                                        else {
                                            /**
                                            * Default Formatted Status bar string
                                            */
                                            window.status = href;
                                        }
                                    }
                                },
                                function(){
                                    /**
                                    * "un"-hovered Element
                                    */
                                    $h = $(this);

                                    /**
                                    * Remove the Title Attribute if it was set by the Plugin
                                    */
                                    if(typeof o['title'] != 'undefined' && o['title']===true && title != '') {
                                        $h.removeAttr('title');
                                    }

                                    /**
                                    * Remove the 'hover' class defined in settings
                                    */
                                    $h.removeClass(o['class']['hover']);

                                    /**
                                    * Remove the Status bar string
                                    */
                                    window.status = '';
                                }
                            ).click(
                                function(){
                                    /**
                                    * Clicked!
                                    * The Container has been Clicked
                                    * Trigger the Anchor / Follow the Link
                                    */
                                    if($a.is('[rel*=external]')){
                                        window.open(href);
                                        return true;
                                    }
                                    else {
                                        //$a.click(); $a.trigger('click');
                                        window.location = href;
                                    }
                                }
                            );
                        }
                    }
                );
            }
        });

        /**
        * Plugin Defaults
        */
        $.fn.fitted.defaults = {
            'class' : {
                'container' : 'fitted',
                'hover' : 'hovered'
            },
            'title' : true,
            'status' : true
        };
    });
}

*: http://www.trovster.com/lab/plugins/fitted/

How to solve this? can be fixed?

thank you very much

A: 

Solved:

this:

 if($a.is('[rel*=external]')){
            window.open(href);
            return true;
            }

for this:

 if($a.is('[rel*=external]')){
            window.open(href);
            return false;
            }
quinti
A: 

I think actually to be able to use other functions on the clicks it is btter to do this:

.click(function(e){
  e.preventDefault();
  if($a.is('[rel*=external]')){
    window.open(href);
  } else {
    window.location = href;
  }
});
BenWells