/[suikacvs]/markup/slide/implementation/slide-xbl.xml
Suika

Contents of /markup/slide/implementation/slide-xbl.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations) (download) (as text)
Sat Apr 23 06:56:36 2005 UTC (19 years, 7 months ago) by wakaba
Branch: MAIN
Changes since 1.2: +20 -7 lines
File MIME type: text/xml
HTCs incorporated into CSSs as expression; xhtml2:title now shown as window title

1 wakaba 1.1 <?xml version="1.0"?>
2     <bindings xmlns="http://www.mozilla.org/xbl">
3     <binding id="slideCore">
4     <implementation>
5     <field name="SLIDE_XBL_BASE">'http://suika.fam.cx/~wakaba/-temp/slide/implementation/'</field>
6     <field name="NS_SLIDE">'urn:x-suika-fam-cx:markup:slide:1'</field>
7     <field name="NS_XHTML1">'http://www.w3.org/1999/xhtml'</field>
8     <field name="NS_XHTML2">'http://www.w3.org/2002/06/xhtml2'</field>
9 wakaba 1.2 <method name="getSlideList" type="application/x-javascript">
10     <body xml:space="preserve"><![CDATA[
11     return document.getElementsByTagNameNS (this.NS_SLIDE, 'slides')[0]
12     .getElementsByTagNameNS (this.NS_SLIDE, 'slide');
13     ]]></body>
14     </method>
15     <method name="createSlideBodyElement" type="application/x-javascript">
16     <parameter name="slide"/>
17     <body xml:space="preserve"><![CDATA[
18     var slideBody = document.createElementNS (this.NS_SLIDE, 'slideBody');
19     var notes = document.createElementNS (this.NS_SLIDE, 'notes');
20     var slideChildren = slide.childNodes;
21     while (slideChildren.length) {
22     if (slideChildren[0].namespaceURI === this.NS_SLIDE
23     && slideChildren[0].localName === 'note') {
24     notes.appendChild (slideChildren[0]);
25     } else {
26     slideBody.appendChild (slideChildren[0]);
27     }
28     }
29     slide.appendChild (slideBody);
30     if (notes.childNodes.length)
31     slide.appendChild (notes);
32     ]]></body>
33     </method>
34 wakaba 1.1 <constructor type="application/x-javascript" xml:space="preserve"><![CDATA[
35 wakaba 1.2 var topLevelNodes = document.documentElement.childNodes;
36     for (var i = 0; i < topLevelNodes.length;) {
37     if (topLevelNodes[i].nodeType === TEXT_NODE
38     || topLevelNodes[i].nodeType === COMMENT_NODE) {
39     document.documentElement.removeChild (topLevelNodes[i]);
40     } else {
41     i++;
42     }
43     }
44     var slides = this.getSlideList ();
45 wakaba 1.1 for (var i = 0; i < slides.length; i++) {
46     slides[i].setAttribute ('slideIndex', i);
47 wakaba 1.2 this.createSlideBodyElement (slides[i]);
48 wakaba 1.1 }
49    
50     var h = document.getElementsByTagNameNS (this.NS_XHTML2, 'head')[0];
51     // Common slide style
52     var l = document.createElementNS (this.NS_XHTML1, 'link');
53     l.setAttribute ('rel', 'stylesheet');
54 wakaba 1.3 l.setAttribute ('href',
55     /* URI-reference== */
56     this.SLIDE_XBL_BASE+'xhtml2.css'
57     /* ==URI-reference */);
58 wakaba 1.2 h.appendChild (l);
59    
60     l = document.createElementNS (this.NS_XHTML1, 'link');
61     l.setAttribute ('rel', 'stylesheet');
62 wakaba 1.3 l.setAttribute ('href',
63     /* URI-reference== */
64     this.SLIDE_XBL_BASE+'slide-style.css'
65     /* ==URI-reference */);
66 wakaba 1.1 h.appendChild (l);
67    
68     // Slide listing style
69     l = document.createElementNS (this.NS_XHTML1, 'link');
70     l.setAttribute ('rel', 'stylesheet');
71 wakaba 1.3 l.setAttribute ('href',
72     /* URI-reference== */
73     this.SLIDE_XBL_BASE+'slide-list.css'
74     /* ==URI-reference */);
75 wakaba 1.1 l.setAttribute ('title', 'Slide List');
76     h.appendChild (l);
77    
78     // Slide showing style
79     l = document.createElementNS (this.NS_XHTML1, 'link');
80     l.setAttribute ('rel', 'stylesheet alternate');
81 wakaba 1.3 l.setAttribute ('href',
82     /* URI-reference== */
83     this.SLIDE_XBL_BASE+'slide-show.css'
84     /* ==URI-reference */);
85 wakaba 1.1 l.setAttribute ('title', 'Slideshow');
86     h.appendChild (l);
87     }
88     ]]></constructor>
89     </implementation>
90     </binding>
91     <binding id="slideshow">
92     <implementation>
93     <field name="currentSlideIndex">0</field>
94     <field name="NS_SLIDE">'urn:x-suika-fam-cx:markup:slide:1'</field>
95     <field name="NS_XHTML1">'http://www.w3.org/1999/xhtml'</field>
96     <field name="NS_XHTML2">'http://www.w3.org/2002/06/xhtml2'</field>
97     <method name="getInnerText" type="application/x-javascript">
98     <parameter name="node"/>
99     <body xml:space="preserve"><![CDATA[
100     // <http://white.sakura.ne.jp/~piro/xul/tips/x0013.html>
101     var nodes = node.childNodes;
102     var ret = [];
103     for (var i = 0; i < nodes.length; i++)
104     if (nodes[i].hasChildNodes())
105     ret.push(this.getInnerText(nodes[i]));
106     else if (nodes[i].nodeType == Node.TEXT_NODE)
107     ret.push(nodes[i].nodeValue);
108     else if (nodes[i].alt)
109     ret.push(nodes[i].alt);
110     return ret.join('');
111     ]]></body>
112     </method>
113 wakaba 1.2 <method name="getSlideList" type="application/x-javascript">
114     <body xml:space="preserve"><![CDATA[
115     return document.getElementsByTagNameNS (this.NS_SLIDE, 'slides')[0]
116     .getElementsByTagNameNS (this.NS_SLIDE, 'slide');
117     ]]></body>
118     </method>
119 wakaba 1.1 <method name="setCurrentSlide" type="application/x-javascript">
120     <parameter name="n"/>
121     <body xml:space="preserve"><![CDATA[
122 wakaba 1.2 var slides = this.getSlideList ();
123 wakaba 1.1 if (n < 0) n = slides.length + n; // -1 = slides.length-1
124     else if (slides.length <= n) n = 0;
125     for (var i = 0; i < slides.length; i++) {
126 wakaba 1.3 slides[i].setAttributeNS (this.NS_SLIDE, 'isCurrentSlide',
127     (i == n ? 'yes' : 'no'));
128 wakaba 1.1 }
129     this.currentSlideIndex = n;
130     ]]></body>
131     </method>
132     <method name="getSlideTitle" type="application/x-javascript">
133     <parameter name="n"/>
134     <body xml:space="preserve"><![CDATA[
135 wakaba 1.2 var slides = this.getSlideList ();
136 wakaba 1.1 if (n < 0) n = slides.length + n; // -1 = slides.length-1
137     else if (slides.length <= n) n = slides.length - 1;
138     if (slides[n]) {
139     var h = this.getInnerText (slides[n].getElementsByTagNameNS (this.NS_XHTML2, 'h')[0]);
140     if (h) {
141     return h;
142     } else {
143     return 'Slide ' + n;
144     }
145     } else {
146     return '';
147     }
148     ]]></body>
149     </method>
150     <method name="onKeyDown" type="application/x-javascript">
151     <parameter name="e"/>
152     <parameter name="myThis"/>
153     <body xml:space="preserve"><![CDATA[
154     if (e.keyCode == 13 || e.keyCode == 39) { // Enter / <-
155     myThis.setCurrentSlide (myThis.currentSlideIndex + 1);
156     } else if (e.keyCode == 8 || e.keyCode == 37) { // BS / ->
157     myThis.setCurrentSlide (myThis.currentSlideIndex - 1);
158     e.preventDefault ();
159     }
160     //else alert ('KC: ' + (e.keyCode) + ', CC: ' + (e.charCode));
161     ]]></body>
162     </method>
163     <constructor type="application/x-javascript" xml:space="preserve">
164     <![CDATA[
165     if (document.__slideControl__) return;
166     document.__slideControl__ = this;
167    
168     var myThis = this;
169     document.defaultView.addEventListener ('keydown', function (e) {
170     myThis.onKeyDown (e, myThis);
171     }, false);
172    
173     var h = document.getElementsByTagNameNS (this.NS_XHTML2, 'head')[0];
174     var l = document.createElementNS (this.NS_XHTML1, 'link');
175     l.setAttribute ('rel', 'first');
176     l.setAttribute ('href', 'javascript:document.__slideControl__.setCurrentSlide(0)');
177     l.setAttribute ('title', this.getSlideTitle (0));
178     h.appendChild (l);
179    
180     l = document.createElementNS (this.NS_XHTML1, 'link');
181     l.setAttribute ('rel', 'last');
182     l.setAttribute ('href', 'javascript:document.__slideControl__.setCurrentSlide(-1)');
183     l.setAttribute ('title', this.getSlideTitle (-1));
184     h.appendChild (l);
185    
186     l = document.createElementNS (this.NS_XHTML1, 'link');
187     l.setAttribute ('rel', 'next');
188     l.setAttribute ('href', 'javascript:document.__slideControl__.setCurrentSlide(document.__slideControl__.currentSlideIndex+1)');
189     h.appendChild (l);
190    
191     l = document.createElementNS (this.NS_XHTML1, 'link');
192     l.setAttribute ('rel', 'prev');
193     l.setAttribute ('id', 'link-prev-page');
194     l.setAttribute ('href', 'javascript:document.__slideControl__.setCurrentSlide(document.__slideControl__.currentSlideIndex-1)');
195     h.appendChild (l);
196     this.setCurrentSlide (0);
197     ]]>
198     </constructor>
199     </implementation>
200     </binding>
201     <binding id="seqNo">
202     <implementation>
203 wakaba 1.3 <field name="NS_SLIDE">'urn:x-suika-fam-cx:markup:slide:1'</field>
204 wakaba 1.1 <constructor type="application/x-javascript" xml:space="preserve"><![CDATA[
205     var t;
206     var seqName = this.getAttribute ('name');
207     if (!document.__slideSeqNo__) {
208     document.__slideSeqNo__ = [];
209     }
210     t = document.__slideSeqNo__;
211     if (t[seqName]) {
212     t[seqName]++;
213     } else {
214     t[seqName] = 1;
215     }
216 wakaba 1.3 this.setAttributeNS (this.NS_SLIDE, 's:seq-no', t[seqName]);
217 wakaba 1.1 ]]></constructor>
218     </implementation>
219     </binding>
220     <binding id="refTo">
221     <implementation>
222     <field name="NS_SLIDE">'urn:x-suika-fam-cx:markup:slide:1'</field>
223     <field name="NS_XHTML1">'http://www.w3.org/1999/xhtml'</field>
224     <field name="NS_XHTML2">'http://www.w3.org/2002/06/xhtml2'</field>
225     <field name="NS_XLINK">'http://www.w3.org/1999/xlink'</field>
226     <method name="getInnerText" type="application/x-javascript">
227     <parameter name="node"/>
228     <body xml:space="preserve"><![CDATA[
229     // <http://white.sakura.ne.jp/~piro/xul/tips/x0013.html>
230     var nodes = node.childNodes;
231     var ret = [];
232     for (var i = 0; i < nodes.length; i++)
233     if (nodes[i].hasChildNodes())
234     ret.push(this.getInnerText(nodes[i]));
235     else if (nodes[i].nodeType == Node.TEXT_NODE)
236     ret.push(nodes[i].nodeValue);
237     else if (nodes[i].alt)
238     ret.push(nodes[i].alt);
239     return ret.join('');
240     ]]></body>
241     </method>
242     <constructor type="application/x-javascript" xml:space="preserve"><![CDATA[
243     var targetId = this.getAttribute ('to');
244     var targetElement = document.getElementById (targetId);
245     if (targetElement && (targetElement.namespaceURI == this.NS_SLIDE) && (targetElement.localName == 'slide')) {
246     targetElement = targetElement.getElementsByTagNameNS (NS_XHTML2, 'h')[0];
247     }
248    
249     if (targetElement) {
250     for (var i = 0; i < targetElement.childNodes.length; i++) {
251     var cN = targetElement.childNodes[i];
252     //if (cN.nodeType != ATTRIBUTE_NODE)
253     // this.appendChild (cN.cloneNode);
254     this.appendChild (document.createTextNode (this.getInnerText (cN)));
255     }
256     this.setAttributeNS (this.NS_XLINK, 'type', 'simple');
257     this.setAttributeNS (this.NS_XLINK, 'href', '#' + targetId);
258     }
259     ]]></constructor>
260     </implementation>
261     </binding>
262     </bindings>
263     <!-- ***** BEGIN LICENSE BLOCK *****
264     - Version: MPL 1.1/GPL 2.0/LGPL 2.1
265     -
266     - The contents of this file are subject to the Mozilla Public License Version
267     - 1.1 (the "License"); you may not use this file except in compliance with
268     - the License. You may obtain a copy of the License at
269     - <http://www.mozilla.org/MPL/>
270     -
271     - Software distributed under the License is distributed on an "AS IS" basis,
272     - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
273     - for the specific language governing rights and limitations under the
274     - License.
275     -
276     - The Original Code is HSML experimental implemention code.
277     -
278     - The Initial Developer of the Original Code is Wakaba.
279     - Portions created by the Initial Developer are Copyright (C) 2003
280     - the Initial Developer. All Rights Reserved.
281     -
282     - Contributor(s):
283     - Wakaba <w@suika.fam.cx>
284     -
285     - Alternatively, the contents of this file may be used under the terms of
286     - either the GNU General Public License Version 2 or later (the "GPL"), or
287     - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
288     - in which case the provisions of the GPL or the LGPL are applicable instead
289     - of those above. If you wish to allow use of your version of this file only
290     - under the terms of either the GPL or the LGPL, and not to allow others to
291     - use your version of this file under the terms of the MPL, indicate your
292     - decision by deleting the provisions above and replace them with the notice
293     - and other provisions required by the LGPL or the GPL. If you do not delete
294     - the provisions above, a recipient may use your version of this file under
295     - the terms of any one of the MPL, the GPL or the LGPL.
296     -
297     - ***** END LICENSE BLOCK ***** -->

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24