这是indexloc提供的服务,不要输入任何密码
Skip to content

Add deprecated blocks support #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 111 additions & 5 deletions blocks/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,112 @@ registerBlockType('rtgb/showcase', {
}
},

deprecated: [{
save: function save(props) {
var _props$attributes = props.attributes,
showCaseImage = _props$attributes.showCaseImage,
showCaseTitle = _props$attributes.showCaseTitle,
showCaseContent = _props$attributes.showCaseContent,
showCaseLink = _props$attributes.showCaseLink;


var className = props.className ? props.className : '';
var imageContent = '';

imageContent = wp.element.createElement(
'div',
{ className: 'image-container' },
wp.element.createElement(
'figure',
null,
wp.element.createElement('img', { src: showCaseImage.url, alt: showCaseImage.title })
)
);

return wp.element.createElement(
'div',
{ className: className + ' showcase-wrapper alignwide' },
imageContent,
wp.element.createElement(
'div',
{ className: 'info-container' },
showCaseLink ? wp.element.createElement(
'h3',
null,
wp.element.createElement(
'a',
{ href: showCaseLink, className: 'showcase-title' },
showCaseTitle
)
) : wp.element.createElement(
'h3',
{ className: 'showcase-title' },
showCaseTitle
),
wp.element.createElement(
'div',
{ className: 'showcase-content' },
showCaseContent
),
showCaseLink ? wp.element.createElement(
'a',
{
href: showCaseLink,
title: __('Read More'),
className: 'button secondary' },
__('Read More')
) : ''
)
);
},

attributes: {
showCaseTitle: {
type: 'array',
field: {
type: 'rich-text',
className: 'showcase-title',
placeholder: __('Showcase Title'),
tagName: 'h3'
},
selector: '.showcase-title',
source: 'children'
},

showCaseContent: {
type: 'array',
field: {
type: 'rich-text',
className: 'showcase-content',
placeholder: __('Showcase description'),
tagName: 'div',
multiline: 'p'
},
selector: '.showcase-content',
source: 'children'
},

showCaseImage: {
type: 'object',
field: {
type: 'image',
buttonText: __('Upload'),
imagePlaceholder: true,
removeButtonText: __('Remove')
}
},

showCaseLink: {
type: 'string',
field: {
type: 'link',
placement: 'inspector',
label: __('Showcase link')
}
}
}
}],

getEditWrapperProps: function getEditWrapperProps() {
return { 'data-align': 'wide' };
},
Expand Down Expand Up @@ -506,11 +612,11 @@ registerBlockType('rtgb/showcase', {
);
},
save: function save(props) {
var _props$attributes = props.attributes,
showCaseImage = _props$attributes.showCaseImage,
showCaseTitle = _props$attributes.showCaseTitle,
showCaseContent = _props$attributes.showCaseContent,
showCaseLink = _props$attributes.showCaseLink;
var _props$attributes2 = props.attributes,
showCaseImage = _props$attributes2.showCaseImage,
showCaseTitle = _props$attributes2.showCaseTitle,
showCaseContent = _props$attributes2.showCaseContent,
showCaseLink = _props$attributes2.showCaseLink;


var className = props.className ? props.className : '';
Expand Down
101 changes: 100 additions & 1 deletion blocks/showcase/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,105 @@ registerBlockType( 'rtgb/showcase', {
},
},

deprecated: [
{
save( props ) {
const {
attributes: {
showCaseImage,
showCaseTitle,
showCaseContent,
showCaseLink,
},
} = props;

const className = props.className ? props.className : '';
let imageContent = '';

imageContent = (
<div className="image-container">
<figure>
<img src={ showCaseImage.url } alt={ showCaseImage.title } />
</figure>
</div>
);

return (
<div className={ className + ' showcase-wrapper alignwide' }>
{ imageContent }
<div className="info-container">
{ showCaseLink ? (
<h3>
<a href={ showCaseLink } className="showcase-title">
{ showCaseTitle }
</a>
</h3>
) : (
<h3 className="showcase-title">{ showCaseTitle }</h3>
) }
<div className="showcase-content">{ showCaseContent }</div>
{ showCaseLink ? (
<a
href={ showCaseLink }
title={ __( 'Read More' ) }
className="button secondary">
{ __( 'Read More' ) }
</a>
) : (
''
) }
</div>
</div>
);
},
attributes: {
showCaseTitle: {
type: 'array',
field: {
type: 'rich-text',
className: 'showcase-title',
placeholder: __( 'Showcase Title' ),
tagName: 'h3',
},
selector: '.showcase-title',
source: 'children',
},

showCaseContent: {
type: 'array',
field: {
type: 'rich-text',
className: 'showcase-content',
placeholder: __( 'Showcase description' ),
tagName: 'div',
multiline: 'p',
},
selector: '.showcase-content',
source: 'children',
},

showCaseImage: {
type: 'object',
field: {
type: 'image',
buttonText: __( 'Upload' ),
imagePlaceholder: true,
removeButtonText: __( 'Remove' ),
},
},

showCaseLink: {
type: 'string',
field: {
type: 'link',
placement: 'inspector',
label: __( 'Showcase link' ),
},
},
},
},
],

getEditWrapperProps() {
return { 'data-align': 'wide' };
},
Expand All @@ -72,7 +171,7 @@ registerBlockType( 'rtgb/showcase', {
const {
attributes: {
showCaseLink,
}
},
} = props;

const className = props.className ? props.className : '';
Expand Down