1if (typeof $ === "undefined" && typeof jQuery === "function") { 2 $ = jQuery; 3} 4$(document).on('ready', function () { 5 const getClassNames = { 6 0 : "largestory", 7 1 : "replaceStory", 8 2 : "smallStory", 9 3 : "smallStory", 10 4 : "smallStory", 11 5 : "mobilesmallStory", 12 6 : "bigmiddleStory", 13 7 : "mobilesmallStory" 14 } 15 16 if (typeof $ === "undefined" && typeof jQuery === "function") { 17 $ = jQuery; 18 } 19 let sliderWidth = $('.story-curousal').width(); 20 let slideNo = 5; 21 22 if (sliderWidth < 587) { 23 slideNo = 1; 24 } else if (sliderWidth < 587) { 25 slideNo = 2; 26 } else if (sliderWidth < 761) { 27 slideNo = 3; 28 } else if (sliderWidth < 979) { 29 slideNo = 4; 30 } 31 32 // Curousal for all publishes stories 33 // $('.story-curousal').slick({ 34 // slidesToShow: slideNo, 35 // slidesToScroll: 1, 36 // autoplay: true, 37 // autoplaySpeed: 2000, 38 // fade: false, 39 // responsive: [ 40 // { 41 // breakpoint: 550, 42 // settings: { 43 // centerMode: true, 44 // } 45 // } 46 // ] 47 // }); 48 49 $story = ''; 50 $default = ''; 51 52 // Get value on form submit 53 $('.category-allow-form').on('submit', function (e) { 54 e.preventDefault(); 55 56 $story = $('.category').val(); 57 $default = $('.default').val(); 58 59 }); 60 61 //generate post grid function 62 function generatePostGrid(data, design = "1") { 63 let clsName = design ? "story-thumb-card card" : "single-story-col"; 64 if (data.length > 8) { 65 //creating array chunks 66 let mainArr = []; 67 for (let i=0; i < children.length; i += 8) { 68 let temporary; 69 temporary = children.slice(i, i + 8); 70 mainArr.push(temporary); 71 } 72 73 let parentArr = []; 74 let gridBlock; 75 for (let i = 0; i<mainArr.length; i++) { 76 77 let currentDiv = mainArr[i]; 78 gridBlock = document.createElement("div"); 79 $(gridBlock).addClass('ms-grid'); 80 $(gridBlock).attr('id', 'listing-grid'); 81 for (let j = 0; j < currentDiv.length; j++) { 82 let cssClass = getClassNames[j]; 83 let mainElm = currentDiv[j]; 84 mainElm.removeClass(); 85 mainElm.addClass(clsName); 86 mainElm.addClass(cssClass); 87 gridBlock.append(mainElm[0]); 88 parentArr.push(mainElm[0]); 89 } 90 91 gridBlock.append(parentArr); 92 } 93 $("#ajax-posts").append(gridBlock); 94 } else { 95 let gridBlock = document.createElement("div"); 96 $(gridBlock).addClass('ms-grid'); 97 $(gridBlock).attr('id', 'listing-grid'); 98 for (let i = 0; i < data.length; i++) { 99 let cssClass = getClassNames[i]; 100 let mainElm = data[i]; 101 mainElm.removeClass(); 102 mainElm.addClass(clsName); 103 mainElm.addClass(cssClass); 104 105 gridBlock.append(mainElm[0]); 106 } 107 $("#ajax-posts").append(gridBlock); 108 } 109 } 110 111 // Load more functionality 112 let ajaxUrl = $('#ajax-posts').attr('data-ajax'); 113 let post_per_page = $('#ajax-posts').attr('data-posts'); 114 let page = 1; 115 let ppp = parseInt(post_per_page); 116 117 //reinitialize the player class and load more button function 118 function reInitializePlayer(page, ppp) { 119 $.post(ajaxUrl, { 120 action: "load_post_data_ajax", 121 offset: page, 122 ppp: ppp, 123 }) 124 .success(function (posts) { 125 return posts; 126 }); 127 } 128 129 $("#more_posts").on("click", function () { 130 131 // When btn is pressed. 132 $(this).attr("disabled", true); 133 let offset = page * ppp; 134 let design = $('#listing-grid').data('design'); 135 let clsName = design ? ".story-thumb-card" : ".single-story-col"; 136 let clsName2 = design ? "story-thumb-card card" : "single-story-col"; 137 console.log({design}); 138 // Disable the button, temp. 139 $.post(ajaxUrl, { 140 action: "more_post_ajax", 141 offset: offset, 142 ppp: ppp, 143 beforeSend: function () { 144 $('body').addClass('ms_loading'); 145 }, 146 }) 147 .success(function (posts) { 148 let post_length = posts.htmlData.length; 149 let count = posts?.count?.publish; 150 if (post_length > 0) { 151 page++; 152 let jelm = $(posts.htmlData); 153 let childElm = $(jelm).find(clsName); 154 let lastGrid = $('.ms-grid:last-child'); 155 let lastPostCount = lastGrid.children().length; 156 157 let emptySlots = 8 - lastPostCount; 158 159 // let postJSON = reInitializePlayer(offset, ppp); 160 161 if (emptySlots != 0) { 162 let domChild = []; 163 164 for (let i = 0; i < emptySlots; i++) { 165 let cssClass = getClassNames[lastPostCount]; 166 let mainElm = $(childElm).eq(i); 167 mainElm.removeClass(); 168 mainElm.addClass(clsName2); 169 mainElm.addClass(cssClass); 170 domChild.push(mainElm); 171 lastPostCount++; 172 } 173 lastGrid.append(domChild); 174 175 let newGridData = []; 176 for (let i = emptySlots; i < childElm.length; i++) { 177 let mainElm = $(childElm).eq(i); 178 newGridData.push(mainElm); 179 } 180 181 if(newGridData.length > 0) { 182 generatePostGrid(newGridData, design); 183 } 184 185 } else { 186 $("#ajax-posts").append(posts.htmlData); 187 } 188 189 // reInitializePlayer(); 190 191 // CHANGE THIS! 192 $("#more_posts").attr("disabled", false); 193 let post_count = $('.single-story-col').length; 194 if (post_count >= count) { 195 $('body').addClass('ms_no_more_posts'); 196 } 197 } else { 198 $('body').addClass('ms_no_more_posts'); 199 } 200 $('body').removeClass('ms_loading'); 201 }) 202 .error(function(error) { 203 console.log("error"); 204 }); 205 }); 206 207 208 // story player on click function 209 $('#ajax-posts').on('click', '.single-story-col', function(e){ 210 let elm = $(this); 211 let url = elm.attr('data-story-url'); 212 window.loadStoryPlayer(e, elm, url); 213 214 }); 215 216 $('#ajax-posts').on('click', '.story-thumb-card', function(e){ 217 e.preventDefault(); 218 let elm = $(this); 219 let url = elm.attr('data-story-url'); 220 window.loadStoryPlayer(e, elm, url); 221 }); 222 223 $('#single-story').click(function(e) { 224 let elm = $(this); 225 let url = elm.attr('data-story-url'); 226 window.loadStoryPlayer(e, elm, url); 227 }) 228 229 $('.story-widget').each(function() { 230 if ($(this).find('div').is(':empty') && $(this).hasClass('widget-message')) { 231 $(this).children('div').append('<p class="no-stories-text">No Published Available, Publish stories before using widget</p>') 232 } 233 }) 234 235})
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.