0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00
Commit graph

492 commits

Author SHA1 Message Date
Neil Jenkins
c190fab9fd Fix deletion of range when start or end is at edge of block.
If the selection starts and ends in the middle of blocks, we need to merge
these after extracting the range. But we need to be careful not to merge if
the selection ends at a block, as we end up merging into a block that wasn't
selected.
2015-07-25 18:03:51 -07:00
Neil Jenkins
715166b95d Let browser handle paste of images in FF/Safari. 2015-07-16 10:47:56 -07:00
Neil Jenkins
fdcef5fc8e Workaround clipboard having blank text/html version. 2015-07-14 12:59:27 -07:00
Je
aac169f764 Add support for the AMD 2015-07-14 00:33:38 +08:00
Je
3f13435182 Add support for AMD 2015-07-14 00:16:16 +08:00
Neil Jenkins
8d764f6638 Fix Chrome may replace <div> with <br> if you delete all content.
Fixes #108.
2015-07-13 06:39:07 -07:00
Neil Jenkins
a8fcd55cf4 Make event.preventDefault() cancel default key actions.
Fixes #107
2015-07-13 09:25:44 +07:00
Neil Jenkins
579cad7ff9 Fix pasting plain text in Safari. 2015-07-11 19:22:46 +07:00
Neil Jenkins
522a481dd3 Require <html data-squireinit="true"> to auto-instantiate.
Explicit opt-in to autoinstantiation (included in the default document.html)
means Squire may be loaded in sites that themselves are loaded in iframes,
without unexpected consequences.

Resolves #104.
2015-07-06 12:19:21 +07:00
Neil Jenkins
4f010a5de0 Override page up/down to match expected platform behaviour. 2015-06-25 11:02:56 +07:00
Neil Jenkins
de7d7011a7 Merge pull request #103 from shiawuen/top
fix bug on Browserify component when embed in multi layers of iframe
2015-06-23 15:16:08 +07:00
Neil Jenkins
2a8fb93cd9 Fix erroneous white-space removal when pasting inline fragment. 2015-06-23 09:46:15 +07:00
Neil Jenkins
def56193d4 Fix dummy paste area should be removed after paste completes 2015-06-22 09:32:47 +07:00
Neil Jenkins
7fc3ab55c3 Better cleanTree fn.
- Better checks to precisely trim white space only at beginning and end of block
- Don't keep the contents of <head> or <style> tags if inserted into body.
- Always keep styles to preserve fidelity on paste.

Fixes #95.
2015-06-19 14:20:19 +07:00
Neil Jenkins
926f40d033 Tidy Clean.js file layout 2015-06-19 14:20:01 +07:00
Neil Jenkins
c3701ba026 Move addLinks fn into Editor.js
It's only used by insertHTML, and isn't really about cleaning.
2015-06-19 14:19:49 +07:00
Neil Jenkins
680c0fbbb7 Don't use old clipboard API.
Safari very rarely has a text/html version (even if you copy from within
Safari!) so you end up always pasting plain text. Better to use the fallback
method to grab the data.
2015-06-19 14:19:37 +07:00
Neil Jenkins
bc523f83e8 Better paste handling
Get paste data directly from browser when supported. Funnel all pastes through
the insertHTML method for consistent results.
2015-06-19 14:19:21 +07:00
Neil Jenkins
395a5825e9 Split cleaning fns and clipboard handlers into separate file. 2015-06-19 14:18:32 +07:00
Neil Jenkins
e90f18dba9 Fix inserting partial inlines in insertTreeFragmentIntoRange
Needs to account for browser "<br>"s inside blocks.
2015-06-19 14:18:07 +07:00
shiawuen
ff21cb37e6 fix bug on Browserify component when embed on another window replacing containing window content 2015-06-19 12:12:37 +08:00
Neil Jenkins
a1ff33da9f Squire#removeAllFormatting fixes.
* Update the path after making the changes, so UI buttons can update correctly.
* Focus the editor on completion, to match the behaviour of other commands.
* Merge all the gathered text nodes if they're adjacent, so we have a normalised
  result.
2015-06-17 19:07:29 +07:00
Neil Jenkins
09167c73e4 Make it possible to delete an <img> with display other than inline
Based on pull request #85 from dryoma.
2015-06-17 17:18:34 +07:00
Neil Jenkins
345159b4c4 Better algorithm for remove all formatting action.
1. Keeps all leaf nodes not just text nodes, so images etc. are not removed.
2. If the selection is not within a single block, it is expanded to the edges
   of the blocks rather than splitting the blocks; this is unlikely to have
   been what the user wanted.
3. More efficient tree traversal and manipulation; no duplication of nodes.
4. Records undo state before performing the action.
2015-06-17 15:43:27 +07:00
Neil Jenkins
d9872fb4b2 More efficient forEachChildInRange fn.
No need for a tree walker, and we don't waste time iterating into children
that can never match the filter function.
2015-06-17 15:43:27 +07:00
Neil Jenkins
8b112b7615 Ensure removeAllFormatting always returns self. 2015-06-17 15:43:27 +07:00
Neil Jenkins
36432d45bd Fix whitespace. 2015-06-17 15:43:27 +07:00
Gert Sønderby
90660e8e4f Updated README, aligned return value with other API functions. 2015-06-17 15:43:26 +07:00
Gert Sønderby
6aba099388 Tests run in latest Chrome, FF, Safari + IE10 and 11. 2015-06-17 15:43:26 +07:00
Gert K. Sønderby
654706f15f Squire#removeAllFormatting() implemented, replaces range contents with style-sanitized version. 2015-06-17 15:43:26 +07:00
Gert K. Sønderby
d16de00a23 Added option to persist splits in inline nodes when fetching range from bookmark. 2015-06-17 15:43:26 +07:00
Neil Jenkins
42139c8399 Fix error thrown inserting tree fragment at start/end of document. 2015-06-17 15:43:26 +07:00
Neil Jenkins
c29a8c639b Wrap rather than split to replace <br>s.
Fixes #81.
2015-06-13 11:44:32 +07:00
Neil Jenkins
27b1532ca6 Add Squire#moveCursorTo(Start|End) methods.
I've got 99 GitHub issues, but #99 ain't one (any more).
2015-06-13 11:20:07 +07:00
Neil Jenkins
e59e6418af Improve merging edges of inserted tree fragment.
Fixes #87.
2015-06-12 17:48:06 +07:00
Neil Jenkins
f6cddb4626 Remove some old IE8-specific code. 2015-06-11 15:53:12 +07:00
Neil Jenkins
ae7d93a8fe Position paste area further off screen to hide IE handlebars
Fixes #84.
2015-06-09 16:38:16 +07:00
Neil Jenkins
60169dce6b Handle browser splitting paste area.
Fixes #88.
2015-06-09 16:32:20 +07:00
Neil Jenkins
884f352846 Set focus after element inserted with Squire#insertElement
Fixes #90.
2015-06-02 21:15:14 +07:00
Neil Jenkins
c524772a63 Merge branch 'npm' of https://github.com/shiawuen/Squire into shiawuen-npm 2015-05-09 17:29:50 +07:00
Neil Jenkins
a2ca4a3864 Allow setting default attributes for ul/ol/li/blockquote.
Merges #83, with fixes, tidying and squashing.
2015-05-09 17:22:54 +07:00
shiawuen
619a3abc5d fix module check getting undefined for Firefox 2015-05-07 23:40:49 +08:00
shiawuen
3f643b5718 export Squire 2015-05-07 10:52:52 +08:00
Neil Jenkins
c48e9b73f5 Code style/naming convention cleanups 2015-05-07 09:08:58 +07:00
crossjs
8d8798a673 add parameter for override default properties; initialize editor document now run after instance saved. 2015-05-05 20:28:30 +08:00
Neil Jenkins
73641ad899 Fix white-space and naming convention errors. 2015-05-03 13:18:00 +07:00
Misha Koryak
3da7b19404 fix isDefaultPrevented method ;) 2015-05-01 14:10:48 -04:00
Misha Koryak
ed10b03b9f make it possible to replace the reference to e.fragment in willPaste event, also add isDefaultPrevented method to that event 2015-05-01 14:07:28 -04:00
Neil Jenkins
223060ecf9 Add method to set key handlers.
Resolves #70
2015-04-29 11:16:11 +07:00
Umer Farooq
c249e3bc19 Document that if the current selection is not collapsed, that it will
be deleted and replaced by the html. Make style and consistency changes.
2015-04-15 16:23:36 +10:00
Umer Farooq
6fdb288e00 Add the ability to insert an HTML fragment at the cursor location. 2015-04-15 16:23:36 +10:00
Neil Jenkins
73ca65edb5 Fix pasting multiple lines into a blockquote.
Pasting is hard to get right in the general case, not least because the
browsers give so little control over the process, leaving you to resort to
crappy hacks. But we can special case the pasting to a blockquote case fairly
easily, and I can't see any particular regression it should cause.

Fixes #59.
2015-04-09 20:16:04 +07:00
Neil Jenkins
7db0ae059a Fix cleanup empty <a> on enter in WebKit/Blink
Need to consider zero-width space equivalent to no content.
Also cleanup empty inline nodes in general when cleaning up zero-width spaces
inside them.

Fixes #58
2015-04-08 18:02:23 +07:00
Neil Jenkins
1c0fa1a50f Rewrite getSelectedText method.
Fixes #57.

* Fixes bug where it could return text outside selection
* Inserts new line between blocks.
2015-04-08 17:13:21 +07:00
Neil Jenkins
e6ae25b589 Fix formatting commands when selection has no text nodes
Fixes #60
2015-04-08 15:33:27 +07:00
Neil Jenkins
1b9606452e Check for redundant WS when ensuring bottom line.
Fixes #55.
2015-03-29 18:56:32 +11:00
Neil Jenkins
4c63ad696e Only maintain LI numbering when splitting OL if in BLOCKQUOTE.
Fixes #53
2015-03-29 18:39:50 +11:00
Neil Jenkins
3c8eaa1fcc Use default block settings when fixCursor called on body 2015-03-29 18:36:58 +11:00
Allen Heavey
eced74244d fix typo: ndoes -> nodes 2015-03-19 14:55:45 +08:00
Neil Jenkins
1362383aea Fire "select" event whenever selected range is not collapsed
Fixes #50.
2015-03-18 18:19:15 +08:00
masonicboom
eba853a0f7 allow "audio" elements
http://www.w3.org/wiki/HTML/Elements/audio
2015-03-05 16:57:33 -08:00
Neil Jenkins
ed0ebdae49 Merge adjacent text nodes after extracting range. 2015-03-04 14:50:44 +08:00
Neil Jenkins
5865eb032a Maintain li numbering when splitting OL 2015-02-06 14:19:06 +07:00
Neil Jenkins
5b8e348232 Fix invalid caching of selection nodes in paste handler.
Fixes error thrown when pasting text twice in succession (or more generally,
when pasting it into non-normalised text nodes).
2015-02-06 14:18:38 +07:00
Neil Jenkins
dfed911833 Add .jshintrc file so JSHint checks it correctly.
Resolves #25.
2015-01-08 12:25:54 +07:00
Neil Jenkins
8e8874b554 Don't fire an input event on setHTML call. 2014-12-30 10:22:39 +07:00
Neil Jenkins
249ea93c13 Allow defaultBlockTag to be configured
Resolves #23
2014-12-27 15:02:26 +07:00
Neil Jenkins
b69a1635de Use mutation observers where possible to detect change
We need to know when the document is modified in order to fire an "input" event
and set the undo/redo state correctly. Observing keyup is imprecise, as it's
hard to tell whether the key press actually modified anything. Newer browsers
support mutation observers, which tell you precisely when something has changed.
For IE9/10, Opera 12 and other older browsers, we fall back to observing keyup
again.

Fixes #26.
2014-12-27 13:48:15 +07:00
Neil Jenkins
5b5d65f684 Record undo checkpoint before deleting any selection. 2014-12-26 20:04:42 +07:00
Neil Jenkins
797dbf46fb Fix selection lost on action in Presto 2014-12-26 20:01:36 +07:00
Neil Jenkins
54b428aaa6 Fix deleting selection across block boundary. 2014-12-26 14:48:13 +07:00
Neil Jenkins
a46dc2ef02 Take over selection deletion in more cases.
Never really want to let the browser delete a selection; it always makes a mess
of it. This now covers the case when an English letter key or number key is
pressed when a selection exists. Handling this completely (to include all keys
that produce a symbol) is tricky due to cross-browser key event compatibility
issues.
2014-12-26 14:27:19 +07:00
Neil Jenkins
4a264a52c7 Replace feature test w/ UA sniff for buggy splitText. *sigh*
The feature test is sometimes passing in IE9, but then the buggy behaviour
still appears later. FFS IE.
2014-12-26 14:26:29 +07:00
Neil Jenkins
805f3cffff Remove last remnants of IE8 support. 2014-12-26 14:24:22 +07:00
Neil Jenkins
90623a51a2 Clean up empty inlines when deleting selection.
Fixes #6
2014-12-25 15:09:46 +07:00
Neil Jenkins
5b52467815 Fix inserting line break at start of link
Before, hitting enter at the start of the link would result in the link text
being removed from an <a> on the new line, and an empty <a> tag on the previous
line. Now the link remains on the new line as expected, and no empty <a> tag is
produced.

in the preceding block.
2014-12-25 11:39:07 +07:00
Neil Jenkins
f781e07b23 Ensure space is inserted after link if cursor at end of <a> tag
If your cursor is at the end of a link, ensure pressing space always inserts
the space outside of the <a> tag.
2014-12-24 14:24:25 +07:00
Neil Jenkins
824a3b0a3b Resolves #22. 2014-12-20 17:07:11 +11:00
Neil Jenkins
25f78ff31d Fix cursor no longer appears on focus in Chrome. 2014-12-07 14:33:43 +07:00
Neil Jenkins
ae38caba31 Remove IE8 support.
It was always a bit buggy, and realistically there's no point in putting in the
time to fix it up.
2014-11-29 20:08:53 +07:00
Neil Jenkins
cb9292721c Let the browser handle shift-delete.
Apparently it's "cut" on Windows. Who knew.
2014-11-20 12:45:36 +07:00
Neil Jenkins
3296e7576e Register for events on capture rather than bubble phase.
Allows "load" events to be triggered for images in the document.
2014-11-18 12:02:36 +07:00
Neil Jenkins
73c4146e27 Fix range error in addFormat if start == end container. 2014-10-03 16:38:20 +07:00
Neil Jenkins
b944eb3b3b Fix ZWS removal when Squire script not in iframe. 2014-10-02 16:36:39 +07:00
Neil Jenkins
e7cef49818 Rename isOpera -> isPresto.
Opera now uses WebKit, but these tweaks are only for the Presto version.
2014-10-02 16:23:30 +07:00
Neil Jenkins
a408fcaca6 Fix range construction in addFormat method. 2014-10-02 16:00:35 +07:00
Neil Jenkins
6080cbf819 Add Squire#destroy method.
Unbinds all event handlers to ensure no memory leaks.
2014-10-02 12:06:17 +07:00
Neil Jenkins
d21ae23215 Record undo checkpoint before paste or delete. 2014-10-01 10:12:58 +07:00
Neil Jenkins
c0e33843fb Use helper fn to get start block in paste handler.
Neater and deals with the edge cases.
2014-09-24 16:36:14 +07:00
Neil Jenkins
597024eecb Remove FILTER_(ACCEPT|SKIP) constants.
Just return a boolean for the TreeWalker filter fn. This diverges from the spec,
but since the goal of this implementation is not to fully implement the spec
and we're never going to use a native implementation, this doesn't matter and
the code is easier to read when the function is just returning a boolean like
any normal filter function.
2014-09-04 17:24:31 +07:00
Neil Jenkins
a280cb4946 Improve detection of range at begin/end of block. 2014-09-03 11:17:14 +07:00
Neil Jenkins
4a8152d280 Remove zws in key handlers they could affect. 2014-09-03 09:21:16 +07:00
Neil Jenkins
d5e8ef1381 Preserve inline styles on enter in WebKit. 2014-08-28 08:17:07 +07:00
Neil Jenkins
da49316876 Better positioning of paste area to prevent auto-scrolling. 2014-08-06 14:42:57 +02:00
Neil Jenkins
afd3e9807c Be more careful about splitting nodes to remove <br>s.
Can't split an <li> to remove a <br>.
2014-08-05 13:44:41 +01:00
Neil Jenkins
1fac17b514 Don't strip WS between two inline nodes. 2014-08-05 10:58:22 +01:00
Neil Jenkins
3b95f7b864 Better parsing of links and emails into links.
* Be more liberal in tld, as there are now a billion new ones, of every length.
* Fix bug where if the URL contains an @ it would add it as a mailto link
  instead.
2014-07-03 14:16:20 +01:00
Neil Jenkins
bbf765bee7 Ensure there is always a selection.
Many functions rely on there being a selection; if the browser doesn't return
one, make one up (collapsed, at beginning of document).
2014-06-30 15:10:30 +01:00
Neil Jenkins
c09c5e98f7 Fix Firefox cursor disappears after calling modifyBlocks
Workaround for an old Firefox bug was causing it. Happily, that seems to no
longer be needed, so can just remove it and we're all good. :)
2014-06-26 16:13:54 +01:00
Neil Jenkins
eed472b5ef Don't change encoding of URL in Squire#makeLink.
Presume the URL is already valid, otherwise we could end up double encoding.
2014-06-06 14:00:31 +10:00
Neil Jenkins
e108c18c38 Ensure there is always a normal block at the bottom of the page. 2014-06-02 13:41:59 +10:00
Neil Jenkins
f0bd5138e1 Add support for defaultBlockProperties.
Set the defaultBlockProperties property on a squire instance to an object and
it will use these properties when it has to create a new default block element.
2014-06-02 10:22:52 +10:00
Neil Jenkins
aa9afdfaf6 Code format tidying.
* Use upper-case for all tag names.
* Tidy document reference.
2014-06-02 10:17:54 +10:00
Neil Jenkins
34d3839ceb Don't trim whitespace if inside another inline node. 2014-05-27 12:24:31 +10:00
Neil Jenkins
aca8fd4fab Better fix up of mixed inline/block content. 2014-05-27 11:31:06 +10:00
Neil Jenkins
46706db889 Wrap LI contents when merging. 2014-05-23 15:33:00 +10:00
Neil Jenkins
ca5c08e4d0 Cleanup nbsp-only text nodes. 2014-05-20 17:47:02 +10:00
Neil Jenkins
f9cb71a666 Remove Firefox's native table controls. 2014-05-20 13:55:11 +10:00
Neil Jenkins
85c458b2d2 Drop all formatting when breaking block quote.
We don't want the same formatting as the quote in the unquoted section.
2014-05-20 13:49:55 +10:00
Neil Jenkins
76b482b41f Fix off-by-one error trimming white space. 2014-04-30 15:15:54 +10:00
Neil Jenkins
996a0dd672 Trim meaningless white space from text nodes in cleanTree fn.
If a text node at the beinning of a block began with white-space, it would mean
some situations where we should be doing all the transformations for
enter/delete/backspace were being left to the browser.
2014-04-26 11:58:58 +10:00
Neil Jenkins
0d5398868f Better, simpler cleanup of zero-width space placeholders.
Fixes issue applying multiple inline formats at the same time with a collapsed
selection in WebKit. Much more robust than previous method.
2014-04-16 18:07:46 +10:00
Neil Jenkins
712104cd99 Add kb shortcuts for making lists and +/- quote level. 2014-04-07 14:44:44 +10:00
Neil Jenkins
6b754d423c Add support mult-level lists.
* Hit tab to increase list depth, or call increaseListLevel method.
* Hit enter on a blank item to decrease list depth, or call decreaseListLevel method.
2014-04-07 13:05:44 +10:00
Neil Jenkins
bee49bef40 Use <S> to markup strike through, not <STRIKE>.
The <strike> tab has been obsoleted in HTML5.
2014-02-03 18:20:03 +11:00
Neil Jenkins
a875d20f12 Rewrite <s> to <strike> in cleanTree fn. 2014-02-03 17:58:11 +11:00
Neil Jenkins
db82ba1217 Fixup colour attribute in <font> tags.
In the markup cleanup function, extract the "color" attribute from font tags
as well as the size and font-face.
2014-01-28 17:37:31 +11:00
Neil Jenkins
88ced455f9 Add subscript/superscript/strikethrough helper methods.
* And keyboard shortcuts. (Ctrl-Shift-5/6/7 respectively).
2014-01-13 14:32:24 +11:00
Neil Jenkins
08cc8172a8 Stop treating a non-breaking space as white-space.
Its effect is that of a normal character in HTML, that just happens to render
as a space.
2013-11-04 18:21:57 +11:00
Neil Jenkins
0b3df54b6e IE11 Compatibility 2013-10-08 16:44:08 +11:00
Neil Jenkins
5d30a85aa8 Fix broken this reference in afterCut handler. 2013-07-18 15:49:21 +10:00
Neil Jenkins
f918a0106b Fix method call names in _onCut handler. 2013-07-17 17:13:04 +10:00
Neil Jenkins
731a1da910 Fix wrong method name & invalid this. 2013-07-17 16:13:29 +10:00
Neil Jenkins
02a647c574 Fix reference to old range method.
Now a function instead.
2013-07-17 11:35:34 +10:00
Neil Jenkins
d2e9d2214b Fix broken references to this.
The clean functions used a `this` reference to call createElement, but are
called as functions not methods so `this` is undefined. Instead, we'll get the
ownerDocument off the nodes passed in, then call the createElement function
directly.
2013-07-17 11:13:49 +10:00
Neil Jenkins
fefa32b744 Fix reference to setPlaceholderTextNode
This is now an instance method, whereas before it was global. Annoyingly, we
need to access this from from within fixCursor which has no reference to the
RTE instance itself (and it would be a pain to pass one down). For now, just
referring to the global `editor` variable if it exists (i.e. if the script
loaded in an iframe). Need a better solution longer term though.
2013-07-16 20:36:24 +10:00
Neil Jenkins
6b4dda816e Make into a JS class for multiple instantiation.
* If you load the squire.js script into a top-level page rather than an iframe,
  it will add a Squire constructor to the global scope.
* The Squire constructor can be used to instantiate multiple instances on the
  same page without having to load/parse/execute the full code every time.
* For each instance, create a new iframe, then call `new Squire( document )`,
  with the document node for each iframe.
2013-06-20 23:15:18 +10:00
Neil Jenkins
7812b8db23 Turn Range prototype extensions into functions.
A step towards being able to share code between multiple concurrent instances of
the editor. Also reduces minified size slightly.
2013-06-20 21:03:01 +10:00
Neil Jenkins
dbda1fa4ed On paste, ignore image if text/html present.
If you copy a portion of text from word, it includes an image version of the text as well as an HTML version. On paste, we now ignore the image
representation on the clipboard if an HTML representation is present, so that
the text pastes as expected, rather than as an image.
2013-06-03 15:34:51 +10:00
Neil Jenkins
946afc9a17 Support add/removing listeners whilst firing event
If you removed an event listener whilst it was being fired, this would alter the
list of handlers, which would cause the fireEvent function to read past the end
of the array (and to skip the next listener). Now, we clone the array of
listeners before firing, so adding/removing listeners has no effect on an
already firing event.
2013-05-24 14:02:12 +10:00
Neil Jenkins
87c0f3fbe1 Fix Cmd-left/right bug in Firefox on Mac OS X.
Firefox incorrectly goes back/forward in history instead of moving the cursor to
the beginning/end of the line when you press cmd-left/right on a mac. We now
override this to do the right thing.
2013-05-20 16:14:28 +10:00
Neil Jenkins
03818bd3e8 Log error if addEventListener called with null fn 2013-05-20 11:43:08 +10:00
Neil Jenkins
1fbc166226 Ignore IMGs when stripping empty inlines.
When cleaning up pasted content, we remove any empty inline tags. However, we
should not be stripping <img> tags (which are of course both inline and empty).
2013-05-17 17:24:00 +10:00
Neil Jenkins
4c5b157d09 Fix KB bold/italic etc. shortcuts in Webkit.
Webkit needs a special placeholder text node as it can't focus empty text nodes.
This was being cleaned up too early, before the user had a chance to enter any
text.
2013-04-18 13:59:08 +02:00
Neil Jenkins
20f92c9785 Always return nodeAfterSplit from split fn 2013-04-10 13:43:31 +10:00
Neil Jenkins
77b0b6c716 Check for null start block in backspace handler. 2013-04-10 11:08:40 +10:00
Neil Jenkins
dd7034501f Return same node passed in to fixCursor function. 2013-04-10 10:47:42 +10:00
Neil Jenkins
e1bae30a16 Make editor.insertElement support block elements. 2013-04-08 13:48:06 +10:00
Neil Jenkins
af1720282c Replace Node prototype extensions with normal fns.
* Firefox was sometimes not finding the extensions on elements.
* This minifies to a smaller target.
2013-04-08 13:27:06 +10:00
Neil Jenkins
10abc3faf8 Check for null return from Range#getStartBlock. 2013-04-05 15:58:34 +11:00
Neil Jenkins
02d25f0ef5 Catch and log FF error getting selection. 2013-03-27 16:04:57 +11:00
Neil Jenkins
768f4420b9 Correctly check if <br> makes a line break.
The previous test was incorrect. A <br> actually introduces a line break if
there is any non-whitespace after it in the block or if there is another <br>
after it in the block. It is irrelevant what comes before it in the block.
2013-03-08 17:14:11 +11:00
Neil Jenkins
a12f6905a5 Always call setSelection after bookmarking.
IE and Safari 5 loses the selection during the bookmarking process, so we must
always explicitly reset the selection after recording an undo state (which adds
a bookmark).
2013-03-08 13:25:56 +11:00
Neil Jenkins
6927928a79 If can't split block, wrap inlines instead.
When cleaning up <br>s, if it's inside a block we can't split, it's probably a
containing node (like a <blockquote>), so we should wrap the top level inlines
instead.
2013-03-07 18:12:18 +11:00
Neil Jenkins
a340115a87 Preserve background colour on paste. 2013-03-07 16:25:20 +11:00
Neil Jenkins
7d760ce635 Don't strip styles added by tag rewriters.
* Should preserve font styles on paste.
2013-03-07 13:52:38 +11:00
Neil Jenkins
5b52e9b4b8 FF: Selection range may not have startContainer.
* Odd bug this. From the logs, it seems either it's returning a range with no
  startContainer, or the startContainer is not something inheriting from the
  Node prototype (which would be very wrong).
2013-02-27 10:49:08 +11:00
Neil Jenkins
a069e8305e Add accurate check for whether <br> breaks line.
When cleaning up <br> elements, we need to accurately determine whether there's
text before and after it in the block to know whether it will introduce a
visible line break.
2013-02-26 10:19:00 +11:00
Neil Jenkins
327b48b9db Save undo step on delete.
* But only if it's deleting whitespace or destroying a block or deleting a
  selection. This makes it undo deletion word-by-word rather than
  character-by-character.
2013-02-25 13:52:22 +11:00
Neil Jenkins
e3ad6c6b18 Fix allowed block regexp.
* Was not correctly matching full string only.
2013-02-25 11:05:26 +11:00
Neil Jenkins
0ba91e627d Rewrite all <br>s in cleanupBRs fn.
Previously, we were just removing <br>s that didn't have siblings on both sides. A better test is whether the containing block has any non-whitespace text content. If it does, the <br> is a line break and we can just split the block. If it doesn't though, we need to leave the <br> as a placeholder, to ensure the block doesn't collapse to 0 height.
2013-02-25 10:39:27 +11:00
Neil Jenkins
ac14985583 Remove empty inline nodes on paste. 2013-02-22 15:06:56 +11:00
Neil Jenkins
7162777a0f Only remove whitespace nodes if between blocks.
* When cleaning the tree we want to remove useless whitespace between block
  nodes, but we were being a bit too aggressive and removing all whitespace
  nodes. Now checks the context first.
2013-02-21 11:37:20 +11:00
Neil Jenkins
0bb3c142eb Rewrite <font> tags when cleaning tree.
* Converts to <span>.
2013-02-21 11:35:23 +11:00
Neil Jenkins
b35b7d4b35 Fix bug in Range#insertTreeFragment
Merging containers could remove the nodeAfterSplit from the tree, which then
caused an error to be thrown if it had no content, as the code would try to
remove it again.
2013-01-30 11:30:11 +11:00
Neil Jenkins
775b72ec88 Make Element#getPath more robust.
Won't throw an error if called on a node that is not part of a document, but
will now instead return the path from whatever the root element is down to the
node.
2013-01-30 11:28:36 +11:00
Neil Jenkins
52e517b376 Catch all errors to allow logging.
* All errors will be caught and passed to the editor.didError fn. This can be
  overridden to do something useful, like logging them to the server.
2013-01-24 11:54:44 +11:00
Neil Jenkins
45711a38a4 Markup links on 'enter' too.
* Check for links in the current text node, and add <a> tags if found, when the
  enter key is pressed, not just when the spacebar is pressed.
2013-01-24 11:51:51 +11:00
Neil Jenkins
f49d1c190e Automatically markup <a> links on spacebar press.
* When spacebar is pressed, any URL-like text in the current text node will be
  wrapped in an <a> tag with the URL as the href.
2013-01-15 10:34:37 +11:00
Neil Jenkins
8b2090c94e Add <a> for ftp:// links on paste. 2013-01-15 10:34:03 +11:00
Neil Jenkins
bce3e8d208 Ensure IE not in compat-mode on demo page. 2013-01-15 10:32:21 +11:00
Neil Jenkins
8ccc9fad06 Add argument to getHTML to include bookmark.
* Selection is then automatically restored when HTML containing a bookmark is
  set.
2012-11-21 12:35:50 +11:00
Neil Jenkins
fe6ffb0ed5 Add IE10 compatibility.
* All UA detection moved into a separate file.
2012-11-12 18:30:40 +11:00
Neil Jenkins
1d83790a57 Fix Webkit scrolls to top on paste bug. 2012-11-12 11:51:46 +11:00
Neil Jenkins
99c26861c1 Force IE to not be in compatibility mode. 2012-11-05 10:00:21 +11:00
Neil Jenkins
388740c7f8 Fix bug in cut in Safari
* Safari 6 modifies the selection when bookmarking it. Ensure it is restored
  before the cut takes place.
2012-11-01 18:14:10 +11:00
Neil Jenkins
92645f1c0f Add extra check to loop. 2012-08-22 13:14:08 +02:00
Neil Jenkins
691058e071 Fix blur() function loses IE browser window focus. 2012-08-09 16:08:21 +10:00
Neil Jenkins
f9974ed7d9 Fix IE returns null for getSelection if never focussed. 2012-08-09 15:08:04 +10:00
Neil Jenkins
52a10d463c Tidy. Make backspace/delete aware of non-editable blocks 2012-08-08 16:20:28 +10:00
Neil Jenkins
f2090b05d0 Tidy. Ensure trailing new line in all source files 2012-08-07 13:36:05 +10:00
Neil Jenkins
50b7ad1e4e Treat pasted image as a drag-dropped image file. 2012-08-07 12:20:55 +10:00
Neil Jenkins
a9a0ac6411 Fix bug where image may be duplicated on enter.
* Do not move range boundaries inside images; these should always be treated as
  leaf nodes.
* Workaround FF bug where it may return range as being inside of image node.
2012-08-01 11:53:37 +10:00
Neil Jenkins
0412ece8ec Fix blur method.
Have to blur the body, not the window.
2012-07-25 17:35:03 +10:00
Neil Jenkins
b87a9c26fe Add setTextDirection method.
Allows setting RTL or LTR text direction on a block level basis.
2012-07-24 15:59:36 +10:00
Neil Jenkins
630a7c4e4f Tidy IE8 range code. 2012-07-24 15:54:05 +10:00
Neil Jenkins
c964a6a564 Fix bug in removing empty inlines on delete. 2012-07-02 16:44:10 +10:00
Neil Jenkins
e4b5ea6ee8 If all text in inline tag deleted, remove tag. 2012-07-02 14:04:06 +10:00
Neil Jenkins
819ddb296e Always restore range to textnodes.
When restoring a range from a bookmark, always call range.moveBoundariesDownTree
to anchor it to the nearest text node. If you call setSelection with a range not
anchored inside a textnode, Opera may incorrectly set the selection.
2012-06-19 14:43:10 +10:00
Neil Jenkins
ffd6edbaef Remove redundant -ms-box-sizing CSS.
Prefix was only used in IE8 betas. No need to keep it.
2012-04-27 17:52:10 +10:00
Neil Jenkins
c5abcde210 API rename (inc|dec)reaseQuoteLevel
Use full words in API method name for consistency with the rest of the API.
2012-04-12 11:42:07 +10:00
Neil Jenkins
98ebe661b2 Allow custom cleaning on paste.
A willPaste event is now fired just before pasted content is inserted into the
document, allowing custom, arbitrary modification of the pasted content, or
prevention of the paste event altogether.
2012-04-12 11:38:22 +10:00
Neil Jenkins
b6c659e295 Remove unused variables. 2012-04-12 09:22:58 +10:00
Neil Jenkins
bf8598e060 Fix zero-width space character bug.
If the node containing the zero-width space character was merged by a call to
Range#mergeInlines, the character was not being removed, making for odd cursor
movement.
2012-04-10 15:42:47 +10:00
Neil Jenkins
63a97d9b99 Fix IE8 grabs focus on load of editor. 2012-04-04 17:01:28 +10:00
Neil Jenkins
c595fb0bb8 Fix cursor location after Range::_deleteContents
Should always collapse to start.
2012-04-04 15:11:27 +10:00
Neil Jenkins
5c9420c7fa Fix bug in updating path correctly. 2012-04-03 20:35:07 +10:00
Neil Jenkins
9b5512bf98 Tidy up a few bits of code. 2012-04-02 17:38:19 +10:00
Neil Jenkins
543abca022 Workaround WebKit/IE can't focus empty text nodes. 2012-04-02 17:38:01 +10:00
Neil Jenkins
6480739143 Update copyright year. 2012-04-02 15:55:33 +10:00
Neil Jenkins
89eb88ce15 Fix repeating keys don't fire handlers.
Holding down a key will trigger it repeatedly; we need to capture all of these
events to override backspace/enter etc.
2012-04-02 15:55:33 +10:00
Neil Jenkins
f0ba6216cc Add support for IE8. 2012-04-02 15:55:33 +10:00
Neil Jenkins
746e86a3a8 Tidy document.html 2012-03-29 17:55:15 +11:00
Neil Jenkins
cfb08691c2 Don't focus body in non-Gecko.
Opera loses selection. Only Gecko seems to need it.
2012-03-29 17:55:15 +11:00
Neil Jenkins
70078355b7 Whitespace fix. 2012-03-08 15:19:43 +11:00
Neil Jenkins
f8273e7d15 Make email addresses into links on paste. 2012-03-08 15:13:32 +11:00
Neil Jenkins
64b8f9affa Fix focus method not working in Firefox. 2012-02-08 23:23:55 +11:00
Neil Jenkins
e3ee4dad12 Whitespace cleanup. 2012-01-25 11:47:26 +11:00
Neil Jenkins
78e8955be1 Work around iOS bug when setting selection. 2012-01-25 11:37:38 +11:00
Neil Jenkins
d413b1bb85 Automatically wrap URLs in <a> when pasting text. 2012-01-25 11:36:51 +11:00
Neil Jenkins
aa8527fc2c Fix bug in removing format. 2011-12-09 14:27:37 +11:00
Neil Jenkins
ceed1cfa81 Don't continue link over block break. 2011-12-09 13:53:09 +11:00
Neil Jenkins
cfe9bea8b3 Opera collapses blocks with just spaces for data 2011-12-09 13:30:58 +11:00
Neil Jenkins
14ee0d0ad5 Scroll cursor into view on enter. 2011-12-09 13:15:15 +11:00
Neil Jenkins
43634a3ba4 Add styles via separate API method.
<style></style> must not be included text supplied to setHTML call.
2011-11-17 18:37:49 +11:00
Neil Jenkins
a8e6e5b391 Merge adjacent containers on delete/backspace.
If you delete the line separating two containers (e.g. a blockquote), the
containers are merged.
2011-11-17 18:36:58 +11:00
Neil Jenkins
f4c5a85379 Don't prevent tabbing out of area. 2011-11-17 18:36:29 +11:00
Neil Jenkins
17cb1e0043 Guard against IE firing beforepaste twice 2011-11-17 18:36:07 +11:00
Neil Jenkins
3ca646a1d1 Make enter break through all levels of blockquoting 2011-11-17 18:33:24 +11:00
Neil Jenkins
09308b729b Fix bug in hasFormat
Must see at least one text node with format to return true.
2011-11-17 18:32:11 +11:00
Neil Jenkins
f1a714a179 <br>s should be added to every block in Webkit/Gecko 2011-11-16 19:24:43 +11:00
Neil Jenkins
3068c496c9 Allow contents of unknown tags in.
Clean functions were removing contents of any unknown tag. This was, it turned
out, a bit too strict.
2011-11-15 21:46:47 +11:00
Neil Jenkins
143eea15cb Fix cursor when deleting range contents 2011-11-15 21:46:11 +11:00
Neil Jenkins
feca3e4d8f Make forEachBlock method public.
And tidy a few bits and pieces.
2011-11-14 17:55:40 +11:00
Neil Jenkins
3f5233c61a Fix bug in applying styles in Opera/IE.
Was removing the crucial empty text node that these browsers use to indicate and
editable line.
2011-11-14 15:18:05 +11:00
Neil Jenkins
d24aba73ad Stop using DOM mutation events to detect changes.
Unreliable in some browsers, and may be deprecated in the future.
2011-11-10 18:44:00 +11:00
Neil Jenkins
a2ef14e218 Add make/remove link sugar.
Also:
Add getSelectedText method.
Fix bug in setting HTML after undo/redo in Opera.
2011-11-10 18:31:07 +11:00
Neil Jenkins
d01cc9875f Add commands for setting text/background colour. 2011-11-09 15:41:46 +11:00
Neil Jenkins
b3d9de6e86 Fix infinite loop bug in key down.
Also fix font changes removing all spans.
And fix firing of path change events to occur at the right times.
2011-11-08 16:43:46 +11:00
Neil Jenkins
aa8b4b7ac6 Fix setTextAlignment command
And make propagating native events more elegant (only adds observer to document
when first function added).
2011-11-08 13:59:47 +11:00
Neil Jenkins
75109c404e IE requires handlers on before(cut|paste) events. 2011-11-04 17:53:24 +11:00
Neil Jenkins
3b09cbf703 Improve cleaning of inserted content. 2011-11-04 16:53:12 +11:00
Neil Jenkins
f15a57cba6 Standardise white space in public getHTML method.
Add in <br>s where required in Opera and IE.
2011-11-03 17:37:32 +11:00
Neil Jenkins
28c9ab10a9 Fix FF deleting everything on cut. 2011-11-03 17:05:18 +11:00
Neil Jenkins
0bdbef305a Use <b>, <i> instead of semantic elements
As the W3C spec says, only use <strong>, <em> if you're sure of the intended
semantics.
2011-11-03 14:18:00 +11:00
Neil Jenkins
c83688b630 TreeWalker must not try to access parent of root node 2011-11-03 12:45:41 +11:00
Neil Jenkins
183091e4e1 Bias towards adding, not removing format.
editor.hasFormat(...) now only returns true if all text in the range has that
format.
2011-11-03 12:44:54 +11:00
Neil Jenkins
0f750d2a0e Fix Range#get(Start|End)Block.
Was still returning the wrong result in certain situations (for example when the
start boundary was just before the end of a block).
2011-11-03 12:10:16 +11:00
Neil Jenkins
1792b66ac3 Normalise text nodes when setting initial HTML. 2011-11-03 12:09:39 +11:00
Neil Jenkins
e8a917f321 Fix Range#containsNode.
Not sufficient for node to be adjacent to range; must actually contain range.
2011-11-02 19:12:31 +11:00
Neil Jenkins
953ee3bfc7 Fix bug in FF on enter. 2011-11-02 18:46:45 +11:00
Neil Jenkins
a91df2db4c Ensure range is valid after Range#_deleteContents. 2011-11-02 18:46:18 +11:00
Neil Jenkins
ae09554883 Don't try to merge <br>s or <img>s etc. 2011-11-02 16:43:42 +11:00
Neil Jenkins
9dcbf45f4a Fix Range#get(Start|End)Block. 2011-11-02 16:31:46 +11:00
Neil Jenkins
f89490736e Replace buggy TreeWalker implementations. 2011-11-02 14:02:18 +11:00
Neil Jenkins
7b000293d6 Fix bug in text cursor fixing in IE/Opera. 2011-11-02 11:55:08 +11:00
Neil Jenkins
1d5b841860 Fix bug in deleting all. 2011-11-02 11:54:58 +11:00
Neil Jenkins
110568350b Bookmarking must not uncollapse a range. 2011-11-02 10:45:33 +11:00
Neil Jenkins
0d706180fe Refactor cleaning code and merge blockquotes 2011-10-31 15:16:08 +11:00
Neil Jenkins
f245cc0dba Fix Range#get(Start|End)Block methods. 2011-10-31 13:08:51 +11:00
Neil Jenkins
b8e2b5fb81 Normalise <br>/<#text> on setHTML and paste
Make sure all the block level elements have either a <br> or an empty text node
in the right place, as required by the browser.
2011-10-31 13:07:41 +11:00
Neil Jenkins
72141fd670 Initial commit for public release. 2011-10-29 14:15:21 +11:00