moved the highlight code to a js file
This commit is contained in:
parent
baf8d14ccf
commit
3f9d634670
96
static/js/highlight.js
Normal file
96
static/js/highlight.js
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
$(document).ready(function() {
|
||||||
|
// function to extract the parameters from the url. once we have them we can give them the class 'clicked'
|
||||||
|
function getAllUrlParams(url) {
|
||||||
|
// get query string from url (optional) or window
|
||||||
|
var queryString = url ? url.split('?')[1] : window.location.search.slice(1);
|
||||||
|
// we'll store the parameters here
|
||||||
|
var obj = {};
|
||||||
|
// if query string exists
|
||||||
|
if (queryString) {
|
||||||
|
// stuff after # is not part of query string, so get rid of it
|
||||||
|
queryString = queryString.split('#')[0];
|
||||||
|
// split our query string into its component parts
|
||||||
|
var arr = queryString.split('&');
|
||||||
|
for (var i = 0; i < arr.length; i++) {
|
||||||
|
// separate the keys and the values
|
||||||
|
var a = arr[i].split('=');
|
||||||
|
// set parameter name and value (use 'true' if empty)
|
||||||
|
var paramName = a[0];
|
||||||
|
var paramValue = typeof (a[1]) === 'undefined' ? true : a[1];
|
||||||
|
// (optional) keep case consistent
|
||||||
|
// paramName = paramName.toLowerCase();
|
||||||
|
// if (typeof paramValue === 'string') paramValue = paramValue.toLowerCase();
|
||||||
|
// if the paramName ends with square brackets, e.g. colors[] or colors[2]
|
||||||
|
if (paramName.match(/\[(\d+)?\]$/)) {
|
||||||
|
// create key if it doesn't exist
|
||||||
|
var key = paramName.replace(/\[(\d+)?\]/, '');
|
||||||
|
if (!obj[key]) obj[key] = [];
|
||||||
|
// if it's an indexed array e.g. colors[2]
|
||||||
|
if (paramName.match(/\[\d+\]$/)) {
|
||||||
|
// get the index value and add the entry at the appropriate position
|
||||||
|
var index = /\[(\d+)\]/.exec(paramName)[1];
|
||||||
|
obj[key][index] = paramValue;
|
||||||
|
} else {
|
||||||
|
// otherwise add the value to the end of the array
|
||||||
|
obj[key].push(paramValue);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// we're dealing with a string
|
||||||
|
if (!obj[paramName]) {
|
||||||
|
// if it doesn't exist, create property
|
||||||
|
obj[paramName] = paramValue;
|
||||||
|
} else if (obj[paramName] && typeof obj[paramName] === 'string'){
|
||||||
|
// if property does exist and it's a string, convert it to an array
|
||||||
|
obj[paramName] = [obj[paramName]];
|
||||||
|
obj[paramName].push(paramValue);
|
||||||
|
} else {
|
||||||
|
// otherwise add the property
|
||||||
|
obj[paramName].push(paramValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var methodList = getAllUrlParams().method;
|
||||||
|
var libList = getAllUrlParams().librarian;
|
||||||
|
|
||||||
|
if ( (typeof methodList === 'undefined') && (typeof libList === 'undefined')) {
|
||||||
|
} else {
|
||||||
|
|
||||||
|
|
||||||
|
if (typeof libList !== 'undefined') {
|
||||||
|
if (Array.isArray(libList)===false) {
|
||||||
|
var search_id0 = libList;
|
||||||
|
var element0 = document.getElementById(search_id0);
|
||||||
|
element0.classList.add("clicked");
|
||||||
|
// alert(search_id0);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
for (i=0; i < libList.length ; i++) {
|
||||||
|
var search_id = libList[i];
|
||||||
|
var element = document.getElementById(search_id);
|
||||||
|
element.classList.add("clicked");
|
||||||
|
// alert(i);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof methodList !== 'undefined') {
|
||||||
|
if (Array.isArray(methodList)===false) { // is not array
|
||||||
|
var search_meth0 = methodList;
|
||||||
|
var elementy0 = document.getElementById(search_meth0);
|
||||||
|
elementy0.classList.add("methodclicked");
|
||||||
|
} else { // is array
|
||||||
|
for (y=0; y < methodList.length ; y++) {
|
||||||
|
var search_meth = methodList[y];
|
||||||
|
var elementy = document.getElementById(search_meth);
|
||||||
|
elementy.classList.add("methodclicked");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
});
|
@ -7,8 +7,10 @@
|
|||||||
<title>Library</title>
|
<title>Library</title>
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
|
||||||
|
|
||||||
|
|
||||||
<!--TEST-->
|
<!--TEST-->
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/highlight.js') }}"></script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
@ -253,110 +255,5 @@ $.ajax({
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
|
||||||
$(document).ready(function() {
|
|
||||||
// function to extract the parameters from the url. once we have them we can give them the class 'clicked'
|
|
||||||
function getAllUrlParams(url) {
|
|
||||||
// get query string from url (optional) or window
|
|
||||||
var queryString = url ? url.split('?')[1] : window.location.search.slice(1);
|
|
||||||
// we'll store the parameters here
|
|
||||||
var obj = {};
|
|
||||||
// if query string exists
|
|
||||||
if (queryString) {
|
|
||||||
// stuff after # is not part of query string, so get rid of it
|
|
||||||
queryString = queryString.split('#')[0];
|
|
||||||
// split our query string into its component parts
|
|
||||||
var arr = queryString.split('&');
|
|
||||||
for (var i = 0; i < arr.length; i++) {
|
|
||||||
// separate the keys and the values
|
|
||||||
var a = arr[i].split('=');
|
|
||||||
// set parameter name and value (use 'true' if empty)
|
|
||||||
var paramName = a[0];
|
|
||||||
var paramValue = typeof (a[1]) === 'undefined' ? true : a[1];
|
|
||||||
// (optional) keep case consistent
|
|
||||||
// paramName = paramName.toLowerCase();
|
|
||||||
// if (typeof paramValue === 'string') paramValue = paramValue.toLowerCase();
|
|
||||||
// if the paramName ends with square brackets, e.g. colors[] or colors[2]
|
|
||||||
if (paramName.match(/\[(\d+)?\]$/)) {
|
|
||||||
// create key if it doesn't exist
|
|
||||||
var key = paramName.replace(/\[(\d+)?\]/, '');
|
|
||||||
if (!obj[key]) obj[key] = [];
|
|
||||||
// if it's an indexed array e.g. colors[2]
|
|
||||||
if (paramName.match(/\[\d+\]$/)) {
|
|
||||||
// get the index value and add the entry at the appropriate position
|
|
||||||
var index = /\[(\d+)\]/.exec(paramName)[1];
|
|
||||||
obj[key][index] = paramValue;
|
|
||||||
} else {
|
|
||||||
// otherwise add the value to the end of the array
|
|
||||||
obj[key].push(paramValue);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// we're dealing with a string
|
|
||||||
if (!obj[paramName]) {
|
|
||||||
// if it doesn't exist, create property
|
|
||||||
obj[paramName] = paramValue;
|
|
||||||
} else if (obj[paramName] && typeof obj[paramName] === 'string'){
|
|
||||||
// if property does exist and it's a string, convert it to an array
|
|
||||||
obj[paramName] = [obj[paramName]];
|
|
||||||
obj[paramName].push(paramValue);
|
|
||||||
} else {
|
|
||||||
// otherwise add the property
|
|
||||||
obj[paramName].push(paramValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
var methodList = getAllUrlParams().method;
|
|
||||||
var libList = getAllUrlParams().librarian;
|
|
||||||
|
|
||||||
if ( (typeof methodList === 'undefined') && (typeof libList === 'undefined')) {
|
|
||||||
} else {
|
|
||||||
|
|
||||||
|
|
||||||
if (typeof libList !== 'undefined') {
|
|
||||||
if (Array.isArray(libList)===false) {
|
|
||||||
var search_id0 = libList;
|
|
||||||
var element0 = document.getElementById(search_id0);
|
|
||||||
element0.classList.add("clicked");
|
|
||||||
// alert(search_id0);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
for (i=0; i < libList.length ; i++) {
|
|
||||||
var search_id = libList[i];
|
|
||||||
var element = document.getElementById(search_id);
|
|
||||||
element.classList.add("clicked");
|
|
||||||
// alert(i);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
if (typeof methodList !== 'undefined') {
|
|
||||||
if (Array.isArray(methodList)===false) { // is not array
|
|
||||||
var search_meth0 = methodList;
|
|
||||||
var elementy0 = document.getElementById(search_meth0);
|
|
||||||
elementy0.classList.add("methodclicked");
|
|
||||||
} else { // is array
|
|
||||||
for (y=0; y < methodList.length ; y++) {
|
|
||||||
var search_meth = methodList[y];
|
|
||||||
var elementy = document.getElementById(search_meth);
|
|
||||||
elementy.classList.add("methodclicked");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user