Skip to content

Commit 01ac3cc

Browse files
Merge pull request #20 from MachoThemes/master
Update to 1.2.0
2 parents 6d7565c + 3fbac10 commit 01ac3cc

24 files changed

+745
-183
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/node_modules/
33
.idea/
44
/.standard.json
5+
shapely-companion.zip

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"jQuery": false,
1919
"wp": false,
2020
"shapelyCompanion": false,
21+
"wpNavMenu" : false,
2122
"Masonry" : false
2223
}
2324
}

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
sudo: false
22
language: php
3+
dist: precise
34
matrix:
45
fast_finish: true
56
include:
@@ -9,15 +10,17 @@ matrix:
910
- php: '5.6'
1011
- php: '7.0'
1112
- php: '7.1'
12-
env: SNIFF=1
13+
env:
14+
- DEPLOY=1
15+
- SNIFF=1
1316
before_script:
1417
- export PHPCS_DIR=/tmp/phpcs
1518
- export SNIFFS_DIR=/tmp/sniffs
1619
- if [[ "$SNIFF" == "1" ]]; then git clone -b 2.9 --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git
1720
$PHPCS_DIR; fi
1821
- if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git
1922
$SNIFFS_DIR; fi
20-
- if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/wimg/PHPCompatibility.git
23+
- if [[ "$SNIFF" == "1" ]]; then git clone -b 7.1.4 --depth 1 https://github.com/wimg/PHPCompatibility.git
2124
$SNIFFS_DIR/PHPCompatibility; fi
2225
- if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs --config-set installed_paths
2326
$SNIFFS_DIR; fi

assets/js/nav-menu.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
(function( $ ) {// jscs:ignore validateLineBreaks
2+
3+
'use strict';
4+
var api;
5+
6+
api = wpNavMenu;
7+
8+
$( '#submit-shapelysection' ).click( function( evt ) {
9+
var section = $( '#shapelysectionsdiv' ).find( '#shapely-section-item-widget' ).val(),
10+
label = $( '#shapelysectionsdiv' ).find( '#shapely-section-item-name' ).val(),
11+
url = $( '#shapelysectionsdiv' ).find( '#shapely-section-item-url' ).val();
12+
13+
evt.preventDefault();
14+
15+
if ( '0' === section || '' === label || '' === url ) {
16+
$( '#shapelysectionsdiv' ).addClass( 'form-invalid' );
17+
return false;
18+
}
19+
20+
$( '.customlinkdiv .spinner' ).addClass( 'is-active' );
21+
22+
api.addItemToMenu( {
23+
'-1': {
24+
'menu-item-type': 'custom',
25+
'menu-item-extra': 'shapely-section',
26+
'menu-item-url': url,
27+
'menu-item-widget': section,
28+
'menu-item-title': label
29+
}
30+
}, api.addMenuItemToBottom, shapelyMenuAdded );
31+
32+
} );
33+
34+
function shapelyMenuAdded() {
35+
36+
// Remove the ajax spinner
37+
$( '#shapelysectionsdiv .spinner' ).removeClass( 'is-active' );
38+
39+
// Set custom link form back to defaults
40+
$( '#shapelysectionsdiv #shapely-section-item-widget' ).val( '0' ).blur();
41+
$( '#shapelysectionsdiv #shapely-section-item-url' ).val( '' ).blur();
42+
$( '#shapelysectionsdiv #shapely-section-item-name' ).val( '' ).blur();
43+
44+
}
45+
46+
})( jQuery );

assets/js/widget.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ jQuery( document ).ready(function() {// jscs:ignore validateLineBreaks
33
/* Clonning of Logo Client Widgets */
44
jQuery( document ).on( 'widget-added', function() {
55
shapelySort();
6+
shapelyCreateColorPicker();
67
});
78
jQuery( document ).on( 'widget-updated', function() {
89
shapelySort();
10+
shapelyCreateColorPicker();
911
});
1012

1113
shapelySort();
14+
shapelyCreateColorPicker();
1215

1316
/* Client widget sorting and cloning*/
1417
/* Font awsome selector */
@@ -48,4 +51,11 @@ jQuery( document ).ready(function() {// jscs:ignore validateLineBreaks
4851

4952
}
5053

54+
function shapelyCreateColorPicker() {
55+
var colorPickers = jQuery( '.shapely-color-picker' );
56+
if ( colorPickers.length > 0 ) {
57+
colorPickers.wpColorPicker();
58+
}
59+
}
60+
5161
});
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
<?php
2+
3+
if ( ! class_exists( 'Walker_Nav_Menu ' ) ) {
4+
return;
5+
}
6+
7+
class Shapely_Walker_Nav_Menu_Edit extends Walker_Nav_Menu {
8+
9+
public function start_lvl( &$output, $depth = 0, $args = array() ) {
10+
}
11+
12+
public function end_lvl( &$output, $depth = 0, $args = array() ) {
13+
}
14+
15+
public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
16+
global $_wp_nav_menu_max_depth;
17+
$_wp_nav_menu_max_depth = $depth > $_wp_nav_menu_max_depth ? $depth : $_wp_nav_menu_max_depth;
18+
19+
ob_start();
20+
$item_id = esc_attr( $item->ID );
21+
$removed_args = array(
22+
'action',
23+
'customlink-tab',
24+
'edit-menu-item',
25+
'menu-item',
26+
'page-tab',
27+
'_wpnonce',
28+
);
29+
30+
$original_title = false;
31+
if ( 'taxonomy' == $item->type ) {
32+
$original_title = get_term_field( 'name', $item->object_id, $item->object, 'raw' );
33+
if ( is_wp_error( $original_title ) ) {
34+
$original_title = false;
35+
}
36+
} elseif ( 'post_type' == $item->type ) {
37+
$original_object = get_post( $item->object_id );
38+
$original_title = get_the_title( $original_object->ID );
39+
} elseif ( 'post_type_archive' == $item->type ) {
40+
$original_object = get_post_type_object( $item->object );
41+
if ( $original_object ) {
42+
$original_title = $original_object->labels->archives;
43+
}
44+
}
45+
46+
$extra = get_post_meta( $item_id, '_menu_item_extra', true );
47+
$widget = get_post_meta( $item_id, '_menu_item_widget', true );
48+
49+
if ( 'shapely-section' == $extra ) {
50+
$item->type_label = __( 'Homepage Widget', 'shapely-companion' );
51+
}
52+
53+
$classes = array(
54+
'menu-item menu-item-depth-' . $depth,
55+
'menu-item-' . esc_attr( $item->object ),
56+
'menu-item-edit-' . ( ( isset( $_GET['edit-menu-item'] ) && $item_id == $_GET['edit-menu-item'] ) ? 'active' : 'inactive' ),
57+
);
58+
59+
$title = $item->title;
60+
61+
if ( ! empty( $item->_invalid ) ) {
62+
$classes[] = 'menu-item-invalid';
63+
/* translators: %s: title of menu item which is invalid */
64+
$title = sprintf( __( '%s (Invalid)', 'shapely-companion' ), $item->title );
65+
} elseif ( isset( $item->post_status ) && 'draft' == $item->post_status ) {
66+
$classes[] = 'pending';
67+
/* translators: %s: title of menu item in draft status */
68+
$title = sprintf( __( '%s (Pending)', 'shapely-companion' ), $item->title );
69+
}
70+
71+
$title = ( ! isset( $item->label ) || '' == $item->label ) ? $title : $item->label;
72+
73+
$submenu_text = '';
74+
if ( 0 == $depth ) {
75+
$submenu_text = 'style="display: none;"';
76+
}
77+
$move_up_url = wp_nonce_url( add_query_arg(
78+
array(
79+
'action' => 'move-up-menu-item',
80+
'menu-item' => $item_id,
81+
),
82+
remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
83+
), 'move-menu_item' );
84+
$move_down_url = wp_nonce_url( add_query_arg(
85+
array(
86+
'action' => 'move-down-menu-item',
87+
'menu-item' => $item_id,
88+
),
89+
remove_query_arg( $removed_args, admin_url( 'nav-menus.php' ) )
90+
), 'move-menu_item' );
91+
92+
?>
93+
<li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode( ' ', $classes ); ?>">
94+
<div class="menu-item-bar">
95+
<div class="menu-item-handle">
96+
<span class="item-title">
97+
<span class="menu-item-title">
98+
<?php echo esc_html( $title ); ?>
99+
</span>
100+
<span class="is-submenu" <?php echo $submenu_text; ?>> <?php _e( 'sub item', 'shapely-companion' ); ?></span>
101+
</span> <span class="item-controls">
102+
<span class="item-type"><?php echo esc_html( $item->type_label ); ?></span>
103+
<span class="item-order hide-if-js">
104+
<a href="<?php echo $move_up_url; ?>" class="item-move-up" aria-label="<?php esc_attr_e( 'Move up', 'shapely-companion' ); ?>">&#8593;</a>
105+
|
106+
<a href="<?php echo $move_down_url; ?>" class="item-move-down" aria-label="<?php esc_attr_e( 'Move down', 'shapely-companion' ); ?>">&#8595;</a>
107+
</span>
108+
<a class="item-edit" id="edit-<?php echo $item_id; ?>" 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 ) ) ); ?>" aria-label="<?php esc_attr_e( 'Edit menu item', 'shapely-companion' ); ?>"><span class="screen-reader-text"><?php _e( 'Edit', 'shapely-companion' ); ?></span></a>
109+
</span>
110+
</div>
111+
</div>
112+
113+
<div class="menu-item-settings wp-clearfix" id="menu-item-settings-<?php echo $item_id; ?>">
114+
<?php if ( 'custom' == $item->type ) : ?>
115+
<p class="field-url description description-wide">
116+
<label for="edit-menu-item-url-<?php echo $item_id; ?>">
117+
<?php _e( 'URL', 'shapely-companion' ); ?><br/>
118+
<input type="text" id="edit-menu-item-url-<?php echo $item_id; ?>" class="widefat code edit-menu-item-url" name="menu-item-url[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->url ); ?>"/>
119+
</label>
120+
</p>
121+
<?php endif; ?>
122+
<p class="description description-wide">
123+
<label for="edit-menu-item-title-<?php echo $item_id; ?>">
124+
<?php _e( 'Navigation Label', 'shapely-companion' ); ?><br/>
125+
<input type="text" id="edit-menu-item-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-title" name="menu-item-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->title ); ?>"/>
126+
</label>
127+
</p>
128+
<p class="field-title-attribute field-attr-title description description-wide">
129+
<label for="edit-menu-item-attr-title-<?php echo $item_id; ?>">
130+
<?php _e( 'Title Attribute', 'shapely-companion' ); ?><br/>
131+
<input type="text" id="edit-menu-item-attr-title-<?php echo $item_id; ?>" class="widefat edit-menu-item-attr-title" name="menu-item-attr-title[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->post_excerpt ); ?>"/>
132+
</label>
133+
</p>
134+
<p class="field-link-target description">
135+
<label for="edit-menu-item-target-<?php echo $item_id; ?>">
136+
<input type="checkbox" id="edit-menu-item-target-<?php echo $item_id; ?>" value="_blank" name="menu-item-target[<?php echo $item_id; ?>]"<?php checked( $item->target, '_blank' ); ?> />
137+
<?php _e( 'Open link in a new tab', 'shapely-companion' ); ?>
138+
</label>
139+
</p>
140+
<p class="field-css-classes description description-thin">
141+
<label for="edit-menu-item-classes-<?php echo $item_id; ?>">
142+
<?php _e( 'CSS Classes (optional)', 'shapely-companion' ); ?><br/>
143+
<input type="text" id="edit-menu-item-classes-<?php echo $item_id; ?>" class="widefat code edit-menu-item-classes" name="menu-item-classes[<?php echo $item_id; ?>]" value="<?php echo esc_attr( implode( ' ', $item->classes ) ); ?>"/>
144+
</label>
145+
</p>
146+
<p class="field-xfn description description-thin">
147+
<label for="edit-menu-item-xfn-<?php echo $item_id; ?>">
148+
<?php _e( 'Link Relationship (XFN)', 'shapely-companion' ); ?><br/>
149+
<input type="text" id="edit-menu-item-xfn-<?php echo $item_id; ?>" class="widefat code edit-menu-item-xfn" name="menu-item-xfn[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->xfn ); ?>"/>
150+
</label>
151+
</p>
152+
<p class="field-description description description-wide">
153+
<label for="edit-menu-item-description-<?php echo $item_id; ?>">
154+
<?php _e( 'Description', 'shapely-companion' ); ?><br/>
155+
<textarea id="edit-menu-item-description-<?php echo $item_id; ?>" class="widefat edit-menu-item-description" rows="3" cols="20" name="menu-item-description[<?php echo $item_id; ?>]"><?php echo esc_html( $item->description ); ?></textarea>
156+
<span class="description"><?php _e( 'The description will be displayed in the menu if the current theme supports it.', 'shapely-companion' ); ?></span>
157+
</label>
158+
</p>
159+
160+
<fieldset class="field-move hide-if-no-js description description-wide">
161+
<span class="field-move-visual-label" aria-hidden="true"><?php _e( 'Move', 'shapely-companion' ); ?></span>
162+
<button type="button" class="button-link menus-move menus-move-up" data-dir="up"><?php _e( 'Up one', 'shapely-companion' ); ?></button>
163+
<button type="button" class="button-link menus-move menus-move-down" data-dir="down"><?php _e( 'Down one', 'shapely-companion' ); ?></button>
164+
<button type="button" class="button-link menus-move menus-move-left" data-dir="left"></button>
165+
<button type="button" class="button-link menus-move menus-move-right" data-dir="right"></button>
166+
<button type="button" class="button-link menus-move menus-move-top" data-dir="top"><?php _e( 'To the top', 'shapely-companion' ); ?></button>
167+
</fieldset>
168+
169+
<div class="menu-item-actions description-wide submitbox">
170+
<?php if ( 'custom' != $item->type && false !== $original_title ) : ?>
171+
<p class="link-to-original">
172+
<?php printf( __( 'Original: %s', 'shapely-companion' ), '<a href="' . esc_attr( $item->url ) . '">' . esc_html( $original_title ) . '</a>' ); ?>
173+
</p>
174+
<?php endif; ?>
175+
<a class="item-delete submitdelete deletion" id="delete-<?php echo $item_id; ?>" href="
176+
<?php
177+
echo wp_nonce_url( add_query_arg(
178+
array(
179+
'action' => 'delete-menu-item',
180+
'menu-item' => $item_id,
181+
),
182+
admin_url( 'nav-menus.php' )
183+
), 'delete-menu_item_' . $item_id );
184+
?>
185+
"><?php _e( 'Remove', 'shapely-companion' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span>
186+
<a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="
187+
<?php
188+
echo esc_url( add_query_arg( array(
189+
'edit-menu-item' => $item_id,
190+
'cancel' => time(),
191+
), admin_url( 'nav-menus.php' ) ) );
192+
?>
193+
#menu-item-settings-<?php echo $item_id; ?>"><?php _e( 'Cancel', 'shapely-companion' ); ?></a>
194+
</div>
195+
196+
<input class="menu-item-data-db-id" type="hidden" name="menu-item-db-id[<?php echo $item_id; ?>]" value="<?php echo $item_id; ?>"/>
197+
<input class="menu-item-data-object-id" type="hidden" name="menu-item-object-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object_id ); ?>"/>
198+
<input class="menu-item-data-object" type="hidden" name="menu-item-object[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->object ); ?>"/>
199+
<input class="menu-item-data-parent-id" type="hidden" name="menu-item-parent-id[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_item_parent ); ?>"/>
200+
<input class="menu-item-data-position" type="hidden" name="menu-item-position[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->menu_order ); ?>"/>
201+
<input class="menu-item-data-type" type="hidden" name="menu-item-type[<?php echo $item_id; ?>]" value="<?php echo esc_attr( $item->type ); ?>"/>
202+
</div><!-- .menu-item-settings-->
203+
<ul class="menu-item-transport"></ul>
204+
<?php
205+
$output .= ob_get_clean();
206+
}
207+
208+
} // Shapely_Walker_Nav_Menu_Edit

inc/shapely-demo-content.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function shapely_companion_add_default_widgets() {
5252

5353
#add current widget with his index and args
5454
$widgets[ $index_widget ] = get_object_vars( $args );
55-
55+
5656
}
5757
#update widgets who are like current widget
5858
update_option( 'widget_' . $widget_name, $widgets );
@@ -74,16 +74,20 @@ function shapely_companion_import_content() {
7474
$frontpage_title = __( 'Front Page', 'shapely-companion' );
7575
$blog_title = __( 'Blog', 'shapely-companion' );
7676

77-
$frontpage_id = wp_insert_post( array(
78-
'post_title' => $frontpage_title,
79-
'post_status' => 'publish',
80-
'post_type' => 'page',
81-
) );
82-
$blog_id = wp_insert_post( array(
83-
'post_title' => $blog_title,
84-
'post_status' => 'publish',
85-
'post_type' => 'page',
86-
) );
77+
$frontpage_id = wp_insert_post(
78+
array(
79+
'post_title' => $frontpage_title,
80+
'post_status' => 'publish',
81+
'post_type' => 'page',
82+
)
83+
);
84+
$blog_id = wp_insert_post(
85+
array(
86+
'post_title' => $blog_title,
87+
'post_status' => 'publish',
88+
'post_type' => 'page',
89+
)
90+
);
8791

8892
if ( - 1 != $frontpage_id ) {
8993
update_post_meta( $frontpage_id, '_wp_page_template', 'page-templates/template-home.php' );

inc/shapely-enqueues.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,24 @@
77
function shapely_companion_admin_scripts( $hook ) {
88
wp_enqueue_style( 'shapely-companion-admin-css', plugins_url( 'assets/css/admin.css', dirname( __FILE__ ) ) );
99
wp_enqueue_script( 'shapely-companion-admin-js', plugins_url( 'assets/js/admin.js', dirname( __FILE__ ) ), array( 'jquery' ) );
10-
wp_localize_script( 'shapely-companion-admin-js', 'shapelyCompanion', array(
11-
'ajaxurl' => admin_url( 'admin-ajax.php' ),
12-
) );
13-
if ( 'widgets.php' == $hook || 'customize.php' == $hook ) {
10+
wp_localize_script(
11+
'shapely-companion-admin-js', 'shapelyCompanion', array(
12+
'ajaxurl' => admin_url( 'admin-ajax.php' ),
13+
)
14+
);
15+
if ( 'widgets.php' == $hook || 'customize.php' == $hook ) {
1416
wp_enqueue_media();
1517
wp_enqueue_script( 'shapely_cloneya_js', plugins_url( 'assets/js/vendor/jquery-cloneya.min.js', dirname( __FILE__ ) ), array( 'jquery' ) );
16-
wp_enqueue_script( 'widget-js', plugins_url( 'assets/js/widget.js', dirname( __FILE__ ) ), array( 'media-upload' ), '1.0', true );
18+
wp_enqueue_style( 'wp-color-picker' );
19+
wp_enqueue_script( 'widget-js', plugins_url( 'assets/js/widget.js', dirname( __FILE__ ) ), array( 'media-upload', 'wp-color-picker' ), '1.0', true );
1720
// Add Font Awesome stylesheet
1821
wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/assets/css/font-awesome.min.css' );
1922
}
23+
24+
if ( 'nav-menus.php' == $hook ) {
25+
wp_enqueue_script( 'shapley-nav-menu-js', plugins_url( 'assets/js/nav-menu.js', dirname( __FILE__ ) ), array( 'nav-menu' ), '1.0', true );
26+
}
27+
2028
}
2129

2230
function shapely_companion_customizer_live_preview() {

0 commit comments

Comments
 (0)