source: chrome/content/v_identity/vI_htmlTextBox.xml @ ce8828

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

new modifications - now using remotecontent element from update.xml

  • Property mode set to 100644
File size: 7.9 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   
31    <binding id="vI_browserBox" extends="chrome://global/content/bindings/browser.xml#browser">
32    <implementation>
33    <field name="_cssRead">false</field>
34    <property name="cssSource" >
35        <setter><![CDATA[
36        if (!val) return;
37        dump("cssSource set to " + val + "\n");
38        var head = this.contentDocument.getElementsByTagName("HEAD").item(0);
39        var range = document.createRange();
40        range.selectNode(head);
41        var css_text = this._getContents("chrome://v_identity/skin/" + val);
42        dump("cssSource set to " + val + " cont.\n");
43        var documentFragment = range.createContextualFragment("<style type='text/css'>" + css_text + "</style>");
44        head.appendChild(documentFragment);
45        dump("cssSource set to " + val + " done\n");
46        this._cssRead = true;
47        ]]></setter>
48    </property>
49    <property name="htmlSource" >
50        <setter><![CDATA[
51        if (!val) return;
52        dump("htmlSource set to " + val + "\n");
53        var body = this.contentDocument.getElementsByTagName("BODY").item(0);
54       
55        var range = document.createRange();
56        range.selectNode(body);
57        var html_text = this._getContents("chrome://v_identity/content/doc/" + val);
58        dump("htmlSource set to " + val + " cont.\n");
59        var documentFragment = range.createContextualFragment(html_text);
60        body.appendChild(documentFragment);
61        for (var i = 0; i < body.children.length; i++)
62            if (!body.children[i].id || body.children[i].id != "main") body.removeChild(body.children[i--]);
63        dump("htmlSource set to " + val + " done\n");
64        ]]></setter>
65    </property>
66    <method name="_getContents">
67        <parameter name="aURL" />
68        <body><![CDATA[     
69        // read the chrome file (copied from http://forums.mozillazine.org/viewtopic.php?p=921150)
70        var ioService=Components.classes["@mozilla.org/network/io-service;1"]
71            .getService(Components.interfaces.nsIIOService);
72        var scriptableStream=Components
73            .classes["@mozilla.org/scriptableinputstream;1"]
74            .getService(Components.interfaces.nsIScriptableInputStream);
75       
76        var channel=ioService.newChannel(aURL,null,null);
77        var input=channel.open();
78        scriptableStream.init(input);
79        var str=scriptableStream.read(input.available());
80        scriptableStream.close();
81        input.close();
82        return str;
83        ]]></body>
84    </method>
85    </implementation>
86    </binding>
87
88    <binding id="vI_remoteBrowserBox" extends="chrome://mozapps/content/update/updates.xml#remotecontent">
89    <content>
90        <xul:hbox flex="1" >
91            <xul:vbox class="vI_remoteBrowserBoxProgressmeter" flex="1" >
92                <xul:progressmeter mode="undetermined" />
93                <xul:spacer flex="1" />
94            </xul:vbox>
95            <xul:browser class="vI_browserBox" hidden="true" flex="1" />
96        </xul:hbox>
97    </content>
98    <resources>
99            <stylesheet src="chrome://v_identity/skin/v_identity.css"/>
100    </resources>
101    <implementation>
102    <field name="_content">
103        document.getAnonymousElementByAttribute(this, "class", "vI_browserBox");
104    </field>
105    <field name="_progress">
106        document.getAnonymousElementByAttribute(this, "class", "vI_remoteBrowserBoxProgressmeter");
107    </field>
108    <property name="localCss" onget="return this.getAttribute('localCss');" onset="this.setAttribute('localCss', val); return val;" />
109    <method name="onError">
110    <body><![CDATA[
111        alert("error");
112    ]]></body>
113    </method>
114    <method name="onLoad">
115        <body><![CDATA[
116        this._content.cssSource = this.localCss;
117        this._progress.setAttribute("hidden", "true");
118        this._content.removeAttribute("hidden");
119    ]]></body>
120    </method>
121    <method name="onStart">
122    <body><![CDATA[
123        this._content.setAttribute("hidden", "true");
124        this._progress.removeAttribute("hidden");
125    ]]></body>
126    </method>
127    </implementation>
128    </binding>
129
130
131    <binding id="vI_htmlTextBox" extends="chrome://v_identity/content/vI_htmlTextBox.xml#BrowserBox">
132    <implementation>
133    <constructor>
134        <![CDATA[       
135        dump('******* vI_htmlTextBox.xml constructor\n');
136        ]]>
137    </constructor>
138    <property name="outputString" >
139        <setter><![CDATA[
140        if (!this._cssRead) this.cssSource = this.getAttribute('cssSource');    // read initial Attributes
141        this.contentDocument.lastChild.setAttribute("style", this.getAttribute('documentStyle'));
142       
143        var oldChilds = this.contentDocument.body.childNodes;
144        while (oldChilds.length > 0) this.contentDocument.body.removeChild(oldChilds[0])
145
146        var text_list = val.split(/\n/)
147        for (var i = 0; i < text_list.length; i++) {
148            if (this._isHR(text_list[i])) continue;
149            var text_item = this._checkList(text_list[i]);
150            this._add(text_item);
151            if (!this._currentList && (i + 1) < text_list.length) {
152                var new_br = this.contentDocument
153                    .createElementNS("http://www.w3.org/1999/xhtml", 'html:br');
154                this.contentDocument.body.appendChild(new_br);
155            }
156        }
157        ]]></setter>
158    </property>
159    <field name="_currentList">null</field>
160    <field name="_currentBaseNode">null</field>
161    <method name="_isHR">
162        <parameter name="text" />
163        <body><![CDATA[     
164        if (text == "---") {
165            var new_hr = this.contentDocument
166                .createElementNS("http://www.w3.org/1999/xhtml", 'html:hr');
167            this.contentDocument.body.appendChild(new_hr);
168            return true;
169        }
170        return false;
171        ]]></body>
172    </method>
173    <method name="_checkList">
174        <parameter name="text" />
175        <body><![CDATA[
176        if (text.match(/^\*\s/)) {
177            if (!this._currentList) {
178                this._currentList = this.contentDocument
179                    .createElementNS("http://www.w3.org/1999/xhtml", 'html:ul');
180                this.contentDocument.body.appendChild(this._currentList);
181            }
182            this._currentBaseNode = this.contentDocument
183                                .createElementNS("http://www.w3.org/1999/xhtml", 'html:li');
184            this._currentList.appendChild(this._currentBaseNode);
185        }
186        else {
187            this._currentList = null;
188            this._currentBaseNode = this.contentDocument.body;
189        }
190        return text.replace(/^\*\s/,"")
191        ]]></body>
192    </method>
193    <method name="_add">
194        <parameter name="text" />
195        <body><![CDATA[
196        if (text.match(/http[s]?:\/\/\S+/)) {
197            if (RegExp.leftContext) this._addText(RegExp.leftContext)
198            if (RegExp.lastMatch) this._addLink(RegExp.lastMatch)
199            if (RegExp.rightContext) this._add(RegExp.rightContext)
200        }
201        else this._addText(text);
202        ]]></body>
203    </method>
204    <method name="_addText">
205        <parameter name="text" />
206        <body><![CDATA[     
207        var range = document.createRange();
208        range.selectNode(this._currentBaseNode);
209        var documentFragment = range.createContextualFragment(text);
210        this._currentBaseNode.appendChild(documentFragment);
211        ]]></body>
212    </method>
213    <method name="_addLink">
214        <parameter name="text" />
215        <body><![CDATA[     
216        var new_a = this.contentDocument
217            .createElementNS("http://www.w3.org/1999/xhtml", 'html:a');
218        new_a.setAttribute("href", text)
219        new_a.setAttribute("style", "text-decoration: underline")
220        this._currentBaseNode.appendChild(new_a);
221        var new_text = this.contentDocument.createTextNode(text);
222        new_a.appendChild(new_text);
223        ]]></body>
224    </method>
225    </implementation>
226    </binding>
227
228</bindings>
Note: See TracBrowser for help on using the repository browser.