Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var max = 2; // сколько комментариев выводить
  2. var com_to_load = 2;  // сколько подгружать кнопкой
  3.  
  4. $(document).ready(function() {
  5.  
  6.     $(".slider_btn").on("click", function(){
  7.         $(this).toggleClass("open");
  8.         $(this).parent().find("ul:first").slideToggle(300);
  9.     });
  10.  
  11.     $(".cat-list li.active").parents("li.slider").find(".slider_btn:first").addClass("open");
  12.     $(".cat-list li.active").parents("ul").show();
  13.  
  14.     var slider_width = $('.menu-block').width() + 2;
  15.     var deviceWidth = $(window).width();
  16.  
  17.     /*Mobile menu*/
  18.     $(".mobile-categories h2").on("click", function() {
  19.         $(this).toggleClass("open-menu");
  20.         $(this).next(".cat-list").slideToggle("fast");
  21.     });
  22.  
  23.     $(".show-menu-toggle").on("click", function() {
  24.         $(this).parent().find(".mobile-top-menu").slideToggle("fast");
  25.         ;
  26.     });
  27.  
  28.     /*Fix mobile top menu position if login admin*/
  29.     if ($("body").hasClass("admin-on-site")) {
  30.         $("body").find(".mobile-top-panel").addClass("position-fix");
  31.     }
  32.  
  33.     var tabContainers = $('.product-tabs-container > div');
  34.         tabContainers.hide().filter(':first').show();
  35.  
  36.         $('.product-tabs li a').click(function () {
  37.             tabContainers.hide();
  38.             tabContainers.filter(this.hash).fadeIn("fast");
  39.             $('.product-tabs li').removeClass('active');
  40.             $(this).parent().addClass('active');
  41.             return false;
  42.         }).filter(':first').click();
  43.  
  44.  
  45.     $('.menu-block li a').each(function(){ // получаем все нужные нам ссылки  
  46.       var location = window.location.protocol+'//'+window.location.hostname+window.location.pathname; // получаем адрес страницы без параметров
  47.       var link = this.href;// получаем адрес ссылки
  48.       if(location == link){// при совпадении адреса ссылки и адреса окна
  49.         $(this).parents('li').addClass('active');  //добавляем класс
  50.       }
  51.     });
  52.  
  53.     $(".cat-list li.active").find(".slider_btn:first").trigger("click");
  54.  
  55.     /*Выводим надпись "Выберите цвет" в зависимости от присутствия списка*/
  56.     var anchors = document.getElementsByTagName('select');
  57.     for(var i=0; i<anchors.length; i++) {
  58.         if (anchors[i].className != "") {
  59.             document.getElementById('select-color-title').innerHTML = 'Выберите цвет:';
  60.         break;
  61.         }
  62.     }
  63.     var a_array = document.getElementsByTagName('a');
  64.     for(var i=0; i<a_array.length; i++) {
  65.     if (a_array[i].className == "addToCart buy-product buy") a_array[i].innerHTML = 'Купить';
  66.     if (a_array[i].className == "addToCompare") a_array[i].innerHTML = 'Добавить к сравнению';
  67.     }
  68.  
  69.     document.getElementsByTagName('form')[2].style.display = 'none';
  70.     var parametrs = new Array();
  71.     var comments = document.getElementsByTagName('div');
  72.     for(var i=0; i<comments.length; i++){  
  73.         if (comments[i].className=="comment-post"){
  74.             var autor = comments[i].getElementsByTagName('span')[0];
  75.             var comment = comments[i].getElementsByTagName('p')[0];
  76.             comment.innerHTML+='<br><div class="reply-button">Ответить</div>';
  77.             var a = autor.innerHTML;
  78.             var reply = 'commentReply("'+a+'");';
  79.             parametrs.push(reply);
  80.         }
  81.     }
  82.  
  83.     var replies = document.getElementsByClassName('reply-button');
  84.     for(var i=0; i<replies.length; i++){
  85.     replies[i].setAttribute("onclick", parametrs[i]);
  86.     }
  87.     setStyle();
  88.     hideComments();
  89.     checkCommentsCount(max);
  90.    
  91. });
  92.  
  93. function commentReply(name){
  94.    forms = document.getElementsByTagName('textarea');
  95.    var f = document.getElementsByTagName('form')[2];
  96.    if (f.style.display == 'none') { f.style.display = 'block'; f.focus(); }
  97.    forms[0].value += name + ", ";
  98.    forms[0].focus();
  99. };
  100.  
  101. function showCommentForm() { document.getElementsByTagName('form')[2].style.display = 'block'; }
  102.  
  103. function hideComments(){
  104.   var comments = document.getElementsByClassName('comment-post');
  105.   if (comments.length > max) {
  106.     for(var i=comments.length; i>max; i--) {
  107.      comments[i-1].style.display = 'none';
  108.     }
  109.   }
  110. };
  111.  
  112. function checkCommentsCount(max){
  113.   var no_hide_comments = true;
  114.   var button = document.getElementById('load-more-comments');  
  115.   var comments = document.getElementsByClassName('comment-post');
  116.   for(var i=0; i<comments.length; i++) {
  117.     if (comments[i].style.display == 'none') no_hide_comments = false;
  118.   }
  119.   if (no_hide_comments == true) { button.innerHTML = "<br>Комментариев больше нет :("; return true; }
  120.   else {
  121.     if (document.getElementsByClassName('comment-post').length > max) {
  122.         var attribute = 'loadMoreComments();';
  123.         button.innerHTML = '<br><div id="load-comments-button">Загрузить еще</div>';
  124.         button.setAttribute("onclick", attribute);
  125.         return false;
  126.     }
  127.   }
  128. };
  129.  
  130. function setStyle() {
  131.    var comments = document.getElementsByClassName('comment-post');
  132.    for(var i=0; i<comments.length; i++) comments[i].style.display = 'block';
  133. };
  134.  
  135. function loadMoreComments(){
  136.   var counter = 0;
  137.   var comments = document.getElementsByClassName('comment-post');
  138.   for(var i=0; i<comments.length; i++) {
  139.         if (comments[i].style.display == 'block') counter++;
  140.   }
  141.   if (!checkCommentsCount(max)) {
  142.     for(var i = 0; i < (counter+com_to_load); i++) {
  143.       comments[i].style.display = 'block';
  144.     }
  145.   }
  146. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement