Getting Content Synchronously

The standard APIs that EditLive! provides are designed to maximize browser compatibility and ensure that the integration works the same way on any browser. The big disadvantage of this approach is that the APIs all need to be asynchronous - instead of returning the requested value directly, they return immediately and call back to another JavaScript function with the value. This is architecture was required for compatibility with Macintosh browsers and Netscape 4, however with advances in browsers and users upgrading, many sites no longer require compatibility with these older browsers and development would be much simpler with a synchronous API.

If you don't need to support old browsers like Netscape 4, Internet Explorer on Mac or Safari before about OS X 10.31, you can safely use the synchronous APIs that EditLive! provides and it's really simple. First you need to get the actual applet instance instead of the JavaScript wrapper object we provide:

var editliveApplet = document.getElementById(editorName + "_elj");

The applet is given an ID attribute consisting of the name you specify in the EditLiveJava constructor with "_elj" appended to it. Once we have the applet instance, we can call methods on it as if it were any other JavaScript object and the results will be returned synchronously. The available methods are:

  • getBody()
  • getDocument()
  • setBody(String)
  • setDocument(String)
  • uploadImages()
  • getSelectedText()
  • isDirty()
  • setIsDirty(boolean)

If you need images to be uploaded, make sure you call uploadImages before getBody or getDocument. If there are other APIs in the JavaScript object that you'd need made available synchronously through the applet, please let us know and we'll see what we can do.

1 - make sure you test in your target versions of Safari, the technology that enables synchronous calls, LiveConnect, was added but with some limitations, then fixed in later updates so it's hard to pinpoint exactly which versions work well.

Adrian spends his days working out ways to make life easier for Ephox clients through initiatives like LiveWorks! Previously a senior engineer, he has now moved on to the fancier sounding title of CTO.

Leave a Reply