Compatibility with jQuery Update ($form.ajaxForm is not a function)
kenorb - May 20, 2009 - 16:28
| Project: | Popups API (Ajax Dialogs) |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | reviewed & tested by the community |
Description
On some popups there is Javascript error:
$form.ajaxForm is not a function in popups.js?E (line 934)
--
openPathContent()("add/parent", "Parent Registration", "<form action="/add/parent?&destination=node%2Fadd%2Fchild" accept-charset="UTF-8"
...
</form>\n", a.popups-reference-0 parent?des.../add/child, Object updateMethod=none updateSource=initial, null)Any clue why this happen?

#1
And when after close this Popup, cursor have loading icon.
#2
I had the same problem. Seems to be related to jquery.js being included twice.
In the Popups.addJS = function(js) in popups.js commenting out the following block gets rid of the error but could possibly cause other prolbems? Anyways, I'm reverting back to stable popups.
for (var i in scripts) {
var src = scripts[i];
if (!$('script[src='+ src + ']').length && !Popups.addedJS[src]) {
// Get the script from the server and execute it.
$.ajax({
type: 'GET',
url: src,
dataType: 'script',
async : false,
success: function(script) {
eval(script);
}
});
alert(src);
// Mark the js as added to the underlying page.
Popups.addedJS[src] = true;
}
}
#3
Hey guys,
I believe I figured out what is going on here -- and the jquery_update module is at fault. I haven't delved into it very deeply, but jquery_update doesn't do it's thing until after the popups api has checked to see if jquery.js exists. So, on your initial page you have the jquery.js file being placed in there by jquery_update -- and on the newly loaded page called by popup api, you have the default jquery.js.
Popup api sees them as being different files (since they are in different places), and whalaaa, you have two version of jquery being loaded.
Hope this helps.
#4
I can't find the jquery twice in the source. Also popups 1.3 works.
#5
I did a quick hack, checking src for the jquery string, and skipping if so, and that works great.
for (var i in scripts) {
var src = scripts[i];
if (src.match('/misc/jquery.js')) {
Popups.addedJS[src] = true;
}
if (!$('script[src='+ src + ']').length && !Popups.addedJS[src]) {
#6
In fact, it's a general compatibility with how jQuery Update alters the javascript files loaded, and the fact that Popups2 loads the missing JS files on demand: Popups sees the original path instead of the altered ones, and thus loads the original versions. This is obviously problematic with jquery.js, but with the dev version of jQuery Update that needs to also change ahah.js, its an even bigger problem.
It's solved in D7 with the shinny drupal_alter('js') added in #315801: JavaScript Patch #3: JS Alter Operation , but for D6 I would propose to check in popups_get_js if the jquery_update module exists, and if it does, use the replacements it defines.
One issue with this approach is that jquery_update_get_replacements returns the list of all the files it replaces except jquery.js. Attached patch deals with this problem by simply removing misc/jquery.js from the list of files that needs to be loaded. The rationale is that by the time we get in popups_get_js, we're inside a popup, which means that we've already used jQuery to open the popup and thus its already loaded.
#7
Bumping this issue to a feature request, as it's not really a support request anymore.
#8
The patch is working for me =)
#9
Ok, so we have a community thumbs up. Giving the patch a quick eyeball, it looks good. I will roll this into the next 2.x release
#10
patch in #6 did not completely fix the issue for me. Whilst it did not re-load the jqyery.js file, it added a bunch of other javascript files (both from my theme) + it reloaded the entire popups.js file again. This cause the popups to behave weirdly and basically screw up =)
#11
@tayzlor: Just to be sure, those other js files are added both with and without the patch in #6 ? If so, are you doing something alike to jQuery Update in your theme, altering the path to the javascript files in a preprocess_page hook ?
I guess an easy check would be the following one: are the full path to the popups.js normally loaded on the page, and the one Popups tries to add to the page when you open a popup the same ?
#12
@DeFr
without the patch in #6 , the extra js files are not loaded (a couple are, jquery.js , jquery_form.js) , with the patch, it does not load jquery.js again anymore, but it loads around 6 others, including popups.js again, which appears to break the popup stack.
I'm also not altering any paths to any js files in any preprocess functions, that im aware of.
#13
@tayzlor: Another stab in the dark: do you have JavaScript files optimization turned on in admin/settings/performance ?
#14
The patch is not working for me. I have jQuery Update enabled, applied the patch, but anything jQuery into the popup just doesn't work (jcarousel, tabs, validation, slimbox, etc). Nothing. I have JavaScript files optimization turned OFF, but changing this does not impact on anything at all.
#15
I have also tried the hacks above, and nothing. Please can anyone tell me why nothing jQuey is working inside the popups and how to solve this?... The patch was no use to me.
I tried reverting to the last stable version but it was all the same. These are my loaded scripts/libraries:
<script type="text/javascript" src="/<?php print path_to_theme(); ?>/js/jcarousel/lib/thickbox/thickbox.js"></script><script type="text/javascript" src="/<?php print path_to_theme(); ?>/js/jcarousel/lib/jquery.jcarousel.pack.js"></script>
<script type="text/javascript" src="/<?php print path_to_theme(); ?>/js/jcarousel/lib/jquery.jcarousel.js"></script>
<script type="text/javascript" src="/<?php print path_to_theme(); ?>/js/tabs/jquery.history_remote.pack.js"></script>
<script type="text/javascript" src="/<?php print path_to_theme(); ?>/js/tabs/jquery.tabs.js"></script>
<script type="text/javascript" src="/<?php print path_to_theme(); ?>/js/tabs/jquery.tabs.min.js"></script>
<script type="text/javascript" src="/<?php print path_to_theme(); ?>/js/tabs/jquery.tabs.pack.js"></script>
<script type="text/javascript" src="/<?php print path_to_theme(); ?>/js/validator/js/jquery.validationEngine.js"></script>
<script type="text/javascript" src="/<?php print path_to_theme(); ?>/js/slimbox/js/slimbox2.js"></script>
Thanks!!!
#16
@alextronic: Javascript autoloading isn't implemented in the 1.x branch of popups, so unless the page calling the popups contains all the script needed by the popup, it won't work. This is fixed in the unstable 2.x branch of popups, which adds to the calling page all the scripts normally added to the popup page via drupal_add_js.
The patch attached to this issue fix one well identified potential issue when both jQuery Update and Popups are enabled on the same patch. If the JavaScript works in the popup with the stock 2.0-alpha5 release when you disable the JQuery Update module, and doesn't work when you both apply this patch and enable the jQuery Update module, then that's a problem with this patch. Otherwise, it's another issue entirely.
Looking at the code snippet you've posted, it looks like you're putting the javascript files directly in your theme page.tpl.php file, which isn't really supported by the popups approach that suppose the different JS files are added via drupal_add_js. It shouldn't be a complete showstopper at first sight though, because if you did put them in your page.tpl.php file, then they are loaded in the parent window...
(Btw, the correct value for the Javascript files optimisation is OFF for the autodetection of already loaded script to work, so your original setting shouldn't be the problem).
So to sum it up: disable the jQuery Update module, revert to the official 2.0-alpha5 release and check if it works.
#17
"Disable the jQuery Update module, revert to the official 2.0-alpha5 release and check if it works" <- This worked, thanks.
I had to load the validation script from the node, but it worked in the end.
Now I'll try applying the patch and re-enabling jQuery Update.
Thank you
#18
Based on #5,
I added the following couple of lines and it works:
Popups.addJS = function(js) {
...
...
for (var i in scripts) {
var src = scripts[i];
if (!jQuery.browser.mozilla && (isNaN(i) || src.match(/misc\/jquery.js/) || src.match(/popups.js/) || src.match(/misc\/drupal.js/) || src.match(/misc\/gmap.js/) ) )
continue;
without !jQuery.browser.mozilla, jQuery tends to become unresponsive and crashes Firefox. This also solves the popups not showing under Safari/Chrome for me.
That, with the patch from #362878-11: jQuery 1.3.2 issue.