On Oct 30, 12:35 am, Remy Blank <[EMAIL PROTECTED]> wrote:
> Martin S. wrote:
> > However I need to do somehing like this:
>
> > a = GetElementById("foo-1");
> > b = new SomeClassWhichNeedsAnElement(a);
> > b.doSomething();
>
> Usually, you want to perform some operation like above on *every*
> element injected. Using jQuery, you would do this:
>
> jQuery(document).ready(function($) {
> $(".foo").each(function() {
> var b = new SomeClassWhichNeedsAnElement(this);
> b.doSomething();
> };
>
> });
>
> The selector $(".foo") will generate a list of all elements with the
> class "foo". The .each() function will call its argument once for each
> of the elements in the list. The element will be passed as "this" to the
> function.
I see your point, thanks for the example.
In my case the different div's contain different Google Maps with
different locations, markers, etc.,
so different methods must be called with different values.
Let me think,
maybe it could be done like this:
jQuery(document).ready(function($) {
var n = 0;
$(".foo").each(function() {
var b = new SomeClassWhichNeedsAnElement(this);
if (n == 0) {
b.doSomething('value 1');
}
elsif (n == 1) {
b.doSomething(value 2');
b.doMore();
}
n = n + 1;
};
});
Because the actual per-map javascript code is produced by the Trac
macro it is in an own <script> tag and not together like above,
but this could be fixed by creating an special init function for every
map and then call it from the above script while providing the 'this'
pointer.
But the function need to have unique names and we are back at the
original ID problem.
Otherwise, I could create a global array of function pointers and let
every macro push an function reference in it, which is then executed
like this:
// Header
var funcarray = ( );
jQuery(document).ready(function($) {
$(".foo").each(function() {
if (funcarray[0]) {
var f = funcarray.shift();
f(this);
}
};
});
// Macro 1
funcarrary.push( function(this) {
map = new GMap2(this);
map.setcenter(10.000,30.000);
});
// Macro 2
funcarrary.push( function(this) {
map = new GMap2(this);
map.setcenter(25.230,12.346);
map.addoverlay( .... );
});
What do you think about it?
Best Regards,
Martin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---