diff --git a/src/services/Viewer.js b/src/services/Viewer.js index b56f79ffd..9ed09fc2f 100644 --- a/src/services/Viewer.js +++ b/src/services/Viewer.js @@ -47,6 +47,7 @@ export default class Viewer { this._state.file = '' this._state.fileInfo = null this._state.files = [] + this._state.el = null this._state.loadMore = () => ([]) this._state.onPrev = () => {} this._state.onNext = () => {} @@ -114,6 +115,16 @@ export default class Viewer { return this._state.files } + /** + * Get the element to render the current file in + * + * @memberof Viewer + * @return {string} selector of the element + */ + get el() { + return this._state.el + } + /** * Get the supported mimetypes that can be opened with the viewer * @@ -183,6 +194,19 @@ export default class Viewer { return this._state.overrideHandlerId } + /** + * Set element to open viewer in + * + * @memberof Viewer + * @param {string} el selector of the element to render the file in + */ + setRootElement(el = null) { + if (this._state.file) { + throw new Error('Please set root element before calling Viewer.open().') + } + this._state.el = el + } + /** * Open the path into the viewer * @@ -223,12 +247,14 @@ export default class Viewer { } else { this._state.fileInfo = fileInfo } - this._state.files = list - this._state.loadMore = loadMore - this._state.onPrev = onPrev - this._state.onNext = onNext - this._state.onClose = onClose - this._state.canLoop = canLoop + if (!this._state.el) { + this._state.files = list + this._state.loadMore = loadMore + this._state.onPrev = onPrev + this._state.onNext = onNext + this._state.onClose = onClose + this._state.canLoop = canLoop + } } /** diff --git a/src/utils/fileUtils.js b/src/utils/fileUtils.js index 7016eadd4..74ac05730 100644 --- a/src/utils/fileUtils.js +++ b/src/utils/fileUtils.js @@ -56,18 +56,6 @@ const extractFilePaths = function(path) { return [dirPath, fileName] } -/** - * A single shared file can be opend with path: '/'. - * In this case there is no parent folder to find sibling files in. - * - * @param {string} path the full path - * @return {boolean} - */ -const isSingleSharedFile = function(path) { - - return path === '/' -} - /** * Sorting comparison function * @@ -153,4 +141,4 @@ const getDavPath = function({ filename, basename }) { return getRootPath() + encodeFilePath(filename) } -export { encodeFilePath, extractFilePaths, isSingleSharedFile, sortCompare, genFileInfo, getDavPath } +export { encodeFilePath, extractFilePaths, sortCompare, genFileInfo, getDavPath } diff --git a/src/views/Viewer.vue b/src/views/Viewer.vue index 9fdf962d3..df9f7a3ef 100644 --- a/src/views/Viewer.vue +++ b/src/views/Viewer.vue @@ -22,7 +22,24 @@ -->