1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
| (function(blocks, editor, element, components, _) { var el = element.createElement; var RichText = editor.RichText; var AlignmentToolbar = editor.AlignmentToolbar; var BlockControls = editor.BlockControls; var Fragment = element.Fragment;
blocks.registerBlockType('reilve/quote', { title: 'DUXQ引言', category: 'layout', icon: { src: 'format-quote', foreground: '#f85253' }, description: '几种不同的引言框', attributes: { content: { type: 'array', source: 'children', selector: 'span', }, typeClass: { source: 'attribute', selector: '.quote_q', attribute: 'class', } }, edit: function(props) { var content = props.attributes.content, typeClass = props.attributes.typeClass 'quote_q qe_wzk_lan', isSelected = props.isSelected; function onChangeContent(newContent) { props.setAttributes({ content: newContent }) } function changeType(event) { var type = event.target.className; props.setAttributes({ typeClass: 'quote_q ' + type }) } var richText = el(RichText, { tagName: 'p', onChange: onChangeContent, value: content, isSelected: props.isSelected, placeholder: '请输入...' }); var outerHtml = el('div', { className: typeClass }, richText); var selector = el('div', { className: 'duxq anz' }, [el('button', {className: 'qe_wzk_lan',onClick: changeType}), el('button', {className: 'qe_wzk_lv',onClick: changeType}), el('button', {className: 'qe_wzk_hui',onClick: changeType}), el('button', {className: 'qe_wzk_hong',onClick: changeType})] ); return el('div', {},[outerHtml, isSelected && selector])}, save: function(props) { var content = props.attributes.content, typeClass = props.attributes.typeClass 'quote_q qe_wzk_lan'; var outerHtml = el('div', { className: typeClass }, el('i', { className: 'fa fa-quote-left ' }), el('span', {}, content)); return el('div', {}, outerHtml) }, });
blocks.registerBlockType('aduxq/button', { title: 'UDXQ 按钮', category: 'layout', icon: { src: 'marker', foreground: '#f85253' }, attributes: { content: { type: 'array', source: 'children', selector: 'span', }, alignment: { type: 'string', }, typeClass: { source: 'attribute', selector: '.an_q', attribute: 'class', } }, edit: function(props) { var content = props.attributes.content, typeClass = props.attributes.typeClass 'qe_fxan b1', alignment = props.attributes.alignment, isSelected = props.isSelected; function onChangeContent(newContent) { props.setAttributes({ content: newContent }) } function changeType(event) { var type = event.target.className; props.setAttributes({ typeClass: 'an_q ' + type }) } function onChangeAlignment(newAlignment) { props.setAttributes({ alignment: newAlignment }) } var richText = el(RichText, { tagName: 'span', onChange: onChangeContent, value: content, isSelected: props.isSelected, placeholder: '按钮' }); var outerHtml1 = el('div', { className: typeClass }, richText); var outerHtml = (el(element.Fragment, null, el(BlockControls, null, el(AlignmentToolbar, { value: alignment, onChange: onChangeAlignment, })), outerHtml1)); var selector = el('div', { className: 'duxq anz' }, [el('button', { className: 'qe_fxan b1', onClick: changeType }, ''), el('button', { className: 'qe_fxan b2', onClick: changeType }, ''), el('button', { className: 'qe_fxan b3', onClick: changeType }, ''), el('button', { className: 'qe_fxan b4', onClick: changeType }, ''), el('button', { className: 'qe_fxan b5', onClick: changeType }, ''), ]); return el('div', { style: { textAlign: alignment } }, [outerHtml, isSelected && selector]) }, save: function(props) { var content = props.attributes.content, alignment = props.attributes.alignment, typeClass = props.attributes.typeClass 'qe_fxan b1'; if (alignment) { var outerHtml = el('div', { style: { textAlign: alignment } }, el('span', { className: typeClass }, content)) } else { var outerHtml = el('span', { className: typeClass }, content) } return outerHtml }, }) })(window.wp.blocks, window.wp.editor, window.wp.element, window.wp.components, window._, );
|