2
** InkWeb - Inkscape's Javscript features for the open vector web
4
** Copyright (C) 2009 Aurelio A. Heckert, aurium (a) gmail dot com
6
** ********* Bugs and New Fetures *************************************
7
** If you found any bug on this script or if you want to propose a
8
** new feature, please report it in the inkscape bug traker
9
** https://bugs.launchpad.net/inkscape/+filebug
10
** and assign that to Aurium.
11
** ********************************************************************
13
** This program is free software: you can redistribute it and/or modify
14
** it under the terms of the GNU Lesser General Public License as published
15
** by the Free Software Foundation, either version 3 of the License, or
16
** (at your option) any later version.
18
** This program is distributed in the hope that it will be useful,
19
** but WITHOUT ANY WARRANTY; without even the implied warranty of
20
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
** GNU Lesser General Public License for more details.
23
** You should have received a copy of the GNU Lesser General Public License
24
** along with this program. If not, see <http://www.gnu.org/licenses/>.
32
svg: "http://www.w3.org/2000/svg",
33
sodipodi: "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd",
34
inkscape: "http://www.inkscape.org/namespaces/inkscape",
35
cc: "http://creativecommons.org/ns#",
36
dc: "http://purl.org/dc/elements/1.1/",
37
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
38
xlink: "http://www.w3.org/1999/xlink",
39
xml: "http://www.w3.org/XML/1998/namespace"
44
InkWeb.el = function (tag, attributes) {
45
// A helper to create SVG elements
46
var element = document.createElementNS( this.NS.svg, tag );
47
for ( var att in attributes ) {
50
attributes.parent.appendChild( element );
53
element.appendChild( document.createTextNode( attributes.text ) );
56
element.setAttribute( att, attributes[att] );
62
InkWeb.reGetStyleAttVal = function (att) {
63
return new RegExp( "(^|.*;)[ ]*"+ att +":([^;]*)(;.*|$)" )
66
InkWeb.getStyle = function (el, att) {
67
// This method is needed because el.style is only working
68
// to HTML style in the Firefox 3.0
69
if ( typeof(el) == "string" )
70
el = document.getElementById(el);
71
var style = el.getAttribute("style");
72
var match = this.reGetStyleAttVal(att).exec(style);
80
InkWeb.setStyle = function (el, att, val) {
81
if ( typeof(el) == "string" )
82
el = document.getElementById(el);
83
var style = el.getAttribute("style");
84
re = this.reGetStyleAttVal(att);
85
if ( re.test(style) ) {
86
style = style.replace( re, "$1"+ att +":"+ val +"$3" );
88
style += ";"+ att +":"+ val;
90
el.setAttribute( "style", style );
94
InkWeb.transmitAtt = function (conf) {
95
conf.att = conf.att.split( /\s+/ );
96
if ( typeof(conf.from) == "string" )
97
conf.from = document.getElementById( conf.from );
99
conf.to = [ conf.to ];
100
for ( var toEl,elN=0; toEl=conf.to[elN]; elN++ ) {
101
if ( typeof(toEl) == "string" )
102
toEl = document.getElementById( toEl );
103
for ( var i=0; i<conf.att.length; i++ ) {
104
var val = this.getStyle( conf.from, conf.att[i] );
106
this.setStyle( toEl, conf.att[i], val );
108
val = conf.from.getAttribute(conf.att[i]);
109
toEl.setAttribute( conf.att[i], val );
115
InkWeb.setAtt = function (conf) {
116
if ( ! conf.el.join )
117
conf.to = [ conf.el ];
118
conf.att = conf.att.split( /\s+/ );
119
conf.val = conf.val.split( /\s+/ );
120
for ( var el,elN=0; el=conf.el[elN]; elN++ ) {
121
if ( typeof(el) == "string" )
122
el = document.getElementById( el );
123
for ( var att,i=0; att=conf.att[i]; i++ ) {
136
el.setAttribute( att, conf.val[i] );
138
this.setStyle( el, att, conf.val[i] );
144
InkWeb.moveElTo = function (startConf) {
145
if ( typeof(startConf) == "string" ) {
146
// startConf may be only a element Id, to timeout recursive calls.
147
var el = document.getElementById( startConf );
149
if ( typeof(startConf.el) == "string" )
150
startConf.el = document.getElementById( startConf.el );
151
var el = startConf.el;
153
if ( ! el.inkWebMoving ) {
158
var conf = el.inkWebMoving;
159
if ( conf.step == 0 ) {
160
conf.x = startConf.x;
161
conf.y = startConf.y;
162
// dur : duration of the animation in seconds
163
if ( startConf.dur ) { conf.dur = startConf.dur }
164
else { conf.dur = 1 }
165
// steps : animation steps in a second
166
if ( startConf.stepsBySec ) { conf.stepsBySec = startConf.stepsBySec }
167
else { conf.stepsBySec = 16 }
168
conf.sleep = Math.round( 1000 / conf.stepsBySec );
169
conf.steps = conf.dur * conf.stepsBySec;
170
var startPos = el.getBBox();
171
conf.xInc = ( conf.x - startPos.x ) / conf.steps;
172
conf.yInc = ( conf.y - startPos.y ) / conf.steps;
173
conf.transform = el.transform.baseVal.consolidate();
174
if ( ! conf.transform ) {
175
conf.transform = el.ownerSVGElement.createSVGTransform();
177
el.transform.baseVal.clear();
178
el.transform.baseVal.appendItem(conf.transform);
180
if ( conf.step < conf.steps ) {
182
conf.transform.matrix.e += conf.xInc;
183
conf.transform.matrix.f += conf.yInc;
184
try{ el.ownerSVGElement.forceRedraw() }
185
catch(e){ this.log(e, "this "+el.ownerSVGElement+" has no forceRedraw().") }
186
conf.timeout = setTimeout( 'InkWeb.moveElTo("'+el.id+'")', conf.sleep );
188
delete el.inkWebMoving;
192
InkWeb.log = function () { /* if you need that, use the inkweb-debug.js too */ }