source: chrome/content/v_identity/vI_htmlTextBox.xml @ 90d3d0

multiEditng_0.6ng_0.6_helpng_0.8ng_0.9
Last change on this file since 90d3d0 was 90d3d0, checked in by rene <rene@…>, 13 years ago

test of html help

  • Property mode set to 100644
File size: 6.4 KB
Line 
1<?xml version="1.0"?>
2<!-- ***** BEGIN LICENSE BLOCK *****
3   - This program is free software; you can redistribute it and/or modify
4   - it under the terms of the GNU General Public License as published by
5   - the Free Software Foundation; either version 2 of the License, or
6   - (at your option) any later version.
7
8   - This program is distributed in the hope that it will be useful,
9   - but WITHOUT ANY WARRANTY; without even the implied warranty of
10   - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11   - GNU General Public License for more details.
12
13   - You should have received a copy of the GNU General Public License
14   - along with this program; if not, write to the Free Software
15   - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16
17   - The Original Code is the Virtual Identity Extension.
18
19   - The Initial Developer of the Original Code is Rene Ejury.
20   - Portions created by the Initial Developer are Copyright (C) 2007
21   - the Initial Developer. All Rights Reserved.
22
23   - Contributor(s):
24   - ***** END LICENSE BLOCK ***** -->
25
26<bindings id="vI_htmlTextBoxBindings"
27          xmlns="http://www.mozilla.org/xbl"
28          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
29          xmlns:xbl="http://www.mozilla.org/xbl">
30    <binding id="vI_htmlTextBox" extends="chrome://global/content/bindings/browser.xml#browser">
31    <implementation>
32    <constructor>
33        <![CDATA[       
34        dump('******* vI_htmlTextBox.xml constructor\n');
35        ]]>
36    </constructor>
37    <property name="outputString" >
38        <setter><![CDATA[
39        if (!this._cssRead) this.cssSource = this.getAttribute('cssSource');    // read initial Attributes
40        this.contentDocument.lastChild.setAttribute("style", this.getAttribute('documentStyle'));
41       
42        var oldChilds = this.contentDocument.body.childNodes;
43        while (oldChilds.length > 0) this.contentDocument.body.removeChild(oldChilds[0])
44
45        var text_list = val.split(/\n/)
46        for (var i = 0; i < text_list.length; i++) {
47            if (this._isHR(text_list[i])) continue;
48            var text_item = this._checkList(text_list[i]);
49            this._add(text_item);
50            if (!this._currentList && (i + 1) < text_list.length) {
51                var new_br = this.contentDocument
52                    .createElementNS("http://www.w3.org/1999/xhtml", 'html:br');
53                this.contentDocument.body.appendChild(new_br);
54            }
55        }
56        ]]></setter>
57    </property>
58    <field name="_cssRead">false</field>
59    <property name="cssSource" >
60        <setter><![CDATA[
61        if (!val) return;
62        dump("cssSource set to " + val + "\n");
63        var head = this.contentDocument.getElementsByTagName("HEAD").item(0);
64        var range = document.createRange();
65        range.selectNode(head);
66        var css_text = this._getContents("chrome://v_identity/skin/" + val);
67        dump("cssSource set to " + val + " cont.\n");
68        var documentFragment = range.createContextualFragment("<style type='text/css'>" + css_text + "</style>");
69        head.appendChild(documentFragment);
70        dump("cssSource set to " + val + " done\n");
71        this._cssRead = true;
72        ]]></setter>
73    </property>
74    <property name="htmlSource" >
75        <setter><![CDATA[
76        if (!val) return;
77        dump("htmlSource set to " + val + "\n");
78        var body = this.contentDocument.getElementsByTagName("BODY").item(0);
79       
80        var range = document.createRange();
81        range.selectNode(body);
82        var html_text = this._getContents("chrome://v_identity/content/doc/" + val);
83        dump("htmlSource set to " + val + " cont.\n");
84        var documentFragment = range.createContextualFragment(html_text);
85        body.appendChild(documentFragment);
86        for (var i = 0; i < body.children.length; i++)
87            if (!body.children[i].id || body.children[i].id != "main") body.removeChild(body.children[i--]);
88        dump("htmlSource set to " + val + " done\n");
89        ]]></setter>
90    </property>
91    <field name="_currentList">null</field>
92    <field name="_currentBaseNode">null</field>
93    <method name="_getContents">
94        <parameter name="aURL" />
95        <body><![CDATA[     
96        // read the chrome file (copied from http://forums.mozillazine.org/viewtopic.php?p=921150)
97        var ioService=Components.classes["@mozilla.org/network/io-service;1"]
98            .getService(Components.interfaces.nsIIOService);
99        var scriptableStream=Components
100            .classes["@mozilla.org/scriptableinputstream;1"]
101            .getService(Components.interfaces.nsIScriptableInputStream);
102       
103        var channel=ioService.newChannel(aURL,null,null);
104        var input=channel.open();
105        scriptableStream.init(input);
106        var str=scriptableStream.read(input.available());
107        scriptableStream.close();
108        input.close();
109        return str;
110        ]]></body>
111    </method>
112    <method name="_isHR">
113        <parameter name="text" />
114        <body><![CDATA[     
115        if (text == "---") {
116            var new_hr = this.contentDocument
117                .createElementNS("http://www.w3.org/1999/xhtml", 'html:hr');
118            this.contentDocument.body.appendChild(new_hr);
119            return true;
120        }
121        return false;
122        ]]></body>
123    </method>
124    <method name="_checkList">
125        <parameter name="text" />
126        <body><![CDATA[
127        if (text.match(/^\*\s/)) {
128            if (!this._currentList) {
129                this._currentList = this.contentDocument
130                    .createElementNS("http://www.w3.org/1999/xhtml", 'html:ul');
131                this.contentDocument.body.appendChild(this._currentList);
132            }
133            this._currentBaseNode = this.contentDocument
134                                .createElementNS("http://www.w3.org/1999/xhtml", 'html:li');
135            this._currentList.appendChild(this._currentBaseNode);
136        }
137        else {
138            this._currentList = null;
139            this._currentBaseNode = this.contentDocument.body;
140        }
141        return text.replace(/^\*\s/,"")
142        ]]></body>
143    </method>
144    <method name="_add">
145        <parameter name="text" />
146        <body><![CDATA[
147        if (text.match(/http[s]?:\/\/\S+/)) {
148            if (RegExp.leftContext) this._addText(RegExp.leftContext)
149            if (RegExp.lastMatch) this._addLink(RegExp.lastMatch)
150            if (RegExp.rightContext) this._add(RegExp.rightContext)
151        }
152        else this._addText(text);
153        ]]></body>
154    </method>
155    <method name="_addText">
156        <parameter name="text" />
157        <body><![CDATA[     
158        var range = document.createRange();
159        range.selectNode(this._currentBaseNode);
160        var documentFragment = range.createContextualFragment(text);
161        this._currentBaseNode.appendChild(documentFragment);
162        ]]></body>
163    </method>
164    <method name="_addLink">
165        <parameter name="text" />
166        <body><![CDATA[     
167        var new_a = this.contentDocument
168            .createElementNS("http://www.w3.org/1999/xhtml", 'html:a');
169        new_a.setAttribute("href", text)
170        new_a.setAttribute("style", "text-decoration: underline")
171        this._currentBaseNode.appendChild(new_a);
172        var new_text = this.contentDocument.createTextNode(text);
173        new_a.appendChild(new_text);
174        ]]></body>
175    </method>
176    </implementation>
177    </binding>
178
179</bindings>
Note: See TracBrowser for help on using the repository browser.