Tempcode in PHP

Post

Posted
Rating:
#6342 (In Topic #1599)
Avatar
Standard member
Terry is in the usergroup ‘Fan in action’
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:
{$REQUIRE_JAVASCRIPT,jquery}
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?
 
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by Chris Graham)
#6346
Avatar
Site staff
Adam is in the usergroup ‘Super-moderators’
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');
Online now: No Back to the top

Post

Posted
Rating:
#6353
Avatar
Site director
Chris Graham is in the usergroup ‘Administrators’
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.


Become a fan of Composr on Facebook or add me as a friend. Add me on on Twitter. Follow me on Minds (where I am most active). Support me on Patreon

Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by Chris Graham)
#6355
Avatar
Standard member
Terry is in the usergroup ‘Fan in action’
Yep, enabling it in HTML_HEAD.tpl did the trick. I removed my own references to JQuery. Perfect!
 
Online now: No Back to the top
1 guest and 0 members have just viewed this.

Statistics

Users online:

Paul D, Salman, amit.nigam, babu, deepu_ms

Forum statistics:
  • 1,151 topics, 5,503 posts, 6,644 members
  • Our newest member is TheMaker
Birthdays:
Back to Top