PrimeFaces.widget.Identicon = PrimeFaces.widget.BaseWidget.extend({
    init: function (cfg) {

        this._super(cfg);

        this.text = cfg.text;
        this.salt = cfg.salt;
        this.rounds = cfg.rounds;
        this.size = cfg.size;
        this.outputType = cfg.outputType;
        this.hashVariant = cfg.hashVariant;

        var that = this;

        var shaObj = new jsSHA(that.text + that.salt, "TEXT");
        var hash = shaObj.getHash(that.hashVariant, that.outputType, that.rounds);
        var data = new Identicon(hash, that.size).toString();

        jQuery(that.jqId).attr("src", "data:image/png;base64," + data);

        /*Uses https://github.com/stewartlord/identicon.js and http://caligatio.github.io/jsSHA/  */
        function get_identicon(text) {
            var salt = $("#salt")[0].value;
            var rounds = Number($("#rounds")[0].value);
            var size = Number($("#size")[0].value);
            var outputType = $('input[name=outputType]:checked')[0].value;
            var hashtype = $('input[name=hashVariant]:checked')[0].value;

            var shaObj = new jsSHA(text + salt, "TEXT");
            var hash = shaObj.getHash(hashtype, outputType, rounds);
            var data = new Identicon(hash, size).toString();

            $("#show_identicon")[0].src = 'data:image/png;base64,' + data;
        }

    }
});
