From: aurium Date: Thu, 26 Mar 2009 22:22:45 +0000 (+0000) Subject: the little InkWeb is now usable X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0d882ce92a1b44b4822297a7233bf5e306d4624b;p=inkscape.git the little InkWeb is now usable --- 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