1/** 2 * Some utility functions for sending requests to the 3 * Multi-Taxonomy Widget(s) via Ajax 4 */ 5var MTW = { 6 action: 'BoCUtil_Widget_AjaxGetWidget', 7 request: null, 8 /** 9 * Gets the page id from the current document 10 * eventually should change this to get it relative to the widget so that menus will work 11 * 12 * @param DOMElement|jQuery widget The widget element 13 * @return string The page id 14 */ 15 getPageID: function (widget) { 16 var id = /(page|post)-?id-([0-9]+)/.exec(document.body.className); 17 if (id && id[2]) { 18 return id[2]; 19 } 20 return false; 21 }, 22 /** 23 * Sets up the "loading" view for the specified widget 24 * @param DOMElement|jQuery widget The widget element 25 */ 26 loading: function (widget) { 27 if (jQuery(widget).find('.overground').length > 0) { 28 return; 29 } 30 jQuery(widget).fadeTo('fast', 0.3); 31 }, 32 /** 33 * Completes the "loading" view for the specified widget 34 * @param DOMElement|jQuery widget The widget element 35 */ 36 loadComplete: function (widget) { 37 if(typeof addPlayButton == 'function') { 38 addPlayButton(); 39 } 40 jQuery('.archive form.sort button').hide(); 41 jQuery(widget).fadeTo('fast', 1); 42 }, 43 /** 44 * Always sends a signal to complete the load after ajax requests 45 * @this DOMElement|jQuery The widget element 46 */ 47 always: function () { 48 MTW.loadComplete(this); 49 jQuery(this).data('request', null); 50 }, 51 /** 52 * Uses the response from a valid ajax request to update the Multi-Taxonomy Widget 53 * @this DOMElement|jQuery The widget element 54 * @param JSONArray data A JSON array 55 */ 56 done: function (data) { 57 if (data.content) { 58 var content = jQuery(data.content); 59 jQuery(this).find('.results').replaceWith(content.find('.results')); 60 jQuery(this).find('.num-results').html(content.find('.num-results').html() || ''); 61 jQuery(this).find('.governorNames').replaceWith(content.find('.governorNames')); 62 } 63 64 if (document.getElementById('langSwitch')) { 65 var langSwitchButton = document.getElementById('langSwitch'); 66 var langSwitchURL = langSwitchButton.getAttribute('href').split("?")[0] + data.langSwitchParams; //url that button links to 67 langSwitchButton.setAttribute('href', langSwitchURL); //change url of langSwitch button 68 } 69 70 if (window.ajax_resize) { 71 window.ajax_resize(); 72 } 73 }, 74 /** 75 * Notifies the user that the request could not be completed 76 * @this DOMElement|jQuery The widget element 77 * @param jqXHR xhr A jQuery XHR object 78 * @param string status The status code for the XHR request 79 * @param string error The error message for the current status 80 */ 81 fail: function (xhr, status, error){ 82 if (error && status != "abort") { 83 alert('Failed to load content: ' + error); 84 } 85 }, 86 /** 87 * Loads a request via ajax instead of creating a new page request 88 * @param string id The id of the widget 89 * @param object data Data to be sent to the server 90 */ 91 loadWidget: function (id, data, cancelHistory) { 92 var widget = jQuery('#'+id); 93 MTW.loading(widget); 94 95 var req = widget.data('request'); 96 if (req) { 97 req.abort(); 98 } 99 100 if (!cancelHistory) { 101 MTW.State.push(id, data); 102 } 103 104 data.action = MTW.action; 105 data.pageid = MTW.getPageID(); 106 data.widgetid = id; 107 108 req = jQuery.ajax( 109 jQuery(widget).data('ajax-url'), 110 { 111 'type': 'GET', 112 'dataType': 'json', 113 'data': data, 114 'context': widget 115 } 116 ) 117 .done(MTW.done) 118 .fail(MTW.fail) 119 .always(MTW.always); 120 121 widget.data('request', req); 122 }, 123 124 /** 125 * Some utility functions for JS History manipulation 126 */ 127 State : { 128 /** 129 * Whether or not this is the first load 130 * @var bool 131 */ 132 firstLoad: true, 133 /** 134 * Whether or not the state is currently popping 135 * @var bool 136 */ 137 popping: false, 138 /** 139 * A list of functions to call when popping the MTW data 140 * @var function[] 141 */ 142 poppers: [], 143 144 /** 145 * Pushes a state into the stack 146 * @param string id The id of the MTW being modified 147 * @param object data The state data 148 */ 149 push: function (id, data) { 150 var param = jQuery.param(data); 151 if (window.history && window.history.pushState) { 152 var url = "?" + param; 153 window.history.pushState( 154 { 155 'id' : id, 156 'data' : data 157 }, 158 window.title, 159 url 160 ); 161 } else { 162 window.location.hash = param; 163 } 164 }, 165 166 /** 167 * Restores a state to a specific MTW 168 * @param string id The id of the MTW being modified 169 * @param object data The state data 170 */ 171 restore: function(id, data) { 172 var widget = jQuery('#'+id); 173 for (var i = 0, l = MTW.State.poppers.length; i < l; i++) { 174 MTW.State.poppers[i](id, data); 175 } 176 var orderby = data['mt_orderby'] 177 if ((typeof orderby).toLowerCase() != 'string') { 178 orderby = widget.find('form.sort select').data('default'); 179 } 180 widget.find('form.sort select').val(orderby); 181 MTW.loadWidget(id, data, true); 182 }, 183 184 /** 185 * Pops a state from the browser stack 186 * Only pops if the url onLoad, is different then a clicked url (indicated by boolean hrefHasChanged) 187 * Or if the browser is Internet Explorer (because IE uses #s for browser history) 188 * @param jqEvent e A browser state 189 */ 190 pop: function (e) { 191 if (navigator.appName == 'Microsoft Internet Explorer' || MTW.hrefHasChanged){ 192 if (MTW.State.firstLoad) { 193 MTW.State.firstLoad = false;
194 return; 195 } 196 MTW.State.popping = true; 197 var data = MTW.State.getLastData(); 198 var state = null; 199 if (e) { 200 state = e.originalEvent.state; 201 } 202 if (state && state.id) { 203 MTW.State.restore(state.id, data); 204 } else { 205 jQuery('.archive.ajax').each(function () { 206 MTW.State.restore(this.id, data); 207 }); 208 } 209 MTW.State.popping = false; 210 } 211 }, 212 213 /** 214 * Unserializes URL parameters (returns it to object format) 215 * @param string str URL formatted parameters 216 * @return object URL parameters as an object 217 */ 218 deParam: function (str) { 219 if (!str) { 220 return {}; 221 } 222 var obj = {}; 223 var paramRE = /([^#=\?\&]+)=([^\&]+)(&|$)/g; 224 var splitRE = /\]?\[/g; 225 var removeBracketsRE = /(\[|\])/g; 226 227 // Use replace because it will give detailed info for each of the matches 228 str.replace(paramRE, function(match, m1, m2) { 229 m1 = decodeURIComponent(m1); 230 m2 = decodeURIComponent(m2); 231 // Remove all special characters except for periods, hyphens, whitespace and plus signs 232 m2 = m2.replace(/[^\s+0-9a-z.-]/gi, ''); 233 234 // if there's square brackets, then parse them to get multi-level data 235 if (m1.indexOf('[') > 0) { 236 var keys = m1.split(splitRE); 237 var current = obj; 238 for (var i = 0, l = keys.length; i < l; i++) { 239 var key = keys[i].replace(removeBracketsRE, ''); 240 if (!key) { 241 current.push(m2); 242 break; 243 } else if (i == l-1) { 244 current[key] = m2; 245 break; 246 } else if (!current[key]) { 247 current[key] = []; 248 } 249 current = current[key]; 250 } 251 } else { 252 obj[m1] = m2; 253 } 254 }); 255 return obj; 256 }, 257 258 /** 259 * Gets the latest State data for the MTW 260 * @return object State data from the browser 261 */ 262 getLastData: function () { 263 // use the hash if it exists 264 var params = location.hash || location.search; 265 return MTW.State.deParam(params); 266 } 267 268 }, 269 270 /** 271 * This function gets a URL and returns a stripped version of it that has no anchor link 272 * @param string url 273 * @return string url A stripped version of url that has no anchor link 274 */ 275 stripAnchorFromURL: function (url) { 276 if (url.indexOf("#")>=0){ 277 url = url.slice(0, url.indexOf("#")); 278 }; 279 return url; 280 }, 281 282 /* 283 * This var indicates whether the clicked stripped url (no anchor link) is the same as 284 * the previous stripped url. It used to indicate whether to make an ajax call or not in pop. 285 */ 286 hrefHasChanged: null 287 288} 289 290jQuery(function($) { 291 292 /** 293 * Handle enter key on go to navigation element on MTW 294 * @param jqEvent e A jQuery event object 295 */ 296 $('body').on("keyup", '.bocss-input__text', function(e) { 297 var parentDiv = $(this).closest('.bocss-main-pagination'); 298 if (e.key === 'Enter' || e.keyCode === 13) { 299 parentDiv.find('#bocss-go-to-navigation--button').click(); 300 } 301 }); 302 303 /** 304 * Send an ajax request for the page given 305 * @param jqEvent e A jQuery event object 306 */ 307 $('body').on('click', '#bocss-go-to-navigation--button', function () { 308 var id = $(this).closest('.archive').prop('id'); 309 var parentDiv = $(this).closest('.bocss-main-pagination'); 310 var pageNum = parentDiv.find('.bocss-input__text').val(); 311 312 var data = MTW.State.getLastData(); 313 var lastPage = parentDiv.find('li').last(); 314 315 if (Number.isInteger(lastPage.find('a').text())) { 316 lastPage = parseInt(lastPage.find('a').text().replace(/\D/g, '')); 317 } else if (lastPage.find('span.current').text()) { 318 lastPage = parseInt(lastPage.find('span.current').text().replace(/\D/g, '')); 319 } else { 320 lastPage = parseInt(lastPage.prev().find('a').text().replace(/\D/g, '')); 321 } 322 323 if (pageNum > lastPage) { 324 pageNum = lastPage; 325 } 326 327 if (pageNum > 0) { 328 data.mt_page = pageNum; 329 MTW.hrefHasChanged=true; 330 MTW.State.firstLoad = false;
331 MTW.loadWidget( 332 id, 333 data 334 ); 335 } 336 337 }); 338}); 339 340 341jQuery(function($) { 342 var originalURL = MTW.stripAnchorFromURL(window.location.href);//URL on page load 343 $('.archive[data-ajax-url]').addClass('ajax'); 344 345 if (location.hash) { 346 MTW.State.firstLoad = false; 347 } 348 if (window.history && window.history.pushState) { 349 jQuery(window).on('popstate', MTW.State.pop); // modern browsers 350 } else { 351 jQuery(window).on('hashchange', MTW.State.pop); // IE8-9 352 if (location.hash) { 353 MTW.State.pop(); 354 } 355 } 356 357 /** 358 * Gets the url from an onClick, sets hrefChanged to false if the clicked url is the same 359 * url as the page load, sets hrefChanged to true if the urls are different 360 * @param jqEvent e A jQuery event object 361 */ 362 $('body').on('click', function (e){ 363 var clickedURL = MTW.stripAnchorFromURL(window.location.href); 364 if (originalURL==clickedURL){ 365 MTW.hrefHasChanged=false; 366 } 367 else { 368 MTW.hrefHasChanged=true; 369 if(MTW.State.firstLoad){ 370 MTW.State.firstLoad = false; 371 } 372 } 373 }); 374 375 /** 376 * Make the pagination send signals to ajax instead of a new page request 377 * @param jqEvent e A jQuery event object 378 * @return bool False if we want to prevent the action from proceeding 379 */ 380 $('body').on('click', '.archive.ajax .pagination a', function (e){ 381 var id = $(this).closest('.archive').prop('id'); 382 var pageNum = /mt_page=([0-9]+)/.exec(this.href); 383 var data = MTW.State.getLastData(); 384 if (pageNum) { 385 data.mt_page = pageNum[1]; 386 MTW.hrefHasChanged=true; 387 MTW.State.firstLoad = false; 388 } else { 389 delete data.mt_page; 390 } 391 MTW.loadWidget( 392 id, 393 data 394 ); 395 e.preventDefault(); 396 e.stopImmediatePropagation(); 397 return false; 398 }); 399 400 /** 401 * Get Sort changes and send them via Ajax 402 * @param jqEvent e A jQuery event object 403 * @return false False to prevent any other actions 404 */ 405 $('body').on('change', '.archive.ajax form.sort select', function (e){ 406 var id = $(this).closest('.archive').prop('id'); 407 var data = MTW.State.getLastData(); 408 data['mt_orderby'] = $(this).find(':selected').val(); 409 delete data.mt_page; 410 411 MTW.loadWidget( 412 id, 413 data 414 ); 415 e.preventDefault(); 416 e.stopImmediatePropagation(); 417 return false; 418 }); 419 420 // hide the submit button if JS is on 421 $('.archive.ajax form.sort button').hide(); 422 423 // Prevent MTW pagination from flying to the top upon going to the first page in IE 424 $(".mtw.archive.ajax").on( "mouseenter", "a.page-numbers", function() { 425 if( ($(this).attr("href") === "?") || ($(this).attr("href").match(/\?$/)) ) { 426 $(this).attr("href", "?mt_page=1"); 427 } 428 }); 429});
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.