import { CaxtonLayoutBlocksSetup } from './layout-blocks/layout-blocks.es6'; /** * Plugin front end scripts * * @package Caxton * @version 1.0.0 */ ( (( $, blocks, el, i18n, {SelectControl, TextControl, ToggleControl, RangeControl} ) => { const createBlock = blocks.createBlock; const InspectorControls = caxtonWPEditor.InspectorControls; const __ = i18n.__; CaxtonLayoutBlocksSetup( $, wp ); CaxtonBlock( { id: 'hero', title: 'Cover with button', icon: 'archive', category: 'caxton', tpl: '
%s
', section: 'Slide 1', }, 'Slide 1 button text': { type: 'text', tpl: '%s', section: 'Slide 1', }, 'Slide 1 button url': { type: 'text', section: 'Slide 1', }, 'Slide 2 image': { type: 'image', tpl: '%s
', section: 'Slide 2', }, 'Slide 2 button text': { type: 'text', tpl: '%s', section: 'Slide 2', }, 'Slide 2 button url': { type: 'text', section: 'Slide 2', }, 'Slide 3 image': { type: 'image', tpl: '%s
', section: 'Slide 3', }, 'Slide 3 button text': { type: 'text', tpl: '%s', section: 'Slide 3', }, 'Slide 3 button url': { type: 'text', section: 'Slide 3', }, 'Slide 4 image': { type: 'image', tpl: '%s
', section: 'Slide 4', }, 'Slide 4 button text': { type: 'text', tpl: '%s', section: 'Slide 4', }, 'Slide 4 button url': { type: 'text', section: 'Slide 4', }, 'Slide 5 image': { type: 'image', tpl: '%s
', section: 'Slide 5', }, 'Slide 5 button text': { type: 'text', tpl: '%s', section: 'Slide 5', }, 'Slide 5 button url': { type: 'text', section: 'Slide 5', }, 'Button color': { type: 'color', default: '#0693e3', tpl: 'background:%s;', section: 'Typography', }, 'Button text color': { type: 'color', default: '#ffffff', tpl: 'color:%s;', section: 'Typography', }, 'Text color': { type: 'color', tpl: 'color:%s;', default: '#ffffff', section: 'Typography', }, 'Font size': { type: 'range', min: 5, max: 250, default: 16, tpl: 'font-size:%spx;', section: 'Typography', }, 'Font size tablet': { type: 'range', min: 5, max: 250, tpl: 'font-size:%spx;', section: 'Typography', }, 'Font size mobile': { type: 'range', min: 5, max: 250, tpl: 'font-size:%spx;', section: 'Typography', }, 'Text Glow/Shadow': { type: 'select', options: [ {value: '', label: 'No shadow/glow',}, {value: '255,255,255', label: 'Glow',}, {value: '0,0,0', label: 'Shadow',}, ], section: 'Text Glow/Shadow', tpl: 'text-shadow:{{Text Shadow position}} .05em rgba(%s,{{Text Shadow strength}});', }, 'Text Shadow position': { type: 'select', options: [ {value: 'calc( -3px + -.07em ) calc( 2px + .03em )', label: 'Far Left',}, {value: 'calc( -1px + -.03em ) calc( 1px + .01em )', label: 'Left',}, {value: '0 0', label: 'Center',}, {value: 'calc( 1px + .03em ) calc( 1px + .01em )', label: 'Right',}, {value: 'calc( 2px + .05em ) calc( 2px + .03em )', label: 'Far Right',}, ], default: '0 0', section: 'Text Glow/Shadow', }, 'Text Shadow strength': { type: 'select', options: [ {value: '.25', label: 'Light',}, {value: '.5', label: 'Normal',}, {value: '.75', label: 'Strong',}, ], default: '.5', section: 'Text Glow/Shadow', } }, } ); CaxtonBlock( { id: 'super-hero', title: 'Super Hero', icon: 'archive', category: 'caxton', toolbars: { Layout: 'BlockWidthToolbar', }, fields: { 'Background image': { type: 'image', section: 'Background image', tpl: 'background-image:url(%s);', }, 'Background image position': { type: 'position', section: 'Background image', tpl: 'background-position:%s;', }, 'Background parallax': { type: 'toggle', value: 'background-attachment:fixed;', section: 'Background image', }, 'Background color': { type: 'color', section: 'Background colors', }, 'Gradient color': { type: 'color', section: 'Background colors', tpl: ', %s', }, 'Gradient type': { type: 'select', options: [ {value: 'linear-gradient( ', label: 'Linear vertical',}, {value: 'linear-gradient( 90deg, ', label: 'Linear horizontal',}, {value: 'linear-gradient( 45deg, ', label: 'Linear 45 deg',}, {value: 'linear-gradient( -45deg, ', label: 'Linear 45 deg anticlockwise',}, {value: 'radial-gradient( ', label: 'Radial gradient',}, ], default: 'linear-gradient( ', section: 'Background colors', }, 'Background colors opacity': { type: 'range', min: 0, max: 1, step: .05, help: 'Reduce opacity to have transparent colors over image', default: '.9', section: 'Background colors', tpl: 'opacity:%s;', }, 'Columns': { type: 'range', min: 1, max: 8, section: 'Layout', default: 1, }, 'Column gap': { type: 'select', options: [ {value: 'grid-gap-none', label: 'None',}, {value: 'grid-gap-tight', label: 'Tight',}, {value: '', label: 'Normal',}, {value: 'grid-gap-wide', label: 'Wide',}, {value: 'grid-gap-wider', label: 'Wider',}, ], section: 'Layout', }, 'Inner Padding top': { type: 'range', section: 'Layout', default: 5, }, 'Inner Padding left': { type: 'range', max: 70, section: 'Layout', default: 5, }, 'Inner Padding bottom': { type: 'range', section: 'Layout', default: 5, }, 'Inner Padding right': { type: 'range', max: 70, section: 'Layout', default: 5, }, 'Inner Padding left/right tablet': { type: 'range', max: 70, section: 'Layout', default: 5, }, 'Inner Padding left/right mobile': { type: 'range', max: 70, section: 'Layout', default: 5, }, 'Inner Padding unit': { type: 'select', options: [ {value: '%', label: 'Responsive',}, {value: 'px', label: 'Pixels x 5',}, ], default: '%', section: 'Layout', }, }, edit(props, block) { const colBlk = ['core/column']; function getColumnsTemplate( columns ) { return Array( +columns ).fill( colBlk ); } let bgHTML, padUnit, padT, padL, padB, padR, columns; let cls = 'relative ', colCls = 'relative caxton-columns'; const padMob = block.attrs['Inner Padding left/right tablet']; const padTab = block.attrs['Inner Padding left/right mobile']; padUnit = block.attrs['Inner Padding unit']; padT = block.attrs['Inner Padding top']; padL = block.attrs['Inner Padding left']; padB = block.attrs['Inner Padding bottom']; padR = block.attrs['Inner Padding right']; columns = block.attrs['Columns']; if ( 'px' === padUnit ) { padT *= 5; padL *= 5; padB *= 5; padR *= 5; } padT = padT ? padT + padUnit : 0; padL = padL ? padL + padUnit : 0; padB = padB ? padB + padUnit : 0; padR = padR ? padR + padUnit : 0; if ( block.attrs['Layout'] ) { cls += ` ${block.attrs['Layout']}`; } if ( block.attrs['Column gap'] ) { colCls += ` ${block.attrs['Column gap']}`; } bgHTML = '' + ''; return el( // Element 'div', { className: cls, key: 'super-hero-block' }, // Background div el( 'div', {key: 'bg', className: 'absolute absolute--fill', dangerouslySetInnerHTML: block.outputHTML( bgHTML )} ), // Blocks inserter el( 'div', { className: `${colCls} caxton-${columns}-columns`, style: { 'paddingTop': padT, 'paddingLeft': padL, 'paddingBottom': padB, 'paddingRight': padR, }, 'data-tablet-css' : `padding-left:${padTab}em;padding-right:${padTab}em;`, 'data-mobile-css' : `padding-left:${padMob}em;padding-right:${padMob}em;`, key: 'block', }, el( caxtonWPEditor.InnerBlocks, { template: getColumnsTemplate( block.attrs['Columns'] ), templateLock: 'all', allowedBlock: colBlk, key: 'innerblockscontent' } ) ) ); }, save(props, block) { let cls = 'relative'; let bgHTML; let padUnit; let padT; let padL; let padB; let padR; let columns; let colCls = 'relative caxton-columns'; const padMob = block.attrs['Inner Padding left/right tablet']; const padTab = block.attrs['Inner Padding left/right mobile']; padUnit = block.attrs['Inner Padding unit']; padT = block.attrs['Inner Padding top']; padL = block.attrs['Inner Padding left']; padB = block.attrs['Inner Padding bottom']; padR = block.attrs['Inner Padding right']; columns = block.attrs['Columns']; if ( 'px' == padUnit ) { padT *= 5; padL *= 5; padB *= 5; padR *= 5; } padT = padT ? padT + padUnit : 0; padL = padL ? padL + padUnit : 0; padB = padB ? padB + padUnit : 0; padR = padR ? padR + padUnit : 0; if ( block.attrs['Layout'] ) { cls += ` ${block.attrs['Layout']}`; } if ( block.attrs['Column gap'] ) { colCls += ` ${block.attrs['Column gap']}`; } bgHTML = '' + ''; const childrenBlocks = el( caxtonWPEditor.InnerBlocks.Content, {} ); return el( // Element 'div', { className: cls, key: 'super-hero-block' }, [ // Background div el( 'div', { key: 'bg', className: 'absolute absolute--fill', dangerouslySetInnerHTML: block.outputHTML( bgHTML )} ), // Blocks inserter el( 'div', { className: `${colCls} caxton-${columns}-columns`, style: { 'paddingTop': padT, 'paddingLeft': padL, 'paddingBottom': padB, 'paddingRight': padR, }, 'data-mobile-css' : `padding-left:${padMob}em;padding-right:${padMob}em;`, 'data-tablet-css' : `padding-left:${padTab}em;padding-right:${padTab}em;`, key: 'block', }, childrenBlocks ) ] ); } } ); CaxtonBlock( { id: 'divider', title: 'Shape Divider', icon: 'cloud', category: 'caxton', tpl: function( props ) { let svgMaps = { '': '