source: chrome/content/v_identity/vI_htmlTextBox.xml @ 2f8c7f

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

collection of changes to 0.6 branch

  • Property mode set to 100644
File size: 5.6 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<!--        vI_notificationBar.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        var head = this.contentDocument.getElementsByTagName("HEAD").item(0);
63        var range = document.createRange();
64        range.selectNode(head);
65        var css_text = this._getContents("chrome://v_identity/skin/" + val);
66        var documentFragment = range.createContextualFragment("<style type='text/css'>" + css_text + "</style>");
67        head.appendChild(documentFragment);
68        this._cssRead = true;
69        ]]></setter>
70    </property>
71    <field name="_currentList">null</field>
72    <field name="_currentBaseNode">null</field>
73    <method name="_getContents">
74        <parameter name="aURL" />
75        <body><![CDATA[     
76        // read the chrome file (copied from http://forums.mozillazine.org/viewtopic.php?p=921150)
77        var ioService=Components.classes["@mozilla.org/network/io-service;1"]
78            .getService(Components.interfaces.nsIIOService);
79        var scriptableStream=Components
80            .classes["@mozilla.org/scriptableinputstream;1"]
81            .getService(Components.interfaces.nsIScriptableInputStream);
82       
83        var channel=ioService.newChannel(aURL,null,null);
84        var input=channel.open();
85        scriptableStream.init(input);
86        var str=scriptableStream.read(input.available());
87        scriptableStream.close();
88        input.close();
89        return str;
90        ]]></body>
91    </method>
92    <method name="_isHR">
93        <parameter name="text" />
94        <body><![CDATA[     
95        if (text == "---") {
96            var new_hr = this.contentDocument
97                .createElementNS("http://www.w3.org/1999/xhtml", 'html:hr');
98            this.contentDocument.body.appendChild(new_hr);
99            return true;
100        }
101        return false;
102        ]]></body>
103    </method>
104    <method name="_checkList">
105        <parameter name="text" />
106        <body><![CDATA[
107        if (text.match(/^\*\s/)) {
108            if (!this._currentList) {
109                this._currentList = this.contentDocument
110                    .createElementNS("http://www.w3.org/1999/xhtml", 'html:ul');
111                this.contentDocument.body.appendChild(this._currentList);
112            }
113            this._currentBaseNode = this.contentDocument
114                                .createElementNS("http://www.w3.org/1999/xhtml", 'html:li');
115            this._currentList.appendChild(this._currentBaseNode);
116        }
117        else {
118            this._currentList = null;
119            this._currentBaseNode = this.contentDocument.body;
120        }
121        return text.replace(/^\*\s/,"")
122        ]]></body>
123    </method>
124    <method name="_add">
125        <parameter name="text" />
126        <body><![CDATA[
127        if (text.match(/http[s]?:\/\/\S+/)) {
128            if (RegExp.leftContext) this._addText(RegExp.leftContext)
129            if (RegExp.lastMatch) this._addLink(RegExp.lastMatch)
130            if (RegExp.rightContext) this._add(RegExp.rightContext)
131        }
132        else this._addText(text);
133        ]]></body>
134    </method>
135    <method name="_addText">
136        <parameter name="text" />
137        <body><![CDATA[     
138        var range = document.createRange();
139        range.selectNode(this._currentBaseNode);
140        var documentFragment = range.createContextualFragment(text);
141        this._currentBaseNode.appendChild(documentFragment);
142        ]]></body>
143    </method>
144    <method name="_addLink">
145        <parameter name="text" />
146        <body><![CDATA[     
147        var new_a = this.contentDocument
148            .createElementNS("http://www.w3.org/1999/xhtml", 'html:a');
149        new_a.setAttribute("href", text)
150        new_a.setAttribute("style", "text-decoration: underline")
151        this._currentBaseNode.appendChild(new_a);
152        var new_text = this.contentDocument.createTextNode(text);
153        new_a.appendChild(new_text);
154        ]]></body>
155    </method>
156    </implementation>
157    </binding>
158
159</bindings>
Note: See TracBrowser for help on using the repository browser.