Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.9 kB
2
Indexable
Never
let match = window.matchMedia("(max-width: 770px)");

  function addButtonAll() {          
          let catCounts = match.matches ? 3 : 10;
          if($(".ddcategories-links").length){
                let match = window.matchMedia("(max-width: 770px)");
                let catCounts = match.matches ? 3 : 10;
                $.each($(".ddcategories-links"), function(i, v) {
                        let wrapperItem = $(v);
                        if (wrapperItem.find(".dd_categories-links__item").length > catCounts) {
                                wrapperItem.find(".dd_categories-links-all-view").remove();
                                $.each(wrapperItem.find(".dd_categories-links__item"), function(k, item) {
                                        if(k > (catCounts - 1)) {
                                                $(item).css({
                                                        "display": "none"
                                                });
                                                $(item).addClass("hidden");
                                        }
                                });

                                let buttonAll = `<div class="dd_categories-links-all-view">Показать еще</div>`;

                                $(".ddcategories-links").append(buttonAll);
      
                                $(".dd_categories-links_block").find(".dd_categories-links-all-view").on("click", function () {
      
                                        let button = $(this);
      
                                        $.each($(".ddcategories-links").find(".dd_categories-links__item"), function (index, val) {
                                                if (index > (catCounts - 1)) {
                                                        if ($(val).hasClass("hidden")) {
                                                                $(val).css({ "display": "inline-block" });
                                                                $(val).removeClass("hidden");
                                                                button.text("Скрыть");
                                                        } else {
                                                                $(val).css({ "display": "none" });
                                                                $(val).addClass("hidden");
                                                                button.text("Показать еще");
                                                        }
                                                }
                                        });
                                });
                        }              
                          });

                          
                  }
       
  }