Commit e64acf10 authored by Tino Goratsch's avatar Tino Goratsch

rework the ajax-form class

parent 21b7925b
......@@ -3,30 +3,29 @@
* See the LICENSE file at the top-level module directory for licencing details.
*/
(function ($, window, document) {
(($, window, document) => {
'use strict';
let pluginName = 'formSubmit',
defaults = {
targetElement: '#content',
loadingOverlay: true,
loadingText: '',
customFormData: null,
scrollOffsetElement: null
};
function Plugin(element, options) {
this.element = element;
this.isFormValid = true;
this.settings = $.extend({}, defaults, options);
this._defaults = defaults;
this._name = pluginName;
this.init();
}
const pluginName = 'formSubmit';
class AjaxForm {
constructor(element, options) {
this.element = element;
this.isFormValid = true;
this._defaults = {
targetElement: '#content',
loadingOverlay: true,
loadingText: '',
customFormData: null,
scrollOffsetElement: null
};
this.settings = $.extend({}, this._defaults, options);
this._name = pluginName;
this.init();
}
$.extend(Plugin.prototype, {
init: function () {
init() {
const that = this;
this.mergeSettings();
......@@ -34,15 +33,15 @@
this.addLoadingLayer();
this.element.noValidate = true;
$(this.element).on('submit', function (e) {
$(this.element).on('submit', (e) => {
e.preventDefault();
that.isFormValid = true;
this.isFormValid = true;
$(document).trigger('acp3.ajaxFrom.submit.before', [that]);
$(document).trigger('acp3.ajaxFrom.submit.before', [this]);
if (that.isFormValid && that.preValidateForm(that.element)) {
that.processAjaxRequest();
if (this.isFormValid && this.preValidateForm(this.element)) {
this.processAjaxRequest();
}
}).on('click', function (e) {
if ($(this).prop('tagName') === 'A') {
......@@ -50,14 +49,15 @@
that.processAjaxRequest();
}
}).on('change', function () {
if (that.isFormValid === false) {
that.removeAllPreviousErrors();
that.checkFormElementsForErrors(that.element);
}).on('change', () => {
if (this.isFormValid === false) {
this.removeAllPreviousErrors();
this.checkFormElementsForErrors(this.element);
}
});
},
mergeSettings: function () {
}
mergeSettings() {
const data = $(this.element).data();
for (let key in data) {
if (data.hasOwnProperty(key)) {
......@@ -68,33 +68,36 @@
}
}
}
},
lowerCaseFirstLetter: function (string) {
}
lowerCaseFirstLetter(string) {
return string.charAt(0).toLowerCase() + string.slice(1);
},
findSubmitButton: function () {
}
findSubmitButton() {
$(this.element).find(':submit').click(function () {
$(':submit', $(this).closest('form')).removeAttr('data-clicked');
$(this).attr('data-clicked', 'true');
});
},
preValidateForm: function (form) {
}
preValidateForm(form) {
this.removeAllPreviousErrors();
this.checkFormElementsForErrors(form);
this.focusTabWithFirstErrorMessage();
this.scrollToFirstFormError();
return this.isFormValid;
},
removeAllPreviousErrors: function () {
}
removeAllPreviousErrors() {
$('form .form-group.has-error')
.removeClass('has-error')
.find('.validation-failed').remove();
},
checkFormElementsForErrors: function (form) {
for (let i = 0; i < form.elements.length; i++) {
const field = form.elements[i];
}
checkFormElementsForErrors(form) {
for (const field of form.elements) {
if (field.nodeName !== 'INPUT' && field.nodeName !== 'TEXTAREA' && field.nodeName !== 'SELECT') {
continue;
}
......@@ -106,23 +109,26 @@
this.isFormValid = false;
}
}
},
addErrorDecorationToFormGroup: function ($elem) {
}
addErrorDecorationToFormGroup($elem) {
$elem.closest('.form-group').addClass('has-error');
},
removeErrorMessageFromFormField: function ($elem) {
}
removeErrorMessageFromFormField($elem) {
$elem.closest('div').find('.validation-failed').remove();
},
addErrorMessageToFormField: function ($element, errorMessage) {
}
addErrorMessageToFormField($element, errorMessage) {
this.removeErrorMessageFromFormField($element);
$element
.closest('div:not(.input-group):not(.btn-group)')
.append(
'<small class="help-block validation-failed"><i class="glyphicon glyphicon-exclamation-sign"></i> ' + errorMessage + '</small>'
.append(`<small class="help-block validation-failed"><i class="glyphicon glyphicon-exclamation-sign"></i> ${errorMessage}</small>`
);
},
focusTabWithFirstErrorMessage: function () {
}
focusTabWithFirstErrorMessage() {
if ($('.tabbable').length > 0) {
let $elem = $('.tabbable .form-group.has-error:first'),
tabId = $elem.closest('.tab-pane').prop('id');
......@@ -130,8 +136,9 @@
$elem.find(':input').focus();
}
},
processAjaxRequest: function () {
}
processAjaxRequest() {
const $form = $(this.element),
hasCustomData = !$.isEmptyObject(this.settings.customFormData);
......@@ -209,46 +216,53 @@
this.hideLoadingLayer();
this.enableSubmitButton($submitButton);
});
},
addLoadingLayer: function () {
}
addLoadingLayer() {
if (this.settings.loadingOverlay === false) {
return;
}
let $loadingLayer = $('#loading-layer');
const $loadingLayer = $('#loading-layer');
if ($loadingLayer.length === 0) {
let $body = $('body'),
const $body = $('body'),
loadingText = this.settings.loadingText || '',
html = '<div id="loading-layer" class="loading-layer"><h1><span class="glyphicon glyphicon-cog"></span>' + loadingText + '</h1></div>';
html = `<div id="loading-layer" class="loading-layer"><h1><span class="glyphicon glyphicon-cog"></span> ${loadingText}</h1></div>`;
$(html).appendTo($body);
}
},
showLoadingLayer: function () {
}
showLoadingLayer() {
$('#loading-layer').addClass('loading-layer__active');
},
disableSubmitButton: ($submitButton) => {
}
disableSubmitButton($submitButton) {
if (typeof $submitButton !== 'undefined') {
$submitButton.prop('disabled', true);
}
},
enableSubmitButton: ($submitButton) => {
}
enableSubmitButton($submitButton) {
if (typeof $submitButton !== 'undefined') {
$submitButton.prop('disabled', false);
}
},
redirectToNewPage: function (hash, responseData) {
}
redirectToNewPage(hash, responseData) {
if (typeof hash !== 'undefined') {
window.location.href = responseData.redirect_url + hash;
window.location.reload();
} else {
window.location.href = responseData.redirect_url;
}
},
}
/**
* Scroll to the beginning of the content area, if the current viewport is near the bottom
*/
scrollIntoView: function () {
scrollIntoView() {
const offsetTop = $(this.settings.targetElement).offset().top;
if ($(document).scrollTop() > offsetTop) {
......@@ -259,25 +273,29 @@
'fast'
);
}
},
replaceContent: function (hash, responseData) {
}
replaceContent(hash, responseData) {
if (hash && $(hash).length) {
$(hash).html($(responseData).find(hash).html());
} else {
$(this.settings.targetElement).html(responseData);
}
},
rebindHandlers: function (hash) {
}
rebindHandlers(hash) {
const $bindingTarget = (hash && $(hash).length) ? $(hash) : $(this.settings.targetElement);
$bindingTarget.find('[data-ajax-form="true"]').formSubmit();
this.findSubmitButton();
},
hideLoadingLayer: function () {
}
hideLoadingLayer() {
$('#loading-layer').removeClass('loading-layer__active');
},
handleFormErrorMessages: function ($form, errorMessagesHtml) {
}
handleFormErrorMessages($form, errorMessagesHtml) {
let $errorBox = $('#error-box');
const $modalBody = $form.find('.modal-body');
......@@ -292,27 +310,26 @@
.fadeIn();
this.prettyPrintResponseErrorMessages($form, $errorBox);
},
prettyPrintResponseErrorMessages: function ($form, $errorBox) {
const that = this;
}
prettyPrintResponseErrorMessages($form, $errorBox) {
this.removeAllPreviousErrors();
// highlight all input fields where the validation has failed
$errorBox.find('li').each(function () {
let $this = $(this),
$errorBox.find('li').each((index, element) => {
let $this = $(element),
errorClass = $this.data('error');
if (errorClass.length > 0) {
let $elem = $form.find('#' + errorClass) || $form.find('[id|="' + errorClass + '"]').filter(':not([id$="container"])');
if ($elem.length > 0) {
that.addErrorDecorationToFormGroup($elem);
this.addErrorDecorationToFormGroup($elem);
// Move the error message to the responsible input field(s)
// and remove the list item from the error box container
if ($elem.length === 1) {
that.addErrorMessageToFormField($elem, $this.html());
this.addErrorMessageToFormField($elem, $this.html());
$this.remove();
}
}
......@@ -325,8 +342,9 @@
}
this.focusTabWithFirstErrorMessage();
},
scrollToFirstFormError: function () {
}
scrollToFirstFormError() {
const $form = $(this.element);
const $formErrors = $form.find('.form-group.has-error');
......@@ -358,8 +376,9 @@
},
'fast'
);
},
isElementInViewport: function (element) {
}
isElementInViewport(element) {
// special bonus for those using jQuery
if (typeof jQuery === 'function' && element instanceof jQuery) {
element = element[0];
......@@ -379,12 +398,12 @@
&& rect.bottom <= (window.innerHeight || document.documentElement.clientHeight)
&& rect.right <= (window.innerWidth || document.documentElement.clientWidth);
}
});
}
$.fn[pluginName] = function (options) {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) {
$.data(this, 'plugin_' + pluginName, new Plugin(this, options));
$.data(this, 'plugin_' + pluginName, new AjaxForm(this, options));
}
});
};
......@@ -393,7 +412,7 @@
jQuery(document).ready(($) => {
$('[data-ajax-form="true"]').formSubmit();
$(document).on('draw.dt', function (e) {
$(document).on('draw.dt', (e) => {
$(e.target).find('[data-ajax-form="true"]').formSubmit();
});
});
"use strict";/*
"use strict";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}/*
* Copyright (c) by the ACP3 Developers.
* See the LICENSE file at the top-level module directory for licencing details.
*/(function(a,b,c){'use strict';function d(b,c){this.element=b,this.isFormValid=!0,this.settings=a.extend({},e,c),this._defaults=e,this._name="formSubmit",this.init()}var e={targetElement:"#content",loadingOverlay:!0,loadingText:"",customFormData:null,scrollOffsetElement:null};a.extend(d.prototype,{init:function init(){var b=this;this.mergeSettings(),this.findSubmitButton(),this.addLoadingLayer(),this.element.noValidate=!0,a(this.element).on("submit",function(d){d.preventDefault(),b.isFormValid=!0,a(c).trigger("acp3.ajaxFrom.submit.before",[b]),b.isFormValid&&b.preValidateForm(b.element)&&b.processAjaxRequest()}).on("click",function(c){"A"===a(this).prop("tagName")&&(c.preventDefault(),b.processAjaxRequest())}).on("change",function(){!1===b.isFormValid&&(b.removeAllPreviousErrors(),b.checkFormElementsForErrors(b.element))})},mergeSettings:function mergeSettings(){var b=a(this.element).data();for(var c in b)if(b.hasOwnProperty(c)){var d=this.lowerCaseFirstLetter(c.replace("ajaxForm",""));0<d.length&&"undefined"!=typeof this.settings[d]&&(this.settings[d]=b[c])}},lowerCaseFirstLetter:function lowerCaseFirstLetter(a){return a.charAt(0).toLowerCase()+a.slice(1)},findSubmitButton:function findSubmitButton(){a(this.element).find(":submit").click(function(){a(":submit",a(this).closest("form")).removeAttr("data-clicked"),a(this).attr("data-clicked","true")})},preValidateForm:function preValidateForm(a){return this.removeAllPreviousErrors(),this.checkFormElementsForErrors(a),this.focusTabWithFirstErrorMessage(),this.scrollToFirstFormError(),this.isFormValid},removeAllPreviousErrors:function removeAllPreviousErrors(){a("form .form-group.has-error").removeClass("has-error").find(".validation-failed").remove()},checkFormElementsForErrors:function checkFormElementsForErrors(b){for(var c,d=0;d<b.elements.length;d++)(c=b.elements[d],"INPUT"===c.nodeName||"TEXTAREA"===c.nodeName||"SELECT"===c.nodeName)&&(c.checkValidity()||(this.addErrorDecorationToFormGroup(a(c)),this.addErrorMessageToFormField(a(c),c.validationMessage),this.isFormValid=!1))},addErrorDecorationToFormGroup:function addErrorDecorationToFormGroup(a){a.closest(".form-group").addClass("has-error")},removeErrorMessageFromFormField:function removeErrorMessageFromFormField(a){a.closest("div").find(".validation-failed").remove()},addErrorMessageToFormField:function addErrorMessageToFormField(a,b){this.removeErrorMessageFromFormField(a),a.closest("div:not(.input-group):not(.btn-group)").append("<small class=\"help-block validation-failed\"><i class=\"glyphicon glyphicon-exclamation-sign\"></i> "+b+"</small>")},focusTabWithFirstErrorMessage:function focusTabWithFirstErrorMessage(){if(0<a(".tabbable").length){var b=a(".tabbable .form-group.has-error:first"),c=b.closest(".tab-pane").prop("id");a(".tabbable .nav-tabs a[href=\"#"+c+"\"]").tab("show"),b.find(":input").focus()}},processAjaxRequest:function processAjaxRequest(){var d,e,f=this,g=a(this.element),h=!a.isEmptyObject(this.settings.customFormData),i=!0,j=this.settings.customFormData||{};if(g.attr("method")){if(e=a(":submit[data-clicked=\"true\"]",g),d=e.data("hashChange"),j=new FormData(g[0]),e.length&&j.append(e.attr("name"),1),h)for(var k in this.settings.customFormData)this.settings.customFormData.hasOwnProperty(k)&&j.append(k,this.settings.customFormData[k]);i=!1}else d=g.data("hashChange");a.ajax({url:g.attr("action")||g.attr("href"),type:g.attr("method")?g.attr("method").toUpperCase():"GET",data:j,processData:i,contentType:!!i&&"application/x-www-form-urlencoded; charset=UTF-8",beforeSend:function beforeSend(){f.showLoadingLayer(e),f.disableSubmitButton(e)}}).done(function(a){try{var c=g.data("ajax-form-complete-callback");"function"==typeof b[c]?b[c](a):a.redirect_url?f.redirectToNewPage(d,a):(f.scrollIntoView(),f.replaceContent(d,a),f.rebindHandlers(d),"undefined"!=typeof d&&(b.location.hash=d))}catch(a){console.error(a.message)}}).fail(function(b){400===b.status?(f.handleFormErrorMessages(g,b.responseText),f.scrollToFirstFormError(),a(c).trigger("acp3.ajaxFrom.submit.fail",[f])):0<b.responseText.length&&(c.open(),c.write(b.responseText),c.close())}).always(function(){f.hideLoadingLayer(),f.enableSubmitButton(e)})},addLoadingLayer:function addLoadingLayer(){if(!1!==this.settings.loadingOverlay){var b=a("#loading-layer");if(0===b.length){var c=a("body"),d=this.settings.loadingText||"";a("<div id=\"loading-layer\" class=\"loading-layer\"><h1><span class=\"glyphicon glyphicon-cog\"></span>"+d+"</h1></div>").appendTo(c)}}},showLoadingLayer:function showLoadingLayer(){a("#loading-layer").addClass("loading-layer__active")},disableSubmitButton:function disableSubmitButton(a){"undefined"!=typeof a&&a.prop("disabled",!0)},enableSubmitButton:function enableSubmitButton(a){"undefined"!=typeof a&&a.prop("disabled",!1)},redirectToNewPage:function redirectToNewPage(a,c){"undefined"==typeof a?b.location.href=c.redirect_url:(b.location.href=c.redirect_url+a,b.location.reload())},/**
*/(function(a,b,c){'use strict';var d=/*#__PURE__*/function(){function d(b,c){_classCallCheck(this,d),this.element=b,this.isFormValid=!0,this._defaults={targetElement:"#content",loadingOverlay:!0,loadingText:"",customFormData:null,scrollOffsetElement:null},this.settings=a.extend({},this._defaults,c),this._name="formSubmit",this.init()}return _createClass(d,[{key:"init",value:function init(){var b=this,d=this;this.mergeSettings(),this.findSubmitButton(),this.addLoadingLayer(),this.element.noValidate=!0,a(this.element).on("submit",function(d){d.preventDefault(),b.isFormValid=!0,a(c).trigger("acp3.ajaxFrom.submit.before",[b]),b.isFormValid&&b.preValidateForm(b.element)&&b.processAjaxRequest()}).on("click",function(b){"A"===a(this).prop("tagName")&&(b.preventDefault(),d.processAjaxRequest())}).on("change",function(){!1===b.isFormValid&&(b.removeAllPreviousErrors(),b.checkFormElementsForErrors(b.element))})}},{key:"mergeSettings",value:function mergeSettings(){var b=a(this.element).data();for(var c in b)if(b.hasOwnProperty(c)){var d=this.lowerCaseFirstLetter(c.replace("ajaxForm",""));0<d.length&&"undefined"!=typeof this.settings[d]&&(this.settings[d]=b[c])}}},{key:"lowerCaseFirstLetter",value:function lowerCaseFirstLetter(a){return a.charAt(0).toLowerCase()+a.slice(1)}},{key:"findSubmitButton",value:function findSubmitButton(){a(this.element).find(":submit").click(function(){a(":submit",a(this).closest("form")).removeAttr("data-clicked"),a(this).attr("data-clicked","true")})}},{key:"preValidateForm",value:function preValidateForm(a){return this.removeAllPreviousErrors(),this.checkFormElementsForErrors(a),this.focusTabWithFirstErrorMessage(),this.scrollToFirstFormError(),this.isFormValid}},{key:"removeAllPreviousErrors",value:function removeAllPreviousErrors(){a("form .form-group.has-error").removeClass("has-error").find(".validation-failed").remove()}},{key:"checkFormElementsForErrors",value:function checkFormElementsForErrors(b){var c=!0,d=!1,e=void 0;try{for(var f,g,h=b.elements[Symbol.iterator]();!(c=(f=h.next()).done);c=!0)(g=f.value,"INPUT"===g.nodeName||"TEXTAREA"===g.nodeName||"SELECT"===g.nodeName)&&(g.checkValidity()||(this.addErrorDecorationToFormGroup(a(g)),this.addErrorMessageToFormField(a(g),g.validationMessage),this.isFormValid=!1))}catch(a){d=!0,e=a}finally{try{c||null==h.return||h.return()}finally{if(d)throw e}}}},{key:"addErrorDecorationToFormGroup",value:function addErrorDecorationToFormGroup(a){a.closest(".form-group").addClass("has-error")}},{key:"removeErrorMessageFromFormField",value:function removeErrorMessageFromFormField(a){a.closest("div").find(".validation-failed").remove()}},{key:"addErrorMessageToFormField",value:function addErrorMessageToFormField(a,b){this.removeErrorMessageFromFormField(a),a.closest("div:not(.input-group):not(.btn-group)").append("<small class=\"help-block validation-failed\"><i class=\"glyphicon glyphicon-exclamation-sign\"></i> ".concat(b,"</small>"))}},{key:"focusTabWithFirstErrorMessage",value:function focusTabWithFirstErrorMessage(){if(0<a(".tabbable").length){var b=a(".tabbable .form-group.has-error:first"),c=b.closest(".tab-pane").prop("id");a(".tabbable .nav-tabs a[href=\"#"+c+"\"]").tab("show"),b.find(":input").focus()}}},{key:"processAjaxRequest",value:function processAjaxRequest(){var d,e,f=this,g=a(this.element),h=!a.isEmptyObject(this.settings.customFormData),i=!0,j=this.settings.customFormData||{};if(g.attr("method")){if(e=a(":submit[data-clicked=\"true\"]",g),d=e.data("hashChange"),j=new FormData(g[0]),e.length&&j.append(e.attr("name"),1),h)for(var k in this.settings.customFormData)this.settings.customFormData.hasOwnProperty(k)&&j.append(k,this.settings.customFormData[k]);i=!1}else d=g.data("hashChange");a.ajax({url:g.attr("action")||g.attr("href"),type:g.attr("method")?g.attr("method").toUpperCase():"GET",data:j,processData:i,contentType:!!i&&"application/x-www-form-urlencoded; charset=UTF-8",beforeSend:function beforeSend(){f.showLoadingLayer(e),f.disableSubmitButton(e)}}).done(function(a){try{var c=g.data("ajax-form-complete-callback");"function"==typeof b[c]?b[c](a):a.redirect_url?f.redirectToNewPage(d,a):(f.scrollIntoView(),f.replaceContent(d,a),f.rebindHandlers(d),"undefined"!=typeof d&&(b.location.hash=d))}catch(a){console.error(a.message)}}).fail(function(b){400===b.status?(f.handleFormErrorMessages(g,b.responseText),f.scrollToFirstFormError(),a(c).trigger("acp3.ajaxFrom.submit.fail",[f])):0<b.responseText.length&&(c.open(),c.write(b.responseText),c.close())}).always(function(){f.hideLoadingLayer(),f.enableSubmitButton(e)})}},{key:"addLoadingLayer",value:function addLoadingLayer(){if(!1!==this.settings.loadingOverlay){var b=a("#loading-layer");if(0===b.length){var c=a("body"),d=this.settings.loadingText||"",e="<div id=\"loading-layer\" class=\"loading-layer\"><h1><span class=\"glyphicon glyphicon-cog\"></span> ".concat(d,"</h1></div>");a(e).appendTo(c)}}}},{key:"showLoadingLayer",value:function showLoadingLayer(){a("#loading-layer").addClass("loading-layer__active")}},{key:"disableSubmitButton",value:function disableSubmitButton(a){"undefined"!=typeof a&&a.prop("disabled",!0)}},{key:"enableSubmitButton",value:function enableSubmitButton(a){"undefined"!=typeof a&&a.prop("disabled",!1)}},{key:"redirectToNewPage",value:function redirectToNewPage(a,c){"undefined"==typeof a?b.location.href=c.redirect_url:(b.location.href=c.redirect_url+a,b.location.reload())}/**
* Scroll to the beginning of the content area, if the current viewport is near the bottom
*/scrollIntoView:function scrollIntoView(){var b=a(this.settings.targetElement).offset().top;a(c).scrollTop()>b&&a("html, body").animate({scrollTop:b},"fast")},replaceContent:function replaceContent(b,c){b&&a(b).length?a(b).html(a(c).find(b).html()):a(this.settings.targetElement).html(c)},rebindHandlers:function rebindHandlers(b){var c=b&&a(b).length?a(b):a(this.settings.targetElement);c.find("[data-ajax-form=\"true\"]").formSubmit(),this.findSubmitButton()},hideLoadingLayer:function hideLoadingLayer(){a("#loading-layer").removeClass("loading-layer__active")},handleFormErrorMessages:function handleFormErrorMessages(b,c){var d=a("#error-box"),e=b.find(".modal-body");// Place the error messages inside the modal body for a better styling
d.remove(),d=a(c),d.hide().prependTo(0<e.length&&e.is(":visible")?e:b).fadeIn(),this.prettyPrintResponseErrorMessages(b,d)},prettyPrintResponseErrorMessages:function prettyPrintResponseErrorMessages(b,c){var d=this;// highlight all input fields where the validation has failed
this.removeAllPreviousErrors(),c.find("li").each(function(){var c=a(this),e=c.data("error");if(0<e.length){var f=b.find("#"+e)||b.find("[id|=\""+e+"\"]").filter(":not([id$=\"container\"])");0<f.length&&(d.addErrorDecorationToFormGroup(f),1===f.length&&(d.addErrorMessageToFormField(f,c.html()),c.remove()))}}),0===c.find("li").length&&c.remove(),this.focusTabWithFirstErrorMessage()},scrollToFirstFormError:function scrollToFirstFormError(){var b=a(this.element),c=b.find(".form-group.has-error");if(!(0<b.closest(".modal").length)&&c&&0!==c.length&&!this.isElementInViewport(b.find(".help-block.validation-failed"))){var d=c.offset().top;if(this.settings.scrollOffsetElement){var e=a(this.settings.scrollOffsetElement);e&&0<e.length&&(d-=e.height())}a("html, body").animate({scrollTop:d},"fast")}},isElementInViewport:function isElementInViewport(d){"function"==typeof jQuery&&d instanceof jQuery&&(d=d[0]);var e=a(this.settings.scrollOffsetElement),f=0;e&&(f=e.height());var g=d.getBoundingClientRect();return g.top>=f&&0<=g.left&&g.bottom<=(b.innerHeight||c.documentElement.clientHeight)&&g.right<=(b.innerWidth||c.documentElement.clientWidth)}}),a.fn.formSubmit=function(b){return this.each(function(){a.data(this,"plugin_formSubmit")||a.data(this,"plugin_formSubmit",new d(this,b))})}})(jQuery,window,document),jQuery(document).ready(function(a){a("[data-ajax-form=\"true\"]").formSubmit(),a(document).on("draw.dt",function(b){a(b.target).find("[data-ajax-form=\"true\"]").formSubmit()})});
\ No newline at end of file
*/},{key:"scrollIntoView",value:function scrollIntoView(){var b=a(this.settings.targetElement).offset().top;a(c).scrollTop()>b&&a("html, body").animate({scrollTop:b},"fast")}},{key:"replaceContent",value:function replaceContent(b,c){b&&a(b).length?a(b).html(a(c).find(b).html()):a(this.settings.targetElement).html(c)}},{key:"rebindHandlers",value:function rebindHandlers(b){var c=b&&a(b).length?a(b):a(this.settings.targetElement);c.find("[data-ajax-form=\"true\"]").formSubmit(),this.findSubmitButton()}},{key:"hideLoadingLayer",value:function hideLoadingLayer(){a("#loading-layer").removeClass("loading-layer__active")}},{key:"handleFormErrorMessages",value:function handleFormErrorMessages(b,c){var d=a("#error-box"),e=b.find(".modal-body");d.remove(),d=a(c),d.hide().prependTo(0<e.length&&e.is(":visible")?e:b).fadeIn(),this.prettyPrintResponseErrorMessages(b,d)}},{key:"prettyPrintResponseErrorMessages",value:function prettyPrintResponseErrorMessages(b,c){var d=this;this.removeAllPreviousErrors(),c.find("li").each(function(c,e){var f=a(e),g=f.data("error");if(0<g.length){var h=b.find("#"+g)||b.find("[id|=\""+g+"\"]").filter(":not([id$=\"container\"])");0<h.length&&(d.addErrorDecorationToFormGroup(h),1===h.length&&(d.addErrorMessageToFormField(h,f.html()),f.remove()))}}),0===c.find("li").length&&c.remove(),this.focusTabWithFirstErrorMessage()}},{key:"scrollToFirstFormError",value:function scrollToFirstFormError(){var b=a(this.element),c=b.find(".form-group.has-error");if(!(0<b.closest(".modal").length)&&c&&0!==c.length&&!this.isElementInViewport(b.find(".help-block.validation-failed"))){var d=c.offset().top;if(this.settings.scrollOffsetElement){var e=a(this.settings.scrollOffsetElement);e&&0<e.length&&(d-=e.height())}a("html, body").animate({scrollTop:d},"fast")}}},{key:"isElementInViewport",value:function isElementInViewport(d){"function"==typeof jQuery&&d instanceof jQuery&&(d=d[0]);var e=a(this.settings.scrollOffsetElement),f=0;e&&(f=e.height());var g=d.getBoundingClientRect();return g.top>=f&&0<=g.left&&g.bottom<=(b.innerHeight||c.documentElement.clientHeight)&&g.right<=(b.innerWidth||c.documentElement.clientWidth)}}]),d}();a.fn.formSubmit=function(b){return this.each(function(){a.data(this,"plugin_formSubmit")||a.data(this,"plugin_formSubmit",new d(this,b))})}})(jQuery,window,document),jQuery(document).ready(function(a){a("[data-ajax-form=\"true\"]").formSubmit(),a(document).on("draw.dt",function(b){a(b.target).find("[data-ajax-form=\"true\"]").formSubmit()})});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment