MyBB Community Forums

Full Version: Codebuttons conflict
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Is there a better way to implement codebuttons? I have seen it multiple times on this forum, and my own. Javascript breaks code button feature.

Is there any way to fix that, other than removing the script or using noconflict option? Also, would anyone be able to go in detail on what changes might be needed in javascript to make it compatible?
Quote:Is there a better way to implement codebuttons? 
compared to what? Do you mean shceditor? I have been using myinsertbuttons and it seems fine.
If you read those topics, you should have noticed that contents of your headerinclude template are required for us to be able to help you. Board URL would also be nice.
I'm aware of that, but I was asking this in general, and not related to my specific forums. Since, you have asked,  I'll pin point to the exact thing that is causing the issues.

The js that I'm trying to run is from an old plugin called steamprofile. 

https://community.mybb.com/thread-78990.html

This is the javascript converted into an easily readable form.


function SteamProfile() {
    function H(b) {
        return W + X + "?id=" + escape(b) + "&lang=" + escape(U)
    }

    function G(b) {
        return P.find('vars > var[name="' + b + '"]').text()
    }

    function F(b) {
        return G(b).toLowerCase() == "true"
    }

    function E() {
        N = F("slidermenu");
        O = F("gamebanner");
        U = G("language");
        T = U;
        if (S[T] == null) {
            T = "english"
        }
        V = W + "themes/" + G("theme") + "/";
        jQuery("head").append('<link rel="stylesheet" type="text/css" href="' + V + 'style.css">');
        K = jQuery(P.find("templates > profile").text());
        J = jQuery(P.find("templates > loading").text());
        I = jQuery(P.find("templates > error").text());
        K.find("img").attrAppend("src", V);
        J.find("img").attrAppend("src", V);
        I.find("img").attrAppend("src", V);
        J.append(S[T].loading);
        Q = true;
        SteamProfile.refresh()
    }

    function D(f) {
        if (f >= M.length) {
            R = false;
            return
        }
        var e = jQuery(M[f++]);
        var h = e.data("profileID");
        if (L[h] == null) {
            jQuery.ajax({
                type: "GET",
                url: H(h),
                dataType: "xml",
                complete: function(b, a) {
                    L[h] = C(jQuery(b.responseXML));
                    e.empty().append(L[h]);
                    D(f)
                }
            })
        } else {
            var g = L[h].clone();
            B(g);
            e.empty().append(g);
            D(f)
        }
    }

    function C(r) {
        if (r.find("profile").length !== 0) {
            var q;
            var p = r.find("profile > steamID").text();
            var o = r.find("profile > steamID64").text();
            var n = r.find("profile > customURL").text();
            var m = "http://steamcommunity.com/profiles/" + o;
            if (n.length > 0) {
                m = "http://steamcommunity.com/id/" + n
            }
            if (p.length == 0) {
                return A(S[T].no_profile)
            }
            q = K.clone();
            var l = r.find("profile > onlineState").text();
            q.find(".sp-badge").addClass("sp-" + l);
            q.find(".sp-avatar img").attr("src", r.find("profile > avatarIcon").text());
            q.find(".sp-info a").append(r.find("profile > steamID").text());
            var h = q.find(".sp-info");
            if (r.find("profile > visibilityState").text() == "1") {
                h.append(S[T].private_profile)
            } else {
                h.append(r.find("profile > stateMessage").text())
            }
            var g = r.find("profile > inGameInfo > gameLogoSmall").text();
            if (O && g.length > 0) {
                q.css("background-image", "url(" + g + ")")
            } else {
                q.removeClass("sp-bg-game");
                q.find(".sp-bg-fade").removeClass("sp-bg-fade")
            }
            if (N) {
                q.find(".sp-addfriend").attr("href", "steam://friends/add/" + o);
                q.find(".sp-addfriend").attr("title", S[T].add_friend);
                q.find(".sp-viewgames").attr("href", m + "/games/");
                q.find(".sp-viewgames").attr("title", S[T].view_games);
                q.find(".sp-viewfriends").attr("href", m + "/friends/");
                q.find(".sp-viewfriends").attr("title", S[T].view_friends);
                q.find(".sp-viewgroups").attr("href", m + "/groups/");
                q.find(".sp-viewgroups").attr("title", S[T].view_groups);
                q.find(".sp-viewinventory").attr("href", m + "/inventory/");
                q.find(".sp-viewinventory").attr("title", S[T].view_inventory);
                q.find(".sp-viewwishlist").attr("href", m + "/wishlist/");
                q.find(".sp-viewwishlist").attr("title", S[T].view_wishlist);
                q.find(".sp-viewvideos").attr("href", m + "/videos/");
                q.find(".sp-viewvideos").attr("title", S[T].view_videos);
                q.find(".sp-viewscreenshots").attr("href", m + "/screenshots/");
                q.find(".sp-viewscreenshots").attr("title", S[T].view_screenshots);
                B(q)
            } else {
                q.find(".sp-extra").remove()
            }
            q.find(".sp-avatar a, .sp-info a.sp-name").attr("href", m);
            return q
        } else {
            if (r.find("response").length !== 0) {
                return A(r.find("response > error").text())
            } else {
                return A(S[T].invalid_data)
            }
        }
    }

    function B(b) {
        b.find(".sp-handle").click(function() {
            b.find(".sp-content").toggle(200)
        })
    }

    function A(d) {
        var c = I.clone();
        c.append(d);
        return c
    }
    var Z = "steamprofile.js";
    var Y = "steamprofile.xml";
    var X = "xmlproxy.php";
    var W;
    var V;
    var U = "english";
    var T = "english";
    var S = {
        english: {
            loading: "Loading...",
            no_profile: "This user has not yet set up their Steam Community profile.",
            private_profile: "This profile is private.",
            invalid_data: "Invalid profile data.",
            add_friend: "Add to friends",
            view_games: "View games",
            view_friends: "View friends",
            view_groups: "View groups",
            view_inventory: "View inventory",
            view_wishlist: "View wishlist",
            view_videos: "View videos",
            view_screenshots: "View screenshots"
        }
    };
    var R = false;
    var Q = false;
    var P;
    var O;
    var N;
    var M = [];
    var L = {};
    var K;
    var J;
    var I;
    this.init = function() {
        if (typeof spBasePath == "string") {
            W = spBasePath
        } else {
            var a = jQuery("script[src$='" + Z + "']");
            if (a.length === 0) {
                return
            }
            W = a.attr("src").replace(Z, "")
        }
        jQuery.ajax({
            type: "GET",
            url: W + Y,
            dataType: "html",
            complete: function(d, c) {
                P = jQuery(d.responseXML);
                E()
            }
        })
    };
    this.refresh = function() {
        if (!Q || R) {
            return
        }
        R = true;
        M = jQuery(".steamprofile[title]");
        if (M.length === 0) {
            return
        }
        M.each(function() {
            var b = jQuery(this);
            b.data("profileID", jQuery.trim(b.attr("title")));
            b.removeAttr("title")
        });
        M.empty().append(J);
        D(0)
    };
    this.load = function(b) {
        if (!Q || R) {
            return null
        }
        profile = jQuery('<div class="steamprofile"></div>');
        profile.append(J);
        jQuery.ajax({
            type: "GET",
            url: H(b),
            dataType: "xml",
            complete: function(d, c) {
                profile.empty().append(C(jQuery(d.responseXML)))
            }
        });
        return profile
    };
    this.isLocked = function() {
        return R
    }
}
jQuery.fn.attrAppend = function(e, d) {
    var f;
    return this.each(function() {
        f = jQuery(this);
        if (f.attr(e) !== undefined && f.attr(e) != "") {
            f.attr(e, d + f.attr(e))
        }
    })
};
jQuery(document).ready(function() {
    SteamProfile = new SteamProfile;
    SteamProfile.init()
});

It is being ran on a test forum with stock Mybb install. No plugins or themes have been installed at this moment.