1// ALL FUNCTIONS MUST BE INSIDE jQuery(document).ready(async function($) {});<br /> 2 3// NOTE: the contents of this file should be moved to hp-project.js before deployment -- TW 4 5/* 6functions: 7nav2select() 8resources_carousel_nav() 9resources_menu_show_hide() 10pagination_anchors() 11*/ 12 13jQuery(document).ready(function($) { 14 15 /** 16 * nav2select() 17 * change a ul list nav or button set to a dropdown 18 * 19 * see also /assets/css/style-tw.css nav2select 20 * 21 * if client requests full control of dropdown, see: 22 * https://blog.logrocket.com/creating-custom-select-dropdown-css/ 23 * https://www.w3schools.com/howto/howto_custom_select.asp 24 */ 25 if ($('nav.menu-news')) { 26 nav2select($('nav.menu-news'),'ul'); 27 } 28 if ($('.page-toggles')) { 29 nav2select($('.page-toggles'),'buttons'); 30 } 31 function nav2select($obj,$type) { 32 let $select = '<select title="Navigation" name="" class="menu-news-select" id="">'; 33 //$select += '<option>--select one--</option>'; 34 if ($type == 'ul') { 35 let $ul = $obj.find('li'); 36 $.each($ul,function($k,$v){ 37 let $href = $(this).find('a').attr('href'); 38 let $text = $(this).find('a').find('span').text(); 39 let $selected = ''; 40 if ($(this).hasClass('current-menu-item')) { 41 $selected = ' selected="selected"'; 42 } 43 $select += '<option value="'+$href+'"'+$selected+'>'+$text+'</option>'; 44 }); 45 }//if ($type == 'ul') { 46 if ($type == 'buttons') { 47 let $buttons = $obj.find('.wp-block-buttons div'); 48 $.each($buttons,function($k,$v){ 49 let $a = $(this).find('a'); 50 let $href = $a.attr('href'); 51 let $text = $a.text(); 52 let $selected = ''; 53 if ($(this).hasClass('wp-block-button selected')) { 54 $selected = ' selected="selected"'; 55 } 56 $select += '<option value="'+$href+'"'+$selected+'>'+$text+'</option>'; 57 }); 58 }// /if ($type == 'buttons') { 59 $select += '</select>'; 60 $obj.append($select); 61 62 // navigate on select, see also this->resources_menu_show_hide() 63 if (!$('nav.menu-news').hasClass('menu-resources')) { 64 $(document).on('change','.menu-news-select',function($e){ 65 let $href = $(this).find('option:selected').val(); 66 window.location = $href; 67 }); 68 } 69 }// /function nav2select() { 70 71 /** 72 * resources_carousel_nav() 73 * 74 * DO NOT put this in blocks/lemelson-resources-carousel/render.php 75 * the file will replace && below with && -- caused by ACF blocks afaik 76 * feh :( 77 */ 78 if ($('.resources-container')) { 79 // set the initial conditions ===== 80 let $group = $('.resources-container').find('.tout-2-group'); 81 $.each($group,function($k,$v){ 82 let $touts = $(this).find('li.wp-block-post'); 83 84 // hide > 4 touts 85 $.each($touts,function($k2,$v2){ 86 if ($k2 >= 4) {$(this).hide();} 87 }); 88 89 // get the navigation buttons 90 let $nav_bns = $(this).closest('.tout-2-container').find('.carousel-nav-buttons'); 91 92 // disable the back button on page load 93 $nav_bns.addClass('carousel-nav-back-button-disabled'); 94 95 // disable back && next navigation if fewer than 4 touts 96 if ($touts.length <= 4) { 97 $nav_bns.addClass('carousel-nav-buttons-disabled'); 98 } 99 }); 100 // /set the initial conditions ===== 101 102 // run the back/next buttons ===== 103 $('.carousel-nav-back').on('click',function($e){ 104 resources_carousel_nav('back',$(this)); 105 }); 106 $('.carousel-nav-next').on('click',function($e){ 107 resources_carousel_nav('next',$(this)); 108 }); 109 var $nums = []; 110 // /run the back/next buttons ===== 111 112 }// if ($('.resources-container')) { 113 function resources_carousel_nav($dir,$obj) { 114 const $touts = $obj.closest('.resources-container').find('li.wp-block-post'); 115 const $touts_count = $touts.length; 116 // console.log('$touts_count',$touts_count); 117 118 // get the navigation buttons 119 let $nav_bns = $obj.closest('.resources-container').find('.carousel-nav-buttons'); 120 121 // stop back && next navigation if fewer than 4 touts 122 if ($touts_count <= 4) { 123 $nav_bns.addClass('carousel-nav-buttons-disabled'); 124 return false; 125 } 126 127 let $n = -1; 128 let $proceed = true;
129 $.each($touts,function($k,$v){ 130 if($(this).is(':visible')) { 131 $n++; 132 let $key = $k; 133 if ($dir == 'back') {$key--;} 134 if ($dir == 'next') {$key++;} 135 136 if ($dir == 'back' && $key < 0) { 137 $proceed = false; 138 return false; 139 } 140 if ($dir == 'next' && $key == $touts_count) { 141 $proceed = false; 142 return false; 143 } 144 $nums[$n] = $key; 145 } 146 }); 147 // console.log('$nums',$nums); 148 149 // turn off the nav back arrow 150 if (typeof $nums[0] === 'undefined' || $nums[0] === 0) { 151 $nav_bns.addClass('carousel-nav-back-button-disabled'); 152 } 153 else { 154 $nav_bns.removeClass('carousel-nav-back-button-disabled'); 155 } 156 157 // turn off the nav next arrow 158 if (typeof $nums[3] !== 'undefined' && $nums[3] == ($touts_count - 1)) { 159 $nav_bns.addClass('carousel-nav-next-button-disabled'); 160 } 161 else { 162 $nav_bns.removeClass('carousel-nav-next-button-disabled'); 163 } 164 165 if (!$proceed) {return false;} 166 $touts.hide(); 167 $.each($nums,function($k,$v){ 168 $.each($touts,function($k2,$v2){ 169 if ($k2 == $v) { 170 $(this).show(); 171 shave_content($(this)); 172 } 173 }); 174 }); 175 }// /function resources_carousel_nav($dir,$obj) { 176 177 /** 178 * resources_menu_show_hide() 179 */ 180 if ($('.menu-resources').length > 0) { 181 let $anchor = window.location.hash; 182 // on page load, if anchor exists, show only the corresponding section 183 if ($anchor != '') { 184 $('.tout-2-group').hide(); 185 let $navitems = $('.menu-resources').find('ul li'); 186 $navitems.each(function($k,$v){ 187 let $lnk = $(this).find('a'); 188 if ($lnk.attr('href') == $anchor) { 189 resources_menu_show_hide($lnk); 190 return false; 191 } 192 }); 193 } 194 // on page nav item click, show only the corresponding section 195 $(document).on('click','.menu-resources .wp-block-navigation-item__content',function($e){ 196 $e.preventDefault(); 197 resources_menu_show_hide($(this)); 198 }); 199 // navigate on select, see also this->nav2select() 200 if ($('nav.menu-news') && $('nav.menu-news').hasClass('menu-resources')) { 201 $(document).on('change','.menu-news-select',function($e){ 202 let $href = $(this).find('option:selected').val(); 203 resources_menu_show_hide($href); 204 }); 205 } 206 }// /if ($('.menu-resources').length > 0) { 207 function resources_menu_show_hide($obj) { 208 // FIRST show all groups 209 $('.tout-2-group').fadeIn(); 210 211 // get the target group 212 let $id = ''; 213 // if $obj is the value from a dropdown: 214 if (typeof $obj !== 'object') {$id = $obj;} 215 // if $obj is a link object: 216 else {$id = $obj.attr('href');} 217 218 // if "all" is clicked, skip the hides below 219 if ($id === '#all' || $id === '') {return false;} 220 221 // loop the groups and hide all but the target group 222 let $nav = $('.menu-resources li'); 223 $nav.each(function($i,$v){ 224 let $nav_id = $(this).find('a').attr('href'); 225 if ($nav_id !== $id) { 226 $($nav_id).hide(); 227 } 228 }); 229 230 }// /function resources_menu_show_hide() { 231 232});// /jQuery(document).ready(function($) {
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.