diff --git a/read/Script/Read.js b/read/Script/Read.js index 5d1ca9a..e701766 100644 --- a/read/Script/Read.js +++ b/read/Script/Read.js @@ -1,6 +1,7 @@ /** * @fileOverview Read is the JavaScript controller for OSHB Read. - * @version 1.0 + * @version 1.1 + * Version 1.1: Factored in Reference Location, to link to the current verse (marcstober). * @author David */ (function() { @@ -9,7 +10,8 @@ "book": document.getElementById('book'), "chapter": document.getElementById('chapter'), "verse": document.getElementById('verse'), - "display": document.getElementById('display') + "display": document.getElementById('display'), + "link": document.getElementById('link') }; // Utility functions. // Utility function to clear child nodes from an element. @@ -74,7 +76,9 @@ for (; i <= num; i++) { elements.verse.options[elements.verse.options.length] = new Option(i); } - getChapter(); + elements.verse[initialVerse].selected = "selected"; + initialVerse = 0; + getChapter(); }; // Extracts the XML chapter from bookText. var setChapterFile = function() { @@ -93,6 +97,11 @@ return loadFile("../wlc/" + book + ".xml", setChapters); }; // Interface elements. + // Marks up the link. + function linkMark() { + var address = refLocation.getLocation(elements.book.value, elements.chapter.value, elements.verse.value); + return '' + address + '' + } var chapterMarkup = window.chapterMarkup; // Marks up the chapter. function getChapter() { @@ -101,14 +110,18 @@ elements.display.appendChild(chapterMarkup(chapter)); // Highlight the selected verse. selectVerse(document.getElementById("v." + elements.verse.value)); + elements.link.innerHTML = linkMark(); } // Initialize. - var initialChapter = elements.chapter.value - 1, + var refLocation = window.refLocation, + initialChapter = refLocation.chapterIndex(), + initialVerse = refLocation.verseIndex(), selectVerse = window.selectVerse; elements.book.onchange = setBookFile; elements.chapter.onchange = setChapterFile; elements.verse.onchange = function() { selectVerse(document.getElementById("v." + elements.verse.value)); + elements.link.innerHTML = linkMark(); }; setBookFile(); })(); \ No newline at end of file diff --git a/read/Script/ReferenceLocation.js b/read/Script/ReferenceLocation.js new file mode 100644 index 0000000..caefb3b --- /dev/null +++ b/read/Script/ReferenceLocation.js @@ -0,0 +1,57 @@ +/** + * @fileOverview Reference Location manages URL locations. + * @version 1.0 + * @author David + */ +refLocation = function() { + // Assemble an array of SBL book abbreviations. + var book = document.getElementById("book"), + sblNames = [], i = 0; + while (book.options[i]) { + sblNames.push(book.options[i].value); + i++; + } + // Parses the URL. + function parseURL() { + var parts = {book: "Gen", chapter: 1, verse: 1}, + url = window.location, + results; + if (url.length > 75) {return parts;} // Excessively long URL. + results = url.search.match(/b=(\w+)/); + if (results && results[1]) { + if (sblNames.indexOf(results[1]) >= 0) { + parts.book = results[1]; + } else { + mtNum = parseInt(results[1]); + if (mtNum > 0 && mtNum < 40) { + parts.book = sblNames[mtNum - 1]; + } else { + return parts; // Unknown book number. + } + } + } else { + return parts; // Unknown book abbreviation. + } + results = url.search.match(/c=(\d+)/); + if (results) {parts.chapter = parseInt(results[1]);} + results = url.search.match(/v=(\d+)/); + if (results) {parts.verse = parseInt(results[1]);} + return parts; + } + // Apply the results. + var ref = parseURL(), + homePage = window.location.protocol + "//" + window.location.host + "/read/index.html"; + book[sblNames.indexOf(ref.book)].selected = "selected"; + // Return the public interface. + return { + chapterIndex: function() { + return ref.chapter - 1; + }, + verseIndex: function() { + return ref.verse - 1; + }, + getLocation: function(sblBook, chapter, verse) { + return homePage + "?b=" + sblBook + "&c=" + chapter + "&v=" + verse; + } + } +}(); \ No newline at end of file diff --git a/read/Style/ReadStyle.css b/read/Style/ReadStyle.css index 4ed4c36..4974bbc 100644 --- a/read/Style/ReadStyle.css +++ b/read/Style/ReadStyle.css @@ -59,6 +59,16 @@ section#work { margin: 0.5em; } +section#work aside +{ + padding: 0 1em 0.5em 1em; + background-color: rgba(255, 251, 208, 0.7); + border: 3px double #217438; + width: intrinsic; /* Safari/WebKit uses a non-standard name */ + width: -moz-max-content; /* Firefox/Gecko */ + width: -webkit-max-content; /* Chrome */ + margin-top: 0.5em; +} /* Passage Styles */ section.passage { diff --git a/read/index.html b/read/index.html index efb1bf5..83c0f9c 100644 --- a/read/index.html +++ b/read/index.html @@ -14,7 +14,6 @@