Skip to content

Commit 44243ac

Browse files
committed
Merge pull request #93 from x-team/live-preview-without-manual-submit
See live preview changes as-you-type, without hitting Update button
2 parents b246a9b + f92a887 commit 44243ac

File tree

4 files changed

+247
-42
lines changed

4 files changed

+247
-42
lines changed

class-options-transaction.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ class Options_Transaction {
1010
*/
1111
public $options = array();
1212

13+
protected $_ignore_transients = true;
1314
protected $_is_current = false;
1415
protected $_operations = array();
1516

17+
function __construct( $ignore_transients = true ) {
18+
$this->_ignore_transients = $ignore_transients;
19+
}
20+
1621
/**
1722
* Determine whether or not the transaction is open
1823
* @return bool
@@ -21,6 +26,14 @@ function is_current() {
2126
return $this->_is_current;
2227
}
2328

29+
/**
30+
* @param $option_name
31+
* @return boolean
32+
*/
33+
function is_option_ignored( $option_name ) {
34+
return ( $this->_ignore_transients && 0 === strpos( $option_name, '_transient_' ) );
35+
}
36+
2437
/**
2538
* Get the number of operations performed in the transaction
2639
* @return bool
@@ -46,6 +59,9 @@ function start() {
4659
* @param $new_value
4760
*/
4861
function _capture_added_option( $option_name, $new_value ) {
62+
if ( $this->is_option_ignored( $option_name ) ) {
63+
return;
64+
}
4965
$this->options[$option_name] = $new_value;
5066
$operation = 'add';
5167
$this->_operations[] = compact( 'operation', 'option_name', 'new_value' );
@@ -58,6 +74,9 @@ function _capture_added_option( $option_name, $new_value ) {
5874
* @param mixed $new_value
5975
*/
6076
function _capture_updated_option( $option_name, $old_value, $new_value ) {
77+
if ( $this->is_option_ignored( $option_name ) ) {
78+
return;
79+
}
6180
$this->options[$option_name] = $new_value;
6281
$operation = 'update';
6382
$this->_operations[] = compact( 'operation', 'option_name', 'old_value', 'new_value' );
@@ -72,8 +91,10 @@ function _capture_updated_option( $option_name, $old_value, $new_value ) {
7291
* @param string $option_name
7392
*/
7493
function _capture_pre_deleted_option( $option_name ) {
94+
if ( $this->is_option_ignored( $option_name ) ) {
95+
return;
96+
}
7597
global $wpdb;
76-
7798
$autoload = $wpdb->get_var( $wpdb->prepare( "SELECT autoload FROM $wpdb->options WHERE option_name = %s", $option_name ) ); // db call ok; no-cache ok
7899
$this->_pending_delete_option_autoload = $autoload;
79100
$this->_pending_delete_option_value = get_option( $option_name );
@@ -84,6 +105,9 @@ function _capture_pre_deleted_option( $option_name ) {
84105
* @param string $option_name
85106
*/
86107
function _capture_deleted_option( $option_name ) {
108+
if ( $this->is_option_ignored( $option_name ) ) {
109+
return;
110+
}
87111
unset( $this->options[$option_name] );
88112
$operation = 'delete';
89113
$old_value = $this->_pending_delete_option_value;

widget-customizer.css

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,22 @@
5050
opacity: 0.5;
5151
}
5252

53-
.customize-control-widget_form.previewer-loading .spinner {
53+
54+
.customize-control-widget_form.is-live-previewable .widget-control-save {
55+
display: none;
56+
}
57+
58+
.customize-control-widget_form .spinner {
5459
display: inline;
60+
opacity: 0.0;
61+
-webkit-transition: opacity 0.1s;
62+
transition: opacity 0.1s;
63+
}
64+
.customize-control-widget_form.previewer-loading .spinner {
65+
opacity: 1.0;
5566
}
5667

57-
.customize-control-widget_form.widget-form-loading .widget-content {
68+
.customize-control-widget_form.widget-form-loading:not(.is-live-previewable) .widget-content {
5869
opacity: 0.7;
5970
pointer-events: none;
6071
-moz-user-select: none;

0 commit comments

Comments
 (0)