This commit is contained in:
Wei Wei 2016-09-22 12:00:38 +08:00
Родитель e613e38b4f
Коммит a3937fb21f
5 изменённых файлов: 57 добавлений и 4 удалений

3
.gitignore поставляемый
Просмотреть файл

@ -17,3 +17,6 @@ examples/webpack/dist
# npm config
.npmrc
# jsdocs
docs

Просмотреть файл

@ -110,8 +110,8 @@ gulp.task('static', function () {
.pipe(eslint.failAfterError());
});
gulp.task('docs', function (cb) {
gulp.src(['README.md', './src/**/*.js'], { read: false })
gulp.task('jsdoc', function (cb) {
gulp.src(['README.md', './js/**/*.js'], { read: false })
.pipe(jsdoc(require('./jsdoc.json'), cb));
});

Просмотреть файл

@ -47,6 +47,17 @@ function renderItemTree(root) {
return contexts;
}
/**
* The Backbone View of configurable toolbar
* @class ToolbarView
*
* @param {string} [toolbarId]
* The id of the toolbar.
* @param {string[]} [classes=[]]
* The classes of the toolbar.
* @param {ToolbarItemConfig[]} [items=[]]
* The list of the toolbar items.
*/
export class ToolbarView extends Backbone.View {
initialize({
toolbarId = _.uniqueId('toolbar-'),
@ -55,10 +66,13 @@ export class ToolbarView extends Backbone.View {
events = {},
}) {
this._root = { type: 'toolbar', id: toolbarId, classes, items };
this._events = events;
this._contexts = renderItemTree(this._root);
}
/**
* Get the Backbone View event hash.
* @return BackboneViewEventHash
*/
events() {
const handlerHash = {};
const mergeEvents = events => {
@ -69,7 +83,6 @@ export class ToolbarView extends Backbone.View {
handlerHash[key].push(handler);
});
};
mergeEvents(this._events || {});
_.each(this._contexts || {}, context => mergeEvents(context.events));
return _.mapObject(handlerHash, sequence);
@ -80,10 +93,19 @@ export class ToolbarView extends Backbone.View {
delete this._contexts[id];
}
/**
* Get the configuration of a toolbar item.
* @param {string} id - The ID of the item.
* @return {ToolbarItemConfig}
*/
get(id) {
return _.chain(this._contexts).result(id).result('item').value();
}
/**
* Update a toolbar item.
* @param {ToolbarItemConfig} item - The updated toolbar item configuration.
*/
update(item) {
const id = item.id || this._root.id;
const itemNew = _.defaults({ id }, item, this.get(id));
@ -114,6 +136,9 @@ export class ToolbarView extends Backbone.View {
}
}
/**
* Render the toolbar as a Backbone View.
*/
render() {
this._isRendered = true;
this.undelegateEvents();

Просмотреть файл

@ -1,5 +1,17 @@
import _ from 'underscore';
/**
* @typedef ParsedSelector
* @type {Object}
* @property {string[]} classes - The CSS classes
* @property {string} id - The CSS id
*/
/**
* A simple CSS selector parser recognizing classes and ID
* @param {string} selector - The CSS selector
* @return ParsedSelector
*/
export function parseSelector(selector) {
const classes = [];
const ids = [];
@ -22,6 +34,11 @@ export function parseSelector(selector) {
return result;
}
/**
* Merge a list of callbacks into one which invokes them in sequence.
* @param {function[]} funcs
* @return {function}
*/
export function sequence(funcs) {
return function (...args) {
_.each(funcs, func => func.apply(this, args));

8
jsdoc.json Normal file
Просмотреть файл

@ -0,0 +1,8 @@
{
"opts": {
"destination": "docs",
"recurse": true
},
"plugins": ["plugins/markdown"]
}