JavaScript

Not logged in - Log In / Register

JavaScript in Launchpad

This page covers everything to do with JavaScript development in Launchpad.

Some useful links:

Zope, JavaScript, and YUI3 Tips

Zope's TAL engine is clever, and helpfully breaks any <script> nodes in your template. Here's how to make the TAL interpreter do the right thing:

<js tal:replace="structure string:<script>...</script>" />


Zope3 forms have field names with dots in them, like this:

  <input id="field.action.visibility" name="field.action.visibility" type="hidden"/>

This makes it impossible to grab <input> nodes with CSS3 selectors, or with YUI3's Y.get() function.

For example, this will return null:

  Y.get('#field.action.visibility');

(Because it looks for an element with ID field and with action and visibility` in its classes.)

You can work around this by using the attribute selector:

  Y.get("id='field.action.visibility']");


Sometimes you need to pass a raw DOM node into another JavaScript library, but YUI3's Y.get() function returns a YUI3 Node instance, which is incompatible.

You can unwrap the Node instance like this:

  var yui_node = Y.get('#foo');
  var raw_node = Y.Node.getDOMNode(yui_node);


By default the YUI3 test runner stops any JavaScript exceptions from propagating. This prevents the test suite from breaking on errors in the code under test, but it also stops Firebug from stopping on errors in the test case itself.

You can force the debugger to open on test-case programming errors by selecting both the Break on All Errors and Track Throw/Catch options under the Firebug Script tab's Options menu.


Here is a clean way to disable a YUI3 widget in a specific browser:

    initializer: function() {
        if (Y.UA.ie) {
            // XXX mars 2009-03-30 bug=352022
            // Disabled in IE due to weirdness.
            this.disabled();
            this.render = function();
        }
    }

This technique means the widget callsites remain the same, but perform null operations. However, the developer integrating the widget still has to work around the fact that the widget will not be publishing new values or events.


Every browser page has a collection of links and JSON available to Javascript. Server-side code can populate that collection by adapting the request to lazr.restful.interfaces.IJSONRequestCache. The resulting object will allow you to put in objects to be marshalled to JSON in the "objects" mapping, and objects to be sent as links in the "links" mapping.


CategoryCategory

JavaScript (last edited 2011-10-28 19:33:58 by flacoste)