Avoid These Common Gotchas
Here are some common gotchas that developers face when getting started with EditMe development. Being aware of these up front can save you lots of time.
Don't Re-use Implicit Variable Names
EditMe's implicit objects are documented on the Java Script API page. Unless you are doing so on purpose, don't name your variables with names used for these implicit objects. If you need a variable to store a page, don't use "page". If you're looping through an array of users, don't use "user" to store each one in the loop. Scripts that run after your own may very well rely on "user" to be pointing to the current user, or "page" to the current page.
Learn JavaScript's Reserved Words
JavaScript has more reserved words than you probably think, and using them in your code can lead to head scratching errors. See this list of reserved words. You'll see why we used "destroy()" to delete things and not the more obvious "delete()".
Become Familiar with XML Validation Rules
EditMe page scripts must be valid XML, and there are a number of traps you can fall into that don't always provide meaningful error messages. One trick you can use to get a good validation error message every time is to save your script as a .xml file on your local hard drive and open it up with Internet Explorer. This will usually give you a very specific line numbered reason your script is invalid. Otherwise, here are some common XML validation gotchas:
- All single tags must be self-closed. For example, <br> must be <br /> and <img src=".."> must be <img src=".." />
- All tags must be properly nested. For example, <p><span></p></span> is invalid. It should be <p><span></span></p>
- Browsers don't like self-closed script tags. If your page script outputs a <script/> you'll have problems. Make sure to put a line break or space in any script tag that will be outputted to the browser.
- If you use a & in an attribute script, it must be escaped. For example <span editme="if a && b"/> won't work. It should be <span editme="if a && b"/>
- Page scripts must have a single root element enclosing the entire script. A simple <span> or <div> tag can be used for this purpose.
- Always Put Scripts in CDATA
- is invalid. Use   to force a space, or if you really want the HTML non-breaking space behavior, you can use <![CDATA[ ]]>
- For other HTML entities, see this list. Use the "Unicode code point" number to insert these. For example, for ¥ you would use ¥
- EditMe doesn't like there to be a namespace declared in a Layout. Just use <html>, not something like <html xmlns="..." lang="..">
- If you want to use a DOCTYPE in your layout, you must follow these instructions.
EditMe's foreach vs. JavaScript for/in
EditMe has a foreach attribute command that is used like this: <span editme="foreach item myarray">...</span>. This will repeat the span tag with the "item" variable pointing to each consecutive element in the "myarrray" array. JavaScript for loops, on the other hand, will give you the index of the array, not the element. For example for (var i in myarray) {..} will give you 0, 1, 2 in the "i" variable instead of whatever value is stored at that location in the array.