JS error with popups_add_popups in template.php file

amandawolfe - October 24, 2008 - 03:22
Project:Popups API (Ajax Dialogs)
Version:6.x-1.1-rc1
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

I have a strange problem. When I navigate to the popups test page, all of the popups are working fine. I added the class "popups" to a link in a block override and from that page still, I tested it and it's also working fine (node pops up as expected).

But when I add popups_add_popups(); to my template.php file and navigate away from the popups test page (back to home page or wherever), the ajax loader just goes on and on and nothing ever pops up from the link. In Firefox it's saying that popups.js has an error on line 269 (template has no properties). That's this line:

var popups = template.replace('%title', title).replace('%body', body);

Also, when I navigate back to the template test page (with the add_popups in my template file) then none of the examples work, when they did before! Very strange that it would be registering an error in some situations but not all (for the same links) when it's using the same .js file. Anyhow, just wanted to report this!

#1

amandawolfe - October 24, 2008 - 20:56

Just wanted to update that RC2 doesn't fix this issue for me. Do you have any idea what might be going on? I'm really hoping to use this feature on my site, which is launching asap!

Thanks so much for all your hard work!
Amanda

#2

starbow - October 25, 2008 - 01:03

I have no idea what is causing the behavior you describe. That particular error sounds like you are having a theming issue, and the popups-popup.tpl.php file is not being read.

#3

amandawolfe - October 25, 2008 - 15:25

Yes, definitely. I'm just wondering why it would work fine when it's on the test page and not anywhere else. I looked at the source code and all of the css and js files are being called in both cases. As far as I can tell, there aren't any other interfering scripts or files that are different from page to page. I'd instantly assume a theming issue if it didn't work at all--what's a mystery to me is how it works just peachy sometimes.

Anyhow, thanks. If you have any other insights on how to debug this from my end, or if anyone else has had a similar problem, please let me know. I *really* want to get this working for my site! :)

#4

amandawolfe - October 26, 2008 - 13:37

Also, for what it's worth, the error is with the same line of code as the error that these people were having: http://drupal.org/node/214432

Tried the last fix that chirale suggested, which didn't work for me.

#5

starbow - October 30, 2008 - 21:15
Status:active» postponed (maintainer needs more info)

Ok, it looks like calling popups_add_popups() in the template.php file is too late. Bummer. In RC3 I have added a setting checkbox "Scan all pages for popups links", that does a popups_add_popups() for all pages. Let me know if that fixes your problem.

#6

amandawolfe - October 30, 2008 - 22:30

Thanks for making a fix! Unfortunately it doesn't quite work for me. I get a js error on page load (rather than clicking on the popup link itself). It's on line 32 of popups.js, and the error message says: popit has no properties.

I feel like we're close! And thanks again for the awesome module--I can't wait to get it working for my site. :)

#7

starbow - November 1, 2008 - 07:35

Yeah, RC3 needed more testing. Actually RC4 needs more testing too, but at least it should run :)

#8

amandawolfe - November 1, 2008 - 14:31

It's working for me so far! Can't tell you how excited I am!

As a sidenote, it's only working if I add the "popups" or "popups-form" class to a link in the theme layer. The option to attach it to an already-existing link isn't working, at least not from template.php. (Should I be adding it somewhere else?)

This code: $output .= l("older polls", 'poll', attributes=>array(array('class' => 'popups'))) ."<br />"; from the newest README is actually breaking my page and giving me an error message (unexpected double arrow).

The old README code, which I had commented out but left in my template php file just in case we got this working, doesn't work but doesn't break anything either. Hmm.
//$output .= l("older polls", 'poll', array('attributes' => array('class' => 'popups'))) ."<br />";

Anyhow, just throwing that out there . And THANKS!

#9

starbow - November 1, 2008 - 15:57

Great.
The most reliable way to modify an existing link is to create your own custom module. popups_add_popups() in template.php or page.tpl.php doesn't seem to work.

Thanks for the note on the documentation. That is the (slightly wrong) instructions from the soon-to-be-released Drupal 5 version.

#10

amandawolfe - November 2, 2008 - 14:36

So I hate to keep bothering you.. I'm working on a custom module (kinda scary, I've never attempted to write a module before!) I'm using your popups admin module as a template. Anyhow, I'm trying to add a popups-form link to a link on the user profile. (Specifically, the "add me as a friend" link. Can't add it directly in the user-profile tpl page, because I'm not printing just a static link, I'm printing a chunk of different behaviors from the Friend module. Aanyhow, what I'm asking is this: Is possible to create a custom module hook for a link that's on the user profile page, since that's a dynamic link (site.com/users/1, site.com/users/2, etc.). And also, the link that I'm trying to make into a popup is also dynamic (ugh! of course!). It's something like site.com/friend/request/36?destination=user/36. Or should I just give up on this? Maybe it's not possible? Wanted to just run it by you before I drove myself crazy. :) Thanks again for all your help!

#11

starbow - November 2, 2008 - 21:31
Category:bug report» support request
Status:postponed (maintainer needs more info)» fixed

Should be possible. Since the url of the page you want to hook isn't constant, you'll need to hook on the id of the form, not the url. You can get the id of the form by examining the html of the page. Then your rule will be something like
my_form_id => array ('a[href~=friend/request]')

Good luck.

#12

System Message - November 16, 2008 - 21:32
Status:fixed» closed

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

#13

hunvreus - February 7, 2009 - 05:31
Status:closed» needs review

It actually seems it's a problem of type: casting the content from the Drupal.settings array to a string fixed the problem. Just replace the line 278 by the following:

  var template = new String(Drupal.settings.popups.template);

The replace() method can only be used by strings in Javascript and it seems what is returned from the Drupal settings (Drupal.settings.popups.template) is not a string.

#14

starbow - February 25, 2009 - 23:17
Status:needs review» fixed

In 1.2-alpha2, the template is moving into the popups.js file, which should fix this issue.

#15

System Message - March 11, 2009 - 23:20
Status:fixed» closed

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

#16

kevin riggen - September 8, 2009 - 17:00
Status:closed» needs review

I am using 6.x-2.0-alpha5 . popups_add_popups() does not seem to work from a .tpl.php. Should it now?

 
 

Drupal is a registered trademark of Dries Buytaert.