mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(cloudcmd) add ability to open html files using F3
This commit is contained in:
parent
cd7bf0fe01
commit
57485b5b4b
4 changed files with 53 additions and 6 deletions
|
|
@ -38,7 +38,6 @@ test('cloudcmd: client: key: enable vim', async (t) => {
|
|||
});
|
||||
|
||||
test('cloudcmd: client: key: disable vim', async (t) => {
|
||||
const vim = stub();
|
||||
const _config = stub();
|
||||
|
||||
const {_listener, setBind} = reRequire('.');
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ const Config = {
|
|||
title: {},
|
||||
},
|
||||
};
|
||||
module.exports._Config = Config;
|
||||
|
||||
module.exports.init = async () => {
|
||||
await loadAll();
|
||||
|
|
@ -126,6 +127,9 @@ async function show(data, options) {
|
|||
default:
|
||||
return viewFile();
|
||||
|
||||
case 'html':
|
||||
return viewHtml(path);
|
||||
|
||||
case 'image':
|
||||
return viewImage(prefixURL);
|
||||
|
||||
|
|
@ -137,7 +141,8 @@ async function show(data, options) {
|
|||
}
|
||||
}
|
||||
|
||||
function viewPDF(src) {
|
||||
module.exports._createIframe = createIframe;
|
||||
function createIframe(src) {
|
||||
const element = createElement('iframe', {
|
||||
src,
|
||||
width: '100%',
|
||||
|
|
@ -147,6 +152,15 @@ function viewPDF(src) {
|
|||
element.addEventListener('load', () => {
|
||||
element.contentWindow.addEventListener('keydown', listener);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports._viewHtml = viewHtml;
|
||||
function viewHtml(src) {
|
||||
modal.open(createIframe(src), Config);
|
||||
}
|
||||
|
||||
function viewPDF(src) {
|
||||
const element = createIframe(src);
|
||||
|
||||
const options = assign({}, Config);
|
||||
|
||||
|
|
@ -285,7 +299,8 @@ function isVideo(name) {
|
|||
return /\.(mp4|avi|webm)$/i.test(name);
|
||||
}
|
||||
|
||||
const isPDF = (name) => /\.(pdf)$/i.test(name);
|
||||
const isPDF = (name) => /\.pdf$/i.test(name);
|
||||
const isHTML = (name) => /\.html/.test(name);
|
||||
|
||||
function getType(name) {
|
||||
if (isPDF(name))
|
||||
|
|
@ -296,6 +311,9 @@ function getType(name) {
|
|||
|
||||
if (isMedia(name))
|
||||
return 'media';
|
||||
|
||||
if (isHTML(name))
|
||||
return 'html';
|
||||
}
|
||||
|
||||
async function getMediaElement(src) {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
require('css-modules-require-hook/preset');
|
||||
|
||||
const test = require('supertape');
|
||||
const {reRequire} = require('mock-require');
|
||||
const autoGlobals = require('auto-globals');
|
||||
const test = autoGlobals(require('supertape'));
|
||||
const stub = require('@cloudcmd/stub');
|
||||
const mockRequire = require('mock-require');
|
||||
const {reRequire} = mockRequire;
|
||||
|
||||
test('cloudcmd: client: view: initConfig', (t) => {
|
||||
let config;
|
||||
|
|
@ -50,3 +53,30 @@ test('cloudcmd: client: view: initConfig: no options', (t) => {
|
|||
t.end();
|
||||
});
|
||||
|
||||
test('cloudcmd: client: view: html', (t) => {
|
||||
const {CloudCmd, DOM} = global;
|
||||
|
||||
global.CloudCmd = {};
|
||||
global.DOM = {};
|
||||
const open = stub();
|
||||
|
||||
mockRequire('@cloudcmd/modal', {
|
||||
open,
|
||||
});
|
||||
|
||||
const {
|
||||
_viewHtml,
|
||||
_createIframe,
|
||||
_Config,
|
||||
} = reRequire('./view');
|
||||
|
||||
const src = '/hello.html';
|
||||
_viewHtml(src);
|
||||
|
||||
global.CloudCmd = CloudCmd;
|
||||
global.DOM = DOM;
|
||||
|
||||
t.calledWith(open, [_createIframe(src), _Config]);
|
||||
t.end();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ function getSize(file) {
|
|||
type,
|
||||
} = file;
|
||||
|
||||
if (/^directory$/.test(type))
|
||||
if (type === 'directory')
|
||||
return '<dir>';
|
||||
|
||||
if (/link/.test(type))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue