1$(function() { 2 3 sno.init(); 4 5}); 6 7 8var sno = { 9 reloadTarget: {}, 10 parentClass: '.news-grid-plugin', 11 dataTag: false, 12 13 init:function(){ 14 sno.parentPlugin = $(sno.parentClass); 15 sno.clickHandlers(); 16 sno.newslick(); 17 sno.tagInit(); 18 sno.hashUrl(); 19 }, 20 21 newsReloadData: function(obj) { 22 // if its the search then the pageNo attr won't be present 23 if(obj.attr('data-page')) { 24 var pageNo = obj.attr('data-page'); 25 } else { 26 var pageNo = 1; 27 } 28 29 var totalPerPage = sno.parentPlugin.find('ul.pagination').attr('data-page-total'); 30 31 // get existing params specified in the CMS 32 var params = JSON.parse(sno.parentPlugin.attr('data-params')); 33 34 // get new params for the ajax call 35 params['page'] = pageNo; 36 37 38 let searchTerm = obj.parents('.news-grid-plugin').find('input[name="search"]').val(); 39 params['search'] = ''; 40 if( $.trim(searchTerm) != "" && $.trim(searchTerm).length >= 3 ){ 41 params['search'] = searchTerm; 42 } 43 44 45 let tag = $('.tagging').select2('data'); 46 // console.log(tag); 47 searchTags = tag[0].text ? tag[0].text : ''; 48 // searchTags = sno.dataTag ? sno.dataTag : ''; 49 if(searchTags) { 50 //params['news-tags'] = params['search'] + ','+searchTags; 51 params['news-tags'] = searchTags; 52 //sno.dataTag = searchTags; 53 } 54 55 56 // load data 57 sno.parentPlugin.find('.ign-news-grid-content').load('/ajaxAPI .ign-news-grid-content > *',{'ajax': 1,'type':'loadPlugin','plugin':'news','params':params}, function(response, status, xhr) { 58 59 var totalRows = sno.parentPlugin.find('input[name="ign_news_total"]').val(); 60 61 // if pagination exists then update it 62 if($('ul.pagination').length) { 63 $.ajax({ 64 url: '/ajaxAPI', 65 data: {'ajax':1,'type':'loadPagination','page':pageNo,'totalRows':totalRows,'totalPerPage':totalPerPage} 66 }).done(function(data){ 67 sno.parentPlugin.find('.ign-news-grid-pagination').html(data); 68 observer.observe() // observe newly added elements 69 // reattach functions 70 $('button.ign-filter-news-btn , ul.pagination a.page-link').off('click').on('click', function(e){ 71 e.preventDefault(); 72 sno.newsReloadData($(this)); 73 }); 74 }); 75 } 76 77 // if load more button exists then add the tag to it 78 if($('a.load-more-news').length) { 79 console.log(params['news-tags']); 80 $('a.load-more-news').data("tag",params['news-tags']); 81 } 82 83 }); 84 $("html,body").animate({scrollTop:sno.parentPlugin.offset().top - 100 },"7000"); 85 }, 86 87 newsLoadMore: function(obj) { 88 console.log('trigger'); 89 //let params = {'page':2,'search':''}; 90 var params = JSON.parse(sno.parentPlugin.attr('data-params')); 91 params['page'] = parseInt(obj.data("page")); 92 93 if(sno.tagSelect) { 94 params['news-tags'] = sno.tagSelect.val(); 95 } 96 97 $('#news-holder').load('/ajaxAPI .ign-news-grid-content > *',{'ajax': 1,'type':'loadPlugin','plugin':'news','params':params}, function(response, status, xhr) { 98 let html = $('#news-holder').html(); 99 $('.ign-news-grid-content').append(html); 100 $('#news-holder').html(''); 101 obj.data("page",(params['page']+=1)); 102 103 if(html.search("max-articles-reached") > 0) { 104 obj.hide(); 105 } 106 }); 107 }, 108 109 newslick: function(){ 110 if ($('.slick-feature-slider').length) { 111 $('.slick-feature-slider').slick({ 112 arrows: true,
113 //prevArrow: false, 114 //nextArrow: false, 115 dots: true, 116 slidesToShow: 1, 117 slidesToScroll: 1, 118 autoplay: true, 119 autoplaySpeed: 5000, 120 adaptiveHeight: true 121 }); 122 } 123 }, 124 125 clickHandlers: function(){ 126 /* filter news button loads ajax */ 127 $('button.ign-filter-news-btn , ul.pagination a.page-link').click(function(e){ 128 e.preventDefault(); 129 sno.newsReloadData($(this)); 130 }); 131 /* filter news button loads ajax */ 132 $(document).on('click','#custom-single .select2-selection__choice__remove',function(e){ 133 e.preventDefault(); 134 console.log(sno); 135 //if (sno.dataTag) { 136 let url = location.href.replace(location.search, ""); 137 //console.log(url); 138 history.replaceState(null, null, url); 139 //} 140 sno.tagSelect.val(null).trigger('change'); 141 sno.setSearchHeight(); 142 sno.newsReloadData($(e.target)); 143 }); 144 145 $('a.load-more-news').on("click",function(e){ 146 e.preventDefault(); 147 sno.newsLoadMore($(this)); 148 }); 149 150 }, 151 152 tagInit: function(){ 153 if ($(".tagging").length) { 154 sno.tagSelect = $(".tagging"); 155 sno.tagSelect.select2({ 156 placeholder: "filter by category", 157 // allowClear: true, 158 tags: true, 159 // maximumSelectionLength: 1, 160 templateSelection: formatState, 161 matcher: matchCustom 162 }); 163 164 sno.dataTag = sno.tagSelect.val(); 165 166 sno.tagSelect.trigger('change.select2'); // Notify only Select2 of changes 167 // sno.tagSelect.on("change", function (e) { 168 // sno.setSearchHeight(); 169 // sno.newsReloadData($(e.target)); 170 // }); 171 sno.tagSelect.on('select2:select', function (e) { 172 var data = e.params.data; 173 sno.setSearchHeight(); 174 sno.newsReloadData($(e.target)); 175 176 let url = location.href.replace(location.search, ""); 177 history.replaceState(null, null, url+'?filter='+data.text); 178 179 }); 180 181 $('input[name="search"]').on('input', function() { 182 sno.newsReloadData($(this)); 183 }); 184 185 console.log(sno.dataTag); 186 } 187 }, 188 189 hashUrl: function(){ 190 let opt = $(".tagging option"); 191 let options = {}; 192 if (opt.length) { 193 options = opt.map(function(){ 194 if ($.trim(this.value).length > 0) { 195 return this.value; 196 } 197 }).get(); 198 199 let stricmp = options.toString(); 200 //sno.dataTag = sno.parentPlugin.attr('data-tag'); 201 202 if(sno.dataTag.length){ 203 if (stricmp.toLowerCase().indexOf(sno.dataTag.toLowerCase()) > -1) { 204 let idx = stricmp.toLowerCase().indexOf(sno.dataTag.toLowerCase()); 205 sno.tagSelect.val(sno.dataTag).trigger('change'); 206 sno.setSearchHeight(); 207 sno.newsReloadData(opt); 208 } 209 } 210 211 } 212 213 214 }, 215 216 setSearchHeight: function(){ 217 let height = $('.select2-selection__rendered',sno.parentPlugin).innerHeight(); 218 $('input[name="search"]',sno.parentPlugin).css({'height':height}); 219 } 220 221} 222 223 224function matchCustom(params, data) { 225 // If there are no search terms, return all of the data 226 if ($.trim(params.term) === '') { 227 return data; 228 } 229 230 // Do not display the item if there is no 'text' property 231 if (typeof data.text === 'undefined') { 232 return null; 233 } 234 235 // `params.term` should be the term that is used for searching 236 // `data.text` is the text that is displayed for the data object 237 if (data.text.toLowerCase().indexOf(params.term) > -1) { 238 var modifiedData = $.extend({}, data, true); 239 modifiedData.text += ' (matched)'; 240 241 // You can return modified objects from here 242 // This includes matching the `children` how you want in nested data sets 243 return modifiedData; 244 } 245 246 // Return `null` if the term should not be displayed 247 return null; 248} 249 250function formatState (state) { 251 252 if (!state.id) { 253 return state.text; 254 } 255 256 var $state = $( 257 '<div class="select2-selection__choice" id="custom-single" title="'+state.element.value+'" data-select2-id=""><span class="select2-selection__choice__remove" role="presentation">Ã</span>'+state.element.value+'</div>' 258 ); 259 260 // Use .text() instead of HTML string concatenation to avoid script injection issues 261 $state.find(".selection").text(state.text); 262 return $state; 263}; 264
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.