jQuery in Admin Custom HTML?


(Arlair) #1

I have tried various things, but seem to be getting nowhere and thought I would ask.

I want to add some nav links after the site logo. I managed to do this using getElementsByClassName and appendChild javascript similar to the code in the first post at How to add external link on top menu?.

However, it is rather verbose and I tried some jQuery.

I have seen various mentions of jQuery in the code and on meta about jQuery, but I tried the following and don’t seem to have anything to show for it.

Inside a script tag I have tried various combos along the lines of:

function doLink(){
    var $ = window.jQuery;
    var wibble = window.jQuery;
    //$("#site-text-logo").append("<ul><li><a href="/">Home</a></li></ul>");
    $(".ember-view title").after("<h1>Home</h1>");
    //jQuery(".ember-view title").append("<h1>Home</h1>");
    //wibble(".ember-view title").append("<h1>Home</h1>");

window.onload = function() {
//jQuery( document ).ready(function() {
//    doLink();
//    }

I noticed there is a jQuery plugin loaded, but didn’t find jQuery itself. I also tried adding a script flag with a link to Google jQuery, but I think this doesn’t work due to the way the custom HTML is inserted. emberjs is still a bit like black magic to me :wink:

Disable email or provide Contact URL on About page
(Arlair) #2

It seems I can override templates by adding a script in the custom Header, so I am going to modify home-logo template and add my links in there.

<script type='text/x-handlebars' data-template-name='components/home-logo'>

(Arlair) #3

Being able to insert at a class or id would be nice. I want to append at the end of the header template for mobile: discourse/header.hbs at 350554e198084ee241143cc55891e80fd1c8c00a · discourse/discourse · GitHub

I would have to override the whole header template using this technique, which seems like a good way to get bitten by upgrades. Not that appending to classes or ids can’t be broken, but it is less likely.

(Mittineague) #4

I have a strong dislike of applications that give anything and everything ids and classes in over abundance.
[cough] WordPress [/cough]

So far I have been able to target specific elements in Discourse by using long-chained selectors
Whether or not they are truly unique and only suit my needs or may have unexpected effect elsewhere is unknown.

But - AFAIK - even though I’d prefer to have Discourse not fall into id and class bloat, the Discourse Team is open to suggestions and can and will add them to elements if requested and deemed safe and useful.