Browse Source

Add `appendTo` option to SelectorManager

pull/856/head
Artur Arseniev 8 years ago
parent
commit
4ede1c66fc
  1. 4
      src/selector_manager/config/config.js
  2. 15
      src/selector_manager/index.js
  3. 16
      src/selector_manager/view/ClassTagsView.js

4
src/selector_manager/config/config.js

@ -2,6 +2,10 @@ module.exports = {
// Style prefix
stylePrefix: 'clm-',
// Specify the element to use as a container, string (query) or HTMLElement
// With the empty value, nothing will be rendered
appendTo: '',
// Default selectors
selectors: [],

15
src/selector_manager/index.js

@ -49,7 +49,7 @@
* }
*/
import { isString } from 'underscore';
import { isString, isElement } from 'underscore';
module.exports = config => {
var c = config || {},
@ -71,6 +71,10 @@ module.exports = config => {
*/
name: 'SelectorManager',
getConfig() {
return c;
},
/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations
@ -103,6 +107,15 @@ module.exports = config => {
return this;
},
postRender() {
const elTo = this.getConfig().appendTo;
if (elTo) {
const el = isElement(elTo) ? elTo : document.querySelector(elTo);
el.appendChild(this.render([]));
}
},
/**
* Add a new selector to collection if it's not already exists. Class type is a default one
* @param {String} name Selector name

16
src/selector_manager/view/ClassTagsView.js

@ -303,8 +303,10 @@ module.exports = Backbone.View.extend({
},
render() {
const ppfx = this.ppfx;
const config = this.config;
this.$el.html(
const $el = this.$el;
$el.html(
this.template({
selectedLabel: config.selectedLabel,
statesLabel: config.statesLabel,
@ -313,14 +315,14 @@ module.exports = Backbone.View.extend({
ppfx: this.ppfx
})
);
this.$input = this.$el.find('input#' + this.newInputId);
this.$addBtn = this.$el.find('#' + this.addBtnId);
this.$classes = this.$el.find('#' + this.pfx + 'tags-c');
this.$states = this.$el.find('#' + this.stateInputId);
this.$statesC = this.$el.find('#' + this.stateInputC);
this.$input = $el.find('input#' + this.newInputId);
this.$addBtn = $el.find('#' + this.addBtnId);
this.$classes = $el.find('#' + this.pfx + 'tags-c');
this.$states = $el.find('#' + this.stateInputId);
this.$statesC = $el.find('#' + this.stateInputC);
this.$states.append(this.getStateOptions());
this.renderClasses();
this.$el.attr('class', this.className);
$el.attr('class', `${this.className} ${ppfx}one-bg ${ppfx}two-color`);
return this;
}
});

Loading…
Cancel
Save