Created
September 15, 2012 00:42
-
-
Save vojtech-dobes/3725831 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div n:class="tab-pane, $tab == 'content' ? active" id="component-{$id}-{$tab}"> | |
{snippet tab} | |
{include #content} | |
{/snippet} | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{extends @Component.layout.latte} | |
{block #content} | |
<h2>Component {$id} - content</h2> | |
<p>Lorem ipsum dolor sit amet</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="tab-pane active" id="component-{$id}-tab"> | |
{snippet tab} | |
{include #content} | |
{/snippet} | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul class="nav nav-tabs" id="myTab"> | |
<li n:class="$tab == 'content' ? active"><a n:href="change! content" data-target="#component-{$id}-tab" data-toggle="tab">content</a></li> | |
<li n:class="$tab == 'settings' ? active"><a n:href="change! settings" data-target="#component-{$id}-tab" data-toggle="tab">settings</a></li> | |
<li n:class="$tab == 'history' ? active"><a n:href="change! history" data-target="#component-{$id}-tab" data-toggle="tab">history</a></li> | |
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ComponentControl extends \Nette\Application\UI\Control | |
{ | |
/** @var int */ | |
private $id; | |
/** | |
* @persistent | |
* @var string | |
*/ | |
public $tab = 'content'; | |
/** | |
* @param int | |
*/ | |
public function __construct($id) | |
{ | |
parent::__construct(); | |
$this->id = $id; | |
} | |
public function render() | |
{ | |
$this->template->id = $this->id; | |
$this->template->tab = $this->tab; | |
if (!$this->presenter->isAjax()) { | |
$this->template->setFile(__DIR__ . '/templates/Component.tabs.latte'); | |
} | |
$this->template->render(); | |
} | |
public function renderTab() | |
{ | |
$this->template->id = $this->id; | |
$this->template->tab = $this->tab; | |
$this->template->setFile(__DIR__ . '/templates/Component.' . $this->tab . '.latte'); | |
$this->template->render(); | |
} | |
public function handleChange($tab) | |
{ | |
if (!$this->presenter->isAjax()) { | |
$this->redirect('this'); | |
} | |
$this->invalidateControl('tab'); | |
$this->template->id = $this->id; | |
$this->template->tab = $tab; | |
$this->template->setFile(__DIR__ . "/templates/Component.$tab.latte"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function ($, undefined) { | |
$.nette.ext('tabs', { | |
load: function () { | |
$('[data-toggle="tab"]').off('show.nette'); | |
$('[data-toggle="tab"][href]').on('show.nette', function () { | |
var $header = $(this); | |
$.nette.ajax({ | |
url: $header.attr('href') | |
}).done(function (payload) { | |
$header.off('show.nette'); | |
$header.removeAttr('href'); | |
}); | |
}); | |
} | |
}); | |
$(function() { | |
$.nette.init(); | |
}); | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{foreach $components as $component} | |
<div id="component-{$component}"> | |
{control component-$component} | |
<div class="tab-content"> | |
{control "component-$component":tab} | |
</div> | |
</div> | |
{/foreach} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment