File size: 6,232 Bytes
d736789 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
const bibUtil = (function () {
return {
parseField: function (fieldString, field, tagCategories) {
function tagSort(a, b) {
var categoryA = a.substring(0, a.indexOf(':')).toLowerCase();
var categoryB = b.substring(0, b.indexOf(':')).toLowerCase();
if (categoryA && categoryB) {
if (categoryA != categoryB) {
var indexA = Object.keys(tagCategories).indexOf(categoryA);
var indexB = Object.keys(tagCategories).indexOf(categoryB);
return ((indexA < indexB) ? -1 : ((indexA > indexB) ? 1 : 0));
}
} else if (categoryA) {
return -1;
} else if (categoryB) {
return 1;
}
var aName = a.toLowerCase();
var bName = b.toLowerCase();
return ((aName < bName) ? -1 : ((aName > bName) ? 1 : 0));
}
if (!fieldString) {
fieldString = '?';
}
switch (field) {
case 'keywords':
var tags = [];
const splitter = fieldString.indexOf(',') < 0?';':',';
$.each(fieldString.split(splitter), function (i, tag) {
tag = $.trim(tag.split("\\").join("")).toLowerCase();
if ($.inArray(tag, tags) == -1) {
tags.push(tag);
}
});
$.each(tagCategories, function (categoryName) {
if (fieldString.indexOf(categoryName + ":") == -1) {
tags.push(categoryName + ":?");
}
});
tags.sort(tagSort);
return tags;
case 'author':
return fieldString.split(' and ');
default :
return [fieldString];
}
}
}
})();
const tagUtil = (function () {
return {
simplifyTag: function (tag) {
return tag.toLowerCase().replace(/\W/g, '');
},
getFrequencyClass: function (frequency) {
var frequencyClass = 'freq1';
if (frequency >= 2) {
frequencyClass = 'freq2';
}
if (frequency >= 3) {
frequencyClass = 'freq3';
}
if (frequency >= 5) {
frequencyClass = 'freq5';
}
if (frequency >= 10) {
frequencyClass = 'freq10';
}
if (frequency >= 20) {
frequencyClass = 'freq20';
}
if (frequency >= 35) {
frequencyClass = 'freq35';
}
if (frequency >= 50) {
frequencyClass = 'freq50';
}
if (frequency >= 80) {
frequencyClass = 'freq80';
}
if (frequency >= 120) {
frequencyClass = 'freq120';
}
return frequencyClass;
}
}
})();
const latexUtil = (function () {
return {
latexToHtml: function (latex) {
if (!latex) {
return '';
}
latex = latex.replace(/{|}/g, '');
latex = latex.replace(/---/g, '—');
latex = latex.replace(/--/g, '–');
var encoding = {
"'": "acute",
"`": "grave",
"^": "circ",
"\"": "uml",
"s": "zlig",
'~': 'tilde',
'c': 'cedil',
'l': 'ł',
'L': 'Ł',
'o': 'ø',
'O': 'Ø',
'v': '_̌',
'k': '_̨',
'=': '_̄',
'b': '_̱',
'.': '_̇',
'd': '_̣',
'r': '_ḁ',
'u': '_̆',
'H': '_̋'
};
var html = "";
for (var i = 0; i < latex.length; i++) {
var c = latex[i];
if (c == "\\") {
if (i + 1 < latex.length && latex[i + 1] == '&') {
c = '&';
i++;
} else if (i + 1 < latex.length && latex[i + 1] == '_') {
c = '_';
i++;
} else if (i + 2 < latex.length && encoding[latex[i + 1]]) {
if (encoding[latex[i + 1]].indexOf('&') == -1) {
c = "&" + latex[i + 2] + encoding[latex[i + 1]] + ";";
i += 2;
} else if (encoding[latex[i + 1]].indexOf('_') >= 0) {
c = encoding[latex[i + 1]].replace('_', latex[i + 2]);
i += 2;
} else {
c = encoding[latex[i + 1]];
i += 1;
}
}
}
html += c;
}
return html;
},
}
})();
const browserUtil = (function () {
return {
// http://stackoverflow.com/questions/19491336/get-url-parameter-jquery
getUrlParameter: function (sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
return sParameterName[1];
}
}
}
}
})();
const uiUtil = (function () {
return {
toggleControl: function (h2Div) {
h2Div.parent().children('.toggle-container').toggle();
var symbol = h2Div.find('span.symbol');
symbol.text(symbol.text() == '/' ? '>' : '/');
},
}
})(); |