Available in service plans: Advanced, Universal


If you would like to run some JS script on your page you can add it in your Project settings -> Custom CSS/JS -> External or Embedded (JS/CSS). Example:


<script>
alert('test');
</script>

Sometimes you need to run the script when page is ready. We have a special array of methods (initqueue) which we run when page is ready. Just add your method to this array.


<script>
initqueue.push(function(){
    // your code is here
});
</script>

You are able to use JQuery library when page is ready!


Additionally, sometimes you need to run a script when "topic popup" is ready. For example, to customize the topic form. We have a special event for this case: uetopicpopuploaded.


Here is an example how to add some text to the topic popup.


<script language="javascript">
initqueue.push(function(){
    $(window).on('uetopicpopuploaded', function () {
        $('#module_add_topic .modal-body').prepend('<div style="background-color: #ffdd99;padding:10px;margin-bottom:10px"><strong>Test message in the topic popup</div>');
    });
});
</script>

One more example: pre-defined text in the description field if field is empty.


<script language="javascript">
initqueue.push(function(){
    $(window).on('uetopicpopuploaded', function () {
        var description_field = $('#module_add_topic .redactor-editor:first');
        if ( description_field.length > 0 &&  description_field.html()=='<p></p>'){
              var text = "<p>text line 1<br>text line 2</p>";
               description_field.html(text);
        };
    });
});
</script>

This article was helpful for 5 people. Is this article helpful for you?