mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-14 09:44:55 +02:00
* colorful dynamic menus!
* and also: blank option for menus * NOTICE: Not all templates support that options yet
This commit is contained in:
7
system/migrations/23.php
Normal file
7
system/migrations/23.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
if(!$db->hasColumn(TABLE_PREFIX . 'menu', 'blank'))
|
||||
$db->query('ALTER TABLE `' . TABLE_PREFIX . 'menu` ADD `blank` TINYINT(1) NOT NULL DEFAULT 0 AFTER `link`;');
|
||||
|
||||
if(!$db->hasColumn(TABLE_PREFIX . 'menu', 'color'))
|
||||
$db->query('ALTER TABLE `' . TABLE_PREFIX . 'menu` ADD `color` CHAR(6) NOT NULL DEFAULT "ffffff" AFTER `blank`;');
|
@@ -22,6 +22,8 @@ if(isset($_REQUEST['template'])) {
|
||||
if(isset($_REQUEST['menu'])) {
|
||||
$post_menu = $_REQUEST['menu'];
|
||||
$post_menu_link = $_REQUEST['menu_link'];
|
||||
$post_menu_blank = $_REQUEST['menu_blank'];
|
||||
$post_menu_color = $_REQUEST['menu_color'];
|
||||
if(count($post_menu) != count($post_menu_link)) {
|
||||
echo 'Menu count is not equal menu links. Something went wrong when sending form.';
|
||||
return;
|
||||
@@ -34,7 +36,7 @@ if(isset($_REQUEST['template'])) {
|
||||
continue;
|
||||
|
||||
try {
|
||||
$db->insert(TABLE_PREFIX . 'menu', array('template' => $template, 'name' => $menu, 'link' => $post_menu_link[$category][$i], 'category' => $category, 'ordering' => $i));
|
||||
$db->insert(TABLE_PREFIX . 'menu', array('template' => $template, 'name' => $menu, 'link' => $post_menu_link[$category][$i], 'blank' => $post_menu_blank[$category][$i] == 'on', 'color' => str_replace('#', '', $post_menu_color[$category][$i]), 'category' => $category, 'ordering' => $i));
|
||||
}
|
||||
catch(PDOException $error) {
|
||||
warning('Error while adding menu item (' . $menu . '): ' . $error->getMessage());
|
||||
@@ -59,15 +61,18 @@ if(isset($_REQUEST['template'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo 'Hint: You can drag menu items.<br/>Editing: ' . $template . ' template.';
|
||||
echo 'Hint: You can drag menu items.<br/>
|
||||
Hint: Add links to external sites using: <b>http://</b> prefix.<br/>
|
||||
Not all templates support blank and colorful links.<br/>
|
||||
Editing: ' . $template . ' template.';
|
||||
$menus = array();
|
||||
$menus_db = $db->query('SELECT `name`, `link`, `category`, `ordering` FROM `' . TABLE_PREFIX . 'menu` WHERE `enabled` = 1 AND `template` = ' . $db->quote($template) . ' ORDER BY `ordering` ASC;')->fetchAll();
|
||||
$menus_db = $db->query('SELECT `name`, `link`, `blank`, `color`, `category`, `ordering` FROM `' . TABLE_PREFIX . 'menu` WHERE `enabled` = 1 AND `template` = ' . $db->quote($template) . ' ORDER BY `ordering` ASC;')->fetchAll();
|
||||
foreach($menus_db as $menu) {
|
||||
$menus[$menu['category']][] = array('name' => $menu['name'], 'link' => $menu['link'], 'ordering' => $menu['ordering']);
|
||||
$menus[$menu['category']][] = array('name' => $menu['name'], 'link' => $menu['link'], 'blank' => $menu['blank'], 'color' => $menu['color'], 'ordering' => $menu['ordering']);
|
||||
}
|
||||
|
||||
|
||||
$last_id = array();
|
||||
echo '<form method="post" action="?p=menus">';
|
||||
echo '<form method="post" id="menus-form" action="?p=menus">';
|
||||
echo '<input type="hidden" name="template" value="' . $template . '"/>';
|
||||
foreach($config['menu_categories'] as $id => $cat) {
|
||||
echo '<h2>' . $cat['name'] . '<img class="add-button" id="add-button-' . $id . '" src="' . BASE_URL . 'images/plus.png" width="16" height="16"/></h2>';
|
||||
@@ -75,7 +80,14 @@ if(isset($_REQUEST['template'])) {
|
||||
if(isset($menus[$id])) {
|
||||
$i = 0;
|
||||
foreach($menus[$id] as $menu) {
|
||||
echo '<li class="ui-state-default" id="list-' . $id . '-' . $i . '"><input type="text" name="menu[' . $id . '][]" value="' . $menu['name'] . '"/><input type="text" name="menu_link[' . $id . '][]" value="' . $menu['link'] . '"/><a class="remove-button" id="remove-button-' . $id . '-' . $i . '"><img src="' . BASE_URL . 'images/del.png"/></a></li>';
|
||||
echo '<li class="ui-state-default" id="list-' . $id . '-' . $i . '"><input type="text" name="menu[' . $id . '][]" value="' . $menu['name'] . '"/>
|
||||
<input type="text" name="menu_link[' . $id . '][]" value="' . $menu['link'] . '"/>
|
||||
<input type="hidden" name="menu_blank[' . $id . '][]" value="0" />
|
||||
<label><input class="blank-checkbox" type="checkbox" ' . ($menu['blank'] == 1 ? 'checked' : '') . '/><span title="Open in New Window">Blank</span></label>
|
||||
|
||||
<input class="color-picker" type="text" name="menu_color[' . $id . '][]" value="#' . $menu['color'] . '" />
|
||||
|
||||
<a class="remove-button" id="remove-button-' . $id . '-' . $i . '"><img src="' . BASE_URL . 'images/del.png"/></a></li>';
|
||||
|
||||
$i++;
|
||||
$last_id[$id] = $i;
|
||||
|
@@ -101,9 +101,10 @@ function get_template_menus() {
|
||||
global $db, $config, $template_name;
|
||||
|
||||
$menus = array();
|
||||
$query = $db->query('SELECT `name`, `link`, `category` FROM `' . TABLE_PREFIX . 'menu` WHERE `template` = ' . $db->quote($template_name) . ' ORDER BY `category`, `ordering` ASC');
|
||||
$query = $db->query('SELECT `name`, `link`, `blank`, `color`, `category` FROM `' . TABLE_PREFIX . 'menu` WHERE `template` = ' . $db->quote($template_name) . ' ORDER BY `category`, `ordering` ASC');
|
||||
foreach($query->fetchAll() as $menu) {
|
||||
$menus[$menu['category']][] = array('name' => $menu['name'], 'link' => $menu['link']);
|
||||
$link_full = strpos(trim($menu['link']), 'http') === 0 ? $menu['link'] : getLink($menu['link']);
|
||||
$menus[$menu['category']][] = array('name' => $menu['name'], 'link' => $menu['link'], 'link_full' => $link_full, 'blank' => $menu['blank'] == 1, 'color' => '#' . $menu['color']);
|
||||
}
|
||||
|
||||
$new_menus = array();
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<link rel="stylesheet" href="{{ constant('BASE_URL') }}tools/jquery-ui.min.css">
|
||||
<link type="text/css" rel="stylesheet" href="{{ constant('BASE_URL') }}tools/jquery-ui.min.css">
|
||||
<script src="{{ constant('BASE_URL') }}tools/jquery-ui.min.js"></script>
|
||||
<script>
|
||||
var last_id = [];
|
||||
@@ -18,16 +18,46 @@
|
||||
var cat = $(this).attr("id").replace('add-button-', '');
|
||||
var id = last_id[cat];
|
||||
last_id[cat]++;
|
||||
$('#sortable-' + cat).append('<li class="ui-state-default" id="list-' + cat + '-' + id + '"><input type="text" name="menu[' + cat + '][]" value=""/><input type="text" name="menu_link[' + cat + '][]" value=""/><a class="remove-button" id="remove-button-' + cat + '-' + id + '"><img src="{{ constant('BASE_URL') }}images/del.png"/></a></li>'); //add input bo
|
||||
$('#sortable-' + cat).append('<li class="ui-state-default" id="list-' + cat + '-' + id + '"><input type="text" name="menu[' + cat + '][]" value=""/> <input type="text" name="menu_link[' + cat + '][]" value=""/><input type="hidden" name="menu_blank[' + cat + '][]" value="0" /> <label><input class="blank-checkbox" type="checkbox"/><span title="Open in New Window">Blank</span></label> <input class="color-picker" type="text" name="menu_color[' + cat + '][]" value="#ffffff" /><a class="remove-button" id="remove-button-' + cat + '-' + id + '"><img src="{{ constant('BASE_URL') }}images/del.png"/></a></li>'); //add input bo
|
||||
$('#remove-button-' + cat + '-' + id).click(function() {
|
||||
$('#list-' + $(this).attr("id").replace('remove-button-', '')).remove();
|
||||
});
|
||||
|
||||
initialiceSpectrum();
|
||||
});
|
||||
|
||||
$("#menus-form").submit(function(e) {
|
||||
$('.blank-checkbox:not(:checked)').each(function(i, obj) {
|
||||
$(obj).parent().prev().val("off");
|
||||
});
|
||||
|
||||
$('.blank-checkbox:checked').each(function(i, obj) {
|
||||
$(obj).parent().prev().val("on");
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
.sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
|
||||
<style type="text/css">
|
||||
.sortable { list-style-type: none; margin: 0; padding: 0; width: 100%; }
|
||||
.remove-button, .add-button {
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
<script type="text/javascript" src="{{ constant('BASE_URL') }}tools/spectrum.js"></script>
|
||||
<link type="text/css" rel="stylesheet" href="{{ constant('BASE_URL') }}tools/spectrum.css" />
|
||||
<script type="text/javascript">
|
||||
initialiceSpectrum();
|
||||
function initialiceSpectrum() {
|
||||
$(".color-picker").spectrum({
|
||||
preferredFormat: "hex",
|
||||
showInput: true,
|
||||
showPalette: true,
|
||||
palette: [
|
||||
['black', 'white', 'blanchedalmond',
|
||||
'rgb(255, 128, 0);', 'hsv 100 70 50'],
|
||||
['red', 'yellow', 'green', 'blue', 'violet']
|
||||
]
|
||||
});
|
||||
}
|
||||
</script>
|
Reference in New Issue
Block a user