CoreFiles by mySites.guru
joomla-field-subform-es5.min.js1 lines, 10,753 bytes, from Joomla_4.0.0-beta7-Beta-Full_Package.zip
Raw History Compare with 4.0.0-beta6
md5
2e52ce94369713364f423370d0d89941
sha1
4b1e79a8602bf431b2aeafcd5f1152509089ddfa
sha256
85c1a7103098205f6803092cb0b4b7ff9e7dd7445cb7d94200623b6e4bf6556d
"use strict";function _typeof(a){"@babel/helpers - typeof";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 _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 _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}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 _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 _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 _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 _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){return a.ctrlKey||a.metaKey||a.shiftKey}var c={SPACE:32,ESC:27,ENTER:13},d=function(a){function d(){var a;_classCallCheck(this,d),a=e.call(this);var b=_assertThisInitialized(a);if(a.containerWithRows=_assertThisInitialized(a),a.rowsContainer){var f=a.querySelectorAll(a.rowsContainer);Array.from(f).forEach(function(b){b.closest("joomla-field-subform")===_assertThisInitialized(a)&&(a.containerWithRows=b)})}return a.lastRowIndex=a.getRows().length-1,a.template="",a.prepareTemplate(),(a.buttonAdd||a.buttonRemove)&&(a.addEventListener("click",function(a){var c=null,d=null;if(b.buttonAdd&&(c=a.target.matches(b.buttonAdd)?a.target:a.target.closest(b.buttonAdd)),b.buttonRemove&&(d=a.target.matches(b.buttonRemove)?a.target:a.target.closest(b.buttonRemove)),c&&c.closest("joomla-field-subform")===b){var e=c.closest("joomla-field-subform");e=e.closest(b.repeatableElement)===b?e:null,b.addRow(e),a.preventDefault()}else if(d&&d.closest("joomla-field-subform")===b){var f=d.closest(b.repeatableElement);b.removeRow(f),a.preventDefault()}}),a.addEventListener("keydown",function(a){if(a.keyCode===c.SPACE){var d=b.buttonAdd&&a.target.matches(b.buttonAdd),e=b.buttonRemove&&a.target.matches(b.buttonRemove);if((d||e)&&a.target.closest("joomla-field-subform")===b){var f=a.target.closest("joomla-field-subform");f=f.closest(b.repeatableElement)===b?f:null,e&&f?b.removeRow(f):d&&b.addRow(f),a.preventDefault()}}})),a.buttonMove&&a.setUpDragSort(),a}_inherits(d,a);var e=_createSuper(d);return _createClass(d,[{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(d,[{key:"getRows",value:function getRows(){var a=this,b=Array.from(this.containerWithRows.children),c=[];return b.forEach(function(b){b.matches(a.repeatableElement)&&c.push(b)}),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,b){var c=this,d=a.getAttribute("data-group"),e=a.getAttribute("data-base-name"),f=Math.max(this.lastRowIndex,b||0),g=e+f;this.lastRowIndex=f+1,a.setAttribute("data-group",g);var h=a.querySelectorAll("[name]"),i={};h=[].slice.call(h).filter(function(a){return a.closest("joomla-field-subform")===c}),h.forEach(function(b){var c=b,e=c.getAttribute("name"),f=e.replace(/(\[\]$)/g,"").replace(/(\]\[)/g,"__").replace(/\[/g,"_").replace(/\]/g,""),h=e.replace("[".concat(d,"]["),"[".concat(g,"][")),j=f.replace(d,g).replace(/\W/g,"_"),k=0,l=f;if("checkbox"===c.type&&e.match(/\[\]$/)){if(k=i[f]?i[f].length:0,!k){var m=c.closest("fieldset.checkboxes"),n=a.querySelector("label[for=\"".concat(f,"\"]"));m&&m.setAttribute("id",j),n&&(n.setAttribute("for",j),n.setAttribute("id","".concat(j,"-lbl")))}l+=k,j+=k}else if("radio"===c.type){if(k=i[f]?i[f].length:0,!k){var o=c.closest("fieldset.radio"),p=a.querySelector("label[for=\"".concat(f,"\"]"));o&&o.setAttribute("id",j),p&&(p.setAttribute("for",j),p.setAttribute("id","".concat(j,"-lbl")))}l+=k,j+=k}i[f]?i[f].push(!0):i[f]=[!0],c.name=h,c.id&&(c.id=j);var q=a.querySelector("label[for=\"".concat(l,"\"]"));q&&(q.setAttribute("for",j),q.setAttribute("id","".concat(j,"-lbl")))})}},{key:"setUpDragSort",value:function setUpDragSort(){function a(a){return!a.form&&a.matches(e.buttonMove)?a:a.closest(e.buttonMove)}function d(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)}var e=this,f=null,g=!1,h=Array.from(this.getRows());h.forEach(function(a){a.setAttribute("draggable","false"),a.setAttribute("aria-grabbed","false"),a.setAttribute("tabindex","0")}),this.addEventListener("touchstart",function(b){g=!0;var c=a(b.target),h=c?c.closest(e.repeatableElement):null;h&&h.closest("joomla-field-subform")===e&&(f?(h!==f&&d(f,h),f.setAttribute("draggable","false"),f.setAttribute("aria-grabbed","false"),f=null):(h.setAttribute("draggable","true"),h.setAttribute("aria-grabbed","true"),f=h),b.preventDefault())}),this.addEventListener("mousedown",function(b){var c=b.target;if(!g){var d=a(c),h=d?d.closest(e.repeatableElement):null;h&&h.closest("joomla-field-subform")===e&&(h.setAttribute("draggable","true"),h.setAttribute("aria-grabbed","true"),f=h)}}),this.addEventListener("mouseup",function(){f&&!g&&(f.setAttribute("draggable","false"),f.setAttribute("aria-grabbed","false"),f=null)}),this.addEventListener("keydown",function(a){if((a.keyCode===c.ESC||a.keyCode===c.SPACE||a.keyCode===c.ENTER)&&!a.target.form&&a.target.matches(e.repeatableElement)){var g=a.target;if(g&&g.closest("joomla-field-subform")===e&&(a.keyCode===c.SPACE&&b(a)&&("true"===g.getAttribute("aria-grabbed")?(g.setAttribute("draggable","false"),g.setAttribute("aria-grabbed","false"),f=null):(f&&(f.setAttribute("draggable","false"),f.setAttribute("aria-grabbed","false"),f=null),g.setAttribute("draggable","true"),g.setAttribute("aria-grabbed","true"),f=g),a.preventDefault()),a.keyCode===c.ESC&&f&&(f.setAttribute("draggable","false"),f.setAttribute("aria-grabbed","false"),f=null),a.keyCode===c.ENTER&&f)){if(f.setAttribute("draggable","false"),f.setAttribute("aria-grabbed","false"),g===f)return void(f=null);d(f,g),a.preventDefault(),f=null}}}),this.addEventListener("dragstart",function(a){var b=a.dataTransfer;f&&(b.effectAllowed="move",b.setData("text",""))}),this.addEventListener("dragover",function(a){f&&a.preventDefault()}),this.addEventListener("dragenter",function(a){var b=a.target;if(f&&(!e.rowsContainer||b.closest(e.rowsContainer)===e.containerWithRows)){var c=b.matches(e.repeatableElement)?b:b.closest(e.repeatableElement);c&&d(f,c)}}),this.addEventListener("dragend",function(){f&&(f.setAttribute("draggable","false"),f.setAttribute("aria-grabbed","false"),f=null)})}}]),d}(_wrapNativeSuper(HTMLElement));a.define("joomla-field-subform",d)})(customElements);

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