!function(){function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(e,t){for(var i=0;i/g,interpolate:/\{\{\{([\s\S]+?)\}\}\}/g,escape:/\{\{([^\}]+?)\}\}(?!\})/g,variable:"data"};return function(t){return _.template(i.container.find(".customize-control-repeatable-content").first().html(),null,e)(t)}}));var r=this.getValue();r.length&&_.each(r,(function(t){e.addRow(t)})),this.repeatableFieldsContainer.sortable({handle:".repeatable-row-header",update:function(t,i){return e.sort()},axis:"y"})},getValue:function(){if(this.setting.get())try{return JSON.parse(decodeURI(this.setting.get()))}catch(e){return console.info("JSON PARSING ISSUE:",e),[]}return[]},setValue:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.setting.set(encodeURI(JSON.stringify(e))),t&&this.settingField.trigger("change")},addRow:function(e){var t=this,r=this.repeatableTemplate(),n=this.getValue(),a={};if(r){var o=jQuery.extend(!0,{},this.params.fields);if(e)for(var s in e)e.hasOwnProperty(s)&&o.hasOwnProperty(s)&&(o[s].default=e[s]);o.index=this.currentIndex,r=r(o);var l=new i(this.currentIndex,jQuery(r).appendTo(this.repeatableFieldsContainer),this.params.row_label);for(var c in l.container.on("row:remove",(function(e,i){t.deleteRow(i)})),l.container.on("row:update",(function(e,i,r,n){t.updateField(e,i,r,n)})),this.rows[this.currentIndex]=l,o)o.hasOwnProperty(c)&&(a[c]=o[c].default);return n[this.currentIndex]=a,this.setValue(n,!0),this.currentIndex++,l}},sort:function(){var e=this,t=this.repeatableFieldsContainer.find(".repeatable-row"),i=[],r=this.getValue(),n=[],a=[];t.each((function(e,t){i.push(jQuery(t).data("row"))})),jQuery.each(i,(function(t,i){n[t]=e.rows[i],n[t].setRowIndex(t),a[t]=r[i]})),this.rows=n,this.setValue(a)},deleteRow:function(e){var t=this,i=this.getValue();i[e]&&(this.rows[e]&&(i.splice(e,1),this.rows.splice(e,1),this.setValue(i,!0)));this.rows.map((function(e,i){return t.rows[i].setRowIndex(i)}))},updateField:function(e,t,i,r){if(this.rows[t]&&this.params.fields[i]){var n=this.params.fields[i].type,a=this.rows[t],o=this.getValue(),s=jQuery(r);void 0!==o[a.rowIndex][i]&&(o[a.rowIndex][i]="checkbox"===n?s.is(":checked"):s.val(),this.setValue(o,!0))}},initColorPicker:function(){"use strict";var t=this,i=t.container.find(".color-picker-hex"),r={},n=i.data("field");void 0!==n&&void 0!==t.params.fields[n]&&void 0!==t.params.fields[n].palettes&&"object"===e(t.params.fields[n].palettes)&&(r.palettes=t.params.fields[n].palettes),r.change=function(e,i){var r=jQuery(e.target),n=r.closest(".repeatable-row").data("row"),a=t.getValue();a[n][r.data("field")]=i.color.toString(),t.setValue(a,!0)},0!==i.length&&i.wpColorPicker(r)},initDropdownPages:function(e,t){"use strict";var i,r,n=this,a=e.container.find(".repeatable-dropdown-pages select");0!==a.length&&(i=jQuery(a).selectize()[0].selectize,r=a.data("field"),t&&i.setValue(t[r]),this.container.on("change",".repeatable-dropdown-pages select",(function(e){var t=jQuery(e.target),i=t.closest(".repeatable-row").data("row"),r=n.getValue();r[i][t.data("field")]=jQuery(this).val(),n.setValue(r)})))}};wp.customize.controlConstructor.repeatable=wp.customize.Control.extend(r)}();