ui progress
This commit is contained in:
parent
76c7e7b8a6
commit
c67c2b4c50
37 changed files with 773 additions and 788 deletions
|
|
@ -1,5 +1,5 @@
|
|||
var screenfull = require('screenfull'),
|
||||
{Popup} = require('./utils'),
|
||||
UiModal = require('./ui-modal'),
|
||||
locales = require('../locales')
|
||||
|
||||
var fullscreen
|
||||
|
|
@ -21,7 +21,7 @@ if (screenfull.isEnabled) {
|
|||
|
||||
toggle(){
|
||||
|
||||
new Popup({
|
||||
new UiModal({
|
||||
title: locales('fs_unnavailable'),
|
||||
content: locales('fs_addtohome'),
|
||||
closable: true
|
||||
|
|
|
|||
|
|
@ -1,16 +1,8 @@
|
|||
require('./zoom')
|
||||
require('./lobby').create()
|
||||
// require('./lobby').create()
|
||||
// require('./sidepanel')
|
||||
require('../events/click')
|
||||
require('./ios')
|
||||
require('./notifications')
|
||||
require('./ui-workspace')
|
||||
// require('./ui-sidepanel')
|
||||
|
||||
var UiModal = require('./ui-modal')
|
||||
|
||||
module.exports = {
|
||||
|
||||
uiModal: new UiModal({selector: 'osc-modal-container'})
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
var html = require('nanohtml')
|
||||
|
||||
class Lobby {
|
||||
|
||||
constructor() {
|
||||
|
||||
this.state = 0
|
||||
|
||||
}
|
||||
|
||||
create() {
|
||||
|
||||
this.html = html`
|
||||
<div id="lobby">
|
||||
<div class="main">
|
||||
<div class="header">
|
||||
${PACKAGE.productName}
|
||||
</div>
|
||||
<div class="list"></div>
|
||||
<div class="footer"></div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
||||
this.main = DOM.get(this.html, '.main')[0]
|
||||
this.list = DOM.get(this.html, '.list')[0]
|
||||
this.footer = DOM.get(this.html, '.footer')[0]
|
||||
|
||||
}
|
||||
|
||||
open() {
|
||||
if (this.state) return
|
||||
this.state = 1
|
||||
document.body.appendChild(this.html)
|
||||
setTimeout(()=>{
|
||||
this.main.classList.add('show')
|
||||
})
|
||||
}
|
||||
|
||||
close() {
|
||||
if (!this.state) return
|
||||
this.state = 0
|
||||
this.main.classList.remove('show')
|
||||
document.body.removeChild(this.html)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var lobby = new Lobby()
|
||||
|
||||
module.exports = lobby
|
||||
|
|
@ -144,8 +144,8 @@ class UiDragResize extends UiWidget {
|
|||
|
||||
var handlesVisibility = [
|
||||
!(widget instanceof Tab) && widget.parent.getProp('layout') === 'default', // nw
|
||||
widget.parent.getProp('layout') !== 'vertical', // e
|
||||
widget.parent.getProp('layout') !== 'horizontal', // s
|
||||
widget.parent.getProp('layout').match(/horizontal|default/), // e
|
||||
widget.parent.getProp('layout').match(/vertical|default/), // s
|
||||
]
|
||||
handlesVisibility.push(handlesVisibility[1] && handlesVisibility[2]) // se
|
||||
|
||||
|
|
|
|||
206
src/client/ui/ui-filebrowser.js
Normal file
206
src/client/ui/ui-filebrowser.js
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
var locales = require('../locales'),
|
||||
html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw'),
|
||||
ipc = require('../ipc'),
|
||||
doubleClick = require('../events/double-click'),
|
||||
{icon} = require('./utils'),
|
||||
UiModal = require('./ui-modal')
|
||||
|
||||
|
||||
module.exports = function UiFilebrowser(options, callback) {
|
||||
|
||||
var save = options.save,
|
||||
saveInputFocus = undefined
|
||||
|
||||
var popup = new UiModal({
|
||||
closable: true,
|
||||
title: locales(save ? 'remotesave_save' : 'remotesave_open'),
|
||||
hide: true
|
||||
})
|
||||
|
||||
var container = DOM.get(popup.container, '.popup-content')[0],
|
||||
browser = html`<div class="file-browser"></div>`,
|
||||
ariane = html`<div class="ariane"></div>`,
|
||||
list = html`<form class="file-list"></form>`,
|
||||
saveInput = html`<input type="text" class="save-as no-keybinding" placeholder="${options.extension ? '*.' + options.extension : ''}" ${options.save ? '' : 'disabled'}/>`,
|
||||
actions = html`
|
||||
<div class="file-actions">
|
||||
${saveInput}
|
||||
<div class="btn cancel">${raw(icon('times'))} Cancel</div>
|
||||
${
|
||||
save ?
|
||||
html`<div class="btn submit save">${raw(icon('save'))} Save</div>` :
|
||||
html`<div class="btn submit open">${raw(icon('folder-open'))} Open</div>`
|
||||
}
|
||||
</div>
|
||||
`
|
||||
|
||||
var files = [],
|
||||
path = ''
|
||||
|
||||
var extRe = options.extension ? new RegExp('.*\\.' + options.extension + '$') : /.*/
|
||||
|
||||
if (save) {
|
||||
saveInput.addEventListener('change', ()=>{
|
||||
if (!saveInput.value.match(extRe)) saveInput.value += '.' + options.extension
|
||||
})
|
||||
saveInput.addEventListener('focus', ()=>{
|
||||
saveInputFocus = true
|
||||
})
|
||||
list.addEventListener('change', ()=>{
|
||||
saveInputFocus = false
|
||||
var choice = DOM.get(list, ':checked')[0]
|
||||
if (choice && choice.classList.contains('file')) {
|
||||
saveInput.value = choice.value
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
doubleClick(list, submit, {click: true})
|
||||
|
||||
function submit(){
|
||||
|
||||
var choice = DOM.get(list, ':checked')[0]
|
||||
|
||||
if (!choice && (!save || !saveInput.value) && !options.loadDir) return
|
||||
|
||||
if (choice && choice.classList.contains('folder') && (!save || !saveInputFocus)) {
|
||||
ipc.send('listDir', {path: [path, choice.value]})
|
||||
} else {
|
||||
if (save) {
|
||||
if (files.some(x=>x.name===saveInput.value)) {
|
||||
if (!confirm(locales('remotesave_overwrite'))) return
|
||||
}
|
||||
callback([path, saveInput.value])
|
||||
popup.close()
|
||||
} else {
|
||||
callback([path, choice ? choice.value : ''])
|
||||
popup.close()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
actions.addEventListener('click', (e)=>{
|
||||
if (e.target.classList.contains('submit')) {
|
||||
submit()
|
||||
} else if ((e.target.classList.contains('cancel'))){
|
||||
popup.close()
|
||||
}
|
||||
})
|
||||
|
||||
function keyDownHandler(e){
|
||||
|
||||
if (e.keyCode === 13) {
|
||||
if (save) {
|
||||
document.addEventListener('keyup', keyUpHandler)
|
||||
} else {
|
||||
submit()
|
||||
}
|
||||
} else if (e.target === saveInput) {
|
||||
return
|
||||
} else if (e.keyCode === 8) {
|
||||
list.childNodes[0].firstElementChild.checked = true
|
||||
submit()
|
||||
} else if (e.key.length === 1) {
|
||||
var letter = e.key.toLowerCase(),
|
||||
current = DOM.get(list, ':checked')[0],
|
||||
minIndex = -1,
|
||||
index = -1
|
||||
|
||||
if (current) minIndex = DOM.index(current.parentNode)
|
||||
|
||||
for (let i in files) {
|
||||
if (files[i].name[0].toLowerCase() === letter && !list.childNodes[i].firstElementChild.checked) {
|
||||
if (index === -1) index = i
|
||||
if (minIndex !== -1 && i < minIndex) continue
|
||||
index = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (index !== -1) {
|
||||
list.childNodes[index].firstElementChild.click()
|
||||
list.childNodes[index].firstElementChild.focus()
|
||||
}
|
||||
}
|
||||
}
|
||||
function keyUpHandler(e){
|
||||
|
||||
if (e.keyCode === 13) {
|
||||
setTimeout(submit, 100)
|
||||
document.removeEventListener('keyup', keyUpHandler)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', keyDownHandler)
|
||||
|
||||
ipc.on('listDir', (data)=>{
|
||||
|
||||
ariane.textContent = path = data.path
|
||||
|
||||
files = data.files.filter(x=>x.folder || x.name.match(extRe))
|
||||
|
||||
|
||||
function alphaSort(a, b){
|
||||
// convert to strings and force lowercase
|
||||
a = typeof a.name === 'string' ? a.name.toLowerCase() : a.name.toString()
|
||||
b = typeof b.name === 'string' ? b.name.toLowerCase() : b.name.toString()
|
||||
return a.localeCompare(b)
|
||||
}
|
||||
|
||||
var fo = files.filter(x=>x.folder),
|
||||
fi = files.filter(x=>!x.folder)
|
||||
|
||||
fo.sort(alphaSort)
|
||||
fi.sort(alphaSort)
|
||||
|
||||
files = fo.concat(fi)
|
||||
|
||||
files.unshift({
|
||||
name: '..',
|
||||
folder: true
|
||||
})
|
||||
|
||||
|
||||
browser.removeChild(list)
|
||||
list.innerHTML = ''
|
||||
for (let i in files) {
|
||||
var file = files[i]
|
||||
list.appendChild(html`
|
||||
<div class="file">
|
||||
<input type="radio" value="${file.name}" name="file" class="${file.folder ? 'folder' : 'file'}"/>
|
||||
<div class="label"><span>${raw(icon(file.folder ? 'folder' : 'osc'))} ${file.name}</span></div>
|
||||
</div>
|
||||
`)
|
||||
}
|
||||
|
||||
|
||||
browser.insertBefore(list, actions)
|
||||
|
||||
|
||||
if (save && saveInputFocus === undefined) {
|
||||
saveInput.focus()
|
||||
} else {
|
||||
list.childNodes[0].firstElementChild.focus()
|
||||
}
|
||||
|
||||
}, {context: popup})
|
||||
|
||||
popup.on('close', ()=>{
|
||||
ipc.off('listDir', null, popup)
|
||||
document.removeEventListener('keydown', keyDownHandler)
|
||||
document.removeEventListener('keyup', keyUpHandler)
|
||||
})
|
||||
|
||||
browser.appendChild(ariane)
|
||||
browser.appendChild(list)
|
||||
browser.appendChild(actions)
|
||||
container.appendChild(browser)
|
||||
|
||||
ipc.send('listDir', {extension: options.extension, path: options.directory ? [options.directory] : null})
|
||||
|
||||
popup.open()
|
||||
|
||||
}
|
||||
40
src/client/ui/ui-fileupload.js
Normal file
40
src/client/ui/ui-fileupload.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
var locales = require('../locales'),
|
||||
uiLoading = require('./ui-loading'),
|
||||
html = require('nanohtml'),
|
||||
SINGLETON = null,
|
||||
CONTAINER = null
|
||||
|
||||
module.exports = function uiFileUpload(types, ok, error) {
|
||||
|
||||
if (!CONTAINER) CONTAINER = DOM.get('osc-modal-container')[0]
|
||||
|
||||
if (SINGLETON) CONTAINER.removeChild(uploadSingleton)
|
||||
|
||||
SINGLETON = html`<input type="file" accept="${types}" style="position:absolute;opacity:0;pointer-events:none;"/>`
|
||||
|
||||
CONTAINER.appendChild(SINGLETON)
|
||||
|
||||
SINGLETON.addEventListener('change',function(e){
|
||||
|
||||
|
||||
var reader = new FileReader(),
|
||||
file = e.target.files[0],
|
||||
loader = uiLoading(locales('loading_upload'))
|
||||
|
||||
reader.onerror = reader.onabort = function() {
|
||||
loader.close()
|
||||
error()
|
||||
}
|
||||
|
||||
reader.onload = function(e) {
|
||||
loader.close()
|
||||
ok(file.path, e.target.result)
|
||||
}
|
||||
|
||||
reader.readAsText(file, 'utf-8')
|
||||
|
||||
})
|
||||
|
||||
SINGLETON.click()
|
||||
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ var UiWidget = require('./ui-widget'),
|
|||
{categories} = require('../widgets/'),
|
||||
html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw'),
|
||||
{icon, Popup} = require('../ui/utils'),
|
||||
{icon} = require('../ui/utils'),
|
||||
chroma = require('chroma-js')
|
||||
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ class UiInspectorField extends UiWidget {
|
|||
this.container = html`<osc-inspector-field></osc-inspector-field>`
|
||||
this.label = this.container.appendChild(html`<label>${this.name}</label>`)
|
||||
|
||||
if (this.name === 'type') this.createTypeSelect()
|
||||
if (this.name === 'type' || this.name === 'widgetType') this.createTypeSelect()
|
||||
else this.createInput()
|
||||
|
||||
}
|
||||
|
|
|
|||
12
src/client/ui/ui-loading.js
Normal file
12
src/client/ui/ui-loading.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
var html = require('nanohtml'),
|
||||
UiModal = require('./ui-modal')
|
||||
|
||||
module.exports = function uiLoading(title) {
|
||||
|
||||
return new UiModal({
|
||||
title: title,
|
||||
content: html`<p><div class="spinner"></div></p>`,
|
||||
closable: false
|
||||
})
|
||||
|
||||
}
|
||||
44
src/client/ui/ui-lobby.js
Normal file
44
src/client/ui/ui-lobby.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
var html = require('nanohtml'),
|
||||
UiModal = require('./ui-modal')
|
||||
|
||||
class UiLobby {
|
||||
|
||||
constructor() {
|
||||
|
||||
this.state = 0
|
||||
|
||||
this.container = html`
|
||||
<div class="lobby">
|
||||
<div class="list"></div>
|
||||
<div class="footer"></div>
|
||||
</div>
|
||||
`
|
||||
|
||||
this.list = DOM.get(this.container, '.list')[0]
|
||||
this.footer = DOM.get(this.container, '.footer')[0]
|
||||
|
||||
this.modal = new UiModal({
|
||||
content: this.container,
|
||||
closable: false,
|
||||
title: `${PACKAGE.productName} v${PACKAGE.version}`
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
open() {
|
||||
|
||||
this.modal.open()
|
||||
|
||||
}
|
||||
|
||||
close() {
|
||||
|
||||
this.modal.close()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var uiLobby = new UiLobby()
|
||||
|
||||
module.exports = uiLobby
|
||||
|
|
@ -1,97 +1,100 @@
|
|||
var UiWidget = require('./ui-widget'),
|
||||
{icon} = require('./utils'),
|
||||
html = require('nanohtml'),
|
||||
raw = require('nanohtml/raw'),
|
||||
{iconify} = require('../ui/utils')
|
||||
|
||||
|
||||
class UiModalWindow {
|
||||
|
||||
constructor(options) {
|
||||
|
||||
this.container = html`
|
||||
<osc-modal-window class="${options.class || ''}">
|
||||
<inner>
|
||||
${options.content}
|
||||
</inner>
|
||||
</osc-modal-window>
|
||||
`
|
||||
|
||||
if (options.label) {
|
||||
this.container.appendChild(html`<label>${raw(iconify(options.label))}</label>`)
|
||||
}
|
||||
|
||||
this.opened = false
|
||||
}
|
||||
|
||||
open(z) {
|
||||
|
||||
this.opened = true
|
||||
this.container.classList.add('on')
|
||||
this.container.style.zIndex = z
|
||||
|
||||
}
|
||||
|
||||
close() {
|
||||
|
||||
this.opened = false
|
||||
this.container.classList.remove('on')
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
SINGLETON = null,
|
||||
CONTAINER = null
|
||||
|
||||
class UiModal extends UiWidget {
|
||||
|
||||
constructor(options) {
|
||||
constructor(options) {
|
||||
|
||||
super(options)
|
||||
super(options)
|
||||
|
||||
this.modals = {}
|
||||
this.openedModals = []
|
||||
if (!CONTAINER) CONTAINER = DOM.get('osc-modal-container')[0]
|
||||
|
||||
}
|
||||
if (options.closable) {
|
||||
|
||||
create(id, options) {
|
||||
if (SINGLETON) SINGLETON.close()
|
||||
SINGLETON = this
|
||||
|
||||
if (this.modals[id]) this.destroy(id)
|
||||
}
|
||||
|
||||
this.modals[id] = new UiModalWindow(options)
|
||||
this.container.appendChild(this.modals[id].container)
|
||||
this.escKey = options.closable || options.escKey
|
||||
this.enterKey = options.enterKey
|
||||
this.state = 0
|
||||
|
||||
this.container = html`
|
||||
<div class="popup show">
|
||||
<div class="popup-wrapper">
|
||||
<div class="popup-title ${options.closable? 'closable' : ''}">
|
||||
<span class="title">
|
||||
${options.icon ? raw(icon(options.icon)) : ''}
|
||||
${options.title}
|
||||
</span>
|
||||
${options.closable? html`<span class="closer">${raw(icon('times'))}</span>` : ''}
|
||||
</div>
|
||||
<div class="popup-content">
|
||||
${options.content}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
||||
if (options.closable) {
|
||||
var closer = DOM.get(this.container, '.popup-title .closer')[0]
|
||||
this.container.addEventListener('fast-click',(e)=>{
|
||||
if (e.target === this.container || e.target === closer) {
|
||||
e.detail.preventOriginalEvent = true
|
||||
this.close()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (this.escKey) {
|
||||
this.escKeyHandler = ((e)=>{
|
||||
if (e.keyCode==27) this.close()
|
||||
}).bind(this)
|
||||
}
|
||||
|
||||
if (this.enterKey) {
|
||||
this.enterKeyHandler = ((e)=>{
|
||||
if (e.keyCode == 13) this.enterKey.call(this, e)
|
||||
}).bind(this)
|
||||
}
|
||||
|
||||
if (!options.hide) this.open()
|
||||
|
||||
|
||||
}
|
||||
|
||||
destroy(id) {
|
||||
|
||||
if (!this.modals[id]) return
|
||||
|
||||
this.close(id)
|
||||
this.container.removeChild(this.modals[id].container)
|
||||
delete this.modals[id]
|
||||
}
|
||||
|
||||
open(id) {
|
||||
|
||||
if (!this.modals[id]) return
|
||||
if (this.openedModals.includes(id)) this.close(id)
|
||||
|
||||
this.openedModals.push(id)
|
||||
|
||||
this.modals[id].open(this.openedModals.length)
|
||||
|
||||
}
|
||||
|
||||
close(id) {
|
||||
|
||||
if (!this.modals[id] || !this.openedModals.includes(id)) return
|
||||
|
||||
this.openedModals.splice(this.openedModals.indexOf(id), 1)
|
||||
this.modals[id].close()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
close() {
|
||||
|
||||
if (!this.state) return
|
||||
this.state = 0
|
||||
|
||||
if (this.escKey) document.removeEventListener('keydown', this.escKeyHandler)
|
||||
if (this.enterKey) document.removeEventListener('keydown', this.enterKeyHandler)
|
||||
CONTAINER.removeChild(this.container)
|
||||
|
||||
this.trigger('close')
|
||||
|
||||
}
|
||||
|
||||
open() {
|
||||
|
||||
if (this.state) return
|
||||
this.state = 1
|
||||
|
||||
if (this.escKey) document.addEventListener('keydown', this.escKeyHandler)
|
||||
if (this.enterKey) document.addEventListener('keydown', this.enterKeyHandler)
|
||||
CONTAINER.appendChild(this.container)
|
||||
|
||||
this.trigger('open')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = UiModal
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ var UiWidget = require('./ui-widget'),
|
|||
doubleClick = require('../events/double-click'),
|
||||
Sortable = require('sortablejs'),
|
||||
morph = require('nanomorph'),
|
||||
Panel, widgetManager
|
||||
Panel, Matrix, widgetManager
|
||||
|
||||
class UiTree extends UiWidget {
|
||||
|
||||
constructor(options) {
|
||||
|
||||
Panel = require('../widgets/containers/panel')
|
||||
Matrix = require('../widgets/containers/matrix')
|
||||
widgetManager = require('../managers/widgets')
|
||||
|
||||
super(options)
|
||||
|
|
@ -139,7 +140,7 @@ class UiTree extends UiWidget {
|
|||
data-id="${id}"">
|
||||
${id}</li>`
|
||||
|
||||
if (widget instanceof Panel) {
|
||||
if (widget instanceof Panel && !(widget instanceof Matrix)) {
|
||||
node.insertBefore(html`<span class="toggle no-widget-select"></span>`, node.childNodes[0])
|
||||
node.classList.add('container')
|
||||
if (this.expanded[id]) node.classList.add('expanded')
|
||||
|
|
|
|||
|
|
@ -9,342 +9,14 @@ var popupSingleton = null,
|
|||
|
||||
module.exports = {
|
||||
|
||||
Popup: class Popup extends EventEmitter {
|
||||
|
||||
constructor(options) {
|
||||
|
||||
super()
|
||||
|
||||
if (options.closable) {
|
||||
|
||||
if (popupSingleton) {
|
||||
popupSingleton.close()
|
||||
popupSingleton = null
|
||||
}
|
||||
|
||||
popupSingleton = this
|
||||
|
||||
}
|
||||
|
||||
this.closable = options.closable
|
||||
this.escKey = options.closable || options.escKey
|
||||
this.enterKey = options.enterKey
|
||||
this.content = options.content
|
||||
this.title = options.title
|
||||
this.state = 0
|
||||
|
||||
this.html = html`
|
||||
<div class="popup show">
|
||||
<div class="popup-wrapper">
|
||||
<div class="popup-title ${this.closable? 'closable' : ''}">
|
||||
<span class="title">
|
||||
${options.icon ? raw(module.exports.icon(options.icon)) : ''}
|
||||
${this.title}
|
||||
</span>
|
||||
${this.closable? html`<span class="closer">${raw(module.exports.icon('times'))}</span>` : ''}
|
||||
</div>
|
||||
<div class="popup-content">
|
||||
${this.content}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
||||
if (this.closable) {
|
||||
var closer = DOM.get(this.html, '.popup-title .closer')[0]
|
||||
this.html.addEventListener('fast-click',(e)=>{
|
||||
if (e.target === this.html || e.target === closer) {
|
||||
e.detail.preventOriginalEvent = true
|
||||
this.close()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (this.escKey) {
|
||||
this.escKeyHandler = ((e)=>{
|
||||
if (e.keyCode==27) this.close()
|
||||
}).bind(this)
|
||||
}
|
||||
|
||||
if (this.enterKey) {
|
||||
this.enterKeyHandler = ((e)=>{
|
||||
if (e.keyCode == 13) this.enterKey.call(this, e)
|
||||
}).bind(this)
|
||||
}
|
||||
|
||||
if (!options.hide) this.open()
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
close() {
|
||||
|
||||
if (!this.state) return
|
||||
this.state = 0
|
||||
|
||||
if (this.escKey) document.removeEventListener('keydown', this.escKeyHandler)
|
||||
if (this.enterKey) document.removeEventListener('keydown', this.enterKeyHandler)
|
||||
document.body.removeChild(this.html)
|
||||
|
||||
this.trigger('close')
|
||||
|
||||
}
|
||||
|
||||
open() {
|
||||
|
||||
if (this.state) return
|
||||
this.state = 1
|
||||
|
||||
if (this.escKey) document.addEventListener('keydown', this.escKeyHandler)
|
||||
if (this.enterKey) document.addEventListener('keydown', this.enterKeyHandler)
|
||||
document.body.appendChild(this.html)
|
||||
|
||||
this.trigger('open')
|
||||
}
|
||||
},
|
||||
|
||||
loading: function(title){
|
||||
return new module.exports.Popup({
|
||||
title: title,
|
||||
content: html`<p><div class="spinner"></div></p>`,
|
||||
closable: false
|
||||
})
|
||||
},
|
||||
icon: function(i) {
|
||||
return `<i class="fa fa-fw fa-${i}"></i>`
|
||||
},
|
||||
iconify:function(string){
|
||||
return String(string).replace(/\^[^\s]*/g,(x)=>{return module.exports.icon(x.substring(1))})
|
||||
},
|
||||
upload: function(types, ok, error) {
|
||||
|
||||
if (uploadSingleton) document.body.removeChild(uploadSingleton)
|
||||
|
||||
uploadSingleton = html`<input type="file" accept="${types}" style="position:absolute;opacity:0;pointer-events:none;"/>`
|
||||
document.body.appendChild(uploadSingleton)
|
||||
|
||||
uploadSingleton.addEventListener('change',function(e){
|
||||
|
||||
|
||||
var reader = new FileReader(),
|
||||
file = e.target.files[0],
|
||||
loader = module.exports.loading(locales('loading_upload'))
|
||||
|
||||
reader.onerror = reader.onabort = function() {
|
||||
loader.close()
|
||||
error()
|
||||
}
|
||||
|
||||
reader.onload = function(e) {
|
||||
loader.close()
|
||||
ok(file.path, e.target.result)
|
||||
}
|
||||
|
||||
reader.readAsText(file, 'utf-8')
|
||||
|
||||
})
|
||||
|
||||
uploadSingleton.click()
|
||||
|
||||
},
|
||||
remoteBrowse: function(options, callback) {
|
||||
|
||||
var save = options.save,
|
||||
saveInputFocus = undefined
|
||||
|
||||
var popup = new module.exports.Popup({
|
||||
closable: true,
|
||||
title: locales(save ? 'remotesave_save' : 'remotesave_open'),
|
||||
hide: true
|
||||
})
|
||||
|
||||
var container = DOM.get(popup.html, '.popup-content')[0],
|
||||
browser = html`<div class="file-browser"></div>`,
|
||||
ariane = html`<div class="ariane"></div>`,
|
||||
list = html`<form class="file-list"></form>`,
|
||||
saveInput = html`<input type="text" class="save-as no-keybinding" placeholder="${options.extension ? '*.' + options.extension : ''}" ${options.save ? '' : 'disabled'}/>`,
|
||||
actions = html`
|
||||
<div class="file-actions">
|
||||
${saveInput}
|
||||
<div class="btn cancel">${raw(module.exports.icon('times'))} Cancel</div>
|
||||
${
|
||||
save ?
|
||||
html`<div class="btn submit save">${raw(module.exports.icon('save'))} Save</div>` :
|
||||
html`<div class="btn submit open">${raw(module.exports.icon('folder-open'))} Open</div>`
|
||||
}
|
||||
</div>
|
||||
`
|
||||
|
||||
var files = [],
|
||||
path = ''
|
||||
|
||||
var extRe = options.extension ? new RegExp('.*\\.' + options.extension + '$') : /.*/
|
||||
|
||||
if (save) {
|
||||
saveInput.addEventListener('change', ()=>{
|
||||
if (!saveInput.value.match(extRe)) saveInput.value += '.' + options.extension
|
||||
})
|
||||
saveInput.addEventListener('focus', ()=>{
|
||||
saveInputFocus = true
|
||||
})
|
||||
list.addEventListener('change', ()=>{
|
||||
saveInputFocus = false
|
||||
var choice = DOM.get(list, ':checked')[0]
|
||||
if (choice && choice.classList.contains('file')) {
|
||||
saveInput.value = choice.value
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
doubleTap(list, submit, {click: true})
|
||||
|
||||
function submit(){
|
||||
|
||||
var choice = DOM.get(list, ':checked')[0]
|
||||
|
||||
if (!choice && (!save || !saveInput.value) && !options.loadDir) return
|
||||
|
||||
if (choice && choice.classList.contains('folder') && (!save || !saveInputFocus)) {
|
||||
ipc.send('listDir', {path: [path, choice.value]})
|
||||
} else {
|
||||
if (save) {
|
||||
if (files.some(x=>x.name===saveInput.value)) {
|
||||
if (!confirm(locales('remotesave_overwrite'))) return
|
||||
}
|
||||
callback([path, saveInput.value])
|
||||
popup.close()
|
||||
} else {
|
||||
callback([path, choice ? choice.value : ''])
|
||||
popup.close()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
actions.addEventListener('click', (e)=>{
|
||||
if (e.target.classList.contains('submit')) {
|
||||
submit()
|
||||
} else if ((e.target.classList.contains('cancel'))){
|
||||
popup.close()
|
||||
}
|
||||
})
|
||||
|
||||
function keyDownHandler(e){
|
||||
|
||||
if (e.keyCode === 13) {
|
||||
if (save) {
|
||||
document.addEventListener('keyup', keyUpHandler)
|
||||
} else {
|
||||
submit()
|
||||
}
|
||||
} else if (e.target === saveInput) {
|
||||
return
|
||||
} else if (e.keyCode === 8) {
|
||||
list.childNodes[0].firstElementChild.checked = true
|
||||
submit()
|
||||
} else if (e.key.length === 1) {
|
||||
var letter = e.key.toLowerCase(),
|
||||
current = DOM.get(list, ':checked')[0],
|
||||
minIndex = -1,
|
||||
index = -1
|
||||
|
||||
if (current) minIndex = DOM.index(current.parentNode)
|
||||
|
||||
for (let i in files) {
|
||||
if (files[i].name[0].toLowerCase() === letter && !list.childNodes[i].firstElementChild.checked) {
|
||||
if (index === -1) index = i
|
||||
if (minIndex !== -1 && i < minIndex) continue
|
||||
index = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (index !== -1) {
|
||||
list.childNodes[index].firstElementChild.click()
|
||||
list.childNodes[index].firstElementChild.focus()
|
||||
}
|
||||
}
|
||||
}
|
||||
function keyUpHandler(e){
|
||||
|
||||
if (e.keyCode === 13) {
|
||||
setTimeout(submit, 100)
|
||||
document.removeEventListener('keyup', keyUpHandler)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', keyDownHandler)
|
||||
|
||||
ipc.on('listDir', (data)=>{
|
||||
|
||||
ariane.textContent = path = data.path
|
||||
|
||||
files = data.files.filter(x=>x.folder || x.name.match(extRe))
|
||||
|
||||
|
||||
function alphaSort(a, b){
|
||||
// convert to strings and force lowercase
|
||||
a = typeof a.name === 'string' ? a.name.toLowerCase() : a.name.toString()
|
||||
b = typeof b.name === 'string' ? b.name.toLowerCase() : b.name.toString()
|
||||
return a.localeCompare(b)
|
||||
}
|
||||
|
||||
var fo = files.filter(x=>x.folder),
|
||||
fi = files.filter(x=>!x.folder)
|
||||
|
||||
fo.sort(alphaSort)
|
||||
fi.sort(alphaSort)
|
||||
|
||||
files = fo.concat(fi)
|
||||
|
||||
files.unshift({
|
||||
name: '..',
|
||||
folder: true
|
||||
})
|
||||
|
||||
|
||||
browser.removeChild(list)
|
||||
list.innerHTML = ''
|
||||
for (let i in files) {
|
||||
var file = files[i]
|
||||
list.appendChild(html`
|
||||
<div class="file">
|
||||
<input type="radio" value="${file.name}" name="file" class="${file.folder ? 'folder' : 'file'}"/>
|
||||
<div class="label"><span>${raw(module.exports.icon(file.folder ? 'folder' : 'osc'))} ${file.name}</span></div>
|
||||
</div>
|
||||
`)
|
||||
}
|
||||
|
||||
|
||||
browser.insertBefore(list, actions)
|
||||
|
||||
|
||||
if (save && saveInputFocus === undefined) {
|
||||
saveInput.focus()
|
||||
} else {
|
||||
list.childNodes[0].firstElementChild.focus()
|
||||
}
|
||||
|
||||
}, {context: popup})
|
||||
|
||||
popup.on('close', ()=>{
|
||||
ipc.off('listDir', null, popup)
|
||||
document.removeEventListener('keydown', keyDownHandler)
|
||||
document.removeEventListener('keyup', keyUpHandler)
|
||||
})
|
||||
|
||||
browser.appendChild(ariane)
|
||||
browser.appendChild(list)
|
||||
browser.appendChild(actions)
|
||||
container.appendChild(browser)
|
||||
|
||||
ipc.send('listDir', {extension: options.extension, path: options.directory ? [options.directory] : null})
|
||||
|
||||
popup.open()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue