Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop' of github.com:xwp/wp-customize-posts into feat…
Browse files Browse the repository at this point in the history
…ure/add-qunit
  • Loading branch information
mohdsayed committed Dec 14, 2017
2 parents b693ef9 + 2f9a4b0 commit e954fa3
Show file tree
Hide file tree
Showing 32 changed files with 333 additions and 204 deletions.
4 changes: 4 additions & 0 deletions .dev-lib
@@ -1,2 +1,6 @@
WPCS_GIT_TREE=develop
ASSETS_DIR=wp-assets

if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.2" ]] || [[ ${TRAVIS_PHP_VERSION:0:3} == "5.3" ]]; then
DEV_LIB_SKIP="$DEV_LIB_SKIP,phpcs"
fi
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -17,13 +17,13 @@ language:
- node_js

php:
- 5.3
- 5.2
- 7.0

env:
- WP_VERSION=trunk WP_MULTISITE=0
- WP_VERSION=latest WP_MULTISITE=0
- WP_VERSION=4.6.1 WP_MULTISITE=0
- WP_VERSION=4.7.6 WP_MULTISITE=0
- WP_VERSION=latest WP_MULTISITE=1

install:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
@@ -1,7 +1,7 @@
{
"name": "xwp/wp-customize-posts",
"description": "Manage posts and postmeta via the Customizer.",
"version": "0.8.7",
"version": "0.9.1",
"type": "wordpress-plugin",
"keywords": [ "customizer", "customize", "posts", "postmeta", "preview", "featured-image", "page-template" ],
"homepage": "https://github.com/xwp/wp-customize-posts/",
Expand Down
7 changes: 7 additions & 0 deletions css/customize-posts.css
Expand Up @@ -439,3 +439,10 @@ body.customize-posts-content-editor-pane-resize #customize-preview:before {
content: "\f464";
top: -2px;
}

@media screen and (max-width:600px) {
.outer-section-open .select2-container,
.outer-section-open .select2-selection__clear {
z-index: auto !Important;
}
}
3 changes: 2 additions & 1 deletion css/edit-post-preview-customize.css
Expand Up @@ -6,7 +6,8 @@
#customize-header-actions #snapshot-save,
#snapshot-status-button-wrapper,
#snapshot-preview-link,
#snapshot-expand-button
#snapshot-expand-button,
#publish-settings
{
display: none !important;
}
Expand Down
2 changes: 1 addition & 1 deletion customize-posts.php
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Customize Posts
* Description: Manage posts and postmeta via the Customizer.
* Plugin URI: https://github.com/xwp/wp-customize-posts/
* Version: 0.8.7
* Version: 0.9.1
* Author: XWP
* Author URI: https://make.xwp.co/
* License: GPLv2+
Expand Down
2 changes: 1 addition & 1 deletion dev-lib
5 changes: 0 additions & 5 deletions js/customize-featured-image.js
Expand Up @@ -123,11 +123,6 @@ var CustomizeFeaturedImage = (function( api ) {
} );
};

control.active.set( true );
control.active.validate = function validateForcingTrue() {
return true;
};

// Register.
api.control.add( control.id, control );

Expand Down
6 changes: 3 additions & 3 deletions js/customize-page-template.js
Expand Up @@ -50,7 +50,7 @@ var CustomizePageTemplate = (function( api ) {
* @returns {wp.customize.Control|null} The control.
*/
component.addControl = function( section ) {
var supports, control, controlId, settingId, isActiveCallback;
var supports, control, controlId, settingId;
supports = api.Posts.data.postTypes[ section.params.post_type ].supports;

if ( ! supports['page-attributes'] || 'page' !== section.params.post_type ) {
Expand Down Expand Up @@ -103,13 +103,13 @@ var CustomizePageTemplate = (function( api ) {
*
* @returns {boolean} Is active.
*/
isActiveCallback = function() {
function isActiveCallback() {
var defaultSize = 1;
if ( api.has( 'page_for_posts' ) && parseInt( api( 'page_for_posts' ).get(), 10 ) === section.params.post_id ) {
return false;
}
return _.size( control.params.choices ) > defaultSize;
};
}
control.active.set( isActiveCallback() );
control.active.validate = isActiveCallback;
api( 'page_for_posts', function( pageOnFrontSetting ) {
Expand Down
112 changes: 45 additions & 67 deletions js/customize-post-section.js
Expand Up @@ -307,16 +307,17 @@
* unless the notification is specifically for this control's setting property.
*
* @this {wp.customize.Control}
* @param {string} code Notification code.
* @param {wp.customize.Notification} notification Notification object.
* @param {string|wp.customize.Notification} notification - Notification object to add. Alternatively code may be supplied, and in that case the second notificationObject argument must be supplied.
* @param {wp.customize.Notification} [notificationObject] - Notification to add when first argument is the code string.
* @returns {wp.customize.Notification|null} Notification if not bypassed.
*/
addPostFieldControlNotification: function addPostFieldControlNotification( code, notification ) {
var isSettingNotification, isSettingPropertyNotification;
addPostFieldControlNotification: function addPostFieldControlNotification( notification, notificationObject ) {
var isSettingNotification, isSettingPropertyNotification, code;
code = 'string' === typeof notification ? notification : notification.code;
isSettingNotification = -1 !== code.indexOf( ':' ) || notification.setting; // Note that sniffing for ':' is deprecated as of #36944 & #37890.
isSettingPropertyNotification = notification.data && notification.data.setting_property === this.setting_property;
if ( isSettingPropertyNotification || ! isSettingNotification ) {
return api.Values.prototype.add.call( this, code, notification );
return ( api.Notifications || api.Values ).prototype.add.call( this, notification, notificationObject );
} else {
return null;
}
Expand Down Expand Up @@ -393,11 +394,6 @@
}
} );

// Override preview trying to de-activate control not present in preview context. See WP Trac #37270.
control.active.validate = function() {
return true;
};

// Register.
section.postFieldControls.post_title = control;
api.control.add( control.id, control );
Expand Down Expand Up @@ -451,11 +447,6 @@
setting.bind( setPlaceholder );
} );

// Override preview trying to de-activate control not present in preview context. See WP Trac #37270.
control.active.validate = function() {
return true;
};

// Register.
section.postFieldControls.post_name = control;
api.control.add( control.id, control );
Expand Down Expand Up @@ -487,11 +478,6 @@
}
} );

// Override preview trying to de-activate control not present in preview context. See WP Trac #37270.
control.active.validate = function() {
return true;
};

// Register.
section.postFieldControls.post_status = control;
api.control.add( control.id, control );
Expand Down Expand Up @@ -524,11 +510,6 @@
}
} );

// Override preview trying to de-activate control not present in preview context. See WP Trac #37270.
control.active.validate = function() {
return true;
};

// Register.
section.postFieldControls.post_date = control;
api.control.add( control.id, control );
Expand Down Expand Up @@ -617,11 +598,6 @@
}
} );

// Override preview trying to de-activate control not present in preview context. See WP Trac #37270.
control.active.validate = function() {
return true;
};

// Register.
section.postFieldControls.post_excerpt = control;
api.control.add( control.id, control );
Expand Down Expand Up @@ -686,11 +662,6 @@
} );
}

// Override preview trying to de-activate control not present in preview context.
control.active.validate = function() {
return true;
};

// Register.
section.postFieldControls.page_parent = control;
api.control.add( control.id, control );
Expand Down Expand Up @@ -724,11 +695,6 @@
}
} );

// Override preview trying to de-activate control not present in preview context. See WP Trac #37270.
control.active.validate = function() {
return true;
};

// Register.
section.postFieldControls.menu_order = control;
api.control.add( control.id, control );
Expand Down Expand Up @@ -761,11 +727,6 @@
}
} );

// Override preview trying to de-activate control not present in preview context. See WP Trac #37270.
control.active.validate = function() {
return true;
};

// Register.
section.postFieldControls.post_discussion_fields = control;
api.control.add( control.id, control );
Expand Down Expand Up @@ -809,11 +770,6 @@
return data;
};

// Override preview trying to de-activate control not present in preview context. See WP Trac #37270.
control.active.validate = function() {
return true;
};

// Register.
section.postFieldControls.post_author = control;
api.control.add( control.id, control );
Expand All @@ -826,37 +782,27 @@
},

/**
* Set up section notifications.
* Polyfill notifications API onto sections if not yet on WordPress 4.9 where it is defined in core.
*
* @link <https://core.trac.wordpress.org/ticket/38794>
* @returns {void}
*/
setupSectionNotifications: function() {
var section = this, setting = api( section.id ), debouncedRenderNotifications, setPageForPostsNotice;
if ( ! setting.notifications ) {
polyfillNotifications: function() {
var section = this, debouncedRenderNotifications;
if ( section.notifications ) {
return;
}

// Add the notifications API.
section.notifications = new api.Values({ defaultConstructor: api.Notification });
section.notificationsContainer = $( '<div class="customize-control-notifications-container"></div>' );
section.notifications.container = section.notificationsContainer;
section.notificationsTemplate = wp.template( 'customize-post-section-notifications' );
section.container.find( '.customize-section-title' ).after( section.notificationsContainer );
section.getNotificationsContainerElement = function() {
return section.notificationsContainer;
};
section.renderNotifications = api.Control.prototype.renderNotifications;

// Sync setting notifications into the section notifications
setting.notifications.bind( 'add', function( settingNotification ) {
var notification = new api.Notification( setting.id + ':' + settingNotification.code, settingNotification );
if ( ! settingNotification.data || ! settingNotification.data.setting_property || ! api.control.has( section.id + '[' + settingNotification.data.setting_property + ']' ) ) {
section.notifications.add( notification.code, notification );
}
} );
setting.notifications.bind( 'remove', function( settingNotification ) {
section.notifications.remove( setting.id + ':' + settingNotification.code );
} );

/*
* Render notifications when the collection is updated.
* Note that this debounced/deferred rendering is needed for two reasons:
Expand All @@ -872,9 +818,40 @@
} );
section.notifications.bind( 'remove', debouncedRenderNotifications );
section.renderNotifications();
},

/**
* Set up section notifications.
*
* @returns {void}
*/
setupSectionNotifications: function() {
var section = this, setting = api( section.id ), setPageForPostsNotice, notificationTemplate;
if ( ! setting.notifications ) {
return;
}

// Add the notifications API if not present.
section.polyfillNotifications();

// Sync setting notifications into the section notifications
setting.notifications.bind( 'add', function( settingNotification ) {
var notification = new api.Notification( setting.id + ':' + settingNotification.code, _.extend( {},
settingNotification,
{
template: notificationTemplate
}
) );
if ( ! settingNotification.data || ! settingNotification.data.setting_property || ! api.control.has( section.id + '[' + settingNotification.data.setting_property + ']' ) ) {
section.notifications.add( notification.code, notification );
}
} );
setting.notifications.bind( 'remove', function( settingNotification ) {
section.notifications.remove( setting.id + ':' + settingNotification.code );
} );

// Dismiss conflict block when clicking on button.
section.notificationsContainer.on( 'click', '.override-post-conflict', function( e ) {
section.notifications.container.on( 'click', '.override-post-conflict', function( e ) {
var ourValue;
e.preventDefault();
ourValue = _.clone( setting.get() );
Expand All @@ -890,6 +867,7 @@
} );

// Detect conflict errors.
notificationTemplate = wp.template( 'customize-post-field-notification' );
api.bind( 'error', function( response ) {
var theirValue, ourValue,
conflictedControls = [];
Expand Down
37 changes: 26 additions & 11 deletions js/customize-posts.js
Expand Up @@ -571,7 +571,7 @@
* @return {void}
*/
component.focusControl = function focusControl( controlId ) {
var control, section, postSectionId, matches;
var control, section, postSectionId, matches, postId;

/**
* Attempt focus on the control.
Expand All @@ -594,18 +594,33 @@
if ( ! matches ) {
return;
}
postSectionId = 'post[' + matches[1] + '][' + matches[2] + ']';
section = api.section( postSectionId );
if ( ! section || ! section.extended( component.PostSection ) ) {
return;
postId = parseInt( matches[2], 10 );
postSectionId = 'post[' + matches[1] + '][' + String( postId ) + ']';

/**
* Expand and focus on control in section.
*
* @param {component.PostSection} postSection - Section.
* @returns {void}
*/
function sectionResolved( postSection ) {
postSection.expand();
postSection.contentsEmbedded.done( function() {
var ms = 500;

// @todo It is not clear why a delay is needed for focus to work. It could be due to focus failing during animation.
_.delay( tryFocus, ms );
} );
}
section.expand();
section.contentsEmbedded.done( function() {
var ms = 500;

// @todo It is not clear why a delay is needed for focus to work. It could be due to focus failing during animation.
_.delay( tryFocus, ms );
} );
section = api.section( postSectionId );
if ( section ) {
sectionResolved( section );
} else {
api.Posts.ensurePosts( [ postId ] ).done( function( data ) {
sectionResolved( data[ postId ].section );
} );
}
};

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -6,7 +6,7 @@
"type": "git",
"url": "https://github.com/xwp/wp-customize-posts.git"
},
"version": "0.8.7",
"version": "0.9.1",
"license": "GPL-2.0+",
"private": true,
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion php/class-wp-customize-dynamic-control.php
Expand Up @@ -74,7 +74,7 @@ protected function content_template() {
$data = $this->json();
?>
<#
_.defaults( data, <?php echo wp_json_encode( $data ) ?> );
_.defaults( data, <?php echo wp_json_encode( $data ); ?> );
data.input_id = 'input-' + String( Math.random() );
#>
<# if ( 'checkbox' === data.field_type ) { #>
Expand Down

0 comments on commit e954fa3

Please sign in to comment.