I generalized it a bit more:
function IndexOf(arr, szMatch)
{
        for (var i in arr) 
        {
            if (arr[i] == szMatch)
                {
                        return i;
                }
        }
        return null;
}

var arrEventScripts = new Array();
function AddEventScript(EventObject, szEventType, szName, 
szScriptBody)
{
        if (IndexOf(arrEventScripts, szName) == null);
        {
                //add this
                arrEventScripts.push(szName);
                //add the script to the "AddScript" block since it 
doesn't yet exist;
                document.all("AddScript").text += "\nfunction " + 
szName + "(evt)\n{ " + szScriptBody + "}";
        }
        
        //add a listener for the script to the object;
        eval("EventObject.addEventListener('" + szEventType + "'," + 
szName + ", false );");
}



--- In [email protected], "Geoff Swenson" 
<[EMAIL PROTECTED]> wrote:
>
> This is what I just discovered, after tearing my hair out for a 
couple of
> days.
> 
> This is an utter hack, so if there is and easier way, I am all ears.
> 
> //add a stub script to your doc.(the dummy script is probably not 
necessary):
> 
> <script language="javascript" id="AddScript">function dummy() { 
return
> null;}</script>
> 
> //inside your label class, when you add the event:
> 
> //create a unique function name:
> var szOnClickName = this.DrawingObjectID + "_Click";
> 
> //create the function with the desired objects actually specified by
> //appending it to the stub script text. (InnerHTML does not work).
> 
> document.all("AddScript").text += "\nfunction " + szOnClickName +
> "(evt)\n{ var svgDoc = OpenSVG('" + this.DrawingObjectID + "');\n
> svgOnClick(svgDoc, evt);}";
> 
> //use eval to add the listener with the function you just created.
> eval("objBackgroundRect.addEventListener('click'," + szOnClickName 
+ ",
> false );");
> 
> function svgOnClick(theObj, theEvent)
> {
>       alert(theObj + "," + theEvent);
> }
> 
> function OpenSVG(szContainerID)
> {
>       try
>       {
>               return document.all(szContainerID).getSVGDocument();
>       }
>       catch (e)
>       {
>               //a_lert(e);
>               var answer = confirm("You probably don't have the SVG 
plugin.\nDo you
> want to install it now?")
>               if (answer)
>               {
>                       try
>                       {
>                               window.location.href =
> "http://download.adobe.com/pub/adobe/magic/svgviewer/win/3.x/3.03/en
/SVGView.exe";
>                       }
>                       catch(e)
>                       {
>                               alert("Could not open up plugin 
website");
>                               return false;
>                       }
>               }
>               return false;
>       }
> }
> 
> I just needed the parent embed object, but I think this would
> work with any object you need. But you do have to make sure that 
you run
> this sort of thing ONLY once when the object is created.
> 
> Geoff Swenson
> [EMAIL PROTECTED]
> 
> 
> >     I have 2 objects: one for the map (zoom/pan, ...), one for 
displaying
> >  labels (more objects to come :)). The purpose of the labels 
class is
> >  displaying a label of a map element like icons for restaurants,
> >  streetnames, rivers, ... . In the SVG map I use
> >  onclick=&quot;ShowLabel(evt)&quot;. How do I get this event 
handled by
> > the Label
> >  class.
> >
> >  This is the code for my labels (in a normal script file, not a 
js class
> >  yet):
> >
> >  /**
> >   * OnClick
> >   */
> >  function ShowLabel(evt) {
> >      var STROKEWIDTH = 2;
> >      var FONTSIZE = 15;
> >      var SPACEX = 5;
> >      var OPACITY = 1;
> >      var RX = 3;
> >      var RY = 3;
> >      var LINELENGTH = 10;
> >
> >      var group = svgdoc.createElement(&quot;g&quot;);
> >      group.setAttribute(&quot;id&quot;, &quot;label&quot; + 
labelCount);
> >      labelCount++;
> >      group.setAttribute(&quot;onclick&quot;,&quot;OnClose(evt)
&quot;);
> >
> >      var textNode =
> >  svgdoc.createTextNode(evt.target.getAttribute
(&quot;fme:NAME&quot;));
> >
> >      var text = svgdoc.createElement(&quot;text&quot;);
> >
> >      text.appendChild(textNode);
> >      text.setAttribute(&quot;x&quot;, evt.clientX -
> > text.getComputedTextLength() /
> >  2 - text.getComputedTextLength() * 0.25);
> >      text.setAttribute(&quot;y&quot;, evt.clientY - FONTSIZE + 1);
> >      text.setAttribute(&quot;fill&quot;,&quot;rgb(0,0,0)&quot;);
> >      text.setAttribute(&quot;opacity&quot;,1);
> >      text.setAttribute(&quot;font-size&quot;, FONTSIZE);
> >      text.setAttribute(&quot;pointer-
events&quot;,&quot;none&quot;);
> >
> >      var rect = svgdoc.createElement(&quot;rect&quot;);
> >       rect.setAttribute(&quot;x&quot;, evt.clientX -
> > text.getComputedTextLength() /
> >  2 - SPACEX);
> >      rect.setAttribute(&quot;y&quot;, evt.clientY - FONTSIZE * 
1.2 -
> > LINELENGTH);
> >      rect.setAttribute(&quot;width&quot;, 
text.getComputedTextLength() +
> > SPACEX * 2);
> >      rect.setAttribute(&quot;height&quot;, FONTSIZE + 
FONTSIZE*0.2);
> >      rect.setAttribute(&quot;opacity&quot;, OPACITY);
> >      rect.setAttribute(&quot;fill&quot;,&quot;rgb(255,255,255)
&quot;);
> >      rect.setAttribute(&quot;stroke&quot;,&quot;rgb(0,0,0)&quot;);
> >      rect.setAttribute(&quot;stroke-width&quot;,STROKEWIDTH);
> >      rect.setAttribute(&quot;rx&quot;,RX);
> >      rect.setAttribute(&quot;ry&quot;,RY);
> >
> >      var line = svgdoc.createElement(&quot;line&quot;);
> >      line.setAttribute(&quot;x1&quot;, evt.clientX);
> >      line.setAttribute(&quot;y1&quot;, evt.clientY);
> >      line.setAttribute(&quot;x2&quot;, evt.clientX);
> >      line.setAttribute(&quot;y2&quot;, evt.clientY - LINELENGTH);
> >      line.setAttribute(&quot;stroke&quot;, &quot;rgb(0,0,0)
&quot;);
> >      line.setAttribute(&quot;stroke-width&quot;, STROKEWIDTH);
> >
> >      var circle = svgdoc.createElement(&quot;circle&quot;);
> >      circle.setAttribute(&quot;cx&quot;, evt.clientX);
> >      circle.setAttribute(&quot;cy&quot;, evt.clientY);
> >      circle.setAttribute(&quot;r&quot;, 3);
> >      circle.setAttribute(&quot;stroke&quot;, &quot;rgb(0,0,0)
&quot;);
> >      circle.setAttribute(&quot;fill&quot;, &quot;rgb(255,255,255)
&quot;);
> >      circle.setAttribute(&quot;stroke-width&quot;, 2);
> >
> >      group.appendChild(rect);
> >      group.appendChild(line);
> >      group.appendChild(text);
> >      group.appendChild(circle);
> >
> >      svgdoc.getElementById(&quot;Names&quot;).appendChild(group);
> >  }
> >
> >  /**
> >   * OnClose
> >   */
> >  function OnClose(evt) {
> >      try {
> >
> >  svgdoc.getElementById(&quot;Names&quot;).removeChild
(svgdoc.getElementById(evt.currentTarget.getAttribute
(&quot;id&quot;)));
> >          labelCount--;
> >      } catch (exception) {
> >          alert(exception);
> >      }
> >  }
> >
> >
> >
>






------------------------ Yahoo! Groups Sponsor --------------------~--> 
Most low income households are not online. Help bridge the digital divide today!
http://us.click.yahoo.com/I258zB/QnQLAA/TtwFAA/1U_rlB/TM
--------------------------------------------------------------------~-> 

-----
To unsubscribe send a message to: [EMAIL PROTECTED]
-or-
visit http://groups.yahoo.com/group/svg-developers and click "edit my 
membership"
---- 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/svg-developers/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to