Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Recently, I had some related difficulties with the timing of when event handlers fire, particularly as the size of the character buffer pasted in from Word increases. The event I was interested in was the key-up: as the user types into a headline field (for a blog post), the app updates an auto-generated permalink field. I ended up with a belt-and-suspenders approach: handle the key-up and handle the change event, just in case. An abridged version of my code:</p> <pre><code>hdlHeadlineChange = function (code) { //NOTES: The 'code' argument is for debugging purposes only: it helps you //figure out which event has fired. var headlineText = $(tinyMCE.selectedInstance.getBody()).text(); //heuristically detect and ignore text with embedded Microsoft Word markup if (headlineText.match(/&lt;!--/)) { return; } //as a backstop, trim excessively long text to fit database maximum lengths var truncateLength; var semanticTitle = replaceSpecialCharactersInSemanticUrl(headlineText); //trim the permalink to fit the 255-character max in the database truncateLength = 255 - $('#permalinkPreface').text().length; $('#permalinkSpan').text(semanticTitle.substring(0, truncateLength)); }; function setupHeadlineEventHandlers() { tinyMCE.get("headline").onKeyUp.add(function(ed, evt) { hdlHeadlineChange(evt.keyCode); }); //NOTES: This handler is sort of a backstop. Although the key-up handler may see text //with markup, we expect that the change handler will not. $('#headline').change(function () { hdlHeadlineChange(-1); }); } </code></pre> <p>The key point is that I used .change() to arm the event handler, rather than onchange_callback.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload