Tempcode in PHP

Post

Posted
Rating:
#5726 (In Topic #1175)
I created a card-flip JQuery and it's used on the right-pane of the site. It introduced a small warning/error
46: TypeError: $(...).sew is not a function
https://witches.chat/themes/Witches_Chat/templates_cached/EN/jquery_autocomplete_ssl.js?1580696555

also seen is...
46: TypeError: $(...).sew is not a function
https://witches.chat/data/script.php?script=jquery_autocomplete&theme=admin&keep_theme=admin
One happens when I click on Read More in the News_Block, the other happens when I click "Edit in zone editor" to edit the Right Side-panel. They are both caused by my card-flip JQuery. I think it's because I'm loading JQuery using my own JQuery js file. It also happens if I link to the latest JQuery js file. If I remove the card-flip miniblocks, the problem goes away. If I disable the link to JQuery, the card-flip won't work, of course, but the error also goes away. So it's the JQuery.

Composr has its own JQuery. I've seen it called like this:

I'd like to remove my own calls to load JQuery in my card-flip miniblocks, and call JQuery the Composr way, and that way there won't be any version collision issues, which is my theory about the issue. I tried to add the call to JQuery from inside the miniblock, but no-go. This might be a bad idea, but, is there a way to call a bit of Tempcode from inside PHP, or even just in a Miniblock in general, so I can try calling JQuery like it's done elsewhere in Composr?
 

Post

Posted
Rating:
Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 (Liked by Chris Graham)
#5728
If you are planning to use jQuery a lot, it might be better to enable globally. Check HTML_HEAD.tpl and uncomment the JQuery require (you will need to empty the template cache). Else in PHP it would be, require_javascript('jquery');

Post

Posted
Rating:
#5735
Adam's answer is the right one.

It is likely that loading up a second jQuery causes conflicts, either as there are 2, or our own bundled jQuery autocomplete plugin (sadly) depends on the much older version we bundled. We need to get that upgraded, but it's not going to happen in v10.

Maybe the jQuery you have will be compatible with our older version.

As to why you couldn't load the JS within your block code:

I'd guess that your JavaScript code within your mini-block (not loading jQuery, your embedded JS code) runs before the browser's onload event, and thus if JS code is not loaded in <head> then it will run too late. One solution to that is to make your block's HTML's JavaScript only do anything after onload, which Composr does itself for many things (e.g. the COMCODE_CAROUSEL template's <script> tag). I am guessing the way we execute mini-blocks, we can't tell early enough that a JavaScript file is going to be needed for the <head> so it ends up being included at the end of the page. This won't fix the library version conflict though, if that's what's happening.

Post

Posted
Rating:
Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 Item has a rating of 5 (Liked by Chris Graham)
#5737
Yep, enabling it in HTML_HEAD.tpl did the trick. I removed my own references to JQuery. Perfect!
 
4 guests and 0 members have recently viewed this.