source: chrome/content/v_identity/vI_htmlTextBox.xml @ 97d350

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

created new branch for upcoming 0.6 release. focus on object-orientation. somehow working.

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