silverstripe-userforms/client/dist/js/userforms.js

1 line
93 KiB
JavaScript
Raw Normal View History

!function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,n){"use strict";var r=n(2),i=n.n(r),o=this;i()(document).ready(function(){function e(e){return this.$el=e instanceof i.a?e:i()(e),this.$el.find("h4").text(window.ss.i18n._t("UserForms.ERROR_CONTAINER_HEADER","Please correct the following errors and try again:")),this}function t(t){var n=this;return this.$el=t instanceof i.a?t:i()(t),this.$elButton=i()(".step-button-wrapper[data-for='"+this.$el.prop("id")+"]"),this.viewed=!1,this.valid=!1,this.id=null,this.hide(),u.DISPLAY_ERROR_MESSAGES_AT_TOP&&(this.errorContainer=new e(this.$el.find(".error-container")),a.$el.on("userform.form.error",function(e,t){n.$el.is(":visible")&&i.a.each(t.errorList,function(e,t){n.errorContainer.updateErrorMessage(i()(t.element),t.message)})}),a.$el.on("userform.form.valid",function(e,t){n.errorContainer.removeErrorMessage(t)})),this.$elButton.on("userform.field.hide userform.field.show",function(){a.$el.trigger("userform.form.conditionalstep")}),this}function n(e){var t=this,n=this;return this.$el=e instanceof i.a?e:i()(e),this.$buttons=this.$el.find(".step-button-jump"),this.$jsAlign=this.$el.find(".js-align"),this.$buttons.each(function(e,r){i()(r).on("click",function(e){e.preventDefault(),n.$el.trigger("userform.progress.changestep",[parseInt(i()(t).data("step"),10)])})}),a.$el.on("userform.form.changestep",function(e,t){n.update(t)}),a.$el.on("userform.form.conditionalstep",function(){var e=n.$buttons.filter(":visible");e.each(function(e,t){i()(t).text(e+1)}),n.$el.find(".progress-bar").attr("aria-valuemax",e.length),n.$el.find(".total-step-number").text(e.length)}),this.$jsAlign.each(function(e,t){var r=i()(t),o=100/(n.$jsAlign.length-1)*(e+"%"),s=r.innerWidth()/2*-1;r.css({left:o,marginLeft:s}),e===n.$jsAlign.length-1?r.css({marginLeft:2*s}):0===e&&r.css({marginLeft:0})}),this.update(0),this}function r(e){var t=this;return this.$el=e instanceof i.a?e:i()(e),this.$prevButton=this.$el.find(".step-button-prev"),this.$nextButton=this.$el.find(".step-button-next"),this.$prevButton.parent().attr("aria-hidden",!1).show(),this.$nextButton.parent().attr("aria-hidden",!1).show(),this.$prevButton.on("click",function(e){e.preventDefault(),t.$el.trigger("userform.action.prev")}),this.$nextButton.on("click",function(e){e.preventDefault(),t.$el.trigger("userform.action.next")}),a.$el.on("userform.form.changestep userform.form.conditionalstep",function(){t.update()}),this.update(),this}function s(t){var n=this,r=this;return this.$el=t instanceof i.a?t:i()(t),this.steps=[],this.errorContainer=new e(this.$el.children(".error-container")),this.$el.on("userform.action.prev",function(){r.prevStep()}),this.$el.on("userform.action.next",function(){r.nextStep()}),i()("#userform-progress").on("userform.progress.changestep",function(e,t){r.jumpToStep(t-1)}),this.$el.on("userform.form.valid",function(e,t){r.errorContainer.removeStepLink(t)}),this.$el.validate(this.validationOptions),i()(".optionset.requiredField input").each(function(){i()(n).rules("add",{required:!0})}),this}var a=null,u={},l={show:function(){o.$el.attr("aria-hidden",!1).show()},hide:function(){o.$el.attr("aria-hidden",!0).hide()}};e.prototype.hasErrors=function(){return o.$el.find(".error-list").children().length>0},e.prototype.removeErrorMessage=function(e){o.$el.find("#"+e+"-top-error").remove(),o.hasErrors()||o.hide()},e.prototype.addStepLink=function(e){var t=e.$el.attr("id")+"-error-link",n=o.$el.find("#"+t),r=e.$el.attr("id"),s=e.$el.data("title");n.length||(n=i()('<li id="'+t+'"><a href="#'+r+'">'+s+"</a></li>"),n.on("click",function(t){t.preventDefault(),a.jumpToStep(e.id)}),o.$el.find(".error-li