5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-07-06 00:55:45 +00:00

usar data- para botones/inputs + css

This commit is contained in:
void 2020-11-03 18:29:47 -03:00
parent 3508223ca0
commit 9f36636227
4 changed files with 57 additions and 31 deletions

View file

@ -126,17 +126,17 @@ const typesWithProperties = {
mark: { mark: {
checkFn: marks.mark.checkFn, checkFn: marks.mark.checkFn,
updateInput (el, editorEl) { updateInput (el, editorEl) {
const markColorInputEl = editorEl.querySelector("#mark-color") const markColorInputEl = editorEl.querySelector("*[data-prop=\"mark-color\"]")
markColorInputEl.disabled = false markColorInputEl.disabled = false
markColorInputEl.value = el.style.backgroundColor ? rgb2hex(el.style.backgroundColor) : "#f206f9" markColorInputEl.value = el.style.backgroundColor ? rgb2hex(el.style.backgroundColor) : "#f206f9"
}, },
disableInput (editorEl) { disableInput (editorEl) {
const markColorInputEl = editorEl.querySelector("#mark-color") const markColorInputEl = editorEl.querySelector("*[data-prop=\"mark-color\"]")
markColorInputEl.disabled = true markColorInputEl.disabled = true
markColorInputEl.value = "#000000" markColorInputEl.value = "#000000"
}, },
setupInput (editorEl, contentEl) { setupInput (editorEl, contentEl) {
const markColorInputEl = editorEl.querySelector("#mark-color") const markColorInputEl = editorEl.querySelector("*[data-prop=\"mark-color\"]")
markColorInputEl.addEventListener("change", event => { markColorInputEl.addEventListener("change", event => {
const markEl = findRecursiveChild(marks.mark.checkFn, contentEl) const markEl = findRecursiveChild(marks.mark.checkFn, contentEl)
if (markEl) markEl.style.backgroundColor = markColorInputEl.value if (markEl) markEl.style.backgroundColor = markColorInputEl.value
@ -146,32 +146,32 @@ const typesWithProperties = {
img: { img: {
checkFn: blocks.img.checkFn, checkFn: blocks.img.checkFn,
updateInput (el, editorEl) { updateInput (el, editorEl) {
const imgSrcEl = editorEl.querySelector("#img-src") const imgSrcEl = editorEl.querySelector("*[data-prop=\"img-src\"]")
imgSrcEl.disabled = false imgSrcEl.disabled = false
imgSrcEl.value = el.src imgSrcEl.value = el.src
const imgAltEl = editorEl.querySelector("#img-alt") const imgAltEl = editorEl.querySelector("*[data-prop=\"img-alt\"]")
imgAltEl.disabled = false imgAltEl.disabled = false
imgAltEl.value = el.alt imgAltEl.value = el.alt
}, },
disableInput (editorEl) { disableInput (editorEl) {
const imgSrcEl = editorEl.querySelector("#img-src") const imgSrcEl = editorEl.querySelector("*[data-prop=\"img-src\"]")
imgSrcEl.disabled = true imgSrcEl.disabled = true
imgSrcEl.value = "" imgSrcEl.value = ""
const imgAltEl = editorEl.querySelector("#img-alt") const imgAltEl = editorEl.querySelector("*[data-prop=\"img-alt\"]")
imgAltEl.disabled = true imgAltEl.disabled = true
imgAltEl.value = "" imgAltEl.value = ""
}, },
setupInput (editorEl, contentEl) { setupInput (editorEl, contentEl) {
const imgSrcEl = editorEl.querySelector("#img-src") const imgSrcEl = editorEl.querySelector("*[data-prop=\"img-src\"]")
imgSrcEl.addEventListener("input", event => { imgSrcEl.addEventListener("input", event => {
// const imgEl = findRecursiveChild(blocks.img.checkFn, contentEl) // const imgEl = findRecursiveChild(blocks.img.checkFn, contentEl)
const imgEl = getSelected(contentEl) const imgEl = getSelected(contentEl)
if (imgEl) imgEl.src = imgSrcEl.value if (imgEl) imgEl.src = imgSrcEl.value
}, false) }, false)
const imgAltEl = editorEl.querySelector("#img-alt") const imgAltEl = editorEl.querySelector("*[data-prop=\"img-alt\"]")
imgAltEl.addEventListener("input", event => { imgAltEl.addEventListener("input", event => {
// const imgEl = findRecursiveChild(blocks.img.checkFn, contentEl) // const imgEl = findRecursiveChild(blocks.img.checkFn, contentEl)
const imgEl = getSelected(contentEl) const imgEl = getSelected(contentEl)

View file

@ -376,7 +376,7 @@ function setupEditor (editorEl) {
characterData: true, characterData: true,
}) })
const editorBtn = id => editorEl.querySelector(`#${id}-button`) const editorBtn = id => editorEl.querySelector(`*[data-button="${id}"]`)
const tagNameSetFn = tagName => el => { const tagNameSetFn = tagName => el => {
const newEl = document.createElement(tagName) const newEl = document.createElement(tagName)

View file

@ -1,4 +1,30 @@
.editor { .editor {
box-sizing: border-box;
*, *::before, *::after { box-sizing: inherit; }
h1, h2, h3, h4, h5, h6, p {
min-height: 1.4em;
line-height: 1.4;
margin: 0;
}
mark {
background: #f206f9;
padding: 0;
}
.selected {
outline: #f206f9 solid medium;
outline-offset: 1pt;
}
img {
width: 100%;
max-width: 600px;
display: block;
margin: 0 auto;
}
.editor-content { .editor-content {
div[data-align="left"] { text-align: left; } div[data-align="left"] { text-align: left; }
div[data-align="center"] { text-align: center; } div[data-align="center"] { text-align: center; }

View file

@ -1,33 +1,33 @@
= form_with do = form_with do
.editor .editor
%button#bold-button Bold %button{:data => {:button => "bold"}} Bold
%button#italic-button Italic %button{:data => {:button => "italic"}} Italic
%button#deleted-button Deleted %button{:data => {:button => "deleted"}} Deleted
%button#underline-button Underline %button{:data => {:button => "underline"}} Underline
%button#mark-button Mark %button{:data => {:button => "mark"}} Mark
%button#h1-button H1 %button{:data => {:button => "h1"}} H1
%button#h2-button H2 %button{:data => {:button => "h2"}} H2
%button#h3-button H3 %button{:data => {:button => "h3"}} H3
%button#h4-button H4 %button{:data => {:button => "h4"}} H4
%button#h5-button H5 %button{:data => {:button => "h5"}} H5
%button#h6-button H6 %button{:data => {:button => "h6"}} H6
%button#ul-button Lista desordenada %button{:data => {:button => "ul"}} Lista desordenada
%button#ol-button Lista ordenada %button{:data => {:button => "ol"}} Lista ordenada
%button#left-button Left %button{:data => {:button => "left"}} Left
%button#center-button Center %button{:data => {:button => "center"}} Center
%button#right-button Right %button{:data => {:button => "right"}} Right
%br/ %br/
%label{:for => "mark-color"} Color de resaltado: %label{:for => "mark-color"} Color de resaltado:
%input#mark-color{:type => "color"}/ %input{:type => "color", :data => {:prop => "mark-color"}}/
%br/ %br/
%label{:for => "img-src"} URL de imágen: %label{:for => "img-src"} URL de imágen:
%input#img-src{:placeholder => "https://radio.sutty.nl/public/placeholder_992x992.png", :type => "url"}/ %input{:placeholder => "https://radio.sutty.nl/public/placeholder_992x992.png", :type => "url", :data => {:prop => "img-src"}}/
%label{:for => "img-alt"} Descripción de imágen: %label{:for => "img-alt"} Descripción de imágen:
%input#img-alt{:placeholder => "Un álbum", :type => "text"}/ %input{:placeholder => "Un álbum", :type => "text", :data => {:prop => "img-alt"}}/
%button#img-button Insertar imágen %button{:data => {:button => "img"}} Insertar imágen
%br/ %br/
%label{:for => "link-href"} URL de link: %label{:for => "link-href"} URL de link:
%input#link-href{:type => "url"}/ %input{:type => "url", :data => {:prop => "link-href"}}/
.editor-content{:contenteditable => "true"} .editor-content{:contenteditable => "true"}
%h1 %h1
Hola Hola