Thanks for your work!

Here's my problem.
I added a standard drupal block and inserted the code of Google Canlenar gadget in it.
It work as expected I can see calendar widget. But when I try to drag a block with calendar to another column the widget reloads the whole page and display calendar twice on blank page.
It seems like js code of widget is being executed during the block dragging.

Is there the way to 'freeze' the content of block being dragging?

I hope I made clear what I mean. Thank you!

Comments

jchatard’s picture

Well I have to admit I've never tested this kind of situation, but I guess Google Gadget are sort of iFrame stuff.

Could you digg a little?

Thanks,
Jérémy

itsnotme’s picture

I have a similar problem with a block in which a weather forecast is included.

The code in question is:

<script src="http://www.donnerwetter.de/wetter/net/boxregio.mv?typ=&amp;plz=28357&amp;color_bg=FFFFFF&amp;color_hi=FFCC00&amp;color_txt=&amp;width=" type="text/javascript"></script>
<noscript></noscript>

The problem is reproducible and persistent in Firefox and Chrome. (Opera 10 and IE 8 mostly seem to work - few problems, not reproducible.)

My version is 6.2x dev of today, October 4th.

mstef’s picture

Version: 6.x-1.2 » 6.x-2.x-dev

I think I know the problem. It seems that if a block with js or flash is dragged and dropped, the content inside is reloaded by the browser. So a problem is either occurring with Homebox or the script itself. I'll try looking into it.

nibo’s picture

I am also interested in this issue. I'm not 100% sure, but I think, that in the previous version 2.0 the problem wasn't there ...

d0t101101’s picture

Subscribing, also facing this issue...

mlconnor’s picture

Title: dragging a block with Google Gadget » SOLVED: dragging a block with Google Gadget

This issue appears to be caused because jQuery reruns the scripts in the blocks when the block has been dropped.

The key to solving this issue is to prevent the scripts from running a second time. My first thought was simply to add the JavaScript for the block (in my case it creates a Twitter widget) to the .ready() function so that it would only run once but that didn't solve it for me.

It would be great if there were a flag in jQuery that would indicate whether or not .ready() had been called so that you could check that and only run scripts if .ready() had not been called. Until I find something, I was able to fix this by creating a flag in the .ready() function that I could check later. So somewhere on the page you have to...

$(document).ready(function() {
  // Handler for .ready() called.
  $('#page').addClass('widget_scripts_fired');
});

...and then in each block HTML (not PHP) where there are scripts that you don't want to run twice you can wrap them with...

  if ( ! $('#page').hasClass('widget_scripts_fired') ) {
    // the widget script runs here...
  }

Can anyone think of an easier way to check whether ready was fired yet?

mstef’s picture

Status: Active » Needs work

Yes I can, and I had a feeling I left this out..

You need to add a 'processed' class to everything select in jQuery, after you select it. Upon selecting, you only grab items that weren't 'processed'. This way the events are only attached once and things don't blow up..

Example:

var buttons = $('input[type=submit]:not(.homebox-processed)');
$(buttons).addClass('homebox-processed');
$(buttons).click(function() {
  alert('hello world');
}

Make sense? I'll get it fixed..

mlconnor’s picture

mikesteff, i see that you add a homebox-processed class to all of the widgets. are you saying that the existing code erroneously reprocesses items that already have the homebox-processed flag? if so, am i right to assume that you plan to fold the code you provided above back into the code base?

thanks for all your work on this. it's a great module and i hope i can help to make it better. i think it's getting really close.

itsnotme’s picture

mikesteff, any plans when to add the fix? I'd do it myself with a patch but I'm not sure where to add the solution :)

*eagerly waiting*

mlconnor’s picture

I've changed my widget code a little bit to get around this issue. In my block I add the following code...

if ( ! $('div#homebox').hasClass('homebox-processed') ) {
  // add widget here....
}

I'm still trying to figure out how to implement this from the actual homebox code instead of hacking each block. Any thoughts?

mlconnor’s picture

One of the Google gadgets I'm running has a simple

tag. That script tag adds an iframe via a document.write. Document.write appears to blow away your entire page. One way I was able to solve this is by removing the script that constructs the gadget in .ready(). Vicious hack.
brianV’s picture

Version: 6.x-2.x-dev » 6.x-3.x-dev

Bumping version since 6.x-2.x is no longer being developed.

drumm’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

D6 is no longer supported. If this can be reproduced with Drupal 7, please re-open with details.