hovercard: cache raw content of the template so we don't have to request it everytime from the server

This commit is contained in:
rabuzarus 2016-05-05 23:48:52 +02:00
parent adefc315f7
commit 8609cc1675

View file

@ -85,7 +85,6 @@ $(document).ready(function(){
});
// hover cards should be removed very easily, e.g. when any of these events happen
$('body').on("mouseleave touchstart scroll click dblclick mousedown mouseup submit keydown keypress keyup", function(e){
var timeNow = new Date().getTime();
@ -196,6 +195,7 @@ function getHoverCardContent(term, url, callback) {
// });
}
// Ajax request to get the raw template content
function getHoverCardTemplate (url, callback) {
var postdata = {
@ -203,14 +203,24 @@ function getHoverCardTemplate (url, callback) {
datatype: 'tpl'
};
// Look if we have the template already in the cace, so we don't have
// request it again
if('hovercard' in getHoverCardTemplate.cache) {
setTimeout(function() { callback(getHoverCardTemplate.cache['hovercard']); } , 1);
return;
}
$.ajax({
url: url,
data: postdata,
success: function(data, textStatus) {
// write the data in the cache
getHoverCardTemplate.cache['hovercard'] = data;
callback(data);
}
});
}).fail(function () {callback([]); });
}
getHoverCardTemplate.cache = {};
// The Variables used for the template
function getHoverCardVariables(object) {