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