urbit/web/tree/main.js

2376 lines
59 KiB
JavaScript
Raw Normal View History

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2015-05-27 00:22:49 +03:00
var TreeDispatcher, TreePersistence;
TreeDispatcher = require('../dispatcher/Dispatcher.coffee');
TreePersistence = require('../persistence/TreePersistence.coffee');
module.exports = {
2015-08-06 05:13:41 +03:00
loadPath: function(path, data) {
2015-05-27 00:22:49 +03:00
return TreeDispatcher.handleServerAction({
path: path,
2015-08-06 05:13:41 +03:00
data: data,
2016-01-30 05:18:51 +03:00
type: "loadPath"
2015-05-27 00:22:49 +03:00
});
},
sendQuery: function(path, query) {
2015-08-05 05:09:58 +03:00
if (query == null) {
return;
2015-05-27 00:22:49 +03:00
}
if (path.slice(-1) === "/") {
path = path.slice(0, -1);
}
return TreePersistence.get(path, query, (function(_this) {
return function(err, res) {
2016-01-30 05:54:28 +03:00
if (err != null) {
throw err;
}
2015-08-06 05:13:41 +03:00
return _this.loadPath(path, res);
2015-05-27 00:22:49 +03:00
};
})(this));
},
2016-01-30 05:18:51 +03:00
registerComponent: function(name, comp) {
2016-02-03 21:23:49 +03:00
var obj;
return this.addVirtual((
obj = {},
obj["" + name] = comp,
obj
));
},
addVirtual: function(components) {
return TreeDispatcher.handleViewAction({
type: "addVirtual",
components: components
});
2016-01-30 05:18:51 +03:00
},
2015-05-27 00:22:49 +03:00
setCurr: function(path) {
return TreeDispatcher.handleViewAction({
2016-01-30 05:18:51 +03:00
type: "setCurr",
2015-05-27 00:22:49 +03:00
path: path
});
2016-01-30 05:18:51 +03:00
},
setNav: function(arg) {
var dpad, sibs, subnav, title;
title = arg.title, dpad = arg.dpad, sibs = arg.sibs, subnav = arg.subnav;
return TreeDispatcher.handleViewAction({
title: title,
dpad: dpad,
sibs: sibs,
subnav: subnav,
type: "setNav"
});
},
toggleNav: function() {
return TreeDispatcher.handleViewAction({
type: "toggleNav"
});
},
clearNav: function() {
return TreeDispatcher.handleViewAction({
type: "clearNav"
});
2015-05-27 00:22:49 +03:00
}
};
2016-02-03 21:23:49 +03:00
},{"../dispatcher/Dispatcher.coffee":18,"../persistence/TreePersistence.coffee":20}],2:[function(require,module,exports){
var BodyComponent, Dpad, Nav, Sibs, TreeActions, TreeStore, a, button, clas, div, li, query, reactify, recl, ref, rend, ul, util;
2015-08-06 02:48:34 +03:00
clas = require('classnames');
2015-06-18 19:10:34 +03:00
2015-08-04 06:54:39 +03:00
BodyComponent = React.createFactory(require('./BodyComponent.coffee'));
2015-08-06 02:48:34 +03:00
query = require('./Async.coffee');
2015-05-27 00:22:49 +03:00
2016-02-03 21:23:49 +03:00
reactify = require('./Reactify.coffee');
2015-05-27 00:22:49 +03:00
TreeStore = require('../stores/TreeStore.coffee');
TreeActions = require('../actions/TreeActions.coffee');
2016-01-30 05:18:51 +03:00
Sibs = require('./SibsComponent.coffee');
Dpad = require('./DpadComponent.coffee');
util = require('../utils/util.coffee');
2015-05-27 00:22:49 +03:00
recl = React.createClass;
2016-02-02 03:00:45 +03:00
rend = ReactDOM.render;
ref = React.DOM, div = ref.div, a = ref.a, ul = ref.ul, li = ref.li, button = ref.button;
2015-05-27 00:22:49 +03:00
2016-01-30 05:18:51 +03:00
Nav = React.createFactory(query({
2015-08-06 02:48:34 +03:00
path: 't',
kids: {
name: 't',
head: 'r',
meta: 'j'
}
}, recl({
displayName: "Links",
2016-01-30 05:18:51 +03:00
stateFromStore: function() {
return TreeStore.getNav();
},
getInitialState: function() {
return this.stateFromStore();
},
_onChangeStore: function() {
return this.setState(this.stateFromStore());
},
componentDidMount: function() {
return TreeStore.addChangeListener(this._onChangeStore);
},
componentWillUnmount: function() {
return TreeStore.removeChangeListener(this._onChangeStore);
},
onClick: function() {
return this.toggleFocus();
},
onMouseOver: function() {
return this.toggleFocus(true);
},
onMouseOut: function() {
return this.toggleFocus(false);
},
onTouchStart: function() {
return this.ts = Number(Date.now());
},
onTouchEnd: function() {
var dt;
return dt = this.ts - Number(Date.now());
},
2016-02-02 08:46:38 +03:00
_home: function() {
if (document.location.pathname !== "/") {
return document.location = "/";
}
},
2016-01-30 05:18:51 +03:00
toggleFocus: function(state) {
return $(ReactDOM.findDOMNode(this)).toggleClass('focus', state);
},
toggleNav: function() {
2016-01-30 05:18:51 +03:00
return TreeActions.toggleNav();
},
2015-08-06 02:48:34 +03:00
render: function() {
2016-01-30 05:18:51 +03:00
var attr, dpad, navClas, sibs, title, toggleClas;
attr = {
onMouseOver: this.onMouseOver,
onMouseOut: this.onMouseOut,
onClick: this.onClick,
onTouchStart: this.onTouchStart,
onTouchEnd: this.onTouchEnd
};
if (_.keys(window).indexOf("ontouchstart") !== -1) {
delete attr.onMouseOver;
delete attr.onMouseOut;
}
navClas = clas({
'col-md-2': true,
ctrl: true,
open: this.state.open === true
});
attr = _.extend(attr, {
className: navClas,
key: "nav"
});
title = this.state.title ? this.state.title : "";
dpad = this.state.dpad !== false ? Dpad(this.props, "") : "";
sibs = this.state.sibs !== false ? Sibs(_.merge(this.props, {
toggleNav: this.toggleNav
}), "") : "";
toggleClas = clas({
'navbar-toggler': true,
show: this.state.subnav != null
});
return div(attr, div({
className: 'links',
key: "links"
2016-01-21 19:33:19 +03:00
}, div({
className: 'icon'
}, div({
2016-02-02 08:46:38 +03:00
className: 'home',
onClick: this._home
2016-01-21 19:33:19 +03:00
}, ""), div({
className: 'app'
2016-01-30 05:18:51 +03:00
}, title), dpad, button({
className: toggleClas,
type: 'button',
onClick: this.toggleNav
2016-01-30 05:18:51 +03:00
}, "☰")), sibs));
2015-08-06 02:48:34 +03:00
}
}), recl({
displayName: "Links_loading",
render: function() {
return div({
2016-01-30 05:18:51 +03:00
className: "col-md-2 ctrl",
key: "nav-loading"
}, div({
className: 'links'
2016-01-30 05:18:51 +03:00
}, div({
className: 'icon'
}, div({
className: 'home'
}, "")), ul({
2016-01-21 19:33:19 +03:00
className: "nav"
}, li({
className: "nav-item selected"
}, a({
className: "nav-link"
2016-01-30 05:18:51 +03:00
}, this.props.curr)))));
2015-08-06 02:48:34 +03:00
}
})));
module.exports = query({
sein: 't',
path: 't',
name: 't',
2015-10-12 07:48:22 +03:00
meta: 'j'
2015-08-06 02:48:34 +03:00
}, recl({
2015-07-21 00:13:45 +03:00
displayName: "Anchor",
2016-01-30 05:18:51 +03:00
stateFromStore: function() {
return TreeStore.getNav();
},
2015-08-06 02:48:34 +03:00
getInitialState: function() {
2016-01-30 05:18:51 +03:00
return _.extend(this.stateFromStore(), {
2015-05-27 00:22:49 +03:00
url: window.location.pathname
2016-01-30 05:18:51 +03:00
});
2015-05-27 00:22:49 +03:00
},
2016-01-30 05:18:51 +03:00
_onChangeStore: function() {
return this.setState(this.stateFromStore());
2015-05-27 00:22:49 +03:00
},
2015-08-06 02:48:34 +03:00
componentWillUnmount: function() {
clearInterval(this.interval);
2016-01-30 05:18:51 +03:00
$('body').off('click', 'a');
return TreeStore.removeChangeListener(this._onChangeStore);
2015-05-27 00:22:49 +03:00
},
componentDidUpdate: function() {
return this.setTitle();
},
2015-05-27 00:22:49 +03:00
componentDidMount: function() {
2015-08-12 01:10:33 +03:00
var _this;
2015-05-27 00:22:49 +03:00
this.setTitle();
this.interval = setInterval(this.checkURL, 100);
2016-01-30 05:18:51 +03:00
TreeStore.addChangeListener(this._onChangeStore);
2015-08-12 01:10:33 +03:00
_this = this;
return $('body').on('click', 'a', function(e) {
var href;
2015-08-12 01:10:33 +03:00
href = $(this).attr('href');
2015-10-21 23:24:29 +03:00
if (href && !/^https?:\/\//i.test(href)) {
e.preventDefault();
if ((href != null ? href[0] : void 0) !== "/") {
2015-10-22 03:13:23 +03:00
href = (document.location.pathname.replace(/[^\/]*\/?$/, '')) + href;
}
return _this.goTo(util.fragpath(href));
2015-08-12 01:10:33 +03:00
}
});
2015-05-27 00:22:49 +03:00
},
2015-08-06 02:48:34 +03:00
setTitle: function() {
2015-10-22 21:50:41 +03:00
var ref1, title;
2016-01-30 06:02:03 +03:00
title = $('#body h1').first().text() || this.props.name;
2015-10-22 21:50:41 +03:00
if ((ref1 = this.props.meta) != null ? ref1.title : void 0) {
title = this.props.meta.title;
}
2015-08-06 02:48:34 +03:00
return document.title = title + " - " + this.props.path;
2015-05-27 00:22:49 +03:00
},
setPath: function(href, hist) {
2015-08-06 02:48:34 +03:00
var href_parts, next;
href_parts = href.split("#");
next = href_parts[0];
if (next.substr(-1) === "/") {
next = next.slice(0, -1);
}
href_parts[0] = next;
2015-05-27 00:22:49 +03:00
if (hist !== false) {
history.pushState({}, "", util.basepath(href_parts.join("")));
2015-05-27 00:22:49 +03:00
}
2015-08-06 02:48:34 +03:00
if (next !== this.props.path) {
2016-01-30 06:02:03 +03:00
React.unmountComponentAtNode($('#body')[0]);
2015-08-06 02:48:34 +03:00
TreeActions.setCurr(next);
2016-02-02 03:00:45 +03:00
return rend(BodyComponent({}, ""), $('#body')[0]);
2015-06-18 19:10:34 +03:00
}
2015-05-27 00:22:49 +03:00
},
2015-10-21 04:04:26 +03:00
reset: function() {
2015-05-27 00:22:49 +03:00
$("html,body").animate({
scrollTop: 0
});
2015-10-21 04:04:26 +03:00
$('#nav').attr('style', '');
$('#nav').removeClass('scrolling m-up');
return $('#nav').addClass('m-down m-fixed');
},
goTo: function(path) {
this.reset();
2015-08-06 02:48:34 +03:00
return this.setPath(path);
2015-05-27 00:22:49 +03:00
},
checkURL: function() {
if (this.state.url !== window.location.pathname) {
2015-10-21 04:04:26 +03:00
this.reset();
this.setPath(util.fragpath(window.location.pathname), false);
2015-08-06 02:48:34 +03:00
return this.setState({
url: window.location.pathname
});
2015-05-27 00:22:49 +03:00
}
},
render: function() {
2016-01-30 05:18:51 +03:00
var kids;
2015-10-12 07:48:22 +03:00
if (this.props.meta.anchor === 'none') {
return div({}, "");
}
2016-01-30 05:18:51 +03:00
kids = [
Nav({
curr: this.props.name,
dataPath: this.props.sein,
sein: this.props.sein,
key: "nav"
}, "div")
];
if (this.state.subnav) {
2016-02-03 21:23:49 +03:00
kids.push(reactify({
gn: this.state.subnav,
ga: {
open: this.state.open,
toggle: TreeActions.toggleNav
},
c: []
}, "subnav"));
2016-01-30 05:18:51 +03:00
}
return div({}, kids);
2015-05-27 00:22:49 +03:00
}
2016-01-30 05:18:51 +03:00
}));
2015-05-27 00:22:49 +03:00
2016-02-03 21:23:49 +03:00
},{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":21,"../utils/util.coffee":23,"./Async.coffee":3,"./BodyComponent.coffee":4,"./DpadComponent.coffee":7,"./Reactify.coffee":13,"./SibsComponent.coffee":16,"classnames":24}],3:[function(require,module,exports){
2015-08-06 02:48:34 +03:00
var TreeActions, TreeStore, _load, code, div, recl, ref, span;
2015-08-04 06:54:39 +03:00
2015-08-06 02:48:34 +03:00
_load = require('./LoadComponent.coffee');
2015-05-27 00:22:49 +03:00
TreeStore = require('../stores/TreeStore.coffee');
TreeActions = require('../actions/TreeActions.coffee');
recl = React.createClass;
2015-08-05 05:09:58 +03:00
ref = React.DOM, div = ref.div, span = ref.span, code = ref.code;
2015-05-27 00:22:49 +03:00
2015-08-06 02:48:34 +03:00
module.exports = function(queries, Child, load) {
if (load == null) {
load = _load;
}
2015-08-05 05:09:58 +03:00
return recl({
displayName: "Async",
2015-08-06 02:48:34 +03:00
getInitialState: function() {
return this.stateFromStore();
},
_onChangeStore: function() {
2015-10-16 00:43:23 +03:00
if (this.isMounted()) {
return this.setState(this.stateFromStore());
}
2015-08-06 02:48:34 +03:00
},
getPath: function() {
2015-10-16 02:37:49 +03:00
var path, ref1;
path = (ref1 = this.props.dataPath) != null ? ref1 : TreeStore.getCurr();
if (path.slice(-1) === "/") {
return path.slice(0, -1);
} else {
return path;
}
2015-08-06 02:48:34 +03:00
},
2015-08-05 05:09:58 +03:00
stateFromStore: function() {
return {
2015-08-06 02:48:34 +03:00
got: TreeStore.fulfill(this.getPath(), queries)
2015-08-05 05:09:58 +03:00
};
},
componentDidMount: function() {
TreeStore.addChangeListener(this._onChangeStore);
return this.checkPath();
},
componentWillUnmount: function() {
return TreeStore.removeChangeListener(this._onChangeStore);
},
componentDidUpdate: function(_props, _state) {
2015-08-06 02:48:34 +03:00
if (_props !== this.props) {
this.setState(this.stateFromStore());
}
2015-08-05 05:09:58 +03:00
return this.checkPath();
},
2015-08-06 02:48:34 +03:00
checkPath: function() {
return TreeActions.sendQuery(this.getPath(), this.filterQueries());
2015-08-06 02:48:34 +03:00
},
2015-08-05 05:09:58 +03:00
filterQueries: function() {
return this.filterWith(this.state.got, queries);
},
filterWith: function(have, _queries) {
var k, kid, ref1, request;
if (have == null) {
return _queries;
}
request = {};
for (k in _queries) {
2015-09-24 02:10:30 +03:00
if (k !== 'kids') {
if (have[k] === void 0) {
request[k] = _queries[k];
}
2015-08-05 05:09:58 +03:00
}
}
2015-09-24 03:17:09 +03:00
if (_queries.kids != null) {
if (have.kids == null) {
2015-08-05 05:09:58 +03:00
request.kids = _queries.kids;
} else {
request.kids = {};
ref1 = have.kids;
for (k in ref1) {
kid = ref1[k];
_.merge(request.kids, this.filterWith(kid, _queries.kids));
}
if (_.isEmpty(request.kids)) {
delete request.kids;
}
}
}
if (!_.isEmpty(request)) {
return request;
}
},
2015-08-12 00:31:16 +03:00
scrollHash: function() {
var ref1;
return (ref1 = this.getHashElement()) != null ? ref1.scrollIntoView() : void 0;
},
getHashElement: function() {
var hash;
hash = document.location.hash;
if (hash) {
return document.getElementById(hash.slice(1));
}
},
2015-08-05 05:09:58 +03:00
render: function() {
2015-08-12 00:31:16 +03:00
return div({}, this.filterQueries() != null ? React.createElement(load, this.props) : (!this.getHashElement() ? setTimeout(this.scrollHash, 0) : void 0, React.createElement(Child, _.extend({}, this.props, this.state.got), this.props.children)));
2015-05-27 00:22:49 +03:00
}
2015-08-05 05:09:58 +03:00
});
};
2016-02-03 21:23:49 +03:00
},{"../actions/TreeActions.coffee":1,"../stores/TreeStore.coffee":21,"./LoadComponent.coffee":11}],4:[function(require,module,exports){
var a, clas, div, extras, img, p, query, reactify, recl, ref, rele, util;
2015-10-22 02:35:46 +03:00
clas = require('classnames');
2015-10-22 02:11:23 +03:00
2015-08-05 05:09:58 +03:00
query = require('./Async.coffee');
reactify = require('./Reactify.coffee');
util = require('../utils/util.coffee');
2015-08-05 05:09:58 +03:00
recl = React.createClass;
2015-11-09 23:30:55 +03:00
rele = React.createElement;
2015-10-21 00:53:15 +03:00
ref = React.DOM, div = ref.div, p = ref.p, img = ref.img, a = ref.a;
extras = {
2015-11-09 23:30:55 +03:00
spam: recl({
displayName: "Spam",
render: function() {
2015-11-09 23:30:55 +03:00
if (document.location.hostname !== 'urbit.org') {
return div({});
}
return div({
2015-11-09 23:30:55 +03:00
className: 'spam'
}, a({
href: "http://urbit.org#sign-up"
2015-11-13 23:18:38 +03:00
}, "Sign up"), " for our newsletter.");
2015-10-22 02:11:23 +03:00
}
}),
logo: recl({
displayName: "Logo",
render: function() {
var color, src;
color = this.props.color;
if (color === "white" || color === "black") {
src = "//storage.googleapis.com/urbit-extra/logo/logo-" + color + "-100x100.png";
2015-10-22 22:30:22 +03:00
}
return a({
href: "http://urbit.org",
style: {
border: "none"
}
}, img({
2015-10-22 22:30:22 +03:00
src: src,
2016-01-21 19:33:19 +03:00
className: "logo first"
}));
}
}),
next: query({
path: 't',
kids: {
name: 't',
head: 'r',
meta: 'j'
}
}, recl({
displayName: "Next",
render: function() {
var curr, index, keys, next, ref1;
curr = this.props.kids[this.props.curr];
if (curr != null ? (ref1 = curr.meta) != null ? ref1.next : void 0 : void 0) {
keys = util.getKeys(this.props.kids);
if (keys.length > 1) {
index = keys.indexOf(this.props.curr);
next = index + 1;
if (next === keys.length) {
next = 0;
}
next = keys[next];
next = this.props.kids[next];
if (next) {
return div({
className: "link-next"
}, [
a({
href: this.props.path + "/" + next.name
}, "Next: " + next.meta.title)
]);
}
2015-11-04 00:17:30 +03:00
}
2015-10-21 00:53:15 +03:00
}
return div({}, "");
2015-10-21 00:53:15 +03:00
}
2015-11-09 23:30:55 +03:00
})),
footer: recl({
displayName: "Footer",
render: function() {
return div({
className: "footer"
}, p({}, "This page was served by Urbit."));
}
})
};
2015-05-27 00:22:49 +03:00
2015-08-05 05:09:58 +03:00
module.exports = query({
body: 'r',
2015-10-21 00:53:15 +03:00
name: 't',
2015-10-12 07:48:22 +03:00
path: 't',
2015-10-21 00:53:15 +03:00
meta: 'j',
sein: 't'
2015-08-05 05:09:58 +03:00
}, recl({
2015-07-21 00:13:45 +03:00
displayName: "Body",
2015-05-27 00:22:49 +03:00
render: function() {
2015-11-09 23:30:55 +03:00
var className, extra, ref1;
className = clas((ref1 = this.props.meta.layout) != null ? ref1.split(',') : void 0);
extra = (function(_this) {
2015-11-09 23:30:55 +03:00
return function(name, props) {
if (props == null) {
props = {};
}
if (_this.props.meta[name] != null) {
2015-11-09 23:30:55 +03:00
return React.createElement(extras[name], props);
}
};
})(this);
2015-10-19 09:19:27 +03:00
return div({
2016-01-30 05:18:51 +03:00
className: "col-md-10 col-md-offset-2 body"
}, [
div({
key: "body" + this.props.path,
className: className
}, extra('spam'), extra('logo', {
color: this.props.meta.logo
}), reactify(this.props.body), extra('next', {
dataPath: this.props.sein,
curr: this.props.name
}), extra('footer'))
]);
2015-05-27 00:22:49 +03:00
}
2015-08-05 05:09:58 +03:00
}));
2015-05-27 00:22:49 +03:00
2016-02-03 21:23:49 +03:00
},{"../utils/util.coffee":23,"./Async.coffee":3,"./Reactify.coffee":13,"classnames":24}],5:[function(require,module,exports){
2015-05-27 00:22:49 +03:00
var div, recl, ref, textarea;
recl = React.createClass;
2015-08-05 05:09:58 +03:00
ref = React.DOM, div = ref.div, textarea = ref.textarea;
2015-05-27 00:22:49 +03:00
module.exports = recl({
render: function() {
return div({}, textarea({
ref: 'ed',
value: this.props.value
}));
},
componentDidMount: function() {
return CodeMirror.fromTextArea(ReactDOM.findDOMNode(this.refs.ed), {
2015-05-27 00:52:59 +03:00
readOnly: true,
lineNumbers: true
2015-05-27 00:22:49 +03:00
});
}
});
},{}],6:[function(require,module,exports){
2015-08-13 03:27:13 +03:00
var div, recl;
2015-05-27 00:22:49 +03:00
recl = React.createClass;
2015-05-27 00:22:49 +03:00
2015-08-13 03:27:13 +03:00
div = React.DOM.div;
module.exports = {
codemirror: require('./CodeMirror.coffee'),
2015-08-07 04:21:51 +03:00
search: require('./SearchComponent.coffee'),
list: require('./ListComponent.coffee'),
kids: require('./KidsComponent.coffee'),
toc: require('./TocComponent.coffee'),
2015-09-23 19:56:58 +03:00
email: require('./EmailComponent.coffee'),
module: require('./ModuleComponent.coffee'),
2016-02-03 21:23:49 +03:00
script: require('./ScriptComponent.coffee'),
lost: recl({
render: function() {
2015-08-13 03:27:13 +03:00
return div({}, "<lost(", this.props.children, ")>");
}
})
2015-08-04 06:54:39 +03:00
};
2016-02-03 21:23:49 +03:00
},{"./CodeMirror.coffee":5,"./EmailComponent.coffee":8,"./KidsComponent.coffee":9,"./ListComponent.coffee":10,"./ModuleComponent.coffee":12,"./ScriptComponent.coffee":14,"./SearchComponent.coffee":15,"./TocComponent.coffee":17}],7:[function(require,module,exports){
2016-01-30 05:18:51 +03:00
var a, div, recl, ref, util;
util = require('../utils/util.coffee');
recl = React.createClass;
ref = React.DOM, div = ref.div, a = ref.a;
module.exports = React.createFactory(recl({
displayName: "Dpad",
renderUp: function() {
if (this.props.sein) {
return this.renderArrow("up", this.props.sein);
}
},
renderArrow: function(name, path) {
var href;
href = util.basepath(path);
return a({
href: href,
key: "" + name,
className: "" + name
}, "");
},
renderArrows: function() {
var index, keys, next, prev, sein;
keys = util.getKeys(this.props.kids);
if (keys.length > 1) {
index = keys.indexOf(this.props.curr);
prev = index - 1;
next = index + 1;
if (prev < 0) {
prev = keys.length - 1;
}
if (next === keys.length) {
next = 0;
}
prev = keys[prev];
next = keys[next];
}
if (this.props.sein) {
sein = this.props.sein;
if (sein === "/") {
sein = "";
}
return div({}, prev ? this.renderArrow("prev", sein + "/" + prev) : void 0, next ? this.renderArrow("next", sein + "/" + next) : void 0);
}
},
render: function() {
return div({
className: 'dpad',
key: 'dpad'
}, [this.renderUp(), this.renderArrows()]);
}
}));
2016-02-03 21:23:49 +03:00
},{"../utils/util.coffee":23}],8:[function(require,module,exports){
2015-09-23 19:56:58 +03:00
var button, div, input, p, reactify, recl, ref;
reactify = require('./Reactify.coffee');
recl = React.createClass;
ref = React.DOM, div = ref.div, p = ref.p, button = ref.button, input = ref.input;
module.exports = recl({
displayName: "email",
getInitialState: function() {
return {
submit: false,
email: ""
};
},
onClick: function() {
return this.submit();
},
onKeyUp: function(e) {
var email, valid;
email = this.$email.val();
valid = email.indexOf('@') !== -1 && email.indexOf('.') !== -1 && email.length > 7 && email.split(".")[1].length > 1 && email.split("@")[0].length > 0 && email.split("@")[1].length > 4;
this.$email.toggleClass('valid', valid);
this.$email.removeClass('error');
2015-09-23 19:56:58 +03:00
if (e.keyCode === 13) {
if (valid === true) {
this.submit();
e.stopPropagation();
e.preventDefault();
return false;
} else {
return this.$email.addClass('error');
}
2015-09-23 19:56:58 +03:00
}
},
submit: function() {
return $.post(this.props.dataPath, {
2015-09-24 21:07:34 +03:00
email: this.$email.val()
}, (function(_this) {
return function() {
return _this.setState({
submit: true
});
};
})(this));
2015-09-23 19:56:58 +03:00
},
componentDidMount: function() {
return this.$email = $('input.email');
},
2015-09-23 19:56:58 +03:00
render: function() {
var cont;
if (this.state.submit === false) {
cont = [
input({
key: "field",
className: "email",
placeholder: "your@email.com",
onKeyUp: this.onKeyUp
}, this.state.email), button({
key: "submit",
className: "submit",
onClick: this.onClick
2015-10-20 00:07:00 +03:00
}, "Sign up")
2015-09-23 19:56:58 +03:00
];
} else {
cont = [
div({
className: "submitted"
}, "Got it. Thanks!")
];
}
return p({
2015-11-09 22:08:08 +03:00
className: "email",
id: "sign-up"
2015-09-23 19:56:58 +03:00
}, cont);
}
});
2016-01-30 05:18:51 +03:00
},{"./Reactify.coffee":13}],9:[function(require,module,exports){
var a, div, hr, li, query, reactify, recl, ref, ul;
reactify = require('./Reactify.coffee');
2015-08-05 05:09:58 +03:00
query = require('./Async.coffee');
2015-05-27 00:22:49 +03:00
recl = React.createClass;
2015-08-05 05:09:58 +03:00
ref = React.DOM, div = ref.div, a = ref.a, ul = ref.ul, li = ref.li, hr = ref.hr;
2015-05-27 00:22:49 +03:00
2015-08-05 05:09:58 +03:00
module.exports = query({
kids: {
2015-10-13 03:44:14 +03:00
body: 'r',
meta: 'j'
2015-08-05 05:09:58 +03:00
}
}, recl({
2015-07-21 00:13:45 +03:00
displayName: "Kids",
2015-05-27 00:22:49 +03:00
render: function() {
2015-11-11 09:15:24 +03:00
var _k, d, elem, k, keyed, keys, klass, ref1, ref2, ref3, ref4, sorted, str, v;
2015-10-13 03:44:14 +03:00
klass = "kids";
if (this.props.dataType) {
klass += " " + this.props.dataType;
}
sorted = true;
2015-11-04 03:26:20 +03:00
keyed = {};
2015-10-13 03:44:14 +03:00
ref1 = this.props.kids;
for (k in ref1) {
v = ref1[k];
if (this.props.sortBy) {
if (this.props.sortBy === 'date') {
if (((ref2 = v.meta) != null ? ref2.date : void 0) == null) {
sorted = false;
2015-11-04 03:26:20 +03:00
continue;
2015-10-13 03:44:14 +03:00
}
2015-11-04 03:26:20 +03:00
d = v.meta.date.slice(1).split(".");
if (d.length < 3) {
sorted = false;
continue;
}
str = d[0] + "-" + d[1] + "-" + d[2];
if (d.length > 3) {
str += " " + d[3] + ":" + d[4] + ":" + d[5];
}
_k = Number(new Date(str));
keyed[_k] = k;
2015-10-13 03:44:14 +03:00
}
} else {
if (((ref3 = v.meta) != null ? ref3.sort : void 0) == null) {
sorted = false;
}
2015-11-04 03:26:20 +03:00
keyed[Number((ref4 = v.meta) != null ? ref4.sort : void 0)] = k;
2015-10-13 03:44:14 +03:00
}
}
2015-11-11 09:15:24 +03:00
if (sorted === false) {
keyed = _.keys(this.props.kids);
2015-11-04 03:26:20 +03:00
}
2015-11-11 09:15:24 +03:00
keys = _.keys(keyed).sort();
2015-11-04 03:26:20 +03:00
if (this.props.sortBy === 'date') {
2015-11-11 09:15:24 +03:00
keys.reverse();
2015-10-13 03:44:14 +03:00
}
2015-05-27 00:22:49 +03:00
return div({
2015-10-13 03:44:14 +03:00
className: klass
2015-07-22 03:49:02 +03:00
}, (function() {
2015-11-11 09:15:24 +03:00
var i, len, ref5, results;
2015-08-05 05:09:58 +03:00
results = [];
2015-11-11 09:15:24 +03:00
for (i = 0, len = keys.length; i < len; i++) {
k = keys[i];
elem = (ref5 = this.props.kids[keyed[k]]) != null ? ref5 : "";
2015-08-05 05:09:58 +03:00
results.push([
div({
2015-11-11 09:15:24 +03:00
key: keyed[k]
2015-10-13 03:44:14 +03:00
}, reactify(elem.body)), hr({}, "")
2015-08-05 05:09:58 +03:00
]);
2015-07-21 00:13:45 +03:00
}
2015-08-05 05:09:58 +03:00
return results;
2015-07-22 03:49:02 +03:00
}).call(this));
2015-05-27 00:22:49 +03:00
}
2015-08-05 05:09:58 +03:00
}));
2015-05-27 00:22:49 +03:00
2016-01-30 05:18:51 +03:00
},{"./Async.coffee":3,"./Reactify.coffee":13}],10:[function(require,module,exports){
var a, clas, div, h1, li, pre, query, reactify, recl, ref, span, ul, util;
2015-05-27 00:22:49 +03:00
2015-07-23 00:23:34 +03:00
clas = require('classnames');
2015-05-27 00:22:49 +03:00
reactify = require('./Reactify.coffee');
2015-05-27 00:22:49 +03:00
2015-08-05 05:09:58 +03:00
query = require('./Async.coffee');
2015-05-27 00:22:49 +03:00
util = require('../utils/util.coffee');
2015-05-27 00:22:49 +03:00
recl = React.createClass;
2015-10-30 02:49:10 +03:00
ref = React.DOM, div = ref.div, pre = ref.pre, span = ref.span, a = ref.a, ul = ref.ul, li = ref.li, h1 = ref.h1;
2015-05-27 00:22:49 +03:00
2015-08-05 05:09:58 +03:00
module.exports = query({
path: 't',
kids: {
snip: 'r',
head: 'r',
meta: 'j'
}
}, recl({
2015-07-21 00:13:45 +03:00
displayName: "List",
2015-08-05 05:09:58 +03:00
render: function() {
2015-10-30 02:49:10 +03:00
var k, kids;
2015-08-05 05:09:58 +03:00
k = clas({
2015-10-13 03:44:14 +03:00
list: true
}, this.props.dataType, {
2015-08-05 05:09:58 +03:00
posts: this.props.dataType === 'post',
"default": this.props['data-source'] === 'default'
2016-01-21 19:33:19 +03:00
}, this.props.className);
2015-10-30 02:49:10 +03:00
kids = this.renderList();
if (!(kids.length === 0 && (this.props.is404 != null))) {
return ul({
className: k
}, kids);
}
return div({
2015-08-05 05:09:58 +03:00
className: k
2015-10-30 02:49:10 +03:00
}, h1({
className: 'error'
}, 'Error: Empty path'), div({}, pre({}, this.props.path), span({}, 'is either empty or does not exist.')));
2015-05-27 00:22:49 +03:00
},
2015-07-21 00:13:45 +03:00
renderList: function() {
2015-10-04 01:58:06 +03:00
var _date, _k, _keys, date, elem, href, i, item, k, len, parts, path, preview, ref1, ref2, ref3, ref4, ref5, ref6, ref7, results, sorted, title, v;
2015-08-06 04:56:50 +03:00
sorted = true;
_keys = [];
2015-10-04 01:58:06 +03:00
ref1 = this.props.kids;
for (k in ref1) {
v = ref1[k];
if (this.props.sortBy) {
if (this.props.sortBy === 'date') {
if (((ref2 = v.meta) != null ? ref2.date : void 0) == null) {
sorted = false;
}
_k = Number(v.meta.date.slice(1).replace(/\./g, ""));
_keys[_k] = k;
}
} else {
if (((ref3 = v.meta) != null ? ref3.sort : void 0) == null) {
2015-10-03 01:25:01 +03:00
sorted = false;
}
2015-10-04 01:58:06 +03:00
_keys[Number((ref4 = v.meta) != null ? ref4.sort : void 0)] = k;
2015-05-27 00:22:49 +03:00
}
2015-10-04 01:58:06 +03:00
}
if (this.props.sortBy === 'date') {
2015-10-03 01:25:01 +03:00
_keys.reverse();
2015-05-27 00:22:49 +03:00
}
2015-08-06 04:56:50 +03:00
if (sorted !== true) {
_keys = _.keys(this.props.kids).sort();
2015-05-27 00:22:49 +03:00
}
2015-07-21 00:13:45 +03:00
if (this.props.dataType === 'post') {
_keys = _keys.reverse();
2015-05-27 00:22:49 +03:00
}
2015-10-04 01:58:06 +03:00
ref5 = _.values(_keys);
2015-07-21 00:13:45 +03:00
results = [];
2015-10-04 01:58:06 +03:00
for (i = 0, len = ref5.length; i < len; i++) {
item = ref5[i];
2015-08-05 05:09:58 +03:00
path = this.props.path + "/" + item;
elem = this.props.kids[item];
2015-10-20 02:27:22 +03:00
if (elem.meta.hide != null) {
continue;
}
href = util.basepath(path);
2015-10-15 04:22:06 +03:00
if (elem.meta.link) {
href = elem.meta.link;
}
2015-08-06 04:56:50 +03:00
parts = [];
title = null;
2015-10-04 01:58:06 +03:00
if ((ref6 = elem.meta) != null ? ref6.title : void 0) {
2015-08-06 04:56:50 +03:00
title = {
gn: 'h1',
c: [elem.meta.title]
};
}
2015-10-19 09:19:27 +03:00
if (!title && elem.head.c.length > 0) {
2015-08-06 04:56:50 +03:00
title = elem.head;
}
if (!title) {
title = {
gn: 'h1',
c: [item]
};
}
2015-10-02 03:21:52 +03:00
if (!this.props.titlesOnly) {
if (this.props.dataDates) {
_date = elem.meta.date;
if (!_date || _date.length === 0) {
_date = "";
}
date = {
gn: 'div',
ga: {
className: 'date'
},
c: [_date]
};
parts.push(date);
}
}
2015-08-06 04:56:50 +03:00
parts.push(title);
2015-08-12 00:31:16 +03:00
if (!this.props.titlesOnly) {
if (this.props.dataPreview) {
2015-10-02 03:21:52 +03:00
if (this.props.dataType === 'post' && !elem.meta.preview) {
2015-08-12 00:31:16 +03:00
parts.push.apply(parts, elem.snip.c.slice(0, 2));
2015-05-27 00:22:49 +03:00
} else {
2015-10-02 03:21:52 +03:00
if (elem.meta.preview) {
preview = {
gn: 'p',
c: [elem.meta.preview]
};
} else {
preview = elem.snip;
}
parts.push(preview);
2015-05-27 00:22:49 +03:00
}
2015-08-06 04:56:50 +03:00
}
}
2015-07-21 00:13:45 +03:00
results.push(li({
key: item,
2015-10-04 01:58:06 +03:00
className: (ref7 = this.props.dataType) != null ? ref7 : ""
2015-07-21 00:13:45 +03:00
}, a({
href: href,
2015-07-23 00:23:34 +03:00
className: clas({
preview: this.props.dataPreview != null
})
2015-08-06 04:56:50 +03:00
}, reactify({
2015-07-23 00:23:34 +03:00
gn: 'div',
2015-08-06 04:56:50 +03:00
c: parts
}))));
2015-06-18 09:26:09 +03:00
}
2015-07-21 00:13:45 +03:00
return results;
2015-05-27 00:22:49 +03:00
}
2015-08-05 05:09:58 +03:00
}));
2015-05-27 00:22:49 +03:00
2016-02-03 21:23:49 +03:00
},{"../utils/util.coffee":23,"./Async.coffee":3,"./Reactify.coffee":13,"classnames":24}],11:[function(require,module,exports){
2016-01-21 19:33:19 +03:00
var div, recl, ref, span;
2015-05-27 00:22:49 +03:00
recl = React.createClass;
2016-01-21 19:33:19 +03:00
ref = React.DOM, span = ref.span, div = ref.div;
2015-05-27 00:22:49 +03:00
module.exports = recl({
2015-07-21 00:13:45 +03:00
displayName: "Load",
2015-05-27 00:22:49 +03:00
getInitialState: function() {
return {
anim: 0
};
},
componentDidMount: function() {
return this.interval = setInterval(this.setAnim, 100);
},
componentWillUnmount: function() {
return clearInterval(this.interval);
},
setAnim: function() {
var anim;
anim = this.state.anim + 1;
if (anim > 3) {
anim = 0;
}
return this.setState({
anim: anim
});
},
render: function() {
2016-01-21 19:33:19 +03:00
return span({
className: "loading state-" + this.state.anim
}, '');
2015-05-27 00:22:49 +03:00
}
});
2016-01-30 05:18:51 +03:00
},{}],12:[function(require,module,exports){
2016-02-03 21:23:49 +03:00
var TreeActions, div, recl;
recl = React.createClass;
2016-02-03 21:23:49 +03:00
div = React.DOM.div;
TreeActions = require('../actions/TreeActions.coffee');
module.exports = recl({
2016-02-02 03:00:45 +03:00
displayName: "Module",
componentDidMount: function() {
2016-02-03 21:23:49 +03:00
return setTimeout((function(_this) {
return function() {
return TreeActions.setNav({
title: _this.props["nav:title"],
dpad: _this.props["nav:no-dpad"] != null ? false : void 0,
sibs: _this.props["nav:no-sibs"] != null ? false : void 0,
subnav: _this.props["nav:subnav"]
}, 0);
};
})(this));
2016-01-30 05:18:51 +03:00
},
componentWillUnmount: function() {
2016-02-03 21:23:49 +03:00
return TreeActions.clearNav();
},
render: function() {
2016-02-03 21:23:49 +03:00
return div({
className: "module"
}, this.props.children);
}
});
2015-11-13 23:18:38 +03:00
2016-02-03 21:23:49 +03:00
},{"../actions/TreeActions.coffee":1}],13:[function(require,module,exports){
var TreeStore, Virtual, div, load, reactify, recl, ref, rele, span, walk;
2015-08-04 06:54:39 +03:00
recl = React.createClass;
rele = React.createElement;
2015-08-05 05:09:58 +03:00
ref = React.DOM, div = ref.div, span = ref.span;
2015-08-04 06:54:39 +03:00
2015-08-05 05:09:58 +03:00
load = React.createFactory(require('./LoadComponent.coffee'));
2015-08-04 06:54:39 +03:00
2016-02-03 21:23:49 +03:00
TreeStore = require('../stores/TreeStore.coffee');
walk = function(root, _nil, _str, _comp) {
var _walk;
_walk = function(elem, key) {
2015-08-12 00:31:16 +03:00
var c, ga, gn, ref1;
2015-08-04 06:54:39 +03:00
switch (false) {
2015-08-06 02:48:34 +03:00
case !(elem == null):
return _nil();
2015-08-06 02:48:34 +03:00
case typeof elem !== "string":
return _str(elem);
2015-08-06 02:48:34 +03:00
case elem.gn == null:
gn = elem.gn, ga = elem.ga, c = elem.c;
2015-08-12 00:31:16 +03:00
c = (ref1 = c != null ? c.map(_walk) : void 0) != null ? ref1 : [];
2015-08-07 04:21:51 +03:00
return _comp.call(elem, {
gn: gn,
ga: ga,
c: c
}, key);
2015-08-04 06:54:39 +03:00
default:
2015-08-06 02:48:34 +03:00
throw "Bad react-json " + (JSON.stringify(elem));
2015-08-04 06:54:39 +03:00
}
};
return _walk(root);
};
Virtual = recl({
displayName: "Virtual",
2016-02-03 21:23:49 +03:00
getInitialState: function() {
return this.stateFromStore();
},
stateFromStore: function() {
return {
components: TreeStore.getVirtualComponents()
};
},
_onChangeStore: function() {
if (this.isMounted()) {
return this.setState(this.stateFromStore());
}
},
componentDidMount: function() {
return TreeStore.addChangeListener(this._onChangeStore);
},
componentWillUnmount: function() {
return TreeStore.removeChangeListener(this._onChangeStore);
},
render: function() {
var components;
2016-02-03 21:23:49 +03:00
components = this.state.components;
return walk(this.props.manx, function() {
return load({}, "");
}, function(str) {
return str;
}, function(arg, key) {
var c, ga, gn, ref1;
gn = arg.gn, ga = arg.ga, c = arg.c;
return rele((ref1 = components[gn]) != null ? ref1 : gn, _.extend({
key: key
}, ga), c);
});
2015-08-04 06:54:39 +03:00
}
});
2015-08-07 04:21:51 +03:00
reactify = function(manx, key) {
return rele(Virtual, {
2015-08-07 04:21:51 +03:00
manx: manx,
key: key
});
};
module.exports = _.extend(reactify, {
walk: walk,
Virtual: Virtual
});
2015-08-04 06:54:39 +03:00
2016-02-03 21:23:49 +03:00
},{"../stores/TreeStore.coffee":21,"./LoadComponent.coffee":11}],14:[function(require,module,exports){
var recl, rele;
recl = React.createClass;
rele = React.createElement;
module.exports = recl({
displayName: "Script",
componentDidMount: function() {
var s;
s = document.createElement('script');
_.assign(s, this.props);
urb.waspElem(s);
document.body.appendChild(s);
return this.js = s;
},
componentWillUnmount: function() {
return document.body.removeChild(this.js);
},
render: function() {
return rele("script", this.props);
}
});
},{}],15:[function(require,module,exports){
2015-08-12 00:31:16 +03:00
var a, div, input, query, reactify, recl, ref,
2015-08-07 04:21:51 +03:00
slice = [].slice;
query = require('./Async.coffee');
reactify = require('./Reactify.coffee');
recl = React.createClass;
2015-08-12 00:31:16 +03:00
ref = React.DOM, a = ref.a, div = ref.div, input = ref.input;
2015-08-07 04:21:51 +03:00
module.exports = query({
2015-08-12 00:31:16 +03:00
name: 't',
2015-08-07 04:21:51 +03:00
kids: {
2015-08-12 00:31:16 +03:00
sect: 'j'
2015-08-07 04:21:51 +03:00
}
}, recl({
hash: null,
displayName: "Search",
getInitialState: function() {
return {
2015-08-12 00:31:16 +03:00
search: 'wut'
2015-08-07 04:21:51 +03:00
};
},
onKeyUp: function(e) {
return this.setState({
search: e.target.value
});
},
2015-08-12 00:31:16 +03:00
wrap: function(elem, dir, path) {
var c, ga, gn, href, ref1;
if (path.slice(-1) === "/") {
path = path.slice(0, -1);
}
href = this.props.name + "/" + dir + path;
if (elem != null ? (ref1 = elem.ga) != null ? ref1.id : void 0 : void 0) {
gn = elem.gn, ga = elem.ga, c = elem.c;
ga = _.clone(ga);
href += "#" + ga.id;
delete ga.id;
elem = {
gn: gn,
ga: ga,
c: c
};
}
return {
gn: 'div',
c: [
{
gn: 'a',
ga: {
href: href
},
c: [elem]
}
]
};
},
2015-08-07 04:21:51 +03:00
render: function() {
return div({}, input({
onKeyUp: this.onKeyUp,
ref: 'inp',
2015-08-12 00:31:16 +03:00
defaultValue: 'wut'
}), _(this.props.kids).map((function(_this) {
return function(arg, dir) {
var h, heds, path, results, sect;
sect = arg.sect;
results = [];
for (path in sect) {
heds = sect[path];
results.push((function() {
var i, len, results1;
results1 = [];
for (i = 0, len = heds.length; i < len; i++) {
h = heds[i];
results1.push(this.wrap(h, dir, path));
}
return results1;
}).call(_this));
}
return results;
};
2015-08-13 02:29:41 +03:00
})(this)).flatten().flatten().map(this.highlight).filter().take(50).map(reactify).value());
2015-08-07 04:21:51 +03:00
},
highlight: function(e) {
var got, res;
if (!this.state.search) {
return e;
}
got = false;
res = reactify.walk(e, function() {
return null;
}, (function(_this) {
return function(s) {
var lit, m;
m = s.split(_this.state.search);
if (m[1] == null) {
return [s];
}
lit = {
gn: 'span',
c: [_this.state.search],
ga: {
style: {
background: '#ff6'
}
}
};
got = true;
return [m[0]].concat(slice.call(_.flatten((function() {
var i, len, ref1, results;
ref1 = m.slice(1);
results = [];
for (i = 0, len = ref1.length; i < len; i++) {
s = ref1[i];
results.push([lit, s]);
}
return results;
})())));
};
})(this), function(arg) {
var c, ga, gn;
gn = arg.gn, ga = arg.ga, c = arg.c;
return {
gn: gn,
ga: ga,
c: _.flatten(c)
};
});
if (got) {
return res;
}
}
}));
2016-02-03 21:23:49 +03:00
},{"./Async.coffee":3,"./Reactify.coffee":13}],16:[function(require,module,exports){
2016-01-30 05:18:51 +03:00
var a, clas, li, reactify, recl, ref, ul, util;
util = require('../utils/util.coffee');
clas = require('classnames');
reactify = require('./Reactify.coffee');
recl = React.createClass;
ref = React.DOM, ul = ref.ul, li = ref.li, a = ref.a;
module.exports = React.createFactory(recl({
displayName: "Siblings",
toText: function(elem) {
return reactify.walk(elem, function() {
return '';
}, function(s) {
return s;
}, function(arg) {
var c;
c = arg.c;
return (c != null ? c : []).join('');
});
},
render: function() {
var keys;
keys = util.getKeys(this.props.kids);
return ul({
className: "nav"
}, keys.map((function(_this) {
return function(key) {
var className, data, head, href;
href = util.basepath(_this.props.path + "/" + key);
data = _this.props.kids[key];
if (data.meta) {
head = data.meta.title;
}
if (head == null) {
head = _this.toText(data.head);
}
head || (head = key);
className = clas({
"nav-item": true,
selected: key === _this.props.curr
});
return li({
className: className,
key: key
}, a({
className: "nav-link",
href: href,
onClick: _this.props.toggleNav
}, head));
};
})(this)));
}
}));
2016-02-03 21:23:49 +03:00
},{"../utils/util.coffee":23,"./Reactify.coffee":13,"classnames":24}],17:[function(require,module,exports){
2015-09-24 23:14:23 +03:00
var div, query, reactify, recl,
slice = [].slice;
2015-08-06 01:07:16 +03:00
query = require('./Async.coffee');
2015-08-06 01:07:16 +03:00
reactify = require('./Reactify.coffee');
2015-08-06 01:07:16 +03:00
recl = React.createClass;
2015-08-06 03:16:30 +03:00
div = React.DOM.div;
2015-08-06 01:07:16 +03:00
module.exports = query({
body: 'r'
}, recl({
2015-08-06 01:07:16 +03:00
hash: null,
2015-08-06 05:13:41 +03:00
displayName: "TableOfContents",
2015-09-24 23:14:23 +03:00
_click: function(id) {
return function() {
if (id) {
return document.location.hash = id;
}
};
2015-08-06 01:07:16 +03:00
},
componentDidMount: function() {
this.int = setInterval(this.checkHash, 100);
2015-08-06 03:25:36 +03:00
this.st = $(window).scrollTop();
2015-09-24 23:14:23 +03:00
return this.$headers = $('#toc').children('h1,h2,h3,h4').filter('[id]');
2015-08-06 03:25:36 +03:00
},
checkScroll: function() {
2015-09-24 22:05:19 +03:00
var $h, hash, hst, i, len, ref, results, st, v;
2015-08-06 03:25:36 +03:00
st = $(window).scrollTop();
if (Math.abs(this.st - st) > 10) {
hash = null;
this.st = st;
2015-08-06 03:27:00 +03:00
ref = this.$headers;
2015-08-06 03:25:36 +03:00
results = [];
2015-09-24 22:05:19 +03:00
for (i = 0, len = ref.length; i < len; i++) {
v = ref[i];
2015-08-06 03:25:36 +03:00
if (v.tagName === void 0) {
continue;
}
$h = $(v);
2015-08-06 04:56:50 +03:00
hst = $h.offset().top - $h.outerHeight(true) + 10;
2015-08-06 03:25:36 +03:00
if (hst < st) {
2015-09-24 23:14:23 +03:00
hash = $h.attr('id');
2015-08-06 03:25:36 +03:00
}
if (hst > st && hash !== this.hash && hash !== null) {
this.hash = "#" + hash;
document.location.hash = hash;
break;
} else {
results.push(void 0);
}
}
return results;
}
2015-08-06 01:07:16 +03:00
},
checkHash: function() {
2015-09-24 22:05:19 +03:00
var $h, hash, i, len, offset, ref, ref1, results, v;
2015-08-06 03:27:00 +03:00
if (((ref = document.location.hash) != null ? ref.length : void 0) > 0 && document.location.hash !== this.hash) {
2015-08-06 01:07:16 +03:00
hash = document.location.hash.slice(1);
2015-08-06 03:27:00 +03:00
ref1 = this.$headers;
2015-08-06 01:07:16 +03:00
results = [];
2015-09-24 22:05:19 +03:00
for (i = 0, len = ref1.length; i < len; i++) {
v = ref1[i];
2015-08-06 03:25:36 +03:00
$h = $(v);
2015-09-24 23:14:23 +03:00
if (hash === $h.attr('id')) {
2015-08-06 01:07:16 +03:00
this.hash = document.location.hash;
2015-08-06 03:25:36 +03:00
offset = $h.offset().top - $h.outerHeight(true);
setTimeout(function() {
return $(window).scrollTop(offset, 10);
});
2015-08-06 01:07:16 +03:00
break;
} else {
results.push(void 0);
}
}
return results;
}
},
componentWillUnmount: function() {
return clearInterval(this.int);
},
2015-09-24 23:14:23 +03:00
collectHeader: function(arg) {
var c, ga, gn;
gn = arg.gn, ga = arg.ga, c = arg.c;
if (gn && gn[0] === 'h' && parseInt(gn[1]) !== NaN) {
ga = _.clone(ga);
ga.onClick = this._click(ga.id);
delete ga.id;
return {
gn: gn,
ga: ga,
c: c
};
2015-08-06 03:25:36 +03:00
}
2015-08-06 01:07:16 +03:00
},
2015-08-06 03:25:36 +03:00
parseHeaders: function() {
2015-09-24 23:14:23 +03:00
var i, len, ref, ref1, v;
if (this.props.body.c) {
ref = this.props.body.c;
2015-09-24 23:14:23 +03:00
for (i = 0, len = ref.length; i < len; i++) {
v = ref[i];
2015-08-06 03:27:00 +03:00
if (v.gn === 'div' && ((ref1 = v.ga) != null ? ref1.id : void 0) === "toc") {
2015-08-06 03:25:36 +03:00
return {
gn: "div",
ga: {
2015-09-24 23:14:23 +03:00
className: "toc"
2015-08-06 03:25:36 +03:00
},
2015-09-24 23:14:23 +03:00
c: [{
gn: "h1",
ga: {
className: "t"
},
c: ["Table of contents"]
}].concat(slice.call(_.filter(v.c.map(this.collectHeader))))
2015-08-06 03:25:36 +03:00
};
}
}
2015-08-06 01:07:16 +03:00
}
},
render: function() {
2015-08-06 03:25:36 +03:00
return reactify(this.parseHeaders());
2015-08-06 01:07:16 +03:00
}
}));
2015-08-06 01:07:16 +03:00
2016-02-03 21:23:49 +03:00
},{"./Async.coffee":3,"./Reactify.coffee":13}],18:[function(require,module,exports){
module.exports = _.extend(new Flux.Dispatcher(), {
2015-05-27 00:22:49 +03:00
handleServerAction: function(action) {
return this.dispatch({
source: 'server',
action: action
});
},
handleViewAction: function(action) {
return this.dispatch({
source: 'view',
action: action
});
}
});
2016-02-03 21:23:49 +03:00
},{}],19:[function(require,module,exports){
2015-05-27 00:22:49 +03:00
var rend;
rend = ReactDOM.render;
2015-05-27 00:22:49 +03:00
$(function() {
2016-01-30 05:18:51 +03:00
var body, frag, head, util;
util = require('./utils/util.coffee');
require('./utils/scroll.coffee');
2016-01-30 05:18:51 +03:00
window.tree.actions = require('./actions/TreeActions.coffee');
2016-02-03 21:23:49 +03:00
window.tree.actions.addVirtual(require('./components/Components.coffee'));
2016-01-30 05:54:28 +03:00
frag = util.fragpath(window.location.pathname.replace(/\.[^\/]*$/, ''));
2016-01-30 05:18:51 +03:00
window.tree.actions.setCurr(frag);
2016-01-30 05:54:28 +03:00
window.tree.actions.loadPath(frag, window.tree.data);
head = React.createFactory(require('./components/AnchorComponent.coffee'));
body = React.createFactory(require('./components/BodyComponent.coffee'));
2016-01-30 05:18:51 +03:00
rend(head({}, ""), $('#head')[0]);
return rend(body({}, ""), $('#body')[0]);
2015-05-27 00:22:49 +03:00
});
2016-02-03 21:23:49 +03:00
},{"./actions/TreeActions.coffee":1,"./components/AnchorComponent.coffee":2,"./components/BodyComponent.coffee":4,"./components/Components.coffee":6,"./utils/scroll.coffee":22,"./utils/util.coffee":23}],20:[function(require,module,exports){
var dedup, util;
2015-05-27 00:22:49 +03:00
util = require('../utils/util.coffee');
2015-09-24 03:22:28 +03:00
dedup = {};
2015-05-27 00:22:49 +03:00
module.exports = {
get: function(path, query, cb) {
var url;
2015-08-04 04:37:19 +03:00
if (query == null) {
query = "no-query";
2015-05-27 00:22:49 +03:00
}
2016-01-30 05:54:28 +03:00
url = (util.basepath(path)) + ".tree-json?q=" + (this.encode(query));
2015-09-24 03:22:28 +03:00
if (dedup[url]) {
return;
}
dedup[url] = true;
2015-05-27 00:22:49 +03:00
return $.get(url, {}, function(data) {
if (cb) {
return cb(null, data);
}
});
2015-08-05 05:09:58 +03:00
},
encode: function(obj) {
var _encode, delim;
delim = function(n) {
2015-09-23 19:56:58 +03:00
return Array(n + 1).join('_') || '.';
2015-08-05 05:09:58 +03:00
};
_encode = function(obj) {
var _dep, dep, k, res, sub, v;
if (typeof obj !== 'object') {
return [0, obj];
}
dep = 0;
sub = (function() {
var ref, results;
results = [];
for (k in obj) {
v = obj[k];
ref = _encode(v), _dep = ref[0], res = ref[1];
if (_dep > dep) {
dep = _dep;
}
if (res != null) {
results.push(k + (delim(_dep)) + res);
} else {
results.push(void 0);
}
}
return results;
})();
dep++;
return [dep, sub.join(delim(dep))];
};
return (_encode(obj))[1];
2015-05-27 00:22:49 +03:00
}
};
2016-02-03 21:23:49 +03:00
},{"../utils/util.coffee":23}],21:[function(require,module,exports){
var EventEmitter, MessageDispatcher, QUERIES, TreeStore, _curr, _data, _nav, _tree, _virt, clog;
2015-05-27 00:22:49 +03:00
2016-02-03 21:23:49 +03:00
EventEmitter = require('events').EventEmitter.EventEmitter;
2015-05-27 00:22:49 +03:00
MessageDispatcher = require('../dispatcher/Dispatcher.coffee');
2015-08-06 02:48:34 +03:00
clog = console.log.bind(console);
2015-05-27 00:22:49 +03:00
2016-02-03 21:23:49 +03:00
_virt = {};
2015-05-27 00:22:49 +03:00
_tree = {};
2015-08-06 05:13:41 +03:00
_data = {};
2015-05-27 00:22:49 +03:00
_curr = "";
2016-01-30 05:18:51 +03:00
_nav = {};
QUERIES = {
body: 'r',
head: 'r',
snip: 'r',
2015-08-12 00:31:16 +03:00
sect: 'j',
meta: 'j'
};
2016-02-03 21:23:49 +03:00
TreeStore = _.extend(new EventEmitter, {
2015-05-27 00:22:49 +03:00
addChangeListener: function(cb) {
return this.on('change', cb);
},
removeChangeListener: function(cb) {
return this.removeListener("change", cb);
},
emitChange: function() {
return this.emit('change');
},
pathToArr: function(_path) {
return _path.split("/");
},
2015-08-05 05:09:58 +03:00
fulfill: function(path, query) {
2015-10-19 09:19:27 +03:00
if (path === "/") {
path = "";
}
2015-08-06 05:13:41 +03:00
return this.fulfillAt(this.getTree(path.split('/')), path, query);
},
fulfillAt: function(tree, path, query) {
2015-09-24 02:53:48 +03:00
var data, have, k, sub, t;
2015-08-05 05:09:58 +03:00
data = this.fulfillLocal(path, query);
2015-09-24 02:53:48 +03:00
have = _data[path];
if (have != null) {
for (k in query) {
t = query[k];
if (!QUERIES[k]) {
continue;
}
if (t !== QUERIES[k]) {
throw TypeError("Wrong query type: " + k + ", '" + t + "'");
}
data[k] = have[k];
2015-08-06 05:13:41 +03:00
}
2015-09-24 03:17:09 +03:00
if (query.kids) {
2015-10-30 02:49:10 +03:00
if (have.kids === false) {
2015-09-24 03:17:09 +03:00
data.kids = {};
} else {
for (k in tree) {
sub = tree[k];
if (data.kids == null) {
data.kids = {};
}
data.kids[k] = this.fulfillAt(sub, path + "/" + k, query.kids);
}
2015-09-24 02:53:48 +03:00
}
2015-05-27 00:22:49 +03:00
}
2015-08-05 05:09:58 +03:00
}
if (!_.isEmpty(data)) {
return data;
2015-05-27 00:22:49 +03:00
}
},
2015-08-05 05:09:58 +03:00
fulfillLocal: function(path, query) {
var data;
data = {};
if (query.path) {
data.path = path;
2015-05-27 00:22:49 +03:00
}
2015-08-05 05:09:58 +03:00
if (query.name) {
data.name = path.split("/").pop();
}
if (query.sein) {
2015-08-06 05:13:41 +03:00
data.sein = this.getPare(path);
2015-08-05 05:09:58 +03:00
}
if (query.next) {
2015-08-06 05:13:41 +03:00
data.next = this.getNext(path);
2015-08-05 05:09:58 +03:00
}
if (query.prev) {
2015-08-06 05:13:41 +03:00
data.prev = this.getPrev(path);
2015-08-05 05:09:58 +03:00
}
return data;
2015-05-27 00:22:49 +03:00
},
2016-01-30 05:18:51 +03:00
setCurr: function(arg) {
var path;
path = arg.path;
2015-05-27 00:22:49 +03:00
return _curr = path;
},
getCurr: function() {
return _curr;
},
2016-02-03 21:23:49 +03:00
addVirtual: function(arg) {
var components;
components = arg.components;
return _.extend(_virt, components);
},
getVirtualComponents: function() {
return _virt;
},
2016-01-30 05:18:51 +03:00
loadPath: function(arg) {
var data, path;
path = arg.path, data = arg.data;
2015-08-06 05:13:41 +03:00
return this.loadValues(this.getTree(path.split('/'), true), path, data);
2015-05-27 00:22:49 +03:00
},
2015-08-06 05:13:41 +03:00
loadValues: function(tree, path, data) {
var k, old, ref, ref1, v;
2015-08-06 05:13:41 +03:00
old = (ref = _data[path]) != null ? ref : {};
for (k in data) {
if (QUERIES[k]) {
2015-08-06 05:13:41 +03:00
old[k] = data[k];
2015-06-18 04:30:19 +03:00
}
2015-05-27 00:22:49 +03:00
}
ref1 = data.kids;
for (k in ref1) {
v = ref1[k];
2015-08-06 05:13:41 +03:00
if (tree[k] == null) {
tree[k] = {};
2015-06-18 04:30:19 +03:00
}
2015-08-06 05:13:41 +03:00
this.loadValues(tree[k], path + "/" + k, v);
2015-05-27 00:22:49 +03:00
}
2015-08-06 05:13:41 +03:00
if (data.kids && _.isEmpty(data.kids)) {
2015-10-30 02:49:10 +03:00
old.kids = false;
2015-05-27 00:22:49 +03:00
}
2015-08-06 05:13:41 +03:00
return _data[path] = old;
2015-05-27 00:22:49 +03:00
},
2015-08-05 05:09:58 +03:00
getSiblings: function(path) {
2015-05-27 00:22:49 +03:00
var curr;
2015-08-05 05:09:58 +03:00
if (path == null) {
path = _curr;
}
curr = path.split("/");
2015-05-27 00:22:49 +03:00
curr.pop();
if (curr.length !== 0) {
return this.getTree(curr);
} else {
return {};
}
},
2015-08-06 05:13:41 +03:00
getTree: function(_path, make) {
var i, len, sub, tree;
if (make == null) {
make = false;
}
tree = _tree;
for (i = 0, len = _path.length; i < len; i++) {
sub = _path[i];
if (tree[sub] == null) {
if (!make) {
return null;
}
tree[sub] = {};
}
tree = tree[sub];
}
return tree;
},
2015-08-05 05:09:58 +03:00
getPrev: function(path) {
2015-05-27 00:22:49 +03:00
var ind, key, par, sibs, win;
2015-08-05 05:09:58 +03:00
if (path == null) {
path = _curr;
}
sibs = _.keys(this.getSiblings(path)).sort();
2015-05-27 00:22:49 +03:00
if (sibs.length < 2) {
return null;
} else {
2015-08-06 05:13:41 +03:00
par = path.split("/");
2015-05-27 00:22:49 +03:00
key = par.pop();
ind = sibs.indexOf(key);
win = ind - 1 >= 0 ? sibs[ind - 1] : sibs[sibs.length - 1];
par.push(win);
return par.join("/");
}
},
2015-08-05 05:09:58 +03:00
getNext: function(path) {
2015-05-27 00:22:49 +03:00
var ind, key, par, sibs, win;
2015-08-05 05:09:58 +03:00
if (path == null) {
path = _curr;
}
sibs = _.keys(this.getSiblings(path)).sort();
2015-05-27 00:22:49 +03:00
if (sibs.length < 2) {
return null;
} else {
2015-08-06 05:13:41 +03:00
par = path.split("/");
2015-05-27 00:22:49 +03:00
key = par.pop();
ind = sibs.indexOf(key);
win = ind + 1 < sibs.length ? sibs[ind + 1] : sibs[0];
par.push(win);
return par.join("/");
}
},
2015-08-05 05:09:58 +03:00
getPare: function(path) {
2015-05-27 00:22:49 +03:00
var _path;
2015-08-05 05:09:58 +03:00
if (path == null) {
path = _curr;
}
_path = this.pathToArr(path);
2015-05-27 00:22:49 +03:00
if (_path.length > 1) {
_path.pop();
_path = _path.join("/");
if (_path === "") {
_path = "/";
}
return _path;
} else {
return null;
}
2016-01-30 05:18:51 +03:00
},
setNav: function(arg) {
var dpad, nav, sibs, subnav, title;
title = arg.title, dpad = arg.dpad, sibs = arg.sibs, subnav = arg.subnav;
nav = {
title: title,
dpad: dpad,
sibs: sibs,
subnav: subnav,
open: (_nav.open ? _nav.open : false)
};
return _nav = nav;
},
getNav: function() {
return _nav;
},
toggleNav: function() {
return _nav.open = !_nav.open;
},
clearNav: function() {
return _nav = {
title: null,
dpad: null,
sibs: null,
subnav: null,
open: false
};
2015-05-27 00:22:49 +03:00
}
});
2016-01-30 05:18:51 +03:00
TreeStore.dispatchToken = MessageDispatcher.register(function(p) {
var a;
a = p.action;
if (TreeStore[a.type]) {
TreeStore[a.type](a);
return TreeStore.emitChange();
2015-05-27 00:22:49 +03:00
}
});
module.exports = TreeStore;
2016-02-03 21:23:49 +03:00
},{"../dispatcher/Dispatcher.coffee":18,"events":25}],22:[function(require,module,exports){
var scroll;
scroll = {
w: null,
$d: null,
$n: null,
nh: null,
cs: null,
ls: null,
track: function() {
this.w = $(window).width();
this.$n = $('.nav.container');
return this.nh = $('.nav.container .ctrl').outerHeight(true);
},
clearNav: function() {
return this.$n.removeClass('m-up m-down m-fixed');
},
resize: function() {
if (this.w > 1170) {
return this.clearNav();
}
},
scroll: function() {
var ct, dy, top;
this.cs = $(window).scrollTop();
if (this.w > 1170) {
this.clearNav();
}
if (this.w < 1170) {
dy = this.ls - this.cs;
this.$d.removeClass('focus');
if (this.cs <= 0) {
this.$n.removeClass('m-up');
this.$n.addClass('m-down m-fixed');
return;
}
if (dy > 0) {
if (!this.$n.hasClass('m-down')) {
this.$n.removeClass('m-up').addClass('m-down');
ct = this.$n.offset().top;
top = this.cs - this.nh;
if (this.cs > ct && this.cs < ct + this.nh) {
top = ct;
}
this.$n.offset({
top: this.$n.top
});
}
if (this.$n.hasClass('m-down') && !this.$n.hasClass('m-fixed') && this.$n.offset().top >= this.cs) {
this.$n.addClass('m-fixed');
this.$n.attr({
style: ''
});
}
}
if (dy < 0) {
if (!this.$n.hasClass('m-up')) {
this.$n.removeClass('m-down m-fixed').addClass('m-up');
top = this.cs < 0 ? 0 : this.cs;
ct = this.$n.offset().top;
if (top > ct && top < ct + this.nh) {
top = ct;
}
this.$n.offset({
top: top
});
}
if (this.$n.hasClass('m-up') && this.$d.hasClass('open')) {
if (this.cs > this.$n.offset().top + this.$n.height()) {
this.$d.removeClass('open');
}
}
}
}
return this.ls = this.cs;
},
init: function() {
setInterval(this.track.bind(this), 200);
this.ls = $(window).scrollTop();
this.cs = $(window).scrollTop();
this.$d = $('.nav.container .ctrl');
$(window).on('resize', this.resize.bind(this));
return $(window).on('scroll', this.scroll.bind(this));
}
};
scroll.init();
module.exports = scroll;
2016-02-03 21:23:49 +03:00
},{}],23:[function(require,module,exports){
var _basepath;
_basepath = window.urb.util.basepath("/");
_basepath += (window.location.pathname.replace(window.tree._basepath, "")).split("/")[0];
module.exports = {
basepath: function(path) {
var _path, prefix;
prefix = _basepath;
if (prefix === "/") {
prefix = "";
}
if (path[0] !== "/") {
path = "/" + path;
}
_path = prefix + path;
if (_path.slice(-1) === "/") {
_path = _path.slice(0, -1);
}
return _path;
},
fragpath: function(path) {
return path.replace(/\/$/, '').replace(_basepath, "");
},
getKeys: function(kids) {
var k, keys, ref, ref1, ref2, sorted, v;
sorted = true;
keys = [];
for (k in kids) {
v = kids[k];
if ((ref = v.meta) != null ? ref.hide : void 0) {
continue;
}
if (((ref1 = v.meta) != null ? ref1.sort : void 0) == null) {
sorted = false;
}
keys[Number((ref2 = v.meta) != null ? ref2.sort : void 0)] = k;
}
if (sorted !== true) {
return keys = _.keys(kids).sort();
} else {
return keys = _.values(keys);
}
}
};
2015-11-13 23:18:38 +03:00
2016-02-03 21:23:49 +03:00
},{}],24:[function(require,module,exports){
2016-01-30 05:18:51 +03:00
/*!
Copyright (c) 2016 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
/* global define */
(function () {
'use strict';
var hasOwn = {}.hasOwnProperty;
function classNames () {
var classes = [];
for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
if (!arg) continue;
var argType = typeof arg;
if (argType === 'string' || argType === 'number') {
classes.push(arg);
} else if (Array.isArray(arg)) {
classes.push(classNames.apply(null, arg));
} else if (argType === 'object') {
for (var key in arg) {
if (hasOwn.call(arg, key) && arg[key]) {
classes.push(key);
}
}
}
}
return classes.join(' ');
}
if (typeof module !== 'undefined' && module.exports) {
module.exports = classNames;
} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {
// register as 'classnames', consistent with npm package name
define('classnames', [], function () {
return classNames;
});
} else {
window.classNames = classNames;
}
}());
2016-02-03 21:23:49 +03:00
},{}],25:[function(require,module,exports){
2015-05-27 00:22:49 +03:00
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
function EventEmitter() {
this._events = this._events || {};
this._maxListeners = this._maxListeners || undefined;
}
module.exports = EventEmitter;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
EventEmitter.defaultMaxListeners = 10;
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function(n) {
if (!isNumber(n) || n < 0 || isNaN(n))
throw TypeError('n must be a positive number');
this._maxListeners = n;
return this;
};
EventEmitter.prototype.emit = function(type) {
var er, handler, len, args, i, listeners;
if (!this._events)
this._events = {};
// If there is no 'error' event listener then throw.
if (type === 'error') {
if (!this._events.error ||
(isObject(this._events.error) && !this._events.error.length)) {
er = arguments[1];
if (er instanceof Error) {
throw er; // Unhandled 'error' event
}
throw TypeError('Uncaught, unspecified "error" event.');
2015-05-27 00:22:49 +03:00
}
}
handler = this._events[type];
if (isUndefined(handler))
return false;
if (isFunction(handler)) {
switch (arguments.length) {
// fast cases
case 1:
handler.call(this);
break;
case 2:
handler.call(this, arguments[1]);
break;
case 3:
handler.call(this, arguments[1], arguments[2]);
break;
// slower
default:
2016-01-30 05:18:51 +03:00
args = Array.prototype.slice.call(arguments, 1);
2015-05-27 00:22:49 +03:00
handler.apply(this, args);
}
} else if (isObject(handler)) {
2016-01-30 05:18:51 +03:00
args = Array.prototype.slice.call(arguments, 1);
2015-05-27 00:22:49 +03:00
listeners = handler.slice();
len = listeners.length;
for (i = 0; i < len; i++)
listeners[i].apply(this, args);
}
return true;
};
EventEmitter.prototype.addListener = function(type, listener) {
var m;
if (!isFunction(listener))
throw TypeError('listener must be a function');
if (!this._events)
this._events = {};
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (this._events.newListener)
this.emit('newListener', type,
isFunction(listener.listener) ?
listener.listener : listener);
if (!this._events[type])
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;
else if (isObject(this._events[type]))
// If we've already got an array, just append.
this._events[type].push(listener);
else
// Adding the second element, need to change to array.
this._events[type] = [this._events[type], listener];
// Check for listener leak
if (isObject(this._events[type]) && !this._events[type].warned) {
if (!isUndefined(this._maxListeners)) {
m = this._maxListeners;
} else {
m = EventEmitter.defaultMaxListeners;
}
if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;
console.error('(node) warning: possible EventEmitter memory ' +
'leak detected. %d listeners added. ' +
'Use emitter.setMaxListeners() to increase limit.',
this._events[type].length);
if (typeof console.trace === 'function') {
// not supported in IE 10
console.trace();
}
}
}
return this;
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function(type, listener) {
if (!isFunction(listener))
throw TypeError('listener must be a function');
var fired = false;
function g() {
this.removeListener(type, g);
if (!fired) {
fired = true;
listener.apply(this, arguments);
}
}
g.listener = listener;
this.on(type, g);
return this;
};
// emits a 'removeListener' event iff the listener was removed
EventEmitter.prototype.removeListener = function(type, listener) {
var list, position, length, i;
if (!isFunction(listener))
throw TypeError('listener must be a function');
if (!this._events || !this._events[type])
return this;
list = this._events[type];
length = list.length;
position = -1;
if (list === listener ||
(isFunction(list.listener) && list.listener === listener)) {
delete this._events[type];
if (this._events.removeListener)
this.emit('removeListener', type, listener);
} else if (isObject(list)) {
for (i = length; i-- > 0;) {
if (list[i] === listener ||
(list[i].listener && list[i].listener === listener)) {
position = i;
break;
}
}
if (position < 0)
return this;
if (list.length === 1) {
list.length = 0;
delete this._events[type];
} else {
list.splice(position, 1);
}
if (this._events.removeListener)
this.emit('removeListener', type, listener);
}
return this;
};
EventEmitter.prototype.removeAllListeners = function(type) {
var key, listeners;
if (!this._events)
return this;
// not listening for removeListener, no need to emit
if (!this._events.removeListener) {
if (arguments.length === 0)
this._events = {};
else if (this._events[type])
delete this._events[type];
return this;
}
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
for (key in this._events) {
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = {};
return this;
}
listeners = this._events[type];
if (isFunction(listeners)) {
this.removeListener(type, listeners);
2016-01-30 05:18:51 +03:00
} else if (listeners) {
2015-05-27 00:22:49 +03:00
// LIFO order
while (listeners.length)
this.removeListener(type, listeners[listeners.length - 1]);
}
delete this._events[type];
return this;
};
EventEmitter.prototype.listeners = function(type) {
var ret;
if (!this._events || !this._events[type])
ret = [];
else if (isFunction(this._events[type]))
ret = [this._events[type]];
else
ret = this._events[type].slice();
return ret;
};
2016-01-30 05:18:51 +03:00
EventEmitter.prototype.listenerCount = function(type) {
if (this._events) {
var evlistener = this._events[type];
if (isFunction(evlistener))
return 1;
else if (evlistener)
return evlistener.length;
}
return 0;
};
2015-05-27 00:22:49 +03:00
EventEmitter.listenerCount = function(emitter, type) {
2016-01-30 05:18:51 +03:00
return emitter.listenerCount(type);
2015-05-27 00:22:49 +03:00
};
function isFunction(arg) {
return typeof arg === 'function';
}
function isNumber(arg) {
return typeof arg === 'number';
}
function isObject(arg) {
return typeof arg === 'object' && arg !== null;
}
function isUndefined(arg) {
return arg === void 0;
}
2016-02-03 21:23:49 +03:00
},{}]},{},[19]);