1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.5 This script causes anything that needs the Ajax Progress Bar to not load

Discussion in 'Troubleshooting and Problems' started by overifist, Dec 10, 2015.

  1. overifist

    overifist Member

    This script retrieves information about a Discord server and displays it in HTML.

    When I include this script everything that requires the Ajax Progress Bar does not load. If I remove it, they do load.

    Could someone tell me what in the script causes this?

    Code:
    var discordWidget = discordWidget || (function() {
        var c = {};
        return {
            init: function(e) {
                e.serverId = typeof e.serverId !== "undefined" ? e.serverId : false;
                e.title = typeof e.title !== "undefined" ? e.title : false;
                e.join = typeof e.join !== "undefined" ? e.join : true;
                e.alphabetical = typeof e.alphabetical !== "undefined" ? e.alphabetical : false;
                e.theme = typeof e.theme !== "undefined" ? e.theme : "light";
                e.hideChannels = typeof e.hideChannels !== "undefined" ? e.hideChannels : false;
                e.showAllUsers = typeof e.showAllUsers !== "undefined" ? e.showAllUsers : false;
                c.serverId = e.serverId;
                c.title = e.title;
                c.join = e.join;
                c.alphabetical = e.alphabetical;
                c.theme = e.theme;
                c.hideChannels = e.hideChannels;
                c.showAllUsers = e.showAllUsers
            },
            render: function() {
                if (c.theme == "dark") {
                    b("http://discord.knightsoftheblade.com/dark.min.css", "css")
                } else {
                    b("http://discord.knightsoftheblade.com/light.min.css", "css")
                }
                var e = "http://discordapp.com/api/servers/" + c.serverId + "/embed.json";
                var f = new XMLHttpRequest();
                f.onreadystatechange = function() {
                    if (f.readyState == 4 && f.status == 200) {
                        var g = JSON.parse(f.responseText);
                        d(g, c)
                    }
                };
                f.open("GET", e, true);
                f.send()
            }
        };
    
        function a(f, e) {
            if (f.position < e.position) {
                return -1
            }
            if (f.position > e.position) {
                return 1
            }
            return 0
        }
    
        function d(t, g) {
            var u = document.getElementsByClassName("discord-widget")[0];
            var v = '<ul class="discord-tree"></ul><p class="discord-users-online"></p><p class="discord-join"></p><div class="discord-fade"></div>';
            var n = "";
            var k = "";
            var e, q, r;
            var o, f, h;
            if (g.title !== false) {
                u.innerHTML = '<div class="discord-title"><h3>' + g.title + "</h3></div>" + v;
                e = document.getElementsByClassName("discord-tree")[0]
            } else {
                u.innerHTML = v;
                e = document.getElementsByClassName("discord-tree")[0];
                e.style.marginTop = "0"
            }
            q = document.getElementsByClassName("discord-users-online")[0];
            r = document.getElementsByClassName("discord-join")[0];
            if (g.alphabetical) {
                o = [];
                for (var m = 0; m < t.channels.length; m++) {
                    h = false;
                    for (var l = 0; l < g.hideChannels.length; l++) {
                        if (t.channels[m].name.includes(g.hideChannels[l])) {
                            h = true
                        }
                    }
                    if (!h) {
                        o.push(t.channels[m])
                    }
                }
                for (var m = 0; m < o.length; m++) {
                    n += '<li class="discord-channel">' + o[m].name + '</li><ul class="discord-userlist">';
                    for (var l = 0; l < t.members.length; l++) {
                        k = "";
                        if (t.members[l].game) {
                            k = " - " + t.members[l].game.name
                        }
                        if (t.members[l].channel_id == o[m].id) {
                            if (t.members[l].status != "online") {
                                n += '<li class="discord-user"><img src="' + t.members[l].avatar_url + '" class="discord-avatar"/><div class="discord-user-status discord-idle"></div>' + t.members[l].username + "<span>" + k + "</span></li>"
                            } else {
                                n += '<li class="discord-user"><img src="' + t.members[l].avatar_url + '" class="discord-avatar"/><div class="discord-user-status discord-online"></div>' + t.members[l].username + "<span>" + k + "</span></li>"
                            }
                        }
                    }
                    n += "</ul>"
                }
            } else {
                o = [];
                for (var m = 0; m < t.channels.length; m++) {
                    h = false;
                    for (var l = 0; l < g.hideChannels.length; l++) {
                        if (t.channels[m].name.includes(g.hideChannels[l])) {
                            h = true
                        }
                    }
                    if (!h) {
                        o.push(t.channels[m])
                    }
                }
                o.sort(a);
                for (var m = 0; m < o.length; m++) {
                    n += '<li class="discord-channel">' + o[m].name + '</li><ul class="discord-userlist">';
                    for (var l = 0; l < t.members.length; l++) {
                        k = "";
                        if (t.members[l].game) {
                            k = " - " + t.members[l].game.name
                        }
                        if (t.members[l].channel_id == o[m].id) {
                            if (t.members[l].status != "online") {
                                n += '<li class="discord-user"><img src="' + t.members[l].avatar_url + '" class="discord-avatar"/><div class="discord-user-status discord-idle"></div>' + t.members[l].username + "<span>" + k + "</span></li>"
                            } else {
                                n += '<li class="discord-user"><img src="' + t.members[l].avatar_url + '" class="discord-avatar"/><div class="discord-user-status discord-online"></div>' + t.members[l].username + "<span>" + k + "</span></li>"
                            }
                        }
                    }
                    n += "</ul>"
                }
            }
            if (g.showAllUsers) {
                var x = document.createElement("script");
                x.type = "text/javascript";
                x.src = "http://code.jquery.com/jquery-1.11.3.min.js";
                document.head.appendChild(x);
                x.onload = function() {
                    $(".discord-allusers-toggle").click(function() {
                        $(".discord-allusers").toggle(200, function() {
                            if ($(this).is(":visible")) {
                                $(".discord-allusers-toggle").html("&#9660; Online Users")
                            } else {
                                $(".discord-allusers-toggle").html("&#9654; Online Users")
                            }
                        })
                    })
                };
                n += '<li class="discord-channel discord-allusers-toggle">&#9660; Online Users</li><ul class="discord-userlist discord-allusers">';
                for (var l = 0; l < t.members.length; l++) {
                    if (!t.members[l].channel_id) {
                        if (t.members[l].status != "online") {
                            n += '<li class="discord-user"><img src="' + t.members[l].avatar_url + '" class="discord-avatar"/><div class="discord-user-status discord-idle"></div>' + t.members[l].username + "<span>" + k + "</span></li>"
                        } else {
                            n += '<li class="discord-user"><img src="' + t.members[l].avatar_url + '" class="discord-avatar"/><div class="discord-user-status discord-online"></div>' + t.members[l].username + "<span>" + k + "</span></li>"
                        }
                    }
                }
                n += "</ul>";
                console.log("added")
            }
            var w = "";
            if (t.instant_invite != "null") {
                w = '<p class="discord-join"><a href="' + t.instant_invite + '">Join Our Discord!</a></p>'
            }
            e.innerHTML = n;
            q.innerHTML = "Users Online: " + t.members.length;
            if (g.join) {
                r.innerHTML = w
            } else {
                r.style.display = "none"
            }
        }
    
        function b(e, f) {
            if (f == "css") {
                var g = document.createElement("link");
                g.setAttribute("rel", "stylesheet");
                g.setAttribute("type", "text/css");
                g.setAttribute("href", e)
            }
            if (typeof g != "undefined") {
                document.getElementsByTagName("head")[0].appendChild(g)
            }
        }
    }());
     
  2. overifist

    overifist Member

    Anyone?
     
  3. Mike

    Mike XenForo Developer Staff Member

    I can see it loading it's own jQuery, so that may be the cause. You can likely remove that (and move the onload behavior to happen immediately) as XF already loads jQuery.
     
    overifist likes this.
  4. overifist

    overifist Member

    Oh that fixed it. Thanks!
     

Share This Page