There is the part of my code which works perfectly
var image_mini = $('#map_mini');
var image_full = $('#map_full');
function state_change(data) {
// This is just part of code which show idea
image_mini.mapster(data.state);
}
// This is full block of code, works correct
$("#map_full").mapster(
$.extend({}, options, {
onStateChange: state_change
})
);
Now I need to enhance function state_change so, that it fill recive second agrument with image variable, which will be use insted of the directly writed image_mini.
Something like this (the code below is WRONG), but with CORRECT syntax code:
function state_change(data, working_image) {
working_image.mapster(...);
}
$("#map_full").mapster(
$.extend({}, options, {
onStateChange: state_change, image_mini
})
);
I feel me lamer, but I haven’t found example of correct sintax for passing two variables in such onStateChange… I tried some ideas, but it didn’t work correctly.
Please help!
==============================
Added later:
Looks like my idea wasn’t understood correctly, so I write more of code:
var image_mini = $('#map_mini');
var image_full = $('#map_full');
function state_change(data, working_image) {
working_image.mapster(data.state);
}
$("#map_full").mapster(
$.extend({}, options, {
onStateChange: state_change, image_mini
})
);
$("#map_mini").mapster(
$.extend({}, options, {
onStateChange: state_change, image_full
})
);
This is idea of what I want: both images must be crosslinked, so changes on one will be showed on both of them.
onStateChange: state_change, image_full
This is WRONG, I ask about correct syntax for the task.
It might not be as pretty, but you can do this using:
EDIT
To explain, your first version of code reads like this:
What happens here is that whenever
onStateChangefires, it calls thestate_changefunction. If this follows general jQuery parlance, then that function gets passed the jQuery event object as the function’s first parameter. In this case, that event object would resolve as thedataargument in yourstate_changefunction declaration.My code above, follows the same logic:
So when
onStateChangefires, it’ll call that anonymous function, and pass in the event object as the first argument. This will resolve aseinside the handler function. Therefore:… performs mostly the same thing with respect to the event object. When the
onStateChangeevent fires, the handler gets the event object ase, which it will then pass to the call tostate_change. That’ll resolve todatainsidestate_changeas a result, and will not change how you use the original function much.This way, however, we’re free to pass in additional arguments into the call to
state_change, like throwing inimage_minior whatever.