v1.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace zin;
  3. class popovers extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'placement?: string="bottom"', // 位置
  10. 'strategy?: string="fixed"', // 定位类型
  11. 'flip?: bool=true', // 是否启用 flip
  12. 'shift?: array|bool', // 是否启用 shift
  13. 'arrow?: bool=false', // 是否启用箭头
  14. 'offset?: int=1' // 偏移量
  15. );
  16. /**
  17. * @var mixed[]
  18. */
  19. protected static $defaultProps = array(
  20. 'shift' => array('padding' => 5)
  21. );
  22. /**
  23. * @var mixed[]
  24. */
  25. protected static $defineBlocks = array(
  26. 'trigger' => array(),
  27. 'target' => array()
  28. );
  29. protected function build()
  30. {
  31. $trigger = $this->block('trigger')[0]->children()[0];
  32. $target = $this->block('target')[0];
  33. if(!($target instanceof \zin\zui)) $target = $target->children()[0];
  34. $trigger->setProp('data-zin-id', $trigger->gid);
  35. $trigger->setProp('data-target', "[data-zin-id='{$target->gid}']");
  36. $target->setProp('data-zin-id', $target->gid);
  37. $props = array_merge($this->props->pick(array('placement', 'strategy', 'flip', 'shift', 'arrow', 'offset')), array('_to' => "[data-zin-id='{$trigger->gid}']"));
  38. return array(
  39. $trigger,
  40. $target,
  41. zui::popovers(set($props))
  42. );
  43. }
  44. }