acf-field-group.js 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645
  1. /******/ (function() { // webpackBootstrap
  2. /******/ var __webpack_modules__ = ({
  3. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_field-group-compatibility.js":
  4. /*!************************************************************************************!*\
  5. !*** ./src/advanced-custom-fields-pro/assets/src/js/_field-group-compatibility.js ***!
  6. \************************************************************************************/
  7. /***/ (function() {
  8. (function ($, undefined) {
  9. var _acf = acf.getCompatibility(acf);
  10. /**
  11. * fieldGroupCompatibility
  12. *
  13. * Compatibility layer for extinct acf.field_group
  14. *
  15. * @date 15/12/17
  16. * @since 5.7.0
  17. *
  18. * @param void
  19. * @return void
  20. */
  21. _acf.field_group = {
  22. save_field: function ($field, type) {
  23. type = type !== undefined ? type : 'settings';
  24. acf.getFieldObject($field).save(type);
  25. },
  26. delete_field: function ($field, animate) {
  27. animate = animate !== undefined ? animate : true;
  28. acf.getFieldObject($field).delete({
  29. animate: animate
  30. });
  31. },
  32. update_field_meta: function ($field, name, value) {
  33. acf.getFieldObject($field).prop(name, value);
  34. },
  35. delete_field_meta: function ($field, name) {
  36. acf.getFieldObject($field).prop(name, null);
  37. }
  38. };
  39. /**
  40. * fieldGroupCompatibility.field_object
  41. *
  42. * Compatibility layer for extinct acf.field_group.field_object
  43. *
  44. * @date 15/12/17
  45. * @since 5.7.0
  46. *
  47. * @param void
  48. * @return void
  49. */
  50. _acf.field_group.field_object = acf.model.extend({
  51. // vars
  52. type: '',
  53. o: {},
  54. $field: null,
  55. $settings: null,
  56. tag: function (tag) {
  57. // vars
  58. var type = this.type;
  59. // explode, add 'field' and implode
  60. // - open => open_field
  61. // - change_type => change_field_type
  62. var tags = tag.split('_');
  63. tags.splice(1, 0, 'field');
  64. tag = tags.join('_');
  65. // add type
  66. if (type) {
  67. tag += '/type=' + type;
  68. }
  69. // return
  70. return tag;
  71. },
  72. selector: function () {
  73. // vars
  74. var selector = '.acf-field-object';
  75. var type = this.type;
  76. // add type
  77. if (type) {
  78. selector += '-' + type;
  79. selector = acf.str_replace('_', '-', selector);
  80. }
  81. // return
  82. return selector;
  83. },
  84. _add_action: function (name, callback) {
  85. // vars
  86. var model = this;
  87. // add action
  88. acf.add_action(this.tag(name), function ($field) {
  89. // focus
  90. model.set('$field', $field);
  91. // callback
  92. model[callback].apply(model, arguments);
  93. });
  94. },
  95. _add_filter: function (name, callback) {
  96. // vars
  97. var model = this;
  98. // add action
  99. acf.add_filter(this.tag(name), function ($field) {
  100. // focus
  101. model.set('$field', $field);
  102. // callback
  103. model[callback].apply(model, arguments);
  104. });
  105. },
  106. _add_event: function (name, callback) {
  107. // vars
  108. var model = this;
  109. var event = name.substr(0, name.indexOf(' '));
  110. var selector = name.substr(name.indexOf(' ') + 1);
  111. var context = this.selector();
  112. // add event
  113. $(document).on(event, context + ' ' + selector, function (e) {
  114. // append $el to event object
  115. e.$el = $(this);
  116. e.$field = e.$el.closest('.acf-field-object');
  117. // focus
  118. model.set('$field', e.$field);
  119. // callback
  120. model[callback].apply(model, [e]);
  121. });
  122. },
  123. _set_$field: function () {
  124. // vars
  125. this.o = this.$field.data();
  126. // els
  127. this.$settings = this.$field.find('> .settings > table > tbody');
  128. // focus
  129. this.focus();
  130. },
  131. focus: function () {
  132. // do nothing
  133. },
  134. setting: function (name) {
  135. return this.$settings.find('> .acf-field-setting-' + name);
  136. }
  137. });
  138. /*
  139. * field
  140. *
  141. * This model fires actions and filters for registered fields
  142. *
  143. * @type function
  144. * @date 21/02/2014
  145. * @since 3.5.1
  146. *
  147. * @param n/a
  148. * @return n/a
  149. */
  150. var actionManager = new acf.Model({
  151. actions: {
  152. open_field_object: 'onOpenFieldObject',
  153. close_field_object: 'onCloseFieldObject',
  154. add_field_object: 'onAddFieldObject',
  155. duplicate_field_object: 'onDuplicateFieldObject',
  156. delete_field_object: 'onDeleteFieldObject',
  157. change_field_object_type: 'onChangeFieldObjectType',
  158. change_field_object_label: 'onChangeFieldObjectLabel',
  159. change_field_object_name: 'onChangeFieldObjectName',
  160. change_field_object_parent: 'onChangeFieldObjectParent',
  161. sortstop_field_object: 'onChangeFieldObjectParent'
  162. },
  163. onOpenFieldObject: function (field) {
  164. acf.doAction('open_field', field.$el);
  165. acf.doAction('open_field/type=' + field.get('type'), field.$el);
  166. acf.doAction('render_field_settings', field.$el);
  167. acf.doAction('render_field_settings/type=' + field.get('type'), field.$el);
  168. },
  169. onCloseFieldObject: function (field) {
  170. acf.doAction('close_field', field.$el);
  171. acf.doAction('close_field/type=' + field.get('type'), field.$el);
  172. },
  173. onAddFieldObject: function (field) {
  174. acf.doAction('add_field', field.$el);
  175. acf.doAction('add_field/type=' + field.get('type'), field.$el);
  176. },
  177. onDuplicateFieldObject: function (field) {
  178. acf.doAction('duplicate_field', field.$el);
  179. acf.doAction('duplicate_field/type=' + field.get('type'), field.$el);
  180. },
  181. onDeleteFieldObject: function (field) {
  182. acf.doAction('delete_field', field.$el);
  183. acf.doAction('delete_field/type=' + field.get('type'), field.$el);
  184. },
  185. onChangeFieldObjectType: function (field) {
  186. acf.doAction('change_field_type', field.$el);
  187. acf.doAction('change_field_type/type=' + field.get('type'), field.$el);
  188. acf.doAction('render_field_settings', field.$el);
  189. acf.doAction('render_field_settings/type=' + field.get('type'), field.$el);
  190. },
  191. onChangeFieldObjectLabel: function (field) {
  192. acf.doAction('change_field_label', field.$el);
  193. acf.doAction('change_field_label/type=' + field.get('type'), field.$el);
  194. },
  195. onChangeFieldObjectName: function (field) {
  196. acf.doAction('change_field_name', field.$el);
  197. acf.doAction('change_field_name/type=' + field.get('type'), field.$el);
  198. },
  199. onChangeFieldObjectParent: function (field) {
  200. acf.doAction('update_field_parent', field.$el);
  201. }
  202. });
  203. })(jQuery);
  204. /***/ }),
  205. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_field-group-conditions.js":
  206. /*!*********************************************************************************!*\
  207. !*** ./src/advanced-custom-fields-pro/assets/src/js/_field-group-conditions.js ***!
  208. \*********************************************************************************/
  209. /***/ (function() {
  210. (function ($, undefined) {
  211. /**
  212. * ConditionalLogicFieldSetting
  213. *
  214. * description
  215. *
  216. * @date 3/2/18
  217. * @since 5.6.5
  218. *
  219. * @param type $var Description. Default.
  220. * @return type Description.
  221. */
  222. var ConditionalLogicFieldSetting = acf.FieldSetting.extend({
  223. type: '',
  224. name: 'conditional_logic',
  225. events: {
  226. 'change .conditions-toggle': 'onChangeToggle',
  227. 'click .add-conditional-group': 'onClickAddGroup',
  228. 'focus .condition-rule-field': 'onFocusField',
  229. 'change .condition-rule-field': 'onChangeField',
  230. 'change .condition-rule-operator': 'onChangeOperator',
  231. 'click .add-conditional-rule': 'onClickAdd',
  232. 'click .remove-conditional-rule': 'onClickRemove'
  233. },
  234. $rule: false,
  235. scope: function ($rule) {
  236. this.$rule = $rule;
  237. return this;
  238. },
  239. ruleData: function (name, value) {
  240. return this.$rule.data.apply(this.$rule, arguments);
  241. },
  242. $input: function (name) {
  243. return this.$rule.find('.condition-rule-' + name);
  244. },
  245. $td: function (name) {
  246. return this.$rule.find('td.' + name);
  247. },
  248. $toggle: function () {
  249. return this.$('.conditions-toggle');
  250. },
  251. $control: function () {
  252. return this.$('.rule-groups');
  253. },
  254. $groups: function () {
  255. return this.$('.rule-group');
  256. },
  257. $rules: function () {
  258. return this.$('.rule');
  259. },
  260. $tabLabel: function () {
  261. return this.fieldObject.$el.find('.conditional-logic-badge');
  262. },
  263. open: function () {
  264. var $div = this.$control();
  265. $div.show();
  266. acf.enable($div);
  267. },
  268. close: function () {
  269. var $div = this.$control();
  270. $div.hide();
  271. acf.disable($div);
  272. },
  273. render: function () {
  274. // show
  275. if (this.$toggle().prop('checked')) {
  276. this.$tabLabel().addClass('is-enabled');
  277. this.renderRules();
  278. this.open();
  279. // hide
  280. } else {
  281. this.$tabLabel().removeClass('is-enabled');
  282. this.close();
  283. }
  284. },
  285. renderRules: function () {
  286. // vars
  287. var self = this;
  288. // loop
  289. this.$rules().each(function () {
  290. self.renderRule($(this));
  291. });
  292. },
  293. renderRule: function ($rule) {
  294. this.scope($rule);
  295. this.renderField();
  296. this.renderOperator();
  297. this.renderValue();
  298. },
  299. renderField: function () {
  300. // vars
  301. var choices = [];
  302. var validFieldTypes = [];
  303. var cid = this.fieldObject.cid;
  304. var $select = this.$input('field');
  305. // loop
  306. acf.getFieldObjects().map(function (fieldObject) {
  307. // vars
  308. var choice = {
  309. id: fieldObject.getKey(),
  310. text: fieldObject.getLabel()
  311. };
  312. // bail early if is self
  313. if (fieldObject.cid === cid) {
  314. choice.text += acf.__('(this field)');
  315. choice.disabled = true;
  316. }
  317. // get selected field conditions
  318. var conditionTypes = acf.getConditionTypes({
  319. fieldType: fieldObject.getType()
  320. });
  321. // bail early if no types
  322. if (!conditionTypes.length) {
  323. choice.disabled = true;
  324. }
  325. // calulate indents
  326. var indents = fieldObject.getParents().length;
  327. choice.text = '- '.repeat(indents) + choice.text;
  328. // append
  329. choices.push(choice);
  330. });
  331. // allow for scenario where only one field exists
  332. if (!choices.length) {
  333. choices.push({
  334. id: '',
  335. text: acf.__('No toggle fields available')
  336. });
  337. }
  338. // render
  339. acf.renderSelect($select, choices);
  340. // set
  341. this.ruleData('field', $select.val());
  342. },
  343. renderOperator: function () {
  344. // bail early if no field selected
  345. if (!this.ruleData('field')) {
  346. return;
  347. }
  348. // vars
  349. var $select = this.$input('operator');
  350. var val = $select.val();
  351. var choices = [];
  352. // set saved value on first render
  353. // - this allows the 2nd render to correctly select an option
  354. if ($select.val() === null) {
  355. acf.renderSelect($select, [{
  356. id: this.ruleData('operator'),
  357. text: ''
  358. }]);
  359. }
  360. // get selected field
  361. var $field = acf.findFieldObject(this.ruleData('field'));
  362. var field = acf.getFieldObject($field);
  363. // get selected field conditions
  364. var conditionTypes = acf.getConditionTypes({
  365. fieldType: field.getType()
  366. });
  367. // html
  368. conditionTypes.map(function (model) {
  369. choices.push({
  370. id: model.prototype.operator,
  371. text: model.prototype.label
  372. });
  373. });
  374. // render
  375. acf.renderSelect($select, choices);
  376. // set
  377. this.ruleData('operator', $select.val());
  378. },
  379. renderValue: function () {
  380. // bail early if no field selected
  381. if (!this.ruleData('field') || !this.ruleData('operator')) {
  382. return;
  383. }
  384. // vars
  385. var $select = this.$input('value');
  386. var $td = this.$td('value');
  387. var val = $select.val();
  388. // get selected field
  389. var $field = acf.findFieldObject(this.ruleData('field'));
  390. var field = acf.getFieldObject($field);
  391. // get selected field conditions
  392. var conditionTypes = acf.getConditionTypes({
  393. fieldType: field.getType(),
  394. operator: this.ruleData('operator')
  395. });
  396. // html
  397. var conditionType = conditionTypes[0].prototype;
  398. var choices = conditionType.choices(field);
  399. // create html: array
  400. if (choices instanceof Array) {
  401. var $newSelect = $('<select></select>');
  402. acf.renderSelect($newSelect, choices);
  403. // create html: string (<input />)
  404. } else {
  405. var $newSelect = $(choices);
  406. }
  407. // append
  408. $select.detach();
  409. $td.html($newSelect);
  410. // copy attrs
  411. // timeout needed to avoid browser bug where "disabled" attribute is not applied
  412. setTimeout(function () {
  413. ['class', 'name', 'id'].map(function (attr) {
  414. $newSelect.attr(attr, $select.attr(attr));
  415. });
  416. }, 0);
  417. // select existing value (if not a disabled input)
  418. if (!$newSelect.prop('disabled')) {
  419. acf.val($newSelect, val, true);
  420. }
  421. // set
  422. this.ruleData('value', $newSelect.val());
  423. },
  424. onChangeToggle: function () {
  425. this.render();
  426. },
  427. onClickAddGroup: function (e, $el) {
  428. this.addGroup();
  429. },
  430. addGroup: function () {
  431. // vars
  432. var $group = this.$('.rule-group:last');
  433. // duplicate
  434. var $group2 = acf.duplicate($group);
  435. // update h4
  436. $group2.find('h4').text(acf.__('or'));
  437. // remove all tr's except the first one
  438. $group2.find('tr').not(':first').remove();
  439. // save field
  440. this.fieldObject.save();
  441. },
  442. onFocusField: function (e, $el) {
  443. this.renderField();
  444. },
  445. onChangeField: function (e, $el) {
  446. // scope
  447. this.scope($el.closest('.rule'));
  448. // set data
  449. this.ruleData('field', $el.val());
  450. // render
  451. this.renderOperator();
  452. this.renderValue();
  453. },
  454. onChangeOperator: function (e, $el) {
  455. // scope
  456. this.scope($el.closest('.rule'));
  457. // set data
  458. this.ruleData('operator', $el.val());
  459. // render
  460. this.renderValue();
  461. },
  462. onClickAdd: function (e, $el) {
  463. // duplciate
  464. var $rule = acf.duplicate($el.closest('.rule'));
  465. // render
  466. this.renderRule($rule);
  467. },
  468. onClickRemove: function (e, $el) {
  469. // vars
  470. var $rule = $el.closest('.rule');
  471. // save field
  472. this.fieldObject.save();
  473. // remove group
  474. if ($rule.siblings('.rule').length == 0) {
  475. $rule.closest('.rule-group').remove();
  476. }
  477. // remove
  478. $rule.remove();
  479. }
  480. });
  481. acf.registerFieldSetting(ConditionalLogicFieldSetting);
  482. /**
  483. * conditionalLogicHelper
  484. *
  485. * description
  486. *
  487. * @date 20/4/18
  488. * @since 5.6.9
  489. *
  490. * @param type $var Description. Default.
  491. * @return type Description.
  492. */
  493. var conditionalLogicHelper = new acf.Model({
  494. actions: {
  495. duplicate_field_objects: 'onDuplicateFieldObjects'
  496. },
  497. onDuplicateFieldObjects: function (children, newField, prevField) {
  498. // vars
  499. var data = {};
  500. var $selects = $();
  501. // reference change in key
  502. children.map(function (child) {
  503. // store reference of changed key
  504. data[child.get('prevKey')] = child.get('key');
  505. // append condition select
  506. $selects = $selects.add(child.$('.condition-rule-field'));
  507. });
  508. // loop
  509. $selects.each(function () {
  510. // vars
  511. var $select = $(this);
  512. var val = $select.val();
  513. // bail early if val is not a ref key
  514. if (!val || !data[val]) {
  515. return;
  516. }
  517. // modify selected option
  518. $select.find('option:selected').attr('value', data[val]);
  519. // set new val
  520. $select.val(data[val]);
  521. });
  522. }
  523. });
  524. })(jQuery);
  525. /***/ }),
  526. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_field-group-field.js":
  527. /*!****************************************************************************!*\
  528. !*** ./src/advanced-custom-fields-pro/assets/src/js/_field-group-field.js ***!
  529. \****************************************************************************/
  530. /***/ (function() {
  531. (function ($, undefined) {
  532. acf.FieldObject = acf.Model.extend({
  533. // class used to avoid nested event triggers
  534. eventScope: '.acf-field-object',
  535. // events
  536. events: {
  537. 'click .copyable': 'onClickCopy',
  538. 'click .handle': 'onClickEdit',
  539. 'click .close-field': 'onClickEdit',
  540. 'click a[data-key="acf_field_settings_tabs"]': 'onChangeSettingsTab',
  541. 'click .delete-field': 'onClickDelete',
  542. 'click .duplicate-field': 'duplicate',
  543. 'click .move-field': 'move',
  544. 'focus .edit-field': 'onFocusEdit',
  545. 'blur .edit-field, .row-options a': 'onBlurEdit',
  546. 'change .field-type': 'onChangeType',
  547. 'change .field-required': 'onChangeRequired',
  548. 'blur .field-label': 'onChangeLabel',
  549. 'blur .field-name': 'onChangeName',
  550. change: 'onChange',
  551. changed: 'onChanged'
  552. },
  553. // data
  554. data: {
  555. // Similar to ID, but used for HTML puposes.
  556. // It is possbile for a new field to have an ID of 0, but an id of 'field_123' */
  557. id: 0,
  558. // The field key ('field_123')
  559. key: '',
  560. // The field type (text, image, etc)
  561. type: ''
  562. // The $post->ID of this field
  563. //ID: 0,
  564. // The field's parent
  565. //parent: 0,
  566. // The menu order
  567. //menu_order: 0
  568. },
  569. setup: function ($field) {
  570. // set $el
  571. this.$el = $field;
  572. // inherit $field data (id, key, type)
  573. this.inherit($field);
  574. // load additional props
  575. // - this won't trigger 'changed'
  576. this.prop('ID');
  577. this.prop('parent');
  578. this.prop('menu_order');
  579. },
  580. $input: function (name) {
  581. return $('#' + this.getInputId() + '-' + name);
  582. },
  583. $meta: function () {
  584. return this.$('.meta:first');
  585. },
  586. $handle: function () {
  587. return this.$('.handle:first');
  588. },
  589. $settings: function () {
  590. return this.$('.settings:first');
  591. },
  592. $setting: function (name) {
  593. return this.$('.acf-field-settings:first .acf-field-setting-' + name);
  594. },
  595. getParent: function () {
  596. return acf.getFieldObjects({
  597. child: this.$el,
  598. limit: 1
  599. }).pop();
  600. },
  601. getParents: function () {
  602. return acf.getFieldObjects({
  603. child: this.$el
  604. });
  605. },
  606. getFields: function () {
  607. return acf.getFieldObjects({
  608. parent: this.$el
  609. });
  610. },
  611. getInputName: function () {
  612. return 'acf_fields[' + this.get('id') + ']';
  613. },
  614. getInputId: function () {
  615. return 'acf_fields-' + this.get('id');
  616. },
  617. newInput: function (name, value) {
  618. // vars
  619. var inputId = this.getInputId();
  620. var inputName = this.getInputName();
  621. // append name
  622. if (name) {
  623. inputId += '-' + name;
  624. inputName += '[' + name + ']';
  625. }
  626. // create input (avoid HTML + JSON value issues)
  627. var $input = $('<input />').attr({
  628. id: inputId,
  629. name: inputName,
  630. value: value
  631. });
  632. this.$('> .meta').append($input);
  633. // return
  634. return $input;
  635. },
  636. getProp: function (name) {
  637. // check data
  638. if (this.has(name)) {
  639. return this.get(name);
  640. }
  641. // get input value
  642. var $input = this.$input(name);
  643. var value = $input.length ? $input.val() : null;
  644. // set data silently (cache)
  645. this.set(name, value, true);
  646. // return
  647. return value;
  648. },
  649. setProp: function (name, value) {
  650. // get input
  651. var $input = this.$input(name);
  652. var prevVal = $input.val();
  653. // create if new
  654. if (!$input.length) {
  655. $input = this.newInput(name, value);
  656. }
  657. // remove
  658. if (value === null) {
  659. $input.remove();
  660. // update
  661. } else {
  662. $input.val(value);
  663. }
  664. //console.log('setProp', name, value, this);
  665. // set data silently (cache)
  666. if (!this.has(name)) {
  667. //console.log('setting silently');
  668. this.set(name, value, true);
  669. // set data allowing 'change' event to fire
  670. } else {
  671. //console.log('setting loudly!');
  672. this.set(name, value);
  673. }
  674. // return
  675. return this;
  676. },
  677. prop: function (name, value) {
  678. if (value !== undefined) {
  679. return this.setProp(name, value);
  680. } else {
  681. return this.getProp(name);
  682. }
  683. },
  684. props: function (props) {
  685. Object.keys(props).map(function (key) {
  686. this.setProp(key, props[key]);
  687. }, this);
  688. },
  689. getLabel: function () {
  690. // get label with empty default
  691. var label = this.prop('label');
  692. if (label === '') {
  693. label = acf.__('(no label)');
  694. }
  695. // return
  696. return label;
  697. },
  698. getName: function () {
  699. return this.prop('name');
  700. },
  701. getType: function () {
  702. return this.prop('type');
  703. },
  704. getTypeLabel: function () {
  705. var type = this.prop('type');
  706. var types = acf.get('fieldTypes');
  707. return types[type] ? types[type].label : type;
  708. },
  709. getKey: function () {
  710. return this.prop('key');
  711. },
  712. initialize: function () {
  713. this.addProFields();
  714. this.checkCopyable();
  715. },
  716. makeCopyable: function (text) {
  717. if (!navigator.clipboard) return '<span class="copyable copy-unsupported">' + text + '</span>';
  718. return '<span class="copyable">' + text + '</span>';
  719. },
  720. checkCopyable: function () {
  721. if (!navigator.clipboard) {
  722. this.$el.find('.copyable').addClass('copy-unsupported');
  723. }
  724. },
  725. addProFields: function () {
  726. // Make sure we're only running this on free version.
  727. if (acf.data.fieldTypes.hasOwnProperty('clone')) {
  728. return;
  729. }
  730. // Make sure we haven't appended these fields before.
  731. var $fieldTypeSelect = $('.field-type').not('.acf-free-field-type');
  732. // Append pro fields to "Layout" group.
  733. var $layoutGroup = $fieldTypeSelect.find('optgroup option[value="group"]').parent();
  734. $layoutGroup.append('<option value="null" disabled="disabled">' + acf.__('Repeater (Pro only)') + '</option>' + '<option value="null" disabled="disabled">' + acf.__('Flexible Content (Pro only)') + '</option>' + '<option value="null" disabled="disabled">' + acf.__('Clone (Pro only)') + '</option>');
  735. // Add pro fields to "Content" group.
  736. var $contentGroup = $fieldTypeSelect.find('optgroup option[value="image"]').parent();
  737. $contentGroup.append('<option value="null" disabled="disabled">' + acf.__('Gallery (Pro only)') + '</option>');
  738. $fieldTypeSelect.addClass('acf-free-field-type');
  739. },
  740. render: function () {
  741. // vars
  742. var $handle = this.$('.handle:first');
  743. var menu_order = this.prop('menu_order');
  744. var label = this.getLabel();
  745. var name = this.prop('name');
  746. var type = this.getTypeLabel();
  747. var key = this.prop('key');
  748. var required = this.$input('required').prop('checked');
  749. // update menu order
  750. $handle.find('.acf-icon').html(parseInt(menu_order) + 1);
  751. // update required
  752. if (required) {
  753. label += ' <span class="acf-required">*</span>';
  754. }
  755. // update label
  756. $handle.find('.li-field-label strong a').html(label);
  757. // update name
  758. $handle.find('.li-field-name').html(this.makeCopyable(name));
  759. // update type
  760. const iconName = acf.strSlugify(this.getType());
  761. $handle.find('.field-type-label').text(' ' + type);
  762. $handle.find('.field-type-icon').removeClass().addClass('field-type-icon field-type-icon-' + iconName);
  763. // update key
  764. $handle.find('.li-field-key').html(this.makeCopyable(key));
  765. // action for 3rd party customization
  766. acf.doAction('render_field_object', this);
  767. },
  768. refresh: function () {
  769. acf.doAction('refresh_field_object', this);
  770. },
  771. isOpen: function () {
  772. return this.$el.hasClass('open');
  773. },
  774. onClickCopy: function (e) {
  775. e.stopPropagation();
  776. if (!navigator.clipboard) return;
  777. navigator.clipboard.writeText($(e.target).text()).then(() => {
  778. $(e.target).addClass('copied');
  779. setTimeout(function () {
  780. $(e.target).removeClass('copied');
  781. }, 2000);
  782. });
  783. },
  784. onClickEdit: function (e) {
  785. $target = $(e.target);
  786. if ($target.parent().hasClass('row-options') && !$target.hasClass('edit-field')) return;
  787. this.isOpen() ? this.close() : this.open();
  788. },
  789. onChangeSettingsTab: function () {
  790. const $settings = this.$el.children('.settings');
  791. acf.doAction('show', $settings);
  792. },
  793. /**
  794. * Adds 'active' class to row options nearest to the target.
  795. */
  796. onFocusEdit: function (e) {
  797. var $rowOptions = $(e.target).closest('li').find('.row-options');
  798. $rowOptions.addClass('active');
  799. },
  800. /**
  801. * Removes 'active' class from row options if links in same row options area are no longer in focus.
  802. */
  803. onBlurEdit: function (e) {
  804. var focusDelayMilliseconds = 50;
  805. var $rowOptionsBlurElement = $(e.target).closest('li').find('.row-options');
  806. // Timeout so that `activeElement` gives the new element in focus instead of the body.
  807. setTimeout(function () {
  808. var $rowOptionsFocusElement = $(document.activeElement).closest('li').find('.row-options');
  809. if (!$rowOptionsBlurElement.is($rowOptionsFocusElement)) {
  810. $rowOptionsBlurElement.removeClass('active');
  811. }
  812. }, focusDelayMilliseconds);
  813. },
  814. open: function () {
  815. // vars
  816. var $settings = this.$el.children('.settings');
  817. // action (open)
  818. acf.doAction('open_field_object', this);
  819. this.trigger('openFieldObject');
  820. // action (show)
  821. acf.doAction('show', $settings);
  822. // open
  823. $settings.slideDown();
  824. this.$el.addClass('open');
  825. },
  826. close: function () {
  827. // vars
  828. var $settings = this.$el.children('.settings');
  829. // close
  830. $settings.slideUp();
  831. this.$el.removeClass('open');
  832. // action (close)
  833. acf.doAction('close_field_object', this);
  834. this.trigger('closeFieldObject');
  835. // action (hide)
  836. acf.doAction('hide', $settings);
  837. },
  838. serialize: function () {
  839. return acf.serialize(this.$el, this.getInputName());
  840. },
  841. save: function (type) {
  842. // defaults
  843. type = type || 'settings'; // meta, settings
  844. // vars
  845. var save = this.getProp('save');
  846. // bail if already saving settings
  847. if (save === 'settings') {
  848. return;
  849. }
  850. // prop
  851. this.setProp('save', type);
  852. // debug
  853. this.$el.attr('data-save', type);
  854. // action
  855. acf.doAction('save_field_object', this, type);
  856. },
  857. submit: function () {
  858. // vars
  859. var inputName = this.getInputName();
  860. var save = this.get('save');
  861. // close
  862. if (this.isOpen()) {
  863. this.close();
  864. }
  865. // allow all inputs to save
  866. if (save == 'settings') {
  867. // do nothing
  868. // allow only meta inputs to save
  869. } else if (save == 'meta') {
  870. this.$('> .settings [name^="' + inputName + '"]').remove();
  871. // prevent all inputs from saving
  872. } else {
  873. this.$('[name^="' + inputName + '"]').remove();
  874. }
  875. // action
  876. acf.doAction('submit_field_object', this);
  877. },
  878. onChange: function (e, $el) {
  879. // save settings
  880. this.save();
  881. // action for 3rd party customization
  882. acf.doAction('change_field_object', this);
  883. },
  884. onChanged: function (e, $el, name, value) {
  885. // ignore 'save'
  886. if (name == 'save') {
  887. return;
  888. }
  889. // save meta
  890. if (['menu_order', 'parent'].indexOf(name) > -1) {
  891. this.save('meta');
  892. // save field
  893. } else {
  894. this.save();
  895. }
  896. // render
  897. if (['menu_order', 'label', 'required', 'name', 'type', 'key'].indexOf(name) > -1) {
  898. this.render();
  899. }
  900. // action for 3rd party customization
  901. acf.doAction('change_field_object_' + name, this, value);
  902. },
  903. onChangeLabel: function (e, $el) {
  904. // set
  905. var label = $el.val();
  906. this.set('label', label);
  907. // render name
  908. if (this.prop('name') == '') {
  909. var name = acf.applyFilters('generate_field_object_name', acf.strSanitize(label), this);
  910. this.prop('name', name);
  911. }
  912. },
  913. onChangeName: function (e, $el) {
  914. // set
  915. var name = $el.val();
  916. this.set('name', name);
  917. // error
  918. if (name.substr(0, 6) === 'field_') {
  919. alert(acf.__('The string "field_" may not be used at the start of a field name'));
  920. }
  921. },
  922. onChangeRequired: function (e, $el) {
  923. // set
  924. var required = $el.prop('checked') ? 1 : 0;
  925. this.set('required', required);
  926. },
  927. delete: function (args) {
  928. // defaults
  929. args = acf.parseArgs(args, {
  930. animate: true
  931. });
  932. // add to remove list
  933. var id = this.prop('ID');
  934. if (id) {
  935. var $input = $('#_acf_delete_fields');
  936. var newVal = $input.val() + '|' + id;
  937. $input.val(newVal);
  938. }
  939. // action
  940. acf.doAction('delete_field_object', this);
  941. // animate
  942. if (args.animate) {
  943. this.removeAnimate();
  944. } else {
  945. this.remove();
  946. }
  947. },
  948. onClickDelete: function (e, $el) {
  949. // Bypass confirmation when holding down "shift" key.
  950. if (e.shiftKey) {
  951. return this.delete();
  952. }
  953. // add class
  954. this.$el.addClass('-hover');
  955. // add tooltip
  956. var tooltip = acf.newTooltip({
  957. confirmRemove: true,
  958. target: $el,
  959. context: this,
  960. confirm: function () {
  961. this.delete();
  962. },
  963. cancel: function () {
  964. this.$el.removeClass('-hover');
  965. }
  966. });
  967. },
  968. removeAnimate: function () {
  969. // vars
  970. var field = this;
  971. var $list = this.$el.parent();
  972. var $fields = acf.findFieldObjects({
  973. sibling: this.$el
  974. });
  975. // remove
  976. acf.remove({
  977. target: this.$el,
  978. endHeight: $fields.length ? 0 : 50,
  979. complete: function () {
  980. field.remove();
  981. acf.doAction('removed_field_object', field, $list);
  982. }
  983. });
  984. // action
  985. acf.doAction('remove_field_object', field, $list);
  986. },
  987. duplicate: function () {
  988. // vars
  989. var newKey = acf.uniqid('field_');
  990. // duplicate
  991. var $newField = acf.duplicate({
  992. target: this.$el,
  993. search: this.get('id'),
  994. replace: newKey
  995. });
  996. // set new key
  997. $newField.attr('data-key', newKey);
  998. // get instance
  999. var newField = acf.getFieldObject($newField);
  1000. // open / close
  1001. if (this.isOpen()) {
  1002. this.close();
  1003. } else {
  1004. newField.open();
  1005. }
  1006. // focus label
  1007. var $label = newField.$setting('label input');
  1008. setTimeout(function () {
  1009. $label.trigger('focus');
  1010. }, 251);
  1011. // update newField label / name
  1012. var label = newField.prop('label');
  1013. var name = newField.prop('name');
  1014. var end = name.split('_').pop();
  1015. var copy = acf.__('copy');
  1016. // increase suffix "1"
  1017. if (acf.isNumeric(end)) {
  1018. var i = end * 1 + 1;
  1019. label = label.replace(end, i);
  1020. name = name.replace(end, i);
  1021. // increase suffix "(copy1)"
  1022. } else if (end.indexOf(copy) === 0) {
  1023. var i = end.replace(copy, '') * 1;
  1024. i = i ? i + 1 : 2;
  1025. // replace
  1026. label = label.replace(end, copy + i);
  1027. name = name.replace(end, copy + i);
  1028. // add default "(copy)"
  1029. } else {
  1030. label += ' (' + copy + ')';
  1031. name += '_' + copy;
  1032. }
  1033. newField.prop('ID', 0);
  1034. newField.prop('label', label);
  1035. newField.prop('name', name);
  1036. newField.prop('key', newKey);
  1037. // action
  1038. acf.doAction('duplicate_field_object', this, newField);
  1039. acf.doAction('append_field_object', newField);
  1040. },
  1041. wipe: function () {
  1042. // vars
  1043. var prevId = this.get('id');
  1044. var prevKey = this.get('key');
  1045. var newKey = acf.uniqid('field_');
  1046. // rename
  1047. acf.rename({
  1048. target: this.$el,
  1049. search: prevId,
  1050. replace: newKey
  1051. });
  1052. // data
  1053. this.set('id', newKey);
  1054. this.set('prevId', prevId);
  1055. this.set('prevKey', prevKey);
  1056. // props
  1057. this.prop('key', newKey);
  1058. this.prop('ID', 0);
  1059. // attr
  1060. this.$el.attr('data-key', newKey);
  1061. this.$el.attr('data-id', newKey);
  1062. // action
  1063. acf.doAction('wipe_field_object', this);
  1064. },
  1065. move: function () {
  1066. // helper
  1067. var hasChanged = function (field) {
  1068. return field.get('save') == 'settings';
  1069. };
  1070. // vars
  1071. var changed = hasChanged(this);
  1072. // has sub fields changed
  1073. if (!changed) {
  1074. acf.getFieldObjects({
  1075. parent: this.$el
  1076. }).map(function (field) {
  1077. changed = hasChanged(field) || field.changed;
  1078. });
  1079. }
  1080. // bail early if changed
  1081. if (changed) {
  1082. alert(acf.__('This field cannot be moved until its changes have been saved'));
  1083. return;
  1084. }
  1085. // step 1.
  1086. var id = this.prop('ID');
  1087. var field = this;
  1088. var popup = false;
  1089. var step1 = function () {
  1090. // popup
  1091. popup = acf.newPopup({
  1092. title: acf.__('Move Custom Field'),
  1093. loading: true,
  1094. width: '300px',
  1095. openedBy: field.$el.find('.move-field')
  1096. });
  1097. // ajax
  1098. var ajaxData = {
  1099. action: 'acf/field_group/move_field',
  1100. field_id: id
  1101. };
  1102. // get HTML
  1103. $.ajax({
  1104. url: acf.get('ajaxurl'),
  1105. data: acf.prepareForAjax(ajaxData),
  1106. type: 'post',
  1107. dataType: 'html',
  1108. success: step2
  1109. });
  1110. };
  1111. var step2 = function (html) {
  1112. // update popup
  1113. popup.loading(false);
  1114. popup.content(html);
  1115. // submit form
  1116. popup.on('submit', 'form', step3);
  1117. };
  1118. var step3 = function (e, $el) {
  1119. // prevent
  1120. e.preventDefault();
  1121. // disable
  1122. acf.startButtonLoading(popup.$('.button'));
  1123. // ajax
  1124. var ajaxData = {
  1125. action: 'acf/field_group/move_field',
  1126. field_id: id,
  1127. field_group_id: popup.$('select').val()
  1128. };
  1129. // get HTML
  1130. $.ajax({
  1131. url: acf.get('ajaxurl'),
  1132. data: acf.prepareForAjax(ajaxData),
  1133. type: 'post',
  1134. dataType: 'html',
  1135. success: step4
  1136. });
  1137. };
  1138. var step4 = function (html) {
  1139. popup.content(html);
  1140. if (wp.a11y && wp.a11y.speak && acf.__) {
  1141. wp.a11y.speak(acf.__('Field moved to other group'), 'polite');
  1142. }
  1143. popup.$('.acf-close-popup').focus();
  1144. field.removeAnimate();
  1145. };
  1146. // start
  1147. step1();
  1148. },
  1149. onChangeType: function (e, $el) {
  1150. // clea previous timout
  1151. if (this.changeTimeout) {
  1152. clearTimeout(this.changeTimeout);
  1153. }
  1154. // set new timeout
  1155. // - prevents changing type multiple times whilst user types in newType
  1156. this.changeTimeout = this.setTimeout(function () {
  1157. this.changeType($el.val());
  1158. }, 300);
  1159. },
  1160. changeType: function (newType) {
  1161. var prevType = this.prop('type');
  1162. var prevClass = acf.strSlugify('acf-field-object-' + prevType);
  1163. var newClass = acf.strSlugify('acf-field-object-' + newType);
  1164. // Update props.
  1165. this.$el.removeClass(prevClass).addClass(newClass);
  1166. this.$el.attr('data-type', newType);
  1167. this.$el.data('type', newType);
  1168. // Abort XHR if this field is already loading AJAX data.
  1169. if (this.has('xhr')) {
  1170. this.get('xhr').abort();
  1171. }
  1172. // Store old settings so they can be reused later.
  1173. const $oldSettings = [];
  1174. this.$el.find('.acf-field-settings:first > .acf-field-settings-main > .acf-field-type-settings').each(function () {
  1175. let tab = $(this).data('parent-tab');
  1176. let $tabSettings = $(this).children();
  1177. $oldSettings[tab] = $tabSettings;
  1178. $tabSettings.detach();
  1179. });
  1180. this.set('settings-' + prevType, $oldSettings);
  1181. // Show the settings if we already have them cached.
  1182. if (this.has('settings-' + newType)) {
  1183. let $newSettings = this.get('settings-' + newType);
  1184. this.showFieldTypeSettings($newSettings);
  1185. this.set('type', newType);
  1186. return;
  1187. }
  1188. // Add loading spinner.
  1189. const $loading = $('<div class="acf-field"><div class="acf-input"><div class="acf-loading"></div></div></div>');
  1190. this.$el.find('.acf-field-settings-main-general .acf-field-type-settings').before($loading);
  1191. const ajaxData = {
  1192. action: 'acf/field_group/render_field_settings',
  1193. field: this.serialize(),
  1194. prefix: this.getInputName()
  1195. };
  1196. // Get the settings for this field type over AJAX.
  1197. var xhr = $.ajax({
  1198. url: acf.get('ajaxurl'),
  1199. data: acf.prepareForAjax(ajaxData),
  1200. type: 'post',
  1201. dataType: 'json',
  1202. context: this,
  1203. success: function (response) {
  1204. if (!acf.isAjaxSuccess(response)) {
  1205. return;
  1206. }
  1207. this.showFieldTypeSettings(response.data);
  1208. },
  1209. complete: function () {
  1210. // also triggered by xhr.abort();
  1211. $loading.remove();
  1212. this.set('type', newType);
  1213. //this.refresh();
  1214. }
  1215. });
  1216. // set
  1217. this.set('xhr', xhr);
  1218. },
  1219. showFieldTypeSettings: function (settings) {
  1220. if ('object' !== typeof settings) {
  1221. return;
  1222. }
  1223. const self = this;
  1224. const tabs = Object.keys(settings);
  1225. tabs.forEach(tab => {
  1226. const $tab = self.$el.find('.acf-field-settings-main-' + tab + ' .acf-field-type-settings');
  1227. let tabContent = '';
  1228. if (['object', 'string'].includes(typeof settings[tab])) {
  1229. tabContent = settings[tab];
  1230. }
  1231. $tab.prepend(tabContent);
  1232. acf.doAction('append', $tab);
  1233. });
  1234. },
  1235. updateParent: function () {
  1236. // vars
  1237. var ID = acf.get('post_id');
  1238. // check parent
  1239. var parent = this.getParent();
  1240. if (parent) {
  1241. ID = parseInt(parent.prop('ID')) || parent.prop('key');
  1242. }
  1243. // update
  1244. this.prop('parent', ID);
  1245. }
  1246. });
  1247. })(jQuery);
  1248. /***/ }),
  1249. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_field-group-fields.js":
  1250. /*!*****************************************************************************!*\
  1251. !*** ./src/advanced-custom-fields-pro/assets/src/js/_field-group-fields.js ***!
  1252. \*****************************************************************************/
  1253. /***/ (function() {
  1254. (function ($, undefined) {
  1255. /**
  1256. * acf.findFieldObject
  1257. *
  1258. * Returns a single fieldObject $el for a given field key
  1259. *
  1260. * @date 1/2/18
  1261. * @since 5.7.0
  1262. *
  1263. * @param string key The field key
  1264. * @return jQuery
  1265. */
  1266. acf.findFieldObject = function (key) {
  1267. return acf.findFieldObjects({
  1268. key: key,
  1269. limit: 1
  1270. });
  1271. };
  1272. /**
  1273. * acf.findFieldObjects
  1274. *
  1275. * Returns an array of fieldObject $el for the given args
  1276. *
  1277. * @date 1/2/18
  1278. * @since 5.7.0
  1279. *
  1280. * @param object args
  1281. * @return jQuery
  1282. */
  1283. acf.findFieldObjects = function (args) {
  1284. // vars
  1285. args = args || {};
  1286. var selector = '.acf-field-object';
  1287. var $fields = false;
  1288. // args
  1289. args = acf.parseArgs(args, {
  1290. id: '',
  1291. key: '',
  1292. type: '',
  1293. limit: false,
  1294. list: null,
  1295. parent: false,
  1296. sibling: false,
  1297. child: false
  1298. });
  1299. // id
  1300. if (args.id) {
  1301. selector += '[data-id="' + args.id + '"]';
  1302. }
  1303. // key
  1304. if (args.key) {
  1305. selector += '[data-key="' + args.key + '"]';
  1306. }
  1307. // type
  1308. if (args.type) {
  1309. selector += '[data-type="' + args.type + '"]';
  1310. }
  1311. // query
  1312. if (args.list) {
  1313. $fields = args.list.children(selector);
  1314. } else if (args.parent) {
  1315. $fields = args.parent.find(selector);
  1316. } else if (args.sibling) {
  1317. $fields = args.sibling.siblings(selector);
  1318. } else if (args.child) {
  1319. $fields = args.child.parents(selector);
  1320. } else {
  1321. $fields = $(selector);
  1322. }
  1323. // limit
  1324. if (args.limit) {
  1325. $fields = $fields.slice(0, args.limit);
  1326. }
  1327. // return
  1328. return $fields;
  1329. };
  1330. /**
  1331. * acf.getFieldObject
  1332. *
  1333. * Returns a single fieldObject instance for a given $el|key
  1334. *
  1335. * @date 1/2/18
  1336. * @since 5.7.0
  1337. *
  1338. * @param string|jQuery $field The field $el or key
  1339. * @return jQuery
  1340. */
  1341. acf.getFieldObject = function ($field) {
  1342. // allow key
  1343. if (typeof $field === 'string') {
  1344. $field = acf.findFieldObject($field);
  1345. }
  1346. // instantiate
  1347. var field = $field.data('acf');
  1348. if (!field) {
  1349. field = acf.newFieldObject($field);
  1350. }
  1351. // return
  1352. return field;
  1353. };
  1354. /**
  1355. * acf.getFieldObjects
  1356. *
  1357. * Returns an array of fieldObject instances for the given args
  1358. *
  1359. * @date 1/2/18
  1360. * @since 5.7.0
  1361. *
  1362. * @param object args
  1363. * @return array
  1364. */
  1365. acf.getFieldObjects = function (args) {
  1366. // query
  1367. var $fields = acf.findFieldObjects(args);
  1368. // loop
  1369. var fields = [];
  1370. $fields.each(function () {
  1371. var field = acf.getFieldObject($(this));
  1372. fields.push(field);
  1373. });
  1374. // return
  1375. return fields;
  1376. };
  1377. /**
  1378. * acf.newFieldObject
  1379. *
  1380. * Initializes and returns a new FieldObject instance
  1381. *
  1382. * @date 1/2/18
  1383. * @since 5.7.0
  1384. *
  1385. * @param jQuery $field The field $el
  1386. * @return object
  1387. */
  1388. acf.newFieldObject = function ($field) {
  1389. // instantiate
  1390. var field = new acf.FieldObject($field);
  1391. // action
  1392. acf.doAction('new_field_object', field);
  1393. // return
  1394. return field;
  1395. };
  1396. /**
  1397. * actionManager
  1398. *
  1399. * description
  1400. *
  1401. * @date 15/12/17
  1402. * @since 5.6.5
  1403. *
  1404. * @param type $var Description. Default.
  1405. * @return type Description.
  1406. */
  1407. var eventManager = new acf.Model({
  1408. priority: 5,
  1409. initialize: function () {
  1410. // actions
  1411. var actions = ['prepare', 'ready', 'append', 'remove'];
  1412. // loop
  1413. actions.map(function (action) {
  1414. this.addFieldActions(action);
  1415. }, this);
  1416. },
  1417. addFieldActions: function (action) {
  1418. // vars
  1419. var pluralAction = action + '_field_objects'; // ready_field_objects
  1420. var singleAction = action + '_field_object'; // ready_field_object
  1421. var singleEvent = action + 'FieldObject'; // readyFieldObject
  1422. // global action
  1423. var callback = function ($el /*, arg1, arg2, etc*/) {
  1424. // vars
  1425. var fieldObjects = acf.getFieldObjects({
  1426. parent: $el
  1427. });
  1428. // call plural
  1429. if (fieldObjects.length) {
  1430. /// get args [$el, arg1]
  1431. var args = acf.arrayArgs(arguments);
  1432. // modify args [pluralAction, fields, arg1]
  1433. args.splice(0, 1, pluralAction, fieldObjects);
  1434. acf.doAction.apply(null, args);
  1435. }
  1436. };
  1437. // plural action
  1438. var pluralCallback = function (fieldObjects /*, arg1, arg2, etc*/) {
  1439. /// get args [fields, arg1]
  1440. var args = acf.arrayArgs(arguments);
  1441. // modify args [singleAction, fields, arg1]
  1442. args.unshift(singleAction);
  1443. // loop
  1444. fieldObjects.map(function (fieldObject) {
  1445. // modify args [singleAction, field, arg1]
  1446. args[1] = fieldObject;
  1447. acf.doAction.apply(null, args);
  1448. });
  1449. };
  1450. // single action
  1451. var singleCallback = function (fieldObject /*, arg1, arg2, etc*/) {
  1452. /// get args [$field, arg1]
  1453. var args = acf.arrayArgs(arguments);
  1454. // modify args [singleAction, $field, arg1]
  1455. args.unshift(singleAction);
  1456. // action variations (ready_field/type=image)
  1457. var variations = ['type', 'name', 'key'];
  1458. variations.map(function (variation) {
  1459. args[0] = singleAction + '/' + variation + '=' + fieldObject.get(variation);
  1460. acf.doAction.apply(null, args);
  1461. });
  1462. // modify args [arg1]
  1463. args.splice(0, 2);
  1464. // event
  1465. fieldObject.trigger(singleEvent, args);
  1466. };
  1467. // add actions
  1468. acf.addAction(action, callback, 5);
  1469. acf.addAction(pluralAction, pluralCallback, 5);
  1470. acf.addAction(singleAction, singleCallback, 5);
  1471. }
  1472. });
  1473. /**
  1474. * fieldManager
  1475. *
  1476. * description
  1477. *
  1478. * @date 4/1/18
  1479. * @since 5.6.5
  1480. *
  1481. * @param type $var Description. Default.
  1482. * @return type Description.
  1483. */
  1484. var fieldManager = new acf.Model({
  1485. id: 'fieldManager',
  1486. events: {
  1487. 'submit #post': 'onSubmit',
  1488. 'mouseenter .acf-field-list': 'onHoverSortable',
  1489. 'click .add-field': 'onClickAdd'
  1490. },
  1491. actions: {
  1492. removed_field_object: 'onRemovedField',
  1493. sortstop_field_object: 'onReorderField',
  1494. delete_field_object: 'onDeleteField',
  1495. change_field_object_type: 'onChangeFieldType',
  1496. duplicate_field_object: 'onDuplicateField'
  1497. },
  1498. onSubmit: function (e, $el) {
  1499. // vars
  1500. var fields = acf.getFieldObjects();
  1501. // loop
  1502. fields.map(function (field) {
  1503. field.submit();
  1504. });
  1505. },
  1506. setFieldMenuOrder: function (field) {
  1507. this.renderFields(field.$el.parent());
  1508. },
  1509. onHoverSortable: function (e, $el) {
  1510. // bail early if already sortable
  1511. if ($el.hasClass('ui-sortable')) return;
  1512. // sortable
  1513. $el.sortable({
  1514. helper: 'clone',
  1515. handle: '.acf-sortable-handle',
  1516. connectWith: '.acf-field-list',
  1517. start: function (e, ui) {
  1518. var field = acf.getFieldObject(ui.item);
  1519. ui.placeholder.height(ui.item.height());
  1520. acf.doAction('sortstart_field_object', field, $el);
  1521. },
  1522. update: function (e, ui) {
  1523. var field = acf.getFieldObject(ui.item);
  1524. acf.doAction('sortstop_field_object', field, $el);
  1525. }
  1526. });
  1527. },
  1528. onRemovedField: function (field, $list) {
  1529. this.renderFields($list);
  1530. },
  1531. onReorderField: function (field, $list) {
  1532. field.updateParent();
  1533. this.renderFields($list);
  1534. },
  1535. onDeleteField: function (field) {
  1536. // delete children
  1537. field.getFields().map(function (child) {
  1538. child.delete({
  1539. animate: false
  1540. });
  1541. });
  1542. },
  1543. onChangeFieldType: function (field) {
  1544. // this caused sub fields to disapear if changing type back...
  1545. //this.onDeleteField( field );
  1546. },
  1547. onDuplicateField: function (field, newField) {
  1548. // check for children
  1549. var children = newField.getFields();
  1550. if (children.length) {
  1551. // loop
  1552. children.map(function (child) {
  1553. // wipe field
  1554. child.wipe();
  1555. // update parent
  1556. child.updateParent();
  1557. });
  1558. // action
  1559. acf.doAction('duplicate_field_objects', children, newField, field);
  1560. }
  1561. // set menu order
  1562. this.setFieldMenuOrder(newField);
  1563. },
  1564. renderFields: function ($list) {
  1565. // vars
  1566. var fields = acf.getFieldObjects({
  1567. list: $list
  1568. });
  1569. // no fields
  1570. if (!fields.length) {
  1571. $list.addClass('-empty');
  1572. $list.parents('.acf-field-list-wrap').first().addClass('-empty');
  1573. return;
  1574. }
  1575. // has fields
  1576. $list.removeClass('-empty');
  1577. $list.parents('.acf-field-list-wrap').first().removeClass('-empty');
  1578. // prop
  1579. fields.map(function (field, i) {
  1580. field.prop('menu_order', i);
  1581. });
  1582. },
  1583. onClickAdd: function (e, $el) {
  1584. let $list;
  1585. if ($el.hasClass('add-first-field')) {
  1586. $list = $el.parents('.acf-field-list').eq(0);
  1587. } else if ($el.parent().hasClass('acf-headerbar-actions') || $el.parent().hasClass('no-fields-message-inner')) {
  1588. $list = $('.acf-field-list:first');
  1589. } else if ($el.parent().hasClass('acf-sub-field-list-header')) {
  1590. $list = $el.parents('.acf-input:first').find('.acf-field-list');
  1591. } else {
  1592. $list = $el.closest('.acf-tfoot').siblings('.acf-field-list');
  1593. }
  1594. this.addField($list);
  1595. },
  1596. addField: function ($list) {
  1597. // vars
  1598. var html = $('#tmpl-acf-field').html();
  1599. var $el = $(html);
  1600. var prevId = $el.data('id');
  1601. var newKey = acf.uniqid('field_');
  1602. // duplicate
  1603. var $newField = acf.duplicate({
  1604. target: $el,
  1605. search: prevId,
  1606. replace: newKey,
  1607. append: function ($el, $el2) {
  1608. $list.append($el2);
  1609. }
  1610. });
  1611. // get instance
  1612. var newField = acf.getFieldObject($newField);
  1613. // props
  1614. newField.prop('key', newKey);
  1615. newField.prop('ID', 0);
  1616. newField.prop('label', '');
  1617. newField.prop('name', '');
  1618. // attr
  1619. $newField.attr('data-key', newKey);
  1620. $newField.attr('data-id', newKey);
  1621. // update parent prop
  1622. newField.updateParent();
  1623. // focus type
  1624. var $type = newField.$input('type');
  1625. setTimeout(function () {
  1626. if ($list.hasClass('acf-auto-add-field')) {
  1627. $list.removeClass('acf-auto-add-field');
  1628. } else {
  1629. $type.trigger('focus');
  1630. }
  1631. }, 251);
  1632. // open
  1633. newField.open();
  1634. // set menu order
  1635. this.renderFields($list);
  1636. // action
  1637. acf.doAction('add_field_object', newField);
  1638. acf.doAction('append_field_object', newField);
  1639. }
  1640. });
  1641. })(jQuery);
  1642. /***/ }),
  1643. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_field-group-locations.js":
  1644. /*!********************************************************************************!*\
  1645. !*** ./src/advanced-custom-fields-pro/assets/src/js/_field-group-locations.js ***!
  1646. \********************************************************************************/
  1647. /***/ (function() {
  1648. (function ($, undefined) {
  1649. /**
  1650. * locationManager
  1651. *
  1652. * Field group location rules functionality
  1653. *
  1654. * @date 15/12/17
  1655. * @since 5.7.0
  1656. *
  1657. * @param void
  1658. * @return void
  1659. */
  1660. var locationManager = new acf.Model({
  1661. id: 'locationManager',
  1662. wait: 'ready',
  1663. events: {
  1664. 'click .add-location-rule': 'onClickAddRule',
  1665. 'click .add-location-group': 'onClickAddGroup',
  1666. 'click .remove-location-rule': 'onClickRemoveRule',
  1667. 'change .refresh-location-rule': 'onChangeRemoveRule'
  1668. },
  1669. initialize: function () {
  1670. this.$el = $('#acf-field-group-options');
  1671. this.updateGroupsClass();
  1672. },
  1673. onClickAddRule: function (e, $el) {
  1674. this.addRule($el.closest('tr'));
  1675. },
  1676. onClickRemoveRule: function (e, $el) {
  1677. this.removeRule($el.closest('tr'));
  1678. },
  1679. onChangeRemoveRule: function (e, $el) {
  1680. this.changeRule($el.closest('tr'));
  1681. },
  1682. onClickAddGroup: function (e, $el) {
  1683. this.addGroup();
  1684. },
  1685. addRule: function ($tr) {
  1686. acf.duplicate($tr);
  1687. this.updateGroupsClass();
  1688. },
  1689. removeRule: function ($tr) {
  1690. if ($tr.siblings('tr').length == 0) {
  1691. $tr.closest('.rule-group').remove();
  1692. } else {
  1693. $tr.remove();
  1694. }
  1695. // Update h4
  1696. var $group = this.$('.rule-group:first');
  1697. $group.find('h4').text(acf.__('Show this field group if'));
  1698. this.updateGroupsClass();
  1699. },
  1700. changeRule: function ($rule) {
  1701. // vars
  1702. var $group = $rule.closest('.rule-group');
  1703. var prefix = $rule.find('td.param select').attr('name').replace('[param]', '');
  1704. // ajaxdata
  1705. var ajaxdata = {};
  1706. ajaxdata.action = 'acf/field_group/render_location_rule';
  1707. ajaxdata.rule = acf.serialize($rule, prefix);
  1708. ajaxdata.rule.id = $rule.data('id');
  1709. ajaxdata.rule.group = $group.data('id');
  1710. // temp disable
  1711. acf.disable($rule.find('td.value'));
  1712. // ajax
  1713. $.ajax({
  1714. url: acf.get('ajaxurl'),
  1715. data: acf.prepareForAjax(ajaxdata),
  1716. type: 'post',
  1717. dataType: 'html',
  1718. success: function (html) {
  1719. if (!html) return;
  1720. $rule.replaceWith(html);
  1721. }
  1722. });
  1723. },
  1724. addGroup: function () {
  1725. // vars
  1726. var $group = this.$('.rule-group:last');
  1727. // duplicate
  1728. $group2 = acf.duplicate($group);
  1729. // update h4
  1730. $group2.find('h4').text(acf.__('or'));
  1731. // remove all tr's except the first one
  1732. $group2.find('tr').not(':first').remove();
  1733. // update the groups class
  1734. this.updateGroupsClass();
  1735. },
  1736. updateGroupsClass: function () {
  1737. var $group = this.$('.rule-group:last');
  1738. var $ruleGroups = $group.closest('.rule-groups');
  1739. var rows_count = $ruleGroups.find('.acf-table tr').length;
  1740. if (rows_count > 1) {
  1741. $ruleGroups.addClass('rule-groups-multiple');
  1742. } else {
  1743. $ruleGroups.removeClass('rule-groups-multiple');
  1744. }
  1745. }
  1746. });
  1747. })(jQuery);
  1748. /***/ }),
  1749. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_field-group-settings.js":
  1750. /*!*******************************************************************************!*\
  1751. !*** ./src/advanced-custom-fields-pro/assets/src/js/_field-group-settings.js ***!
  1752. \*******************************************************************************/
  1753. /***/ (function() {
  1754. (function ($, undefined) {
  1755. /**
  1756. * mid
  1757. *
  1758. * Calculates the model ID for a field type
  1759. *
  1760. * @date 15/12/17
  1761. * @since 5.6.5
  1762. *
  1763. * @param string type
  1764. * @return string
  1765. */
  1766. var modelId = function (type) {
  1767. return acf.strPascalCase(type || '') + 'FieldSetting';
  1768. };
  1769. /**
  1770. * registerFieldType
  1771. *
  1772. * description
  1773. *
  1774. * @date 14/12/17
  1775. * @since 5.6.5
  1776. *
  1777. * @param type $var Description. Default.
  1778. * @return type Description.
  1779. */
  1780. acf.registerFieldSetting = function (model) {
  1781. var proto = model.prototype;
  1782. var mid = modelId(proto.type + ' ' + proto.name);
  1783. this.models[mid] = model;
  1784. };
  1785. /**
  1786. * newField
  1787. *
  1788. * description
  1789. *
  1790. * @date 14/12/17
  1791. * @since 5.6.5
  1792. *
  1793. * @param type $var Description. Default.
  1794. * @return type Description.
  1795. */
  1796. acf.newFieldSetting = function (field) {
  1797. // vars
  1798. var type = field.get('setting') || '';
  1799. var name = field.get('name') || '';
  1800. var mid = modelId(type + ' ' + name);
  1801. var model = acf.models[mid] || null;
  1802. // bail early if no setting
  1803. if (model === null) return false;
  1804. // instantiate
  1805. var setting = new model(field);
  1806. // return
  1807. return setting;
  1808. };
  1809. /**
  1810. * acf.getFieldSetting
  1811. *
  1812. * description
  1813. *
  1814. * @date 19/4/18
  1815. * @since 5.6.9
  1816. *
  1817. * @param type $var Description. Default.
  1818. * @return type Description.
  1819. */
  1820. acf.getFieldSetting = function (field) {
  1821. // allow jQuery
  1822. if (field instanceof jQuery) {
  1823. field = acf.getField(field);
  1824. }
  1825. // return
  1826. return field.setting;
  1827. };
  1828. /**
  1829. * settingsManager
  1830. *
  1831. * @since 5.6.5
  1832. *
  1833. * @param object The object containing the extended variables and methods.
  1834. * @return void
  1835. */
  1836. var settingsManager = new acf.Model({
  1837. actions: {
  1838. new_field: 'onNewField'
  1839. },
  1840. onNewField: function (field) {
  1841. field.setting = acf.newFieldSetting(field);
  1842. }
  1843. });
  1844. /**
  1845. * acf.FieldSetting
  1846. *
  1847. * @since 5.6.5
  1848. *
  1849. * @param object The object containing the extended variables and methods.
  1850. * @return void
  1851. */
  1852. acf.FieldSetting = acf.Model.extend({
  1853. field: false,
  1854. type: '',
  1855. name: '',
  1856. wait: 'ready',
  1857. eventScope: '.acf-field',
  1858. events: {
  1859. change: 'render'
  1860. },
  1861. setup: function (field) {
  1862. // vars
  1863. var $field = field.$el;
  1864. // set props
  1865. this.$el = $field;
  1866. this.field = field;
  1867. this.$fieldObject = $field.closest('.acf-field-object');
  1868. this.fieldObject = acf.getFieldObject(this.$fieldObject);
  1869. // inherit data
  1870. $.extend(this.data, field.data);
  1871. },
  1872. initialize: function () {
  1873. this.render();
  1874. },
  1875. render: function () {
  1876. // do nothing
  1877. }
  1878. });
  1879. /**
  1880. * Accordion and Tab Endpoint Settings
  1881. *
  1882. * The 'endpoint' setting on accordions and tabs requires an additional class on the
  1883. * field object row when enabled.
  1884. *
  1885. * @since 6.0.0
  1886. *
  1887. * @param object The object containing the extended variables and methods.
  1888. * @return void
  1889. */
  1890. var EndpointFieldSetting = acf.FieldSetting.extend({
  1891. type: '',
  1892. name: '',
  1893. render: function () {
  1894. var $endpoint_setting = this.fieldObject.$setting('endpoint');
  1895. var $endpoint_field = $endpoint_setting.find('input[type="checkbox"]:first');
  1896. if ($endpoint_field.is(':checked')) {
  1897. this.fieldObject.$el.addClass('acf-field-is-endpoint');
  1898. } else {
  1899. this.fieldObject.$el.removeClass('acf-field-is-endpoint');
  1900. }
  1901. }
  1902. });
  1903. var AccordionEndpointFieldSetting = EndpointFieldSetting.extend({
  1904. type: 'accordion',
  1905. name: 'endpoint'
  1906. });
  1907. var TabEndpointFieldSetting = EndpointFieldSetting.extend({
  1908. type: 'tab',
  1909. name: 'endpoint'
  1910. });
  1911. acf.registerFieldSetting(AccordionEndpointFieldSetting);
  1912. acf.registerFieldSetting(TabEndpointFieldSetting);
  1913. /**
  1914. * Date Picker
  1915. *
  1916. * This field type requires some extra logic for its settings
  1917. *
  1918. * @since 5.0.0
  1919. *
  1920. * @param object The object containing the extended variables and methods.
  1921. * @return void
  1922. */
  1923. var DisplayFormatFieldSetting = acf.FieldSetting.extend({
  1924. type: '',
  1925. name: '',
  1926. render: function () {
  1927. var $input = this.$('input[type="radio"]:checked');
  1928. if ($input.val() != 'other') {
  1929. this.$('input[type="text"]').val($input.val());
  1930. }
  1931. }
  1932. });
  1933. var DatePickerDisplayFormatFieldSetting = DisplayFormatFieldSetting.extend({
  1934. type: 'date_picker',
  1935. name: 'display_format'
  1936. });
  1937. var DatePickerReturnFormatFieldSetting = DisplayFormatFieldSetting.extend({
  1938. type: 'date_picker',
  1939. name: 'return_format'
  1940. });
  1941. acf.registerFieldSetting(DatePickerDisplayFormatFieldSetting);
  1942. acf.registerFieldSetting(DatePickerReturnFormatFieldSetting);
  1943. /**
  1944. * Date Time Picker
  1945. *
  1946. * This field type requires some extra logic for its settings
  1947. *
  1948. * @since 5.0.0
  1949. *
  1950. * @param object The object containing the extended variables and methods.
  1951. * @return void
  1952. */
  1953. var DateTimePickerDisplayFormatFieldSetting = DisplayFormatFieldSetting.extend({
  1954. type: 'date_time_picker',
  1955. name: 'display_format'
  1956. });
  1957. var DateTimePickerReturnFormatFieldSetting = DisplayFormatFieldSetting.extend({
  1958. type: 'date_time_picker',
  1959. name: 'return_format'
  1960. });
  1961. acf.registerFieldSetting(DateTimePickerDisplayFormatFieldSetting);
  1962. acf.registerFieldSetting(DateTimePickerReturnFormatFieldSetting);
  1963. /**
  1964. * Time Picker
  1965. *
  1966. * This field type requires some extra logic for its settings
  1967. *
  1968. * @since 5.0.0
  1969. *
  1970. * @param object The object containing the extended variables and methods.
  1971. * @return void
  1972. */
  1973. var TimePickerDisplayFormatFieldSetting = DisplayFormatFieldSetting.extend({
  1974. type: 'time_picker',
  1975. name: 'display_format'
  1976. });
  1977. var TimePickerReturnFormatFieldSetting = DisplayFormatFieldSetting.extend({
  1978. type: 'time_picker',
  1979. name: 'return_format'
  1980. });
  1981. acf.registerFieldSetting(TimePickerDisplayFormatFieldSetting);
  1982. acf.registerFieldSetting(TimePickerReturnFormatFieldSetting);
  1983. /**
  1984. * Color Picker Settings.
  1985. *
  1986. * @date 16/12/20
  1987. * @since 5.9.4
  1988. *
  1989. * @param object The object containing the extended variables and methods.
  1990. * @return void
  1991. */
  1992. var ColorPickerReturnFormat = acf.FieldSetting.extend({
  1993. type: 'color_picker',
  1994. name: 'enable_opacity',
  1995. render: function () {
  1996. var $return_format_setting = this.fieldObject.$setting('return_format');
  1997. var $default_value_setting = this.fieldObject.$setting('default_value');
  1998. var $labelText = $return_format_setting.find('input[type="radio"][value="string"]').parent('label').contents().last();
  1999. var $defaultPlaceholder = $default_value_setting.find('input[type="text"]');
  2000. var l10n = acf.get('colorPickerL10n');
  2001. if (this.field.val()) {
  2002. $labelText.replaceWith(l10n.rgba_string);
  2003. $defaultPlaceholder.attr('placeholder', 'rgba(255,255,255,0.8)');
  2004. } else {
  2005. $labelText.replaceWith(l10n.hex_string);
  2006. $defaultPlaceholder.attr('placeholder', '#FFFFFF');
  2007. }
  2008. }
  2009. });
  2010. acf.registerFieldSetting(ColorPickerReturnFormat);
  2011. })(jQuery);
  2012. /***/ }),
  2013. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_field-group.js":
  2014. /*!**********************************************************************!*\
  2015. !*** ./src/advanced-custom-fields-pro/assets/src/js/_field-group.js ***!
  2016. \**********************************************************************/
  2017. /***/ (function() {
  2018. (function ($, undefined) {
  2019. /**
  2020. * fieldGroupManager
  2021. *
  2022. * Generic field group functionality
  2023. *
  2024. * @date 15/12/17
  2025. * @since 5.7.0
  2026. *
  2027. * @param void
  2028. * @return void
  2029. */
  2030. var fieldGroupManager = new acf.Model({
  2031. id: 'fieldGroupManager',
  2032. events: {
  2033. 'submit #post': 'onSubmit',
  2034. 'click a[href="#"]': 'onClick',
  2035. 'click .acf-delete-field-group': 'onClickDeleteFieldGroup',
  2036. 'blur input#title': 'onBlurValidateTitle'
  2037. },
  2038. filters: {
  2039. find_fields_args: 'filterFindFieldArgs',
  2040. find_fields_selector: 'filterFindFieldsSelector'
  2041. },
  2042. initialize: function () {
  2043. acf.addAction('prepare', this.maybeInitNewFieldGroup);
  2044. },
  2045. maybeInitNewFieldGroup: function () {
  2046. let $field_list_wrapper = $('#acf-field-group-fields > .inside > .acf-field-list-wrap.acf-auto-add-field');
  2047. if ($field_list_wrapper.length) {
  2048. $('.acf-headerbar-actions .add-field').trigger('click');
  2049. $('.acf-title-wrap #title').trigger('focus');
  2050. }
  2051. // Watch title input
  2052. // if title empty disable submit button
  2053. // if title exists allow submitting form
  2054. let $submitButton = $('.acf-publish');
  2055. $('input#title').on('input', function () {
  2056. const titleValue = $(this).val();
  2057. if (!titleValue) {
  2058. $submitButton.addClass('disabled');
  2059. } else {
  2060. $submitButton.removeClass('disabled');
  2061. $(this).removeClass('acf-input-error');
  2062. }
  2063. });
  2064. },
  2065. onSubmit: function (e, $el) {
  2066. // vars
  2067. var $title = $('.acf-title-wrap #title');
  2068. // empty
  2069. if (!$title.val()) {
  2070. // prevent default
  2071. e.preventDefault();
  2072. // unlock form
  2073. acf.unlockForm($el);
  2074. // focus
  2075. $title.trigger('focus');
  2076. }
  2077. },
  2078. onClick: function (e) {
  2079. e.preventDefault();
  2080. },
  2081. onClickDeleteFieldGroup: function (e, $el) {
  2082. e.preventDefault();
  2083. $el.addClass('-hover');
  2084. // Add confirmation tooltip.
  2085. acf.newTooltip({
  2086. confirm: true,
  2087. target: $el,
  2088. context: this,
  2089. text: acf.__('Move field group to trash?'),
  2090. confirm: function () {
  2091. window.location.href = $el.attr('href');
  2092. },
  2093. cancel: function () {
  2094. $el.removeClass('-hover');
  2095. }
  2096. });
  2097. },
  2098. onBlurValidateTitle: function (e, $el) {
  2099. if (!$el.val()) {
  2100. $el.addClass('acf-input-error');
  2101. $('.acf-publish').addClass('disabled');
  2102. } else {
  2103. $el.removeClass('acf-input-error');
  2104. $('.acf-publish').removeClass('disabled');
  2105. }
  2106. },
  2107. filterFindFieldArgs: function (args) {
  2108. args.visible = true;
  2109. if (args.parent && (args.parent.hasClass('acf-field-object') || args.parent.parents('.acf-field-object').length)) {
  2110. args.visible = false;
  2111. args.excludeSubFields = true;
  2112. }
  2113. return args;
  2114. },
  2115. filterFindFieldsSelector: function (selector) {
  2116. return selector + ', .acf-field-acf-field-group-settings-tabs';
  2117. }
  2118. });
  2119. /**
  2120. * screenOptionsManager
  2121. *
  2122. * Screen options functionality
  2123. *
  2124. * @date 15/12/17
  2125. * @since 5.7.0
  2126. *
  2127. * @param void
  2128. * @return void
  2129. */
  2130. var screenOptionsManager = new acf.Model({
  2131. id: 'screenOptionsManager',
  2132. wait: 'prepare',
  2133. events: {
  2134. 'change #acf-field-key-hide': 'onFieldKeysChange',
  2135. 'change #acf-field-settings-tabs': 'onFieldSettingsTabsChange',
  2136. 'change [name="screen_columns"]': 'render'
  2137. },
  2138. initialize: function () {
  2139. // vars
  2140. var $div = $('#adv-settings');
  2141. var $append = $('#acf-append-show-on-screen');
  2142. // append
  2143. $div.find('.metabox-prefs').append($append.html());
  2144. $div.find('.metabox-prefs br').remove();
  2145. // clean up
  2146. $append.remove();
  2147. // initialize
  2148. this.$el = $('#screen-options-wrap');
  2149. // render
  2150. this.render();
  2151. },
  2152. isFieldKeysChecked: function () {
  2153. return this.$el.find('#acf-field-key-hide').prop('checked');
  2154. },
  2155. isFieldSettingsTabsChecked: function () {
  2156. const $input = this.$el.find('#acf-field-settings-tabs');
  2157. // Screen option is hidden by filter.
  2158. if (!$input.length) {
  2159. return false;
  2160. }
  2161. return $input.prop('checked');
  2162. },
  2163. getSelectedColumnCount: function () {
  2164. return this.$el.find('input[name="screen_columns"]:checked').val();
  2165. },
  2166. onFieldKeysChange: function (e, $el) {
  2167. var val = this.isFieldKeysChecked() ? 1 : 0;
  2168. acf.updateUserSetting('show_field_keys', val);
  2169. this.render();
  2170. },
  2171. onFieldSettingsTabsChange: function () {
  2172. const val = this.isFieldSettingsTabsChecked() ? 1 : 0;
  2173. acf.updateUserSetting('show_field_settings_tabs', val);
  2174. this.render();
  2175. },
  2176. render: function () {
  2177. if (this.isFieldKeysChecked()) {
  2178. $('#acf-field-group-fields').addClass('show-field-keys');
  2179. } else {
  2180. $('#acf-field-group-fields').removeClass('show-field-keys');
  2181. }
  2182. if (!this.isFieldSettingsTabsChecked()) {
  2183. $('#acf-field-group-fields').addClass('hide-tabs');
  2184. $('.acf-field-settings-main').removeClass('acf-hidden').prop('hidden', false);
  2185. } else {
  2186. $('#acf-field-group-fields').removeClass('hide-tabs');
  2187. $('.acf-field-object.open').each(function () {
  2188. const tabFields = acf.getFields({
  2189. type: 'tab',
  2190. parent: $(this),
  2191. excludeSubFields: true,
  2192. limit: 1
  2193. });
  2194. if (tabFields.length) {
  2195. tabFields[0].tabs.set('initialized', false);
  2196. }
  2197. acf.doAction('show', $(this));
  2198. });
  2199. }
  2200. if (this.getSelectedColumnCount() == 1) {
  2201. $('body').removeClass('columns-2');
  2202. $('body').addClass('columns-1');
  2203. } else {
  2204. $('body').removeClass('columns-1');
  2205. $('body').addClass('columns-2');
  2206. }
  2207. }
  2208. });
  2209. /**
  2210. * appendFieldManager
  2211. *
  2212. * Appends fields together
  2213. *
  2214. * @date 15/12/17
  2215. * @since 5.7.0
  2216. *
  2217. * @param void
  2218. * @return void
  2219. */
  2220. var appendFieldManager = new acf.Model({
  2221. actions: {
  2222. new_field: 'onNewField'
  2223. },
  2224. onNewField: function (field) {
  2225. // bail early if not append
  2226. if (!field.has('append')) return;
  2227. // vars
  2228. var append = field.get('append');
  2229. var $sibling = field.$el.siblings('[data-name="' + append + '"]').first();
  2230. // bail early if no sibling
  2231. if (!$sibling.length) return;
  2232. // ul
  2233. var $div = $sibling.children('.acf-input');
  2234. var $ul = $div.children('ul');
  2235. // create ul
  2236. if (!$ul.length) {
  2237. $div.wrapInner('<ul class="acf-hl"><li></li></ul>');
  2238. $ul = $div.children('ul');
  2239. }
  2240. // li
  2241. var html = field.$('.acf-input').html();
  2242. var $li = $('<li>' + html + '</li>');
  2243. $ul.append($li);
  2244. $ul.attr('data-cols', $ul.children().length);
  2245. // clean up
  2246. field.remove();
  2247. }
  2248. });
  2249. })(jQuery);
  2250. /***/ })
  2251. /******/ });
  2252. /************************************************************************/
  2253. /******/ // The module cache
  2254. /******/ var __webpack_module_cache__ = {};
  2255. /******/
  2256. /******/ // The require function
  2257. /******/ function __webpack_require__(moduleId) {
  2258. /******/ // Check if module is in cache
  2259. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  2260. /******/ if (cachedModule !== undefined) {
  2261. /******/ return cachedModule.exports;
  2262. /******/ }
  2263. /******/ // Create a new module (and put it into the cache)
  2264. /******/ var module = __webpack_module_cache__[moduleId] = {
  2265. /******/ // no module.id needed
  2266. /******/ // no module.loaded needed
  2267. /******/ exports: {}
  2268. /******/ };
  2269. /******/
  2270. /******/ // Execute the module function
  2271. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  2272. /******/
  2273. /******/ // Return the exports of the module
  2274. /******/ return module.exports;
  2275. /******/ }
  2276. /******/
  2277. /************************************************************************/
  2278. /******/ /* webpack/runtime/compat get default export */
  2279. /******/ !function() {
  2280. /******/ // getDefaultExport function for compatibility with non-harmony modules
  2281. /******/ __webpack_require__.n = function(module) {
  2282. /******/ var getter = module && module.__esModule ?
  2283. /******/ function() { return module['default']; } :
  2284. /******/ function() { return module; };
  2285. /******/ __webpack_require__.d(getter, { a: getter });
  2286. /******/ return getter;
  2287. /******/ };
  2288. /******/ }();
  2289. /******/
  2290. /******/ /* webpack/runtime/define property getters */
  2291. /******/ !function() {
  2292. /******/ // define getter functions for harmony exports
  2293. /******/ __webpack_require__.d = function(exports, definition) {
  2294. /******/ for(var key in definition) {
  2295. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  2296. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  2297. /******/ }
  2298. /******/ }
  2299. /******/ };
  2300. /******/ }();
  2301. /******/
  2302. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  2303. /******/ !function() {
  2304. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  2305. /******/ }();
  2306. /******/
  2307. /******/ /* webpack/runtime/make namespace object */
  2308. /******/ !function() {
  2309. /******/ // define __esModule on exports
  2310. /******/ __webpack_require__.r = function(exports) {
  2311. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  2312. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  2313. /******/ }
  2314. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  2315. /******/ };
  2316. /******/ }();
  2317. /******/
  2318. /************************************************************************/
  2319. var __webpack_exports__ = {};
  2320. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  2321. !function() {
  2322. "use strict";
  2323. /*!*************************************************************************!*\
  2324. !*** ./src/advanced-custom-fields-pro/assets/src/js/acf-field-group.js ***!
  2325. \*************************************************************************/
  2326. __webpack_require__.r(__webpack_exports__);
  2327. /* harmony import */ var _field_group_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./_field-group.js */ "./src/advanced-custom-fields-pro/assets/src/js/_field-group.js");
  2328. /* harmony import */ var _field_group_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_field_group_js__WEBPACK_IMPORTED_MODULE_0__);
  2329. /* harmony import */ var _field_group_field_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./_field-group-field.js */ "./src/advanced-custom-fields-pro/assets/src/js/_field-group-field.js");
  2330. /* harmony import */ var _field_group_field_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_field_group_field_js__WEBPACK_IMPORTED_MODULE_1__);
  2331. /* harmony import */ var _field_group_settings_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./_field-group-settings.js */ "./src/advanced-custom-fields-pro/assets/src/js/_field-group-settings.js");
  2332. /* harmony import */ var _field_group_settings_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_field_group_settings_js__WEBPACK_IMPORTED_MODULE_2__);
  2333. /* harmony import */ var _field_group_conditions_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./_field-group-conditions.js */ "./src/advanced-custom-fields-pro/assets/src/js/_field-group-conditions.js");
  2334. /* harmony import */ var _field_group_conditions_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_field_group_conditions_js__WEBPACK_IMPORTED_MODULE_3__);
  2335. /* harmony import */ var _field_group_fields_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./_field-group-fields.js */ "./src/advanced-custom-fields-pro/assets/src/js/_field-group-fields.js");
  2336. /* harmony import */ var _field_group_fields_js__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_field_group_fields_js__WEBPACK_IMPORTED_MODULE_4__);
  2337. /* harmony import */ var _field_group_locations_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./_field-group-locations.js */ "./src/advanced-custom-fields-pro/assets/src/js/_field-group-locations.js");
  2338. /* harmony import */ var _field_group_locations_js__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_field_group_locations_js__WEBPACK_IMPORTED_MODULE_5__);
  2339. /* harmony import */ var _field_group_compatibility_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./_field-group-compatibility.js */ "./src/advanced-custom-fields-pro/assets/src/js/_field-group-compatibility.js");
  2340. /* harmony import */ var _field_group_compatibility_js__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_field_group_compatibility_js__WEBPACK_IMPORTED_MODULE_6__);
  2341. }();
  2342. /******/ })()
  2343. ;
  2344. //# sourceMappingURL=acf-field-group.js.map