PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/lib/adianti/widget/container/TExpander.php

https://bitbucket.org/jacklan/bloglps
PHP | 122 lines | 69 code | 14 blank | 39 comment | 5 complexity | a5aefb197a5781ba8a69b636743dbf7f MD5 | raw file
  1. <?php
  2. namespace Adianti\Widget\Container;
  3. use Adianti\Widget\Base\TElement;
  4. use Adianti\Widget\Base\TScript;
  5. /**
  6. * Expander Widget
  7. *
  8. * @version 5.0
  9. * @package widget
  10. * @subpackage container
  11. * @author Pablo Dall'Oglio
  12. * @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  13. * @license http://www.adianti.com.br/framework-license
  14. */
  15. class TExpander extends TElement
  16. {
  17. private $container;
  18. private $button;
  19. private $caret_side;
  20. private $label;
  21. /**
  22. * Class Constructor
  23. * @param $value text label
  24. */
  25. public function __construct($label = '')
  26. {
  27. parent::__construct('div');
  28. $this->{'id'} = 'texpander_'.mt_rand(1000000000, 1999999999);
  29. $this->{'class'} = 'dropdown';
  30. $this->button = new TElement('button');
  31. $this->button->{'class'} = 'btn btn-default dropdown-toggle';
  32. $this->button->{'type'} = 'button';
  33. $this->button->{'id'} = 'button_'.mt_rand(1000000000, 1999999999);
  34. $this->button->{'data-toggle'} = 'dropdown';
  35. $this->label = $label;
  36. $this->container = new TElement('ul');
  37. $this->container->{'class'} = 'dropdown-menu texpander-container';
  38. $this->container->{'style'} = 'z-index: inherit';
  39. $this->container->{'aria-labelledby'} = $this->button->{'id'};
  40. parent::add($this->button);
  41. parent::add($this->container);
  42. }
  43. /**
  44. * Set caret side
  45. * @caret_side Caret side (left, right)
  46. */
  47. public function setCaretSide($caret_side)
  48. {
  49. $this->caret_side = $caret_side;
  50. }
  51. /**
  52. * Define the pull side
  53. * @side left/right
  54. */
  55. public function setPullSide($side)
  56. {
  57. $this->container->{'class'} = "dropdown-menu texpander-container pull-{$side}";
  58. }
  59. /**
  60. * Define a button property
  61. * @param $property Property name (Ex: style)
  62. * @param $value Property value
  63. */
  64. public function setButtonProperty($property, $value)
  65. {
  66. $this->button->$property = $value;
  67. }
  68. /**
  69. * Define a container property
  70. * @param $property Property name (Ex: style)
  71. * @param $value Property value
  72. */
  73. public function setProperty($property, $value)
  74. {
  75. $this->container->$property = $value;
  76. }
  77. /**
  78. * Add content to the expander
  79. * @param $content Any Object that implements show() method
  80. */
  81. public function add($content)
  82. {
  83. $this->container->add($content);
  84. }
  85. /**
  86. * Shows the expander
  87. */
  88. public function show()
  89. {
  90. if ($this->caret_side == 'left')
  91. {
  92. $this->button->add(TElement::tag('span', '', array('class'=>'caret')));
  93. $this->button->add($this->label);
  94. }
  95. else if ($this->caret_side == 'right')
  96. {
  97. $this->button->add($this->label);
  98. $this->button->add('&nbsp');
  99. $this->button->add(TElement::tag('span', '', array('class'=>'caret')));
  100. }
  101. else
  102. {
  103. $this->button->add($this->label);
  104. }
  105. parent::show();
  106. TScript::create('texpander_start();');
  107. }
  108. }