Loading editor/node/widgets/accordion.js +71 −9 Changes for editor/node/widgets/accordion.js: 71 added lines, 9 removed lines. Original line number Diff line number Diff line 'use strict'; const { makeWidget } = require('./_base_widget'); module.exports = makeWidget({ name: 'Accordion', author: 'Jan Koester', version: '1.0', canHaveChildren: true, className: 'we-accordion' }); module.exports = { metadata() { return { name: 'Accordion', author: 'Jan Koester', version: '1.0', can_have_children: true }; }, json_api(ctx) { const req = (ctx && ctx.payload && ctx.payload.request) || {}; if (req.action !== 'get_schema') return {}; return { schema: [ field('title', 'Title', 'text', 'Accordion'), field('allow_multiple', 'Allow Multiple Open', 'checkbox'), field('border_style', 'Border', 'text', '1px solid var(--blogi-border, #ccc)'), field('header_bg', 'Header Background', 'color_var'), field('content_bg', 'Content Background', 'color_var'), field('hidden', 'Hidden', 'checkbox', null, 'desktop', null, false), field('custom_css', 'Custom CSS', 'textarea', '.we-xxx { ... }') ] }; }, render(ctx) { const p = (ctx && ctx.properties) || {}; const id = safe((ctx && ctx.instance_id) || 'accordion'); const cls = `we-accordion-${id}`; const title = esc(str(p.title) || 'Accordion'); const allowMultiple = bool(p.allow_multiple, false); return { html: `<style> .${cls}{${bool(p.hidden,false)?'display:none;':''}} .${cls}-item{${css('border', str(p.border_style) || '1px solid var(--blogi-border, #ccc)')}} .${cls}-head{cursor:pointer;padding:10px 12px;${css('background', str(p.header_bg))}} .${cls}-body{display:none;padding:10px 12px;${css('background', str(p.content_bg))}} ${str(p.custom_css)} </style> <div class="${cls}" data-acc-root="1"> <div class="${cls}-item"> <div class="${cls}-head" data-acc-head="1">${title}</div> <div class="${cls}-body" data-acc-body="1"></div> </div> </div> <script>(function(){ var s=document.currentScript,h=s&&s.closest('.we-node-widget');if(!h)return; var root=h.querySelector('[data-acc-root="1"]');var body=h.querySelector('[data-acc-body="1"]'); var kids=Array.from(h.children).filter(function(el){return el.classList&&el.classList.contains('we-node-widget');}); kids.forEach(function(k){if(body)body.appendChild(k);}); var heads=root?root.querySelectorAll('[data-acc-head="1"]'):[]; heads.forEach(function(head){head.addEventListener('click',function(){ var item=head.parentElement;var b=item.querySelector('[data-acc-body="1"]');if(!b)return; var open=b.style.display==='block'; if(!${allowMultiple ? 'true' : 'false'}){heads.forEach(function(hh){var bb=hh.parentElement.querySelector('[data-acc-body="1"]');if(bb)bb.style.display='none';});} b.style.display=open?'none':'block'; });}); })();</script>` }; }, have_childs(ctx) { return { have_childs: !!(ctx && ctx.payload && ctx.payload.have_childs) }; }, set_child() { return {}; }, unset_child() { return {}; }, add_next() { return {}; }, remove_next() { return {}; } }; function field(key,label,type,placeholder,target,options,defVal){const f={key,label,type,target:target||'all'};if(placeholder)f.placeholder=placeholder;if(Array.isArray(options))f.options=options;if(typeof defVal!=='undefined')f.default=defVal;return f;} function str(v){return typeof v==='string'?v:'';} function bool(v,d){if(typeof v==='boolean')return v;if(typeof v==='number')return v!==0;if(typeof v==='string')return v==='true'||v==='1';return !!d;} function css(k,v){const s=str(v);return s?`${k}:${s};`:'';} function safe(v){return String(v).replace(/[^a-zA-Z0-9_-]/g,'_');} function esc(v){return String(v).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,''');} editor/node/widgets/article.js +56 −9 Changes for editor/node/widgets/article.js: 56 added lines, 9 removed lines. Original line number Diff line number Diff line 'use strict'; const { makeWidget } = require('./_base_widget'); module.exports = makeWidget({ name: 'Article', author: 'Jan Koester', version: '1.0', canHaveChildren: true, className: 'we-article' }); module.exports = { metadata() { return { name: 'Article', author: 'Jan Koester', version: '1.0', can_have_children: true }; }, json_api(ctx) { const req = (ctx && ctx.payload && ctx.payload.request) || {}; if (req.action !== 'get_schema') return {}; return { schema: [ field('title', 'Title', 'text', 'Article title'), field('intro', 'Intro', 'textarea', 'Short intro text'), field('padding', 'Padding', 'text', '24px'), field('background_color', 'Background', 'color_var'), field('hidden', 'Hidden', 'checkbox', null, 'desktop', null, false), field('custom_css', 'Custom CSS', 'textarea', '.we-xxx { ... }') ] }; }, render(ctx) { const p = (ctx && ctx.properties) || {}; const id = safe((ctx && ctx.instance_id) || 'article'); const cls = `we-article-${id}`; const title = str(p.title); const intro = str(p.intro); return { html: `<style> .${cls}{${css('padding',str(p.padding)||'24px')}${css('background',str(p.background_color))}${bool(p.hidden,false)?'display:none;':''}} .${cls} h2{margin:0 0 .5rem 0;} .${cls} .intro{margin:0 0 1rem 0;opacity:.9;} ${str(p.custom_css)} </style> <article class="${cls}" data-article-root="1"> ${title ? `<h2>${esc(title)}</h2>` : ''} ${intro ? `<p class="intro">${esc(intro)}</p>` : ''} <div data-article-content="1"></div> </article> <script>(function(){ var s=document.currentScript,h=s&&s.closest('.we-node-widget');if(!h)return; var c=h.querySelector('[data-article-content="1"]'); Array.from(h.children).filter(function(el){return el.classList&&el.classList.contains('we-node-widget');}).forEach(function(k){if(c)c.appendChild(k);}); })();</script>` }; }, have_childs(ctx) { return { have_childs: !!(ctx && ctx.payload && ctx.payload.have_childs) }; }, set_child() { return {}; }, unset_child() { return {}; }, add_next() { return {}; }, remove_next() { return {}; } }; function field(key,label,type,placeholder,target,options,defVal){const f={key,label,type,target:target||'all'};if(placeholder)f.placeholder=placeholder;if(Array.isArray(options))f.options=options;if(typeof defVal!=='undefined')f.default=defVal;return f;} function str(v){return typeof v==='string'?v:'';} function bool(v,d){if(typeof v==='boolean')return v;if(typeof v==='number')return v!==0;if(typeof v==='string')return v==='true'||v==='1';return !!d;} function css(k,v){const s=str(v);return s?`${k}:${s};`:'';} function safe(v){return String(v).replace(/[^a-zA-Z0-9_-]/g,'_');} function esc(v){return String(v).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,''');} editor/node/widgets/button.js +120 −8 Changes for editor/node/widgets/button.js: 120 added lines, 8 removed lines. Original line number Diff line number Diff line 'use strict'; const { makeWidget } = require('./_base_widget'); module.exports = makeWidget({ name: 'Button', author: 'Jan Koester', version: '1.0', canHaveChildren: false, className: 'we-button' module.exports = { metadata() { return { name: 'Button', author: 'Jan Koester', version: '1.0', can_have_children: false }; }, json_api(ctx) { const req = (ctx && ctx.payload && ctx.payload.request) || {}; if (req.action !== 'get_schema') return {}; return { schema: [ field('label', 'Button Label', 'text', 'Click Me'), field('link_type', 'Link Type', 'select', null, 'all', ['url', 'section']), field('link_url', 'Link URL', 'text', 'https://...'), field('section_id', 'Target Section', 'text', 'we-...'), field('open_new_tab', 'Open in New Tab', 'checkbox'), field('background_color', 'Background Color', 'color_var'), field('l_background_color', 'Background Color (Light)', 'color_var', null, 'light'), field('text_color', 'Text Color', 'color_var'), field('l_text_color', 'Text Color (Light)', 'color_var', null, 'light'), field('font_size', 'Font Size', 'text', '16px'), field('padding', 'Padding', 'text', '10px 20px'), field('border_radius', 'Border Radius', 'text', '4px'), field('border_style', 'Border Style', 'text', 'none'), field('text_align', 'Text Align', 'select', null, 'all', ['left', 'center', 'right', 'justify']), field('width', 'Width', 'text', 'e.g. 200px', 'desktop'), field('height', 'Height', 'text', 'e.g. auto', 'desktop'), field('m_font_size', 'Font Size (Mobile)', 'text', 'e.g. 14px', 'mobile'), field('m_padding', 'Padding (Mobile)', 'text', 'e.g. 8px 16px', 'mobile'), field('m_width', 'Width (Mobile)', 'text', 'e.g. 100%', 'mobile'), field('m_height', 'Height (Mobile)', 'text', 'e.g. auto', 'mobile'), field('hidden', 'Hidden', 'checkbox', null, 'desktop', null, false), field('m_hidden', 'Hidden (Mobile)', 'checkbox', null, 'mobile', null, false), field('g_event_enabled', 'Enable Google Event', 'checkbox'), field('g_event_name', 'Event Name', 'text', 'button_click'), field('g_event_category', 'Event Category', 'text', 'engagement'), field('g_event_label', 'Event Label', 'text', 'cta_button'), field('g_event_value', 'Event Value', 'text', '1'), field('g_consent_update', 'Send Consent Update on Click', 'checkbox'), field('custom_css', 'Custom CSS', 'textarea', '.we-xxx { ... }') ] }; }, render(ctx) { const p = (ctx && ctx.properties) || {}; const id = safe((ctx && ctx.instance_id) || 'button'); const cls = `we-button-${id}`; const label = esc(str(p.label) || 'Click Me'); const linkType = str(p.link_type) === 'section' ? 'section' : 'url'; const href = linkType === 'section' ? `#${safe(str(p.section_id))}` : (str(p.link_url) || '#'); const newTab = bool(p.open_new_tab, false) && linkType === 'url'; const gtagSnippet = buildGtagSnippet(p); const mobileCss = [ css('font-size', p.m_font_size, true), css('padding', p.m_padding, true), css('width', p.m_width, true), css('height', p.m_height, true), bool(p.m_hidden, false) ? 'display:none !important;' : '', (!bool(p.m_hidden, false) && bool(p.hidden, false)) ? 'display:inline-block !important;' : '' ].join(''); const lightCss = `${css('background-color', p.l_background_color, true)}${css('color', p.l_text_color, true)}`; return { html: `<style> .${cls}{display:inline-block;${css('background-color',str(p.background_color)||'var(--blogi-accent)')}${css('color',str(p.text_color)||'var(--blogi-text)')}${css('font-size',str(p.font_size)||'16px')}${css('padding',str(p.padding)||'10px 20px')}${css('border-radius',str(p.border_radius)||'4px')}${css('border',str(p.border_style)||'none')}${css('text-align',str(p.text_align)||'center')}${css('width',str(p.width))}${css('height',str(p.height))}text-decoration:none;cursor:pointer;${bool(p.hidden,false)?'display:none;':''}} @media (max-width:768px){.${cls}{${mobileCss}}} @media (prefers-color-scheme: light){.${cls}{${lightCss}}} ${str(p.custom_css)} </style> <a class="${cls}" href="${escAttr(href)}" ${newTab ? 'target="_blank" rel="noopener noreferrer"' : ''} data-btn-type="${linkType}">${label}</a> <script>(function(){ var s=document.currentScript,h=s&&s.closest('.we-node-widget');if(!h)return; var a=h.querySelector('a.${cls}');if(!a)return; var runGtag=function(){${gtagSnippet}}; if(a.getAttribute('data-btn-type')==='section'){ a.addEventListener('click',function(e){ e.preventDefault(); runGtag(); var id=(a.getAttribute('href')||'').replace(/^#/,''); if(!id)return; var t=document.getElementById(id); if(t&&t.scrollIntoView)t.scrollIntoView({behavior:'smooth'}); }); }else if(${gtagSnippet ? 'true' : 'false'}){ a.addEventListener('click',function(){runGtag();}); } })();</script>` }; }, have_childs() { return { have_childs: false }; }, set_child() { return {}; }, unset_child() { return {}; }, add_next() { return {}; }, remove_next() { return {}; } }; function field(key,label,type,placeholder,target,options,defVal){const f={key,label,type,target:target||'all'};if(placeholder)f.placeholder=placeholder;if(Array.isArray(options))f.options=options;if(typeof defVal!=='undefined')f.default=defVal;return f;} function str(v){return typeof v==='string'?v:'';} function bool(v,d){if(typeof v==='boolean')return v;if(typeof v==='number')return v!==0;if(typeof v==='string')return v==='true'||v==='1';return !!d;} function css(k,v,important){const s=str(v);return s?`${k}:${s}${important?' !important':''};`:'';} function safe(v){return String(v).replace(/[^a-zA-Z0-9_-]/g,'_');} function esc(v){return String(v).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,''');} function escAttr(v){return esc(v).replace(/`/g,'`');} function buildGtagSnippet(p){ if(!bool(p.g_event_enabled,false) && !bool(p.g_consent_update,false)) return ''; const eventName = str(p.g_event_name); let code = "if(typeof gtag==='function'){"; if(bool(p.g_consent_update,false)){ code += "gtag('consent','update',{'ad_storage':'granted','ad_user_data':'granted','ad_personalization':'granted','analytics_storage':'granted','functionality_storage':'granted','personalization_storage':'granted','security_storage':'granted'});"; } if(bool(p.g_event_enabled,false) && eventName){ const parts = []; if(str(p.g_event_category)) parts.push(`'event_category':'${jsEsc(str(p.g_event_category))}'`); if(str(p.g_event_label)) parts.push(`'event_label':'${jsEsc(str(p.g_event_label))}'`); if(str(p.g_event_value)) parts.push(`'value':'${jsEsc(str(p.g_event_value))}'`); code += `gtag('event','${jsEsc(eventName)}',{${parts.join(',')}});`; } code += '}'; return code; } function jsEsc(v){return String(v).replace(/\\/g,'\\\\').replace(/'/g,"\\'");} editor/node/widgets/container.js +97 −9 Changes for editor/node/widgets/container.js: 97 added lines, 9 removed lines. Original line number Diff line number Diff line 'use strict'; const { makeWidget } = require('./_base_widget'); module.exports = makeWidget({ name: 'Container', author: 'Jan Koester', version: '1.0', canHaveChildren: true, className: 'we-container' }); module.exports = { metadata() { return { name: 'Container', author: 'Jan Koester', version: '1.0', can_have_children: true }; }, json_api(ctx) { const req = (ctx && ctx.payload && ctx.payload.request) || {}; if (req.action !== 'get_schema') return {}; return { schema: [ field('background_color', 'Background Color (Dark)', 'color_var', null, 'desktop'), field('l_background_color', 'Background Color (Light)', 'color_var', null, 'light'), field('background_image', 'Background Image', 'media_browse', '/media/getimage/...', 'desktop'), field('background_size', 'Background Size', 'select', null, 'desktop', ['cover', 'contain', 'auto', '100% 100%']), field('background_position', 'Background Position', 'select', null, 'desktop', ['center', 'top', 'bottom', 'left', 'right', 'top left', 'top right', 'bottom left', 'bottom right']), field('background_repeat', 'Background Repeat', 'select', null, 'all', ['no-repeat', 'repeat', 'repeat-x', 'repeat-y']), field('width', 'Width', 'text', 'e.g. 100%', 'desktop'), field('height', 'Height', 'text', 'e.g. auto', 'desktop'), field('padding', 'Padding', 'text', '10px', 'desktop'), field('margin', 'Margin', 'text', '10px auto', 'desktop'), field('border_radius', 'Border Radius', 'text', '8px', 'desktop'), field('border_style', 'Border', 'text', '1px solid #ccc', 'desktop'), field('hidden', 'Hidden', 'checkbox', null, 'desktop', null, false), field('custom_css', 'Custom CSS', 'textarea', '.we-xxx { ... }') ] }; }, render(ctx) { const p = (ctx && ctx.properties) || {}; const id = safe((ctx && ctx.instance_id) || 'container'); const cls = `we-container-${id}`; const style = buildStyle(p, false); const mobile = buildMobileStyle(p); const light = str(p.l_background_color) ? `background-color:${str(p.l_background_color)} !important;` : ''; return { html: `<style> .${cls}{${style}} @media (max-width:768px){.${cls}{${mobile}}} @media (prefers-color-scheme: light){.${cls}{${light}}} ${str(p.custom_css)} </style> <div class="${cls}" data-container-content="1"></div> <script>(function(){ var s=document.currentScript,h=s&&s.closest('.we-node-widget');if(!h)return; var c=h.querySelector('[data-container-content="1"]'); Array.from(h.children).filter(function(el){return el.classList&&el.classList.contains('we-node-widget');}).forEach(function(k){if(c)c.appendChild(k);}); })();</script>` }; }, have_childs(ctx) { return { have_childs: !!(ctx && ctx.payload && ctx.payload.have_childs) }; }, set_child() { return {}; }, unset_child() { return {}; }, add_next() { return {}; }, remove_next() { return {}; } }; function buildStyle(p, important) { const imp = important ? ' !important' : ''; let s = ''; const bg = str(p.background_color); if (bg && bg !== 'none' && bg !== 'transparent') s += `background-color:${bg}${imp};`; if (str(p.background_image)) { s += `background-image:url('${escCssUrl(str(p.background_image))}')${imp};`; s += `background-size:${str(p.background_size) || 'cover'}${imp};`; s += `background-position:${str(p.background_position) || 'center'}${imp};`; s += `background-repeat:${str(p.background_repeat) || 'no-repeat'}${imp};`; } s += css('padding', p.padding, important); s += css('margin', p.margin, important); s += css('width', p.width, important); s += css('height', p.height, important); s += css('border-radius', p.border_radius, important); s += css('border', p.border_style, important); if (bool(p.hidden, false)) s += `display:none${imp};`; return s; } function buildMobileStyle(p) { let s = ''; s += css('background-color', p.m_background_color, true); s += css('padding', p.m_padding, true); s += css('margin', p.m_margin, true); s += css('width', p.m_width, true); s += css('height', p.m_height, true); s += css('border-radius', p.m_border_radius, true); s += css('border', p.m_border_style, true); if (bool(p.m_hidden, false)) s += 'display:none !important;'; else if (bool(p.hidden, false)) s += 'display:block !important;'; return s; } function field(key,label,type,placeholder,target,options,defVal){const f={key,label,type,target:target||'all'};if(placeholder)f.placeholder=placeholder;if(Array.isArray(options))f.options=options;if(typeof defVal!=='undefined')f.default=defVal;return f;} function str(v){return typeof v==='string'?v:'';} function bool(v,d){if(typeof v==='boolean')return v;if(typeof v==='number')return v!==0;if(typeof v==='string')return v==='true'||v==='1';return !!d;} function css(k,v,important){const s=str(v);return s?`${k}:${s}${important?' !important':''};`:'';} function safe(v){return String(v).replace(/[^a-zA-Z0-9_-]/g,'_');} function escCssUrl(v){return String(v).replace(/'/g,"%27");} editor/node/widgets/customhtml.js +57 −9 Changes for editor/node/widgets/customhtml.js: 57 added lines, 9 removed lines. Original line number Diff line number Diff line 'use strict'; const { makeWidget } = require('./_base_widget'); module.exports = makeWidget({ name: 'CustomHtml', author: 'Jan Koester', version: '1.0', canHaveChildren: false, className: 'we-customhtml' }); module.exports = { metadata() { return { name: 'CustomHtml', author: 'Jan Koester', version: '1.0', can_have_children: false }; }, json_api(ctx) { const req = (ctx && ctx.payload && ctx.payload.request) || {}; if (req.action !== 'get_schema') return {}; return { schema: [ field('html_content', 'HTML Content', 'textarea', '<div>Your custom HTML here</div>'), field('css_content', 'CSS', 'textarea', 'color: red; font-size: 16px;'), field('js_content', 'JavaScript', 'textarea', 'console.log("Hello from widget");'), field('width', 'Width', 'text', 'e.g. 100%', 'desktop'), field('height', 'Height', 'text', 'e.g. auto', 'desktop'), field('hidden', 'Hidden', 'checkbox', null, 'desktop', null, false) ] }; }, render(ctx) { const p = (ctx && ctx.properties) || {}; const id = safe((ctx && ctx.instance_id) || 'customhtml'); const cls = `we-customhtml-${id}`; const html = str(p.html_content); const cssContent = str(p.css_content); const jsContent = str(p.js_content); const style = `${bool(p.hidden,false)?'display:none;':''}${css('width',p.width)}${css('height',p.height)}`; const mobile = `${css('width',p.m_width,true)}${css('height',p.m_height,true)}${bool(p.m_hidden,false)?'display:none !important;':''}${(!bool(p.m_hidden,false)&&bool(p.hidden,false))?'display:block !important;':''}`; return { html: `<style> .${cls}{${style}} ${cssContent ? `.${cls}{${cssContent}}` : ''} @media (max-width:768px){.${cls}{${mobile}}} </style> <div class="${cls}" data-custom-host="1">${html}</div> <script>(function(){ var s=document.currentScript,h=s&&s.closest('.we-node-widget');if(!h)return; var host=h.querySelector('[data-custom-host="1"]'); if(!host)return; try{ (function(widget){${jsContent}})(host); }catch(e){console.error('CustomHtml widget script error',e);} })();</script>` }; }, have_childs() { return { have_childs: false }; }, set_child() { return {}; }, unset_child() { return {}; }, add_next() { return {}; }, remove_next() { return {}; } }; function field(key,label,type,placeholder,target,options,defVal){const f={key,label,type,target:target||'all'};if(placeholder)f.placeholder=placeholder;if(Array.isArray(options))f.options=options;if(typeof defVal!=='undefined')f.default=defVal;return f;} function str(v){return typeof v==='string'?v:'';} function bool(v,d){if(typeof v==='boolean')return v;if(typeof v==='number')return v!==0;if(typeof v==='string')return v==='true'||v==='1';return !!d;} function css(k,v,important){const s=str(v);return s?`${k}:${s}${important?' !important':''};`:'';} function safe(v){return String(v).replace(/[^a-zA-Z0-9_-]/g,'_');} Loading
editor/node/widgets/accordion.js +71 −9 Changes for editor/node/widgets/accordion.js: 71 added lines, 9 removed lines. Original line number Diff line number Diff line 'use strict'; const { makeWidget } = require('./_base_widget'); module.exports = makeWidget({ name: 'Accordion', author: 'Jan Koester', version: '1.0', canHaveChildren: true, className: 'we-accordion' }); module.exports = { metadata() { return { name: 'Accordion', author: 'Jan Koester', version: '1.0', can_have_children: true }; }, json_api(ctx) { const req = (ctx && ctx.payload && ctx.payload.request) || {}; if (req.action !== 'get_schema') return {}; return { schema: [ field('title', 'Title', 'text', 'Accordion'), field('allow_multiple', 'Allow Multiple Open', 'checkbox'), field('border_style', 'Border', 'text', '1px solid var(--blogi-border, #ccc)'), field('header_bg', 'Header Background', 'color_var'), field('content_bg', 'Content Background', 'color_var'), field('hidden', 'Hidden', 'checkbox', null, 'desktop', null, false), field('custom_css', 'Custom CSS', 'textarea', '.we-xxx { ... }') ] }; }, render(ctx) { const p = (ctx && ctx.properties) || {}; const id = safe((ctx && ctx.instance_id) || 'accordion'); const cls = `we-accordion-${id}`; const title = esc(str(p.title) || 'Accordion'); const allowMultiple = bool(p.allow_multiple, false); return { html: `<style> .${cls}{${bool(p.hidden,false)?'display:none;':''}} .${cls}-item{${css('border', str(p.border_style) || '1px solid var(--blogi-border, #ccc)')}} .${cls}-head{cursor:pointer;padding:10px 12px;${css('background', str(p.header_bg))}} .${cls}-body{display:none;padding:10px 12px;${css('background', str(p.content_bg))}} ${str(p.custom_css)} </style> <div class="${cls}" data-acc-root="1"> <div class="${cls}-item"> <div class="${cls}-head" data-acc-head="1">${title}</div> <div class="${cls}-body" data-acc-body="1"></div> </div> </div> <script>(function(){ var s=document.currentScript,h=s&&s.closest('.we-node-widget');if(!h)return; var root=h.querySelector('[data-acc-root="1"]');var body=h.querySelector('[data-acc-body="1"]'); var kids=Array.from(h.children).filter(function(el){return el.classList&&el.classList.contains('we-node-widget');}); kids.forEach(function(k){if(body)body.appendChild(k);}); var heads=root?root.querySelectorAll('[data-acc-head="1"]'):[]; heads.forEach(function(head){head.addEventListener('click',function(){ var item=head.parentElement;var b=item.querySelector('[data-acc-body="1"]');if(!b)return; var open=b.style.display==='block'; if(!${allowMultiple ? 'true' : 'false'}){heads.forEach(function(hh){var bb=hh.parentElement.querySelector('[data-acc-body="1"]');if(bb)bb.style.display='none';});} b.style.display=open?'none':'block'; });}); })();</script>` }; }, have_childs(ctx) { return { have_childs: !!(ctx && ctx.payload && ctx.payload.have_childs) }; }, set_child() { return {}; }, unset_child() { return {}; }, add_next() { return {}; }, remove_next() { return {}; } }; function field(key,label,type,placeholder,target,options,defVal){const f={key,label,type,target:target||'all'};if(placeholder)f.placeholder=placeholder;if(Array.isArray(options))f.options=options;if(typeof defVal!=='undefined')f.default=defVal;return f;} function str(v){return typeof v==='string'?v:'';} function bool(v,d){if(typeof v==='boolean')return v;if(typeof v==='number')return v!==0;if(typeof v==='string')return v==='true'||v==='1';return !!d;} function css(k,v){const s=str(v);return s?`${k}:${s};`:'';} function safe(v){return String(v).replace(/[^a-zA-Z0-9_-]/g,'_');} function esc(v){return String(v).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,''');}
editor/node/widgets/article.js +56 −9 Changes for editor/node/widgets/article.js: 56 added lines, 9 removed lines. Original line number Diff line number Diff line 'use strict'; const { makeWidget } = require('./_base_widget'); module.exports = makeWidget({ name: 'Article', author: 'Jan Koester', version: '1.0', canHaveChildren: true, className: 'we-article' }); module.exports = { metadata() { return { name: 'Article', author: 'Jan Koester', version: '1.0', can_have_children: true }; }, json_api(ctx) { const req = (ctx && ctx.payload && ctx.payload.request) || {}; if (req.action !== 'get_schema') return {}; return { schema: [ field('title', 'Title', 'text', 'Article title'), field('intro', 'Intro', 'textarea', 'Short intro text'), field('padding', 'Padding', 'text', '24px'), field('background_color', 'Background', 'color_var'), field('hidden', 'Hidden', 'checkbox', null, 'desktop', null, false), field('custom_css', 'Custom CSS', 'textarea', '.we-xxx { ... }') ] }; }, render(ctx) { const p = (ctx && ctx.properties) || {}; const id = safe((ctx && ctx.instance_id) || 'article'); const cls = `we-article-${id}`; const title = str(p.title); const intro = str(p.intro); return { html: `<style> .${cls}{${css('padding',str(p.padding)||'24px')}${css('background',str(p.background_color))}${bool(p.hidden,false)?'display:none;':''}} .${cls} h2{margin:0 0 .5rem 0;} .${cls} .intro{margin:0 0 1rem 0;opacity:.9;} ${str(p.custom_css)} </style> <article class="${cls}" data-article-root="1"> ${title ? `<h2>${esc(title)}</h2>` : ''} ${intro ? `<p class="intro">${esc(intro)}</p>` : ''} <div data-article-content="1"></div> </article> <script>(function(){ var s=document.currentScript,h=s&&s.closest('.we-node-widget');if(!h)return; var c=h.querySelector('[data-article-content="1"]'); Array.from(h.children).filter(function(el){return el.classList&&el.classList.contains('we-node-widget');}).forEach(function(k){if(c)c.appendChild(k);}); })();</script>` }; }, have_childs(ctx) { return { have_childs: !!(ctx && ctx.payload && ctx.payload.have_childs) }; }, set_child() { return {}; }, unset_child() { return {}; }, add_next() { return {}; }, remove_next() { return {}; } }; function field(key,label,type,placeholder,target,options,defVal){const f={key,label,type,target:target||'all'};if(placeholder)f.placeholder=placeholder;if(Array.isArray(options))f.options=options;if(typeof defVal!=='undefined')f.default=defVal;return f;} function str(v){return typeof v==='string'?v:'';} function bool(v,d){if(typeof v==='boolean')return v;if(typeof v==='number')return v!==0;if(typeof v==='string')return v==='true'||v==='1';return !!d;} function css(k,v){const s=str(v);return s?`${k}:${s};`:'';} function safe(v){return String(v).replace(/[^a-zA-Z0-9_-]/g,'_');} function esc(v){return String(v).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,''');}
editor/node/widgets/button.js +120 −8 Changes for editor/node/widgets/button.js: 120 added lines, 8 removed lines. Original line number Diff line number Diff line 'use strict'; const { makeWidget } = require('./_base_widget'); module.exports = makeWidget({ name: 'Button', author: 'Jan Koester', version: '1.0', canHaveChildren: false, className: 'we-button' module.exports = { metadata() { return { name: 'Button', author: 'Jan Koester', version: '1.0', can_have_children: false }; }, json_api(ctx) { const req = (ctx && ctx.payload && ctx.payload.request) || {}; if (req.action !== 'get_schema') return {}; return { schema: [ field('label', 'Button Label', 'text', 'Click Me'), field('link_type', 'Link Type', 'select', null, 'all', ['url', 'section']), field('link_url', 'Link URL', 'text', 'https://...'), field('section_id', 'Target Section', 'text', 'we-...'), field('open_new_tab', 'Open in New Tab', 'checkbox'), field('background_color', 'Background Color', 'color_var'), field('l_background_color', 'Background Color (Light)', 'color_var', null, 'light'), field('text_color', 'Text Color', 'color_var'), field('l_text_color', 'Text Color (Light)', 'color_var', null, 'light'), field('font_size', 'Font Size', 'text', '16px'), field('padding', 'Padding', 'text', '10px 20px'), field('border_radius', 'Border Radius', 'text', '4px'), field('border_style', 'Border Style', 'text', 'none'), field('text_align', 'Text Align', 'select', null, 'all', ['left', 'center', 'right', 'justify']), field('width', 'Width', 'text', 'e.g. 200px', 'desktop'), field('height', 'Height', 'text', 'e.g. auto', 'desktop'), field('m_font_size', 'Font Size (Mobile)', 'text', 'e.g. 14px', 'mobile'), field('m_padding', 'Padding (Mobile)', 'text', 'e.g. 8px 16px', 'mobile'), field('m_width', 'Width (Mobile)', 'text', 'e.g. 100%', 'mobile'), field('m_height', 'Height (Mobile)', 'text', 'e.g. auto', 'mobile'), field('hidden', 'Hidden', 'checkbox', null, 'desktop', null, false), field('m_hidden', 'Hidden (Mobile)', 'checkbox', null, 'mobile', null, false), field('g_event_enabled', 'Enable Google Event', 'checkbox'), field('g_event_name', 'Event Name', 'text', 'button_click'), field('g_event_category', 'Event Category', 'text', 'engagement'), field('g_event_label', 'Event Label', 'text', 'cta_button'), field('g_event_value', 'Event Value', 'text', '1'), field('g_consent_update', 'Send Consent Update on Click', 'checkbox'), field('custom_css', 'Custom CSS', 'textarea', '.we-xxx { ... }') ] }; }, render(ctx) { const p = (ctx && ctx.properties) || {}; const id = safe((ctx && ctx.instance_id) || 'button'); const cls = `we-button-${id}`; const label = esc(str(p.label) || 'Click Me'); const linkType = str(p.link_type) === 'section' ? 'section' : 'url'; const href = linkType === 'section' ? `#${safe(str(p.section_id))}` : (str(p.link_url) || '#'); const newTab = bool(p.open_new_tab, false) && linkType === 'url'; const gtagSnippet = buildGtagSnippet(p); const mobileCss = [ css('font-size', p.m_font_size, true), css('padding', p.m_padding, true), css('width', p.m_width, true), css('height', p.m_height, true), bool(p.m_hidden, false) ? 'display:none !important;' : '', (!bool(p.m_hidden, false) && bool(p.hidden, false)) ? 'display:inline-block !important;' : '' ].join(''); const lightCss = `${css('background-color', p.l_background_color, true)}${css('color', p.l_text_color, true)}`; return { html: `<style> .${cls}{display:inline-block;${css('background-color',str(p.background_color)||'var(--blogi-accent)')}${css('color',str(p.text_color)||'var(--blogi-text)')}${css('font-size',str(p.font_size)||'16px')}${css('padding',str(p.padding)||'10px 20px')}${css('border-radius',str(p.border_radius)||'4px')}${css('border',str(p.border_style)||'none')}${css('text-align',str(p.text_align)||'center')}${css('width',str(p.width))}${css('height',str(p.height))}text-decoration:none;cursor:pointer;${bool(p.hidden,false)?'display:none;':''}} @media (max-width:768px){.${cls}{${mobileCss}}} @media (prefers-color-scheme: light){.${cls}{${lightCss}}} ${str(p.custom_css)} </style> <a class="${cls}" href="${escAttr(href)}" ${newTab ? 'target="_blank" rel="noopener noreferrer"' : ''} data-btn-type="${linkType}">${label}</a> <script>(function(){ var s=document.currentScript,h=s&&s.closest('.we-node-widget');if(!h)return; var a=h.querySelector('a.${cls}');if(!a)return; var runGtag=function(){${gtagSnippet}}; if(a.getAttribute('data-btn-type')==='section'){ a.addEventListener('click',function(e){ e.preventDefault(); runGtag(); var id=(a.getAttribute('href')||'').replace(/^#/,''); if(!id)return; var t=document.getElementById(id); if(t&&t.scrollIntoView)t.scrollIntoView({behavior:'smooth'}); }); }else if(${gtagSnippet ? 'true' : 'false'}){ a.addEventListener('click',function(){runGtag();}); } })();</script>` }; }, have_childs() { return { have_childs: false }; }, set_child() { return {}; }, unset_child() { return {}; }, add_next() { return {}; }, remove_next() { return {}; } }; function field(key,label,type,placeholder,target,options,defVal){const f={key,label,type,target:target||'all'};if(placeholder)f.placeholder=placeholder;if(Array.isArray(options))f.options=options;if(typeof defVal!=='undefined')f.default=defVal;return f;} function str(v){return typeof v==='string'?v:'';} function bool(v,d){if(typeof v==='boolean')return v;if(typeof v==='number')return v!==0;if(typeof v==='string')return v==='true'||v==='1';return !!d;} function css(k,v,important){const s=str(v);return s?`${k}:${s}${important?' !important':''};`:'';} function safe(v){return String(v).replace(/[^a-zA-Z0-9_-]/g,'_');} function esc(v){return String(v).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,''');} function escAttr(v){return esc(v).replace(/`/g,'`');} function buildGtagSnippet(p){ if(!bool(p.g_event_enabled,false) && !bool(p.g_consent_update,false)) return ''; const eventName = str(p.g_event_name); let code = "if(typeof gtag==='function'){"; if(bool(p.g_consent_update,false)){ code += "gtag('consent','update',{'ad_storage':'granted','ad_user_data':'granted','ad_personalization':'granted','analytics_storage':'granted','functionality_storage':'granted','personalization_storage':'granted','security_storage':'granted'});"; } if(bool(p.g_event_enabled,false) && eventName){ const parts = []; if(str(p.g_event_category)) parts.push(`'event_category':'${jsEsc(str(p.g_event_category))}'`); if(str(p.g_event_label)) parts.push(`'event_label':'${jsEsc(str(p.g_event_label))}'`); if(str(p.g_event_value)) parts.push(`'value':'${jsEsc(str(p.g_event_value))}'`); code += `gtag('event','${jsEsc(eventName)}',{${parts.join(',')}});`; } code += '}'; return code; } function jsEsc(v){return String(v).replace(/\\/g,'\\\\').replace(/'/g,"\\'");}
editor/node/widgets/container.js +97 −9 Changes for editor/node/widgets/container.js: 97 added lines, 9 removed lines. Original line number Diff line number Diff line 'use strict'; const { makeWidget } = require('./_base_widget'); module.exports = makeWidget({ name: 'Container', author: 'Jan Koester', version: '1.0', canHaveChildren: true, className: 'we-container' }); module.exports = { metadata() { return { name: 'Container', author: 'Jan Koester', version: '1.0', can_have_children: true }; }, json_api(ctx) { const req = (ctx && ctx.payload && ctx.payload.request) || {}; if (req.action !== 'get_schema') return {}; return { schema: [ field('background_color', 'Background Color (Dark)', 'color_var', null, 'desktop'), field('l_background_color', 'Background Color (Light)', 'color_var', null, 'light'), field('background_image', 'Background Image', 'media_browse', '/media/getimage/...', 'desktop'), field('background_size', 'Background Size', 'select', null, 'desktop', ['cover', 'contain', 'auto', '100% 100%']), field('background_position', 'Background Position', 'select', null, 'desktop', ['center', 'top', 'bottom', 'left', 'right', 'top left', 'top right', 'bottom left', 'bottom right']), field('background_repeat', 'Background Repeat', 'select', null, 'all', ['no-repeat', 'repeat', 'repeat-x', 'repeat-y']), field('width', 'Width', 'text', 'e.g. 100%', 'desktop'), field('height', 'Height', 'text', 'e.g. auto', 'desktop'), field('padding', 'Padding', 'text', '10px', 'desktop'), field('margin', 'Margin', 'text', '10px auto', 'desktop'), field('border_radius', 'Border Radius', 'text', '8px', 'desktop'), field('border_style', 'Border', 'text', '1px solid #ccc', 'desktop'), field('hidden', 'Hidden', 'checkbox', null, 'desktop', null, false), field('custom_css', 'Custom CSS', 'textarea', '.we-xxx { ... }') ] }; }, render(ctx) { const p = (ctx && ctx.properties) || {}; const id = safe((ctx && ctx.instance_id) || 'container'); const cls = `we-container-${id}`; const style = buildStyle(p, false); const mobile = buildMobileStyle(p); const light = str(p.l_background_color) ? `background-color:${str(p.l_background_color)} !important;` : ''; return { html: `<style> .${cls}{${style}} @media (max-width:768px){.${cls}{${mobile}}} @media (prefers-color-scheme: light){.${cls}{${light}}} ${str(p.custom_css)} </style> <div class="${cls}" data-container-content="1"></div> <script>(function(){ var s=document.currentScript,h=s&&s.closest('.we-node-widget');if(!h)return; var c=h.querySelector('[data-container-content="1"]'); Array.from(h.children).filter(function(el){return el.classList&&el.classList.contains('we-node-widget');}).forEach(function(k){if(c)c.appendChild(k);}); })();</script>` }; }, have_childs(ctx) { return { have_childs: !!(ctx && ctx.payload && ctx.payload.have_childs) }; }, set_child() { return {}; }, unset_child() { return {}; }, add_next() { return {}; }, remove_next() { return {}; } }; function buildStyle(p, important) { const imp = important ? ' !important' : ''; let s = ''; const bg = str(p.background_color); if (bg && bg !== 'none' && bg !== 'transparent') s += `background-color:${bg}${imp};`; if (str(p.background_image)) { s += `background-image:url('${escCssUrl(str(p.background_image))}')${imp};`; s += `background-size:${str(p.background_size) || 'cover'}${imp};`; s += `background-position:${str(p.background_position) || 'center'}${imp};`; s += `background-repeat:${str(p.background_repeat) || 'no-repeat'}${imp};`; } s += css('padding', p.padding, important); s += css('margin', p.margin, important); s += css('width', p.width, important); s += css('height', p.height, important); s += css('border-radius', p.border_radius, important); s += css('border', p.border_style, important); if (bool(p.hidden, false)) s += `display:none${imp};`; return s; } function buildMobileStyle(p) { let s = ''; s += css('background-color', p.m_background_color, true); s += css('padding', p.m_padding, true); s += css('margin', p.m_margin, true); s += css('width', p.m_width, true); s += css('height', p.m_height, true); s += css('border-radius', p.m_border_radius, true); s += css('border', p.m_border_style, true); if (bool(p.m_hidden, false)) s += 'display:none !important;'; else if (bool(p.hidden, false)) s += 'display:block !important;'; return s; } function field(key,label,type,placeholder,target,options,defVal){const f={key,label,type,target:target||'all'};if(placeholder)f.placeholder=placeholder;if(Array.isArray(options))f.options=options;if(typeof defVal!=='undefined')f.default=defVal;return f;} function str(v){return typeof v==='string'?v:'';} function bool(v,d){if(typeof v==='boolean')return v;if(typeof v==='number')return v!==0;if(typeof v==='string')return v==='true'||v==='1';return !!d;} function css(k,v,important){const s=str(v);return s?`${k}:${s}${important?' !important':''};`:'';} function safe(v){return String(v).replace(/[^a-zA-Z0-9_-]/g,'_');} function escCssUrl(v){return String(v).replace(/'/g,"%27");}
editor/node/widgets/customhtml.js +57 −9 Changes for editor/node/widgets/customhtml.js: 57 added lines, 9 removed lines. Original line number Diff line number Diff line 'use strict'; const { makeWidget } = require('./_base_widget'); module.exports = makeWidget({ name: 'CustomHtml', author: 'Jan Koester', version: '1.0', canHaveChildren: false, className: 'we-customhtml' }); module.exports = { metadata() { return { name: 'CustomHtml', author: 'Jan Koester', version: '1.0', can_have_children: false }; }, json_api(ctx) { const req = (ctx && ctx.payload && ctx.payload.request) || {}; if (req.action !== 'get_schema') return {}; return { schema: [ field('html_content', 'HTML Content', 'textarea', '<div>Your custom HTML here</div>'), field('css_content', 'CSS', 'textarea', 'color: red; font-size: 16px;'), field('js_content', 'JavaScript', 'textarea', 'console.log("Hello from widget");'), field('width', 'Width', 'text', 'e.g. 100%', 'desktop'), field('height', 'Height', 'text', 'e.g. auto', 'desktop'), field('hidden', 'Hidden', 'checkbox', null, 'desktop', null, false) ] }; }, render(ctx) { const p = (ctx && ctx.properties) || {}; const id = safe((ctx && ctx.instance_id) || 'customhtml'); const cls = `we-customhtml-${id}`; const html = str(p.html_content); const cssContent = str(p.css_content); const jsContent = str(p.js_content); const style = `${bool(p.hidden,false)?'display:none;':''}${css('width',p.width)}${css('height',p.height)}`; const mobile = `${css('width',p.m_width,true)}${css('height',p.m_height,true)}${bool(p.m_hidden,false)?'display:none !important;':''}${(!bool(p.m_hidden,false)&&bool(p.hidden,false))?'display:block !important;':''}`; return { html: `<style> .${cls}{${style}} ${cssContent ? `.${cls}{${cssContent}}` : ''} @media (max-width:768px){.${cls}{${mobile}}} </style> <div class="${cls}" data-custom-host="1">${html}</div> <script>(function(){ var s=document.currentScript,h=s&&s.closest('.we-node-widget');if(!h)return; var host=h.querySelector('[data-custom-host="1"]'); if(!host)return; try{ (function(widget){${jsContent}})(host); }catch(e){console.error('CustomHtml widget script error',e);} })();</script>` }; }, have_childs() { return { have_childs: false }; }, set_child() { return {}; }, unset_child() { return {}; }, add_next() { return {}; }, remove_next() { return {}; } }; function field(key,label,type,placeholder,target,options,defVal){const f={key,label,type,target:target||'all'};if(placeholder)f.placeholder=placeholder;if(Array.isArray(options))f.options=options;if(typeof defVal!=='undefined')f.default=defVal;return f;} function str(v){return typeof v==='string'?v:'';} function bool(v,d){if(typeof v==='boolean')return v;if(typeof v==='number')return v!==0;if(typeof v==='string')return v==='true'||v==='1';return !!d;} function css(k,v,important){const s=str(v);return s?`${k}:${s}${important?' !important':''};`:'';} function safe(v){return String(v).replace(/[^a-zA-Z0-9_-]/g,'_');}