Skip to content

Instantly share code, notes, and snippets.

@vojtech-dobes
Created September 15, 2012 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vojtech-dobes/3725831 to your computer and use it in GitHub Desktop.
Save vojtech-dobes/3725831 to your computer and use it in GitHub Desktop.
<div n:class="tab-pane, $tab == 'content' ? active" id="component-{$id}-{$tab}">
{snippet tab}
{include #content}
{/snippet}
</div>
{extends @Component.layout.latte}
{block #content}
<h2>Component {$id} - content</h2>
<p>Lorem ipsum dolor sit amet</p>
<div class="tab-pane active" id="component-{$id}-tab">
{snippet tab}
{include #content}
{/snippet}
</div>
<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>
<?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");
}
}
(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);
{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