v1.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace zin;
  3. class modalTrigger extends wg
  4. {
  5. /**
  6. * @var mixed[]
  7. */
  8. protected static $defineProps = array(
  9. 'target?:string',
  10. 'position?:string|int|object|function',
  11. 'size?:string|int|object',
  12. 'backdrop?:bool|string',
  13. 'keyboard?:bool',
  14. 'moveable?:bool',
  15. 'animation?:bool',
  16. 'transTime?:int',
  17. 'responsive?:bool',
  18. 'type?:string',
  19. 'loadingText?:string',
  20. 'loadTimeout?:int',
  21. 'failedTip?:string',
  22. 'timeoutTip?:string',
  23. 'title?:string',
  24. 'content?:string',
  25. 'custom?:object',
  26. 'url?:string',
  27. 'request?:object',
  28. 'dataType?:string'
  29. );
  30. /**
  31. * @var mixed[]
  32. */
  33. protected static $defineBlocks = array(
  34. 'trigger' => array('map' => 'btn,a'),
  35. 'modal' => array('map' => 'modal')
  36. );
  37. protected function build()
  38. {
  39. list($target, $url, $type) = $this->prop(['target', 'url', 'type']);
  40. $triggerBlock = $this->block('trigger');
  41. $modalBlock = $this->block('modal');
  42. if(empty($target) && !empty($modalBlock))
  43. {
  44. $modal = $modalBlock[0];
  45. $target = $modal->id();
  46. if(empty($target))
  47. {
  48. $target = $modal->gid;
  49. $modal->setProp('id', $target);
  50. }
  51. $target = "#$target";
  52. }
  53. if(!empty($url) && empty($type)) $type = 'ajax';
  54. if(empty($triggerBlock)) $triggerBlock = h::a($this->children());
  55. elseif(is_array($triggerBlock)) $triggerBlock = $triggerBlock[0];
  56. if($triggerBlock instanceof node)
  57. {
  58. $triggerBlock->setProp($this->getRestProps());
  59. $triggerProps = array(
  60. 'data-toggle' => 'modal',
  61. 'data-target' => $triggerBlock->hasProp('target', 'href') ? null : $target,
  62. 'data-type' => $type,
  63. 'data-url' => $url,
  64. 'data-position' => $this->prop('position'),
  65. 'data-size' => $this->prop('size'),
  66. 'data-backdrop' => $this->prop('backdrop'),
  67. 'data-keyboard' => $this->prop('keyboard'),
  68. 'data-moveable' => $this->prop('moveable'),
  69. 'data-animation' => $this->prop('animation'),
  70. 'data-trans-time' => $this->prop('transTime'),
  71. 'data-responsive' => $this->prop('responsive'),
  72. 'data-loading-text' => $this->prop('loadingText'),
  73. 'data-loadTimeout' => $this->prop('loadTimeout'),
  74. 'data-failed-tip' => $this->prop('failedTip'),
  75. 'data-timeout-tip' => $this->prop('timeoutTip'),
  76. 'data-title' => $this->prop('title'),
  77. 'data-content' => $this->prop('content'),
  78. 'data-custom' => $this->prop('custom'),
  79. 'data-request' => $this->prop('request'),
  80. 'data-data-type' => $this->prop('dataType')
  81. );
  82. $triggerBlock->setProp($triggerProps);
  83. }
  84. return array($triggerBlock, $modalBlock);
  85. }
  86. }