Skip to content
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
25 changes: 24 additions & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,30 @@
"Image",
"Video",
"Tweet"
]
],
textFormatting: {
bold: true,
italic: true,
underline: true,
strikethrough: true,
link: true,
h1: true,
h2: true,
list: true,
blockquote: true,
configure: function(scribe, scribeConfiguration){
scribeConfiguration.formatBarCommands.push({
name: "Superscript",
cmd: "superscript",
text: "^",
title: "superscript"
});
scribeConfiguration.sanitize.sup = {};
scribeConfiguration.shortcuts.superscript = function (event) {
return (event.metaKey || event.ctrlKey) && event.keyCode === 80; // p
};
}
}
});

$('form').bind('submit', function () {
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@
"node-bourbon": "^4.2.1-beta1",
"object.assign": "^1.1.1",
"scribe-editor": "1.4.15",
"scribe-plugin-blockquote-command": "^0.1.0",
"scribe-plugin-formatter-plain-text-convert-new-lines-to-html": "^0.1.1",
"scribe-plugin-heading-command": "^0.1.0",
"scribe-plugin-intelligent-unlink-command": "^0.1.6",
"scribe-plugin-keyboard-shortcuts": "^0.1.1",
"scribe-plugin-link-prompt-command": "^0.2.0",
"scribe-plugin-sanitizer": "^0.1.9",
"selenium-webdriver": "2.47.0",
"scribe-plugin-smart-lists": "^0.1.8",
"spin.js": "^2.0.1",
"webpack": "^1.8.4",
"webpack-dev-server": "^1.8.0"
Expand Down
11 changes: 11 additions & 0 deletions spec/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
<script type="text/javascript" charset="utf-8">
$(function(){
SirTrevor.config.language = "en";
SirTrevor.config.defaults.textFormatting = {
bold: true,
italic: true,
underline: true,
strikethrough: true,
link: true,
h1: true,
h2: true,
list: true,
blockquote: true
};
});
</script>
</body>
Expand Down
162 changes: 145 additions & 17 deletions spec/e2e/format-bar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('Format Bar', function() {
{
"type": "text",
"data": {
"text": "Bold, Italic, Link"
"text": "Bold, Italic, Link, Underline, Strikethrough\\n\\nH1\\n\\nH2\\n\\nUL\\n\\nOL\\n\\nQuote"
}
}
]
Expand All @@ -31,8 +31,10 @@ describe('Format Bar', function() {
it('should allow formatting of text', function(done) {

var testUrl = 'http://www.example.com';
var expectedHtmlWithoutLink = '<p><b>Bold</b>, <i>Italic</i>, Link</p>';
var expectedFullHtml = '<p><b>Bold</b>, <i>Italic</i>, <a href="' + testUrl + '">Link</a></p>';
var expectedHtmlUpToLink = '<p><b>Bold</b>, <i>Italic</i>, <a href="' + testUrl + '">Link</a>, Underline, Strikethrough</p><p>H1</p><p>H2</p><p>UL</p><p>OL</p><p>Quote</p>';
var expectedHtmlWithLinkRemoved = '<p><b>Bold</b>, <i>Italic</i>, Link, Underline, Strikethrough</p><p>H1</p><p>H2</p><p>UL</p><p>OL</p><p>Quote</p>';
var expectedFinalFirefoxHtml = '<p><b>Bold</b>, <i>Italic</i>, Link, <u>Underline</u>, <strike>Strikethrough</strike></p><h1>H1</h1><h2>H2</h2><ul><li>UL</li></ul><ol><li>OL</li></ol><blockquote><p>Quote</p></blockquote>';
var expectedFinalChromeHtml = '<p><b>Bold</b>, <i>Italic</i>, Link, <u>Underline</u>, <strike>Strikethrough</strike></p><h1>H1</h1><h2>H2</h2><ul><li>UL<br></li></ul><ol><li>OL<br></li></ol><blockquote><p>Quote</p></blockquote>';

function selectBoldText() {
return helpers.browser.actions()
Expand Down Expand Up @@ -67,18 +69,132 @@ describe('Format Bar', function() {

function selectLinkText() {
return helpers.browser.actions()
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyDown(driver.Key.SHIFT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyUp(driver.Key.SHIFT)
.perform().then( function() {
return helpers.findElementByCss('.st-format-btn--Link').click();
});
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyDown(driver.Key.SHIFT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyUp(driver.Key.SHIFT)
.perform().then( function() {
return helpers.findElementByCss('.st-format-btn--Link').click();
});
}

function selectUnderlineText() {
return helpers.browser.actions()
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyDown(driver.Key.SHIFT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyUp(driver.Key.SHIFT)
.perform().then( function() {
return helpers.findElementByCss('.st-format-btn--Underline').click();
});
}

function selectStrikethroughText() {
return helpers.browser.actions()
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyDown(driver.Key.SHIFT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyUp(driver.Key.SHIFT)
.perform().then( function() {
return helpers.findElementByCss('.st-format-btn--Strikethrough').click();
});
}

function selectH1Text() {
return helpers.browser.actions()
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyDown(driver.Key.SHIFT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyUp(driver.Key.SHIFT)
.perform().then( function() {
return helpers.findElementByCss('.st-format-btn--Heading1').click();
});
}

function selectH2Text() {
return helpers.browser.actions()
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyDown(driver.Key.SHIFT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyUp(driver.Key.SHIFT)
.perform().then( function() {
return helpers.findElementByCss('.st-format-btn--Heading2').click();
});
}

function selectUnorderedListText() {
return helpers.browser.actions()
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyDown(driver.Key.SHIFT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyUp(driver.Key.SHIFT)
.perform().then( function() {
return helpers.findElementByCss('.st-format-btn--UnorderedList').click();
});
}

function selectOrderedListText() {
return helpers.browser.actions()
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyDown(driver.Key.SHIFT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyUp(driver.Key.SHIFT)
.perform().then( function() {
return helpers.findElementByCss('.st-format-btn--OrderedList').click();
});
}

function selectQuoteText() {
return helpers.browser.actions()
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyDown(driver.Key.SHIFT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.sendKeys(driver.Key.ARROW_RIGHT)
.keyUp(driver.Key.SHIFT)
.perform().then( function() {
return helpers.findElementByCss('.st-format-btn--Blockquote').click();
});
}

var parent;
Expand All @@ -96,12 +212,24 @@ describe('Format Bar', function() {
}).then( function() {
return parent.getInnerHtml();
}).then( function(html) {
expect(html).toBe(expectedFullHtml);
expect(html).toBe(expectedHtmlUpToLink);
return helpers.findElementByCss('.st-format-btn--Unlink').click();
}).then( function() {
return parent.getInnerHtml();
}).then( function(html) {
expect(html).toBe(expectedHtmlWithoutLink);
expect(html).toBe(expectedHtmlWithLinkRemoved);
}).then(selectUnderlineText)
.then(selectStrikethroughText)
.then(selectH1Text)
.then(selectH2Text)
.then(selectUnorderedListText)
.then(selectOrderedListText)
.then(selectQuoteText)
.then( function() {
return parent.getInnerHtml();
}).then( function(html) {
var result = html === expectedFinalChromeHtml || html === expectedFinalFirefoxHtml;
expect(result).toBe(true);
done();
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/block-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var EventBus = require('./event-bus');
var Blocks = require('./blocks');

var BLOCK_OPTION_KEYS = ['convertToMarkdown', 'convertFromMarkdown',
'formatBar'];
'formatBar', 'textFormatting'];

var BlockManager = function(options, editorInstance, mediator) {
this.options = options;
Expand Down
50 changes: 9 additions & 41 deletions src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ Object.assign(Block.prototype, SimpleBlock.fn, require('./block-validations'), {
paste_options: {},
upload_options: {},

formattable: true,

_previousSelection: '',

initialize: function() {},
Expand Down Expand Up @@ -115,6 +113,9 @@ Object.assign(Block.prototype, SimpleBlock.fn, require('./block-validations'), {
this.$inputs = input_html;
}

// This is also used by multi-editable mixin.
this.textFormatting = Object.assign({}, this.options.textFormatting, this.textFormatting);

if (this.hasTextBlock()) { this._initTextBlocks(); }

this.availableMixins.forEach(function(mixin) {
Expand All @@ -123,8 +124,6 @@ Object.assign(Block.prototype, SimpleBlock.fn, require('./block-validations'), {
}
}, this);

if (this.formattable) { this._initFormatting(); }

this._blockPrepare();

return this;
Expand Down Expand Up @@ -303,41 +302,6 @@ Object.assign(Block.prototype, SimpleBlock.fn, require('./block-validations'), {
this.onBlur();
},

_initFormatting: function() {

// Enable formatting keyboard input
var block = this;

if (!this.options.formatBar) {
return;
}

this.options.formatBar.commands.forEach(function(cmd) {
if (_.isUndefined(cmd.keyCode)) {
return;
}

var ctrlDown = false;

block.$el
.on('keyup','.st-text-block', function(ev) {
if(ev.which === 17 || ev.which === 224 || ev.which === 91) {
ctrlDown = false;
}
})
.on('keydown','.st-text-block', {formatter: cmd}, function(ev) {
if(ev.which === 17 || ev.which === 224 || ev.which === 91) {
ctrlDown = true;
}

if(ev.which === ev.data.formatter.keyCode && ctrlDown) {
ev.preventDefault();
block.execTextBlockCommand(ev.data.formatter.cmd);
}
});
});
},

_initTextBlocks: function() {
this.getTextBlock()
.bind('keyup', this.getSelectionForFormatter)
Expand All @@ -349,9 +313,13 @@ Object.assign(Block.prototype, SimpleBlock.fn, require('./block-validations'), {

var configureScribe =
_.isFunction(this.configureScribe) ? this.configureScribe.bind(this) : null;
this._scribe = ScribeInterface.initScribeInstance(
textBlock, this.scribeOptions, configureScribe

var scribeData = ScribeInterface.initScribeInstance(
textBlock, this.scribeOptions, this.textFormatting, configureScribe
);

this._scribe = scribeData.scribe;
this.formatBarCommands = scribeData.formatBarCommands;
}
},

Expand Down
8 changes: 6 additions & 2 deletions src/block_mixins/multi-editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ module.exports = {

var configureScribe =
_.isFunction(this.configureScribe) ? this.configureScribe.bind(this) : null;
var scribe = ScribeInterface.initScribeInstance(
editor, this.scribeOptions, configureScribe

var scribeData = ScribeInterface.initScribeInstance(
editor, this.scribeOptions, this.textFormatting, configureScribe
);

var scribe = scribeData.scribe;
this.formatBarCommands = scribeData.formatBarCommands;

scribe.setContent(content);

var editorObject = {
Expand Down
10 changes: 9 additions & 1 deletion src/blocks/heading.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ module.exports = Block.extend({

editorHTML: '<h2 class="st-required st-text-block st-text-block--heading" contenteditable="true"></h2>',

scribeOptions: {
scribeOptions: {
allowBlockElements: false,
tags: {
p: false
}
},

textFormatting: {
bold: false,
h1: false,
h2: false,
list: false,
blockquote: false
},

icon_name: 'heading',

loadData: function(data){
Expand Down
Loading