1// HERES A SIMPLE JQUERY EXTENSION TO GET THE PARAMETERS FROM THE REQUEST PARAMETER (URL) 2// IT RETURNS AN ARRAY CONTAINING A NUMBER OF NAME/VALUE PAIRS 3// IF WE HAD A URL LIKE... https://f1000research.com/experts?topicIds=1,2&subtopicIds=12 4// 5// var objParameters = $.getURLParameters(); 6// RETURN VALUE: ["topicIds", "subtopicIds", topicIds: "1,2", subtopicIds: "12"] 7// 8// var objParameters = $.getURLParametersJSON(); 9// RETURN VALUE: [Object, Object] / Object[1]: parameterName: topicIds, parameterValue: 1,2 10// 11// var parameterValue = $.getURLParameterValue("topicIds"); 12// RETURN VALUE: 1,2 13$.extend({ 14 getURLParameters: function() { 15 var params = [], 16 currentParam = "", 17 URLString = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'), 18 i = 0; 19 for (i = 0; i < URLString.length; i++) { 20 currentParam = URLString[i].split('='); 21 params.push(currentParam[0]); 22 params[currentParam[0]] = currentParam[1]; 23 } 24 return params; 25 }, 26 getURLParametersJSON: function(queryString) { 27 var params = [], 28 queryString = typeof queryString === 'undefined' ? window.location.search : queryString; 29 currentParam = "", 30 URLString = queryString.replace(/^\?/,""), 31 i = 0; 32 33 if(URLString.trim() === "") { 34 return []; 35 } 36 37 var URLParams = URLString.split("&"); 38 39 for (i = 0; i < URLParams.length; i++) { 40 currentParam = URLParams[i].split('='); 41 params[i] = { "parameterName": currentParam[0], "parameterValue": currentParam[1] }; 42 } 43 return params; 44 }, 45 getURLParameterValue: function(name) { 46 return $.getURLParameters()[name]; 47 }, 48 setURLParameter: function(name, value, queryString) { 49 queryString = typeof queryString === 'undefined' ? window.location.search : queryString; 50 51 var params = $.getURLParametersJSON(queryString); 52 53 var updatedParams = params 54 55 // Remove existing paramter, if it's there 56 .filter(function(param) { 57 return param.parameterName && param.parameterValue && param.parameterName !== name; 58 }) 59 60 // Add the new paramter 61 // Or not, if the parameter value is empty 62 .concat(value ? [{ parameterName: name, parameterValue: value }] : []) 63 64 // Encode all the URI's and convert to key=value 65 .map(function(param) { 66 return param.parameterName + "=" + param.parameterValue; 67 }) 68 .join("&"); 69 70 return updatedParams; 71 } 72});
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.