/*! * * magic-rows v1.0.2 * Adds rows to your forms automagically * Copyright (c) 2016 Francois Chalifour * https://github.com/francoischalifour/magic-rows * MIT license * */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("magic-rows",[],e):"object"==typeof exports?exports["magic-rows"]=e():t["magic-rows"]=e()}(this,function(){return function(t){function e(s){if(r[s])return r[s].exports;var n=r[s]={exports:{},id:s,loaded:!1};return t[s].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e){"use strict";function r(t){if(Array.isArray(t)){for(var e=0,r=Array(t.length);e=this.maxRows)&&(!(this.noRows>1)||this.rows[this.noRows-2].value)){this.removeEventListeners(),this.noRows++;var t=this.cloneRow(this.lastRow),e=this.fillRow(t);this.insertRow(this.lastRow,e),this.lastRow=e,this.rows.push(this.lastRow),this.addEventListeners()}}},{key:"cloneRow",value:function(t){var e=this.lastRow.cloneNode(!0);return e.value="",e}},{key:"fillRow",value:function(t){var e=t.getAttribute("id"),r=t.getAttribute("placeholder"),s=t.getAttribute("name");return e&&t.setAttribute("id",this.getNextValue(e,this.idFormat)),r&&t.setAttribute("placeholder",this.getNextValue(r,this.placeholderFormat)),s&&t.setAttribute("name",this.getNextValue(s,this.nameFormat)),t}},{key:"insertRow",value:function(t,e){t.parentNode.insertBefore(e,t.nextSibling)}},{key:"getNextValue",value:function(t,e){return e?e.includes("$")?e.replace(/\$+/g,this.getPatternNumbers(e,e.split("$").length-1)):e.includes("@")?e.replace("@",this.getLetter(this.guessNextPatternNumber())):this.guessNextValue(t):this.guessNextValue(t,!0)}},{key:"getPatternNumbers",value:function(t,e){return(Array(e).fill("0").join("")+this.guessNextPatternNumber()).slice(-e)}},{key:"guessNextPatternNumber",value:function(){var t=this.lastRow.getAttribute("id")||this.lastRow.getAttribute("name")||this.lastRow.getAttribute("placeholder"),e=Number(t.replace(/^\D+/g,""))+1;return e}},{key:"guessNextValue",value:function(t,e){return e?t.replace(/\d+/g,function(t){return++t}):this.hasNumber(t)?t.replace(/\d+/g,this.getPatternNumbers(t,t.replace(/^\D+/g,"").length)):t+"-"+this.noRows}},{key:"getLetter",value:function(t){return String.fromCharCode(96+t).toUpperCase()}},{key:"hasNumber",value:function(t){return/\d/.test(t)}}]),t}();window.addEventListener("load",function(){[].concat(r(document.querySelectorAll('[data-action="magic-rows"]'))).forEach(function(t){return new o(t)})})}])}); //# sourceMappingURL=magic-rows.min.js.map