Code

group recognition to a more faster work with web-transmit-att extension.
authoraurium <aurium@users.sourceforge.net>
Wed, 8 Apr 2009 21:40:18 +0000 (21:40 +0000)
committeraurium <aurium@users.sourceforge.net>
Wed, 8 Apr 2009 21:40:18 +0000 (21:40 +0000)
share/extensions/inkweb.js
share/extensions/web-transmit-att.inx
share/extensions/web-transmit-att.py

index 7b53153e748685d0d5d14a6bfd57bf37ea0d61b4..10eaf9d01e4ce83977e1a99f29ff986d5e993b35 100644 (file)
@@ -67,18 +67,22 @@ InkWeb.setStyle = function (el, att, val) {
 }
 
 InkWeb.transmitAtt = function (conf) {
+  conf.att = conf.att.split( /\s+/ );
   if ( typeof(conf.from) == "string" )
     conf.from = document.getElementById( conf.from );
-  if ( typeof(conf.to) == "string" )
-    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 );
+  if ( ! conf.to.join )
+    conf.to = [ conf.to ];
+  for ( var toEl,elN=0; toEl=conf.to[elN]; elN++ ) {
+    if ( typeof(toEl) == "string" )
+      toEl = document.getElementById( toEl );
+    for ( var i=0; i<conf.att.length; i++ ) {
+      var val = this.getStyle( conf.from, conf.att[i] );
+      if ( val ) {
+        this.setStyle( toEl, conf.att[i], val );
+      } else {
+        val = conf.from.getAttribute(conf.att[i]);
+        toEl.setAttribute( conf.att[i], val );
+      }
     }
   }
 }
index 0c0a4e0d136423b7195f12726c5721a92b2fb84c..205df8d816e5f5d43dd8ca45e2fbf2525d80e2cf 100644 (file)
     <_item value="prepend">Run it before</_item>
     <_item value="replace">Replace</_item>
   </param>
+  <_param name="help" type="description">The next parameter is useful when you select more then two elements.</_param>
+  <param name="from-and-to" type="enum" _gui-text="Who transmit to Who?">
+    <_item value="g-to-one">All tramsmit to the last</_item>
+    <_item value="one-to-g">The first transmit to all</_item>
+  </param>
   <effect>
     <object-type>all</object-type>
     <effects-menu>
index 830085fab07b2e959a693f30b8426c3938fe8258..9c7844dfc3ad96b6e32650e104bf161fda306da1 100644 (file)
@@ -36,6 +36,10 @@ class InkWebTransmitAtt(inkwebeffect.InkWebEffect):
                         action="store", type="string",
                         dest="compatibility", default="append",
                         help="Compatibility with previews code to this event.")
+        self.OptionParser.add_option("-t", "--from-and-to",
+                        action="store", type="string",
+                        dest="from_and_to", default="g-to-one",
+                        help='Who transmit to Who? "g-to-one" All tramsmit to the last. "one-to-g" The first transmit to all.')
 
     def effect(self):
       self.ensureInkWebSupport()
@@ -44,20 +48,31 @@ class InkWebTransmitAtt(inkwebeffect.InkWebEffect):
         inkwebeffect.inkex.errormsg(_("You must to select at least two elements."))
         exit(1)
 
-      elFrom = self.selected[ self.options.ids[0] ]
-      idTo = self.options.ids[1]
+      elFrom = []
+      idTo = []
+      if self.options.from_and_to == "g-to-one":
+        # All tramsmit to the last
+        for selId in self.options.ids[:-1]:
+          elFrom.append( self.selected[selId] )
+        idTo.append( self.options.ids[-1] )
+      else:
+        # The first transmit to all
+        elFrom.append( self.selected[ self.options.ids[0] ] )
+        for selId in self.options.ids[1:]:
+          idTo.append( selId )
 
-      prevEvCode = elFrom.get( self.options.when )
-      if prevEvCode == None: prevEvCode = ""
+      evCode = "InkWeb.transmitAtt({from:this, to:['"+ "','".join(idTo) +"'], att:'"+self.options.att+"'})"
 
-      evCode = "InkWeb.transmitAtt({from:this, to:'"+idTo+"', att:'"+self.options.att+"'})"
+      for el in elFrom:
+        prevEvCode = el.get( self.options.when )
+        if prevEvCode == None: prevEvCode = ""
 
-      if self.options.compatibility == 'append':
-        evCode = prevEvCode +";\n"+ evCode
-      if self.options.compatibility == 'prepend':
-        evCode = evCode +";\n"+ prevEvCode
+        if self.options.compatibility == 'append':
+          elEvCode = prevEvCode +";\n"+ evCode
+        if self.options.compatibility == 'prepend':
+          elEvCode = evCode +";\n"+ prevEvCode
 
-      elFrom.set( self.options.when, evCode )
+        el.set( self.options.when, elEvCode )
 
 if __name__ == '__main__':
     e = InkWebTransmitAtt()