advanced-custom-fields-pro/assets/build/js/pro/acf-pro-input.min.js

1 line
19 KiB
JavaScript

!function(i){var t=acf.Field.extend({type:"repeater",wait:"",events:{'click a[data-event="add-row"]':"onClickAdd",'click a[data-event="duplicate-row"]':"onClickDuplicate",'click a[data-event="remove-row"]':"onClickRemove",'click a[data-event="collapse-row"]':"onClickCollapse",showField:"onShow",unloadField:"onUnload",mouseover:"onHover"},$control:function(){return this.$(".acf-repeater:first")},$table:function(){return this.$("table:first")},$tbody:function(){return this.$("tbody:first")},$rows:function(){return this.$("tbody:first > tr").not(".acf-clone")},$row:function(t){return this.$("tbody:first > tr:eq("+t+")")},$clone:function(){return this.$("tbody:first > tr.acf-clone")},$actions:function(){return this.$(".acf-actions:last")},$button:function(){return this.$(".acf-actions:last .button")},getValue:function(){return this.$rows().length},allowRemove:function(){var t=parseInt(this.get("min"));return!t||t<this.val()},allowAdd:function(){var t=parseInt(this.get("max"));return!t||t>this.val()},addSortable:function(a){1!=this.get("max")&&this.$tbody().sortable({items:"> tr",handle:"> td.order",forceHelperSize:!0,forcePlaceholderSize:!0,scroll:!0,stop:function(t,e){a.render()},update:function(t,e){a.$input().trigger("change")}})},addCollapsed:function(){var e=a.load(this.get("key"));if(!e)return!1;this.$rows().each(function(t){-1<e.indexOf(t)&&i(this).addClass("-collapsed")})},addUnscopedEvents:function(a){this.on("invalidField",".acf-row",function(t){var e=i(this);a.isCollapsed(e)&&a.expand(e)})},initialize:function(){this.addUnscopedEvents(this),this.addCollapsed(),acf.disable(this.$clone(),this.cid),this.render()},render:function(){this.$rows().each(function(t){i(this).find("> .order > span").html(t+1)});var t=this.$control(),e=this.$button();0==this.val()?t.addClass("-empty"):t.removeClass("-empty"),this.allowAdd()?(t.removeClass("-max"),e.removeClass("disabled")):(t.addClass("-max"),e.addClass("disabled"))},validateAdd:function(){if(this.allowAdd())return!0;var t=this.get("max"),e=(e=acf.__("Maximum rows reached ({max} rows)")).replace("{max}",t);return this.showNotice({text:e,type:"warning"}),!1},onClickAdd:function(t,e){if(!this.validateAdd())return!1;e.hasClass("acf-icon")?this.add({before:e.closest(".acf-row")}):this.add()},add:function(a){if(!this.allowAdd())return!1;a=acf.parseArgs(a,{before:!1});var t=acf.duplicate({target:this.$clone(),append:this.proxy(function(t,e){(a.before||t).before(e),e.removeClass("acf-clone"),acf.enable(e,this.cid),this.render()})});return this.$input().trigger("change"),t},onClickDuplicate:function(t,e){if(!this.validateAdd())return!1;e=e.closest(".acf-row");this.duplicateRow(e)},duplicateRow:function(t){if(!this.allowAdd())return!1;var n=this.get("key"),t=acf.duplicate({target:t,rename:function(t,e,a,i){return"id"===t?e.replace(n+"-"+a,n+"-"+i):e.replace(n+"]["+a,n+"]["+i)},before:function(t){acf.doAction("unmount",t)},after:function(t,e){acf.doAction("remount",t)}});return this.$input().trigger("change"),this.render(),acf.focusAttention(t),t},validateRemove:function(){if(this.allowRemove())return!0;var t=this.get("min"),e=(e=acf.__("Minimum rows reached ({min} rows)")).replace("{min}",t);return this.showNotice({text:e,type:"warning"}),!1},onClickRemove:function(t,e){var a=e.closest(".acf-row");if(t.shiftKey)return this.remove(a);a.addClass("-hover");acf.newTooltip({confirmRemove:!0,target:e,context:this,confirm:function(){this.remove(a)},cancel:function(){a.removeClass("-hover")}})},remove:function(t){var e=this;acf.remove({target:t,endHeight:0,complete:function(){e.$input().trigger("change"),e.render()}})},isCollapsed:function(t){return t.hasClass("-collapsed")},collapse:function(t){t.addClass("-collapsed"),acf.doAction("hide",t,"collapse")},expand:function(t){t.removeClass("-collapsed"),acf.doAction("show",t,"collapse")},onClickCollapse:function(t,e){var a=e.closest(".acf-row"),e=this.isCollapsed(a);t.shiftKey&&(a=this.$rows()),e?this.expand(a):this.collapse(a)},onShow:function(t,e,a){var i=acf.getFields({is:":visible",parent:this.$el});acf.doAction("show_fields",i)},onUnload:function(){var e=[];this.$rows().each(function(t){i(this).hasClass("-collapsed")&&e.push(t)}),e=e.length?e:null,a.save(this.get("key"),e)},onHover:function(){this.addSortable(this),this.off("mouseover")}});acf.registerFieldType(t),acf.registerConditionForFieldType("hasValue","repeater"),acf.registerConditionForFieldType("hasNoValue","repeater"),acf.registerConditionForFieldType("lessThan","repeater"),acf.registerConditionForFieldType("greaterThan","repeater");var a=new acf.Model({name:"this.collapsedRows",key:function(t,e){var a=this.get(t+e)||0;return this.set(t+e,++a,!0),1<a&&(t+="-"+a),t},load:function(t){var t=this.key(t,"load"),e=acf.getPreference(this.name);return!(!e||!e[t])&&e[t]},save:function(t,e){var t=this.key(t,"save"),a=acf.getPreference(this.name)||{};null===e?delete a[t]:a[t]=e,i.isEmptyObject(a)&&(a=null),acf.setPreference(this.name,a)}})}(jQuery),function(r){var t=acf.Field.extend({type:"flexible_content",wait:"",events:{'click [data-name="add-layout"]':"onClickAdd",'click [data-name="duplicate-layout"]':"onClickDuplicate",'click [data-name="remove-layout"]':"onClickRemove",'click [data-name="collapse-layout"]':"onClickCollapse",showField:"onShow",unloadField:"onUnload",mouseover:"onHover"},$control:function(){return this.$(".acf-flexible-content:first")},$layoutsWrap:function(){return this.$(".acf-flexible-content:first > .values")},$layouts:function(){return this.$(".acf-flexible-content:first > .values > .layout")},$layout:function(t){return this.$(".acf-flexible-content:first > .values > .layout:eq("+t+")")},$clonesWrap:function(){return this.$(".acf-flexible-content:first > .clones")},$clones:function(){return this.$(".acf-flexible-content:first > .clones > .layout")},$clone:function(t){return this.$('.acf-flexible-content:first > .clones > .layout[data-layout="'+t+'"]')},$actions:function(){return this.$(".acf-actions:last")},$button:function(){return this.$(".acf-actions:last .button")},$popup:function(){return this.$(".tmpl-popup:last")},getPopupHTML:function(){var t=this.$popup().html(),e=r(t),l=this.$layouts();return e.find("[data-layout]").each(function(){var t,e,a=r(this),i=a.data("min")||0,n=a.data("max")||0,o=a.data("layout")||"",s=(t=o,l.filter(function(){return r(this).data("layout")===t}).length);n&&n<=s?a.addClass("disabled"):i&&s<i&&(e=i-s,n=acf.__("{required} {label} {identifier} required (min {min})"),s=acf._n("layout","layouts",e),n=(n=(n=(n=n.replace("{required}",e)).replace("{label}",o)).replace("{identifier}",s)).replace("{min}",i),a.append('<span class="badge" title="'+n+'">'+e+"</span>"))}),e.outerHTML()},getValue:function(){return this.$layouts().length},allowRemove:function(){var t=parseInt(this.get("min"));return!t||t<this.val()},allowAdd:function(){var t=parseInt(this.get("max"));return!t||t>this.val()},isFull:function(){var t=parseInt(this.get("max"));return t&&this.val()>=t},addSortable:function(a){1!=this.get("max")&&this.$layoutsWrap().sortable({items:"> .layout",handle:"> .acf-fc-layout-handle",forceHelperSize:!0,forcePlaceholderSize:!0,scroll:!0,stop:function(t,e){a.render()},update:function(t,e){a.$input().trigger("change")}})},addCollapsed:function(){var e=a.load(this.get("key"));if(!e)return!1;this.$layouts().each(function(t){-1<e.indexOf(t)&&r(this).addClass("-collapsed")})},addUnscopedEvents:function(e){this.on("invalidField",".layout",function(t){e.onInvalidField(t,r(this))})},initialize:function(){this.addUnscopedEvents(this),this.addCollapsed(),acf.disable(this.$clonesWrap(),this.cid),this.render()},render:function(){this.$layouts().each(function(t){r(this).find(".acf-fc-layout-order:first").html(t+1)}),0==this.val()?this.$control().addClass("-empty"):this.$control().removeClass("-empty"),this.isFull()?this.$button().addClass("disabled"):this.$button().removeClass("disabled")},onShow:function(t,e,a){var i=acf.getFields({is:":visible",parent:this.$el});acf.doAction("show_fields",i)},validateAdd:function(){if(this.allowAdd())return!0;var t=this.get("max"),e=acf.__("This field has a limit of {max} {label} {identifier}"),a=acf._n("layout","layouts",t);return e=(e=(e=e.replace("{max}",t)).replace("{label}","")).replace("{identifier}",a),this.showNotice({text:e,type:"warning"}),!1},onClickAdd:function(t,e){if(!this.validateAdd())return!1;var a=null;e.hasClass("acf-icon")&&(a=e.closest(".layout")).addClass("-hover"),new i({target:e,targetConfirm:!1,text:this.getPopupHTML(),context:this,confirm:function(t,e){e.hasClass("disabled")||this.add({layout:e.data("layout"),before:a})},cancel:function(){a&&a.removeClass("-hover")}}).on("click","[data-layout]","onConfirm")},add:function(a){if(a=acf.parseArgs(a,{layout:"",before:!1}),!this.allowAdd())return!1;var t=acf.duplicate({target:this.$clone(a.layout),append:this.proxy(function(t,e){a.before?a.before.before(e):this.$layoutsWrap().append(e),acf.enable(e,this.cid),this.render()})});return this.$input().trigger("change"),t},onClickDuplicate:function(t,e){if(!this.validateAdd())return!1;e=e.closest(".layout");this.duplicateLayout(e)},duplicateLayout:function(t){if(!this.allowAdd())return!1;var n=this.get("key"),t=acf.duplicate({target:t,rename:function(t,e,a,i){return"id"===t?e.replace(n+"-"+a,n+"-"+i):e.replace(n+"]["+a,n+"]["+i)},before:function(t){acf.doAction("unmount",t)},after:function(t,e){acf.doAction("remount",t)}});return this.$input().trigger("change"),this.render(),acf.focusAttention(t),t},validateRemove:function(){if(this.allowRemove())return!0;var t=this.get("min"),e=acf.__("This field requires at least {min} {label} {identifier}"),a=acf._n("layout","layouts",t);return e=(e=(e=e.replace("{min}",t)).replace("{label}","")).replace("{identifier}",a),this.showNotice({text:e,type:"warning"}),!1},onClickRemove:function(t,e){var a=e.closest(".layout");if(t.shiftKey)return this.removeLayout(a);a.addClass("-hover");acf.newTooltip({confirmRemove:!0,target:e,context:this,confirm:function(){this.removeLayout(a)},cancel:function(){a.removeClass("-hover")}})},removeLayout:function(t){var e=this,a=1==this.getValue()?60:0;acf.remove({target:t,endHeight:a,complete:function(){e.$input().trigger("change"),e.render()}})},onClickCollapse:function(t,e){e=e.closest(".layout");this.isLayoutClosed(e)?this.openLayout(e):this.closeLayout(e)},isLayoutClosed:function(t){return t.hasClass("-collapsed")},openLayout:function(t){t.removeClass("-collapsed"),acf.doAction("show",t,"collapse")},closeLayout:function(t){t.addClass("-collapsed"),acf.doAction("hide",t,"collapse"),this.renderLayout(t)},renderLayout:function(e){var t=e.children("input").attr("name").replace("[acf_fc_layout]",""),t={action:"acf/fields/flexible_content/layout_title",field_key:this.get("key"),i:e.index(),layout:e.data("layout"),value:acf.serialize(e,t)};r.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(t),dataType:"html",type:"post",success:function(t){t&&e.children(".acf-fc-layout-handle").html(t)}})},onUnload:function(){var e=[];this.$layouts().each(function(t){r(this).hasClass("-collapsed")&&e.push(t)}),e=e.length?e:null,a.save(this.get("key"),e)},onInvalidField:function(t,e){this.isLayoutClosed(e)&&this.openLayout(e)},onHover:function(){this.addSortable(this),this.off("mouseover")}});acf.registerFieldType(t);var i=acf.models.TooltipConfirm.extend({events:{"click [data-layout]":"onConfirm",'click [data-event="cancel"]':"onCancel"},render:function(){this.html(this.get("text")),this.$el.addClass("acf-fc-popup")}});acf.registerConditionForFieldType("hasValue","flexible_content"),acf.registerConditionForFieldType("hasNoValue","flexible_content"),acf.registerConditionForFieldType("lessThan","flexible_content"),acf.registerConditionForFieldType("greaterThan","flexible_content");var a=new acf.Model({name:"this.collapsedLayouts",key:function(t,e){var a=this.get(t+e)||0;return this.set(t+e,++a,!0),1<a&&(t+="-"+a),t},load:function(t){var t=this.key(t,"load"),e=acf.getPreference(this.name);return!(!e||!e[t])&&e[t]},save:function(t,e){var t=this.key(t,"save"),a=acf.getPreference(this.name)||{};null===e?delete a[t]:a[t]=e,r.isEmptyObject(a)&&(a=null),acf.setPreference(this.name,a)}})}(jQuery),function(o){var t=acf.Field.extend({type:"gallery",events:{"click .acf-gallery-add":"onClickAdd","click .acf-gallery-edit":"onClickEdit","click .acf-gallery-remove":"onClickRemove","click .acf-gallery-attachment":"onClickSelect","click .acf-gallery-close":"onClickClose","change .acf-gallery-sort":"onChangeSort","click .acf-gallery-update":"onUpdate",mouseover:"onHover",showField:"render"},actions:{validation_begin:"onValidationBegin",validation_failure:"onValidationFailure",resize:"onResize"},onValidationBegin:function(){acf.disable(this.$sideData(),this.cid)},onValidationFailure:function(){acf.enable(this.$sideData(),this.cid)},$control:function(){return this.$(".acf-gallery")},$collection:function(){return this.$(".acf-gallery-attachments")},$attachments:function(){return this.$(".acf-gallery-attachment")},$attachment:function(t){return this.$('.acf-gallery-attachment[data-id="'+t+'"]')},$active:function(){return this.$(".acf-gallery-attachment.active")},$main:function(){return this.$(".acf-gallery-main")},$side:function(){return this.$(".acf-gallery-side")},$sideData:function(){return this.$(".acf-gallery-side-data")},isFull:function(){var t=parseInt(this.get("max")),e=this.$attachments().length;return t&&t<=e},getValue:function(){var t=[];return this.$attachments().each(function(){t.push(o(this).data("id"))}),!!t.length&&t},addUnscopedEvents:function(e){this.on("change",".acf-gallery-side",function(t){e.onUpdate(t,o(this))})},addSortable:function(a){this.$collection().sortable({items:".acf-gallery-attachment",forceHelperSize:!0,forcePlaceholderSize:!0,scroll:!0,start:function(t,e){e.placeholder.html(e.item.html()),e.placeholder.removeAttr("style")},update:function(t,e){a.$input().trigger("change")}}),this.$control().resizable({handles:"s",minHeight:200,stop:function(t,e){acf.update_user_setting("gallery_height",e.size.height)}})},initialize:function(){this.addUnscopedEvents(this),this.render()},render:function(){var t=this.$(".acf-gallery-sort"),e=this.$(".acf-gallery-add"),a=this.$attachments().length;this.isFull()?e.addClass("disabled"):e.removeClass("disabled"),a?t.removeClass("disabled"):t.addClass("disabled"),this.resize()},resize:function(){var t=this.$control().width(),t=Math.round(t/150),t=Math.min(t,8);this.$control().attr("data-columns",t)},onResize:function(){this.resize()},openSidebar:function(){this.$control().addClass("-open");var t=this.$control().width()/3,t=parseInt(t);t=Math.max(t,350),this.$(".acf-gallery-side-inner").css({width:t-1}),this.$side().animate({width:t-1},250),this.$main().animate({right:t},250)},closeSidebar:function(){this.$control().removeClass("-open"),this.$active().removeClass("active"),acf.disable(this.$side());var t=this.$(".acf-gallery-side-data");this.$main().animate({right:0},250),this.$side().animate({width:0},250,function(){t.html("")})},onClickAdd:function(t,e){this.isFull()?this.showNotice({text:acf.__("Maximum selection reached"),type:"warning"}):acf.newMediaPopup({mode:"select",title:acf.__("Add Image to Gallery"),field:this.get("key"),multiple:"add",library:this.get("library"),allowedTypes:this.get("mime_types"),selected:this.val(),select:o.proxy(function(t,e){this.appendAttachment(t,e)},this)})},appendAttachment:function(t,e){var a;t=this.validateAttachment(t),this.isFull()||this.$attachment(t.id).length||(a=['<div class="acf-gallery-attachment" data-id="'+t.id+'">','<input type="hidden" value="'+t.id+'" name="'+this.getInputName()+'[]">','<div class="margin" title="">','<div class="thumbnail">','<img src="" alt="">',"</div>",'<div class="filename"></div>',"</div>",'<div class="actions">','<a href="#" class="acf-icon -cancel dark acf-gallery-remove" data-id="'+t.id+'"></a>',"</div>","</div>"].join(""),a=o(a),this.$collection().append(a),"prepend"!==this.get("insert")||(e=this.$attachments().eq(e)).length&&e.before(a),this.renderAttachment(t),this.render(),this.$input().trigger("change"))},validateAttachment:function(t){var e;return(t=acf.parseArgs(t,{id:"",url:"",alt:"",title:"",filename:"",type:"image"})).attributes&&(t=t.attributes,null!==(e=acf.isget(t,"sizes",this.get("preview_size"),"url"))&&(t.url=e)),t},renderAttachment:function(t){t=this.validateAttachment(t);var e,a=this.$attachment(t.id);"image"==t.type?a.find(".filename").remove():(null!==(e=acf.isget(t,"image","src"))&&(t.url=e),a.find(".filename").text(t.filename)),t.url||(t.url=acf.get("mimeTypeIcon"),a.addClass("-icon")),a.find("img").attr({src:t.url,alt:t.alt,title:t.title}),acf.val(a.find("input"),t.id)},editAttachment:function(t){acf.newMediaPopup({mode:"edit",title:acf.__("Edit Image"),button:acf.__("Update Image"),attachment:t,field:this.get("key"),select:o.proxy(function(t,e){this.renderAttachment(t)},this)})},onClickEdit:function(t,e){e=e.data("id");e&&this.editAttachment(e)},removeAttachment:function(t){this.closeSidebar(),this.$attachment(t).remove(),this.render(),this.$input().trigger("change")},onClickRemove:function(t,e){t.preventDefault(),t.stopPropagation();e=e.data("id");e&&this.removeAttachment(e)},selectAttachment:function(e){var t,a,i,n=this.$attachment(e);n.hasClass("active")||(t=this.proxy(function(){this.$side().find(":focus").trigger("blur"),this.$active().removeClass("active"),n.addClass("active"),this.openSidebar(),a()}),a=this.proxy(function(){var t={action:"acf/fields/gallery/get_attachment",field_key:this.get("key"),id:e};this.has("xhr")&&this.get("xhr").abort(),acf.showLoading(this.$sideData());t=o.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(t),type:"post",dataType:"html",cache:!1,success:i});this.set("xhr",t)}),i=this.proxy(function(t){var e;t&&((e=this.$sideData()).html(t),e.find(".compat-field-acf-form-data").remove(),e.find("> table.form-table > tbody").append(e.find("> .compat-attachment-fields > tbody > tr")),acf.doAction("append",e))}),t())},onClickSelect:function(t,e){e=e.data("id");e&&this.selectAttachment(e)},onClickClose:function(t,e){this.closeSidebar()},onChangeSort:function(t,e){var a,i,n;e.hasClass("disabled")||(a=e.val())&&(i=[],this.$attachments().each(function(){i.push(o(this).data("id"))}),e=this.proxy(function(){var t={action:"acf/fields/gallery/get_sort_order",field_key:this.get("key"),ids:i,sort:a};o.ajax({url:acf.get("ajaxurl"),dataType:"json",type:"post",cache:!1,data:acf.prepareForAjax(t),success:n})}),n=this.proxy(function(t){acf.isAjaxSuccess(t)&&(t.data.reverse(),t.data.map(function(t){this.$collection().prepend(this.$attachment(t))},this))}),e())},onUpdate:function(t,e){var a,i=this.$(".acf-gallery-update");i.hasClass("disabled")||(a=acf.serialize(this.$sideData()),i.addClass("disabled"),i.before('<i class="acf-loading"></i> '),a.action="acf/fields/gallery/update_attachment",o.ajax({url:acf.get("ajaxurl"),data:acf.prepareForAjax(a),type:"post",dataType:"json",complete:function(){i.removeClass("disabled"),i.prev(".acf-loading").remove()}}))},onHover:function(){this.addSortable(this),this.off("mouseover")}});acf.registerFieldType(t),acf.registerConditionForFieldType("hasValue","gallery"),acf.registerConditionForFieldType("hasNoValue","gallery"),acf.registerConditionForFieldType("selectionLessThan","gallery"),acf.registerConditionForFieldType("selectionGreaterThan","gallery")}(jQuery);