CoreFiles by mySites.guru
joomla-field-subform-es5.min.js1 lines, 10,513 bytes, from Joomla_4.0.0-alpha9-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha8
md5
6066067488a369cd1aca9cbebf54acb0
sha1
578a9524c5f45735343ab3fa7754ead4cce5b4bb
sha256
72a0994dfaba19a55942a670e11c8684e644d47c76d7e92831997ad679bf94ed
"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 _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return 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 _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(a);if(a.containerWithRows=_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(a)){a.containerWithRows=g[h];break}return 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 get(){return this.getAttribute("button-add")}},{key:"buttonRemove",get:function get(){return this.getAttribute("button-remove")}},{key:"buttonMove",get:function get(){return this.getAttribute("button-move")}},{key:"rowsContainer",get:function get(){return this.getAttribute("rows-container")}},{key:"repeatableElement",get:function get(){return this.getAttribute("repeatable-element")}},{key:"minimum",get:function get(){return this.getAttribute("minimum")}},{key:"maximum",get:function get(){return this.getAttribute("maximum")}},{key:"name",get:function get(){return this.getAttribute("name")},set:function set(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 getRows(){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 prepareTemplate(){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 addRow(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 removeRow(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 fixUniqueAttributes(a,c){var d=this;c=c||0;var e=a.getAttribute("data-group"),f=a.getAttribute("data-base-name"),g=f+c;a.setAttribute("data-group",g);var h=a.querySelectorAll("[name]"),j={};h=[].slice.call(h).filter(function(a){return b(a,"joomla-field-subform")===d});for(var w=0,i=h.length;w<i;w++){var k=h[w],m=k.getAttribute("name"),n=m.replace(/(\[\]$)/g,"").replace(/(\]\[)/g,"__").replace(/\[/g,"_").replace(/\]/g,""),o=m.replace("[".concat(e,"]["),"[".concat(g,"][")),p=n.replace(e,g),q=0,r=n;if("checkbox"===k.type&&m.match(/\[\]$/)){if(q=j[n]?j[n].length:0,!q){var s=b(k,"fieldset.checkboxes"),t=a.querySelector("label[for=\"".concat(n,"\"]"));s&&s.setAttribute("id",p),t&&(t.setAttribute("for",p),t.setAttribute("id","".concat(p,"-lbl")))}r+=q,p+=q}else if("radio"===k.type){if(q=j[n]?j[n].length:0,!q){var u=b(k,"fieldset.radio"),v=a.querySelector("label[for=\"".concat(n,"\"]"));u&&u.setAttribute("id",p),v&&(v.setAttribute("for",p),v.setAttribute("id","".concat(p,"-lbl")))}r+=q,p+=q}j[n]?j[n].push(!0):j[n]=[!0],k.name=o,k.id&&(k.id=p);var l=a.querySelector("label[for=\"".concat(r,"\"]"));l&&(l.setAttribute("for",p),l.setAttribute("id","".concat(p,"-lbl")))}}},{key:"setUpDragSort",value:function setUpDragSort(){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);

The same content is in 3 releases, Joomla 4.0.0-alpha9 to 4.0.0-alpha11. See them all, or every version of this file.