UNPKG

noide

Version:

Web Editor built on hapi and nes websockets using browserify, superviews.js, bootstrap and the ACE editor.

55 lines (48 loc) 1.24 kB
var page = require('page') var patch = require('../patch') var fs = require('../fs') var view = require('./view.html') function FileEditor (el) { var model = { mode: null, file: null, rename: fs.rename, mkfile: function (path) { fs.mkfile(path, function (err, payload) { if (!err) { // Open the new file. Leave a short delay // to allow it to register from the socket setTimeout(function () { page('/file?path=' + payload.relativePath) }, 500) } }) }, mkdir: fs.mkdir } function hide () { model.file = null model.mode = null patch(el, view, model, hide) } function show (file, mode) { model.file = file model.mode = mode patch(el, view, model, hide) var input = el.querySelector('input') input.focus() } this.show = show } FileEditor.prototype.rename = function (file) { this.show(file, 'rename') } FileEditor.prototype.mkfile = function (dir) { this.show(dir, 'mkfile') } FileEditor.prototype.mkdir = function (dir) { this.show(dir, 'mkdir') } var fileEditorEl = document.getElementById('file-editor') var fileEditor = new FileEditor(fileEditorEl) module.exports = fileEditor