-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.simpleClone.min.js
11 lines (11 loc) · 2.02 KB
/
jquery.simpleClone.min.js
1
2
3
4
5
6
7
8
9
10
11
/*!
* jQuery Simple Clone.
*
* @category Plugins
* @author KUCKLU
* @license Licensed under MIT (http://www.opensource.org/licenses/mit-license.php)
* @copyright (c) 2022 KUCKLU
* @version 1.2.0
*/
!function(e){"use strict";var t={copyValue:!0,cloneLimit:!1,limitMessageClass:"simpleClone-clnLmt",limitMessageText:"Maximum count has been reached.",targetClass:"simpleClone-clnElem",addButtonWrapClass:"simpleClone-btnWrap",removeButtonClass:"simpleClone-rmvBtn",removeButtonText:"Remove",filterCloneElement:null,onClone:null,onComplete:null,onRemove:null,onCompleteRemove:null};e.fn.simpleClone=function(n){var l=e.extend({},t,n);return e(document).on("click","."+l.removeButtonClass,(function(t){t.preventDefault();var n=e(this).parent();e.isFunction(l.onRemove)&&l.onRemove.call(this,l),n.remove(),e.isFunction(l.onCompleteRemove)&&l.onCompleteRemove.call(this,l)})),this.on("click",(function(n){n.preventDefault();var o=e(this),s=o.closest("."+l.addButtonWrapClass).prev().find("."+l.targetClass).first(),i=s.parent().children("."+l.targetClass).length+1;if(!1===l.cloneLimit||"number"==typeof l.cloneLimit&&i<=l.cloneLimit){var a=s.clone(!0),m=e("<button>").attr("type","button").addClass(null===l.removeButtonClass?t.removeButtonClass:t.removeButtonClass+" "+l.removeButtonClass).text(l.removeButtonText);a.append(m),e.isFunction(l.filterCloneElement)&&(a=l.filterCloneElement.call(this,a,l)),a.find("select").each((function(t,n){e(n).val(s.find("select").eq(t).val())})),!1===l.copyValue&&a.find('input:not("input[type=radio], input[type=button], input[type=submit]"), textarea, select').each((function(t,n){e(n).val("")})),e.isFunction(l.onClone)&&l.onClone.call(this,a,l),s.parent().append(a),e.isFunction(l.onComplete)&&l.onComplete.call(this,a,l)}else{var u=e("<span>").addClass(l.limitMessageClass).text(l.limitMessageText);0===o.next("."+l.limitMessageClass).length&&(o.after(u),setTimeout((function(){o.next("."+l.limitMessageClass).fadeOut().remove()}),4e3))}})),this}}(jQuery);
//# sourceMappingURL=jquery.simpleClone.min.js.map