well i used joomla's ScriptMerge to merge all js files into one but now i get window.addEvent is not a function on squeeze box initialization,everything else is working fine except for this...i noticed that the squeeze box code is the only javascript block left in the head tag,all the other scripts are merged and moved to body...when i click a button that opens squeeze box it wont open of course,but when i click it again it opens normally...does anyone have an idea how to resolve this error?maybe it is because now the mootools core is being called in the merged js file but not in the head so the squeeze box code returns error because it doesnt have the mootools core?
1 Answer
There is your problem:
You are using async attribute on the script - async means the script will load and not holding the dom execution like the default behavior does(without async or defer).
so you try to call window.addEvent
when you don't have mootools loaded to the page and this is why you get the error of undefined
.
2 solutions for the problem:
- remove the async attribute to force the script to hold until loaded and then continue executing the dom.
- add to the script tag the
onload
event and execute the rest of your script there:
<script src="http://tereni.me/cache/plg_scriptmerge/975e10ecd911c8ca09713d1120c51a6d.js" async type="text/javascript" onload="onLoadScript();"></script>
and after it inside another script tag:
function onLoadScript(){
window.addEvent('domready',function(){
alert('dom is ready');
});
}
-
first solution worked for me,i cant believe i havent seen it myself...i spent hours debugging this!thanks man!– AndrejApr 23, 2013 at 21:22
-
window.addEvent
it will throw an error - mootools libs should be the first thing loading - so or move all the script from body to head or put squeeze box script after the body scriptconsole.log(window.addEvent);
and see what you get. can you post a link ?