Skip to content

Commit

Permalink
Enhance nav menu script + jsDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
JoryHogeveen committed Aug 29, 2017
1 parent 32b370b commit cb17f79
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 48 deletions.
2 changes: 1 addition & 1 deletion includes/class-menu-meta-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function admin_enqueue_scripts() {
$data['val'][ $item ] = get_post_meta( $item, '_off_canvas_control_menu_item', true );

// send all these data to javascript
wp_localize_script( 'off_canvas_control_nav_menu', 'off_canvas_control_data', $data );
wp_localize_script( 'off_canvas_control_nav_menu', 'ocsNavControl', $data );
}

/*
Expand Down
60 changes: 19 additions & 41 deletions js/nav-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
* @author Jory Hogeveen <[email protected]>
* @package off-canvas-slidebars
* @version 0.4
* @global ocsNavControl
* @preserve
*
* Credits to the Polylang plugin for inspiration
*/

if ( 'undefined' === typeof off_canvas_control_data ) {
var off_canvas_control_data = {};
if ( 'undefined' === typeof ocsNavControl ) {
var ocsNavControl = {};
}

jQuery( document ).ready( function( $ ) {
Expand All @@ -22,41 +24,35 @@ jQuery( document ).ready( function( $ ) {
$this.addClass('off-canvas-control');

/* If control selected, then show it */
if ( off_canvas_control_data.val[ db_id ]['off-canvas-control']) {
var key = off_canvas_control_data.val[ db_id ]['off-canvas-control'];
control_type = ' <i class="item-type-off-canvas-control">(' + off_canvas_control_data.controls[ key ] + ')</i>';
if ( ocsNavControl.val[ db_id ]['off-canvas-control']) {
var key = ocsNavControl.val[ db_id ]['off-canvas-control'];
control_type = ' <i class="item-type-off-canvas-control">(' + ocsNavControl.controls[ key ] + ')</i>';
}
$this.find('.menu-item-bar .item-type').html( off_canvas_control_data.strings.menu_item_type + control_type );
$this.find('.menu-item-bar .item-type').html( ocsNavControl.strings.menu_item_type + control_type );
});

/* change menu type label on selecting a controller */
/* Change menu type label on selecting a controller */
$(document).on( 'change', '.field-off-canvas-control input', function() {
var key = $(this).val();
var control_type = ' <i class="item-type-off-canvas-control">(' + off_canvas_control_data.controls[ key ] + ')</i>';
$(this).parents('.menu-item').find('.menu-item-bar .item-type').html( off_canvas_control_data.strings.menu_item_type + control_type );
var control_type = ' <i class="item-type-off-canvas-control">(' + ocsNavControl.controls[ key ] + ')</i>';
$(this).parents('.menu-item').find('.menu-item-bar .item-type').html( ocsNavControl.strings.menu_item_type + control_type );
} );

/* init/change menu item options */
/* Init/change menu item options */
$('#update-nav-menu').bind( 'click load', function(e) {
if ( e.target && e.target.className && -1 < e.target.className.indexOf('item-edit')) {
$('input[value="#off_canvas_control"][type=text]').parent().parent().parent().each( function() {
var $this = $(this),
item = $this.attr('id').substring(19),
strings = off_canvas_control_data.strings,
controls = off_canvas_control_data.controls,
strings = ocsNavControl.strings,
controls = ocsNavControl.controls,
option;

$this.children('p.field-url, p.field-link-target, .field-xfn, .field-description').remove(); // remove default fields we don't need
// Remove default fields we don't need
$this.children('p.field-url, p.field-link-target, .field-xfn, .field-description').remove();
// Change description width.
$this.children('p.field-css-classes').removeClass('description-thin').addClass('description-wide');

/*option = $('<input>').attr({
type: 'hidden',
id: 'edit-menu-item-title-'+item,
name: 'menu-item-title['+item+']',
value: off_canvas_control_data.title
});
$this.append(option);*/

option = $('<input>').attr( {
type: 'hidden',
id: 'edit-menu-item-url-' + item,
Expand All @@ -81,7 +77,7 @@ jQuery( document ).ready( function( $ ) {
continue;
}
var checked = '';
if (( 'undefined' !== typeof off_canvas_control_data.val[ item ] && key === off_canvas_control_data.val[ item ]['off-canvas-control'] ) ) {
if (( 'undefined' !== typeof ocsNavControl.val[ item ] && key === ocsNavControl.val[ item ]['off-canvas-control'] ) ) {
checked = ' checked="checked"';
}
o += '<input type="radio" id="edit-menu-item-off-canvas-control-' + key + '-item-' + item + '" name="menu-item-off-canvas-control[' + item + ']" value="' + key + '" ' + checked + ' /> ';
Expand All @@ -95,25 +91,7 @@ jQuery( document ).ready( function( $ ) {
if ( 1 === $field_control_options.length ) {
$field_control_options.prop('checked', true);
}
/*
ids = Array('menu_item_type'); // reverse order
// add the fields
for(var i = 0; i < ids.length; i++) {
p = $('<p>').attr('class', 'description');
$(this).prepend(p);
label = $('<label>').attr('for', 'menu-item-'+ids[i]+'-'+item).text(' '+off_canvas_control_data.strings[i]);
p.append(label);
cb = $('<input>').attr({
type: 'checkbox',
id: 'edit-menu-item-'+ids[i]+'-'+item,
name: 'menu-item-'+ids[i]+'['+item+']',
value: 1
});
if ((typeof(off_canvas_control_data.val[item]) != 'undefined' && off_canvas_control_data.val[item][ids[i]] == 1) || (typeof(off_canvas_control_data.val[item]) == 'undefined' && ids[i] == 'show_names')) // show_names as default value
cb.prop('checked', true);
label.prepend(cb);
}
*/

} );
}
} );
Expand Down
12 changes: 9 additions & 3 deletions slidebars/slidebars.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;/*!
;/**
* Slidebars - A jQuery Framework for Off-Canvas Menus and Sidebars
* Version: 2.0.2
* Url: http://www.adchsm.com/slidebars/
Expand All @@ -8,9 +8,15 @@
* License url: http://www.adchsm.com/slidebars/license/
*
* Modified by: Jory Hogeveen
* Version numbers below are related to Off-Canvas Sidebars, not Slidebars.
* Version numbers and info below is related to Off-Canvas Sidebars, not Slidebars.
*
* @since 0.4 Add scope for this reference + Add legacy CSS support (no hardware acceleration)
* @package off-canvas-slidebars
* @author Jory Hogeveen <[email protected]>
*
* @version 0.4
* @since 0.4 Add scope for this reference + Add legacy CSS support (no hardware acceleration)
* @global slidebars
* @preserve
*/

var slidebars;
Expand Down
12 changes: 9 additions & 3 deletions slidebars/slidebars.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cb17f79

Please sign in to comment.