summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a38766e)
raw | patch | inline | side by side (parent: a38766e)
author | aurium <aurium@users.sourceforge.net> | |
Thu, 26 Mar 2009 22:22:45 +0000 (22:22 +0000) | ||
committer | aurium <aurium@users.sourceforge.net> | |
Thu, 26 Mar 2009 22:22:45 +0000 (22:22 +0000) |
share/extensions/inkweb.js | patch | blob | history | |
share/extensions/inkwebeffect.py | patch | blob | history |
index d398d5f506cbbe99e5375e991bc2f4bb82bef4d0..dfadd4a7f0e4d928242d54d1bbabd10a17b3d7b4 100644 (file)
};
+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 );
}
+
index 65176652fb61624318b3bbe1171d4d323150ab7e..5fbb8db8be5e3b11d445ffb0dee1567864c05ea8 100644 (file)
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
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)