From a67707a4f4ed50d75da665968df70c77c634d6f8 Mon Sep 17 00:00:00 2001 From: PeeterPaal Date: Tue, 8 Mar 2022 20:12:45 +0200 Subject: [PATCH] Add bgpicker to auto-rendered product pages - Include template settings - Adjust auto-gen page colors for dark background --- components/html-head.tpl | 2 +- components/site-header.tpl | 10 ++++- components/site-javascripts.tpl | 2 +- components/template-cs-style-rules.tpl | 5 +++ components/template-settings-json.tpl | 13 ++++++ components/template-settings.tpl | 5 +++ components/template-styles.tpl | 7 +++ components/template-tools.tpl | 2 + components/template-variables.tpl | 45 ++++++++++++++++++- javascripts/main.js | 2 +- javascripts/main.min.js | 2 +- layouts/auto_generated_product.tpl | 23 +++++++--- layouts/blog___news.tpl | 7 +-- layouts/blog_article.tpl | 7 +-- layouts/common_page.tpl | 3 +- layouts/front_page.tpl | 3 +- layouts/product.tpl | 3 +- layouts/product_list.tpl | 3 +- manifest.json | 14 ++++++ .../template-cs-style-rules.scss | 8 ++++ sources/javascripts/concat/base.js | 2 +- 21 files changed, 145 insertions(+), 23 deletions(-) create mode 100644 components/template-settings-json.tpl create mode 100644 components/template-settings.tpl diff --git a/components/html-head.tpl b/components/html-head.tpl index 7fc5a60..a6d7dd0 100644 --- a/components/html-head.tpl +++ b/components/html-head.tpl @@ -17,7 +17,7 @@ {% if editmode %} {% endif %} -{% stylesheet_link "main.min.css?v=dorpat-1.1.1" %} + {% comment %}Google fonts for Design Editor{% endcomment %} diff --git a/components/site-header.tpl b/components/site-header.tpl index 1fc7891..2d328a2 100644 --- a/components/site-header.tpl +++ b/components/site-header.tpl @@ -55,7 +55,15 @@ {% else %} - + {% endif %} {% endif %} diff --git a/components/site-javascripts.tpl b/components/site-javascripts.tpl index a4b21b7..bf008f9 100644 --- a/components/site-javascripts.tpl +++ b/components/site-javascripts.tpl @@ -1,7 +1,7 @@ {% comment %}SITE WIDE JAVASCRIPTS{% endcomment %} - + {% sitejs_include %} {% comment %}Site search related javascript components.{% endcomment %} diff --git a/components/template-cs-style-rules.tpl b/components/template-cs-style-rules.tpl index 80b960f..4739545 100644 --- a/components/template-cs-style-rules.tpl +++ b/components/template-cs-style-rules.tpl @@ -738,6 +738,11 @@ body { text-decoration: var(--content-area-product-title__text-decoration); text-transform: var(--content-area-product-title__text-transform); } +.dark-background .product-content .product-price, +.dark-background .product-content .product-description, +.dark-background .product-content .content-item-title h1 { + color: var(--third-color); +} .dark-background .edy-product-widget-grid .edy-product-widget-item .edy-product-widget-item-details-wrap .edy-product-widget-item-title, .dark-background .edy-product-widget-grid .edy-product-widget-item .edy-product-widget-item-details-wrap .edy-product-widget-item-link { diff --git a/components/template-settings-json.tpl b/components/template-settings-json.tpl new file mode 100644 index 0000000..23a7270 --- /dev/null +++ b/components/template-settings-json.tpl @@ -0,0 +1,13 @@ +{ + "product": { + "body_bg": { + "key": "PREFIX_product_body_bg", + "value": {} + }, + "header_bg": { + "key": "PREFIX_product_header_bg", + "value": {} + } + }, + "version": "dorpat-1.1.1" +} diff --git a/components/template-settings.tpl b/components/template-settings.tpl new file mode 100644 index 0000000..3bddbdf --- /dev/null +++ b/components/template-settings.tpl @@ -0,0 +1,5 @@ +{%- capture template_settings_json -%} + {% include 'template-settings-json' %} +{%- endcapture -%} + +{%- assign template_settings = template_settings_json | replace: 'PREFIX', 'dorpat' | json_parse -%} diff --git a/components/template-styles.tpl b/components/template-styles.tpl index daf8267..b025265 100644 --- a/components/template-styles.tpl +++ b/components/template-styles.tpl @@ -173,6 +173,13 @@ } {% endif %} + {% comment %}/* Product page content area background*/ {% endcomment %} + {% if product_body_bg_color != blank %} + .product-page .page-body .background-color { + background-color: {{ product_body_bg_color }} + } + {% endif %} + {% comment %}/* FOOTER BACKGROUND */{% endcomment %} {% comment %}/* Front page content area 1 background color style. */{% endcomment %} {% if footer_bg_color != blank %} diff --git a/components/template-tools.tpl b/components/template-tools.tpl index 0ca6cae..e478801 100644 --- a/components/template-tools.tpl +++ b/components/template-tools.tpl @@ -18,6 +18,8 @@ //========================================================================== {% if front_page %} pageType = 'frontPage'; + {% elsif product_page %} + pageType = 'productPage'; {% else %} {% if blog_article_page %} pageType = 'articlePage'; diff --git a/components/template-variables.tpl b/components/template-variables.tpl index bfc84ac..0eb80d9 100644 --- a/components/template-variables.tpl +++ b/components/template-variables.tpl @@ -86,7 +86,13 @@ {% comment %}SITE HEADER RELATED VARIABLES.{% endcomment %} {% comment %}Assign variables based on page type.{% endcomment %} - {% assign header_bg = page.data.header_bg %} + {% if product_page == true %} + {% assign header_bg_key = template_settings.product.header_bg.key %} + {% assign header_bg = site.data[header_bg_key] %} + {% else %} + {% assign header_bg = page.data.header_bg %} + {% endif %} + {% assign header_bg_image = header_bg.image %} {% assign header_bg_image_sizes = header_bg.imageSizes %} {% assign header_bg_color = header_bg.color %} @@ -94,7 +100,7 @@ {% assign header_bg_combined_lightness = header_bg.combinedLightness %} {% comment %}Sets the background type to choose active CMS color scheme.{% endcomment %} - {% if header_bg %} + {% if header_bg != blank%} {% if header_bg_combined_lightness %} {% if header_bg_combined_lightness > 0.6 %} {% assign header_bg_type = "light-background" %} @@ -301,6 +307,41 @@ {% assign content_bg_2_color_data_str = content_bg_2_color_data | json %} {% endif %} + {% comment %}AUTO-RENDERED PRODUCT PAGE BACKGROUND VARIABLES{% endcomment %} + {% assign product_body_bg_key = template_settings.product.body_bg.key %} + + {% assign product_body_bg = site.data[product_body_bg_key] %} + {% assign product_body_bg_color = product_body_bg.color %} + {% assign product_body_bg_color_data = product_body_bg.colorData %} + {% assign product_body_bg_combined_lightness = product_body_bg.combinedLightness %} + + {% if product_body_bg != blank %} + {% if product_body_bg_combined_lightness %} + {% if product_body_bg_combined_lightness > 0.6 %} + {% assign product_body_bg_type = "light-background" %} + {% else %} + {% assign product_body_bg_type = "dark-background" %} + {% endif %} + {% else %} + {% if product_body_bg_color_data.a >= 0.6 %} + {% if product_body_bg_color_data.lightness >= 0.6 %} + {% assign product_body_bg_type = "light-background" %} + {% else %} + {% assign product_body_bg_type = "dark-background" %} + {% endif %} + {% else %} + {% assign product_body_bg_type = "light-background" %} + {% endif %} + {% endif %} + {% else %} + {% assign product_body_bg_type = "light-background" %} + {% endif %} + + {% if product_body_bg_color_data == nil %} + {% assign product_body_bg_color_data_str = "" %} + {% else %} + {% assign product_body_bg_color_data_str = product_body_bg_color_data | json %} + {% endif %} {% comment %}SITE MAIN CONTENT AREA RELATED VARIABLES.{% endcomment %} {% comment %}Assign variables based on page type.{% endcomment %} diff --git a/javascripts/main.js b/javascripts/main.js index b90e086..6b308ec 100644 --- a/javascripts/main.js +++ b/javascripts/main.js @@ -441,7 +441,7 @@ Edicy.articles.currentArticle.setData(dataBgKey, commitData); } } else { - if (pageType === 'contentPage' && (dataBgKey === 'footer_bg') || (dataBgKey === 'body_bg')) { + if (pageType === 'contentPage' && (dataBgKey === 'footer_bg') || (dataBgKey === 'body_bg') || pageType === 'productPage') { siteData.set(dataBgKey, commitData); } else { pageData.set(dataBgKey, commitData); diff --git a/javascripts/main.min.js b/javascripts/main.min.js index eb145eb..4e671c8 100644 --- a/javascripts/main.min.js +++ b/javascripts/main.min.js @@ -1 +1 @@ -var MMCQ,PriorityQueue;!function(n,i,e,t){var s="textareaAutoSize",o="plugin_"+s;function a(e,t){this.element=e,this.$element=n(e),this.init()}a.prototype={init:function(){this.$element.outerHeight();var o=parseInt(this.$element.css("paddingBottom"))+parseInt(this.$element.css("paddingTop"))||0;0")),h=v(""),g=e.image&&""!==e.image?e.image:null;g?function(e,t){for(var s=e.length;s--;)if(-1'+s+"",removeBtn:'
',change:function(e){var t,s,o,n,i,a,r,l,c,h,g,u,d;m.removeClass("is-cropped").addClass("not-cropped").css("opacity",.1),e?(t=e.original_id,p.removeClass("without-image is-loaded with-error").addClass("with-image not-loaded"),s=p,o=e.width,n=e.height,i=s.find(".js-content-item-img-drop-area"),a=s.find(".js-toggle-crop-state"),n')}),v(document).ready(function(){v(".comment-form").hasClass("form_with_errors")?v("html, body").scrollTop(v(".comment-form").offset().top):0>b.rshift,s=e[1]>>b.rshift,t=e[2]>>b.rshift,this.r1<=o&&o<=this.r2&&this.g1<=s&&s<=this.g2&&this.b1<=t&&t<=this.b2},e}(),a=function(){function e(){this.cboxes=new PriorityQueue(function(e,t){var s,o;return s=e.count()*e.volume(),(o=t.count()*t.volume())>b.rshift,s=i[1]>>b.rshift,t=i[2]>>b.rshift,o[n=T(a,s,t)]=(o[n]||0)+1;return o},h=function(e,t){var s,o,n,i,a,r,l,c,h,g,u,d;for(n=r=g=1e6,u=o=a=h=0,d=e.length;u>b.rshift)>b.rshift)>b.rshift)p/2){for(t=u.copy(),s=u.copy(),n=(l=r-u[i])<=(c=u[a]-r)?Math.min(u[a]-1,~~(r+c/2)):Math.max(u[i],~~(r-1-l/2));!m[n];)n++;for(o=d[n];!o&&m[n-1];)o=d[--n];return t[a]=n,s[i]=t[a]+1,[t,s]}},a===l?o("r"):a===i?o("g"):a===s?o("b"):void 0}},b.prototype.quantize=function(e,t){var r,s,l,o,n,i,c=this;if(!e.length||t<2||256c.maxIterations)return void console.log("infinite loop; perhaps too few pixels")}else e.push(r),a++})(n,this.fractByPopulations*t),i=new PriorityQueue(function(e,t){var s,o;return s=e.count()*e.volume(),(o=t.count()*t.volume())")),h=v(""),g=e.image&&""!==e.image?e.image:null;g?function(e,t){for(var s=e.length;s--;)if(-1'+s+"",removeBtn:'
',change:function(e){var t,s,o,n,i,a,r,l,c,h,g,u,d;m.removeClass("is-cropped").addClass("not-cropped").css("opacity",.1),e?(t=e.original_id,p.removeClass("without-image is-loaded with-error").addClass("with-image not-loaded"),s=p,o=e.width,n=e.height,i=s.find(".js-content-item-img-drop-area"),a=s.find(".js-toggle-crop-state"),n')}),v(document).ready(function(){v(".comment-form").hasClass("form_with_errors")?v("html, body").scrollTop(v(".comment-form").offset().top):0>b.rshift,s=e[1]>>b.rshift,t=e[2]>>b.rshift,this.r1<=o&&o<=this.r2&&this.g1<=s&&s<=this.g2&&this.b1<=t&&t<=this.b2},e}(),a=function(){function e(){this.cboxes=new PriorityQueue(function(e,t){var s,o;return s=e.count()*e.volume(),(o=t.count()*t.volume())>b.rshift,s=i[1]>>b.rshift,t=i[2]>>b.rshift,o[n=T(a,s,t)]=(o[n]||0)+1;return o},h=function(e,t){var s,o,n,i,a,r,l,c,h,g,u,d;for(n=r=g=1e6,u=o=a=h=0,d=e.length;u>b.rshift)>b.rshift)>b.rshift)p/2){for(t=u.copy(),s=u.copy(),n=(l=r-u[i])<=(c=u[a]-r)?Math.min(u[a]-1,~~(r+c/2)):Math.max(u[i],~~(r-1-l/2));!m[n];)n++;for(o=d[n];!o&&m[n-1];)o=d[--n];return t[a]=n,s[i]=t[a]+1,[t,s]}},a===l?o("r"):a===i?o("g"):a===s?o("b"):void 0}},b.prototype.quantize=function(e,t){var r,s,l,o,n,i,c=this;if(!e.length||t<2||256c.maxIterations)return void console.log("infinite loop; perhaps too few pixels")}else e.push(r),a++})(n,this.fractByPopulations*t),i=new PriorityQueue(function(e,t){var s,o;return s=e.count()*e.volume(),(o=t.count()*t.volume()) -{% include "template-variables" %} +{%- assign product_page = true -%} +{%- include "template-settings" -%} +{%- include "template-variables" -%} @@ -25,7 +27,7 @@ {% assign gallery_content_size = gallery_content_html | strip | size %} - + {% include "template-svg-spritesheet" %}
@@ -33,8 +35,19 @@ {% include "site-header" %} {% include "common-page-variables" %} -
-
+
+
+ {% if editmode %} + + {% endif %} +
+
@@ -121,7 +134,7 @@ {% include "menu-mobile" %} {% include "site-signout" %} {% include "site-javascripts" %} - {% include "template-tools" with "item_list_page" %} + {% include "template-tools" with "product_page" %}