From 39811fb54553727676e036b36fce83ead689a0f1 Mon Sep 17 00:00:00 2001 From: Braam Genis Date: Tue, 23 May 2017 15:32:26 +0200 Subject: [PATCH 01/10] To fix #9. Use `home_url` instead of `site_url` to determine where to open CSS preview. --- build | 2 +- so-css.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/build b/build index bc118dd..5fc61aa 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit bc118dd703dbe89e483115d6184e226dd28ea67f +Subproject commit 5fc61aa4b19cdb3cad8cab48a42e11a0d5b8256e diff --git a/so-css.php b/so-css.php index 63e0c20..33a1994 100644 --- a/so-css.php +++ b/so-css.php @@ -186,7 +186,9 @@ function enqueue_admin_scripts( $page ){ wp_localize_script( 'siteorigin-custom-css', 'socssOptions', array( 'themeCSS' => SiteOrigin_CSS::single()->get_theme_css(), - 'homeURL' => add_query_arg( 'so_css_preview', '1', site_url() ), + // Pretty confusing, but it seems we should be using `home_url` and NOT `site_url` + // as described here => https://wordpress.stackexchange.com/a/50605 + 'homeURL' => add_query_arg( 'so_css_preview', '1', home_url() ), 'snippets' => $this->get_snippets(), 'propertyControllers' => apply_filters( 'siteorigin_css_property_controllers', $this->get_property_controllers() ), From adf34eb76c14e2ed3f44983cf021c30f9177cdfa Mon Sep 17 00:00:00 2001 From: Braam Genis Date: Tue, 23 May 2017 17:26:45 +0200 Subject: [PATCH 02/10] To resolve #32. Increment and decrement buttons work when value empty or zero. Also added repeating action while button held down. --- js/editor.js | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/js/editor.js b/js/editor.js index be677e1..d2e3d26 100644 --- a/js/editor.js +++ b/js/editor.js @@ -1481,32 +1481,46 @@ var $dec = $('
').appendTo($diw); var $inc = $('
').appendTo($diw); - // Increment is clicked - $inc.click( function(){ - var value = thisView.parseUnits( $el.val() ); - if( value.value === '' ) { - return true; + var stepValue = function( direction ) { + var value = Number.parseInt( thisView.parseUnits( $el.val() ).value ); + + if( Number.isNaN( value ) ) { + value = 0; } - var newVal = Math.ceil( value.value * 1.05 ); + var newVal = value + direction; $fi.val( newVal ); updateValue(); $el.trigger('change').trigger('measurement_refresh'); - } ); + }; - $dec.click( function(){ - var value = thisView.parseUnits( $el.val() ); - if( value.value === '' ) { - return true; - } + var setupStepButton = function ( $button ) { + var direction = $button.is( '.dec-button' ) ? -1 : 1; + var intervalId; + var timeoutId; + $button.mousedown( function(){ + stepValue( direction ); + timeoutId = setTimeout( function () { + intervalId = setInterval( function () { + stepValue( direction ); + }, 50 ); + }, 500 ); + } ).on( 'mouseup mouseout', function(){ + if ( timeoutId ) { + clearTimeout( timeoutId ); + timeoutId = null; + } + if ( intervalId ) { + clearInterval( intervalId ); + intervalId = null; + } + } ); + }; - var newVal = Math.floor( value.value / 1.05 ); + setupStepButton( $dec ); + setupStepButton( $inc ); - $fi.val( newVal ); - updateValue(); - $el.trigger('change').trigger('measurement_refresh'); - } ); } } ); From d9bfc6d9f1a039381a09ed61786192443fd15b5e Mon Sep 17 00:00:00 2001 From: Braam Genis Date: Wed, 24 May 2017 11:56:07 +0200 Subject: [PATCH 03/10] To fix #36. Scroll editor instead of the whole page so 'Save' button is always visible. --- js/editor.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/js/editor.js b/js/editor.js index d2e3d26..b65e5aa 100644 --- a/js/editor.js +++ b/js/editor.js @@ -290,12 +290,23 @@ * Scale the size of the editor depending on whether it's expanded or not */ scaleEditor: function () { + var windowHeight = $( window ).outerHeight(); if (this.$el.hasClass('expanded')) { // If we're in the expanded view, then resize the editor - this.codeMirror.setSize('100%', $(window).outerHeight() - this.$('.custom-css-toolbar').outerHeight()); + this.$el.find( '.CodeMirror-scroll' ).css( 'max-height', '' ); + this.codeMirror.setSize('100%', windowHeight - this.$('.custom-css-toolbar').outerHeight()); } else { - this.codeMirror.setSize('100%', 'auto'); + // Attempt to calculate approximate space available for editor when not expanded. + var $form = $( '#so-custom-css-form' ); + var otherEltsHeight = $('#wpadminbar').outerHeight( true ) + + $( '#siteorigin-custom-css' ).find( '> h2' ).outerHeight( true ) + + $form.find( '> .custom-css-toolbar' ).outerHeight( true ) + + $form.find( '> p.description' ).outerHeight( true ) + + $form.find( '> p.submit' ).outerHeight( true ) + + parseFloat( $( '#wpbody-content' ).css( 'padding-bottom' ) ); + this.$el.find( '.CodeMirror-scroll' ).css( 'max-height', windowHeight - otherEltsHeight ); + this.codeMirror.setSize( '100%', 'auto' ); } }, From 5c505a7acfbc5f3b3aa2bf70d076b66a9e5f243d Mon Sep 17 00:00:00 2001 From: Braam Genis Date: Wed, 24 May 2017 12:09:50 +0200 Subject: [PATCH 04/10] To fix #60. Set color CSS on visual editor and inspector. --- css/admin.css | 1 + css/admin.less | 1 + css/inspector.css | 1 + css/inspector.less | 1 + 4 files changed, 4 insertions(+) diff --git a/css/admin.css b/css/admin.css index 00a0e68..f899bbe 100644 --- a/css/admin.css +++ b/css/admin.css @@ -1,4 +1,5 @@ #siteorigin-custom-css { + color: #333; margin: 0 0 0 -20px; } #siteorigin-custom-css h2 { diff --git a/css/admin.less b/css/admin.less index 0b1962a..2f0dae9 100644 --- a/css/admin.less +++ b/css/admin.less @@ -1,6 +1,7 @@ @import "mixins"; #siteorigin-custom-css { + color: #333; margin: 0 0 0 -20px; h2 { diff --git a/css/inspector.css b/css/inspector.css index bc375ca..16bce95 100644 --- a/css/inspector.css +++ b/css/inspector.css @@ -1,4 +1,5 @@ #socss-inspector-interface { + color: #333; display: none; position: fixed; bottom: 0; diff --git a/css/inspector.less b/css/inspector.less index 18ac06b..06a30cc 100644 --- a/css/inspector.less +++ b/css/inspector.less @@ -1,4 +1,5 @@ #socss-inspector-interface { + color: #333; display: none; position: fixed; bottom: 0; From e3d8355e602b49808d36020adc4e93070340a613 Mon Sep 17 00:00:00 2001 From: Braam Genis Date: Mon, 26 Jun 2017 16:45:21 +0200 Subject: [PATCH 05/10] To resolve #17. Saving generated CSS to stylesheet file in uploads directory. --- so-css.php | 65 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/so-css.php b/so-css.php index 9c626e6..cbfa3d8 100644 --- a/so-css.php +++ b/so-css.php @@ -76,13 +76,28 @@ static function single(){ * Display the custom CSS in the header. */ function action_wp_head(){ - $custom_css = get_option( 'siteorigin_custom_css[' . $this->theme . ']', '' ); - if ( empty( $custom_css ) ) return; - - // We just need to enqueue a dummy style - echo "\n"; + $upload_dir = wp_upload_dir(); + $upload_dir_path = $upload_dir['basedir'] . '/so-css/'; + + $css_file_name = 'so-css-' . $this->theme; + $css_file_path = $upload_dir_path . $css_file_name . '.css'; + + if ( file_exists( $css_file_path ) ) { + wp_enqueue_style( + 'so-css-' . $this->theme, + set_url_scheme( $upload_dir['baseurl'] . '/so-css/' . $css_file_name . '.css' ), + array(), + SOCSS_VERSION + ); + } else { + $custom_css = get_option( 'siteorigin_custom_css[' . $this->theme . ']', '' ); + if ( ! empty( $custom_css ) ) { + // We just need to enqueue a dummy style + echo "\n"; + } + } } function set_plugin_textdomain(){ @@ -97,24 +112,23 @@ function action_admin_menu(){ if ( current_user_can('edit_theme_options') && isset( $_POST['siteorigin_custom_css_save'] ) ) { check_admin_referer( 'custom_css', '_sononce' ); - $theme = basename( get_template_directory() ); // Sanitize CSS input. Should keep most tags, apart from script and style tags. $custom_css = self::sanitize_css( filter_input(INPUT_POST, 'custom_css' ) ); - $current = get_option('siteorigin_custom_css[' . $theme . ']'); + $current = get_option('siteorigin_custom_css[' . $this->theme . ']'); if( $current === false ) { - add_option( 'siteorigin_custom_css[' . $theme . ']', $custom_css , '', 'no' ); + add_option( 'siteorigin_custom_css[' . $this->theme . ']', $custom_css , '', 'no' ); } else { - update_option( 'siteorigin_custom_css[' . $theme . ']', $custom_css ); + update_option( 'siteorigin_custom_css[' . $this->theme . ']', $custom_css ); } // If this has changed, then add a revision. if ( $current != $custom_css ) { - $revisions = get_option( 'siteorigin_custom_css_revisions[' . $theme . ']' ); + $revisions = get_option( 'siteorigin_custom_css_revisions[' . $this->theme . ']' ); if ( empty( $revisions ) ) { - add_option( 'siteorigin_custom_css_revisions[' . $theme . ']', array(), '', 'no' ); + add_option( 'siteorigin_custom_css_revisions[' . $this->theme . ']', array(), '', 'no' ); $revisions = array(); } $revisions[ time() ] = $custom_css; @@ -123,7 +137,30 @@ function action_admin_menu(){ krsort($revisions); $revisions = array_slice($revisions, 0, 15, true); - update_option( 'siteorigin_custom_css_revisions[' . $theme . ']', $revisions ); + update_option( 'siteorigin_custom_css_revisions[' . $this->theme . ']', $revisions ); + + if( WP_Filesystem() ) { + global $wp_filesystem; + $upload_dir = wp_upload_dir(); + $upload_dir_path = $upload_dir['basedir'] . '/so-css/'; + + if ( ! $wp_filesystem->is_dir( $upload_dir_path ) ) { + $wp_filesystem->mkdir( $upload_dir_path ); + } + + $css_file_name = 'so-css-' . $this->theme; + $css_file_path = $upload_dir_path . $css_file_name . '.css'; + + if ( file_exists( $css_file_path ) ) { + $wp_filesystem->delete( $css_file_path ); + } + + $wp_filesystem->put_contents( + $css_file_path, + $custom_css + ); + + } } } } From 7bb8ffcb8a59fc8aedced3d96ef8f12673ede89e Mon Sep 17 00:00:00 2001 From: Braam Genis Date: Mon, 26 Jun 2017 21:02:58 +0200 Subject: [PATCH 06/10] Don't load saved CSS file when in preview and use revision timestamp for cache busting. --- so-css.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/so-css.php b/so-css.php index cbfa3d8..a268d64 100644 --- a/so-css.php +++ b/so-css.php @@ -45,7 +45,7 @@ function __construct(){ // The request to hide the getting started video add_action( 'wp_ajax_socss_hide_getting_started', array( $this, 'admin_action_hide_getting_started' ) ); - if( isset($_GET['so_css_preview']) && !is_admin() ) { + if( isset( $_GET['so_css_preview'] ) && !is_admin() ) { add_action( 'plugins_loaded', array($this, 'disable_ngg_resource_manager') ); add_filter( 'show_admin_bar', '__return_false' ); @@ -82,12 +82,12 @@ function action_wp_head(){ $css_file_name = 'so-css-' . $this->theme; $css_file_path = $upload_dir_path . $css_file_name . '.css'; - if ( file_exists( $css_file_path ) ) { + if ( empty( $_GET['so_css_preview'] ) && ! is_admin() && file_exists( $css_file_path ) ) { wp_enqueue_style( 'so-css-' . $this->theme, set_url_scheme( $upload_dir['baseurl'] . '/so-css/' . $css_file_name . '.css' ), array(), - SOCSS_VERSION + $this->get_latest_revision_timestamp() ); } else { $custom_css = get_option( 'siteorigin_custom_css[' . $this->theme . ']', '' ); @@ -477,6 +477,14 @@ function disable_ngg_resource_manager() { //The NextGen Gallery plugin does some weird interfering with the output buffer. define('NGG_DISABLE_RESOURCE_MANAGER', true); } + + private function get_latest_revision_timestamp() { + $revisions = get_option( 'siteorigin_custom_css_revisions[' . $this->theme . ']' ); + krsort( $revisions ); + $revision_times = array_keys( $revisions ); + + return $revision_times[0]; + } } // Initialize the single From 8de735f22c5d371b7138ebe4baf7d1823b5970f4 Mon Sep 17 00:00:00 2001 From: Braam Genis Date: Mon, 17 Jul 2017 17:13:48 +0200 Subject: [PATCH 07/10] Fixed indentation. --- so-css.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/so-css.php b/so-css.php index a268d64..df58159 100644 --- a/so-css.php +++ b/so-css.php @@ -75,7 +75,7 @@ static function single(){ /** * Display the custom CSS in the header. */ - function action_wp_head(){ + function action_wp_head() { $upload_dir = wp_upload_dir(); $upload_dir_path = $upload_dir['basedir'] . '/so-css/'; @@ -91,12 +91,12 @@ function action_wp_head(){ ); } else { $custom_css = get_option( 'siteorigin_custom_css[' . $this->theme . ']', '' ); + // We just need to enqueue a dummy style if ( ! empty( $custom_css ) ) { - // We just need to enqueue a dummy style - echo "\n"; - } + echo "\n"; + } } } @@ -136,9 +136,9 @@ function action_admin_menu(){ // Sort the revisions and cut off any old ones. krsort($revisions); $revisions = array_slice($revisions, 0, 15, true); - + update_option( 'siteorigin_custom_css_revisions[' . $this->theme . ']', $revisions ); - + if( WP_Filesystem() ) { global $wp_filesystem; $upload_dir = wp_upload_dir(); @@ -174,9 +174,9 @@ function add_help_tab(){ 'id' => 'custom-css', 'title' => __( 'Custom CSS', 'so-css' ), 'content' => '

' - . sprintf( __( "SiteOrigin CSS adds any custom CSS you enter here into your site's header. ", 'so-css' ) ) - . __( "These changes will persist across updates so it's best to make all your changes here. ", 'so-css' ) - . '

' + . sprintf( __( "SiteOrigin CSS adds any custom CSS you enter here into your site's header. ", 'so-css' ) ) + . __( "These changes will persist across updates so it's best to make all your changes here. ", 'so-css' ) + . '

' ) ); } @@ -223,8 +223,8 @@ function enqueue_admin_scripts( $page ){ wp_localize_script( 'siteorigin-custom-css', 'socssOptions', array( 'themeCSS' => SiteOrigin_CSS::single()->get_theme_css(), - // Pretty confusing, but it seems we should be using `home_url` and NOT `site_url` - // as described here => https://wordpress.stackexchange.com/a/50605 + // Pretty confusing, but it seems we should be using `home_url` and NOT `site_url` + // as described here => https://wordpress.stackexchange.com/a/50605 'homeURL' => add_query_arg( 'so_css_preview', '1', home_url() ), 'snippets' => $this->get_snippets(), From 2fec5997a0f6ac40de3be78cc2df441497298841 Mon Sep 17 00:00:00 2001 From: Braam Genis Date: Thu, 20 Jul 2017 14:02:09 +0200 Subject: [PATCH 08/10] Updated build submodule --- build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build b/build index 5fc61aa..1a69478 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit 5fc61aa4b19cdb3cad8cab48a42e11a0d5b8256e +Subproject commit 1a6947867f54158ea66e9888f24b08c8473681a2 From 3e5cb2501bedbc95c9b78fb94c9c7c2c4a1456b7 Mon Sep 17 00:00:00 2001 From: Braam Genis Date: Thu, 14 Sep 2017 09:56:47 +0200 Subject: [PATCH 09/10] Updated build submodule. --- build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build b/build index 1a69478..bb9f428 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit 1a6947867f54158ea66e9888f24b08c8473681a2 +Subproject commit bb9f428cff69262f027356fd44772cd7f6d5634d From c63a3185a8c589796d53a494db23e8070bf524ac Mon Sep 17 00:00:00 2001 From: Braam Genis Date: Tue, 19 Sep 2017 16:54:05 +0200 Subject: [PATCH 10/10] Updated changelog. --- readme.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 1f2033a..e8d2e46 100644 --- a/readme.txt +++ b/readme.txt @@ -65,6 +65,13 @@ We offer free support on the [SiteOrigin support forums](https://siteorigin.com/ == Changelog == += 1.1.5 - 14 September 2017 = +* Use `home_url` instead of `site_url` to determine where to open CSS preview. +* Increment and decrement buttons work when value empty or zero. Also added repeating action while button held down. +* Scroll editor instead of the whole page so 'Save' button is always visible. +* Set color CSS on visual editor and inspector. +* Saving generated CSS to stylesheet file in uploads directory. + = 1.1.4 - 31 January 2017 = * Updated CodeMirror to 2.25.2. * Removed extra line padding. @@ -128,4 +135,4 @@ We offer free support on the [SiteOrigin support forums](https://siteorigin.com/ * Made it easier to follow links with inspector enabled. = 1.0 = -* Initial release. \ No newline at end of file +* Initial release.