// JavaScript Document if (typeof $ === 'function') { $(document).ready(function() { "use strict"; $('footer').css('display', 'none'); fix_footer(); //clown var clown = $('.clown'); if (clown && typeof(clown) !== 'undefined') { setTimeout(function() { $('.clown').fadeOut(2000); }, 3000); } get_server_time(); setInterval(function () { get_server_time(); }, 1000); setTimeout(function() { go_up_show(); go_down_show(); }, 350); $(window).scroll(function() { fix_footer(); go_up_show(); go_down_show(); }); $(window).resize(function() { fix_footer(); go_up_show(); go_down_show(); }); $('.go-up').click(function() { $('html, body').animate({'scrollTop': 0}, 'fast'); }); $('.go-down').click(function() { $('html, body').animate({'scrollTop': $(document).height()}, 'fast'); }); $('.td-xml').click(function() { var idx = $(this).index() + 1; // rows $('.tr-xml div:not(.empty-val-xml)').removeClass('select-row-xml'); $(this).parent().find('.td-xml:not(.empty-val-xml)').addClass('select-row-xml'); // cols $('.tr-xml .th-xml, .tr-xml .td-xml:not(.empty-val-xml)').removeClass('select-col-xml'); $('.tr-xml .th-xml:nth-child('+ idx + '), .tr-xml .td-xml:nth-child('+ idx + '):not(.empty-val-xml)').addClass('select-col-xml'); }); $('.th-xml').click(function() { var idx = $(this).index() + 1; // cols $('.tr-xml .th-xml, .tr-xml .td-xml:not(.empty-val-xml)').removeClass('select-col-xml'); $('.tr-xml .th-xml:nth-child('+ idx + '), .tr-xml .td-xml:nth-child('+ idx + '):not(.empty-val-xml)').addClass('select-col-xml'); }); $(':radio').click(function() { if ($(this).is(':checked')) { $(this).parent('label').css('color', '#F00'); } $(':radio').not(':checked').parent('label').css('color', ''); }); $(':checkbox').click(function() { if ($(this).is(':checked')) { $(this).parent('label').css('color', '#F00'); } $(':checkbox').not(':checked').parent('label').css('color', ''); }); }); } function fix_footer() { "use strict"; var f = $('footer'); if (f !== 'undefined' && f) { if ($(window).height() >= $(document).height()) { if (f.css('position') !== 'fixed') { f.css('position', 'fixed'); f.css('bottom', '0px'); f.css('left', '0px'); } } else { if (f.css('position') !== 'static') { f.css('position', 'static'); } } f.css('display', 'block'); } } function go_up_show() { "use strict"; if ($(document).scrollTop() >= 100) { $('.go-up:hidden').stop().fadeIn('fast'); } else { $('.go-up:visible').stop().fadeOut('fast'); } } function go_down_show() { "use strict"; if ($(document).height() - $(window).height() - $(document).scrollTop() >= 100) { $('.go-down:hidden').stop().fadeIn('fast'); } else { $('.go-down:visible').stop().fadeOut('fast'); } } function str_ipos(haystack, needle, offset) { "use strict"; if (typeof(haystack) === 'string' && haystack && typeof(needle) === 'string' && needle ) { haystack = haystack.toLowerCase(); needle = needle.toLowerCase(); var index = 0; if (isNaN(offset)) { offset = 0; } if ((index = haystack.indexOf(needle, offset)) > -1) { return index; } } return false; } function get_server_time() { "use strict"; var elm = document.getElementById('watch'); if (typeof(elm) !== 'undefined' && elm) { // var d = new Date(); d.setHours(d.getHours() + 3, d.getMinutes() + d.getTimezoneOffset()); elm.innerHTML = d.toDateString() + ' ' + d.toTimeString().substr(0, 8) + ' (MSK)'; // /*if (typeof $ === 'function') { $.ajax({ method: 'GET', url: 'server_time.php', cache: false, dataType: 'html', success: function(data) { elm.innerHTML = data; } }); }*/ // } } function range_change(dest_id, _this) { "use strict"; var elm = document.getElementById(dest_id); if (typeof(elm) !== 'undefined' && elm) { elm.innerHTML = _this.value; } } function vote_item_del(parent_id, item_id, db_item_id) { "use strict"; var prnt = document.getElementById(parent_id); prnt.removeChild(document.getElementById(item_id)); var items_id_del = document.getElementById('items_id_del'); if (typeof(items_id_del) !== 'undefined' && items_id_del) { if (items_id_del.value) { items_id_del.value = items_id_del.value + ','; } items_id_del.value = items_id_del.value + db_item_id; } } var vote_item_add_num = 1; function vote_item_add(parent_id) { "use strict"; var prnt = document.getElementById(parent_id); var elm = document.createElement('table'); elm.className = 'vote-item'; elm.id = 'vote_item_add_' + vote_item_add_num; elm.innerHTML = 'Название:Удалить элементСсылка:'; prnt.appendChild(elm); vote_item_add_num++; } function win_popup(id, action) { "use strict"; var v = document.getElementById(id); if (typeof(v) !== 'undefined' && v) { if (typeof(action) !== 'undefined' && action) { if (v.style.display !== action) { v.style.display = action; } } else { $(v).toggle('slow'); /*if (v.style.display !== 'block') { $(v).fadeIn('slowslow', function() { v.style.display = 'block'; }); } else { $(v).fadeOut('fast', function() { v.style.display = 'none'; }); }*/ } } } function select_group(sel_id) { "use strict"; /*var groups_items = document.getElementsByClassName('groups-items'); if (typeof(groups_items) != 'undefined' && groups_items.length) { for (var i = 0; i < groups_items.length; i++) { groups_items[i].style.display = 'none'; } }*/ var elm = document.getElementById(sel_id); if (typeof(elm) !== 'undefined' && elm) { if (elm.style.display === 'none') { //elm.style.display = 'block'; //elm.parentNode.className = 'groups-item groups-show'; $(elm).slideDown('fast', function() { $(this).parent().removeClass('groups-hide').addClass('groups-show'); }); } else { //elm.style.display = 'none'; //elm.parentNode.className = 'groups-item groups-hide'; $(elm).slideUp('fast', function() { $(this).parent().removeClass('groups-show').addClass('groups-hide'); }); } } } function show_add_group(_this) { "use strict"; if (typeof(_this) !== 'undefined' && _this) { var elm = document.getElementById('add_group'); if (typeof(elm) !== 'undefined' && elm) { var elm1 = document.getElementById('new_group_title'); //if (_this.options[_this.selectedIndex].value == 'add_group') { if (_this.value === 'add_group') { elm.style.display = ''; elm1.disabled = false; elm1.focus(); } else { elm.style.display = 'none'; elm1.disabled = true; } } } } function like_inc(_this, item_id, hide_res) { "use strict"; $('#overlay').fadeIn(function() { $.ajax({ method: 'GET', url: 'like_inc.php?id=' + item_id, cache: false, dataType: 'html', success: function(data) { var elm = document.getElementById('like_res_' + item_id); if (typeof(elm) !== 'undefined' && elm) { var s = ''; if (data === 'ok') { if (!hide_res) { var v = parseInt(elm.innerHTML); if (isNaN(v)) { v = 0; } v++; s = '

' + v + ' (ваше мнение учтено)

'; } else { s = '

Ваше мнение учтено

'; } _this.onmouseover = null; _this.onmouseout = null; _this.style.cursor = 'default'; _this.src = 'images/like_gray.png'; } else { s = '

Ошибка! Обратитесь в техподдержку.

'; } elm.innerHTML = s; } }, complete: function() { $('#overlay').fadeOut(); } }); }); } function bribe_inc(_this, item_id, hide_res) { "use strict"; $('#overlay').fadeIn(function() { $.ajax({ method: 'GET', url: 'bribe_inc.php?id=' + item_id, cache: false, dataType: 'html', success: function(data) { var elm = document.getElementById('bribe_res_' + item_id); if (typeof(elm) !== 'undefined' && elm) { var s = ''; if (data === 'ok') { if (!hide_res) { var v = parseInt(elm.innerHTML); if (isNaN(v)) { v = 0; } v++; s = '

' + v + ' (в знак благодарности номер Вашего счета включен в Наш благотворительный фонд навечно!)

'; } else { s = '

В знак благодарности номер Вашего счета включен в Наш благотворительный фонд навечно!

'; } _this.onmouseover = null; _this.onmouseout = null; _this.style.cursor = 'default'; _this.src = 'images/bribe_gray.png'; } else { s = '

Ошибка! Деньги украли по дороге!

'; } elm.innerHTML = s; } }, complete: function() { $('#overlay').fadeOut(); } }); }); } function upload_file_result_local(_form, item_id) { "use strict"; $('#overlay').fadeIn(function() { document.body.style.cursor = 'wait'; var fd = new FormData(_form); $.ajax({ type: 'POST', url: 'ajax_upload_file.php', cache: false, contentType: false, processData: false, data: fd ? fd : _form.serialize(), success: function(data) { var elm = document.getElementById('file_result_' + item_id); if (typeof(elm) !== 'undefined' && elm) { if (str_ipos(data, '---') === 0) { alert(data.substr(3)); } else { elm.value = data; } } }, error: function() { alert('Не удалось загрузить файл на сервер'); }, complete: function() { document.body.style.cursor = 'default'; $('#overlay').fadeOut(); } }); }); } function get_guess() { "use strict"; var r = Math.random(); if (r <= 0.2) { $('#guess_link').html('Упс... нас кажется бдят! Тырки попозже...
'); } else { $('#overlay').fadeIn(function() { document.body.style.cursor = 'wait'; var guess_authors_list = document.getElementById('guess_authors_list').value; var guess_items_list = document.getElementById('guess_items_list').value; $.post({ url: 'rand_generator.php', cache: false, dataType: 'html', data: { stories_list : guess_items_list, authors_list : guess_authors_list, only_result : 1 }, success: function(data) { $('#authors_guess').html(data); }, error: function() { $('#authors_guess').html('Упс... нас засекли!
'); }, complete: function() { document.body.style.cursor = 'default'; $('#overlay').fadeOut(); } }); }); } } function vote_items_import(_form, dest_id) { "use strict"; $('#overlay').fadeIn(function() { document.body.style.cursor = 'wait'; var fd = new FormData(_form); $.ajax({ type: 'POST', url: 'ajax_items_import.php', cache: false, contentType: false, processData: false, data: fd ? fd : _form.serialize(), success: function(data) { if (data && String(data) !== '') { try { let data1 = JSON.parse(data); data = data1; } catch(e) { if (typeof(data) === 'string') { alert(data); } } } if (Array.isArray(data) && data.length) { var dest = document.getElementById(dest_id); var items_exists = dest.children; var items_exists_title = []; for (var i = 0; i < items_exists.length; i++) { let title = String(items_exists[i].rows[0].cells[1].firstChild.value.toLowerCase()); items_exists_title.push(title); } let item_add_id = 1001; for (var j = 0; j < data.length; j += 2) { let items_new_title = String(data[j]); if (items_new_title && items_new_title !== '') { let items_new_url = ''; if (typeof(data[j + 1]) !== 'undefined') { items_new_url = String(data[j + 1]); } else { items_new_url = ''; } if (items_exists_title.indexOf(items_new_title.toLowerCase()) < 0) { items_exists_title.push(items_new_title.toLowerCase()); dest.innerHTML = dest.innerHTML + '
Название:Удалить элемент
Ссылка:
'; item_add_id++; } } } } else { alert('Неверный тип данных'); } }, error: function() { alert('Не удалось загрузить файл импорта на сервер'); }, complete: function() { document.body.style.cursor = 'default'; $('#overlay').fadeOut(); } }); }); } function get_votes_more(_this, group_id, list_cur_count) { "use strict"; $('#overlay').fadeIn(function() { document.body.style.cursor = 'wait'; $.ajax({ type: 'GET', url: 'ajax_votes_more.php?group_id=' + group_id + '&list_cur_count=' + list_cur_count, cache: false, dataType: 'html', success: function(data) { $(_this).parent().before(data); $(_this).parent().remove(); }, error: function() { alert('Не удалось получить данные с сервера'); }, complete: function() { fix_footer(); go_up_show(); go_down_show(); document.body.style.cursor = 'default'; $('#overlay').fadeOut(); } }); }); } function settnigs_group_del_click(row_id, input_id) { "use strict"; var inpt = $('#' + input_id); inpt.attr('name', 'del_' + inpt.attr('name')); $('#' + row_id).hide(); }