From 0b9aedf060ee1233d22881175d505340a064c5af Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Tue, 30 Apr 2019 18:14:49 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Added=20caption=20support=20to=20co?= =?UTF-8?q?de=20cards?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue --- .../addon/components/koenig-card-code.js | 7 +++++++ .../koenig-editor/addon/components/koenig-card.js | 13 +++++++++++-- .../addon/templates/components/koenig-card-code.hbs | 13 +++++++++++++ .../addon/templates/components/koenig-toolbar.hbs | 2 +- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-card-code.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-card-code.js index 3c06250417..4f9980509c 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-card-code.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-card-code.js @@ -35,6 +35,9 @@ export default Component.extend({ deselectCard() {}, deleteCard() {}, registerComponent() {}, + moveCursorToNextSection() {}, + moveCursorToPrevSection() {}, + addParagraphAfterCard() {}, counts: computed('payload.code', function () { return {wordCount: countWords(this.payload.code)}; @@ -98,6 +101,10 @@ export default Component.extend({ this._updatePayloadAttr('code', code); }, + updateCaption(caption) { + this._updatePayloadAttr('caption', caption); + }, + enterEditMode() { this._addMousemoveHandler(); }, diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-card.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-card.js index a3d71d4bd7..0c95369c85 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-card.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-card.js @@ -141,7 +141,7 @@ export default Component.extend({ }, mouseDown(event) { - let {isSelected, isEditing} = this; + let {isSelected, isEditing, hasEditMode} = this; // if we perform an action we want to prevent the mousedown from // triggering a cursor position change which can result in multiple @@ -165,6 +165,14 @@ export default Component.extend({ // don't trigger edit mode immediately this._skipMouseUp = true; } + + // don't trigger select->edit transition for clicks in the caption + if (isSelected && hasEditMode) { + let allowClickthrough = !!event.target.closest('[data-kg-allow-clickthrough]'); + if (allowClickthrough) { + this._skipMouseUp = true; + } + } }, // lazy-click to enter edit mode @@ -181,7 +189,8 @@ export default Component.extend({ }, doubleClick() { - if (this.hasEditMode && !this.isEditing) { + let allowClickthrough = !!event.target.closest('[data-kg-allow-clickthrough]'); + if (this.hasEditMode && !this.isEditing && !allowClickthrough) { this.editCard(); this.set('showToolbar', true); } diff --git a/ghost/admin/lib/koenig-editor/addon/templates/components/koenig-card-code.hbs b/ghost/admin/lib/koenig-editor/addon/templates/components/koenig-card-code.hbs index 90de7250af..fe8a3d19e8 100644 --- a/ghost/admin/lib/koenig-editor/addon/templates/components/koenig-card-code.hbs +++ b/ghost/admin/lib/koenig-editor/addon/templates/components/koenig-card-code.hbs @@ -12,7 +12,11 @@ saveCard=(action saveCard) onEnterEdit=(action "enterEditMode") onLeaveEdit=(action "leaveEditMode") + addParagraphAfterCard=addParagraphAfterCard + moveCursorToPrevSection=moveCursorToPrevSection + moveCursorToNextSection=moveCursorToNextSection editor=editor + as |card| }} {{#if isEditing}} {{gh-cm-editor payload.code @@ -42,4 +46,13 @@ {{/if}}
{{/if}} + + {{#if (and (not isEditing) (or isSelected (clean-basic-html payload.caption)))}} + {{card.captionInput + class="z-999" + caption=payload.caption + update=(action "updateCaption") + placeholder="Type caption for image (optional)" + }} + {{/if}} {{/koenig-card}} \ No newline at end of file diff --git a/ghost/admin/lib/koenig-editor/addon/templates/components/koenig-toolbar.hbs b/ghost/admin/lib/koenig-editor/addon/templates/components/koenig-toolbar.hbs index efacdc580d..f4a9edc47d 100644 --- a/ghost/admin/lib/koenig-editor/addon/templates/components/koenig-toolbar.hbs +++ b/ghost/admin/lib/koenig-editor/addon/templates/components/koenig-toolbar.hbs @@ -1,4 +1,4 @@ -