zcloudcmd
Version:
### [Main][MainURL] [Blog][BlogURL] Live([Heroku][HerokuURL], [Now][NowURL])
169 lines (165 loc) • 14.9 kB
JavaScript
/******/ (function(modules) { // webpackBootstrap
/******/ // install a JSONP callback for chunk loading
/******/ function webpackJsonpCallback(data) {
/******/ var chunkIds = data[0];
/******/ var moreModules = data[1];
/******/ var executeModules = data[2];
/******/
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0, resolves = [];
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
/******/ if(installedChunks[chunkId]) {
/******/ resolves.push(installedChunks[chunkId][0]);
/******/ }
/******/ installedChunks[chunkId] = 0;
/******/ }
/******/ for(moduleId in moreModules) {
/******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
/******/ modules[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(parentJsonpFunction) parentJsonpFunction(data);
/******/
/******/ while(resolves.length) {
/******/ resolves.shift()();
/******/ }
/******/
/******/ // add entry modules from loaded chunk to deferred list
/******/ deferredModules.push.apply(deferredModules, executeModules || []);
/******/
/******/ // run deferred modules when all chunks ready
/******/ return checkDeferredModules();
/******/ };
/******/ function checkDeferredModules() {
/******/ var result;
/******/ for(var i = 0; i < deferredModules.length; i++) {
/******/ var deferredModule = deferredModules[i];
/******/ var fulfilled = true;
/******/ for(var j = 1; j < deferredModule.length; j++) {
/******/ var depId = deferredModule[j];
/******/ if(installedChunks[depId] !== 0) fulfilled = false;
/******/ }
/******/ if(fulfilled) {
/******/ deferredModules.splice(i--, 1);
/******/ result = __webpack_require__(__webpack_require__.s = deferredModule[0]);
/******/ }
/******/ }
/******/ return result;
/******/ }
/******/
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // object to store loaded and loading chunks
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
/******/ // Promise = chunk loading, 0 = chunk loaded
/******/ var installedChunks = {
/******/ "./modules/menu": 0
/******/ };
/******/
/******/ var deferredModules = [];
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/dist/";
/******/
/******/ var jsonpArray = window["webpackJsonp"] = window["webpackJsonp"] || [];
/******/ var oldJsonpFunction = jsonpArray.push.bind(jsonpArray);
/******/ jsonpArray.push = webpackJsonpCallback;
/******/ jsonpArray = jsonpArray.slice();
/******/ for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);
/******/ var parentJsonpFunction = oldJsonpFunction;
/******/
/******/
/******/ // add entry module to deferred list
/******/ deferredModules.push(["./client/modules/menu.js","cloudcmd.common"]);
/******/ // run deferred modules when ready
/******/ return checkDeferredModules();
/******/ })
/************************************************************************/
/******/ ({
/***/ "./client/modules/menu.js":
/*!********************************!*\
!*** ./client/modules/menu.js ***!
\********************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("/* global CloudCmd, DOM */\n\n\n\nconst exec = __webpack_require__(/*! execon */ \"./node_modules/execon/lib/exec.js\");\nconst wrap = __webpack_require__(/*! wraptile/legacy */ \"./node_modules/wraptile/legacy/index.js\");\nconst supermenu = __webpack_require__(/*! supermenu */ \"./node_modules/supermenu/legacy/supermenu.js\");\nconst createElement = __webpack_require__(/*! @cloudcmd/create-element */ \"./node_modules/@cloudcmd/create-element/legacy/create-element.js\");\n\nconst {FS} = __webpack_require__(/*! ../../common/cloudfunc */ \"./common/cloudfunc.js\");\nconst {getIdBySrc} = __webpack_require__(/*! ../dom/load */ \"./client/dom/load.js\");\nconst RESTful = __webpack_require__(/*! ../dom/rest */ \"./client/dom/rest.js\");\n\nconst {\n config,\n Key,\n} = CloudCmd;\n\nconst {\n Buffer,\n Events,\n Dialog,\n Images,\n} = DOM;\n\nconst Info = DOM.CurrentInfo;\nconst TITLE = 'Cloud Commander';\nconst alertNoFiles = wrap(Dialog.alert.noFiles)(TITLE);\nconst uploadTo = wrap(_uploadTo);\n\nlet MenuShowedName;\nlet MenuContext;\nlet MenuContextFile;\n\nmodule.exports.ENABLED = false;\n\nCloudCmd.Menu = exports;\n\nmodule.exports.init = () => {\n const {\n isAuth,\n menuDataFile,\n } = getFileMenuData();\n \n const NOT_FILE = true;\n const fm = DOM.getFM();\n const menuData = getMenuData(isAuth);\n const options = getOptions(NOT_FILE);\n const optionsFile = getOptions();\n \n MenuContext = supermenu(fm, options, menuData);\n MenuContextFile = supermenu(fm, optionsFile, menuDataFile);\n \n Events.addKey(listener);\n};\n\nmodule.exports.hide = hide;\n\nfunction hide() {\n MenuContext.hide();\n MenuContextFile.hide();\n}\n\nmodule.exports.show = (position) => {\n const {x, y} = getPosition(position);\n \n MenuContext.show(x, y);\n MenuContextFile.show(x, y);\n \n Images.hide();\n};\n\nfunction getPosition(position) {\n if (position)\n return {\n x: position.x,\n y: position.y,\n };\n \n return getCurrentPosition();\n}\n\nfunction getMenuNameByEl(el) {\n if (!el)\n return 'context';\n \n const name = DOM.getCurrentName(el);\n \n if (name === '..')\n return 'context';\n \n return 'contextFile';\n}\n\nfunction getOptions(notFile) {\n let name;\n let func;\n \n if (notFile) {\n name = 'context';\n func = Key.unsetBind;\n } else {\n name = 'contextFile';\n }\n \n const options = {\n icon : true,\n beforeClose : Key.setBind,\n beforeShow : exec.with(beforeShow, func),\n beforeClick,\n name,\n };\n \n return options;\n}\n\nfunction getMenuData(isAuth) {\n const menu = {\n 'Paste': Buffer.paste,\n 'New': {\n 'File': DOM.promptNewFile,\n 'Directory': DOM.promptNewDir,\n },\n 'Upload': () => {\n CloudCmd.Upload.show();\n },\n 'Upload From Cloud': uploadFromCloud,\n '(Un)Select All': DOM.toggleAllSelectedFiles,\n };\n \n if (isAuth)\n menu['Log Out'] = CloudCmd.logOut;\n \n return menu;\n}\n\nfunction getFileMenuData() {\n const isAuth = CloudCmd.config('auth');\n const show = wrap((name) => {\n CloudCmd[name].show();\n });\n \n const menuBottom = getMenuData(isAuth);\n const menuTop = {\n 'View': show('View'),\n 'Edit': show('EditFile'),\n 'Rename': () => {\n setTimeout(DOM.renameCurrent, 100);\n },\n 'Delete': () => {\n CloudCmd.Operation.show('delete');\n },\n 'Pack': () => {\n CloudCmd.Operation.show('pack');\n },\n 'Extract': () => {\n CloudCmd.Operation.show('extract');\n },\n 'Download': preDownload,\n 'Upload To Cloud': uploadTo('Cloud'),\n 'Cut': () => {\n isCurrent(Buffer.cut, alertNoFiles);\n },\n 'Copy': () => {\n isCurrent(Buffer.copy, alertNoFiles);\n },\n };\n \n const menuDataFile = {\n ...menuTop,\n ...menuBottom,\n };\n \n return {\n isAuth,\n menuDataFile,\n };\n}\n\nfunction isCurrent(yesFn, noFn) {\n if (Info.name !== '..')\n return yesFn();\n \n noFn();\n}\n\nfunction isPath(x, y) {\n const {panel} = Info;\n const isEmptyRoot = !panel;\n \n if (isEmptyRoot)\n return false;\n \n const el = document.elementFromPoint(x, y);\n const elements = panel.querySelectorAll('[data-name=\"js-path\"] *');\n const is = ~[].indexOf.call(elements, el);\n \n return is;\n}\n\nfunction beforeShow(callback, params) {\n const {name} = params;\n const el = DOM.getCurrentByPosition({\n x: params.x,\n y: params.y,\n });\n \n const menuName = getMenuNameByEl(el);\n let notShow = menuName === 'contextFile';\n \n if (params.name === 'contextFile') {\n notShow = !notShow;\n }\n \n if (!notShow)\n MenuShowedName = name;\n \n exec(callback);\n \n if (!notShow)\n notShow = isPath(params.x, params.y);\n \n return notShow;\n}\n\nfunction beforeClick(name) {\n return MenuShowedName !== name;\n}\n\nfunction _uploadTo(nameModule) {\n Info.getData((error, data) => {\n if (error)\n return;\n \n const {name} = Info;\n const execFrom = CloudCmd.execFromModule;\n \n execFrom(nameModule, 'uploadFile', name, data);\n });\n \n CloudCmd.log('Uploading to ' + name + '...');\n}\n\nfunction uploadFromCloud() {\n Images.show.load('top');\n \n CloudCmd.execFromModule('Cloud', 'saveFile', (currentName, data) => {\n const path = DOM.getCurrentDirPath() + currentName;\n \n RESTful.write(path, data, (error) => {\n if (error)\n return;\n \n CloudCmd.refresh({currentName});\n });\n });\n}\n\nfunction preDownload() {\n download(config('packer'));\n}\n\nfunction download(type) {\n const TIME = 30 * 1000;\n const {prefixURL} = CloudCmd;\n const PACK = '/pack';\n const date = Date.now();\n const files = DOM.getActiveFiles();\n \n if (!files.length)\n return alertNoFiles();\n \n files.forEach((file) => {\n const selected = DOM.isSelected(file);\n const isDir = DOM.isCurrentIsDir(file);\n const path = DOM.getCurrentPath(file);\n \n CloudCmd.log('downloading file ' + path + '...');\n /*\n * if we send ajax request -\n * no need in hash so we escape #\n * and all other characters, like \"%\"\n */\n const encodedPath = encodeURI(path).replace(/#/g, '%23');\n const id = getIdBySrc(path);\n \n let src;\n \n if (isDir)\n src = prefixURL + PACK + encodedPath + DOM.getPackerExt(type);\n else\n src = prefixURL + FS + encodedPath + '?download';\n \n const element = createElement('iframe', {\n id : id + '-' + date,\n async: false,\n className: 'hidden',\n src,\n });\n \n const {body} = document;\n const removeChild = body.removeChild.bind(body, element);\n \n setTimeout(removeChild, TIME);\n \n if (selected)\n DOM.toggleSelectedFile(file);\n });\n}\n\nfunction getCurrentPosition() {\n const current = Info.element;\n const rect = current.getBoundingClientRect();\n \n const position = {\n x: Math.round(rect.left + rect.width / 3),\n y: Math.round(rect.top),\n };\n \n return position;\n}\n\nfunction listener(event) {\n const {\n F9,\n ESC,\n } = Key;\n \n const key = event.keyCode;\n const isBind = Key.isBind();\n \n if (!isBind)\n return;\n \n if (key === ESC)\n return hide();\n \n if (key === F9) {\n const position = getCurrentPosition();\n MenuContext.show(position.x, position.y);\n \n event.preventDefault();\n }\n}\n\n\n//# sourceURL=file://cloudcmd/client/modules/menu.js");
/***/ })
/******/ });