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

231 commits

Author SHA1 Message Date
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
b6473508a2 Set build as default Make target. 2013-01-30 11:11:49 +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
f08fe04bb2 Update Makefile to use uglifyjs2.
* Takes different options as parameters.
2013-01-24 11:53:22 +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