acf-pro-field-group.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /******/ (function() { // webpackBootstrap
  2. /******/ var __webpack_modules__ = ({
  3. /***/ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-clone.js":
  4. /*!********************************************************************************!*\
  5. !*** ./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-clone.js ***!
  6. \********************************************************************************/
  7. /***/ (function() {
  8. (function ($) {
  9. /**
  10. * CloneDisplayFieldSetting
  11. *
  12. * Extra logic for this field setting
  13. *
  14. * @date 18/4/18
  15. * @since 5.6.9
  16. *
  17. * @param void
  18. * @return void
  19. */
  20. var CloneDisplayFieldSetting = acf.FieldSetting.extend({
  21. type: 'clone',
  22. name: 'display',
  23. render: function () {
  24. // vars
  25. var display = this.field.val();
  26. // set data attribute used by CSS to hide/show
  27. this.$fieldObject.attr('data-display', display);
  28. }
  29. });
  30. acf.registerFieldSetting(CloneDisplayFieldSetting);
  31. /**
  32. * ClonePrefixLabelFieldSetting
  33. *
  34. * Extra logic for this field setting
  35. *
  36. * @date 18/4/18
  37. * @since 5.6.9
  38. *
  39. * @param void
  40. * @return void
  41. */
  42. var ClonePrefixLabelFieldSetting = acf.FieldSetting.extend({
  43. type: 'clone',
  44. name: 'prefix_label',
  45. render: function () {
  46. // vars
  47. var prefix = '';
  48. // if checked
  49. if (this.field.val()) {
  50. prefix = this.fieldObject.prop('label') + ' ';
  51. }
  52. // update HTML
  53. this.$('code').html(prefix + '%field_label%');
  54. }
  55. });
  56. acf.registerFieldSetting(ClonePrefixLabelFieldSetting);
  57. /**
  58. * ClonePrefixNameFieldSetting
  59. *
  60. * Extra logic for this field setting
  61. *
  62. * @date 18/4/18
  63. * @since 5.6.9
  64. *
  65. * @param void
  66. * @return void
  67. */
  68. var ClonePrefixNameFieldSetting = acf.FieldSetting.extend({
  69. type: 'clone',
  70. name: 'prefix_name',
  71. render: function () {
  72. // vars
  73. var prefix = '';
  74. // if checked
  75. if (this.field.val()) {
  76. prefix = this.fieldObject.prop('name') + '_';
  77. }
  78. // update HTML
  79. this.$('code').html(prefix + '%field_name%');
  80. }
  81. });
  82. acf.registerFieldSetting(ClonePrefixNameFieldSetting);
  83. /**
  84. * cloneFieldSelectHelper
  85. *
  86. * Customizes the clone field setting Select2 isntance
  87. *
  88. * @date 18/4/18
  89. * @since 5.6.9
  90. *
  91. * @param void
  92. * @return void
  93. */
  94. var cloneFieldSelectHelper = new acf.Model({
  95. filters: {
  96. select2_args: 'select2Args'
  97. },
  98. select2Args: function (options, $select, data, $el, instance) {
  99. // check
  100. if (data.ajaxAction == 'acf/fields/clone/query') {
  101. // remain open on select
  102. options.closeOnSelect = false;
  103. // customize ajaxData function
  104. instance.data.ajaxData = this.ajaxData;
  105. }
  106. // return
  107. return options;
  108. },
  109. ajaxData: function (data) {
  110. // find current fields
  111. data.fields = {};
  112. // loop
  113. acf.getFieldObjects().map(function (fieldObject) {
  114. // append
  115. data.fields[fieldObject.prop('key')] = {
  116. key: fieldObject.prop('key'),
  117. type: fieldObject.prop('type'),
  118. label: fieldObject.prop('label'),
  119. ancestors: fieldObject.getParents().length
  120. };
  121. });
  122. // append title
  123. data.title = $('#title').val();
  124. // return
  125. return data;
  126. }
  127. });
  128. })(jQuery);
  129. /***/ }),
  130. /***/ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-flexible-content.js":
  131. /*!*******************************************************************************************!*\
  132. !*** ./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-flexible-content.js ***!
  133. \*******************************************************************************************/
  134. /***/ (function() {
  135. (function ($) {
  136. /**
  137. * CloneDisplayFieldSetting
  138. *
  139. * Extra logic for this field setting
  140. *
  141. * @date 18/4/18
  142. * @since 5.6.9
  143. *
  144. * @param void
  145. * @return void
  146. */
  147. var FlexibleContentLayoutFieldSetting = acf.FieldSetting.extend({
  148. type: 'flexible_content',
  149. name: 'fc_layout',
  150. events: {
  151. 'blur .layout-label': 'onChangeLabel',
  152. 'click .add-layout': 'onClickAdd',
  153. 'click .acf-field-settings-fc_head': 'onClickEdit',
  154. 'click .acf-field-setting-fc-duplicate': 'onClickDuplicate',
  155. 'click .acf-field-setting-fc-delete': 'onClickDelete',
  156. 'changed:layoutLabel': 'updateLayoutTitles'
  157. },
  158. $input: function (name) {
  159. return $('#' + this.getInputId() + '-' + name);
  160. },
  161. $list: function () {
  162. return this.$('.acf-field-list:first');
  163. },
  164. getInputId: function () {
  165. return this.fieldObject.getInputId() + '-layouts-' + this.field.get('id');
  166. },
  167. // get all sub fields
  168. getFields: function () {
  169. return acf.getFieldObjects({
  170. parent: this.$el
  171. });
  172. },
  173. // get imediate children
  174. getChildren: function () {
  175. return acf.getFieldObjects({
  176. list: this.$list()
  177. });
  178. },
  179. initialize: function () {
  180. // add sortable
  181. var $tbody = this.$el.parent();
  182. if (!$tbody.hasClass('ui-sortable')) {
  183. $tbody.sortable({
  184. items: '> .acf-field-setting-fc_layout',
  185. handle: '.acf-fc_draggable',
  186. forceHelperSize: true,
  187. forcePlaceholderSize: true,
  188. scroll: true,
  189. stop: this.proxy(function (event, ui) {
  190. this.fieldObject.save();
  191. })
  192. });
  193. }
  194. // add meta to sub fields
  195. this.updateFieldLayouts();
  196. this.updateLayoutTitles();
  197. },
  198. updateFieldLayouts: function () {
  199. this.getChildren().map(this.updateFieldLayout, this);
  200. },
  201. updateFieldLayout: function (field) {
  202. field.prop('parent_layout', this.get('id'));
  203. },
  204. updateLayoutTitles: function () {
  205. const label = this.get('layoutLabel');
  206. const parentLabel = this.$el.find('> .acf-label .acf-fc-layout-name');
  207. const subFieldsLabel = this.$el.find('> .acf-input > .acf-input-sub > .acf-sub-field-list-header > h3.acf-sub-field-list-title');
  208. if (label) {
  209. parentLabel.html(': ' + label);
  210. subFieldsLabel.html(acf.__('Fields') + ': ' + label);
  211. } else {
  212. parentLabel.html('');
  213. subFieldsLabel.html(acf.__('Fields'));
  214. }
  215. },
  216. onClickEdit: function (e) {
  217. const $target = $(e.target);
  218. if ($target.hasClass('acf-btn') || $target.parent().hasClass('acf-btn')) {
  219. return;
  220. }
  221. this.isOpen() ? this.close() : this.open();
  222. },
  223. isOpen: function (e) {
  224. const $settings = this.$el.children('.acf-field-layout-settings');
  225. return $settings.hasClass('open');
  226. },
  227. open: function (element, isAddingLayout) {
  228. const $settings = element ? element.children('.acf-field-layout-settings') : this.$el.children('.acf-field-layout-settings');
  229. const toggle = element ? element.find('.toggle-indicator').first() : this.$el.find('.toggle-indicator').first();
  230. // action (show)
  231. acf.doAction('show', $settings);
  232. // open
  233. if (isAddingLayout) {
  234. $settings.slideDown({
  235. complete: function () {
  236. $settings.find('.layout-label').trigger('focus');
  237. }
  238. });
  239. } else {
  240. $settings.slideDown();
  241. }
  242. toggle.addClass('open');
  243. if (toggle.hasClass('closed')) {
  244. toggle.removeClass('closed');
  245. }
  246. $settings.addClass('open');
  247. },
  248. close: function () {
  249. const $settings = this.$el.children('.acf-field-layout-settings');
  250. const toggle = this.$el.find('.toggle-indicator').first();
  251. // close
  252. $settings.slideUp();
  253. $settings.removeClass('open');
  254. toggle.removeClass('open');
  255. if (!toggle.hasClass('closed')) {
  256. toggle.addClass('closed');
  257. }
  258. // action (hide)
  259. acf.doAction('hide', $settings);
  260. },
  261. onChangeLabel: function (e, $el) {
  262. var label = $el.val();
  263. this.set('layoutLabel', label);
  264. this.$el.attr('data-layout-label', label);
  265. var $name = this.$input('name');
  266. // render name
  267. if ($name.val() == '') {
  268. acf.val($name, acf.strSanitize(label));
  269. }
  270. },
  271. onClickAdd: function (e, $el) {
  272. e.preventDefault();
  273. var prevKey = this.get('id');
  274. var newKey = acf.uniqid('layout_');
  275. // duplicate
  276. $layout = acf.duplicate({
  277. $el: this.$el,
  278. search: prevKey,
  279. replace: newKey,
  280. after: function ($el, $el2) {
  281. var $list = $el2.find('.acf-field-list:first');
  282. // remove sub fields
  283. $list.children('.acf-field-object').remove();
  284. // show empty
  285. $list.addClass('-empty');
  286. // reset layout meta values
  287. $el2.attr('data-layout-label', '');
  288. $el2.find('.acf-fc-meta input').val('');
  289. $el2.find('.acf-fc-layout-name').html('');
  290. $el2.find('.acf-sub-field-list-title').html(acf.__('Fields '));
  291. }
  292. });
  293. // get layout
  294. var layout = acf.getFieldSetting($layout);
  295. // update hidden input
  296. layout.$input('key').val(newKey);
  297. !this.isOpen() ? this.open(layout.$el, true) : layout.$el.find('.layout-label').trigger('focus');
  298. // save
  299. this.fieldObject.save();
  300. },
  301. onClickDuplicate: function (e, $el) {
  302. e.preventDefault();
  303. var prevKey = this.get('id');
  304. var newKey = acf.uniqid('layout_');
  305. // duplicate
  306. $layout = acf.duplicate({
  307. $el: this.$el,
  308. search: prevKey,
  309. replace: newKey
  310. });
  311. // get all fields in new layout similar to fieldManager.onDuplicateField().
  312. // important to run field.wipe() before making any changes to the "parent_layout" prop
  313. // to ensure the correct input is modified.
  314. var children = acf.getFieldObjects({
  315. parent: $layout
  316. });
  317. if (children.length) {
  318. // loop
  319. children.map(function (child) {
  320. // wipe field
  321. child.wipe();
  322. // update parent
  323. child.updateParent();
  324. });
  325. // action
  326. acf.doAction('duplicate_field_objects', children, this.fieldObject, this.fieldObject);
  327. }
  328. // get layout
  329. var layout = acf.getFieldSetting($layout);
  330. // update hidden input
  331. layout.$input('key').val(newKey);
  332. !this.isOpen() ? this.open(layout.$el, true) : layout.$el.find('.layout-label').trigger('focus');
  333. // save
  334. this.fieldObject.save();
  335. },
  336. onClickDelete: function (e, $el) {
  337. e.preventDefault();
  338. // Bypass confirmation when holding down "shift" key.
  339. if (e.shiftKey) {
  340. return this.delete();
  341. }
  342. // add class
  343. this.$el.addClass('-hover');
  344. // add tooltip
  345. var tooltip = acf.newTooltip({
  346. confirmRemove: true,
  347. target: $el,
  348. context: this,
  349. confirm: function () {
  350. this.delete();
  351. },
  352. cancel: function () {
  353. this.$el.removeClass('-hover');
  354. }
  355. });
  356. },
  357. delete: function () {
  358. var $siblings = this.$el.siblings('.acf-field-setting-fc_layout');
  359. // validate
  360. if (!$siblings.length) {
  361. alert(acf.__('Flexible Content requires at least 1 layout'));
  362. return false;
  363. }
  364. // delete sub fields
  365. this.getFields().map(function (child) {
  366. child.delete({
  367. animate: false
  368. });
  369. });
  370. // remove tr
  371. acf.remove(this.$el);
  372. // save
  373. this.fieldObject.save();
  374. }
  375. });
  376. acf.registerFieldSetting(FlexibleContentLayoutFieldSetting);
  377. /**
  378. * flexibleContentHelper
  379. *
  380. * description
  381. *
  382. * @date 19/4/18
  383. * @since 5.6.9
  384. *
  385. * @param type $var Description. Default.
  386. * @return type Description.
  387. */
  388. var flexibleContentHelper = new acf.Model({
  389. actions: {
  390. sortstop_field_object: 'updateParentLayout',
  391. change_field_object_parent: 'updateParentLayout'
  392. },
  393. updateParentLayout: function (fieldObject) {
  394. var parent = fieldObject.getParent();
  395. // delete meta
  396. if (!parent || parent.prop('type') !== 'flexible_content') {
  397. fieldObject.prop('parent_layout', null);
  398. return;
  399. }
  400. // get layout
  401. var $layout = fieldObject.$el.closest('.acf-field-setting-fc_layout');
  402. var layout = acf.getFieldSetting($layout);
  403. // check if previous prop exists
  404. // - if not, set prop to allow following code to trigger 'change' and save the field
  405. if (!fieldObject.has('parent_layout')) {
  406. fieldObject.prop('parent_layout', 0);
  407. }
  408. // update meta
  409. fieldObject.prop('parent_layout', layout.get('id'));
  410. }
  411. });
  412. })(jQuery);
  413. /***/ }),
  414. /***/ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-repeater.js":
  415. /*!***********************************************************************************!*\
  416. !*** ./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-repeater.js ***!
  417. \***********************************************************************************/
  418. /***/ (function() {
  419. (function ($) {
  420. /*
  421. * Repeater
  422. *
  423. * This field type requires some extra logic for its settings
  424. *
  425. * @type function
  426. * @date 24/10/13
  427. * @since 5.0.0
  428. *
  429. * @param n/a
  430. * @return n/a
  431. */
  432. var RepeaterCollapsedFieldSetting = acf.FieldSetting.extend({
  433. type: 'repeater',
  434. name: 'collapsed',
  435. events: {
  436. 'focus select': 'onFocus'
  437. },
  438. onFocus: function (e, $el) {
  439. // vars
  440. var $select = $el;
  441. // collapsed
  442. var choices = [];
  443. // keep 'null' choice
  444. choices.push({
  445. label: $select.find('option[value=""]').text(),
  446. value: ''
  447. });
  448. // find sub fields
  449. var $list = this.fieldObject.$('.acf-field-list:first');
  450. var fields = acf.getFieldObjects({
  451. list: $list
  452. });
  453. // loop
  454. fields.map(function (field) {
  455. choices.push({
  456. label: field.prop('label'),
  457. value: field.prop('key')
  458. });
  459. });
  460. // render
  461. acf.renderSelect($select, choices);
  462. }
  463. });
  464. acf.registerFieldSetting(RepeaterCollapsedFieldSetting);
  465. })(jQuery);
  466. /***/ })
  467. /******/ });
  468. /************************************************************************/
  469. /******/ // The module cache
  470. /******/ var __webpack_module_cache__ = {};
  471. /******/
  472. /******/ // The require function
  473. /******/ function __webpack_require__(moduleId) {
  474. /******/ // Check if module is in cache
  475. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  476. /******/ if (cachedModule !== undefined) {
  477. /******/ return cachedModule.exports;
  478. /******/ }
  479. /******/ // Create a new module (and put it into the cache)
  480. /******/ var module = __webpack_module_cache__[moduleId] = {
  481. /******/ // no module.id needed
  482. /******/ // no module.loaded needed
  483. /******/ exports: {}
  484. /******/ };
  485. /******/
  486. /******/ // Execute the module function
  487. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  488. /******/
  489. /******/ // Return the exports of the module
  490. /******/ return module.exports;
  491. /******/ }
  492. /******/
  493. /************************************************************************/
  494. /******/ /* webpack/runtime/compat get default export */
  495. /******/ !function() {
  496. /******/ // getDefaultExport function for compatibility with non-harmony modules
  497. /******/ __webpack_require__.n = function(module) {
  498. /******/ var getter = module && module.__esModule ?
  499. /******/ function() { return module['default']; } :
  500. /******/ function() { return module; };
  501. /******/ __webpack_require__.d(getter, { a: getter });
  502. /******/ return getter;
  503. /******/ };
  504. /******/ }();
  505. /******/
  506. /******/ /* webpack/runtime/define property getters */
  507. /******/ !function() {
  508. /******/ // define getter functions for harmony exports
  509. /******/ __webpack_require__.d = function(exports, definition) {
  510. /******/ for(var key in definition) {
  511. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  512. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  513. /******/ }
  514. /******/ }
  515. /******/ };
  516. /******/ }();
  517. /******/
  518. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  519. /******/ !function() {
  520. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  521. /******/ }();
  522. /******/
  523. /******/ /* webpack/runtime/make namespace object */
  524. /******/ !function() {
  525. /******/ // define __esModule on exports
  526. /******/ __webpack_require__.r = function(exports) {
  527. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  528. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  529. /******/ }
  530. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  531. /******/ };
  532. /******/ }();
  533. /******/
  534. /************************************************************************/
  535. var __webpack_exports__ = {};
  536. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  537. !function() {
  538. "use strict";
  539. /*!*********************************************************************************!*\
  540. !*** ./src/advanced-custom-fields-pro/assets/src/js/pro/acf-pro-field-group.js ***!
  541. \*********************************************************************************/
  542. __webpack_require__.r(__webpack_exports__);
  543. /* harmony import */ var _acf_setting_repeater_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./_acf-setting-repeater.js */ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-repeater.js");
  544. /* harmony import */ var _acf_setting_repeater_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_acf_setting_repeater_js__WEBPACK_IMPORTED_MODULE_0__);
  545. /* harmony import */ var _acf_setting_flexible_content_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./_acf-setting-flexible-content.js */ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-flexible-content.js");
  546. /* harmony import */ var _acf_setting_flexible_content_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_acf_setting_flexible_content_js__WEBPACK_IMPORTED_MODULE_1__);
  547. /* harmony import */ var _acf_setting_clone_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./_acf-setting-clone.js */ "./src/advanced-custom-fields-pro/assets/src/js/pro/_acf-setting-clone.js");
  548. /* harmony import */ var _acf_setting_clone_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_acf_setting_clone_js__WEBPACK_IMPORTED_MODULE_2__);
  549. }();
  550. /******/ })()
  551. ;
  552. //# sourceMappingURL=acf-pro-field-group.js.map