PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/atk4/lib/View/Tabs/jUItabs.php

https://github.com/mahimarathore/mahi
PHP | 79 lines | 44 code | 5 blank | 30 comment | 1 complexity | 95c8298f621abfcdb4d81116704e8f0a MD5 | raw file
Possible License(s): AGPL-3.0, MPL-2.0-no-copyleft-exception
  1. <?php // vim:ts=4:sw=4:et:fdm=marker
  2. /*
  3. * Undocumented
  4. *
  5. * @link http://agiletoolkit.org/
  6. *//*
  7. ==ATK4===================================================
  8. This file is part of Agile Toolkit 4
  9. http://agiletoolkit.org/
  10. (c) 2008-2013 Agile Toolkit Limited <info@agiletoolkit.org>
  11. Distributed under Affero General Public License v3 and
  12. commercial license.
  13. See LICENSE or LICENSE_COM for more information
  14. =====================================================ATK4=*/
  15. /**
  16. * Implementation of jQuery UI Tabs
  17. *
  18. * Use:
  19. * $tabs=$this->add('Tabs');
  20. * $tabs->addTab('Tab1')->add('LoremIpsum');
  21. *
  22. * $tabs->addTabURL('./details','Details'); // AJAX tab
  23. *
  24. * @license See http://agiletoolkit.org/about/license
  25. *
  26. **/
  27. class View_Tabs_jUItabs extends View_Tabs {
  28. public $tab_template=null;
  29. public $options=array('cache'=>false);
  30. function init(){
  31. parent::init();
  32. $this->tab_template=$this->template->cloneRegion('tabs');
  33. $this->template->del('tabs');
  34. }
  35. /* Set tabs option, for example, 'selected'=>'zero-based index of tab */
  36. function setOption($key,$value){
  37. $this->options[$key]=$value;
  38. return $this;
  39. }
  40. function render(){
  41. $this->js(true)
  42. ->tabs($this->options);
  43. return parent::render();
  44. }
  45. /* Add tab and returns it so that you can add static content */
  46. function addTab($title,$name=null){
  47. $container=$this->add('View_HtmlElement',$name);
  48. $this->tab_template->set(array(
  49. 'url'=>'#'.$container->name,
  50. 'tab_name'=>$title,
  51. 'tab_id'=>$container->short_name,
  52. ));
  53. $this->template->appendHTML('tabs',$this->tab_template->render());
  54. return $container;
  55. }
  56. /* Add tab which loads dynamically. Returns $this for chaining */
  57. function addTabURL($page,$title=null){
  58. if(is_null($title)){
  59. $title=ucwords(preg_replace('/[_\/\.]+/',' ',$page));
  60. }
  61. $this->tab_template->set(array(
  62. 'url'=>$this->api->url($page,array('cut_page'=>1)),
  63. 'tab_name'=>$title,
  64. 'tab_id'=>basename($page),
  65. ));
  66. $this->template->appendHTML('tabs',$this->tab_template->render());
  67. return $this;
  68. }
  69. function defaultTemplate(){
  70. return array('tabs');
  71. }
  72. }