Modules (188)

LiveDevProtocolRemote

Description

Dependencies

This module has no dependencies

Variables

CSS

CSS Domain.

    var CSS = {

        setStylesheetText : function (msg) {

            if (!msg || !msg.params || !msg.params.text || !msg.params.url) {
                return;
            }

            var i,
                node;

            var head = window.document.getElementsByTagName('head')[0];
            // create an style element to replace the one loaded with <link>
            var s = window.document.createElement('style');
            s.type = 'text/css';
            s.appendChild(window.document.createTextNode(msg.params.text));

            for (i = 0; i < window.document.styleSheets.length; i++) {
                node = window.document.styleSheets[i];
                if (node.ownerNode.id === msg.params.url) {
                    head.insertBefore(s, node.ownerNode); // insert the style element here
                    // now can remove the style element previously created (if any)
                    node.ownerNode.parentNode.removeChild(node.ownerNode);
                } else if (node.href === msg.params.url  && !node.disabled) {
                    // if the link element to change
                    head.insertBefore(s, node.ownerNode); // insert the style element here
                    node.disabled = true;
                    i++; // since we have just inserted a stylesheet
                }
            }
            s.id = msg.params.url;
        },

MessageBroker

Manage messaging between Editor and Browser at the protocol layer. Handle messages that arrives through the current transport and dispatch them to subscribers. Subscribers are handlers that implements remote commands/functions. Property 'method' of messages body is used as the 'key' to identify message types. Provide a 'send' operation that allows remote commands sending messages to the Editor.

    var MessageBroker = {

Page

Page Domain.

    var Page = {

ProtocolHandler

The remote handler for the protocol.

    var ProtocolHandler = {

Runtime

Runtime Domain. Implements remote commands for "Runtime.*"

    var Runtime = {

Functions

onDocumentClick

Sends the message containing tagID which is being clicked to the editor in order to change the cursor position to the HTML tag corresponding to the clicked element.

    function onDocumentClick(event) {
        var element = event.target;
        if (element && element.hasAttribute('data-brackets-id')) {
            MessageBroker.send({"tagId": element.getAttribute('data-brackets-id')});
        }
    }
    window.document.addEventListener("click", onDocumentClick);

}(this));