Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.34 KB | None | 0 0
  1. /* Group related articles on mobile for single casino pages */
  2. (function ($) {
  3.  
  4.     function groupArticles() {
  5.         var articles = $( '.single-casino .casino-articles' );
  6.    
  7.         if ( matchMedia('only screen and (max-width: 576px)').matches) {
  8.  
  9.             articles.find( '.ast-col-md-4' ).each(function (i, e) {
  10.                 var postCatSlug = $( this ).data( 'cat' );
  11.                 var postCatName = $( this ).data( 'cat-name' );
  12.                 //Build the mobile category sections
  13.                 if ( !$( '.mobile-articles .cat-' + postCatSlug ).length ) {
  14.                     $( '.mobile-articles' ).append( '<div class="cat-' + postCatSlug + '"><h3 class="article-group-title">' + postCatName + '<span class="toggle">+</span></span></h3><div class="group-inner"></div></div></div>' );
  15.                 }
  16.                 //Insert the posts
  17.                 var clonedEl = $( this ).clone();
  18.                 clonedEl.appendTo( '.mobile-articles .cat-' + postCatSlug + ' .group-inner' );     
  19.             });
  20.  
  21.             $( '.desktop-articles' ).hide();
  22.  
  23.             $( '.article-group-title' ).click(function (e) {
  24.                 e.preventDefault();
  25.                 $( this ).next( '.group-inner' ).slideToggle();
  26.                 var text = $( this ).find( '.toggle' ).text();
  27.                 $( this ).find( '.toggle' ).text( text == '+' ? '-' : '+');
  28.             });
  29.            
  30.         } else {
  31.             $( '.desktop-articles' ).show();
  32.             $( '.mobile-articles' ).empty();
  33.         }
  34.     }
  35.     groupArticles();
  36.     window.addEventListener('resize', groupArticles);
  37. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement