In openlayers_behaviors.behaviors.js : OL Popup Behavior - Feature Clicked Handler,

At the end of the function, after running feature.layer.map.addPopup(popup), the script should call Drupal.attachBehaviors(); so that other behaviours, like lightbox scripts, get run on the popup contents. Otherwise Lightbox, Thickbox and similar scripts won't run on the content of OpenLayers popups (and I'm sure there are plenty of other cases as well, those are just the ones that i've been trying to implement).

This would be after line 99 in the current dev version, and after line 108 in 1.0-beta4.

I don't have a platform to test the dev on right now, but this addition seems to be working fine on my 1.x install. Since I'm not running the dev, I don't feel comfortable proposing a patch for it, but if someone else could test it and then add a patch that would be great.

Or if there's some reason I shouldn't be calling the function in that spot, I'd be equally interested in learning about that, to avoid any issues down the road.

Comments

phayes’s picture

Good call. This should also be done on the tooltip behavior.

tmcw’s picture

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

Is this misassigned as 2.x? Popups haven't been ported to 2.x at all yet, and won't work at all. I'll incorporate this fix in when popups are done (hopefully today).

robin.puga’s picture

Status: Active » Needs review
StatusFileSize
new505 bytes

Convenient timing mcook; we were wrestling with this issue as it relates to tooltips yesterday. Thanks to Patrick for bringing this issue to our attention.

Attached is our patch for 6.x-1.0-beta4 using the method mcook suggested. This will call Drupal.attachBehaviors() each time a tooltip is created on mouseover and when a popup is created on region click.

Our (I should say "my") only concern with running all the Drupal behaviors again in this way is in the event that your behavior does something that should not be called additional times (like a toggle or something). In the case of our tooltips, this means all Drupal behaviors are going to be loaded whenever someone mouses over our polygons.

phayes’s picture

Thanks Robin,

Re: running attach behaviors multiple times - I believe all Drupal behaviors are responsible for doing their own 'cleanup' (ie. registering which elements have been processed and then skipping them next time around). I think it is generally assumed that Drupal will run attach behaviors every time new content is brought in via AJAX or AHAH (or just javascript in our case).

robin.puga’s picture

Okay, that totally makes sense.

Thanks again for the help. :-)

robin.puga’s picture

After another review I re-rolled the patch. Please test with this patch instead. :-)

Again, this patch is for OpenLayers 6.x-1.0-beta4

phayes’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mr.baileys’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Component: OpenLayers Behaviors » OL Behaviors
Status: Closed (fixed) » Needs review
StatusFileSize
new1.13 KB

Re-opening as this seems to be missing from the 7.x-2.x branch.

zzolo’s picture

Status: Needs review » Fixed

Thanks @mr.baileys! Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

nitebreed’s picture

Hadding some trouble with my other drupal.behaviors when using just Drupal.addbehaviors() (they got executed again).
I changed it to <?php Drupal.addBehaviors(this);?> and then it worked fine.

jetsonjohn’s picture

Status: Closed (fixed) » Active

It is not working with 7.x-2.0-beta7 and also in 7.x-2.x-dev version. The lightbox2 popup is not coming in these version.

pol’s picture

Hi,

Could you try to invert the lines 113 and 114 on this file and report to me ?

Thanks !

jetsonjohn’s picture

changed the code a little bit and the the lightbox popup is working

//sites/all/modules/openlayers/plugins/behaviors/openlayers_behavior_popup.js
selectedFeature = feature;
feature.popup = popup;
//Drupal.attachBehaviors(); //old code
//map.addPopup(popup); //old code
map.addPopup(popup); //new code
Drupal.attachBehaviors(); //new code
},
onUnselect: function(feature) {

but the problem with this code is that when the lightbox2 popup is displayed and after that I close the lightbox popup and also close the openlayer marker popup. Then again click on the openlayer marker, popup is not displayed. The following error is being displayed
Uncaught TypeError: Cannot call method 'apply' of undefined

pol’s picture

Could you try this too: #2006576: Widgets fail to redraw on zoom (scale and pop-up), see comment #10 ?

jetsonjohn’s picture

That is also not working

aaronbauman’s picture

Status: Active » Needs review
StatusFileSize
new627 bytes

Looks like this got reverted at some point in openlayers_behavior_popup.js, so that attachBehaviors() gets called before addPopup, which makes responding to the popup rather difficult.

The behavior in openlayers_behavior_tooltip.js was unaffected - attachBehaviors still called after addpopup there.

Should be a quick fix.

re-reading this thread, I see that this solution is what was discussed in #14 and #15, so this is a patch-ified version.

re: jetsonjohn #15 and your broken openlayers popup:
Are you performing some destructive operation in your behavior? I'm not having any problems with the solution proposed by Pol.

jetsonjohn’s picture

This is not working for me. What you meant by destructive operation in your behavior?

aaronbauman’s picture

What I'm saying is probably something else is going wrong in your javascript app, unrelated to this issue, since this fix works on a vanilla install.

jetsonjohn’s picture

I just install a fresh version only the change in java script file is this patch only. But the problem is not solved. What I am trying to do is to popup a view in the lightbox popup. On the first time when I click on the openlayer marker the openlayer popup and then on clicking the title of the popup a lighbox popup with a view is displayed. But the problem is starting when I close the lightbox popup with view and then I close the openlayer marker popup. After that when I click on any another marker in the openlayer map it is not displaying the popup. What I am doing in openlayer data overlay view is that I created a field title then I check 'Rewrite the output of this field' in the Rewrite Result and gave a text like this <a href='/viewname' rel='lightmodal'>[title]</a> . There is no other thing I do in the installs or other files.

aaronbauman’s picture

Sorry, but if you're trying to do something with lightbox, then you're certainly not using a fresh install.
This is a very simple patch addressing one particular issue.
Your bug may be related, but is not evidence that this patch fails.
Sounds to me like you need to open a new issue and provide more information about this problem.

jetsonjohn’s picture

Thanks for your replay I just created a new issue

pmusaraj’s picture

Issue summary: View changes
StatusFileSize
new897 bytes
pmusaraj’s picture

The patch in #24 is a minor modification that attaches behaviours also when the popup is closed. I needed this for a project, and could not find another way to attach some events to the map when popup closes. If this is not the right way to do this, please let me know an alternative.

pol’s picture

Thanks, committed.

pol’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.