From dcbc4c90c69e91970871ee377addb1a0f040665b Mon Sep 17 00:00:00 2001 From: unkelpehr Date: Sun, 21 Sep 2014 19:53:57 +0200 Subject: [PATCH] Upgraded fandango, general cleanup --- public/css/default.css | 1 + public/index.html | 2 +- public/js/bootstrap.js | 14 ++--- public/js/cryptalk_modules/$.js | 4 +- public/js/cryptalk_modules/cryptalk.js | 30 +++++------ public/js/cryptalk_modules/queue.js | 60 ++++++++++------------ public/js/cryptalk_modules/sound.js | 3 +- public/js/vendor/fandango.v20140918.min.js | 23 --------- public/js/vendor/fandango.v20140921.min.js | 20 ++++++++ 9 files changed, 73 insertions(+), 84 deletions(-) delete mode 100644 public/js/vendor/fandango.v20140918.min.js create mode 100644 public/js/vendor/fandango.v20140921.min.js diff --git a/public/css/default.css b/public/css/default.css index 810c5ad..cd90c6d 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -55,6 +55,7 @@ body, html { #chat i.error { color: #ff7777; } #chat i.message { color: #eeeeee; } #chat i.nick { color: #99FF99; } +#chat i.fatal { color: #ff7777; } /*------------------------------------*\ INPUT diff --git a/public/index.html b/public/index.html index b286b2c..79e1424 100644 --- a/public/index.html +++ b/public/index.html @@ -20,7 +20,7 @@ - + diff --git a/public/js/bootstrap.js b/public/js/bootstrap.js index ec63521..d0e23d7 100644 --- a/public/js/bootstrap.js +++ b/public/js/bootstrap.js @@ -19,12 +19,8 @@ fandango.defaults({ } }); -// Fetch our modules asynchronously, when the DOM is finished loading. -//define('bootstrap_module', ['domReady'], function (domReady) { -// domReady(function () { -// require(['cryptalk']); -// }); -//}); - -// No need to wait for DOM - the Javascript is at the bottom -require(['cryptalk']); \ No newline at end of file +// Require main cryptalk module. +require(['cryptalk'], function () {}, function (e) { + document.getElementById('chat').innerHTML = '
  • Fatal: An error was thrown during initialization causing the application to stop.
    Examine the logs for more details.
  • '; + throw e; +}); \ No newline at end of file diff --git a/public/js/cryptalk_modules/$.js b/public/js/cryptalk_modules/$.js index cfc522b..bb43e34 100644 --- a/public/js/cryptalk_modules/$.js +++ b/public/js/cryptalk_modules/$.js @@ -1,4 +1,4 @@ -define('$', ['fandango', 'websocket', 'aes'], function (fandango, websocket, aes) { +define(['fandango', 'websocket', 'aes'], function (fandango, websocket, aes) { var exports = { selector: 0, utilities: {}, @@ -10,7 +10,7 @@ define('$', ['fandango', 'websocket', 'aes'], function (fandango, websocket, aes proto = exports.prototype, each = fandango.each; - + // The DOM selector engine exports.selector = function (selector) { var match, diff --git a/public/js/cryptalk_modules/cryptalk.js b/public/js/cryptalk_modules/cryptalk.js index 9668172..daec06c 100644 --- a/public/js/cryptalk_modules/cryptalk.js +++ b/public/js/cryptalk_modules/cryptalk.js @@ -1,11 +1,11 @@ -// Main cryptalk module. Will be called by bootstrap.js when the DOM is ready to interact with. -define('cryptalk', { +// Main cryptalk module +define({ data: { // If no host is given it will default to localhost. host: '' }, compiles: ['$'], - requires: ['templates','sound'] + requires: ['templates', 'sound', 'fandango'] }, function ($, requires, data) { var socket, key, @@ -27,6 +27,7 @@ define('cryptalk', { }, // Shortcut + fandango = requires.fandango; templates = requires.templates; sound = requires.sound; @@ -61,21 +62,19 @@ define('cryptalk', { }, leave: function () { - if( room ) { + if (room) { socket.emit('room:leave', room); } else { post('error', templates.messages.leave_from_nowhere); } - }, count: function () { - if( room ) { + if (room) { socket.emit('room:count'); } else { post('error', templates.messages.not_in_room); } - }, key: function (payload) { @@ -105,14 +104,11 @@ define('cryptalk', { }, mute: function () { - // Set nick + // Invert mute mute = !mute; // Inform that the key has been set - if( mute ) - post('info', $.template(templates.messages.muted )); - else - post('info', $.template(templates.messages.unmuted )); + post('info', $.template(templates.messages[mute ? 'muted' : 'unmuted'])); }, join: function (payload) { @@ -137,7 +133,9 @@ define('cryptalk', { history.push(b); // Shift oldest buffer if we have more than we should keep - if( history.length > history_keep ) history.shift(); + if (history.length > history_keep) { + history.shift(); + } }, // Clear input buffer history @@ -148,7 +146,9 @@ define('cryptalk', { // Clear input buffer clearInput = function() { - setTimeout(function(){components.input[0].value = '';},0); + fandango.subordinate(function () { + components.input[0].value = ''; + }); }, // Handler for the document`s keyDown-event. @@ -168,7 +168,7 @@ define('cryptalk', { // Reset command history clear timer clearTimeout(history_timer); - history_timer = setTimeout(function(){clearHistory()}, 60000); + history_timer = setTimeout(clearHistory, 60000); // Check for escape key, this does nothing but clear the input buffer and reset history position if ( e.keyCode == 27 ) { diff --git a/public/js/cryptalk_modules/queue.js b/public/js/cryptalk_modules/queue.js index ce45d56..8c560db 100644 --- a/public/js/cryptalk_modules/queue.js +++ b/public/js/cryptalk_modules/queue.js @@ -1,48 +1,44 @@ -define('queue', function(){ - - var exports = {}; - - queue = []; - - exports.add_function_delayed = function(d,callback,data) { - - queue.push( - { - func: - function(){ - var finished = callback(); - }, - pushed:Date.now(), - delay:d, - data:data - } - ); +define(function (){ + var exports = {}, + queue = [], + now = function () { + return performance.now() || Date.now(); + }; + exports.add_function_delayed = function(delay, callback, data) { + queue.push({ + func: callback, + pushed: now(), + delay: delay, + data: data + }); } - exports.get = function() { + exports.get = function () { return queue; } - exports.run = function(){ + exports.run = function () { + var i = 0, + current, + lrt_inner; - for(var i=0;i current.delay) { + while (current = queue[i++]) { + if (now() - current.pushed > current.delay) { current.func(); - queue.splice(i,1); + queue.splice(i - 1, 1); } } - if(!queue.length) return; - // Waste a ms to prevent callstack overflow - lrt_inner = Date.now(); - while (Date.now() - lrt_inner < 1) { var a=1+1; }; + if (queue.length) { + // Waste a ms to prevent callstack overflow + lrt_inner = now(); - exports.run(); - + while (now() - lrt_inner < 1) { void 0; }; + + exports.run(); + } } return exports; - }); \ No newline at end of file diff --git a/public/js/cryptalk_modules/sound.js b/public/js/cryptalk_modules/sound.js index 9c87249..953e6cd 100644 --- a/public/js/cryptalk_modules/sound.js +++ b/public/js/cryptalk_modules/sound.js @@ -1,8 +1,7 @@ // Sounds module, used for emitting those annoying bl-up sounds when receiving a message -define('sound',{requires: ['queue']}, function (requires) { +define(['queue'], function (queue) { var exports = { messages: {} }, - queue = requires.queue, ac = false; diff --git a/public/js/vendor/fandango.v20140918.min.js b/public/js/vendor/fandango.v20140918.min.js deleted file mode 100644 index fe61dd3..0000000 --- a/public/js/vendor/fandango.v20140918.min.js +++ /dev/null @@ -1,23 +0,0 @@ -(function(l){var y={"http://":1,"https://":1,"file://":1},u={deepCopy:!0,baseUrl:"",namespace:"default",timeout:1E3,paths:{}},g={};(function(){this.is=function(){var f=Object.prototype.hasOwnProperty,b=Object.prototype.toString,d={array:Array.isArray||function(a){return"[object Array]"==b.call(a)},arraylike:function(a){if(!a||!a.length&&0!==a.length||d.window(a))return!1;var c=a.length;return 1===a.nodeType||d.array(a)||!d["function"](a)&&(0===c||"number"===typeof c&&0a&&Math.floor(a)===a},iterable:function(a){try{1 in obj}catch(c){return!1}return!0},nan:function(a){return d.number(a)&&a!=+a},number:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},object:function(a){return a===Object(a)}, -primitive:function(a){return!0===a||!1===a||null==a||!!{string:1,number:1}[typeof a]},string:function(a){return"string"==typeof a||a instanceof String},undefined:function(a){return void 0===a},untyped:function(a){if(!a||a.nodeType||"[object Object]"!==b.call(a)||d.window(a))return!1;try{if(a.constructor&&!f.call(a,"constructor")&&!f.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}for(var e in a);return void 0===e||f.call(a,e)},window:function(a){return null!=a&&a==a.window}, -empty:function(a){if(a){if(g.is(a,"array"))return 0===a.length;for(var c in a)if(f.call(a,c))return!1}return!0}},e=0,c=["Arguments","Date","Function","RegExp"];for(;4>e;e++)d[c[e].toLowerCase()]=function(a){a="[object "+a+"]";return function(c){return b.call(c)==a}}(c[e]);d.args=d.arguments;d.bool=d["boolean"];d.plain=d.untyped;return function(a,c){if(d["function"](c))return a===c(a);if(!d.string(c))return a===c;if((c=c.toLowerCase())&&d[c])return d[c](a);throw'Unknown type "'+c+'"';}}();this.each= -function(){var f=Array.prototype.some;return function(b,d,e){var c,a;if(void 0===b)return obj;e=e||g;if(f&&b.some===f)return b.some(d,e),b;if(g.is(b,"array")||g.is(b,"arraylike")){c=0;for(a=b.length;c=b.load.length){for(;d=b.onResolved.shift();)d([]);return b.shared}for(;!b.error&&(e=b.load[d++]);)e=b.prefix+e+b.suffix,f[e]?onProgress(b,e,document.getElementById("script::"+e))():(f[e]=1,c=createScriptNode(e),useAttachEvent?c.attachEvent("onreadystatechange",onProgress(b,e,c,!0)):(b.loadListener=onProgress(b,e,c),b.errorListener=onError(b,e,c),c.addEventListener("load",b.loadListener,!1),c.addEventListener("error",b.errorListener,!1)),c.src=e,headElement.appendChild(c))}; -unload=function(b){for(var d=0,e,c;e=b[d++];)(c=document.getElementById("script::"+e))&&c.parentElement.removeChild(c),f[e]=0};return function(b,d){var e,c={load:b,loaded:[],prefix:"",suffix:"",onResolved:[],onRejected:[],onProgress:[],onAlways:[],error:null,shared:e};void 0!==d&&!0!==d||load(c);e={prefix:function(a){c.prefix=a;return e},suffix:function(a){c.suffix=a;return e},now:function(){load(c);return e},and:function(a){c.load=c.load.concat(a);return e},unload:function(a){unload(a);return e}, -isLoaded:function(a){return isLoaded(c,a)},done:function(){c.onResolved=c.onResolved.concat(nativeSlice.call(arguments));return e},fail:function(){c.onRejected=c.onRejected.concat(nativeSlice.call(arguments));return e},progress:function(){c.onProgress=c.onProgress.concat(nativeSlice.call(arguments));return e},always:function(){c.onAlways=c.onAlways.concat(nativeSlice.call(arguments));return e}};e["try"]=e.done;e["catch"]=e.fail;e["finally"]=e.always;e.add=e.and;return e}}(),E=function(){function f(a){var c= -function(){return[]},b={},e={},d,f;for(f=0;d=a[f++];)d.selector&&(c=d.selector),d.prototype&&("function"===typeof d.prototype?d.prototype.call(e):g.merge(e,d.prototype)),d.utilities&&("function"===typeof d.utilities?d.utilities.call(b):g.merge(b,d.utilities));var k=function(a,b,e){var d=0;a=c(a,b);this.context=b||document;this.identify=e;for(this.length=a.length;dr.length&&r.push(p.data? -g.merge(p.deepCopy,{},p.data,h.data):h.data),m>r.length&&r.push(g.merge(p.deepCopy,{},p,h))),p.exports=q?h.factory.apply(p.context,r)||{}:h.factory,void 0===h.exports&&(h.exports=l?p.exports?g.merge(!0,{},l,p.exports):l:p.exports);h.state=3;if(a[b])for(;a[b].length;)a[b].pop()(b)}function d(d,f){var l,h=f.length,q,m,k=[],r={},n,x=[],p,t=void 0!==c[d].timeout?c[d].timeout:u.timeout,s=function(a){1===c[d].state&&(k.push(a),--h||(t&&clearTimeout(p),b(d)))};for(l=0;n=f[l++];)if(q=c[n],!q||1===q.state)(a[n]= -a[n]||[]).push(s),q||((m=u.paths[n])?g.is(m,"array")&&(m=m[0]):m=n,m=v(m),r[m]=n,x.push(m));else if(3===q.state)k.push(n);else if(2===q.state)throw Error('Could not instantiate "'+d+'"; dependency "'+n+'" has been rejected.');if(!((h=f.length)-k.length))return b(d);0a&&Math.floor(a)===a},iterable:function(a){try{1 in obj}catch(b){return!1}return!0},nan:function(a){return e.number(a)&& +a!=+a},number:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},object:function(a){return a===Object(a)},primitive:function(a){return!0===a||!1===a||null==a||!!{string:1,number:1}[typeof a]},string:function(a){return"string"==typeof a||a instanceof String},undefined:function(a){return void 0===a},untyped:function(a){if(!a||a.nodeType||"[object Object]"!==c.call(a)||e.window(a))return!1;try{if(a.constructor&&!f.call(a,"constructor")&&!f.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(b){return!1}for(var d in a); +return void 0===d||f.call(a,d)},window:function(a){return null!=a&&a==a.window},empty:function(a){if(a){if(h.is(a,"array"))return 0===a.length;for(var b in a)if(f.call(a,b))return!1}return!0}},g=0,d=["Arguments","Date","Function","RegExp"];for(;4>g;g++)e[d[g].toLowerCase()]=function(a){a="[object "+a+"]";return function(b){return c.call(b)==a}}(d[g]);e.args=e.arguments;e.bool=e["boolean"];e.plain=e.untyped;return function(a,b){if(e["function"](b))return a===b(a);if(!e.string(b))return a===b;if((b= +b.toLowerCase())&&e[b])return e[b](a);throw'Unknown type "'+b+'"';}}();h.each=function(){var f=Array.prototype.some;return function(c,e,g){var d,a;if(void 0===c)return obj;g=g||h;if(f&&c.some===f)return c.some(e,g),c;if(h.is(c,"array")||h.is(c,"arraylike")){d=0;for(a=c.length;dt.length&&t.push(d.data?h.merge(d.deepCopy,{},d.data,b.data):b.data),p>t.length&&t.push(h.merge(d.deepCopy,{},d,b))),d.exports=m?b.factory.apply(d.context,t)||{}:b.factory,void 0===b.exports&&(b.exports=g?d.exports?h.merge(!0,{},g,d.exports):g:d.exports);b.state=3;if(u[c])for(;u[c].length;)u[c].pop()(c)}return function e(g, +d){var a,b=l[g],m=h.is(b.factory,"function")?b.factory.length:0,p=b.amdStyle,k=[],t,s,r;a=[];var q,n;if(!d&&(b.requires||b.compiles||b.inherits)){b.requires&&z.apply(a,b.requires);b.inherits&&z.apply(a,b.inherits);b.compiles&&z.apply(a,b.compiles);for(q=0;n=a[q++];)if(l[n])if(3===l[n].state)a.splice(--q,1);else if(2===l[n].state)throw Error('Could not instantiate "'+UID+'"; dependency "'+dependency+'" has been rejected.');if(0