menu.html.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <?php if (!defined('HTMLY')) die('HTMLy'); ?>
  2. <?php
  3. $menu = '';
  4. $filename = "content/data/menu.json";
  5. if (file_exists($filename)) {
  6. $json = json_decode(file_get_contents('content/data/menu.json', true));
  7. $menus = json_decode($json);
  8. if (!empty($menus)) {
  9. $menu = parseMenus($menus);
  10. }
  11. }
  12. function parseMenus($menus) {
  13. $ol = '<ol class="dd-list">';
  14. foreach ($menus as $menu) {
  15. $ol .= parseMenu($menu);
  16. }
  17. $ol .= '</ol>';
  18. return $ol;
  19. }
  20. function parseMenu($menu) {
  21. $target = !empty($menu->target) ? 'data-target="'.$menu->target.'"' : null;
  22. $li = '<li class="dd-item" data-class="'. $menu->class .'" data-id="'. $menu->id .'" data-name="'.$menu->name.'" '.$target.' data-slug="'.htmlspecialchars($menu->slug, FILTER_SANITIZE_URL).'">';
  23. $li .= '<div class="dd-handle">'.$menu->name.'</div>';
  24. $li .= '<span class="button-delete btn btn-danger btn-xs" style="margin-right:0.5rem" data-owner-id="'.$menu->id.'">'.i18n('Delete').'</span>';
  25. $li .= '<span class="button-edit btn btn-primary btn-xs" data-owner-id="'.$menu->id.'">'.i18n('Edit').'</span>';
  26. if (isset($menu->children)) {
  27. $li .= parseMenus($menu->children);
  28. }
  29. $li .= '</li>';
  30. return $li;
  31. }
  32. ?>
  33. <div class="row">
  34. <div class="col-md-6">
  35. <div class="dd nestable"><?php if (!empty($menu)) {echo '<h2>Drag & Drop</h2><br>'. $menu;} else {echo '<span>'.i18n('At_the_moment_you_are_using_auto_generated_menu').'</span><ol class="dd-list"></ol>';}?></div>
  36. </div>
  37. <div class="col-md-6">
  38. <form id="menu-add">
  39. <h4><?php echo i18n('Add_menu');?></h4>
  40. <div class="form-group">
  41. <label for="addInputName"><?php echo i18n('Name');?></label>
  42. <input type="text" class="form-control" id="addInputName" placeholder="<?php echo i18n('Link_name')?>" required>
  43. </div>
  44. <div class="form-group">
  45. <label for="addInputSlug"><?php echo i18n('Slug');?></label>
  46. <input type="text" class="form-control" id="addInputSlug" placeholder="<?php echo i18n('item_slug');?>" required>
  47. </div>
  48. <div class="form-group">
  49. <label for="addInputTarget">Target (<?php echo i18n('optional');?>)</label>
  50. <input type="text" class="form-control" id="addInputTarget" placeholder="_blank, _self, _parent etc.">
  51. </div>
  52. <div class="form-group">
  53. <label for="addInputClass"><?php echo i18n('CSS_Class_Optional');?></label>
  54. <input type="text" class="form-control" id="addInputClass" placeholder="<?php echo i18n('item_class');?>">
  55. </div>
  56. <button class="btn btn-primary btn-sm" id="addButton"><?php echo i18n('Add_link');?></button>
  57. </form>
  58. <form id="menu-editor" style="display: none;">
  59. <h4>Editing <span id="currentEditName"></span></h4>
  60. <div class="form-group">
  61. <label for="editInputName"><?php echo i18n('Name')?></label>
  62. <input type="text" class="form-control" id="editInputName" placeholder="<?php echo i18n('Link_name')?>" required>
  63. </div>
  64. <div class="form-group">
  65. <label for="editInputSlug"><?php echo i18n('Slug');?></label>
  66. <input type="text" class="form-control" id="editInputSlug" placeholder="<?php echo i18n('item_slug');?>">
  67. </div>
  68. <div class="form-group">
  69. <label for="editInputTarget">Target (<?php echo i18n('optional');?>)</label>
  70. <input type="text" class="form-control" id="editInputTarget" placeholder="_blank, _self, _parent etc.">
  71. </div>
  72. <div class="form-group">
  73. <label for="editInputClass"><?php echo i18n('CSS_Class_Optional');?></label>
  74. <input type="text" class="form-control" id="editInputClass" placeholder="<?php echo i18n('item_class');?>">
  75. </div>
  76. <button class="btn btn-primary btn-sm" id="editButton"><?php echo i18n('Save_Edit');?></button>
  77. </form>
  78. </div>
  79. </div>
  80. <div class="row">
  81. <div class="output-container">
  82. <div class="col">
  83. <button class="btn btn-primary" id="saveButton"><?php echo i18n('Save_Menu');?></button>
  84. <form class="form" style="display:none;">
  85. <textarea class="form-control" id="json-output" rows="5"></textarea>
  86. </form>
  87. </div>
  88. </div>
  89. </div>
  90. <script src="<?php echo site_url() ?>system/resources/js/jquery.nestable.js"></script>
  91. <script src="<?php echo site_url() ?>system/resources/js/jquery.nestable++.js"></script>
  92. <script>
  93. $('.dd.nestable').nestable({
  94. maxDepth: 2
  95. })
  96. .on('change', updateOutput);
  97. $('#addMenu').click(function() {
  98. $('#menu-add').fadeIn();
  99. });
  100. $("#saveButton").click(function(){
  101. updateOutput($('.dd.nestable').data('output', $('#json-output')));
  102. var js = $('#json-output').val();
  103. $.ajax({
  104. type: 'POST',
  105. url: '<?php echo site_url();?>admin/menu',
  106. dataType: 'json',
  107. data: {'json': js},
  108. success: function (response) {
  109. alert(response.message);
  110. location.reload();
  111. },
  112. });
  113. });
  114. </script>
  115. <style>
  116. /**
  117. * Nestable css
  118. */
  119. .dd {
  120. position: relative;
  121. display: block;
  122. margin: 0;
  123. padding: 0;
  124. max-width: 600px;
  125. list-style: none;
  126. font-size: 13px;
  127. line-height: 20px;
  128. }
  129. .dd-list {
  130. display: block;
  131. position: relative;
  132. margin: 0;
  133. padding: 0;
  134. list-style: none;
  135. }
  136. .dd-list .dd-list {
  137. padding-left: 30px;
  138. }
  139. .dd-collapsed .dd-list {
  140. display: none;
  141. }
  142. .dd-item,
  143. .dd-empty,
  144. .dd-placeholder {
  145. display: block;
  146. position: relative;
  147. margin: 0;
  148. padding: 0;
  149. min-height: 20px;
  150. font-size: 13px;
  151. line-height: 20px;
  152. }
  153. .dd-handle {
  154. display: block;
  155. margin: 5px 0;
  156. padding: 5px 10px;
  157. color: #333;
  158. text-decoration: none;
  159. font-weight: bold;
  160. border: 1px solid #ccc;
  161. background: #fafafa;
  162. background: -webkit-linear-gradient(top, #fafafa 0%, #eee 100%);
  163. background: -moz-linear-gradient(top, #fafafa 0%, #eee 100%);
  164. background: linear-gradient(top, #fafafa 0%, #eee 100%);
  165. -webkit-border-radius: 3px;
  166. border-radius: 3px;
  167. box-sizing: border-box;
  168. -moz-box-sizing: border-box;
  169. cursor: move;
  170. }
  171. .dd-handle:hover {
  172. color: #2ea8e5;
  173. background: #fff;
  174. }
  175. .dd-item > button {
  176. display: block;
  177. position: relative;
  178. cursor: pointer;
  179. float: left;
  180. width: 25px;
  181. height: 20px;
  182. margin: 5px 0;
  183. padding: 0;
  184. text-indent: 100%;
  185. white-space: nowrap;
  186. overflow: hidden;
  187. border: 0;
  188. background: transparent;
  189. font-size: 12px;
  190. line-height: 1;
  191. text-align: center;
  192. font-weight: bold;
  193. }
  194. .dd-item > button:before {
  195. content: '+';
  196. display: block;
  197. position: absolute;
  198. width: 100%;
  199. text-align: center;
  200. text-indent: 0;
  201. }
  202. .dd-item > button[data-action="collapse"]:before {
  203. content: '-';
  204. }
  205. .dd-placeholder,
  206. .dd-empty {
  207. margin: 5px 0;
  208. padding: 0;
  209. min-height: 30px;
  210. background: #f2fbff;
  211. border: 1px dashed #b6bcbf;
  212. box-sizing: border-box;
  213. -moz-box-sizing: border-box;
  214. }
  215. .dd-empty {
  216. border: 1px dashed #bbb;
  217. min-height: 100px;
  218. background-color: #e5e5e5;
  219. background-image: -webkit-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
  220. -webkit-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
  221. background-image: -moz-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
  222. -moz-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
  223. background-image: linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
  224. linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
  225. background-size: 60px 60px;
  226. background-position: 0 0, 30px 30px;
  227. }
  228. .dd-dragel {
  229. position: absolute;
  230. pointer-events: none;
  231. z-index: 9999;
  232. }
  233. .dd-dragel > .dd-item .dd-handle {
  234. margin-top: 0;
  235. }
  236. .dd-dragel .dd-handle {
  237. -webkit-box-shadow: 2px 4px 6px 0 rgba(0, 0, 0, .1);
  238. box-shadow: 2px 4px 6px 0 rgba(0, 0, 0, .1);
  239. }
  240. /**
  241. * Nestable Extras
  242. */
  243. .nestable-lists {
  244. display: block;
  245. clear: both;
  246. padding: 30px 0;
  247. width: 100%;
  248. border: 0;
  249. border-top: 2px solid #ddd;
  250. border-bottom: 2px solid #ddd;
  251. }
  252. #nestable-menu {
  253. padding: 0;
  254. margin: 20px 0;
  255. }
  256. #nestable-output,
  257. #nestable2-output {
  258. width: 100%;
  259. height: 7em;
  260. font-size: 0.75em;
  261. line-height: 1.333333em;
  262. font-family: Consolas, monospace;
  263. padding: 5px;
  264. box-sizing: border-box;
  265. -moz-box-sizing: border-box;
  266. }
  267. #nestable2 .dd-handle {
  268. color: #fff;
  269. border: 1px solid #999;
  270. background: #bbb;
  271. background: -webkit-linear-gradient(top, #bbb 0%, #999 100%);
  272. background: -moz-linear-gradient(top, #bbb 0%, #999 100%);
  273. background: linear-gradient(top, #bbb 0%, #999 100%);
  274. }
  275. #nestable2 .dd-handle:hover {
  276. background: #bbb;
  277. }
  278. #nestable2 .dd-item > button:before {
  279. color: #fff;
  280. }
  281. .dd {
  282. // float: left;
  283. // width: 48 %;
  284. width: 80%;
  285. }
  286. .dd + .dd {
  287. margin-left: 2%;
  288. }
  289. .dd-hover > .dd-handle {
  290. background: #2ea8e5 !important;
  291. }
  292. /**
  293. * Nestable Draggable Handles
  294. */
  295. .dd3-content {
  296. display: block;
  297. height: 30px;
  298. margin: 5px 0;
  299. padding: 5px 10px 5px 40px;
  300. color: #333;
  301. text-decoration: none;
  302. font-weight: bold;
  303. border: 1px solid #ccc;
  304. background: #fafafa;
  305. background: -webkit-linear-gradient(top, #fafafa 0%, #eee 100%);
  306. background: -moz-linear-gradient(top, #fafafa 0%, #eee 100%);
  307. background: linear-gradient(top, #fafafa 0%, #eee 100%);
  308. -webkit-border-radius: 3px;
  309. border-radius: 3px;
  310. box-sizing: border-box;
  311. -moz-box-sizing: border-box;
  312. }
  313. .dd3-content:hover {
  314. color: #2ea8e5;
  315. background: #fff;
  316. }
  317. .dd-dragel > .dd3-item > .dd3-content {
  318. margin: 0;
  319. }
  320. .dd3-item > button {
  321. margin-left: 30px;
  322. }
  323. .dd3-handle {
  324. position: absolute;
  325. margin: 0;
  326. left: 0;
  327. top: 0;
  328. cursor: pointer;
  329. width: 30px;
  330. text-indent: 100%;
  331. white-space: nowrap;
  332. overflow: hidden;
  333. border: 1px solid #aaa;
  334. background: #ddd;
  335. background: -webkit-linear-gradient(top, #ddd 0%, #bbb 100%);
  336. background: -moz-linear-gradient(top, #ddd 0%, #bbb 100%);
  337. background: linear-gradient(top, #ddd 0%, #bbb 100%);
  338. border-top-right-radius: 0;
  339. border-bottom-right-radius: 0;
  340. }
  341. .dd3-handle:before {
  342. content: '≡';
  343. display: block;
  344. position: absolute;
  345. left: 0;
  346. top: 3px;
  347. width: 100%;
  348. text-align: center;
  349. text-indent: 0;
  350. color: #fff;
  351. font-size: 20px;
  352. font-weight: normal;
  353. }
  354. .dd3-handle:hover {
  355. background: #ddd;
  356. }
  357. /*
  358. * Nestable++
  359. */
  360. .button-delete {
  361. position: absolute;
  362. top: 4px;
  363. right: 40px;
  364. }
  365. .button-edit {
  366. position: absolute;
  367. top: 4px;
  368. right: 5px;
  369. }
  370. #saveButton {
  371. padding-right: 30px;
  372. padding-left: 30px;
  373. }
  374. .output-container {
  375. margin-top: 20px;
  376. }
  377. #json-output {
  378. margin-top: 20px;
  379. }
  380. </style>