OSDN Git Service

Merge branch 'master' into develop
[sie/sie.git] / tool / inlinesvg / svginhtml.js
1 /*SIE svginhtml.js - SVG in HTML LGPL2.1 & GPL1.1 & Mozilla Public Lisence*/\r
2 /* ***** BEGIN LICENSE BLOCK *****\r
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1\r
4  *\r
5  * The contents of this file are subject to the Mozilla Public License Version\r
6  * 1.1 (the "License"); you may not use this file except in compliance with\r
7  * the License. You may obtain a copy of the License at\r
8  * http://www.mozilla.org/MPL/\r
9  *\r
10  * Software distributed under the License is distributed on an "AS IS" basis,\r
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License\r
12  * for the specific language governing rights and limitations under the\r
13  * License.\r
14  *\r
15  * Contributor(s):DHRNAME revulo\r
16  *\r
17  * Alternatively, the contents of this file may be used under the terms of\r
18  * either of the GNU General Public License Version 2 or later (the "GPL"),\r
19  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),\r
20  * in which case the provisions of the GPL or the LGPL are applicable instead\r
21  * of those above. If you wish to allow use of your version of this file only\r
22  * under the terms of either the GPL or the LGPL, and not to allow others to\r
23  * use your version of this file under the terms of the MPL, indicate your\r
24  * decision by deleting the provisions above and replace them with the notice\r
25  * and other provisions required by the GPL or the LGPL. If you do not delete\r
26  * the provisions above, a recipient may use your version of this file under\r
27  * the terms of any one of the MPL, the GPL or the LGPL.\r
28  *\r
29  * ***** END LICENSE BLOCK ***** */\r
30 function _wo(){\r
31   var sc = document.getElementsByTagName("script"), source = "";\r
32   for (var i=0;i<sc.length;++i) {\r
33     if (sc[i].getAttribute("type") === "text/svg") {\r
34       source = sc[i].text.replace(/<svg[^>]*/g, (function(s) {\r
35                 s = s.replace(/xmlns(\:xlink)?=["'][^"']+?["']/g, "").replace(/<svg/, "");\r
36                 s = '<script type="image/svg+xml"' +s+ '><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +s;\r
37                 return s;\r
38              }))\r
39              .replace(/<\/svg>/g, "</svg></script>")\r
40              .replace(/<\/(body|html)>/g, "");\r
41     }\r
42   }\r
43   if (navigator.userAgent.indexOf('WebKit') > -1 || navigator.userAgent.indexOf('Safari') > -1) { //WebKit系ならば、Ajaxを使って自分自身のページを再読み込み\r
44     var xmlhttp = new XMLHttpRequest();\r
45     xmlhttp.open("GET", document.location.href, true);\r
46     xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");\r
47     xmlhttp.onreadystatechange = function() {\r
48       if ((xmlhttp.readyState === 4) && (xmlhttp.status === 200)) {\r
49         _webkit_wo(xmlhttp.responseText);\r
50       }\r
51     };\r
52     xmlhttp.send(null);\r
53     return;\r
54   }\r
55   document.getElementById("hogehoge").innerHTML = source;\r
56   var isOpera = (window.opera !== void 0); //Operaだったらtrueを返す\r
57   if (isOpera){\r
58     NAIBU._main();\r
59   }\r
60 };\r
61 function _webkit_wo(content) {\r
62   var source = "";\r
63   source = content.replace(/<svg[^>]*/g, (function(s) {\r
64               s = s.replace(/xmlns(\:xlink)?=["'][^"']+?["']/g, "").replace(/<svg/, "");\r
65               s = '<script type="image/svg+xml"' +s+ '><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' +s;\r
66               return s;\r
67            }))\r
68            .replace(/<\/svg>/g, "</svg></script>")\r
69            .replace(/<\/(body|html)>/g, "");\r
70   var n = source.indexOf("svginhtml.js");\r
71   source = source.substring(n+24, source.length-1);\r
72   document.getElementById("hogehoge").innerHTML = source;\r
73   NAIBU._main();\r
74 };\r
75 if (navigator.userAgent.indexOf('Chrome') === -1) { //WebKit系ならば、Ajaxを使って自分自身のページを再読み込み\r
76   window.onload = _wo;\r
77   document.write('<div id="hogehoge"></div>');\r
78   document.write('<script type="text/svg"><p style="display:none;">n</p>');\r
79 }