Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Add Source button #14

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
<link rel="stylesheet" href="./style.css">
</head>
<body>
<template id="term-actions-tpl">
<div class="term-actions">
<a href="#" class="btn btn--flat btn--icon-left js-source-link" target="_blank" rel="noopener">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M10 6v2H5v11h11v-5h2v6a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h6zm11-3v8h-2V6.413l-7.793 7.794-1.414-1.414L17.585 5H13V3h8z"/></svg>
Source
</a>
</div>
</template>

<div class="app">
<div class="app__layout app__layout--main">
<div class="app__topbar">
Expand Down
17 changes: 15 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const domParser = new DOMParser();

// https://stackoverflow.com/a/4793630/10074924
function insertAfter(referenceNode, newNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}

const termActions = document.importNode(
document.getElementById("term-actions-tpl").content, true);
const app = document.querySelector(".app");
const appTitle = document.querySelector(".js-app-title");
const appProgressBar = document.querySelector(".app__progress-bar");
Expand All @@ -9,6 +16,7 @@ const appForwardButton = document.querySelector(".js-forward-button");
const appMainSearch = document.querySelector(".js-app-main-search");
const appSearchButton = document.querySelector(".js-search-button");
const dictContentHolder = document.querySelector(".js-dict-content");
const dictContentSourceLink = () => document.querySelector(".js-source-link");
const dictError = document.querySelector(".js-dict-error")

function setLoadProgress (percent) {
Expand All @@ -21,13 +29,18 @@ function loadArticle (article) {
dictContentHolder.innerHTML = "";
dictError.style.display = "none";
setLoadProgress(50);
fetch(`https://cors-anywhere.herokuapp.com/www.cnrtl.fr/definition/${article}`)
const termUrl = `https://www.cnrtl.fr/definition/${article}`;
fetch(`https://cors-anywhere.herokuapp.com/${termUrl}`)
.then(response => response.text())
.then(responseText => {
const responseDOM = domParser.parseFromString(responseText, "text/html")
setLoadProgress(90);
const responseDictContent = responseDOM.getElementById("lexicontent").outerHTML;
dictContentHolder.innerHTML = responseDictContent;

const termTitle = dictContentHolder.querySelector(".tlf_cvedette");
insertAfter(termTitle, termActions);
dictContentSourceLink().href = termUrl;

setLoadProgress(100);
})
.catch(() => {
Expand Down
42 changes: 39 additions & 3 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ body {
Cantarell, 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

a {
color: #c51162;
text-decoration-style: dotted;
}

strong, b {
color: #212121;
}
Expand All @@ -27,15 +32,34 @@ svg {
fill: currentColor;
}

.btn.btn--icon {
.btn {
-webkit-appearance: none;
display: flex;
padding: 5px;
margin: 5px;
border: none;
border-radius: 4px;
font: inherit;
text-decoration: none;
color: inherit;
background-color: #eee;
}

.btn:hover, .btn:active {
color: #c51162;
background-color: #fce3ee;
}

.btn--flat {
color: #888;
background-color: transparent;
}

.btn--icon {
width: 40px;
height: 40px;
padding: 0;
margin: 0 5px;
border: none;
border-radius: 4px;
background-color: transparent;
}

Expand All @@ -44,6 +68,14 @@ svg {
background-color: #fce3ee;
}

.btn.btn--icon-left svg {
margin-right: 5px;
}

.btn.btn--icon-right svg {
margin-left: 5px;
}

.btn.btn--icon svg {
margin: auto;
}
Expand Down Expand Up @@ -191,6 +223,10 @@ svg {
padding: 5px 15px;
}

.term-actions {
display: flex;
}

.dict-error {
display: none;
flex-direction: column;
Expand Down