Changeset 2254118
- Timestamp:
- 03/04/2020 10:02:27 AM (6 years ago)
- Location:
- swiper-lite/trunk
- Files:
-
- 2 edited
-
js/post-swiper.js (modified) (1 diff)
-
post-swiper.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
swiper-lite/trunk/js/post-swiper.js
r2227730 r2254118 1 1 jQuery(function($){ 2 3 4 2 5 3 let likedPosts = []; 6 4 7 8 9 5 let bodyClass = $('body').attr('class').replace(/\s/g,'_').trim(); 10 6 11 12 13 7 if (Cookies.get(`likedPosts_${bodyClass}`)){ 14 15 8 likedPosts = JSON.parse(Cookies.get(`likedPosts_${bodyClass}`)); 16 17 9 renderLikedPosts(); 18 19 10 for (let i = 0; i<likedPosts.length; i++) { 20 21 11 $('.postswiper-posttitle').each(function(){ 22 23 12 let thisTitle = $(this).html(); 24 25 13 if (thisTitle==likedPosts[i]){ 26 27 14 $(this).parent().parent().hide(); 28 29 15 } 30 31 16 }); 32 33 17 } 34 35 18 } 36 19 37 38 39 20 $('.postswiper-post').on('swiperight',function(){ 40 41 21 if ( !$(this).hasClass('rot-left') && !$(this).hasClass('rot-right') ){ 42 43 22 $(this).addClass('rot-left'); 44 45 23 $('.postswiper-post').find('.status').remove(); 46 47 48 24 49 25 $(this).append('<div class="status like">Like!</div>'); 50 26 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 }); 51 35 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>'); 61 41 } 62 42 63 43 }); 64 44 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)'); 81 60 }); 82 61 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 } 115 72 }); 116 73 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 + ')'); 137 79 } 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'); 153 82 } 154 155 if ( $('.postswiper-likedlist-opener').hasClass('disabled') ) {156 157 $('.postswiper-likedlist-opener').removeClass('disabled');158 159 }160 161 83 } 162 84 163 164 165 85 function resizeWrapper(){ 166 167 86 let postHeight = 0; 168 169 87 $('.postswiper-post').each(function(){ 170 171 88 let thisHeight = parseInt($(this).height()); 172 173 89 if (thisHeight > postHeight) { 174 175 90 postHeight = thisHeight; 176 177 91 } 178 179 92 }); 180 181 93 $('.postswiper-wrapper').css('height',postHeight+60); 182 183 94 $('.postswiper-post').css('height',postHeight+30); 184 185 95 } 186 96 187 188 189 97 $(window).resize(function(){ 190 191 98 resizeWrapper(); 192 193 99 }); 194 195 196 100 197 101 resizeWrapper(); 198 102 199 200 201 103 }); 202 -
swiper-lite/trunk/post-swiper.php
r2231651 r2254118 4 4 Plugin URI: https://southdevondigital.com/plugins/ 5 5 Description: 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. 06 Version: 1.2.1 7 7 Author: South Devon Digital 8 8 Author URI: https://southdevondigital.com
Note: See TracChangeset
for help on using the changeset viewer.