[Mapbender-dev] Working with jQuery in Mapbenders mainframe...
a testscript and a suggestion
Marc Jansen
jansen.marc at gmx.de
Tue Nov 13 08:55:28 EST 2007
Hi Christoph,
try this:
// a test setting
window.setTimeout(function() {
alert('working in parent');
$('#parentdiv', parent).each(function() {
alert(this);
}).append('<div>I have been created not using the context
parameter (I should be in the parent)</div>');
$('<div>second approach (parent)</div>').appendTo(
$('#parentdiv', parent) );
alert('working in child');
$('#iframediv').each( function() {
alert(this);
}).append('<div>I have been created not using the context
parameter (I should be in the child)</div>');
$('<div>second approach (child)</div>').appendTo( $('#iframediv') );
}, 3000 );
Please note that appendTo can take a jquery object as well.
post any code that is not working as desired / expected so we can fix it.
-- Marc
Christoph Baudson (WhereGroup) schrieb:
> Hi Marc,
>
> thanks for your test scripts.
>
> I have an additional question: As the magic of jQuery lies in
> chaining, I wonder if expressions like these could be done with the
> frame environment:
>
> $("<div>").addClass(currentWfsConf.g_label_id).text(currentWfsConf.g_label).appendTo("#wfsForm");
>
>
> (Disclaimer: this is untestedcompletely and I hope it's not all bad
> jQuery code)
>
> Can you create new tags in the frame, like $("<div>", parent)?
>
> Can you use the appendTo with a context parameter?
> I failed, but I may not yet have seen the light.
>
> Thanks for your contribution,
>
> Christoph
>
>
>
> Marc Jansen schrieb:
>> Hi devs,
>>
>> as discussed on monday there are certain things to be considered
>> when you want to use jQuery. Please rebuild this testcript(s):
>>
>> File 1 (the parent | mainframe in Mapbender):
>>
>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
>> "http://www.w3.org/TR/html4/strict.dtd">
>> <html>
>> <head>
>> <title>Test</title>
>> <script src="./tree21/jquery-1.2.1.pack.js"
>> type="text/javascript"></script>
>> </head>
>> <body>
>> <iframe src="test2.php">
>> </iframe>
>> <div id="parentdiv">I shall disappear first</div>
>> </body>
>> </html>
>>
>>
>> File 2 (the child | any frame embeded in Mapbenders mainframe):
>>
>> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
>> "http://www.w3.org/TR/html4/strict.dtd">
>> <html>
>> <head>
>> <title>Test</title>
>> <script type="text/javascript">
>> /**
>> * Map over parent's jquery to this frame's "$"/"jQuery".
>> * Keep the second parameter to work in other contexts.
>> *
>> * @todo check thoroughly.
>> * @author Marc Jansen <jansen at terrestris.de>
>> */
>> if (typeof $ == 'undefined' && typeof parent.$ != 'undefined' &&
>> typeof jQuery == 'undefined' && typeof parent.jQuery != 'undefined') {
>> jQuery = function(param, context) {
>> return parent.jQuery(param, context || window.document);
>> };
>> $ = jQuery;
>> }
>> // a test setting
>> window.setTimeout(function() {
>> alert('working in parent');
>> $('#parentdiv', parent).each(function() {
>> alert(this);
>> }).hide();
>> alert('working in child');
>> $('#iframediv').each( function() {
>> alert(this);
>> }).hide();
>> alert('has everything disappeared?');
>> }, 3000 );
>> </script>
>> </head>
>> <body>
>> <div id="iframediv">I shall disappear later</div>
>> </body>
>> </html>
>>
>> Try to rebuild the two files and you'll understand what is happening
>> here. Needs to be checked in detail!
>>
>> I suggest to test this further and to use this:
>> /**
>> * Map over parent's jquery to this frame's "$"/"jQuery".
>> * Keep the second parameter to work in other contexts.
>> *
>> * @todo check thoroughly.
>> * @author Marc Jansen <jansen at terrestris.de>
>> */
>> if (typeof $ == 'undefined' && typeof parent.$ != 'undefined' &&
>> typeof jQuery == 'undefined' && typeof parent.jQuery != 'undefined') {
>> jQuery = function(param, context) {
>> return parent.jQuery(param, context || window.document);
>> };
>> $ = jQuery;
>> }
>> when you want to use jQuery.
>>
>> Bye,
>>
>> -- Marc
>>
>> _______________________________________________
>> Mapbender_dev mailing list
>> Mapbender_dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapbender_dev
>
>
More information about the Mapbender_dev
mailing list