1/* stafflist handlers */ 2jQuery(document).ready( function($) { 3 build_stafflist(); 4}); 5 6/************************************************************************************************** 7* Build a Dynamic Pager 8**************************************************************************************************/ 9var sl_current_page = false, 10 sl_total_pages = false; 11var sl_pager = new function() { 12 this.makeBtn = function(c,v){ return "<p class='pager"+c+"'>"+v+"</p>"; }; 13 this.build = function(pgobj){ //console.log(pgobj); console.log(stafflistpaths); 14 //globals 15 cur = sl_current_page = parseInt(pgobj[3]), 16 last = sl_total_pages = parseInt(pgobj[2]); 17 //one page? 18 if(pgobj[0] < 1) return "<div class='pageNum'></div>"; 19 if(last < 2) return "<div class='pageNum'>"+stafflistpaths.results+": "+(pgobj[0])+"</div>"; 20 //previous 21 html = (cur > 1 ? this.makeBtn(" wp-exclude-emoji prev", "") : this.makeBtn(" wp-exclude-emoji prev disabled", "")); //< 22 //pages 23 if(cur<=3){ 24 for(var p=1; p<=Math.min(last,5); p++){ 25 html += (p == cur ? this.makeBtn(" current disabled", cur) : this.makeBtn("", p)); 26 } 27 if(last> 5) html += this.makeBtn(" disabled", "..."); 28 if(last> 5) html += this.makeBtn("", last); 29 } else if(cur>=(last-3)){ 30 if(last-4>1) html += this.makeBtn("", 1); 31 if(last>7) html += this.makeBtn(" disabled", "..."); 32 for(p=(last-4); p<=last; p++){ 33 if(p>0) html += (p == cur ? this.makeBtn(" current disabled", cur) : this.makeBtn("", p)); 34 } 35 } else { 36 html += this.makeBtn(" default", 1); 37 if(last>7) html += this.makeBtn(" disabled", "..."); 38 html += this.makeBtn("", cur-1); 39 html += this.makeBtn(" current disabled", cur); 40 html += this.makeBtn("", cur+1); 41 if(last>7) html += this.makeBtn(" disabled", "..."); 42 html += this.makeBtn("", last); 43 } 44 //next 45 html += ((cur < pgobj[2] && pgobj[2] > 1) ? this.makeBtn(" wp-exclude-emoji next", "") : this.makeBtn(" wp-exclude-emoji next disabled", "")); //> 46 //page numbering 47 html += "<div class='pageNum'>"+stafflistpaths.pagelabel+": "+(pgobj[3])+" ("+(pgobj[4]+1)+" - "+(pgobj[5]+1)+" of "+(pgobj[0])+")</div>"; 48 return(html); 49 }; 50} 51/************************************************************************************************** 52* On Page Load, Insert the StaffList into the Container & Attach Listeners 53**************************************************************************************************/ 54function build_stafflist() { 55 56 jQuery("div.staffwrapper").each(function( index, item ){ 57 jQuery(this).attr("id","stafflist_"+index); 58 var list = jQuery(this).find("div.staffdirectory table.stafflists"); 59 var form = jQuery(this).find("div.stafflistctl"); 60 var pagers = jQuery(this).find("div.staffdirectory div.staffpager"); 61 var wait = jQuery(this).hasClass("onwait"); 62 63 var data = { action: 'ajax_build', 64 wait: wait, 65 sort: form.find("input[rel='sl_sort']").val(), 66 rows: form.find("input[rel='sl_rows']").val() } 67 68 //filter by subset, if needed 69 if(form.find("input[rel='sl_subs']").length > 0) data.subset = form.find("input[rel='sl_subs']").val(); 70 71 //fetch stafflist 72 jQuery.post(stafflistpaths.ajaxurl, data, function(response) { 73 list.html(response.html); 74 75 createTooltips(); 76 77 if(!wait){ 78 pagers.html(sl_pager.build(response.pager)) 79 .find("p.pager:not(.disabled)").on("click",function(){ 80 sl_page(jQuery(this)); 81 }); 82 } 83 84 },'JSON'); 85 86 //prevent submit 87 jQuery(item).find('.sl_search').keyup(function(e){ 88 var list = jQuery(this).closest("div.staffwrapper"); 89 var using = jQuery(this).val(); 90 //clearing the search 91 var clear = jQuery(item).find(".search-clear"); 92 clear.css({display: (using.length > 0) ? "block" : "none" }); 93 clear.off().on("click", function(){ 94 clear.prev(".sl_search").val(""); 95 refine_stafflist(list.attr("id"),""); 96 }); 97 //searching 98 if(list.hasClass('ontype') && e.which==13) return(false); 99 if(list.hasClass('onenter') && e.which!=13) return(false); 100 refine_stafflist(list.attr("id"),using); 101 }); 102 }); 103 104} 105/************************************************************************************************** 106* Handle Sorting 107**************************************************************************************************/ 108function sl_sort(el,col){ 109 var list = jQuery(el).closest("div.staffwrapper"); 110 var form = list.find("div.stafflistctl"); 111 var opt = form.find("input[rel='sl_sort']").val(); 112 opt = (opt == col) ? (opt.indexOf("-")<0 ? opt+"-" : opt) : col; 113 form.find("input[rel='sl_sort']").val(opt); 114 refine_stafflist(list.attr("id")); 115 return; 116} 117/************************************************************************************************** 118* Handle Paging 119**************************************************************************************************/ 120function sl_page(el){ 121 var list = el.closest("div.staffwrapper"); 122 var form = list.find("div.stafflistctl"); 123 124 if(el.hasClass('prev')){ page = (sl_current_page-1); } 125 else if(el.hasClass('next')){ page = (sl_current_page+1); } 126 else { page = el.html(); } 127 128 if(page < 1 || page > sl_total_pages) return; 129 130 list.find("div.staffdirectory p.pager").off("click"); 131 form.find("input[rel='sl_page']").val(page); 132 refine_stafflist(list.attr("id")); 133 return; 134} 135/************************************************************************************************** 136* Fetch Updated StaffList when changes are made to: sorting, paging, search 137**************************************************************************************************/ 138function refine_stafflist(listid, using){ 139 var list = jQuery("#"+listid); 140 //hide all tipsy 141 //jQuery('.tipsy').hide(); 142 143 var data = { 144 action: 'ajax_build', 145 rows: list.find("input[rel='sl_rows']").val(), 146 sort: list.find("input[rel='sl_sort']").val(), 147 page: list.find("input[rel='sl_page']").val(), 148 search: using || list.find("input[rel='sl_search']").val(), 149 wait: list.hasClass("onwait") 150 }; 151 152 //subsets 153 if(list.find("input[rel='sl_subs']").length > 0) data.subset = list.find("input[rel='sl_subs']").val(); 154 155 //execute 156 jQuery.post(stafflistpaths.ajaxurl, data, function(response) { 157 list.find("div.staffdirectory table.stafflists").html(response.html); 158 if(""==data.search && data.wait){ 159 list.find("div.staffdirectory div.staffpager").html(""); 160 } else { 161 list.find("div.staffdirectory div.staffpager").html(sl_pager.build(response.pager)); 162 } 163 list.find("p.pager").on("click",function(){ 164 sl_page(jQuery(this)); 165 }); 166 createTooltips(); 167 168 },'json'); 169 170 return false; 171} 172 173/************************************************************************************************** 174* Create Tooltips 175**************************************************************************************************/ 176function createTooltips(){ 177 tippy('p.contactcard', { 178 interactive: true, 179 placement: "right", 180 allowHTML: true, 181 content(reference){ 182 let s = JSON.parse(reference.getAttribute('rel')); 183 let html = ""; 184 for(key in s){ 185 if("img" == key){ 186 if(""!=s['key']) html+= "<img src='"+s[key]+"' class='stafflist_image_medium'/><br />"; 187 } else { 188 html+= "<span class='sl_property'>"+key+"</span>: "+s[key]+"<br />"; 189 } 190 } 191 return "<p>"+html+"</p>"; 192 }, 193 }); 194} 195/************************************************************************************************** 196* Done 197**************************************************************************************************/
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.