2015-08-20 01:44:58 +03:00
|
|
|
(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){
|
2016-06-05 21:19:47 +03:00
|
|
|
var Dispatcher, Persistence, _persistence, util;
|
|
|
|
|
|
|
|
util = require('../util.coffee');
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2015-11-03 22:27:39 +03:00
|
|
|
Dispatcher = require('../dispatcher/Dispatcher.coffee');
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2015-11-03 22:27:39 +03:00
|
|
|
_persistence = require('../persistence/MessagePersistence.coffee');
|
|
|
|
|
|
|
|
Persistence = _persistence({
|
|
|
|
MessageActions: module.exports = {
|
|
|
|
loadMessages: function(messages, last, get) {
|
|
|
|
return Dispatcher.handleServerAction({
|
|
|
|
messages: messages,
|
|
|
|
last: last,
|
|
|
|
get: get,
|
|
|
|
type: "messages-load"
|
|
|
|
});
|
|
|
|
},
|
|
|
|
listenStation: function(station, date) {
|
2016-07-06 00:45:48 +03:00
|
|
|
var now;
|
2015-11-03 22:27:39 +03:00
|
|
|
if (!date) {
|
2016-07-06 00:45:48 +03:00
|
|
|
date = window.urb.util.toDate((now = new Date(), now.setSeconds(0), now.setMilliseconds(0), new Date(now - 24 * 3600 * 1000)));
|
2015-11-03 22:27:39 +03:00
|
|
|
}
|
2016-07-06 00:45:48 +03:00
|
|
|
Dispatcher.handleViewAction({
|
|
|
|
type: "messages-fetch"
|
|
|
|
});
|
2015-11-03 22:27:39 +03:00
|
|
|
return Persistence.listenStation(station, date);
|
|
|
|
},
|
|
|
|
listeningStation: function(station) {
|
|
|
|
return Dispatcher.handleViewAction({
|
|
|
|
station: station,
|
|
|
|
type: "messages-listen"
|
|
|
|
});
|
|
|
|
},
|
|
|
|
setTyping: function(state) {
|
|
|
|
return Dispatcher.handleViewAction({
|
|
|
|
state: state,
|
|
|
|
type: "messages-typing"
|
|
|
|
});
|
|
|
|
},
|
|
|
|
getMore: function(station, start, end) {
|
|
|
|
Dispatcher.handleViewAction({
|
|
|
|
type: "messages-fetch"
|
|
|
|
});
|
|
|
|
return Persistence.get(station, start, end);
|
|
|
|
},
|
2016-06-05 21:19:47 +03:00
|
|
|
sendMessage: function(txt, audience, global) {
|
|
|
|
var _audi, j, k, len, message, messageType, ref, ref1, results, say, serial, speech, speeches, v;
|
|
|
|
if (global == null) {
|
|
|
|
global = urb.user === urb.ship;
|
|
|
|
}
|
|
|
|
serial = util.uuid32();
|
2015-11-03 22:27:39 +03:00
|
|
|
audience = _.uniq(audience);
|
|
|
|
_audi = {};
|
|
|
|
for (k in audience) {
|
|
|
|
v = audience[k];
|
|
|
|
_audi[v] = {
|
|
|
|
envelope: {
|
|
|
|
visible: true,
|
|
|
|
sender: null
|
|
|
|
},
|
|
|
|
delivery: "pending"
|
|
|
|
};
|
2015-06-19 04:47:41 +03:00
|
|
|
}
|
|
|
|
speech = {
|
2015-10-28 02:43:08 +03:00
|
|
|
lin: {
|
2015-11-03 22:27:39 +03:00
|
|
|
txt: txt,
|
|
|
|
say: true
|
2015-01-27 01:47:18 +03:00
|
|
|
}
|
2015-10-28 02:43:08 +03:00
|
|
|
};
|
2015-11-03 22:27:39 +03:00
|
|
|
if (txt[0] === "@") {
|
|
|
|
speech.lin.txt = speech.lin.txt.slice(1).trim();
|
|
|
|
speech.lin.say = false;
|
|
|
|
} else if (txt[0] === "#") {
|
|
|
|
speech = {
|
|
|
|
"eval": speech.lin.txt.slice(1).trim()
|
|
|
|
};
|
|
|
|
} else if (window.urb.util.isURL(txt)) {
|
|
|
|
speech = {
|
|
|
|
url: txt
|
|
|
|
};
|
|
|
|
}
|
|
|
|
speeches = !(((ref = speech.lin) != null ? ref.txt.length : void 0) > 64) ? [speech] : ((ref1 = speech.lin, say = ref1.say, txt = ref1.txt, ref1), txt.match(/(.{1,64}$|.{0,64} |.{64}|.+$)/g).map(function(s, i) {
|
|
|
|
say || (say = i !== 0);
|
|
|
|
return {
|
|
|
|
lin: {
|
|
|
|
say: say,
|
|
|
|
txt: s.slice(-1 !== " ") ? s : s.slice(0, -1)
|
2015-10-28 02:43:08 +03:00
|
|
|
}
|
2015-11-03 22:27:39 +03:00
|
|
|
};
|
|
|
|
}));
|
|
|
|
results = [];
|
|
|
|
for (j = 0, len = speeches.length; j < len; j++) {
|
|
|
|
speech = speeches[j];
|
|
|
|
message = {
|
2016-07-16 03:15:03 +03:00
|
|
|
ship: window.urb.user,
|
2015-11-03 22:27:39 +03:00
|
|
|
thought: {
|
2016-06-05 21:19:47 +03:00
|
|
|
serial: util.uuid32(),
|
2015-11-03 22:27:39 +03:00
|
|
|
audience: _audi,
|
|
|
|
statement: {
|
|
|
|
bouquet: [],
|
|
|
|
speech: speech,
|
|
|
|
date: Date.now()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Dispatcher.handleViewAction({
|
|
|
|
message: message,
|
|
|
|
type: "message-send"
|
|
|
|
});
|
2016-06-05 21:19:47 +03:00
|
|
|
messageType = (global ? "publish" : "review");
|
|
|
|
results.push(Persistence.sendMessage(messageType, message.thought));
|
2015-11-03 22:27:39 +03:00
|
|
|
}
|
|
|
|
return results;
|
2015-10-28 02:43:08 +03:00
|
|
|
}
|
2015-01-27 01:47:18 +03:00
|
|
|
}
|
2015-11-03 22:27:39 +03:00
|
|
|
});
|
2015-01-27 01:47:18 +03:00
|
|
|
|
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
},{"../dispatcher/Dispatcher.coffee":9,"../persistence/MessagePersistence.coffee":11,"../util.coffee":15}],2:[function(require,module,exports){
|
2015-11-03 22:27:39 +03:00
|
|
|
var Dispatcher, Persistence, _persistence, serverAction, viewAction;
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2015-11-03 22:27:39 +03:00
|
|
|
Dispatcher = require('../dispatcher/Dispatcher.coffee');
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2015-11-03 22:27:39 +03:00
|
|
|
serverAction = function(f) {
|
|
|
|
return function() {
|
|
|
|
return Dispatcher.handleServerAction(f.apply(this, arguments));
|
|
|
|
};
|
2015-01-27 01:47:18 +03:00
|
|
|
};
|
|
|
|
|
2015-11-03 22:27:39 +03:00
|
|
|
viewAction = function(f) {
|
|
|
|
return function() {
|
|
|
|
return Dispatcher.handleViewAction(f.apply(this, arguments));
|
|
|
|
};
|
|
|
|
};
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2015-11-03 22:27:39 +03:00
|
|
|
_persistence = require('../persistence/StationPersistence.coffee');
|
2015-06-19 04:47:41 +03:00
|
|
|
|
2015-11-03 22:27:39 +03:00
|
|
|
Persistence = _persistence({
|
|
|
|
StationActions: module.exports = {
|
|
|
|
loadGlyphs: serverAction(function(glyphs) {
|
|
|
|
return {
|
|
|
|
glyphs: glyphs,
|
|
|
|
type: "glyphs-load"
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
loadMembers: serverAction(function(members) {
|
|
|
|
return {
|
|
|
|
members: members,
|
|
|
|
type: "members-load"
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
loadStations: serverAction(function(stations) {
|
|
|
|
return {
|
|
|
|
stations: stations,
|
|
|
|
type: "stations-load"
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
loadConfig: serverAction(function(station, config) {
|
|
|
|
return {
|
|
|
|
station: station,
|
|
|
|
config: config,
|
|
|
|
type: "config-load"
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
setTyping: viewAction(function(station, state) {
|
|
|
|
return {
|
|
|
|
station: station,
|
|
|
|
state: state,
|
|
|
|
type: "typing-set"
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
setAudience: viewAction(function(audience) {
|
|
|
|
return {
|
|
|
|
audience: audience,
|
|
|
|
type: "station-set-audience"
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
setValidAudience: viewAction(function(valid) {
|
|
|
|
return {
|
|
|
|
valid: valid,
|
|
|
|
type: "station-set-valid-audience"
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
toggleAudience: viewAction(function(station) {
|
|
|
|
return {
|
|
|
|
station: station,
|
|
|
|
type: "station-audience-toggle"
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
switchStation: viewAction(function(station) {
|
|
|
|
return {
|
|
|
|
station: station,
|
|
|
|
type: "station-switch"
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
listeningStation: viewAction(function(station) {
|
|
|
|
return {
|
|
|
|
station: station,
|
|
|
|
type: "station-listen"
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
createStation: function(station) {
|
|
|
|
Dispatcher.handleViewAction({
|
|
|
|
station: station,
|
|
|
|
type: "station-create"
|
|
|
|
});
|
|
|
|
return Persistence.createStation(station);
|
|
|
|
},
|
|
|
|
listen: function() {
|
|
|
|
return Persistence.listen();
|
|
|
|
},
|
|
|
|
ping: function(_ping) {
|
|
|
|
return Persistence.ping(_ping);
|
|
|
|
},
|
|
|
|
removeStation: function(station) {
|
|
|
|
return Persistence.removeStation(station);
|
|
|
|
},
|
|
|
|
listenStation: function(station) {
|
2016-07-16 03:15:03 +03:00
|
|
|
return Persistence.listenStation(station, {
|
|
|
|
'group': 'group',
|
|
|
|
'glyph': 'glyph',
|
|
|
|
'cabal': 'cabal'
|
|
|
|
});
|
2015-11-03 22:27:39 +03:00
|
|
|
},
|
|
|
|
createStation: function(name) {
|
|
|
|
return Persistence.createStation(name);
|
|
|
|
},
|
|
|
|
setSources: function(station, sources) {
|
|
|
|
return Persistence.setSources(station, window.urb.ship, sources);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
},{"../dispatcher/Dispatcher.coffee":9,"../persistence/StationPersistence.coffee":12}],3:[function(require,module,exports){
|
2016-07-06 00:45:48 +03:00
|
|
|
var div, recl, ref, span;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
|
|
|
recl = React.createClass;
|
|
|
|
|
2016-07-06 00:45:48 +03:00
|
|
|
ref = React.DOM, span = ref.span, div = ref.div;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
|
|
|
module.exports = recl({
|
|
|
|
displayName: "Load",
|
|
|
|
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-07-06 00:45:48 +03:00
|
|
|
return span({
|
|
|
|
className: "loading state-" + this.state.anim
|
|
|
|
}, '');
|
2016-01-27 21:53:37 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-06-19 04:47:41 +03:00
|
|
|
|
2016-01-27 21:53:37 +03:00
|
|
|
},{}],4:[function(require,module,exports){
|
2016-06-05 21:19:47 +03:00
|
|
|
var Ship, div, input, recl, ref, rele, textarea;
|
|
|
|
|
|
|
|
Ship = window.tree.util.components.ship;
|
2015-01-27 01:47:18 +03:00
|
|
|
|
|
|
|
recl = React.createClass;
|
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
rele = React.createElement;
|
|
|
|
|
2015-09-01 21:27:12 +03:00
|
|
|
ref = React.DOM, div = ref.div, input = ref.input, textarea = ref.textarea;
|
2015-01-27 01:47:18 +03:00
|
|
|
|
|
|
|
module.exports = recl({
|
2016-01-27 21:53:37 +03:00
|
|
|
displayName: "Member",
|
2015-01-27 01:47:18 +03:00
|
|
|
render: function() {
|
2016-08-09 00:04:59 +03:00
|
|
|
var k, ref1, ship;
|
|
|
|
ship = (ref1 = this.props.ship) != null ? ref1 : "";
|
2015-01-27 01:47:18 +03:00
|
|
|
k = "ship";
|
|
|
|
if (this.props.presence) {
|
|
|
|
k += " " + this.props.presence;
|
|
|
|
}
|
|
|
|
return div({
|
2016-01-27 21:53:37 +03:00
|
|
|
className: "iden",
|
|
|
|
key: "iden"
|
2015-01-27 01:47:18 +03:00
|
|
|
}, [
|
2016-06-05 21:19:47 +03:00
|
|
|
rele(Ship, {
|
|
|
|
ship: ship
|
|
|
|
})
|
2015-01-27 01:47:18 +03:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-01-27 21:53:37 +03:00
|
|
|
},{}],5:[function(require,module,exports){
|
2016-06-05 21:19:47 +03:00
|
|
|
var Member, a, clas, div, h2, h3, label, pre, recl, ref, util,
|
2015-10-29 00:38:03 +03:00
|
|
|
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
util = require('../util.coffee');
|
|
|
|
|
2015-10-29 00:38:03 +03:00
|
|
|
clas = require('classnames');
|
|
|
|
|
2015-01-27 01:47:18 +03:00
|
|
|
recl = React.createClass;
|
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
ref = React.DOM, div = ref.div, pre = ref.pre, a = ref.a, label = ref.label, h2 = ref.h2, h3 = ref.h3;
|
2015-03-06 06:58:23 +03:00
|
|
|
|
2015-01-27 01:47:18 +03:00
|
|
|
Member = require('./MemberComponent.coffee');
|
|
|
|
|
2016-01-27 21:53:37 +03:00
|
|
|
module.exports = recl({
|
2015-10-29 00:38:03 +03:00
|
|
|
displayName: "Message",
|
2015-01-27 01:47:18 +03:00
|
|
|
lz: function(n) {
|
|
|
|
if (n < 10) {
|
|
|
|
return "0" + n;
|
|
|
|
} else {
|
|
|
|
return "" + n;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
convTime: function(time) {
|
|
|
|
var d, h, m, s;
|
|
|
|
d = new Date(time);
|
|
|
|
h = this.lz(d.getHours());
|
|
|
|
m = this.lz(d.getMinutes());
|
|
|
|
s = this.lz(d.getSeconds());
|
|
|
|
return "~" + h + "." + m + "." + s;
|
|
|
|
},
|
2015-03-10 21:49:01 +03:00
|
|
|
_handleAudi: function(e) {
|
|
|
|
var audi;
|
2016-02-07 03:42:31 +03:00
|
|
|
audi = _.map($(e.target).closest('.path').find('div'), function(div) {
|
2016-12-20 02:23:15 +03:00
|
|
|
return "~" + $(div).text();
|
2015-03-26 00:05:46 +03:00
|
|
|
});
|
2015-03-10 21:49:01 +03:00
|
|
|
return this.props._handleAudi(audi);
|
|
|
|
},
|
2015-03-07 22:09:30 +03:00
|
|
|
_handlePm: function(e) {
|
2015-03-10 01:45:34 +03:00
|
|
|
var user;
|
|
|
|
if (!this.props._handlePm) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-07 21:47:25 +03:00
|
|
|
user = $(e.target).closest('.iden').text();
|
2016-07-20 00:48:14 +03:00
|
|
|
if (user[0] === "~") {
|
|
|
|
user = user.slice(1);
|
|
|
|
}
|
2015-05-07 21:47:25 +03:00
|
|
|
if (user.toLowerCase() === 'system') {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-10 01:45:34 +03:00
|
|
|
return this.props._handlePm(user);
|
2015-03-07 22:09:30 +03:00
|
|
|
},
|
2016-03-01 00:20:19 +03:00
|
|
|
renderSpeech: function(arg) {
|
2016-05-19 08:48:27 +03:00
|
|
|
var app, com, exp, fat, lin, mor, tax, url, x;
|
|
|
|
lin = arg.lin, app = arg.app, exp = arg.exp, tax = arg.tax, url = arg.url, mor = arg.mor, fat = arg.fat, com = arg.com;
|
2015-10-28 02:43:08 +03:00
|
|
|
switch (false) {
|
2016-03-04 02:18:16 +03:00
|
|
|
case !(lin || app || exp || tax):
|
|
|
|
return (lin || app || exp || tax).txt;
|
2016-03-01 00:20:19 +03:00
|
|
|
case !url:
|
2015-10-28 02:43:08 +03:00
|
|
|
return a({
|
2016-03-01 00:20:19 +03:00
|
|
|
href: url.txt,
|
2016-01-27 21:53:37 +03:00
|
|
|
target: "_blank",
|
|
|
|
key: "speech"
|
2016-03-01 00:20:19 +03:00
|
|
|
}, url.txt);
|
2016-03-04 02:18:16 +03:00
|
|
|
case !com:
|
|
|
|
return div({}, com.txt, div({}, a({
|
|
|
|
className: "btn",
|
|
|
|
href: com.url
|
|
|
|
}, "Go to thread")));
|
2016-03-01 00:20:19 +03:00
|
|
|
case !mor:
|
|
|
|
return mor.map(this.renderSpeech);
|
|
|
|
case !fat:
|
2016-03-04 02:18:16 +03:00
|
|
|
return div({}, this.renderSpeech(fat.taf), div({
|
|
|
|
className: "fat"
|
|
|
|
}, this.renderTorso(fat.tor)));
|
2015-10-28 02:43:08 +03:00
|
|
|
default:
|
|
|
|
return "Unknown speech type:" + ((function() {
|
|
|
|
var results;
|
|
|
|
results = [];
|
2016-03-01 00:20:19 +03:00
|
|
|
for (x in arguments[0]) {
|
2015-10-28 02:43:08 +03:00
|
|
|
results.push(" %" + x);
|
|
|
|
}
|
|
|
|
return results;
|
2016-03-01 00:20:19 +03:00
|
|
|
}).apply(this, arguments)).join('');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
renderTorso: function(arg) {
|
|
|
|
var name, tank, text, x;
|
|
|
|
text = arg.text, tank = arg.tank, name = arg.name;
|
|
|
|
switch (false) {
|
|
|
|
case text == null:
|
|
|
|
return text;
|
|
|
|
case tank == null:
|
|
|
|
return pre({}, tank.join("\n"));
|
|
|
|
case name == null:
|
2016-03-04 02:18:16 +03:00
|
|
|
return div({}, name.nom, ": ", this.renderTorso(name.mon));
|
2016-03-01 00:20:19 +03:00
|
|
|
default:
|
|
|
|
return "Unknown torso:" + ((function() {
|
|
|
|
var results;
|
|
|
|
results = [];
|
|
|
|
for (x in arguments[0]) {
|
|
|
|
results.push(" %" + x);
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}).apply(this, arguments)).join('');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
classesInSpeech: function(arg) {
|
2016-05-19 08:48:27 +03:00
|
|
|
var app, exp, fat, lin, mor, url;
|
|
|
|
url = arg.url, exp = arg.exp, app = arg.app, lin = arg.lin, mor = arg.mor, fat = arg.fat;
|
2016-03-01 00:20:19 +03:00
|
|
|
switch (false) {
|
|
|
|
case !url:
|
|
|
|
return "url";
|
|
|
|
case !exp:
|
|
|
|
return "exp";
|
|
|
|
case !app:
|
|
|
|
return "say";
|
|
|
|
case !lin:
|
|
|
|
return {
|
|
|
|
say: lin.say === false
|
|
|
|
};
|
|
|
|
case !mor:
|
|
|
|
return mor != null ? mor.map(this.classesInSpeech) : void 0;
|
|
|
|
case !fat:
|
|
|
|
return this.classesInSpeech(fat.taf);
|
2015-10-28 02:43:08 +03:00
|
|
|
}
|
|
|
|
},
|
2015-01-27 01:47:18 +03:00
|
|
|
render: function() {
|
2016-06-05 21:19:47 +03:00
|
|
|
var aude, audi, bouquet, className, comment, delivery, k, mainStation, name, path, ref1, speech, style, thought, txt, type, url, v;
|
2016-01-27 21:53:37 +03:00
|
|
|
thought = this.props.thought;
|
|
|
|
delivery = _.uniq(_.pluck(thought.audience, "delivery"));
|
|
|
|
speech = thought.statement.speech;
|
2016-03-04 02:18:16 +03:00
|
|
|
bouquet = thought.statement.bouquet;
|
2015-06-19 04:47:41 +03:00
|
|
|
if (speech == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-27 01:47:18 +03:00
|
|
|
name = this.props.name ? this.props.name : "";
|
2016-01-27 21:53:37 +03:00
|
|
|
aude = _.keys(thought.audience);
|
2016-06-05 21:19:47 +03:00
|
|
|
audi = util.clipAudi(aude).map(function(_audi) {
|
2016-03-04 02:18:16 +03:00
|
|
|
return div({
|
|
|
|
key: _audi
|
2016-07-27 03:57:59 +03:00
|
|
|
}, _audi);
|
2015-03-26 00:05:46 +03:00
|
|
|
});
|
2016-06-05 21:19:47 +03:00
|
|
|
mainStation = util.mainStationPath(window.urb.user);
|
2015-10-29 00:38:03 +03:00
|
|
|
type = indexOf.call(aude, mainStation) >= 0 ? 'private' : 'public';
|
2016-03-04 02:18:16 +03:00
|
|
|
if (_.filter(bouquet, ["comment"]).length > 0) {
|
|
|
|
comment = true;
|
|
|
|
ref1 = speech.mor;
|
|
|
|
for (k in ref1) {
|
|
|
|
v = ref1[k];
|
|
|
|
if (v.fat) {
|
|
|
|
url = v.fat.taf.url.txt;
|
|
|
|
txt = v.fat.tor.text;
|
|
|
|
}
|
|
|
|
if (v.app) {
|
|
|
|
path = v.app.txt.replace("comment on ", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
audi = a({
|
|
|
|
href: url
|
|
|
|
}, path);
|
|
|
|
speech = {
|
|
|
|
com: {
|
|
|
|
txt: txt,
|
|
|
|
url: url
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
className = clas('gram', (this.props.sameAs ? "same" : "first"), (delivery.indexOf("received") !== -1 ? "received" : "pending"), {
|
2015-10-29 00:38:03 +03:00
|
|
|
'new': this.props.unseen
|
2016-03-04 02:18:16 +03:00
|
|
|
}, {
|
|
|
|
comment: comment
|
2016-03-01 00:20:19 +03:00
|
|
|
}, this.classesInSpeech(speech));
|
2016-06-05 21:19:47 +03:00
|
|
|
style = {
|
2016-06-07 21:42:19 +03:00
|
|
|
height: this.props.height,
|
|
|
|
marginTop: this.props.marginTop
|
2016-06-05 21:19:47 +03:00
|
|
|
};
|
2016-01-30 05:18:51 +03:00
|
|
|
return div({
|
2016-01-27 21:53:37 +03:00
|
|
|
className: className,
|
|
|
|
'data-index': this.props.index,
|
2016-06-05 21:19:47 +03:00
|
|
|
key: "message",
|
|
|
|
style: style
|
2016-01-27 21:53:37 +03:00
|
|
|
}, div({
|
|
|
|
className: "meta",
|
|
|
|
key: "meta"
|
|
|
|
}, label({
|
|
|
|
className: "type " + type,
|
|
|
|
"data-glyph": this.props.glyph || "*"
|
|
|
|
}), h2({
|
|
|
|
className: 'author planet',
|
|
|
|
onClick: this._handlePm,
|
|
|
|
key: "member"
|
|
|
|
}, React.createElement(Member, {
|
|
|
|
ship: this.props.ship,
|
|
|
|
glyph: this.props.glyph,
|
|
|
|
key: "member"
|
|
|
|
})), h3({
|
|
|
|
className: "path",
|
|
|
|
onClick: this._handleAudi,
|
|
|
|
key: "audi"
|
|
|
|
}, audi), h3({
|
|
|
|
className: "time",
|
|
|
|
key: "time"
|
|
|
|
}, this.convTime(thought.statement.date))), div({
|
|
|
|
className: "speech",
|
|
|
|
key: "speech"
|
2016-03-04 02:18:16 +03:00
|
|
|
}, this.renderSpeech(speech, bouquet)));
|
2015-01-27 01:47:18 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
},{"../util.coffee":15,"./MemberComponent.coffee":4,"classnames":16}],6:[function(require,module,exports){
|
2016-07-06 00:45:48 +03:00
|
|
|
var FONT_SIZE, INFINITE, Infinite, Load, MESSAGE_HEIGHT_FIRST, MESSAGE_HEIGHT_FIRST_MARGIN_TOP, MESSAGE_HEIGHT_SAME, Message, MessageActions, MessageStore, StationActions, StationStore, div, recl, rele, util;
|
2016-06-05 21:19:47 +03:00
|
|
|
|
|
|
|
util = require('../util.coffee');
|
2016-01-27 21:53:37 +03:00
|
|
|
|
|
|
|
Infinite = null;
|
|
|
|
|
|
|
|
recl = React.createClass;
|
|
|
|
|
2016-07-06 00:45:48 +03:00
|
|
|
rele = React.createElement;
|
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
div = React.DOM.div;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
|
|
|
MessageActions = require('../actions/MessageActions.coffee');
|
|
|
|
|
|
|
|
MessageStore = require('../stores/MessageStore.coffee');
|
|
|
|
|
|
|
|
StationActions = require('../actions/StationActions.coffee');
|
|
|
|
|
|
|
|
StationStore = require('../stores/StationStore.coffee');
|
|
|
|
|
|
|
|
Message = require('./MessageComponent.coffee');
|
|
|
|
|
2016-07-06 00:45:48 +03:00
|
|
|
Load = require('./LoadComponent.coffee');
|
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
INFINITE = true;
|
|
|
|
|
2016-07-06 00:45:48 +03:00
|
|
|
MESSAGE_HEIGHT_SAME = 27;
|
2016-02-07 03:42:31 +03:00
|
|
|
|
2016-07-06 00:45:48 +03:00
|
|
|
MESSAGE_HEIGHT_FIRST = 56 - MESSAGE_HEIGHT_SAME;
|
2016-06-07 21:42:19 +03:00
|
|
|
|
2016-07-06 00:45:48 +03:00
|
|
|
MESSAGE_HEIGHT_FIRST_MARGIN_TOP = 16;
|
|
|
|
|
|
|
|
FONT_SIZE = parseInt($('body').css('font-size').match(/(\d*)px/)[1]);
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2015-01-27 01:47:18 +03:00
|
|
|
module.exports = recl({
|
2015-10-28 03:56:27 +03:00
|
|
|
displayName: "Messages",
|
2016-06-05 21:19:47 +03:00
|
|
|
pageSize: 200,
|
2015-01-27 01:47:18 +03:00
|
|
|
paddingTop: 100,
|
2016-06-05 21:19:47 +03:00
|
|
|
paddingBottom: 100,
|
2015-01-27 01:47:18 +03:00
|
|
|
stateFromStore: function() {
|
|
|
|
return {
|
|
|
|
messages: MessageStore.getAll(),
|
|
|
|
last: MessageStore.getLast(),
|
|
|
|
fetching: MessageStore.getFetching(),
|
|
|
|
listening: MessageStore.getListening(),
|
2016-03-01 04:31:08 +03:00
|
|
|
station: StationStore.getStation(),
|
2015-01-27 08:16:26 +03:00
|
|
|
stations: StationStore.getStations(),
|
|
|
|
configs: StationStore.getConfigs(),
|
2015-10-29 05:10:20 +03:00
|
|
|
typing: MessageStore.getTyping(),
|
2016-01-27 21:53:37 +03:00
|
|
|
glyph: StationStore.getGlyphMap()
|
2015-01-27 01:47:18 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
getInitialState: function() {
|
|
|
|
return this.stateFromStore();
|
|
|
|
},
|
2015-04-28 22:00:46 +03:00
|
|
|
_blur: function() {
|
2016-01-27 21:53:37 +03:00
|
|
|
this.focused = false;
|
2015-04-28 22:00:46 +03:00
|
|
|
return this.lastSeen = this.last;
|
|
|
|
},
|
|
|
|
_focus: function() {
|
2016-01-27 21:53:37 +03:00
|
|
|
this.focused = true;
|
2015-04-28 22:00:46 +03:00
|
|
|
this.lastSeen = null;
|
|
|
|
$('.message.new').removeClass('new');
|
|
|
|
return document.title = document.title.replace(/\ \([0-9]*\)/, "");
|
|
|
|
},
|
2016-06-05 21:19:47 +03:00
|
|
|
atScrollEdge: function() {
|
|
|
|
switch (this.props.chrono) {
|
|
|
|
case "reverse":
|
|
|
|
return $(window).height() < $(window).scrollTop() + $(window)[0].innerHeight + this.paddingBottom;
|
|
|
|
default:
|
|
|
|
return $(window).scrollTop() < this.paddingTop;
|
|
|
|
}
|
|
|
|
},
|
2015-01-27 01:47:18 +03:00
|
|
|
checkMore: function() {
|
|
|
|
var end;
|
2016-06-05 21:19:47 +03:00
|
|
|
if (this.atScrollEdge() && this.state.fetching === false && this.state.last && this.state.last > 0) {
|
2015-01-27 01:47:18 +03:00
|
|
|
end = this.state.last - this.pageSize;
|
|
|
|
if (end < 0) {
|
|
|
|
end = 0;
|
|
|
|
}
|
|
|
|
this.lastLength = this.length;
|
|
|
|
return MessageActions.getMore(this.state.station, this.state.last + 1, end);
|
|
|
|
}
|
|
|
|
},
|
2015-01-27 08:16:26 +03:00
|
|
|
setAudience: function() {
|
2016-01-27 21:53:37 +03:00
|
|
|
var laudi;
|
|
|
|
if (this.state.typing || !this.last) {
|
2015-01-27 08:16:26 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
laudi = _.keys(this.last.thought.audience);
|
|
|
|
if ((_.isEmpty(laudi)) || !_(laudi).difference(this.state.audi).isEmpty()) {
|
2015-01-27 08:16:26 +03:00
|
|
|
return StationActions.setAudience(_.keys(this.last.thought.audience));
|
|
|
|
}
|
|
|
|
},
|
2015-04-28 22:00:46 +03:00
|
|
|
sortedMessages: function(messages) {
|
2016-01-27 21:53:37 +03:00
|
|
|
var station;
|
|
|
|
station = this.state.station;
|
2016-03-01 04:31:08 +03:00
|
|
|
return _.sortBy(messages, (function(_this) {
|
|
|
|
return function(message) {
|
|
|
|
message.pending = message.thought.audience[station];
|
2016-07-16 03:15:03 +03:00
|
|
|
return message.key;
|
2016-03-01 04:31:08 +03:00
|
|
|
};
|
|
|
|
})(this));
|
2015-04-28 22:00:46 +03:00
|
|
|
},
|
2016-01-27 21:53:37 +03:00
|
|
|
componentWillMount: function() {
|
2016-03-04 02:18:16 +03:00
|
|
|
return Infinite = window.Infinite;
|
2016-01-27 21:53:37 +03:00
|
|
|
},
|
2015-01-27 01:47:18 +03:00
|
|
|
componentDidMount: function() {
|
|
|
|
MessageStore.addChangeListener(this._onChangeStore);
|
|
|
|
StationStore.addChangeListener(this._onChangeStore);
|
|
|
|
if (this.state.station && this.state.listening.indexOf(this.state.station) === -1) {
|
|
|
|
MessageActions.listenStation(this.state.station);
|
|
|
|
}
|
2016-06-05 21:19:47 +03:00
|
|
|
if (this.props["static"] == null) {
|
2016-03-09 03:20:49 +03:00
|
|
|
$(window).on('scroll', this.checkMore);
|
2016-06-05 21:19:47 +03:00
|
|
|
}
|
|
|
|
if (this.props.chrono !== "reverse") {
|
|
|
|
util.scrollToBottom();
|
2016-03-09 03:20:49 +03:00
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
this.focused = true;
|
2015-04-28 22:00:46 +03:00
|
|
|
$(window).on('blur', this._blur);
|
2016-07-06 00:45:48 +03:00
|
|
|
$(window).on('focus', this._focus);
|
|
|
|
return $(window).on('resize', _.debounce((function(_this) {
|
|
|
|
return function() {
|
|
|
|
return _this.forceUpdate();
|
|
|
|
};
|
|
|
|
})(this), 250));
|
2015-01-27 01:47:18 +03:00
|
|
|
},
|
2016-02-23 01:58:27 +03:00
|
|
|
componentWillUpdate: function(props, state) {
|
2016-06-13 01:24:12 +03:00
|
|
|
return this.scrollBottom = $(document).height() - ($(window).scrollTop() + window.innerHeight);
|
2016-02-23 01:58:27 +03:00
|
|
|
},
|
|
|
|
componentDidUpdate: function(_props, _state) {
|
2016-06-13 01:24:12 +03:00
|
|
|
var _messages, _oldMessages, appendedToBottom, d, ref, ref1, ref2, setOffset, t;
|
|
|
|
_messages = this.sortedMessages(this.state.messages);
|
|
|
|
_oldMessages = this.sortedMessages(_state.messages);
|
|
|
|
appendedToBottom = (((ref = _.last(_messages)) != null ? ref.key : void 0) == null) || ((ref1 = _.last(_messages)) != null ? ref1.key : void 0) > ((ref2 = _.last(_oldMessages)) != null ? ref2.key : void 0);
|
|
|
|
setOffset = $(document).height() - window.innerHeight - this.scrollBottom;
|
|
|
|
if (this.props.chrono !== "reverse") {
|
|
|
|
if (!(this.scrollBottom > 0 && appendedToBottom)) {
|
|
|
|
$(window).scrollTop(setOffset);
|
|
|
|
}
|
2015-04-28 22:00:46 +03:00
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
if (this.focused === false && this.last !== this.lastSeen) {
|
2015-04-28 22:00:46 +03:00
|
|
|
d = _messages.length - _messages.indexOf(this.lastSeen) - 1;
|
|
|
|
t = document.title;
|
|
|
|
if (document.title.match(/\([0-9]*\)/)) {
|
|
|
|
return document.title = document.title.replace(/\([0-9]*\)/, "(" + d + ")");
|
|
|
|
} else {
|
|
|
|
return document.title = document.title + (" (" + d + ")");
|
2015-01-27 01:47:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
MessageStore.removeChangeListener(this._onChangeStore);
|
|
|
|
return StationStore.removeChangeListener(this._onChangeStore);
|
|
|
|
},
|
|
|
|
_onChangeStore: function() {
|
|
|
|
return this.setState(this.stateFromStore());
|
|
|
|
},
|
2015-03-10 01:45:34 +03:00
|
|
|
_handlePm: function(user) {
|
|
|
|
var audi;
|
2016-07-16 03:15:03 +03:00
|
|
|
if (this.props['audience-lock'] != null) {
|
2016-06-05 21:19:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
audi = [util.mainStationPath(user)];
|
2015-03-26 00:05:46 +03:00
|
|
|
if (user === window.urb.user) {
|
|
|
|
audi.pop();
|
|
|
|
}
|
2015-03-10 01:45:34 +03:00
|
|
|
return StationActions.setAudience(audi);
|
|
|
|
},
|
2015-03-10 21:49:01 +03:00
|
|
|
_handleAudi: function(audi) {
|
|
|
|
return StationActions.setAudience(audi);
|
|
|
|
},
|
2015-01-27 01:47:18 +03:00
|
|
|
render: function() {
|
2016-07-16 03:15:03 +03:00
|
|
|
var _messageGroups, _messages, audience, body, canvas, context, fetching, height, i, index, lastIndex, lastSaid, len, lineNums, marginTop, message, messageHeights, messages, mez, nowSaid, ref, sameAs, speech, speechArr, speechLength, station;
|
2015-01-27 01:47:18 +03:00
|
|
|
station = this.state.station;
|
2016-01-27 21:53:37 +03:00
|
|
|
messages = this.sortedMessages(this.state.messages);
|
|
|
|
this.last = messages[messages.length - 1];
|
|
|
|
if (((ref = this.last) != null ? ref.ship : void 0) && this.last.ship === window.urb.user) {
|
2015-06-23 07:52:46 +03:00
|
|
|
this.lastSeen = this.last;
|
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
this.length = messages.length;
|
|
|
|
setTimeout(((function(_this) {
|
2015-01-27 01:47:18 +03:00
|
|
|
return function() {
|
2016-01-27 21:53:37 +03:00
|
|
|
if (_this.length < _this.pageSize) {
|
2015-01-27 01:47:18 +03:00
|
|
|
return _this.checkMore();
|
|
|
|
}
|
|
|
|
};
|
2016-01-27 21:53:37 +03:00
|
|
|
})(this)), 1);
|
|
|
|
lastIndex = this.lastSeen ? messages.indexOf(this.lastSeen) + 1 : null;
|
2015-05-07 04:01:36 +03:00
|
|
|
lastSaid = null;
|
2016-02-07 03:42:31 +03:00
|
|
|
messageHeights = [];
|
2016-07-06 00:45:48 +03:00
|
|
|
canvas = document.createElement('canvas');
|
|
|
|
context = canvas.getContext('2d');
|
|
|
|
speechLength = $('.grams').width() - (FONT_SIZE * 1.875);
|
2016-07-16 03:15:03 +03:00
|
|
|
_messageGroups = [[]];
|
|
|
|
for (index = i = 0, len = messages.length; i < len; index = ++i) {
|
|
|
|
message = messages[index];
|
|
|
|
nowSaid = [message.ship, _.keys(message.thought.audience)];
|
|
|
|
sameAs = _.isEqual(lastSaid, nowSaid);
|
|
|
|
lastSaid = nowSaid;
|
|
|
|
lineNums = 1;
|
|
|
|
speechArr = [];
|
|
|
|
context.font = FONT_SIZE + 'px bau';
|
|
|
|
if (message.thought.statement.speech.lin != null) {
|
|
|
|
speechArr = message.thought.statement.speech.lin.txt.split(/(\s|-)/);
|
|
|
|
} else if (message.thought.statement.speech.url != null) {
|
|
|
|
speechArr = message.thought.statement.speech.url.txt.split(/(\s|-)/);
|
|
|
|
} else if (message.thought.statement.speech.fat != null) {
|
|
|
|
context.font = (FONT_SIZE * 0.9) + 'px scp';
|
|
|
|
speechArr = message.thought.statement.speech.fat.taf.exp.txt.split(/(\s|-)/);
|
|
|
|
}
|
|
|
|
_.reduce(_.tail(speechArr), function(base, word) {
|
|
|
|
if (context.measureText(base + word).width > speechLength) {
|
|
|
|
lineNums += 1;
|
|
|
|
if (word === ' ') {
|
|
|
|
return '';
|
|
|
|
} else if (word === '-') {
|
|
|
|
return _.head(base.split(/\s|-/).reverse()) + word;
|
2016-06-07 21:42:19 +03:00
|
|
|
} else {
|
2016-07-16 03:15:03 +03:00
|
|
|
return word;
|
2016-06-07 21:42:19 +03:00
|
|
|
}
|
|
|
|
} else {
|
2016-07-16 03:15:03 +03:00
|
|
|
return base + word;
|
2016-06-07 21:42:19 +03:00
|
|
|
}
|
2016-07-16 03:15:03 +03:00
|
|
|
}, _.head(speechArr));
|
|
|
|
if (INFINITE) {
|
|
|
|
height = MESSAGE_HEIGHT_SAME * lineNums;
|
|
|
|
if (sameAs) {
|
|
|
|
marginTop = 0;
|
|
|
|
} else {
|
|
|
|
height += MESSAGE_HEIGHT_FIRST;
|
|
|
|
marginTop = MESSAGE_HEIGHT_FIRST_MARGIN_TOP;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
height = null;
|
|
|
|
marginTop = null;
|
|
|
|
}
|
|
|
|
speech = message.thought.statement.speech;
|
|
|
|
audience = (_.keys(message.thought.audience)).join(" ");
|
|
|
|
mez = rele(Message, _.extend({}, message, {
|
|
|
|
station: station,
|
|
|
|
sameAs: sameAs,
|
|
|
|
_handlePm: this._handlePm,
|
|
|
|
_handleAudi: this._handleAudi,
|
|
|
|
height: height,
|
|
|
|
marginTop: marginTop,
|
|
|
|
index: message.key,
|
|
|
|
key: "message-" + message.key,
|
|
|
|
ship: (speech != null ? speech.app : void 0) ? "system" : message.ship,
|
|
|
|
glyph: this.state.glyph[audience] || this.props['default-glyph'],
|
|
|
|
unseen: lastIndex && lastIndex === index
|
|
|
|
}));
|
|
|
|
mez.computedHeight = height + marginTop;
|
|
|
|
if (sameAs) {
|
|
|
|
_messageGroups[0].push(mez);
|
|
|
|
} else {
|
|
|
|
_messageGroups.unshift([mez]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.props.chrono !== "reverse") {
|
|
|
|
_messageGroups = _messageGroups.reverse();
|
|
|
|
}
|
|
|
|
_messages = _.flatten(_messageGroups);
|
2016-06-05 21:19:47 +03:00
|
|
|
if ((this.props.readOnly == null) && INFINITE) {
|
2016-07-06 00:45:48 +03:00
|
|
|
body = rele(Infinite, {
|
2016-03-09 03:20:49 +03:00
|
|
|
useWindowAsScrollContainer: true,
|
|
|
|
containerHeight: window.innerHeight,
|
2016-07-16 03:15:03 +03:00
|
|
|
elementHeight: _.map(_messages, 'computedHeight'),
|
2016-03-09 03:20:49 +03:00
|
|
|
key: "messages-infinite"
|
|
|
|
}, _messages);
|
|
|
|
} else {
|
|
|
|
body = _messages;
|
|
|
|
}
|
2016-07-06 00:45:48 +03:00
|
|
|
fetching = this.state.fetching ? rele(Load, {}) : void 0;
|
2016-01-30 05:18:51 +03:00
|
|
|
return div({
|
2016-01-27 21:53:37 +03:00
|
|
|
className: "grams",
|
|
|
|
key: "messages"
|
2016-07-06 00:45:48 +03:00
|
|
|
}, body, fetching);
|
2015-01-27 01:47:18 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-07-06 00:45:48 +03:00
|
|
|
},{"../actions/MessageActions.coffee":1,"../actions/StationActions.coffee":2,"../stores/MessageStore.coffee":13,"../stores/StationStore.coffee":14,"../util.coffee":15,"./LoadComponent.coffee":3,"./MessageComponent.coffee":5}],7:[function(require,module,exports){
|
2016-06-05 21:19:47 +03:00
|
|
|
var Load, Member, MessageStore, StationActions, StationStore, a, clas, div, h1, h2, input, label, recl, ref, rele, span, style, util,
|
2016-01-27 21:53:37 +03:00
|
|
|
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
util = require('../util.coffee');
|
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
clas = require('classnames');
|
|
|
|
|
2015-01-27 01:47:18 +03:00
|
|
|
recl = React.createClass;
|
|
|
|
|
2016-01-27 21:53:37 +03:00
|
|
|
rele = React.createElement;
|
|
|
|
|
2016-02-02 03:00:45 +03:00
|
|
|
ref = React.DOM, div = ref.div, style = ref.style, input = ref.input, h1 = ref.h1, h2 = ref.h2, label = ref.label, span = ref.span, a = ref.a;
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2016-01-27 21:53:37 +03:00
|
|
|
MessageStore = require('../stores/MessageStore.coffee');
|
|
|
|
|
2015-01-27 01:47:18 +03:00
|
|
|
StationStore = require('../stores/StationStore.coffee');
|
|
|
|
|
|
|
|
StationActions = require('../actions/StationActions.coffee');
|
|
|
|
|
|
|
|
Member = require('./MemberComponent.coffee');
|
|
|
|
|
2016-01-27 21:53:37 +03:00
|
|
|
Load = require('./LoadComponent.coffee');
|
|
|
|
|
2015-01-27 01:47:18 +03:00
|
|
|
module.exports = recl({
|
2015-11-03 21:55:08 +03:00
|
|
|
displayName: "Station",
|
2015-01-27 01:47:18 +03:00
|
|
|
stateFromStore: function() {
|
2016-02-03 02:25:15 +03:00
|
|
|
var ref1;
|
2015-01-27 01:47:18 +03:00
|
|
|
return {
|
2015-01-27 08:16:26 +03:00
|
|
|
audi: StationStore.getAudience(),
|
2015-01-27 01:47:18 +03:00
|
|
|
members: StationStore.getMembers(),
|
2016-06-05 21:19:47 +03:00
|
|
|
station: util.mainStation(),
|
2015-01-27 01:47:18 +03:00
|
|
|
stations: StationStore.getStations(),
|
|
|
|
configs: StationStore.getConfigs(),
|
2016-01-27 21:53:37 +03:00
|
|
|
fetching: MessageStore.getFetching(),
|
2015-01-27 01:47:18 +03:00
|
|
|
typing: StationStore.getTyping(),
|
2016-02-03 02:25:15 +03:00
|
|
|
listening: StationStore.getListening(),
|
|
|
|
open: (((ref1 = this.state) != null ? ref1.open : void 0) ? this.state.open : null)
|
2015-01-27 01:47:18 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
getInitialState: function() {
|
|
|
|
return this.stateFromStore();
|
|
|
|
},
|
|
|
|
componentDidMount: function() {
|
2016-01-30 05:18:51 +03:00
|
|
|
this.$el = $(ReactDOM.findDOMNode());
|
2015-01-27 01:47:18 +03:00
|
|
|
StationStore.addChangeListener(this._onChangeStore);
|
|
|
|
if (this.state.listening.indexOf(this.state.station) === -1) {
|
|
|
|
return StationActions.listenStation(this.state.station);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
return StationStore.removeChangeListener(this._onChangeStore);
|
|
|
|
},
|
|
|
|
_onChangeStore: function() {
|
|
|
|
return this.setState(this.stateFromStore());
|
|
|
|
},
|
2016-02-03 02:25:15 +03:00
|
|
|
componentWillReceiveProps: function(nextProps) {
|
|
|
|
if (this.props.open === true && nextProps.open === false) {
|
|
|
|
return this.setState({
|
|
|
|
open: null
|
|
|
|
});
|
2015-03-27 03:44:39 +03:00
|
|
|
}
|
2015-03-27 01:31:07 +03:00
|
|
|
},
|
2015-05-17 23:27:59 +03:00
|
|
|
validateSource: function(s) {
|
2016-01-27 21:53:37 +03:00
|
|
|
var sources;
|
|
|
|
sources = this.state.configs[this.state.station].sources;
|
|
|
|
return indexOf.call(sources, s) < 0 && indexOf.call(s, "/") >= 0 && s[0] === "~" && s.length >= 5;
|
2015-05-17 23:27:59 +03:00
|
|
|
},
|
2016-01-27 21:53:37 +03:00
|
|
|
onKeyUp: function(e) {
|
2016-02-02 03:00:45 +03:00
|
|
|
var $input, _sources, v;
|
|
|
|
$('.menu.depth-1 .add').removeClass('valid-false');
|
2015-01-27 01:47:18 +03:00
|
|
|
if (e.keyCode === 13) {
|
2016-02-02 03:00:45 +03:00
|
|
|
$input = $(e.target);
|
|
|
|
v = $input.val().toLowerCase();
|
2015-05-17 23:27:59 +03:00
|
|
|
if (v[0] !== "~") {
|
|
|
|
v = "~" + v;
|
|
|
|
}
|
|
|
|
if (this.validateSource(v)) {
|
2015-01-27 08:16:26 +03:00
|
|
|
_sources = _.clone(this.state.configs[this.state.station].sources);
|
|
|
|
_sources.push(v);
|
2015-01-27 01:47:18 +03:00
|
|
|
StationActions.setSources(this.state.station, _sources);
|
2016-02-02 03:00:45 +03:00
|
|
|
$input.val('');
|
|
|
|
return $input.blur();
|
2015-05-17 23:27:59 +03:00
|
|
|
} else {
|
2016-02-02 03:00:45 +03:00
|
|
|
return $('.menu.depth-1 .add').addClass('valid-false');
|
2015-01-27 01:47:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2016-02-03 02:25:15 +03:00
|
|
|
_openStation: function(e) {
|
|
|
|
var $t;
|
|
|
|
$t = $(e.target);
|
|
|
|
return this.setState({
|
|
|
|
open: $t.attr('data-station')
|
|
|
|
});
|
|
|
|
},
|
|
|
|
_closeStation: function() {
|
|
|
|
return this.setState({
|
|
|
|
open: null
|
|
|
|
});
|
|
|
|
},
|
2015-01-27 01:47:18 +03:00
|
|
|
_remove: function(e) {
|
|
|
|
var _sources, _station;
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
_station = $(e.target).attr("data-station");
|
2015-01-27 08:16:26 +03:00
|
|
|
_sources = _.clone(this.state.configs[this.state.station].sources);
|
2015-03-26 00:05:46 +03:00
|
|
|
_sources.splice(_sources.indexOf(_station), 1);
|
2015-01-27 08:16:26 +03:00
|
|
|
return StationActions.setSources(this.state.station, _sources);
|
2015-01-27 01:47:18 +03:00
|
|
|
},
|
|
|
|
render: function() {
|
2016-03-04 02:18:16 +03:00
|
|
|
var _clas, member, members, parts, source, sources, sourcesSum, station;
|
2015-01-27 01:47:18 +03:00
|
|
|
parts = [];
|
|
|
|
members = [];
|
2016-02-03 02:25:15 +03:00
|
|
|
if (this.state.station && this.state.configs[this.state.station]) {
|
|
|
|
members = (function() {
|
|
|
|
var ref1, results;
|
|
|
|
ref1 = this.state.members;
|
|
|
|
results = [];
|
|
|
|
for (station in ref1) {
|
|
|
|
members = ref1[station];
|
|
|
|
_clas = clas({
|
|
|
|
open: this.state.open === station,
|
|
|
|
closed: !(this.state.open === station),
|
|
|
|
menu: true,
|
|
|
|
'depth-2': true
|
|
|
|
});
|
|
|
|
results.push(div({
|
|
|
|
className: _clas,
|
2016-03-04 02:18:16 +03:00
|
|
|
"data-members": station,
|
|
|
|
key: station
|
|
|
|
}, div({
|
|
|
|
className: "contents",
|
|
|
|
onClick: this._closeStation
|
|
|
|
}, div({
|
|
|
|
className: "close"
|
2016-06-05 21:19:47 +03:00
|
|
|
}, "✕"), h2({}, span({}, "Members"), label({
|
2016-03-04 02:18:16 +03:00
|
|
|
className: "sum"
|
2016-06-05 21:19:47 +03:00
|
|
|
}, _.keys(members).length)), (function() {
|
2016-03-04 02:18:16 +03:00
|
|
|
var results1;
|
|
|
|
results1 = [];
|
|
|
|
for (member in members) {
|
|
|
|
results1.push(div({
|
|
|
|
key: member
|
|
|
|
}, div({
|
|
|
|
className: "name"
|
|
|
|
}, ""), div({
|
|
|
|
className: "planet"
|
|
|
|
}, member)));
|
|
|
|
}
|
|
|
|
return results1;
|
|
|
|
})())));
|
2016-02-03 02:25:15 +03:00
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}).call(this);
|
|
|
|
}
|
2016-02-02 03:00:45 +03:00
|
|
|
if (this.state.station && this.state.configs[this.state.station]) {
|
|
|
|
sources = (function() {
|
|
|
|
var i, len, ref1, results;
|
|
|
|
ref1 = this.state.configs[this.state.station].sources;
|
|
|
|
results = [];
|
|
|
|
for (i = 0, len = ref1.length; i < len; i++) {
|
|
|
|
source = ref1[i];
|
|
|
|
results.push(div({
|
2016-03-04 02:18:16 +03:00
|
|
|
key: source,
|
2016-02-02 03:00:45 +03:00
|
|
|
className: "room"
|
2016-03-04 02:18:16 +03:00
|
|
|
}, div({
|
|
|
|
className: (this.state.open === source ? "selected" : ""),
|
|
|
|
onClick: this._openStation,
|
|
|
|
"data-station": source
|
2016-07-27 03:57:59 +03:00
|
|
|
}, source), div({
|
2016-03-04 02:18:16 +03:00
|
|
|
className: "close",
|
|
|
|
onClick: this._remove,
|
|
|
|
"data-station": source
|
|
|
|
}, "✕")));
|
2016-02-02 03:00:45 +03:00
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}).call(this);
|
|
|
|
sources.push(input({
|
2016-03-04 02:18:16 +03:00
|
|
|
key: "placeholder",
|
2016-02-02 03:00:45 +03:00
|
|
|
className: "action add",
|
|
|
|
placeholder: "+ Listen",
|
|
|
|
onKeyUp: this.onKeyUp
|
2016-03-04 02:18:16 +03:00
|
|
|
}));
|
2016-02-02 03:00:45 +03:00
|
|
|
sourcesSum = this.state.configs[this.state.station].sources.length;
|
|
|
|
} else {
|
|
|
|
sources = "";
|
|
|
|
sourcesSum = 0;
|
|
|
|
}
|
2016-01-30 05:18:51 +03:00
|
|
|
_clas = clas({
|
|
|
|
open: this.props.open === true,
|
|
|
|
closed: this.props.open !== true,
|
|
|
|
menu: true,
|
|
|
|
'depth-1': true
|
|
|
|
});
|
2015-01-27 01:47:18 +03:00
|
|
|
return div({
|
2016-02-03 02:25:15 +03:00
|
|
|
key: "station-container"
|
2016-03-04 02:18:16 +03:00
|
|
|
}, div({
|
|
|
|
className: _clas,
|
|
|
|
key: 'station'
|
|
|
|
}, div({
|
|
|
|
className: "contents"
|
|
|
|
}, div({
|
|
|
|
className: "close",
|
|
|
|
onClick: this.props.toggle
|
|
|
|
}, "✕"), h2({}, span({}, "Stations"), label({
|
|
|
|
className: "sum"
|
|
|
|
}, sourcesSum)), div({}, sources))), members);
|
2015-01-27 01:47:18 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
},{"../actions/StationActions.coffee":2,"../stores/MessageStore.coffee":13,"../stores/StationStore.coffee":14,"../util.coffee":15,"./LoadComponent.coffee":3,"./MemberComponent.coffee":4,"classnames":16}],8:[function(require,module,exports){
|
2016-07-16 03:15:03 +03:00
|
|
|
var Audience, Member, MessageActions, MessageStore, PO, SHIPSHAPE, StationActions, StationStore, br, div, husl, input, recl, ref, textToHTML, textarea, util,
|
|
|
|
hasProp = {}.hasOwnProperty;
|
2016-06-05 21:19:47 +03:00
|
|
|
|
|
|
|
util = require('../util.coffee');
|
2015-01-27 01:47:18 +03:00
|
|
|
|
|
|
|
recl = React.createClass;
|
|
|
|
|
2015-09-10 20:27:52 +03:00
|
|
|
ref = React.DOM, div = ref.div, br = ref.br, input = ref.input, textarea = ref.textarea;
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2015-11-03 23:12:32 +03:00
|
|
|
husl = require('husl');
|
|
|
|
|
2015-01-27 01:47:18 +03:00
|
|
|
MessageActions = require('../actions/MessageActions.coffee');
|
|
|
|
|
2015-03-06 06:58:23 +03:00
|
|
|
MessageStore = require('../stores/MessageStore.coffee');
|
|
|
|
|
2015-01-27 01:47:18 +03:00
|
|
|
StationActions = require('../actions/StationActions.coffee');
|
|
|
|
|
|
|
|
StationStore = require('../stores/StationStore.coffee');
|
|
|
|
|
|
|
|
Member = require('./MemberComponent.coffee');
|
|
|
|
|
2015-10-28 02:43:08 +03:00
|
|
|
SHIPSHAPE = /^~?([a-z]{3}|[a-z]{6}(-[a-z]{6}){0,3}|[a-z]{6}(-[a-z]{6}){3}(--[a-z]{6}(-[a-z]{6}){3})+)$/;
|
|
|
|
|
|
|
|
PO = 'dozmarbinwansamlitsighidfidlissogdirwacsabwissib\nrigsoldopmodfoglidhopdardorlorhodfolrintogsilmir\nholpaslacrovlivdalsatlibtabhanticpidtorbolfosdot\nlosdilforpilramtirwintadbicdifrocwidbisdasmidlop\nrilnardapmolsanlocnovsitnidtipsicropwitnatpanmin\nritpodmottamtolsavposnapnopsomfinfonbanporworsip\nronnorbotwicsocwatdolmagpicdavbidbaltimtasmallig\nsivtagpadsaldivdactansidfabtarmonranniswolmispal\nlasdismaprabtobrollatlonnodnavfignomnibpagsopral\nbilhaddocridmocpacravripfaltodtiltinhapmicfanpat\ntaclabmogsimsonpinlomrictapfirhasbosbatpochactid\nhavsaplindibhosdabbitbarracparloddosbortochilmac\ntomdigfilfasmithobharmighinradmashalraglagfadtop\nmophabnilnosmilfopfamdatnoldinhatnacrisfotribhoc\nnimlarfitwalrapsarnalmoslandondanladdovrivbacpol\nlaptalpitnambonrostonfodponsovnocsorlavmatmipfap\n\nzodnecbudwessevpersutletfulpensytdurwepserwylsun\nrypsyxdyrnuphebpeglupdepdysputlughecryttyvsydnex\nlunmeplutseppesdelsulpedtemledtulmetwenbynhexfeb\npyldulhetmevruttylwydtepbesdexsefwycburderneppur\nrysrebdennutsubpetrulsynregtydsupsemwynrecmegnet\nsecmulnymtevwebsummutnyxrextebfushepbenmuswyxsym\nselrucdecwexsyrwetdylmynmesdetbetbeltuxtugmyrpel\nsyptermebsetdutdegtexsurfeltudnuxruxrenwytnubmed\nlytdusnebrumtynseglyxpunresredfunrevrefmectedrus\nbexlebduxrynnumpyxrygryxfeptyrtustyclegnemfermer\ntenlusnussyltecmexpubrymtucfyllepdebbermughuttun\nbylsudpemdevlurdefbusbeprunmelpexdytbyttyplevmyl\nwedducfurfexnulluclennerlexrupnedlecrydlydfenwel\nnydhusrelrudneshesfetdesretdunlernyrsebhulryllud\nremlysfynwerrycsugnysnyllyndyndemluxfedsedbecmun\nlyrtesmudnytbyrsenwegfyrmurtelreptegpecnelnevfes';
|
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
textToHTML = function(txt) {
|
|
|
|
return {
|
|
|
|
__html: $('<div>').text(txt).html()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-10-28 02:43:08 +03:00
|
|
|
Audience = recl({
|
|
|
|
displayName: "Audience",
|
|
|
|
onKeyDown: function(e) {
|
|
|
|
if (e.keyCode === 13) {
|
|
|
|
e.preventDefault();
|
2016-02-03 02:25:15 +03:00
|
|
|
if (this.props.validate()) {
|
|
|
|
setTimeout((function() {
|
2016-02-07 03:42:31 +03:00
|
|
|
return $('.writing').focus();
|
2016-02-03 02:25:15 +03:00
|
|
|
}), 0);
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-28 02:43:08 +03:00
|
|
|
}
|
2016-07-27 03:57:59 +03:00
|
|
|
if (e.keyCode === 9) {
|
|
|
|
e.preventDefault();
|
|
|
|
this._autoCompleteAudience();
|
|
|
|
return false;
|
|
|
|
} else if ((this.tabAudList != null) && e.keyCode !== 16) {
|
|
|
|
this.tabAudList = null;
|
|
|
|
return this.tabAudIndex = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_autoCompleteAudience: function() {
|
|
|
|
var aud, g, i, j, len, len1, ref1, ref2, s, stations, txt;
|
|
|
|
txt = $('#audience .input').text().trim();
|
|
|
|
if (this.tabAudList == null) {
|
|
|
|
this.tabAudList = [];
|
|
|
|
if (txt.length === 1 && StationStore.getGlyphs()[txt[0]]) {
|
|
|
|
ref1 = this._getGlyphExpansions(txt[0]);
|
|
|
|
for (i = 0, len = ref1.length; i < len; i++) {
|
|
|
|
s = ref1[i];
|
|
|
|
this.tabAudList.push(s[0]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(txt[0] === '~')) {
|
|
|
|
txt = '~' + txt;
|
|
|
|
}
|
|
|
|
ref2 = StationStore.getGlyphs();
|
|
|
|
for (g in ref2) {
|
|
|
|
stations = ref2[g];
|
|
|
|
for (j = 0, len1 = stations.length; j < len1; j++) {
|
|
|
|
aud = stations[j];
|
|
|
|
if (aud[0].indexOf(txt) === 0 && this.tabAudList.indexOf(aud[0]) < 0) {
|
|
|
|
this.tabAudList.push(aud[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((this.tabAudList != null) && this.tabAudList.length > 0) {
|
|
|
|
if (this.tabAudIndex != null) {
|
|
|
|
if (event.shiftKey) {
|
|
|
|
this.tabAudIndex--;
|
|
|
|
} else {
|
|
|
|
this.tabAudIndex++;
|
|
|
|
}
|
|
|
|
this.tabAudIndex = (this.tabAudIndex % this.tabAudList.length + this.tabAudList.length) % this.tabAudList.length;
|
|
|
|
} else {
|
|
|
|
this.tabAudIndex = 0;
|
|
|
|
}
|
|
|
|
return StationActions.setAudience(this.tabAudList[this.tabAudIndex].split(/\ +/));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_getGlyphExpansions: function(g) {
|
|
|
|
var glyphs;
|
|
|
|
glyphs = StationStore.getGlyphs();
|
|
|
|
if (glyphs[g]) {
|
|
|
|
return glyphs[g];
|
|
|
|
}
|
2015-10-28 02:43:08 +03:00
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return div({
|
2016-01-27 21:53:37 +03:00
|
|
|
className: 'audience',
|
2016-02-02 03:00:45 +03:00
|
|
|
id: 'audience',
|
|
|
|
key: 'audience'
|
2016-01-27 21:53:37 +03:00
|
|
|
}, div({
|
|
|
|
className: "input valid-" + this.props.valid,
|
2016-02-02 03:00:45 +03:00
|
|
|
key: 'input',
|
2016-06-05 21:19:47 +03:00
|
|
|
contentEditable: this.props.editable ? true : void 0,
|
2015-10-28 02:43:08 +03:00
|
|
|
onKeyDown: this.onKeyDown,
|
2016-03-04 02:18:16 +03:00
|
|
|
onBlur: this.props.onBlur,
|
|
|
|
dangerouslySetInnerHTML: textToHTML(this.props.audi.join(" "))
|
|
|
|
}));
|
2015-10-28 02:43:08 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-27 01:47:18 +03:00
|
|
|
module.exports = recl({
|
2015-10-28 02:43:08 +03:00
|
|
|
displayName: "Writing",
|
2015-01-27 01:47:18 +03:00
|
|
|
set: function() {
|
2016-01-27 21:53:37 +03:00
|
|
|
if (window.localStorage && this.$message) {
|
|
|
|
return window.localStorage.setItem('writing', this.$message.text());
|
2015-01-27 01:47:18 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
get: function() {
|
|
|
|
if (window.localStorage) {
|
|
|
|
return window.localStorage.getItem('writing');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
stateFromStore: function() {
|
2015-03-26 23:55:26 +03:00
|
|
|
var s;
|
|
|
|
s = {
|
2015-03-06 06:58:23 +03:00
|
|
|
audi: StationStore.getAudience(),
|
2015-03-26 23:55:26 +03:00
|
|
|
ludi: MessageStore.getLastAudience(),
|
2015-05-07 21:47:25 +03:00
|
|
|
config: StationStore.getConfigs(),
|
2015-01-27 01:47:18 +03:00
|
|
|
members: StationStore.getMembers(),
|
2015-03-06 06:58:23 +03:00
|
|
|
typing: StationStore.getTyping(),
|
2016-03-01 04:31:08 +03:00
|
|
|
station: StationStore.getStation(),
|
2015-03-07 22:09:30 +03:00
|
|
|
valid: StationStore.getValidAudience()
|
2015-01-27 01:47:18 +03:00
|
|
|
};
|
2016-06-05 21:19:47 +03:00
|
|
|
s.audi = _.without(s.audi, util.mainStationPath(window.urb.user));
|
|
|
|
s.ludi = _.without(s.ludi, util.mainStationPath(window.urb.user));
|
2015-03-26 23:55:26 +03:00
|
|
|
return s;
|
2015-01-27 01:47:18 +03:00
|
|
|
},
|
|
|
|
getInitialState: function() {
|
2015-10-28 02:43:08 +03:00
|
|
|
return _.extend(this.stateFromStore(), {
|
|
|
|
length: 0,
|
|
|
|
lengthy: false
|
|
|
|
});
|
2015-01-27 01:47:18 +03:00
|
|
|
},
|
|
|
|
typing: function(state) {
|
|
|
|
if (this.state.typing[this.state.station] !== state) {
|
|
|
|
return StationActions.setTyping(this.state.station, state);
|
|
|
|
}
|
|
|
|
},
|
2015-10-28 02:43:08 +03:00
|
|
|
onBlur: function() {
|
2016-01-27 21:53:37 +03:00
|
|
|
this.$message.text(this.$message.text());
|
2015-01-27 08:16:26 +03:00
|
|
|
MessageActions.setTyping(false);
|
2015-01-27 01:47:18 +03:00
|
|
|
return this.typing(false);
|
|
|
|
},
|
2015-10-28 02:43:08 +03:00
|
|
|
onFocus: function() {
|
2015-01-27 08:16:26 +03:00
|
|
|
MessageActions.setTyping(true);
|
2015-10-28 02:43:08 +03:00
|
|
|
this.typing(true);
|
|
|
|
return this.cursorAtEnd;
|
2015-01-27 08:16:26 +03:00
|
|
|
},
|
2015-05-07 21:47:25 +03:00
|
|
|
addCC: function(audi) {
|
2016-03-01 04:31:08 +03:00
|
|
|
var listening, ref1, ref2;
|
2016-06-05 21:19:47 +03:00
|
|
|
if (urb.user !== urb.ship) {
|
|
|
|
return audi;
|
|
|
|
}
|
2016-03-01 04:31:08 +03:00
|
|
|
listening = (ref1 = (ref2 = this.state.config[this.props.station]) != null ? ref2.sources : void 0) != null ? ref1 : [];
|
|
|
|
if (_.isEmpty(_.intersection(audi, listening))) {
|
|
|
|
audi.push("~" + window.urb.user + "/" + this.props.station);
|
2015-05-07 21:47:25 +03:00
|
|
|
}
|
|
|
|
return audi;
|
|
|
|
},
|
2015-01-27 01:47:18 +03:00
|
|
|
sendMessage: function() {
|
2015-10-28 02:43:08 +03:00
|
|
|
var audi, txt;
|
2015-03-07 22:09:30 +03:00
|
|
|
if (this._validateAudi() === false) {
|
2016-02-03 02:25:15 +03:00
|
|
|
setTimeout((function() {
|
|
|
|
return $('#audience .input').focus();
|
|
|
|
}), 0);
|
2015-03-07 22:09:30 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-07-06 00:45:48 +03:00
|
|
|
if (!(this.state.audi.length === 0 && $('#audience').text().trim().length > 0)) {
|
2015-03-07 22:09:30 +03:00
|
|
|
audi = this.state.audi;
|
2016-07-06 00:45:48 +03:00
|
|
|
} else {
|
|
|
|
audi = this._setAudi() || this.state.ludi;
|
|
|
|
}
|
2016-07-16 03:15:03 +03:00
|
|
|
if (_.isEmpty(audi)) {
|
|
|
|
console.warn("No audience");
|
|
|
|
return;
|
|
|
|
}
|
2016-07-06 00:45:48 +03:00
|
|
|
if (this.props['audience-lock'] != null) {
|
|
|
|
audi = _.union(audi, ["~" + window.urb.ship + "/" + this.props.station]);
|
2015-03-07 22:09:30 +03:00
|
|
|
}
|
2015-05-07 21:47:25 +03:00
|
|
|
audi = this.addCC(audi);
|
2016-01-27 21:53:37 +03:00
|
|
|
txt = this.$message.text().trim().replace(/\xa0/g, ' ');
|
2015-10-28 02:43:08 +03:00
|
|
|
MessageActions.sendMessage(txt, audi);
|
2016-01-27 21:53:37 +03:00
|
|
|
this.$message.text('');
|
2015-10-28 02:43:08 +03:00
|
|
|
this.setState({
|
|
|
|
length: 0
|
|
|
|
});
|
2015-01-27 01:47:18 +03:00
|
|
|
this.set();
|
|
|
|
return this.typing(false);
|
|
|
|
},
|
2015-10-28 02:43:08 +03:00
|
|
|
onKeyUp: function(e) {
|
2016-01-27 21:53:37 +03:00
|
|
|
if (!window.urb.util.isURL(this.$message.text())) {
|
2015-10-28 02:43:08 +03:00
|
|
|
return this.setState({
|
2016-01-27 21:53:37 +03:00
|
|
|
lengthy: this.$message.text().length > 62
|
2015-10-28 02:43:08 +03:00
|
|
|
});
|
2015-04-11 00:43:44 +03:00
|
|
|
}
|
2015-04-08 00:02:40 +03:00
|
|
|
},
|
2015-10-28 02:43:08 +03:00
|
|
|
onKeyDown: function(e) {
|
2015-04-08 00:02:40 +03:00
|
|
|
var txt;
|
2015-01-27 01:47:18 +03:00
|
|
|
if (e.keyCode === 13) {
|
2016-01-27 21:53:37 +03:00
|
|
|
txt = this.$message.text();
|
2015-01-27 01:47:18 +03:00
|
|
|
e.preventDefault();
|
2015-10-28 02:43:08 +03:00
|
|
|
if (txt.length > 0) {
|
2015-11-03 23:12:32 +03:00
|
|
|
if (window.talk.online) {
|
|
|
|
this.sendMessage();
|
|
|
|
} else {
|
2015-11-03 23:55:28 +03:00
|
|
|
$('#offline').addClass('error').one('transitionend', function() {
|
|
|
|
return $('#offline').removeClass('error');
|
2015-11-03 23:12:32 +03:00
|
|
|
});
|
|
|
|
}
|
2015-04-08 00:02:40 +03:00
|
|
|
}
|
2015-01-27 01:47:18 +03:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-16 03:15:03 +03:00
|
|
|
if (e.keyCode === 9) {
|
|
|
|
e.preventDefault();
|
|
|
|
this._autoComplete();
|
|
|
|
return false;
|
|
|
|
} else if ((this.tabList != null) && e.keyCode !== 16) {
|
|
|
|
this.tabList = null;
|
|
|
|
this.tabIndex = null;
|
|
|
|
}
|
2015-10-28 02:43:08 +03:00
|
|
|
this.onInput();
|
2015-01-27 01:47:18 +03:00
|
|
|
return this.set();
|
|
|
|
},
|
2016-07-16 03:15:03 +03:00
|
|
|
_autoComplete: function() {
|
|
|
|
var i, msg, name, obj, ptxt, ref1, ref2, tindex, txt;
|
|
|
|
txt = this.$message.text();
|
|
|
|
tindex = txt.lastIndexOf('~');
|
|
|
|
if (tindex === -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.tabList == null) {
|
|
|
|
ptxt = txt.substr(tindex + 1);
|
|
|
|
if (ptxt.length < 13 && (ptxt.match('^[a-z]{0,6}([\\-\\^_][a-z]{0,5})?$') != null)) {
|
|
|
|
this.tabList = [];
|
|
|
|
ref1 = MessageStore.getAll();
|
|
|
|
for (i = ref1.length - 1; i >= 0; i += -1) {
|
|
|
|
msg = ref1[i];
|
|
|
|
this._processAutoCompleteName(ptxt, msg.ship);
|
|
|
|
}
|
|
|
|
ref2 = this.state.members[this.state.ludi[0]];
|
|
|
|
for (name in ref2) {
|
|
|
|
if (!hasProp.call(ref2, name)) continue;
|
|
|
|
obj = ref2[name];
|
|
|
|
this._processAutoCompleteName(ptxt, name.substr(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((this.tabList != null) && this.tabList.length > 0) {
|
|
|
|
if (this.tabIndex != null) {
|
|
|
|
if (event.shiftKey) {
|
|
|
|
this.tabIndex--;
|
|
|
|
} else {
|
|
|
|
this.tabIndex++;
|
|
|
|
}
|
|
|
|
this.tabIndex = (this.tabIndex % this.tabList.length + this.tabList.length) % this.tabList.length;
|
|
|
|
} else {
|
|
|
|
this.tabIndex = 0;
|
|
|
|
}
|
|
|
|
name = this.tabList[this.tabIndex];
|
|
|
|
this.$message.text(this.$message.text().substr(0, tindex + 1) + name);
|
|
|
|
return this.cursorAtEnd();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_processAutoCompleteName: function(ptxt, name) {
|
|
|
|
if (name.length === 27) {
|
|
|
|
name = name.substr(-13).replace('-', '^');
|
|
|
|
} else if (name.length === 56) {
|
|
|
|
name = name.substr(0, 6) + '_' + name.substr(-6);
|
|
|
|
}
|
|
|
|
if (name.indexOf(ptxt) === 0 && this.tabList.indexOf(name) === -1) {
|
|
|
|
return this.tabList.push(name);
|
|
|
|
}
|
|
|
|
},
|
2015-10-28 02:43:08 +03:00
|
|
|
onInput: function(e) {
|
2015-04-11 00:43:44 +03:00
|
|
|
var length, text;
|
2016-01-27 21:53:37 +03:00
|
|
|
text = this.$message.text();
|
2015-01-27 01:47:18 +03:00
|
|
|
length = text.length;
|
2015-10-28 02:43:08 +03:00
|
|
|
return this.setState({
|
|
|
|
length: length
|
|
|
|
});
|
2015-01-27 01:47:18 +03:00
|
|
|
},
|
2015-03-07 22:09:30 +03:00
|
|
|
_validateAudiPart: function(a) {
|
2015-03-10 21:49:01 +03:00
|
|
|
var _a, ship;
|
2015-10-28 02:43:08 +03:00
|
|
|
a = a.trim();
|
2015-03-10 21:49:01 +03:00
|
|
|
if (a.indexOf("/") !== -1) {
|
|
|
|
_a = a.split("/");
|
|
|
|
if (_a[1].length === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ship = _a[0];
|
|
|
|
} else {
|
|
|
|
ship = a;
|
2015-03-07 22:09:30 +03:00
|
|
|
}
|
2015-10-28 02:43:08 +03:00
|
|
|
return (SHIPSHAPE.test(ship)) && _.all(ship.match(/[a-z]{3}/g), function(a) {
|
|
|
|
return -1 !== PO.indexOf(a);
|
|
|
|
});
|
2015-03-06 06:58:23 +03:00
|
|
|
},
|
2015-03-07 22:09:30 +03:00
|
|
|
_validateAudi: function() {
|
2015-10-28 02:43:08 +03:00
|
|
|
var v;
|
2016-02-03 02:25:15 +03:00
|
|
|
v = $('#audience .input').text();
|
2015-03-26 23:55:26 +03:00
|
|
|
v = v.trim();
|
|
|
|
if (v.length === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-17 23:27:59 +03:00
|
|
|
if (v.length < 5) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-28 02:43:08 +03:00
|
|
|
return _.all(v.split(/\ +/), this._validateAudiPart);
|
2015-03-07 22:09:30 +03:00
|
|
|
},
|
|
|
|
_setAudi: function() {
|
2015-10-28 02:43:08 +03:00
|
|
|
var stan, valid;
|
2015-03-10 01:45:34 +03:00
|
|
|
valid = this._validateAudi();
|
2015-03-07 22:09:30 +03:00
|
|
|
StationActions.setValidAudience(valid);
|
|
|
|
if (valid === true) {
|
2016-06-05 21:19:47 +03:00
|
|
|
stan = $('#audience .input').text() || util.mainStationPath(window.urb.user);
|
2015-10-28 02:43:08 +03:00
|
|
|
stan = (stan.split(/\ +/)).map(function(v) {
|
|
|
|
if (v[0] === "~") {
|
|
|
|
return v;
|
|
|
|
} else {
|
|
|
|
return "~" + v;
|
2015-05-07 22:16:48 +03:00
|
|
|
}
|
2015-10-28 02:43:08 +03:00
|
|
|
});
|
|
|
|
StationActions.setAudience(stan);
|
|
|
|
return stan;
|
2015-05-09 01:56:33 +03:00
|
|
|
} else {
|
|
|
|
return false;
|
2015-03-06 06:58:23 +03:00
|
|
|
}
|
|
|
|
},
|
2015-01-27 01:47:18 +03:00
|
|
|
getTime: function() {
|
|
|
|
var d, seconds;
|
|
|
|
d = new Date();
|
|
|
|
seconds = d.getSeconds();
|
|
|
|
if (seconds < 10) {
|
|
|
|
seconds = "0" + seconds;
|
|
|
|
}
|
|
|
|
return "~" + d.getHours() + "." + d.getMinutes() + "." + seconds;
|
|
|
|
},
|
|
|
|
cursorAtEnd: function() {
|
|
|
|
var range, selection;
|
|
|
|
range = document.createRange();
|
2016-01-27 21:53:37 +03:00
|
|
|
range.selectNodeContents(this.$message[0]);
|
2015-01-27 01:47:18 +03:00
|
|
|
range.collapse(false);
|
|
|
|
selection = window.getSelection();
|
|
|
|
selection.removeAllRanges();
|
|
|
|
return selection.addRange(range);
|
|
|
|
},
|
|
|
|
componentDidMount: function() {
|
2016-06-05 21:19:47 +03:00
|
|
|
util.sendMessage = this.sendMessage;
|
2015-01-27 01:47:18 +03:00
|
|
|
StationStore.addChangeListener(this._onChangeStore);
|
2015-03-06 06:58:23 +03:00
|
|
|
MessageStore.addChangeListener(this._onChangeStore);
|
2016-01-27 21:53:37 +03:00
|
|
|
this.$el = $(ReactDOM.findDOMNode(this));
|
|
|
|
this.$message = $('#message .input');
|
|
|
|
this.$message.focus();
|
2015-01-27 01:47:18 +03:00
|
|
|
if (this.get()) {
|
2016-01-27 21:53:37 +03:00
|
|
|
this.$message.text(this.get());
|
2015-10-28 02:43:08 +03:00
|
|
|
this.onInput();
|
2015-01-27 01:47:18 +03:00
|
|
|
}
|
|
|
|
return this.interval = setInterval((function(_this) {
|
|
|
|
return function() {
|
|
|
|
return _this.$el.find('.time').text(_this.getTime());
|
|
|
|
};
|
|
|
|
})(this), 1000);
|
|
|
|
},
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
StationStore.removeChangeListener(this._onChangeStore);
|
|
|
|
return clearInterval(this.interval);
|
|
|
|
},
|
|
|
|
_onChangeStore: function() {
|
|
|
|
return this.setState(this.stateFromStore());
|
|
|
|
},
|
|
|
|
render: function() {
|
2015-05-07 21:47:25 +03:00
|
|
|
var audi, iden, k, name, ship, user, v;
|
2015-01-27 01:47:18 +03:00
|
|
|
user = "~" + window.urb.user;
|
|
|
|
iden = StationStore.getMember(user);
|
|
|
|
ship = iden ? iden.ship : user;
|
|
|
|
name = iden ? iden.name : "";
|
2015-03-07 22:09:30 +03:00
|
|
|
audi = this.state.audi.length === 0 ? this.state.ludi : this.state.audi;
|
2016-06-05 21:19:47 +03:00
|
|
|
audi = util.clipAudi(audi);
|
2015-05-07 21:47:25 +03:00
|
|
|
for (k in audi) {
|
|
|
|
v = audi[k];
|
2016-07-27 03:57:59 +03:00
|
|
|
if (audi[k].indexOf('~~') === 0) {
|
|
|
|
audi[k] = v.slice(1);
|
|
|
|
}
|
2015-05-07 21:47:25 +03:00
|
|
|
}
|
2015-01-27 01:47:18 +03:00
|
|
|
return div({
|
2016-02-02 03:00:45 +03:00
|
|
|
className: 'writing',
|
|
|
|
key: 'writing'
|
2016-03-04 02:18:16 +03:00
|
|
|
}, React.createElement(Audience, {
|
|
|
|
audi: audi,
|
|
|
|
valid: this.state.valid,
|
|
|
|
validate: this._validateAudi,
|
2016-06-05 21:19:47 +03:00
|
|
|
editable: this.props['audience-lock'] == null,
|
2016-03-04 02:18:16 +03:00
|
|
|
onBlur: this._setAudi
|
|
|
|
}), div({
|
|
|
|
className: 'message',
|
|
|
|
id: 'message',
|
|
|
|
key: 'message'
|
|
|
|
}, div({
|
|
|
|
className: 'input',
|
|
|
|
contentEditable: true,
|
|
|
|
onPaste: this.onInput,
|
|
|
|
onInput: this.onInput,
|
|
|
|
onFocus: this.onFocus,
|
|
|
|
onBlur: this.onBlur,
|
|
|
|
onKeyDown: this.onKeyDown,
|
|
|
|
onKeyUp: this.onKeyUp,
|
|
|
|
dangerouslySetInnerHTML: {
|
|
|
|
__html: ""
|
|
|
|
}
|
|
|
|
})), div({
|
|
|
|
className: 'length',
|
|
|
|
key: 'length'
|
|
|
|
}, this.state.length + "/64 (" + (Math.ceil(this.state.length / 64)) + ")"));
|
2015-01-27 01:47:18 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
},{"../actions/MessageActions.coffee":1,"../actions/StationActions.coffee":2,"../stores/MessageStore.coffee":13,"../stores/StationStore.coffee":14,"../util.coffee":15,"./MemberComponent.coffee":4,"husl":17}],9:[function(require,module,exports){
|
2016-01-27 21:53:37 +03:00
|
|
|
module.exports = _.extend(new Flux.Dispatcher(), {
|
2015-01-27 01:47:18 +03:00
|
|
|
handleServerAction: function(action) {
|
|
|
|
return this.dispatch({
|
|
|
|
source: 'server',
|
|
|
|
action: action
|
|
|
|
});
|
|
|
|
},
|
|
|
|
handleViewAction: function(action) {
|
|
|
|
return this.dispatch({
|
|
|
|
source: 'view',
|
|
|
|
action: action
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2016-01-27 21:53:37 +03:00
|
|
|
},{}],10:[function(require,module,exports){
|
2016-06-05 21:19:47 +03:00
|
|
|
var MessageListComponent, StationActions, StationComponent, TreeActions, WritingComponent, div, link, ref, util;
|
|
|
|
|
|
|
|
util = require('./util.coffee');
|
|
|
|
|
|
|
|
_.merge(window, {
|
|
|
|
util: util,
|
|
|
|
talk: {
|
|
|
|
online: true
|
|
|
|
}
|
|
|
|
});
|
2015-06-19 04:47:41 +03:00
|
|
|
|
2016-01-27 21:53:37 +03:00
|
|
|
StationActions = require('./actions/StationActions.coffee');
|
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
TreeActions = window.tree.actions;
|
|
|
|
|
2016-01-27 21:53:37 +03:00
|
|
|
setInterval((function() {
|
|
|
|
window.talk.online = window.urb.poll.dely < 500;
|
|
|
|
if (window.talk.online) {
|
|
|
|
return $('body').removeClass('offline');
|
|
|
|
} else {
|
|
|
|
return $('body').addClass('offline');
|
|
|
|
}
|
|
|
|
}), 300);
|
|
|
|
|
2016-02-03 02:25:15 +03:00
|
|
|
StationComponent = require('./components/StationComponent.coffee');
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
MessageListComponent = React.createFactory(require('./components/MessageListComponent.coffee'));
|
2016-01-27 21:53:37 +03:00
|
|
|
|
|
|
|
WritingComponent = React.createFactory(require('./components/WritingComponent.coffee'));
|
|
|
|
|
|
|
|
ref = React.DOM, div = ref.div, link = ref.link;
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
TreeActions.registerComponent("talk", React.createClass({
|
2016-01-27 21:53:37 +03:00
|
|
|
displayName: "talk",
|
2016-03-01 04:31:08 +03:00
|
|
|
getStation: function() {
|
2016-06-05 21:19:47 +03:00
|
|
|
return this.props.station || util.defaultStation();
|
2016-03-01 04:31:08 +03:00
|
|
|
},
|
2016-01-27 21:53:37 +03:00
|
|
|
componentWillMount: function() {
|
2016-03-01 04:31:08 +03:00
|
|
|
var station;
|
2016-03-09 03:20:49 +03:00
|
|
|
if (!this.props.readonly) {
|
2016-06-05 21:19:47 +03:00
|
|
|
$(window).on('scroll', util.checkScroll);
|
2016-03-09 03:20:49 +03:00
|
|
|
}
|
2016-03-01 04:31:08 +03:00
|
|
|
station = this.getStation();
|
2016-01-27 21:53:37 +03:00
|
|
|
StationActions.listen();
|
2016-03-01 04:31:08 +03:00
|
|
|
return StationActions.switchStation(station);
|
2016-01-27 21:53:37 +03:00
|
|
|
},
|
|
|
|
render: function() {
|
2016-06-05 21:19:47 +03:00
|
|
|
var children, station;
|
2016-03-01 04:31:08 +03:00
|
|
|
station = this.getStation();
|
2016-06-05 21:19:47 +03:00
|
|
|
children = [
|
2016-01-27 21:53:37 +03:00
|
|
|
div({
|
|
|
|
key: "grams-container"
|
2016-06-05 21:19:47 +03:00
|
|
|
}, MessageListComponent(_.merge({}, this.props, {
|
2016-03-01 04:31:08 +03:00
|
|
|
station: station,
|
2016-01-27 21:53:37 +03:00
|
|
|
key: 'grams'
|
2016-03-01 04:31:08 +03:00
|
|
|
}), '')), this.props.readOnly == null ? div({
|
2016-01-27 21:53:37 +03:00
|
|
|
key: 'writing-container'
|
2016-03-01 04:31:08 +03:00
|
|
|
}, WritingComponent(_.merge({}, this.props, {
|
|
|
|
station: station,
|
2016-01-27 21:53:37 +03:00
|
|
|
key: 'writing'
|
2016-03-01 04:31:08 +03:00
|
|
|
}), '')) : void 0
|
2016-06-05 21:19:47 +03:00
|
|
|
];
|
|
|
|
if (this.props.chrono === "reverse") {
|
|
|
|
children = children.reverse();
|
|
|
|
}
|
|
|
|
return div({
|
|
|
|
key: "talk-container"
|
|
|
|
}, children);
|
2016-01-27 21:53:37 +03:00
|
|
|
}
|
2016-01-30 05:18:51 +03:00
|
|
|
}));
|
2015-04-28 22:00:46 +03:00
|
|
|
|
2016-02-03 02:25:15 +03:00
|
|
|
TreeActions.registerComponent("talk-station", StationComponent);
|
|
|
|
|
2015-04-28 22:00:46 +03:00
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
},{"./actions/StationActions.coffee":2,"./components/MessageListComponent.coffee":6,"./components/StationComponent.coffee":7,"./components/WritingComponent.coffee":8,"./util.coffee":15}],11:[function(require,module,exports){
|
2016-07-16 03:15:03 +03:00
|
|
|
var send, util;
|
|
|
|
|
|
|
|
util = require('../util.coffee');
|
2015-04-28 22:00:46 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
window.urb.appl = "talk";
|
2015-04-28 22:00:46 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
send = function(data, cb) {
|
|
|
|
return window.urb.send(data, {
|
|
|
|
mark: "talk-command"
|
|
|
|
}, cb);
|
2015-04-28 22:00:46 +03:00
|
|
|
};
|
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
module.exports = function(arg) {
|
|
|
|
var MessageActions;
|
|
|
|
MessageActions = arg.MessageActions;
|
|
|
|
return {
|
|
|
|
listenStation: function(station, since) {
|
2016-07-16 03:15:03 +03:00
|
|
|
var $this, path;
|
2016-01-30 05:18:51 +03:00
|
|
|
console.log('listen station');
|
|
|
|
console.log(arguments);
|
|
|
|
$this = this;
|
2016-07-16 03:15:03 +03:00
|
|
|
path = util.talkPath({
|
|
|
|
'f_grams': 'f_grams'
|
|
|
|
}, station, since);
|
|
|
|
return window.urb.bind(path, function(err, res) {
|
2016-01-30 05:18:51 +03:00
|
|
|
var num, ref, ref1, ref2, ref3, tele;
|
|
|
|
if (err || !res.data) {
|
2016-07-16 03:15:03 +03:00
|
|
|
console.log(path, 'err!');
|
2016-01-30 05:18:51 +03:00
|
|
|
console.log(err);
|
|
|
|
console.log(res);
|
|
|
|
$this.listenStation(station, since);
|
|
|
|
return;
|
|
|
|
}
|
2016-07-16 03:15:03 +03:00
|
|
|
console.log(path);
|
2016-01-30 05:18:51 +03:00
|
|
|
console.log(res.data);
|
|
|
|
if (res.data.ok === true) {
|
|
|
|
MessageActions.listeningStation(station);
|
|
|
|
}
|
|
|
|
if ((ref = res.data) != null ? (ref1 = ref.grams) != null ? ref1.tele : void 0 : void 0) {
|
|
|
|
ref3 = (ref2 = res.data) != null ? ref2.grams : void 0, tele = ref3.tele, num = ref3.num;
|
2016-07-20 00:48:14 +03:00
|
|
|
return MessageActions.loadMessages(tele, num);
|
2016-01-30 05:18:51 +03:00
|
|
|
}
|
2015-04-28 22:00:46 +03:00
|
|
|
});
|
2016-01-30 05:18:51 +03:00
|
|
|
},
|
|
|
|
get: function(station, start, end) {
|
2016-07-16 03:15:03 +03:00
|
|
|
var path;
|
2016-01-30 05:18:51 +03:00
|
|
|
end = window.urb.util.numDot(end);
|
|
|
|
start = window.urb.util.numDot(start);
|
2016-07-16 03:15:03 +03:00
|
|
|
path = util.talkPath({
|
|
|
|
'f_grams': 'f_grams'
|
|
|
|
}, station, end, start);
|
|
|
|
return window.urb.bind(path, function(err, res) {
|
2016-01-30 05:18:51 +03:00
|
|
|
var num, ref, ref1, ref2, ref3, tele;
|
|
|
|
if (err || !res.data) {
|
2016-07-16 03:15:03 +03:00
|
|
|
console.log(path, '/e/s err');
|
2016-01-30 05:18:51 +03:00
|
|
|
console.log(err);
|
|
|
|
return;
|
2015-04-28 22:00:46 +03:00
|
|
|
}
|
2016-07-16 03:15:03 +03:00
|
|
|
console.log(path, '/e/s');
|
2016-01-30 05:18:51 +03:00
|
|
|
console.log(res);
|
|
|
|
if ((ref = res.data) != null ? (ref1 = ref.grams) != null ? ref1.tele : void 0 : void 0) {
|
|
|
|
ref3 = (ref2 = res.data) != null ? ref2.grams : void 0, tele = ref3.tele, num = ref3.num;
|
|
|
|
MessageActions.loadMessages(tele, num, true);
|
2016-07-16 03:15:03 +03:00
|
|
|
return window.urb.drop(path, function(err, res) {
|
2016-01-30 05:18:51 +03:00
|
|
|
console.log('done');
|
|
|
|
return console.log(res);
|
|
|
|
});
|
2015-04-28 22:00:46 +03:00
|
|
|
}
|
2016-01-30 05:18:51 +03:00
|
|
|
});
|
|
|
|
},
|
2016-06-05 21:19:47 +03:00
|
|
|
sendMessage: function(messageType, message, cb) {
|
|
|
|
var obj;
|
|
|
|
return send((
|
|
|
|
obj = {},
|
|
|
|
obj["" + messageType] = [message],
|
|
|
|
obj
|
|
|
|
), function(err, res) {
|
2016-01-30 05:18:51 +03:00
|
|
|
console.log('sent');
|
|
|
|
console.log(arguments);
|
|
|
|
if (cb) {
|
|
|
|
return cb(err, res);
|
2015-04-28 22:00:46 +03:00
|
|
|
}
|
2016-01-30 05:18:51 +03:00
|
|
|
});
|
2015-04-28 22:00:46 +03:00
|
|
|
}
|
2016-01-30 05:18:51 +03:00
|
|
|
};
|
|
|
|
};
|
2015-04-28 22:00:46 +03:00
|
|
|
|
|
|
|
|
2016-07-16 03:15:03 +03:00
|
|
|
},{"../util.coffee":15}],12:[function(require,module,exports){
|
|
|
|
var design, send, subscribed, util;
|
2016-06-05 21:19:47 +03:00
|
|
|
|
|
|
|
util = require('../util.coffee');
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
window.urb.appl = "talk";
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
send = function(data, cb) {
|
|
|
|
return window.urb.send(data, {
|
|
|
|
mark: "talk-command"
|
|
|
|
}, cb);
|
|
|
|
};
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
design = function(party, config, cb) {
|
|
|
|
return send({
|
|
|
|
design: {
|
|
|
|
party: party,
|
|
|
|
config: config
|
|
|
|
}
|
|
|
|
}, cb);
|
|
|
|
};
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2016-07-16 03:15:03 +03:00
|
|
|
subscribed = {};
|
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
module.exports = function(arg) {
|
|
|
|
var StationActions;
|
|
|
|
StationActions = arg.StationActions;
|
|
|
|
return {
|
|
|
|
createStation: function(name, cb) {
|
|
|
|
return design(name, {
|
|
|
|
sources: [],
|
|
|
|
caption: "",
|
|
|
|
cordon: {
|
|
|
|
posture: "white",
|
|
|
|
list: []
|
|
|
|
}
|
|
|
|
}, cb);
|
|
|
|
},
|
|
|
|
removeStation: function(name, cb) {
|
|
|
|
return design(name, null, cb);
|
|
|
|
},
|
|
|
|
setSources: function(station, ship, sources) {
|
|
|
|
var cordon;
|
|
|
|
cordon = {
|
2016-02-02 03:00:45 +03:00
|
|
|
posture: "black",
|
2016-01-30 05:18:51 +03:00
|
|
|
list: []
|
|
|
|
};
|
|
|
|
return design(station, {
|
|
|
|
sources: sources,
|
|
|
|
cordon: cordon,
|
|
|
|
caption: ""
|
|
|
|
}, function(err, res) {
|
|
|
|
console.log('talk-command');
|
|
|
|
return console.log(arguments);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
listen: function() {
|
|
|
|
return window.urb.bind("/", function(err, res) {
|
2016-03-01 04:31:08 +03:00
|
|
|
var house;
|
2016-01-30 05:18:51 +03:00
|
|
|
if (err || !res.data) {
|
|
|
|
console.log('/ err');
|
|
|
|
console.log(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log('/');
|
|
|
|
console.log(res.data);
|
2016-03-01 04:31:08 +03:00
|
|
|
house = res.data.house;
|
|
|
|
if (house) {
|
2016-01-30 05:18:51 +03:00
|
|
|
return StationActions.loadStations(res.data.house);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2016-07-16 03:15:03 +03:00
|
|
|
listenStation: function(station, arg1) {
|
|
|
|
var cabal, glyph, group, k, path, types;
|
|
|
|
group = arg1.group, glyph = arg1.glyph, cabal = arg1.cabal;
|
|
|
|
if (subscribed[station] == null) {
|
|
|
|
subscribed[station] = {};
|
|
|
|
}
|
|
|
|
types = {
|
|
|
|
a_group: group,
|
|
|
|
v_glyph: glyph,
|
|
|
|
x_cabal: cabal
|
|
|
|
};
|
|
|
|
for (k in types) {
|
|
|
|
if (subscribed[station][k]) {
|
|
|
|
delete types[k];
|
|
|
|
} else {
|
|
|
|
subscribed[station][k] = types[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_.isEmpty(types)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
path = util.talkPath(types, station);
|
|
|
|
return window.urb.bind(path, function(err, res) {
|
|
|
|
var ok, ref;
|
2016-01-30 05:18:51 +03:00
|
|
|
if (err || !res) {
|
2016-07-16 03:15:03 +03:00
|
|
|
console.log(path, 'err');
|
2016-01-30 05:18:51 +03:00
|
|
|
console.log(err);
|
|
|
|
return;
|
|
|
|
}
|
2016-07-16 03:15:03 +03:00
|
|
|
console.log(path);
|
2016-01-30 05:18:51 +03:00
|
|
|
console.log(res.data);
|
2016-03-01 04:31:08 +03:00
|
|
|
ref = res.data, ok = ref.ok, group = ref.group, cabal = ref.cabal, glyph = ref.glyph;
|
|
|
|
switch (false) {
|
|
|
|
case !ok:
|
|
|
|
return StationActions.listeningStation(station);
|
|
|
|
case !group:
|
2016-06-05 21:19:47 +03:00
|
|
|
group.global[util.mainStationPath(window.urb.user)] = group.local;
|
2016-03-01 04:31:08 +03:00
|
|
|
return StationActions.loadMembers(group.global);
|
|
|
|
case !(cabal != null ? cabal.loc : void 0):
|
|
|
|
return StationActions.loadConfig(station, cabal.loc);
|
|
|
|
case !glyph:
|
|
|
|
return StationActions.loadGlyphs(glyph);
|
2016-01-30 05:18:51 +03:00
|
|
|
}
|
|
|
|
});
|
2016-01-27 21:53:37 +03:00
|
|
|
}
|
|
|
|
};
|
2016-01-30 05:18:51 +03:00
|
|
|
};
|
2015-01-27 01:47:18 +03:00
|
|
|
|
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
},{"../util.coffee":15}],13:[function(require,module,exports){
|
2016-01-30 05:18:51 +03:00
|
|
|
var EventEmitter, MessageDispatcher, MessageStore, _fetching, _last, _listening, _messages, _station, _typing, moment;
|
2015-01-27 01:47:18 +03:00
|
|
|
|
2016-03-04 03:13:05 +03:00
|
|
|
moment = window.moment.tz;
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
EventEmitter = require('events').EventEmitter;
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
MessageDispatcher = require('../dispatcher/Dispatcher.coffee');
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_messages = {};
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_fetching = false;
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_last = null;
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_station = null;
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_listening = [];
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_typing = false;
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
MessageStore = _.merge(new EventEmitter, {
|
|
|
|
removeChangeListener: function(cb) {
|
|
|
|
return this.removeListener("change", cb);
|
|
|
|
},
|
|
|
|
emitChange: function() {
|
|
|
|
return this.emit('change');
|
|
|
|
},
|
|
|
|
addChangeListener: function(cb) {
|
|
|
|
return this.on('change', cb);
|
|
|
|
},
|
|
|
|
leadingZero: function(str) {
|
|
|
|
if (Number(str) < 10) {
|
|
|
|
return "0" + str;
|
2015-11-03 23:12:32 +03:00
|
|
|
} else {
|
2016-01-30 05:18:51 +03:00
|
|
|
return str;
|
2015-11-03 23:12:32 +03:00
|
|
|
}
|
2016-01-30 05:18:51 +03:00
|
|
|
},
|
|
|
|
convertDate: function(time) {
|
|
|
|
var d;
|
|
|
|
time = time.substr(1).split(".");
|
|
|
|
time[1] = this.leadingZero(time[1]);
|
|
|
|
time[2] = this.leadingZero(time[2]);
|
|
|
|
d = new moment(time[0] + "-" + time[1] + "-" + time[2] + "T" + time[4] + ":" + time[5] + ":" + time[6] + "Z");
|
|
|
|
d.tz("Europe/London");
|
|
|
|
return d;
|
|
|
|
},
|
|
|
|
getListening: function() {
|
|
|
|
return _listening;
|
|
|
|
},
|
|
|
|
getTyping: function() {
|
|
|
|
return _typing;
|
|
|
|
},
|
|
|
|
getLastAudience: function() {
|
|
|
|
var messages;
|
|
|
|
if (_.keys(_messages).length === 0) {
|
|
|
|
return [];
|
2015-11-03 23:12:32 +03:00
|
|
|
}
|
2016-01-30 05:18:51 +03:00
|
|
|
messages = _.sortBy(_messages, function(_message) {
|
|
|
|
return _message.thought.statement.time;
|
|
|
|
});
|
|
|
|
return _.keys(messages[messages.length - 1].thought.audience);
|
|
|
|
},
|
|
|
|
setTyping: function(state) {
|
|
|
|
return _typing = state;
|
|
|
|
},
|
|
|
|
setListening: function(station) {
|
|
|
|
if (_listening.indexOf(station) !== -1) {
|
|
|
|
return console.log('already listening on that station (somehow).');
|
2015-11-03 23:12:32 +03:00
|
|
|
} else {
|
2016-01-30 05:18:51 +03:00
|
|
|
return _listening.push(station);
|
2015-11-03 23:12:32 +03:00
|
|
|
}
|
2016-01-30 05:18:51 +03:00
|
|
|
},
|
|
|
|
setStation: function(station) {
|
|
|
|
return _station = station;
|
|
|
|
},
|
|
|
|
sendMessage: function(message) {
|
|
|
|
return _messages[message.thought.serial] = message;
|
|
|
|
},
|
|
|
|
loadMessages: function(messages, last, get) {
|
|
|
|
var i, key, len, serial, v;
|
|
|
|
key = last;
|
|
|
|
for (i = 0, len = messages.length; i < len; i++) {
|
|
|
|
v = messages[i];
|
|
|
|
serial = v.thought.serial;
|
|
|
|
v.key = key++;
|
|
|
|
_messages[serial] = v;
|
2015-11-03 23:12:32 +03:00
|
|
|
}
|
2016-01-30 05:18:51 +03:00
|
|
|
if (last < _last || _last === null || get === true) {
|
|
|
|
_last = last;
|
2015-11-03 23:12:32 +03:00
|
|
|
}
|
2016-01-30 05:18:51 +03:00
|
|
|
return _fetching = false;
|
|
|
|
},
|
|
|
|
getAll: function() {
|
|
|
|
return _.values(_messages);
|
|
|
|
},
|
|
|
|
getFetching: function() {
|
|
|
|
return _fetching;
|
|
|
|
},
|
|
|
|
setFetching: function(state) {
|
|
|
|
return _fetching = state;
|
|
|
|
},
|
|
|
|
getLast: function() {
|
|
|
|
return _last;
|
|
|
|
}
|
|
|
|
});
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
MessageStore.setMaxListeners(100);
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
MessageStore.dispatchToken = MessageDispatcher.register(function(payload) {
|
|
|
|
var action;
|
|
|
|
action = payload.action;
|
|
|
|
switch (action.type) {
|
|
|
|
case 'station-switch':
|
|
|
|
MessageStore.setStation(action.station);
|
|
|
|
break;
|
|
|
|
case 'messages-listen':
|
|
|
|
MessageStore.setListening(action.station);
|
|
|
|
MessageStore.emitChange();
|
|
|
|
break;
|
|
|
|
case 'messages-typing':
|
|
|
|
MessageStore.setTyping(action.state);
|
|
|
|
MessageStore.emitChange();
|
|
|
|
break;
|
|
|
|
case 'messages-fetch':
|
|
|
|
MessageStore.setFetching(true);
|
|
|
|
MessageStore.emitChange();
|
|
|
|
break;
|
|
|
|
case 'messages-load':
|
|
|
|
MessageStore.loadMessages(action.messages, action.last, action.get);
|
|
|
|
MessageStore.emitChange();
|
|
|
|
break;
|
|
|
|
case 'message-load':
|
|
|
|
MessageStore.loadMessage(action.time, action.message, action.author);
|
|
|
|
MessageStore.emitChange();
|
|
|
|
break;
|
|
|
|
case 'message-send':
|
|
|
|
MessageStore.sendMessage(action.message);
|
|
|
|
MessageStore.emitChange();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
module.exports = MessageStore;
|
2015-11-03 23:12:32 +03:00
|
|
|
|
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
},{"../dispatcher/Dispatcher.coffee":9,"events":18}],14:[function(require,module,exports){
|
2016-01-30 05:18:51 +03:00
|
|
|
var EventEmitter, StationDispatcher, StationStore, _audience, _config, _glyphs, _listening, _members, _shpylg, _station, _stations, _typing, _validAudience;
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
EventEmitter = require('events').EventEmitter;
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
StationDispatcher = require('../dispatcher/Dispatcher.coffee');
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_audience = [];
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_members = {};
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_stations = [];
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_listening = [];
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_station = null;
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_config = {};
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_typing = {};
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_glyphs = {};
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_shpylg = {};
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
_validAudience = true;
|
2015-11-03 23:12:32 +03:00
|
|
|
|
2016-01-30 05:18:51 +03:00
|
|
|
StationStore = _.merge(new EventEmitter, {
|
|
|
|
removeChangeListener: function(cb) {
|
|
|
|
return this.removeListener("change", cb);
|
|
|
|
},
|
|
|
|
emitChange: function() {
|
|
|
|
return this.emit('change');
|
|
|
|
},
|
|
|
|
addChangeListener: function(cb) {
|
|
|
|
return this.on('change', cb);
|
|
|
|
},
|
|
|
|
getAudience: function() {
|
|
|
|
return _audience;
|
|
|
|
},
|
|
|
|
setAudience: function(audience) {
|
|
|
|
return _audience = audience;
|
|
|
|
},
|
|
|
|
getValidAudience: function() {
|
|
|
|
return _validAudience;
|
|
|
|
},
|
|
|
|
setValidAudience: function(valid) {
|
|
|
|
return _validAudience = valid;
|
|
|
|
},
|
|
|
|
toggleAudience: function(station) {
|
|
|
|
if (_audience.indexOf(station) !== -1) {
|
|
|
|
return _audience.splice(_audience.indexOf(station), 1);
|
|
|
|
} else {
|
|
|
|
return _audience.push(station);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
loadConfig: function(station, config) {
|
|
|
|
return _config[station] = config;
|
|
|
|
},
|
|
|
|
getConfigs: function() {
|
|
|
|
return _config;
|
|
|
|
},
|
|
|
|
getConfig: function(station) {
|
|
|
|
return _config[station];
|
|
|
|
},
|
|
|
|
getGlyph: function(station) {
|
|
|
|
return _shpylg[station];
|
|
|
|
},
|
|
|
|
getGlyphMap: function() {
|
|
|
|
return _shpylg;
|
|
|
|
},
|
|
|
|
getGlyphAudience: function(glyph) {
|
|
|
|
var aud, ref;
|
|
|
|
aud = (ref = _glyphs[glyph]) != null ? ref : [];
|
|
|
|
if (aud.length === 1) {
|
|
|
|
return aud[0];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getMember: function(ship) {
|
|
|
|
return {
|
|
|
|
ship: ship
|
|
|
|
};
|
|
|
|
},
|
|
|
|
loadMembers: function(members) {
|
2016-02-03 02:25:15 +03:00
|
|
|
return _members = members;
|
2016-01-30 05:18:51 +03:00
|
|
|
},
|
|
|
|
getMembers: function() {
|
|
|
|
return _members;
|
|
|
|
},
|
|
|
|
getListening: function() {
|
|
|
|
return _listening;
|
|
|
|
},
|
|
|
|
setListening: function(station) {
|
|
|
|
if (_listening.indexOf(station) !== -1) {
|
|
|
|
return console.log('already listening on that station (somehow).');
|
|
|
|
} else {
|
|
|
|
return _listening.push(station);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
createStation: function(station) {
|
|
|
|
if (_stations.indexOf(station) === -1) {
|
|
|
|
return _stations.push(station);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
loadStations: function(stations) {
|
|
|
|
return _stations = stations;
|
|
|
|
},
|
|
|
|
loadGlyphs: function(glyphs) {
|
|
|
|
var aud, auds, char, results;
|
|
|
|
_glyphs = glyphs;
|
|
|
|
_shpylg = {};
|
|
|
|
results = [];
|
|
|
|
for (char in glyphs) {
|
|
|
|
auds = glyphs[char];
|
|
|
|
results.push((function() {
|
|
|
|
var i, len, results1;
|
|
|
|
results1 = [];
|
|
|
|
for (i = 0, len = auds.length; i < len; i++) {
|
|
|
|
aud = auds[i];
|
|
|
|
results1.push(_shpylg[aud.join(" ")] = char);
|
|
|
|
}
|
|
|
|
return results1;
|
|
|
|
})());
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
},
|
2016-07-27 03:57:59 +03:00
|
|
|
getGlyphs: function() {
|
|
|
|
return _glyphs;
|
|
|
|
},
|
2016-01-30 05:18:51 +03:00
|
|
|
getStations: function() {
|
|
|
|
return _stations;
|
|
|
|
},
|
|
|
|
setStation: function(station) {
|
|
|
|
return _station = station;
|
|
|
|
},
|
|
|
|
unsetStation: function(station) {
|
|
|
|
if (_station === station) {
|
|
|
|
return _station = null;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getStation: function() {
|
|
|
|
return _station;
|
|
|
|
},
|
|
|
|
joinStation: function(station) {
|
|
|
|
var ref;
|
|
|
|
if (((ref = _config.court) != null ? ref.sources.indexOf(station) : void 0) === -1) {
|
|
|
|
return _config.court.sources.push(station);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
getTyping: function() {
|
|
|
|
return _typing;
|
|
|
|
},
|
|
|
|
setTyping: function(station, state) {
|
|
|
|
var k, v;
|
|
|
|
for (k in _typing) {
|
|
|
|
v = _typing[k];
|
|
|
|
_typing[k] = k === station;
|
|
|
|
}
|
|
|
|
return _typing[station] = state;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
StationStore.setMaxListeners(100);
|
|
|
|
|
|
|
|
StationStore.dispatchToken = StationDispatcher.register(function(payload) {
|
|
|
|
var action;
|
|
|
|
action = payload.action;
|
|
|
|
switch (action.type) {
|
|
|
|
case 'station-audience-toggle':
|
|
|
|
StationStore.toggleAudience(action.station);
|
|
|
|
StationStore.emitChange();
|
|
|
|
break;
|
|
|
|
case 'station-set-audience':
|
|
|
|
StationStore.setAudience(action.audience);
|
|
|
|
StationStore.emitChange();
|
|
|
|
break;
|
|
|
|
case 'station-set-valid-audience':
|
|
|
|
StationStore.setValidAudience(action.valid);
|
|
|
|
StationStore.emitChange();
|
|
|
|
break;
|
|
|
|
case 'station-switch':
|
|
|
|
StationStore.setAudience([]);
|
|
|
|
StationStore.setStation(action.station);
|
|
|
|
StationStore.emitChange();
|
|
|
|
break;
|
|
|
|
case 'station-listen':
|
|
|
|
StationStore.setListening(action.station);
|
|
|
|
StationStore.emitChange();
|
|
|
|
break;
|
|
|
|
case "config-load":
|
|
|
|
StationStore.loadConfig(action.station, action.config);
|
|
|
|
StationStore.emitChange();
|
|
|
|
break;
|
|
|
|
case "glyphs-load":
|
|
|
|
StationStore.loadGlyphs(action.glyphs);
|
|
|
|
StationStore.emitChange();
|
|
|
|
break;
|
|
|
|
case "stations-load":
|
|
|
|
StationStore.loadStations(action.stations);
|
|
|
|
StationStore.emitChange();
|
|
|
|
break;
|
|
|
|
case "stations-leave":
|
|
|
|
StationStore.loadStations(action.stations);
|
|
|
|
StationStore.unsetStation(action.station);
|
|
|
|
StationStore.emitChange();
|
|
|
|
break;
|
|
|
|
case "station-create":
|
|
|
|
StationStore.createStation(action.station);
|
|
|
|
StationStore.emitChange();
|
|
|
|
break;
|
|
|
|
case "members-load":
|
|
|
|
StationStore.loadMembers(action.members);
|
|
|
|
StationStore.emitChange();
|
|
|
|
break;
|
|
|
|
case "typing-set":
|
|
|
|
StationStore.setTyping(action.station, action.state);
|
|
|
|
StationStore.emitChange();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = StationStore;
|
|
|
|
|
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
},{"../dispatcher/Dispatcher.coffee":9,"events":18}],15:[function(require,module,exports){
|
2016-07-16 03:15:03 +03:00
|
|
|
var util,
|
|
|
|
slice = [].slice;
|
2016-01-30 05:18:51 +03:00
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
module.exports = util = {
|
2016-03-01 04:31:08 +03:00
|
|
|
defaultStation: function() {
|
2016-06-05 21:19:47 +03:00
|
|
|
var station;
|
2016-03-01 04:31:08 +03:00
|
|
|
if (document.location.search) {
|
2016-06-05 21:19:47 +03:00
|
|
|
station = document.location.search.replace(/^\?/, '');
|
|
|
|
if (station.indexOf('dbg.nopack') !== -1) {
|
|
|
|
return station = util.mainStation();
|
2016-05-19 08:48:27 +03:00
|
|
|
}
|
2016-03-01 04:31:08 +03:00
|
|
|
} else {
|
2016-06-05 21:19:47 +03:00
|
|
|
return util.mainStation();
|
2016-03-01 04:31:08 +03:00
|
|
|
}
|
|
|
|
},
|
2016-01-30 05:18:51 +03:00
|
|
|
mainStations: ["court", "floor", "porch"],
|
|
|
|
mainStationPath: function(user) {
|
2016-07-06 00:45:48 +03:00
|
|
|
if (user) {
|
|
|
|
return "~" + user + "/" + (util.mainStation(user));
|
|
|
|
}
|
2016-01-30 05:18:51 +03:00
|
|
|
},
|
|
|
|
mainStation: function(user) {
|
|
|
|
if (!user) {
|
|
|
|
user = window.urb.user;
|
|
|
|
}
|
2016-07-06 00:45:48 +03:00
|
|
|
if (!user) {
|
|
|
|
return;
|
|
|
|
}
|
2016-01-30 05:18:51 +03:00
|
|
|
switch (user.length) {
|
|
|
|
case 3:
|
|
|
|
return "court";
|
|
|
|
case 6:
|
|
|
|
return "floor";
|
2016-02-23 01:58:27 +03:00
|
|
|
default:
|
2016-01-30 05:18:51 +03:00
|
|
|
return "porch";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
clipAudi: function(audi) {
|
|
|
|
var ms, regx;
|
|
|
|
audi = audi.join(" ");
|
2016-06-05 21:19:47 +03:00
|
|
|
ms = util.mainStationPath(window.urb.user);
|
2016-01-30 05:18:51 +03:00
|
|
|
regx = new RegExp("/" + ms, "g");
|
|
|
|
audi = audi.replace(regx, "");
|
|
|
|
return audi.split(" ");
|
|
|
|
},
|
|
|
|
expandAudi: function(audi) {
|
|
|
|
var ms;
|
|
|
|
audi = audi.join(" ");
|
2016-06-05 21:19:47 +03:00
|
|
|
ms = util.mainStationPath(window.urb.user);
|
2016-01-30 05:18:51 +03:00
|
|
|
if (audi.indexOf(ms) === -1) {
|
|
|
|
if (audi.length > 0) {
|
|
|
|
audi += " ";
|
|
|
|
}
|
|
|
|
audi += "" + ms;
|
|
|
|
}
|
|
|
|
return audi.split(" ");
|
|
|
|
},
|
|
|
|
create: function(name) {
|
|
|
|
return window.talk.StationPersistence.createStation(name, function(err, res) {});
|
|
|
|
},
|
|
|
|
subscribe: function(name) {
|
|
|
|
return window.talk.StationPersistence.addSource("main", window.urb.ship, ["~zod/" + name]);
|
|
|
|
},
|
|
|
|
uuid32: function() {
|
|
|
|
var _str, i, j, str;
|
|
|
|
str = "0v";
|
|
|
|
str += Math.ceil(Math.random() * 8) + ".";
|
|
|
|
for (i = j = 0; j <= 5; i = ++j) {
|
|
|
|
_str = Math.ceil(Math.random() * 10000000).toString(32);
|
|
|
|
_str = ("00000" + _str).substr(-5, 5);
|
|
|
|
str += _str + ".";
|
|
|
|
}
|
|
|
|
return str.slice(0, -1);
|
|
|
|
},
|
|
|
|
populate: function(station, number) {
|
|
|
|
var c, send;
|
|
|
|
c = 0;
|
|
|
|
send = function() {
|
|
|
|
var _audi, _message;
|
|
|
|
if (c < number) {
|
|
|
|
c++;
|
|
|
|
} else {
|
|
|
|
console.log('done');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
_audi = {};
|
|
|
|
_audi[station] = "pending";
|
|
|
|
_message = {
|
2016-06-05 21:19:47 +03:00
|
|
|
serial: util.uuid32(),
|
2016-01-30 05:18:51 +03:00
|
|
|
audience: _audi,
|
|
|
|
statement: {
|
|
|
|
speech: {
|
|
|
|
say: "Message " + c
|
|
|
|
},
|
|
|
|
time: Date.now(),
|
|
|
|
now: Date.now()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return window.talk.MessagePersistence.sendMessage(_message, send);
|
|
|
|
};
|
|
|
|
return send();
|
|
|
|
},
|
|
|
|
scrollToBottom: function() {
|
2016-06-07 21:42:19 +03:00
|
|
|
return $(window).scrollTop($(".container").outerHeight(true));
|
2016-01-30 05:18:51 +03:00
|
|
|
},
|
|
|
|
getScroll: function() {
|
2016-02-07 03:42:31 +03:00
|
|
|
return this.writingPosition = $('.container').outerHeight(true) + $('.container').offset().top - $(window).height();
|
2016-01-30 05:18:51 +03:00
|
|
|
},
|
|
|
|
setScroll: function() {
|
2016-06-05 21:19:47 +03:00
|
|
|
util.getScroll();
|
2016-02-07 03:42:31 +03:00
|
|
|
return $(window).scrollTop($(".container").height());
|
2016-01-30 05:18:51 +03:00
|
|
|
},
|
|
|
|
isScrolling: function() {
|
2016-06-05 21:19:47 +03:00
|
|
|
if (!util.writingPosition) {
|
|
|
|
util.getScroll();
|
2016-01-30 05:18:51 +03:00
|
|
|
}
|
2016-06-05 21:19:47 +03:00
|
|
|
return $(window).scrollTop() + $('.writing').outerHeight() < util.writingPosition;
|
2016-07-16 03:15:03 +03:00
|
|
|
},
|
|
|
|
talkPath: function() {
|
|
|
|
var components, encodedTypes, key, types, val;
|
|
|
|
types = arguments[0], components = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
|
|
|
encodedTypes = ((function() {
|
|
|
|
var results;
|
|
|
|
results = [];
|
|
|
|
for (key in types) {
|
|
|
|
val = types[key];
|
|
|
|
if (key !== 'a_group' && key !== 'f_grams' && key !== 'v_glyph' && key !== 'x_cabal') {
|
|
|
|
throw new Error("Weird type: '" + key + "'");
|
|
|
|
}
|
|
|
|
if (val) {
|
|
|
|
results.push(key[0]);
|
|
|
|
} else {
|
|
|
|
results.push(void 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
})()).join('');
|
|
|
|
return ['', encodedTypes].concat(slice.call(components)).join('/');
|
2016-01-30 05:18:51 +03:00
|
|
|
}
|
2016-06-05 21:19:47 +03:00
|
|
|
};
|
2016-01-30 05:18:51 +03:00
|
|
|
|
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
},{}],16:[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-06-05 21:19:47 +03:00
|
|
|
},{}],17:[function(require,module,exports){
|
2016-01-30 05:18:51 +03:00
|
|
|
// Generated by CoffeeScript 1.9.3
|
|
|
|
(function() {
|
|
|
|
var L_to_Y, Y_to_L, conv, distanceFromPole, dotProduct, epsilon, fromLinear, getBounds, intersectLineLine, kappa, lengthOfRayUntilIntersect, m, m_inv, maxChromaForLH, maxSafeChromaForL, refU, refV, root, toLinear;
|
|
|
|
|
|
|
|
m = {
|
|
|
|
R: [3.2409699419045214, -1.5373831775700935, -0.49861076029300328],
|
|
|
|
G: [-0.96924363628087983, 1.8759675015077207, 0.041555057407175613],
|
|
|
|
B: [0.055630079696993609, -0.20397695888897657, 1.0569715142428786]
|
|
|
|
};
|
|
|
|
|
|
|
|
m_inv = {
|
|
|
|
X: [0.41239079926595948, 0.35758433938387796, 0.18048078840183429],
|
|
|
|
Y: [0.21263900587151036, 0.71516867876775593, 0.072192315360733715],
|
|
|
|
Z: [0.019330818715591851, 0.11919477979462599, 0.95053215224966058]
|
|
|
|
};
|
|
|
|
|
|
|
|
refU = 0.19783000664283681;
|
|
|
|
|
|
|
|
refV = 0.468319994938791;
|
|
|
|
|
|
|
|
kappa = 903.2962962962963;
|
|
|
|
|
|
|
|
epsilon = 0.0088564516790356308;
|
|
|
|
|
|
|
|
getBounds = function(L) {
|
|
|
|
var bottom, channel, j, k, len1, len2, m1, m2, m3, ref, ref1, ref2, ret, sub1, sub2, t, top1, top2;
|
|
|
|
sub1 = Math.pow(L + 16, 3) / 1560896;
|
|
|
|
sub2 = sub1 > epsilon ? sub1 : L / kappa;
|
|
|
|
ret = [];
|
|
|
|
ref = ['R', 'G', 'B'];
|
|
|
|
for (j = 0, len1 = ref.length; j < len1; j++) {
|
|
|
|
channel = ref[j];
|
|
|
|
ref1 = m[channel], m1 = ref1[0], m2 = ref1[1], m3 = ref1[2];
|
|
|
|
ref2 = [0, 1];
|
|
|
|
for (k = 0, len2 = ref2.length; k < len2; k++) {
|
|
|
|
t = ref2[k];
|
|
|
|
top1 = (284517 * m1 - 94839 * m3) * sub2;
|
|
|
|
top2 = (838422 * m3 + 769860 * m2 + 731718 * m1) * L * sub2 - 769860 * t * L;
|
|
|
|
bottom = (632260 * m3 - 126452 * m2) * sub2 + 126452 * t;
|
|
|
|
ret.push([top1 / bottom, top2 / bottom]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
intersectLineLine = function(line1, line2) {
|
|
|
|
return (line1[1] - line2[1]) / (line2[0] - line1[0]);
|
|
|
|
};
|
|
|
|
|
|
|
|
distanceFromPole = function(point) {
|
|
|
|
return Math.sqrt(Math.pow(point[0], 2) + Math.pow(point[1], 2));
|
|
|
|
};
|
|
|
|
|
|
|
|
lengthOfRayUntilIntersect = function(theta, line) {
|
|
|
|
var b1, len, m1;
|
|
|
|
m1 = line[0], b1 = line[1];
|
|
|
|
len = b1 / (Math.sin(theta) - m1 * Math.cos(theta));
|
|
|
|
if (len < 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
};
|
|
|
|
|
|
|
|
maxSafeChromaForL = function(L) {
|
|
|
|
var b1, j, len1, lengths, m1, ref, ref1, x;
|
|
|
|
lengths = [];
|
|
|
|
ref = getBounds(L);
|
|
|
|
for (j = 0, len1 = ref.length; j < len1; j++) {
|
|
|
|
ref1 = ref[j], m1 = ref1[0], b1 = ref1[1];
|
|
|
|
x = intersectLineLine([m1, b1], [-1 / m1, 0]);
|
|
|
|
lengths.push(distanceFromPole([x, b1 + x * m1]));
|
|
|
|
}
|
|
|
|
return Math.min.apply(Math, lengths);
|
|
|
|
};
|
|
|
|
|
|
|
|
maxChromaForLH = function(L, H) {
|
|
|
|
var hrad, j, l, len1, lengths, line, ref;
|
|
|
|
hrad = H / 360 * Math.PI * 2;
|
|
|
|
lengths = [];
|
|
|
|
ref = getBounds(L);
|
|
|
|
for (j = 0, len1 = ref.length; j < len1; j++) {
|
|
|
|
line = ref[j];
|
|
|
|
l = lengthOfRayUntilIntersect(hrad, line);
|
|
|
|
if (l !== null) {
|
|
|
|
lengths.push(l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Math.min.apply(Math, lengths);
|
|
|
|
};
|
|
|
|
|
|
|
|
dotProduct = function(a, b) {
|
|
|
|
var i, j, ref, ret;
|
|
|
|
ret = 0;
|
|
|
|
for (i = j = 0, ref = a.length - 1; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) {
|
|
|
|
ret += a[i] * b[i];
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
fromLinear = function(c) {
|
|
|
|
if (c <= 0.0031308) {
|
|
|
|
return 12.92 * c;
|
|
|
|
} else {
|
|
|
|
return 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
toLinear = function(c) {
|
|
|
|
var a;
|
|
|
|
a = 0.055;
|
|
|
|
if (c > 0.04045) {
|
|
|
|
return Math.pow((c + a) / (1 + a), 2.4);
|
|
|
|
} else {
|
|
|
|
return c / 12.92;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
conv = {
|
|
|
|
'xyz': {},
|
|
|
|
'luv': {},
|
|
|
|
'lch': {},
|
|
|
|
'husl': {},
|
|
|
|
'huslp': {},
|
|
|
|
'rgb': {},
|
|
|
|
'hex': {}
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.xyz.rgb = function(tuple) {
|
|
|
|
var B, G, R;
|
|
|
|
R = fromLinear(dotProduct(m.R, tuple));
|
|
|
|
G = fromLinear(dotProduct(m.G, tuple));
|
|
|
|
B = fromLinear(dotProduct(m.B, tuple));
|
|
|
|
return [R, G, B];
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.rgb.xyz = function(tuple) {
|
|
|
|
var B, G, R, X, Y, Z, rgbl;
|
|
|
|
R = tuple[0], G = tuple[1], B = tuple[2];
|
|
|
|
rgbl = [toLinear(R), toLinear(G), toLinear(B)];
|
|
|
|
X = dotProduct(m_inv.X, rgbl);
|
|
|
|
Y = dotProduct(m_inv.Y, rgbl);
|
|
|
|
Z = dotProduct(m_inv.Z, rgbl);
|
|
|
|
return [X, Y, Z];
|
|
|
|
};
|
|
|
|
|
|
|
|
Y_to_L = function(Y) {
|
|
|
|
if (Y <= epsilon) {
|
|
|
|
return Y * kappa;
|
|
|
|
} else {
|
|
|
|
return 116 * Math.pow(Y, 1 / 3) - 16;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
L_to_Y = function(L) {
|
|
|
|
if (L <= 8) {
|
|
|
|
return L / kappa;
|
|
|
|
} else {
|
|
|
|
return Math.pow((L + 16) / 116, 3);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.xyz.luv = function(tuple) {
|
|
|
|
var L, U, V, X, Y, Z, varU, varV;
|
|
|
|
X = tuple[0], Y = tuple[1], Z = tuple[2];
|
|
|
|
if (Y === 0) {
|
|
|
|
return [0, 0, 0];
|
|
|
|
}
|
|
|
|
L = Y_to_L(Y);
|
|
|
|
varU = (4 * X) / (X + (15 * Y) + (3 * Z));
|
|
|
|
varV = (9 * Y) / (X + (15 * Y) + (3 * Z));
|
|
|
|
U = 13 * L * (varU - refU);
|
|
|
|
V = 13 * L * (varV - refV);
|
|
|
|
return [L, U, V];
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.luv.xyz = function(tuple) {
|
|
|
|
var L, U, V, X, Y, Z, varU, varV;
|
|
|
|
L = tuple[0], U = tuple[1], V = tuple[2];
|
|
|
|
if (L === 0) {
|
|
|
|
return [0, 0, 0];
|
|
|
|
}
|
|
|
|
varU = U / (13 * L) + refU;
|
|
|
|
varV = V / (13 * L) + refV;
|
|
|
|
Y = L_to_Y(L);
|
|
|
|
X = 0 - (9 * Y * varU) / ((varU - 4) * varV - varU * varV);
|
|
|
|
Z = (9 * Y - (15 * varV * Y) - (varV * X)) / (3 * varV);
|
|
|
|
return [X, Y, Z];
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.luv.lch = function(tuple) {
|
|
|
|
var C, H, Hrad, L, U, V;
|
|
|
|
L = tuple[0], U = tuple[1], V = tuple[2];
|
|
|
|
C = Math.sqrt(Math.pow(U, 2) + Math.pow(V, 2));
|
|
|
|
if (C < 0.00000001) {
|
|
|
|
H = 0;
|
|
|
|
} else {
|
|
|
|
Hrad = Math.atan2(V, U);
|
|
|
|
H = Hrad * 360 / 2 / Math.PI;
|
|
|
|
if (H < 0) {
|
|
|
|
H = 360 + H;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [L, C, H];
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.lch.luv = function(tuple) {
|
|
|
|
var C, H, Hrad, L, U, V;
|
|
|
|
L = tuple[0], C = tuple[1], H = tuple[2];
|
|
|
|
Hrad = H / 360 * 2 * Math.PI;
|
|
|
|
U = Math.cos(Hrad) * C;
|
|
|
|
V = Math.sin(Hrad) * C;
|
|
|
|
return [L, U, V];
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.husl.lch = function(tuple) {
|
|
|
|
var C, H, L, S, max;
|
|
|
|
H = tuple[0], S = tuple[1], L = tuple[2];
|
|
|
|
if (L > 99.9999999 || L < 0.00000001) {
|
|
|
|
C = 0;
|
|
|
|
} else {
|
|
|
|
max = maxChromaForLH(L, H);
|
|
|
|
C = max / 100 * S;
|
|
|
|
}
|
|
|
|
return [L, C, H];
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.lch.husl = function(tuple) {
|
|
|
|
var C, H, L, S, max;
|
|
|
|
L = tuple[0], C = tuple[1], H = tuple[2];
|
|
|
|
if (L > 99.9999999 || L < 0.00000001) {
|
|
|
|
S = 0;
|
|
|
|
} else {
|
|
|
|
max = maxChromaForLH(L, H);
|
|
|
|
S = C / max * 100;
|
|
|
|
}
|
|
|
|
return [H, S, L];
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.huslp.lch = function(tuple) {
|
|
|
|
var C, H, L, S, max;
|
|
|
|
H = tuple[0], S = tuple[1], L = tuple[2];
|
|
|
|
if (L > 99.9999999 || L < 0.00000001) {
|
|
|
|
C = 0;
|
|
|
|
} else {
|
|
|
|
max = maxSafeChromaForL(L);
|
|
|
|
C = max / 100 * S;
|
|
|
|
}
|
|
|
|
return [L, C, H];
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.lch.huslp = function(tuple) {
|
|
|
|
var C, H, L, S, max;
|
|
|
|
L = tuple[0], C = tuple[1], H = tuple[2];
|
|
|
|
if (L > 99.9999999 || L < 0.00000001) {
|
|
|
|
S = 0;
|
|
|
|
} else {
|
|
|
|
max = maxSafeChromaForL(L);
|
|
|
|
S = C / max * 100;
|
|
|
|
}
|
|
|
|
return [H, S, L];
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.rgb.hex = function(tuple) {
|
|
|
|
var ch, hex, j, len1;
|
|
|
|
hex = "#";
|
|
|
|
for (j = 0, len1 = tuple.length; j < len1; j++) {
|
|
|
|
ch = tuple[j];
|
|
|
|
ch = Math.round(ch * 1e6) / 1e6;
|
|
|
|
if (ch < 0 || ch > 1) {
|
|
|
|
throw new Error("Illegal rgb value: " + ch);
|
|
|
|
}
|
|
|
|
ch = Math.round(ch * 255).toString(16);
|
|
|
|
if (ch.length === 1) {
|
|
|
|
ch = "0" + ch;
|
|
|
|
}
|
|
|
|
hex += ch;
|
|
|
|
}
|
|
|
|
return hex;
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.hex.rgb = function(hex) {
|
|
|
|
var b, g, j, len1, n, r, ref, results;
|
|
|
|
if (hex.charAt(0) === "#") {
|
|
|
|
hex = hex.substring(1, 7);
|
|
|
|
}
|
|
|
|
r = hex.substring(0, 2);
|
|
|
|
g = hex.substring(2, 4);
|
|
|
|
b = hex.substring(4, 6);
|
|
|
|
ref = [r, g, b];
|
|
|
|
results = [];
|
|
|
|
for (j = 0, len1 = ref.length; j < len1; j++) {
|
|
|
|
n = ref[j];
|
|
|
|
results.push(parseInt(n, 16) / 255);
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.lch.rgb = function(tuple) {
|
|
|
|
return conv.xyz.rgb(conv.luv.xyz(conv.lch.luv(tuple)));
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.rgb.lch = function(tuple) {
|
|
|
|
return conv.luv.lch(conv.xyz.luv(conv.rgb.xyz(tuple)));
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.husl.rgb = function(tuple) {
|
|
|
|
return conv.lch.rgb(conv.husl.lch(tuple));
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.rgb.husl = function(tuple) {
|
|
|
|
return conv.lch.husl(conv.rgb.lch(tuple));
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.huslp.rgb = function(tuple) {
|
|
|
|
return conv.lch.rgb(conv.huslp.lch(tuple));
|
|
|
|
};
|
|
|
|
|
|
|
|
conv.rgb.huslp = function(tuple) {
|
|
|
|
return conv.lch.huslp(conv.rgb.lch(tuple));
|
|
|
|
};
|
|
|
|
|
|
|
|
root = {};
|
|
|
|
|
|
|
|
root.fromRGB = function(R, G, B) {
|
|
|
|
return conv.rgb.husl([R, G, B]);
|
|
|
|
};
|
|
|
|
|
|
|
|
root.fromHex = function(hex) {
|
|
|
|
return conv.rgb.husl(conv.hex.rgb(hex));
|
|
|
|
};
|
|
|
|
|
|
|
|
root.toRGB = function(H, S, L) {
|
|
|
|
return conv.husl.rgb([H, S, L]);
|
|
|
|
};
|
|
|
|
|
|
|
|
root.toHex = function(H, S, L) {
|
|
|
|
return conv.rgb.hex(conv.husl.rgb([H, S, L]));
|
|
|
|
};
|
|
|
|
|
|
|
|
root.p = {};
|
|
|
|
|
|
|
|
root.p.toRGB = function(H, S, L) {
|
|
|
|
return conv.xyz.rgb(conv.luv.xyz(conv.lch.luv(conv.huslp.lch([H, S, L]))));
|
|
|
|
};
|
|
|
|
|
|
|
|
root.p.toHex = function(H, S, L) {
|
|
|
|
return conv.rgb.hex(conv.xyz.rgb(conv.luv.xyz(conv.lch.luv(conv.huslp.lch([H, S, L])))));
|
2015-11-03 23:12:32 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
root.p.fromRGB = function(R, G, B) {
|
|
|
|
return conv.lch.huslp(conv.luv.lch(conv.xyz.luv(conv.rgb.xyz([R, G, B]))));
|
|
|
|
};
|
|
|
|
|
|
|
|
root.p.fromHex = function(hex) {
|
|
|
|
return conv.lch.huslp(conv.luv.lch(conv.xyz.luv(conv.rgb.xyz(conv.hex.rgb(hex)))));
|
|
|
|
};
|
|
|
|
|
|
|
|
root._conv = conv;
|
|
|
|
|
|
|
|
root._getBounds = getBounds;
|
|
|
|
|
|
|
|
root._maxChromaForLH = maxChromaForLH;
|
|
|
|
|
|
|
|
root._maxSafeChromaForL = maxSafeChromaForL;
|
|
|
|
|
|
|
|
if (!((typeof module !== "undefined" && module !== null) || (typeof jQuery !== "undefined" && jQuery !== null) || (typeof requirejs !== "undefined" && requirejs !== null))) {
|
|
|
|
this.HUSL = root;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof module !== "undefined" && module !== null) {
|
|
|
|
module.exports = root;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof jQuery !== "undefined" && jQuery !== null) {
|
|
|
|
jQuery.husl = root;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((typeof requirejs !== "undefined" && requirejs !== null) && (typeof define !== "undefined" && define !== null)) {
|
|
|
|
define(root);
|
|
|
|
}
|
|
|
|
|
|
|
|
}).call(this);
|
|
|
|
|
2016-06-05 21:19:47 +03:00
|
|
|
},{}],18:[function(require,module,exports){
|
2016-03-04 02:18:16 +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.
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
function EventEmitter() {
|
|
|
|
this._events = this._events || {};
|
|
|
|
this._maxListeners = this._maxListeners || undefined;
|
|
|
|
}
|
|
|
|
module.exports = EventEmitter;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
// Backwards-compat with node 0.10.x
|
|
|
|
EventEmitter.EventEmitter = EventEmitter;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
EventEmitter.prototype._events = undefined;
|
|
|
|
EventEmitter.prototype._maxListeners = undefined;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
// 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;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
// 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;
|
|
|
|
};
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
EventEmitter.prototype.emit = function(type) {
|
|
|
|
var er, handler, len, args, i, listeners;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (!this._events)
|
|
|
|
this._events = {};
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
// 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
|
2016-01-27 21:53:37 +03:00
|
|
|
}
|
2016-03-04 02:18:16 +03:00
|
|
|
throw TypeError('Uncaught, unspecified "error" event.');
|
2016-01-27 21:53:37 +03:00
|
|
|
}
|
2016-03-04 02:18:16 +03:00
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
handler = this._events[type];
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (isUndefined(handler))
|
|
|
|
return false;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
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:
|
|
|
|
args = Array.prototype.slice.call(arguments, 1);
|
|
|
|
handler.apply(this, args);
|
|
|
|
}
|
|
|
|
} else if (isObject(handler)) {
|
|
|
|
args = Array.prototype.slice.call(arguments, 1);
|
|
|
|
listeners = handler.slice();
|
|
|
|
len = listeners.length;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
listeners[i].apply(this, args);
|
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
return true;
|
|
|
|
};
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
EventEmitter.prototype.addListener = function(type, listener) {
|
|
|
|
var m;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (!isFunction(listener))
|
|
|
|
throw TypeError('listener must be a function');
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (!this._events)
|
|
|
|
this._events = {};
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
// 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);
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
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];
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
// Check for listener leak
|
|
|
|
if (isObject(this._events[type]) && !this._events[type].warned) {
|
|
|
|
if (!isUndefined(this._maxListeners)) {
|
|
|
|
m = this._maxListeners;
|
|
|
|
} else {
|
|
|
|
m = EventEmitter.defaultMaxListeners;
|
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
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();
|
2016-01-27 21:53:37 +03:00
|
|
|
}
|
|
|
|
}
|
2016-03-04 02:18:16 +03:00
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
return this;
|
|
|
|
};
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
EventEmitter.prototype.once = function(type, listener) {
|
|
|
|
if (!isFunction(listener))
|
|
|
|
throw TypeError('listener must be a function');
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
var fired = false;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
function g() {
|
|
|
|
this.removeListener(type, g);
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (!fired) {
|
|
|
|
fired = true;
|
|
|
|
listener.apply(this, arguments);
|
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
}
|
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
g.listener = listener;
|
|
|
|
this.on(type, g);
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
return this;
|
|
|
|
};
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
// emits a 'removeListener' event iff the listener was removed
|
|
|
|
EventEmitter.prototype.removeListener = function(type, listener) {
|
|
|
|
var list, position, length, i;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (!isFunction(listener))
|
|
|
|
throw TypeError('listener must be a function');
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (!this._events || !this._events[type])
|
|
|
|
return this;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
list = this._events[type];
|
|
|
|
length = list.length;
|
|
|
|
position = -1;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (list === listener ||
|
|
|
|
(isFunction(list.listener) && list.listener === listener)) {
|
|
|
|
delete this._events[type];
|
|
|
|
if (this._events.removeListener)
|
|
|
|
this.emit('removeListener', type, listener);
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
} else if (isObject(list)) {
|
|
|
|
for (i = length; i-- > 0;) {
|
|
|
|
if (list[i] === listener ||
|
|
|
|
(list[i].listener && list[i].listener === listener)) {
|
|
|
|
position = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (position < 0)
|
|
|
|
return this;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (list.length === 1) {
|
|
|
|
list.length = 0;
|
|
|
|
delete this._events[type];
|
|
|
|
} else {
|
|
|
|
list.splice(position, 1);
|
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (this._events.removeListener)
|
|
|
|
this.emit('removeListener', type, listener);
|
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
return this;
|
|
|
|
};
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
EventEmitter.prototype.removeAllListeners = function(type) {
|
|
|
|
var key, listeners;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (!this._events)
|
|
|
|
return this;
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
// 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;
|
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
// 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;
|
|
|
|
}
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
listeners = this._events[type];
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
if (isFunction(listeners)) {
|
|
|
|
this.removeListener(type, listeners);
|
|
|
|
} else if (listeners) {
|
|
|
|
// LIFO order
|
|
|
|
while (listeners.length)
|
|
|
|
this.removeListener(type, listeners[listeners.length - 1]);
|
|
|
|
}
|
|
|
|
delete this._events[type];
|
2016-01-27 21:53:37 +03:00
|
|
|
|
2016-03-04 02:18:16 +03:00
|
|
|
return this;
|
|
|
|
};
|
2015-01-27 01:47:18 +03:00
|
|
|
|
|
|
|
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-01-27 01:47:18 +03:00
|
|
|
EventEmitter.listenerCount = function(emitter, type) {
|
2016-01-30 05:18:51 +03:00
|
|
|
return emitter.listenerCount(type);
|
2015-01-27 01:47:18 +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-01-27 21:53:37 +03:00
|
|
|
},{}]},{},[10]);
|