734 lines
23 KiB
JavaScript
734 lines
23 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Created by mdonnel on 10/04/2017.
|
|
*/
|
|
var EventModel = Backbone.Model.extend({
|
|
'initialize': function initialize() {
|
|
this.update();
|
|
},
|
|
'getDays': function getDays(startdate, enddate) {
|
|
var r = void 0,
|
|
s = void 0,
|
|
e = void 0;
|
|
s = startdate.getTime();
|
|
e = enddate.getTime();
|
|
r = (e - s) / (24 * 60 * 60 * 1000);
|
|
|
|
return r;
|
|
},
|
|
'update': function update() {
|
|
var now = new Date();
|
|
var mod = 3600000 - now.getTime() % 3600000;
|
|
var data = {};
|
|
data.days = Math.ceil(this.getDays(now, this.get('event')));
|
|
data.weeks = Math.ceil(this.getDays(now, this.get('event')) / 7);
|
|
this.set('data', data);
|
|
|
|
var clockFn = function clockFn() {
|
|
this.update();
|
|
};
|
|
|
|
setTimeout(clockFn.bind(this), mod + 10);
|
|
}
|
|
});
|
|
|
|
var EventView = Backbone.View.extend({
|
|
'tagName': 'div',
|
|
'initialize': function initialize() {
|
|
_.bindAll(this, 'render');
|
|
this.model.bind('change', this.render);
|
|
this.id = 'e_' + Math.random().toString(36).substr(2, 9);
|
|
this.$events = $('#events');
|
|
this.$myEvent = null;
|
|
this.$el = this.$events;
|
|
this.initView();
|
|
this.render();
|
|
},
|
|
'render': function render() {
|
|
var label = this.model.get('label');
|
|
var data = this.model.get('data');
|
|
var str = label + ' ' + data.days + ' days / ' + data.weeks + ' weeks';
|
|
this.$myEvent.empty().append(str);
|
|
},
|
|
'initView': function initView() {
|
|
var html = '<div class=\'mui-col-xs-12 mui-col-md-3\' id="' + this.id + '"></div>';
|
|
this.$html = $(html);
|
|
this.$events.append(this.$html);
|
|
this.$myEvent = $('#' + this.id);
|
|
}
|
|
});
|
|
'use strict';
|
|
|
|
/**
|
|
* Created by mdonnel on 22/03/2017.
|
|
*/
|
|
|
|
var BitcoinModel = Backbone.Model.extend({
|
|
'initialize': function initialize() {
|
|
this.set('url', '/btc');
|
|
this.set('balanceUrl', '/balance');
|
|
var data = {
|
|
'lastGBP': 0.0,
|
|
'lastUSD': 0.0,
|
|
'lows': { 'gbp': 0, 'usd': 0 },
|
|
'highs': { 'gbp': 0, 'usd': 0 },
|
|
'eclass': '',
|
|
'balance': 0.0,
|
|
'trend': 0
|
|
};
|
|
this.set('btcdata', data);
|
|
this.set('balance', 0);
|
|
this.update();
|
|
this.updateHourly();
|
|
},
|
|
'update': function update() {
|
|
this.getBTC();
|
|
// this.getBalance();
|
|
var now = new Date();
|
|
var mod = 300000 - now.getTime() % 300000;
|
|
|
|
var btcupdateFn = function btcupdateFn() {
|
|
this.update();
|
|
};
|
|
setTimeout(btcupdateFn.bind(this), mod + 10);
|
|
},
|
|
'updateHourly': function updateHourly() {
|
|
this.getBalance();
|
|
var now = new Date();
|
|
var mod = 3600000 - now.getTime() % 3600000;
|
|
|
|
var btcupdateFn = function btcupdateFn() {
|
|
this.update();
|
|
};
|
|
setTimeout(btcupdateFn.bind(this), mod + 10);
|
|
},
|
|
'recalc': function recalc() {
|
|
var data = this.get('btcdata');
|
|
var lastGBP = data.lastGBP;
|
|
var lastUSD = void 0;
|
|
var g = data.gbp;
|
|
var u = data.usd;
|
|
var lows = data.lows;
|
|
var highs = data.highs;
|
|
var eclass = data.eclass;
|
|
var balance = data.balance;
|
|
var trend = data.trend;
|
|
|
|
if (trend === undefined || trend === null) trend = 1;
|
|
|
|
if (g !== undefined) {
|
|
if (data.lastGBP !== 0) {
|
|
if (g > lastGBP) {
|
|
eclass = 'up';
|
|
} else {
|
|
eclass = 'down';
|
|
}
|
|
} else {
|
|
lows.gbp = g;
|
|
lows.usd = u;
|
|
|
|
highs.gbp = g;
|
|
highs.usd = u;
|
|
}
|
|
lastGBP = g;
|
|
lastUSD = u;
|
|
|
|
if (g < lows.gbp) lows.gbp = g;
|
|
if (u < lows.usd) lows.usd = u;
|
|
|
|
if (highs.gbp < g) highs.gbp = g;
|
|
if (highs.usd < u) highs.usd = u;
|
|
|
|
data = {
|
|
lastGBP: lastGBP,
|
|
lastUSD: lastUSD,
|
|
lows: lows,
|
|
highs: highs,
|
|
eclass: eclass,
|
|
balance: balance,
|
|
trend: trend
|
|
};
|
|
}
|
|
data.stub = Math.random(Number.MAX_SAFE_INTEGER).toString(32);
|
|
|
|
this.set('btcdata', data);
|
|
// total = myBTC * g;
|
|
},
|
|
'getBTC': function getBTC() {
|
|
var self = this;
|
|
var url = this.get('url');
|
|
$.ajax({
|
|
'type': 'GET',
|
|
'url': url,
|
|
'data': '',
|
|
'dataType': 'json',
|
|
'timeout': 10000,
|
|
// contentType: ('application/json'),
|
|
'headers': {
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
|
'Access-Control-Allow-Headers': 'Content-Type'
|
|
},
|
|
'success': function success(data) {
|
|
var gbp = data.bpi.GBP.rate_float,
|
|
usd = data.bpi.USD.rate_float;
|
|
var trend = data.trend;
|
|
var btcdata = self.get('btcdata');
|
|
btcdata.gbp = gbp;
|
|
btcdata.usd = usd;
|
|
btcdata.trend = trend;
|
|
self.set('btcdata', btcdata);
|
|
self.recalc();
|
|
},
|
|
'error': function error(xhr, type) {
|
|
void 0;
|
|
void 0;
|
|
void 0;
|
|
}
|
|
});
|
|
},
|
|
'getBalance': function getBalance() {
|
|
var self = this;
|
|
var url = this.get('balanceUrl');
|
|
$.ajax({
|
|
'type': 'GET',
|
|
'url': url,
|
|
'data': '',
|
|
'dataType': 'json',
|
|
'timeout': 10000,
|
|
// contentType: ('application/json'),
|
|
'headers': {
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
|
'Access-Control-Allow-Headers': 'Content-Type'
|
|
},
|
|
'success': function success(data) {
|
|
var balance = data.balance;
|
|
|
|
self.set('balance', balance);
|
|
self.recalc();
|
|
},
|
|
'error': function error(xhr, type) {
|
|
void 0;
|
|
void 0;
|
|
void 0;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
var Bitcoin = Backbone.View.extend({
|
|
'tagName': 'div',
|
|
'initialize': function initialize() {
|
|
_.bindAll(this, 'render');
|
|
this.model.bind('change', this.render);
|
|
this.$btc = $('#btc');
|
|
this.$trend = $('#trend');
|
|
},
|
|
'render': function render() {
|
|
var btcdata = this.model.get('btcdata');
|
|
var balance = this.model.get('balance');
|
|
// console.log(`Balance: ${btcdata.balance.toFixed(4)}`);
|
|
// console.log(btcdata.lastGBP);
|
|
var owned = parseFloat(btcdata.lastGBP) * parseFloat(balance);
|
|
// console.log(`owned: ${owned}`);
|
|
var title = 'High: $' + parseFloat(btcdata.highs.usd.toFixed(2)) + ' / Low $' + parseFloat(btcdata.lows.usd.toFixed(2));
|
|
var trendClass = '';
|
|
|
|
if (btcdata.trend > 1.00) trendClass = 'trendUp';else if (btcdata.trend < 1.00) trendClass = 'trendDown';else trendClass = '';
|
|
|
|
this.$trend.removeClass();
|
|
this.$trend.addClass(trendClass);
|
|
this.$btc.removeClass();
|
|
this.$btc.addClass(btcdata.eclass);
|
|
this.$btc.html('$' + parseFloat(btcdata.lastUSD.toFixed(2)) + ' / £' + parseFloat(btcdata.lastGBP.toFixed(2)) + ' <div>₿' + balance + ' £' + parseFloat(owned.toFixed(2)) + '</div>');
|
|
this.$btc.prop('title', title);
|
|
}
|
|
});
|
|
'use strict';
|
|
|
|
/**
|
|
* Created by mdonnel on 22/03/2017.
|
|
*/
|
|
|
|
var FxModel = Backbone.Model.extend({
|
|
'initialize': function initialize() {
|
|
this.set('url', '/fx');
|
|
this.set('fxdata', {});
|
|
this.update();
|
|
},
|
|
'update': function update() {
|
|
this.getFX();
|
|
var now = new Date();
|
|
var mod = 900000 - now.getTime() % 900000;
|
|
|
|
var fxUpdateFn = function fxUpdateFn() {
|
|
this.update();
|
|
};
|
|
setTimeout(fxUpdateFn.bind(this), mod + 10);
|
|
},
|
|
'getFX': function getFX() {
|
|
var url = this.get('url');
|
|
var self = this;
|
|
$.ajax({
|
|
'type': 'GET',
|
|
'url': url,
|
|
'data': '',
|
|
'dataType': 'json',
|
|
|
|
'timeout': 10000,
|
|
|
|
// contentType: ('application/json'),
|
|
'headers': {
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
|
'Access-Control-Allow-Headers': 'Content-Type'
|
|
|
|
},
|
|
'success': function success(data) {
|
|
var fxdata = {};
|
|
if (data.rates !== undefined) {
|
|
var gpbex = 1 / data.rates.GBP;
|
|
var sekex = gpbex * data.rates.SEK;
|
|
fxdata = {
|
|
'usd': 1,
|
|
'gbp': data.rates.GBP,
|
|
'sek': data.rates.SEK,
|
|
'gpbe': gpbex,
|
|
'sekex': sekex
|
|
};
|
|
}
|
|
|
|
self.set('fxdata', fxdata);
|
|
},
|
|
'error': function error(xhr, type) {
|
|
void 0;
|
|
void 0;
|
|
void 0;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
var FxView = Backbone.View.extend({
|
|
'tagName': 'div',
|
|
'initialize': function initialize() {
|
|
_.bindAll(this, 'render');
|
|
this.model.bind('change', this.render);
|
|
this.$fx = $('#fx');
|
|
},
|
|
'render': function render() {
|
|
var fxdata = this.model.get('fxdata');
|
|
this.$fx.html('£1 = $' + parseFloat(fxdata.gpbe.toFixed(2)) + ' = ' + parseFloat(fxdata.sekex.toFixed(2)) + ' SEK');
|
|
}
|
|
});
|
|
'use strict';
|
|
|
|
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
|
|
|
/**
|
|
*
|
|
* User: Martin Donnelly
|
|
* Date: 2016-10-03
|
|
* Time: 14:20
|
|
*
|
|
*/
|
|
|
|
var TrainModel = Backbone.Model.extend({
|
|
'initialize': function initialize() {
|
|
var fromStation = this.get('from');
|
|
var toStation = this.get('to');
|
|
var url = '/getnexttraintimes?from=' + fromStation + '&to=' + toStation;
|
|
var routeUrl = '/gettrains?from=' + fromStation + '&to=' + toStation;
|
|
var target = fromStation + toStation;
|
|
this.set('url', url);
|
|
this.set('routeUrl', routeUrl);
|
|
this.set('target', target);
|
|
this.set('visible', false);
|
|
this.set('trainData', { 'eta': 'OFF', 'sta': 'OFF' });
|
|
this.update();
|
|
},
|
|
'update': function update() {
|
|
var now = new Date();
|
|
var hours = now.getHours();
|
|
var limit = hours < 6 ? 3600000 : 60000;
|
|
|
|
var mod = limit - now.getTime() % limit;
|
|
|
|
if (hours >= 6) this.getTrain();else this.set('trainData', { 'eta': 'OFF', 'sta': 'OFF' });
|
|
|
|
var trainUpdateFn = function trainUpdateFn() {
|
|
this.update();
|
|
};
|
|
|
|
setTimeout(trainUpdateFn.bind(this), mod + 10);
|
|
},
|
|
'getTrain': function getTrain() {
|
|
var url = this.get('url');
|
|
var self = this;
|
|
$.ajax({
|
|
'type': 'GET',
|
|
'url': url,
|
|
'data': '',
|
|
'dataType': 'json',
|
|
'timeout': 10000,
|
|
'headers': {
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
|
'Access-Control-Allow-Headers': 'Content-Type'
|
|
},
|
|
'success': function success(data) {
|
|
self.set('trainData', data);
|
|
},
|
|
'error': function error(xhr, type) {
|
|
void 0;
|
|
void 0;
|
|
void 0;
|
|
}
|
|
});
|
|
},
|
|
'getRoute': function getRoute() {
|
|
var url = this.get('routeUrl');
|
|
var self = this;
|
|
|
|
if (this.get('visible') === true) this.set('visible', false);else $.ajax({
|
|
'type': 'GET',
|
|
'url': url,
|
|
'data': '',
|
|
'dataType': 'json',
|
|
|
|
'timeout': 10000,
|
|
'headers': {
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
|
'Access-Control-Allow-Headers': 'Content-Type'
|
|
|
|
},
|
|
'success': function success(data) {
|
|
// getTrainsCB(data);
|
|
// console.log('Got', data);
|
|
|
|
self.set('route', data);
|
|
self.set('visible', true);
|
|
},
|
|
'error': function error(xhr, type) {
|
|
void 0;
|
|
void 0;
|
|
void 0;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
var TrainView = Backbone.View.extend({
|
|
'tagName': 'div',
|
|
'initialize': function initialize() {
|
|
_.bindAll(this, 'render');
|
|
this.model.bind('change', this.render);
|
|
this.$trains = $('#trains');
|
|
this.$traininfo = $('#traininfo');
|
|
this.$traintext = $('#trainResults');
|
|
this.$el = this.$trains;
|
|
this.initView();
|
|
},
|
|
'events': {
|
|
'click': 'showTrains'
|
|
},
|
|
'render': function render() {
|
|
var obj = this.model.get('trainData');
|
|
var visible = this.model.get('visible');
|
|
var route = this.model.get('route');
|
|
|
|
var output = obj.eta.toLowerCase() === 'on time' ? obj.sta : obj.eta;
|
|
var status = obj.eta.toLowerCase() === 'on time' ? 'ontime' : 'delayed';
|
|
|
|
this.$button.html(output);
|
|
this.$button.removeClass('delayed').removeClass('ontime').addClass(status);
|
|
|
|
if (visible) {
|
|
var ws = '<div>' + route.locationName + ' TO ' + route.filterLocationName + '</div>\n <table class="mui-table mui-table-bordered">\n <tr><th>Destination</th>\n <th>Time</th>\n <th>Status</th>\n <th>Platform</th></tr>\n ';
|
|
|
|
var services = [];
|
|
if (_typeof(route.trainServices) === 'object' && route.trainServices !== null) {
|
|
var _iteratorNormalCompletion = true;
|
|
var _didIteratorError = false;
|
|
var _iteratorError = undefined;
|
|
|
|
try {
|
|
for (var _iterator = route.trainServices[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
var _item = _step.value;
|
|
|
|
var dest = _item.destination[0];
|
|
var via = dest.via !== null ? '<em>' + dest.via + '</em>' : '';
|
|
var platform = _item.platform !== null ? _item.platform : '💠';
|
|
var time = _item.sta !== null ? _item.sta : 'D ' + _item.std;
|
|
var _status = _item.eta !== null ? _item.eta : _item.etd;
|
|
|
|
services.push({ 'location': dest.locationName, 'time': time, 'status': _status, 'platform': platform, 'cancel': _item.cancelReason, 'type': 'train' });
|
|
if (!_item.isCancelled) ws = ws + '<tr><td>' + dest.locationName + ' ' + via + '</td>\n <td>' + time + '</td>\n <td>' + _status + '</td>\n <td>' + platform + '</td>\n </tr>';else ws = ws + '<tr><td>' + dest.locationName + ' ' + via + '</td><td>' + time + '</td>\n <td colspan="2">\u274C ' + _item.cancelReason + '</td></tr>';
|
|
}
|
|
} catch (err) {
|
|
_didIteratorError = true;
|
|
_iteratorError = err;
|
|
} finally {
|
|
try {
|
|
if (!_iteratorNormalCompletion && _iterator.return) {
|
|
_iterator.return();
|
|
}
|
|
} finally {
|
|
if (_didIteratorError) {
|
|
throw _iteratorError;
|
|
}
|
|
}
|
|
}
|
|
}if (_typeof(route.busServices) === 'object' && route.busServices !== null) {
|
|
var _iteratorNormalCompletion2 = true;
|
|
var _didIteratorError2 = false;
|
|
var _iteratorError2 = undefined;
|
|
|
|
try {
|
|
for (var _iterator2 = route.busServices[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
var _item2 = _step2.value;
|
|
|
|
var _dest = _item2.destination[0];
|
|
var _via = _dest.via !== null ? '<em>' + _dest.via + '</em>' : '';
|
|
var _platform = _item2.platform !== null ? _item2.platform : '';
|
|
var _time = _item2.sta !== null ? _item2.sta : 'D ' + _item2.std;
|
|
var _status2 = _item2.eta !== null ? _item2.eta : _item2.etd;
|
|
services.push({ 'location': _dest.locationName, 'time': _time, 'status': _status2, 'platform': _platform, 'cancel': _item2.cancelReason, 'type': 'bus' });
|
|
// ws = ws + `<div class="mui-row"><div class="mui-col-md-12"><strong>${dest.locationName} Bus</strong> ${via}</div></div>`;
|
|
// ws = ws + '<div class="mui-row"><div class="mui-col-md-12">' + item.sta + '</div></div>';
|
|
ws = ws + '<tr><td>\uD83D\uDE8C ' + _dest.locationName + ' ' + _via + '</td><td>' + _time + '</td><td>' + _status2 + '</td><td>' + _platform + '</td></tr>';
|
|
}
|
|
} catch (err) {
|
|
_didIteratorError2 = true;
|
|
_iteratorError2 = err;
|
|
} finally {
|
|
try {
|
|
if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
|
_iterator2.return();
|
|
}
|
|
} finally {
|
|
if (_didIteratorError2) {
|
|
throw _iteratorError2;
|
|
}
|
|
}
|
|
}
|
|
}ws = ws + '</table>';
|
|
this.$traintext.empty().html(ws);
|
|
this.$traintext.removeClass('mui--hide').addClass('mui--show');
|
|
} else this.$traintext.removeClass('mui--show').addClass('mui--hide');
|
|
},
|
|
'initView': function initView() {
|
|
// el: $('#myView').get(0)
|
|
var self = this;
|
|
var target = this.model.get('target');
|
|
var html = '<div class=\'mui-col-xs-12 mui-col-md-6\'>' + target.toUpperCase() + ': <button class="mui-btn mui-btn--flat" id="' + target + '"></button></div>';
|
|
this.$html = $(html);
|
|
this.$html.on('click', function () {
|
|
// console.log(self)
|
|
self.model.getRoute();
|
|
});
|
|
this.$trains.append(this.$html);
|
|
|
|
// this.el = `#${target}`;
|
|
|
|
this.$button = $('#' + target);
|
|
|
|
var output = 'OFF';
|
|
var status = output === 'on time' ? 'ontime' : 'delayed';
|
|
|
|
this.$button.html(output);
|
|
this.$button.removeClass('delayed').removeClass('ontime').addClass(status);
|
|
|
|
var cevent = 'click #$(target)';
|
|
this.events[cevent] = 'showTrains';
|
|
},
|
|
'showTrains': function showTrains() {
|
|
void 0;
|
|
}
|
|
|
|
});
|
|
'use strict';
|
|
|
|
/**
|
|
*
|
|
* User: Martin Donnelly
|
|
* Date: 2016-10-03
|
|
* Time: 14:20
|
|
*
|
|
*/
|
|
|
|
var WeatherModel = Backbone.Model.extend({
|
|
'initialize': function initialize() {
|
|
var geo = this.get('geo');
|
|
this.set('url', 'https://api.darksky.net/forecast/9ad2a41d420f3cf4960571bb886f710c/' + geo.coords.latitude.toString() + ',' + geo.coords.longitude.toString() + '?units=uk2&exclude=minutely,hourly,alerts,flags');
|
|
this.update();
|
|
},
|
|
'update': function update() {
|
|
var _this = this;
|
|
|
|
this.getWeather();
|
|
var now = new Date();
|
|
var mod = 1800000 - now.getTime() % 1800000;
|
|
var weatherTrigger = function weatherTrigger() {
|
|
_this.update();
|
|
};
|
|
|
|
setTimeout(weatherTrigger.bind(this), mod + 10);
|
|
},
|
|
'getWeather': function getWeather() {
|
|
var self = this;
|
|
$.ajax({
|
|
'type': 'GET',
|
|
'url': self.get('url'),
|
|
'data': '',
|
|
'dataType': 'jsonp',
|
|
'timeout': 10000,
|
|
'context': $('body'),
|
|
'contentType': 'application/json',
|
|
'headers': {
|
|
'Access-Control-Allow-Origin': '*',
|
|
'Access-Control-Allow-Methods': 'PUT, GET, POST, DELETE, OPTIONS',
|
|
'Access-Control-Allow-Headers': 'Content-Type'
|
|
},
|
|
'success': function success(data) {
|
|
var stored = {
|
|
'temperature': data.currently.temperature,
|
|
'icon': data.currently.icon,
|
|
'summary': data.currently.summary,
|
|
'daily': data.daily.summary
|
|
};
|
|
self.set(stored);
|
|
},
|
|
'error': function error(xhr, type) {
|
|
void 0;
|
|
void 0;
|
|
void 0;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
var Weather = Backbone.View.extend({
|
|
'tagName': 'div',
|
|
'initialize': function initialize() {
|
|
_.bindAll(this, 'render');
|
|
this.model.bind('change', this.render);
|
|
this.$weatherText = $('#weatherDescription');
|
|
this.$weatherTemp = $('#temp');
|
|
this.$weatherIcon = $('#weatherIcon');
|
|
},
|
|
'render': function render() {
|
|
void 0;
|
|
|
|
var ws = '<i class="wi wi-forecast-io-' + this.model.get('icon') + '"></i>';
|
|
|
|
this.$weatherTemp.empty().html(parseInt(this.model.get('temperature')) + '°c ');
|
|
this.$weatherText.empty().html(this.model.get('summary'));
|
|
|
|
this.$weatherIcon.empty().html(ws);
|
|
}
|
|
|
|
});
|
|
|
|
var WeatherSlim = Backbone.View.extend({
|
|
'tagName': 'div',
|
|
'initialize': function initialize() {
|
|
_.bindAll(this, 'render');
|
|
this.model.bind('change', this.render);
|
|
this.$weather = $('#weather');
|
|
this.render();
|
|
},
|
|
'render': function render() {
|
|
var summary = this.model.get('summary');
|
|
var temp = this.model.get('temperature');
|
|
var daily = this.model.get('daily');
|
|
|
|
var ws = summary + ' ' + temp + '° <em>' + daily + '</em>';
|
|
|
|
this.$weather.empty().html(ws);
|
|
}
|
|
|
|
});
|
|
'use strict';
|
|
|
|
/**
|
|
* Created by mdonnel on 20/04/2017.
|
|
*/
|
|
/*_.templateSettings = {
|
|
'evaluate': /\{\{(.+?)\}\}/g,
|
|
'interpolate': /\{\{=(.+?)\}\}/g,
|
|
'escape': /\{\{-(.+?)\}\}/g
|
|
};*/
|
|
|
|
Array.prototype.random = function () {
|
|
return this[Math.floor(Math.random() * this.length)];
|
|
};
|
|
|
|
var PasswordView = Backbone.View.extend({
|
|
'el': '#passwords',
|
|
'passwordTemplate': _.template('<div>Long: <%=long%></div><div>Short: <%=short%></div>'),
|
|
'initialize': function initialize() {
|
|
this.alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|
this.whitespace = ['.', '~', '#', '!', '$', '+', '-', '+'];
|
|
this.numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
|
this.left = ['Alabama', 'Alaska', 'Arizona', 'Maryland', 'Nevada', 'Mexico', 'Texas', 'Utah', 'Glasgow', 'Inverness', 'Edinburgh', 'Dumbarton', 'Balloch', 'Renton', 'Cardross', 'Dundee', 'Paisley', 'Hamilton', 'Greenock', 'Falkirk', 'Irvine', 'Renfrew', 'Erskine', 'London', 'Hammersmith', 'Islington', 'Silver', 'Black', 'Yellow', 'Purple', 'White', 'Pink', 'Red', 'Orange', 'Brown', 'Green', 'Blue', 'Amber', 'Aqua', 'Azure', 'Bronze', 'Coral', 'Copper', 'Crimson', 'Cyan', 'Ginger', 'Gold', 'Indigo', 'Jade'];
|
|
|
|
this.right = ['Aganju', 'Cygni', 'Akeron', 'Antares', 'Aragoth', 'Ardus', 'Carpenter', 'Cooper', 'Dahin', 'Capella', 'Endriago', 'Gallina', 'Fenris', 'Freya', 'Glenn', 'Grissom', 'Jotunheim', 'Kailaasa', 'Lagarto', 'Muspelheim', 'Nifleheim', 'Primus', 'Vega', 'Ragnarok', 'Shepard', 'Slayton', 'Tarsis', 'Mercury', 'Venus', 'Mars', 'Earth', 'Terra', 'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Pluto', 'Europa', 'Ganymede', 'Callisto', 'Titan', 'Juno', 'Eridanus', 'Scorpius', 'Crux', 'Cancer', 'Taurus', 'Lyra', 'Andromeda', 'Virgo', 'Aquarius', 'Cygnus', 'Corvus', 'Taurus', 'Draco', 'Perseus', 'Pegasus', 'Gemini', 'Columbia', 'Bootes', 'Orion', 'Deneb', 'Merope', 'Agate', 'Amber', 'Beryl', 'Calcite', 'Citrine', 'Coral', 'Diamond', 'Emerald', 'Garnet', 'Jade', 'Lapis', 'Moonstone', 'Obsidian', 'Onyx', 'Opal', 'Pearl', 'Quartz', 'Ruby', 'Sapphire', 'Topaz', 'Iron', 'Lead', 'Nickel', 'Copper', 'Zinc', 'Tin', 'Manes', 'Argon', 'Neon', 'Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot', 'Golf', 'Hotel', 'India', 'Juliett', 'Kilo', 'Lima', 'Mike', 'November', 'Oscar', 'Papa', 'Quebec', 'Romeo', 'Sierra', 'Tango', 'Uniform', 'Victor', 'Whisky', 'Xray', 'Yankee', 'Zulu'];
|
|
|
|
this.passwordOut = this.$('#passwordOut');
|
|
_.bindAll(this, 'newClick');
|
|
},
|
|
'events': {
|
|
'click #newPassword': 'newClick'
|
|
},
|
|
'numberCluster': numberCluster,
|
|
'randomAmount': randomAmount,
|
|
'newClick': newClick
|
|
|
|
});
|
|
|
|
function randomAmount(i) {
|
|
var str = '';
|
|
|
|
for (var t = 0; t < i; t++) {
|
|
str = str + this.alpha.random();
|
|
}return str;
|
|
}
|
|
|
|
function newClick(e) {
|
|
var long = (this.left.random() + ' ' + this.right.random() + ' ' + this.numberCluster()).split(' ').join(this.whitespace.random());
|
|
var short = (this.randomAmount(5) + ' ' + this.randomAmount(5)).split(' ').join(this.whitespace.random());
|
|
var html = this.passwordTemplate({
|
|
'long': long,
|
|
'short': short
|
|
});
|
|
this.passwordOut.removeClass('mui--hide');
|
|
this.passwordOut.empty().append(html);
|
|
}
|
|
|
|
function numberCluster() {
|
|
return this.numbers.random() + this.numbers.random() + this.numbers.random();
|
|
}
|
|
'use strict';
|
|
|
|
(function () {
|
|
document.title = 'Slack';
|
|
})();
|
|
|
|
var popitout = function popitout(url) {
|
|
var newwindow = window.open(url, 'name', 'height=600,width=570');
|
|
if (window.focus) {
|
|
newwindow.focus();
|
|
}
|
|
return false;
|
|
};
|
|
|
|
var popitoutSmall = function popitoutSmall(url) {
|
|
var newwindow = window.open(url, 'name', 'height=400,width=520');
|
|
if (window.focus) {
|
|
newwindow.focus();
|
|
}
|
|
return false;
|
|
}; |