Skip to content

Commit 3ac204d

Browse files
committed
added cache source codes by id
1 parent 399cfc2 commit 3ac204d

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

‎cache.manifest‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CACHE MANIFEST
2-
# Build: 20151224120725
2+
# Build: 20151224122820
33

44
CACHE:
55
resources/css/bootstrap.min.css

‎index.html‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,18 +453,14 @@ <h5 class="variable-wrap" data-id="{id}" data-repo="{repo}" data-url="{url}" dat
453453
var langs = localStorage.get(persistLangsName),langQuery;
454454
var page = 0;
455455
var lastVal;
456-
var lastCodeId;
456+
var cacheSourceCodes = {};
457457

458458
genLangQuery(langs);
459459

460460
this.resetPage = function(){
461461
page = 0;
462462
}
463463

464-
this.getPage = function(){
465-
return page;
466-
}
467-
468464
this.setLang = function(val){
469465
langs = val || null;
470466
genLangQuery(val);
@@ -513,12 +509,16 @@ <h5 class="variable-wrap" data-id="{id}" data-repo="{repo}" data-url="{url}" dat
513509

514510
//get source code by id
515511
this.requestSourceCode = function(id,callback){
516-
lastCodeId = id;
517-
lastCodeId && $.ajax({
512+
if(cacheSourceCodes[id]){
513+
callback && callback(cacheSourceCodes[id]);
514+
return;
515+
}
516+
id && $.ajax({
518517
type: 'GET',
519518
dataType: 'json',
520-
url: 'https://searchcode.com/api/result/'+lastCodeId+'/',
519+
url: 'https://searchcode.com/api/result/'+id+'/',
521520
success: function(data){
521+
cacheSourceCodes[id] = data;
522522
callback && callback(data);
523523
}
524524
});
@@ -633,17 +633,19 @@ <h5 class="variable-wrap" data-id="{id}" data-repo="{repo}" data-url="{url}" dat
633633
});
634634
els.body.on('click','.js-variable-button__code',showSourceCode);
635635
els.body.on('click',removeVariableMenus);
636+
els.sourceCodeModal.on('hidden.bs.modal', function () {
637+
els.sourceCodeContent.text('');
638+
});
636639
}
637640
function init(){
638641
bindEvent();
639642
renderTitle();
640643
renderLangMunu();
641644
onLocationHashChanged();
642645
renderAnalytics();
643-
// hljs.highlightBlock(els.sourceCodeContent[0]);
644646
}
645647

646-
function showSourceCode(e){
648+
function showSourceCode(){
647649
searchcode.requestSourceCode(this.dataset.id,renderSourceCode);
648650
els.sourceCodeModal.modal('toggle');
649651
}

0 commit comments

Comments
 (0)