summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAur??lio A. Heckert <aurium@gmail.com>2009-03-26 22:22:45 +0000
committeraurium <aurium@users.sourceforge.net>2009-03-26 22:22:45 +0000
commit8daf4d76f2e7e989420933d877264d0610e932d2 (patch)
tree0b4f2fbb870198e1a91e0788e2684776bc983c1c
parentthis terminal submenu really saves us no space (diff)
downloadinkscape-8daf4d76f2e7e989420933d877264d0610e932d2.tar.gz
inkscape-8daf4d76f2e7e989420933d877264d0610e932d2.zip
the little InkWeb is now usable
(bzr r7564)
-rw-r--r--share/extensions/inkweb.js53
-rw-r--r--share/extensions/inkwebeffect.py12
2 files changed, 50 insertions, 15 deletions
diff --git a/share/extensions/inkweb.js b/share/extensions/inkweb.js
index d398d5f50..dfadd4a7f 100644
--- a/share/extensions/inkweb.js
+++ b/share/extensions/inkweb.js
@@ -34,17 +34,52 @@ var InkWeb = {
};
+InkWeb.reGetStyleAttVal = function (att) {
+ return new RegExp( "(^|.*;)[ ]*"+ att +":([^;]*)(;.*|$)" )
+}
+
+InkWeb.getStyle = function (el, att) {
+ // This method is needed because el.style is only working
+ // to HTML style in the Firefox 3.0
+ if ( typeof(el) == "string" )
+ el = document.getElementById(el);
+ var style = el.getAttribute("style");
+ var match = this.reGetStyleAttVal(att).exec(style);
+ if ( match ) {
+ return match[2];
+ } else {
+ return false;
+ }
+}
+
+InkWeb.setStyle = function (el, att, val) {
+ if ( typeof(el) == "string" )
+ el = document.getElementById(el);
+ var style = el.getAttribute("style");
+ re = this.reGetStyleAttVal(att);
+ if ( re.test(style) ) {
+ style = style.replace( re, "$1"+ att +":"+ val +"$3" );
+ } else {
+ style += ";"+ att +":"+ val;
+ }
+ el.setAttribute( "style", style );
+ return val
+}
+
InkWeb.transmitAtt = function (conf) {
if ( typeof(conf.from) == "string" )
- conf.from = document.getElementById(conf.from);
+ conf.from = document.getElementById( conf.from );
if ( typeof(conf.to) == "string" )
- conf.to = document.getElementById(conf.to);
- var s = conf.from.getAttribute("style")
- var re = new RegExp("(^|.*;)[ ]*"+conf.att+":([^;]*)(;.*|$)")
- if ( re.test(s) ) {
- var val = s.replace( re, "$2" );
- } else {
- var val = conf.from.getAttribute(conf.att);
+ conf.to = document.getElementById( conf.to );
+ conf.att = conf.att.split( /\s+/ )
+ for ( var i=0; i<conf.att.length; i++ ) {
+ var val = this.getStyle( conf.from, conf.att[i] );
+ if ( val ) {
+ this.setStyle( conf.to, conf.att[i], val );
+ } else {
+ val = conf.from.getAttribute(conf.att[i]);
+ conf.to.setAttribute( conf.att[i], val );
+ }
}
- conf.to.setAttribute( conf.att, val );
}
+
diff --git a/share/extensions/inkwebeffect.py b/share/extensions/inkwebeffect.py
index 65176652f..5fbb8db8b 100644
--- a/share/extensions/inkwebeffect.py
+++ b/share/extensions/inkwebeffect.py
@@ -25,6 +25,7 @@ class InkWebEffect(inkex.Effect):
self.reUpdateJS = '/\\*\\s* inkweb.js [^*]* InkWebEffect:AutoUpdate \\s*\\*/'
def mustAddInkWebJSCode(self, scriptEl):
+ #inkex.errormsg( re.search(self.reUpdateJS, scriptEl.text) )
if not scriptEl.text: return True
if len(scriptEl.text) == 0: return True
if re.search(self.reUpdateJS, scriptEl.text): return True
@@ -40,20 +41,19 @@ class InkWebEffect(inkex.Effect):
def ensureInkWebSupport(self):
# Search for the script tag with the inkweb.js code:
- scriptEl = False
- scripts = self.document.xpath('//script', namespaces=inkex.NSS)
+ scriptEl = None
+ scripts = self.document.xpath('//svg:script', namespaces=inkex.NSS)
for s in scripts:
- inkex.errormsg(s)
if re.search(self.reUpdateJS, s.text):
- inkex.errormsg("OK!")
scriptEl = s
- if not scriptEl:
+ if scriptEl is None:
root = self.document.getroot()
scriptEl = inkex.etree.Element( "script" )
scriptEl.set( "id", "inkwebjs" )
scriptEl.set( "type", "text/javascript" )
root.insert( 0, scriptEl )
- if self.mustAddInkWebJSCode(scriptEl): self.addInkWebJSCode(scriptEl)
+ if self.mustAddInkWebJSCode(scriptEl):
+ self.addInkWebJSCode(scriptEl)