Skip to content

Commit

Permalink
Merge pull request #39 from xwp/develop
Browse files Browse the repository at this point in the history
Release 0.4.0
  • Loading branch information
westonruter committed Feb 17, 2017
2 parents 910bcc9 + d7e388a commit 4bbf4bc
Show file tree
Hide file tree
Showing 41 changed files with 2,627 additions and 198 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
**/*.min.js
**/node_modules/**
**/vendor/**
/tests/js/lib/**
**/*.browserified.js
/bower_components/**
5 changes: 5 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
{
"preset": "wordpress",
"requireCamelCaseOrUpperCaseIdentifiers": {
"ignoreProperties": true,
"allExcept": [ "Shortcode_UI" ]
},
"excludeFiles": [
"**/*.min.js",
"**/*.jsx",
"**/node_modules/**",
"**/vendor/**",
"**/tests/**",
"bower_components/**"
]
}
1 change: 1 addition & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
**/vendor/**
**/*.jsx
/bower_components/**
/tests/js/**
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ install:
- source $DEV_LIB_PATH/travis.install.sh

script:
- npm test
- source $DEV_LIB_PATH/travis.script.sh

after_script:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "xwp/wp-js-widgets",
"description": "The next generation of widgets in Core (Widgets 3.0), embracing JS for UI and powering the Widgets REST API.",
"version": "0.3.0",
"version": "0.4.0",
"type": "wordpress-plugin",
"keywords": [ "customizer", "widgets", "rest-api" ],
"homepage": "https://github.com/xwp/wp-js-widgets/",
Expand Down
7 changes: 7 additions & 0 deletions core-adapter-widgets/archives/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
*/
class WP_JS_Widget_Archives extends WP_Adapter_JS_Widget {

/**
* Icon name.
*
* @var string
*/
public $icon_name = 'dashicons-archive';

/**
* WP_JS_Widget_Archives constructor.
*
Expand Down
4 changes: 1 addition & 3 deletions core-adapter-widgets/archives/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ wp.widgets.formConstructor.archives = (function() {
*
* @constructor
*/
ArchivesWidgetForm = wp.widgets.Form.extend( {
id_base: 'archives'
} );
ArchivesWidgetForm = wp.widgets.Form.extend( {} );

if ( 'undefined' !== typeof module ) {
module.exports = ArchivesWidgetForm;
Expand Down
7 changes: 7 additions & 0 deletions core-adapter-widgets/calendar/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
*/
class WP_JS_Widget_Calendar extends WP_Adapter_JS_Widget {

/**
* Icon name.
*
* @var string
*/
public $icon_name = 'dashicons-calendar';

/**
* WP_JS_Widget_Calendar constructor.
*
Expand Down
11 changes: 9 additions & 2 deletions core-adapter-widgets/categories/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
*/
class WP_JS_Widget_Categories extends WP_Adapter_JS_Widget {

/**
* Icon name.
*
* @var string
*/
public $icon_name = 'dashicons-category';

/**
* WP_JS_Widget_Categories constructor.
*
Expand Down Expand Up @@ -164,7 +171,7 @@ public function get_categories_list( $args ) {
public function get_rest_response_links( $response, $request, $controller ) {
$links = array();

$links['wp:term'] = array();
$links['item'] = array();
foreach ( $response->data['terms'] as $term_id ) {
$term = get_term( (int) $term_id );
if ( empty( $term ) || is_wp_error( $term ) ) {
Expand All @@ -178,7 +185,7 @@ public function get_rest_response_links( $response, $request, $controller ) {
$rest_base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name;
$base = sprintf( '/wp/v2/%s', $rest_base );

$links['wp:term'][] = array(
$links['item'][] = array(
'href' => rest_url( trailingslashit( $base ) . $term_id ),
'embeddable' => true,
'taxonomy' => $term->taxonomy,
Expand Down
4 changes: 1 addition & 3 deletions core-adapter-widgets/categories/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ wp.widgets.formConstructor.categories = (function() {
*
* @constructor
*/
CategoriesWidgetForm = wp.widgets.Form.extend( {
id_base: 'categories'
} );
CategoriesWidgetForm = wp.widgets.Form.extend( {} );

if ( 'undefined' !== typeof module ) {
module.exports = CategoriesWidgetForm;
Expand Down
8 changes: 7 additions & 1 deletion core-adapter-widgets/meta/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
*/
class WP_JS_Widget_Meta extends WP_Adapter_JS_Widget {

/**
* Icon name.
*
* @var string
*/
public $icon_name = 'dashicons-wordpress';

/**
* WP_JS_Widget_Meta constructor.
*
Expand All @@ -22,7 +29,6 @@ public function __construct( JS_Widgets_Plugin $plugin, WP_Widget_Meta $adapted_
parent::__construct( $plugin, $adapted_widget );
}


/**
* Get instance schema properties.
*
Expand Down
9 changes: 8 additions & 1 deletion core-adapter-widgets/nav_menu/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
*/
class WP_JS_Widget_Nav_Menu extends WP_Adapter_JS_Widget {

/**
* Icon name.
*
* @var string
*/
public $icon_name = 'dashicons-menu';

/**
* WP_JS_Widget_Nav_Menu constructor.
*
Expand Down Expand Up @@ -101,7 +108,7 @@ public function render_form_template() {
),
) );
?>
<p>
<p class="edit-menu" hidden>
<button type="button" class="button edit"><?php esc_html_e( 'Edit Menu', 'default' ) ?></button>
</p>
</div>
Expand Down
16 changes: 15 additions & 1 deletion core-adapter-widgets/nav_menu/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ wp.widgets.formConstructor.nav_menu = (function( api, $ ) {
initialize: function initialize( properties ) {
var form = this;
wp.widgets.Form.prototype.initialize.call( form, properties );
_.bindAll( form, 'updateForm', 'handleEditButtonClick' );
_.bindAll( form, 'updateForm', 'handleEditButtonClick', 'updateEditButtonVisibility' );

if ( _.isObject( form.config.nav_menus ) && 0 === classProps.navMenuCollection.length ) {
_.each( form.config.nav_menus, function( name, id ) {
Expand All @@ -120,10 +120,12 @@ wp.widgets.formConstructor.nav_menu = (function( api, $ ) {
var form = this;
wp.widgets.Form.prototype.render.call( form );
NavMenuWidgetForm.navMenuCollection.on( 'update change', form.updateForm );
form.model.bind( form.updateEditButtonVisibility );
form.container.find( 'button.edit' ).on( 'click', form.handleEditButtonClick );
form.noMenusMessage = form.container.find( '.no-menus-message' );
form.menuSelection = form.container.find( '.menu-selection' );
form.updateForm();
form.updateEditButtonVisibility();
},

/**
Expand All @@ -135,6 +137,7 @@ wp.widgets.formConstructor.nav_menu = (function( api, $ ) {
var form = this;
form.container.find( 'button.edit' ).off( 'click', form.handleEditButtonClick );
NavMenuWidgetForm.navMenuCollection.off( 'update change', form.updateForm );
form.model.unbind( form.updateEditButtonVisibility );
form.noMenusMessage = null;
form.menuSelection = null;
wp.widgets.Form.prototype.destruct.call( form );
Expand Down Expand Up @@ -182,6 +185,17 @@ wp.widgets.formConstructor.nav_menu = (function( api, $ ) {
select.val( NavMenuWidgetForm.navMenuCollection.has( currentValue.nav_menu ) ? currentValue.nav_menu : 0 );
form.noMenusMessage.toggle( 0 === NavMenuWidgetForm.navMenuCollection.length );
form.menuSelection.toggle( 0 !== NavMenuWidgetForm.navMenuCollection.length );
},

/**
* Update the visibility of the edit button based on whether a menu is selected.
*
* @returns {void}
*/
updateEditButtonVisibility: function updateEditButtonVisibility() {
var form = this, button;
button = form.container.find( '.edit-menu' );
button.toggle( NavMenuWidgetForm.navMenuCollection.length > 0 && form.getValue().nav_menu > 0 );
}

}, classProps );
Expand Down
11 changes: 9 additions & 2 deletions core-adapter-widgets/pages/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class WP_JS_Widget_Pages extends WP_Adapter_JS_Widget {

const ID_LIST_PATTERN = '\d+(,\s*\d+)*';

/**
* Icon name.
*
* @var string
*/
public $icon_name = 'dashicons-admin-page';

/**
* WP_JS_Widget_Pages constructor.
*
Expand Down Expand Up @@ -180,7 +187,7 @@ public function prepare_item_for_response( $instance, $request ) {
public function get_rest_response_links( $response, $request, $controller ) {
$links = array();

$links['wp:page'] = array();
$links['item'] = array();
foreach ( $response->data['pages'] as $post_id ) {
$post = get_post( $post_id );
if ( empty( $post ) ) {
Expand All @@ -194,7 +201,7 @@ public function get_rest_response_links( $response, $request, $controller ) {
$rest_base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name;
$base = sprintf( '/wp/v2/%s', $rest_base );

$links['wp:page'][] = array(
$links['item'][] = array(
'href' => rest_url( trailingslashit( $base ) . $post_id ),
'embeddable' => true,
'post_type' => $post->post_type,
Expand Down
2 changes: 1 addition & 1 deletion core-adapter-widgets/pages/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ wp.widgets.formConstructor.pages = (function( api ) {
excludeIds.push( id );
}
} );
form.model._value.exclude = excludeIds;
}
form.model._value.exclude = excludeIds;

form.syncedProperties.exclude = form.createSyncedPropertyValue( form.model, 'exclude' );
}
Expand Down
11 changes: 9 additions & 2 deletions core-adapter-widgets/recent-comments/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
*/
class WP_JS_Widget_Recent_Comments extends WP_Adapter_JS_Widget {

/**
* Icon name.
*
* @var string
*/
public $icon_name = 'dashicons-admin-comments';

/**
* WP_JS_Widget_Recent_Comments constructor.
*
Expand Down Expand Up @@ -94,9 +101,9 @@ public function prepare_item_for_response( $instance, $request ) {
public function get_rest_response_links( $response, $request, $controller ) {
$links = array();

$links['wp:comment'] = array();
$links['item'] = array();
foreach ( $response->data['comments'] as $comment_id ) {
$links['wp:comment'][] = array(
$links['item'][] = array(
'href' => rest_url( "/wp/v2/comments/$comment_id" ),
'embeddable' => true,
);
Expand Down
11 changes: 9 additions & 2 deletions core-adapter-widgets/recent-posts/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
*/
class WP_JS_Widget_Recent_Posts extends WP_Adapter_JS_Widget {

/**
* Icon name.
*
* @var string
*/
public $icon_name = 'dashicons-admin-post';

/**
* WP_JS_Widget_Recent_Posts constructor.
*
Expand Down Expand Up @@ -104,7 +111,7 @@ public function prepare_item_for_response( $instance, $request ) {
public function get_rest_response_links( $response, $request, $controller ) {
$links = array();

$links['wp:post'] = array();
$links['item'] = array();
foreach ( $response->data['posts'] as $post_id ) {
$post = get_post( $post_id );
if ( empty( $post ) ) {
Expand All @@ -118,7 +125,7 @@ public function get_rest_response_links( $response, $request, $controller ) {
$rest_base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name;
$base = sprintf( '/wp/v2/%s', $rest_base );

$links['wp:post'][] = array(
$links['item'][] = array(
'href' => rest_url( trailingslashit( $base ) . $post_id ),
'embeddable' => true,
'post_type' => $post->post_type,
Expand Down
7 changes: 7 additions & 0 deletions core-adapter-widgets/rss/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
*/
class WP_JS_Widget_RSS extends WP_Adapter_JS_Widget {

/**
* Icon name.
*
* @var string
*/
public $icon_name = 'dashicons-rss';

/**
* WP_JS_Widget_RSS constructor.
*
Expand Down
7 changes: 7 additions & 0 deletions core-adapter-widgets/search/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
*/
class WP_JS_Widget_Search extends WP_Adapter_JS_Widget {

/**
* Icon name.
*
* @var string
*/
public $icon_name = 'dashicons-search';

/**
* WP_JS_Widget_Search constructor.
*
Expand Down
Loading

0 comments on commit 4bbf4bc

Please sign in to comment.