1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101 |
- /******/ (function() { // webpackBootstrap
- /******/ var __webpack_modules__ = ({
- /***/ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-flexible-content.js":
- /*!*****************************************************************************************!*\
- !*** ./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-flexible-content.js ***!
- \*****************************************************************************************/
- /***/ (function() {
- (function ($) {
- var Field = 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 (index) {
- return this.$('.acf-flexible-content:first > .values > .layout:eq(' + index + ')');
- },
- $clonesWrap: function () {
- return this.$('.acf-flexible-content:first > .clones');
- },
- $clones: function () {
- return this.$('.acf-flexible-content:first > .clones > .layout');
- },
- $clone: function (name) {
- return this.$('.acf-flexible-content:first > .clones > .layout[data-layout="' + name + '"]');
- },
- $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 html = this.$popup().html();
- var $html = $(html);
- // count layouts
- var $layouts = this.$layouts();
- var countLayouts = function (name) {
- return $layouts.filter(function () {
- return $(this).data('layout') === name;
- }).length;
- };
- // modify popup
- $html.find('[data-layout]').each(function () {
- var $a = $(this);
- var min = $a.data('min') || 0;
- var max = $a.data('max') || 0;
- var name = $a.data('layout') || '';
- var count = countLayouts(name);
- // max
- if (max && count >= max) {
- $a.addClass('disabled');
- return;
- }
- // min
- if (min && count < min) {
- var required = min - count;
- var title = acf.__('{required} {label} {identifier} required (min {min})');
- var identifier = acf._n('layout', 'layouts', required);
- // translate
- title = title.replace('{required}', required);
- title = title.replace('{label}', name); // 5.5.0
- title = title.replace('{identifier}', identifier);
- title = title.replace('{min}', min);
- // badge
- $a.append('<span class="badge" title="' + title + '">' + required + '</span>');
- }
- });
- // update
- html = $html.outerHTML();
- return html;
- },
- getValue: function () {
- return this.$layouts().length;
- },
- allowRemove: function () {
- var min = parseInt(this.get('min'));
- return !min || min < this.val();
- },
- allowAdd: function () {
- var max = parseInt(this.get('max'));
- return !max || max > this.val();
- },
- isFull: function () {
- var max = parseInt(this.get('max'));
- return max && this.val() >= max;
- },
- addSortable: function (self) {
- // bail early if max 1 row
- if (this.get('max') == 1) {
- return;
- }
- // add sortable
- this.$layoutsWrap().sortable({
- items: '> .layout',
- handle: '> .acf-fc-layout-handle',
- forceHelperSize: true,
- forcePlaceholderSize: true,
- scroll: true,
- stop: function (event, ui) {
- self.render();
- },
- update: function (event, ui) {
- self.$input().trigger('change');
- }
- });
- },
- addCollapsed: function () {
- var indexes = preference.load(this.get('key'));
- // bail early if no collapsed
- if (!indexes) {
- return false;
- }
- // loop
- this.$layouts().each(function (i) {
- if (indexes.indexOf(i) > -1) {
- $(this).addClass('-collapsed');
- }
- });
- },
- addUnscopedEvents: function (self) {
- // invalidField
- this.on('invalidField', '.layout', function (e) {
- self.onInvalidField(e, $(this));
- });
- },
- initialize: function () {
- // add unscoped events
- this.addUnscopedEvents(this);
- // add collapsed
- this.addCollapsed();
- // disable clone
- acf.disable(this.$clonesWrap(), this.cid);
- // render
- this.render();
- },
- render: function () {
- // update order number
- this.$layouts().each(function (i) {
- $(this).find('.acf-fc-layout-order:first').html(i + 1);
- });
- // empty
- if (this.val() == 0) {
- this.$control().addClass('-empty');
- } else {
- this.$control().removeClass('-empty');
- }
- // max
- if (this.isFull()) {
- this.$button().addClass('disabled');
- } else {
- this.$button().removeClass('disabled');
- }
- },
- onShow: function (e, $el, context) {
- // get sub fields
- var fields = acf.getFields({
- is: ':visible',
- parent: this.$el
- });
- // trigger action
- // - ignore context, no need to pass through 'conditional_logic'
- // - this is just for fields like google_map to render itself
- acf.doAction('show_fields', fields);
- },
- validateAdd: function () {
- // return true if allowed
- if (this.allowAdd()) {
- return true;
- }
- var max = this.get('max');
- var text = acf.__('This field has a limit of {max} {label} {identifier}');
- var identifier = acf._n('layout', 'layouts', max);
- // replace
- text = text.replace('{max}', max);
- text = text.replace('{label}', '');
- text = text.replace('{identifier}', identifier);
- // add notice
- this.showNotice({
- text: text,
- type: 'warning'
- });
- return false;
- },
- onClickAdd: function (e, $el) {
- // validate
- if (!this.validateAdd()) {
- return false;
- }
- // within layout
- var $layout = null;
- if ($el.hasClass('acf-icon')) {
- $layout = $el.closest('.layout');
- $layout.addClass('-hover');
- }
- // new popup
- var popup = new Popup({
- target: $el,
- targetConfirm: false,
- text: this.getPopupHTML(),
- context: this,
- confirm: function (e, $el) {
- // check disabled
- if ($el.hasClass('disabled')) {
- return;
- }
- // add
- this.add({
- layout: $el.data('layout'),
- before: $layout
- });
- },
- cancel: function () {
- if ($layout) {
- $layout.removeClass('-hover');
- }
- }
- });
- // add extra event
- popup.on('click', '[data-layout]', 'onConfirm');
- },
- add: function (args) {
- // defaults
- args = acf.parseArgs(args, {
- layout: '',
- before: false
- });
- // validate
- if (!this.allowAdd()) {
- return false;
- }
- // add row
- var $el = acf.duplicate({
- target: this.$clone(args.layout),
- append: this.proxy(function ($el, $el2) {
- // append
- if (args.before) {
- args.before.before($el2);
- } else {
- this.$layoutsWrap().append($el2);
- }
- // enable
- acf.enable($el2, this.cid);
- // render
- this.render();
- })
- });
- // trigger change for validation errors
- this.$input().trigger('change');
- return $el;
- },
- onClickDuplicate: function (e, $el) {
- // Validate with warning.
- if (!this.validateAdd()) {
- return false;
- }
- // get layout and duplicate it.
- var $layout = $el.closest('.layout');
- this.duplicateLayout($layout);
- },
- duplicateLayout: function ($layout) {
- // Validate without warning.
- if (!this.allowAdd()) {
- return false;
- }
- var fieldKey = this.get('key');
- // Duplicate layout.
- var $el = acf.duplicate({
- target: $layout,
- // Provide a custom renaming callback to avoid renaming parent row attributes.
- rename: function (name, value, search, replace) {
- // Rename id attributes from "field_1-search" to "field_1-replace".
- if (name === 'id' || name === 'for') {
- return value.replace(fieldKey + '-' + search, fieldKey + '-' + replace);
- // Rename name and for attributes from "[field_1][search]" to "[field_1][replace]".
- } else {
- return value.replace(fieldKey + '][' + search, fieldKey + '][' + replace);
- }
- },
- before: function ($el) {
- acf.doAction('unmount', $el);
- },
- after: function ($el, $el2) {
- acf.doAction('remount', $el);
- }
- });
- // trigger change for validation errors
- this.$input().trigger('change');
- // Update order numbers.
- this.render();
- // Draw focus to layout.
- acf.focusAttention($el);
- // Return new layout.
- return $el;
- },
- validateRemove: function () {
- // return true if allowed
- if (this.allowRemove()) {
- return true;
- }
- var min = this.get('min');
- var text = acf.__('This field requires at least {min} {label} {identifier}');
- var identifier = acf._n('layout', 'layouts', min);
- // replace
- text = text.replace('{min}', min);
- text = text.replace('{label}', '');
- text = text.replace('{identifier}', identifier);
- // add notice
- this.showNotice({
- text: text,
- type: 'warning'
- });
- return false;
- },
- onClickRemove: function (e, $el) {
- var $layout = $el.closest('.layout');
- // Bypass confirmation when holding down "shift" key.
- if (e.shiftKey) {
- return this.removeLayout($layout);
- }
- // add class
- $layout.addClass('-hover');
- // add tooltip
- var tooltip = acf.newTooltip({
- confirmRemove: true,
- target: $el,
- context: this,
- confirm: function () {
- this.removeLayout($layout);
- },
- cancel: function () {
- $layout.removeClass('-hover');
- }
- });
- },
- removeLayout: function ($layout) {
- // reference
- var self = this;
- var endHeight = this.getValue() == 1 ? 60 : 0;
- // remove
- acf.remove({
- target: $layout,
- endHeight: endHeight,
- complete: function () {
- // trigger change to allow attachment save
- self.$input().trigger('change');
- // render
- self.render();
- }
- });
- },
- onClickCollapse: function (e, $el) {
- var $layout = $el.closest('.layout');
- // toggle
- if (this.isLayoutClosed($layout)) {
- this.openLayout($layout);
- } else {
- this.closeLayout($layout);
- }
- },
- isLayoutClosed: function ($layout) {
- return $layout.hasClass('-collapsed');
- },
- openLayout: function ($layout) {
- $layout.removeClass('-collapsed');
- acf.doAction('show', $layout, 'collapse');
- },
- closeLayout: function ($layout) {
- $layout.addClass('-collapsed');
- acf.doAction('hide', $layout, 'collapse');
- // render
- // - no change could happen if layout was already closed. Only render when closing
- this.renderLayout($layout);
- },
- renderLayout: function ($layout) {
- var $input = $layout.children('input');
- var prefix = $input.attr('name').replace('[acf_fc_layout]', '');
- // ajax data
- var ajaxData = {
- action: 'acf/fields/flexible_content/layout_title',
- field_key: this.get('key'),
- i: $layout.index(),
- layout: $layout.data('layout'),
- value: acf.serialize($layout, prefix)
- };
- // ajax
- $.ajax({
- url: acf.get('ajaxurl'),
- data: acf.prepareForAjax(ajaxData),
- dataType: 'html',
- type: 'post',
- success: function (html) {
- if (html) {
- $layout.children('.acf-fc-layout-handle').html(html);
- }
- }
- });
- },
- onUnload: function () {
- var indexes = [];
- // loop
- this.$layouts().each(function (i) {
- if ($(this).hasClass('-collapsed')) {
- indexes.push(i);
- }
- });
- // allow null
- indexes = indexes.length ? indexes : null;
- // set
- preference.save(this.get('key'), indexes);
- },
- onInvalidField: function (e, $layout) {
- // open if is collapsed
- if (this.isLayoutClosed($layout)) {
- this.openLayout($layout);
- }
- },
- onHover: function () {
- // add sortable
- this.addSortable(this);
- // remove event
- this.off('mouseover');
- }
- });
- acf.registerFieldType(Field);
- /**
- * Popup
- *
- * description
- *
- * @date 7/4/18
- * @since 5.6.9
- *
- * @param type $var Description. Default.
- * @return type Description.
- */
- var Popup = acf.models.TooltipConfirm.extend({
- events: {
- 'click [data-layout]': 'onConfirm',
- 'click [data-event="cancel"]': 'onCancel'
- },
- render: function () {
- // set HTML
- this.html(this.get('text'));
- // add class
- this.$el.addClass('acf-fc-popup');
- }
- });
- /**
- * conditions
- *
- * description
- *
- * @date 9/4/18
- * @since 5.6.9
- *
- * @param type $var Description. Default.
- * @return type Description.
- */
- // register existing conditions
- acf.registerConditionForFieldType('hasValue', 'flexible_content');
- acf.registerConditionForFieldType('hasNoValue', 'flexible_content');
- acf.registerConditionForFieldType('lessThan', 'flexible_content');
- acf.registerConditionForFieldType('greaterThan', 'flexible_content');
- // state
- var preference = new acf.Model({
- name: 'this.collapsedLayouts',
- key: function (key, context) {
- var count = this.get(key + context) || 0;
- // update
- count++;
- this.set(key + context, count, true);
- // modify fieldKey
- if (count > 1) {
- key += '-' + count;
- }
- return key;
- },
- load: function (key) {
- var key = this.key(key, 'load');
- var data = acf.getPreference(this.name);
- if (data && data[key]) {
- return data[key];
- } else {
- return false;
- }
- },
- save: function (key, value) {
- var key = this.key(key, 'save');
- var data = acf.getPreference(this.name) || {};
- // delete
- if (value === null) {
- delete data[key];
- // append
- } else {
- data[key] = value;
- }
- // allow null
- if ($.isEmptyObject(data)) {
- data = null;
- }
- // save
- acf.setPreference(this.name, data);
- }
- });
- })(jQuery);
- /***/ }),
- /***/ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-gallery.js":
- /*!********************************************************************************!*\
- !*** ./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-gallery.js ***!
- \********************************************************************************/
- /***/ (function() {
- (function ($) {
- var Field = 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 (id) {
- return this.$('.acf-gallery-attachment[data-id="' + id + '"]');
- },
- $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 max = parseInt(this.get('max'));
- var count = this.$attachments().length;
- return max && count >= max;
- },
- getValue: function () {
- // vars
- var val = [];
- // loop
- this.$attachments().each(function () {
- val.push($(this).data('id'));
- });
- // return
- return val.length ? val : false;
- },
- addUnscopedEvents: function (self) {
- // invalidField
- this.on('change', '.acf-gallery-side', function (e) {
- self.onUpdate(e, $(this));
- });
- },
- addSortable: function (self) {
- // add sortable
- this.$collection().sortable({
- items: '.acf-gallery-attachment',
- forceHelperSize: true,
- forcePlaceholderSize: true,
- scroll: true,
- start: function (event, ui) {
- ui.placeholder.html(ui.item.html());
- ui.placeholder.removeAttr('style');
- },
- update: function (event, ui) {
- self.$input().trigger('change');
- }
- });
- // resizable
- this.$control().resizable({
- handles: 's',
- minHeight: 200,
- stop: function (event, ui) {
- acf.update_user_setting('gallery_height', ui.size.height);
- }
- });
- },
- initialize: function () {
- // add unscoped events
- this.addUnscopedEvents(this);
- // render
- this.render();
- },
- render: function () {
- // vars
- var $sort = this.$('.acf-gallery-sort');
- var $add = this.$('.acf-gallery-add');
- var count = this.$attachments().length;
- // disable add
- if (this.isFull()) {
- $add.addClass('disabled');
- } else {
- $add.removeClass('disabled');
- }
- // disable select
- if (!count) {
- $sort.addClass('disabled');
- } else {
- $sort.removeClass('disabled');
- }
- // resize
- this.resize();
- },
- resize: function () {
- // vars
- var width = this.$control().width();
- var target = 150;
- var columns = Math.round(width / target);
- // max columns = 8
- columns = Math.min(columns, 8);
- // update data
- this.$control().attr('data-columns', columns);
- },
- onResize: function () {
- this.resize();
- },
- openSidebar: function () {
- // add class
- this.$control().addClass('-open');
- // hide bulk actions
- // should be done with CSS
- //this.$main().find('.acf-gallery-sort').hide();
- // vars
- var width = this.$control().width() / 3;
- width = parseInt(width);
- width = Math.max(width, 350);
- // animate
- this.$('.acf-gallery-side-inner').css({
- width: width - 1
- });
- this.$side().animate({
- width: width - 1
- }, 250);
- this.$main().animate({
- right: width
- }, 250);
- },
- closeSidebar: function () {
- // remove class
- this.$control().removeClass('-open');
- // clear selection
- this.$active().removeClass('active');
- // disable sidebar
- acf.disable(this.$side());
- // animate
- var $sideData = this.$('.acf-gallery-side-data');
- this.$main().animate({
- right: 0
- }, 250);
- this.$side().animate({
- width: 0
- }, 250, function () {
- $sideData.html('');
- });
- },
- onClickAdd: function (e, $el) {
- // validate
- if (this.isFull()) {
- this.showNotice({
- text: acf.__('Maximum selection reached'),
- type: 'warning'
- });
- return;
- }
- // new frame
- var frame = 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: $.proxy(function (attachment, i) {
- this.appendAttachment(attachment, i);
- }, this)
- });
- },
- appendAttachment: function (attachment, i) {
- // vars
- attachment = this.validateAttachment(attachment);
- // bail early if is full
- if (this.isFull()) {
- return;
- }
- // bail early if already exists
- if (this.$attachment(attachment.id).length) {
- return;
- }
- // html
- var html = ['<div class="acf-gallery-attachment" data-id="' + attachment.id + '">', '<input type="hidden" value="' + attachment.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="' + attachment.id + '"></a>', '</div>', '</div>'].join('');
- var $html = $(html);
- // append
- this.$collection().append($html);
- // move to beginning
- if (this.get('insert') === 'prepend') {
- var $before = this.$attachments().eq(i);
- if ($before.length) {
- $before.before($html);
- }
- }
- // render attachment
- this.renderAttachment(attachment);
- // render
- this.render();
- // trigger change
- this.$input().trigger('change');
- },
- validateAttachment: function (attachment) {
- // defaults
- attachment = acf.parseArgs(attachment, {
- id: '',
- url: '',
- alt: '',
- title: '',
- filename: '',
- type: 'image'
- });
- // WP attachment
- if (attachment.attributes) {
- attachment = attachment.attributes;
- // preview size
- var url = acf.isget(attachment, 'sizes', this.get('preview_size'), 'url');
- if (url !== null) {
- attachment.url = url;
- }
- }
- // return
- return attachment;
- },
- renderAttachment: function (attachment) {
- // vars
- attachment = this.validateAttachment(attachment);
- // vars
- var $el = this.$attachment(attachment.id);
- // Image type.
- if (attachment.type == 'image') {
- // Remove filename.
- $el.find('.filename').remove();
- // Other file type.
- } else {
- // Check for attachment featured image.
- var image = acf.isget(attachment, 'image', 'src');
- if (image !== null) {
- attachment.url = image;
- }
- // Update filename text.
- $el.find('.filename').text(attachment.filename);
- }
- // Default to mimetype icon.
- if (!attachment.url) {
- attachment.url = acf.get('mimeTypeIcon');
- $el.addClass('-icon');
- }
- // update els
- $el.find('img').attr({
- src: attachment.url,
- alt: attachment.alt,
- title: attachment.title
- });
- // update val
- acf.val($el.find('input'), attachment.id);
- },
- editAttachment: function (id) {
- // new frame
- var frame = acf.newMediaPopup({
- mode: 'edit',
- title: acf.__('Edit Image'),
- button: acf.__('Update Image'),
- attachment: id,
- field: this.get('key'),
- select: $.proxy(function (attachment, i) {
- this.renderAttachment(attachment);
- // todo - render sidebar
- }, this)
- });
- },
- onClickEdit: function (e, $el) {
- var id = $el.data('id');
- if (id) {
- this.editAttachment(id);
- }
- },
- removeAttachment: function (id) {
- // close sidebar (if open)
- this.closeSidebar();
- // remove attachment
- this.$attachment(id).remove();
- // render
- this.render();
- // trigger change
- this.$input().trigger('change');
- },
- onClickRemove: function (e, $el) {
- // prevent event from triggering click on attachment
- e.preventDefault();
- e.stopPropagation();
- //remove
- var id = $el.data('id');
- if (id) {
- this.removeAttachment(id);
- }
- },
- selectAttachment: function (id) {
- // vars
- var $el = this.$attachment(id);
- // bail early if already active
- if ($el.hasClass('active')) {
- return;
- }
- // step 1
- var step1 = this.proxy(function () {
- // save any changes in sidebar
- this.$side().find(':focus').trigger('blur');
- // clear selection
- this.$active().removeClass('active');
- // add selection
- $el.addClass('active');
- // open sidebar
- this.openSidebar();
- // call step 2
- step2();
- });
- // step 2
- var step2 = this.proxy(function () {
- // ajax
- var ajaxData = {
- action: 'acf/fields/gallery/get_attachment',
- field_key: this.get('key'),
- id: id
- };
- // abort prev ajax call
- if (this.has('xhr')) {
- this.get('xhr').abort();
- }
- // loading
- acf.showLoading(this.$sideData());
- // get HTML
- var xhr = $.ajax({
- url: acf.get('ajaxurl'),
- data: acf.prepareForAjax(ajaxData),
- type: 'post',
- dataType: 'html',
- cache: false,
- success: step3
- });
- // update
- this.set('xhr', xhr);
- });
- // step 3
- var step3 = this.proxy(function (html) {
- // bail early if no html
- if (!html) {
- return;
- }
- // vars
- var $side = this.$sideData();
- // render
- $side.html(html);
- // remove acf form data
- $side.find('.compat-field-acf-form-data').remove();
- // merge tables
- $side.find('> table.form-table > tbody').append($side.find('> .compat-attachment-fields > tbody > tr'));
- // setup fields
- acf.doAction('append', $side);
- });
- // run step 1
- step1();
- },
- onClickSelect: function (e, $el) {
- var id = $el.data('id');
- if (id) {
- this.selectAttachment(id);
- }
- },
- onClickClose: function (e, $el) {
- this.closeSidebar();
- },
- onChangeSort: function (e, $el) {
- // Bail early if is disabled.
- if ($el.hasClass('disabled')) {
- return;
- }
- // Get sort val.
- var val = $el.val();
- if (!val) {
- return;
- }
- // find ids
- var ids = [];
- this.$attachments().each(function () {
- ids.push($(this).data('id'));
- });
- // step 1
- var step1 = this.proxy(function () {
- // vars
- var ajaxData = {
- action: 'acf/fields/gallery/get_sort_order',
- field_key: this.get('key'),
- ids: ids,
- sort: val
- };
- // get results
- var xhr = $.ajax({
- url: acf.get('ajaxurl'),
- dataType: 'json',
- type: 'post',
- cache: false,
- data: acf.prepareForAjax(ajaxData),
- success: step2
- });
- });
- // step 2
- var step2 = this.proxy(function (json) {
- // validate
- if (!acf.isAjaxSuccess(json)) {
- return;
- }
- // reverse order
- json.data.reverse();
- // loop
- json.data.map(function (id) {
- this.$collection().prepend(this.$attachment(id));
- }, this);
- });
- // call step 1
- step1();
- },
- onUpdate: function (e, $el) {
- // vars
- var $submit = this.$('.acf-gallery-update');
- // validate
- if ($submit.hasClass('disabled')) {
- return;
- }
- // serialize data
- var ajaxData = acf.serialize(this.$sideData());
- // loading
- $submit.addClass('disabled');
- $submit.before('<i class="acf-loading"></i> ');
- // append AJAX action
- ajaxData.action = 'acf/fields/gallery/update_attachment';
- // ajax
- $.ajax({
- url: acf.get('ajaxurl'),
- data: acf.prepareForAjax(ajaxData),
- type: 'post',
- dataType: 'json',
- complete: function () {
- $submit.removeClass('disabled');
- $submit.prev('.acf-loading').remove();
- }
- });
- },
- onHover: function () {
- // add sortable
- this.addSortable(this);
- // remove event
- this.off('mouseover');
- }
- });
- acf.registerFieldType(Field);
- // register existing conditions
- acf.registerConditionForFieldType('hasValue', 'gallery');
- acf.registerConditionForFieldType('hasNoValue', 'gallery');
- acf.registerConditionForFieldType('selectionLessThan', 'gallery');
- acf.registerConditionForFieldType('selectionGreaterThan', 'gallery');
- })(jQuery);
- /***/ }),
- /***/ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-repeater.js":
- /*!*********************************************************************************!*\
- !*** ./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-repeater.js ***!
- \*********************************************************************************/
- /***/ (function() {
- (function ($) {
- var Field = acf.Field.extend({
- type: 'repeater',
- wait: '',
- page: 1,
- nextRowNum: 0,
- 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',
- 'click a[data-event="first-page"]:not(.disabled)': 'onClickFirstPage',
- 'click a[data-event="last-page"]:not(.disabled)': 'onClickLastPage',
- 'click a[data-event="prev-page"]:not(.disabled)': 'onClickPrevPage',
- 'click a[data-event="next-page"]:not(.disabled)': 'onClickNextPage',
- 'change .current-page': 'onChangeCurrentPage',
- 'click .acf-order-input-wrap': 'onClickRowOrder',
- 'blur .acf-order-input': 'onBlurRowOrder',
- 'change .acf-order-input': 'onChangeRowOrder',
- 'changed:total_rows': 'onChangeTotalRows',
- showField: 'onShow',
- unloadField: 'onUnload',
- mouseover: 'onHover',
- change: 'onChangeField'
- },
- $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, .acf-deleted');
- },
- $row: function (index) {
- return this.$('tbody:first > tr:eq(' + index + ')');
- },
- $clone: function () {
- return this.$('tbody:first > tr.acf-clone');
- },
- $actions: function () {
- return this.$('.acf-actions:last');
- },
- $button: function () {
- return this.$('.acf-actions:last .button');
- },
- $firstPageButton: function () {
- return this.$('.acf-tablenav:last .first-page');
- },
- $prevPageButton: function () {
- return this.$('.acf-tablenav:last .prev-page');
- },
- $nextPageButton: function () {
- return this.$('.acf-tablenav:last .next-page');
- },
- $lastPageButton: function () {
- return this.$('.acf-tablenav:last .last-page');
- },
- $pageInput: function () {
- return this.$('.current-page:last');
- },
- totalPages: function () {
- const totalPages = this.$('.acf-total-pages:last').text();
- return parseInt(totalPages);
- },
- getValue: function () {
- return this.$rows().length;
- },
- allowRemove: function () {
- let numRows = this.val();
- let minRows = parseInt(this.get('min'));
- if (this.get('pagination')) {
- numRows = this.get('total_rows');
- }
- return !minRows || minRows < numRows;
- },
- allowAdd: function () {
- let numRows = this.val();
- let maxRows = parseInt(this.get('max'));
- if (this.get('pagination')) {
- numRows = this.get('total_rows');
- }
- return !maxRows || maxRows > numRows;
- },
- addSortable: function (self) {
- // bail early if max 1 row
- if (this.get('max') == 1) {
- return;
- }
- // Bail early if using pagination.
- if (this.get('pagination')) {
- return;
- }
- // add sortable
- this.$tbody().sortable({
- items: '> tr',
- handle: '> td.order',
- forceHelperSize: true,
- forcePlaceholderSize: true,
- scroll: true,
- stop: function (event, ui) {
- self.render();
- },
- update: function (event, ui) {
- self.$input().trigger('change');
- }
- });
- },
- addCollapsed: function () {
- // vars
- var indexes = preference.load(this.get('key'));
- // bail early if no collapsed
- if (!indexes) {
- return false;
- }
- // loop
- this.$rows().each(function (i) {
- if (indexes.indexOf(i) > -1) {
- if ($(this).find('.-collapsed-target').length) {
- $(this).addClass('-collapsed');
- }
- }
- });
- },
- addUnscopedEvents: function (self) {
- // invalidField
- this.on('invalidField', '.acf-row', function (e) {
- var $row = $(this);
- if (self.isCollapsed($row)) {
- self.expand($row);
- }
- });
- // Listen for changes to fields, so we can persist them in the DOM.
- if (this.get('pagination')) {
- this.on('change', 'input, select, textarea', function (e) {
- const $changed = $(e.currentTarget);
- if (!$changed.hasClass('acf-order-input') && !$changed.hasClass('acf-row-status')) {
- self.onChangeField(e, $(this));
- }
- });
- }
- this.listenForSavedMetaBoxes();
- },
- initialize: function () {
- // add unscoped events
- this.addUnscopedEvents(this);
- // add collapsed
- this.addCollapsed();
- // disable clone
- acf.disable(this.$clone(), this.cid);
- // Set up the next row number.
- if (this.get('pagination')) {
- this.nextRowNum = this.get('total_rows');
- }
- // render
- this.render();
- },
- render: function () {
- let update_order_numbers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
- // Update order number.
- if (update_order_numbers) {
- this.$rows().each(function (i) {
- $(this).find('> .order > span').html(i + 1);
- });
- }
- // Extract vars.
- var $control = this.$control();
- var $button = this.$button();
- // empty
- if (this.val() == 0) {
- $control.addClass('-empty');
- } else {
- $control.removeClass('-empty');
- }
- // Reached max rows.
- if (!this.allowAdd()) {
- $control.addClass('-max');
- $button.addClass('disabled');
- } else {
- $control.removeClass('-max');
- $button.removeClass('disabled');
- }
- if (this.get('pagination')) {
- this.maybeDisablePagination();
- }
- // Reached min rows (not used).
- //if( !this.allowRemove() ) {
- // $control.addClass('-min');
- //} else {
- // $control.removeClass('-min');
- //}
- },
- listenForSavedMetaBoxes: function () {
- if (!acf.isGutenberg() || !this.get('pagination')) {
- return;
- }
- let checkedMetaBoxes = true;
- wp.data.subscribe(() => {
- if (wp.data.select('core/edit-post').isSavingMetaBoxes()) {
- checkedMetaBoxes = false;
- } else {
- if (!checkedMetaBoxes) {
- checkedMetaBoxes = true;
- this.set('total_rows', 0, true);
- this.ajaxLoadPage(true);
- }
- }
- });
- },
- incrementTotalRows: function () {
- let totalRows = this.get('total_rows');
- this.set('total_rows', ++totalRows, true);
- },
- decrementTotalRows: function () {
- let totalRows = this.get('total_rows');
- this.set('total_rows', --totalRows, true);
- },
- validateAdd: function () {
- // return true if allowed
- if (this.allowAdd()) {
- return true;
- }
- // vars
- var max = this.get('max');
- var text = acf.__('Maximum rows reached ({max} rows)');
- // replace
- text = text.replace('{max}', max);
- // add notice
- this.showNotice({
- text: text,
- type: 'warning'
- });
- // return
- return false;
- },
- onClickAdd: function (e, $el) {
- // validate
- if (!this.validateAdd()) {
- return false;
- }
- // add above row
- if ($el.hasClass('acf-icon')) {
- this.add({
- before: $el.closest('.acf-row')
- });
- // default
- } else {
- this.add();
- }
- },
- add: function (args) {
- // validate
- if (!this.allowAdd()) {
- return false;
- }
- // defaults
- args = acf.parseArgs(args, {
- before: false
- });
- // add row
- var $el = acf.duplicate({
- target: this.$clone(),
- append: this.proxy(function ($el, $el2) {
- // append
- if (args.before) {
- args.before.before($el2);
- } else {
- $el.before($el2);
- }
- // remove clone class
- $el2.removeClass('acf-clone');
- // enable
- acf.enable($el2, this.cid);
- })
- });
- if (this.get('pagination')) {
- this.incrementTotalRows();
- if (false !== args.before) {
- // If the row was inserted above an existing row, try to keep that order.
- const prevRowNum = parseInt(args.before.find('.acf-row-number').first().text()) || 0;
- let newRowNum = prevRowNum;
- if (newRowNum && !args.before.hasClass('acf-inserted') && !args.before.hasClass('acf-added')) {
- --newRowNum;
- }
- if (args.before.hasClass('acf-divider')) {
- args.before.removeClass('acf-divider');
- $el.addClass('acf-divider');
- }
- this.updateRowStatus($el, 'inserted');
- this.updateRowStatus($el, 'reordered', newRowNum);
- // Hide the row numbers to avoid confusion with existing rows.
- $el.find('.acf-row-number').first().hide().text(newRowNum);
- if (!$el.find('.acf-order-input-wrap').hasClass('disabled')) {
- let message = acf.__('Order will be assigned upon save');
- $el.find('.acf-order-input-wrap').addClass('disabled');
- $el.find('.acf-row-number').first().after('<span title="' + message + '">-</span>');
- }
- $el.find('.acf-order-input').first().hide();
- $el.attr('data-inserted', newRowNum);
- } else {
- this.nextRowNum++;
- $el.find('.acf-order-input').first().val(this.nextRowNum);
- $el.find('.acf-row-number').first().text(this.nextRowNum);
- this.updateRowStatus($el, 'added');
- if (!this.$tbody().find('.acf-divider').length) {
- $el.addClass('acf-divider');
- }
- }
- $el.find('.acf-input:first').find('input:not([type=hidden]), select, textarea').first().trigger('focus');
- }
- // Render and trigger change for validation errors.
- this.render();
- this.$input().trigger('change');
- return $el;
- },
- onClickDuplicate: function (e, $el) {
- // Validate with warning.
- if (!this.validateAdd()) {
- return false;
- }
- // get layout and duplicate it.
- var $row = $el.closest('.acf-row');
- this.duplicateRow($row);
- },
- duplicateRow: function ($row) {
- // Validate without warning.
- if (!this.allowAdd()) {
- return false;
- }
- // Vars.
- var fieldKey = this.get('key');
- // Duplicate row.
- var $el = acf.duplicate({
- target: $row,
- // Provide a custom renaming callback to avoid renaming parent row attributes.
- rename: function (name, value, search, replace) {
- // Rename id attributes from "field_1-search" to "field_1-replace".
- if (name === 'id' || name === 'for') {
- return value.replace(fieldKey + '-' + search, fieldKey + '-' + replace);
- // Rename name and for attributes from "[field_1][search]" to "[field_1][replace]".
- } else {
- return value.replace(fieldKey + '][' + search, fieldKey + '][' + replace);
- }
- },
- before: function ($el) {
- acf.doAction('unmount', $el);
- },
- after: function ($el, $el2) {
- acf.doAction('remount', $el);
- }
- });
- if (this.get('pagination')) {
- this.incrementTotalRows();
- // If the row was inserted above an existing row, try to keep that order.
- const prevRowNum = parseInt($row.find('.acf-row-number').first().text()) || 0;
- this.updateRowStatus($el, 'inserted');
- this.updateRowStatus($el, 'reordered', prevRowNum);
- // Hide the row numbers to avoid confusion with existing rows.
- $el.find('.acf-row-number').first().hide();
- if (!$el.find('.acf-order-input-wrap').hasClass('disabled')) {
- let message = acf.__('Order will be assigned upon save');
- $el.find('.acf-order-input-wrap').addClass('disabled');
- $el.find('.acf-row-number').first().after('<span title="' + message + '">-</span>');
- }
- $el.find('.acf-order-input').first().hide();
- $el.attr('data-inserted', prevRowNum);
- $el.removeClass('acf-divider');
- }
- // trigger change for validation errors
- this.$input().trigger('change');
- // Update order numbers.
- this.render();
- // Focus on new row.
- acf.focusAttention($el);
- // Return new layout.
- return $el;
- },
- validateRemove: function () {
- // return true if allowed
- if (this.allowRemove()) {
- return true;
- }
- // vars
- var min = this.get('min');
- var text = acf.__('Minimum rows reached ({min} rows)');
- // replace
- text = text.replace('{min}', min);
- // add notice
- this.showNotice({
- text: text,
- type: 'warning'
- });
- // return
- return false;
- },
- onClickRemove: function (e, $el) {
- var $row = $el.closest('.acf-row');
- // Bypass confirmation when holding down "shift" key.
- if (e.shiftKey) {
- return this.remove($row);
- }
- // add class
- $row.addClass('-hover');
- // add tooltip
- var tooltip = acf.newTooltip({
- confirmRemove: true,
- target: $el,
- context: this,
- confirm: function () {
- this.remove($row);
- },
- cancel: function () {
- $row.removeClass('-hover');
- }
- });
- },
- onClickRowOrder: function (e, $el) {
- if (!this.get('pagination')) {
- return;
- }
- if ($el.hasClass('disabled')) {
- return;
- }
- $el.find('.acf-row-number').hide();
- $el.find('.acf-order-input').show().trigger('select');
- },
- onBlurRowOrder: function (e, $el) {
- this.onChangeRowOrder(e, $el, false);
- },
- onChangeRowOrder: function (e, $el) {
- let update = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
- if (!this.get('pagination')) {
- return;
- }
- const $row = $el.closest('.acf-row');
- const $orderSpan = $row.find('.acf-row-number').first();
- let hrOrder = $el.val();
- $row.find('.acf-order-input').first().hide();
- if (!acf.isNumeric(hrOrder) || parseFloat(hrOrder) < 0) {
- $orderSpan.show();
- return;
- }
- hrOrder = Math.round(hrOrder);
- const newOrder = hrOrder - 1;
- $el.val(hrOrder);
- $orderSpan.text(hrOrder).show();
- if (update) {
- this.updateRowStatus($row, 'reordered', newOrder);
- }
- },
- onChangeTotalRows: function () {
- const perPage = parseInt(this.get('per_page')) || 20;
- const totalRows = parseInt(this.get('total_rows')) || 0;
- const totalPages = Math.ceil(totalRows / perPage);
- // Update the total pages in pagination.
- this.$('.acf-total-pages:last').text(totalPages);
- this.nextRowNum = totalRows;
- // If the current page no longer exists, load the last page.
- if (this.page > totalPages) {
- this.page = totalPages;
- this.ajaxLoadPage();
- }
- },
- remove: function ($row) {
- const self = this;
- if (this.get('pagination')) {
- this.decrementTotalRows();
- // If using pagination and the row had already been saved, just hide the row instead of deleting it.
- if ($row.data('id').includes('row-')) {
- this.updateRowStatus($row, 'deleted');
- $row.hide();
- self.$input().trigger('change');
- self.render(false);
- return;
- } else if ($row.hasClass('acf-divider')) {
- $row.next('.acf-added').addClass('acf-divider');
- }
- }
- // If not using pagination, delete the actual row.
- acf.remove({
- target: $row,
- endHeight: 0,
- complete: function () {
- // trigger change to allow attachment save
- self.$input().trigger('change');
- // render
- self.render();
- // sync collapsed order
- //self.sync();
- }
- });
- },
- isCollapsed: function ($row) {
- return $row.hasClass('-collapsed');
- },
- collapse: function ($row) {
- $row.addClass('-collapsed');
- acf.doAction('hide', $row, 'collapse');
- },
- expand: function ($row) {
- $row.removeClass('-collapsed');
- acf.doAction('show', $row, 'collapse');
- },
- onClickCollapse: function (e, $el) {
- // vars
- var $row = $el.closest('.acf-row');
- var isCollpased = this.isCollapsed($row);
- // shift
- if (e.shiftKey) {
- $row = this.$rows();
- }
- // toggle
- if (isCollpased) {
- this.expand($row);
- } else {
- this.collapse($row);
- }
- },
- onShow: function (e, $el, context) {
- // get sub fields
- var fields = acf.getFields({
- is: ':visible',
- parent: this.$el
- });
- // trigger action
- // - ignore context, no need to pass through 'conditional_logic'
- // - this is just for fields like google_map to render itself
- acf.doAction('show_fields', fields);
- },
- onUnload: function () {
- // vars
- var indexes = [];
- // loop
- this.$rows().each(function (i) {
- if ($(this).hasClass('-collapsed')) {
- indexes.push(i);
- }
- });
- // allow null
- indexes = indexes.length ? indexes : null;
- // set
- preference.save(this.get('key'), indexes);
- },
- onHover: function () {
- // add sortable
- this.addSortable(this);
- // remove event
- this.off('mouseover');
- },
- onChangeField: function (e, $el) {
- const $target = $(e.delegateTarget);
- let $row = $el.closest('.acf-row');
- if ($row.closest('.acf-field-repeater').data('key') !== $target.data('key')) {
- $row = $row.parent().closest('.acf-row');
- }
- this.updateRowStatus($row, 'changed');
- },
- updateRowStatus: function ($row, status) {
- let data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
- if (!this.get('pagination')) {
- return;
- }
- const parent_key = $row.parents('.acf-field-repeater').data('key');
- if (this.parent() && parent_key !== this.get('key')) {
- return;
- }
- const row_id = $row.data('id');
- const input_name = this.$el.find('.acf-repeater-hidden-input:first').attr('name');
- const status_name = `${input_name}[${row_id}][acf_${status}]`;
- const status_input = `<input type="hidden" class="acf-row-status" name="${status_name}" value="${data}" />`;
- if (!$row.hasClass('acf-' + status)) {
- $row.addClass('acf-' + status);
- }
- // TODO: Update so that this doesn't get messed up with repeater subfields.
- const $existing_status = $row.find(`input[name='${status_name}']`);
- if (!$existing_status.length) {
- $row.find('td').first().append(status_input);
- } else {
- $existing_status.val(data);
- }
- },
- onClickFirstPage: function () {
- this.validatePage(1);
- },
- onClickPrevPage: function () {
- this.validatePage(this.page - 1);
- },
- onClickNextPage: function (e) {
- this.validatePage(this.page + 1);
- },
- onClickLastPage: function () {
- this.validatePage(this.totalPages());
- },
- onChangeCurrentPage: function () {
- this.validatePage(this.$pageInput().val());
- },
- maybeDisablePagination: function () {
- this.$actions().find('.acf-nav').removeClass('disabled');
- if (this.page <= 1) {
- this.$firstPageButton().addClass('disabled');
- this.$prevPageButton().addClass('disabled');
- }
- if (this.page >= this.totalPages()) {
- this.$nextPageButton().addClass('disabled');
- this.$lastPageButton().addClass('disabled');
- }
- },
- validatePage: function (nextPage) {
- const self = this;
- // Validate the current page.
- acf.validateForm({
- form: this.$control(),
- event: '',
- reset: true,
- success: function ($form) {
- self.page = nextPage;
- // Set up some sane defaults.
- if (self.page <= 1) {
- self.page = 1;
- }
- if (self.page >= self.totalPages()) {
- self.page = self.totalPages();
- }
- self.ajaxLoadPage();
- },
- failure: function ($form) {
- self.$pageInput().val(self.page);
- return false;
- }
- });
- },
- ajaxLoadPage: function () {
- let clearChanged = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
- const ajaxData = acf.prepareForAjax({
- action: 'acf/ajax/query_repeater',
- paged: this.page,
- field_key: this.get('key'),
- field_name: this.get('orig_name'),
- rows_per_page: parseInt(this.get('per_page')),
- refresh: clearChanged
- });
- $.ajax({
- url: ajaxurl,
- method: 'POST',
- dataType: 'json',
- data: ajaxData,
- context: this
- }).done(function (response) {
- const {
- rows
- } = response.data;
- const $existingRows = this.$tbody().find('> tr');
- $existingRows.not('.acf-clone').hide();
- if (clearChanged) {
- // Remove any existing rows since we are refreshing from the server.
- $existingRows.not('.acf-clone').remove();
- // Trigger a change in total rows, so we can update pagination.
- this.set('total_rows', response.data.total_rows, false);
- } else {
- $existingRows.not('.acf-changed, .acf-deleted, .acf-reordered, .acf-added, .acf-inserted, .acf-clone').remove();
- }
- Object.keys(rows).forEach(index => {
- let $row = false;
- let $unsavedRow = this.$tbody().find('> *[data-id=row-' + index + ']');
- let $insertedRow = this.$tbody().find('> *[data-inserted=' + index + ']');
- // Unsaved new rows that are inserted into this specific position.
- if ($insertedRow.length) {
- $insertedRow.appendTo(this.$tbody()).show();
- acf.doAction('remount', $insertedRow);
- }
- // Skip unsaved deleted rows; we don't want to show them again.
- if ($unsavedRow.hasClass('acf-deleted')) {
- return;
- }
- // Unsaved edited rows should be moved to correct position.
- if ($unsavedRow.length) {
- acf.doAction('unmount', $unsavedRow);
- $unsavedRow.appendTo(this.$tbody()).show();
- acf.doAction('remount', $unsavedRow);
- return;
- }
- // Rows from the server (that haven't been changed or deleted) should be appended and shown.
- $row = $(rows[index]);
- this.$tbody().append($row).show();
- acf.doAction('remount', $row);
- // Move clone field back to the right spot.
- this.$clone().appendTo(this.$tbody());
- });
- const $addedRows = this.$tbody().find('.acf-added:hidden');
- // If there are any new rows that are still hidden, append them to the bottom.
- if ($addedRows.length) {
- const self = this;
- $addedRows.each(function () {
- const $addedRow = $(this);
- $addedRow.insertBefore(self.$clone()).show();
- acf.doAction('remount', $addedRow);
- });
- }
- // Update the page input.
- this.$pageInput().val(this.page);
- this.maybeDisablePagination();
- }).fail(function (jqXHR, textStatus, errorThrown) {
- const error = acf.getXhrError(jqXHR);
- let message = acf.__('Error loading page');
- if ('' !== error) {
- message = `${message}: ${error}`;
- }
- this.showNotice({
- text: message,
- type: 'warning'
- });
- });
- }
- });
- acf.registerFieldType(Field);
- // register existing conditions
- acf.registerConditionForFieldType('hasValue', 'repeater');
- acf.registerConditionForFieldType('hasNoValue', 'repeater');
- acf.registerConditionForFieldType('lessThan', 'repeater');
- acf.registerConditionForFieldType('greaterThan', 'repeater');
- // state
- var preference = new acf.Model({
- name: 'this.collapsedRows',
- key: function (key, context) {
- // vars
- var count = this.get(key + context) || 0;
- // update
- count++;
- this.set(key + context, count, true);
- // modify fieldKey
- if (count > 1) {
- key += '-' + count;
- }
- // return
- return key;
- },
- load: function (key) {
- // vars
- var key = this.key(key, 'load');
- var data = acf.getPreference(this.name);
- // return
- if (data && data[key]) {
- return data[key];
- } else {
- return false;
- }
- },
- save: function (key, value) {
- // vars
- var key = this.key(key, 'save');
- var data = acf.getPreference(this.name) || {};
- // delete
- if (value === null) {
- delete data[key];
- // append
- } else {
- data[key] = value;
- }
- // allow null
- if ($.isEmptyObject(data)) {
- data = null;
- }
- // save
- acf.setPreference(this.name, data);
- }
- });
- })(jQuery);
- /***/ })
- /******/ });
- /************************************************************************/
- /******/ // The module cache
- /******/ var __webpack_module_cache__ = {};
- /******/
- /******/ // The require function
- /******/ function __webpack_require__(moduleId) {
- /******/ // Check if module is in cache
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
- /******/ if (cachedModule !== undefined) {
- /******/ return cachedModule.exports;
- /******/ }
- /******/ // Create a new module (and put it into the cache)
- /******/ var module = __webpack_module_cache__[moduleId] = {
- /******/ // no module.id needed
- /******/ // no module.loaded needed
- /******/ exports: {}
- /******/ };
- /******/
- /******/ // Execute the module function
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
- /******/
- /******/ // Return the exports of the module
- /******/ return module.exports;
- /******/ }
- /******/
- /************************************************************************/
- /******/ /* webpack/runtime/compat get default export */
- /******/ !function() {
- /******/ // getDefaultExport function for compatibility with non-harmony modules
- /******/ __webpack_require__.n = function(module) {
- /******/ var getter = module && module.__esModule ?
- /******/ function() { return module['default']; } :
- /******/ function() { return module; };
- /******/ __webpack_require__.d(getter, { a: getter });
- /******/ return getter;
- /******/ };
- /******/ }();
- /******/
- /******/ /* webpack/runtime/define property getters */
- /******/ !function() {
- /******/ // define getter functions for harmony exports
- /******/ __webpack_require__.d = function(exports, definition) {
- /******/ for(var key in definition) {
- /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
- /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
- /******/ }
- /******/ }
- /******/ };
- /******/ }();
- /******/
- /******/ /* webpack/runtime/hasOwnProperty shorthand */
- /******/ !function() {
- /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
- /******/ }();
- /******/
- /******/ /* webpack/runtime/make namespace object */
- /******/ !function() {
- /******/ // define __esModule on exports
- /******/ __webpack_require__.r = function(exports) {
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
- /******/ }
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
- /******/ };
- /******/ }();
- /******/
- /************************************************************************/
- var __webpack_exports__ = {};
- // This entry need to be wrapped in an IIFE because it need to be in strict mode.
- !function() {
- "use strict";
- /*!***************************************************************************!*\
- !*** ./src/advanced-custom-fields-pro/assets/src/js/pro/acf-pro-input.js ***!
- \***************************************************************************/
- __webpack_require__.r(__webpack_exports__);
- /* harmony import */ var _acf_field_repeater_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./_acf-field-repeater.js */ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-repeater.js");
- /* harmony import */ var _acf_field_repeater_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_acf_field_repeater_js__WEBPACK_IMPORTED_MODULE_0__);
- /* harmony import */ var _acf_field_flexible_content_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./_acf-field-flexible-content.js */ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-flexible-content.js");
- /* harmony import */ var _acf_field_flexible_content_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_acf_field_flexible_content_js__WEBPACK_IMPORTED_MODULE_1__);
- /* harmony import */ var _acf_field_gallery_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./_acf-field-gallery.js */ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-gallery.js");
- /* harmony import */ var _acf_field_gallery_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_acf_field_gallery_js__WEBPACK_IMPORTED_MODULE_2__);
- }();
- /******/ })()
- ;
- //# sourceMappingURL=acf-pro-input.js.map
|