var Bind = require("github/jillix/bind");
var Events = require("github/jillix/events");

module.exports = function(config) {

    var self = this;
    Events.call(self, config);

    for (var i in config.roles) {
        $("." + config.roles[i]).hide();
    }

    var cache;

    self.updateLinks = function (data) {

        cache = cache || data;
        data = cache || {};

        data.role = data.role || config.publicRole;

        $("." + data.role).fadeIn();
        var index = config.roles.indexOf(data.role);

        if (index !== -1) {
            config.roles.splice(index, 1);
        }

        for (var i in config.roles) {
            $("." + config.roles[i]).remove();
        }

        self.emit("updatedLinks", data);
    };
};

var Bind = require("github/jillix/bind");
var Events = require("github/jillix/events");

module.exports = function(config) {

    var self = this;
    Events.call(self, config);

    for (var i in config.roles) {
        $("." + config.roles[i]).hide();
    }

    var cache;

    self.updateLinks = function (data) {

        cache = cache || data;
        data = cache || {};

        data.role = data.role || config.publicRole;

        $("." + data.role).fadeIn();
        var index = config.roles.indexOf(data.role);

        if (index !== -1) {
            config.roles.splice(index, 1);
        }

        for (var i in config.roles) {
            $("." + config.roles[i] + ":not('." + data.role + "')").remove();
        }

        self.emit("updatedLinks", data);
    };
};

Remove only links that have not the data.role class.
Remove only links that have not the data.role class.
