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
c656be7e65 Fix copying plain text in Firefox
Resolves #244
2016-11-02 15:32:06 +11:00
Neil Jenkins
e517f1505b Fix converting OL <-> UL 2016-10-19 14:45:17 +11:00
selvan
23375d4422 Preserve 'bold' font style while copy & pasting from Google Docs. Google docs uses numeric value 700 as font-weight for bold instead of string value 'bold' 2016-09-29 11:37:25 +05:30
selvan
68618b1e5d Preserve cell width while copy & pasting from Goolgle Sheet - added COLGROUP and COL as part of 'allowedBlock' regex 2016-09-29 11:36:14 +05:30
Neil Jenkins
5f8bd2d935 Treat nbsp as content when cleaning DOM tree.
Fixes #240.
2016-09-28 12:02:29 +10:00
Neil Jenkins
0fa4a9b587 Replace block node when creating list
So you get:

<li>Text</li>

instead of

<li><p>Text</p></li>
2016-09-27 06:06:42 +04:00
Islam Sharabash
6a9582c7e7 Allowing arbitrary nesting for bullets
This allows any level of indentation for bullets. It does this by introducing
invalid HTML. In particular, you can make bullets like:

<ul>
  <ul>
    <li>foo</li>
  </ul>
</ul>
2016-09-27 05:50:59 +04:00
Neil Jenkins
4f83b0a8bc Treat inline tags as containers in malformed HTML
Fixes #239.
2016-09-26 11:37:38 +01:00
Neil Jenkins
d8239d2570 Skip placeholder BRs when moving range up/down tree 2016-09-25 21:43:47 +01:00
Neil Jenkins
78b638f79b Ensure root node is never returned by get(Start|End)BlockOfRange
Fixes #237
2016-09-22 09:44:03 +01:00
Neil Jenkins
e1d30b7082 Fix error when copying inline text-only. 2016-09-10 09:24:14 -04:00
Neil Jenkins
26b71dee8e Fix copying inline styles when selection not on boundary.
Resolves #219 properly this time.
2016-09-09 12:14:57 -04:00
Neil Jenkins
9aacad6e3c Make Shift-Ctrl-V paste as plain text.
Fixes #230.
2016-09-04 20:58:49 -04:00
Neil Jenkins
cbde7a9198 Always preserve inline formatting on copy
Fixes #219.
2016-09-04 20:44:36 -04:00
Neil Jenkins
25ff83455e Exports some useful internal functions
This is a rebase/slight tidy of #226.
2016-08-23 20:59:38 +10:00
Islam Sharabash
ead3ea9f39 Fix bug where TIME element was not being counted as inline
This makes inline node detection count the TIME element as an inline element.
This was causing <br> to be inserted into a TIME element incorrectly via fixCursor.
2016-08-22 13:16:05 -07:00
Neil Jenkins
aae328e226 Ensure valid DOM tree is added to clipboard on copy
Fixes #204.
2016-08-10 16:24:13 +10:00
Neil Jenkins
aaaae70504 Tidy code. 2016-08-05 20:49:44 +10:00
Andy Kauffman
6e1b864663 Remove Unneeded ZWS
ZWS are added when formats are added, however these are not cleaned up
if the format is changed. Now they will be cleaned up if they only
contain ZWS and no text.
2016-08-05 20:48:24 +10:00
Neil Jenkins
1a797aca48 Merge pull request #218 from nhnent/leafNodeNames-are-configurable
leafNodeNames are configurable
2016-08-05 20:37:12 +10:00
Sungho Kim
b83d071666 leafNodeNames are configurable 2016-07-27 16:59:15 +09:00
Sungho Kim
c3d4d551ed Fix MSIE detection regex 2016-07-27 16:33:06 +09:00
Sungho Kim
96b03d4aaf Fire focus or blur event manually in focus/blur method for MSIE because
MSIE invoke focus/blur event listener asynchronously
2016-07-27 16:15:42 +09:00
Neil Jenkins
df9b5add68 Explicit attributes should override defaults
Fixes #203
2016-07-16 16:51:24 +10:00
Neil Jenkins
766dea7ccf Merge inlines when inserting node into range 2016-07-14 12:15:06 +10:00
Neil Jenkins
13241028f1 Workaround Android hiding the keyboard on cut. 2016-07-14 11:32:38 +10:00
Neil Jenkins
d4abc182c8 If selection, delete contents before letting brower insert space
Fixes #213
2016-07-14 11:31:11 +10:00
Neil Jenkins
aaf84870aa Ensure focus after paste 2016-07-14 10:39:20 +10:00
Neil Jenkins
6ef4ad96e8 Fix whitespace 2016-07-07 16:11:45 +10:00
Andy Kauffman
964070ee46 Path contains format values
Add values of font size, font face, and color to the path. This allows
us to distinguish path changes to different formats.
2016-07-07 16:11:45 +10:00
Neil Jenkins
db09921d7b Fix multiple firing of updatePathOnEvent 2016-06-27 13:17:18 +10:00
Neil Jenkins
267085e8c1 Don't disable restore selection on input
The only time we don't want to restore selection is if the user explicitly
changes it, by clicking/touching a specific cursor point.

Fixes formatting commands in IE11, where the mutation event first between
calling editor.focus() and the focus event actually firing, rather than
after the focus event as in other browsers.
2016-06-27 12:05:40 +10:00
Neil Jenkins
f060dbf978 Restore selection of focus after call to setHTML. 2016-06-16 14:45:19 +10:00
Neil Jenkins
f593d8ac04 Enforce sane focus/blur events.
Because focus/blur events are fired synchonously, browsers can get confused if
UI code starts focusing other elements while inside a focus/blur handler, and
end up firing events in the wrong order which can cause infinite loops.

This change ensures we only get a focus/blur event when they really are
happening, and you always get one then the other.
2016-06-10 11:02:24 +10:00
Neil Jenkins
84ae8a05f5 Interpret null value for set font/size/colour methods correctly.
Removes any current formatting of the given type.
2016-06-08 15:38:13 +10:00
Neil Jenkins
048a7296b2 changeFormat should always return self. 2016-06-07 16:27:04 +10:00
Andy Kauffman
8eea926e2b Limit the undo stack size
Add an undo configuration.
If the document is larger than the configured threshold, then limit the
number of undo states that can be saved to the configured amount.
Defaults to no limit.

Merged for #200
2016-06-06 18:50:11 +10:00
Neil Jenkins
bd4d377cf0 Sanitise pasted HTML if DOMPurify library present.
This protects against malicious HTML being added to the clipboard, and also
removes unwanted content before insertion.

DOMPurify can be found at https://github.com/cure53/DOMPurify
2016-06-06 12:36:08 +10:00
Andy Kauffman
9dcc4fb79f Cleanup P and Underline tags
node.
2016-05-26 14:16:15 +10:00
Neil Jenkins
8b580ed988 Add undo checkpoint on drop.
Resolves #188.
2016-05-26 13:54:26 +10:00
Neil Jenkins
6deae3c188 Strip HTML surrounding copied fragment added by Edge.
Fixes #181
2016-05-26 13:09:49 +10:00
Neil Jenkins
7ecf75f246 Fix determining if at start of block when at end of doc
Fixes #190
2016-05-26 11:42:53 +10:00
Neil Jenkins
d225f384b7 Use selectionchange event if available.
Fixes #194.
2016-05-26 11:07:11 +10:00
Neil Jenkins
4354b46db9 Don't merge <a> tags.
Fixes #198
2016-05-26 10:33:18 +10:00
Neil Jenkins
aa3857ab77 Use default block config when inserting plain text 2016-05-25 12:41:57 +10:00
Andy Kauffman
4e7e290fbc Fix block boundary issue
If the node is at the end of the document, this method can fail with
'TypeError: Cannot read property 'previousSibling' of null'
2016-05-19 10:28:46 +10:00
Neil Jenkins
f7774c8cf3 Always save selection on blur.
Hopefully fixes #194
2016-05-18 18:07:55 +10:00
Neil Jenkins
1f4baefda4 Remove dragover/drop from custom events list.
Fixes #183
2016-05-05 12:22:56 +10:00
Neil Jenkins
6c4f8e1aaf Add support for default <a> attributes
Resolves #186.
2016-05-05 11:50:36 +10:00
Andy Kauffman
f50962db7f Add a modifyDocument method
There are certain times when it is necessary to modify the document
programmatically, such as to set attributes, add tooltips, etc. Such
edits should not be observed as inputs. This method allows edits to be
ignored by the editor.
2016-05-05 11:30:27 +10:00
Andy Kauffman
64ee5db293 insertElement should register as input for older browsers 2016-05-02 13:47:39 -04:00
Neil Jenkins
0f361d69c6 Add IFRAME to list of inline nodes.
Resolves #180.
2016-05-01 16:36:43 +10:00
Neil Jenkins
6a28aafd2f Add HR as a leaf node name. 2016-05-01 16:33:47 +10:00
Neil Jenkins
e3d0576a38 Workaround Facebook iOS URL copying bug 2016-04-11 16:58:13 +10:00
Neil Jenkins
44a2b5c7a8 Add guard for null nodes in insertTreeFragmentIntoRange 2016-04-08 17:42:47 +10:00
Neil Jenkins
66c0b20702 Squire: Fix possible error when deleting range 2016-04-07 13:08:45 +10:00
Neil Jenkins
d9122222b2 Restore range more accurately from bookmark 2016-03-30 16:39:04 +11:00
Neil Jenkins
ed44d72ca7 Add dragover and drop to custom events list
Since these are fired by the clipboard handler.
2016-03-30 13:23:47 +11:00
Neil Jenkins
5b4aa6b764 Add getRoot method 2016-03-30 10:42:41 +11:00
Neil Jenkins
230520645b Fix cleanup of white space 2016-03-28 10:14:55 +11:00
Neil Jenkins
bac7c5d2cc Restore selection on focus, unless explicit click 2016-03-28 09:58:50 +11:00
Neil Jenkins
3ff9a46ea9 Check for null parent in getPath 2016-03-26 11:32:59 +11:00
Neil Jenkins
923a0efd1a Fix delete/backspace removing content outside editor 2016-03-26 11:20:28 +11:00
Neil Jenkins
3dca852630 Log errors from fixCursor to track down bug 2016-03-24 22:04:42 +11:00
Neil Jenkins
4ca3b20b8a Handle old browsers w/o range.getBoundingClientRect 2016-03-24 21:25:14 +11:00
Neil Jenkins
072a2d9fce Add getCursorPosition method, remove scrollRangeIntoView
Scrolling depends so much on the integration. Better to allow the cursor
position to be fetched, and then the integration can do the scrolling when it
wants (for example on each "input" event).
2016-03-24 13:48:09 +11:00
Neil Jenkins
3be9a7dea8 Workaround iOS clipboardData bug 2016-03-24 09:44:35 +11:00
Neil Jenkins
6a348e084b Make Squire work without an iframe(!) 2016-03-23 17:41:09 +11:00
Neil Jenkins
e133f26db1 Fix getFontInfo iteration up tree 2016-03-18 18:55:21 +11:00
Neil Jenkins
349f391075 Fix typo in cut/copy handlers 2016-03-14 15:21:48 +11:00
Neil Jenkins
c895d6b307 Set a plain text version too on cut/copy 2016-03-12 17:18:21 +11:00
Neil Jenkins
62616ef4ec Add saveUndoState method to public API
For #174
2016-03-11 15:58:32 +11:00
Neil Jenkins
6413034884 Improve copy/paste
* In browsers that support it, we now tell it to copy exactly what was selected
  in the DOM, and not to add extra gunk which browsers do to preserve exact
  styling if pasted into another document.
* Don't use the clipboard APIs with MS Edge, since it only supports plain text.
  If we let it fallback to the browser implementation it will insert HTML.
2016-03-11 15:22:49 +11:00
Neil Jenkins
6ed3b93900 Workaround Firefox clipboard ignores RTF data 2016-03-07 18:38:07 +11:00
Neil Jenkins
9b88aca813 Fix crash in scrollRangeIntoView if no bounding rect 2016-03-07 17:19:51 +11:00
Neil Jenkins
6bafa1d140 Run fixContainers before merging blocks.
In case paste or something has got the document into a weird state with inline
content not inside a block.
2016-02-26 14:28:53 +11:00
Neil Jenkins
2fccc317ad Fix getFontInfo method.
Resolves #169
2016-02-03 15:35:13 +11:00
Neil Jenkins
7330324d92 Fix Firefox throws error if initialised with display:none
Fixes #168.
2016-01-06 14:38:53 +11:00
Neil Jenkins
93f7867214 Fix Meta-Left/Right handling in Firefox.
Fixes #167.
2015-12-29 11:15:01 +11:00
Neil Jenkins
8b183c6ef6 Add scrollPointIntoView event for integrations. 2015-12-09 17:29:47 +11:00
Neil Jenkins
9ccf765ba8 Scroll cursor into view after setting selection.
Fixes #162 and fixes #165.
2015-12-09 15:12:47 +11:00
Neil Jenkins
df25d6d596 Add colour/background-colour to result of getFontInfo
Resolves #158
2015-12-03 18:14:49 +11:00
Neil Jenkins
0d1f1cf44b Consistently don't use a space in CSS when setting colour.
Fixes #159.
2015-12-03 17:55:22 +11:00
priceld
abfebbab16 change the walker's currentNode to reflect the changes being made to the tree 2015-12-01 10:53:30 -05:00
Neil Jenkins
987f3afd52 Fix escaping first/last line plain text on insertion.
Fixes #157.
2015-11-20 13:55:57 +11:00
Neil Jenkins
bf8f796ea4 Add shift-tab keyboard shortcut.
If at beginning of list item, shift-tab decreases indent (to mirror tab to indent).
2015-11-17 16:50:55 +11:00
Neil Jenkins
162ec9049e Make scroll on enter logic independent of CSS.
Fixes #149.
2015-10-23 17:05:32 +01:00
Trey Cordova
85c9002ce5 Add tab nesting capability to list items with text in them;
- This requires your cursor to be at the beginning of the list item.
- This implementation mimics Google Docs.
2015-10-23 14:22:04 +02:00
Neil Jenkins
8d178e1a65 Merge pull request #141 from gertsonderby/test/hasFormat
Added test suite that checks a number of cases for hasFormat().
2015-10-13 09:10:13 +02:00
Gert Sønderby
c40f900b7d Fixed copypasta-mistake, nextSibling -> previousSibling. 2015-10-13 08:46:44 +02:00
Ray Brooks
08e85c912b [Issue-147] Fix Firefox hidden iframe win.getSelection() bug
[Issue-147] Fixed code convention errors
2015-10-12 21:52:10 +01:00
Gert K. Sønderby
49ca521704 Fix up ranges in weird cases generated by IE (both start and end to be safe). 2015-10-02 15:26:30 +02:00
Neil Jenkins
9461368a5c Fix whitespace errors.
Thanks to @gertsonderby who pointed these out in #138.
2015-09-28 15:48:23 +02:00
Neil Jenkins
0ec3c43791 Don't prevent default on tab unless doing something.
Fixes #131.
2015-09-04 18:33:11 +01:00
Gert K. Sønderby
94f5a56255 Added getFontInfo() function, which extracts font-family and font-size styles. 2015-09-03 11:48:47 +01:00
xfra35
702991c2c6 Allow FIGCAPTION block tags 2015-08-31 16:41:29 +02:00
Neil Jenkins
02df8f9ed4 Merge pull request #127 from gertsonderby/remove-all-cleans-inputs 2015-08-27 11:16:20 +01:00
Gert K. Sønderby
8238b7a8e4 Removing all formatting also removes INPUT elements. 2015-08-26 15:42:01 +02:00
Gert K. Sønderby
5a46d51671 Lone IMG tags in a range will be accepted by _addFormat, so that they can be made into links. 2015-08-26 15:07:58 +02:00
Neil Jenkins
900e43cca8 Fix prefix white-space trimmed on paste of plain text. 2015-07-25 18:11:56 -07:00
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