Fix up the results saving and restore to be more robust.

Always display passages using DisplayPassage so that UI events get
hooked up correctly.
This commit is contained in:
Jeremy Wall (zaphar) 2013-04-27 18:03:40 -04:00
parent 34de294ed1
commit 6d6c52db3e

View File

@ -1,3 +1,5 @@
(function() {
var CurrentReferences = {};
define(['jquery', 'reference', 'tagging', 'jquery.ui'],
function($, reference, tagging) {
function SortNumeric(x, y) {
@ -26,6 +28,7 @@ define(['jquery', 'reference', 'tagging', 'jquery.ui'],
},
RemoveResult: function(e) {
$(e.target).parent().parent().remove();
if (ref) delete CurrentReferences[ref.ToString()];
Settings.SaveResults();
},
HandleError: function(e) {
@ -184,10 +187,19 @@ define(['jquery', 'reference', 'tagging', 'jquery.ui'],
$("#display-strongs-as-dialog")[0].checked = true;
}
if (localStorage.Results !== "undefined" && localStorage.SearchResults !== "undefined") {
$("#resultwrap").html(localStorage.Results);
if (typeof localStorage.Results !== "undefined") {
$.each(
localStorage.Results.replace(/;$/, '').split(';'),
function(i, ref) {
console.log('showing ref', ref);
var myref = reference.Parse(ref);
var r = Bible.GetPassage(myref.book, myref.startchapter, myref.endchapter, myref.startverse, myref.endverse);
Bible.DisplayPassage(r.cs, myref, r.testament);
});
}
if (typeof localStorage.SearchResults !== "undefined") {
$("#searchresultswrap").html(localStorage.SearchResults);
Bible.AttachEvents($("#resultwrap"));
Words.AttachEvents($("#searchresultswrap"));
}
}
@ -249,8 +261,14 @@ define(['jquery', 'reference', 'tagging', 'jquery.ui'],
this.Save();
},
SaveResults: function() {
localStorage.Results = $("#resultwrap").html();
localStorage.SearchResults = $("#searchresultswrap").html();
if (typeof localStorage != 'undefined') {
var results = "";
for (ref in CurrentReferences) {
results += ref + ';';
}
localStorage.Results = results;
localStorage.SearchResults = $("#searchresultswrap").html();
}
}
};
var Bible = {
@ -294,6 +312,7 @@ define(['jquery', 'reference', 'tagging', 'jquery.ui'],
Bible.AttachEvents(t, ref);
$("#result").prepend(t);
CurrentReferences[ref.toString()] = true;
}
catch (err) {
Util.HandleError(err);
@ -374,7 +393,7 @@ define(['jquery', 'reference', 'tagging', 'jquery.ui'],
Util.HandleHiddenLink(e);
});
t.find(".removeresult").click(function(e) {
Util.RemoveResult(e);
Util.RemoveResult(e, ref);
});
// TODO(jwall): support longtouch events on mobile?
t.find(".resultbody h2").tooltip({
@ -1049,3 +1068,4 @@ define(['jquery', 'reference', 'tagging', 'jquery.ui'],
};
}
);
})();