Closed (fixed)
Project:
Rate
Version:
7.x-1.4
Component:
User interface
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
29 Oct 2012 at 09:54 UTC
Updated:
5 Aug 2014 at 05:51 UTC
Jump to comment: Most recent
Since I have updated the rate module to 1.4 Ajax does not work any more for voting. That means, that the whole page is reloaded by clicking the rate button. The cause of that problem is, that the rate.js is included before the jquery.js. This leads in Javascript error:
ReferenceError: jQuery is not defined @ ***/sites/all/modules/rate/rate.js?mcndu4:60
Comments
Comment #1
gunwald commentedI changed line 292 in rate.module from:
to
Just for testing, but did not help. The I commented the line out and added the line
scripts[] = rate.jsto rate.info.
Now it works again. I know that this is not a good solution, because now the JS is loaded every time on every page. But I am a bit helpless at that point not having any idea what could be the cause of that strange issue.
Comment #2
gunwald commentedWith the above described workaround Ajax does not work if content was loaded via Ajax it self.
Comment #3
XmhO commentedI guess my issue is related to yours. Since fresh install of 1.4, I've got "jQuery is not defined" errors for both rate.js and fivestar.js (I'm using fivestar widget).
I'm using Fivestar via "rate_embed" function (I'm embedding fivestar widget in a display suite field).
The error is caused by too early loading of rate.js and fivestar.js : if you look at JS loading order, you can see that these JS are loaded before jquery.js.
Comment #4
gunwald commentedI actually fond out that skipping the 'scope' brings drupal_add_js() back to work. I don't have an idea why. So for rate widget I changed line 292 in rate.module in:
It looks to me like a Drupal bug. The problem is, that AJAX loaded widgets keep refuse working. I get the error:
The cause of that error seems to be that the code form line 286-291 is not being executed or perhaps not at the right moment?
Does anybody know where o what could cause that strange behavior?
Comment #5
XmhO commentedI fixed my problem by specifying another scope for rate JS files :
It's not a good solution but It fixes my problem. Can you try this snippet gunwald in order to see if our error messages are based on same issue?
Comment #6
gunwald commentedThanks XmhO, it works. But apart from the fact, that your solution is much more elegant then mine, both do the same: Deleting or changing the scope. Bu why have we to do so? And why does it not work with AJAX loaded content? XmhO, do you have a widget witch is loaded with AJAX? Just to tray whether or not you experience the same problem? Thank you so far!
Comment #7
mauritsl commentedThe Javascript was moved to the footer for performance reasons, see #1717484: Move JavaScript to footer. The script should be loaded after the other scripts (and content) are loaded, but it seems to have the opposite effect in some cases.
I have reverted this. Too much problems to keep it.
Original commit:
http://drupalcode.org/project/rate.git/commitdiff/739768c
Comment #8
gunwald commentedThank you mauritsl. Reverting this two lines solves the first issue: The rate.js is loaded with the right weight again. But I still get an JavaScript error when I click on a rate widget which was loaded via AJAX because of the fact that Drupal.setting.rate.basePath seems not to be set.
Maybe that is a different issue? Could that have something to do with the function drupal_get_destination()? Maybe it does not return a result when the script is called via AJAX?
Thank you very much for your help!
Comment #9
gunwald commentedI hunted it down. The problem is, that for some reason the JavaScript variable set in line 286 in rate.module "Drupal.settings.rate.basePath" and "Drupal.settings.rate.destination":
becomes an Array instead of a string when the content containing the widget is loaded via Ajax. The cause of that problem may be an bug in drupal_add_js() core function because of the fact that documentation says if a setting value is set more than once it will be overwritten. How ever, in this case it is not, but becomes an array which looks like:
I added, just for testing, these to lines to line before line 31 in rate.js:
Now it works again. I know it is a dirty workaround but I could not find the real cause of the problem. Would be glad to know whether or not someone can reproduce the described problem.
Comment #10
XmhO commentedI don't have anything loaded in Ajax, but my widget is displayed with "rate_embed" built-in function, inside a Display Suite field.
I guess It is not Ajax related.
Comment #11
gunwald commentedBut the problem occurs only with content loaded via AJAX, I can't imagine the real cause but I did not had that issue with the former versions of Rate Widget. One could set a View's load more behavior to AJAX for testing.
Comment #12
XmhO commentedAs mentioned above, the line has been reverted. It should work now, with last revert. Isn't it?
Comment #14
Aurochs commenteddidnt help me
Comment #15
rooby commentedFor anyone coming across this issue (because there is still a similar issue to what some of you describe in the latest version), see #2102571: drupal_add_js() call turns basePath string into array