1/** 2 * Put button to a loading state. 3 * @param {Object} button Button to be putted. 4 * @param {string} loadingText Text that will be displayed while loading. 5 */ 6AS.Util.loadingButton = function(button, loadingText) { 7 button.data("original-content", button.html()) 8 .text(loadingText) 9 .addClass("disabled") 10 .attr('disabled', "disabled"); 11}; 12 13/** 14 * Returns button from loadin state to normal state. 15 * @param {Object} button Button object. 16 */ 17AS.Util.removeLoadingButton = function (button) { 18 button.html(button.data("original-content")) 19 .removeClass("disabled") 20 .removeAttr("disabled") 21 .removeAttr("rel"); 22}; 23 24/** 25 * Append success message to provided parent element. 26 * @param {Object} parentElement Parent element where message will be appended. 27 * @param {String} message Message to be displayed. 28 */ 29AS.Util.displaySuccessMessage = function (parentElement, message) { 30 $(".alert-success").remove(); 31 var div = ("<div class='alert alert-success mb-3'>"+message+"</div>"); 32 parentElement.prepend(div); 33}; 34 35 36/** 37 * Append error message to an input element. If message is omitted, it will be set to empty string. 38 * @param {Object} element Input element on which error message will be appended. 39 * @param {String} message Message to be displayed. 40 */ 41AS.Util.displayErrorMessage = function(element, message) { 42 element.addClass('is-invalid').removeClass('is-valid'); 43 44 if(typeof message !== "undefined") { 45 element.after( 46 $("<em class='invalid-feedback'>"+message+"</em>") 47 ); 48 } 49}; 50 51 52/** 53 * Removes all error messages from all input fields. 54 */ 55AS.Util.removeErrorMessages = function () { 56 $("form input").removeClass('is-invalid').removeClass('is-valid'); 57 $(".invalid-feedback").remove(); 58}; 59 60/** 61 * Get an parameter from URL. 62 * @param {string} name Parameter name. 63 * @returns {string} Value of parameter with given name. 64 */ 65AS.Util.urlParam = function(name) { 66 return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)') 67 .exec(location.search)||[,""])[1] 68 .replace(/\+/g, '%20'))||null; 69}; 70 71 72/** 73 * Show errors received from the server. 74 * @param form 75 * @param error 76 */ 77AS.Util.showFormErrors = function (form, error) { 78 $.each(error.responseJSON.errors, function (key, error) { 79 AS.Util.displayErrorMessage($(form).find("input[name="+key+"]"), error); 80 }); 81}; 82 83/** 84 * Hash a given value using SHA512 hashing algorithm. 85 * @param value 86 * @returns {string} 87 */ 88AS.Util.hash = function (value) { 89 return value.length ? CryptoJS.SHA512(value).toString() : ""; 90}; 91 92/** 93 * Submit a specified form using AJAX. 94 * 95 * @param form A form object. 96 * @param data JSON data to be sent via the AJAX request. 97 * @param success Success callback. 98 * @param error Error callback. 99 * @param complete Complete callback. 100 */ 101AS.Http.submit = function (form, data, success, error, complete) { 102 AS.Util.removeErrorMessages(); 103 104 var $submitBtn = $(form).find("button[type=submit]"); 105 106 if ($submitBtn) { 107 AS.Util.loadingButton($submitBtn, $submitBtn.data('loading-text') || $_lang.working); 108 } 109 110 $.ajax({ 111 url: "ASEngine/ASAjax.php", 112 type: "POST", 113 dataType: "json", 114 data: data, 115 success: function (response) { 116 form.reset(); 117 118 if (typeof success === "function") { 119 success(response); 120 } 121 }, 122 error: error || function (errorResponse) { 123 AS.Util.showFormErrors(form, errorResponse); 124 }, 125 complete: complete || function () { 126 if ($submitBtn) { 127 AS.Util.removeLoadingButton($submitBtn); 128 } 129 } 130 }); 131}; 132 133/** 134 * Make a HTTP POST request via AJAX. 135 * 136 * @param data JSON data to be sent via the AJAX request. 137 * @param success Success callback. 138 * @param error Error callback. 139 * @param complete Complete callback. 140 */ 141AS.Http.post = function (data, success, error, complete) { 142 $.ajax({ 143 url: "ASEngine/ASAjax.php", 144 type: "POST", 145 dataType: "json", 146 data: data, 147 success: success || function () {}, 148 error: error || function () {}, 149 complete: complete || function () {} 150 }); 151};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.