first commit
This commit is contained in:
@@ -0,0 +1,209 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class FW_Extension_Megamenu extends FW_Extension
|
||||
{
|
||||
public function render_str($rel, $param = array())
|
||||
{
|
||||
return $this->render_view($rel, $param);
|
||||
}
|
||||
|
||||
public function render($rel, $param = array())
|
||||
{
|
||||
$this->render_view($rel, $param, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if menu icon is enabled (checked in Screen Options on admin Menus page)
|
||||
* @return bool
|
||||
*/
|
||||
public function show_icon()
|
||||
{
|
||||
return !in_array('icon', (array) get_user_option('manage' . 'nav-menus' . 'columnshidden'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _init() {
|
||||
add_action('wp_update_nav_menu_item', array($this, '_admin_action_wp_update_nav_menu_item'), 10, 3);
|
||||
add_action('admin_enqueue_scripts', array($this, '_admin_action_admin_enqueue_scripts'));
|
||||
add_action('wp_ajax_fw_ext_megamenu_item_values', array($this, '_action_ajax_item_values'));
|
||||
|
||||
add_filter('wp_edit_nav_menu_walker', array($this, '_admin_filter_wp_edit_nav_menu_walker'));
|
||||
add_filter('manage_nav-menus_columns', array($this, '_admin_filter_manage_nav_menus_columns'), 20);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _admin_action_admin_enqueue_scripts($hook)
|
||||
{
|
||||
if ($hook != 'nav-menus.php') {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_media(); // required for modal
|
||||
|
||||
wp_enqueue_style(
|
||||
"fw-ext-{$this->get_name()}-admin",
|
||||
$this->get_uri('/static/css/admin.css'),
|
||||
array(),
|
||||
$this->manifest->get_version()
|
||||
);
|
||||
wp_enqueue_script(
|
||||
"fw-ext-{$this->get_name()}-admin",
|
||||
$this->get_uri('/static/js/admin.js'),
|
||||
array('fw'),
|
||||
$this->manifest->get_version()
|
||||
);
|
||||
|
||||
{
|
||||
$items_options = $items_options_modal_sizes = array();
|
||||
|
||||
foreach (array('row', 'column', 'item', 'default') as $type) {
|
||||
$items_options[$type] = $this->get_options($type);
|
||||
$items_options_modal_sizes[$type] = $this->get_config('item-options:popup-size:'. $type);
|
||||
|
||||
// Enqueue assets for item options
|
||||
fw()->backend->enqueue_options_static($items_options[$type]);
|
||||
}
|
||||
}
|
||||
|
||||
$icon_option = apply_filters('fw:ext:megamenu:icon-option', array(
|
||||
'type' => 'icon',
|
||||
'label' => __('Select Icon', 'fw'),
|
||||
));
|
||||
fw()->backend->option_type($icon_option['type'])->enqueue_static();
|
||||
|
||||
wp_localize_script(
|
||||
"fw-ext-{$this->get_name()}-admin",
|
||||
'_fw_ext_mega_menu',
|
||||
array(
|
||||
'l10n' => array(
|
||||
'item_options_btn' => apply_filters('fw:ext:megamenu:label:item-options-btn', __('Settings', 'fw')),
|
||||
),
|
||||
'icon_option' => $icon_option,
|
||||
'options' => $items_options,
|
||||
'item_options_modal_sizes' => $items_options_modal_sizes,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _admin_action_wp_update_nav_menu_item($menu_id, $menu_item_db_id, $args)
|
||||
{
|
||||
if (!isset($_POST['menu']) || !isset($_POST['action'])) {
|
||||
return; // this is not a form submit
|
||||
}
|
||||
|
||||
// Save hardcoded options
|
||||
{
|
||||
$meta = _fw_ext_mega_menu_admin_input_POST_values($menu_item_db_id);
|
||||
$meta = array(
|
||||
'enabled' => (
|
||||
isset($meta['enabled'])
|
||||
&&
|
||||
// only first level items can have "Enable as MegaMenu" checkbox
|
||||
!intval(get_post_meta( $menu_item_db_id, '_menu_item_menu_item_parent', true ))
|
||||
),
|
||||
'title-off' => isset($meta['title-off']),
|
||||
'new-row' => isset($meta['new-row']),
|
||||
'icon' => isset($meta['icon']) ? (string)$meta['icon'] : '',
|
||||
);
|
||||
|
||||
fw_ext_mega_menu_update_meta($menu_item_db_id, $meta);
|
||||
}
|
||||
|
||||
// Save item custom options
|
||||
if (
|
||||
$this->get_options('row') ||
|
||||
$this->get_options('column') ||
|
||||
$this->get_options('item') ||
|
||||
$this->get_options('default')
|
||||
) {
|
||||
$item_values = fw_ext_mega_menu_get_db_item_option($menu_item_db_id);
|
||||
|
||||
if (isset($_POST['fw-megamenu-items-values'])) {
|
||||
// cache to prevent json_decode() on every item save
|
||||
try {
|
||||
$decoded_values = FW_Cache::get($cache_key = 'fw:ext:megamenu:POST-items-values-decoded');
|
||||
} catch (FW_Cache_Not_Found_Exception $e) {
|
||||
FW_Cache::set(
|
||||
$cache_key,
|
||||
$decoded_values = json_decode(FW_Request::POST('fw-megamenu-items-values'), true)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($decoded_values[$menu_item_db_id])) {
|
||||
$item_values = array_merge(
|
||||
$item_values,
|
||||
$decoded_values[$menu_item_db_id]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($level = fw_ext_mega_menu_is_mm_item($menu_item_db_id)) {
|
||||
if ($level === 1) {
|
||||
$item_values['type'] = 'row';
|
||||
} elseif ($level === 2) {
|
||||
$item_values['type'] = 'column';
|
||||
} else {
|
||||
$item_values['type'] = 'item';
|
||||
}
|
||||
} else {
|
||||
$item_values['type'] = 'default';
|
||||
}
|
||||
|
||||
if (
|
||||
empty($decoded_values[$menu_item_db_id])
|
||||
&&
|
||||
!FW_WP_Meta::get( 'post', $menu_item_db_id, FW_Db_Options_Model_MegaMenu::get_meta_name(), false)
|
||||
) {
|
||||
// Don't create an useless meta for all menu items if they were never saved
|
||||
} else {
|
||||
fw_ext_mega_menu_set_db_item_option($menu_item_db_id, null, $item_values);
|
||||
}
|
||||
} elseif (FW_WP_Meta::get( 'post', $menu_item_db_id, FW_Db_Options_Model_MegaMenu::get_meta_name(), false)) {
|
||||
// Orphan meta that needs to be deleted because there are no item options
|
||||
delete_post_meta($menu_item_db_id, FW_Db_Options_Model_MegaMenu::get_meta_name());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _admin_filter_wp_edit_nav_menu_walker()
|
||||
{
|
||||
return 'FW_Ext_Mega_Menu_Admin_Walker';
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _admin_filter_manage_nav_menus_columns($columns)
|
||||
{
|
||||
$columns['icon'] = __('Icon', 'fw');
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function _get_link()
|
||||
{
|
||||
return self_admin_url('nav-menus.php');
|
||||
}
|
||||
|
||||
public function _action_ajax_item_values() {
|
||||
if (!current_user_can('manage_options')) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
wp_send_json_success(array(
|
||||
'values' => fw_ext_mega_menu_get_db_item_option(intval($_POST['id']))
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
$cfg = array();
|
||||
|
||||
$cfg['item-options:popup-size:row'] = 'small'; // small, medium, large
|
||||
$cfg['item-options:popup-size:column'] = 'small';
|
||||
$cfg['item-options:popup-size:item'] = 'small';
|
||||
$cfg['item-options:popup-size:default'] = 'small';
|
||||
@@ -0,0 +1,198 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* @param int|object $post
|
||||
* @param $key
|
||||
* @param null $default
|
||||
* @return mixed
|
||||
*/
|
||||
function fw_ext_mega_menu_get_meta($post, $key, $default = null) {
|
||||
return _fw_ext_mega_menu_meta($post, $key, $default);
|
||||
}
|
||||
|
||||
function fw_ext_mega_menu_update_meta($post, array $array) {
|
||||
return _fw_ext_mega_menu_meta($post, $array, null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if menu item is a MegaMenu item or is inside a MegaMenu item
|
||||
* @param WP_Post $item
|
||||
* @return bool
|
||||
*/
|
||||
function fw_ext_mega_menu_is_mm_item($item) {
|
||||
if (!is_object($item)) {
|
||||
if ($item = get_post($item)) {
|
||||
$item = wp_setup_nav_menu_item($item);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$mm_items = FW_Cache::get( $cache_key = fw_ext('megamenu')->get_cache_key('/mm_item') );
|
||||
} catch (FW_Cache_Not_Found_Exception $e) {
|
||||
$mm_items = array();
|
||||
}
|
||||
|
||||
if (array_key_exists($item->ID, $mm_items)) {
|
||||
return $mm_items[$item->ID];
|
||||
}
|
||||
|
||||
$level = 0;
|
||||
$cursor_item = array(
|
||||
'id' => $item->ID,
|
||||
'parent' => intval($item->menu_item_parent),
|
||||
);
|
||||
|
||||
do {
|
||||
++$level;
|
||||
$mm_items[ $cursor_item['id'] ] = 0; // cache all parsed items to prevent posts query on next function call
|
||||
} while(
|
||||
/**
|
||||
* Only first level parent item can have the "Use as MegaMenu" checkbox.
|
||||
* Other level items also can have set this checkbox when they were on first level,
|
||||
* but it is hidden and must be ignored.
|
||||
*/
|
||||
$cursor_item['parent'] !== 0
|
||||
&&
|
||||
($cursor_item = get_post($cursor_item['parent']))
|
||||
&&
|
||||
($cursor_item = array(
|
||||
'id' => $cursor_item->ID,
|
||||
'parent' => intval(get_post_meta( $cursor_item->ID, '_menu_item_menu_item_parent', true ))
|
||||
))
|
||||
);
|
||||
|
||||
$mm_items[$item->ID] = (fw_ext_mega_menu_get_meta($cursor_item['id'], 'enabled') ? $level : 0);
|
||||
|
||||
FW_Cache::set($cache_key, $mm_items);
|
||||
|
||||
return $mm_items[$item->ID];
|
||||
}
|
||||
|
||||
/**
|
||||
* Item Options
|
||||
* @since 1.1.0
|
||||
*/
|
||||
class FW_Db_Options_Model_MegaMenu extends FW_Db_Options_Model {
|
||||
protected function get_id()
|
||||
{
|
||||
return 'megamenu';
|
||||
}
|
||||
|
||||
protected function get_fw_storage_params($item_id, array $extra_data = array()) {
|
||||
return array( 'megamenu-item' => $item_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FW_Extension_Megamenu
|
||||
*/
|
||||
private function ext() {
|
||||
return fw_ext('megamenu');
|
||||
}
|
||||
|
||||
protected function _get_cache_key($key, $item_id, array $extra_data = array())
|
||||
{
|
||||
if ($key === 'options') {
|
||||
return '';
|
||||
} else {
|
||||
return parent::_get_cache_key($key, $item_id, $extra_data);
|
||||
}
|
||||
}
|
||||
|
||||
protected function get_options($item_id, array $extra_data = array())
|
||||
{
|
||||
$options = array(
|
||||
'type' => array('type' => 'text') // one of the below types
|
||||
);
|
||||
|
||||
foreach (array('row', 'column', 'item', 'default') as $type) {
|
||||
$options[$type] = array(
|
||||
'type' => 'multi',
|
||||
'inner-options' => $this->ext()->get_options($type),
|
||||
);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use theme in meta name
|
||||
* so when the user will change the theme which has other options, there will be no notices/errors/conflicts
|
||||
* @return string
|
||||
*/
|
||||
public static function get_meta_name() {
|
||||
try {
|
||||
return FW_Cache::get($cache_key = 'fw:ext:megamenu:items-options:meta-name');
|
||||
} catch (FW_Cache_Not_Found_Exception $e) {
|
||||
FW_Cache::set(
|
||||
$cache_key,
|
||||
/**
|
||||
* Use basename() because it can be 'theme-name/theme-name-parent'
|
||||
* then after theme update it becomes 'theme-name-parent'
|
||||
*/
|
||||
$meta_name = 'fw:ext:mm:io:' . basename(get_template())
|
||||
);
|
||||
|
||||
return $meta_name;
|
||||
}
|
||||
}
|
||||
|
||||
protected function get_values($item_id, array $extra_data = array())
|
||||
{
|
||||
return FW_WP_Meta::get( 'post', $item_id, self::get_meta_name(), array() );
|
||||
}
|
||||
|
||||
protected function set_values($item_id, $values, array $extra_data = array())
|
||||
{
|
||||
return FW_WP_Meta::set( 'post', $item_id, self::get_meta_name(), $values );
|
||||
}
|
||||
|
||||
protected function _init()
|
||||
{
|
||||
/**
|
||||
* Get item option value from the database
|
||||
*
|
||||
* @param int $item
|
||||
* @param string|null $option_id 'type/option_id' (accepts multikey). null - all options
|
||||
* @param null|mixed $default_value If no option found in the database, this value will be returned
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
function fw_ext_mega_menu_get_db_item_option($item, $option_id = null, $default_value = null) {
|
||||
/*if ( ! $item ) {
|
||||
global $post;
|
||||
|
||||
if ( ! $post || $post->post_type != 'nav_menu_item' ) {
|
||||
return $default_value;
|
||||
} else {
|
||||
$item = $post;
|
||||
}
|
||||
} elseif ( ! $item instanceof WP_Post ) {
|
||||
if (
|
||||
($post = get_post($item))
|
||||
&&
|
||||
$post->post_type == 'nav_menu_item'
|
||||
) {
|
||||
$item = $post;
|
||||
} else {
|
||||
return $default_value;
|
||||
}
|
||||
}*/
|
||||
|
||||
return FW_Db_Options_Model::_get_instance('megamenu')->get(intval($item), $option_id, $default_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set item option value in database
|
||||
*
|
||||
* @param int $item
|
||||
* @param string|null $option_id 'type/option_id' (accepts multikey). null - all options
|
||||
* @param $value
|
||||
*/
|
||||
function fw_ext_mega_menu_set_db_item_option( $item, $option_id = null, $value ) {
|
||||
return FW_Db_Options_Model::_get_instance('megamenu')->set(intval($item), $option_id, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
new FW_Db_Options_Model_MegaMenu();
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
* @return array
|
||||
* @internal
|
||||
*/
|
||||
function _filter_fw_ext_mega_menu_wp_nav_menu_args($args) {
|
||||
// nav-menu-template.php L271
|
||||
// $args['menu'] = ...
|
||||
|
||||
// nav-menu-template.php L363
|
||||
// $args['menu_id'] = 'xxx-menu-id';
|
||||
// $args['menu_class'] = 'xxx-menu-class';
|
||||
|
||||
// nav-menu-template.php L311
|
||||
// $args['container'] = 'xxx-container'; // should be in apply_filters('wp_nav_menu_container_allowedtags')
|
||||
// $args['container_id'] = 'xxx-container-id';
|
||||
// $args['container_class'] = 'xxx-container-class';
|
||||
|
||||
// nav-menu-template.php L151
|
||||
// $args['before'] = 'xxx-before';
|
||||
// $args['after'] = 'xxx-after';
|
||||
// $args['link_before'] = 'xxx-link-before';
|
||||
// $args['link_after'] = 'xxx-link-after';
|
||||
|
||||
// nav-menu-template.php L405
|
||||
// $args['items_wrap'] = '<ul id="%1$s" class="%2$s">%3$s</ul>';
|
||||
|
||||
$args['walker'] = new FW_Ext_Mega_Menu_Walker();
|
||||
|
||||
return $args;
|
||||
}
|
||||
add_filter('wp_nav_menu_args', '_filter_fw_ext_mega_menu_wp_nav_menu_args');
|
||||
|
||||
/**
|
||||
* Just for removing FW_Ext_Mega_Menu_Walker set in the previous
|
||||
* filter when the fallback menu is in action.
|
||||
* @param array $args
|
||||
* @return array
|
||||
* @internal
|
||||
*/
|
||||
function _filter_fw_ext_mega_menu_wp_page_menu_args($args) {
|
||||
if ($args['walker'] instanceof FW_Ext_Mega_Menu_Walker) {
|
||||
$args['walker'] = '';
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
add_filter('wp_page_menu_args', '_filter_fw_ext_mega_menu_wp_page_menu_args');
|
||||
|
||||
/**
|
||||
* @param [WP_Post] $sorted_menu_items
|
||||
* @param $args
|
||||
* @return array
|
||||
* @internal
|
||||
*/
|
||||
function _filter_fw_ext_mega_menu_wp_nav_menu_objects($sorted_menu_items, $args) {
|
||||
// <li id="menu-item-1234" class="menu-item menu-item-type-post_type ... mega-menu">
|
||||
// ....
|
||||
// </li>
|
||||
|
||||
$mega_menu = array();
|
||||
foreach ($sorted_menu_items as $item) {
|
||||
if ($item->menu_item_parent == 0 && fw_ext_mega_menu_get_meta($item, 'enabled')) {
|
||||
$mega_menu[$item->ID] = true;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($sorted_menu_items as $item) {
|
||||
if (isset($mega_menu[$item->ID])) {
|
||||
$item->classes[] = 'menu-item-has-mega-menu';
|
||||
}
|
||||
if (isset($mega_menu[$item->menu_item_parent])) {
|
||||
$item->classes[] = 'mega-menu-col';
|
||||
}
|
||||
if (fw_ext_mega_menu_get_meta($item, 'icon')) {
|
||||
$item->classes[] = 'menu-item-has-icon';
|
||||
}
|
||||
}
|
||||
|
||||
return $sorted_menu_items;
|
||||
}
|
||||
add_filter('wp_nav_menu_objects', '_filter_fw_ext_mega_menu_wp_nav_menu_objects', 10, 2);
|
||||
|
||||
/**
|
||||
* nav-menu-template.php L174
|
||||
* Walker_Nav_Menu::start_el
|
||||
*
|
||||
* @param $item_output
|
||||
* @param $item
|
||||
* @param $depth
|
||||
* @param $args
|
||||
* @return string
|
||||
* @internal
|
||||
*/
|
||||
function _filter_fw_ext_mega_menu_walker_nav_menu_start_el($item_output, $item, $depth, $args) {
|
||||
/** @since 1.1.3 */
|
||||
if (apply_filters('fw:ext:megamenu:start_el_item_content:disable', false, $item)) {
|
||||
return $item_output;
|
||||
}
|
||||
|
||||
if (!fw_ext_mega_menu_is_mm_item($item)) {
|
||||
return $item_output;
|
||||
}
|
||||
|
||||
// <li>
|
||||
// {{ item_output }}
|
||||
// <div>{{ item.description }}</div>
|
||||
// <div class="mega-menu">
|
||||
// <ul class="sub-menu"></ul>
|
||||
// </div>
|
||||
// </li>
|
||||
|
||||
if ($depth > 0 && fw_ext_mega_menu_get_meta($item, 'title-off')) {
|
||||
$item_output = '';
|
||||
}
|
||||
|
||||
// Note that raw description is stored in post_content field.
|
||||
if ($depth > 0 && trim($item->post_content)) {
|
||||
$item_output .= '<div>' . do_shortcode($item->post_content) . '</div>';
|
||||
}
|
||||
|
||||
return $item_output;
|
||||
}
|
||||
add_filter('walker_nav_menu_start_el', '_filter_fw_ext_mega_menu_walker_nav_menu_start_el', 10, 4);
|
||||
@@ -0,0 +1,262 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class FW_Ext_Mega_Menu_Admin_Walker extends Walker_Nav_Menu /* Walker_Nav_Menu_Edit: Fatal Error: Class Not Found */
|
||||
{
|
||||
function start_lvl( &$output, $depth = 0, $args = array() ) {}
|
||||
function end_lvl( &$output, $depth = 0, $args = array() ) {}
|
||||
|
||||
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
||||
global $_wp_nav_menu_max_depth;
|
||||
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
|
||||
|
||||
ob_start();
|
||||
$item_id = esc_attr( $item->ID );
|
||||
$removed_args = array(
|
||||
'action',
|
||||
'customlink-tab',
|
||||
'edit-menu-item',
|
||||
'menu-item',
|
||||
'page-tab',
|
||||
'_wpnonce',
|
||||
);
|
||||
|
||||
$original_title = '';
|
||||
if ( 'taxonomy' == $item->type ) {
|
||||
$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
|
||||
if ( is_wp_error( $original_title ) )
|
||||
$original_title = false;
|
||||
} elseif ( 'post_type' == $item->type ) {
|
||||
$original_object = get_post( $item->object_id );
|
||||
$original_title = get_the_title( $original_object->ID );
|
||||
}
|
||||
|
||||
$classes = array(
|
||||
'menu-item menu-item-depth-' . $depth,
|
||||
'menu-item-' . esc_attr( $item->object ),
|
||||
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive'),
|
||||
);
|
||||
|
||||
$title = $item->title;
|
||||
|
||||
if ( ! empty( $item->_invalid ) ) {
|
||||
$classes[] = 'menu-item-invalid';
|
||||
/* translators: %s: title of menu item which is invalid */
|
||||
$title = sprintf( __( '%s (Invalid)', 'fw' ), $item->title );
|
||||
} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
|
||||
$classes[] = 'pending';
|
||||
/* translators: %s: title of menu item in draft status */
|
||||
$title = sprintf( __('%s (Pending)', 'fw'), $item->title );
|
||||
}
|
||||
|
||||
$title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
|
||||
|
||||
$submenu_text = '';
|
||||
if ( 0 == $depth )
|
||||
$submenu_text = 'style="display: none;"';
|
||||
|
||||
?>
|
||||
<li id="menu-item-<?php echo esc_attr($item_id); ?>" class="<?php echo esc_attr(implode(' ', $classes )); ?>">
|
||||
<dl class="menu-item-bar">
|
||||
<dt class="menu-item-handle">
|
||||
<span class="item-title"><span class="menu-item-title"><?php echo esc_html( $title ); ?></span> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item', 'fw' ); ?></span></span>
|
||||
<span class="item-controls">
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<span class="item-type show-if-mega-menu-top"><?php esc_html_e('Mega Menu', 'fw') ?></span>
|
||||
<span class="item-type show-if-mega-menu-column"><?php esc_html_e('Column', 'fw') ?></span>
|
||||
<span class="item-type hide-if-mega-menu-top hide-if-mega-menu-column"><?php echo esc_html($item->type_label) ?></span>
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<span class="item-order hide-if-js">
|
||||
<a href="<?php
|
||||
echo wp_nonce_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'action' => 'move-up-menu-item',
|
||||
'menu-item' => $item_id,
|
||||
),
|
||||
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
|
||||
),
|
||||
'move-menu_item'
|
||||
);
|
||||
?>" class="item-move-up"><abbr title="<?php esc_attr_e('Move up', 'fw'); ?>">↑</abbr></a>
|
||||
|
|
||||
<a href="<?php
|
||||
echo wp_nonce_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'action' => 'move-down-menu-item',
|
||||
'menu-item' => $item_id,
|
||||
),
|
||||
remove_query_arg($removed_args, admin_url( 'nav-menus.php' ) )
|
||||
),
|
||||
'move-menu_item'
|
||||
);
|
||||
?>" class="item-move-down"><abbr title="<?php esc_attr_e('Move down', 'fw'); ?>">↓</abbr></a>
|
||||
</span>
|
||||
<a class="item-edit" id="edit-<?php echo esc_attr($item_id); ?>" title="<?php esc_attr_e('Edit Menu Item', 'fw'); ?>" href="<?php
|
||||
echo ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? admin_url( 'nav-menus.php' ) : add_query_arg( 'edit-menu-item', $item_id, remove_query_arg( $removed_args, admin_url( 'nav-menus.php#menu-item-settings-' . $item_id ) ) );
|
||||
?>"><?php _e( 'Edit Menu Item', 'fw' ); ?></a>
|
||||
</span>
|
||||
</dt>
|
||||
</dl>
|
||||
|
||||
<div class="menu-item-settings" id="menu-item-settings-<?php echo esc_attr($item_id); ?>">
|
||||
<?php if( 'custom' == $item->type ) : ?>
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<p class="field-url description description-wide hide-if-mega-menu-column">
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<label for="edit-menu-item-url-<?php echo esc_attr($item_id); ?>">
|
||||
<?php _e( 'URL', 'fw' ); ?><br />
|
||||
<input type="text" id="edit-menu-item-url-<?php echo esc_attr($item_id); ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->url ); ?>" />
|
||||
</label>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<p class="description description-thin hide-if-mega-menu-column hide-if-mega-menu-item">
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<label for="edit-menu-item-title-<?php echo esc_attr($item_id); ?>">
|
||||
<?php _e( 'Navigation Label', 'fw' ); ?><br />
|
||||
<input type="text" id="edit-menu-item-title-<?php echo esc_attr($item_id); ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->title ); ?>" />
|
||||
</label>
|
||||
</p>
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<p class="description description-thin hide-if-mega-menu-column hide-if-mega-menu-item">
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<label for="edit-menu-item-attr-title-<?php echo esc_attr($item_id); ?>">
|
||||
<?php _e( 'Title Attribute', 'fw' ); ?><br />
|
||||
<input type="text" id="edit-menu-item-attr-title-<?php echo esc_attr($item_id); ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>" />
|
||||
</label>
|
||||
</p>
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<p class="field-link-target description hide-if-mega-menu-column">
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<label for="edit-menu-item-target-<?php echo esc_attr($item_id); ?>">
|
||||
<input type="checkbox" id="edit-menu-item-target-<?php echo esc_attr($item_id); ?>" value="_blank" name="menu-item-target[<?php echo esc_attr($item_id); ?>]"<?php checked( $item->target, '_blank' ); ?> />
|
||||
<?php _e( 'Open link in a new window/tab', 'fw' ); ?>
|
||||
</label>
|
||||
</p>
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<p class="field-css-classes description description-thin hide-if-mega-menu-column">
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<label for="edit-menu-item-classes-<?php echo esc_attr($item_id); ?>">
|
||||
<?php _e( 'CSS Classes (optional)', 'fw' ); ?><br />
|
||||
<input type="text" id="edit-menu-item-classes-<?php echo esc_attr($item_id); ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( implode(' ', $item->classes ) ); ?>" />
|
||||
</label>
|
||||
</p>
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<p class="field-xfn description description-thin hide-if-mega-menu-column">
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<label for="edit-menu-item-xfn-<?php echo esc_attr($item_id); ?>">
|
||||
<?php _e( 'Link Relationship (XFN)', 'fw' ); ?><br />
|
||||
<input type="text" id="edit-menu-item-xfn-<?php echo esc_attr($item_id); ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->xfn ); ?>" />
|
||||
</label>
|
||||
</p>
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<?php # Column ?>
|
||||
<p class="description description-wide show-if-mega-menu-column show-if-mega-menu-item">
|
||||
<label>
|
||||
<span class="hide-if-mega-menu-item"><?php _e('Mega Menu Column Title', 'fw') ?></span>
|
||||
<span class="hide-if-mega-menu-column"><?php _e('Item Title', 'fw') ?></span><br />
|
||||
<?php // -------------------------- ?>
|
||||
<?php // NOTE this is a post title! ?>
|
||||
<?php // -------------------------- ?>
|
||||
<input type="text" name="menu-item-title[<?php echo esc_attr($item_id) ?>]" value="<?php echo esc_attr($item->title) ?>" class="widefat mega-menu-title" />
|
||||
</label>
|
||||
<label class="mega-menu-title-off-label">
|
||||
<input type="checkbox" name="<?php echo _fw_ext_mega_menu_admin_input_name($item, 'title-off') ?>" <?php checked(fw_ext_mega_menu_get_meta($item, 'title-off')) ?> class="mega-menu-title-off" />
|
||||
<?php _e('Hide', 'fw') ?>
|
||||
</label>
|
||||
</p>
|
||||
<p class="description description-wide show-if-mega-menu-column">
|
||||
<label>
|
||||
<input type="checkbox" name="<?php echo _fw_ext_mega_menu_admin_input_name($item, 'new-row') ?>" <?php checked(fw_ext_mega_menu_get_meta($item, 'new-row')) ?> class="mega-menu-column-new-row" />
|
||||
<?php _e('This column should start a new row', 'fw') ?>
|
||||
</label>
|
||||
</p>
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<p class="field-description description description-wide x-hide-if-mega-menu-column force-show-if-mega-menu-column force-show-if-mega-menu-item">
|
||||
<label for="edit-menu-item-description-<?php echo esc_attr($item_id); ?>">
|
||||
<?php _e( 'Description (HTML)', 'fw' ); ?><br />
|
||||
<?php /* Note that raw description is stored in post_content */ ?>
|
||||
<textarea id="edit-menu-item-description-<?php echo esc_attr($item_id); ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo esc_attr($item_id); ?>]"><?php echo esc_html( $item->post_content ); // textarea_escaped ?></textarea>
|
||||
<span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.', 'fw'); ?></span>
|
||||
</label>
|
||||
</p>
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<?php do_action( 'wp_nav_menu_item_custom_fields', $item_id, $item, $depth, $args ); // https://github.com/ThemeFuse/Unyson-MegaMenu-Extension/issues/5 ?>
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<?php # Icon ?>
|
||||
<p class="field-mega-menu-icon description description-wide empty show-if-screen-options-icon">
|
||||
<label>
|
||||
<?php _e('Icon', 'fw') ?><br />
|
||||
<a href="#" class="button" data-action="mega-menu-pick-icon">
|
||||
<span class="inline-if-empty"><?php _e('Add Icon', 'fw') ?></span>
|
||||
<span class="hide-if-empty"><?php _e('Edit Icon', 'fw') ?></span>
|
||||
</a>
|
||||
<span data-action="mega-menu-pick-icon" class="mega-menu-icon-frame hide-if-empty" style="position: relative;">
|
||||
<i class="mega-menu-icon-i"></i>
|
||||
<a href="#" class="mega-menu-icon-remove dashicons fw-x" data-action="mega-menu-remove-icon" title="<?php esc_attr_e('Remove Icon', 'fw') ?>"></a>
|
||||
</span>
|
||||
<span class="mega-menu-icon-frame inline-if-empty" data-action="mega-menu-pick-icon"><i class="fa fa-lg fa-eye" style="position: relative; top: -1px;"></i></span>
|
||||
<input type="hidden" name="<?php echo _fw_ext_mega_menu_admin_input_name($item, 'icon') ?>" value="<?php echo esc_attr(fw_ext_mega_menu_get_meta($item, 'icon')) ?>" data-subject="mega-menu-icon-input" />
|
||||
</label>
|
||||
</p>
|
||||
<?php # Use as Mega Menu ?>
|
||||
<p class="description description-wide show-if-menu-top">
|
||||
<label>
|
||||
<input type="checkbox" name="<?php echo _fw_ext_mega_menu_admin_input_name($item, 'enabled') ?>"
|
||||
<?php checked(fw_ext_mega_menu_get_meta($item, 'enabled')) ?> class="mega-menu-enabled" />
|
||||
<?php _e('Use as Mega Menu', 'fw') ?>
|
||||
</label>
|
||||
</p>
|
||||
<p class="field-move hide-if-no-js description description-wide hide-if-mega-menu-column">
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<label>
|
||||
<span><?php _e( 'Move', 'fw' ); ?></span>
|
||||
<a href="#" class="menus-move-up"><?php _e( 'Up one', 'fw' ); ?></a>
|
||||
<a href="#" class="menus-move-down"><?php _e( 'Down one', 'fw' ); ?></a>
|
||||
<a href="#" class="menus-move-left"></a>
|
||||
<a href="#" class="menus-move-right"></a>
|
||||
<a href="#" class="menus-move-top"><?php _e( 'To the top', 'fw' ); ?></a>
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<div class="menu-item-actions description-wide submitbox">
|
||||
<?php # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ?>
|
||||
<?php if( 'custom' != $item->type && $original_title !== false ) : ?>
|
||||
<p class="link-to-original hide-if-mega-menu-column">
|
||||
<?php printf( __('Original: %s', 'fw'), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<a class="item-delete submitdelete deletion" id="delete-<?php echo esc_attr($item_id); ?>" href="<?php
|
||||
echo wp_nonce_url(
|
||||
add_query_arg(
|
||||
array(
|
||||
'action' => 'delete-menu-item',
|
||||
'menu-item' => $item_id,
|
||||
),
|
||||
admin_url( 'nav-menus.php' )
|
||||
),
|
||||
'delete-menu_item_' . $item_id
|
||||
); ?>"><?php _e( 'Remove', 'fw' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo esc_attr($item_id); ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) );
|
||||
?>#menu-item-settings-<?php echo esc_attr($item_id); ?>"><?php _e('Cancel', 'fw'); ?></a>
|
||||
</div>
|
||||
|
||||
<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr($item_id); ?>" />
|
||||
<input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->object_id ); ?>" />
|
||||
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->object ); ?>" />
|
||||
<input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>" />
|
||||
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>" />
|
||||
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo esc_attr($item_id); ?>]" value="<?php echo esc_attr( $item->type ); ?>" />
|
||||
<div class="fw-clear"></div>
|
||||
</div><!-- .menu-item-settings-->
|
||||
<ul class="menu-item-transport"></ul>
|
||||
<?php
|
||||
$output .= ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
class FW_Admin_Menu_Walker extends FW_Ext_Mega_Menu_Admin_Walker {}
|
||||
@@ -0,0 +1,284 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class FW_Ext_Mega_Menu_Walker extends Walker_Nav_Menu
|
||||
{
|
||||
/**
|
||||
* Start the element output.
|
||||
*
|
||||
* @see Walker::start_el()
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param string $output Passed by reference. Used to append additional content.
|
||||
* @param object $item Menu item data object.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
* @param array $args An array of arguments. @see wp_nav_menu()
|
||||
* @param int $id Current item ID.
|
||||
*/
|
||||
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
|
||||
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
|
||||
|
||||
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
|
||||
$classes[] = 'menu-item-' . $item->ID;
|
||||
|
||||
/**
|
||||
* Filter the CSS class(es) applied to a menu item's list item element.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @since 4.1.0 The `$depth` parameter was added.
|
||||
*
|
||||
* @param array $classes The CSS classes that are applied to the menu item's `<li>` element.
|
||||
* @param object $item The current menu item.
|
||||
* @param array $args An array of {@see wp_nav_menu()} arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
*/
|
||||
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item, $args, $depth ) );
|
||||
$class_names = $class_names ? ' class="' . esc_attr( $class_names ) . '"' : '';
|
||||
|
||||
/**
|
||||
* Filter the ID applied to a menu item's list item element.
|
||||
*
|
||||
* @since 3.0.1
|
||||
* @since 4.1.0 The `$depth` parameter was added.
|
||||
*
|
||||
* @param string $menu_id The ID that is applied to the menu item's `<li>` element.
|
||||
* @param object $item The current menu item.
|
||||
* @param array $args An array of {@see wp_nav_menu()} arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
*/
|
||||
$id = apply_filters( 'nav_menu_item_id', 'menu-item-'. $item->ID, $item, $args, $depth );
|
||||
$id = $id ? ' id="' . esc_attr( $id ) . '"' : '';
|
||||
|
||||
$output .= $indent . '<li' . $id . $class_names .'>';
|
||||
|
||||
$atts = array();
|
||||
$atts['title'] = ! empty( $item->attr_title ) ? $item->attr_title : '';
|
||||
$atts['target'] = ! empty( $item->target ) ? $item->target : '';
|
||||
$atts['rel'] = ! empty( $item->xfn ) ? $item->xfn : '';
|
||||
$atts['href'] = ! empty( $item->url ) ? $item->url : '';
|
||||
|
||||
/**
|
||||
* Filter the HTML attributes applied to a menu item's anchor element.
|
||||
*
|
||||
* @since 3.6.0
|
||||
* @since 4.1.0 The `$depth` parameter was added.
|
||||
*
|
||||
* @param array $atts {
|
||||
* The HTML attributes applied to the menu item's `<a>` element, empty strings are ignored.
|
||||
*
|
||||
* @type string $title Title attribute.
|
||||
* @type string $target Target attribute.
|
||||
* @type string $rel The rel attribute.
|
||||
* @type string $href The href attribute.
|
||||
* }
|
||||
* @param object $item The current menu item.
|
||||
* @param array $args An array of {@see wp_nav_menu()} arguments.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
*/
|
||||
$atts = apply_filters( 'nav_menu_link_attributes', $atts, $item, $args, $depth );
|
||||
|
||||
$attributes = '';
|
||||
foreach ( $atts as $attr => $value ) {
|
||||
if ( ! empty( $value ) ) {
|
||||
$value = ( 'href' === $attr ) ? esc_url( $value ) : esc_attr( $value );
|
||||
$attributes .= ' ' . $attr . '="' . $value . '"';
|
||||
}
|
||||
}
|
||||
|
||||
# BEGIN - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// $item_output = $args->before;
|
||||
// $item_output .= '<a'. $attributes .'>';
|
||||
// /** This filter is documented in wp-includes/post-template.php */
|
||||
// $item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
|
||||
// $item_output .= '</a>';
|
||||
// $item_output .= $args->after;
|
||||
$title = apply_filters('the_title', $item->title, $item->ID);
|
||||
$attributes = array_filter($atts);
|
||||
$item_output = fw_ext('megamenu')->render_str('item-link', compact('item', 'attributes', 'title', 'args', 'depth'));
|
||||
# END - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
/**
|
||||
* Filter a menu item's starting output.
|
||||
*
|
||||
* The menu item's starting output only includes $args->before, the opening <a>,
|
||||
* the menu item's title, the closing </a>, and $args->after. Currently, there is
|
||||
* no filter for modifying the opening and closing <li> for a menu item.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @see wp_nav_menu()
|
||||
*
|
||||
* @param string $item_output The menu item's starting HTML output.
|
||||
* @param object $item Menu item data object.
|
||||
* @param int $depth Depth of menu item. Used for padding.
|
||||
* @param array $args An array of wp_nav_menu() arguments.
|
||||
*/
|
||||
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Walker::display_element
|
||||
*/
|
||||
function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
|
||||
|
||||
if ( !$element )
|
||||
return;
|
||||
|
||||
$id_field = $this->db_fields['id'];
|
||||
$id = $element->$id_field;
|
||||
|
||||
//display this element
|
||||
$this->has_children = ! empty( $children_elements[ $id ] );
|
||||
if ( isset( $args[0] ) && is_array( $args[0] ) ) {
|
||||
$args[0]['has_children'] = $this->has_children; // Backwards compatibility.
|
||||
}
|
||||
|
||||
$cb_args = array_merge( array(&$output, $element, $depth), $args);
|
||||
call_user_func_array(array($this, 'start_el'), $cb_args);
|
||||
|
||||
// descend only when the depth is right and there are childrens for this element
|
||||
if ( ($max_depth == 0 || $max_depth > $depth+1 ) && isset( $children_elements[$id]) ) {
|
||||
|
||||
foreach( $children_elements[ $id ] as $child ){
|
||||
# BEGIN - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if ($depth == 0 && fw_ext_mega_menu_get_meta($id, 'enabled') && fw_ext_mega_menu_get_meta($child, 'new-row')) {
|
||||
if (isset($newlevel) && $newlevel) {
|
||||
$cb_args = array_merge( array(&$output, $depth), $args);
|
||||
call_user_func_array(array($this, 'end_lvl'), $cb_args);
|
||||
unset($newlevel);
|
||||
}
|
||||
}
|
||||
# END - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if ( !isset($newlevel) ) {
|
||||
$newlevel = true;
|
||||
# BEGIN - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if (!isset($mega_menu_container) && $depth == 0 && fw_ext_mega_menu_get_meta($id, 'enabled')) {
|
||||
$mega_menu_container = apply_filters('fw_ext_mega_menu_container', array(
|
||||
'tag' => 'div',
|
||||
'attr' => array( 'class' => 'mega-menu' )
|
||||
), array(
|
||||
'element' => $element,
|
||||
'children_elements' => $children_elements,
|
||||
'max_depth' => $max_depth,
|
||||
'depth' => $depth,
|
||||
'args' => $args,
|
||||
));
|
||||
$output .= '<'. $mega_menu_container['tag'] .' '. fw_attr_to_html($mega_menu_container['attr']) .'>';
|
||||
}
|
||||
|
||||
$classes = array('sub-menu' => true);
|
||||
if (isset($mega_menu_container)) {
|
||||
if ($this->row_contains_icons($element, $child, $children_elements)) {
|
||||
$classes['sub-menu-has-icons'] = true;
|
||||
}
|
||||
$classes['mega-menu-row'] = true;;
|
||||
}
|
||||
else {
|
||||
if ($this->sub_menu_contains_icons($element, $children_elements)) {
|
||||
$classes['sub-menu-has-icons'] = true;
|
||||
}
|
||||
}
|
||||
$classes = apply_filters('fw_ext_mega_menu_start_lvl_classes', $classes, array(
|
||||
'element' => $element,
|
||||
'children_elements' => $children_elements,
|
||||
'max_depth' => $max_depth,
|
||||
'depth' => $depth,
|
||||
'args' => $args,
|
||||
'mega_menu_container' => isset($mega_menu_container) ? $mega_menu_container : false
|
||||
));
|
||||
$classes = array_filter($classes);
|
||||
# END - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
//start the child delimiter
|
||||
# BEGIN - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
//$cb_args = array_merge( array(&$output, $depth), $args);
|
||||
$cb_args = array_merge( array(&$output, $depth), $args, array(
|
||||
implode(' ', array_keys($classes))
|
||||
));
|
||||
# END - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
call_user_func_array(array($this, 'start_lvl'), $cb_args);
|
||||
}
|
||||
$this->display_element( $child, $children_elements, $max_depth, $depth + 1, $args, $output );
|
||||
}
|
||||
unset( $children_elements[ $id ] );
|
||||
}
|
||||
|
||||
if ( isset($newlevel) && $newlevel ){
|
||||
//end the child delimiter
|
||||
$cb_args = array_merge( array(&$output, $depth), $args);
|
||||
call_user_func_array(array($this, 'end_lvl'), $cb_args);
|
||||
}
|
||||
|
||||
# BEGIN - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
if (isset($mega_menu_container)) {
|
||||
$output .= '</'. $mega_menu_container['tag'] .'>';
|
||||
}
|
||||
# END - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
//end this element
|
||||
$cb_args = array_merge( array(&$output, $element, $depth), $args);
|
||||
call_user_func_array(array($this, 'end_el'), $cb_args);
|
||||
}
|
||||
|
||||
function start_lvl( &$output, $depth = 0, $args = array(), $class = 'sub-menu' ) {
|
||||
$indent = str_repeat("\t", $depth);
|
||||
$output .= "\n$indent<ul class=\"$class\">\n";
|
||||
}
|
||||
|
||||
protected function sub_menu_contains_icons($element, $children_elements) {
|
||||
$id_field = $this->db_fields['id'];
|
||||
$id = $element->$id_field;
|
||||
foreach ($children_elements[$id] as $child) {
|
||||
if (fw_ext_mega_menu_get_meta($child, 'icon')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function row_contains_icons($row, $first_column, $children_elements) {
|
||||
|
||||
$id_field = $this->db_fields['id'];
|
||||
$row_id = $row->$id_field;
|
||||
|
||||
reset($children_elements[$row_id]);
|
||||
|
||||
// navigate to $first_column
|
||||
while ($child = next($children_elements[$row_id])) {
|
||||
if ($child->$id_field == $first_column->$id_field) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// scan row
|
||||
while (true) {
|
||||
if (fw_ext_mega_menu_get_meta($child, 'icon')) {
|
||||
return true;
|
||||
}
|
||||
$child = next($children_elements[$row_id]);
|
||||
if ($child === false || fw_ext_mega_menu_get_meta($child, 'new-row')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
class FW_Theme_Menu_Walker extends FW_Ext_Mega_Menu_Walker {
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
private function sub_menu_has_icons($element, $children_elements) {
|
||||
return $this->sub_menu_contains_icons($element, $children_elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
private function row_has_icons($row, $first_column, $children_elements) {
|
||||
return $this->row_contains_icons($row, $first_column, $children_elements);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param $post
|
||||
* @param $key
|
||||
* @param null $default
|
||||
* @return mixed
|
||||
*/
|
||||
function fw_mega_menu_get_meta($post, $key, $default = null) {
|
||||
return fw_ext_mega_menu_get_meta($post, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param $post
|
||||
* @param array $array
|
||||
* @return mixed
|
||||
*/
|
||||
function fw_mega_menu_update_meta($post, array $array) {
|
||||
return fw_ext_mega_menu_update_meta($post, $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param $post
|
||||
* @param $key
|
||||
* @return string
|
||||
*/
|
||||
function fw_mega_menu_name_meta($post, $key) {
|
||||
return _fw_ext_mega_menu_admin_input_name($post, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param $post
|
||||
* @return array
|
||||
*/
|
||||
function fw_mega_menu_request_meta($post) {
|
||||
return _fw_ext_mega_menu_admin_input_POST_values($post);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @param $post
|
||||
* @param $key
|
||||
* @param null $default
|
||||
* @param bool $write
|
||||
* @return mixed
|
||||
*/
|
||||
function _fw_mega_menu_meta($post, $key, $default = null, $write = false) {
|
||||
return _fw_ext_mega_menu_meta($post, $key, $default, $write);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param int|object $post
|
||||
* @param $key
|
||||
* @param null $default
|
||||
* @param bool $write
|
||||
* @return mixed
|
||||
*/
|
||||
function _fw_ext_mega_menu_meta($post, $key, $default = null, $write = false) {
|
||||
static $meta = array();
|
||||
|
||||
$post_id = is_object($post) ? $post->ID : $post;
|
||||
|
||||
if (!isset($meta[$post_id])) {
|
||||
$meta[$post_id] = (array) get_post_meta($post_id, 'mega-menu', true);
|
||||
}
|
||||
|
||||
if ($write) {
|
||||
if (is_array($key)) {
|
||||
$meta[$post_id] = array_filter(array_merge($meta[$post_id], $key));
|
||||
}
|
||||
else {
|
||||
$meta[$post_id][$key] = $default;
|
||||
$meta[$post_id][$key] = array_filter($meta[$post_id][$key]);
|
||||
}
|
||||
fw_update_post_meta($post_id, 'mega-menu', $meta[$post_id]);
|
||||
return null;
|
||||
}
|
||||
|
||||
return isset($meta[$post_id][$key]) ? $meta[$post_id][$key] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $post
|
||||
* @param $key
|
||||
* @return string
|
||||
* @internal
|
||||
*/
|
||||
function _fw_ext_mega_menu_admin_input_name($post, $key) {
|
||||
$post_id = is_object($post) ? $post->ID : $post;
|
||||
|
||||
return "mega-menu[$post_id][$key]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $post
|
||||
* @return array
|
||||
* @internal
|
||||
*/
|
||||
function _fw_ext_mega_menu_admin_input_POST_values($post) {
|
||||
$post_id = is_object($post) ? $post->ID : $post;
|
||||
|
||||
return (array)fw_akg('mega-menu/'. $post_id, $_POST);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
$manifest = array();
|
||||
|
||||
$manifest['name'] = __( 'Mega Menu', 'fw' );
|
||||
$manifest['description'] = __( 'The Mega Menu extension adds a user-friendly drop down menu that will let you easily create highly customized menu configurations.', 'fw' );
|
||||
$manifest['version'] = '1.1.3';
|
||||
$manifest['display'] = true;
|
||||
$manifest['github_repo'] = 'https://github.com/ThemeFuse/Unyson-MegaMenu-Extension';
|
||||
$manifest['uri'] = 'http://manual.unyson.io/en/latest/extension/megamenu/index.html#content';
|
||||
$manifest['author'] = 'ThemeFuse';
|
||||
$manifest['author_uri'] = 'http://themefuse.com/';
|
||||
$manifest['standalone'] = true;
|
||||
$manifest['requirements'] = array(
|
||||
'framework' => array(
|
||||
'min_version' => '2.5.9', // class FW_Db_Options_Model
|
||||
),
|
||||
);
|
||||
|
||||
$manifest['github_update'] = 'ThemeFuse/Unyson-MegaMenu-Extension';
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
// MegaMenu column options
|
||||
$options = array();
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
// default (not MegaMenu) item options
|
||||
$options = array();
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
// MegaMenu item options, column child, level 3+
|
||||
$options = array();
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
// MegaMenu row options
|
||||
$options = array();
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
if (!is_admin()) {
|
||||
wp_enqueue_style(
|
||||
'font-awesome',
|
||||
fw_get_framework_directory_uri('/static/libs/font-awesome/css/font-awesome.min.css'),
|
||||
array(),
|
||||
fw()->manifest->get_version()
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
/* Screen Options */
|
||||
|
||||
.show-if-screen-options-icon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.screen-options-icon .show-if-screen-options-icon {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Menu */
|
||||
|
||||
.show-if-menu-top {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.menu-item-depth-0 .show-if-menu-top {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.menu-item .menu-item-settings {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
/* Mega Menu */
|
||||
|
||||
.show-if-mega-menu-top,
|
||||
.show-if-mega-menu-column,
|
||||
.show-if-mega-menu-item {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.mega-menu.menu-item-depth-0 .show-if-mega-menu-top,
|
||||
.mega-menu.menu-item-depth-1 .show-if-mega-menu-column,
|
||||
.mega-menu.menu-item-depth-2 .show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-3 .show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-4 .show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-5 .show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-6 .show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-7 .show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-8 .show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-9 .show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-1 .force-show-if-mega-menu-column,
|
||||
.mega-menu.menu-item-depth-2 .force-show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-3 .force-show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-4 .force-show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-5 .force-show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-6 .force-show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-7 .force-show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-8 .force-show-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-9 .force-show-if-mega-menu-item {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.mega-menu.menu-item-depth-0 .hide-if-mega-menu-top,
|
||||
.mega-menu.menu-item-depth-1 .hide-if-mega-menu-column,
|
||||
.mega-menu.menu-item-depth-2 .hide-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-3 .hide-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-4 .hide-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-5 .hide-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-6 .hide-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-7 .hide-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-8 .hide-if-mega-menu-item,
|
||||
.mega-menu.menu-item-depth-9 .hide-if-mega-menu-item {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Empty */
|
||||
|
||||
.inline-if-empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.empty .inline-if-empty {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.empty .hide-if-empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* etc */
|
||||
|
||||
.mega-menu-icon-frame {
|
||||
border: 1px solid #e1e1e1;
|
||||
padding: 4px;
|
||||
-webkit-border-radius: 2px;
|
||||
-moz-border-radius: 2px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.mega-menu-icon-frame .mega-menu-icon-i {
|
||||
text-align: center;
|
||||
min-width: 1em;
|
||||
font-size: 1.33333333em;
|
||||
line-height: .75em;
|
||||
vertical-align: -15%;
|
||||
}
|
||||
|
||||
.mega-menu-icon-frame.inline-if-empty .mega-menu-icon-i,
|
||||
.mega-menu-icon-frame.inline-if-empty .fa {
|
||||
color: #e1e1e1;
|
||||
}
|
||||
.mega-menu-icon-frame .mega-menu-icon-i:before {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.mega-menu-icon-remove {
|
||||
font-size: 14px !important;
|
||||
line-height: 13px;
|
||||
position: absolute;
|
||||
top: -10px;
|
||||
right: -11px;
|
||||
display: inline-block;
|
||||
height: auto;
|
||||
border: none;
|
||||
-webkit-transition: none;
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.mega-menu-icon-remove:hover {
|
||||
-webkit-transition: none;
|
||||
transition: none;
|
||||
}
|
||||
|
||||
.mega-menu-icon-remove:before {
|
||||
background-color: #fff;
|
||||
border-radius: 99px;
|
||||
}
|
||||
|
||||
/* Mega Menu Column Options: title and checkbox */
|
||||
|
||||
.mega-menu-title[disabled] {
|
||||
background: #ddd;
|
||||
}
|
||||
|
||||
body .mega-menu-title {
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
body .mega-menu-title-off-label {
|
||||
float: right;
|
||||
border:1px solid #ddd;
|
||||
-webkit-box-shadow:inset 0 1px 2px rgba(0,0,0,.07);
|
||||
box-shadow: inset 0 1px 2px rgba(0,0,0,.07);
|
||||
background-color: #fff;
|
||||
color: #333;
|
||||
-webkit-transition: .05s border-color ease-in-out;
|
||||
transition: .05s border-color ease-in-out;
|
||||
width: 46px; height: 19px;
|
||||
padding: 3px 20px;
|
||||
white-space: nowrap;
|
||||
position: relative;
|
||||
left: -3px;
|
||||
border-left: none;
|
||||
}
|
||||
|
||||
|
||||
#update-nav-menu .menu-item > .menu-item-settings .fw-megamenu-stngs {
|
||||
margin-left: 15px;
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
jQuery(function ($) {
|
||||
|
||||
var localized = _fw_ext_mega_menu;
|
||||
|
||||
// Screen Options: Show advanced menu properties: Icon Checkbox
|
||||
(function () {
|
||||
|
||||
var container = '#menu-to-edit';
|
||||
var selector = jQuery('body.branch-4-0, body.branch-4-1, body.branch-4-2, body.branch-4-3').length
|
||||
? '#icon-hide' // WP <= 4.3
|
||||
: '.hide-column-tog[name="icon-hide"]'; // WP 4.4+
|
||||
|
||||
$(document).on('change', selector, function () {
|
||||
$(container).toggleClass('screen-options-icon', $(this).is(':checked'));
|
||||
});
|
||||
|
||||
$(selector).trigger('change');
|
||||
})();
|
||||
|
||||
// Mega Menu Column Title: input
|
||||
(function (selector) {
|
||||
|
||||
$(document).on('change', selector, function () {
|
||||
$(this).closest('li').find(selector).val($(this).val());
|
||||
});
|
||||
// $(selector).trigger('change') is not necessary since those two fields
|
||||
// are populated by WordPress with the same value (title)
|
||||
|
||||
})('.mega-menu-title, .edit-menu-item-title');
|
||||
|
||||
// Mega Menu Column Title: checkbox
|
||||
(function (selector) {
|
||||
|
||||
$(document).on('change', selector, function () {
|
||||
var checkbox = $(this);
|
||||
checkbox.closest('p').find('.mega-menu-title').prop('readonly', checkbox.is(':checked'));
|
||||
});
|
||||
$(selector).trigger('change');
|
||||
|
||||
})('.mega-menu-title-off');
|
||||
|
||||
// Use as Mega Menu Checkbox
|
||||
(function () {
|
||||
|
||||
var menu = $('#menu-to-edit');
|
||||
|
||||
function update()
|
||||
{
|
||||
menu.children().removeClass('mega-menu');
|
||||
menu.find('.mega-menu-title').prop('disabled', true);
|
||||
menu.find('.edit-menu-item-title').prop('disabled', false);
|
||||
menu.children('.menu-item-depth-0:has(.mega-menu-enabled:checked)').each(function () {
|
||||
var item = $(this);
|
||||
item.addClass('mega-menu');
|
||||
item.nextUntil('.menu-item-depth-0').addClass('mega-menu');
|
||||
item.siblings('.mega-menu').find('.mega-menu-title').prop('disabled', false);
|
||||
item.siblings('.mega-menu').find('.edit-menu-item-title').prop('disabled', true);
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on('change', '.menu-item-depth-0 .mega-menu-enabled', update);
|
||||
// FIXME our handler should be called after WP handler
|
||||
menu.on('sortstop', function () {
|
||||
setTimeout(update, 1);
|
||||
});
|
||||
|
||||
update();
|
||||
|
||||
})();
|
||||
|
||||
// Monitor icon state and reflect it with dependent fields
|
||||
(function (selector) {
|
||||
|
||||
$(document).on('change', selector, function (event) {
|
||||
var field = $(this).closest('.field-mega-menu-icon');
|
||||
var value = $(this).val();
|
||||
field.toggleClass('empty', value == '');
|
||||
field.find('.mega-menu-icon-i').attr('class', 'mega-menu-icon-i ' + value);
|
||||
});
|
||||
$(selector).trigger('change');
|
||||
|
||||
})('.field-mega-menu-icon [data-subject=mega-menu-icon-input]');
|
||||
|
||||
(function(){
|
||||
var modal = new fw.OptionsModal({
|
||||
title: localized.icon_option.label,
|
||||
options: [{
|
||||
icon: localized.icon_option
|
||||
}],
|
||||
values: {
|
||||
icon: ''
|
||||
},
|
||||
size: 'small'
|
||||
}), eventProxy = new Backbone.Model;
|
||||
|
||||
// Immediately close dialog after clicking on icon
|
||||
$(modal.frame.$el).on('change', 'input[name="fw_edit_options_modal[icon]"]', function(){
|
||||
var icon = $(this).val();
|
||||
|
||||
switch (localized.icon_option.type) {
|
||||
case 'icon':
|
||||
// leave as it is
|
||||
break;
|
||||
case 'icon-v2':
|
||||
icon = JSON.parse(icon)['icon-class'];
|
||||
break;
|
||||
default:
|
||||
var eventData = {
|
||||
icon: icon, // this will be changed by reference
|
||||
icon_option: $.extend({}, localized.icon_option)
|
||||
};
|
||||
/** @since 1.1.2 */
|
||||
fwEvents.trigger(
|
||||
'fw:ext:megamenu:custom-icon-value-to-icon-class:'+ localized.icon_option.type, eventData
|
||||
);
|
||||
icon = eventData.icon;
|
||||
}
|
||||
|
||||
modal.set('values', {
|
||||
icon: icon
|
||||
});
|
||||
|
||||
modal.frame.close();
|
||||
});
|
||||
|
||||
{
|
||||
// Resize icon list to fit entire window
|
||||
function resizeIconList() {
|
||||
var option = modal.frame.$el.find('#fw-backend-option-fw-edit-options-modal-icon'),
|
||||
frame_content = option.closest('.media-frame-content'),
|
||||
icon_list = option.find('.js-option-type-icon-list');
|
||||
|
||||
// get rid of bottom border
|
||||
option.closest('.fw-row').css('border-bottom', 'none');
|
||||
|
||||
// resize icon list to fit entire window
|
||||
icon_list.css('max-height', 'none').height(1000000);
|
||||
frame_content.scrollTop(1000000);
|
||||
icon_list.height(icon_list.height() - frame_content.scrollTop());
|
||||
}
|
||||
|
||||
modal.on('change:html', resizeIconList);
|
||||
$(window).resize(resizeIconList);
|
||||
}
|
||||
|
||||
// Replace [Save] button by [Cancel]
|
||||
$(modal.frame.$el).find('.media-toolbar-primary')
|
||||
.html('<a href="#" class="button media-button button-large">Cancel</a>')
|
||||
.find('a').on('click', function (event) {
|
||||
event.preventDefault();
|
||||
modal.frame.close();
|
||||
});
|
||||
|
||||
// Add/Edit Icon Buttons
|
||||
$(document).on('click', '[data-action=mega-menu-pick-icon]', function (event) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
// prevent previous item event listener execution
|
||||
eventProxy.stopListening(modal);
|
||||
|
||||
{
|
||||
var icon = $(event.target).closest('.field-mega-menu-icon').find('input').val();
|
||||
|
||||
switch (localized.icon_option.type) {
|
||||
case 'icon':
|
||||
// leave as it is
|
||||
break;
|
||||
case 'icon-v2':
|
||||
icon = {'type': 'icon-font', 'icon-class': icon}
|
||||
break;
|
||||
default:
|
||||
var eventData = {
|
||||
icon: icon, // this will be changed by reference
|
||||
icon_option: $.extend({}, localized.icon_option)
|
||||
};
|
||||
/** @since 1.1.2 */
|
||||
fwEvents.trigger(
|
||||
'fw:ext:megamenu:icon-class-to-custom-icon-value:'+ localized.icon_option.type, eventData
|
||||
);
|
||||
icon = eventData.icon;
|
||||
}
|
||||
|
||||
modal.set('values', {
|
||||
icon: icon
|
||||
});
|
||||
}
|
||||
|
||||
// Listen for values change
|
||||
eventProxy.listenTo(modal, 'change:values', function(modal, values) {
|
||||
$(event.target).closest('.field-mega-menu-icon').find('input').val(values.icon).trigger('change');
|
||||
});
|
||||
|
||||
modal.open();
|
||||
});
|
||||
})();
|
||||
|
||||
// Remove Icon Button
|
||||
$(document).on('click', '[data-action=mega-menu-remove-icon]', function (event) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
$(this).closest('.field-mega-menu-icon').find('input').val('').trigger('change');
|
||||
});
|
||||
|
||||
// The problem is in using **change** event for initialization.
|
||||
//
|
||||
// Internally WordPress listen this inputs for **change** event
|
||||
// and sets **menuChanged** flag. It also sets window.onbeforeunload handler
|
||||
// which decides whether or not display
|
||||
//
|
||||
// "The changes you made will be lost if you navigate away from this page."
|
||||
//
|
||||
// dialog based on this flag.
|
||||
wpNavMenu.menusChanged = false;
|
||||
|
||||
/**
|
||||
* Item options
|
||||
*/
|
||||
(function(){
|
||||
var inst = {
|
||||
values: {},
|
||||
options: localized.options,
|
||||
modal_sizes: localized.item_options_modal_sizes,
|
||||
$input: null,
|
||||
// Save item values in form hidden input
|
||||
updateInput: function(){
|
||||
if (inst.$input === null) {
|
||||
inst.$input = $('<input type="hidden" name="fw-megamenu-items-values" value="[]" />');
|
||||
$('#update-nav-menu').append(inst.$input);
|
||||
}
|
||||
|
||||
inst.$input.val(JSON.stringify(inst.values));
|
||||
},
|
||||
getItemType: function ($item) {
|
||||
var $parent = $item;
|
||||
|
||||
// find all parents
|
||||
while (!$parent.hasClass('menu-item-depth-0')) {
|
||||
$parent = $parent.prev();
|
||||
}
|
||||
|
||||
if (!$parent.find('input.mega-menu-enabled:first').is(':checked')) {
|
||||
return 'default'; // parent is not MegaMenu enabled
|
||||
}
|
||||
|
||||
if ($item.hasClass('menu-item-depth-0')) {
|
||||
return 'row';
|
||||
} else if ($item.hasClass('menu-item-depth-1')) {
|
||||
return 'column';
|
||||
} else {
|
||||
return 'item';
|
||||
}
|
||||
},
|
||||
modal: new fw.OptionsModal({
|
||||
options: []
|
||||
}),
|
||||
eventProxy: new Backbone.Model({}),
|
||||
/**
|
||||
* Remember ajax handlers and abort previous if a new one was requested
|
||||
* On slow internet connection, when you will move an open menu tree and change the hierarchy
|
||||
*/
|
||||
ajaxHandlers: { values: {} },
|
||||
updateUi: function ($item) {
|
||||
var type, id = $item.find('input.menu-item-data-db-id:first').val();
|
||||
|
||||
if (!(
|
||||
$item.hasClass('menu-item-edit-active') // the box is closed
|
||||
&&
|
||||
(type = inst.getItemType($item))
|
||||
&&
|
||||
!_.isEmpty(inst.options[type])
|
||||
)) {
|
||||
if (typeof inst.ajaxHandlers.values[id] != 'undefined') {
|
||||
inst.ajaxHandlers.values[id].abort();
|
||||
}
|
||||
|
||||
$item.find('button.fw-megamenu-stngs:first').remove();
|
||||
return;
|
||||
}
|
||||
|
||||
var $button = $item.find('button.fw-megamenu-stngs:first');
|
||||
|
||||
if (!$button.length) {
|
||||
$button = $('<button type="button" disabled="disabled" class="button fw-megamenu-stngs"></button>');
|
||||
$button.text(localized.l10n.item_options_btn);
|
||||
|
||||
$item.find('.field-mega-menu-icon:first').append($button);
|
||||
}
|
||||
|
||||
if (typeof inst.values[id] !== 'undefined') {
|
||||
$button.removeAttr('disabled');
|
||||
} else {
|
||||
if (typeof inst.ajaxHandlers.values[id] !== 'undefined') {
|
||||
inst.ajaxHandlers.values[id].abort();
|
||||
}
|
||||
|
||||
$button.attr('disabled', 'disabled');
|
||||
|
||||
inst.ajaxHandlers.values[id] = $.ajax({
|
||||
url: ajaxurl,
|
||||
method: 'post',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: 'fw_ext_megamenu_item_values',
|
||||
id: id
|
||||
}
|
||||
}).done(function (r) {
|
||||
if (r && r.success) {
|
||||
$button.removeAttr('disabled');
|
||||
inst.values[id] = r.data.values;
|
||||
} else {
|
||||
$button.text('Ajax Error');
|
||||
}
|
||||
}).fail(function (x, y, error) {
|
||||
if ($button.length && $button.is(':visible')) { // may not exist
|
||||
$button.text(String(error));
|
||||
|
||||
/**
|
||||
* Remove the button so on next box open the init will try again to do the ajax
|
||||
*
|
||||
* Note: Do not retry ajax because it can be
|
||||
* a server problem and this will cause "DDOS" from all items
|
||||
*/
|
||||
setTimeout(function(){ $button.remove(); }, 3000);
|
||||
}
|
||||
}).always(function () {
|
||||
delete inst.ajaxHandlers.values[id];
|
||||
});
|
||||
}
|
||||
},
|
||||
extractItemDepth: function($item){
|
||||
return parseInt($item.attr('class').match(/ ?menu-item-depth-(\d+) ?/)[1]);
|
||||
},
|
||||
updateItemsTreeUi: function ($item) {
|
||||
var itemDepth = inst.extractItemDepth($item);
|
||||
|
||||
// Update all sub-items (until we reach a higher level item level)
|
||||
do {
|
||||
_.defer(inst.updateUi, $item);
|
||||
$item = $item.next();
|
||||
} while ($item.length && inst.extractItemDepth($item) > itemDepth);
|
||||
}
|
||||
};
|
||||
|
||||
// Add ui elements on item box open
|
||||
$('#update-nav-menu').on('click', '.menu-item > .menu-item-bar .item-edit', function(){
|
||||
_.defer(inst.updateUi, $(this).closest('.menu-item'));
|
||||
});
|
||||
|
||||
// Update UI on "Use as MegaMenu" change
|
||||
$('#update-nav-menu').on('change', '.menu-item > .menu-item-settings input.mega-menu-enabled', function () {
|
||||
_.defer(inst.updateItemsTreeUi, $(this).closest('.menu-item'));
|
||||
});
|
||||
|
||||
// Items moving has stopped
|
||||
$('#update-nav-menu').on('sortstop', function (e, s) {
|
||||
_.defer(inst.updateItemsTreeUi, $(s.item));
|
||||
});
|
||||
|
||||
// Prepare and open modal on button click
|
||||
$('#update-nav-menu').on('click', '.menu-item > .menu-item-settings button.fw-megamenu-stngs', function(){
|
||||
var $item = $(this).closest('.menu-item'),
|
||||
type = inst.getItemType($item),
|
||||
id = $item.find('input.menu-item-data-db-id:first').val();
|
||||
|
||||
if (!type) {
|
||||
$(this).remove(); // button has remained visible because of a bug
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
inst.eventProxy.stopListening(inst.modal);
|
||||
|
||||
inst.modal.set('values', inst.values[id][type]);
|
||||
|
||||
inst.eventProxy.listenTo(inst.modal, 'change:values', function(){
|
||||
inst.values[id][type] = inst.modal.get('values');
|
||||
inst.updateInput();
|
||||
});
|
||||
}
|
||||
|
||||
inst.modal.set('options', inst.options[type]);
|
||||
inst.modal.set('size', inst.modal_sizes[type]);
|
||||
inst.modal.open();
|
||||
});
|
||||
})();
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
/**
|
||||
* @var WP_Post $item
|
||||
* @var string $title
|
||||
* @var array $attributes
|
||||
* @var object $args
|
||||
* @var int $depth
|
||||
*/
|
||||
|
||||
if (
|
||||
fw()->extensions->get('megamenu')->show_icon()
|
||||
&&
|
||||
($icon = fw_ext_mega_menu_get_meta($item, 'icon'))
|
||||
) {
|
||||
if (empty($attributes['class'])) {
|
||||
$attributes['class'] = $icon;
|
||||
} else {
|
||||
$attributes['class'] .= ' ' . $icon;
|
||||
}
|
||||
}
|
||||
|
||||
echo $args->before;
|
||||
echo fw_html_tag('a', $attributes, $args->link_before . $title . $args->link_after);
|
||||
echo $args->after;
|
||||
Reference in New Issue
Block a user