fielduser.min.js
2.35 KB
function jSelectUser(t){var e=jQuery(t),i=e.data("user-value"),o=e.data("user-name"),n=e.data("user-field"),a=jQuery("#"+n+"_id"),s=jQuery("#"+n);if(a.length){a.val(i).trigger("change"),s.val(o||i).trigger("change");var d=a.attr("data-onchange");d&&new Function(d).call(a[0]),jModalClose()}}!(function(t){"use strict";t.fieldUser=function(e,i){this.options=t.extend({},t.fieldUser.defaults,i),this.$container=t(e),this.$modal=this.$container.find(this.options.modal),this.$modalBody=this.$modal.children(".modal-body"),this.$input=this.$container.find(this.options.input),this.$inputName=this.$container.find(this.options.inputName),this.$buttonSelect=this.$container.find(this.options.buttonSelect),this.$buttonSelect.on("click",this.modalOpen.bind(this)),this.$modal.on("hide",this.removeIframe.bind(this));var o,n=this.$input.attr("data-onchange");n&&(o=new Function(n),this.$input.on("change",o.bind(this.$input)))},t.fieldUser.prototype.modalOpen=function(){var e=t("<iframe>",{name:"field-user-modal",src:this.options.url.replace("{field-user-id}",this.$input.attr("id")),width:this.options.modalWidth,height:this.options.modalHeight});this.$modalBody.append(e),this.$modal.modal("show"),t("body").addClass("modal-open");var i=this;e.load((function(){t(this).contents().on("click",".button-select",(function(){i.setValue(t(this).data("user-value"),t(this).data("user-name")),i.modalClose(),t("body").removeClass("modal-open")}))}))},t.fieldUser.prototype.modalClose=function(){this.$modal.modal("hide"),this.$modalBody.empty(),t("body").removeClass("modal-open")},t.fieldUser.prototype.removeIframe=function(){this.$modalBody.empty(),t("body").removeClass("modal-open")},t.fieldUser.prototype.setValue=function(t,e){this.$input.val(t).trigger("change"),this.$inputName.val(e||t).trigger("change")},t.fieldUser.defaults={buttonSelect:".button-select",input:".field-user-input",inputName:".field-user-input-name",modal:".modal",url:"index.php?option=com_users&view=users&layout=modal&tmpl=component",modalWidth:"100%",modalHeight:"300px"},t.fn.fieldUser=function(e){return this.each((function(){var e=t(this),i=e.data("fieldUser");if(!i){var o=o||{},n=e.data();for(var a in n)n.hasOwnProperty(a)&&(o[a]=n[a]);i=new t.fieldUser(this,o),e.data("fieldUser",i)}}))},t((function(t){function e(e,i){t(i||document).find(".field-user-wrapper").fieldUser()}e(),t(document).on("subform-row-add",e)}))})(jQuery);