acf-pro-input.js 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101
  1. /******/ (function() { // webpackBootstrap
  2. /******/ var __webpack_modules__ = ({
  3. /***/ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-flexible-content.js":
  4. /*!*****************************************************************************************!*\
  5. !*** ./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-flexible-content.js ***!
  6. \*****************************************************************************************/
  7. /***/ (function() {
  8. (function ($) {
  9. var Field = acf.Field.extend({
  10. type: 'flexible_content',
  11. wait: '',
  12. events: {
  13. 'click [data-name="add-layout"]': 'onClickAdd',
  14. 'click [data-name="duplicate-layout"]': 'onClickDuplicate',
  15. 'click [data-name="remove-layout"]': 'onClickRemove',
  16. 'click [data-name="collapse-layout"]': 'onClickCollapse',
  17. showField: 'onShow',
  18. unloadField: 'onUnload',
  19. mouseover: 'onHover'
  20. },
  21. $control: function () {
  22. return this.$('.acf-flexible-content:first');
  23. },
  24. $layoutsWrap: function () {
  25. return this.$('.acf-flexible-content:first > .values');
  26. },
  27. $layouts: function () {
  28. return this.$('.acf-flexible-content:first > .values > .layout');
  29. },
  30. $layout: function (index) {
  31. return this.$('.acf-flexible-content:first > .values > .layout:eq(' + index + ')');
  32. },
  33. $clonesWrap: function () {
  34. return this.$('.acf-flexible-content:first > .clones');
  35. },
  36. $clones: function () {
  37. return this.$('.acf-flexible-content:first > .clones > .layout');
  38. },
  39. $clone: function (name) {
  40. return this.$('.acf-flexible-content:first > .clones > .layout[data-layout="' + name + '"]');
  41. },
  42. $actions: function () {
  43. return this.$('.acf-actions:last');
  44. },
  45. $button: function () {
  46. return this.$('.acf-actions:last .button');
  47. },
  48. $popup: function () {
  49. return this.$('.tmpl-popup:last');
  50. },
  51. getPopupHTML: function () {
  52. var html = this.$popup().html();
  53. var $html = $(html);
  54. // count layouts
  55. var $layouts = this.$layouts();
  56. var countLayouts = function (name) {
  57. return $layouts.filter(function () {
  58. return $(this).data('layout') === name;
  59. }).length;
  60. };
  61. // modify popup
  62. $html.find('[data-layout]').each(function () {
  63. var $a = $(this);
  64. var min = $a.data('min') || 0;
  65. var max = $a.data('max') || 0;
  66. var name = $a.data('layout') || '';
  67. var count = countLayouts(name);
  68. // max
  69. if (max && count >= max) {
  70. $a.addClass('disabled');
  71. return;
  72. }
  73. // min
  74. if (min && count < min) {
  75. var required = min - count;
  76. var title = acf.__('{required} {label} {identifier} required (min {min})');
  77. var identifier = acf._n('layout', 'layouts', required);
  78. // translate
  79. title = title.replace('{required}', required);
  80. title = title.replace('{label}', name); // 5.5.0
  81. title = title.replace('{identifier}', identifier);
  82. title = title.replace('{min}', min);
  83. // badge
  84. $a.append('<span class="badge" title="' + title + '">' + required + '</span>');
  85. }
  86. });
  87. // update
  88. html = $html.outerHTML();
  89. return html;
  90. },
  91. getValue: function () {
  92. return this.$layouts().length;
  93. },
  94. allowRemove: function () {
  95. var min = parseInt(this.get('min'));
  96. return !min || min < this.val();
  97. },
  98. allowAdd: function () {
  99. var max = parseInt(this.get('max'));
  100. return !max || max > this.val();
  101. },
  102. isFull: function () {
  103. var max = parseInt(this.get('max'));
  104. return max && this.val() >= max;
  105. },
  106. addSortable: function (self) {
  107. // bail early if max 1 row
  108. if (this.get('max') == 1) {
  109. return;
  110. }
  111. // add sortable
  112. this.$layoutsWrap().sortable({
  113. items: '> .layout',
  114. handle: '> .acf-fc-layout-handle',
  115. forceHelperSize: true,
  116. forcePlaceholderSize: true,
  117. scroll: true,
  118. stop: function (event, ui) {
  119. self.render();
  120. },
  121. update: function (event, ui) {
  122. self.$input().trigger('change');
  123. }
  124. });
  125. },
  126. addCollapsed: function () {
  127. var indexes = preference.load(this.get('key'));
  128. // bail early if no collapsed
  129. if (!indexes) {
  130. return false;
  131. }
  132. // loop
  133. this.$layouts().each(function (i) {
  134. if (indexes.indexOf(i) > -1) {
  135. $(this).addClass('-collapsed');
  136. }
  137. });
  138. },
  139. addUnscopedEvents: function (self) {
  140. // invalidField
  141. this.on('invalidField', '.layout', function (e) {
  142. self.onInvalidField(e, $(this));
  143. });
  144. },
  145. initialize: function () {
  146. // add unscoped events
  147. this.addUnscopedEvents(this);
  148. // add collapsed
  149. this.addCollapsed();
  150. // disable clone
  151. acf.disable(this.$clonesWrap(), this.cid);
  152. // render
  153. this.render();
  154. },
  155. render: function () {
  156. // update order number
  157. this.$layouts().each(function (i) {
  158. $(this).find('.acf-fc-layout-order:first').html(i + 1);
  159. });
  160. // empty
  161. if (this.val() == 0) {
  162. this.$control().addClass('-empty');
  163. } else {
  164. this.$control().removeClass('-empty');
  165. }
  166. // max
  167. if (this.isFull()) {
  168. this.$button().addClass('disabled');
  169. } else {
  170. this.$button().removeClass('disabled');
  171. }
  172. },
  173. onShow: function (e, $el, context) {
  174. // get sub fields
  175. var fields = acf.getFields({
  176. is: ':visible',
  177. parent: this.$el
  178. });
  179. // trigger action
  180. // - ignore context, no need to pass through 'conditional_logic'
  181. // - this is just for fields like google_map to render itself
  182. acf.doAction('show_fields', fields);
  183. },
  184. validateAdd: function () {
  185. // return true if allowed
  186. if (this.allowAdd()) {
  187. return true;
  188. }
  189. var max = this.get('max');
  190. var text = acf.__('This field has a limit of {max} {label} {identifier}');
  191. var identifier = acf._n('layout', 'layouts', max);
  192. // replace
  193. text = text.replace('{max}', max);
  194. text = text.replace('{label}', '');
  195. text = text.replace('{identifier}', identifier);
  196. // add notice
  197. this.showNotice({
  198. text: text,
  199. type: 'warning'
  200. });
  201. return false;
  202. },
  203. onClickAdd: function (e, $el) {
  204. // validate
  205. if (!this.validateAdd()) {
  206. return false;
  207. }
  208. // within layout
  209. var $layout = null;
  210. if ($el.hasClass('acf-icon')) {
  211. $layout = $el.closest('.layout');
  212. $layout.addClass('-hover');
  213. }
  214. // new popup
  215. var popup = new Popup({
  216. target: $el,
  217. targetConfirm: false,
  218. text: this.getPopupHTML(),
  219. context: this,
  220. confirm: function (e, $el) {
  221. // check disabled
  222. if ($el.hasClass('disabled')) {
  223. return;
  224. }
  225. // add
  226. this.add({
  227. layout: $el.data('layout'),
  228. before: $layout
  229. });
  230. },
  231. cancel: function () {
  232. if ($layout) {
  233. $layout.removeClass('-hover');
  234. }
  235. }
  236. });
  237. // add extra event
  238. popup.on('click', '[data-layout]', 'onConfirm');
  239. },
  240. add: function (args) {
  241. // defaults
  242. args = acf.parseArgs(args, {
  243. layout: '',
  244. before: false
  245. });
  246. // validate
  247. if (!this.allowAdd()) {
  248. return false;
  249. }
  250. // add row
  251. var $el = acf.duplicate({
  252. target: this.$clone(args.layout),
  253. append: this.proxy(function ($el, $el2) {
  254. // append
  255. if (args.before) {
  256. args.before.before($el2);
  257. } else {
  258. this.$layoutsWrap().append($el2);
  259. }
  260. // enable
  261. acf.enable($el2, this.cid);
  262. // render
  263. this.render();
  264. })
  265. });
  266. // trigger change for validation errors
  267. this.$input().trigger('change');
  268. return $el;
  269. },
  270. onClickDuplicate: function (e, $el) {
  271. // Validate with warning.
  272. if (!this.validateAdd()) {
  273. return false;
  274. }
  275. // get layout and duplicate it.
  276. var $layout = $el.closest('.layout');
  277. this.duplicateLayout($layout);
  278. },
  279. duplicateLayout: function ($layout) {
  280. // Validate without warning.
  281. if (!this.allowAdd()) {
  282. return false;
  283. }
  284. var fieldKey = this.get('key');
  285. // Duplicate layout.
  286. var $el = acf.duplicate({
  287. target: $layout,
  288. // Provide a custom renaming callback to avoid renaming parent row attributes.
  289. rename: function (name, value, search, replace) {
  290. // Rename id attributes from "field_1-search" to "field_1-replace".
  291. if (name === 'id' || name === 'for') {
  292. return value.replace(fieldKey + '-' + search, fieldKey + '-' + replace);
  293. // Rename name and for attributes from "[field_1][search]" to "[field_1][replace]".
  294. } else {
  295. return value.replace(fieldKey + '][' + search, fieldKey + '][' + replace);
  296. }
  297. },
  298. before: function ($el) {
  299. acf.doAction('unmount', $el);
  300. },
  301. after: function ($el, $el2) {
  302. acf.doAction('remount', $el);
  303. }
  304. });
  305. // trigger change for validation errors
  306. this.$input().trigger('change');
  307. // Update order numbers.
  308. this.render();
  309. // Draw focus to layout.
  310. acf.focusAttention($el);
  311. // Return new layout.
  312. return $el;
  313. },
  314. validateRemove: function () {
  315. // return true if allowed
  316. if (this.allowRemove()) {
  317. return true;
  318. }
  319. var min = this.get('min');
  320. var text = acf.__('This field requires at least {min} {label} {identifier}');
  321. var identifier = acf._n('layout', 'layouts', min);
  322. // replace
  323. text = text.replace('{min}', min);
  324. text = text.replace('{label}', '');
  325. text = text.replace('{identifier}', identifier);
  326. // add notice
  327. this.showNotice({
  328. text: text,
  329. type: 'warning'
  330. });
  331. return false;
  332. },
  333. onClickRemove: function (e, $el) {
  334. var $layout = $el.closest('.layout');
  335. // Bypass confirmation when holding down "shift" key.
  336. if (e.shiftKey) {
  337. return this.removeLayout($layout);
  338. }
  339. // add class
  340. $layout.addClass('-hover');
  341. // add tooltip
  342. var tooltip = acf.newTooltip({
  343. confirmRemove: true,
  344. target: $el,
  345. context: this,
  346. confirm: function () {
  347. this.removeLayout($layout);
  348. },
  349. cancel: function () {
  350. $layout.removeClass('-hover');
  351. }
  352. });
  353. },
  354. removeLayout: function ($layout) {
  355. // reference
  356. var self = this;
  357. var endHeight = this.getValue() == 1 ? 60 : 0;
  358. // remove
  359. acf.remove({
  360. target: $layout,
  361. endHeight: endHeight,
  362. complete: function () {
  363. // trigger change to allow attachment save
  364. self.$input().trigger('change');
  365. // render
  366. self.render();
  367. }
  368. });
  369. },
  370. onClickCollapse: function (e, $el) {
  371. var $layout = $el.closest('.layout');
  372. // toggle
  373. if (this.isLayoutClosed($layout)) {
  374. this.openLayout($layout);
  375. } else {
  376. this.closeLayout($layout);
  377. }
  378. },
  379. isLayoutClosed: function ($layout) {
  380. return $layout.hasClass('-collapsed');
  381. },
  382. openLayout: function ($layout) {
  383. $layout.removeClass('-collapsed');
  384. acf.doAction('show', $layout, 'collapse');
  385. },
  386. closeLayout: function ($layout) {
  387. $layout.addClass('-collapsed');
  388. acf.doAction('hide', $layout, 'collapse');
  389. // render
  390. // - no change could happen if layout was already closed. Only render when closing
  391. this.renderLayout($layout);
  392. },
  393. renderLayout: function ($layout) {
  394. var $input = $layout.children('input');
  395. var prefix = $input.attr('name').replace('[acf_fc_layout]', '');
  396. // ajax data
  397. var ajaxData = {
  398. action: 'acf/fields/flexible_content/layout_title',
  399. field_key: this.get('key'),
  400. i: $layout.index(),
  401. layout: $layout.data('layout'),
  402. value: acf.serialize($layout, prefix)
  403. };
  404. // ajax
  405. $.ajax({
  406. url: acf.get('ajaxurl'),
  407. data: acf.prepareForAjax(ajaxData),
  408. dataType: 'html',
  409. type: 'post',
  410. success: function (html) {
  411. if (html) {
  412. $layout.children('.acf-fc-layout-handle').html(html);
  413. }
  414. }
  415. });
  416. },
  417. onUnload: function () {
  418. var indexes = [];
  419. // loop
  420. this.$layouts().each(function (i) {
  421. if ($(this).hasClass('-collapsed')) {
  422. indexes.push(i);
  423. }
  424. });
  425. // allow null
  426. indexes = indexes.length ? indexes : null;
  427. // set
  428. preference.save(this.get('key'), indexes);
  429. },
  430. onInvalidField: function (e, $layout) {
  431. // open if is collapsed
  432. if (this.isLayoutClosed($layout)) {
  433. this.openLayout($layout);
  434. }
  435. },
  436. onHover: function () {
  437. // add sortable
  438. this.addSortable(this);
  439. // remove event
  440. this.off('mouseover');
  441. }
  442. });
  443. acf.registerFieldType(Field);
  444. /**
  445. * Popup
  446. *
  447. * description
  448. *
  449. * @date 7/4/18
  450. * @since 5.6.9
  451. *
  452. * @param type $var Description. Default.
  453. * @return type Description.
  454. */
  455. var Popup = acf.models.TooltipConfirm.extend({
  456. events: {
  457. 'click [data-layout]': 'onConfirm',
  458. 'click [data-event="cancel"]': 'onCancel'
  459. },
  460. render: function () {
  461. // set HTML
  462. this.html(this.get('text'));
  463. // add class
  464. this.$el.addClass('acf-fc-popup');
  465. }
  466. });
  467. /**
  468. * conditions
  469. *
  470. * description
  471. *
  472. * @date 9/4/18
  473. * @since 5.6.9
  474. *
  475. * @param type $var Description. Default.
  476. * @return type Description.
  477. */
  478. // register existing conditions
  479. acf.registerConditionForFieldType('hasValue', 'flexible_content');
  480. acf.registerConditionForFieldType('hasNoValue', 'flexible_content');
  481. acf.registerConditionForFieldType('lessThan', 'flexible_content');
  482. acf.registerConditionForFieldType('greaterThan', 'flexible_content');
  483. // state
  484. var preference = new acf.Model({
  485. name: 'this.collapsedLayouts',
  486. key: function (key, context) {
  487. var count = this.get(key + context) || 0;
  488. // update
  489. count++;
  490. this.set(key + context, count, true);
  491. // modify fieldKey
  492. if (count > 1) {
  493. key += '-' + count;
  494. }
  495. return key;
  496. },
  497. load: function (key) {
  498. var key = this.key(key, 'load');
  499. var data = acf.getPreference(this.name);
  500. if (data && data[key]) {
  501. return data[key];
  502. } else {
  503. return false;
  504. }
  505. },
  506. save: function (key, value) {
  507. var key = this.key(key, 'save');
  508. var data = acf.getPreference(this.name) || {};
  509. // delete
  510. if (value === null) {
  511. delete data[key];
  512. // append
  513. } else {
  514. data[key] = value;
  515. }
  516. // allow null
  517. if ($.isEmptyObject(data)) {
  518. data = null;
  519. }
  520. // save
  521. acf.setPreference(this.name, data);
  522. }
  523. });
  524. })(jQuery);
  525. /***/ }),
  526. /***/ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-gallery.js":
  527. /*!********************************************************************************!*\
  528. !*** ./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-gallery.js ***!
  529. \********************************************************************************/
  530. /***/ (function() {
  531. (function ($) {
  532. var Field = acf.Field.extend({
  533. type: 'gallery',
  534. events: {
  535. 'click .acf-gallery-add': 'onClickAdd',
  536. 'click .acf-gallery-edit': 'onClickEdit',
  537. 'click .acf-gallery-remove': 'onClickRemove',
  538. 'click .acf-gallery-attachment': 'onClickSelect',
  539. 'click .acf-gallery-close': 'onClickClose',
  540. 'change .acf-gallery-sort': 'onChangeSort',
  541. 'click .acf-gallery-update': 'onUpdate',
  542. mouseover: 'onHover',
  543. showField: 'render'
  544. },
  545. actions: {
  546. validation_begin: 'onValidationBegin',
  547. validation_failure: 'onValidationFailure',
  548. resize: 'onResize'
  549. },
  550. onValidationBegin: function () {
  551. acf.disable(this.$sideData(), this.cid);
  552. },
  553. onValidationFailure: function () {
  554. acf.enable(this.$sideData(), this.cid);
  555. },
  556. $control: function () {
  557. return this.$('.acf-gallery');
  558. },
  559. $collection: function () {
  560. return this.$('.acf-gallery-attachments');
  561. },
  562. $attachments: function () {
  563. return this.$('.acf-gallery-attachment');
  564. },
  565. $attachment: function (id) {
  566. return this.$('.acf-gallery-attachment[data-id="' + id + '"]');
  567. },
  568. $active: function () {
  569. return this.$('.acf-gallery-attachment.active');
  570. },
  571. $main: function () {
  572. return this.$('.acf-gallery-main');
  573. },
  574. $side: function () {
  575. return this.$('.acf-gallery-side');
  576. },
  577. $sideData: function () {
  578. return this.$('.acf-gallery-side-data');
  579. },
  580. isFull: function () {
  581. var max = parseInt(this.get('max'));
  582. var count = this.$attachments().length;
  583. return max && count >= max;
  584. },
  585. getValue: function () {
  586. // vars
  587. var val = [];
  588. // loop
  589. this.$attachments().each(function () {
  590. val.push($(this).data('id'));
  591. });
  592. // return
  593. return val.length ? val : false;
  594. },
  595. addUnscopedEvents: function (self) {
  596. // invalidField
  597. this.on('change', '.acf-gallery-side', function (e) {
  598. self.onUpdate(e, $(this));
  599. });
  600. },
  601. addSortable: function (self) {
  602. // add sortable
  603. this.$collection().sortable({
  604. items: '.acf-gallery-attachment',
  605. forceHelperSize: true,
  606. forcePlaceholderSize: true,
  607. scroll: true,
  608. start: function (event, ui) {
  609. ui.placeholder.html(ui.item.html());
  610. ui.placeholder.removeAttr('style');
  611. },
  612. update: function (event, ui) {
  613. self.$input().trigger('change');
  614. }
  615. });
  616. // resizable
  617. this.$control().resizable({
  618. handles: 's',
  619. minHeight: 200,
  620. stop: function (event, ui) {
  621. acf.update_user_setting('gallery_height', ui.size.height);
  622. }
  623. });
  624. },
  625. initialize: function () {
  626. // add unscoped events
  627. this.addUnscopedEvents(this);
  628. // render
  629. this.render();
  630. },
  631. render: function () {
  632. // vars
  633. var $sort = this.$('.acf-gallery-sort');
  634. var $add = this.$('.acf-gallery-add');
  635. var count = this.$attachments().length;
  636. // disable add
  637. if (this.isFull()) {
  638. $add.addClass('disabled');
  639. } else {
  640. $add.removeClass('disabled');
  641. }
  642. // disable select
  643. if (!count) {
  644. $sort.addClass('disabled');
  645. } else {
  646. $sort.removeClass('disabled');
  647. }
  648. // resize
  649. this.resize();
  650. },
  651. resize: function () {
  652. // vars
  653. var width = this.$control().width();
  654. var target = 150;
  655. var columns = Math.round(width / target);
  656. // max columns = 8
  657. columns = Math.min(columns, 8);
  658. // update data
  659. this.$control().attr('data-columns', columns);
  660. },
  661. onResize: function () {
  662. this.resize();
  663. },
  664. openSidebar: function () {
  665. // add class
  666. this.$control().addClass('-open');
  667. // hide bulk actions
  668. // should be done with CSS
  669. //this.$main().find('.acf-gallery-sort').hide();
  670. // vars
  671. var width = this.$control().width() / 3;
  672. width = parseInt(width);
  673. width = Math.max(width, 350);
  674. // animate
  675. this.$('.acf-gallery-side-inner').css({
  676. width: width - 1
  677. });
  678. this.$side().animate({
  679. width: width - 1
  680. }, 250);
  681. this.$main().animate({
  682. right: width
  683. }, 250);
  684. },
  685. closeSidebar: function () {
  686. // remove class
  687. this.$control().removeClass('-open');
  688. // clear selection
  689. this.$active().removeClass('active');
  690. // disable sidebar
  691. acf.disable(this.$side());
  692. // animate
  693. var $sideData = this.$('.acf-gallery-side-data');
  694. this.$main().animate({
  695. right: 0
  696. }, 250);
  697. this.$side().animate({
  698. width: 0
  699. }, 250, function () {
  700. $sideData.html('');
  701. });
  702. },
  703. onClickAdd: function (e, $el) {
  704. // validate
  705. if (this.isFull()) {
  706. this.showNotice({
  707. text: acf.__('Maximum selection reached'),
  708. type: 'warning'
  709. });
  710. return;
  711. }
  712. // new frame
  713. var frame = acf.newMediaPopup({
  714. mode: 'select',
  715. title: acf.__('Add Image to Gallery'),
  716. field: this.get('key'),
  717. multiple: 'add',
  718. library: this.get('library'),
  719. allowedTypes: this.get('mime_types'),
  720. selected: this.val(),
  721. select: $.proxy(function (attachment, i) {
  722. this.appendAttachment(attachment, i);
  723. }, this)
  724. });
  725. },
  726. appendAttachment: function (attachment, i) {
  727. // vars
  728. attachment = this.validateAttachment(attachment);
  729. // bail early if is full
  730. if (this.isFull()) {
  731. return;
  732. }
  733. // bail early if already exists
  734. if (this.$attachment(attachment.id).length) {
  735. return;
  736. }
  737. // html
  738. 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('');
  739. var $html = $(html);
  740. // append
  741. this.$collection().append($html);
  742. // move to beginning
  743. if (this.get('insert') === 'prepend') {
  744. var $before = this.$attachments().eq(i);
  745. if ($before.length) {
  746. $before.before($html);
  747. }
  748. }
  749. // render attachment
  750. this.renderAttachment(attachment);
  751. // render
  752. this.render();
  753. // trigger change
  754. this.$input().trigger('change');
  755. },
  756. validateAttachment: function (attachment) {
  757. // defaults
  758. attachment = acf.parseArgs(attachment, {
  759. id: '',
  760. url: '',
  761. alt: '',
  762. title: '',
  763. filename: '',
  764. type: 'image'
  765. });
  766. // WP attachment
  767. if (attachment.attributes) {
  768. attachment = attachment.attributes;
  769. // preview size
  770. var url = acf.isget(attachment, 'sizes', this.get('preview_size'), 'url');
  771. if (url !== null) {
  772. attachment.url = url;
  773. }
  774. }
  775. // return
  776. return attachment;
  777. },
  778. renderAttachment: function (attachment) {
  779. // vars
  780. attachment = this.validateAttachment(attachment);
  781. // vars
  782. var $el = this.$attachment(attachment.id);
  783. // Image type.
  784. if (attachment.type == 'image') {
  785. // Remove filename.
  786. $el.find('.filename').remove();
  787. // Other file type.
  788. } else {
  789. // Check for attachment featured image.
  790. var image = acf.isget(attachment, 'image', 'src');
  791. if (image !== null) {
  792. attachment.url = image;
  793. }
  794. // Update filename text.
  795. $el.find('.filename').text(attachment.filename);
  796. }
  797. // Default to mimetype icon.
  798. if (!attachment.url) {
  799. attachment.url = acf.get('mimeTypeIcon');
  800. $el.addClass('-icon');
  801. }
  802. // update els
  803. $el.find('img').attr({
  804. src: attachment.url,
  805. alt: attachment.alt,
  806. title: attachment.title
  807. });
  808. // update val
  809. acf.val($el.find('input'), attachment.id);
  810. },
  811. editAttachment: function (id) {
  812. // new frame
  813. var frame = acf.newMediaPopup({
  814. mode: 'edit',
  815. title: acf.__('Edit Image'),
  816. button: acf.__('Update Image'),
  817. attachment: id,
  818. field: this.get('key'),
  819. select: $.proxy(function (attachment, i) {
  820. this.renderAttachment(attachment);
  821. // todo - render sidebar
  822. }, this)
  823. });
  824. },
  825. onClickEdit: function (e, $el) {
  826. var id = $el.data('id');
  827. if (id) {
  828. this.editAttachment(id);
  829. }
  830. },
  831. removeAttachment: function (id) {
  832. // close sidebar (if open)
  833. this.closeSidebar();
  834. // remove attachment
  835. this.$attachment(id).remove();
  836. // render
  837. this.render();
  838. // trigger change
  839. this.$input().trigger('change');
  840. },
  841. onClickRemove: function (e, $el) {
  842. // prevent event from triggering click on attachment
  843. e.preventDefault();
  844. e.stopPropagation();
  845. //remove
  846. var id = $el.data('id');
  847. if (id) {
  848. this.removeAttachment(id);
  849. }
  850. },
  851. selectAttachment: function (id) {
  852. // vars
  853. var $el = this.$attachment(id);
  854. // bail early if already active
  855. if ($el.hasClass('active')) {
  856. return;
  857. }
  858. // step 1
  859. var step1 = this.proxy(function () {
  860. // save any changes in sidebar
  861. this.$side().find(':focus').trigger('blur');
  862. // clear selection
  863. this.$active().removeClass('active');
  864. // add selection
  865. $el.addClass('active');
  866. // open sidebar
  867. this.openSidebar();
  868. // call step 2
  869. step2();
  870. });
  871. // step 2
  872. var step2 = this.proxy(function () {
  873. // ajax
  874. var ajaxData = {
  875. action: 'acf/fields/gallery/get_attachment',
  876. field_key: this.get('key'),
  877. id: id
  878. };
  879. // abort prev ajax call
  880. if (this.has('xhr')) {
  881. this.get('xhr').abort();
  882. }
  883. // loading
  884. acf.showLoading(this.$sideData());
  885. // get HTML
  886. var xhr = $.ajax({
  887. url: acf.get('ajaxurl'),
  888. data: acf.prepareForAjax(ajaxData),
  889. type: 'post',
  890. dataType: 'html',
  891. cache: false,
  892. success: step3
  893. });
  894. // update
  895. this.set('xhr', xhr);
  896. });
  897. // step 3
  898. var step3 = this.proxy(function (html) {
  899. // bail early if no html
  900. if (!html) {
  901. return;
  902. }
  903. // vars
  904. var $side = this.$sideData();
  905. // render
  906. $side.html(html);
  907. // remove acf form data
  908. $side.find('.compat-field-acf-form-data').remove();
  909. // merge tables
  910. $side.find('> table.form-table > tbody').append($side.find('> .compat-attachment-fields > tbody > tr'));
  911. // setup fields
  912. acf.doAction('append', $side);
  913. });
  914. // run step 1
  915. step1();
  916. },
  917. onClickSelect: function (e, $el) {
  918. var id = $el.data('id');
  919. if (id) {
  920. this.selectAttachment(id);
  921. }
  922. },
  923. onClickClose: function (e, $el) {
  924. this.closeSidebar();
  925. },
  926. onChangeSort: function (e, $el) {
  927. // Bail early if is disabled.
  928. if ($el.hasClass('disabled')) {
  929. return;
  930. }
  931. // Get sort val.
  932. var val = $el.val();
  933. if (!val) {
  934. return;
  935. }
  936. // find ids
  937. var ids = [];
  938. this.$attachments().each(function () {
  939. ids.push($(this).data('id'));
  940. });
  941. // step 1
  942. var step1 = this.proxy(function () {
  943. // vars
  944. var ajaxData = {
  945. action: 'acf/fields/gallery/get_sort_order',
  946. field_key: this.get('key'),
  947. ids: ids,
  948. sort: val
  949. };
  950. // get results
  951. var xhr = $.ajax({
  952. url: acf.get('ajaxurl'),
  953. dataType: 'json',
  954. type: 'post',
  955. cache: false,
  956. data: acf.prepareForAjax(ajaxData),
  957. success: step2
  958. });
  959. });
  960. // step 2
  961. var step2 = this.proxy(function (json) {
  962. // validate
  963. if (!acf.isAjaxSuccess(json)) {
  964. return;
  965. }
  966. // reverse order
  967. json.data.reverse();
  968. // loop
  969. json.data.map(function (id) {
  970. this.$collection().prepend(this.$attachment(id));
  971. }, this);
  972. });
  973. // call step 1
  974. step1();
  975. },
  976. onUpdate: function (e, $el) {
  977. // vars
  978. var $submit = this.$('.acf-gallery-update');
  979. // validate
  980. if ($submit.hasClass('disabled')) {
  981. return;
  982. }
  983. // serialize data
  984. var ajaxData = acf.serialize(this.$sideData());
  985. // loading
  986. $submit.addClass('disabled');
  987. $submit.before('<i class="acf-loading"></i> ');
  988. // append AJAX action
  989. ajaxData.action = 'acf/fields/gallery/update_attachment';
  990. // ajax
  991. $.ajax({
  992. url: acf.get('ajaxurl'),
  993. data: acf.prepareForAjax(ajaxData),
  994. type: 'post',
  995. dataType: 'json',
  996. complete: function () {
  997. $submit.removeClass('disabled');
  998. $submit.prev('.acf-loading').remove();
  999. }
  1000. });
  1001. },
  1002. onHover: function () {
  1003. // add sortable
  1004. this.addSortable(this);
  1005. // remove event
  1006. this.off('mouseover');
  1007. }
  1008. });
  1009. acf.registerFieldType(Field);
  1010. // register existing conditions
  1011. acf.registerConditionForFieldType('hasValue', 'gallery');
  1012. acf.registerConditionForFieldType('hasNoValue', 'gallery');
  1013. acf.registerConditionForFieldType('selectionLessThan', 'gallery');
  1014. acf.registerConditionForFieldType('selectionGreaterThan', 'gallery');
  1015. })(jQuery);
  1016. /***/ }),
  1017. /***/ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-repeater.js":
  1018. /*!*********************************************************************************!*\
  1019. !*** ./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-field-repeater.js ***!
  1020. \*********************************************************************************/
  1021. /***/ (function() {
  1022. (function ($) {
  1023. var Field = acf.Field.extend({
  1024. type: 'repeater',
  1025. wait: '',
  1026. page: 1,
  1027. nextRowNum: 0,
  1028. events: {
  1029. 'click a[data-event="add-row"]': 'onClickAdd',
  1030. 'click a[data-event="duplicate-row"]': 'onClickDuplicate',
  1031. 'click a[data-event="remove-row"]': 'onClickRemove',
  1032. 'click a[data-event="collapse-row"]': 'onClickCollapse',
  1033. 'click a[data-event="first-page"]:not(.disabled)': 'onClickFirstPage',
  1034. 'click a[data-event="last-page"]:not(.disabled)': 'onClickLastPage',
  1035. 'click a[data-event="prev-page"]:not(.disabled)': 'onClickPrevPage',
  1036. 'click a[data-event="next-page"]:not(.disabled)': 'onClickNextPage',
  1037. 'change .current-page': 'onChangeCurrentPage',
  1038. 'click .acf-order-input-wrap': 'onClickRowOrder',
  1039. 'blur .acf-order-input': 'onBlurRowOrder',
  1040. 'change .acf-order-input': 'onChangeRowOrder',
  1041. 'changed:total_rows': 'onChangeTotalRows',
  1042. showField: 'onShow',
  1043. unloadField: 'onUnload',
  1044. mouseover: 'onHover',
  1045. change: 'onChangeField'
  1046. },
  1047. $control: function () {
  1048. return this.$('.acf-repeater:first');
  1049. },
  1050. $table: function () {
  1051. return this.$('table:first');
  1052. },
  1053. $tbody: function () {
  1054. return this.$('tbody:first');
  1055. },
  1056. $rows: function () {
  1057. return this.$('tbody:first > tr').not('.acf-clone, .acf-deleted');
  1058. },
  1059. $row: function (index) {
  1060. return this.$('tbody:first > tr:eq(' + index + ')');
  1061. },
  1062. $clone: function () {
  1063. return this.$('tbody:first > tr.acf-clone');
  1064. },
  1065. $actions: function () {
  1066. return this.$('.acf-actions:last');
  1067. },
  1068. $button: function () {
  1069. return this.$('.acf-actions:last .button');
  1070. },
  1071. $firstPageButton: function () {
  1072. return this.$('.acf-tablenav:last .first-page');
  1073. },
  1074. $prevPageButton: function () {
  1075. return this.$('.acf-tablenav:last .prev-page');
  1076. },
  1077. $nextPageButton: function () {
  1078. return this.$('.acf-tablenav:last .next-page');
  1079. },
  1080. $lastPageButton: function () {
  1081. return this.$('.acf-tablenav:last .last-page');
  1082. },
  1083. $pageInput: function () {
  1084. return this.$('.current-page:last');
  1085. },
  1086. totalPages: function () {
  1087. const totalPages = this.$('.acf-total-pages:last').text();
  1088. return parseInt(totalPages);
  1089. },
  1090. getValue: function () {
  1091. return this.$rows().length;
  1092. },
  1093. allowRemove: function () {
  1094. let numRows = this.val();
  1095. let minRows = parseInt(this.get('min'));
  1096. if (this.get('pagination')) {
  1097. numRows = this.get('total_rows');
  1098. }
  1099. return !minRows || minRows < numRows;
  1100. },
  1101. allowAdd: function () {
  1102. let numRows = this.val();
  1103. let maxRows = parseInt(this.get('max'));
  1104. if (this.get('pagination')) {
  1105. numRows = this.get('total_rows');
  1106. }
  1107. return !maxRows || maxRows > numRows;
  1108. },
  1109. addSortable: function (self) {
  1110. // bail early if max 1 row
  1111. if (this.get('max') == 1) {
  1112. return;
  1113. }
  1114. // Bail early if using pagination.
  1115. if (this.get('pagination')) {
  1116. return;
  1117. }
  1118. // add sortable
  1119. this.$tbody().sortable({
  1120. items: '> tr',
  1121. handle: '> td.order',
  1122. forceHelperSize: true,
  1123. forcePlaceholderSize: true,
  1124. scroll: true,
  1125. stop: function (event, ui) {
  1126. self.render();
  1127. },
  1128. update: function (event, ui) {
  1129. self.$input().trigger('change');
  1130. }
  1131. });
  1132. },
  1133. addCollapsed: function () {
  1134. // vars
  1135. var indexes = preference.load(this.get('key'));
  1136. // bail early if no collapsed
  1137. if (!indexes) {
  1138. return false;
  1139. }
  1140. // loop
  1141. this.$rows().each(function (i) {
  1142. if (indexes.indexOf(i) > -1) {
  1143. if ($(this).find('.-collapsed-target').length) {
  1144. $(this).addClass('-collapsed');
  1145. }
  1146. }
  1147. });
  1148. },
  1149. addUnscopedEvents: function (self) {
  1150. // invalidField
  1151. this.on('invalidField', '.acf-row', function (e) {
  1152. var $row = $(this);
  1153. if (self.isCollapsed($row)) {
  1154. self.expand($row);
  1155. }
  1156. });
  1157. // Listen for changes to fields, so we can persist them in the DOM.
  1158. if (this.get('pagination')) {
  1159. this.on('change', 'input, select, textarea', function (e) {
  1160. const $changed = $(e.currentTarget);
  1161. if (!$changed.hasClass('acf-order-input') && !$changed.hasClass('acf-row-status')) {
  1162. self.onChangeField(e, $(this));
  1163. }
  1164. });
  1165. }
  1166. this.listenForSavedMetaBoxes();
  1167. },
  1168. initialize: function () {
  1169. // add unscoped events
  1170. this.addUnscopedEvents(this);
  1171. // add collapsed
  1172. this.addCollapsed();
  1173. // disable clone
  1174. acf.disable(this.$clone(), this.cid);
  1175. // Set up the next row number.
  1176. if (this.get('pagination')) {
  1177. this.nextRowNum = this.get('total_rows');
  1178. }
  1179. // render
  1180. this.render();
  1181. },
  1182. render: function () {
  1183. let update_order_numbers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  1184. // Update order number.
  1185. if (update_order_numbers) {
  1186. this.$rows().each(function (i) {
  1187. $(this).find('> .order > span').html(i + 1);
  1188. });
  1189. }
  1190. // Extract vars.
  1191. var $control = this.$control();
  1192. var $button = this.$button();
  1193. // empty
  1194. if (this.val() == 0) {
  1195. $control.addClass('-empty');
  1196. } else {
  1197. $control.removeClass('-empty');
  1198. }
  1199. // Reached max rows.
  1200. if (!this.allowAdd()) {
  1201. $control.addClass('-max');
  1202. $button.addClass('disabled');
  1203. } else {
  1204. $control.removeClass('-max');
  1205. $button.removeClass('disabled');
  1206. }
  1207. if (this.get('pagination')) {
  1208. this.maybeDisablePagination();
  1209. }
  1210. // Reached min rows (not used).
  1211. //if( !this.allowRemove() ) {
  1212. // $control.addClass('-min');
  1213. //} else {
  1214. // $control.removeClass('-min');
  1215. //}
  1216. },
  1217. listenForSavedMetaBoxes: function () {
  1218. if (!acf.isGutenberg() || !this.get('pagination')) {
  1219. return;
  1220. }
  1221. let checkedMetaBoxes = true;
  1222. wp.data.subscribe(() => {
  1223. if (wp.data.select('core/edit-post').isSavingMetaBoxes()) {
  1224. checkedMetaBoxes = false;
  1225. } else {
  1226. if (!checkedMetaBoxes) {
  1227. checkedMetaBoxes = true;
  1228. this.set('total_rows', 0, true);
  1229. this.ajaxLoadPage(true);
  1230. }
  1231. }
  1232. });
  1233. },
  1234. incrementTotalRows: function () {
  1235. let totalRows = this.get('total_rows');
  1236. this.set('total_rows', ++totalRows, true);
  1237. },
  1238. decrementTotalRows: function () {
  1239. let totalRows = this.get('total_rows');
  1240. this.set('total_rows', --totalRows, true);
  1241. },
  1242. validateAdd: function () {
  1243. // return true if allowed
  1244. if (this.allowAdd()) {
  1245. return true;
  1246. }
  1247. // vars
  1248. var max = this.get('max');
  1249. var text = acf.__('Maximum rows reached ({max} rows)');
  1250. // replace
  1251. text = text.replace('{max}', max);
  1252. // add notice
  1253. this.showNotice({
  1254. text: text,
  1255. type: 'warning'
  1256. });
  1257. // return
  1258. return false;
  1259. },
  1260. onClickAdd: function (e, $el) {
  1261. // validate
  1262. if (!this.validateAdd()) {
  1263. return false;
  1264. }
  1265. // add above row
  1266. if ($el.hasClass('acf-icon')) {
  1267. this.add({
  1268. before: $el.closest('.acf-row')
  1269. });
  1270. // default
  1271. } else {
  1272. this.add();
  1273. }
  1274. },
  1275. add: function (args) {
  1276. // validate
  1277. if (!this.allowAdd()) {
  1278. return false;
  1279. }
  1280. // defaults
  1281. args = acf.parseArgs(args, {
  1282. before: false
  1283. });
  1284. // add row
  1285. var $el = acf.duplicate({
  1286. target: this.$clone(),
  1287. append: this.proxy(function ($el, $el2) {
  1288. // append
  1289. if (args.before) {
  1290. args.before.before($el2);
  1291. } else {
  1292. $el.before($el2);
  1293. }
  1294. // remove clone class
  1295. $el2.removeClass('acf-clone');
  1296. // enable
  1297. acf.enable($el2, this.cid);
  1298. })
  1299. });
  1300. if (this.get('pagination')) {
  1301. this.incrementTotalRows();
  1302. if (false !== args.before) {
  1303. // If the row was inserted above an existing row, try to keep that order.
  1304. const prevRowNum = parseInt(args.before.find('.acf-row-number').first().text()) || 0;
  1305. let newRowNum = prevRowNum;
  1306. if (newRowNum && !args.before.hasClass('acf-inserted') && !args.before.hasClass('acf-added')) {
  1307. --newRowNum;
  1308. }
  1309. if (args.before.hasClass('acf-divider')) {
  1310. args.before.removeClass('acf-divider');
  1311. $el.addClass('acf-divider');
  1312. }
  1313. this.updateRowStatus($el, 'inserted');
  1314. this.updateRowStatus($el, 'reordered', newRowNum);
  1315. // Hide the row numbers to avoid confusion with existing rows.
  1316. $el.find('.acf-row-number').first().hide().text(newRowNum);
  1317. if (!$el.find('.acf-order-input-wrap').hasClass('disabled')) {
  1318. let message = acf.__('Order will be assigned upon save');
  1319. $el.find('.acf-order-input-wrap').addClass('disabled');
  1320. $el.find('.acf-row-number').first().after('<span title="' + message + '">-</span>');
  1321. }
  1322. $el.find('.acf-order-input').first().hide();
  1323. $el.attr('data-inserted', newRowNum);
  1324. } else {
  1325. this.nextRowNum++;
  1326. $el.find('.acf-order-input').first().val(this.nextRowNum);
  1327. $el.find('.acf-row-number').first().text(this.nextRowNum);
  1328. this.updateRowStatus($el, 'added');
  1329. if (!this.$tbody().find('.acf-divider').length) {
  1330. $el.addClass('acf-divider');
  1331. }
  1332. }
  1333. $el.find('.acf-input:first').find('input:not([type=hidden]), select, textarea').first().trigger('focus');
  1334. }
  1335. // Render and trigger change for validation errors.
  1336. this.render();
  1337. this.$input().trigger('change');
  1338. return $el;
  1339. },
  1340. onClickDuplicate: function (e, $el) {
  1341. // Validate with warning.
  1342. if (!this.validateAdd()) {
  1343. return false;
  1344. }
  1345. // get layout and duplicate it.
  1346. var $row = $el.closest('.acf-row');
  1347. this.duplicateRow($row);
  1348. },
  1349. duplicateRow: function ($row) {
  1350. // Validate without warning.
  1351. if (!this.allowAdd()) {
  1352. return false;
  1353. }
  1354. // Vars.
  1355. var fieldKey = this.get('key');
  1356. // Duplicate row.
  1357. var $el = acf.duplicate({
  1358. target: $row,
  1359. // Provide a custom renaming callback to avoid renaming parent row attributes.
  1360. rename: function (name, value, search, replace) {
  1361. // Rename id attributes from "field_1-search" to "field_1-replace".
  1362. if (name === 'id' || name === 'for') {
  1363. return value.replace(fieldKey + '-' + search, fieldKey + '-' + replace);
  1364. // Rename name and for attributes from "[field_1][search]" to "[field_1][replace]".
  1365. } else {
  1366. return value.replace(fieldKey + '][' + search, fieldKey + '][' + replace);
  1367. }
  1368. },
  1369. before: function ($el) {
  1370. acf.doAction('unmount', $el);
  1371. },
  1372. after: function ($el, $el2) {
  1373. acf.doAction('remount', $el);
  1374. }
  1375. });
  1376. if (this.get('pagination')) {
  1377. this.incrementTotalRows();
  1378. // If the row was inserted above an existing row, try to keep that order.
  1379. const prevRowNum = parseInt($row.find('.acf-row-number').first().text()) || 0;
  1380. this.updateRowStatus($el, 'inserted');
  1381. this.updateRowStatus($el, 'reordered', prevRowNum);
  1382. // Hide the row numbers to avoid confusion with existing rows.
  1383. $el.find('.acf-row-number').first().hide();
  1384. if (!$el.find('.acf-order-input-wrap').hasClass('disabled')) {
  1385. let message = acf.__('Order will be assigned upon save');
  1386. $el.find('.acf-order-input-wrap').addClass('disabled');
  1387. $el.find('.acf-row-number').first().after('<span title="' + message + '">-</span>');
  1388. }
  1389. $el.find('.acf-order-input').first().hide();
  1390. $el.attr('data-inserted', prevRowNum);
  1391. $el.removeClass('acf-divider');
  1392. }
  1393. // trigger change for validation errors
  1394. this.$input().trigger('change');
  1395. // Update order numbers.
  1396. this.render();
  1397. // Focus on new row.
  1398. acf.focusAttention($el);
  1399. // Return new layout.
  1400. return $el;
  1401. },
  1402. validateRemove: function () {
  1403. // return true if allowed
  1404. if (this.allowRemove()) {
  1405. return true;
  1406. }
  1407. // vars
  1408. var min = this.get('min');
  1409. var text = acf.__('Minimum rows reached ({min} rows)');
  1410. // replace
  1411. text = text.replace('{min}', min);
  1412. // add notice
  1413. this.showNotice({
  1414. text: text,
  1415. type: 'warning'
  1416. });
  1417. // return
  1418. return false;
  1419. },
  1420. onClickRemove: function (e, $el) {
  1421. var $row = $el.closest('.acf-row');
  1422. // Bypass confirmation when holding down "shift" key.
  1423. if (e.shiftKey) {
  1424. return this.remove($row);
  1425. }
  1426. // add class
  1427. $row.addClass('-hover');
  1428. // add tooltip
  1429. var tooltip = acf.newTooltip({
  1430. confirmRemove: true,
  1431. target: $el,
  1432. context: this,
  1433. confirm: function () {
  1434. this.remove($row);
  1435. },
  1436. cancel: function () {
  1437. $row.removeClass('-hover');
  1438. }
  1439. });
  1440. },
  1441. onClickRowOrder: function (e, $el) {
  1442. if (!this.get('pagination')) {
  1443. return;
  1444. }
  1445. if ($el.hasClass('disabled')) {
  1446. return;
  1447. }
  1448. $el.find('.acf-row-number').hide();
  1449. $el.find('.acf-order-input').show().trigger('select');
  1450. },
  1451. onBlurRowOrder: function (e, $el) {
  1452. this.onChangeRowOrder(e, $el, false);
  1453. },
  1454. onChangeRowOrder: function (e, $el) {
  1455. let update = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  1456. if (!this.get('pagination')) {
  1457. return;
  1458. }
  1459. const $row = $el.closest('.acf-row');
  1460. const $orderSpan = $row.find('.acf-row-number').first();
  1461. let hrOrder = $el.val();
  1462. $row.find('.acf-order-input').first().hide();
  1463. if (!acf.isNumeric(hrOrder) || parseFloat(hrOrder) < 0) {
  1464. $orderSpan.show();
  1465. return;
  1466. }
  1467. hrOrder = Math.round(hrOrder);
  1468. const newOrder = hrOrder - 1;
  1469. $el.val(hrOrder);
  1470. $orderSpan.text(hrOrder).show();
  1471. if (update) {
  1472. this.updateRowStatus($row, 'reordered', newOrder);
  1473. }
  1474. },
  1475. onChangeTotalRows: function () {
  1476. const perPage = parseInt(this.get('per_page')) || 20;
  1477. const totalRows = parseInt(this.get('total_rows')) || 0;
  1478. const totalPages = Math.ceil(totalRows / perPage);
  1479. // Update the total pages in pagination.
  1480. this.$('.acf-total-pages:last').text(totalPages);
  1481. this.nextRowNum = totalRows;
  1482. // If the current page no longer exists, load the last page.
  1483. if (this.page > totalPages) {
  1484. this.page = totalPages;
  1485. this.ajaxLoadPage();
  1486. }
  1487. },
  1488. remove: function ($row) {
  1489. const self = this;
  1490. if (this.get('pagination')) {
  1491. this.decrementTotalRows();
  1492. // If using pagination and the row had already been saved, just hide the row instead of deleting it.
  1493. if ($row.data('id').includes('row-')) {
  1494. this.updateRowStatus($row, 'deleted');
  1495. $row.hide();
  1496. self.$input().trigger('change');
  1497. self.render(false);
  1498. return;
  1499. } else if ($row.hasClass('acf-divider')) {
  1500. $row.next('.acf-added').addClass('acf-divider');
  1501. }
  1502. }
  1503. // If not using pagination, delete the actual row.
  1504. acf.remove({
  1505. target: $row,
  1506. endHeight: 0,
  1507. complete: function () {
  1508. // trigger change to allow attachment save
  1509. self.$input().trigger('change');
  1510. // render
  1511. self.render();
  1512. // sync collapsed order
  1513. //self.sync();
  1514. }
  1515. });
  1516. },
  1517. isCollapsed: function ($row) {
  1518. return $row.hasClass('-collapsed');
  1519. },
  1520. collapse: function ($row) {
  1521. $row.addClass('-collapsed');
  1522. acf.doAction('hide', $row, 'collapse');
  1523. },
  1524. expand: function ($row) {
  1525. $row.removeClass('-collapsed');
  1526. acf.doAction('show', $row, 'collapse');
  1527. },
  1528. onClickCollapse: function (e, $el) {
  1529. // vars
  1530. var $row = $el.closest('.acf-row');
  1531. var isCollpased = this.isCollapsed($row);
  1532. // shift
  1533. if (e.shiftKey) {
  1534. $row = this.$rows();
  1535. }
  1536. // toggle
  1537. if (isCollpased) {
  1538. this.expand($row);
  1539. } else {
  1540. this.collapse($row);
  1541. }
  1542. },
  1543. onShow: function (e, $el, context) {
  1544. // get sub fields
  1545. var fields = acf.getFields({
  1546. is: ':visible',
  1547. parent: this.$el
  1548. });
  1549. // trigger action
  1550. // - ignore context, no need to pass through 'conditional_logic'
  1551. // - this is just for fields like google_map to render itself
  1552. acf.doAction('show_fields', fields);
  1553. },
  1554. onUnload: function () {
  1555. // vars
  1556. var indexes = [];
  1557. // loop
  1558. this.$rows().each(function (i) {
  1559. if ($(this).hasClass('-collapsed')) {
  1560. indexes.push(i);
  1561. }
  1562. });
  1563. // allow null
  1564. indexes = indexes.length ? indexes : null;
  1565. // set
  1566. preference.save(this.get('key'), indexes);
  1567. },
  1568. onHover: function () {
  1569. // add sortable
  1570. this.addSortable(this);
  1571. // remove event
  1572. this.off('mouseover');
  1573. },
  1574. onChangeField: function (e, $el) {
  1575. const $target = $(e.delegateTarget);
  1576. let $row = $el.closest('.acf-row');
  1577. if ($row.closest('.acf-field-repeater').data('key') !== $target.data('key')) {
  1578. $row = $row.parent().closest('.acf-row');
  1579. }
  1580. this.updateRowStatus($row, 'changed');
  1581. },
  1582. updateRowStatus: function ($row, status) {
  1583. let data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
  1584. if (!this.get('pagination')) {
  1585. return;
  1586. }
  1587. const parent_key = $row.parents('.acf-field-repeater').data('key');
  1588. if (this.parent() && parent_key !== this.get('key')) {
  1589. return;
  1590. }
  1591. const row_id = $row.data('id');
  1592. const input_name = this.$el.find('.acf-repeater-hidden-input:first').attr('name');
  1593. const status_name = `${input_name}[${row_id}][acf_${status}]`;
  1594. const status_input = `<input type="hidden" class="acf-row-status" name="${status_name}" value="${data}" />`;
  1595. if (!$row.hasClass('acf-' + status)) {
  1596. $row.addClass('acf-' + status);
  1597. }
  1598. // TODO: Update so that this doesn't get messed up with repeater subfields.
  1599. const $existing_status = $row.find(`input[name='${status_name}']`);
  1600. if (!$existing_status.length) {
  1601. $row.find('td').first().append(status_input);
  1602. } else {
  1603. $existing_status.val(data);
  1604. }
  1605. },
  1606. onClickFirstPage: function () {
  1607. this.validatePage(1);
  1608. },
  1609. onClickPrevPage: function () {
  1610. this.validatePage(this.page - 1);
  1611. },
  1612. onClickNextPage: function (e) {
  1613. this.validatePage(this.page + 1);
  1614. },
  1615. onClickLastPage: function () {
  1616. this.validatePage(this.totalPages());
  1617. },
  1618. onChangeCurrentPage: function () {
  1619. this.validatePage(this.$pageInput().val());
  1620. },
  1621. maybeDisablePagination: function () {
  1622. this.$actions().find('.acf-nav').removeClass('disabled');
  1623. if (this.page <= 1) {
  1624. this.$firstPageButton().addClass('disabled');
  1625. this.$prevPageButton().addClass('disabled');
  1626. }
  1627. if (this.page >= this.totalPages()) {
  1628. this.$nextPageButton().addClass('disabled');
  1629. this.$lastPageButton().addClass('disabled');
  1630. }
  1631. },
  1632. validatePage: function (nextPage) {
  1633. const self = this;
  1634. // Validate the current page.
  1635. acf.validateForm({
  1636. form: this.$control(),
  1637. event: '',
  1638. reset: true,
  1639. success: function ($form) {
  1640. self.page = nextPage;
  1641. // Set up some sane defaults.
  1642. if (self.page <= 1) {
  1643. self.page = 1;
  1644. }
  1645. if (self.page >= self.totalPages()) {
  1646. self.page = self.totalPages();
  1647. }
  1648. self.ajaxLoadPage();
  1649. },
  1650. failure: function ($form) {
  1651. self.$pageInput().val(self.page);
  1652. return false;
  1653. }
  1654. });
  1655. },
  1656. ajaxLoadPage: function () {
  1657. let clearChanged = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  1658. const ajaxData = acf.prepareForAjax({
  1659. action: 'acf/ajax/query_repeater',
  1660. paged: this.page,
  1661. field_key: this.get('key'),
  1662. field_name: this.get('orig_name'),
  1663. rows_per_page: parseInt(this.get('per_page')),
  1664. refresh: clearChanged
  1665. });
  1666. $.ajax({
  1667. url: ajaxurl,
  1668. method: 'POST',
  1669. dataType: 'json',
  1670. data: ajaxData,
  1671. context: this
  1672. }).done(function (response) {
  1673. const {
  1674. rows
  1675. } = response.data;
  1676. const $existingRows = this.$tbody().find('> tr');
  1677. $existingRows.not('.acf-clone').hide();
  1678. if (clearChanged) {
  1679. // Remove any existing rows since we are refreshing from the server.
  1680. $existingRows.not('.acf-clone').remove();
  1681. // Trigger a change in total rows, so we can update pagination.
  1682. this.set('total_rows', response.data.total_rows, false);
  1683. } else {
  1684. $existingRows.not('.acf-changed, .acf-deleted, .acf-reordered, .acf-added, .acf-inserted, .acf-clone').remove();
  1685. }
  1686. Object.keys(rows).forEach(index => {
  1687. let $row = false;
  1688. let $unsavedRow = this.$tbody().find('> *[data-id=row-' + index + ']');
  1689. let $insertedRow = this.$tbody().find('> *[data-inserted=' + index + ']');
  1690. // Unsaved new rows that are inserted into this specific position.
  1691. if ($insertedRow.length) {
  1692. $insertedRow.appendTo(this.$tbody()).show();
  1693. acf.doAction('remount', $insertedRow);
  1694. }
  1695. // Skip unsaved deleted rows; we don't want to show them again.
  1696. if ($unsavedRow.hasClass('acf-deleted')) {
  1697. return;
  1698. }
  1699. // Unsaved edited rows should be moved to correct position.
  1700. if ($unsavedRow.length) {
  1701. acf.doAction('unmount', $unsavedRow);
  1702. $unsavedRow.appendTo(this.$tbody()).show();
  1703. acf.doAction('remount', $unsavedRow);
  1704. return;
  1705. }
  1706. // Rows from the server (that haven't been changed or deleted) should be appended and shown.
  1707. $row = $(rows[index]);
  1708. this.$tbody().append($row).show();
  1709. acf.doAction('remount', $row);
  1710. // Move clone field back to the right spot.
  1711. this.$clone().appendTo(this.$tbody());
  1712. });
  1713. const $addedRows = this.$tbody().find('.acf-added:hidden');
  1714. // If there are any new rows that are still hidden, append them to the bottom.
  1715. if ($addedRows.length) {
  1716. const self = this;
  1717. $addedRows.each(function () {
  1718. const $addedRow = $(this);
  1719. $addedRow.insertBefore(self.$clone()).show();
  1720. acf.doAction('remount', $addedRow);
  1721. });
  1722. }
  1723. // Update the page input.
  1724. this.$pageInput().val(this.page);
  1725. this.maybeDisablePagination();
  1726. }).fail(function (jqXHR, textStatus, errorThrown) {
  1727. const error = acf.getXhrError(jqXHR);
  1728. let message = acf.__('Error loading page');
  1729. if ('' !== error) {
  1730. message = `${message}: ${error}`;
  1731. }
  1732. this.showNotice({
  1733. text: message,
  1734. type: 'warning'
  1735. });
  1736. });
  1737. }
  1738. });
  1739. acf.registerFieldType(Field);
  1740. // register existing conditions
  1741. acf.registerConditionForFieldType('hasValue', 'repeater');
  1742. acf.registerConditionForFieldType('hasNoValue', 'repeater');
  1743. acf.registerConditionForFieldType('lessThan', 'repeater');
  1744. acf.registerConditionForFieldType('greaterThan', 'repeater');
  1745. // state
  1746. var preference = new acf.Model({
  1747. name: 'this.collapsedRows',
  1748. key: function (key, context) {
  1749. // vars
  1750. var count = this.get(key + context) || 0;
  1751. // update
  1752. count++;
  1753. this.set(key + context, count, true);
  1754. // modify fieldKey
  1755. if (count > 1) {
  1756. key += '-' + count;
  1757. }
  1758. // return
  1759. return key;
  1760. },
  1761. load: function (key) {
  1762. // vars
  1763. var key = this.key(key, 'load');
  1764. var data = acf.getPreference(this.name);
  1765. // return
  1766. if (data && data[key]) {
  1767. return data[key];
  1768. } else {
  1769. return false;
  1770. }
  1771. },
  1772. save: function (key, value) {
  1773. // vars
  1774. var key = this.key(key, 'save');
  1775. var data = acf.getPreference(this.name) || {};
  1776. // delete
  1777. if (value === null) {
  1778. delete data[key];
  1779. // append
  1780. } else {
  1781. data[key] = value;
  1782. }
  1783. // allow null
  1784. if ($.isEmptyObject(data)) {
  1785. data = null;
  1786. }
  1787. // save
  1788. acf.setPreference(this.name, data);
  1789. }
  1790. });
  1791. })(jQuery);
  1792. /***/ })
  1793. /******/ });
  1794. /************************************************************************/
  1795. /******/ // The module cache
  1796. /******/ var __webpack_module_cache__ = {};
  1797. /******/
  1798. /******/ // The require function
  1799. /******/ function __webpack_require__(moduleId) {
  1800. /******/ // Check if module is in cache
  1801. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  1802. /******/ if (cachedModule !== undefined) {
  1803. /******/ return cachedModule.exports;
  1804. /******/ }
  1805. /******/ // Create a new module (and put it into the cache)
  1806. /******/ var module = __webpack_module_cache__[moduleId] = {
  1807. /******/ // no module.id needed
  1808. /******/ // no module.loaded needed
  1809. /******/ exports: {}
  1810. /******/ };
  1811. /******/
  1812. /******/ // Execute the module function
  1813. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  1814. /******/
  1815. /******/ // Return the exports of the module
  1816. /******/ return module.exports;
  1817. /******/ }
  1818. /******/
  1819. /************************************************************************/
  1820. /******/ /* webpack/runtime/compat get default export */
  1821. /******/ !function() {
  1822. /******/ // getDefaultExport function for compatibility with non-harmony modules
  1823. /******/ __webpack_require__.n = function(module) {
  1824. /******/ var getter = module && module.__esModule ?
  1825. /******/ function() { return module['default']; } :
  1826. /******/ function() { return module; };
  1827. /******/ __webpack_require__.d(getter, { a: getter });
  1828. /******/ return getter;
  1829. /******/ };
  1830. /******/ }();
  1831. /******/
  1832. /******/ /* webpack/runtime/define property getters */
  1833. /******/ !function() {
  1834. /******/ // define getter functions for harmony exports
  1835. /******/ __webpack_require__.d = function(exports, definition) {
  1836. /******/ for(var key in definition) {
  1837. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  1838. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  1839. /******/ }
  1840. /******/ }
  1841. /******/ };
  1842. /******/ }();
  1843. /******/
  1844. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  1845. /******/ !function() {
  1846. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  1847. /******/ }();
  1848. /******/
  1849. /******/ /* webpack/runtime/make namespace object */
  1850. /******/ !function() {
  1851. /******/ // define __esModule on exports
  1852. /******/ __webpack_require__.r = function(exports) {
  1853. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  1854. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  1855. /******/ }
  1856. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  1857. /******/ };
  1858. /******/ }();
  1859. /******/
  1860. /************************************************************************/
  1861. var __webpack_exports__ = {};
  1862. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  1863. !function() {
  1864. "use strict";
  1865. /*!***************************************************************************!*\
  1866. !*** ./src/advanced-custom-fields-pro/assets/src/js/pro/acf-pro-input.js ***!
  1867. \***************************************************************************/
  1868. __webpack_require__.r(__webpack_exports__);
  1869. /* 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");
  1870. /* harmony import */ var _acf_field_repeater_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_acf_field_repeater_js__WEBPACK_IMPORTED_MODULE_0__);
  1871. /* 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");
  1872. /* 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__);
  1873. /* 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");
  1874. /* harmony import */ var _acf_field_gallery_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_acf_field_gallery_js__WEBPACK_IMPORTED_MODULE_2__);
  1875. }();
  1876. /******/ })()
  1877. ;
  1878. //# sourceMappingURL=acf-pro-input.js.map