Skip to content

Commit

Permalink
Merge 98c48f3 into b5a40ef
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Jun 5, 2015
2 parents b5a40ef + 98c48f3 commit 9c17688
Show file tree
Hide file tree
Showing 66 changed files with 1,897 additions and 2,461 deletions.
16 changes: 16 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@
"!=",
"!=="
],
"requireSpaceAfterKeywords": [
"do",
"for",
"if",
"else",
"switch",
"case",
"try",
"catch",
"void",
"while",
"with",
"return",
"typeof",
"function"
],
"requireSpaceBeforeBinaryOperators": [
"=",
"+",
Expand Down
7 changes: 2 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@ module.exports = function (grunt) {
'src/js/extension.js',
'src/js/selection.js',
'src/js/events.js',
'src/js/extensions/deprecated/button.js',
'src/js/extensions/deprecated/anchor.js',
'src/js/extensions/deprecated/anchor-preview.js',
'src/js/extensions/deprecated/fontsize.js',
'src/js/extensions/button.js',
'src/js/extensions/form.js',
'src/js/extensions/anchor.js',
'src/js/extensions/anchor-preview.js',
'src/js/extensions/auto-link.js',
'src/js/extensions/image-dragging.js',
'src/js/extensions/keyboard-commands.js',
'src/js/extensions/fontsize.js',
'src/js/extensions/paste.js',
'src/js/extensions/placeholder.js',
'src/js/toolbar.js',
'src/js/extensions/toolbar.js',
'src/js/defaults/options.js',
'src/js/defaults/extensions.js',
'src/js/core.js',
Expand Down
165 changes: 123 additions & 42 deletions README.md

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions demo/custom-toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ <h2>Custom Labels </h2>
<script src="../dist/js/medium-editor.js"></script>
<script>
var editor = new MediumEditor('.editable', {
buttons: ['bold', 'italic', 'underline', 'strikethrough', 'quote', 'anchor', 'image', 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'superscript', 'subscript', 'orderedlist', 'unorderedlist', 'pre', 'removeFormat', 'outdent', 'indent', 'header1', 'header2'],
toolbar: {
buttons: ['bold', 'italic', 'underline', 'strikethrough', 'quote', 'anchor', 'image', 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'superscript', 'subscript', 'orderedlist', 'unorderedlist', 'pre', 'removeFormat', 'outdent', 'indent', 'header1', 'header2'],
},
buttonLabels: 'fontawesome',
anchor: {
targetCheckbox: true
}
});
var editor2 = new MediumEditor('.secondEditable', {
buttons: ['bold', 'italic', 'underline', 'anchor'],
toolbar: {
buttons: ['bold', 'italic', 'underline', 'anchor']
},
buttonLabels: {
'bold': 'bold',
'italic': '<i>italic</i>',
Expand Down
4 changes: 3 additions & 1 deletion demo/multi-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ <h2>Non editable Div</h2>
<script>
var editor = new MediumEditor('.editable'),
editor2 = new MediumEditor('.secondEditable', {
buttons: ['bold', 'italic', 'quote', 'pre']
toolbar: {
buttons: ['bold', 'italic', 'quote', 'pre']
}
});
</script>

Expand Down
4 changes: 3 additions & 1 deletion demo/multi-paragraph.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ <h1>Medium Editor Demo</h1>
<script>
var editor = new MediumEditor('.editable', {
allowMultiParagraphSelection: false,
diffTop: -12,
firstHeader: 'h1',
secondHeader: 'h2',
delay: 0,
toolbar: {
diffTop: -12
},
anchor: {
placeholderText: 'Type a link'
}
Expand Down
8 changes: 6 additions & 2 deletions demo/pass-instance.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ <h1>Medium Editor</h1>
};

var one = new MediumEditor('.one', {
buttons: ['extension'],
toolbar: {
buttons: ['extension'],
},
extensions: {
extension: new Extension()
}
});

var two = new MediumEditor('.two', {
buttons: ['extension'],
toolbar: {
buttons: ['extension'],
},
extensions: {
extension: new Extension()
}
Expand Down
50 changes: 29 additions & 21 deletions demo/static-toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,44 @@ <h3>Right Align</h3>
<script src="../dist/js/medium-editor.js"></script>
<script>
var editor = new MediumEditor('.editable', {
buttons: ['bold', 'italic', 'underline', 'strikethrough', 'quote', 'anchor', 'image', 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'superscript', 'subscript', 'orderedlist', 'unorderedlist', 'pre', 'outdent', 'indent', 'header1', 'header2'],
staticToolbar: true,
stickyToolbar: true
toolbar: {
buttons: ['bold', 'italic', 'underline', 'strikethrough', 'quote', 'anchor', 'image', 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'superscript', 'subscript', 'orderedlist', 'unorderedlist', 'pre', 'outdent', 'indent', 'header1', 'header2'],
static: true,
sticky: true
}
});

var editorColOne = new MediumEditor('#column-one', {
buttons: ['bold', 'italic', 'underline', 'strikethrough', 'quote', 'anchor', 'image', 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'superscript', 'subscript', 'orderedlist', 'unorderedlist', 'pre', 'outdent', 'indent', 'header1', 'header2'],
buttonLabels: 'fontawesome',
stickyToolbar: true,
staticToolbar: true,
toolbarAlign: 'left',
updateOnEmptySelection: true
toolbar: {
buttons: ['bold', 'italic', 'underline', 'strikethrough', 'quote', 'anchor', 'image', 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'superscript', 'subscript', 'orderedlist', 'unorderedlist', 'pre', 'outdent', 'indent', 'header1', 'header2'],
sticky: true,
static: true,
align: 'left',
updateOnEmptySelection: true
},
buttonLabels: 'fontawesome'
});

var editorColTwo = new MediumEditor('#column-two', {
buttons: ['bold', 'italic', 'underline', 'strikethrough', 'quote', 'anchor', 'image', 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'superscript', 'subscript', 'orderedlist', 'unorderedlist', 'pre', 'outdent', 'indent', 'header1', 'header2'],
buttonLabels: 'fontawesome',
stickyToolbar: true,
staticToolbar: true,
toolbarAlign: 'center',
updateOnEmptySelection: true
toolbar: {
buttons: ['bold', 'italic', 'underline', 'strikethrough', 'quote', 'anchor', 'image', 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'superscript', 'subscript', 'orderedlist', 'unorderedlist', 'pre', 'outdent', 'indent', 'header1', 'header2'],
sticky: true,
static: true,
align: 'center',
updateOnEmptySelection: true
},
buttonLabels: 'fontawesome'
});

var editorColThree = new MediumEditor('#column-three', {
buttons: ['bold', 'italic', 'underline', 'strikethrough', 'quote', 'anchor', 'image', 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'superscript', 'subscript', 'orderedlist', 'unorderedlist', 'pre', 'outdent', 'indent', 'header1', 'header2'],
buttonLabels: 'fontawesome',
stickyToolbar: true,
staticToolbar: true,
toolbarAlign: 'right',
updateOnEmptySelection: true
toolbar: {
buttons: ['bold', 'italic', 'underline', 'strikethrough', 'quote', 'anchor', 'image', 'justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull', 'superscript', 'subscript', 'orderedlist', 'unorderedlist', 'pre', 'outdent', 'indent', 'header1', 'header2'],
sticky: true,
static: true,
align: 'right',
updateOnEmptySelection: true
},
buttonLabels: 'fontawesome'
});
</script>
</body>
Expand Down
6 changes: 4 additions & 2 deletions demo/table-extension.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ <h1>Medium Editor Extension Form</h1>
<script src="js/extension-table.js"></script>
<script>
var editor = new MediumEditor('.editable', {
buttons: ['bold', 'italic', 'underline', 'anchor', 'table'],
toolbar: {
buttons: ['bold', 'italic', 'underline', 'anchor', 'table'],
static: true,
},
buttonLabels: 'fontawesome',
staticToolbar: true,
extensions: {
'table': new TableExtension(),
}
Expand Down
66 changes: 39 additions & 27 deletions spec/anchor-preview.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*global MediumEditor, describe, it, expect, spyOn, AnchorForm,
/*global describe, it, expect, spyOn, AnchorForm,
afterEach, beforeEach, jasmine, fireEvent, setupTestHelpers,
AnchorPreview */
AnchorPreview, MediumEditor */

describe('Anchor Preview TestCase', function () {
'use strict';
Expand All @@ -12,6 +12,7 @@ describe('Anchor Preview TestCase', function () {
'<a id="test-link" href="http://test.com">ipsum</a> ' +
'preview <span id="another-element">&nbsp;</span> ' +
'<a id="test-empty-link" href="">ipsum</a> ' +
'<a id="test-link-disable-preview" data-disable-preview="true" href="http://test.com">ipsum</a> ' +
'<a id="test-markup-link" href="http://test.com"><b>ipsum</b></a> ' +
'<a id="test-symbol-link" href="http://[{~#custom#~}].com"></a>');
});
Expand All @@ -23,8 +24,9 @@ describe('Anchor Preview TestCase', function () {
describe('anchor preview element', function () {
it('should be displayed on hover of a link element', function () {
var editor = this.newMediumEditor('.editor', {
delay: 200
}),
delay: 200
}),
toolbar = editor.getExtensionByName('toolbar'),
sel = window.getSelection(),
anchorPreview = editor.getExtensionByName('anchor-preview'),
nextRange;
Expand All @@ -48,21 +50,21 @@ describe('Anchor Preview TestCase', function () {
expect(editor.getExtensionByName('anchor').showForm).toHaveBeenCalled();

// selecting other text should close the toolbar
spyOn(MediumEditor.statics.Toolbar.prototype, 'hideToolbar').and.callThrough();
spyOn(MediumEditor.extensions.toolbar.prototype, 'hideToolbar').and.callThrough();
nextRange = document.createRange();
nextRange.selectNodeContents(document.getElementById('another-element'));
sel.removeAllRanges();
sel.addRange(nextRange);
fireEvent(document.getElementById('another-element'), 'click');
jasmine.clock().tick(200);
expect(editor.toolbar.hideToolbar).toHaveBeenCalled();
expect(toolbar.hideToolbar).toHaveBeenCalled();
});

it('should be displayed on hover of a link element with markup inside', function () {
var editor = this.newMediumEditor('.editor', {
delay: 200
}),
anchorPreview = editor.getExtensionByName('anchor-preview');
delay: 200
}),
anchorPreview = editor.getExtensionByName('anchor-preview');

// show preview
spyOn(AnchorPreview.prototype, 'showPreview').and.callThrough();
Expand Down Expand Up @@ -93,8 +95,8 @@ describe('Anchor Preview TestCase', function () {

it('should display different urls when hovering over different links consecutively', function () {
var editor = this.newMediumEditor('.editor', {
delay: 300
}),
delay: 300
}),
anchorPreview = editor.getExtensionByName('anchor-preview');

// show preview for first link
Expand All @@ -115,7 +117,9 @@ describe('Anchor Preview TestCase', function () {

it('should display the anchor form in the toolbar when clicked', function () {
var editor = this.newMediumEditor('.editor'),
anchorPreview = editor.getExtensionByName('anchor-preview');
anchorPreview = editor.getExtensionByName('anchor-preview'),
anchor = editor.getExtensionByName('anchor'),
toolbar = editor.getExtensionByName('toolbar');

// show preview
fireEvent(document.getElementById('test-link'), 'mouseover');
Expand All @@ -125,14 +129,14 @@ describe('Anchor Preview TestCase', function () {
fireEvent(anchorPreview.getPreviewElement(), 'click');
jasmine.clock().tick(200);

expect(editor.toolbar.isDisplayed()).toBe(true);
expect(editor.getExtensionByName('anchor').isDisplayed()).toBe(true);
expect(toolbar.isDisplayed()).toBe(true);
expect(anchor.isDisplayed()).toBe(true);
});

it('should NOT be displayed when the hovered link is empty', function () {
var editor = this.newMediumEditor('.editor', {
delay: 200
}),
delay: 200
}),
anchorPreview = editor.getExtensionByName('anchor-preview');

// show preview
Expand All @@ -144,30 +148,38 @@ describe('Anchor Preview TestCase', function () {
expect(anchorPreview.showPreview).not.toHaveBeenCalled();
});

it('should not be present when anchorPreview option is set to false', function () {
it('should be displayed when the link has data attribute to disable preview', function () {
var editor = this.newMediumEditor('.editor', {
anchorPreview: false
}),
delay: 200
}),
anchorPreview = editor.getExtensionByName('anchor-preview');

expect(anchorPreview).toBeUndefined();
expect(document.querySelector('.medium-editor-anchor-preview')).toBeNull();
// show preview
spyOn(AnchorPreview.prototype, 'showPreview').and.callThrough();
fireEvent(document.getElementById('test-link-disable-preview'), 'mouseover');

// preview shows only after delay
jasmine.clock().tick(250);
expect(anchorPreview.showPreview).toHaveBeenCalled();

// showPreview is called but the preview isn't displayed
expect(anchorPreview.getPreviewElement().classList.contains('medium-toolbar-arrow-over')).toBe(false);
});

it('should not be present when deprecated disableAnchorPreview option is passed', function () {
it('should NOT be present when anchorPreview option is set to false', function () {
var editor = this.newMediumEditor('.editor', {
disableAnchorPreview: true
}),
anchorPreview: false
}),
anchorPreview = editor.getExtensionByName('anchor-preview');

expect(anchorPreview).toBeUndefined();
expect(document.querySelector('.medium-editor-anchor-preview')).toBeNull();
});

it('should not be present when disableToolbar option is passed', function () {
it('should not be present when toolbar option is disabled', function () {
var editor = this.newMediumEditor('.editor', {
disableToolbar: true
}),
toolbar: false
}),
anchorPreview = editor.getExtensionByName('anchor-preview');

expect(anchorPreview).toBeUndefined();
Expand Down

0 comments on commit 9c17688

Please sign in to comment.