Created
January 12, 2015 12:33
-
-
Save Ulv/97a6aa5138a6ad96ea40 to your computer and use it in GitHub Desktop.
js modal dialog: send mail, countdown and redirect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* form mail + модальное окно при сабмите | |
*/ | |
$.fn.extend({ | |
diplomMailForm: function(data) { | |
countdown = function (element, seconds, minutes) { | |
var interval; | |
minutes = minutes || 0; | |
seconds = seconds || 5; | |
return interval = setInterval(function () { | |
var el; | |
el = document.getElementById(element); | |
if (seconds === 0) { | |
if (minutes === 0) { | |
clearInterval(interval); | |
window.location.href = "/"; | |
return; | |
} else { | |
minutes--; | |
seconds = 60; | |
} | |
} | |
el.innerHTML = seconds; | |
seconds--; | |
}, 1000); | |
}; | |
return this.each(function() { | |
var self, typeIsArray; | |
self = this; | |
typeIsArray = Array.isArray || function(value) { | |
return {}.toString.call(value) === '[object Array]'; | |
}; | |
return $(this).on('submit', function() { | |
var labels, lbl, txt, _i, _len, _ref; | |
labels = {}; | |
_ref = $(this).find('input, select, textarea'); | |
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | |
lbl = _ref[_i]; | |
txt = $(lbl).attr('name'); | |
if (txt) { | |
txt = txt.replace(/^form\[/g, ""); | |
labels[txt] = $(lbl).siblings('label').html() || $(lbl).parent().siblings('label').html() || $(lbl).attr("placeholder"); | |
} | |
} | |
$.post('/send.php', { | |
data: $(this).serialize(), | |
labels: labels | |
}, function(r) { | |
if (r.status && r.status === 'success') { | |
$('#modalDlg').show(); | |
return countdown('countdown', 4); | |
} | |
}); | |
return false; | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment