Wrap all JS code in IIFE to avoid creating global variables

parent f103eaf1
var noticeTimer, noticeShow = false; (function() {
var noticeTimer, noticeShow = false;
function getEMail() function getEMail()
{ {
var emailInput = $('.svcCheckEmail'); var emailInput = $('.svcCheckEmail');
var email = emailInput.val(); var email = emailInput.val();
try { try {
...@@ -10,18 +11,18 @@ function getEMail() ...@@ -10,18 +11,18 @@ function getEMail()
// //
} }
return email; return email;
} }
function closeNotice() { function closeNotice() {
if(noticeShow === true) { if(noticeShow === true) {
clearTimeout(noticeTimer); clearTimeout(noticeTimer);
emailNotice.animate({ marginTop: '-=51px' }, 300); emailNotice.animate({ marginTop: '-=51px' }, 300);
noticeShow = false; noticeShow = false;
} }
} }
function showNotice(type, message) { function showNotice(type, message) {
if(!document.getElementById('svcCheckEmail_notice')) { if(!document.getElementById('svcCheckEmail_notice')) {
var notice = '<div id="svcCheckEmail_notice"><div class="notice_center_auto">'; var notice = '<div id="svcCheckEmail_notice"><div class="notice_center_auto">';
notice += '<div id="notice_text"></div>'; notice += '<div id="notice_text"></div>';
...@@ -47,10 +48,10 @@ function showNotice(type, message) { ...@@ -47,10 +48,10 @@ function showNotice(type, message) {
emailNotice.animate({ marginTop: '-=51px' }, 300); emailNotice.animate({ marginTop: '-=51px' }, 300);
noticeShow = false; noticeShow = false;
}, 7000); }, 7000);
} }
function showErrorNotice(error) function showErrorNotice(error)
{ {
var noticeText; var noticeText;
switch (error) { switch (error) {
case 'dns_records_not_found': case 'dns_records_not_found':
...@@ -71,11 +72,11 @@ function showErrorNotice(error) ...@@ -71,11 +72,11 @@ function showErrorNotice(error)
break; break;
} }
showNotice('red', noticeText); showNotice('red', noticeText);
} }
// Добавляем CSS и расставляем вызов // Добавляем CSS и расставляем вызов
$(function() { $(function() {
$('<link />').attr({ $('<link />').attr({
rel: 'stylesheet', rel: 'stylesheet',
type: 'text/css', type: 'text/css',
...@@ -159,8 +160,7 @@ $(function() { ...@@ -159,8 +160,7 @@ $(function() {
error: function() { error: function() {
showNotice('red', 'Ошибка связи с сервером, проверка адреса не удалась.'); showNotice('red', 'Ошибка связи с сервером, проверка адреса не удалась.');
emailInput.removeClass('bg-loader').addClass('bg-true'); emailInput.removeClass('bg-loader').addClass('bg-true');
// FIXME // FIXME
checkDoneStatus = 'true'; checkDoneStatus = 'true';
}, },
success: function(response) { success: function(response) {
...@@ -185,7 +185,7 @@ $(function() { ...@@ -185,7 +185,7 @@ $(function() {
checkDoneStatus = 'done'; checkDoneStatus = 'done';
} }
// FIXME // FIXME
} catch (e) { } catch (e) {
showNotice('yellow', 'Не удалось проверить адрес e-mail.'); showNotice('yellow', 'Не удалось проверить адрес e-mail.');
emailInput.removeClass('bg-loader').addClass('bg-true'); emailInput.removeClass('bg-loader').addClass('bg-true');
...@@ -194,7 +194,7 @@ $(function() { ...@@ -194,7 +194,7 @@ $(function() {
} }
}); });
return true; return true;
}); });
}); });
})();
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