Navigation Menu

Skip to content

Commit

Permalink
Item10918: bring back tab handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Nov 22, 2016
1 parent 01b1ed3 commit 858833a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
31 changes: 22 additions & 9 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/TABPANE.pm
Expand Up @@ -29,7 +29,7 @@ sub new {
my $this = bless(
$class->SUPER::new(
name => 'Tabpane',
version => '1.23',
version => '2.00',
author => 'Michael Daum',
homepage => 'http://foswiki.org/Extensions/JQueryPlugin',
tags => 'TABPABNE, ENDTABPANE, TAB, ENDTAB',
Expand Down Expand Up @@ -93,21 +93,31 @@ sub handleTab {
my $tabClass = $params->{id} || '';
my $height = $params->{height};
my $width = $params->{width};
my $tabId = 'jqTab' . Foswiki::Plugins::JQueryPlugin::Plugins::getRandom();

my $rand = Foswiki::Plugins::JQueryPlugin::Plugins::getRandom();
my $tabId = "jqTab$rand";

my @callbacks = ();
my @html5Data = ();

if ($beforeHandler) {
push @html5Data,
"data-before-handler=\"function(oldTabId, newTabId) {$beforeHandler}\"";
my $fnName = "beforeHandler$rand";
push @callbacks,
"function $fnName(oldTabId, newTabId) {$beforeHandler}";
push @html5Data, "data-before-handler=\"$fnName\"";
}
if ($afterHandler) {
push @html5Data,
"data-after-handler=\"function(oldTabId, newTabId) {$afterHandler}\"";
my $fnName = "afterHandler$rand";
push @callbacks, "function $fnName(oldTabId, newTabId) {$afterHandler}";
push @html5Data, "data-after-handler=\"$fnName\"";
}
if ($afterLoadHandler) {
push @html5Data,
"data-after-load-handler=\"function(oldTabId, newTabId) {$afterLoadHandler}\"";
my $fnName = "afterLoadHandler$rand";
push @callbacks,
"function $fnName(oldTabId, newTabId) {$afterLoadHandler}";
push @html5Data, "data-after-load-handler=\"$fnName\"";
}

if ($container) {
push @html5Data, "data-container=\"$container\"";
}
Expand All @@ -123,7 +133,10 @@ sub handleTab {
$style = "style='$style'" if $style;

return
"<div id='$tabId' class='$tabClass jqTab'$html5Data style='display:none'>\n<h2 class='jqTabLabel'>$theName</h2>\n<div class='jqTabContents' $style>";
"<literal><script type='text/javascript'>"
. ( join( "\n", @callbacks ) )
. "</script></literal>\n"
. "<div id='$tabId' class='$tabClass jqTab'$html5Data style='display:none'>\n<h2 class='jqTabLabel'>$theName</h2>\n<div class='jqTabContents' $style>";
}

=begin TML
Expand Down
Expand Up @@ -241,8 +241,8 @@ var bottomBarHeight = -1;
data = self.tabs[newTabId];

// before click handler
if (typeof(data.beforeHandler) == "function") {
data.beforeHandler.call(this, oldTabId, newTabId);
if (typeof(data.beforeHandler) !== "undefined") {
window[data.beforeHandler].call(self, oldTabId, newTabId);
}

$newContainer = $newTab.find('.jqTabContents:first');
Expand Down Expand Up @@ -305,9 +305,8 @@ var bottomBarHeight = -1;
$(window).trigger("resize");

// after click handler
if (typeof(data.afterHandler) == "function") {
//$.log("exec "+data.afterHandler);
data.afterHandler.call(this, oldTabId, newTabId);
if (typeof(data.afterHandler) !== "undefined") {
window[data.afterHandler].call(self, oldTabId, newTabId);
}

self.currentTabId = newTabId;
Expand All @@ -316,9 +315,8 @@ var bottomBarHeight = -1;
// async loader
if (typeof(data.url) != "undefined") {
$innerContainer.load(data.url, undefined, function() {
if (typeof(data.afterLoadHandler) == "function") {
//$.log("after load handler "+command);
data.afterLoadHandler.call(this, oldTabId, newTabId);
if (typeof(data.afterLoadHandler) !== "undefined") {
window[data.afterLoadHandler].call(self, oldTabId, newTabId);
}
_finally();
});
Expand Down

0 comments on commit 858833a

Please sign in to comment.