zcloudcmd
Version:
### [Main][MainURL] [Blog][BlogURL] Live([Heroku][HerokuURL], [Now][NowURL])
180 lines (173 loc) • 15.3 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/view": 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/view.js","cloudcmd.common"]);
/******/ // run deferred modules when ready
/******/ return checkDeferredModules();
/******/ })
/************************************************************************/
/******/ ({
/***/ "./client/modules/view.js":
/*!********************************!*\
!*** ./client/modules/view.js ***!
\********************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
eval("\n\n/* global CloudCmd, DOM */\n\n__webpack_require__(/*! ../../css/view.css */ \"./css/view.css\");\n\nconst itype = __webpack_require__(/*! itype/legacy */ \"./node_modules/itype/legacy/index.js\");\nconst rendy = __webpack_require__(/*! rendy/legacy */ \"./node_modules/rendy/legacy/index.js\");\nconst exec = __webpack_require__(/*! execon */ \"./node_modules/execon/lib/exec.js\");\nconst currify = __webpack_require__(/*! currify/legacy */ \"./node_modules/currify/legacy/index.js\");\nconst {promisify} = __webpack_require__(/*! es6-promisify */ \"./node_modules/es6-promisify/dist/promisify.js\");\n\nconst modal = __webpack_require__(/*! @cloudcmd/modal */ \"./node_modules/@cloudcmd/modal/legacy/modal.js\");\nconst createElement = __webpack_require__(/*! @cloudcmd/create-element */ \"./node_modules/@cloudcmd/create-element/legacy/create-element.js\");\n\nconst {time} = __webpack_require__(/*! ../../common/util */ \"./common/util.js\");\nconst {FS} = __webpack_require__(/*! ../../common/cloudfunc */ \"./common/cloudfunc.js\");\n\nconst Files = __webpack_require__(/*! ../dom/files */ \"./client/dom/files.js\");\nconst Events = __webpack_require__(/*! ../dom/events */ \"./client/dom/events/index.js\");\nconst load = __webpack_require__(/*! load.js */ \"./node_modules/load.js/legacy/load.js\");\nconst Images = __webpack_require__(/*! ../dom/images */ \"./client/dom/images.js\");\n\nconst {encode} = __webpack_require__(/*! ../../common/entity */ \"./common/entity.js\");\n\nconst testRegExp = currify((name, reg) => reg.test(name));\nconst lifo = currify((fn, el, cb, name) => fn(name, el, cb));\n\nconst addEvent = lifo(Events.add);\nconst getRegExp = (ext) => RegExp(`\\\\.${ext}$`, 'i');\n\nconst loadCSS = promisify(load.css);\n\nmodule.exports.show = show;\nmodule.exports.hide = hide;\n\nlet Loading = false;\n\nconst Name = 'View';\nCloudCmd[Name] = module.exports;\n\nconst Info = DOM.CurrentInfo;\nconst {Key} = CloudCmd;\nconst basename = (a) => a.split('/').pop();\n\nlet El;\nlet TemplateAudio;\nlet Overlay;\n\nconst Config = {\n beforeShow: (callback) => {\n Images.hide();\n Key.unsetBind();\n exec(callback);\n },\n beforeClose: (callback) => {\n Events.rmKey(listener);\n Key.setBind();\n exec(callback);\n },\n afterShow: (callback) => {\n El.focus();\n exec(callback);\n },\n onOverlayClick,\n afterClose : exec,\n autoSize : false,\n helpers: {\n title: {},\n },\n};\n\nmodule.exports.init = async () => {\n await loadAll();\n \n const events = [\n 'click',\n 'contextmenu',\n ];\n \n events.forEach(addEvent(Overlay, onOverlayClick));\n};\n\nfunction show(data, options) {\n const prefixURL = CloudCmd.prefixURL + FS;\n \n if (Loading)\n return;\n \n if (!options || options.bindKeys !== false)\n Events.addKey(listener);\n \n El = createElement('div', {\n className: 'view',\n notAppend: true,\n });\n \n El.tabIndex = 0;\n \n if (data) {\n El.append(data);\n modal.open(El, initConfig(Config, options));\n return;\n }\n \n Images.show.load();\n \n const path = prefixURL + Info.path;\n const type = getType(path);\n \n switch(type) {\n default:\n return viewFile();\n \n case 'image':\n return viewImage(prefixURL);\n \n case 'media':\n return viewMedia(path);\n }\n}\n\nfunction viewMedia(path) {\n getMediaElement(path, (element) => {\n const allConfig = {\n ...Config,\n ...{\n autoSize: true,\n afterShow: () => {\n element\n .querySelector('audio, video')\n .focus();\n },\n },\n };\n \n modal.open(element, allConfig);\n });\n}\n\nfunction viewFile() {\n Info.getData((error, data) => {\n if (error)\n return Images.hide();\n \n const element = document.createTextNode(data);\n const options = {\n ...Config,\n };\n \n if (CloudCmd.config('showFileName'))\n options.title = Info.name;\n \n El.append(element);\n modal.open(El, options);\n });\n}\n\nfunction initConfig(Config, options) {\n const config = {\n ...Config,\n };\n \n if (!options)\n return config;\n \n Object.keys(options).forEach((name) => {\n const isConfig = !!config[name];\n const item = options[name];\n const isFunc = itype.function(item);\n \n if (!isFunc || !isConfig) {\n config[name] = options[name];\n return;\n }\n \n const func = config[name];\n config[name] = () => {\n exec.series([func, item]);\n };\n });\n \n return config;\n}\n\nfunction hide() {\n modal.close();\n}\n\nfunction viewImage(prefixURL) {\n const makeTitle = (path) => {\n return {\n href: prefixURL + path,\n title: encode(basename(path)),\n };\n };\n \n const names = Info.files\n .map(DOM.getCurrentPath)\n .filter(isImage);\n \n const titles = names\n .map(makeTitle);\n \n const index = names.indexOf(Info.path);\n const imageConfig = {\n index,\n autoSize : true,\n arrows : true,\n keys : true,\n helpers : {\n title : {},\n },\n };\n \n const config = {\n ...Config,\n ...imageConfig,\n };\n \n modal.open(titles, config);\n}\n\nfunction isImage(name) {\n const images = [\n 'jp(e|g|eg)',\n 'gif',\n 'png',\n 'bmp',\n 'webp',\n 'svg',\n 'ico',\n ];\n \n return images\n .map(getRegExp)\n .some(testRegExp(name));\n}\n\nfunction isMedia(name) {\n return isAudio(name) || isVideo(name);\n}\n\nfunction isAudio(name) {\n return /\\.(mp3|ogg|m4a)$/i.test(name);\n}\n\nfunction isVideo(name) {\n return /\\.(mp4|avi)$/i.test(name);\n}\n\nfunction getType(name) {\n if (isImage(name))\n return 'image';\n \n if (isMedia(name))\n return 'media';\n}\n\nfunction getMediaElement(src, callback) {\n check(src, callback);\n \n Files.get('view/media-tmpl', (error, template) => {\n const {name} = Info;\n \n if (error)\n return alert(error);\n \n if (!TemplateAudio)\n TemplateAudio = template;\n \n const is = isAudio(name);\n const type = is ? 'audio' : 'video';\n \n const innerHTML = rendy(TemplateAudio, {\n src,\n type,\n name,\n });\n \n const element = createElement('div', {\n innerHTML,\n });\n \n callback(element);\n });\n}\n\nfunction check(src, callback) {\n if (typeof src !== 'string')\n throw Error('src should be a string!');\n \n if (typeof callback !== 'function')\n throw Error('callback should be a function');\n}\n\n/**\n * function loads css and js of FancyBox\n * @callback - executes, when everything loaded\n */\nasync function loadAll() {\n const {prefix} = CloudCmd;\n \n time(Name + ' load');\n \n Loading = true;\n await loadCSS(`${prefix}/dist/view.css`);\n Loading = false;\n}\n\nfunction onOverlayClick(event) {\n const position = {\n x: event.clientX,\n y: event.clientY,\n };\n \n setCurrentByPosition(position);\n}\n\nfunction setCurrentByPosition(position) {\n const element = DOM.getCurrentByPosition(position);\n \n if (!element)\n return;\n \n const {\n files,\n filesPassive,\n } = Info;\n \n const isFiles = ~files.indexOf(element);\n const isFilesPassive = ~filesPassive.indexOf(element);\n \n if (!isFiles && !isFilesPassive)\n return;\n \n const isCurrent = DOM.isCurrentFile(element);\n \n if (isCurrent)\n return;\n \n DOM.setCurrentFile(element);\n}\n\nfunction listener({keyCode}) {\n if (keyCode === Key.ESC)\n hide();\n}\n\n\n\n//# sourceURL=file://cloudcmd/client/modules/view.js");
/***/ }),
/***/ "./css/view.css":
/*!**********************!*\
!*** ./css/view.css ***!
\**********************/
/*! no static exports found */
/***/ (function(module, exports) {
eval("// removed by extract-text-webpack-plugin\n\n//# sourceURL=file://cloudcmd/css/view.css");
/***/ })
/******/ });