1(function(namespace, undefined) { 2 namespace.submit_form = function(event) { 3 var form = this; 4 if ($(form).attr('action') == '.') { 5 if ($(form).find('.ajax-form-overlay').length > 0) { 6 return false; 7 } 8 9 show_overlay(form); 10 11 var url = $(form).attr('action') || '.'; 12 $.post(url, $(form).serialize(), 13 function(data) { 14 if (data.redirect_to) { 15 $(form).find('.status-text').text('Redirecting...'); 16 if (data.is_login) { 17 $(form).attr('action', data.redirect_to); 18 $(form).submit(); 19 } else { 20 document.location.href = data.redirect_to; 21 } 22 } else { 23 if (data.form) { 24 hide_overlay(form, function() { 25 $(form).replaceWith(data.form); 26 $('form.ajax-form').submit(namespace.submit_form); 27 28 var reloaded_event = document.createEvent('Event'); 29 reloaded_event.initEvent('ajax-form-reloaded', true, true); 30 document.dispatchEvent(reloaded_event); 31 }); 32 } else { 33 hide_overlay(form); 34 } 35 36 if (data.top_text) { 37 $('.top-text').html(data.top_text); 38 } 39 40 if (data.bottom_text) { 41 $('.bottom-text').html(data.bottom_text); 42 } 43 } 44 }).fail( 45 function() { 46 var overlay = $(form).find('.ajax-form-overlay'); 47 $(overlay).find('.status-text').hide(); 48 $(overlay).find('.error-text').show('drop', {'direction': 'down'}, 200); 49 }); 50 51 return false; 52 } 53 } 54 55 function hide_overlay(element, callback) { 56 $(element).find('.ajax-form-overlay') 57 .hide('drop', {'direction': 'down'}, 200, 58 function() { 59 $(this).remove(); 60 callback(); 61 }); 62 } 63 64 function show_overlay(element) { 65 var overlay = $('<div>', {'class': 'ajax-form-overlay', 'style': 'display: none;'}) 66 .appendTo($(element)); 67 68 var status_text = $('<div>', {'class': 'status-text', 'text': 'Loading...'}) 69 .appendTo($(overlay)); 70 71 var error_text = $('<div>', 72 { 73 'class': 'error-text', 74 'text': 'Some error occurred! Please, contact support!'}) 75 .appendTo($(overlay)); 76 77 var offset = $(element).offset(); 78 var width = $(element).outerWidth(); 79 var height = $(element).outerHeight() - 2; 80 81 $(overlay).css({ 82 'top': 0, 83 'width': width, 84 'height': height}); 85 $(status_text).css({ 86 'left': width/2 - 55, 87 'top': height/2 - 5}); 88 $(error_text).css({ 89 'display': 'none', 90 'left': width/2 - 165, 91 'top': height/2 - 20}); 92 93 $(overlay).show('drop', {'direction': 'down'}, 200); 94 } 95 96 namespace.click = function() { 97 hide_overlay($('form.ajax-form')); 98 } 99}(window.ajax_forms_namespace = window.ajax_forms_namespace || {})); 100 101$(document).ready(function() { 102 var form = $('form.ajax-form'); 103 if (form) { 104 if (!$(form).attr('no_ajax')) { 105 $('form.ajax-form').submit(ajax_forms_namespace.submit_form); 106 } 107 } 108});
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.