Guest User

Untitled

a guest
Feb 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. <?php
  2. $staticGroups = array();
  3. foreach($this->plxMotor->aStats as $staticId=>$staticPage) {
  4. if(
  5. intval($staticPage['active']) === 1 and
  6. // $staticPage['menu'] !== 'oui' and
  7. !empty(trim($staticPage['group']))
  8. ) {
  9. $group = $staticPage['group'];
  10. if(!array_key_exists($group, $staticGroups)) {
  11. $staticGroups[$group] = array();
  12. }
  13. $staticGroups[$group][] = array(
  14. 'url' => $this->plxMotor->urlRewrite('?static'.intval($staticId).'/'.$staticPage['url']),
  15. 'title' => $staticPage['name']
  16. );
  17. }
  18. }
  19. if(!empty($staticGroups)) {
  20. $content = implode("\n", array_map(
  21. function($group) {
  22. return <<< EOT
  23. <li><label for="id-stat-group-$group">$group</label></li>
  24. EOT;
  25. },
  26. array_keys($staticGroups)
  27. ));
  28. echo <<< EOT
  29. <ul class="tabs">
  30. $content
  31. </ul>\n
  32. EOT;
  33. ?>
  34. <div class="static-groups">
  35. <?php
  36. foreach($staticGroups as $group=>$pages) {
  37. $content = implode("\n", array_map(
  38. function($page) {
  39. return <<< EOT
  40. <li><a href="${page['url']}">${page['title']}</a></li>
  41. EOT;
  42. },
  43. $pages
  44. ));
  45.  
  46. echo <<< EOT
  47. <input type="radio" id="id-stat-group-$group" name="static-groups" />
  48. <ul>
  49. $content
  50. </ul>\n
  51. EOT;
  52. }
  53. ?>
  54. </div>
  55.  
  56. <style type="text/css">
  57. ul.tabs,
  58. div.static-groups > ul { list-style: none; }
  59. ul.tabs { display: flex; }
  60. ul.tabs li { padding: 0; }
  61. ul.tabs label { padding: 0 1rem; background-color: #ddd; }
  62. ul.tabs label.active { background-color: #444; color: #fff; }
  63. ul.tabs li:not(:first-of-type) { margin-left: 1rem; }
  64. div.static-groups > input[type="radio"],
  65. div.static-groups > input[type="radio"]:not(:checked) + ul { display: none; }
  66. </style>
  67.  
  68. <script type="text/javascript">
  69. (function() {
  70. 'use strict'
  71. const container = document.querySelector('div.static-groups');
  72. if(container != null) {
  73. container.addEventListener('change', function(event) {
  74. if(event.target.tagName == 'INPUT') {
  75. const activeTabs = document.querySelectorAll('ul.tabs label.active');
  76. for(var i=0, iMax=activeTabs.length; i<iMax; i++) {
  77. activeTabs[i].classList.remove('active');
  78. }
  79. document.querySelector('ul.tabs label[for="' + event.target.id + '"]').classList.add('active');
  80. }
  81. });
  82. document.querySelector('ul.tabs label:first-of-type').click();
  83. }
  84. })();
  85. </script>
  86. <?php
  87. }
  88. ?>
Add Comment
Please, Sign In to add comment