Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /SvgViewer.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (hide annotations) (download) (as text)
Fri Jul 16 21:02:43 2010 UTC (13 years, 8 months ago) by isao-hara
File MIME type: application/x-javascript
File size: 3740 byte(s)
SvgViewer.js fixed
1 isao-hara 2 /*
2     * SvgViewer.js
3    
4     iSlideMaker
5     http://sourceforge.jp/projects/islidemaker/simple/
6    
7     Copyright(c) 2010, Isao Hara, isao-hara@users.sourceforge.jp
8    
9     All rights reserved. This program is made available under the terms of the
10     Eclipse Public License v1.0 which accompanies this distribution, and is
11     available at http://www.eclipse.org/legal/epl-v10.html
12    
13     Contributors: Isao Hara.
14    
15     */
16    
17     var systemDB;
18     var currentMode;
19     var editarea_w=80;
20     var editarea_h=10;
21     var MainTitle="Simple SVG Editor";
22    
23     var targetItem=null;
24     var sx=0;
25     var sy=0;
26    
27     function initEditor(name, dispname, size){
28     systemDB = initDB(name, dispname, size);
29     }
30    
31     // initialize a database
32     function initDB(name, dispname, size) {
33     try {
34     if (!window.openDatabase) {
35     alert('not supported');
36     } else {
37     var version = '1.0';
38     var myDB = openDatabase(name, version, dispname, size);
39     }
40     } catch(e) {
41     if (e == INVALID_STATE_ERR) { // Version number mismatch.
42     alert("Invalid database version.");
43     } else {
44     alert("Unknown error "+e+".");
45     }
46     return null;
47     }
48    
49     createTables(myDB);
50     return myDB;
51     }
52    
53     function createTables(db) {
54     if (0) dropTables(db);
55    
56     db.transaction(
57     function (transaction) {
58     transaction.executeSql('CREATE TABLE IF NOT EXISTS files(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, filedata_id INTEGER NOT NULL, deleted INTEGER NOT NULL DEFAULT 0);', [], nullDataHandler, killTransaction);
59     transaction.executeSql('CREATE TABLE IF NOT EXISTS filedata(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, datablob BLOB NOT NULL DEFAULT "");', [], nullDataHandler, errorHandler);
60     }
61     );
62     }
63    
64     function dropTables(db) {
65     db.transaction(
66     function (transaction) {
67     transaction.executeSql('DROP TABLE files;');
68     transaction.executeSql('DROP TABLE filedata;');
69     }
70     );
71     }
72    
73     function getFile(name, func, db){
74     var myDB = db;
75     if(!db) myDB = systemDB;
76    
77     var datadiv = document.getElementById('tempdata');
78     if(datadiv) datadiv.setAttribute('lfname', name);
79    
80     myDB.transaction(
81     function (transaction) {
82     transaction.executeSql('SELECT * from files, filedata where files.name=? and files.filedata_id = filedata.id;', [name], eval(func), errorHandler);
83     }
84     );
85     }
86    
87     // Error Handlers
88     function killTransaction(transaction, error){
89     return true;
90     }
91    
92     function errorHandler(transaction, error){
93     alert('Oops. Error was '+error.message+' (Code '+error.code+')');
94    
95     var we_think_this_error_is_fatal = true;
96     if (we_think_this_error_is_fatal) return true;
97     return false;
98     }
99    
100     function nullDataHandler(transaction, results){
101     }
102    
103     function previewFile(id, data){
104     var preview = document.getElementById(id);
105     removeChildNodes(id);
106    
107     preview.style.display='block';
108     preview.style.position='absolute';
109     preview.style.top='180px';
110     preview.style.width='80%';
111     preview.style.height='80%';
112    
113     var ele = toSVGElement(data, '100%','100%');
114    
115     preview.appendChild(ele);
116    
117     }
118    
119     function previewFileOld(id, data){
120     var preview = document.getElementById(id);
121     preview.innerHTML="";
122     preview.style.display='block';
123     preview.style.position='absolute';
124     preview.style.top='180px';
125     preview.style.width='80%';
126     preview.style.height='80%';
127     preview.innerHTML+=format_file(data);
128     }
129    
130    
131     function toSVGElement(str, w, h){
132 isao-hara 8 var xmlsvg = "xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\"";
133 isao-hara 2 var parser = new DOMParser();
134     var header = "<svg:svg width=\""+w+"\" height=\""+h+"\" "+xmlsvg+" id=\"svg_top\">"
135     var footer = "</svg:svg>";
136     var xmlDoc = parser.parseFromString(header+str+footer, "text/xml");
137     var xmlRoot = xmlDoc.documentElement;
138     var ele = document.importNode(xmlRoot,true);
139     return ele;
140     }
141    

Properties

Name Value
svn:executable *

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26