1/* UCOP Main Javascripts */ 2 3$(document).ready(function() { 4 populateIncludeNodes().finally(() => { 5 $('input.search-query').DefaultValue("Search"); 6 $('input.firstname').DefaultValue("First Name"); 7 $('input.lastname').DefaultValue("Last Name"); 8 $('input.department').DefaultValue("Department"); 9 10 // update directory-search link 11 const dsLink = $('a[href *= "directory-search/index.php"]') 12 const dsForm = $('form[action *= "directory-search/index.php"]') 13 const dsUrl = dsLink.attr('href').replace('php', 'html'); 14 dsLink.attr('href', dsUrl); 15 dsForm.attr('action', dsUrl); 16 dsForm.attr('method', 'get'); 17 18 19 // override double org chart and default text on Presidents page, hidden by default, switch text then show 20 // var regex = new RegExp( 'ucop.edu/president/'); 21 // if( regex.test(window.location) ){ 22 // console.log('janet'); 23 // $( '.span6 a.icon.staff' ).text( 'UC Org Chart' ); 24 // $( '.span6 a.icon.org' ).text( 'UCOP Org Chart' ); 25 // $( '.span6 a.icon.org, .span6 a.icon.staff' ).css('visibility', 'visible'); 26 // } 27 // end override 28 29 30 // need to do this polling thing to make sure that these nodes are inserted before we do stuff to them 31 const key = setInterval(() => { 32 if ($('li.dropdown')[0]) { 33 setTimeout(function() { 34 $('li.dropdown').hoverIntent(function () { 35 $(this).addClass("hover")},function () { 36 $(this).removeClass("hover"); 37 }); 38 39 $('li.dropdown').focusin(function () { 40 $(this).addClass("focus"); 41 }); 42 $('li.dropdown').focusout(function () { 43 $(this).removeClass("focus"); 44 }); 45 fixMenuLinks(); 46 skipMenu(); // -SMB UCA-2 47 48 clearInterval(key) 49 }, 15); 50 } 51 }, 20); 52 53 54 55 $('.flexslider').flexslider({ 56 animation: "slide", 57 controlsContainer: ".flex-container" 58 }); 59 60 61 $('#search-form').attr('action', '//ucop.edu/search/index.html'); 62 $('#search-form').submit(function(){ 63 var q = encodeURI( $(this).find('#query-field').val() ); 64 if(q == '') 65 return false; 66 }); 67 68 //provide skip link after megamenu toggles - SMB UCA-2 69 function skipMenu(){ 70 var skipText = $(".skip-menu").parent().prev("a").text(); 71 var linkTarget = $(".skip-menu").closest(".dropdown").next("li").children(":first"); 72 var breadCrumbs = $(".breadcrumb li:first-child a"); 73 74 // test to see if megamenu is last item in nav, if so set focus to breadcrumbs 75 if ($(".skip-menu").closest(".dropdown").is(':last-child')){ 76 $(".skip-menu").on("click", function(){ 77 breadCrumbs.focus(); 78 }); 79 } else { 80 $(".skip-menu").on("click", function(){ 81 linkTarget.focus(); 82 }); 83 }; 84 85 $(".skip-menu").text("Skip" + skipText + "menu"); 86 }; 87 88 // Highlighting top nav menu items in the absence of pre-SSI script formats 89 90 function fixMenuLinks(){ 91 if (document.URL === "https://ucop.edu/" || 92 document.URL === "https://www.ucop.edu/" || 93 document.URL === "https://www.ucop.edu/index.html" || 94 document.URL === "https://ucop.edu/index.html" || 95 document.URL === "https://qa.ucop.edu/" || 96 document.URL === "https://beta.ucop.edu/" || 97 document.URL === "https://dev.ucop.edu/" || 98 document.URL === "https://dev.beta.ucop.edu/") { 99 100 $("#ariatopnav > li:first-child").addClass("active"); 101 }else if (window.location.href.indexOf("ucop.edu/about/") > -1) { 102 $("#ariatopnav > li:nth-child(2)").addClass("active"); 103 }else if (window.location.href.indexOf("ucop.edu/initiatives/") > -1) { 104 $("#ariatopnav > li:last-child").addClass("active"); 105 }else if (window.location.hostname !== "policy.ucop.edu"){ 106 $("#ariatopnav > li:nth-child(3)").addClass("active"); 107 }else if (window.location.hostname === "policy.ucop.edu"){ 108 $("#ariatopnav a").each( function() { 109 var href = $(this).attr('href'); 110 if( !(/http/.test(href)) ){ 111 $(this).attr('href', 'http://ucop.edu' + href); 112 } 113 }); 114 } 115 }; 116 117 118 // Remove title attribute from skip-link - UCA-31 119 $(".skip-link").removeAttr("title") 120 121 // Fix tab focus after skip-link for IE 122 $("#content").attr("tabindex", "-1") ; 123 124 125 }) 126 127}); 128 129 130// Changes to the Default JQuery UI 1.12.1 Accordion Widget 131 132// set the accordion headers' tabindex to 0 by default 133$(function() { 134 $( "#accordion" ).accordion({ 135 heightStyle: "content", 136 //active: 0 137 }); 138 $( "#accordion .ui-accordion-header").attr("tabindex",0) 139 140 // when accordion header is clicked, send #id to URL 141 $(function(e) { 142 var accordionHeader = $('.ui-accordion-header'); 143 // callback adds ID as hash to URL string 144 var setter = function(elm){ 145 // var a = this; 146 var id = elm.id; 147 history.replaceState({ 148 }, elm, "#" + id); 149 } 150 151 // mouse clicks 152 accordionHeader.on("click", function(){ 153 var _this = this; 154 setter(_this); 155 });
156 157 158 //keyboard enter 159 accordionHeader.on('keyup',function(event) { 160 if (event.which === 13) { 161 var _this = this; 162 setter(_this); 163 }; 164 }); 165 166 //get hash from URL 167 var hash = window.location.hash; 168 //set that tab to active 169 var openTab = $(hash).index()/2 170 $( "#accordion" ).accordion( "option", "active", openTab); 171 if (hash == ""){ 172 $( "#accordion" ).accordion( "option", "active", 0); 173 } 174 }); 175}); 176 177 178 179// redefining _toggle and _keydown methods of ui.accordion - SMB UCA-15 180 181var _toggle = $.ui.accordion.prototype._toggle; 182$.widget("ui.accordion", $.extend({}, $.ui.accordion.prototype, { 183 _toggle: function( data ) { 184 var toShow = data.newPanel, 185 toHide = this.prevShow.length ? this.prevShow : data.oldPanel; 186 187 // Handle activating a panel during the animation for another activation 188 this.prevShow.add( this.prevHide ).stop( true, true ); 189 this.prevShow = toShow; 190 this.prevHide = toHide; 191 192 if ( this.options.animate ) { 193 this._animate( toShow, toHide, data ); 194 } else { 195 toHide.hide(); 196 toShow.show(); 197 this._toggleComplete( data ); 198 } 199 toHide.attr( { 200 "aria-hidden": "true" 201 } ); 202 toHide.prev().attr( { 203 "aria-selected": "false", 204 "aria-expanded": "false" 205 } ); 206 207 // if we're switching panels, remove the old header from the tab order 208 // if we're opening from collapsed state, remove the previous header from the tab order 209 // if we're collapsing, then keep the collapsing header in the tab order 210 if ( toShow.length && toHide.length ) { 211 toHide.prev().attr( { 212 "tabIndex": 0, // SMB UCA-15 213 "aria-expanded": "false" 214 } ); 215 } else if ( toShow.length ) { 216 this.headers.filter( function() { 217 return parseInt( $( this ).attr( "tabIndex" ), 10 ) === 0; 218 } ) 219 .attr( "tabIndex", 0 ); // SMB UCA-15 220 } 221 222 toShow 223 .attr( "aria-hidden", "false" ) 224 .prev() 225 .attr( { 226 "aria-selected": "true", 227 "aria-expanded": "true", 228 tabIndex: 0 229 } ); 230 }, 231 232 233 _keydown: function( event ) { 234 if ( event.altKey || event.ctrlKey ) { 235 return; 236 } 237 238 var keyCode = $.ui.keyCode, 239 length = this.headers.length, 240 currentIndex = this.headers.index( event.target ), 241 toFocus = false; 242 243 switch ( event.keyCode ) { 244 case keyCode.RIGHT: 245 case keyCode.DOWN: 246 toFocus = this.headers[ ( currentIndex + 1 ) % length ]; 247 break; 248 case keyCode.LEFT: 249 case keyCode.UP: 250 toFocus = this.headers[ ( currentIndex - 1 + length ) % length ]; 251 break; 252 case keyCode.SPACE: 253 case keyCode.ENTER: 254 this._eventHandler( event ); 255 break; 256 case keyCode.HOME: 257 toFocus = this.headers[ 0 ]; 258 break; 259 case keyCode.END: 260 toFocus = this.headers[ length - 1 ]; 261 break; 262 } 263 264 if ( toFocus ) { 265 $( event.target ).attr( "tabIndex", 0 ); 266 $( toFocus ).attr( "tabIndex", 0 ); 267 $( toFocus ).trigger( "focus" ); 268 event.preventDefault(); 269 } 270 }, 271})); 272 273 274function populateIncludeNodes() { 275 const nodes = findIncludeNodes(); 276 const parsedNodes = parseNodes(nodes); 277 return insertInlcudeData(parsedNodes); 278} 279 280function findIncludeNodes() { 281 const INCLUDE_STRING = `#include`; 282 let nodeQueue = Array.from(document.childNodes); 283 const commentNodes = []; 284 285 while (nodeQueue.length) { 286 const currentNode = nodeQueue.pop(); 287 288 if ( (currentNode.nodeType === Node.COMMENT_NODE) && 289 (currentNode.data.match(INCLUDE_STRING)) ) { 290 commentNodes.push(currentNode); 291 } else if (currentNode.childNodes.length) { 292 nodeQueue = nodeQueue.concat(Array.from(currentNode.childNodes)); 293 } 294 } 295 296 return commentNodes; 297} 298 299function parseNodes(nodes) { 300 const VIRTUAL_STRING = `virtual=`; 301 302 return nodes.map((node) => { 303 const urlString = node.data.split(VIRTUAL_STRING)[1]; 304 const url = urlString.replace(/['"]+/g, '').trim(); 305 306 return { node, url }; 307 }); 308} 309 310function insertInlcudeData(nodeData) {
311 const LOADING_MESSAGE = 'Loading...' 312 const promises = []; 313 314 nodeData.forEach((nodeDatum) => { 315 const { node, url } = nodeDatum; 316 const containerNode = document.createElement('div'); 317 containerNode.style['display'] = 'inline-block'; 318 containerNode.style['width'] = '100%'; 319 containerNode.style['text-align'] = 'right'; 320 321 containerNode.innerHTML = LOADING_MESSAGE; 322 323 const parent = node.parentNode; 324 const sibling = node.nextSibling; 325 parent.insertBefore(containerNode, sibling); 326 327 // Hide the container if seen in the CMS 328 if (window.location.href.indexOf("cms.ucop.edu") > -1) { 329 containerNode.style.display = 'none'; 330 }else{ 331 containerNode.style.display = 'block'; 332 } 333 334 const currentPromise = fetch(url); 335 promises.push(currentPromise); 336 337 currentPromise.then((res) => { 338 if (!res.ok) { 339 return Promise.reject(); 340 } 341 342 return res.text(); 343 }).then((text) => { 344 containerNode.innerHTML = ''; 345 containerNode.outerHTML = text; 346 return Promise.resolve(); 347 }).catch(() =>{ 348 containerNode.style['text-align'] = 'center'; 349 containerNode.innerHTML = ''; 350 const innerNode = document.createElement('div'); 351 innerNode.style['margin-bottom'] = '20px'; 352 innerNode.style['background'] = 'rgba(255, 255, 255, 0.66)'; 353 innerNode.style['padding'] = '4px'; 354 innerNode.style['margin-top'] = '-10px'; 355 innerNode.innerHTML = `Unable to load page navigation. Please refresh the page. If problem persists, please use search box above or contact <a href="mailto:[email protected]">[email protected]</a> for further assistance`; 356 containerNode.append(innerNode); 357 return Promise.reject(); 358 }); 359 }); 360 361 return Promise.all(promises); 362}
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.