• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Plugin Question: Composer hooks + adding JS to head

Scheduled Pinned Locked Moved NodeBB Plugins
13 Posts 4 Posters 4.1k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    a_5mith
    replied to psychobunny on last edited by
    #1

    @psychobunny I'll get to work then. 😆 Question, how do I add js to the head of a page from a plugin? 🙂

    1 Reply Last reply
    0
  • psychobunnyP Offline
    psychobunnyP Offline
    psychobunny
    wrote on last edited by
    #2

    https://github.com/NodeBB/nodebb-plugin-quickstart/blob/master/plugin.json#L21-L23

    and

    https://github.com/NodeBB/nodebb-plugin-quickstart/blob/master/static/lib/main.js

    👍 gets minified into nodebb.min.js, located in the head

    1 Reply Last reply
    0
  • A Offline
    A Offline
    a_5mith
    wrote on last edited by a_5mith
    #3

    Ok, last question then, everything is done, except the plugin doesn't fire until after a refresh, is their a better way to do this than .on('action:widgets.loaded',

    When you submit a post, nothing appears.

    Is there an on post submit, or post edit, or the composer. 😆

    1 Reply Last reply
    0
  • psychobunnyP Offline
    psychobunnyP Offline
    psychobunny
    wrote on last edited by
    #4

    Nope. Adding one in now

    1 Reply Last reply
    0
  • psychobunnyP Offline
    psychobunnyP Offline
    psychobunny
    wrote on last edited by
    #5

    There you go: https://github.com/NodeBB/NodeBB/commit/eb297d7eab2969766117a2d119ad2f77fb7726e0

    Forking this thread I think we've hijacked this one far enough 😛

    A 1 Reply Last reply
    0
  • A Offline
    A Offline
    a_5mith
    replied to psychobunny on last edited by a_5mith
    #6

    @psychobunny Right, I'm now in the right topic, 😆 thanks for correcting me on the action, however, still nothing, thinking I might be missing a step.

    Also issue 2, doing it through the console stops all other videos playing and resets them. Could get annoying. Unless it only happens for that one user.

    1 Reply Last reply
    0
  • A Offline
    A Offline
    a_5mith
    wrote on last edited by
    #7

    Right, I have made a bit of progress here, I'm now using

    $(window).trigger('action:ajaxify.end', function() {

    which works on new topics, but not on new posts. So I don't really know what to do at this point, this is the last thing, everything else is working fine. I've even stopped it from refreshing youtube videos that are currently playing etc.

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #8

    When a post is entered into the dom $(window).trigger('action:posts.loaded'); is fired.

    $(window).on('action:posts.loaded', function(){
        alert('foo');
    });
    

    Keep in mind this gets triggered when posting a new post as well when scrolling down to reveal new posts.

    A 1 Reply Last reply
    0
  • A Offline
    A Offline
    a_5mith
    replied to <baris> on last edited by a_5mith
    #9

    @baris Hi Baris, thanks for that, I believe that was what I used before changing to ajaxify, it works on new topics / first post. But when you post a reply to a topic, it seems to run before the div is ready to load the video. If I put $('.js-lazyYT').lazyYT(); into my console and run it, the video loads, would it be possible to add a delay to when it gets fired? If that would even help...

    EDIT: Changed it to $('.js-lazyYT').delay(500).lazyYT(); and it now works. 😄 Probably a bit hacky though.

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #10

    You can always do

    $(window).on('action:posts.loaded', function(){
        setTimeout(function() {
            $('.js-lazyYT').lazyYT();
        }, 1000);    
    });
    

    Saw your edit and yeah they are both hacky. Maybe it's the fade in that causing the issue, you can try removing that and the delay and see if it works. Try removing this.

    A 1 Reply Last reply
    0
  • A Offline
    A Offline
    a_5mith
    replied to <baris> on last edited by a_5mith
    #11

    @baris Removing the fade makes the site a lot faster, I like it. However removing the delay stops it loading again. So think the delay may be a necessary thing.

    I'd also like the plugin to work on all sites, so unless you guys were planning on removing the fade at any point, I think for now, a delay may be the best option?

    1 Reply Last reply
    0
  • julianJ Offline
    julianJ Offline
    julian GNU/Linux
    wrote on last edited by
    #12

    That's weird. the action:posts.loaded hook is only fired after the post has been put into the DOM, so it should work...

    What error do you get when a post is lazyloaded w/o the delay?

    A 1 Reply Last reply
    0
  • A Offline
    A Offline
    a_5mith
    replied to julian on last edited by a_5mith
    #13

    @julian No error, I added some logging in to test when things fired, so can confirm that it does, and it refreshes any non playing videos already in the topic as expected (when you click play it remove the class that the script looks for to stop playing videos reloading), but the new one isn't loaded. Unless they're both happening at exactly the same time. I may have a play with the delay timer, to see how far down I can go until it stops loading.

    Currently set to 500ms.

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development