medium-editor
Advanced tools
Comparing version 5.17.0 to 5.18.0
76
API.md
@@ -136,3 +136,3 @@ # MediumEditor Object API (v5.0.0) | ||
3. `Array` | `NodeList` | `HTMLCollection`: If passed as an `Array`-like collection of `HTMLElement`s, all of these elements will be removed from the edtior **elements**. | ||
3. `Array` | `NodeList` | `HTMLCollection`: If passed as an `Array`-like collection of `HTMLElement`s, all of these elements will be removed from the editor **elements**. | ||
@@ -286,2 +286,8 @@ *** | ||
**Arguments** | ||
1. _**range** (`Range`)_: _**OPTIONAL**_ | ||
* The `Range` to find the selection parent element within | ||
* If no element is provided, the editor will use the current range within the selection of the editor's `contentWindow` | ||
*** | ||
@@ -329,2 +335,8 @@ ### `restoreSelection()` | ||
**Arguments** | ||
1. _**text** (`String`)_: | ||
* Content to be pasted at the location of the current selection/cursor | ||
*** | ||
@@ -334,2 +346,24 @@ ### `createLink(opts)` | ||
**Arguments** | ||
1. _**opts** (`Object`)_: | ||
* Object containing additional properties needed for creating a link | ||
**Properties of 'opts'** | ||
1. _**value** (`String`)_ _**REQUIRED**_ | ||
* The url to set as the `href` of the created link. A non-empty value must be provided for the link to be created. | ||
2. _**target** (`String`)_ | ||
* Attribute to set as the `target` attribute of the created link. Passing 'self' or not passing this option at all are equivalent in that they will just ensure that `target="_blank"` will NOT be present on the created link. | ||
* **NOTE** If the `targetBlank` option on the editor is set to true, the `target` property of opts will be ignored and `target="_blank"` will be added to all created links. | ||
3. _**buttonClass** (`String`)_ | ||
* Class (or classes) to append to the `class` attribute of the created link. | ||
##### Example | ||
```js | ||
editor.createLink({ value: 'https://github.com/yabwe/medium-editor', target: '_blank', buttonClass: 'medium-link' }); | ||
``` | ||
*** | ||
@@ -339,2 +373,18 @@ ### `execAction(action, opts)` | ||
**Arguments** | ||
1. _**action** (`String`)_: | ||
* Action to be passed as the 'command' argument to `document.execCommand(command, showDefaultUI, value)` | ||
2. _**opts** (`Object`)_ _**OPTIONAL**_: | ||
* Object containing additional properties for specific commands | ||
**Properties of 'opts'** | ||
1. _**value** (`String`)_ | ||
* The value to pass as the 'value' argument to `document.execCommand(command, showDefaultUI, value)` | ||
2. For 'createLink', the `opts` are passed directly to [`.createLink(opts)`]((#createlinkopts)) so see that method for additional options for that command | ||
*** | ||
@@ -344,6 +394,28 @@ ### `pasteHTML(html, options)` | ||
**Arguments** | ||
1. _**html** (`String`)_: | ||
* Content to be pasted at the location of the current selection/cursor | ||
2. _**options** (`Object`)_ _**OPTIONAL**_: | ||
* Optional overrides for `cleanTags` and/or `cleanAttrs` for removing specific element types (`cleanTags`) or specific attributes (`cleanAttrs`) from the inserted HTML. See [cleanTags](OPTIONS.md#cleantags) and [cleanAttrs](OPTIONS.md#cleanattrs) in OPTIONS.md for more information. | ||
##### Example | ||
```js | ||
editor.pasteHTML('<p class="classy"><strong>Some Custom HTML</strong></p>', { cleanAttrs: ['class'], cleanTags: ['strong']}); | ||
``` | ||
*** | ||
### `queryCommandState(action)` | ||
_wrapper around the browser's built in `document.queryCommandState(action)` for checking whether a specific action has already been applied to the selection._ | ||
_wrapper around the browser's built in `document.queryCommandState(command)` for checking whether a specific action has already been applied to the selection._ | ||
**Arguments** | ||
1. _**action** (`String`)_: | ||
* Action to be passed as the 'command' argument to `document.queryCommandState(command)` | ||
*** | ||
@@ -350,0 +422,0 @@ ## Helper Functions |
@@ -0,1 +1,8 @@ | ||
5.18.0 / 2016-05-21 | ||
================== | ||
* Add support calling document.execCommand with arbitrary argument from execAction | ||
* Also deprecate custom execAction option names in favor of standard .value | ||
* Fix error from addElements when initializing editor with no elements | ||
5.17.0 / 2016-05-17 | ||
@@ -2,0 +9,0 @@ ================== |
{ | ||
"name": "medium-editor", | ||
"version": "5.17.0", | ||
"version": "5.18.0", | ||
"author": "Davi Ferreira <hi@daviferreira.com>", | ||
@@ -5,0 +5,0 @@ "contributors": [ |
@@ -341,3 +341,3 @@ /*global fireEvent, selectElementContents, | ||
expectedOpts = { | ||
url: 'http://te%20s%20t.com/', | ||
value: 'http://te%20s%20t.com/', | ||
target: '_self' | ||
@@ -356,3 +356,3 @@ }; | ||
expect(link).not.toBeNull(); | ||
expect(link.href).toBe(expectedOpts.url); | ||
expect(link.href).toBe(expectedOpts.value); | ||
}); | ||
@@ -368,3 +368,3 @@ it('should not change spaces to %20 if linkValidation is set to false', function () { | ||
expectedOpts = { | ||
url: 'http://te s t.com/', | ||
value: 'http://te s t.com/', | ||
target: '_self' | ||
@@ -376,3 +376,3 @@ }; | ||
selectElementContentsAndFire(editor.elements[0]); | ||
anchorExtension.showForm(expectedOpts.url); | ||
anchorExtension.showForm(expectedOpts.value); | ||
fireEvent(anchorExtension.getForm().querySelector('a.medium-editor-toolbar-save'), 'click'); | ||
@@ -456,3 +456,3 @@ | ||
opts = { | ||
url: 'http://test.com', | ||
value: 'http://test.com', | ||
target: '_self', | ||
@@ -533,3 +533,3 @@ buttonClass: 'btn btn-default' | ||
expect(editor.createLink).toHaveBeenCalledWith({ | ||
url: 'http://www.example.com', | ||
value: 'http://www.example.com', | ||
target: '_blank' | ||
@@ -567,3 +567,3 @@ }); | ||
expect(editor.createLink).toHaveBeenCalledWith({ | ||
url: 'http://www.example.com', | ||
value: 'http://www.example.com', | ||
target: '_self' | ||
@@ -608,3 +608,3 @@ }); | ||
expect(editor.createLink).toHaveBeenCalledWith({ | ||
url: 'http://www.example.com', | ||
value: 'http://www.example.com', | ||
target: '_self' | ||
@@ -648,3 +648,3 @@ }); | ||
expect(editor.createLink).toHaveBeenCalledWith({ | ||
url: 'http://www.example.com', | ||
value: 'http://www.example.com', | ||
target: '_self' | ||
@@ -651,0 +651,0 @@ }); |
@@ -106,2 +106,108 @@ /*global fireEvent, selectElementContents, | ||
describe('execAction', function () { | ||
it('should pass opt directly to document.execCommand', function () { | ||
// In order to safely spy on document.execCommand we need to disable functionality | ||
// which overrides document.execCommand in IE & Edge | ||
var origSupported = MediumEditor.Events.prototype.InputEventOnContenteditableSupported; | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = true; | ||
spyOn(document, 'execCommand').and.callThrough(); | ||
var editor = this.newMediumEditor('.editor'); | ||
editor.execAction('foreColor', { value: 'red' }); | ||
expect(document.execCommand).toHaveBeenCalledWith('foreColor', false, 'red'); | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = origSupported; | ||
}); | ||
it('fontName support old style', function () { | ||
// In order to safely spy on document.execCommand we need to disable functionality | ||
// which overrides document.execCommand in IE & Edge | ||
var origSupported = MediumEditor.Events.prototype.InputEventOnContenteditableSupported; | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = true; | ||
spyOn(document, 'execCommand').and.callThrough(); | ||
var editor = this.newMediumEditor('.editor'); | ||
editor.execAction('fontName', { name: 'Tahoma' }); | ||
expect(document.execCommand).toHaveBeenCalledWith('fontName', false, 'Tahoma'); | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = origSupported; | ||
}); | ||
it('fontName support new stle', function () { | ||
// In order to safely spy on document.execCommand we need to disable functionality | ||
// which overrides document.execCommand in IE & Edge | ||
var origSupported = MediumEditor.Events.prototype.InputEventOnContenteditableSupported; | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = true; | ||
spyOn(document, 'execCommand').and.callThrough(); | ||
var editor = this.newMediumEditor('.editor'); | ||
editor.execAction('fontName', { value: 'Tahoma' }); | ||
expect(document.execCommand).toHaveBeenCalledWith('fontName', false, 'Tahoma'); | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = origSupported; | ||
}); | ||
it('fontSize support old style', function () { | ||
// In order to safely spy on document.execCommand we need to disable functionality | ||
// which overrides document.execCommand in IE & Edge | ||
var origSupported = MediumEditor.Events.prototype.InputEventOnContenteditableSupported; | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = true; | ||
spyOn(document, 'execCommand').and.callThrough(); | ||
var editor = this.newMediumEditor('.editor'); | ||
editor.execAction('fontSize', { size: 14 }); | ||
expect(document.execCommand).toHaveBeenCalledWith('fontSize', false, 14); | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = origSupported; | ||
}); | ||
it('fontSize support new stle', function () { | ||
// In order to safely spy on document.execCommand we need to disable functionality | ||
// which overrides document.execCommand in IE & Edge | ||
var origSupported = MediumEditor.Events.prototype.InputEventOnContenteditableSupported; | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = true; | ||
spyOn(document, 'execCommand').and.callThrough(); | ||
var editor = this.newMediumEditor('.editor'); | ||
editor.execAction('fontSize', { value: 14 }); | ||
expect(document.execCommand).toHaveBeenCalledWith('fontSize', false, 14); | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = origSupported; | ||
}); | ||
it('createLink support old style', function () { | ||
// In order to safely spy on document.execCommand we need to disable functionality | ||
// which overrides document.execCommand in IE & Edge | ||
var origSupported = MediumEditor.Events.prototype.InputEventOnContenteditableSupported; | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = true; | ||
spyOn(document, 'execCommand').and.callThrough(); | ||
var editor = this.newMediumEditor('.editor'); | ||
selectElementContentsAndFire(editor.elements[0].firstChild); | ||
jasmine.clock().tick(1); | ||
editor.execAction('createLink', { url: 'http://www.test.com' }); | ||
expect(document.execCommand).toHaveBeenCalledWith('createLink', false, 'http://www.test.com'); | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = origSupported; | ||
}); | ||
it('createLink support new style', function () { | ||
// In order to safely spy on document.execCommand we need to disable functionality | ||
// which overrides document.execCommand in IE & Edge | ||
var origSupported = MediumEditor.Events.prototype.InputEventOnContenteditableSupported; | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = true; | ||
spyOn(document, 'execCommand').and.callThrough(); | ||
var editor = this.newMediumEditor('.editor'); | ||
selectElementContentsAndFire(editor.elements[0].firstChild); | ||
jasmine.clock().tick(1); | ||
editor.execAction('createLink', { value: 'http://www.test.com' }); | ||
expect(document.execCommand).toHaveBeenCalledWith('createLink', false, 'http://www.test.com'); | ||
MediumEditor.Events.prototype.InputEventOnContenteditableSupported = origSupported; | ||
}); | ||
}); | ||
describe('checkContentChanged', function () { | ||
@@ -108,0 +214,0 @@ it('should trigger editableInput when called after the html has changed', function () { |
@@ -526,3 +526,4 @@ (function () { | ||
justifyAction = /justify([A-Za-z]*)$/g, /* Detecting if is justifyCenter|Right|Left */ | ||
match; | ||
match, | ||
cmdValueArgument; | ||
/*jslint regexp: false*/ | ||
@@ -538,7 +539,17 @@ | ||
if (action === 'fontSize') { | ||
return this.options.ownerDocument.execCommand('fontSize', false, opts.size); | ||
// TODO: Deprecate support for opts.size in 6.0.0 | ||
if (opts.size) { | ||
MediumEditor.util.deprecated('.size option for fontSize command', '.value', '6.0.0'); | ||
} | ||
cmdValueArgument = opts.value || opts.size; | ||
return this.options.ownerDocument.execCommand('fontSize', false, cmdValueArgument); | ||
} | ||
if (action === 'fontName') { | ||
return this.options.ownerDocument.execCommand('fontName', false, opts.name); | ||
// TODO: Deprecate support for opts.name in 6.0.0 | ||
if (opts.name) { | ||
MediumEditor.util.deprecated('.name option for fontName command', '.value', '6.0.0'); | ||
} | ||
cmdValueArgument = opts.value || opts.name; | ||
return this.options.ownerDocument.execCommand('fontName', false, cmdValueArgument); | ||
} | ||
@@ -567,3 +578,4 @@ | ||
return this.options.ownerDocument.execCommand(action, false, null); | ||
cmdValueArgument = opts && opts.value; | ||
return this.options.ownerDocument.execCommand(action, false, cmdValueArgument); | ||
} | ||
@@ -971,3 +983,4 @@ | ||
var currentEditor = MediumEditor.selection.getSelectionElement(this.options.contentWindow), | ||
customEvent = {}; | ||
customEvent = {}, | ||
targetUrl; | ||
@@ -981,3 +994,8 @@ // Make sure the selection is within an element this editor is tracking | ||
this.events.disableCustomEvent('editableInput'); | ||
if (opts.url && opts.url.trim().length > 0) { | ||
// TODO: Deprecate support for opts.url in 6.0.0 | ||
if (opts.url) { | ||
MediumEditor.util.deprecated('.url option for createLink', '.value', '6.0.0'); | ||
} | ||
targetUrl = opts.url || opts.value; | ||
if (targetUrl && targetUrl.trim().length > 0) { | ||
var currentSelection = this.options.contentWindow.getSelection(); | ||
@@ -1074,3 +1092,3 @@ if (currentSelection) { | ||
// Creates the link in the document fragment | ||
MediumEditor.util.createLink(this.options.ownerDocument, textNodes, opts.url.trim()); | ||
MediumEditor.util.createLink(this.options.ownerDocument, textNodes, targetUrl.trim()); | ||
@@ -1087,9 +1105,9 @@ // Chrome trims the leading whitespaces when inserting HTML, which messes up restoring the selection. | ||
} else { | ||
this.options.ownerDocument.execCommand('createLink', false, opts.url); | ||
this.options.ownerDocument.execCommand('createLink', false, targetUrl); | ||
} | ||
if (this.options.targetBlank || opts.target === '_blank') { | ||
MediumEditor.util.setTargetBlank(MediumEditor.selection.getSelectionStart(this.options.ownerDocument), opts.url); | ||
MediumEditor.util.setTargetBlank(MediumEditor.selection.getSelectionStart(this.options.ownerDocument), targetUrl); | ||
} else { | ||
MediumEditor.util.removeTargetBlank(MediumEditor.selection.getSelectionStart(this.options.ownerDocument), opts.url); | ||
MediumEditor.util.removeTargetBlank(MediumEditor.selection.getSelectionStart(this.options.ownerDocument), targetUrl); | ||
} | ||
@@ -1096,0 +1114,0 @@ |
@@ -368,3 +368,5 @@ (function () { | ||
this.detachAllEventsFromElement(element); | ||
delete this.contentCache[index]; | ||
if (this.contentCache) { | ||
delete this.contentCache[index]; | ||
} | ||
} | ||
@@ -371,0 +373,0 @@ }, |
@@ -153,3 +153,3 @@ (function () { | ||
opts = opts || { url: '' }; | ||
opts = opts || { value: '' }; | ||
// TODO: This is for backwards compatability | ||
@@ -159,3 +159,3 @@ // We don't need to support the 'string' argument in 6.0.0 | ||
opts = { | ||
url: opts | ||
value: opts | ||
}; | ||
@@ -169,3 +169,3 @@ } | ||
input.value = opts.url; | ||
input.value = opts.value; | ||
input.focus(); | ||
@@ -207,7 +207,7 @@ | ||
opts = { | ||
url: this.getInput().value.trim() | ||
value: this.getInput().value.trim() | ||
}; | ||
if (this.linkValidation) { | ||
opts.url = this.checkLinkFormat(opts.url); | ||
opts.value = this.checkLinkFormat(opts.value); | ||
} | ||
@@ -214,0 +214,0 @@ |
@@ -161,3 +161,3 @@ (function () { | ||
} else { | ||
this.execAction('fontName', { name: font }); | ||
this.execAction('fontName', { value: font }); | ||
} | ||
@@ -164,0 +164,0 @@ }, |
@@ -154,3 +154,3 @@ (function () { | ||
} else { | ||
this.execAction('fontSize', { size: size }); | ||
this.execAction('fontSize', { value: size }); | ||
} | ||
@@ -157,0 +157,0 @@ }, |
@@ -18,3 +18,3 @@ MediumEditor.parseVersionString = function (release) { | ||
// grunt-bump looks for this: | ||
'version': '5.17.0' | ||
'version': '5.18.0' | ||
}).version); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1867796
24097