/[suikacvs]/webroot/swe/scripts/sw.js
Suika

Contents of /webroot/swe/scripts/sw.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download) (as text)
Mon Mar 2 07:32:30 2009 UTC (17 years, 6 months ago) by wakaba
Branch: MAIN
Changes since 1.2: +23 -2 lines
File MIME type: application/javascript
++ swe/lib/SWE/DB/ChangeLog	2 Mar 2009 07:32:02 -0000
2009-03-01  Wakaba  <wakaba@suika.fam.cx>

	* HashedIndex.pm: New module.

	* IDGenerator.pm (get_last_id): New method.

2009-01-12  Wakaba  <wakaba@suika.fam.cx>

	* SuikaWiki3LastModified.pm (get_data): Why this convertion was
	necessary?

++ swe/lib/suikawiki/ChangeLog	2 Mar 2009 07:31:08 -0000
2009-03-02  Wakaba  <wakaba@suika.fam.cx>

	* main.pl (;search, ;terms): New modes.

++ swe/styles/ChangeLog	3 Feb 2009 03:44:04 -0000
2009-02-03  Wakaba  <wakaba@suika.fam.cx>

	* sw.css: Fixed a typo.

1 window.onload = function () {
2 createToolbar ();
3 initializeHatenaStar();
4 enableHTML5Support ();
5 }; // window.onload
6
7 function getElementsByClassName (c) {
8 if (document.getElementsByClassName) {
9 return document.getElementsByClassName (c);
10 } else {
11 return [];
12 }
13 } // getElementsByClassName
14
15 function getAncestorElement (n, t) {
16 while (n != null) {
17 if (n.nodeName == t) {
18 return n;
19 } else {
20 n = n.parentNode;
21 }
22 }
23 return null;
24 } // getAncestorElement
25
26 function getNextAnchorNumber (s) {
27 var lastId = 0;
28 s.replace (/\[([0-9]+)\]/g, function (l, n) {
29 var v = parseInt (n);
30 if (v > lastId) {
31 lastId = v;
32 }
33 });
34 return lastId + 1;
35 } // getNextAnchorNumber
36
37 function createToolbar () {
38 var containers = getElementsByClassName ('text-toolbar');
39 for (var i = 0; i < containers.length; i++) {
40 var container = containers[i];
41
42 var button = document.createElement ('button');
43 button.setAttribute ('type', 'button');
44 button.innerHTML = '[#]';
45 button.onclick = function () {
46 var form = getAncestorElement (container, 'FORM');
47 var ta = form.elements.text;
48 var st = ta.scrollTop;
49 var ss = ta.selectionStart;
50 var se = (ss != ta.selectionEnd);
51 var added = '[' + getNextAnchorNumber (ta.value) + '] ';
52 /*
53 if (ss > 0 && ta.value.substring (ss - 1, ss) != "\n") {
54 added = "\n" + added;
55 }
56 */
57 ta.value = ta.value.substring (0, ta.selectionStart)
58 + added + ta.value.substring (ta.selectionEnd);
59 if (se) {
60 ta.setSelectionRange (ss, ss + added.length);
61 } else {
62 ta.setSelectionRange (ss + added.length, ss + added.length);
63 }
64 ta.scrollTop = st;
65 ta.focus ();
66 }; // button.onclick
67 container.appendChild (button);
68 }
69 } // createToolbar
70
71 function initializeHatenaStar () {
72 if (!window.Hatena) {
73 window.Hatena = {};
74 }
75 if (!Hatena.Star) {
76 Hatena.Star = {};
77 }
78 if (!Hatena.Star.onLoadFunctions) {
79 Hatena.Star.onLoadFunctions = [];
80 }
81
82 Hatena.Star.onLoadFunctions.push (function () {
83 /*
84 if (Ten.DOM.loaded) {
85 Ten.DOM.loaded = false;
86 Ten.DOM.addObserver ();
87 }
88 */
89
90 Hatena.Star.SiteConfig = {
91 entryNodes: {
92 '' /* body */: {
93 uri: 'h1 a',
94 title: 'h1',
95 container: '.tools' /* .nav.tools */
96 }
97 }
98 };
99
100 /*
101 var realLoadNewEntries = Hatena.Star.EntryLoader.loadNewEntries;
102 Hatena.Star.EntryLoader.loadNewEntries = function (node) {
103 if (!node) {
104 node = document.documentElement;
105 }
106 realLoadNewEntries.apply (this, [node]);
107 };
108 */
109 setTimeout (function () {
110 Ten.DOM.dispatchEvent ('onload');
111 }, 1);
112 }); // Hatena.Star.onLoadFunctions.push'ed function
113
114 var hsScript = document.createElement ('script');
115 hsScript.defer = true;
116 hsScript.src = 'http://s.hatena.ne.jp/js/HatenaStar.js';
117 document.documentElement.lastChild.appendChild (hsScript);
118
119 /*
120 In SuikaWiki, a WikiName can be associated with multiple WikiPages,
121 while a WikiPage can be associated with multiple WikiNames. It would
122 be desired to associate Hatena Stars with WikiPages in theory.
123 However, WikiPages do not have permalinks at the moment.
124
125 See <http://suika.fam.cx/%7Ewakaba/wiki/sw/n/%E3%81%AF%E3%81%A6%E3%81%AA%E3%82%B9%E3%82%BF%E3%83%BC#anchor-2>.
126 */
127 } // initializeHatenaStar
128
129 function enableHTML5Support () {
130 window.TEROnLoad = function () {
131 new TER.Delta (document.body);
132 }; // window.TEROnLoad
133
134 var timeScript = document.createElement ('script');
135 timeScript.defer = true;
136 timeScript.charset = 'utf-8';
137 timeScript.src = 'http://suika.fam.cx/www/style/ui/time.js';
138 document.documentElement.lastChild.appendChild (timeScript);
139 } // enableHTML5Support
140
141 /* Hack for IE */
142 document.createElement ('time');

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24