Skip to content

Commit 702979a

Browse files
committed
#3945 - Glitch in validation code caused color picker failure in rare use case.
Signed-off-by: Kev Provance <[email protected]>
1 parent a964098 commit 702979a

File tree

15 files changed

+140
-95
lines changed

15 files changed

+140
-95
lines changed

redux-core/assets/css/redux-fields.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

redux-core/assets/css/redux-fields.min.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

redux-core/assets/js/redux.js

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@
7979
data: $data
8080
},
8181
error: function( response ) {
82-
$( '.redux-action_bar input' ).prop( 'disabled', false );
82+
var input = $( '.redux-action_bar input' );
83+
84+
input.prop( 'disabled', false );
8385

8486
if ( true === redux.optName.args.dev_mode ) {
8587
console.log( response.responseText );
@@ -91,7 +93,7 @@
9193
redux.optName.args.ajax_save = false;
9294

9395
$( button ).trigger( 'click' );
94-
$( '.redux-action_bar input' ).prop( 'disabled', true );
96+
input.prop( 'disabled', true );
9597
}
9698
},
9799
success: function( response ) {
@@ -158,7 +160,7 @@ function colorValidate( field ) {
158160
function colorNameToHex( colour ) {
159161
'use strict';
160162

161-
var tcolour = colour.replace( /^\s\s*/, '' ).replace( /\s\s*$/, '' ).replace( '#', '' );
163+
var tcolour = colour.replace( /^\s+/, '' ).replace( /\s+$/, '' ).replace( '#', '' );
162164

163165
var colours = {
164166
'aliceblue': '#f0f8ff',
@@ -685,6 +687,7 @@ function colorNameToHex( colour ) {
685687
function() {
686688
var opt_name;
687689
var tempArr = [];
690+
var container;
688691

689692
$.fn.isOnScreen = function() {
690693
var win;
@@ -718,7 +721,9 @@ function colorNameToHex( colour ) {
718721
$( '.wp-full-overlay-sidebar' ).addClass( 'redux-container' );
719722
}
720723

721-
$( '.redux-container' ).each(
724+
container = $( '.redux-container' );
725+
726+
container.each(
722727
function() {
723728
opt_name = $.redux.getOptName( this );
724729

@@ -730,7 +735,7 @@ function colorNameToHex( colour ) {
730735
}
731736
);
732737

733-
$( '.redux-container' ).on(
738+
container.on(
734739
'click',
735740
function() {
736741
opt_name = $.redux.getOptName( this );
@@ -819,7 +824,6 @@ function colorNameToHex( colour ) {
819824

820825
$.redux.getOptName = function( el ) {
821826
var metabox;
822-
var li;
823827
var optName;
824828
var item = $( el );
825829

@@ -829,7 +833,7 @@ function colorNameToHex( colour ) {
829833
optName = $( el ).parents( '.redux-wrap-div' ).data( 'opt-name' );
830834
}
831835

832-
// Compatibility for metaboxes
836+
// Compatibility for metaboxes.
833837
if ( undefined === optName ) {
834838
metabox = $( el ).parents( '.postbox' );
835839
if ( 0 === metabox.length ) {
@@ -956,7 +960,10 @@ function colorNameToHex( colour ) {
956960
function( key, value ) {
957961
var fieldset = $( '#' + redux.optName.args.opt_name + '-' + value.id );
958962

959-
fieldset.addClass( 'redux-field-error' );
963+
if ( '' !== value.msg ) {
964+
fieldset.addClass( 'redux-field-error' );
965+
}
966+
960967
if ( 0 === fieldset.parent().find( '.redux-th-error' ).length ) {
961968
fieldset.append( '<div class="redux-th-error">' + value.msg + '</div>' );
962969
} else {
@@ -1019,7 +1026,9 @@ function colorNameToHex( colour ) {
10191026
function( key, value ) {
10201027
var fieldset = $( '#' + redux.optName.args.opt_name + '-' + value.id );
10211028

1022-
fieldset.addClass( 'redux-field-warning' );
1029+
if ( '' !== value.msg ) {
1030+
fieldset.addClass( 'redux-field-warning' );
1031+
}
10231032

10241033
if ( 0 === fieldset.parent().find( '.redux-th-warning' ).length ) {
10251034
fieldset.append( '<div class="redux-th-warning">' + value.msg + '</div>' );
@@ -1309,7 +1318,6 @@ function redux_change( variable ) {
13091318

13101319
(function( $ ) {
13111320
var rContainer;
1312-
var opt_name;
13131321
var parentID;
13141322
var id;
13151323
var th;
@@ -1324,12 +1332,6 @@ function redux_change( variable ) {
13241332

13251333
rContainer = $( variable ).parents( '.redux-container:first' );
13261334

1327-
if ( redux.customizer ) {
1328-
opt_name = $( '.redux-customizer-opt-name' ).data( 'opt-name' );
1329-
} else {
1330-
opt_name = $.redux.getOptName( rContainer );
1331-
}
1332-
13331335
$( 'body' ).trigger( 'check_dependencies', variable );
13341336

13351337
if ( variable.hasClass( 'compiler' ) ) {
@@ -1360,12 +1362,12 @@ function redux_change( variable ) {
13601362
$( variable ).parents( '.redux-container:first' ).find( '.redux-field-errors' ).slideUp();
13611363
$( '#redux_metaboxes_errors' ).slideUp();
13621364
} else {
1363-
errorsLeft = ( parseInt( th.find( '.redux-menu-error:first' ).text(), 0 ) - 1 );
1365+
errorsLeft = ( parseInt( th.find( 'li .redux-menu-error:first' ).text(), 0 ) - 1 );
13641366

13651367
if ( errorsLeft <= 0 ) {
13661368
th.find( '.redux-menu-error:first' ).fadeOut().remove();
13671369
} else {
1368-
th.find( '.redux-menu-error:first' ).text( errorsLeft );
1370+
th.find( 'li .redux-menu-error:first' ).text( errorsLeft );
13691371
}
13701372

13711373
rContainer.find( '.redux-field-errors span' ).text( errorCount );
@@ -1393,15 +1395,15 @@ function redux_change( variable ) {
13931395
} else {
13941396

13951397
// Let's count down the warnings now. Fancy. ;).
1396-
warningsLeft = ( parseInt( th.find( '.redux-menu-warning:first' ).text(), 0 ) - 1 );
1398+
warningsLeft = ( parseInt( th.find( 'li .redux-menu-warning:first' ).text(), 0 ) - 1 );
13971399

13981400
if ( warningsLeft <= 0 ) {
13991401
th.find( '.redux-menu-warning:first' ).fadeOut().remove();
14001402
} else {
14011403
th.find( '.redux-menu-warning:first' ).text( warningsLeft );
14021404
}
14031405

1404-
rContainer.find( '.redux-field-warning span' ).text( warningCount );
1406+
rContainer.find( 'li .redux-field-warning span' ).text( warningCount );
14051407
}
14061408

14071409
if ( 0 !== subParent.length ) {
@@ -1465,17 +1467,21 @@ function redux_hook( object, functionName, callback, before ) {
14651467
};
14661468

14671469
$.redux.checkRequired = function( el ) {
1470+
var body;
1471+
14681472
$.redux.required();
14691473

1470-
$( 'body' ).on(
1474+
body = $( 'body' );
1475+
1476+
body.on(
14711477
'change',
14721478
'.redux-main select, .redux-main radio, .redux-main input[type=checkbox], .redux-main input[type=hidden]',
14731479
function() {
14741480
$.redux.check_dependencies( this );
14751481
}
14761482
);
14771483

1478-
$( 'body' ).on(
1484+
body.on(
14791485
'check_dependencies',
14801486
function( e, variable ) {
14811487
e = null;
@@ -1494,7 +1500,7 @@ function redux_hook( object, functionName, callback, before ) {
14941500

14951501
// Hide the fold elements on load.
14961502
// It's better to do this by PHP but there is no filter in tr tag , so is not possible
1497-
// we going to move each attributes we may need for folding to tr tag.
1503+
// we're going to move each attributes we may need for folding to tr tag.
14981504
$.each(
14991505
redux.opt_names,
15001506
function( x ) {
@@ -1540,13 +1546,17 @@ function redux_hook( object, functionName, callback, before ) {
15401546
};
15411547

15421548
$.redux.getContainerValue = function( id ) {
1543-
var value = $( '#' + redux.optName.args.opt_name + '-' + id ).serializeForm();
1549+
var theId;
1550+
var value;
1551+
1552+
theId = $( '#' + redux.optName.args.opt_name + '-' + id );
1553+
value = theId.serializeForm();
15441554

15451555
if ( null !== value && 'object' === typeof value && value.hasOwnProperty( redux.optName.args.opt_name ) ) {
15461556
value = value[redux.optName.args.opt_name][id];
15471557
}
15481558

1549-
if ( $( '#' + redux.optName.args.opt_name + '-' + id ).hasClass( 'redux-container-media' ) ) {
1559+
if ( theId.hasClass( 'redux-container-media' ) ) {
15501560
value = value.url;
15511561
}
15521562

@@ -1659,18 +1669,21 @@ function redux_hook( object, functionName, callback, before ) {
16591669
var div;
16601670
var rawTable;
16611671
var toFade;
1672+
var theId;
16621673

1663-
toFade = $( '#' + redux.optName.args.opt_name + '-' + id ).parents( 'tr:first' );
1674+
theId = $( '#' + redux.optName.args.opt_name + '-' + id );
1675+
1676+
toFade = theId.parents( 'tr:first' );
16641677
if ( 0 === toFade ) {
1665-
toFade = $( '#' + redux.optName.args.opt_name + '-' + id ).parents( 'li:first' );
1678+
toFade = theId.parents( 'li:first' );
16661679
}
16671680

16681681
toFade.fadeOut(
16691682
50,
16701683
function() {
16711684
$( this ).addClass( 'hide' );
16721685

1673-
if ( $( '#' + redux.optName.args.opt_name + '-' + id ).hasClass( 'redux-container-section' ) ) {
1686+
if ( theId.hasClass( 'redux-container-section' ) ) {
16741687
div = $( '#section-' + id );
16751688

16761689
if ( div.hasClass( 'redux-section-indent-start' ) ) {
@@ -1679,15 +1692,15 @@ function redux_hook( object, functionName, callback, before ) {
16791692
}
16801693
}
16811694

1682-
if ( $( '#' + redux.optName.args.opt_name + '-' + id ).hasClass( 'redux-container-info' ) ) {
1695+
if ( theId.hasClass( 'redux-container-info' ) ) {
16831696
$( '#info-' + id ).fadeOut( 50 ).addClass( 'hide' );
16841697
}
16851698

1686-
if ( $( '#' + redux.optName.args.opt_name + '-' + id ).hasClass( 'redux-container-divide' ) ) {
1699+
if ( theId.hasClass( 'redux-container-divide' ) ) {
16871700
$( '#divide-' + id ).fadeOut( 50 ).addClass( 'hide' );
16881701
}
16891702

1690-
if ( $( '#' + redux.optName.args.opt_name + '-' + id ).hasClass( 'redux-container-raw' ) ) {
1703+
if ( theId.hasClass( 'redux-container-raw' ) ) {
16911704
rawTable = $( '#' + redux.optName.args.opt_name + '-' + id ).parents().find( 'table#' + redux.optName.args.opt_name + '-' + id );
16921705
rawTable.fadeOut( 50 ).addClass( 'hide' );
16931706
}
@@ -1712,12 +1725,15 @@ function redux_hook( object, functionName, callback, before ) {
17121725
redux.optName.required_child[id],
17131726
function( i, parentData ) {
17141727
var parentValue;
1728+
var parent;
1729+
1730+
parent = $( '#' + redux.optName.args.opt_name + '-' + parentData.parent );
17151731

17161732
i = null;
17171733

1718-
if ( $( '#' + redux.optName.args.opt_name + '-' + parentData.parent ).parents( 'tr:first' ).hasClass( 'hide' ) ) {
1734+
if ( parent.parents( 'tr:first' ).hasClass( 'hide' ) ) {
17191735
show = false;
1720-
} else if ( $( '#' + redux.optName.args.opt_name + '-' + parentData.parent ).parents( 'li:first' ).hasClass( 'hide' ) ) {
1736+
} else if ( parent.parents( 'li:first' ).hasClass( 'hide' ) ) {
17211737
show = false;
17221738
} else {
17231739
if ( false !== show ) {
@@ -2009,30 +2025,33 @@ function redux_hook( object, functionName, callback, before ) {
20092025
$.redux = $.redux || {};
20102026

20112027
$.redux.stickyInfo = function() {
2028+
var sticky = $( '#redux-sticky' );
2029+
var infoBar = $( '#info_bar' );
2030+
var reduxFooter = $( '#redux-footer' );
20122031
var stickyWidth = $( '.redux-main' ).innerWidth() - 20;
2013-
var $width = $( '#redux-sticky' ).offset().left;
2032+
var $width = sticky.offset().left;
20142033

20152034
$( '.redux-save-warn' ).css( 'left', $width + 'px' );
20162035

2017-
if ( ! $( '#info_bar' ).isOnScreen() && ! $( '#redux-footer-sticky' ).isOnScreen() ) {
2018-
$( '#redux-footer' ).css(
2036+
if ( ! infoBar.isOnScreen() && ! $( '#redux-footer-sticky' ).isOnScreen() ) {
2037+
reduxFooter.css(
20192038
{ position: 'fixed', bottom: '0', width: stickyWidth, right: 21 }
20202039
);
20212040

2022-
$( '#redux-footer' ).addClass( 'sticky-footer-fixed' );
2041+
reduxFooter.addClass( 'sticky-footer-fixed' );
20232042
$( '#redux-sticky-padder' ).show();
20242043
} else {
2025-
$( '#redux-footer' ).css(
2044+
reduxFooter.css(
20262045
{ background: '#eee', position: 'inherit', bottom: 'inherit', width: 'inherit' }
20272046
);
20282047

20292048
$( '#redux-sticky-padder' ).hide();
2030-
$( '#redux-footer' ).removeClass( 'sticky-footer-fixed' );
2049+
reduxFooter.removeClass( 'sticky-footer-fixed' );
20312050
}
2032-
if ( ! $( '#info_bar' ).isOnScreen() ) {
2033-
$( '#redux-sticky' ).addClass( 'sticky-save-warn' );
2051+
if ( ! infoBar.isOnScreen() ) {
2052+
sticky.addClass( 'sticky-save-warn' );
20342053
} else {
2035-
$( '#redux-sticky' ).removeClass( 'sticky-save-warn' );
2054+
sticky.removeClass( 'sticky-save-warn' );
20362055
}
20372056
};
20382057
})( jQuery );
@@ -2073,9 +2092,9 @@ function redux_hook( object, functionName, callback, before ) {
20732092
link = elements.slice( index + 1, index + 2 );
20742093
}
20752094

2076-
el = link.parents( '.redux-container:first' );
2077-
relid = link.data( 'rel' ); // The group ID of interest.
2078-
oldid = el.find( '.redux-group-tab-link-li.active:first .redux-group-tab-link-a' ).data( 'rel' );
2095+
el = link.parents( '.redux-container:first' );
2096+
relid = link.data( 'rel' ); // The group ID of interest.
2097+
oldid = el.find( '.redux-group-tab-link-li.active:first .redux-group-tab-link-a' ).data( 'rel' );
20792098
opt_name = $.redux.getOptName( el );
20802099

20812100
if ( oldid === relid ) {

redux-core/assets/js/redux.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

redux-core/assets/js/redux/ajax-save.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@
7979
data: $data
8080
},
8181
error: function( response ) {
82-
$( '.redux-action_bar input' ).prop( 'disabled', false );
82+
var input = $( '.redux-action_bar input' );
83+
84+
input.prop( 'disabled', false );
8385

8486
if ( true === redux.optName.args.dev_mode ) {
8587
console.log( response.responseText );
@@ -91,7 +93,7 @@
9193
redux.optName.args.ajax_save = false;
9294

9395
$( button ).trigger( 'click' );
94-
$( '.redux-action_bar input' ).prop( 'disabled', true );
96+
input.prop( 'disabled', true );
9597
}
9698
},
9799
success: function( response ) {

redux-core/assets/js/redux/color-validate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function colorValidate( field ) {
1616
function colorNameToHex( colour ) {
1717
'use strict';
1818

19-
var tcolour = colour.replace( /^\s\s*/, '' ).replace( /\s\s*$/, '' ).replace( '#', '' );
19+
var tcolour = colour.replace( /^\s+/, '' ).replace( /\s+$/, '' ).replace( '#', '' );
2020

2121
var colours = {
2222
'aliceblue': '#f0f8ff',

redux-core/assets/js/redux/main.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
function() {
1010
var opt_name;
1111
var tempArr = [];
12+
var container;
1213

1314
$.fn.isOnScreen = function() {
1415
var win;
@@ -42,7 +43,9 @@
4243
$( '.wp-full-overlay-sidebar' ).addClass( 'redux-container' );
4344
}
4445

45-
$( '.redux-container' ).each(
46+
container = $( '.redux-container' );
47+
48+
container.each(
4649
function() {
4750
opt_name = $.redux.getOptName( this );
4851

@@ -54,7 +57,7 @@
5457
}
5558
);
5659

57-
$( '.redux-container' ).on(
60+
container.on(
5861
'click',
5962
function() {
6063
opt_name = $.redux.getOptName( this );
@@ -143,7 +146,6 @@
143146

144147
$.redux.getOptName = function( el ) {
145148
var metabox;
146-
var li;
147149
var optName;
148150
var item = $( el );
149151

@@ -153,7 +155,7 @@
153155
optName = $( el ).parents( '.redux-wrap-div' ).data( 'opt-name' );
154156
}
155157

156-
// Compatibility for metaboxes
158+
// Compatibility for metaboxes.
157159
if ( undefined === optName ) {
158160
metabox = $( el ).parents( '.postbox' );
159161
if ( 0 === metabox.length ) {

0 commit comments

Comments
 (0)