v1.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace zin;
  3. class productMenu extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'title?:string',
  10. 'items?:array',
  11. 'activeKey?:string',
  12. 'link?:string',
  13. 'leading?:bool=true'
  14. );
  15. public static function getPageCSS()
  16. {
  17. return file_get_contents(__DIR__ . DS . 'css' . DS . 'v1.css');
  18. }
  19. private function buildMenu()
  20. {
  21. $items = $this->prop('items');
  22. $menus = array();
  23. foreach($items as $itemKey => $item)
  24. {
  25. if(is_array($item))
  26. {
  27. $menus[] = $item;
  28. continue;
  29. }
  30. $menus[] = array('text' => $item, 'key' => $itemKey);
  31. }
  32. return $menus;
  33. }
  34. private function getTitle()
  35. {
  36. global $lang;
  37. $activeKey = $this->prop('activeKey');
  38. $title = $this->prop('title');
  39. if(empty($activeKey) && empty($title)) return $lang->product->all;
  40. $items = $this->prop('items');
  41. foreach($items as $itemID => $itemName)
  42. {
  43. if($itemID == $activeKey) return $itemName;
  44. }
  45. return $title;
  46. }
  47. protected function build()
  48. {
  49. $items = $this->buildMenu();
  50. $activeKey = $this->prop('activeKey');
  51. $link = $this->prop('link');
  52. $leading = $this->prop('leading');
  53. $title = $this->getTitle();
  54. $closeLink = str_replace('{key}', '', $link);
  55. return zui::dropmenu
  56. (
  57. set('_id', 'productMenu'),
  58. set::_className('product-menu btn clip'),
  59. set::defaultValue($activeKey),
  60. set::text($title),
  61. set::caret(true),
  62. set::leadingAngle($leading),
  63. set::popWidth(200),
  64. set::popClass('popup text-md'),
  65. set::onClick(jsRaw("(event) => {if(!event.target.closest('.is-caret')) return; openUrl('$closeLink'); return false}")),
  66. set::data(array('search' => false, 'checkIcon' => false, 'link' => $link, 'data' => $items))
  67. );
  68. }
  69. }