!function(a){a.add("plugin","filemanager",{translations:{en:{choose:"Choose"}},init:function(a){this.app=a,this.lang=a.lang,this.opts=a.opts},onmodal:{file:{open:function(a,t){this.opts.fileManagerJson&&this._load(a)}}},_load:function(t){var e=t.getBody();this.$box=a.dom("<div>"),this.$box.attr("data-title",this.lang.get("choose")),this.$box.addClass("redactor-modal-tab"),this.$box.hide(),this.$box.css({overflow:"auto",height:"300px","line-height":1}),e.append(this.$box),a.ajax.get({url:this.opts.fileManagerJson,success:this._parse.bind(this)})},_parse:function(t){var e=a.dom('<ul id="redactor-filemanager-list">');for(var i in t){var s=t[i];if("object"==typeof s){var o=a.dom("<li>"),n=a.dom("<a>");n.attr("href","#"),n.addClass("redactor-file-manager-link"),n.attr("data-params",encodeURI(JSON.stringify(s))),n.text(s.title||s.name),n.on("click",this._insert.bind(this));var d=a.dom("<span>");d.addClass("r-file-name"),d.text(s.name),n.append(d);var r=a.dom("<span>");r.addClass("r-file-size"),r.text("("+s.size+")"),n.append(r),o.append(n),e.append(o)}}this.$box.append(e)},_insert:function(t){t.preventDefault();var e=a.dom(t.target).closest(".redactor-file-manager-link"),i=JSON.parse(decodeURI(e.attr("data-params")));this.app.api("module.file.insert",{file:i})}})}(Redactor);