Ghost/ghost/admin/lib/gh-koenig/addon/components/koenig-toolbar-newitem.js
Ryan McCarvill 9a0b72071d 👯 ♥️ ♣️ ♦️ ♠️ New editor card menu (#580)
refs https://github.com/TryGhost/Ghost/issues/8106, https://github.com/TryGhost/Ghost/issues/7429, requires https://github.com/TryGhost/Ghost/pull/8137

-Adds new "card" menus
  - Navigation with keyboard in both axis.
  - Search with keyboard in both menus.
  - Adds a "+" Menu for cards
  - Adds a "/" Menu for cards
    - if the block has content and it becomes a markdown or HTML Embed card then the content is included into the card.
    - Image and HR cards appear below the current section
- Adds new toolbar with both inline and block styling.
- Adds a new 'divider' card.
2017-03-14 11:59:34 +00:00

76 lines
2.4 KiB
JavaScript

import Component from 'ember-component';
import $ from 'jquery';
import layout from '../templates/components/koenig-toolbar-newitem';
import Tools from '../options/default-tools';
export default Component.extend({
layout,
classNames: ['toolbar-newitem'],
init() {
this._super(...arguments);
let editor = this.get('editor');
let tools = new Tools(editor, this);
this.tools = [];
tools.forEach((item) => {
if (item.type === 'block' || item.type === 'newline') {
this.tools.push(item);
}
});
this.iconURL = `${this.get('assetPath')}/tools/`;
},
didRender() {
let $this = this.$();
let editor = this.get('editor');
let $editor = $(this.get('containerSelector'));
if (!editor.range || !editor.range.head.section || !editor.range.head.section.isBlank
|| editor.range.head.section.renderNode._element.tagName.toLowerCase() !== 'p') {
$this.hide();
}
editor.cursorDidChange(() => {
// if there is no cursor:
if (!editor.range || !editor.range.head.section || !editor.range.head.section.isBlank
|| editor.range.head.section.renderNode._element.tagName.toLowerCase() !== 'p') {
$this.hide();
return;
}
let element = editor.range.head.section.renderNode._element;
if (this._element === element) {
return;
}
this.propertyWillChange('toolbar');
this.__state = 'normal';
this.isBlank = true;
let offset = this.$(element).position();
let edOffset = $editor.offset();
$this.css('top', offset.top + $editor.scrollTop() - edOffset.top - 13);
$this.css('left', offset.left + $editor.scrollLeft() + 20);
$this.show();
this._element = element;
this.tools.forEach((tool) => {
if (tool.hasOwnProperty('checkElements')) {
// if its a list we want to know what type
let sectionTagName = editor.activeSection._tagName === 'li' ? editor.activeSection.parent._tagName : editor.activeSection._tagName;
tool.checkElements(editor.activeMarkups.concat([{tagName: sectionTagName}]));
}
});
this.propertyDidChange('toolbar');
});
}
});