Skip to content

{ Category Archives } Javascript

Unit testing

I've finally decided to join the 21st century and use automated testing on my bililiteRange code; I'm using QUnit, with tests on github. I want to bililiteRange test on all three types of editable elements, <input type=text>, <textarea>, and <div contenteditable>, so I created a convenience function to run each test on each type of […]

New jQuery plugin, savemonitor

Playing with the kavanot editor, I wanted some way to encapsulate the process of noting that the text is "dirty"—meaning has been changed but not yet saved, and using a Promise to express the idea that the text is soon-to-be-saved, then saved. I created a plugin that simply represents a state machine with four states, […]

Odd bug with document ranges and selections

I use Range and Selection extensively in bililiteRange in regular elements in standards-based browsers. I initially implemented scrolling a range by inserting an empty element, using scrollIntoView on that, then deleting the element. But it turns out adding and removing elements messes up the selection. So I had to change it to manipulate scrollTop directly.

Preserving the Insertion Point on Blur

One of those ongoing unsolved problems with web apps is how to keep track of the selection or insertion point in an editing element, when the focus has moved onto some other element. For instance, in a rich-text editor, you want to be able to select a word, then click the "bold" button and make […]

DOM 3 events for bililiteRange

I've been looking at the DOM 3 event model and decided that the bililiteRange.text() methods ought to implement those, even though they're not in browsers yet. Nobody implements beforeinput, or in the input event handler, and select only works in <input> and <textarea> (not in contenteditable). And that's in modern browsers. But that's […]

Debouncing Prism.editor

Prism is fast, generally fast enough to use for a live syntax highlighter. But for large texts (multiple kilocharacters) having the text re-highlighted with every input bogs down, and I can type faster than the text can show up. I remember old word processors that were like that, back in the dark ages of computerdom. […]

bililiteRange undo

This is a plugin for bililiteRange that implements a simple undo/redo stack. It listens for input events (so to use it in IE

Bitten by the asynchronous bug

As luck would have it, right after I wrote about synchronous vs. asynchronous event handlers, I found exactly that problem in by bililiteRange code. It uses dispatchEvent to fire an input event when text is inserted, but that fires synchronously, so that the event handlers run before the bililiteRange.text() has fully run. I ended up […]

Update status

As promised, I have updated the status plugin to use Promises. Unfortunately, that required a small change to the parameters. Since I doubt anyone is using it, that will not likely affect anyone but me. The version is now 1.1.

Promises and Event Handers

There's a subtlety in using Promises with event handlers or any code that's executed asynchronously. Promises are supposed to be used for future values, with the reject handler acting like an exception handler, so that the Promise constructor actually catches real exceptions and turns them into rejects (from the polyfill; I assume the browser-implemented code […]