1"use strict"; 2const istiFormScript = { 3 orgnTypeSelect: '', 4 taxonomySelect: '', 5 formInputs: '', 6 init:function () { 7 this.initElements(); 8 this.initEvents(); 9 }, 10 initElements:function(){ 11 this.orgnTypeSelect = document.querySelectorAll("#np-search-form select[name='wht_looking_for'],#np-search-form select[name='focus_area_search']"); 12 this.formInputs = document.querySelectorAll("#np-search-form select"); 13 this.taxonomySelect = document.querySelector("#np-search-form select[name='taxonomy_search']"); 14 }, 15 initEvents:function(){ 16 !!this.orgnTypeSelect && this.__AEL(this.orgnTypeSelect, 'change', 'ReplaceTaxonomyList', true); 17 !!this.formInputs && this.__AEL(this.formInputs, 'change', 'HideTaxInput', true); 18 }, 19 handleHideTaxInput:function(){ 20 if(!Object.values(this.orgnTypeSelect).filter(ele=> ele.checkVisibility()).length){ 21 this.taxonomySelect.parentElement.style.display = 'none'; 22 } 23 }, 24 handleReplaceTaxonomyList:function(obj, e, args){ 25 let options = ''; 26 let taxonomy = ''; 27 if(!!window.taxonomyList){ 28 let selectValue = e.target.value; 29 switch (String(selectValue)) { 30 case '1': 31 case '21': 32 taxonomy = 'research'; 33 this.taxonomySelect.parentElement.style.display = 'block'; 34 break; 35 case '2': 36 case '25': 37 taxonomy = 'technologies'; 38 this.taxonomySelect.parentElement.style.display = 'block'; 39 break; 40 // case '3': 41 // taxonomy = 'fellowships_scholarships'; 42 // break; 43 // case '4': 44 // taxonomy = 'programmes_schemes_type'; 45 // break; 46 // case '5': 47 // taxonomy = 'innovation_startups'; 48 // break; 49 // case '6': 50 // taxonomy = 'organization'; 51 // break; 52 default: 53 this.taxonomySelect.parentElement.style.display = 'none'; 54 break; 55 } 56 57 if( !!window?.taxonomyList[taxonomy] ) { 58 options += `<option value="">${window.taxonomyList[taxonomy]['']}</option>`; 59 options += `<option value="any">${window.taxonomyList[taxonomy]['any']}</option>`; 60 Object.entries(window.taxonomyList[taxonomy]).map(([value, title])=>{ 61 options += !!value && 'any' !== value ? `<option value="${value}">${title}</option>` : '' 62 }); 63 } 64 this.taxonomySelect.innerHTML = ''; 65 this.taxonomySelect.insertAdjacentHTML('beforeEnd', options) ; 66 } 67 }, 68 __AEL:function (ele='', act='', fun = null, mul = false, args = {}) { 69 if (!!ele) { 70 (mul === true) ? ele.forEach(el => el.addEventListener(act, (e) => this['handle' + fun](this, e, args))) : ele.addEventListener(act, (e) => this['handle' + fun](this, e, args)); 71 } 72 } 73} 74document.addEventListener('DOMContentLoaded', ()=>{ 75 istiFormScript.init(); 76}); 77 78; 79(function ($) { 80 81 // Need to keep this to check if there are extra parameters in the original URL. 82 var original = { 83 path: window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '') + window.location.pathname, 84 // @TODO integrate #1359798 without breaking history.js 85 query: window.location.search || '' 86 }; 87 88 /** 89 * Keep the original beforeSubmit method to use it later. 90 */ 91 var beforeSubmit = Drupal.ajax.prototype.beforeSubmit; 92 93 /** 94 * Keep the original beforeSerialize method to use it later. 95 */ 96 var beforeSerialize = Drupal.ajax.prototype.beforeSerialize; 97 98 Drupal.behaviors.viewsAjaxHistory = { 99 attach: function (context, settings) { 100 // Init the current page too, because the first loaded pager element do 101 // not have loadable history and will not work the back button. 102 var $body = $('body').once('views-ajax-history-first-page-load'); 103 if ($body.length) { 104 settings.viewsAjaxHistory.onloadPageItem = settings.viewsAjaxHistory.renderPageItem; 105 } 106 } 107 }; 108 109 /** 110 * Modification of Drupal.Views.parseQueryString() to allow extracting multivalues fields 111 * 112 * @param query 113 * String, either a full url or just the query string. 114 */ 115 var parseQueryString = function (query) { 116 var args = {}; 117 var pos = query.indexOf('?'); 118 if (pos != -1) { 119 query = query.substring(pos + 1); 120 } 121 var pairs = query.split('&'); 122 var pair, key, value; 123 for(var i in pairs) { 124 if (typeof(pairs[i]) == 'string') { 125 pair = pairs[i].split('='); 126 // Ignore the 'q' path argument, if present. 127 if (pair[0] != 'q' && pair[1]) { 128 key = decodeURIComponent(pair[0].replace(/\+/g, ' ')); 129 value = decodeURIComponent(pair[1].replace(/\+/g, ' ')); 130 // field name ends with [], it's multivalues 131 if (/\[\]$/.test(key)) { 132 if (!(key in args)) { 133 args[key] = [value]; 134 } 135 // don't duplicate values 136 else if (!$.inArray(value, args[key]) !== -1) { 137 args[key].push(value); 138 } 139 } 140 else { 141 args[key] = value; 142 } 143 } 144 } 145 } 146 return args; 147 }; 148 149 /** 150 * Strip views values and duplicates from URL 151 * 152 * @param url 153 * String with the full URL to clean up. 154 * @param viewArgs 155 * Object containing field values from views. 156 * 157 * @return url 158 * String URL with views values and reduced duplicates. 159 */ 160 var cleanURL = function (url, viewArgs) { 161 var args = parseQueryString(url); 162 var query = []; 163 164 // With clean urls off we need to add the 'q' parameter. 165 if (/\?/.test(Drupal.settings.views.ajax_path)) { 166 query.push('q=' + Drupal.Views.getPath(url)); 167 } 168 169 $.each(args, function (name, value) { 170 // use values from viewArgs if they exists 171 if (name in viewArgs) { 172 value = viewArgs[name]; 173 } 174 if ($.isArray(value)) { 175 $.merge(query, $.map(value, function (sub) { 176 return name + '=' + sub; 177 })); 178 } 179 else { 180 query.push(name + '=' + value); 181 } 182 }); 183 184 url = url.split('?'); 185 return url[0] + (query.length ? '?' + query.join('&') : ''); 186 }; 187 188 /** 189 * Unbind 'statechange' when adding a new state to avoid an infinite loop. 190 * 191 * We only use the 'statechange' event to trigger refresh on back of forward click. 192 * 193 * @param options 194 * Object containing the values from views' AJAX call. 195 * @param url 196 * String with the current URL to be cleaned up. 197 */ 198 var addState = function (options, url) { 199 // Store the actual view's dom id. 200 Drupal.settings.viewsAjaxHistory.lastViewDomID = options.data.view_dom_id; 201 $(window).unbind('statechange', loadView); 202 History.pushState(options, document.title, cleanURL(url, options.data)); 203 $(window).bind('statechange', loadView); 204 }; 205 206 /** 207 * Make an AJAX request to update the view when nagitating back and forth. 208 */ 209 var loadView = function () { 210 var state = History.getState(); 211 var options = state.data; 212 213 // This should be the first loaded page, so init the options object. 214 if (typeof options.data == 'undefined') { 215 var viewsAjaxSettingsKey = 'views_dom_id:' + Drupal.settings.viewsAjaxHistory.lastViewDomID; 216 if (Drupal.settings.views.ajaxViews.hasOwnProperty(viewsAjaxSettingsKey)) { 217 var viewsAjaxSettings = Drupal.settings.views.ajaxViews[viewsAjaxSettingsKey]; 218 viewsAjaxSettings.page = Drupal.settings.viewsAjaxHistory.onloadPageItem; 219 options = { 220 data: viewsAjaxSettings, 221 url: Drupal.settings.views.ajax_path 222 }; 223 } 224 } 225 226 // need a dummy element to trigger Drupal's AJAX call. 227 var $dummy = $('<div class="ajaxHistoryDummy"/>'); 228 // Drupal's AJAX options. 229 var settings = $.extend({ 230 submit: options.data, 231 setClick: true, 232 event: 'click', 233 selector: '.view-dom-id-' + options.data.view_dom_id, 234 progress: { type: 'throbber' } 235 }, options); 236 237 new Drupal.ajax(false, $dummy[0], settings);
238 // trigger ajax call 239 // @TODO check there is no leak, $dummy is never destroyed. 240 $dummy.trigger('click'); 241 }; 242 243 /** 244 * Override beforeSerialize to handle click on pager links 245 * 246 * @param $element 247 * jQuery DOM element 248 * @param options 249 */ 250 Drupal.ajax.prototype.beforeSerialize = function ($element, options) { 251 if (options.data.view_name) { 252 // If we're restoring a previous state the dummy element will have this class, 253 // and we don't need to go trough all this processing. 254 if ($($element).hasClass('ajaxHistoryDummy')) {return;} 255 256 options.url = Drupal.settings.views.ajax_path; 257 258 // Check we handle a click on a link, not a form submission. 259 if ($element.is('a')) { 260 addState(options, $element.attr('href')); 261 } 262 } 263 // Call the original Drupal method with the right context. 264 beforeSerialize.apply(this, arguments); 265 }; 266 267 /** 268 * Override beforeSubmit to handle exposed form submissions. 269 * 270 * @param form_values 271 * Object with all field values. 272 * @param element 273 * jQuery DOM form element. 274 * @param options 275 * Object containing AJAX options. 276 */ 277 Drupal.ajax.prototype.beforeSubmit = function (form_values, element, options) { 278 if (options.data.view_name) { 279 var url = original.path + (/\?/.test(original.path) ? '&' : '?') + element.formSerialize(); 280 281 // copy selected values in history state 282 $.each(form_values, function () { 283 // field name ending with [] is a multi value field 284 if (/\[\]$/.test(this.name)) { 285 if (!options.data[this.name]) { 286 options.data[this.name] = []; 287 } 288 options.data[this.name].push(this.value); 289 } 290 // regular field 291 else { 292 options.data[this.name] = this.value; 293 } 294 }); 295 296 addState(options, url); 297 } 298 299 for (var i = 0; i < arguments[0].length; i++) { 300 if (arguments[0][i].name == 'page') { 301 arguments[0][i].value = 0; 302 } 303 } 304 305 // Call the original Drupal method with the right context. 306 beforeSubmit.apply(this, arguments); 307 }; 308}(jQuery)); 309;
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.