admin-notifications.js
5 years ago
cff-admin-scripts.js
5 years ago
cff-blocks.js
6 years ago
cff-scripts.js
5 years ago
cff-scripts.min.js
6 years ago
jquery.matchHeight-min.js
6 years ago
cff-blocks.js
148 lines
| 1 | "use strict"; |
| 2 | window.cffmetatrans = false; |
| 3 | (function () { |
| 4 | var _wp = wp, |
| 5 | _wp$serverSideRender = _wp.serverSideRender, |
| 6 | createElement = wp.element.createElement, |
| 7 | ServerSideRender = _wp$serverSideRender === void 0 ? wp.components.ServerSideRender : _wp$serverSideRender, |
| 8 | _ref = wp.blockEditor || wp.editor, |
| 9 | InspectorControls = _ref.InspectorControls, |
| 10 | _wp$components = wp.components, |
| 11 | TextareaControl = _wp$components.TextareaControl, |
| 12 | Button = _wp$components.Button, |
| 13 | PanelBody = _wp$components.PanelBody, |
| 14 | Placeholder = _wp$components.Placeholder, |
| 15 | registerBlockType = wp.blocks.registerBlockType; |
| 16 | |
| 17 | var cffIcon = createElement('svg', { |
| 18 | width: 20, |
| 19 | height: 20, |
| 20 | viewBox: '0 0 448 512', |
| 21 | className: 'dashicon' |
| 22 | }, createElement('path', { |
| 23 | fill: 'currentColor', |
| 24 | d: 'M400 32H48A48 48 0 0 0 0 80v352a48 48 0 0 0 48 48h137.25V327.69h-63V256h63v-54.64c0-62.15 37-96.48 93.67-96.48 27.14 0 55.52 4.84 55.52 4.84v61h-31.27c-30.81 0-40.42 19.12-40.42 38.73V256h68.78l-11 71.69h-57.78V480H400a48 48 0 0 0 48-48V80a48 48 0 0 0-48-48z' |
| 25 | })); |
| 26 | |
| 27 | registerBlockType('cff/cff-feed-block', { |
| 28 | title: 'Custom Facebook Feed', |
| 29 | icon: cffIcon, |
| 30 | category: 'widgets', |
| 31 | attributes: { |
| 32 | noNewChanges: { |
| 33 | type: 'boolean', |
| 34 | }, |
| 35 | shortcodeSettings: { |
| 36 | type: 'string', |
| 37 | }, |
| 38 | executed: { |
| 39 | type: 'boolean' |
| 40 | } |
| 41 | }, |
| 42 | edit: function edit(props) { |
| 43 | var _props = props, |
| 44 | setAttributes = _props.setAttributes, |
| 45 | _props$attributes = _props.attributes, |
| 46 | _props$attributes$sho = _props$attributes.shortcodeSettings, |
| 47 | shortcodeSettings = _props$attributes$sho === void 0 ? cff_block_editor.shortcodeSettings : _props$attributes$sho, |
| 48 | _props$attributes$cli = _props$attributes.noNewChanges, |
| 49 | noNewChanges = _props$attributes$cli === void 0 ? true : _props$attributes$cli; |
| 50 | |
| 51 | function setState(shortcodeSettingsContent) { |
| 52 | setAttributes({ |
| 53 | noNewChanges: false, |
| 54 | shortcodeSettings: shortcodeSettingsContent |
| 55 | }) |
| 56 | } |
| 57 | |
| 58 | function previewClick(content) { |
| 59 | setAttributes({ |
| 60 | noNewChanges: true, |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | function cffGutenbergSizeVisualHeader() { |
| 65 | jQuery('.cff-visual-header.cff-has-cover').each(function() { |
| 66 | var wrapperHeight = jQuery(this).find('.cff-header-hero').innerHeight(), |
| 67 | imageHeight = jQuery(this).find('.cff-header-hero img').innerHeight(), |
| 68 | wrapperWidth = jQuery(this).find('.cff-header-hero').innerWidth(), |
| 69 | imageWidth = jQuery(this).find('.cff-header-hero img').innerWidth(), |
| 70 | wrapperAspect = wrapperWidth/wrapperHeight, |
| 71 | imageAspect = imageWidth/imageHeight, |
| 72 | width = wrapperAspect < imageAspect ? wrapperHeight * imageAspect + 'px' : '100%', |
| 73 | difference = imageHeight - wrapperHeight, |
| 74 | topMargin = Math.max(0,Math.round(difference/2)), |
| 75 | leftMargin = width !== '100%' ? Math.max(0,Math.round(((wrapperHeight * imageAspect)-wrapperWidth)/2)) : 0; |
| 76 | jQuery(this).find('.cff-header-hero img').css({ |
| 77 | 'opacity' : 1, |
| 78 | 'display' : 'block', |
| 79 | 'visibility' : 'visible', |
| 80 | 'max-width' : 'none', |
| 81 | 'max-height' : 'none', |
| 82 | 'margin-top' : - topMargin + 'px', |
| 83 | 'margin-left' : - leftMargin + 'px', |
| 84 | 'width' : width, |
| 85 | }); |
| 86 | }); |
| 87 | } |
| 88 | |
| 89 | function afterRender() { |
| 90 | jQuery(window).resize(function () { |
| 91 | setTimeout(function(){ |
| 92 | cffGutenbergSizeVisualHeader(); |
| 93 | }, 500); |
| 94 | }); |
| 95 | var executed = false; |
| 96 | // no way to run a script after AJAX call to get feed so we just try to execute it on a few intervals |
| 97 | setTimeout(function() { if (typeof cffGutenbergSizeVisualHeader !== 'undefined' && !executed) {cffGutenbergSizeVisualHeader();}},1000); |
| 98 | setTimeout(function() { if (typeof cffGutenbergSizeVisualHeader !== 'undefined' && !executed) {cffGutenbergSizeVisualHeader();}},2000); |
| 99 | setTimeout(function() { if (typeof cffGutenbergSizeVisualHeader !== 'undefined' && !executed) {cffGutenbergSizeVisualHeader();}},3000); |
| 100 | setTimeout(function() { if (typeof cffGutenbergSizeVisualHeader !== 'undefined' && !executed) {cffGutenbergSizeVisualHeader();}},5000); |
| 101 | setTimeout(function() { if (typeof cffGutenbergSizeVisualHeader !== 'undefined' && !executed) {cffGutenbergSizeVisualHeader();}},10000); |
| 102 | } |
| 103 | |
| 104 | var jsx = [React.createElement(InspectorControls, { |
| 105 | key: "cff-gutenberg-setting-selector-inspector-controls" |
| 106 | }, React.createElement(PanelBody, { |
| 107 | title: cff_block_editor.i18n.addSettings |
| 108 | }, React.createElement(TextareaControl, { |
| 109 | key: "cff-gutenberg-settings", |
| 110 | className: "cff-gutenberg-settings", |
| 111 | label: cff_block_editor.i18n.shortcodeSettings, |
| 112 | help: cff_block_editor.i18n.example + ": 'id=\"smashballoon\" showheader=\"true\"'", |
| 113 | value: shortcodeSettings, |
| 114 | onChange: setState |
| 115 | }), React.createElement(Button, { |
| 116 | key: "cff-gutenberg-preview", |
| 117 | className: "cff-gutenberg-preview", |
| 118 | onClick: previewClick, |
| 119 | isDefault: true |
| 120 | }, cff_block_editor.i18n.preview)))]; |
| 121 | |
| 122 | if (noNewChanges) { |
| 123 | afterRender(); |
| 124 | jsx.push(React.createElement(ServerSideRender, { |
| 125 | key: "custom-facebook-feeds/custom-facebook-feeds", |
| 126 | block: "cff/cff-feed-block", |
| 127 | attributes: props.attributes, |
| 128 | })); |
| 129 | } else { |
| 130 | props.attributes.noNewChanges = false; |
| 131 | jsx.push(React.createElement(Placeholder, { |
| 132 | key: "cff-gutenberg-setting-selector-select-wrap", |
| 133 | className: "cff-gutenberg-setting-selector-select-wrap" |
| 134 | }, React.createElement(Button, { |
| 135 | key: "cff-gutenberg-preview", |
| 136 | className: "cff-gutenberg-preview", |
| 137 | onClick: previewClick, |
| 138 | isDefault: true |
| 139 | }, cff_block_editor.i18n.preview))); |
| 140 | } |
| 141 | |
| 142 | return jsx; |
| 143 | }, |
| 144 | save: function save() { |
| 145 | return null; |
| 146 | } |
| 147 | }); |
| 148 | })(); |