Skip to content

Commit

Permalink
Merge pull request #1 from Azgaar/master
Browse files Browse the repository at this point in the history
Update from Azgaar master
  • Loading branch information
evolvedexperiment authored Jun 26, 2020
2 parents 1e60b47 + abeafd4 commit 36870a3
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 235 deletions.
41 changes: 40 additions & 1 deletion index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2089,9 +2089,10 @@ svg.button {
padding: 1.2em;
border: solid 1px #000;
font-size: 1.2em;
z-index: 1000;
}

#promptTest {
#promptText {
padding: 0 0 .6em 0;
font-weight: bold;
font-family: sans-serif;
Expand Down Expand Up @@ -2125,6 +2126,44 @@ svg.button {
stroke-width: 0;
}

.pell {
border: 1px solid hsla(0,0%,4%,.1)
}

.pell,.pell-content {
box-sizing: border-box
}

.pell-content {
height: 14em;
outline: 0;
overflow-y: auto;
padding: .6em;
font-family: Copperplate, monospace;
background-color: #fff;
border: 1px solid #dedede;
}

.pell-actionbar {
background-color: #fff;
border: 1px solid #dedede;
border-bottom: 0;
}

.pell-button {
background-color: transparent;
border: none;
cursor: pointer;
height: 30px;
outline: 0;
width: 30px;
vertical-align: bottom
}

.pell-button-selected {
background-color: #f0f0f0
}

#debug {
font-size: 1px;
opacity: .8;
Expand Down
20 changes: 9 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2412,9 +2412,9 @@
<i data-tip="Marker Icon" class="icon-info"></i>
<button id="markerIconSelect" data-tip="Click to select icon"></button>
<i data-tip="Change marker horizontal shift" class="icon-resize-horizontal"></i>
<input id="markerIconShiftX" data-tip="Change icon horizontal shift" type="number" value=50 style="width:3em">
<input id="markerIconShiftX" data-tip="Change icon horizontal shift" type="number" value=50>
<i data-tip="Change marker vertical shift" class="icon-resize-vertical"></i>
<input id="markerIconShiftY" data-tip="Change vertical shift" type="number" min=0 max=100 value=50 style="width:3em">
<input id="markerIconShiftY" data-tip="Change vertical shift" type="number" min=0 max=100 value=50>
</div>

<button id="markerStyle" data-tip="Change marker size and colors" class="icon-brush"></button>
Expand Down Expand Up @@ -2538,7 +2538,7 @@
<span>Attackers</span>
<div style="float: right; font-size: .7em">
<meter id="battleMorale_attackers" data-tip="Attackers morale: " min=0 max=100 low=33 high=66 optimum=80></meter>
<div id="battlePower_attackers" data-tip="Attackers strength during this phase. Strength defines dealt damage" style="width: 3.2em; display: inline-block; text-align: center" class="icon-button-power"></div>
<div id="battlePower_attackers" data-tip="Attackers strength during this phase. Strength defines dealt damage" style="display: inline-block; text-align: center" class="icon-button-power"></div>
<div style="display: inline-block;">
<button id="battlePhase_attackers" style="width: 3.2em"></button>
<div class="battlePhases" style="display: none"></div>
Expand All @@ -2551,7 +2551,7 @@
<span></span>Defenders</span>
<div style="float: right; font-size: .7em">
<meter id="battleMorale_defenders" data-tip="Defenders morale: " min=0 max=100 low=33 high=66 optimum=80></meter>
<div id="battlePower_defenders" data-tip="Defenders strength during this phase. Strength defines dealt damage" style="width: 3.2em; display: inline-block; text-align: center" class="icon-button-power"></div>
<div id="battlePower_defenders" data-tip="Defenders strength during this phase. Strength defines dealt damage" style="display: inline-block; text-align: center" class="icon-button-power"></div>
<div style="display: inline-block;">
<button id="battlePhase_defenders" style="width: 3.2em"></button>
<div class="battlePhases" style="display: none"></div>
Expand Down Expand Up @@ -3209,14 +3209,12 @@
<span>Select object: </span>
<select id="notesSelect" data-tip="Select object" style="width: 12em"></select>
<span>Object name: </span>
<input id="notesName" data-tip="Type to change object name" autocorrect="off" spellcheck="false" style="width: 17em">
</div>
<div>
<span>Legend:</span><br>
<textarea id="notesText" rows="7" data-tip="Type object description" placeholder="Type object description"></textarea>
<input id="notesName" data-tip="Type to change object name" autocorrect="off" spellcheck="false" style="width: 16em">
</div>
<div id="notesText" data-tip="Type and style object description" style="padding: .4em 0"></div>
<div>
<button id="notesFocus" data-tip="Focus on selected object" class="icon-target"></button>
<button id="notesPin" data-tip="Toggle notes box dispay: hide or do not hide the box on mouse move" class="icon-pin"></button>
<button id="notesDownload" data-tip="Download notes to PC" class="icon-download"></button>
<button id="notesUpload" data-tip="Upload notes from PC" class="icon-upload"></button>
<button id="notesRemove" data-tip="Remove this note" class="icon-trash fastDelete"></button>
Expand Down Expand Up @@ -3672,7 +3670,7 @@

<div id="prompt" style="display: none" class="dialog">
<form id="promptForm">
<div id="promptTest"></div>
<div id="promptText"></div>
<input id="promptInput" type="number" step=.01 placeholder="type value" autocomplete="off" required>
<button type="submit">Confirm</button>
<button type="button" id="promptCancel" formnovalidate>Cancel</button>
Expand Down Expand Up @@ -3762,5 +3760,5 @@
<script defer src="modules/ui/3d.js"></script>
<script defer src="libs/rgbquant.js"></script>
<script defer src="libs/jquery.ui.touch-punch.min.js"></script>
<script defer src="libs/publicstorage.js"></script>
<script defer src="libs/pell.js"></script>
</body>
163 changes: 163 additions & 0 deletions libs/pell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.Pell = factory());
}(this, (function () { 'use strict';

const defaultParagraphSeparatorString = 'defaultParagraphSeparator'
const formatBlock = 'formatBlock'
const addEventListener = (parent, type, listener) => parent.addEventListener(type, listener)
const appendChild = (parent, child) => parent.appendChild(child)
const createElement = tag => document.createElement(tag)
const queryCommandState = command => document.queryCommandState(command)
const queryCommandValue = command => document.queryCommandValue(command)
const exec = (command, value = null) => document.execCommand(command, false, value)

const defaultActions = {
bold: {
icon: '<b>B</b>',
title: 'Bold',
state: () => queryCommandState('bold'),
result: () => exec('bold')
},
italic: {
icon: '<i>I</i>',
title: 'Italic',
state: () => queryCommandState('italic'),
result: () => exec('italic')
},
underline: {
icon: '<u>U</u>',
title: 'Underline',
state: () => queryCommandState('underline'),
result: () => exec('underline')
},
strikethrough: {
icon: '<strike>S</strike>',
title: 'Strike-through',
state: () => queryCommandState('strikeThrough'),
result: () => exec('strikeThrough')
},
heading1: {
icon: '<b>H<sub>1</sub></b>',
title: 'Heading 1',
result: () => exec(formatBlock, '<h1>')
},
heading2: {
icon: '<b>H<sub>2</sub></b>',
title: 'Heading 2',
result: () => exec(formatBlock, '<h2>')
},
paragraph: {
icon: '&#182;',
title: 'Paragraph',
result: () => exec(formatBlock, '<p>')
},
quote: {
icon: '&#8220; &#8221;',
title: 'Quote',
result: () => exec(formatBlock, '<blockquote>')
},
olist: {
icon: '&#35;',
title: 'Ordered List',
result: () => exec('insertOrderedList')
},
ulist: {
icon: '&#8226;',
title: 'Unordered List',
result: () => exec('insertUnorderedList')
},
code: {
icon: '&lt;/&gt;',
title: 'Code',
result: () => exec(formatBlock, '<pre>')
},
line: {
icon: '&#8213;',
title: 'Horizontal Line',
result: () => exec('insertHorizontalRule')
},
link: {
icon: '&#128279;',
title: 'Link',
result: () => navigator.clipboard.readText().then(url => exec('createLink', url))
},
image: {
icon: '&#128247;',
title: 'Image',
result: () => {
navigator.clipboard.readText().then(url => exec('insertImage', url))
exec('enableObjectResizing')
}
}
}

const defaultClasses = {
actionbar: 'pell-actionbar',
button: 'pell-button',
content: 'pell-content',
selected: 'pell-button-selected'
}

const init = settings => {
const actions = settings.actions
? (
settings.actions.map(action => {
if (typeof action === 'string') return defaultActions[action]
else if (defaultActions[action.name]) return { ...defaultActions[action.name], ...action }
return action
})
)
: Object.keys(defaultActions).map(action => defaultActions[action])

const classes = { ...defaultClasses, ...settings.classes }

const defaultParagraphSeparator = settings[defaultParagraphSeparatorString] || 'div'

const actionbar = createElement('div')
actionbar.className = classes.actionbar
appendChild(settings.element, actionbar)

const content = settings.element.content = createElement('div')
content.contentEditable = true
content.className = classes.content
content.oninput = ({ target: { firstChild } }) => {
if (firstChild && firstChild.nodeType === 3) exec(formatBlock, `<${defaultParagraphSeparator}>`)
else if (content.innerHTML === '<br>') content.innerHTML = ''
settings.onChange(content.innerHTML)
}
content.onkeydown = event => {
if (event.key === 'Enter' && queryCommandValue(formatBlock) === 'blockquote') {
setTimeout(() => exec(formatBlock, `<${defaultParagraphSeparator}>`), 0)
}
}
appendChild(settings.element, content)

actions.forEach(action => {
const button = createElement('button')
button.className = classes.button
button.innerHTML = action.icon
button.title = action.title
button.setAttribute('type', 'button')
button.onclick = () => action.result() && content.focus()

if (action.state) {
const handler = () => button.classList[action.state() ? 'add' : 'remove'](classes.selected)
addEventListener(content, 'keyup', handler)
addEventListener(content, 'mouseup', handler)
addEventListener(button, 'click', handler)
}

appendChild(actionbar, button)
})

if (settings.styleWithCSS) exec('styleWithCSS')
exec(defaultParagraphSeparatorString, defaultParagraphSeparator)

return settings.element
}

return {exec, init}

})));
Loading

0 comments on commit 36870a3

Please sign in to comment.