-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
484 additions
and
275 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,164 @@ | ||
import "../src/components/views/sh-settings"; | ||
import "../src/components/components/layout-vsplit"; | ||
import "../src/views/sh-settings"; | ||
import "../src/components/layout-vsplit"; | ||
import { BookmarkSource } from "../src/types"; | ||
import { FakeBrowser } from "./fake-browser"; | ||
import { Schmackhaft } from "../src/app-schmackhaft"; | ||
import { Settings } from "../src/model/settings"; | ||
import { SettingsBridge } from "../src/core/settings"; | ||
import { Settings as SettingsElement } from "../src/views/sh-settings"; | ||
|
||
let settingsElementV1 = document.getElementById("SettingsV1") as SettingsBridge; | ||
let settingsElementV2 = document.getElementById("SettingsV2") as SettingsBridge; | ||
settingsElementV2.settings = JSON.stringify({ | ||
remoteUrls: [ | ||
"https://raw.githubusercontent.com/exhuma/dotfiles/master/bookmarks.json", | ||
"https://demo-2.json", | ||
], | ||
enableBrowserBookmarks: true, | ||
version: 2, | ||
}); | ||
settingsElementV2.addEventListener("change", (event) => { | ||
console.log(JSON.parse(event.detail["settings"])); | ||
}); | ||
/** | ||
* Initialise the HTML elements which are used to play with the component | ||
* settings | ||
*/ | ||
function initSettingsUI() { | ||
let settingsElementV1 = document.getElementById( | ||
"SettingsV1" | ||
) as SettingsElement; | ||
let settingsElementV2 = document.getElementById( | ||
"SettingsV2" | ||
) as SettingsElement; | ||
settingsElementV2.settings = JSON.stringify({ | ||
remoteUrls: [ | ||
"https://raw.githubusercontent.com/exhuma/dotfiles/master/bookmarks.json", | ||
"https://demo-2.json", | ||
], | ||
enableBrowserBookmarks: true, | ||
version: 2, | ||
}); | ||
settingsElementV2.addEventListener("change", (event) => { | ||
let evt = event as CustomEvent; | ||
console.log(JSON.parse(evt.detail["settings"])); | ||
}); | ||
|
||
settingsElementV1.settings = JSON.stringify({ | ||
remoteUrl: | ||
"https://raw.githubusercontent.com/exhuma/dotfiles/master/bookmarks.json", | ||
version: 1, | ||
}); | ||
settingsElementV1.settings = JSON.stringify({ | ||
remoteUrl: | ||
"https://raw.githubusercontent.com/exhuma/dotfiles/master/bookmarks.json", | ||
version: 1, | ||
}); | ||
} | ||
|
||
let bookmarksElement = document.getElementById("schmackhaft"); | ||
/** | ||
* Initialise a core "schmackhaft custom-element" | ||
*/ | ||
function initSchmackhaftUI() { | ||
let bookmarksElement = document.getElementById("schmackhaft") as Schmackhaft; | ||
|
||
// We can't use the default settings bridge here, because this only works in a | ||
// browser-extension execution context. | ||
let settings = new Settings( | ||
[ | ||
{ | ||
type: BookmarkSource.HTTP, | ||
settings: { | ||
url: "https://raw.githubusercontent.com/exhuma/dotfiles/master/bookmarks.json", | ||
// We can't use the default settings bridge here, because this only works in a | ||
// browser-extension execution context. | ||
let settings = new Settings( | ||
[ | ||
{ | ||
type: BookmarkSource.HTTP, | ||
settings: { | ||
url: "https://raw.githubusercontent.com/exhuma/dotfiles/master/bookmarks.json", | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: BookmarkSource.HTTP, | ||
settings: { | ||
url: "https://raw.githubusercontent.com/exhuma/schmackhaft/e6439061eedd24c50e00e8b2374ec50d376bc6e5/docs/examples/external-file.json", | ||
{ | ||
type: BookmarkSource.HTTP, | ||
settings: { | ||
url: "https://raw.githubusercontent.com/exhuma/schmackhaft/e6439061eedd24c50e00e8b2374ec50d376bc6e5/docs/examples/external-file.json", | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: BookmarkSource.BROWSER, | ||
settings: {}, | ||
}, | ||
{ | ||
type: BookmarkSource.EXTENSION_STORAGE, | ||
settings: {}, | ||
}, | ||
], | ||
3 | ||
); | ||
bookmarksElement.settings = settings.toJson(); | ||
bookmarksElement?.addEventListener("settingsChanged", (event) => { | ||
console.log("Settings Changed to:"); | ||
console.log(JSON.parse(event.detail["settings"])); | ||
}); | ||
bookmarksElement.injections = { getBrowser: async () => new FakeBrowser() }; | ||
{ | ||
type: BookmarkSource.BROWSER, | ||
settings: {}, | ||
}, | ||
{ | ||
type: BookmarkSource.EXTENSION_STORAGE, | ||
settings: {}, | ||
}, | ||
], | ||
3 | ||
); | ||
bookmarksElement.settings = settings.toJson(); | ||
bookmarksElement?.addEventListener("settingsChanged", (event) => { | ||
let evt = event as CustomEvent; | ||
console.log("Settings Changed to:"); | ||
console.log(JSON.parse(evt.detail["settings"])); | ||
}); | ||
bookmarksElement.injections = { getBrowser: async () => new FakeBrowser() }; | ||
} | ||
|
||
/** | ||
* Ensure only the div related to the clicked link is visible | ||
* Toggle the visibility of a single element with the "togglable" class. | ||
* | ||
* @param evt A click-event from the browser | ||
* All "togglable" elements will be hidden *except* the one with the given | ||
* SGML-ID | ||
* | ||
* @param id The ID of the element which should become/remain visible. | ||
*/ | ||
function toggleDiv(evt) { | ||
let enabledName = evt.target.dataset["div"]; | ||
function toggleDiv(id: string): void { | ||
document.querySelectorAll(".toggleable").forEach((element) => { | ||
let currentName = element.id; | ||
let displayValue = enabledName === currentName ? "block" : "none"; | ||
element.style.display = displayValue; | ||
let elmt = element as HTMLElement; | ||
let currentName = elmt.id; | ||
let displayValue = id === currentName ? "block" : "none"; | ||
elmt.style.display = displayValue; | ||
}); | ||
} | ||
|
||
document.querySelectorAll(".clickable").forEach((element) => { | ||
element.addEventListener("click", toggleDiv); | ||
}); | ||
/** | ||
* Delegate click events to the visibility "toggler". The clicked element *must* | ||
* have the attribute "data-div" with the SGML-ID as value of the element that | ||
* should be displayed. | ||
* | ||
* @param evt A click-event from the browser | ||
*/ | ||
function onTabClicked(evt: Event) { | ||
let enabledName = evt.target.dataset["div"]; | ||
toggleDiv(enabledName); | ||
} | ||
|
||
/** | ||
* Update bookmarks from an external JSON file | ||
* | ||
* @param url The URL from which to fetch the JSON | ||
*/ | ||
async function reloadJson(url) { | ||
async function reloadJson(url: string) { | ||
if (url === undefined || url.trim() === "") { | ||
return; | ||
} | ||
let response = await fetch(url); | ||
if (!response.ok) { | ||
console.error(`Unable to fetch ${url} (${response.statusText})`); | ||
return; | ||
} | ||
let text = await response.text(); | ||
let bookmarksElement = document.getElementById("schmackhaft"); | ||
bookmarksElement.links = text; | ||
let bookmarksElement = document.getElementById("schmackhaft") as Schmackhaft; | ||
let settings = new Settings([ | ||
{ | ||
type: BookmarkSource.HTTP, | ||
settings: { | ||
url: url, | ||
}, | ||
}, | ||
]); | ||
bookmarksElement.settings = settings.toJson(); | ||
} | ||
|
||
document.getElementById("ReloadJsonButton").addEventListener("click", () => { | ||
/** | ||
* Initialise the elements in the demo-page toolbar | ||
*/ | ||
function initToolbar() { | ||
document.getElementById("ReloadJsonButton").addEventListener("click", () => { | ||
let txtJsonFile = document.getElementById( | ||
"ExternalJsonFile" | ||
) as HTMLInputElement; | ||
let url = txtJsonFile.value; | ||
reloadJson(url); | ||
}); | ||
|
||
let txtJsonFile = document.getElementById("ExternalJsonFile"); | ||
let url = txtJsonFile.value; | ||
reloadJson(url); | ||
}); | ||
txtJsonFile.addEventListener("change", async (evt) => { | ||
let target = evt.target as HTMLInputElement; | ||
let url = target.value; | ||
reloadJson(url); | ||
}); | ||
|
||
let txtJsonFile = document.getElementById("ExternalJsonFile"); | ||
txtJsonFile.addEventListener("change", async (evt) => { | ||
let url = evt.target.value; | ||
reloadJson(url); | ||
}); | ||
document.querySelectorAll(".clickable").forEach((element) => { | ||
element.addEventListener("click", onTabClicked); | ||
}); | ||
} | ||
|
||
document.querySelector(".toggleable").style.display = "block"; | ||
/** | ||
* Initialise all UI elements for the demo page | ||
*/ | ||
export function initUI() { | ||
initSettingsUI(); | ||
initSchmackhaftUI(); | ||
initToolbar(); | ||
toggleDiv("Bookmarks"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "schmackhaft", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A bookmark manager based on del.icio.us", | ||
"author": "Michel Albert <[email protected]>", | ||
"license": "MIT", | ||
|
Oops, something went wrong.