Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var max = 2; // сколько комментариев выводить
- var com_to_load = 2; // сколько подгружать кнопкой
- $(document).ready(function() {
- $(".slider_btn").on("click", function(){
- $(this).toggleClass("open");
- $(this).parent().find("ul:first").slideToggle(300);
- });
- $(".cat-list li.active").parents("li.slider").find(".slider_btn:first").addClass("open");
- $(".cat-list li.active").parents("ul").show();
- var slider_width = $('.menu-block').width() + 2;
- var deviceWidth = $(window).width();
- /*Mobile menu*/
- $(".mobile-categories h2").on("click", function() {
- $(this).toggleClass("open-menu");
- $(this).next(".cat-list").slideToggle("fast");
- });
- $(".show-menu-toggle").on("click", function() {
- $(this).parent().find(".mobile-top-menu").slideToggle("fast");
- ;
- });
- /*Fix mobile top menu position if login admin*/
- if ($("body").hasClass("admin-on-site")) {
- $("body").find(".mobile-top-panel").addClass("position-fix");
- }
- var tabContainers = $('.product-tabs-container > div');
- tabContainers.hide().filter(':first').show();
- $('.product-tabs li a').click(function () {
- tabContainers.hide();
- tabContainers.filter(this.hash).fadeIn("fast");
- $('.product-tabs li').removeClass('active');
- $(this).parent().addClass('active');
- return false;
- }).filter(':first').click();
- $('.menu-block li a').each(function(){ // получаем все нужные нам ссылки
- var location = window.location.protocol+'//'+window.location.hostname+window.location.pathname; // получаем адрес страницы без параметров
- var link = this.href;// получаем адрес ссылки
- if(location == link){// при совпадении адреса ссылки и адреса окна
- $(this).parents('li').addClass('active'); //добавляем класс
- }
- });
- $(".cat-list li.active").find(".slider_btn:first").trigger("click");
- /*Выводим надпись "Выберите цвет" в зависимости от присутствия списка*/
- var anchors = document.getElementsByTagName('select');
- for(var i=0; i<anchors.length; i++) {
- if (anchors[i].className != "") {
- document.getElementById('select-color-title').innerHTML = 'Выберите цвет:';
- break;
- }
- }
- var a_array = document.getElementsByTagName('a');
- for(var i=0; i<a_array.length; i++) {
- if (a_array[i].className == "addToCart buy-product buy") a_array[i].innerHTML = 'Купить';
- if (a_array[i].className == "addToCompare") a_array[i].innerHTML = 'Добавить к сравнению';
- }
- document.getElementsByTagName('form')[2].style.display = 'none';
- var parametrs = new Array();
- var comments = document.getElementsByTagName('div');
- for(var i=0; i<comments.length; i++){
- if (comments[i].className=="comment-post"){
- var autor = comments[i].getElementsByTagName('span')[0];
- var comment = comments[i].getElementsByTagName('p')[0];
- comment.innerHTML+='<br><div class="reply-button">Ответить</div>';
- var a = autor.innerHTML;
- var reply = 'commentReply("'+a+'");';
- parametrs.push(reply);
- }
- }
- var replies = document.getElementsByClassName('reply-button');
- for(var i=0; i<replies.length; i++){
- replies[i].setAttribute("onclick", parametrs[i]);
- }
- setStyle();
- hideComments();
- checkCommentsCount(max);
- });
- function commentReply(name){
- forms = document.getElementsByTagName('textarea');
- var f = document.getElementsByTagName('form')[2];
- if (f.style.display == 'none') { f.style.display = 'block'; f.focus(); }
- forms[0].value += name + ", ";
- forms[0].focus();
- };
- function showCommentForm() { document.getElementsByTagName('form')[2].style.display = 'block'; }
- function hideComments(){
- var comments = document.getElementsByClassName('comment-post');
- if (comments.length > max) {
- for(var i=comments.length; i>max; i--) {
- comments[i-1].style.display = 'none';
- }
- }
- };
- function checkCommentsCount(max){
- var no_hide_comments = true;
- var button = document.getElementById('load-more-comments');
- var comments = document.getElementsByClassName('comment-post');
- for(var i=0; i<comments.length; i++) {
- if (comments[i].style.display == 'none') no_hide_comments = false;
- }
- if (no_hide_comments == true) { button.innerHTML = "<br>Комментариев больше нет :("; return true; }
- else {
- if (document.getElementsByClassName('comment-post').length > max) {
- var attribute = 'loadMoreComments();';
- button.innerHTML = '<br><div id="load-comments-button">Загрузить еще</div>';
- button.setAttribute("onclick", attribute);
- return false;
- }
- }
- };
- function setStyle() {
- var comments = document.getElementsByClassName('comment-post');
- for(var i=0; i<comments.length; i++) comments[i].style.display = 'block';
- };
- function loadMoreComments(){
- var counter = 0;
- var comments = document.getElementsByClassName('comment-post');
- for(var i=0; i<comments.length; i++) {
- if (comments[i].style.display == 'block') counter++;
- }
- if (!checkCommentsCount(max)) {
- for(var i = 0; i < (counter+com_to_load); i++) {
- comments[i].style.display = 'block';
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement