MozRepl::Plugin::OpenNewTab - Open new tab and url.


MozRepl-Plugin-LinkTools documentation Contained in the MozRepl-Plugin-LinkTools distribution.

Index


Code Index:

NAME

Top

MozRepl::Plugin::OpenNewTab - Open new tab and url.

VERSION

Top

version 0.01

SYNOPSIS

Top

    use MozRepl;

    my $repl = MozRepl->new;
    $repl->setup({ plugins => { plugins => [qw/OpenNewTab/] } });

    $repl->open_new_tab({ url => "http://d.hatena.ne.jp/ZIGOROu/", selected => 1 });

DESCRIPTION

Top

Add open_new_tab() method to MozRepl.

METHODS

Top

execute($ctx, $args)

$ctx

Context object. See MozRepl.

$args

Hash reference. See below detail.

url
selected

method_name()

Return constant value, "open_new_tab". Used by method name adding method to MozRepl object.

AUTHOR

Top

Toru Yamaguchi, <zigorou@cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-mozrepl-plugin-opennewtab@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

COPYRIGHT & LICENSE

Top


MozRepl-Plugin-LinkTools documentation Contained in the MozRepl-Plugin-LinkTools distribution.
package MozRepl::Plugin::OpenNewTab;

use strict;
use warnings;

use base qw(MozRepl::Plugin::Base);

use MozRepl::Util;

our $VERSION = '0.01';

sub execute {
    my ($self, $ctx, $args) = @_;

    my $params = {};

    $params->{repl} = $ctx->repl;
    $params->{url} = MozRepl::Util->javascript_value($args->{url});
    $params->{selected} = ($args->{selected}) ? "true" : "false";

    my $command = $self->process('execute', $params);
    my $result = $ctx->execute($command);

    return ($result eq 'true') ? 1 : 0;
}

sub method_name {
    return "open_new_tab";
}

1; # End of MozRepl::Plugin::OpenNewTab

__DATA__
__execute__
(function(url, selected) {
  selected = (selected) ? true : false;

  var tab;

  try {
    tab = window.top.getBrowser().addTab(url);

    if (!tab) {
      return false;
    }

    if (selected) {
      window.top.getBrowser().selectedTab = tab;
    }
  }
  catch (e) {
    return false;
  } 

  

  return true;
})([% url %], [% selected %])
__END__