Plugin Directory

Changeset 2254118


Ignore:
Timestamp:
03/04/2020 10:02:27 AM (6 years ago)
Author:
southdevondigital
Message:

V1.2.1 - Added expiry to cookies to save swipes beyond browser session

Location:
swiper-lite/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • swiper-lite/trunk/js/post-swiper.js

    r2227730 r2254118  
    11jQuery(function($){
    2 
    3 
    42
    53    let likedPosts = [];
    64
    7 
    8 
    95    let bodyClass = $('body').attr('class').replace(/\s/g,'_').trim();
    106
    11 
    12 
    137    if (Cookies.get(`likedPosts_${bodyClass}`)){
    14 
    158        likedPosts = JSON.parse(Cookies.get(`likedPosts_${bodyClass}`));
    16 
    179        renderLikedPosts();
    18 
    1910        for (let i = 0; i<likedPosts.length; i++) {
    20 
    2111            $('.postswiper-posttitle').each(function(){
    22 
    2312                let thisTitle = $(this).html();
    24 
    2513                if (thisTitle==likedPosts[i]){
    26 
    2714                    $(this).parent().parent().hide();
    28 
    2915                }
    30 
    3116            });
    32 
    3317        }
    34 
    3518    }
    3619
    37 
    38 
    3920    $('.postswiper-post').on('swiperight',function(){
    40 
    4121        if ( !$(this).hasClass('rot-left') && !$(this).hasClass('rot-right') ){
    42 
    4322            $(this).addClass('rot-left');
    44 
    4523            $('.postswiper-post').find('.status').remove();
    46 
    47 
    4824
    4925            $(this).append('<div class="status like">Like!</div>');
    5026
     27            let postTitle = $(this).find('.postswiper-posttitle').html();
     28            likedPosts.push(postTitle);
     29            Cookies.set(`likedPosts_${bodyClass}`,JSON.stringify(likedPosts), {
     30                expires: 999
     31            });
     32            renderLikedPosts();
     33        }
     34    });
    5135
    52 
    53             let postTitle = $(this).find('.postswiper-posttitle').html();
    54 
    55             likedPosts.push(postTitle);
    56 
    57             Cookies.set(`likedPosts_${bodyClass}`,JSON.stringify(likedPosts));
    58 
    59             renderLikedPosts();
    60 
     36    $('.postswiper-post').on('swipeleft',function(){
     37        if ( !$(this).hasClass('rot-left') && !$(this).hasClass('rot-right') ){
     38            $(this).addClass('rot-right');
     39            $('.postswiper-post').find('.status').remove();
     40            $(this).append('<div class="status dislike">Dislike!</div>');
    6141        }
    6242
    6343    });
    6444
    65 
    66 
    67     $('.postswiper-post').on('swipeleft',function(){
    68 
    69         if ( !$(this).hasClass('rot-left') && !$(this).hasClass('rot-right') ){
    70 
    71             $(this).addClass('rot-right');
    72 
    73             $('.postswiper-post').find('.status').remove();
    74 
    75             $(this).append('<div class="status dislike">Dislike!</div>');
    76 
    77         }
    78 
    79 
    80 
     45    $('#swiper-start-again').on('click',function(e){
     46        e.preventDefault();
     47        $('.postswiper-likedlist-list').slideUp();
     48        Cookies.remove(`likedPosts_${bodyClass}`);
     49        $('.postswiper-post').each(function(){
     50            $(this).hide();
     51            $(this).find('.status').remove();
     52            $(this).removeClass('rot-left');
     53            $(this).removeClass('rot-right');
     54            $(this).fadeIn();
     55        });
     56        likedPosts = [];
     57        renderLikedPosts();
     58        $('.postswiper-likedlist-opener').addClass('disabled').removeClass('toggle-open');
     59        $('.postswiper-likedlist-count').text('View my liked items (0)');
    8160    });
    8261
    83 
    84 
    85     $('#swiper-start-again').on('click',function(e){
    86 
    87         e.preventDefault();
    88 
    89         $('.postswiper-likedlist-list').slideUp();
    90 
    91         Cookies.remove(`likedPosts_${bodyClass}`);
    92 
    93         $('.postswiper-post').each(function(){
    94 
    95             $(this).hide();
    96 
    97             $(this).find('.status').remove();
    98 
    99             $(this).removeClass('rot-left');
    100 
    101             $(this).removeClass('rot-right');
    102 
    103             $(this).fadeIn();
    104 
    105         });
    106 
    107         likedPosts = [];
    108 
    109         renderLikedPosts();
    110 
    111         $('.postswiper-likedlist-opener').addClass('disabled').removeClass('toggle-open');
    112 
    113         $('.postswiper-likedlist-count').text('View my liked items (0)');
    114 
     62    $('.postswiper-likedlist-opener').on('click',function(){
     63        if (likedPosts.length > 0) {
     64            if ( $(this).hasClass('toggle-open') ){
     65                $(this).removeClass('toggle-open');
     66                $('.postswiper-likedlist-list').slideUp();
     67            } else {
     68                $(this).addClass('toggle-open');
     69                $('.postswiper-likedlist-list').slideDown();
     70            }
     71        }
    11572    });
    11673
    117 
    118 
    119     $('.postswiper-likedlist-opener').on('click',function(){
    120 
    121         if (likedPosts.length > 0) {
    122 
    123             if ( $(this).hasClass('toggle-open') ){
    124 
    125                 $(this).removeClass('toggle-open');
    126 
    127                 $('.postswiper-likedlist-list').slideUp();
    128 
    129             } else {
    130 
    131                 $(this).addClass('toggle-open');
    132 
    133                 $('.postswiper-likedlist-list').slideDown();
    134 
    135             }
    136 
     74    function renderLikedPosts(){
     75        $('.postswiper-likedlist-list').html('');
     76        for (let i = 0; i<likedPosts.length; i++) {
     77            $('.postswiper-likedlist-list').append('<div class="postswiper-likedlist-liked">' + likedPosts[i] + '</div>');
     78            $('.postswiper-likedlist-count').text('View my liked items (' + likedPosts.length + ')');
    13779        }
    138 
    139     });
    140 
    141 
    142 
    143     function renderLikedPosts(){
    144 
    145         $('.postswiper-likedlist-list').html('');
    146 
    147         for (let i = 0; i<likedPosts.length; i++) {
    148 
    149             $('.postswiper-likedlist-list').append('<div class="postswiper-likedlist-liked">' + likedPosts[i] + '</div>');
    150 
    151             $('.postswiper-likedlist-count').text('View my liked items (' + likedPosts.length + ')');
    152 
     80        if ( $('.postswiper-likedlist-opener').hasClass('disabled') ) {
     81            $('.postswiper-likedlist-opener').removeClass('disabled');
    15382        }
    154 
    155         if ( $('.postswiper-likedlist-opener').hasClass('disabled') ) {
    156 
    157             $('.postswiper-likedlist-opener').removeClass('disabled');
    158 
    159         }
    160 
    16183    }
    16284
    163 
    164 
    16585    function resizeWrapper(){
    166 
    16786        let postHeight = 0;
    168 
    16987        $('.postswiper-post').each(function(){
    170 
    17188            let thisHeight = parseInt($(this).height());
    172 
    17389            if (thisHeight > postHeight) {
    174 
    17590                postHeight = thisHeight;
    176 
    17791            }
    178 
    17992        });
    180 
    18193        $('.postswiper-wrapper').css('height',postHeight+60);
    182 
    18394        $('.postswiper-post').css('height',postHeight+30);
    184 
    18595    }
    18696
    187 
    188 
    18997    $(window).resize(function(){
    190 
    19198        resizeWrapper();
    192 
    19399    });
    194 
    195 
    196100
    197101    resizeWrapper();
    198102
    199 
    200 
    201103});
    202 
  • swiper-lite/trunk/post-swiper.php

    r2231651 r2254118  
    44Plugin URI:   https://southdevondigital.com/plugins/
    55Description:  Swiper gives you the ability to embed Tinder style swipable cards with content from your posts or pages. Users can swipe through these cards, left to 'dislike', or right to 'like'. Liked items will then be saved in a list below.
    6 Version:      1.2.0
     6Version:      1.2.1
    77Author:       South Devon Digital
    88Author URI:   https://southdevondigital.com
Note: See TracChangeset for help on using the changeset viewer.