acf.js 100 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403
  1. /******/ (function() { // webpackBootstrap
  2. /******/ var __webpack_modules__ = ({
  3. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_acf-hooks.js":
  4. /*!********************************************************************!*\
  5. !*** ./src/advanced-custom-fields-pro/assets/src/js/_acf-hooks.js ***!
  6. \********************************************************************/
  7. /***/ (function() {
  8. (function (window, undefined) {
  9. 'use strict';
  10. /**
  11. * Handles managing all events for whatever you plug it into. Priorities for hooks are based on lowest to highest in
  12. * that, lowest priority hooks are fired first.
  13. */
  14. var EventManager = function () {
  15. /**
  16. * Maintain a reference to the object scope so our public methods never get confusing.
  17. */
  18. var MethodsAvailable = {
  19. removeFilter: removeFilter,
  20. applyFilters: applyFilters,
  21. addFilter: addFilter,
  22. removeAction: removeAction,
  23. doAction: doAction,
  24. addAction: addAction,
  25. storage: getStorage
  26. };
  27. /**
  28. * Contains the hooks that get registered with this EventManager. The array for storage utilizes a "flat"
  29. * object literal such that looking up the hook utilizes the native object literal hash.
  30. */
  31. var STORAGE = {
  32. actions: {},
  33. filters: {}
  34. };
  35. function getStorage() {
  36. return STORAGE;
  37. }
  38. /**
  39. * Adds an action to the event manager.
  40. *
  41. * @param action Must contain namespace.identifier
  42. * @param callback Must be a valid callback function before this action is added
  43. * @param [priority=10] Used to control when the function is executed in relation to other callbacks bound to the same hook
  44. * @param [context] Supply a value to be used for this
  45. */
  46. function addAction(action, callback, priority, context) {
  47. if (typeof action === 'string' && typeof callback === 'function') {
  48. priority = parseInt(priority || 10, 10);
  49. _addHook('actions', action, callback, priority, context);
  50. }
  51. return MethodsAvailable;
  52. }
  53. /**
  54. * Performs an action if it exists. You can pass as many arguments as you want to this function; the only rule is
  55. * that the first argument must always be the action.
  56. */
  57. function doAction( /* action, arg1, arg2, ... */
  58. ) {
  59. var args = Array.prototype.slice.call(arguments);
  60. var action = args.shift();
  61. if (typeof action === 'string') {
  62. _runHook('actions', action, args);
  63. }
  64. return MethodsAvailable;
  65. }
  66. /**
  67. * Removes the specified action if it contains a namespace.identifier & exists.
  68. *
  69. * @param action The action to remove
  70. * @param [callback] Callback function to remove
  71. */
  72. function removeAction(action, callback) {
  73. if (typeof action === 'string') {
  74. _removeHook('actions', action, callback);
  75. }
  76. return MethodsAvailable;
  77. }
  78. /**
  79. * Adds a filter to the event manager.
  80. *
  81. * @param filter Must contain namespace.identifier
  82. * @param callback Must be a valid callback function before this action is added
  83. * @param [priority=10] Used to control when the function is executed in relation to other callbacks bound to the same hook
  84. * @param [context] Supply a value to be used for this
  85. */
  86. function addFilter(filter, callback, priority, context) {
  87. if (typeof filter === 'string' && typeof callback === 'function') {
  88. priority = parseInt(priority || 10, 10);
  89. _addHook('filters', filter, callback, priority, context);
  90. }
  91. return MethodsAvailable;
  92. }
  93. /**
  94. * Performs a filter if it exists. You should only ever pass 1 argument to be filtered. The only rule is that
  95. * the first argument must always be the filter.
  96. */
  97. function applyFilters( /* filter, filtered arg, arg2, ... */
  98. ) {
  99. var args = Array.prototype.slice.call(arguments);
  100. var filter = args.shift();
  101. if (typeof filter === 'string') {
  102. return _runHook('filters', filter, args);
  103. }
  104. return MethodsAvailable;
  105. }
  106. /**
  107. * Removes the specified filter if it contains a namespace.identifier & exists.
  108. *
  109. * @param filter The action to remove
  110. * @param [callback] Callback function to remove
  111. */
  112. function removeFilter(filter, callback) {
  113. if (typeof filter === 'string') {
  114. _removeHook('filters', filter, callback);
  115. }
  116. return MethodsAvailable;
  117. }
  118. /**
  119. * Removes the specified hook by resetting the value of it.
  120. *
  121. * @param type Type of hook, either 'actions' or 'filters'
  122. * @param hook The hook (namespace.identifier) to remove
  123. * @private
  124. */
  125. function _removeHook(type, hook, callback, context) {
  126. if (!STORAGE[type][hook]) {
  127. return;
  128. }
  129. if (!callback) {
  130. STORAGE[type][hook] = [];
  131. } else {
  132. var handlers = STORAGE[type][hook];
  133. var i;
  134. if (!context) {
  135. for (i = handlers.length; i--;) {
  136. if (handlers[i].callback === callback) {
  137. handlers.splice(i, 1);
  138. }
  139. }
  140. } else {
  141. for (i = handlers.length; i--;) {
  142. var handler = handlers[i];
  143. if (handler.callback === callback && handler.context === context) {
  144. handlers.splice(i, 1);
  145. }
  146. }
  147. }
  148. }
  149. }
  150. /**
  151. * Adds the hook to the appropriate storage container
  152. *
  153. * @param type 'actions' or 'filters'
  154. * @param hook The hook (namespace.identifier) to add to our event manager
  155. * @param callback The function that will be called when the hook is executed.
  156. * @param priority The priority of this hook. Must be an integer.
  157. * @param [context] A value to be used for this
  158. * @private
  159. */
  160. function _addHook(type, hook, callback, priority, context) {
  161. var hookObject = {
  162. callback: callback,
  163. priority: priority,
  164. context: context
  165. };
  166. // Utilize 'prop itself' : http://jsperf.com/hasownproperty-vs-in-vs-undefined/19
  167. var hooks = STORAGE[type][hook];
  168. if (hooks) {
  169. hooks.push(hookObject);
  170. hooks = _hookInsertSort(hooks);
  171. } else {
  172. hooks = [hookObject];
  173. }
  174. STORAGE[type][hook] = hooks;
  175. }
  176. /**
  177. * Use an insert sort for keeping our hooks organized based on priority. This function is ridiculously faster
  178. * than bubble sort, etc: http://jsperf.com/javascript-sort
  179. *
  180. * @param hooks The custom array containing all of the appropriate hooks to perform an insert sort on.
  181. * @private
  182. */
  183. function _hookInsertSort(hooks) {
  184. var tmpHook, j, prevHook;
  185. for (var i = 1, len = hooks.length; i < len; i++) {
  186. tmpHook = hooks[i];
  187. j = i;
  188. while ((prevHook = hooks[j - 1]) && prevHook.priority > tmpHook.priority) {
  189. hooks[j] = hooks[j - 1];
  190. --j;
  191. }
  192. hooks[j] = tmpHook;
  193. }
  194. return hooks;
  195. }
  196. /**
  197. * Runs the specified hook. If it is an action, the value is not modified but if it is a filter, it is.
  198. *
  199. * @param type 'actions' or 'filters'
  200. * @param hook The hook ( namespace.identifier ) to be ran.
  201. * @param args Arguments to pass to the action/filter. If it's a filter, args is actually a single parameter.
  202. * @private
  203. */
  204. function _runHook(type, hook, args) {
  205. var handlers = STORAGE[type][hook];
  206. if (!handlers) {
  207. return type === 'filters' ? args[0] : false;
  208. }
  209. var i = 0,
  210. len = handlers.length;
  211. if (type === 'filters') {
  212. for (; i < len; i++) {
  213. args[0] = handlers[i].callback.apply(handlers[i].context, args);
  214. }
  215. } else {
  216. for (; i < len; i++) {
  217. handlers[i].callback.apply(handlers[i].context, args);
  218. }
  219. }
  220. return type === 'filters' ? args[0] : true;
  221. }
  222. // return all of the publicly available methods
  223. return MethodsAvailable;
  224. };
  225. // instantiate
  226. acf.hooks = new EventManager();
  227. })(window);
  228. /***/ }),
  229. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_acf-modal.js":
  230. /*!********************************************************************!*\
  231. !*** ./src/advanced-custom-fields-pro/assets/src/js/_acf-modal.js ***!
  232. \********************************************************************/
  233. /***/ (function() {
  234. (function ($, undefined) {
  235. acf.models.Modal = acf.Model.extend({
  236. data: {
  237. title: '',
  238. content: '',
  239. toolbar: ''
  240. },
  241. events: {
  242. 'click .acf-modal-close': 'onClickClose'
  243. },
  244. setup: function (props) {
  245. $.extend(this.data, props);
  246. this.$el = $();
  247. this.render();
  248. },
  249. initialize: function () {
  250. this.open();
  251. },
  252. render: function () {
  253. // Extract vars.
  254. var title = this.get('title');
  255. var content = this.get('content');
  256. var toolbar = this.get('toolbar');
  257. // Create element.
  258. var $el = $(['<div>', '<div class="acf-modal">', '<div class="acf-modal-title">', '<h2>' + title + '</h2>', '<button class="acf-modal-close" type="button"><span class="dashicons dashicons-no"></span></button>', '</div>', '<div class="acf-modal-content">' + content + '</div>', '<div class="acf-modal-toolbar">' + toolbar + '</div>', '</div>', '<div class="acf-modal-backdrop acf-modal-close"></div>', '</div>'].join(''));
  259. // Update DOM.
  260. if (this.$el) {
  261. this.$el.replaceWith($el);
  262. }
  263. this.$el = $el;
  264. // Trigger action.
  265. acf.doAction('append', $el);
  266. },
  267. update: function (props) {
  268. this.data = acf.parseArgs(props, this.data);
  269. this.render();
  270. },
  271. title: function (title) {
  272. this.$('.acf-modal-title h2').html(title);
  273. },
  274. content: function (content) {
  275. this.$('.acf-modal-content').html(content);
  276. },
  277. toolbar: function (toolbar) {
  278. this.$('.acf-modal-toolbar').html(toolbar);
  279. },
  280. open: function () {
  281. $('body').append(this.$el);
  282. },
  283. close: function () {
  284. this.remove();
  285. },
  286. onClickClose: function (e, $el) {
  287. e.preventDefault();
  288. this.close();
  289. }
  290. });
  291. /**
  292. * Returns a new modal.
  293. *
  294. * @date 21/4/20
  295. * @since 5.9.0
  296. *
  297. * @param object props The modal props.
  298. * @return object
  299. */
  300. acf.newModal = function (props) {
  301. return new acf.models.Modal(props);
  302. };
  303. })(jQuery);
  304. /***/ }),
  305. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_acf-model.js":
  306. /*!********************************************************************!*\
  307. !*** ./src/advanced-custom-fields-pro/assets/src/js/_acf-model.js ***!
  308. \********************************************************************/
  309. /***/ (function() {
  310. (function ($, undefined) {
  311. // Cached regex to split keys for `addEvent`.
  312. var delegateEventSplitter = /^(\S+)\s*(.*)$/;
  313. /**
  314. * extend
  315. *
  316. * Helper function to correctly set up the prototype chain for subclasses
  317. * Heavily inspired by backbone.js
  318. *
  319. * @date 14/12/17
  320. * @since 5.6.5
  321. *
  322. * @param object protoProps New properties for this object.
  323. * @return function.
  324. */
  325. var extend = function (protoProps) {
  326. // vars
  327. var Parent = this;
  328. var Child;
  329. // The constructor function for the new subclass is either defined by you
  330. // (the "constructor" property in your `extend` definition), or defaulted
  331. // by us to simply call the parent constructor.
  332. if (protoProps && protoProps.hasOwnProperty('constructor')) {
  333. Child = protoProps.constructor;
  334. } else {
  335. Child = function () {
  336. return Parent.apply(this, arguments);
  337. };
  338. }
  339. // Add static properties to the constructor function, if supplied.
  340. $.extend(Child, Parent);
  341. // Set the prototype chain to inherit from `parent`, without calling
  342. // `parent`'s constructor function and add the prototype properties.
  343. Child.prototype = Object.create(Parent.prototype);
  344. $.extend(Child.prototype, protoProps);
  345. Child.prototype.constructor = Child;
  346. // Set a convenience property in case the parent's prototype is needed later.
  347. //Child.prototype.__parent__ = Parent.prototype;
  348. // return
  349. return Child;
  350. };
  351. /**
  352. * Model
  353. *
  354. * Base class for all inheritence
  355. *
  356. * @date 14/12/17
  357. * @since 5.6.5
  358. *
  359. * @param object props
  360. * @return function.
  361. */
  362. var Model = acf.Model = function () {
  363. // generate uique client id
  364. this.cid = acf.uniqueId('acf');
  365. // set vars to avoid modifying prototype
  366. this.data = $.extend(true, {}, this.data);
  367. // pass props to setup function
  368. this.setup.apply(this, arguments);
  369. // store on element (allow this.setup to create this.$el)
  370. if (this.$el && !this.$el.data('acf')) {
  371. this.$el.data('acf', this);
  372. }
  373. // initialize
  374. var initialize = function () {
  375. this.initialize();
  376. this.addEvents();
  377. this.addActions();
  378. this.addFilters();
  379. };
  380. // initialize on action
  381. if (this.wait && !acf.didAction(this.wait)) {
  382. this.addAction(this.wait, initialize);
  383. // initialize now
  384. } else {
  385. initialize.apply(this);
  386. }
  387. };
  388. // Attach all inheritable methods to the Model prototype.
  389. $.extend(Model.prototype, {
  390. // Unique model id
  391. id: '',
  392. // Unique client id
  393. cid: '',
  394. // jQuery element
  395. $el: null,
  396. // Data specific to this instance
  397. data: {},
  398. // toggle used when changing data
  399. busy: false,
  400. changed: false,
  401. // Setup events hooks
  402. events: {},
  403. actions: {},
  404. filters: {},
  405. // class used to avoid nested event triggers
  406. eventScope: '',
  407. // action to wait until initialize
  408. wait: false,
  409. // action priority default
  410. priority: 10,
  411. /**
  412. * get
  413. *
  414. * Gets a specific data value
  415. *
  416. * @date 14/12/17
  417. * @since 5.6.5
  418. *
  419. * @param string name
  420. * @return mixed
  421. */
  422. get: function (name) {
  423. return this.data[name];
  424. },
  425. /**
  426. * has
  427. *
  428. * Returns `true` if the data exists and is not null
  429. *
  430. * @date 14/12/17
  431. * @since 5.6.5
  432. *
  433. * @param string name
  434. * @return boolean
  435. */
  436. has: function (name) {
  437. return this.get(name) != null;
  438. },
  439. /**
  440. * set
  441. *
  442. * Sets a specific data value
  443. *
  444. * @date 14/12/17
  445. * @since 5.6.5
  446. *
  447. * @param string name
  448. * @param mixed value
  449. * @return this
  450. */
  451. set: function (name, value, silent) {
  452. // bail if unchanged
  453. var prevValue = this.get(name);
  454. if (prevValue == value) {
  455. return this;
  456. }
  457. // set data
  458. this.data[name] = value;
  459. // trigger events
  460. if (!silent) {
  461. this.changed = true;
  462. this.trigger('changed:' + name, [value, prevValue]);
  463. this.trigger('changed', [name, value, prevValue]);
  464. }
  465. // return
  466. return this;
  467. },
  468. /**
  469. * inherit
  470. *
  471. * Inherits the data from a jQuery element
  472. *
  473. * @date 14/12/17
  474. * @since 5.6.5
  475. *
  476. * @param jQuery $el
  477. * @return this
  478. */
  479. inherit: function (data) {
  480. // allow jQuery
  481. if (data instanceof jQuery) {
  482. data = data.data();
  483. }
  484. // extend
  485. $.extend(this.data, data);
  486. // return
  487. return this;
  488. },
  489. /**
  490. * prop
  491. *
  492. * mimics the jQuery prop function
  493. *
  494. * @date 4/6/18
  495. * @since 5.6.9
  496. *
  497. * @param type $var Description. Default.
  498. * @return type Description.
  499. */
  500. prop: function () {
  501. return this.$el.prop.apply(this.$el, arguments);
  502. },
  503. /**
  504. * setup
  505. *
  506. * Run during constructor function
  507. *
  508. * @date 14/12/17
  509. * @since 5.6.5
  510. *
  511. * @param n/a
  512. * @return n/a
  513. */
  514. setup: function (props) {
  515. $.extend(this, props);
  516. },
  517. /**
  518. * initialize
  519. *
  520. * Also run during constructor function
  521. *
  522. * @date 14/12/17
  523. * @since 5.6.5
  524. *
  525. * @param n/a
  526. * @return n/a
  527. */
  528. initialize: function () {},
  529. /**
  530. * addElements
  531. *
  532. * Adds multiple jQuery elements to this object
  533. *
  534. * @date 9/5/18
  535. * @since 5.6.9
  536. *
  537. * @param type $var Description. Default.
  538. * @return type Description.
  539. */
  540. addElements: function (elements) {
  541. elements = elements || this.elements || null;
  542. if (!elements || !Object.keys(elements).length) return false;
  543. for (var i in elements) {
  544. this.addElement(i, elements[i]);
  545. }
  546. },
  547. /**
  548. * addElement
  549. *
  550. * description
  551. *
  552. * @date 9/5/18
  553. * @since 5.6.9
  554. *
  555. * @param type $var Description. Default.
  556. * @return type Description.
  557. */
  558. addElement: function (name, selector) {
  559. this['$' + name] = this.$(selector);
  560. },
  561. /**
  562. * addEvents
  563. *
  564. * Adds multiple event handlers
  565. *
  566. * @date 14/12/17
  567. * @since 5.6.5
  568. *
  569. * @param object events {event1 : callback, event2 : callback, etc }
  570. * @return n/a
  571. */
  572. addEvents: function (events) {
  573. events = events || this.events || null;
  574. if (!events) return false;
  575. for (var key in events) {
  576. var match = key.match(delegateEventSplitter);
  577. this.on(match[1], match[2], events[key]);
  578. }
  579. },
  580. /**
  581. * removeEvents
  582. *
  583. * Removes multiple event handlers
  584. *
  585. * @date 14/12/17
  586. * @since 5.6.5
  587. *
  588. * @param object events {event1 : callback, event2 : callback, etc }
  589. * @return n/a
  590. */
  591. removeEvents: function (events) {
  592. events = events || this.events || null;
  593. if (!events) return false;
  594. for (var key in events) {
  595. var match = key.match(delegateEventSplitter);
  596. this.off(match[1], match[2], events[key]);
  597. }
  598. },
  599. /**
  600. * getEventTarget
  601. *
  602. * Returns a jQuery element to trigger an event on.
  603. *
  604. * @date 5/6/18
  605. * @since 5.6.9
  606. *
  607. * @param jQuery $el The default jQuery element. Optional.
  608. * @param string event The event name. Optional.
  609. * @return jQuery
  610. */
  611. getEventTarget: function ($el, event) {
  612. return $el || this.$el || $(document);
  613. },
  614. /**
  615. * validateEvent
  616. *
  617. * Returns true if the event target's closest $el is the same as this.$el
  618. * Requires both this.el and this.$el to be defined
  619. *
  620. * @date 5/6/18
  621. * @since 5.6.9
  622. *
  623. * @param type $var Description. Default.
  624. * @return type Description.
  625. */
  626. validateEvent: function (e) {
  627. if (this.eventScope) {
  628. return $(e.target).closest(this.eventScope).is(this.$el);
  629. } else {
  630. return true;
  631. }
  632. },
  633. /**
  634. * proxyEvent
  635. *
  636. * Returns a new event callback function scoped to this model
  637. *
  638. * @date 29/3/18
  639. * @since 5.6.9
  640. *
  641. * @param function callback
  642. * @return function
  643. */
  644. proxyEvent: function (callback) {
  645. return this.proxy(function (e) {
  646. // validate
  647. if (!this.validateEvent(e)) {
  648. return;
  649. }
  650. // construct args
  651. var args = acf.arrayArgs(arguments);
  652. var extraArgs = args.slice(1);
  653. var eventArgs = [e, $(e.currentTarget)].concat(extraArgs);
  654. // callback
  655. callback.apply(this, eventArgs);
  656. });
  657. },
  658. /**
  659. * on
  660. *
  661. * Adds an event handler similar to jQuery
  662. * Uses the instance 'cid' to namespace event
  663. *
  664. * @date 14/12/17
  665. * @since 5.6.5
  666. *
  667. * @param string name
  668. * @param string callback
  669. * @return n/a
  670. */
  671. on: function (a1, a2, a3, a4) {
  672. // vars
  673. var $el, event, selector, callback, args;
  674. // find args
  675. if (a1 instanceof jQuery) {
  676. // 1. args( $el, event, selector, callback )
  677. if (a4) {
  678. $el = a1;
  679. event = a2;
  680. selector = a3;
  681. callback = a4;
  682. // 2. args( $el, event, callback )
  683. } else {
  684. $el = a1;
  685. event = a2;
  686. callback = a3;
  687. }
  688. } else {
  689. // 3. args( event, selector, callback )
  690. if (a3) {
  691. event = a1;
  692. selector = a2;
  693. callback = a3;
  694. // 4. args( event, callback )
  695. } else {
  696. event = a1;
  697. callback = a2;
  698. }
  699. }
  700. // element
  701. $el = this.getEventTarget($el);
  702. // modify callback
  703. if (typeof callback === 'string') {
  704. callback = this.proxyEvent(this[callback]);
  705. }
  706. // modify event
  707. event = event + '.' + this.cid;
  708. // args
  709. if (selector) {
  710. args = [event, selector, callback];
  711. } else {
  712. args = [event, callback];
  713. }
  714. // on()
  715. $el.on.apply($el, args);
  716. },
  717. /**
  718. * off
  719. *
  720. * Removes an event handler similar to jQuery
  721. *
  722. * @date 14/12/17
  723. * @since 5.6.5
  724. *
  725. * @param string name
  726. * @param string callback
  727. * @return n/a
  728. */
  729. off: function (a1, a2, a3) {
  730. // vars
  731. var $el, event, selector, args;
  732. // find args
  733. if (a1 instanceof jQuery) {
  734. // 1. args( $el, event, selector )
  735. if (a3) {
  736. $el = a1;
  737. event = a2;
  738. selector = a3;
  739. // 2. args( $el, event )
  740. } else {
  741. $el = a1;
  742. event = a2;
  743. }
  744. } else {
  745. // 3. args( event, selector )
  746. if (a2) {
  747. event = a1;
  748. selector = a2;
  749. // 4. args( event )
  750. } else {
  751. event = a1;
  752. }
  753. }
  754. // element
  755. $el = this.getEventTarget($el);
  756. // modify event
  757. event = event + '.' + this.cid;
  758. // args
  759. if (selector) {
  760. args = [event, selector];
  761. } else {
  762. args = [event];
  763. }
  764. // off()
  765. $el.off.apply($el, args);
  766. },
  767. /**
  768. * trigger
  769. *
  770. * Triggers an event similar to jQuery
  771. *
  772. * @date 14/12/17
  773. * @since 5.6.5
  774. *
  775. * @param string name
  776. * @param string callback
  777. * @return n/a
  778. */
  779. trigger: function (name, args, bubbles) {
  780. var $el = this.getEventTarget();
  781. if (bubbles) {
  782. $el.trigger.apply($el, arguments);
  783. } else {
  784. $el.triggerHandler.apply($el, arguments);
  785. }
  786. return this;
  787. },
  788. /**
  789. * addActions
  790. *
  791. * Adds multiple action handlers
  792. *
  793. * @date 14/12/17
  794. * @since 5.6.5
  795. *
  796. * @param object actions {action1 : callback, action2 : callback, etc }
  797. * @return n/a
  798. */
  799. addActions: function (actions) {
  800. actions = actions || this.actions || null;
  801. if (!actions) return false;
  802. for (var i in actions) {
  803. this.addAction(i, actions[i]);
  804. }
  805. },
  806. /**
  807. * removeActions
  808. *
  809. * Removes multiple action handlers
  810. *
  811. * @date 14/12/17
  812. * @since 5.6.5
  813. *
  814. * @param object actions {action1 : callback, action2 : callback, etc }
  815. * @return n/a
  816. */
  817. removeActions: function (actions) {
  818. actions = actions || this.actions || null;
  819. if (!actions) return false;
  820. for (var i in actions) {
  821. this.removeAction(i, actions[i]);
  822. }
  823. },
  824. /**
  825. * addAction
  826. *
  827. * Adds an action using the wp.hooks library
  828. *
  829. * @date 14/12/17
  830. * @since 5.6.5
  831. *
  832. * @param string name
  833. * @param string callback
  834. * @return n/a
  835. */
  836. addAction: function (name, callback, priority) {
  837. //console.log('addAction', name, priority);
  838. // defaults
  839. priority = priority || this.priority;
  840. // modify callback
  841. if (typeof callback === 'string') {
  842. callback = this[callback];
  843. }
  844. // add
  845. acf.addAction(name, callback, priority, this);
  846. },
  847. /**
  848. * removeAction
  849. *
  850. * Remove an action using the wp.hooks library
  851. *
  852. * @date 14/12/17
  853. * @since 5.6.5
  854. *
  855. * @param string name
  856. * @param string callback
  857. * @return n/a
  858. */
  859. removeAction: function (name, callback) {
  860. acf.removeAction(name, this[callback]);
  861. },
  862. /**
  863. * addFilters
  864. *
  865. * Adds multiple filter handlers
  866. *
  867. * @date 14/12/17
  868. * @since 5.6.5
  869. *
  870. * @param object filters {filter1 : callback, filter2 : callback, etc }
  871. * @return n/a
  872. */
  873. addFilters: function (filters) {
  874. filters = filters || this.filters || null;
  875. if (!filters) return false;
  876. for (var i in filters) {
  877. this.addFilter(i, filters[i]);
  878. }
  879. },
  880. /**
  881. * addFilter
  882. *
  883. * Adds a filter using the wp.hooks library
  884. *
  885. * @date 14/12/17
  886. * @since 5.6.5
  887. *
  888. * @param string name
  889. * @param string callback
  890. * @return n/a
  891. */
  892. addFilter: function (name, callback, priority) {
  893. // defaults
  894. priority = priority || this.priority;
  895. // modify callback
  896. if (typeof callback === 'string') {
  897. callback = this[callback];
  898. }
  899. // add
  900. acf.addFilter(name, callback, priority, this);
  901. },
  902. /**
  903. * removeFilters
  904. *
  905. * Removes multiple filter handlers
  906. *
  907. * @date 14/12/17
  908. * @since 5.6.5
  909. *
  910. * @param object filters {filter1 : callback, filter2 : callback, etc }
  911. * @return n/a
  912. */
  913. removeFilters: function (filters) {
  914. filters = filters || this.filters || null;
  915. if (!filters) return false;
  916. for (var i in filters) {
  917. this.removeFilter(i, filters[i]);
  918. }
  919. },
  920. /**
  921. * removeFilter
  922. *
  923. * Remove a filter using the wp.hooks library
  924. *
  925. * @date 14/12/17
  926. * @since 5.6.5
  927. *
  928. * @param string name
  929. * @param string callback
  930. * @return n/a
  931. */
  932. removeFilter: function (name, callback) {
  933. acf.removeFilter(name, this[callback]);
  934. },
  935. /**
  936. * $
  937. *
  938. * description
  939. *
  940. * @date 16/12/17
  941. * @since 5.6.5
  942. *
  943. * @param type $var Description. Default.
  944. * @return type Description.
  945. */
  946. $: function (selector) {
  947. return this.$el.find(selector);
  948. },
  949. /**
  950. * remove
  951. *
  952. * Removes the element and listenters
  953. *
  954. * @date 19/12/17
  955. * @since 5.6.5
  956. *
  957. * @param type $var Description. Default.
  958. * @return type Description.
  959. */
  960. remove: function () {
  961. this.removeEvents();
  962. this.removeActions();
  963. this.removeFilters();
  964. this.$el.remove();
  965. },
  966. /**
  967. * setTimeout
  968. *
  969. * description
  970. *
  971. * @date 16/1/18
  972. * @since 5.6.5
  973. *
  974. * @param type $var Description. Default.
  975. * @return type Description.
  976. */
  977. setTimeout: function (callback, milliseconds) {
  978. return setTimeout(this.proxy(callback), milliseconds);
  979. },
  980. /**
  981. * time
  982. *
  983. * used for debugging
  984. *
  985. * @date 7/3/18
  986. * @since 5.6.9
  987. *
  988. * @param type $var Description. Default.
  989. * @return type Description.
  990. */
  991. time: function () {
  992. console.time(this.id || this.cid);
  993. },
  994. /**
  995. * timeEnd
  996. *
  997. * used for debugging
  998. *
  999. * @date 7/3/18
  1000. * @since 5.6.9
  1001. *
  1002. * @param type $var Description. Default.
  1003. * @return type Description.
  1004. */
  1005. timeEnd: function () {
  1006. console.timeEnd(this.id || this.cid);
  1007. },
  1008. /**
  1009. * show
  1010. *
  1011. * description
  1012. *
  1013. * @date 15/3/18
  1014. * @since 5.6.9
  1015. *
  1016. * @param type $var Description. Default.
  1017. * @return type Description.
  1018. */
  1019. show: function () {
  1020. acf.show(this.$el);
  1021. },
  1022. /**
  1023. * hide
  1024. *
  1025. * description
  1026. *
  1027. * @date 15/3/18
  1028. * @since 5.6.9
  1029. *
  1030. * @param type $var Description. Default.
  1031. * @return type Description.
  1032. */
  1033. hide: function () {
  1034. acf.hide(this.$el);
  1035. },
  1036. /**
  1037. * proxy
  1038. *
  1039. * Returns a new function scoped to this model
  1040. *
  1041. * @date 29/3/18
  1042. * @since 5.6.9
  1043. *
  1044. * @param function callback
  1045. * @return function
  1046. */
  1047. proxy: function (callback) {
  1048. return $.proxy(callback, this);
  1049. }
  1050. });
  1051. // Set up inheritance for the model
  1052. Model.extend = extend;
  1053. // Global model storage
  1054. acf.models = {};
  1055. /**
  1056. * acf.getInstance
  1057. *
  1058. * This function will get an instance from an element
  1059. *
  1060. * @date 5/3/18
  1061. * @since 5.6.9
  1062. *
  1063. * @param type $var Description. Default.
  1064. * @return type Description.
  1065. */
  1066. acf.getInstance = function ($el) {
  1067. return $el.data('acf');
  1068. };
  1069. /**
  1070. * acf.getInstances
  1071. *
  1072. * This function will get an array of instances from multiple elements
  1073. *
  1074. * @date 5/3/18
  1075. * @since 5.6.9
  1076. *
  1077. * @param type $var Description. Default.
  1078. * @return type Description.
  1079. */
  1080. acf.getInstances = function ($el) {
  1081. var instances = [];
  1082. $el.each(function () {
  1083. instances.push(acf.getInstance($(this)));
  1084. });
  1085. return instances;
  1086. };
  1087. })(jQuery);
  1088. /***/ }),
  1089. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_acf-notice.js":
  1090. /*!*********************************************************************!*\
  1091. !*** ./src/advanced-custom-fields-pro/assets/src/js/_acf-notice.js ***!
  1092. \*********************************************************************/
  1093. /***/ (function() {
  1094. (function ($, undefined) {
  1095. var Notice = acf.Model.extend({
  1096. data: {
  1097. text: '',
  1098. type: '',
  1099. timeout: 0,
  1100. dismiss: true,
  1101. target: false,
  1102. close: function () {}
  1103. },
  1104. events: {
  1105. 'click .acf-notice-dismiss': 'onClickClose'
  1106. },
  1107. tmpl: function () {
  1108. return '<div class="acf-notice"></div>';
  1109. },
  1110. setup: function (props) {
  1111. $.extend(this.data, props);
  1112. this.$el = $(this.tmpl());
  1113. },
  1114. initialize: function () {
  1115. // render
  1116. this.render();
  1117. // show
  1118. this.show();
  1119. },
  1120. render: function () {
  1121. // class
  1122. this.type(this.get('type'));
  1123. // text
  1124. this.html('<p>' + this.get('text') + '</p>');
  1125. // close
  1126. if (this.get('dismiss')) {
  1127. this.$el.append('<a href="#" class="acf-notice-dismiss acf-icon -cancel small"></a>');
  1128. this.$el.addClass('-dismiss');
  1129. }
  1130. // timeout
  1131. var timeout = this.get('timeout');
  1132. if (timeout) {
  1133. this.away(timeout);
  1134. }
  1135. },
  1136. update: function (props) {
  1137. // update
  1138. $.extend(this.data, props);
  1139. // re-initialize
  1140. this.initialize();
  1141. // refresh events
  1142. this.removeEvents();
  1143. this.addEvents();
  1144. },
  1145. show: function () {
  1146. var $target = this.get('target');
  1147. if ($target) {
  1148. $target.prepend(this.$el);
  1149. }
  1150. },
  1151. hide: function () {
  1152. this.$el.remove();
  1153. },
  1154. away: function (timeout) {
  1155. this.setTimeout(function () {
  1156. acf.remove(this.$el);
  1157. }, timeout);
  1158. },
  1159. type: function (type) {
  1160. // remove prev type
  1161. var prevType = this.get('type');
  1162. if (prevType) {
  1163. this.$el.removeClass('-' + prevType);
  1164. }
  1165. // add new type
  1166. this.$el.addClass('-' + type);
  1167. // backwards compatibility
  1168. if (type == 'error') {
  1169. this.$el.addClass('acf-error-message');
  1170. }
  1171. },
  1172. html: function (html) {
  1173. this.$el.html(acf.escHtml(html));
  1174. },
  1175. text: function (text) {
  1176. this.$('p').html(acf.escHtml(text));
  1177. },
  1178. onClickClose: function (e, $el) {
  1179. e.preventDefault();
  1180. this.get('close').apply(this, arguments);
  1181. this.remove();
  1182. }
  1183. });
  1184. acf.newNotice = function (props) {
  1185. // ensure object
  1186. if (typeof props !== 'object') {
  1187. props = {
  1188. text: props
  1189. };
  1190. }
  1191. // instantiate
  1192. return new Notice(props);
  1193. };
  1194. var noticeManager = new acf.Model({
  1195. wait: 'prepare',
  1196. priority: 1,
  1197. initialize: function () {
  1198. // vars
  1199. var $notice = $('.acf-admin-notice');
  1200. // move to avoid WP flicker
  1201. if ($notice.length) {
  1202. $('h1:first').after($notice);
  1203. }
  1204. }
  1205. });
  1206. })(jQuery);
  1207. /***/ }),
  1208. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_acf-panel.js":
  1209. /*!********************************************************************!*\
  1210. !*** ./src/advanced-custom-fields-pro/assets/src/js/_acf-panel.js ***!
  1211. \********************************************************************/
  1212. /***/ (function() {
  1213. (function ($, undefined) {
  1214. var panel = new acf.Model({
  1215. events: {
  1216. 'click .acf-panel-title': 'onClick'
  1217. },
  1218. onClick: function (e, $el) {
  1219. e.preventDefault();
  1220. this.toggle($el.parent());
  1221. },
  1222. isOpen: function ($el) {
  1223. return $el.hasClass('-open');
  1224. },
  1225. toggle: function ($el) {
  1226. this.isOpen($el) ? this.close($el) : this.open($el);
  1227. },
  1228. open: function ($el) {
  1229. $el.addClass('-open');
  1230. $el.find('.acf-panel-title i').attr('class', 'dashicons dashicons-arrow-down');
  1231. },
  1232. close: function ($el) {
  1233. $el.removeClass('-open');
  1234. $el.find('.acf-panel-title i').attr('class', 'dashicons dashicons-arrow-right');
  1235. }
  1236. });
  1237. })(jQuery);
  1238. /***/ }),
  1239. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_acf-popup.js":
  1240. /*!********************************************************************!*\
  1241. !*** ./src/advanced-custom-fields-pro/assets/src/js/_acf-popup.js ***!
  1242. \********************************************************************/
  1243. /***/ (function() {
  1244. (function ($, undefined) {
  1245. acf.models.Popup = acf.Model.extend({
  1246. data: {
  1247. title: '',
  1248. content: '',
  1249. width: 0,
  1250. height: 0,
  1251. loading: false,
  1252. openedBy: null
  1253. },
  1254. events: {
  1255. 'click [data-event="close"]': 'onClickClose',
  1256. 'click .acf-close-popup': 'onClickClose',
  1257. 'keydown': 'onPressEscapeClose'
  1258. },
  1259. setup: function (props) {
  1260. $.extend(this.data, props);
  1261. this.$el = $(this.tmpl());
  1262. },
  1263. initialize: function () {
  1264. this.render();
  1265. this.open();
  1266. this.focus();
  1267. this.lockFocusToPopup(true);
  1268. },
  1269. tmpl: function () {
  1270. return ['<div id="acf-popup" role="dialog" tabindex="-1">', '<div class="acf-popup-box acf-box">', '<div class="title"><h3></h3><a href="#" class="acf-icon -cancel grey" data-event="close" aria-label="' + acf.__('Close modal') + '"></a></div>', '<div class="inner"></div>', '<div class="loading"><i class="acf-loading"></i></div>', '</div>', '<div class="bg" data-event="close"></div>', '</div>'].join('');
  1271. },
  1272. render: function () {
  1273. // Extract Vars.
  1274. var title = this.get('title');
  1275. var content = this.get('content');
  1276. var loading = this.get('loading');
  1277. var width = this.get('width');
  1278. var height = this.get('height');
  1279. // Update.
  1280. this.title(title);
  1281. this.content(content);
  1282. if (width) {
  1283. this.$('.acf-popup-box').css('width', width);
  1284. }
  1285. if (height) {
  1286. this.$('.acf-popup-box').css('min-height', height);
  1287. }
  1288. this.loading(loading);
  1289. // Trigger action.
  1290. acf.doAction('append', this.$el);
  1291. },
  1292. /**
  1293. * Places focus within the popup.
  1294. */
  1295. focus: function () {
  1296. this.$el.find('.acf-icon').first().trigger('focus');
  1297. },
  1298. /**
  1299. * Locks focus within the popup.
  1300. *
  1301. * @param {boolean} locked True to lock focus, false to unlock.
  1302. */
  1303. lockFocusToPopup: function (locked) {
  1304. let inertElement = $('#wpwrap');
  1305. if (!inertElement.length) {
  1306. return;
  1307. }
  1308. inertElement[0].inert = locked;
  1309. inertElement.attr('aria-hidden', locked);
  1310. },
  1311. update: function (props) {
  1312. this.data = acf.parseArgs(props, this.data);
  1313. this.render();
  1314. },
  1315. title: function (title) {
  1316. this.$('.title:first h3').html(title);
  1317. },
  1318. content: function (content) {
  1319. this.$('.inner:first').html(content);
  1320. },
  1321. loading: function (show) {
  1322. var $loading = this.$('.loading:first');
  1323. show ? $loading.show() : $loading.hide();
  1324. },
  1325. open: function () {
  1326. $('body').append(this.$el);
  1327. },
  1328. close: function () {
  1329. this.lockFocusToPopup(false);
  1330. this.returnFocusToOrigin();
  1331. this.remove();
  1332. },
  1333. onClickClose: function (e, $el) {
  1334. e.preventDefault();
  1335. this.close();
  1336. },
  1337. /**
  1338. * Closes the popup when the escape key is pressed.
  1339. *
  1340. * @param {KeyboardEvent} e
  1341. */
  1342. onPressEscapeClose: function (e) {
  1343. if (e.key === 'Escape') {
  1344. this.close();
  1345. }
  1346. },
  1347. /**
  1348. * Returns focus to the element that opened the popup
  1349. * if it still exists in the DOM.
  1350. */
  1351. returnFocusToOrigin: function () {
  1352. if (this.data.openedBy instanceof $ && this.data.openedBy.closest('body').length > 0) {
  1353. this.data.openedBy.trigger('focus');
  1354. }
  1355. }
  1356. });
  1357. /**
  1358. * newPopup
  1359. *
  1360. * Creates a new Popup with the supplied props
  1361. *
  1362. * @date 17/12/17
  1363. * @since 5.6.5
  1364. *
  1365. * @param object props
  1366. * @return object
  1367. */
  1368. acf.newPopup = function (props) {
  1369. return new acf.models.Popup(props);
  1370. };
  1371. })(jQuery);
  1372. /***/ }),
  1373. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_acf-tooltip.js":
  1374. /*!**********************************************************************!*\
  1375. !*** ./src/advanced-custom-fields-pro/assets/src/js/_acf-tooltip.js ***!
  1376. \**********************************************************************/
  1377. /***/ (function() {
  1378. (function ($, undefined) {
  1379. acf.newTooltip = function (props) {
  1380. // ensure object
  1381. if (typeof props !== 'object') {
  1382. props = {
  1383. text: props
  1384. };
  1385. }
  1386. // confirmRemove
  1387. if (props.confirmRemove !== undefined) {
  1388. props.textConfirm = acf.__('Remove');
  1389. props.textCancel = acf.__('Cancel');
  1390. return new TooltipConfirm(props);
  1391. // confirm
  1392. } else if (props.confirm !== undefined) {
  1393. return new TooltipConfirm(props);
  1394. // default
  1395. } else {
  1396. return new Tooltip(props);
  1397. }
  1398. };
  1399. var Tooltip = acf.Model.extend({
  1400. data: {
  1401. text: '',
  1402. timeout: 0,
  1403. target: null
  1404. },
  1405. tmpl: function () {
  1406. return '<div class="acf-tooltip"></div>';
  1407. },
  1408. setup: function (props) {
  1409. $.extend(this.data, props);
  1410. this.$el = $(this.tmpl());
  1411. },
  1412. initialize: function () {
  1413. // render
  1414. this.render();
  1415. // append
  1416. this.show();
  1417. // position
  1418. this.position();
  1419. // timeout
  1420. var timeout = this.get('timeout');
  1421. if (timeout) {
  1422. setTimeout($.proxy(this.fade, this), timeout);
  1423. }
  1424. },
  1425. update: function (props) {
  1426. $.extend(this.data, props);
  1427. this.initialize();
  1428. },
  1429. render: function () {
  1430. this.html(this.get('text'));
  1431. },
  1432. show: function () {
  1433. $('body').append(this.$el);
  1434. },
  1435. hide: function () {
  1436. this.$el.remove();
  1437. },
  1438. fade: function () {
  1439. // add class
  1440. this.$el.addClass('acf-fade-up');
  1441. // remove
  1442. this.setTimeout(function () {
  1443. this.remove();
  1444. }, 250);
  1445. },
  1446. html: function (html) {
  1447. this.$el.html(html);
  1448. },
  1449. position: function () {
  1450. // vars
  1451. var $tooltip = this.$el;
  1452. var $target = this.get('target');
  1453. if (!$target) return;
  1454. // Reset position.
  1455. $tooltip.removeClass('right left bottom top').css({
  1456. top: 0,
  1457. left: 0
  1458. });
  1459. // Declare tollerance to edge of screen.
  1460. var tolerance = 10;
  1461. // Find target position.
  1462. var targetWidth = $target.outerWidth();
  1463. var targetHeight = $target.outerHeight();
  1464. var targetTop = $target.offset().top;
  1465. var targetLeft = $target.offset().left;
  1466. // Find tooltip position.
  1467. var tooltipWidth = $tooltip.outerWidth();
  1468. var tooltipHeight = $tooltip.outerHeight();
  1469. var tooltipTop = $tooltip.offset().top; // Should be 0, but WP media grid causes this to be 32 (toolbar padding).
  1470. // Assume default top alignment.
  1471. var top = targetTop - tooltipHeight - tooltipTop;
  1472. var left = targetLeft + targetWidth / 2 - tooltipWidth / 2;
  1473. // Check if too far left.
  1474. if (left < tolerance) {
  1475. $tooltip.addClass('right');
  1476. left = targetLeft + targetWidth;
  1477. top = targetTop + targetHeight / 2 - tooltipHeight / 2 - tooltipTop;
  1478. // Check if too far right.
  1479. } else if (left + tooltipWidth + tolerance > $(window).width()) {
  1480. $tooltip.addClass('left');
  1481. left = targetLeft - tooltipWidth;
  1482. top = targetTop + targetHeight / 2 - tooltipHeight / 2 - tooltipTop;
  1483. // Check if too far up.
  1484. } else if (top - $(window).scrollTop() < tolerance) {
  1485. $tooltip.addClass('bottom');
  1486. top = targetTop + targetHeight - tooltipTop;
  1487. // No colision with edges.
  1488. } else {
  1489. $tooltip.addClass('top');
  1490. }
  1491. // update css
  1492. $tooltip.css({
  1493. top: top,
  1494. left: left
  1495. });
  1496. }
  1497. });
  1498. var TooltipConfirm = Tooltip.extend({
  1499. data: {
  1500. text: '',
  1501. textConfirm: '',
  1502. textCancel: '',
  1503. target: null,
  1504. targetConfirm: true,
  1505. confirm: function () {},
  1506. cancel: function () {},
  1507. context: false
  1508. },
  1509. events: {
  1510. 'click [data-event="cancel"]': 'onCancel',
  1511. 'click [data-event="confirm"]': 'onConfirm'
  1512. },
  1513. addEvents: function () {
  1514. // add events
  1515. acf.Model.prototype.addEvents.apply(this);
  1516. // vars
  1517. var $document = $(document);
  1518. var $target = this.get('target');
  1519. // add global 'cancel' click event
  1520. // - use timeout to avoid the current 'click' event triggering the onCancel function
  1521. this.setTimeout(function () {
  1522. this.on($document, 'click', 'onCancel');
  1523. });
  1524. // add target 'confirm' click event
  1525. // - allow setting to control this feature
  1526. if (this.get('targetConfirm')) {
  1527. this.on($target, 'click', 'onConfirm');
  1528. }
  1529. },
  1530. removeEvents: function () {
  1531. // remove events
  1532. acf.Model.prototype.removeEvents.apply(this);
  1533. // vars
  1534. var $document = $(document);
  1535. var $target = this.get('target');
  1536. // remove custom events
  1537. this.off($document, 'click');
  1538. this.off($target, 'click');
  1539. },
  1540. render: function () {
  1541. // defaults
  1542. var text = this.get('text') || acf.__('Are you sure?');
  1543. var textConfirm = this.get('textConfirm') || acf.__('Yes');
  1544. var textCancel = this.get('textCancel') || acf.__('No');
  1545. // html
  1546. var html = [text, '<a href="#" data-event="confirm">' + textConfirm + '</a>', '<a href="#" data-event="cancel">' + textCancel + '</a>'].join(' ');
  1547. // html
  1548. this.html(html);
  1549. // class
  1550. this.$el.addClass('-confirm');
  1551. },
  1552. onCancel: function (e, $el) {
  1553. // prevent default
  1554. e.preventDefault();
  1555. e.stopImmediatePropagation();
  1556. // callback
  1557. var callback = this.get('cancel');
  1558. var context = this.get('context') || this;
  1559. callback.apply(context, arguments);
  1560. //remove
  1561. this.remove();
  1562. },
  1563. onConfirm: function (e, $el) {
  1564. // Prevent event from propagating completely to allow "targetConfirm" to be clicked.
  1565. e.preventDefault();
  1566. e.stopImmediatePropagation();
  1567. // callback
  1568. var callback = this.get('confirm');
  1569. var context = this.get('context') || this;
  1570. callback.apply(context, arguments);
  1571. //remove
  1572. this.remove();
  1573. }
  1574. });
  1575. // storage
  1576. acf.models.Tooltip = Tooltip;
  1577. acf.models.TooltipConfirm = TooltipConfirm;
  1578. /**
  1579. * tooltipManager
  1580. *
  1581. * description
  1582. *
  1583. * @date 17/4/18
  1584. * @since 5.6.9
  1585. *
  1586. * @param type $var Description. Default.
  1587. * @return type Description.
  1588. */
  1589. var tooltipHoverHelper = new acf.Model({
  1590. tooltip: false,
  1591. events: {
  1592. 'mouseenter .acf-js-tooltip': 'showTitle',
  1593. 'mouseup .acf-js-tooltip': 'hideTitle',
  1594. 'mouseleave .acf-js-tooltip': 'hideTitle',
  1595. 'focus .acf-js-tooltip': 'showTitle',
  1596. 'blur .acf-js-tooltip': 'hideTitle',
  1597. 'keyup .acf-js-tooltip': 'onKeyUp'
  1598. },
  1599. showTitle: function (e, $el) {
  1600. // vars
  1601. var title = $el.attr('title');
  1602. // bail early if no title
  1603. if (!title) {
  1604. return;
  1605. }
  1606. // clear title to avoid default browser tooltip
  1607. $el.attr('title', '');
  1608. // create
  1609. if (!this.tooltip) {
  1610. this.tooltip = acf.newTooltip({
  1611. text: title,
  1612. target: $el
  1613. });
  1614. // update
  1615. } else {
  1616. this.tooltip.update({
  1617. text: title,
  1618. target: $el
  1619. });
  1620. }
  1621. },
  1622. hideTitle: function (e, $el) {
  1623. // hide tooltip
  1624. this.tooltip.hide();
  1625. // restore title
  1626. $el.attr('title', this.tooltip.get('text'));
  1627. },
  1628. onKeyUp: function (e, $el) {
  1629. if ('Escape' === e.key) {
  1630. this.hideTitle(e, $el);
  1631. }
  1632. }
  1633. });
  1634. })(jQuery);
  1635. /***/ }),
  1636. /***/ "./src/advanced-custom-fields-pro/assets/src/js/_acf.js":
  1637. /*!**************************************************************!*\
  1638. !*** ./src/advanced-custom-fields-pro/assets/src/js/_acf.js ***!
  1639. \**************************************************************/
  1640. /***/ (function() {
  1641. (function ($, undefined) {
  1642. /**
  1643. * acf
  1644. *
  1645. * description
  1646. *
  1647. * @date 14/12/17
  1648. * @since 5.6.5
  1649. *
  1650. * @param type $var Description. Default.
  1651. * @return type Description.
  1652. */
  1653. // The global acf object
  1654. var acf = {};
  1655. // Set as a browser global
  1656. window.acf = acf;
  1657. /** @var object Data sent from PHP */
  1658. acf.data = {};
  1659. /**
  1660. * get
  1661. *
  1662. * Gets a specific data value
  1663. *
  1664. * @date 14/12/17
  1665. * @since 5.6.5
  1666. *
  1667. * @param string name
  1668. * @return mixed
  1669. */
  1670. acf.get = function (name) {
  1671. return this.data[name] || null;
  1672. };
  1673. /**
  1674. * has
  1675. *
  1676. * Returns `true` if the data exists and is not null
  1677. *
  1678. * @date 14/12/17
  1679. * @since 5.6.5
  1680. *
  1681. * @param string name
  1682. * @return boolean
  1683. */
  1684. acf.has = function (name) {
  1685. return this.get(name) !== null;
  1686. };
  1687. /**
  1688. * set
  1689. *
  1690. * Sets a specific data value
  1691. *
  1692. * @date 14/12/17
  1693. * @since 5.6.5
  1694. *
  1695. * @param string name
  1696. * @param mixed value
  1697. * @return this
  1698. */
  1699. acf.set = function (name, value) {
  1700. this.data[name] = value;
  1701. return this;
  1702. };
  1703. /**
  1704. * uniqueId
  1705. *
  1706. * Returns a unique ID
  1707. *
  1708. * @date 9/11/17
  1709. * @since 5.6.3
  1710. *
  1711. * @param string prefix Optional prefix.
  1712. * @return string
  1713. */
  1714. var idCounter = 0;
  1715. acf.uniqueId = function (prefix) {
  1716. var id = ++idCounter + '';
  1717. return prefix ? prefix + id : id;
  1718. };
  1719. /**
  1720. * acf.uniqueArray
  1721. *
  1722. * Returns a new array with only unique values
  1723. * Credit: https://stackoverflow.com/questions/1960473/get-all-unique-values-in-an-array-remove-duplicates
  1724. *
  1725. * @date 23/3/18
  1726. * @since 5.6.9
  1727. *
  1728. * @param type $var Description. Default.
  1729. * @return type Description.
  1730. */
  1731. acf.uniqueArray = function (array) {
  1732. function onlyUnique(value, index, self) {
  1733. return self.indexOf(value) === index;
  1734. }
  1735. return array.filter(onlyUnique);
  1736. };
  1737. /**
  1738. * uniqid
  1739. *
  1740. * Returns a unique ID (PHP version)
  1741. *
  1742. * @date 9/11/17
  1743. * @since 5.6.3
  1744. * @source http://locutus.io/php/misc/uniqid/
  1745. *
  1746. * @param string prefix Optional prefix.
  1747. * @return string
  1748. */
  1749. var uniqidSeed = '';
  1750. acf.uniqid = function (prefix, moreEntropy) {
  1751. // discuss at: http://locutus.io/php/uniqid/
  1752. // original by: Kevin van Zonneveld (http://kvz.io)
  1753. // revised by: Kankrelune (http://www.webfaktory.info/)
  1754. // note 1: Uses an internal counter (in locutus global) to avoid collision
  1755. // example 1: var $id = uniqid()
  1756. // example 1: var $result = $id.length === 13
  1757. // returns 1: true
  1758. // example 2: var $id = uniqid('foo')
  1759. // example 2: var $result = $id.length === (13 + 'foo'.length)
  1760. // returns 2: true
  1761. // example 3: var $id = uniqid('bar', true)
  1762. // example 3: var $result = $id.length === (23 + 'bar'.length)
  1763. // returns 3: true
  1764. if (typeof prefix === 'undefined') {
  1765. prefix = '';
  1766. }
  1767. var retId;
  1768. var formatSeed = function (seed, reqWidth) {
  1769. seed = parseInt(seed, 10).toString(16); // to hex str
  1770. if (reqWidth < seed.length) {
  1771. // so long we split
  1772. return seed.slice(seed.length - reqWidth);
  1773. }
  1774. if (reqWidth > seed.length) {
  1775. // so short we pad
  1776. return Array(1 + (reqWidth - seed.length)).join('0') + seed;
  1777. }
  1778. return seed;
  1779. };
  1780. if (!uniqidSeed) {
  1781. // init seed with big random int
  1782. uniqidSeed = Math.floor(Math.random() * 0x75bcd15);
  1783. }
  1784. uniqidSeed++;
  1785. retId = prefix; // start with prefix, add current milliseconds hex string
  1786. retId += formatSeed(parseInt(new Date().getTime() / 1000, 10), 8);
  1787. retId += formatSeed(uniqidSeed, 5); // add seed hex string
  1788. if (moreEntropy) {
  1789. // for more entropy we add a float lower to 10
  1790. retId += (Math.random() * 10).toFixed(8).toString();
  1791. }
  1792. return retId;
  1793. };
  1794. /**
  1795. * strReplace
  1796. *
  1797. * Performs a string replace
  1798. *
  1799. * @date 14/12/17
  1800. * @since 5.6.5
  1801. *
  1802. * @param string search
  1803. * @param string replace
  1804. * @param string subject
  1805. * @return string
  1806. */
  1807. acf.strReplace = function (search, replace, subject) {
  1808. return subject.split(search).join(replace);
  1809. };
  1810. /**
  1811. * strCamelCase
  1812. *
  1813. * Converts a string into camelCase
  1814. * Thanks to https://stackoverflow.com/questions/2970525/converting-any-string-into-camel-case
  1815. *
  1816. * @date 14/12/17
  1817. * @since 5.6.5
  1818. *
  1819. * @param string str
  1820. * @return string
  1821. */
  1822. acf.strCamelCase = function (str) {
  1823. var matches = str.match(/([a-zA-Z0-9]+)/g);
  1824. return matches ? matches.map(function (s, i) {
  1825. var c = s.charAt(0);
  1826. return (i === 0 ? c.toLowerCase() : c.toUpperCase()) + s.slice(1);
  1827. }).join('') : '';
  1828. };
  1829. /**
  1830. * strPascalCase
  1831. *
  1832. * Converts a string into PascalCase
  1833. * Thanks to https://stackoverflow.com/questions/1026069/how-do-i-make-the-first-letter-of-a-string-uppercase-in-javascript
  1834. *
  1835. * @date 14/12/17
  1836. * @since 5.6.5
  1837. *
  1838. * @param string str
  1839. * @return string
  1840. */
  1841. acf.strPascalCase = function (str) {
  1842. var camel = acf.strCamelCase(str);
  1843. return camel.charAt(0).toUpperCase() + camel.slice(1);
  1844. };
  1845. /**
  1846. * acf.strSlugify
  1847. *
  1848. * Converts a string into a HTML class friendly slug
  1849. *
  1850. * @date 21/3/18
  1851. * @since 5.6.9
  1852. *
  1853. * @param string str
  1854. * @return string
  1855. */
  1856. acf.strSlugify = function (str) {
  1857. return acf.strReplace('_', '-', str.toLowerCase());
  1858. };
  1859. acf.strSanitize = function (str) {
  1860. // chars (https://jsperf.com/replace-foreign-characters)
  1861. var map = {
  1862. À: 'A',
  1863. Á: 'A',
  1864. Â: 'A',
  1865. Ã: 'A',
  1866. Ä: 'A',
  1867. Å: 'A',
  1868. Æ: 'AE',
  1869. Ç: 'C',
  1870. È: 'E',
  1871. É: 'E',
  1872. Ê: 'E',
  1873. Ë: 'E',
  1874. Ì: 'I',
  1875. Í: 'I',
  1876. Î: 'I',
  1877. Ï: 'I',
  1878. Ð: 'D',
  1879. Ñ: 'N',
  1880. Ò: 'O',
  1881. Ó: 'O',
  1882. Ô: 'O',
  1883. Õ: 'O',
  1884. Ö: 'O',
  1885. Ø: 'O',
  1886. Ù: 'U',
  1887. Ú: 'U',
  1888. Û: 'U',
  1889. Ü: 'U',
  1890. Ý: 'Y',
  1891. ß: 's',
  1892. à: 'a',
  1893. á: 'a',
  1894. â: 'a',
  1895. ã: 'a',
  1896. ä: 'a',
  1897. å: 'a',
  1898. æ: 'ae',
  1899. ç: 'c',
  1900. è: 'e',
  1901. é: 'e',
  1902. ê: 'e',
  1903. ë: 'e',
  1904. ì: 'i',
  1905. í: 'i',
  1906. î: 'i',
  1907. ï: 'i',
  1908. ñ: 'n',
  1909. ò: 'o',
  1910. ó: 'o',
  1911. ô: 'o',
  1912. õ: 'o',
  1913. ö: 'o',
  1914. ø: 'o',
  1915. ù: 'u',
  1916. ú: 'u',
  1917. û: 'u',
  1918. ü: 'u',
  1919. ý: 'y',
  1920. ÿ: 'y',
  1921. Ā: 'A',
  1922. ā: 'a',
  1923. Ă: 'A',
  1924. ă: 'a',
  1925. Ą: 'A',
  1926. ą: 'a',
  1927. Ć: 'C',
  1928. ć: 'c',
  1929. Ĉ: 'C',
  1930. ĉ: 'c',
  1931. Ċ: 'C',
  1932. ċ: 'c',
  1933. Č: 'C',
  1934. č: 'c',
  1935. Ď: 'D',
  1936. ď: 'd',
  1937. Đ: 'D',
  1938. đ: 'd',
  1939. Ē: 'E',
  1940. ē: 'e',
  1941. Ĕ: 'E',
  1942. ĕ: 'e',
  1943. Ė: 'E',
  1944. ė: 'e',
  1945. Ę: 'E',
  1946. ę: 'e',
  1947. Ě: 'E',
  1948. ě: 'e',
  1949. Ĝ: 'G',
  1950. ĝ: 'g',
  1951. Ğ: 'G',
  1952. ğ: 'g',
  1953. Ġ: 'G',
  1954. ġ: 'g',
  1955. Ģ: 'G',
  1956. ģ: 'g',
  1957. Ĥ: 'H',
  1958. ĥ: 'h',
  1959. Ħ: 'H',
  1960. ħ: 'h',
  1961. Ĩ: 'I',
  1962. ĩ: 'i',
  1963. Ī: 'I',
  1964. ī: 'i',
  1965. Ĭ: 'I',
  1966. ĭ: 'i',
  1967. Į: 'I',
  1968. į: 'i',
  1969. İ: 'I',
  1970. ı: 'i',
  1971. IJ: 'IJ',
  1972. ij: 'ij',
  1973. Ĵ: 'J',
  1974. ĵ: 'j',
  1975. Ķ: 'K',
  1976. ķ: 'k',
  1977. Ĺ: 'L',
  1978. ĺ: 'l',
  1979. Ļ: 'L',
  1980. ļ: 'l',
  1981. Ľ: 'L',
  1982. ľ: 'l',
  1983. Ŀ: 'L',
  1984. ŀ: 'l',
  1985. Ł: 'l',
  1986. ł: 'l',
  1987. Ń: 'N',
  1988. ń: 'n',
  1989. Ņ: 'N',
  1990. ņ: 'n',
  1991. Ň: 'N',
  1992. ň: 'n',
  1993. ʼn: 'n',
  1994. Ō: 'O',
  1995. ō: 'o',
  1996. Ŏ: 'O',
  1997. ŏ: 'o',
  1998. Ő: 'O',
  1999. ő: 'o',
  2000. Œ: 'OE',
  2001. œ: 'oe',
  2002. Ŕ: 'R',
  2003. ŕ: 'r',
  2004. Ŗ: 'R',
  2005. ŗ: 'r',
  2006. Ř: 'R',
  2007. ř: 'r',
  2008. Ś: 'S',
  2009. ś: 's',
  2010. Ŝ: 'S',
  2011. ŝ: 's',
  2012. Ş: 'S',
  2013. ş: 's',
  2014. Š: 'S',
  2015. š: 's',
  2016. Ţ: 'T',
  2017. ţ: 't',
  2018. Ť: 'T',
  2019. ť: 't',
  2020. Ŧ: 'T',
  2021. ŧ: 't',
  2022. Ũ: 'U',
  2023. ũ: 'u',
  2024. Ū: 'U',
  2025. ū: 'u',
  2026. Ŭ: 'U',
  2027. ŭ: 'u',
  2028. Ů: 'U',
  2029. ů: 'u',
  2030. Ű: 'U',
  2031. ű: 'u',
  2032. Ų: 'U',
  2033. ų: 'u',
  2034. Ŵ: 'W',
  2035. ŵ: 'w',
  2036. Ŷ: 'Y',
  2037. ŷ: 'y',
  2038. Ÿ: 'Y',
  2039. Ź: 'Z',
  2040. ź: 'z',
  2041. Ż: 'Z',
  2042. ż: 'z',
  2043. Ž: 'Z',
  2044. ž: 'z',
  2045. ſ: 's',
  2046. ƒ: 'f',
  2047. Ơ: 'O',
  2048. ơ: 'o',
  2049. Ư: 'U',
  2050. ư: 'u',
  2051. Ǎ: 'A',
  2052. ǎ: 'a',
  2053. Ǐ: 'I',
  2054. ǐ: 'i',
  2055. Ǒ: 'O',
  2056. ǒ: 'o',
  2057. Ǔ: 'U',
  2058. ǔ: 'u',
  2059. Ǖ: 'U',
  2060. ǖ: 'u',
  2061. Ǘ: 'U',
  2062. ǘ: 'u',
  2063. Ǚ: 'U',
  2064. ǚ: 'u',
  2065. Ǜ: 'U',
  2066. ǜ: 'u',
  2067. Ǻ: 'A',
  2068. ǻ: 'a',
  2069. Ǽ: 'AE',
  2070. ǽ: 'ae',
  2071. Ǿ: 'O',
  2072. ǿ: 'o',
  2073. // extra
  2074. ' ': '_',
  2075. "'": '',
  2076. '?': '',
  2077. '/': '',
  2078. '\\': '',
  2079. '.': '',
  2080. ',': '',
  2081. '`': '',
  2082. '>': '',
  2083. '<': '',
  2084. '"': '',
  2085. '[': '',
  2086. ']': '',
  2087. '|': '',
  2088. '{': '',
  2089. '}': '',
  2090. '(': '',
  2091. ')': ''
  2092. };
  2093. // vars
  2094. var nonWord = /\W/g;
  2095. var mapping = function (c) {
  2096. return map[c] !== undefined ? map[c] : c;
  2097. };
  2098. // replace
  2099. str = str.replace(nonWord, mapping);
  2100. // lowercase
  2101. str = str.toLowerCase();
  2102. // return
  2103. return str;
  2104. };
  2105. /**
  2106. * acf.strMatch
  2107. *
  2108. * Returns the number of characters that match between two strings
  2109. *
  2110. * @date 1/2/18
  2111. * @since 5.6.5
  2112. *
  2113. * @param type $var Description. Default.
  2114. * @return type Description.
  2115. */
  2116. acf.strMatch = function (s1, s2) {
  2117. // vars
  2118. var val = 0;
  2119. var min = Math.min(s1.length, s2.length);
  2120. // loop
  2121. for (var i = 0; i < min; i++) {
  2122. if (s1[i] !== s2[i]) {
  2123. break;
  2124. }
  2125. val++;
  2126. }
  2127. // return
  2128. return val;
  2129. };
  2130. /**
  2131. * Escapes HTML entities from a string.
  2132. *
  2133. * @date 08/06/2020
  2134. * @since 5.9.0
  2135. *
  2136. * @param string string The input string.
  2137. * @return string
  2138. */
  2139. acf.strEscape = function (string) {
  2140. var htmlEscapes = {
  2141. '&': '&amp;',
  2142. '<': '&lt;',
  2143. '>': '&gt;',
  2144. '"': '&quot;',
  2145. "'": '&#39;'
  2146. };
  2147. return ('' + string).replace(/[&<>"']/g, function (chr) {
  2148. return htmlEscapes[chr];
  2149. });
  2150. };
  2151. // Tests.
  2152. //console.log( acf.strEscape('Test 1') );
  2153. //console.log( acf.strEscape('Test & 1') );
  2154. //console.log( acf.strEscape('Test\'s &amp; 1') );
  2155. //console.log( acf.strEscape('<script>js</script>') );
  2156. /**
  2157. * Unescapes HTML entities from a string.
  2158. *
  2159. * @date 08/06/2020
  2160. * @since 5.9.0
  2161. *
  2162. * @param string string The input string.
  2163. * @return string
  2164. */
  2165. acf.strUnescape = function (string) {
  2166. var htmlUnescapes = {
  2167. '&amp;': '&',
  2168. '&lt;': '<',
  2169. '&gt;': '>',
  2170. '&quot;': '"',
  2171. '&#39;': "'"
  2172. };
  2173. return ('' + string).replace(/&amp;|&lt;|&gt;|&quot;|&#39;/g, function (entity) {
  2174. return htmlUnescapes[entity];
  2175. });
  2176. };
  2177. // Tests.
  2178. //console.log( acf.strUnescape( acf.strEscape('Test 1') ) );
  2179. //console.log( acf.strUnescape( acf.strEscape('Test & 1') ) );
  2180. //console.log( acf.strUnescape( acf.strEscape('Test\'s &amp; 1') ) );
  2181. //console.log( acf.strUnescape( acf.strEscape('<script>js</script>') ) );
  2182. /**
  2183. * Escapes HTML entities from a string.
  2184. *
  2185. * @date 08/06/2020
  2186. * @since 5.9.0
  2187. *
  2188. * @param string string The input string.
  2189. * @return string
  2190. */
  2191. acf.escAttr = acf.strEscape;
  2192. /**
  2193. * Encodes <script> tags for safe HTML output.
  2194. *
  2195. * @date 08/06/2020
  2196. * @since 5.9.0
  2197. *
  2198. * @param string string The input string.
  2199. * @return string
  2200. */
  2201. acf.escHtml = function (string) {
  2202. return ('' + string).replace(/<script|<\/script/g, function (html) {
  2203. return acf.strEscape(html);
  2204. });
  2205. };
  2206. // Tests.
  2207. //console.log( acf.escHtml('<script>js</script>') );
  2208. //console.log( acf.escHtml( acf.strEscape('<script>js</script>') ) );
  2209. //console.log( acf.escHtml( '<script>js1</script><script>js2</script>' ) );
  2210. /**
  2211. * acf.decode
  2212. *
  2213. * description
  2214. *
  2215. * @date 13/1/18
  2216. * @since 5.6.5
  2217. *
  2218. * @param type $var Description. Default.
  2219. * @return type Description.
  2220. */
  2221. acf.decode = function (string) {
  2222. return $('<textarea/>').html(string).text();
  2223. };
  2224. /**
  2225. * parseArgs
  2226. *
  2227. * Merges together defaults and args much like the WP wp_parse_args function
  2228. *
  2229. * @date 14/12/17
  2230. * @since 5.6.5
  2231. *
  2232. * @param object args
  2233. * @param object defaults
  2234. * @return object
  2235. */
  2236. acf.parseArgs = function (args, defaults) {
  2237. if (typeof args !== 'object') args = {};
  2238. if (typeof defaults !== 'object') defaults = {};
  2239. return $.extend({}, defaults, args);
  2240. };
  2241. /**
  2242. * __
  2243. *
  2244. * Retrieve the translation of $text.
  2245. *
  2246. * @date 16/4/18
  2247. * @since 5.6.9
  2248. *
  2249. * @param string text Text to translate.
  2250. * @return string Translated text.
  2251. */
  2252. if (window.acfL10n == undefined) {
  2253. acfL10n = {};
  2254. }
  2255. acf.__ = function (text) {
  2256. return acfL10n[text] || text;
  2257. };
  2258. /**
  2259. * _x
  2260. *
  2261. * Retrieve translated string with gettext context.
  2262. *
  2263. * @date 16/4/18
  2264. * @since 5.6.9
  2265. *
  2266. * @param string text Text to translate.
  2267. * @param string context Context information for the translators.
  2268. * @return string Translated text.
  2269. */
  2270. acf._x = function (text, context) {
  2271. return acfL10n[text + '.' + context] || acfL10n[text] || text;
  2272. };
  2273. /**
  2274. * _n
  2275. *
  2276. * Retrieve the plural or single form based on the amount.
  2277. *
  2278. * @date 16/4/18
  2279. * @since 5.6.9
  2280. *
  2281. * @param string single Single text to translate.
  2282. * @param string plural Plural text to translate.
  2283. * @param int number The number to compare against.
  2284. * @return string Translated text.
  2285. */
  2286. acf._n = function (single, plural, number) {
  2287. if (number == 1) {
  2288. return acf.__(single);
  2289. } else {
  2290. return acf.__(plural);
  2291. }
  2292. };
  2293. acf.isArray = function (a) {
  2294. return Array.isArray(a);
  2295. };
  2296. acf.isObject = function (a) {
  2297. return typeof a === 'object';
  2298. };
  2299. /**
  2300. * serialize
  2301. *
  2302. * description
  2303. *
  2304. * @date 24/12/17
  2305. * @since 5.6.5
  2306. *
  2307. * @param type $var Description. Default.
  2308. * @return type Description.
  2309. */
  2310. var buildObject = function (obj, name, value) {
  2311. // replace [] with placeholder
  2312. name = name.replace('[]', '[%%index%%]');
  2313. // vars
  2314. var keys = name.match(/([^\[\]])+/g);
  2315. if (!keys) return;
  2316. var length = keys.length;
  2317. var ref = obj;
  2318. // loop
  2319. for (var i = 0; i < length; i++) {
  2320. // vars
  2321. var key = String(keys[i]);
  2322. // value
  2323. if (i == length - 1) {
  2324. // %%index%%
  2325. if (key === '%%index%%') {
  2326. ref.push(value);
  2327. // default
  2328. } else {
  2329. ref[key] = value;
  2330. }
  2331. // path
  2332. } else {
  2333. // array
  2334. if (keys[i + 1] === '%%index%%') {
  2335. if (!acf.isArray(ref[key])) {
  2336. ref[key] = [];
  2337. }
  2338. // object
  2339. } else {
  2340. if (!acf.isObject(ref[key])) {
  2341. ref[key] = {};
  2342. }
  2343. }
  2344. // crawl
  2345. ref = ref[key];
  2346. }
  2347. }
  2348. };
  2349. acf.serialize = function ($el, prefix) {
  2350. // vars
  2351. var obj = {};
  2352. var inputs = acf.serializeArray($el);
  2353. // prefix
  2354. if (prefix !== undefined) {
  2355. // filter and modify
  2356. inputs = inputs.filter(function (item) {
  2357. return item.name.indexOf(prefix) === 0;
  2358. }).map(function (item) {
  2359. item.name = item.name.slice(prefix.length);
  2360. return item;
  2361. });
  2362. }
  2363. // loop
  2364. for (var i = 0; i < inputs.length; i++) {
  2365. buildObject(obj, inputs[i].name, inputs[i].value);
  2366. }
  2367. // return
  2368. return obj;
  2369. };
  2370. /**
  2371. * acf.serializeArray
  2372. *
  2373. * Similar to $.serializeArray() but works with a parent wrapping element.
  2374. *
  2375. * @date 19/8/18
  2376. * @since 5.7.3
  2377. *
  2378. * @param jQuery $el The element or form to serialize.
  2379. * @return array
  2380. */
  2381. acf.serializeArray = function ($el) {
  2382. return $el.find('select, textarea, input').serializeArray();
  2383. };
  2384. /**
  2385. * acf.serializeForAjax
  2386. *
  2387. * Returns an object containing name => value data ready to be encoded for Ajax.
  2388. *
  2389. * @date 17/12/18
  2390. * @since 5.8.0
  2391. *
  2392. * @param jQUery $el The element or form to serialize.
  2393. * @return object
  2394. */
  2395. acf.serializeForAjax = function ($el) {
  2396. // vars
  2397. var data = {};
  2398. var index = {};
  2399. // Serialize inputs.
  2400. var inputs = acf.serializeArray($el);
  2401. // Loop over inputs and build data.
  2402. inputs.map(function (item) {
  2403. // Append to array.
  2404. if (item.name.slice(-2) === '[]') {
  2405. data[item.name] = data[item.name] || [];
  2406. data[item.name].push(item.value);
  2407. // Append
  2408. } else {
  2409. data[item.name] = item.value;
  2410. }
  2411. });
  2412. // return
  2413. return data;
  2414. };
  2415. /**
  2416. * addAction
  2417. *
  2418. * Wrapper for acf.hooks.addAction
  2419. *
  2420. * @date 14/12/17
  2421. * @since 5.6.5
  2422. *
  2423. * @param n/a
  2424. * @return this
  2425. */
  2426. /*
  2427. var prefixAction = function( action ){
  2428. return 'acf_' + action;
  2429. }
  2430. */
  2431. acf.addAction = function (action, callback, priority, context) {
  2432. //action = prefixAction(action);
  2433. acf.hooks.addAction.apply(this, arguments);
  2434. return this;
  2435. };
  2436. /**
  2437. * removeAction
  2438. *
  2439. * Wrapper for acf.hooks.removeAction
  2440. *
  2441. * @date 14/12/17
  2442. * @since 5.6.5
  2443. *
  2444. * @param n/a
  2445. * @return this
  2446. */
  2447. acf.removeAction = function (action, callback) {
  2448. //action = prefixAction(action);
  2449. acf.hooks.removeAction.apply(this, arguments);
  2450. return this;
  2451. };
  2452. /**
  2453. * doAction
  2454. *
  2455. * Wrapper for acf.hooks.doAction
  2456. *
  2457. * @date 14/12/17
  2458. * @since 5.6.5
  2459. *
  2460. * @param n/a
  2461. * @return this
  2462. */
  2463. var actionHistory = {};
  2464. //var currentAction = false;
  2465. acf.doAction = function (action) {
  2466. //action = prefixAction(action);
  2467. //currentAction = action;
  2468. actionHistory[action] = 1;
  2469. acf.hooks.doAction.apply(this, arguments);
  2470. actionHistory[action] = 0;
  2471. return this;
  2472. };
  2473. /**
  2474. * doingAction
  2475. *
  2476. * Return true if doing action
  2477. *
  2478. * @date 14/12/17
  2479. * @since 5.6.5
  2480. *
  2481. * @param n/a
  2482. * @return this
  2483. */
  2484. acf.doingAction = function (action) {
  2485. //action = prefixAction(action);
  2486. return actionHistory[action] === 1;
  2487. };
  2488. /**
  2489. * didAction
  2490. *
  2491. * Wrapper for acf.hooks.doAction
  2492. *
  2493. * @date 14/12/17
  2494. * @since 5.6.5
  2495. *
  2496. * @param n/a
  2497. * @return this
  2498. */
  2499. acf.didAction = function (action) {
  2500. //action = prefixAction(action);
  2501. return actionHistory[action] !== undefined;
  2502. };
  2503. /**
  2504. * currentAction
  2505. *
  2506. * Wrapper for acf.hooks.doAction
  2507. *
  2508. * @date 14/12/17
  2509. * @since 5.6.5
  2510. *
  2511. * @param n/a
  2512. * @return this
  2513. */
  2514. acf.currentAction = function () {
  2515. for (var k in actionHistory) {
  2516. if (actionHistory[k]) {
  2517. return k;
  2518. }
  2519. }
  2520. return false;
  2521. };
  2522. /**
  2523. * addFilter
  2524. *
  2525. * Wrapper for acf.hooks.addFilter
  2526. *
  2527. * @date 14/12/17
  2528. * @since 5.6.5
  2529. *
  2530. * @param n/a
  2531. * @return this
  2532. */
  2533. acf.addFilter = function (action) {
  2534. //action = prefixAction(action);
  2535. acf.hooks.addFilter.apply(this, arguments);
  2536. return this;
  2537. };
  2538. /**
  2539. * removeFilter
  2540. *
  2541. * Wrapper for acf.hooks.removeFilter
  2542. *
  2543. * @date 14/12/17
  2544. * @since 5.6.5
  2545. *
  2546. * @param n/a
  2547. * @return this
  2548. */
  2549. acf.removeFilter = function (action) {
  2550. //action = prefixAction(action);
  2551. acf.hooks.removeFilter.apply(this, arguments);
  2552. return this;
  2553. };
  2554. /**
  2555. * applyFilters
  2556. *
  2557. * Wrapper for acf.hooks.applyFilters
  2558. *
  2559. * @date 14/12/17
  2560. * @since 5.6.5
  2561. *
  2562. * @param n/a
  2563. * @return this
  2564. */
  2565. acf.applyFilters = function (action) {
  2566. //action = prefixAction(action);
  2567. return acf.hooks.applyFilters.apply(this, arguments);
  2568. };
  2569. /**
  2570. * getArgs
  2571. *
  2572. * description
  2573. *
  2574. * @date 15/12/17
  2575. * @since 5.6.5
  2576. *
  2577. * @param type $var Description. Default.
  2578. * @return type Description.
  2579. */
  2580. acf.arrayArgs = function (args) {
  2581. return Array.prototype.slice.call(args);
  2582. };
  2583. /**
  2584. * extendArgs
  2585. *
  2586. * description
  2587. *
  2588. * @date 15/12/17
  2589. * @since 5.6.5
  2590. *
  2591. * @param type $var Description. Default.
  2592. * @return type Description.
  2593. */
  2594. /*
  2595. acf.extendArgs = function( ){
  2596. var args = Array.prototype.slice.call( arguments );
  2597. var realArgs = args.shift();
  2598. Array.prototype.push.call(arguments, 'bar')
  2599. return Array.prototype.push.apply( args, arguments );
  2600. };
  2601. */
  2602. // Preferences
  2603. // - use try/catch to avoid JS error if cookies are disabled on front-end form
  2604. try {
  2605. var preferences = JSON.parse(localStorage.getItem('acf')) || {};
  2606. } catch (e) {
  2607. var preferences = {};
  2608. }
  2609. /**
  2610. * getPreferenceName
  2611. *
  2612. * Gets the true preference name.
  2613. * Converts "this.thing" to "thing-123" if editing post 123.
  2614. *
  2615. * @date 11/11/17
  2616. * @since 5.6.5
  2617. *
  2618. * @param string name
  2619. * @return string
  2620. */
  2621. var getPreferenceName = function (name) {
  2622. if (name.substr(0, 5) === 'this.') {
  2623. name = name.substr(5) + '-' + acf.get('post_id');
  2624. }
  2625. return name;
  2626. };
  2627. /**
  2628. * acf.getPreference
  2629. *
  2630. * Gets a preference setting or null if not set.
  2631. *
  2632. * @date 11/11/17
  2633. * @since 5.6.5
  2634. *
  2635. * @param string name
  2636. * @return mixed
  2637. */
  2638. acf.getPreference = function (name) {
  2639. name = getPreferenceName(name);
  2640. return preferences[name] || null;
  2641. };
  2642. /**
  2643. * acf.setPreference
  2644. *
  2645. * Sets a preference setting.
  2646. *
  2647. * @date 11/11/17
  2648. * @since 5.6.5
  2649. *
  2650. * @param string name
  2651. * @param mixed value
  2652. * @return n/a
  2653. */
  2654. acf.setPreference = function (name, value) {
  2655. name = getPreferenceName(name);
  2656. if (value === null) {
  2657. delete preferences[name];
  2658. } else {
  2659. preferences[name] = value;
  2660. }
  2661. localStorage.setItem('acf', JSON.stringify(preferences));
  2662. };
  2663. /**
  2664. * acf.removePreference
  2665. *
  2666. * Removes a preference setting.
  2667. *
  2668. * @date 11/11/17
  2669. * @since 5.6.5
  2670. *
  2671. * @param string name
  2672. * @return n/a
  2673. */
  2674. acf.removePreference = function (name) {
  2675. acf.setPreference(name, null);
  2676. };
  2677. /**
  2678. * remove
  2679. *
  2680. * Removes an element with fade effect
  2681. *
  2682. * @date 1/1/18
  2683. * @since 5.6.5
  2684. *
  2685. * @param type $var Description. Default.
  2686. * @return type Description.
  2687. */
  2688. acf.remove = function (props) {
  2689. // allow jQuery
  2690. if (props instanceof jQuery) {
  2691. props = {
  2692. target: props
  2693. };
  2694. }
  2695. // defaults
  2696. props = acf.parseArgs(props, {
  2697. target: false,
  2698. endHeight: 0,
  2699. complete: function () {}
  2700. });
  2701. // action
  2702. acf.doAction('remove', props.target);
  2703. // tr
  2704. if (props.target.is('tr')) {
  2705. removeTr(props);
  2706. // div
  2707. } else {
  2708. removeDiv(props);
  2709. }
  2710. };
  2711. /**
  2712. * removeDiv
  2713. *
  2714. * description
  2715. *
  2716. * @date 16/2/18
  2717. * @since 5.6.9
  2718. *
  2719. * @param type $var Description. Default.
  2720. * @return type Description.
  2721. */
  2722. var removeDiv = function (props) {
  2723. // vars
  2724. var $el = props.target;
  2725. var height = $el.height();
  2726. var width = $el.width();
  2727. var margin = $el.css('margin');
  2728. var outerHeight = $el.outerHeight(true);
  2729. var style = $el.attr('style') + ''; // needed to copy
  2730. // wrap
  2731. $el.wrap('<div class="acf-temp-remove" style="height:' + outerHeight + 'px"></div>');
  2732. var $wrap = $el.parent();
  2733. // set pos
  2734. $el.css({
  2735. height: height,
  2736. width: width,
  2737. margin: margin,
  2738. position: 'absolute'
  2739. });
  2740. // fade wrap
  2741. setTimeout(function () {
  2742. $wrap.css({
  2743. opacity: 0,
  2744. height: props.endHeight
  2745. });
  2746. }, 50);
  2747. // remove
  2748. setTimeout(function () {
  2749. $el.attr('style', style);
  2750. $wrap.remove();
  2751. props.complete();
  2752. }, 301);
  2753. };
  2754. /**
  2755. * removeTr
  2756. *
  2757. * description
  2758. *
  2759. * @date 16/2/18
  2760. * @since 5.6.9
  2761. *
  2762. * @param type $var Description. Default.
  2763. * @return type Description.
  2764. */
  2765. var removeTr = function (props) {
  2766. // vars
  2767. var $tr = props.target;
  2768. var height = $tr.height();
  2769. var children = $tr.children().length;
  2770. // create dummy td
  2771. var $td = $('<td class="acf-temp-remove" style="padding:0; height:' + height + 'px" colspan="' + children + '"></td>');
  2772. // fade away tr
  2773. $tr.addClass('acf-remove-element');
  2774. // update HTML after fade animation
  2775. setTimeout(function () {
  2776. $tr.html($td);
  2777. }, 251);
  2778. // allow .acf-temp-remove to exist before changing CSS
  2779. setTimeout(function () {
  2780. // remove class
  2781. $tr.removeClass('acf-remove-element');
  2782. // collapse
  2783. $td.css({
  2784. height: props.endHeight
  2785. });
  2786. }, 300);
  2787. // remove
  2788. setTimeout(function () {
  2789. $tr.remove();
  2790. props.complete();
  2791. }, 451);
  2792. };
  2793. /**
  2794. * duplicate
  2795. *
  2796. * description
  2797. *
  2798. * @date 3/1/18
  2799. * @since 5.6.5
  2800. *
  2801. * @param type $var Description. Default.
  2802. * @return type Description.
  2803. */
  2804. acf.duplicate = function (args) {
  2805. // allow jQuery
  2806. if (args instanceof jQuery) {
  2807. args = {
  2808. target: args
  2809. };
  2810. }
  2811. // defaults
  2812. args = acf.parseArgs(args, {
  2813. target: false,
  2814. search: '',
  2815. replace: '',
  2816. rename: true,
  2817. before: function ($el) {},
  2818. after: function ($el, $el2) {},
  2819. append: function ($el, $el2) {
  2820. $el.after($el2);
  2821. }
  2822. });
  2823. // compatibility
  2824. args.target = args.target || args.$el;
  2825. // vars
  2826. var $el = args.target;
  2827. // search
  2828. args.search = args.search || $el.attr('data-id');
  2829. args.replace = args.replace || acf.uniqid();
  2830. // before
  2831. // - allow acf to modify DOM
  2832. // - fixes bug where select field option is not selected
  2833. args.before($el);
  2834. acf.doAction('before_duplicate', $el);
  2835. // clone
  2836. var $el2 = $el.clone();
  2837. // rename
  2838. if (args.rename) {
  2839. acf.rename({
  2840. target: $el2,
  2841. search: args.search,
  2842. replace: args.replace,
  2843. replacer: typeof args.rename === 'function' ? args.rename : null
  2844. });
  2845. }
  2846. // remove classes
  2847. $el2.removeClass('acf-clone');
  2848. $el2.find('.ui-sortable').removeClass('ui-sortable');
  2849. // after
  2850. // - allow acf to modify DOM
  2851. args.after($el, $el2);
  2852. acf.doAction('after_duplicate', $el, $el2);
  2853. // append
  2854. args.append($el, $el2);
  2855. /**
  2856. * Fires after an element has been duplicated and appended to the DOM.
  2857. *
  2858. * @date 30/10/19
  2859. * @since 5.8.7
  2860. *
  2861. * @param jQuery $el The original element.
  2862. * @param jQuery $el2 The duplicated element.
  2863. */
  2864. acf.doAction('duplicate', $el, $el2);
  2865. // append
  2866. acf.doAction('append', $el2);
  2867. // return
  2868. return $el2;
  2869. };
  2870. /**
  2871. * rename
  2872. *
  2873. * description
  2874. *
  2875. * @date 7/1/18
  2876. * @since 5.6.5
  2877. *
  2878. * @param type $var Description. Default.
  2879. * @return type Description.
  2880. */
  2881. acf.rename = function (args) {
  2882. // Allow jQuery param.
  2883. if (args instanceof jQuery) {
  2884. args = {
  2885. target: args
  2886. };
  2887. }
  2888. // Apply default args.
  2889. args = acf.parseArgs(args, {
  2890. target: false,
  2891. destructive: false,
  2892. search: '',
  2893. replace: '',
  2894. replacer: null
  2895. });
  2896. // Extract args.
  2897. var $el = args.target;
  2898. // Provide backup for empty args.
  2899. if (!args.search) {
  2900. args.search = $el.attr('data-id');
  2901. }
  2902. if (!args.replace) {
  2903. args.replace = acf.uniqid('acf');
  2904. }
  2905. if (!args.replacer) {
  2906. args.replacer = function (name, value, search, replace) {
  2907. return value.replace(search, replace);
  2908. };
  2909. }
  2910. // Callback function for jQuery replacing.
  2911. var withReplacer = function (name) {
  2912. return function (i, value) {
  2913. return args.replacer(name, value, args.search, args.replace);
  2914. };
  2915. };
  2916. // Destructive Replace.
  2917. if (args.destructive) {
  2918. var html = acf.strReplace(args.search, args.replace, $el.outerHTML());
  2919. $el.replaceWith(html);
  2920. // Standard Replace.
  2921. } else {
  2922. $el.attr('data-id', args.replace);
  2923. $el.find('[id*="' + args.search + '"]').attr('id', withReplacer('id'));
  2924. $el.find('[for*="' + args.search + '"]').attr('for', withReplacer('for'));
  2925. $el.find('[name*="' + args.search + '"]').attr('name', withReplacer('name'));
  2926. }
  2927. // return
  2928. return $el;
  2929. };
  2930. /**
  2931. * acf.prepareForAjax
  2932. *
  2933. * description
  2934. *
  2935. * @date 4/1/18
  2936. * @since 5.6.5
  2937. *
  2938. * @param type $var Description. Default.
  2939. * @return type Description.
  2940. */
  2941. acf.prepareForAjax = function (data) {
  2942. // required
  2943. data.nonce = acf.get('nonce');
  2944. data.post_id = acf.get('post_id');
  2945. // language
  2946. if (acf.has('language')) {
  2947. data.lang = acf.get('language');
  2948. }
  2949. // filter for 3rd party customization
  2950. data = acf.applyFilters('prepare_for_ajax', data);
  2951. // return
  2952. return data;
  2953. };
  2954. /**
  2955. * acf.startButtonLoading
  2956. *
  2957. * description
  2958. *
  2959. * @date 5/1/18
  2960. * @since 5.6.5
  2961. *
  2962. * @param type $var Description. Default.
  2963. * @return type Description.
  2964. */
  2965. acf.startButtonLoading = function ($el) {
  2966. $el.prop('disabled', true);
  2967. $el.after(' <i class="acf-loading"></i>');
  2968. };
  2969. acf.stopButtonLoading = function ($el) {
  2970. $el.prop('disabled', false);
  2971. $el.next('.acf-loading').remove();
  2972. };
  2973. /**
  2974. * acf.showLoading
  2975. *
  2976. * description
  2977. *
  2978. * @date 12/1/18
  2979. * @since 5.6.5
  2980. *
  2981. * @param type $var Description. Default.
  2982. * @return type Description.
  2983. */
  2984. acf.showLoading = function ($el) {
  2985. $el.append('<div class="acf-loading-overlay"><i class="acf-loading"></i></div>');
  2986. };
  2987. acf.hideLoading = function ($el) {
  2988. $el.children('.acf-loading-overlay').remove();
  2989. };
  2990. /**
  2991. * acf.updateUserSetting
  2992. *
  2993. * description
  2994. *
  2995. * @date 5/1/18
  2996. * @since 5.6.5
  2997. *
  2998. * @param type $var Description. Default.
  2999. * @return type Description.
  3000. */
  3001. acf.updateUserSetting = function (name, value) {
  3002. var ajaxData = {
  3003. action: 'acf/ajax/user_setting',
  3004. name: name,
  3005. value: value
  3006. };
  3007. $.ajax({
  3008. url: acf.get('ajaxurl'),
  3009. data: acf.prepareForAjax(ajaxData),
  3010. type: 'post',
  3011. dataType: 'html'
  3012. });
  3013. };
  3014. /**
  3015. * acf.val
  3016. *
  3017. * description
  3018. *
  3019. * @date 8/1/18
  3020. * @since 5.6.5
  3021. *
  3022. * @param type $var Description. Default.
  3023. * @return type Description.
  3024. */
  3025. acf.val = function ($input, value, silent) {
  3026. // vars
  3027. var prevValue = $input.val();
  3028. // bail if no change
  3029. if (value === prevValue) {
  3030. return false;
  3031. }
  3032. // update value
  3033. $input.val(value);
  3034. // prevent select elements displaying blank value if option doesn't exist
  3035. if ($input.is('select') && $input.val() === null) {
  3036. $input.val(prevValue);
  3037. return false;
  3038. }
  3039. // update with trigger
  3040. if (silent !== true) {
  3041. $input.trigger('change');
  3042. }
  3043. // return
  3044. return true;
  3045. };
  3046. /**
  3047. * acf.show
  3048. *
  3049. * description
  3050. *
  3051. * @date 9/2/18
  3052. * @since 5.6.5
  3053. *
  3054. * @param type $var Description. Default.
  3055. * @return type Description.
  3056. */
  3057. acf.show = function ($el, lockKey) {
  3058. // unlock
  3059. if (lockKey) {
  3060. acf.unlock($el, 'hidden', lockKey);
  3061. }
  3062. // bail early if $el is still locked
  3063. if (acf.isLocked($el, 'hidden')) {
  3064. //console.log( 'still locked', getLocks( $el, 'hidden' ));
  3065. return false;
  3066. }
  3067. // $el is hidden, remove class and return true due to change in visibility
  3068. if ($el.hasClass('acf-hidden')) {
  3069. $el.removeClass('acf-hidden');
  3070. return true;
  3071. // $el is visible, return false due to no change in visibility
  3072. } else {
  3073. return false;
  3074. }
  3075. };
  3076. /**
  3077. * acf.hide
  3078. *
  3079. * description
  3080. *
  3081. * @date 9/2/18
  3082. * @since 5.6.5
  3083. *
  3084. * @param type $var Description. Default.
  3085. * @return type Description.
  3086. */
  3087. acf.hide = function ($el, lockKey) {
  3088. // lock
  3089. if (lockKey) {
  3090. acf.lock($el, 'hidden', lockKey);
  3091. }
  3092. // $el is hidden, return false due to no change in visibility
  3093. if ($el.hasClass('acf-hidden')) {
  3094. return false;
  3095. // $el is visible, add class and return true due to change in visibility
  3096. } else {
  3097. $el.addClass('acf-hidden');
  3098. return true;
  3099. }
  3100. };
  3101. /**
  3102. * acf.isHidden
  3103. *
  3104. * description
  3105. *
  3106. * @date 9/2/18
  3107. * @since 5.6.5
  3108. *
  3109. * @param type $var Description. Default.
  3110. * @return type Description.
  3111. */
  3112. acf.isHidden = function ($el) {
  3113. return $el.hasClass('acf-hidden');
  3114. };
  3115. /**
  3116. * acf.isVisible
  3117. *
  3118. * description
  3119. *
  3120. * @date 9/2/18
  3121. * @since 5.6.5
  3122. *
  3123. * @param type $var Description. Default.
  3124. * @return type Description.
  3125. */
  3126. acf.isVisible = function ($el) {
  3127. return !acf.isHidden($el);
  3128. };
  3129. /**
  3130. * enable
  3131. *
  3132. * description
  3133. *
  3134. * @date 12/3/18
  3135. * @since 5.6.9
  3136. *
  3137. * @param type $var Description. Default.
  3138. * @return type Description.
  3139. */
  3140. var enable = function ($el, lockKey) {
  3141. // check class. Allow .acf-disabled to overrule all JS
  3142. if ($el.hasClass('acf-disabled')) {
  3143. return false;
  3144. }
  3145. // unlock
  3146. if (lockKey) {
  3147. acf.unlock($el, 'disabled', lockKey);
  3148. }
  3149. // bail early if $el is still locked
  3150. if (acf.isLocked($el, 'disabled')) {
  3151. return false;
  3152. }
  3153. // $el is disabled, remove prop and return true due to change
  3154. if ($el.prop('disabled')) {
  3155. $el.prop('disabled', false);
  3156. return true;
  3157. // $el is enabled, return false due to no change
  3158. } else {
  3159. return false;
  3160. }
  3161. };
  3162. /**
  3163. * acf.enable
  3164. *
  3165. * description
  3166. *
  3167. * @date 9/2/18
  3168. * @since 5.6.5
  3169. *
  3170. * @param type $var Description. Default.
  3171. * @return type Description.
  3172. */
  3173. acf.enable = function ($el, lockKey) {
  3174. // enable single input
  3175. if ($el.attr('name')) {
  3176. return enable($el, lockKey);
  3177. }
  3178. // find and enable child inputs
  3179. // return true if any inputs have changed
  3180. var results = false;
  3181. $el.find('[name]').each(function () {
  3182. var result = enable($(this), lockKey);
  3183. if (result) {
  3184. results = true;
  3185. }
  3186. });
  3187. return results;
  3188. };
  3189. /**
  3190. * disable
  3191. *
  3192. * description
  3193. *
  3194. * @date 12/3/18
  3195. * @since 5.6.9
  3196. *
  3197. * @param type $var Description. Default.
  3198. * @return type Description.
  3199. */
  3200. var disable = function ($el, lockKey) {
  3201. // lock
  3202. if (lockKey) {
  3203. acf.lock($el, 'disabled', lockKey);
  3204. }
  3205. // $el is disabled, return false due to no change
  3206. if ($el.prop('disabled')) {
  3207. return false;
  3208. // $el is enabled, add prop and return true due to change
  3209. } else {
  3210. $el.prop('disabled', true);
  3211. return true;
  3212. }
  3213. };
  3214. /**
  3215. * acf.disable
  3216. *
  3217. * description
  3218. *
  3219. * @date 9/2/18
  3220. * @since 5.6.5
  3221. *
  3222. * @param type $var Description. Default.
  3223. * @return type Description.
  3224. */
  3225. acf.disable = function ($el, lockKey) {
  3226. // disable single input
  3227. if ($el.attr('name')) {
  3228. return disable($el, lockKey);
  3229. }
  3230. // find and enable child inputs
  3231. // return true if any inputs have changed
  3232. var results = false;
  3233. $el.find('[name]').each(function () {
  3234. var result = disable($(this), lockKey);
  3235. if (result) {
  3236. results = true;
  3237. }
  3238. });
  3239. return results;
  3240. };
  3241. /**
  3242. * acf.isset
  3243. *
  3244. * description
  3245. *
  3246. * @date 10/1/18
  3247. * @since 5.6.5
  3248. *
  3249. * @param type $var Description. Default.
  3250. * @return type Description.
  3251. */
  3252. acf.isset = function (obj /*, level1, level2, ... */) {
  3253. for (var i = 1; i < arguments.length; i++) {
  3254. if (!obj || !obj.hasOwnProperty(arguments[i])) {
  3255. return false;
  3256. }
  3257. obj = obj[arguments[i]];
  3258. }
  3259. return true;
  3260. };
  3261. /**
  3262. * acf.isget
  3263. *
  3264. * description
  3265. *
  3266. * @date 10/1/18
  3267. * @since 5.6.5
  3268. *
  3269. * @param type $var Description. Default.
  3270. * @return type Description.
  3271. */
  3272. acf.isget = function (obj /*, level1, level2, ... */) {
  3273. for (var i = 1; i < arguments.length; i++) {
  3274. if (!obj || !obj.hasOwnProperty(arguments[i])) {
  3275. return null;
  3276. }
  3277. obj = obj[arguments[i]];
  3278. }
  3279. return obj;
  3280. };
  3281. /**
  3282. * acf.getFileInputData
  3283. *
  3284. * description
  3285. *
  3286. * @date 10/1/18
  3287. * @since 5.6.5
  3288. *
  3289. * @param type $var Description. Default.
  3290. * @return type Description.
  3291. */
  3292. acf.getFileInputData = function ($input, callback) {
  3293. // vars
  3294. var value = $input.val();
  3295. // bail early if no value
  3296. if (!value) {
  3297. return false;
  3298. }
  3299. // data
  3300. var data = {
  3301. url: value
  3302. };
  3303. // modern browsers
  3304. var file = $input[0].files.length ? acf.isget($input[0].files, 0) : false;
  3305. if (file) {
  3306. // update data
  3307. data.size = file.size;
  3308. data.type = file.type;
  3309. // image
  3310. if (file.type.indexOf('image') > -1) {
  3311. // vars
  3312. var windowURL = window.URL || window.webkitURL;
  3313. var img = new Image();
  3314. img.onload = function () {
  3315. // update
  3316. data.width = this.width;
  3317. data.height = this.height;
  3318. callback(data);
  3319. };
  3320. img.src = windowURL.createObjectURL(file);
  3321. } else {
  3322. callback(data);
  3323. }
  3324. } else {
  3325. callback(data);
  3326. }
  3327. };
  3328. /**
  3329. * acf.isAjaxSuccess
  3330. *
  3331. * description
  3332. *
  3333. * @date 18/1/18
  3334. * @since 5.6.5
  3335. *
  3336. * @param type $var Description. Default.
  3337. * @return type Description.
  3338. */
  3339. acf.isAjaxSuccess = function (json) {
  3340. return json && json.success;
  3341. };
  3342. /**
  3343. * acf.getAjaxMessage
  3344. *
  3345. * description
  3346. *
  3347. * @date 18/1/18
  3348. * @since 5.6.5
  3349. *
  3350. * @param type $var Description. Default.
  3351. * @return type Description.
  3352. */
  3353. acf.getAjaxMessage = function (json) {
  3354. return acf.isget(json, 'data', 'message');
  3355. };
  3356. /**
  3357. * acf.getAjaxError
  3358. *
  3359. * description
  3360. *
  3361. * @date 18/1/18
  3362. * @since 5.6.5
  3363. *
  3364. * @param type $var Description. Default.
  3365. * @return type Description.
  3366. */
  3367. acf.getAjaxError = function (json) {
  3368. return acf.isget(json, 'data', 'error');
  3369. };
  3370. /**
  3371. * Returns the error message from an XHR object.
  3372. *
  3373. * @date 17/3/20
  3374. * @since 5.8.9
  3375. *
  3376. * @param object xhr The XHR object.
  3377. * @return (string)
  3378. */
  3379. acf.getXhrError = function (xhr) {
  3380. if (xhr.responseJSON) {
  3381. // Responses via `return new WP_Error();`
  3382. if (xhr.responseJSON.message) {
  3383. return xhr.responseJSON.message;
  3384. }
  3385. // Responses via `wp_send_json_error();`.
  3386. if (xhr.responseJSON.data && xhr.responseJSON.data.error) {
  3387. return xhr.responseJSON.data.error;
  3388. }
  3389. } else if (xhr.statusText) {
  3390. return xhr.statusText;
  3391. }
  3392. return '';
  3393. };
  3394. /**
  3395. * acf.renderSelect
  3396. *
  3397. * Renders the innter html for a select field.
  3398. *
  3399. * @date 19/2/18
  3400. * @since 5.6.9
  3401. *
  3402. * @param jQuery $select The select element.
  3403. * @param array choices An array of choices.
  3404. * @return void
  3405. */
  3406. acf.renderSelect = function ($select, choices) {
  3407. // vars
  3408. var value = $select.val();
  3409. var values = [];
  3410. // callback
  3411. var crawl = function (items) {
  3412. // vars
  3413. var itemsHtml = '';
  3414. // loop
  3415. items.map(function (item) {
  3416. // vars
  3417. var text = item.text || item.label || '';
  3418. var id = item.id || item.value || '';
  3419. // append
  3420. values.push(id);
  3421. // optgroup
  3422. if (item.children) {
  3423. itemsHtml += '<optgroup label="' + acf.escAttr(text) + '">' + crawl(item.children) + '</optgroup>';
  3424. // option
  3425. } else {
  3426. itemsHtml += '<option value="' + acf.escAttr(id) + '"' + (item.disabled ? ' disabled="disabled"' : '') + '>' + acf.strEscape(text) + '</option>';
  3427. }
  3428. });
  3429. // return
  3430. return itemsHtml;
  3431. };
  3432. // update HTML
  3433. $select.html(crawl(choices));
  3434. // update value
  3435. if (values.indexOf(value) > -1) {
  3436. $select.val(value);
  3437. }
  3438. // return selected value
  3439. return $select.val();
  3440. };
  3441. /**
  3442. * acf.lock
  3443. *
  3444. * Creates a "lock" on an element for a given type and key
  3445. *
  3446. * @date 22/2/18
  3447. * @since 5.6.9
  3448. *
  3449. * @param jQuery $el The element to lock.
  3450. * @param string type The type of lock such as "condition" or "visibility".
  3451. * @param string key The key that will be used to unlock.
  3452. * @return void
  3453. */
  3454. var getLocks = function ($el, type) {
  3455. return $el.data('acf-lock-' + type) || [];
  3456. };
  3457. var setLocks = function ($el, type, locks) {
  3458. $el.data('acf-lock-' + type, locks);
  3459. };
  3460. acf.lock = function ($el, type, key) {
  3461. var locks = getLocks($el, type);
  3462. var i = locks.indexOf(key);
  3463. if (i < 0) {
  3464. locks.push(key);
  3465. setLocks($el, type, locks);
  3466. }
  3467. };
  3468. /**
  3469. * acf.unlock
  3470. *
  3471. * Unlocks a "lock" on an element for a given type and key
  3472. *
  3473. * @date 22/2/18
  3474. * @since 5.6.9
  3475. *
  3476. * @param jQuery $el The element to lock.
  3477. * @param string type The type of lock such as "condition" or "visibility".
  3478. * @param string key The key that will be used to unlock.
  3479. * @return void
  3480. */
  3481. acf.unlock = function ($el, type, key) {
  3482. var locks = getLocks($el, type);
  3483. var i = locks.indexOf(key);
  3484. if (i > -1) {
  3485. locks.splice(i, 1);
  3486. setLocks($el, type, locks);
  3487. }
  3488. // return true if is unlocked (no locks)
  3489. return locks.length === 0;
  3490. };
  3491. /**
  3492. * acf.isLocked
  3493. *
  3494. * Returns true if a lock exists for a given type
  3495. *
  3496. * @date 22/2/18
  3497. * @since 5.6.9
  3498. *
  3499. * @param jQuery $el The element to lock.
  3500. * @param string type The type of lock such as "condition" or "visibility".
  3501. * @return void
  3502. */
  3503. acf.isLocked = function ($el, type) {
  3504. return getLocks($el, type).length > 0;
  3505. };
  3506. /**
  3507. * acf.isGutenberg
  3508. *
  3509. * Returns true if the Gutenberg editor is being used.
  3510. *
  3511. * @date 14/11/18
  3512. * @since 5.8.0
  3513. *
  3514. * @param vois
  3515. * @return bool
  3516. */
  3517. acf.isGutenberg = function () {
  3518. return !!(window.wp && wp.data && wp.data.select && wp.data.select('core/editor'));
  3519. };
  3520. /**
  3521. * acf.objectToArray
  3522. *
  3523. * Returns an array of items from the given object.
  3524. *
  3525. * @date 20/11/18
  3526. * @since 5.8.0
  3527. *
  3528. * @param object obj The object of items.
  3529. * @return array
  3530. */
  3531. acf.objectToArray = function (obj) {
  3532. return Object.keys(obj).map(function (key) {
  3533. return obj[key];
  3534. });
  3535. };
  3536. /**
  3537. * acf.debounce
  3538. *
  3539. * Returns a debounced version of the passed function which will postpone its execution until after `wait` milliseconds have elapsed since the last time it was invoked.
  3540. *
  3541. * @date 28/8/19
  3542. * @since 5.8.1
  3543. *
  3544. * @param function callback The callback function.
  3545. * @return int wait The number of milliseconds to wait.
  3546. */
  3547. acf.debounce = function (callback, wait) {
  3548. var timeout;
  3549. return function () {
  3550. var context = this;
  3551. var args = arguments;
  3552. var later = function () {
  3553. callback.apply(context, args);
  3554. };
  3555. clearTimeout(timeout);
  3556. timeout = setTimeout(later, wait);
  3557. };
  3558. };
  3559. /**
  3560. * acf.throttle
  3561. *
  3562. * Returns a throttled version of the passed function which will allow only one execution per `limit` time period.
  3563. *
  3564. * @date 28/8/19
  3565. * @since 5.8.1
  3566. *
  3567. * @param function callback The callback function.
  3568. * @return int wait The number of milliseconds to wait.
  3569. */
  3570. acf.throttle = function (callback, limit) {
  3571. var busy = false;
  3572. return function () {
  3573. if (busy) return;
  3574. busy = true;
  3575. setTimeout(function () {
  3576. busy = false;
  3577. }, limit);
  3578. callback.apply(this, arguments);
  3579. };
  3580. };
  3581. /**
  3582. * acf.isInView
  3583. *
  3584. * Returns true if the given element is in view.
  3585. *
  3586. * @date 29/8/19
  3587. * @since 5.8.1
  3588. *
  3589. * @param elem el The dom element to inspect.
  3590. * @return bool
  3591. */
  3592. acf.isInView = function (el) {
  3593. if (el instanceof jQuery) {
  3594. el = el[0];
  3595. }
  3596. var rect = el.getBoundingClientRect();
  3597. return rect.top !== rect.bottom && rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
  3598. };
  3599. /**
  3600. * acf.onceInView
  3601. *
  3602. * Watches for a dom element to become visible in the browser and then excecutes the passed callback.
  3603. *
  3604. * @date 28/8/19
  3605. * @since 5.8.1
  3606. *
  3607. * @param dom el The dom element to inspect.
  3608. * @param function callback The callback function.
  3609. */
  3610. acf.onceInView = function () {
  3611. // Define list.
  3612. var items = [];
  3613. var id = 0;
  3614. // Define check function.
  3615. var check = function () {
  3616. items.forEach(function (item) {
  3617. if (acf.isInView(item.el)) {
  3618. item.callback.apply(this);
  3619. pop(item.id);
  3620. }
  3621. });
  3622. };
  3623. // And create a debounced version.
  3624. var debounced = acf.debounce(check, 300);
  3625. // Define add function.
  3626. var push = function (el, callback) {
  3627. // Add event listener.
  3628. if (!items.length) {
  3629. $(window).on('scroll resize', debounced).on('acfrefresh orientationchange', check);
  3630. }
  3631. // Append to list.
  3632. items.push({
  3633. id: id++,
  3634. el: el,
  3635. callback: callback
  3636. });
  3637. };
  3638. // Define remove function.
  3639. var pop = function (id) {
  3640. // Remove from list.
  3641. items = items.filter(function (item) {
  3642. return item.id !== id;
  3643. });
  3644. // Clean up listener.
  3645. if (!items.length) {
  3646. $(window).off('scroll resize', debounced).off('acfrefresh orientationchange', check);
  3647. }
  3648. };
  3649. // Define returned function.
  3650. return function (el, callback) {
  3651. // Allow jQuery object.
  3652. if (el instanceof jQuery) el = el[0];
  3653. // Execute callback if already in view or add to watch list.
  3654. if (acf.isInView(el)) {
  3655. callback.apply(this);
  3656. } else {
  3657. push(el, callback);
  3658. }
  3659. };
  3660. }();
  3661. /**
  3662. * acf.once
  3663. *
  3664. * Creates a function that is restricted to invoking `func` once.
  3665. *
  3666. * @date 2/9/19
  3667. * @since 5.8.1
  3668. *
  3669. * @param function func The function to restrict.
  3670. * @return function
  3671. */
  3672. acf.once = function (func) {
  3673. var i = 0;
  3674. return function () {
  3675. if (i++ > 0) {
  3676. return func = undefined;
  3677. }
  3678. return func.apply(this, arguments);
  3679. };
  3680. };
  3681. /**
  3682. * Focuses attention to a specific element.
  3683. *
  3684. * @date 05/05/2020
  3685. * @since 5.9.0
  3686. *
  3687. * @param jQuery $el The jQuery element to focus.
  3688. * @return void
  3689. */
  3690. acf.focusAttention = function ($el) {
  3691. var wait = 1000;
  3692. // Apply class to focus attention.
  3693. $el.addClass('acf-attention -focused');
  3694. // Scroll to element if needed.
  3695. var scrollTime = 500;
  3696. if (!acf.isInView($el)) {
  3697. $('body, html').animate({
  3698. scrollTop: $el.offset().top - $(window).height() / 2
  3699. }, scrollTime);
  3700. wait += scrollTime;
  3701. }
  3702. // Remove class after $wait amount of time.
  3703. var fadeTime = 250;
  3704. setTimeout(function () {
  3705. $el.removeClass('-focused');
  3706. setTimeout(function () {
  3707. $el.removeClass('acf-attention');
  3708. }, fadeTime);
  3709. }, wait);
  3710. };
  3711. /**
  3712. * Description
  3713. *
  3714. * @date 05/05/2020
  3715. * @since 5.9.0
  3716. *
  3717. * @param type Var Description.
  3718. * @return type Description.
  3719. */
  3720. acf.onFocus = function ($el, callback) {
  3721. // Only run once per element.
  3722. // if( $el.data('acf.onFocus') ) {
  3723. // return false;
  3724. // }
  3725. // Vars.
  3726. var ignoreBlur = false;
  3727. var focus = false;
  3728. // Functions.
  3729. var onFocus = function () {
  3730. ignoreBlur = true;
  3731. setTimeout(function () {
  3732. ignoreBlur = false;
  3733. }, 1);
  3734. setFocus(true);
  3735. };
  3736. var onBlur = function () {
  3737. if (!ignoreBlur) {
  3738. setFocus(false);
  3739. }
  3740. };
  3741. var addEvents = function () {
  3742. $(document).on('click', onBlur);
  3743. //$el.on('acfBlur', onBlur);
  3744. $el.on('blur', 'input, select, textarea', onBlur);
  3745. };
  3746. var removeEvents = function () {
  3747. $(document).off('click', onBlur);
  3748. //$el.off('acfBlur', onBlur);
  3749. $el.off('blur', 'input, select, textarea', onBlur);
  3750. };
  3751. var setFocus = function (value) {
  3752. if (focus === value) {
  3753. return;
  3754. }
  3755. if (value) {
  3756. addEvents();
  3757. } else {
  3758. removeEvents();
  3759. }
  3760. focus = value;
  3761. callback(value);
  3762. };
  3763. // Add events and set data.
  3764. $el.on('click', onFocus);
  3765. //$el.on('acfFocus', onFocus);
  3766. $el.on('focus', 'input, select, textarea', onFocus);
  3767. //$el.data('acf.onFocus', true);
  3768. };
  3769. /*
  3770. * exists
  3771. *
  3772. * This function will return true if a jQuery selection exists
  3773. *
  3774. * @type function
  3775. * @date 8/09/2014
  3776. * @since 5.0.0
  3777. *
  3778. * @param n/a
  3779. * @return (boolean)
  3780. */
  3781. $.fn.exists = function () {
  3782. return $(this).length > 0;
  3783. };
  3784. /*
  3785. * outerHTML
  3786. *
  3787. * This function will return a string containing the HTML of the selected element
  3788. *
  3789. * @type function
  3790. * @date 19/11/2013
  3791. * @since 5.0.0
  3792. *
  3793. * @param $.fn
  3794. * @return (string)
  3795. */
  3796. $.fn.outerHTML = function () {
  3797. return $(this).get(0).outerHTML;
  3798. };
  3799. /*
  3800. * indexOf
  3801. *
  3802. * This function will provide compatibility for ie8
  3803. *
  3804. * @type function
  3805. * @date 5/3/17
  3806. * @since 5.5.10
  3807. *
  3808. * @param n/a
  3809. * @return n/a
  3810. */
  3811. if (!Array.prototype.indexOf) {
  3812. Array.prototype.indexOf = function (val) {
  3813. return $.inArray(val, this);
  3814. };
  3815. }
  3816. /**
  3817. * Returns true if value is a number or a numeric string.
  3818. *
  3819. * @date 30/11/20
  3820. * @since 5.9.4
  3821. * @link https://stackoverflow.com/questions/9716468/pure-javascript-a-function-like-jquerys-isnumeric/9716488#9716488
  3822. *
  3823. * @param mixed n The variable being evaluated.
  3824. * @return bool.
  3825. */
  3826. acf.isNumeric = function (n) {
  3827. return !isNaN(parseFloat(n)) && isFinite(n);
  3828. };
  3829. /**
  3830. * Triggers a "refresh" action used by various Components to redraw the DOM.
  3831. *
  3832. * @date 26/05/2020
  3833. * @since 5.9.0
  3834. *
  3835. * @param void
  3836. * @return void
  3837. */
  3838. acf.refresh = acf.debounce(function () {
  3839. $(window).trigger('acfrefresh');
  3840. acf.doAction('refresh');
  3841. }, 0);
  3842. // Set up actions from events
  3843. $(document).ready(function () {
  3844. acf.doAction('ready');
  3845. });
  3846. $(window).on('load', function () {
  3847. // Use timeout to ensure action runs after Gutenberg has modified DOM elements during "DOMContentLoaded".
  3848. setTimeout(function () {
  3849. acf.doAction('load');
  3850. });
  3851. });
  3852. $(window).on('beforeunload', function () {
  3853. acf.doAction('unload');
  3854. });
  3855. $(window).on('resize', function () {
  3856. acf.doAction('resize');
  3857. });
  3858. $(document).on('sortstart', function (event, ui) {
  3859. acf.doAction('sortstart', ui.item, ui.placeholder);
  3860. });
  3861. $(document).on('sortstop', function (event, ui) {
  3862. acf.doAction('sortstop', ui.item, ui.placeholder);
  3863. });
  3864. })(jQuery);
  3865. /***/ })
  3866. /******/ });
  3867. /************************************************************************/
  3868. /******/ // The module cache
  3869. /******/ var __webpack_module_cache__ = {};
  3870. /******/
  3871. /******/ // The require function
  3872. /******/ function __webpack_require__(moduleId) {
  3873. /******/ // Check if module is in cache
  3874. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  3875. /******/ if (cachedModule !== undefined) {
  3876. /******/ return cachedModule.exports;
  3877. /******/ }
  3878. /******/ // Create a new module (and put it into the cache)
  3879. /******/ var module = __webpack_module_cache__[moduleId] = {
  3880. /******/ // no module.id needed
  3881. /******/ // no module.loaded needed
  3882. /******/ exports: {}
  3883. /******/ };
  3884. /******/
  3885. /******/ // Execute the module function
  3886. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  3887. /******/
  3888. /******/ // Return the exports of the module
  3889. /******/ return module.exports;
  3890. /******/ }
  3891. /******/
  3892. /************************************************************************/
  3893. /******/ /* webpack/runtime/compat get default export */
  3894. /******/ !function() {
  3895. /******/ // getDefaultExport function for compatibility with non-harmony modules
  3896. /******/ __webpack_require__.n = function(module) {
  3897. /******/ var getter = module && module.__esModule ?
  3898. /******/ function() { return module['default']; } :
  3899. /******/ function() { return module; };
  3900. /******/ __webpack_require__.d(getter, { a: getter });
  3901. /******/ return getter;
  3902. /******/ };
  3903. /******/ }();
  3904. /******/
  3905. /******/ /* webpack/runtime/define property getters */
  3906. /******/ !function() {
  3907. /******/ // define getter functions for harmony exports
  3908. /******/ __webpack_require__.d = function(exports, definition) {
  3909. /******/ for(var key in definition) {
  3910. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  3911. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  3912. /******/ }
  3913. /******/ }
  3914. /******/ };
  3915. /******/ }();
  3916. /******/
  3917. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  3918. /******/ !function() {
  3919. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  3920. /******/ }();
  3921. /******/
  3922. /******/ /* webpack/runtime/make namespace object */
  3923. /******/ !function() {
  3924. /******/ // define __esModule on exports
  3925. /******/ __webpack_require__.r = function(exports) {
  3926. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  3927. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  3928. /******/ }
  3929. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  3930. /******/ };
  3931. /******/ }();
  3932. /******/
  3933. /************************************************************************/
  3934. var __webpack_exports__ = {};
  3935. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  3936. !function() {
  3937. "use strict";
  3938. /*!*************************************************************!*\
  3939. !*** ./src/advanced-custom-fields-pro/assets/src/js/acf.js ***!
  3940. \*************************************************************/
  3941. __webpack_require__.r(__webpack_exports__);
  3942. /* harmony import */ var _acf_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./_acf.js */ "./src/advanced-custom-fields-pro/assets/src/js/_acf.js");
  3943. /* harmony import */ var _acf_js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_acf_js__WEBPACK_IMPORTED_MODULE_0__);
  3944. /* harmony import */ var _acf_hooks_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./_acf-hooks.js */ "./src/advanced-custom-fields-pro/assets/src/js/_acf-hooks.js");
  3945. /* harmony import */ var _acf_hooks_js__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_acf_hooks_js__WEBPACK_IMPORTED_MODULE_1__);
  3946. /* harmony import */ var _acf_model_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./_acf-model.js */ "./src/advanced-custom-fields-pro/assets/src/js/_acf-model.js");
  3947. /* harmony import */ var _acf_model_js__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_acf_model_js__WEBPACK_IMPORTED_MODULE_2__);
  3948. /* harmony import */ var _acf_popup_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./_acf-popup.js */ "./src/advanced-custom-fields-pro/assets/src/js/_acf-popup.js");
  3949. /* harmony import */ var _acf_popup_js__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_acf_popup_js__WEBPACK_IMPORTED_MODULE_3__);
  3950. /* harmony import */ var _acf_modal_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./_acf-modal.js */ "./src/advanced-custom-fields-pro/assets/src/js/_acf-modal.js");
  3951. /* harmony import */ var _acf_modal_js__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_acf_modal_js__WEBPACK_IMPORTED_MODULE_4__);
  3952. /* harmony import */ var _acf_panel_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./_acf-panel.js */ "./src/advanced-custom-fields-pro/assets/src/js/_acf-panel.js");
  3953. /* harmony import */ var _acf_panel_js__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_acf_panel_js__WEBPACK_IMPORTED_MODULE_5__);
  3954. /* harmony import */ var _acf_notice_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./_acf-notice.js */ "./src/advanced-custom-fields-pro/assets/src/js/_acf-notice.js");
  3955. /* harmony import */ var _acf_notice_js__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_acf_notice_js__WEBPACK_IMPORTED_MODULE_6__);
  3956. /* harmony import */ var _acf_tooltip_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./_acf-tooltip.js */ "./src/advanced-custom-fields-pro/assets/src/js/_acf-tooltip.js");
  3957. /* harmony import */ var _acf_tooltip_js__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_acf_tooltip_js__WEBPACK_IMPORTED_MODULE_7__);
  3958. }();
  3959. /******/ })()
  3960. ;
  3961. //# sourceMappingURL=acf.js.map