/[suikacvs]/markup/html/html5/spec-ja/ja-script.js
Suika

Diff of /markup/html/html5/spec-ja/ja-script.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by wakaba, Sun Oct 26 08:44:19 2008 UTC revision 1.6 by wakaba, Mon Oct 27 04:52:39 2008 UTC
# Line 1  Line 1 
1  window.onload = function () {  window.addEventListener ('load', function () {
2    createJaHashIndex ();    createJaHashIndex ();
3    
4    var req = new XMLHttpRequest ();    var req = new XMLHttpRequest ();
# Line 6  window.onload = function () { Line 6  window.onload = function () {
6    req.onreadystatechange = function () {    req.onreadystatechange = function () {
7      if (req.readyState == 4) {      if (req.readyState == 4) {
8        if (req.status >= 200 && req.status < 400) {        if (req.status >= 200 && req.status < 400) {
9          var updates = eval ('(' + req.responseText + ')');          applyJaUpdates (eval ('(' + req.responseText + ')'));
         for (var hash in updates) {  
           if (document.jaHashes[hash]) {  
             for (var i in document.jaHashes[hash]) {  
               applyJaEntry (document.jaHashes[hash][i], updates[hash]);  
             }  
           }  
           if (document.jaRealHashes[hash]) {  
             for (var i in document.jaRealHashes[hash]) {  
               applyJaEntry (document.jaRealHashes[hash][i], updates[hash]);  
             }  
           }  
         }  
10        }        }
11      }      }
12    }; // onreadystatechange    }; // onreadystatechange
13    req.send (null);    req.send (null);
14  }; // window.onload  }, false); // window.onload
15    
16  document.documentElement.ondblclick = function (event) {  document.documentElement.ondblclick = function (event) {
17    var container = getEJContainer (event.target);    var container = getEJContainer (event.target);
# Line 74  function insertJaForm (targetNode) { Line 62  function insertJaForm (targetNode) {
62    
63    form.innerHTML = "<p><label>Original text:<br><textarea name=en></textarea></label><br>\    form.innerHTML = "<p><label>Original text:<br><textarea name=en></textarea></label><br>\
64        (<label><input name=pattern type=checkbox> Pattern</label><span> <button type=button>Load original text</button></span>)\        (<label><input name=pattern type=checkbox> Pattern</label><span> <button type=button>Load original text</button></span>)\
65        <p><label>Translated text:<br><textarea name=ja></textarea></label><p><label>Tags:<br><textarea name=tags></textarea></label><p><button type=submit class=ja-save-button>Save and close</button> <button type=button class=ja-close-button>Close</button> (<output>Text not loaded yet</output>)";        <p><label>Translated text:<br><textarea name=ja></textarea></label><p><label>Tags:<br><textarea name=tags></textarea></label><p><button type=button class=ja-save-button>Save and close</button> <button type=button class=ja-close-button>Close</button> (<output>Text not loaded yet</output>; see also <a href='edit/#license'>license</a>)";
66        
67    form.onchange = function () {    form.onchange = function () {
68      form.jaFormChanged = true;      form.jaFormChanged = true;
# Line 115  function insertJaForm (targetNode) { Line 103  function insertJaForm (targetNode) {
103        v += '&pattern=on';        v += '&pattern=on';
104      }      }
105    
106        form.getElementsByTagName ('output')[0].firstChild.data
107            = 'Saving...';
108    
109      var req = new XMLHttpRequest ();      var req = new XMLHttpRequest ();
110      req.open ('POST', 'edit2/', true);      req.open ('POST', 'edit2/', true);
111      req.onreadystatechange = function () {      req.onreadystatechange = function () {
# Line 122  function insertJaForm (targetNode) { Line 113  function insertJaForm (targetNode) {
113          form.getElementsByTagName ('output')[0].firstChild.data          form.getElementsByTagName ('output')[0].firstChild.data
114              = 'Save: ' + req.status + ' ' + req.statusText;              = 'Save: ' + req.status + ' ' + req.statusText;
115          if (req.status >= 200 && req.status < 400) {          if (req.status >= 200 && req.status < 400) {
           applyJaEntry (targetNode, {ja: ta[1].value});  
116            targetNode.jaForm = null;            targetNode.jaForm = null;
117            form.parentNode.removeChild (form);            form.style.display = 'none';
118              setTimeout (function () {
119                form.parentNode.removeChild (form);
120                applyJaUpdates (eval ('(' + req.responseText + ')'));
121              }, 100);
122          }          }
123        }        }
124      }; // onreadystatechange      }; // onreadystatechange
# Line 175  function loadTextByHash (form, hash) { Line 169  function loadTextByHash (form, hash) {
169  function insertInterfaceElement (insertedElement, contextElement) {  function insertInterfaceElement (insertedElement, contextElement) {
170    var parent = contextElement.parentNode;    var parent = contextElement.parentNode;
171    var prev = contextElement;    var prev = contextElement;
172    /*
173    while (true) {    while (true) {
174      if (!parent.parentNode) break;      if (!parent.parentNode) break;
175      var ln = parent.nodeName.toLowerCase ();      var ln = parent.nodeName.toLowerCase ();
# Line 186  function insertInterfaceElement (inserte Line 181  function insertInterfaceElement (inserte
181        break;        break;
182      }      }
183    }    }
184    */
185    parent.insertBefore (insertedElement, prev.nextSibling);    parent.insertBefore (insertedElement, prev.nextSibling);
186  } // insertInterfaceElement  } // insertInterfaceElement
187    
188    function applyJaUpdates (updates) {
189      for (var hash in updates) {
190        if (document.jaHashes[hash]) {
191          for (var i in document.jaHashes[hash]) {
192            applyJaEntry (document.jaHashes[hash][i], updates[hash]);
193          }
194        }
195        if (document.jaRealHashes[hash]) {
196          for (var i in document.jaRealHashes[hash]) {
197            applyJaEntry (document.jaRealHashes[hash][i], updates[hash]);
198          }
199        }
200      }
201    } // applyJaUpdates
202    
203  function applyJaEntry (targetNode, entry) {  function applyJaEntry (targetNode, entry) {
204    if (entry.isPattern) {    if (entry.isPattern || targetNode.nodeName == 'TR' /* find.cgi */) {
205      targetNode.className += ' ja-not-patched';      targetNode.className += ' ja-not-patched';
206    } else {    } else {
207      var en;      var en;
# Line 203  function applyJaEntry (targetNode, entry Line 213  function applyJaEntry (targetNode, entry
213          if (n.firstChild && n.firstChild.className == 'secno') {          if (n.firstChild && n.firstChild.className == 'secno') {
214            prefix = n.firstChild;            prefix = n.firstChild;
215          }          }
216          n.innerHTML = entry.ja;          n.innerHTML = formatJaText (entry.ja);
217          if (prefix) n.insertBefore (prefix, n.firstChild);          if (prefix) n.insertBefore (prefix, n.firstChild);
218          targetNode.className += ' ja-patched';          targetNode.className += ' ja-patched';
219          return;          return;
# Line 218  function applyJaEntry (targetNode, entry Line 228  function applyJaEntry (targetNode, entry
228      if (en.firstChild && en.firstChild.className == 'secno') {      if (en.firstChild && en.firstChild.className == 'secno') {
229        prefix = en.firstChild.cloneNode (true);        prefix = en.firstChild.cloneNode (true);
230      }      }
231      span.innerHTML = entry.ja;      span.innerHTML = formatJaText (entry.ja);
232      if (prefix) span.insertBefore (prefix, span.firstChild);      if (prefix) span.insertBefore (prefix, span.firstChild);
233      targetNode.appendChild (span);      targetNode.appendChild (span);
234      targetNode.className      targetNode.className
# Line 226  function applyJaEntry (targetNode, entry Line 236  function applyJaEntry (targetNode, entry
236              (/\bno-ja-translation\b/, 'has-ja-translation ja-patched');              (/\bno-ja-translation\b/, 'has-ja-translation ja-patched');
237    }    }
238  } // applyJaEntry  } // applyJaEntry
239    
240    function formatJaText (s) {
241      return s.replace
242          (/\[\[([A-Z ]+):([^\]]+)\]\]/g,
243           function (a, b, c) {
244             return "<em class=rfc2119 title=\"" + b + "\">" + c + "</em>";
245           });
246    } // formatJaText
247    
248    /*
249      Author: Wakaba <[email protected]>.
250      License: Copyright 2008 Wakaba.  You are granted a license to use,
251          reproduce and create derivative works of this script.
252      $Date$
253    */

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.6

[email protected]
ViewVC Help
Powered by ViewVC 1.1.24