1/*! 2 Dashcore - HTML Startup Template, v1.0 3 Forms JS file 4 Copyright © 2018 5Studios.net 5 http://5studios.net 6 */ 7 8'use strict'; 9$(function($) { 10 $("form").each(function() { 11 var $form = $(this); 12 var options = { 13 errorPlacement: function(error, element) { 14 var $parent = element.parent(); 15 16 if ($parent.hasClass("input-group")) { 17 error.insertAfter($parent); 18 } else if ($parent.hasClass("has-icon")) { 19 error.insertBefore($parent); 20 } else if ($parent.hasClass("control")) { 21 error.insertAfter(element.next('.control-label')); 22 } else { 23 error.insertAfter(element); 24 } 25 } 26 }; 27 28 if ($form.data("validate-on") == "submit") { 29 $.extend(options, { 30 onfocusout: false, 31 onkeyup: false 32 }); 33 } 34 35 // call to validate plugin 36 $form.validate(options); 37 }); 38 39 $("form").submit(function(evt) { 40 evt.preventDefault(); 41 var $form = $(this); 42 43 if (!$form.valid()) { 44 return false; 45 } 46 47 var $submit = $("button[type=submit]", this); 48 $submit.addClass('loading'); 49 50 var $ajaxButton = $submit.parent('.ajax-button'); 51 var hasAjaxButton = $ajaxButton.length; 52 var $message = $form.next(".response-message"); 53 54 function doAjax(url, data, config) { 55 var settings = $.extend(true, {}, config, { 56 url: url, 57 type: 'POST', 58 data: data, 59 dataType: 'json' 60 }); 61 62 $.ajax(settings) 63 .done(function(data) { 64 if (data.result) { 65 //setTimeout(function() { 66 $form.trigger("form.submitted", [data]); 67 //}, 1000); 68 69 $("input, textarea", $form).removeClass("error"); 70 $(".response", $message).html(data.message); 71 72 // restore button defaults 73 if (hasAjaxButton) { 74 $(".success", $ajaxButton).addClass("done"); 75 } 76 77 $form.addClass('submitted'); 78 $form[0].reset(); 79 } else { 80 if (hasAjaxButton) { 81 $(".failed", $ajaxButton).addClass("done"); 82 } 83 84 if (data.errors) { 85 $.each(data.errors, function(i, v) { 86 var $input = $("[name$='[" + i + "]']", $form).addClass('error'); 87 $input 88 .tooltip({title: v, placement: 'bottom', trigger: 'manual'}).tooltip('show') 89 .on('focus', function() { $(this).tooltip('destroy'); }); 90 }); 91 } 92 } 93 }).fail(function() { 94 $(".response", $message).html($("<span class='block'>Something went wrong.</span>")); 95 if (hasAjaxButton) { 96 $(".failed", $ajaxButton).addClass("done"); 97 } 98 }).always(function() { 99 $submit.addClass('loading-end'); 100 101 if (hasAjaxButton) { 102 setTimeout(function () { 103 console.log('clearing status'); 104 $submit.removeClass('loading').removeClass('loading-end'); 105 $(".success,.failed", $ajaxButton).removeClass("done"); 106 }, 500); 107 } 108 //some other stuffs 109 }); 110 } 111 112 function submitAjax($form) { 113 doAjax( 114 $form.attr('action'), 115 $form.serializeArray() 116 ); 117 } 118 119 submitAjax($form); 120 121 return false; 122 });
123});
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.