{"version":3,"file":"loading.min.js","sources":["loading.esm.js"],"sourcesContent":["/**\n * A jQuery plugin to add/remove classes to a collection while a promise is pending or something is loading asynchronously.\n *\n * @license MIT\n * @author Dumitru Uzun (DUzun.Me)\n * @version 1.2.1\n */\nexport default function initLoading($) {\n const lck = '_loading_class_';\n const lcd = lck + 'disabled_';\n const prp = 'disabled';\n /**\n * Adds/Removes loading class on the collection.\n *\n * Usage:\n * 1)\n * $('selector').loading('loading'); // add class\n * ...\n * $('selector').loading(false); // remove added loading class\n *\n * 2)\n * const done = $('selector').loading('loading', true); // add class and get the callback\n * ...\n * done(); // remove added loading class\n *\n * 3)\n * $('selector').loading('loading', promise); // add class and remove on promise resolve or reject\n *\n * 4)\n * const done = $('selector').loading('loading', promise); // add class and remove on promise resolve or reject\n * setTimeout(done, 5e3); // timeout if promise takes too long\n *\n * @param {String|Array} classes - classes to be added to collection while loading\n * @param {Boolean|Promise} retCb - if true, return a done() function to be called when done loading\n * - if a promise, remove classes on resolve or reject\n *\n * @return {jQuery|Function} - by default (no retCb) it returns the jQuery collection (this),\n * but if retCb not falsy, done() function returned\n */\n const loading = function loading(classes, retCb = undefined) {\n const that = this;\n if (classes === false) {\n that.each(function (i, e) {\n e = $(e);\n i = e.data(lck);\n if (i) {\n e.removeClass(i).data(lck, undefined);\n }\n i = e.data(lcd);\n if (i) {\n e.attr(i, null).prop(i, false).data(lcd, undefined);\n }\n });\n }\n else {\n if (retCb) {\n that.addClass(classes).attr(prp, prp).prop(prp, true);\n let done = function (a) {\n // Prevent calling it more then once\n if (done) {\n that.removeClass(classes).attr(prp, null).prop(prp, false);\n done = undefined;\n }\n return arguments.length == 1 ? a : that; // in Promises return the result without altering it\n };\n // If retCb is a promise, call done() on resolve and reject\n if (retCb !== true && $.isFunction(retCb.then)) {\n retCb.then(done, done);\n }\n return done;\n }\n that.each(function (i, e) {\n e = $(e);\n i = e.data(lck);\n e.data(lck, (i ? i + ' ' : '') + classes);\n if (!e.prop(prp)) {\n e.attr(prp, prp).prop(prp, true).data(lcd, prp);\n }\n })\n .addClass(classes);\n }\n return that;\n };\n $.fn.loading = loading;\n return loading;\n}\n// Auto-init in browser when jQuery or Zepto is present\nif (typeof window !== 'undefined') {\n const $ = window.jQuery || window.Zepto;\n if ($) {\n initLoading($);\n }\n}\n"],"names":["initLoading","$","lck","lcd","prp","loading","classes","retCb","undefined","that","this","each","i","e","data","removeClass","attr","prop","addClass","done","a","arguments","length","isFunction","then","fn","window","jQuery","Zepto"],"mappings":";;;;;;;OAOe,SAASA,EAAYC,OAC1BC,EAAM,kBACNC,EAAMD,EAAM,YACZE,EAAM,WA6BNC,EAAU,SAAiBC,OAASC,8DAAQC,EACxCC,EAAOC,SACG,IAAZJ,EACAG,EAAKE,MAAK,SAAUC,EAAGC,IAEnBD,GADAC,EAAIZ,EAAEY,IACAC,KAAKZ,KAEPW,EAAEE,YAAYH,GAAGE,KAAKZ,OAAKM,IAE/BI,EAAIC,EAAEC,KAAKX,KAEPU,EAAEG,KAAKJ,EAAG,MAAMK,KAAKL,GAAG,GAAOE,KAAKX,OAAKK,UAIhD,IACGD,EAAO,CACPE,EAAKS,SAASZ,GAASU,KAAKZ,EAAKA,GAAKa,KAAKb,GAAK,OAC5Ce,EAAO,SAAUC,UAEbD,IACAV,EAAKM,YAAYT,GAASU,KAAKZ,EAAK,MAAMa,KAAKb,GAAK,GACpDe,OAAOX,GAEgB,GAApBa,UAAUC,OAAcF,EAAIX,UAGzB,IAAVF,GAAkBN,EAAEsB,WAAWhB,EAAMiB,OACrCjB,EAAMiB,KAAKL,EAAMA,GAEdA,EAEXV,EAAKE,MAAK,SAAUC,EAAGC,GAEnBD,GADAC,EAAIZ,EAAEY,IACAC,KAAKZ,GACXW,EAAEC,KAAKZ,GAAMU,EAAIA,EAAI,IAAM,IAAMN,GAC5BO,EAAEI,KAAKb,IACRS,EAAEG,KAAKZ,EAAKA,GAAKa,KAAKb,GAAK,GAAMU,KAAKX,EAAKC,MAG9Cc,SAASZ,UAEXG,UAEXR,EAAEwB,GAAGpB,QAAUA,EACRA,EAGX,GAAsB,oBAAXqB,OAAwB,KACzBzB,EAAIyB,OAAOC,QAAUD,OAAOE,MAC9B3B,GACAD,EAAYC"}