Tweak github links so they don't break for localhost, and still open in a new window

pull/408/head
Gordon Williams 2020-05-11 08:28:23 +01:00
parent ca3103bf47
commit 9be1fb1164
1 changed files with 7 additions and 17 deletions

View File

@ -218,6 +218,12 @@ function refreshLibrary() {
if (versionInfo) versionInfo = " <small>("+versionInfo+")</small>";
var readme = `<a class="c-hand" onclick="showReadme('${app.id}')">Read more...</a>`;
var favourite = favourites.find(e => e == app.id);
var username = "espruino";
var githubMatch = window.location.href.match(/\/(\w+)\.github\.io/);
if(githubMatch) username = githubMatch[1];
var url = `https://github.com/${username}/BangleApps/tree/master/apps/${app.id}`;
return `<div class="tile column col-6 col-sm-12 col-xs-12">
<div class="tile-icon">
<figure class="avatar"><img src="apps/${app.icon?`${app.id}/${app.icon}`:"unknown.png"}" alt="${escapeHtml(app.name)}"></figure><br/>
@ -225,7 +231,7 @@ function refreshLibrary() {
<div class="tile-content">
<p class="tile-title text-bold">${escapeHtml(app.name)} ${versionInfo}</p>
<p class="tile-subtitle">${escapeHtml(app.description)}${app.readme?`<br/>${readme}`:""}</p>
<a appid="${app.id}" class="link-github"><img src="img/github-icon-sml.png" alt="See the code on GitHub"/></a>
<a href="${url}" target="_blank" class="link-github"><img src="img/github-icon-sml.png" alt="See the code on GitHub"/></a>
</div>
<div class="tile-action">
<button class="btn btn-link btn-action btn-lg ${!app.custom?"text-error":"d-hide"}" appid="${app.id}" title="Favorite"><i class="icon"></i>${favourite?"&#x2665;":"&#x2661;"}</button>
@ -242,22 +248,6 @@ function refreshLibrary() {
var tab = document.querySelector("#tab-librarycontainer a");
tab.classList.add("badge");
tab.setAttribute("data-badge", appJSON.length);
//github icon onClick
htmlToArray(panelbody.getElementsByClassName("link-github")).forEach(link => {
var username = window.location.href;
var url = "https://github.com/espruino/BangleApps/tree/master/apps/"+link.getAttribute("appid");
if(!username.startsWith("https://banglejs.com/apps")){
username = username.substr(0,username.lastIndexOf("."));
if(username.startsWith("https://")){username=username.substr(8,username.length)}
if(username.startsWith("http://")){username=username.substr(7,username.length)}
if(username.startsWith("www.")){username=username.substr(4,username.length)}
username = username.substr(0,username.lastIndexOf("."));
url = "https://github.com/"+username+"/BangleApps/tree/master/apps/"+link.getAttribute("appid");
}
link.href=url;
});
htmlToArray(panelbody.getElementsByTagName("button")).forEach(button => {
button.addEventListener("click",event => {
var button = event.currentTarget;