CoreFiles by mySites.guru
joomla-field-subform-es5.min.js1 lines, 10,604 bytes, from Joomla_4.0.0-alpha7-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha6
md5
60fd93f5c180a7ce6241ab8b6a6ed608
sha1
a0f4dca7e074bf7dc4bbbe2774a8ce27a1bb7888
sha256
f4ae73d005412110d01eda28b7391f1f197c4c593c81b9e60e8fffbbd4e48862
"use strict";function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _wrapNativeSuper(a){var b="function"==typeof Map?new Map:void 0;return _wrapNativeSuper=function(a){function c(){return _construct(a,arguments,_getPrototypeOf(this).constructor)}if(null===a||!_isNativeFunction(a))return a;if("function"!=typeof a)throw new TypeError("Super expression must either be null or a function");if("undefined"!=typeof b){if(b.has(a))return b.get(a);b.set(a,c)}return c.prototype=Object.create(a.prototype,{constructor:{value:c,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(c,a)},_wrapNativeSuper(a)}function isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(a){return!1}}function _construct(){return _construct=isNativeReflectConstruct()?Reflect.construct:function(b,c,d){var e=[null];e.push.apply(e,c);var a=Function.bind.apply(b,e),f=new a;return d&&_setPrototypeOf(f,d.prototype),f},_construct.apply(null,arguments)}function _isNativeFunction(a){return-1!==Function.toString.call(a).indexOf("[native code]")}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}(function(a){"use strict";function b(a,b){for(var c;a;){if(c=a.parentElement,c&&c[e](b))return c;a=c}return null}function c(a){return a.ctrlKey||a.metaKey||a.shiftKey}var d={SPACE:32,ESC:27,ENTER:13},e="matches";["matches","msMatchesSelector"].some(function(a){return!("function"!=typeof document.body[a])&&(e=a,!0)});var f=function(a){function f(){var a;_classCallCheck(this,f),a=_possibleConstructorReturn(this,_getPrototypeOf(f).call(this));var c=_assertThisInitialized(_assertThisInitialized(a));if(a.containerWithRows=_assertThisInitialized(_assertThisInitialized(a)),a.rowsContainer)for(var g=a.querySelectorAll(a.rowsContainer),h=0,j=g.length;h<j;h++)if(b(g[h],"joomla-field-subform")===_assertThisInitialized(_assertThisInitialized(a))){a.containerWithRows=g[h];break}return a.lastRowNum=a.getRows().length,a.template="",a.prepareTemplate(),(a.buttonAdd||a.buttonRemove)&&(a.addEventListener("click",function(a){var d=null,f=null;if(c.buttonAdd&&(d=a.target[e](c.buttonAdd)?a.target:b(a.target,c.buttonAdd)),c.buttonRemove&&(f=a.target[e](c.buttonRemove)?a.target:b(a.target,c.buttonRemove)),d&&b(d,"joomla-field-subform")===c){var g=b(d,c.repeatableElement);g=b(g,"joomla-field-subform")===c?g:null,c.addRow(g),a.preventDefault()}else if(f&&b(f,"joomla-field-subform")===c){var h=b(f,c.repeatableElement);c.removeRow(h),a.preventDefault()}}),a.addEventListener("keydown",function(a){if(a.keyCode===d.SPACE){var f=c.buttonAdd&&a.target[e](c.buttonAdd),g=c.buttonRemove&&a.target[e](c.buttonRemove);if((f||g)&&b(a.target,"joomla-field-subform")===c){var h=b(a.target,c.repeatableElement);h=b(h,"joomla-field-subform")===c?h:null,g&&h?c.removeRow(h):f&&c.addRow(h),a.preventDefault()}}})),a.buttonMove&&a.setUpDragSort(),a}return _inherits(f,a),_createClass(f,[{key:"buttonAdd",get:function a(){return this.getAttribute("button-add")}},{key:"buttonRemove",get:function a(){return this.getAttribute("button-remove")}},{key:"buttonMove",get:function a(){return this.getAttribute("button-move")}},{key:"rowsContainer",get:function a(){return this.getAttribute("rows-container")}},{key:"repeatableElement",get:function a(){return this.getAttribute("repeatable-element")}},{key:"minimum",get:function a(){return this.getAttribute("minimum")}},{key:"maximum",get:function a(){return this.getAttribute("maximum")}},{key:"name",get:function a(){return this.getAttribute("name")},set:function b(a){return this.template=this.template.replace(new RegExp(" name=\"".concat(this.name.replace(/[\[\]]/g,"\\$&")),"g")," name=\"".concat(a)),this.setAttribute("name",a)}}]),_createClass(f,[{key:"getRows",value:function f(){for(var a=this.containerWithRows.children,b=document.body.msMatchesSelector?"msMatchesSelector":"matches",c=[],d=0,e=a.length;d<e;d++)a[d][b](this.repeatableElement)&&c.push(a[d]);return c}},{key:"prepareTemplate",value:function b(){var a=[].slice.call(this.children).filter(function(a){return a.classList.contains("subform-repeatable-template-section")});if(a[0]&&(this.template=a[0].innerHTML),!this.template)throw new Error("The row template are required to subform element to work")}},{key:"addRow",value:function e(a){var b=this.getRows().length;if(b>=this.maximum)return null;var c;c="TBODY"===this.containerWithRows.nodeName||"TABLE"===this.containerWithRows.nodeName?document.createElement("tbody"):document.createElement("div"),c.innerHTML=this.template;var d=c.children[0];return a?a.parentNode.insertBefore(d,a.nextSibling):this.containerWithRows.append(d),this.buttonMove&&(d.setAttribute("draggable","false"),d.setAttribute("aria-grabbed","false"),d.setAttribute("tabindex","0")),d.setAttribute("data-new","1"),this.fixUniqueAttributes(d,b),this.dispatchEvent(new CustomEvent("subform-row-add",{detail:{row:d},bubbles:!0})),window.Joomla&&Joomla.Event.dispatch(d,"joomla:updated"),d}},{key:"removeRow",value:function c(a){var b=this.getRows().length;b<=this.minimum||(this.dispatchEvent(new CustomEvent("subform-row-remove",{detail:{row:a},bubbles:!0})),window.Joomla&&Joomla.Event.dispatch(a,"joomla:removed"),a.parentNode.removeChild(a))}},{key:"fixUniqueAttributes",value:function x(a,c){var d=this;this.lastRowNum++,c=c||0;var e=a.getAttribute("data-group"),f=a.getAttribute("data-base-name"),g=Math.max(this.lastRowNum,c),h=f+g;this.lastRowNum=g+1,a.setAttribute("data-group",h);var j=a.querySelectorAll("[name]"),k={};j=[].slice.call(j).filter(function(a){return b(a,"joomla-field-subform")===d});for(var y=0,i=j.length;y<i;y++){var m=j[y],n=m.getAttribute("name"),o=n.replace(/(\[\]$)/g,"").replace(/(\]\[)/g,"__").replace(/\[/g,"_").replace(/\]/g,""),p=n.replace("[".concat(e,"]["),"[".concat(h,"][")),q=o.replace(e,h),r=0,s=o;if("checkbox"===m.type&&n.match(/\[\]$/)){if(r=k[o]?k[o].length:0,!r){var t=b(m,"fieldset.checkboxes"),u=a.querySelector("label[for=\"".concat(o,"\"]"));t&&t.setAttribute("id",q),u&&(u.setAttribute("for",q),u.setAttribute("id","".concat(q,"-lbl")))}s+=r,q+=r}else if("radio"===m.type){if(r=k[o]?k[o].length:0,!r){var v=b(m,"fieldset.radio"),w=a.querySelector("label[for=\"".concat(o,"\"]"));v&&v.setAttribute("id",q),w&&(w.setAttribute("for",q),w.setAttribute("id","".concat(q,"-lbl")))}s+=r,q+=r}k[o]?k[o].push(!0):k[o]=[!0],m.name=p,m.id&&(m.id=q);var l=a.querySelector("label[for=\"".concat(s,"\"]"));l&&(l.setAttribute("for",q),l.setAttribute("id","".concat(q,"-lbl")))}}},{key:"setUpDragSort",value:function n(){function a(a){return!a.form&&a[e](h.buttonMove)?a:b(a,h.buttonMove)}function f(a,b){var c=!1;if(a.parentNode===b.parentNode)for(var d=a;d;d=d.previousSibling)if(d===b){c=!0;break}c?b.parentNode.insertBefore(a,b):b.parentNode.insertBefore(a,b.nextSibling)}for(var g,h=this,i=null,j=!1,k=this.getRows(),l=0,m=k.length;l<m;l++)g=k[l],g.setAttribute("draggable","false"),g.setAttribute("aria-grabbed","false"),g.setAttribute("tabindex","0");this.addEventListener("touchstart",function(c){j=!0;var d=a(c.target),e=d?b(d,h.repeatableElement):null;e&&b(e,"joomla-field-subform")===h&&(i?(e!==i&&f(i,e),i.setAttribute("draggable","false"),i.setAttribute("aria-grabbed","false"),i=null):(e.setAttribute("draggable","true"),e.setAttribute("aria-grabbed","true"),i=e),c.preventDefault())}),this.addEventListener("mousedown",function(c){if(!j){var d=a(c.target),e=d?b(d,h.repeatableElement):null;e&&b(e,"joomla-field-subform")===h&&(e.setAttribute("draggable","true"),e.setAttribute("aria-grabbed","true"),i=e)}}),this.addEventListener("mouseup",function(){i&&!j&&(i.setAttribute("draggable","false"),i.setAttribute("aria-grabbed","false"),i=null)}),this.addEventListener("keydown",function(a){if((a.keyCode===d.ESC||a.keyCode===d.SPACE||a.keyCode===d.ENTER)&&!a.target.form&&a.target[e](h.repeatableElement)){var g=a.target;if(g&&b(g,"joomla-field-subform")===h&&(a.keyCode===d.SPACE&&c(a)&&("true"===g.getAttribute("aria-grabbed")?(g.setAttribute("draggable","false"),g.setAttribute("aria-grabbed","false"),i=null):(i&&(i.setAttribute("draggable","false"),i.setAttribute("aria-grabbed","false"),i=null),g.setAttribute("draggable","true"),g.setAttribute("aria-grabbed","true"),i=g),a.preventDefault()),a.keyCode===d.ESC&&i&&(i.setAttribute("draggable","false"),i.setAttribute("aria-grabbed","false"),i=null),a.keyCode===d.ENTER&&i)){if(i.setAttribute("draggable","false"),i.setAttribute("aria-grabbed","false"),g===i)return void(i=null);f(i,g),a.preventDefault(),i=null}}}),this.addEventListener("dragstart",function(a){i&&(a.dataTransfer.effectAllowed="move",a.dataTransfer.setData("text",""))}),this.addEventListener("dragover",function(a){i&&a.preventDefault()}),this.addEventListener("dragenter",function(a){if(i&&(!h.rowsContainer||b(a.target,h.rowsContainer)===h.containerWithRows)){var c=a.target[e](h.repeatableElement)?a.target:b(a.target,h.repeatableElement);c&&f(i,c)}}),this.addEventListener("dragend",function(){i&&(i.setAttribute("draggable","false"),i.setAttribute("aria-grabbed","false"),i=null)})}}]),f}(_wrapNativeSuper(HTMLElement));a.define("joomla-field-subform",f)})(customElements);

No other release has this exact content. See every version of this file.