Changeset 50271b


Ignore:
Timestamp:
Aug 11, 2008, 5:47:24 PM (12 years ago)
Author:
rene <rene@…>
Branches:
master
Children:
b89f87
Parents:
ea9884
Message:

changed to support css and parse html. Required by upcoming layouted Dialog.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chrome/content/v_identity/vI_htmlTextBox.js

    rea9884 r50271b  
    2626    Obj_TextBox : null,
    2727    string : null,
     28    cssSource : null,
    2829    objectID : null,
    2930   
    30     init : function(objectID, stringName) {
     31    init : function(objectID, stringName, outputString, cssSource) {
    3132        vI_htmlTextBox.objectID = objectID;
    32         vI_htmlTextBox.string = document.getElementById("vITextBoxBundle").getString(stringName);
     33        if (stringName)
     34            vI_htmlTextBox.string = document.getElementById("vITextBoxBundle").getString(stringName);
     35        else if (outputString)
     36            vI_htmlTextBox.string = outputString;
     37        vI_htmlTextBox.cssSource = cssSource;
    3338        window.setTimeout(vI_htmlTextBox.__init, 200)
     39    },
     40
     41    // read the chrome file (copied from http://forums.mozillazine.org/viewtopic.php?p=921150)
     42    __getContents : function (aURL){
     43        var ioService=Components.classes["@mozilla.org/network/io-service;1"]
     44            .getService(Components.interfaces.nsIIOService);
     45        var scriptableStream=Components
     46            .classes["@mozilla.org/scriptableinputstream;1"]
     47            .getService(Components.interfaces.nsIScriptableInputStream);
     48       
     49        var channel=ioService.newChannel(aURL,null,null);
     50        var input=channel.open();
     51        scriptableStream.init(input);
     52        var str=scriptableStream.read(input.available());
     53        scriptableStream.close();
     54        input.close();
     55        return str;
     56    },
     57
     58    __setCSS : function () {
     59        var head = vI_htmlTextBox.Obj_TextBox.contentDocument.getElementsByTagName("HEAD").item(0);
     60        var range = document.createRange();
     61        range.selectNode(head);
     62        var css_text = vI_htmlTextBox.__getContents("chrome://v_identity/skin/" + vI_htmlTextBox.cssSource);
     63        var documentFragment = range.createContextualFragment("<style type='text/css'>" + css_text + "</style>");
     64        head.appendChild(documentFragment);
    3465    },
    3566   
     
    3869        vI_htmlTextBox.Obj_TextBox.contentDocument
    3970            .lastChild.setAttribute("style", "background-color: -moz-dialog; font: -moz-dialog;");
     71
     72        if (vI_htmlTextBox.cssSource) vI_htmlTextBox.__setCSS();
     73
    4074        vI_htmlTextBox.__echo(vI_htmlTextBox.string);
    41 //      vI_htmlTextBox.Obj_TextBox.setAttribute("hidden", "false");
    4275    },
    4376   
    44     // background-color: -moz-dialog; font: -moz-dialog;
    4577    __echo : function (text) {
    46         //~ alert("echo");
    4778        var text_list = text.split(/\n/)
    4879        for (i = 0; i < text_list.length; i++) {
     
    5687            }
    5788        }
    58         //~ vI_htmlTextBox.Obj_TextBox.inputField.scrollTop =
    59             //~ vI_htmlTextBox.Obj_TextBox.inputField.scrollHeight - vI_htmlTextBox.Obj_TextBox.inputField.clientHeight
    6089    },
    6190   
     
    99128   
    100129    __addText : function (text) {
    101         var new_text = vI_htmlTextBox.Obj_TextBox.contentDocument.createTextNode(text);
    102         vI_htmlTextBox.currentBaseNode.appendChild(new_text);
     130        var range = document.createRange();
     131        range.selectNode(vI_htmlTextBox.currentBaseNode);
     132        var documentFragment = range.createContextualFragment(text);
     133        vI_htmlTextBox.currentBaseNode.appendChild(documentFragment);
    103134    },
    104135   
Note: See TracChangeset for help on using the changeset viewer.