@ -1,7 +1,3 @@ | |||
#zoom button { | |||
padding: 0; | |||
} | |||
#zoom input[type="number"] { | |||
width: 3em; | |||
} |
@ -1,61 +1,40 @@ | |||
return { | |||
/* Display */ | |||
var windowCatchAll = document.getElementById('windowCatchAll'); | |||
var workzone = document.getElementById('workzone'); | |||
var page = document.getElementById('page'); | |||
var selector = document.getElementById('selector'); | |||
windowCatchAll: document.getElementById('windowCatchAll'), | |||
workzone: document.getElementById('workzone'), | |||
page: document.getElementById('page'), | |||
selector: document.getElementById('selector'), | |||
/** Toolbar **/ | |||
/* Menus */ | |||
var menus = document.getElementsByClassName('menu'); | |||
var fileMenu = document.getElementById('file'); | |||
var loadALTO = document.getElementById('loadALTO'); | |||
var saveALTO = document.getElementById('saveALTO'); | |||
var loadScoria = document.getElementById('loadScoria'); | |||
var saveScoria = document.getElementById('saveScoria'); | |||
var helpMenu = document.getElementById('help'); | |||
var documentation = document.getElementById('documentation'); | |||
var reposLink = document.getElementById('reposLink'); | |||
[documentation, reposLink].forEach(function(elem) { | |||
elem.addEventListener('click', function(e) { | |||
if(e.target.tagName != 'A') { | |||
e.target.children[0].click(); | |||
} | |||
}); | |||
}); | |||
/* Controls */ | |||
var fileNumber = document.getElementById('fileNumber'); | |||
var fileName = document.getElementById('fileName'); | |||
var wcThreshold = document.getElementById('wcThreshold'); | |||
var mode = document.getElementById('mode'); | |||
var saveScoria = document.getElementById('saveScoria'); | |||
menus: document.getElementsByClassName('menu'), | |||
fileMenu: document.getElementById('file'), | |||
loadALTO: document.getElementById('loadALTO'), | |||
saveALTO: document.getElementById('saveALTO'), | |||
loadScoria: document.getElementById('loadScoria'), | |||
saveScoria: document.getElementById('saveScoria'), | |||
/* Zoom */ | |||
var zoom = document.getElementById('zoom'); | |||
var fitWidth = document.getElementById('fitWidth'); | |||
var zoomAmount = document.getElementById('zoomAmount'); | |||
var fitHeight = document.getElementById('fitHeight'); | |||
editMenu: document.getElementById('edit'), | |||
editCancel: document.getElementById('editCancel'), | |||
editRedo: document.getElementById('editRedo'), | |||
return { | |||
mode: mode, | |||
fileMenu: fileMenu, | |||
fileName: fileName, | |||
fileNumber: fileNumber, | |||
helpMenu: document.getElementById('help'), | |||
documentation: document.getElementById('documentation'), | |||
reposLink: document.getElementById('reposLink'), | |||
loadALTO: loadALTO, | |||
saveALTO: saveALTO, | |||
loadScoria: loadScoria, | |||
saveScoria: saveScoria, | |||
/* Controls */ | |||
fileNumber: document.getElementById('fileNumber'), | |||
fileName: document.getElementById('fileName'), | |||
wcThreshold: document.getElementById('wcThreshold'), | |||
mode: document.getElementById('mode'), | |||
menus: menus, | |||
page: page, | |||
selector: selector, | |||
wcThreshold: wcThreshold, | |||
windowCatchAll: windowCatchAll, | |||
workzone: workzone, | |||
/* Cancel / Redo */ | |||
cancel: document.getElementById('cancel'), | |||
redo: document.getElementById('redo'), | |||
fitWidth: fitWidth, | |||
zoomAmount: zoomAmount, | |||
fitHeight: fitHeight | |||
/* Zoom */ | |||
zoom: document.getElementById('zoom'), | |||
fitWidth: document.getElementById('fitWidth'), | |||
zoomAmount: document.getElementById('zoomAmount'), | |||
fitHeight: document.getElementById('fitHeight') | |||
}; |
@ -0,0 +1,62 @@ | |||
import GUI; | |||
import bind from GUI.Keys; | |||
import toggleWord from Scoria; | |||
var edits = []; | |||
var cursor = -1; | |||
GUI.cancel.addEventListener('click', cancel); | |||
GUI.editCancel.addEventListener('click', cancel); | |||
GUI.redo.addEventListener('click', redo); | |||
GUI.editRedo.addEventListener('click', redo); | |||
bind('Ctrl+z', cancel); | |||
bind('Ctrl+y', redo); | |||
return { | |||
push: push | |||
}; | |||
function cancel(e) { | |||
if(cursor >= 0) { | |||
edits[cursor--].wordIds.forEach(function(wordId) {toggleWord(wordId);}); | |||
updateButtons(); | |||
} else if(e != undefined) { | |||
e.stopPropagation(); | |||
} | |||
} | |||
function redo(e) { | |||
if(cursor < edits.length - 1) { | |||
edits[++cursor].wordIds.forEach(function(wordId) {toggleWord(wordId);}); | |||
updateButtons(); | |||
} else if(e != undefined) { | |||
e.stopPropagation(); | |||
} | |||
} | |||
function push(description, wordIds, perform) { | |||
edits.length = ++cursor + 1; | |||
edits[cursor] = {description: description, wordIds: wordIds}; | |||
if(perform) { | |||
wordIds.forEach(function(wordId) {toggleWord(wordId);}); | |||
} | |||
updateButtons(); | |||
} | |||
function setState(action, disabled) { | |||
if(action == 'redo') { | |||
var label = 'Refaire' + (disabled ? '' : ' ' + edits[cursor + 1].description); | |||
} else { | |||
var label = 'Annuler' + (disabled ? '' : ' ' + edits[cursor].description); | |||
} | |||
GUI[action].title = label; | |||
GUI[action].disabled = disabled; | |||
var menuElem = GUI['edit' + action[0].toUpperCase() + action.slice(1)]; | |||
menuElem.textContent = label; | |||
menuElem.classList.toggle('disabled', disabled); | |||
} | |||
function updateButtons() { | |||
setState('cancel', cursor < 0); | |||
setState('redo', cursor >= edits.length - 1); | |||
} |
@ -1,18 +1,39 @@ | |||
var bindings = {}; | |||
var bindings = binTree(4); | |||
return { | |||
bind: bind, | |||
init: init | |||
}; | |||
function binTree(n) { | |||
if(n == 0) { | |||
return {}; | |||
} else { | |||
return {false: binTree(n-1), true: binTree(n-1)}; | |||
} | |||
} | |||
function bind(keyCode, f) { | |||
bindings[keyCode] = f; | |||
var components = keyCode.match(/((?:Alt|Ctrl|Meta|Shift)\+)*(.+)$/); | |||
if(components) { | |||
var key = components[2]; | |||
var modifiers = components[0].split('+'); | |||
bindings | |||
[modifiers.includes('Alt')] | |||
[modifiers.includes('Ctrl')] | |||
[modifiers.includes('Meta')] | |||
[modifiers.includes('Shift')] | |||
[key] = f; | |||
} else { | |||
console.log("Did not add binding for invalid key code '" + keyCode + "'"); | |||
} | |||
} | |||
function init() { | |||
window.addEventListener('keydown', function(e) { | |||
if(bindings[e.key] != undefined) { | |||
bindings[e.key](); | |||
var binding = bindings[e.altKey][e.ctrlKey][e.metaKey][e.shiftKey][e.key]; | |||
if(binding != undefined) { | |||
binding(); | |||
} | |||
}); | |||
} |
@ -1,9 +1,11 @@ | |||
import * as Keys from GUI.Keys; | |||
import * as EditMode from Toolbar.EditMode; | |||
import * as Help from Toolbar.Help; | |||
import * as Menu from Toolbar.Menu; | |||
import * as Page from Toolbar.Page; | |||
EditMode.sync(); | |||
Page.syncNumber(); | |||
Help.init(); | |||
Menu.init(); | |||
Keys.init(); |
@ -0,0 +1,15 @@ | |||
import {documentation, reposLink} from GUI; | |||
return { | |||
init: init | |||
}; | |||
function init() { | |||
[documentation, reposLink].forEach(function(elem) { | |||
elem.addEventListener('click', function(e) { | |||
if(e.target.tagName != 'A') { | |||
e.target.children[0].click(); | |||
} | |||
}); | |||
}); | |||
} |