var window_width = parseFloat($(window).width()), window_height = parseFloat($(window).height()); $(document).ready(function () { /** * Валидиране на полета */ $(this).on('keyup', '.number', function () { this.value = this.value.replace(/[^0-9.,]/g, ''); this.value = this.value.replace(',', '.'); }); $(this).on('keyup', '.int', function () { this.value = this.value.replace(/[^0-9]/g, ''); }); $(this).on('keyup', '.telefon', function () { this.value = this.value.replace(/[^0-9,+]/g, ''); }); $(this).on('keyup', '.iban', function () { this.value = this.value.replace(/[^0-9 A-Z]/g, ''); }); $(this).on('keyup', '.bic', function () { this.value = this.value.replace(/[^A-Z]/g, ''); }); $(this).on('keyup', '.eik,.in', function () { this.value = this.value.replace(/[^0-9A-Z]/g, ''); }); /** * Без кавички */ $(this).on('keyup click', 'input[type=text],textarea', function () { this.value = this.value.replace(/["'`]/g, ''); }); /** * Показване на бутон за връщане най-горе */ $(window).scroll(function () { if ($(this).scrollTop() > 370) $('#back_to_top').fadeIn(); else $('#back_to_top').fadeOut(); }); /** * Анимиране на връщането най-горе */ $('#back_to_top').click(function () { $('body,html').animate({ scrollTop: 0 }, 800); return false; }); $(document).on('click', '.close_djam,.djam,.djam_prodex', function () { close_djam(); }); // hover_inputs(); // hover_focus(); $('#login input[name=email]').keyup(function (key) { // this.value = this.value.replace(/[^0-9._\-\@a-z]/g, ''); if (key.keyCode == 13) { $('#login input[name=pass]').focus(); } }); $('#login input[name=pass]').keyup(function (key) { if (key.keyCode == 13) { var val = this.value; if ($.trim(this.value).length <= 0) { $('#login input[name=email]').focus(); } else { login(); } } }); $('#login button').click(function () { login(); }); $('#logout button').click(function () { logout(); }); // $('div#big_pic img').hover(function () { // $(this).animate({ // width: 600, // height: 600 // }, 1000); // }); $(document).on('click', '#new_pass button', function () { var email = $('span.email_').html(), pass = $('#new_pass input[name=new_pass]').val(), pass1 = $('#new_pass input[name=new_pass1]').val(); close_djam(); if (pass === pass1) { if (typeof email === 'undefined') { email = prompt('Въведете имейла си!'); } $.ajax({ type: 'POST', url: $('#logo a').attr('href') + 'home/change_pass_/', data: { change_pass_: 1, email: email, pass: pass } }).done(function (data) { alert(data); }); } }); }); /** * * @description Вход * @returns {undefined} */ function login() { var email = $.trim($('#login input[name=email]').val()), pass = $.trim($('#login input[name=pass]').val()), path = $('#logo a').attr('href'); if (email.length > 5 && pass.length > 5) { $.ajax({ type: 'POST', url: path + 'home/login/', data: { login: 1, email: email, pass: pass } }).done(function () { window.location.href = path; }); } else { refresh(); } } /** * * @description Изход * @returns {undefined} */ function logout() { var $log = confirm('Вы хотите выход из системой?'); if ($log) { var path = $('#logo a').attr('href') $.ajax({ type: 'POST', url: path + 'home/logout/', data: { logout: 1 } }).done(function () { window.location = $('#logo a').attr('href'); }); } } /** * * @description Опресняване на страницата * @returns {undefined} */ function refresh(url) { if (url) { window.location.href = url; } else { window.location.href = window.location.href; } } /** * * @description Псевдо alert() * @param {sting} text * @param {string} color * @returns {undefined} */ function djam(text, color) { $('body').append('
');
$('.wait').css({
'top': (window_height / 2) - (parseFloat($('.wait').height()) / 2),
'left': (window_width / 2) - (parseFloat($('.wait').width()) / 2)
});
}
/**
*
* @description Затваряне на чакалня
* @returns {unresolved}
*/
function close_wait() {
$('.wait_').remove();
$('.wait').remove();
}
/**
*
* @description Отваряне на нов прозорец
* @param {string} url
* @returns {undefined}
*/
function openWin(url) {
window.open(url);
}
/**
*
* @description Отваряне на нов прозорец с по-малки размери
* @example openWinMini({url: 'http://hankrum.info', width: 800, height: 500});
* @see default - url: 'http://hankrum.info', width: 1000, height: 700
* @param {object} params
* @returns {undefined}
*/
function openWinMini(params) {
var object;
if (params === undefined)
object = {};
else
object = params;
if (parseInt(object.width) === 0 || object.width === undefined)
object.width = 1000;
if (parseInt(object.height) === 0 || object.height === undefined)
object.height = 700;
if (String(object.url) === null || object.url === undefined)
object.url = 'http://hankrum.info';
var size = 'width = ' + object.width + ', ' + 'height = ' + object.height;
window.open(object.url, object.name, size);
}
/**
*
* @description Затваряне на нов прозорец
* @returns {undefined}
*/
function closeIt() {
window.close();
}
/**
* Проверява, дали е JSON
* @param {string} str
* @returns {Boolean}
*/
function IsJson(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
function hover_inputs() {
$('input.tabela,textarea.tabela').hover(function () {
$('body').append('' + $(this).attr('placeholder') + '');
$('.help').hide().show(50);
}, function () {
$('.help').remove();
}).bind('mousemove mouseenter', function (e) {
$('.help').css({
left: e.pageX + 6,
top: e.pageY + 9
});
});
}
function hover_focus() {
$('input,textarea,select').hover(function () {
$(this).focus();
});
}
function change_pass() {
var email = prompt('Ваша Э-почта!');
$.ajax({
type: 'POST',
url: $('#logo a').attr('href') + 'home/change_pass/',
data: {
change_pass: 1,
email: email
}
}).done(function (data) {
alert(data);
});
}
function change_pass_() {
djam('