diff --git a/js/main.js b/js/main.js index 887b884..ae5f154 100644 --- a/js/main.js +++ b/js/main.js @@ -81,6 +81,19 @@ $(document).ready(function () { return parentDir; } + function getREADMEmdFile(filesData, path) { + + if (path === "") { + return null; + } + + var readmeFile = filesData.find(function (fileData) { + return fileData.name === "README.md" && fileData.type === "file"; + }); + + return readmeFile ? path + "README.md" : null; + } + function renderFileList(filesData, path) { var sortBy = $('input[name=sort]:checked').val(); @@ -190,6 +203,19 @@ $(document).ready(function () { console.log("replaceState", path); history.replaceState(null, path, '#' + path); + if (path) { + var readmePath = getREADMEmdFile(filesData, path); + if (readmePath) { + var zeroMdElement = document.createElement("zero-md"); + zeroMdElement.setAttribute("src", filesBaseUrl + readmePath); + document.querySelector("body > div.container").appendChild(zeroMdElement); + } else { + var zeroMdElement = document.querySelector("zero-md"); + if (zeroMdElement) { + document.querySelector("body > div.container").removeChild(zeroMdElement); + } + } + } isNavigating = false; },