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

Commit

Permalink
Merge 58f0ce9 into c7b9124
Browse files Browse the repository at this point in the history
  • Loading branch information
Sayed Taqui committed Mar 14, 2017
2 parents c7b9124 + 58f0ce9 commit 7eb4ba9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
8 changes: 6 additions & 2 deletions js/compat/customize-snapshots.js
Expand Up @@ -20,7 +20,6 @@

api.bind( 'ready', function() {
api.state.create( 'snapshot-exists', snapshot.data.snapshotExists );
snapshot.extendPreviewerQuery();

if ( api.state( 'snapshot-exists' ).get() ) {
api.state( 'saved' ).set( false );
Expand Down Expand Up @@ -270,7 +269,12 @@
if ( ! snapshot.data.currentUserCanPublish ) {
snapshot.snapshotButton.attr( 'title', api.state( 'snapshot-exists' ).get() ? snapshot.data.i18n.permsMsg.update : snapshot.data.i18n.permsMsg.save );
}
snapshot.snapshotButton.prop( 'disabled', true );

if ( api.state( 'activated' ).get() ) {
snapshot.snapshotButton.prop( 'disabled', true );
} else if ( ! api.state( 'activated' ).get() && snapshot.data.themeSaved ) {
snapshot.snapshotButton.prop( 'disabled', true );
}

snapshot.snapshotButton.on( 'click', function( event ) {
var status;
Expand Down
43 changes: 27 additions & 16 deletions js/customize-snapshots.js
Expand Up @@ -19,6 +19,7 @@
initialServerDate: '',
initialServerTimestamp: 0,
initialClientTimestamp: 0,
theme: '',
i18n: {},
dirty: false
},
Expand Down Expand Up @@ -51,6 +52,8 @@
api.state( 'snapshot-exists' ).set( true );
}

snapshot.extendPreviewerQuery();

snapshot.editControlSettings = new api.Values();
snapshot.editControlSettings.create( 'title', snapshot.data.title );
snapshot.editControlSettings.create( 'date', snapshot.data.publishDate );
Expand Down Expand Up @@ -104,15 +107,22 @@
* @return {{}} Query vars for scroll, device, url, and autofocus.
*/
getStateQueryVars: function() {
var queryVars = {
var snapshot = this, currentTheme, queryVars;

queryVars = {
'autofocus[control]': null,
'autofocus[section]': null,
'autofocus[panel]': null
};
currentTheme = api.settings.theme.stylesheet;
queryVars.scroll = parseInt( api.previewer.scroll, 10 ) || 0;
queryVars.device = api.previewedDevice.get();
queryVars.url = api.previewer.previewUrl.get();

if ( ! api.state( 'activated' ).get() || snapshot.data.theme !== currentTheme ) {
queryVars.previewingTheme = true;
}

_.find( [ 'control', 'section', 'panel' ], function( constructType ) {
var found = false;
api[ constructType ].each( function( construct ) { // @todo Core needs to support more Backbone methods on wp.customize.Values().
Expand Down Expand Up @@ -255,6 +265,7 @@
dialogElement;

snapshot.statusButton.disableSelect.set( false );
snapshot.statusButton.disbleButton.set( false );

if ( response.setting_validities ) {
invalidityCount = _.size( response.setting_validities, function( validity ) {
Expand Down Expand Up @@ -303,25 +314,30 @@
* @return {void}
*/
addButtons: function addButtons() {
var snapshot = this, setPreviewLinkHref;
var snapshot = this, disableButton = true,
setPreviewLinkHref, currentTheme;

currentTheme = api.settings.theme.stylesheet;
snapshot.spinner = $( '#customize-header-actions' ).find( '.spinner' );
snapshot.publishButton = $( '#save' );

snapshot.publishButton.addClass( 'hidden' );
snapshot.statusButton = snapshot.addStatusButton();
snapshot.statusButton.disbleButton.set( true );

if ( api.state( 'changesetStatus' ).get() ) {
if ( 'auto-draft' === api.state( 'changesetStatus' ).get() ) {
snapshot.statusButton.disable( false );
disableButton = false;
} else {
snapshot.statusButton.updateButtonText( 'alt-text' );
}
} else {
snapshot.statusButton.disable( true );
}

if ( ! api.state( 'activated' ).get() || snapshot.data.theme !== currentTheme ) {
disableButton = false;
}

snapshot.statusButton.disable( disableButton );

// Preview link.
snapshot.previewLink = $( $.trim( wp.template( 'snapshot-preview-link' )() ) );
snapshot.previewLink.toggle( api.state( 'snapshot-saved' ).get() );
Expand Down Expand Up @@ -632,7 +648,7 @@
*/
autoSaveEditBox: function() {
var snapshot = this, update,
delay = 2000, status, isValidChangesetStatus, isFutureDateAndStatus;
delay = 2000, status, isFutureDateAndStatus;

snapshot.updatePending = false;
snapshot.dirtyEditControlValues = false;
Expand Down Expand Up @@ -684,16 +700,7 @@
return undefined;
} );

isValidChangesetStatus = function() {
return _.contains( [ 'future', 'pending', 'draft' ], api.state( 'changesetStatus' ).get() );
};

// @todo Show loader and disable button while auto saving.
api.bind( 'changeset-save', function() {
if ( isValidChangesetStatus() ) {
snapshot.extendPreviewerQuery();
}
} );

api.bind( 'changeset-saved', function() {
if ( 'auto-draft' !== api.state( 'changesetStatus' ).get() ) {
Expand Down Expand Up @@ -1000,6 +1007,10 @@
api.previewer.query = function() {
var retval = originalQuery.apply( this, arguments );

if ( ! _.contains( [ 'future', 'pending', 'draft' ], snapshot.statusButton.value.get() ) ) {
return retval;
}

retval.customizer_state_query_vars = JSON.stringify( snapshot.getStateQueryVars() );

if ( snapshot.editControlSettings( 'title' ).get() ) {
Expand Down
3 changes: 3 additions & 0 deletions php/class-customize-snapshot-manager-back-compat.php
Expand Up @@ -91,6 +91,7 @@ public function enqueue_controls_scripts() {
if ( $this->snapshot ) {
$post = $this->snapshot->post();
$this->override_post_date_default_data( $post );
$preview_url_query_vars = $this->post_type->get_customizer_state_query_vars( $post->ID );
}

// Script data array.
Expand All @@ -104,6 +105,8 @@ public function enqueue_controls_scripts() {
'currentUserCanPublish' => current_user_can( 'customize_publish' ),
'initialServerDate' => current_time( 'mysql', false ),
'initialServerTimestamp' => floor( microtime( true ) * 1000 ),
'theme' => $this->original_stylesheet,
'themeSaved' => isset( $preview_url_query_vars['theme'] ),
'i18n' => array(
'saveButton' => __( 'Save', 'customize-snapshots' ),
'updateButton' => __( 'Update', 'customize-snapshots' ),
Expand Down
2 changes: 2 additions & 0 deletions php/class-customize-snapshot-manager.php
Expand Up @@ -281,6 +281,7 @@ public function enqueue_controls_scripts() {
$this->override_post_date_default_data( $post );
$edit_link = $this->snapshot->get_edit_link( $post );
}
$preview_url_query_vars = $this->post_type->get_customizer_state_query_vars( $post_id );
}

// Script data array.
Expand All @@ -292,6 +293,7 @@ public function enqueue_controls_scripts() {
'currentUserCanPublish' => current_user_can( 'customize_publish' ),
'initialServerDate' => current_time( 'mysql', false ),
'initialServerTimestamp' => floor( microtime( true ) * 1000 ),
'theme' => isset( $preview_url_query_vars['theme'] ) ? $preview_url_query_vars['theme'] : $this->original_stylesheet,
'i18n' => array(
'saveButton' => __( 'Save', 'customize-snapshots' ),
'updateButton' => __( 'Update', 'customize-snapshots' ),
Expand Down
19 changes: 14 additions & 5 deletions php/class-post-type.php
Expand Up @@ -898,6 +898,9 @@ public function set_customizer_state_query_vars( $post_id, $query_vars ) {
if ( isset( $query_vars['scroll'] ) && is_int( $query_vars['scroll'] ) ) {
$stored_query_vars['scroll'] = $query_vars['scroll'];
}
if ( isset( $query_vars['previewingTheme'] ) ) {
$stored_query_vars['theme'] = $this->snapshot_manager->customize_manager->get_stylesheet();
}
update_post_meta( $post_id, '_preview_url_query_vars', $stored_query_vars );
return $stored_query_vars;
}
Expand All @@ -917,11 +920,17 @@ public function get_frontend_view_link( $post ) {
$post = get_post( $post );
$preview_url_query_vars = $this->get_customizer_state_query_vars( $post->ID );
$base_url = isset( $preview_url_query_vars['url'] ) ? $preview_url_query_vars['url'] : home_url( '/' );
return add_query_arg(
array(
static::FRONT_UUID_PARAM_NAME => $post->post_name,
),
$base_url
$current_theme = get_stylesheet();
$args = array(
static::FRONT_UUID_PARAM_NAME => $post->post_name,
);

if ( isset( $preview_url_query_vars['theme'] ) && $current_theme !== $preview_url_query_vars['theme'] ) {
$args = array_merge( $args, array(
'theme' => $preview_url_query_vars['theme'],
) );
}

return add_query_arg( $args, $base_url );
}
}

0 comments on commit 7eb4ba9

Please sign in to comment.