From 2cfe8b6a16329777224a841fd9d4210f9a7c8926 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 3 Feb 2018 16:43:25 +0100 Subject: [PATCH] Add `appendTo` option to BlockManager --- src/block_manager/config/config.js | 4 ++++ src/block_manager/index.js | 13 +++++++++++++ src/navigator/config/config.js | 4 ++-- src/styles/scss/_gjs_layers.scss | 12 ------------ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/block_manager/config/config.js b/src/block_manager/config/config.js index 9a66db002..db1ad9c68 100644 --- a/src/block_manager/config/config.js +++ b/src/block_manager/config/config.js @@ -1,4 +1,8 @@ module.exports = { + // Specify the element to use as a container, string (query) or HTMLElement + // With the empty value, nothing will be rendered + appendTo: '', + blocks: [], appendTo: '' diff --git a/src/block_manager/index.js b/src/block_manager/index.js index ea7e844f5..e524e8c14 100644 --- a/src/block_manager/index.js +++ b/src/block_manager/index.js @@ -28,6 +28,8 @@ * } * ... */ +import { isElement } from 'underscore'; + module.exports = () => { var c = {}, defaults = require('./config/config'), @@ -108,6 +110,15 @@ module.exports = () => { !blocks.length && blocks.reset(c.blocks); }, + postRender() { + const elTo = this.getConfig().appendTo; + + if (elTo) { + const el = isElement(elTo) ? elTo : document.querySelector(elTo); + el.appendChild(this.render()); + } + }, + /** * Add new block to the collection. * @param {string} id Block id @@ -199,6 +210,7 @@ module.exports = () => { * Render blocks * @param {Array} blocks Blocks to render, without the argument will render * all global blocks + * @return {HTMLElement} Rendered element * @example * // Render all blocks (inside the global collection) * blockManager.render(); @@ -225,6 +237,7 @@ module.exports = () => { } blocksView.collection.reset(toRender); + return this.getContainer(); } }; }; diff --git a/src/navigator/config/config.js b/src/navigator/config/config.js index 86ce0ed68..f35c603cf 100644 --- a/src/navigator/config/config.js +++ b/src/navigator/config/config.js @@ -1,8 +1,8 @@ module.exports = { stylePrefix: '', - // Specify the element to use as layers container, string (query) or HTMLElement - // With the empty value, layers won't be rendered automatically + // Specify the element to use as a container, string (query) or HTMLElement + // With the empty value, nothing will be rendered appendTo: '', // Enable/Disable globally the possibility to sort layers diff --git a/src/styles/scss/_gjs_layers.scss b/src/styles/scss/_gjs_layers.scss index 423327945..abb6f89f3 100644 --- a/src/styles/scss/_gjs_layers.scss +++ b/src/styles/scss/_gjs_layers.scss @@ -81,18 +81,6 @@ display: block; } - /* - .#{$nv-prefix}item .#{$nv-prefix}children .#{$nv-prefix}title { - border-left: 1px solid lighten($mainDkColor, 2%); - } - */ - - /* - .#{$nv-prefix}item > .#{$nv-prefix}no-chld > ##{$nv-prefix}caret::before { - content: ''; - } - */ - &-no-chld > .#{$nv-prefix}layer-title-inn > .#{$nv-prefix}layer-caret { display: none; }