diff --git a/lib/classes/class-customizer.php b/lib/classes/class-customizer.php
index 3fec3c5..5347fe4 100644
--- a/lib/classes/class-customizer.php
+++ b/lib/classes/class-customizer.php
@@ -343,6 +343,8 @@ public function prepare_setting( $i ) {
'section' => false,
'control' => false, // values: 'background-image', 'color', 'background-color', 'border-color', 'image'
'selector' => false,
+ 'min_width' => '',
+ 'max_width' => '',
'extra_controls' => false
) );
@@ -373,6 +375,8 @@ public function prepare_setting( $i ) {
foreach( $i[ 'extra_controls' ] as $control => $selector ){
$to_add[ 'control' ] = $control;
$to_add[ 'selector' ] = $selector;
+ $to_add[ 'min_width' ] = $i[ 'min_width' ];
+ $to_add[ 'max_width' ] = $i[ 'max_width' ];
$to_parse[] = $to_add;
}
}
@@ -382,12 +386,24 @@ public function prepare_setting( $i ) {
foreach( $to_parse as $i ){
//** Add CSS rules */
+ $media_query = '';
+ if ( ! empty( $i['min_width'] ) || ! empty( $i['max_width'] ) ) {
+ $media_query .= 'only screen and';
+ if ( ! empty( $i['min_width'] ) ) {
+ $media_query .= ' (min-width: ' . $i['min_width'] . ')';
+ }
+ if ( ! empty( $i['max_width'] ) ) {
+ $media_query .= ' (max-width: ' . $i['max_width'] . ')';
+ }
+ }
+
$rule = array(
'mod_name' => $i[ 'key' ],
'selector' => $i[ 'selector' ],
'style' => false,
'prefix' => '',
'postfix' => '',
+ 'media_query' => $media_query,
'type' => 'style', // style, image
'important' => true, // must default to true for backwards compatibility
);
@@ -470,7 +486,8 @@ public function generate_css( $args ) {
'style' => '',
'mod_name' => '',
'prefix' => '',
- 'postfix' => ''
+ 'postfix' => '',
+ 'media_query' => '',
) ) );
$return = '';
$mod = get_theme_mod( $mod_name );
@@ -483,12 +500,16 @@ public function generate_css( $args ) {
if ( ! empty( $mod ) ) {
- $return = sprintf( '%s { %s: %s%s; }' . "\r\n",
- $selector,
- $style,
- $prefix.$mod.$postfix,
- $important ? ' !important' : ''
- );
+ $return = sprintf( '%s { %s: %s%s; }' . "\r\n",
+ $selector,
+ $style,
+ $prefix.$mod.$postfix,
+ $important ? ' !important' : ''
+ );
+
+ if ( is_string( $media_query ) && ! empty( trim( $media_query ) ) ) {
+ $return = '@media ' . $media_query . ' { ' . $return . ' } ';
+ }
}
return $return;
}
diff --git a/package.json b/package.json
index c6972fd..2db74b2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "lib-wp-theme",
- "version": "0.3.9",
+ "version": "0.4.0",
"private": true,
"repository": {
"type": "git",
diff --git a/scripts/src/udx.wp.customizer.js b/scripts/src/udx.wp.customizer.js
index 0adf5f9..b8356b5 100644
--- a/scripts/src/udx.wp.customizer.js
+++ b/scripts/src/udx.wp.customizer.js
@@ -35,6 +35,9 @@
for ( var i in c ) {
v += c[ i ].selector + ' { ' + c[ i ].style + ':' + c[ i ].prefix + style + c[ i ].postfix + ' !important; } ';
}
+ if ( typeof c[0].media_query === 'string' && c[0].media_query.trim() !== '' ) {
+ v = '@media ' + c[0].media_query + ' { ' + v + ' } ';
+ }
}
$( 'head #lib_wp_theme_customizer_' + mod_name ).text( v );
}
diff --git a/scripts/udx.wp.customizer.js b/scripts/udx.wp.customizer.js
index e7f90e8..95d85b5 100644
--- a/scripts/udx.wp.customizer.js
+++ b/scripts/udx.wp.customizer.js
@@ -1 +1 @@
-!function(a,b){function c(b){if(a("#lib_wp_theme_customizer_"+b).length)return null;var c=a('');a("head").append(c)}function d(b,c){if(b&&b.length>0){var d="",e=b[0].mod_name;if(c&&c.length>0)for(var f in b)d+=b[f].selector+" { "+b[f].style+":"+b[f].prefix+c+b[f].postfix+" !important; } ";a("head #lib_wp_theme_customizer_"+e).text(d)}}function e(b,c){if(c&&c.length>0)for(var d in b)b[d].selector.length>0&&a(b[d].selector).attr("src",c)}a.each(b.settings,function(a,b){switch(b.control){case"image":wp.customize(b.key,function(a){a.bind(function(a){e(b.css,a)})});break;default:wp.customize(b.key,function(a){var e;c(b.key),a.bind(function(a){window.clearTimeout(e),e=window.setTimeout(function(){d(b.css,a)},200)})})}})}(jQuery,_lib_wp_theme_customizer);
\ No newline at end of file
+!function(a,b){function c(b){if(a("#lib_wp_theme_customizer_"+b).length)return null;var c=a('');a("head").append(c)}function d(b,c){if(b&&b.length>0){var d="",e=b[0].mod_name;if(c&&c.length>0){for(var f in b)d+=b[f].selector+" { "+b[f].style+":"+b[f].prefix+c+b[f].postfix+" !important; } ";"string"==typeof b[0].media_query&&""!==b[0].media_query.trim()&&(d="@media "+b[0].media_query+" { "+d+" } ")}a("head #lib_wp_theme_customizer_"+e).text(d)}}function e(b,c){if(c&&c.length>0)for(var d in b)b[d].selector.length>0&&a(b[d].selector).attr("src",c)}a.each(b.settings,function(a,b){switch(b.control){case"image":wp.customize(b.key,function(a){a.bind(function(a){e(b.css,a)})});break;default:wp.customize(b.key,function(a){var e;c(b.key),a.bind(function(a){window.clearTimeout(e),e=window.setTimeout(function(){d(b.css,a)},200)})})}})}(jQuery,_lib_wp_theme_customizer);
\ No newline at end of file