diff options
| author | Aur??lio A. Heckert <aurium@gmail.com> | 2009-03-26 22:22:45 +0000 |
|---|---|---|
| committer | aurium <aurium@users.sourceforge.net> | 2009-03-26 22:22:45 +0000 |
| commit | 8daf4d76f2e7e989420933d877264d0610e932d2 (patch) | |
| tree | 0b4f2fbb870198e1a91e0788e2684776bc983c1c /share/extensions/inkweb.js | |
| parent | this terminal submenu really saves us no space (diff) | |
| download | inkscape-8daf4d76f2e7e989420933d877264d0610e932d2.tar.gz inkscape-8daf4d76f2e7e989420933d877264d0610e932d2.zip | |
the little InkWeb is now usable
(bzr r7564)
Diffstat (limited to 'share/extensions/inkweb.js')
| -rw-r--r-- | share/extensions/inkweb.js | 53 |
1 files changed, 44 insertions, 9 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 ); } + |
