commit
e45edff613
@ -1,9 +1,8 @@
|
|||||||
# built by tools
|
# built by tools
|
||||||
client/js/libs.min.js
|
client/js/bundle.js
|
||||||
client/js/lounge.templates.js
|
client/js/bundle.vendor.js
|
||||||
|
|
||||||
# third party
|
# third party
|
||||||
client/js/libs/jquery/*.js
|
client/js/libs/jquery/*.js
|
||||||
client/js/libs/*.js
|
|
||||||
|
|
||||||
coverage/
|
coverage/
|
||||||
|
@ -44,10 +44,5 @@ rules:
|
|||||||
|
|
||||||
globals:
|
globals:
|
||||||
log: false
|
log: false
|
||||||
$: false
|
|
||||||
Favico: false
|
|
||||||
Handlebars: false
|
|
||||||
io: false
|
|
||||||
Mousetrap: false
|
|
||||||
|
|
||||||
extends: eslint:recommended
|
extends: eslint:recommended
|
||||||
|
7
.gitignore
vendored
7
.gitignore
vendored
@ -6,6 +6,7 @@ coverage/
|
|||||||
# Built assets created at npm install/prepublish time
|
# Built assets created at npm install/prepublish time
|
||||||
# See https://docs.npmjs.com/misc/scripts
|
# See https://docs.npmjs.com/misc/scripts
|
||||||
client/fonts/
|
client/fonts/
|
||||||
client/js/libs.min.js.map
|
client/js/bundle.js
|
||||||
client/js/libs.min.js
|
client/js/bundle.js.map
|
||||||
client/js/lounge.templates.js
|
client/js/bundle.vendor.js
|
||||||
|
client/js/bundle.vendor.js.map
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
instrumentation:
|
instrumentation:
|
||||||
include-all-sources: true
|
include-all-sources: true
|
||||||
excludes:
|
excludes:
|
||||||
- Gruntfile.js
|
- client/js/bundle.js
|
||||||
- client/js/libs/*.js
|
- client/js/bundle.vendor.js
|
||||||
- client/js/libs/jquery/*.js
|
|
||||||
- client/js/libs.min.js
|
|
||||||
- client/js/lounge.js
|
- client/js/lounge.js
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
# npm-debug.log and node_modules/ are ignored by default.
|
# npm-debug.log and node_modules/ are ignored by default.
|
||||||
# See https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package
|
# See https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package
|
||||||
|
|
||||||
|
client/js/bundle.vendor.js.map
|
||||||
client/views/
|
client/views/
|
||||||
coverage/
|
coverage/
|
||||||
scripts/
|
scripts/
|
||||||
@ -16,4 +17,3 @@ test/
|
|||||||
.stylelintrc
|
.stylelintrc
|
||||||
.travis.yml
|
.travis.yml
|
||||||
appveyor.yml
|
appveyor.yml
|
||||||
Gruntfile.js
|
|
||||||
|
3
client/.eslintrc.yml
Normal file
3
client/.eslintrc.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
parserOptions:
|
||||||
|
sourceType: module
|
@ -386,10 +386,8 @@
|
|||||||
<ul id="context-menu"></ul>
|
<ul id="context-menu"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="socket.io/socket.io.js"></script>
|
<script src="js/bundle.vendor.js"></script>
|
||||||
<script src="js/libs.min.js"></script>
|
<script src="js/bundle.js"></script>
|
||||||
<script src="js/lounge.templates.js"></script>
|
|
||||||
<script src="js/lounge.js"></script>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,13 +1,9 @@
|
|||||||
"use strict";
|
// Generates a string from "color-1" to "color-32" based on an input string
|
||||||
|
module.exports = function(str) {
|
||||||
Handlebars.registerHelper(
|
var hash = 0;
|
||||||
// Generates a string from "color-1" to "color-32" based on an input string
|
for (var i = 0; i < str.length; i++) {
|
||||||
"colorClass", function(str) {
|
hash += str.charCodeAt(i);
|
||||||
var hash = 0;
|
|
||||||
for (var i = 0; i < str.length; i++) {
|
|
||||||
hash += str.charCodeAt(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return "color-" + (1 + hash % 32);
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
return "color-" + (1 + hash % 32);
|
||||||
|
};
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
var diff;
|
var diff;
|
||||||
|
|
||||||
Handlebars.registerHelper(
|
module.exports = function(a, opt) {
|
||||||
"diff", function(a, opt) {
|
if (a !== diff) {
|
||||||
if (a !== diff) {
|
diff = a;
|
||||||
diff = a;
|
return opt.fn(this);
|
||||||
return opt.fn(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return opt.inverse(this);
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
return opt.inverse(this);
|
||||||
|
};
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
"use strict";
|
module.exports = function(a, b, opt) {
|
||||||
|
a = a.toString();
|
||||||
Handlebars.registerHelper(
|
b = b.toString();
|
||||||
"equal", function(a, b, opt) {
|
if (a === b) {
|
||||||
a = a.toString();
|
return opt.fn(this);
|
||||||
b = b.toString();
|
|
||||||
if (a === b) {
|
|
||||||
return opt.fn(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return opt.inverse(this);
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
return opt.inverse(this);
|
||||||
|
};
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
"use strict";
|
module.exports = function(time) {
|
||||||
|
|
||||||
Handlebars.registerHelper("localedate", function(time) {
|
|
||||||
return new Date(time).toLocaleDateString();
|
return new Date(time).toLocaleDateString();
|
||||||
});
|
};
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
"use strict";
|
module.exports = function(time) {
|
||||||
|
|
||||||
Handlebars.registerHelper("localetime", function(time) {
|
|
||||||
return new Date(time).toLocaleString();
|
return new Date(time).toLocaleString();
|
||||||
});
|
};
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
"use strict";
|
module.exports = function(mode) {
|
||||||
|
var modes = {
|
||||||
Handlebars.registerHelper(
|
"~": "owner",
|
||||||
"modes", function(mode) {
|
"&": "admin",
|
||||||
var modes = {
|
"!": "admin",
|
||||||
"~": "owner",
|
"@": "op",
|
||||||
"&": "admin",
|
"%": "half-op",
|
||||||
"!": "admin",
|
"+": "voice",
|
||||||
"@": "op",
|
"": "normal"
|
||||||
"%": "half-op",
|
};
|
||||||
"+": "voice",
|
return modes[mode];
|
||||||
"": "normal"
|
};
|
||||||
};
|
|
||||||
return modes[mode];
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
"use strict";
|
import Handlebars from "handlebars/runtime";
|
||||||
|
import URI from "urijs";
|
||||||
|
|
||||||
Handlebars.registerHelper(
|
module.exports = function(text) {
|
||||||
"parse", function(text) {
|
text = Handlebars.Utils.escapeExpression(text);
|
||||||
text = Handlebars.Utils.escapeExpression(text);
|
text = colors(text);
|
||||||
text = colors(text);
|
text = channels(text);
|
||||||
text = channels(text);
|
text = uri(text);
|
||||||
text = uri(text);
|
return text;
|
||||||
return text;
|
};
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
function uri(text) {
|
function uri(text) {
|
||||||
return window.URI.withinString(text, function(url) {
|
return URI.withinString(text, function(url) {
|
||||||
if (url.indexOf("javascript:") === 0) {
|
if (url.indexOf("javascript:") === 0) {
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
"use strict";
|
module.exports = function(count) {
|
||||||
|
if (count < 1000) {
|
||||||
Handlebars.registerHelper(
|
return count;
|
||||||
"roundBadgeNumber", function(count) {
|
|
||||||
if (count < 1000) {
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (count / 1000).toFixed(2).slice(0, -1) + "k";
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
return (count / 1000).toFixed(2).slice(0, -1) + "k";
|
||||||
|
};
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
"use strict";
|
module.exports = function(context) {
|
||||||
|
return window.JSON.stringify(context);
|
||||||
Handlebars.registerHelper(
|
};
|
||||||
"toJSON", function(context) {
|
|
||||||
return JSON.stringify(context);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
@ -1,19 +1,15 @@
|
|||||||
"use strict";
|
module.exports = function(time) {
|
||||||
|
time = new Date(time);
|
||||||
|
var h = time.getHours();
|
||||||
|
var m = time.getMinutes();
|
||||||
|
|
||||||
Handlebars.registerHelper(
|
if (h < 10) {
|
||||||
"tz", function(time) {
|
h = "0" + h;
|
||||||
time = new Date(time);
|
|
||||||
var h = time.getHours();
|
|
||||||
var m = time.getMinutes();
|
|
||||||
|
|
||||||
if (h < 10) {
|
|
||||||
h = "0" + h;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m < 10) {
|
|
||||||
m = "0" + m;
|
|
||||||
}
|
|
||||||
|
|
||||||
return h + ":" + m;
|
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
if (m < 10) {
|
||||||
|
m = "0" + m;
|
||||||
|
}
|
||||||
|
|
||||||
|
return h + ":" + m;
|
||||||
|
};
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
"use strict";
|
module.exports = function(count) {
|
||||||
|
return count + " " + (count === 1 ? "user" : "users");
|
||||||
Handlebars.registerHelper(
|
};
|
||||||
"users", function(count) {
|
|
||||||
return count + " " + (count === 1 ? "user" : "users");
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
9190
client/js/libs/jquery.js
vendored
9190
client/js/libs/jquery.js
vendored
File diff suppressed because it is too large
Load Diff
2
client/js/libs/jquery/inputhistory.js
vendored
2
client/js/libs/jquery/inputhistory.js
vendored
@ -1,3 +1,5 @@
|
|||||||
|
import jQuery from "jquery";
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* inputhistory
|
* inputhistory
|
||||||
* https://github.com/erming/inputhistory
|
* https://github.com/erming/inputhistory
|
||||||
|
4491
client/js/libs/jquery/jquery-ui.js
vendored
4491
client/js/libs/jquery/jquery-ui.js
vendored
File diff suppressed because it is too large
Load Diff
953
client/js/libs/jquery/mousetrap.js
vendored
953
client/js/libs/jquery/mousetrap.js
vendored
@ -1,953 +0,0 @@
|
|||||||
/*global define:false */
|
|
||||||
/**
|
|
||||||
* Copyright 2013 Craig Campbell
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*
|
|
||||||
* Mousetrap is a simple keyboard shortcut library for Javascript with
|
|
||||||
* no external dependencies
|
|
||||||
*
|
|
||||||
* @version 1.4.6
|
|
||||||
* @url craig.is/killing/mice
|
|
||||||
*/
|
|
||||||
(function(window, document, undefined) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* mapping of special keycodes to their corresponding keys
|
|
||||||
*
|
|
||||||
* everything in this dictionary cannot use keypress events
|
|
||||||
* so it has to be here to map to the correct keycodes for
|
|
||||||
* keyup/keydown events
|
|
||||||
*
|
|
||||||
* @type {Object}
|
|
||||||
*/
|
|
||||||
var _MAP = {
|
|
||||||
8: 'backspace',
|
|
||||||
9: 'tab',
|
|
||||||
13: 'enter',
|
|
||||||
16: 'shift',
|
|
||||||
17: 'ctrl',
|
|
||||||
18: 'alt',
|
|
||||||
20: 'capslock',
|
|
||||||
27: 'esc',
|
|
||||||
32: 'space',
|
|
||||||
33: 'pageup',
|
|
||||||
34: 'pagedown',
|
|
||||||
35: 'end',
|
|
||||||
36: 'home',
|
|
||||||
37: 'left',
|
|
||||||
38: 'up',
|
|
||||||
39: 'right',
|
|
||||||
40: 'down',
|
|
||||||
45: 'ins',
|
|
||||||
46: 'del',
|
|
||||||
91: 'meta',
|
|
||||||
93: 'meta',
|
|
||||||
224: 'meta'
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* mapping for special characters so they can support
|
|
||||||
*
|
|
||||||
* this dictionary is only used incase you want to bind a
|
|
||||||
* keyup or keydown event to one of these keys
|
|
||||||
*
|
|
||||||
* @type {Object}
|
|
||||||
*/
|
|
||||||
_KEYCODE_MAP = {
|
|
||||||
106: '*',
|
|
||||||
107: '+',
|
|
||||||
109: '-',
|
|
||||||
110: '.',
|
|
||||||
111 : '/',
|
|
||||||
186: ';',
|
|
||||||
187: '=',
|
|
||||||
188: ',',
|
|
||||||
189: '-',
|
|
||||||
190: '.',
|
|
||||||
191: '/',
|
|
||||||
192: '`',
|
|
||||||
219: '[',
|
|
||||||
220: '\\',
|
|
||||||
221: ']',
|
|
||||||
222: '\''
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this is a mapping of keys that require shift on a US keypad
|
|
||||||
* back to the non shift equivelents
|
|
||||||
*
|
|
||||||
* this is so you can use keyup events with these keys
|
|
||||||
*
|
|
||||||
* note that this will only work reliably on US keyboards
|
|
||||||
*
|
|
||||||
* @type {Object}
|
|
||||||
*/
|
|
||||||
_SHIFT_MAP = {
|
|
||||||
'~': '`',
|
|
||||||
'!': '1',
|
|
||||||
'@': '2',
|
|
||||||
'#': '3',
|
|
||||||
'$': '4',
|
|
||||||
'%': '5',
|
|
||||||
'^': '6',
|
|
||||||
'&': '7',
|
|
||||||
'*': '8',
|
|
||||||
'(': '9',
|
|
||||||
')': '0',
|
|
||||||
'_': '-',
|
|
||||||
'+': '=',
|
|
||||||
':': ';',
|
|
||||||
'\"': '\'',
|
|
||||||
'<': ',',
|
|
||||||
'>': '.',
|
|
||||||
'?': '/',
|
|
||||||
'|': '\\'
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* this is a list of special strings you can use to map
|
|
||||||
* to modifier keys when you specify your keyboard shortcuts
|
|
||||||
*
|
|
||||||
* @type {Object}
|
|
||||||
*/
|
|
||||||
_SPECIAL_ALIASES = {
|
|
||||||
'option': 'alt',
|
|
||||||
'command': 'meta',
|
|
||||||
'return': 'enter',
|
|
||||||
'escape': 'esc',
|
|
||||||
'mod': /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? 'meta' : 'ctrl'
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* variable to store the flipped version of _MAP from above
|
|
||||||
* needed to check if we should use keypress or not when no action
|
|
||||||
* is specified
|
|
||||||
*
|
|
||||||
* @type {Object|undefined}
|
|
||||||
*/
|
|
||||||
_REVERSE_MAP,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* a list of all the callbacks setup via Mousetrap.bind()
|
|
||||||
*
|
|
||||||
* @type {Object}
|
|
||||||
*/
|
|
||||||
_callbacks = {},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* direct map of string combinations to callbacks used for trigger()
|
|
||||||
*
|
|
||||||
* @type {Object}
|
|
||||||
*/
|
|
||||||
_directMap = {},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* keeps track of what level each sequence is at since multiple
|
|
||||||
* sequences can start out with the same sequence
|
|
||||||
*
|
|
||||||
* @type {Object}
|
|
||||||
*/
|
|
||||||
_sequenceLevels = {},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* variable to store the setTimeout call
|
|
||||||
*
|
|
||||||
* @type {null|number}
|
|
||||||
*/
|
|
||||||
_resetTimer,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* temporary state where we will ignore the next keyup
|
|
||||||
*
|
|
||||||
* @type {boolean|string}
|
|
||||||
*/
|
|
||||||
_ignoreNextKeyup = false,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* temporary state where we will ignore the next keypress
|
|
||||||
*
|
|
||||||
* @type {boolean}
|
|
||||||
*/
|
|
||||||
_ignoreNextKeypress = false,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* are we currently inside of a sequence?
|
|
||||||
* type of action ("keyup" or "keydown" or "keypress") or false
|
|
||||||
*
|
|
||||||
* @type {boolean|string}
|
|
||||||
*/
|
|
||||||
_nextExpectedAction = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* loop through the f keys, f1 to f19 and add them to the map
|
|
||||||
* programatically
|
|
||||||
*/
|
|
||||||
for (var i = 1; i < 20; ++i) {
|
|
||||||
_MAP[111 + i] = 'f' + i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* loop through to map numbers on the numeric keypad
|
|
||||||
*/
|
|
||||||
for (i = 0; i <= 9; ++i) {
|
|
||||||
_MAP[i + 96] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cross browser add event method
|
|
||||||
*
|
|
||||||
* @param {Element|HTMLDocument} object
|
|
||||||
* @param {string} type
|
|
||||||
* @param {Function} callback
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function _addEvent(object, type, callback) {
|
|
||||||
if (object.addEventListener) {
|
|
||||||
object.addEventListener(type, callback, false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
object.attachEvent('on' + type, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* takes the event and returns the key character
|
|
||||||
*
|
|
||||||
* @param {Event} e
|
|
||||||
* @return {string}
|
|
||||||
*/
|
|
||||||
function _characterFromEvent(e) {
|
|
||||||
|
|
||||||
// for keypress events we should return the character as is
|
|
||||||
if (e.type == 'keypress') {
|
|
||||||
var character = String.fromCharCode(e.which);
|
|
||||||
|
|
||||||
// if the shift key is not pressed then it is safe to assume
|
|
||||||
// that we want the character to be lowercase. this means if
|
|
||||||
// you accidentally have caps lock on then your key bindings
|
|
||||||
// will continue to work
|
|
||||||
//
|
|
||||||
// the only side effect that might not be desired is if you
|
|
||||||
// bind something like 'A' cause you want to trigger an
|
|
||||||
// event when capital A is pressed caps lock will no longer
|
|
||||||
// trigger the event. shift+a will though.
|
|
||||||
if (!e.shiftKey) {
|
|
||||||
character = character.toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
return character;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for non keypress events the special maps are needed
|
|
||||||
if (_MAP[e.which]) {
|
|
||||||
return _MAP[e.which];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_KEYCODE_MAP[e.which]) {
|
|
||||||
return _KEYCODE_MAP[e.which];
|
|
||||||
}
|
|
||||||
|
|
||||||
// if it is not in the special map
|
|
||||||
|
|
||||||
// with keydown and keyup events the character seems to always
|
|
||||||
// come in as an uppercase character whether you are pressing shift
|
|
||||||
// or not. we should make sure it is always lowercase for comparisons
|
|
||||||
return String.fromCharCode(e.which).toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* checks if two arrays are equal
|
|
||||||
*
|
|
||||||
* @param {Array} modifiers1
|
|
||||||
* @param {Array} modifiers2
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
function _modifiersMatch(modifiers1, modifiers2) {
|
|
||||||
return modifiers1.sort().join(',') === modifiers2.sort().join(',');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* resets all sequence counters except for the ones passed in
|
|
||||||
*
|
|
||||||
* @param {Object} doNotReset
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function _resetSequences(doNotReset) {
|
|
||||||
doNotReset = doNotReset || {};
|
|
||||||
|
|
||||||
var activeSequences = false,
|
|
||||||
key;
|
|
||||||
|
|
||||||
for (key in _sequenceLevels) {
|
|
||||||
if (doNotReset[key]) {
|
|
||||||
activeSequences = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
_sequenceLevels[key] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!activeSequences) {
|
|
||||||
_nextExpectedAction = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* finds all callbacks that match based on the keycode, modifiers,
|
|
||||||
* and action
|
|
||||||
*
|
|
||||||
* @param {string} character
|
|
||||||
* @param {Array} modifiers
|
|
||||||
* @param {Event|Object} e
|
|
||||||
* @param {string=} sequenceName - name of the sequence we are looking for
|
|
||||||
* @param {string=} combination
|
|
||||||
* @param {number=} level
|
|
||||||
* @returns {Array}
|
|
||||||
*/
|
|
||||||
function _getMatches(character, modifiers, e, sequenceName, combination, level) {
|
|
||||||
var i,
|
|
||||||
callback,
|
|
||||||
matches = [],
|
|
||||||
action = e.type;
|
|
||||||
|
|
||||||
// if there are no events related to this keycode
|
|
||||||
if (!_callbacks[character]) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// if a modifier key is coming up on its own we should allow it
|
|
||||||
if (action == 'keyup' && _isModifier(character)) {
|
|
||||||
modifiers = [character];
|
|
||||||
}
|
|
||||||
|
|
||||||
// loop through all callbacks for the key that was pressed
|
|
||||||
// and see if any of them match
|
|
||||||
for (i = 0; i < _callbacks[character].length; ++i) {
|
|
||||||
callback = _callbacks[character][i];
|
|
||||||
|
|
||||||
// if a sequence name is not specified, but this is a sequence at
|
|
||||||
// the wrong level then move onto the next match
|
|
||||||
if (!sequenceName && callback.seq && _sequenceLevels[callback.seq] != callback.level) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the action we are looking for doesn't match the action we got
|
|
||||||
// then we should keep going
|
|
||||||
if (action != callback.action) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if this is a keypress event and the meta key and control key
|
|
||||||
// are not pressed that means that we need to only look at the
|
|
||||||
// character, otherwise check the modifiers as well
|
|
||||||
//
|
|
||||||
// chrome will not fire a keypress if meta or control is down
|
|
||||||
// safari will fire a keypress if meta or meta+shift is down
|
|
||||||
// firefox will fire a keypress if meta or control is down
|
|
||||||
if ((action == 'keypress' && !e.metaKey && !e.ctrlKey) || _modifiersMatch(modifiers, callback.modifiers)) {
|
|
||||||
|
|
||||||
// when you bind a combination or sequence a second time it
|
|
||||||
// should overwrite the first one. if a sequenceName or
|
|
||||||
// combination is specified in this call it does just that
|
|
||||||
//
|
|
||||||
// @todo make deleting its own method?
|
|
||||||
var deleteCombo = !sequenceName && callback.combo == combination;
|
|
||||||
var deleteSequence = sequenceName && callback.seq == sequenceName && callback.level == level;
|
|
||||||
if (deleteCombo || deleteSequence) {
|
|
||||||
_callbacks[character].splice(i, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
matches.push(callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return matches;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* takes a key event and figures out what the modifiers are
|
|
||||||
*
|
|
||||||
* @param {Event} e
|
|
||||||
* @returns {Array}
|
|
||||||
*/
|
|
||||||
function _eventModifiers(e) {
|
|
||||||
var modifiers = [];
|
|
||||||
|
|
||||||
if (e.shiftKey) {
|
|
||||||
modifiers.push('shift');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.altKey) {
|
|
||||||
modifiers.push('alt');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.ctrlKey) {
|
|
||||||
modifiers.push('ctrl');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.metaKey) {
|
|
||||||
modifiers.push('meta');
|
|
||||||
}
|
|
||||||
|
|
||||||
return modifiers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* prevents default for this event
|
|
||||||
*
|
|
||||||
* @param {Event} e
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function _preventDefault(e) {
|
|
||||||
if (e.preventDefault) {
|
|
||||||
e.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
e.returnValue = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* stops propogation for this event
|
|
||||||
*
|
|
||||||
* @param {Event} e
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function _stopPropagation(e) {
|
|
||||||
if (e.stopPropagation) {
|
|
||||||
e.stopPropagation();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
e.cancelBubble = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* actually calls the callback function
|
|
||||||
*
|
|
||||||
* if your callback function returns false this will use the jquery
|
|
||||||
* convention - prevent default and stop propogation on the event
|
|
||||||
*
|
|
||||||
* @param {Function} callback
|
|
||||||
* @param {Event} e
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function _fireCallback(callback, e, combo, sequence) {
|
|
||||||
|
|
||||||
// if this event should not happen stop here
|
|
||||||
if (Mousetrap.stopCallback(e, e.target || e.srcElement, combo, sequence)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (callback(e, combo) === false) {
|
|
||||||
_preventDefault(e);
|
|
||||||
_stopPropagation(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* handles a character key event
|
|
||||||
*
|
|
||||||
* @param {string} character
|
|
||||||
* @param {Array} modifiers
|
|
||||||
* @param {Event} e
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function _handleKey(character, modifiers, e) {
|
|
||||||
var callbacks = _getMatches(character, modifiers, e),
|
|
||||||
i,
|
|
||||||
doNotReset = {},
|
|
||||||
maxLevel = 0,
|
|
||||||
processedSequenceCallback = false;
|
|
||||||
|
|
||||||
// Calculate the maxLevel for sequences so we can only execute the longest callback sequence
|
|
||||||
for (i = 0; i < callbacks.length; ++i) {
|
|
||||||
if (callbacks[i].seq) {
|
|
||||||
maxLevel = Math.max(maxLevel, callbacks[i].level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// loop through matching callbacks for this key event
|
|
||||||
for (i = 0; i < callbacks.length; ++i) {
|
|
||||||
|
|
||||||
// fire for all sequence callbacks
|
|
||||||
// this is because if for example you have multiple sequences
|
|
||||||
// bound such as "g i" and "g t" they both need to fire the
|
|
||||||
// callback for matching g cause otherwise you can only ever
|
|
||||||
// match the first one
|
|
||||||
if (callbacks[i].seq) {
|
|
||||||
|
|
||||||
// only fire callbacks for the maxLevel to prevent
|
|
||||||
// subsequences from also firing
|
|
||||||
//
|
|
||||||
// for example 'a option b' should not cause 'option b' to fire
|
|
||||||
// even though 'option b' is part of the other sequence
|
|
||||||
//
|
|
||||||
// any sequences that do not match here will be discarded
|
|
||||||
// below by the _resetSequences call
|
|
||||||
if (callbacks[i].level != maxLevel) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
processedSequenceCallback = true;
|
|
||||||
|
|
||||||
// keep a list of which sequences were matches for later
|
|
||||||
doNotReset[callbacks[i].seq] = 1;
|
|
||||||
_fireCallback(callbacks[i].callback, e, callbacks[i].combo, callbacks[i].seq);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if there were no sequence matches but we are still here
|
|
||||||
// that means this is a regular match so we should fire that
|
|
||||||
if (!processedSequenceCallback) {
|
|
||||||
_fireCallback(callbacks[i].callback, e, callbacks[i].combo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the key you pressed matches the type of sequence without
|
|
||||||
// being a modifier (ie "keyup" or "keypress") then we should
|
|
||||||
// reset all sequences that were not matched by this event
|
|
||||||
//
|
|
||||||
// this is so, for example, if you have the sequence "h a t" and you
|
|
||||||
// type "h e a r t" it does not match. in this case the "e" will
|
|
||||||
// cause the sequence to reset
|
|
||||||
//
|
|
||||||
// modifier keys are ignored because you can have a sequence
|
|
||||||
// that contains modifiers such as "enter ctrl+space" and in most
|
|
||||||
// cases the modifier key will be pressed before the next key
|
|
||||||
//
|
|
||||||
// also if you have a sequence such as "ctrl+b a" then pressing the
|
|
||||||
// "b" key will trigger a "keypress" and a "keydown"
|
|
||||||
//
|
|
||||||
// the "keydown" is expected when there is a modifier, but the
|
|
||||||
// "keypress" ends up matching the _nextExpectedAction since it occurs
|
|
||||||
// after and that causes the sequence to reset
|
|
||||||
//
|
|
||||||
// we ignore keypresses in a sequence that directly follow a keydown
|
|
||||||
// for the same character
|
|
||||||
var ignoreThisKeypress = e.type == 'keypress' && _ignoreNextKeypress;
|
|
||||||
if (e.type == _nextExpectedAction && !_isModifier(character) && !ignoreThisKeypress) {
|
|
||||||
_resetSequences(doNotReset);
|
|
||||||
}
|
|
||||||
|
|
||||||
_ignoreNextKeypress = processedSequenceCallback && e.type == 'keydown';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* handles a keydown event
|
|
||||||
*
|
|
||||||
* @param {Event} e
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function _handleKeyEvent(e) {
|
|
||||||
|
|
||||||
// normalize e.which for key events
|
|
||||||
// @see http://stackoverflow.com/questions/4285627/javascript-keycode-vs-charcode-utter-confusion
|
|
||||||
if (typeof e.which !== 'number') {
|
|
||||||
e.which = e.keyCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
var character = _characterFromEvent(e);
|
|
||||||
|
|
||||||
// no character found then stop
|
|
||||||
if (!character) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// need to use === for the character check because the character can be 0
|
|
||||||
if (e.type == 'keyup' && _ignoreNextKeyup === character) {
|
|
||||||
_ignoreNextKeyup = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Mousetrap.handleKey(character, _eventModifiers(e), e);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* determines if the keycode specified is a modifier key or not
|
|
||||||
*
|
|
||||||
* @param {string} key
|
|
||||||
* @returns {boolean}
|
|
||||||
*/
|
|
||||||
function _isModifier(key) {
|
|
||||||
return key == 'shift' || key == 'ctrl' || key == 'alt' || key == 'meta';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* called to set a 1 second timeout on the specified sequence
|
|
||||||
*
|
|
||||||
* this is so after each key press in the sequence you have 1 second
|
|
||||||
* to press the next key before you have to start over
|
|
||||||
*
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function _resetSequenceTimer() {
|
|
||||||
clearTimeout(_resetTimer);
|
|
||||||
_resetTimer = setTimeout(_resetSequences, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* reverses the map lookup so that we can look for specific keys
|
|
||||||
* to see what can and can't use keypress
|
|
||||||
*
|
|
||||||
* @return {Object}
|
|
||||||
*/
|
|
||||||
function _getReverseMap() {
|
|
||||||
if (!_REVERSE_MAP) {
|
|
||||||
_REVERSE_MAP = {};
|
|
||||||
for (var key in _MAP) {
|
|
||||||
|
|
||||||
// pull out the numeric keypad from here cause keypress should
|
|
||||||
// be able to detect the keys from the character
|
|
||||||
if (key > 95 && key < 112) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_MAP.hasOwnProperty(key)) {
|
|
||||||
_REVERSE_MAP[_MAP[key]] = key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return _REVERSE_MAP;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* picks the best action based on the key combination
|
|
||||||
*
|
|
||||||
* @param {string} key - character for key
|
|
||||||
* @param {Array} modifiers
|
|
||||||
* @param {string=} action passed in
|
|
||||||
*/
|
|
||||||
function _pickBestAction(key, modifiers, action) {
|
|
||||||
|
|
||||||
// if no action was picked in we should try to pick the one
|
|
||||||
// that we think would work best for this key
|
|
||||||
if (!action) {
|
|
||||||
action = _getReverseMap()[key] ? 'keydown' : 'keypress';
|
|
||||||
}
|
|
||||||
|
|
||||||
// modifier keys don't work as expected with keypress,
|
|
||||||
// switch to keydown
|
|
||||||
if (action == 'keypress' && modifiers.length) {
|
|
||||||
action = 'keydown';
|
|
||||||
}
|
|
||||||
|
|
||||||
return action;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* binds a key sequence to an event
|
|
||||||
*
|
|
||||||
* @param {string} combo - combo specified in bind call
|
|
||||||
* @param {Array} keys
|
|
||||||
* @param {Function} callback
|
|
||||||
* @param {string=} action
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function _bindSequence(combo, keys, callback, action) {
|
|
||||||
|
|
||||||
// start off by adding a sequence level record for this combination
|
|
||||||
// and setting the level to 0
|
|
||||||
_sequenceLevels[combo] = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* callback to increase the sequence level for this sequence and reset
|
|
||||||
* all other sequences that were active
|
|
||||||
*
|
|
||||||
* @param {string} nextAction
|
|
||||||
* @returns {Function}
|
|
||||||
*/
|
|
||||||
function _increaseSequence(nextAction) {
|
|
||||||
return function() {
|
|
||||||
_nextExpectedAction = nextAction;
|
|
||||||
++_sequenceLevels[combo];
|
|
||||||
_resetSequenceTimer();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* wraps the specified callback inside of another function in order
|
|
||||||
* to reset all sequence counters as soon as this sequence is done
|
|
||||||
*
|
|
||||||
* @param {Event} e
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function _callbackAndReset(e) {
|
|
||||||
_fireCallback(callback, e, combo);
|
|
||||||
|
|
||||||
// we should ignore the next key up if the action is key down
|
|
||||||
// or keypress. this is so if you finish a sequence and
|
|
||||||
// release the key the final key will not trigger a keyup
|
|
||||||
if (action !== 'keyup') {
|
|
||||||
_ignoreNextKeyup = _characterFromEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// weird race condition if a sequence ends with the key
|
|
||||||
// another sequence begins with
|
|
||||||
setTimeout(_resetSequences, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// loop through keys one at a time and bind the appropriate callback
|
|
||||||
// function. for any key leading up to the final one it should
|
|
||||||
// increase the sequence. after the final, it should reset all sequences
|
|
||||||
//
|
|
||||||
// if an action is specified in the original bind call then that will
|
|
||||||
// be used throughout. otherwise we will pass the action that the
|
|
||||||
// next key in the sequence should match. this allows a sequence
|
|
||||||
// to mix and match keypress and keydown events depending on which
|
|
||||||
// ones are better suited to the key provided
|
|
||||||
for (var i = 0; i < keys.length; ++i) {
|
|
||||||
var isFinal = i + 1 === keys.length;
|
|
||||||
var wrappedCallback = isFinal ? _callbackAndReset : _increaseSequence(action || _getKeyInfo(keys[i + 1]).action);
|
|
||||||
_bindSingle(keys[i], wrappedCallback, action, combo, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts from a string key combination to an array
|
|
||||||
*
|
|
||||||
* @param {string} combination like "command+shift+l"
|
|
||||||
* @return {Array}
|
|
||||||
*/
|
|
||||||
function _keysFromString(combination) {
|
|
||||||
if (combination === '+') {
|
|
||||||
return ['+'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return combination.split('+');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets info for a specific key combination
|
|
||||||
*
|
|
||||||
* @param {string} combination key combination ("command+s" or "a" or "*")
|
|
||||||
* @param {string=} action
|
|
||||||
* @returns {Object}
|
|
||||||
*/
|
|
||||||
function _getKeyInfo(combination, action) {
|
|
||||||
var keys,
|
|
||||||
key,
|
|
||||||
i,
|
|
||||||
modifiers = [];
|
|
||||||
|
|
||||||
// take the keys from this pattern and figure out what the actual
|
|
||||||
// pattern is all about
|
|
||||||
keys = _keysFromString(combination);
|
|
||||||
|
|
||||||
for (i = 0; i < keys.length; ++i) {
|
|
||||||
key = keys[i];
|
|
||||||
|
|
||||||
// normalize key names
|
|
||||||
if (_SPECIAL_ALIASES[key]) {
|
|
||||||
key = _SPECIAL_ALIASES[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
// if this is not a keypress event then we should
|
|
||||||
// be smart about using shift keys
|
|
||||||
// this will only work for US keyboards however
|
|
||||||
if (action && action != 'keypress' && _SHIFT_MAP[key]) {
|
|
||||||
key = _SHIFT_MAP[key];
|
|
||||||
modifiers.push('shift');
|
|
||||||
}
|
|
||||||
|
|
||||||
// if this key is a modifier then add it to the list of modifiers
|
|
||||||
if (_isModifier(key)) {
|
|
||||||
modifiers.push(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// depending on what the key combination is
|
|
||||||
// we will try to pick the best event for it
|
|
||||||
action = _pickBestAction(key, modifiers, action);
|
|
||||||
|
|
||||||
return {
|
|
||||||
key: key,
|
|
||||||
modifiers: modifiers,
|
|
||||||
action: action
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* binds a single keyboard combination
|
|
||||||
*
|
|
||||||
* @param {string} combination
|
|
||||||
* @param {Function} callback
|
|
||||||
* @param {string=} action
|
|
||||||
* @param {string=} sequenceName - name of sequence if part of sequence
|
|
||||||
* @param {number=} level - what part of the sequence the command is
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function _bindSingle(combination, callback, action, sequenceName, level) {
|
|
||||||
|
|
||||||
// store a direct mapped reference for use with Mousetrap.trigger
|
|
||||||
_directMap[combination + ':' + action] = callback;
|
|
||||||
|
|
||||||
// make sure multiple spaces in a row become a single space
|
|
||||||
combination = combination.replace(/\s+/g, ' ');
|
|
||||||
|
|
||||||
var sequence = combination.split(' '),
|
|
||||||
info;
|
|
||||||
|
|
||||||
// if this pattern is a sequence of keys then run through this method
|
|
||||||
// to reprocess each pattern one key at a time
|
|
||||||
if (sequence.length > 1) {
|
|
||||||
_bindSequence(combination, sequence, callback, action);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
info = _getKeyInfo(combination, action);
|
|
||||||
|
|
||||||
// make sure to initialize array if this is the first time
|
|
||||||
// a callback is added for this key
|
|
||||||
_callbacks[info.key] = _callbacks[info.key] || [];
|
|
||||||
|
|
||||||
// remove an existing match if there is one
|
|
||||||
_getMatches(info.key, info.modifiers, {type: info.action}, sequenceName, combination, level);
|
|
||||||
|
|
||||||
// add this call back to the array
|
|
||||||
// if it is a sequence put it at the beginning
|
|
||||||
// if not put it at the end
|
|
||||||
//
|
|
||||||
// this is important because the way these are processed expects
|
|
||||||
// the sequence ones to come first
|
|
||||||
_callbacks[info.key][sequenceName ? 'unshift' : 'push']({
|
|
||||||
callback: callback,
|
|
||||||
modifiers: info.modifiers,
|
|
||||||
action: info.action,
|
|
||||||
seq: sequenceName,
|
|
||||||
level: level,
|
|
||||||
combo: combination
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* binds multiple combinations to the same callback
|
|
||||||
*
|
|
||||||
* @param {Array} combinations
|
|
||||||
* @param {Function} callback
|
|
||||||
* @param {string|undefined} action
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
function _bindMultiple(combinations, callback, action) {
|
|
||||||
for (var i = 0; i < combinations.length; ++i) {
|
|
||||||
_bindSingle(combinations[i], callback, action);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// start!
|
|
||||||
_addEvent(document, 'keypress', _handleKeyEvent);
|
|
||||||
_addEvent(document, 'keydown', _handleKeyEvent);
|
|
||||||
_addEvent(document, 'keyup', _handleKeyEvent);
|
|
||||||
|
|
||||||
var Mousetrap = {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* binds an event to mousetrap
|
|
||||||
*
|
|
||||||
* can be a single key, a combination of keys separated with +,
|
|
||||||
* an array of keys, or a sequence of keys separated by spaces
|
|
||||||
*
|
|
||||||
* be sure to list the modifier keys first to make sure that the
|
|
||||||
* correct key ends up getting bound (the last key in the pattern)
|
|
||||||
*
|
|
||||||
* @param {string|Array} keys
|
|
||||||
* @param {Function} callback
|
|
||||||
* @param {string=} action - 'keypress', 'keydown', or 'keyup'
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
bind: function(keys, callback, action) {
|
|
||||||
keys = keys instanceof Array ? keys : [keys];
|
|
||||||
_bindMultiple(keys, callback, action);
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* unbinds an event to mousetrap
|
|
||||||
*
|
|
||||||
* the unbinding sets the callback function of the specified key combo
|
|
||||||
* to an empty function and deletes the corresponding key in the
|
|
||||||
* _directMap dict.
|
|
||||||
*
|
|
||||||
* TODO: actually remove this from the _callbacks dictionary instead
|
|
||||||
* of binding an empty function
|
|
||||||
*
|
|
||||||
* the keycombo+action has to be exactly the same as
|
|
||||||
* it was defined in the bind method
|
|
||||||
*
|
|
||||||
* @param {string|Array} keys
|
|
||||||
* @param {string} action
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
unbind: function(keys, action) {
|
|
||||||
return Mousetrap.bind(keys, function() {}, action);
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* triggers an event that has already been bound
|
|
||||||
*
|
|
||||||
* @param {string} keys
|
|
||||||
* @param {string=} action
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
trigger: function(keys, action) {
|
|
||||||
if (_directMap[keys + ':' + action]) {
|
|
||||||
_directMap[keys + ':' + action]({}, keys);
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* resets the library back to its initial state. this is useful
|
|
||||||
* if you want to clear out the current keyboard shortcuts and bind
|
|
||||||
* new ones - for example if you switch to another page
|
|
||||||
*
|
|
||||||
* @returns void
|
|
||||||
*/
|
|
||||||
reset: function() {
|
|
||||||
_callbacks = {};
|
|
||||||
_directMap = {};
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* should we stop this event before firing off callbacks
|
|
||||||
*
|
|
||||||
* @param {Event} e
|
|
||||||
* @param {Element} element
|
|
||||||
* @return {boolean}
|
|
||||||
*/
|
|
||||||
stopCallback: function(e, element) {
|
|
||||||
|
|
||||||
// if the element has the class "mousetrap" then no need to stop
|
|
||||||
if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// stop for input, select, and textarea
|
|
||||||
return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable;
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* exposes _handleKey publicly so it can be overwritten by extensions
|
|
||||||
*/
|
|
||||||
handleKey: _handleKey
|
|
||||||
};
|
|
||||||
|
|
||||||
// expose mousetrap to the global object
|
|
||||||
window.Mousetrap = Mousetrap;
|
|
||||||
|
|
||||||
// expose mousetrap as an AMD module
|
|
||||||
if (typeof define === 'function' && define.amd) {
|
|
||||||
define(Mousetrap);
|
|
||||||
}
|
|
||||||
}) (window, document);
|
|
2
client/js/libs/jquery/stickyscroll.js
vendored
2
client/js/libs/jquery/stickyscroll.js
vendored
@ -1,3 +1,5 @@
|
|||||||
|
import jQuery from "jquery";
|
||||||
|
|
||||||
(function($) {
|
(function($) {
|
||||||
$.fn.unsticky = function() {
|
$.fn.unsticky = function() {
|
||||||
return this.trigger("unstick.sticky").unbind(".sticky");
|
return this.trigger("unstick.sticky").unbind(".sticky");
|
||||||
|
2
client/js/libs/jquery/tabcomplete.js
vendored
2
client/js/libs/jquery/tabcomplete.js
vendored
@ -1,3 +1,5 @@
|
|||||||
|
import jQuery from "jquery";
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* tabcomplete
|
* tabcomplete
|
||||||
* http://github.com/erming/tabcomplete
|
* http://github.com/erming/tabcomplete
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Simple slideout menu implementation.
|
* Simple slideout menu implementation.
|
||||||
*/
|
*/
|
||||||
function slideoutMenu(viewport, menu) {
|
export default function slideoutMenu(viewport, menu) {
|
||||||
var touchStartPos = null;
|
var touchStartPos = null;
|
||||||
var touchCurPos = null;
|
var touchCurPos = null;
|
||||||
var touchStartTime = 0;
|
var touchStartTime = 0;
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,4 @@
|
|||||||
|
/* eslint strict: 0 */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,4 +1,18 @@
|
|||||||
"use strict";
|
// vendor libraries
|
||||||
|
import "jquery-ui/ui/widgets/sortable";
|
||||||
|
import $ from "jquery";
|
||||||
|
import io from "socket.io-client";
|
||||||
|
import Mousetrap from "mousetrap";
|
||||||
|
import URI from "urijs";
|
||||||
|
|
||||||
|
// our libraries
|
||||||
|
import "./libs/jquery/inputhistory";
|
||||||
|
import "./libs/jquery/stickyscroll";
|
||||||
|
import "./libs/jquery/tabcomplete";
|
||||||
|
import helpers_parse from "./libs/handlebars/parse";
|
||||||
|
import helpers_roundBadgeNumber from "./libs/handlebars/roundBadgeNumber";
|
||||||
|
import slideoutMenu from "./libs/slideout";
|
||||||
|
import templates from "../views";
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
var path = window.location.pathname + "socket.io/";
|
var path = window.location.pathname + "socket.io/";
|
||||||
@ -59,10 +73,6 @@ $(function() {
|
|||||||
|
|
||||||
var favicon = $("#favicon");
|
var favicon = $("#favicon");
|
||||||
|
|
||||||
function render(name, data) {
|
|
||||||
return Handlebars.templates[name](data);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setLocalStorageItem(key, value) {
|
function setLocalStorageItem(key, value) {
|
||||||
try {
|
try {
|
||||||
window.localStorage.setItem(key, value);
|
window.localStorage.setItem(key, value);
|
||||||
@ -73,12 +83,6 @@ $(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Handlebars.registerHelper(
|
|
||||||
"partial", function(id) {
|
|
||||||
return new Handlebars.SafeString(render(id, this));
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
[
|
[
|
||||||
"connect_error",
|
"connect_error",
|
||||||
"connect_failed",
|
"connect_failed",
|
||||||
@ -229,12 +233,12 @@ $(function() {
|
|||||||
var id = data.network;
|
var id = data.network;
|
||||||
var network = sidebar.find("#network-" + id);
|
var network = sidebar.find("#network-" + id);
|
||||||
network.append(
|
network.append(
|
||||||
render("chan", {
|
templates.chan({
|
||||||
channels: [data.chan]
|
channels: [data.chan]
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
chat.append(
|
chat.append(
|
||||||
render("chat", {
|
templates.chat({
|
||||||
channels: [data.chan]
|
channels: [data.chan]
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -284,15 +288,18 @@ $(function() {
|
|||||||
"ctcp",
|
"ctcp",
|
||||||
"channel_list",
|
"channel_list",
|
||||||
].indexOf(type) !== -1) {
|
].indexOf(type) !== -1) {
|
||||||
data.msg.template = "actions/" + type;
|
|
||||||
template = "msg_action";
|
template = "msg_action";
|
||||||
} else if (type === "unhandled") {
|
} else if (type === "unhandled") {
|
||||||
template = "msg_unhandled";
|
template = "msg_unhandled";
|
||||||
}
|
}
|
||||||
|
|
||||||
var msg = $(render(template, data.msg));
|
var msg = $(templates[template](data.msg));
|
||||||
|
|
||||||
var text = msg.find(".text");
|
var text = msg.find(".text");
|
||||||
|
|
||||||
|
if (template === "msg_action") {
|
||||||
|
text.html(templates.actions[type](data.msg));
|
||||||
|
}
|
||||||
|
|
||||||
if (text.find("i").size() === 1) {
|
if (text.find("i").size() === 1) {
|
||||||
text = text.find("i");
|
text = text.find("i");
|
||||||
}
|
}
|
||||||
@ -334,12 +341,12 @@ $(function() {
|
|||||||
|
|
||||||
// TODO: If the message is far off in the history, we still need to append the marker into DOM
|
// TODO: If the message is far off in the history, we still need to append the marker into DOM
|
||||||
if (!first.length) {
|
if (!first.length) {
|
||||||
channel.prepend(render("unread_marker"));
|
channel.prepend(templates.unread_marker());
|
||||||
} else {
|
} else {
|
||||||
first.before(render("unread_marker"));
|
first.before(templates.unread_marker());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
channel.append(render("unread_marker"));
|
channel.append(templates.unread_marker());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.type !== "lobby") {
|
if (data.type !== "lobby") {
|
||||||
@ -351,11 +358,11 @@ $(function() {
|
|||||||
// Top-most message in a channel
|
// Top-most message in a channel
|
||||||
if (!lastDate) {
|
if (!lastDate) {
|
||||||
lastDate = msgDate;
|
lastDate = msgDate;
|
||||||
msg.before(render("date-marker", {msgDate: msgDate}));
|
msg.before(templates.date_marker({msgDate: msgDate}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastDate.toDateString() !== msgDate.toDateString()) {
|
if (lastDate.toDateString() !== msgDate.toDateString()) {
|
||||||
msg.before(render("date-marker", {msgDate: msgDate}));
|
msg.before(templates.date_marker({msgDate: msgDate}));
|
||||||
}
|
}
|
||||||
|
|
||||||
lastDate = msgDate;
|
lastDate = msgDate;
|
||||||
@ -383,13 +390,13 @@ $(function() {
|
|||||||
return (oldSortOrder[a] || Number.MAX_VALUE) - (oldSortOrder[b] || Number.MAX_VALUE);
|
return (oldSortOrder[a] || Number.MAX_VALUE) - (oldSortOrder[b] || Number.MAX_VALUE);
|
||||||
});
|
});
|
||||||
|
|
||||||
users.html(render("user", data)).data("nicks", nicks);
|
users.html(templates.user(data)).data("nicks", nicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderNetworks(data) {
|
function renderNetworks(data) {
|
||||||
sidebar.find(".empty").hide();
|
sidebar.find(".empty").hide();
|
||||||
sidebar.find(".networks").append(
|
sidebar.find(".networks").append(
|
||||||
render("network", {
|
templates.network({
|
||||||
networks: data.networks
|
networks: data.networks
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -398,7 +405,7 @@ $(function() {
|
|||||||
return n.channels;
|
return n.channels;
|
||||||
});
|
});
|
||||||
chat.append(
|
chat.append(
|
||||||
render("chat", {
|
templates.chat({
|
||||||
channels: channels
|
channels: channels
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -424,11 +431,11 @@ $(function() {
|
|||||||
|
|
||||||
// It's the first message in a channel/query
|
// It's the first message in a channel/query
|
||||||
if (prevMsg.length === 0) {
|
if (prevMsg.length === 0) {
|
||||||
container.append(render("date-marker", {msgDate: msgTime}));
|
container.append(templates.date_marker({msgDate: msgTime}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prevMsgTime.toDateString() !== msgTime.toDateString()) {
|
if (prevMsgTime.toDateString() !== msgTime.toDateString()) {
|
||||||
prevMsg.append(render("date-marker", {msgDate: msgTime}));
|
prevMsg.append(templates.date_marker({msgDate: msgTime}));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add message to the container
|
// Add message to the container
|
||||||
@ -486,11 +493,11 @@ $(function() {
|
|||||||
// Top-most message in a channel
|
// Top-most message in a channel
|
||||||
if (!lastDate) {
|
if (!lastDate) {
|
||||||
lastDate = msgDate;
|
lastDate = msgDate;
|
||||||
msg.before(render("date-marker", {msgDate: msgDate}));
|
msg.before(templates.date_marker({msgDate: msgDate}));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastDate.toDateString() !== msgDate.toDateString()) {
|
if (lastDate.toDateString() !== msgDate.toDateString()) {
|
||||||
msg.before(render("date-marker", {msgDate: msgDate}));
|
msg.before(templates.date_marker({msgDate: msgDate}));
|
||||||
}
|
}
|
||||||
|
|
||||||
lastDate = msgDate;
|
lastDate = msgDate;
|
||||||
@ -551,7 +558,7 @@ $(function() {
|
|||||||
|
|
||||||
socket.on("toggle", function(data) {
|
socket.on("toggle", function(data) {
|
||||||
var toggle = $("#toggle-" + data.id);
|
var toggle = $("#toggle-" + data.id);
|
||||||
toggle.parent().after(render("toggle", {toggle: data}));
|
toggle.parent().after(templates.toggle({toggle: data}));
|
||||||
switch (data.type) {
|
switch (data.type) {
|
||||||
case "link":
|
case "link":
|
||||||
if (options.links) {
|
if (options.links) {
|
||||||
@ -569,7 +576,7 @@ $(function() {
|
|||||||
|
|
||||||
socket.on("topic", function(data) {
|
socket.on("topic", function(data) {
|
||||||
var topic = $("#chan-" + data.chan).find(".header .topic");
|
var topic = $("#chan-" + data.chan).find(".header .topic");
|
||||||
topic.html(Handlebars.helpers.parse(data.topic));
|
topic.html(helpers_parse(data.topic));
|
||||||
// .attr() is safe escape-wise but consider the capabilities of the attribute
|
// .attr() is safe escape-wise but consider the capabilities of the attribute
|
||||||
topic.attr("title", data.topic);
|
topic.attr("title", data.topic);
|
||||||
});
|
});
|
||||||
@ -710,7 +717,7 @@ $(function() {
|
|||||||
}());
|
}());
|
||||||
|
|
||||||
var viewport = $("#viewport");
|
var viewport = $("#viewport");
|
||||||
var sidebarSlide = window.slideoutMenu(viewport[0], sidebar[0]);
|
var sidebarSlide = slideoutMenu(viewport[0], sidebar[0]);
|
||||||
var contextMenuContainer = $("#context-menu-container");
|
var contextMenuContainer = $("#context-menu-container");
|
||||||
var contextMenu = $("#context-menu");
|
var contextMenu = $("#context-menu");
|
||||||
|
|
||||||
@ -758,19 +765,19 @@ $(function() {
|
|||||||
var output = "";
|
var output = "";
|
||||||
|
|
||||||
if (target.hasClass("user")) {
|
if (target.hasClass("user")) {
|
||||||
output = render("contextmenu_item", {
|
output = templates.contextmenu_item({
|
||||||
class: "user",
|
class: "user",
|
||||||
text: target.text(),
|
text: target.text(),
|
||||||
data: target.data("name")
|
data: target.data("name")
|
||||||
});
|
});
|
||||||
} else if (target.hasClass("chan")) {
|
} else if (target.hasClass("chan")) {
|
||||||
output = render("contextmenu_item", {
|
output = templates.contextmenu_item({
|
||||||
class: "chan",
|
class: "chan",
|
||||||
text: target.data("title"),
|
text: target.data("title"),
|
||||||
data: target.data("target")
|
data: target.data("target")
|
||||||
});
|
});
|
||||||
output += render("contextmenu_divider");
|
output += templates.contextmenu_divider();
|
||||||
output += render("contextmenu_item", {
|
output += templates.contextmenu_item({
|
||||||
class: "close",
|
class: "close",
|
||||||
text: target.hasClass("lobby") ? "Disconnect" : target.hasClass("channel") ? "Leave" : "Close",
|
text: target.hasClass("lobby") ? "Disconnect" : target.hasClass("channel") ? "Leave" : "Close",
|
||||||
data: target.data("target")
|
data: target.data("target")
|
||||||
@ -1178,7 +1185,7 @@ $(function() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var badge = button.find(".badge").html(Handlebars.helpers.roundBadgeNumber(unread));
|
var badge = button.find(".badge").html(helpers_roundBadgeNumber(unread));
|
||||||
|
|
||||||
if (msg.highlight) {
|
if (msg.highlight) {
|
||||||
badge.addClass("highlight");
|
badge.addClass("highlight");
|
||||||
@ -1226,7 +1233,7 @@ $(function() {
|
|||||||
});
|
});
|
||||||
if ($("body").hasClass("public")) {
|
if ($("body").hasClass("public")) {
|
||||||
$("#connect").one("show", function() {
|
$("#connect").one("show", function() {
|
||||||
var params = window.URI(document.location.search);
|
var params = URI(document.location.search);
|
||||||
params = params.search(true);
|
params = params.search(true);
|
||||||
// Possible parameters: name, host, port, password, tls, nick, username, realname, join
|
// Possible parameters: name, host, port, password, tls, nick, username, realname, join
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#Iterating_over_own_properties_only
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#Iterating_over_own_properties_only
|
||||||
|
30
client/views/index.js
Normal file
30
client/views/index.js
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
module.exports = {
|
||||||
|
actions: {
|
||||||
|
action: require("./actions/action.tpl"),
|
||||||
|
channel_list: require("./actions/channel_list.tpl"),
|
||||||
|
ctcp: require("./actions/ctcp.tpl"),
|
||||||
|
invite: require("./actions/invite.tpl"),
|
||||||
|
join: require("./actions/join.tpl"),
|
||||||
|
kick: require("./actions/kick.tpl"),
|
||||||
|
mode: require("./actions/mode.tpl"),
|
||||||
|
nick: require("./actions/nick.tpl"),
|
||||||
|
part: require("./actions/part.tpl"),
|
||||||
|
quit: require("./actions/quit.tpl"),
|
||||||
|
topic: require("./actions/topic.tpl"),
|
||||||
|
topic_set_by: require("./actions/topic_set_by.tpl"),
|
||||||
|
whois: require("./actions/whois.tpl"),
|
||||||
|
},
|
||||||
|
|
||||||
|
chan: require("./chan.tpl"),
|
||||||
|
chat: require("./chat.tpl"),
|
||||||
|
contextmenu_divider: require("./contextmenu_divider.tpl"),
|
||||||
|
contextmenu_item: require("./contextmenu_item.tpl"),
|
||||||
|
date_marker: require("./date-marker.tpl"),
|
||||||
|
msg: require("./msg.tpl"),
|
||||||
|
msg_action: require("./msg_action.tpl"),
|
||||||
|
msg_unhandled: require("./msg_unhandled.tpl"),
|
||||||
|
network: require("./network.tpl"),
|
||||||
|
toggle: require("./toggle.tpl"),
|
||||||
|
unread_marker: require("./unread_marker.tpl"),
|
||||||
|
user: require("./user.tpl"),
|
||||||
|
};
|
@ -13,7 +13,7 @@
|
|||||||
<button id="toggle-{{id}}" class="toggle-button" aria-label="Toggle prefetched media">···</button>
|
<button id="toggle-{{id}}" class="toggle-button" aria-label="Toggle prefetched media">···</button>
|
||||||
</div>
|
</div>
|
||||||
{{#if toggle}}
|
{{#if toggle}}
|
||||||
{{partial "toggle"}}
|
{{> toggle}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</span>
|
</span>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
@ -3,7 +3,5 @@
|
|||||||
{{tz time}}
|
{{tz time}}
|
||||||
</span>
|
</span>
|
||||||
<span class="from"></span>
|
<span class="from"></span>
|
||||||
<span class="text">
|
<span class="text"></span>
|
||||||
{{partial template}}
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{{#each networks}}
|
{{#each networks}}
|
||||||
<section id="network-{{id}}" class="network" data-id="{{id}}" data-nick="{{nick}}" data-options="{{toJSON serverOptions}}">
|
<section id="network-{{id}}" class="network" data-id="{{id}}" data-nick="{{nick}}" data-options="{{tojson serverOptions}}">
|
||||||
{{partial "chan"}}
|
{{> chan}}
|
||||||
</section>
|
</section>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
24
package.json
24
package.json
@ -14,16 +14,15 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"coverage": "istanbul cover node_modules/mocha/bin/_mocha",
|
"coverage": "istanbul cover node_modules/mocha/bin/_mocha",
|
||||||
"start": "node index",
|
"start": "node index",
|
||||||
|
"start-dev": "npm-run-all --parallel watch start",
|
||||||
"build": "npm-run-all build:*",
|
"build": "npm-run-all build:*",
|
||||||
"build:font-awesome": "node scripts/build-fontawesome.js",
|
"build:font-awesome": "node scripts/build-fontawesome.js",
|
||||||
"build:libs": "uglifyjs client/js/libs/*.js client/js/libs/jquery/*.js client/js/libs/handlebars/*.js -o client/js/libs.min.js --source-map client/js/libs.min.js.map --source-map-url libs.min.js.map -p relative",
|
"build:webpack": "webpack",
|
||||||
"build:handlebars": "handlebars client/views/ -e tpl -f client/js/lounge.templates.js",
|
"watch": "webpack -w",
|
||||||
"test": "npm-run-all -c test:mocha lint",
|
"test": "npm-run-all -c test:* lint",
|
||||||
"test:mocha": "mocha",
|
"test:mocha": "mocha",
|
||||||
"lint": "npm-run-all -c lint:js lint:css",
|
"lint": "npm-run-all -c lint:*",
|
||||||
"lint:js": "npm-run-all -c lint:js:es5 lint:js:es6",
|
"lint:js": "eslint .",
|
||||||
"lint:js:es5": "eslint --parser-options=\"ecmaVersion:5\" client/",
|
|
||||||
"lint:js:es6": "eslint --ignore-pattern client/ .",
|
|
||||||
"lint:css": "stylelint \"**/*.css\"",
|
"lint:css": "stylelint \"**/*.css\"",
|
||||||
"prepublish": "npm run build"
|
"prepublish": "npm run build"
|
||||||
},
|
},
|
||||||
@ -59,14 +58,23 @@
|
|||||||
"ldapjs": "1.0.1"
|
"ldapjs": "1.0.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"babel-core": "6.21.0",
|
||||||
|
"babel-loader": "6.2.10",
|
||||||
|
"babel-preset-es2015": "6.18.0",
|
||||||
"chai": "3.5.0",
|
"chai": "3.5.0",
|
||||||
"eslint": "3.12.2",
|
"eslint": "3.12.2",
|
||||||
"font-awesome": "4.7.0",
|
"font-awesome": "4.7.0",
|
||||||
"handlebars": "4.0.6",
|
"handlebars": "4.0.6",
|
||||||
|
"handlebars-loader": "1.4.0",
|
||||||
"istanbul": "0.4.5",
|
"istanbul": "0.4.5",
|
||||||
|
"jquery": "2.1.1",
|
||||||
|
"jquery-ui": "1.12.1",
|
||||||
"mocha": "3.2.0",
|
"mocha": "3.2.0",
|
||||||
|
"mousetrap": "1.4.6",
|
||||||
"npm-run-all": "3.1.2",
|
"npm-run-all": "3.1.2",
|
||||||
|
"socket.io-client": "1.7.2",
|
||||||
"stylelint": "7.7.0",
|
"stylelint": "7.7.0",
|
||||||
"uglify-js": "2.7.5"
|
"urijs": "1.16.1",
|
||||||
|
"webpack": "1.14.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,7 @@ module.exports = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var sockets = io(server, {
|
var sockets = io(server, {
|
||||||
|
serveClient: false,
|
||||||
transports: config.transports
|
transports: config.transports
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const Handlebars = global.Handlebars = require("handlebars");
|
|
||||||
const expect = require("chai").expect;
|
const expect = require("chai").expect;
|
||||||
|
const localetime = require("../../../../../client/js/libs/handlebars/localetime");
|
||||||
require("../../../../../client/js/libs/handlebars/localetime");
|
|
||||||
|
|
||||||
describe("localetime Handlebars helper", () => {
|
describe("localetime Handlebars helper", () => {
|
||||||
|
|
||||||
it("should render a human-readable date", () => {
|
it("should render a human-readable date", () => {
|
||||||
const template = Handlebars.compile("{{localetime time}}");
|
|
||||||
|
|
||||||
// 12PM in UTC time
|
// 12PM in UTC time
|
||||||
const date = new Date("2014-05-22T12:00:00");
|
const date = new Date("2014-05-22T12:00:00");
|
||||||
|
|
||||||
@ -19,7 +15,7 @@ describe("localetime Handlebars helper", () => {
|
|||||||
// Pretend local timezone is UTC by moving the clock of that offset
|
// Pretend local timezone is UTC by moving the clock of that offset
|
||||||
const time = date.getTime() + offset;
|
const time = date.getTime() + offset;
|
||||||
|
|
||||||
expect(template({time: time})).to.equal("5/22/2014, 12:00:00 PM");
|
expect(localetime(time)).to.equal("5/22/2014, 12:00:00 PM");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
66
webpack.config.js
Normal file
66
webpack.config.js
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
const webpack = require("webpack");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
entry: {
|
||||||
|
app: path.resolve(__dirname, "client/js/lounge.js"),
|
||||||
|
vendor: [
|
||||||
|
"handlebars/runtime",
|
||||||
|
"jquery",
|
||||||
|
"jquery-ui/ui/widgets/sortable",
|
||||||
|
"mousetrap",
|
||||||
|
"socket.io-client",
|
||||||
|
"urijs",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
devtool: "source-map",
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, "client/js"),
|
||||||
|
filename: "bundle.js",
|
||||||
|
publicPath: "/"
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
loaders: [
|
||||||
|
{
|
||||||
|
test: /\.js$/,
|
||||||
|
include: [
|
||||||
|
path.resolve(__dirname, "client"),
|
||||||
|
],
|
||||||
|
loader: "babel",
|
||||||
|
query: {
|
||||||
|
presets: [
|
||||||
|
"es2015"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.tpl$/,
|
||||||
|
include: [
|
||||||
|
path.resolve(__dirname, "client/views"),
|
||||||
|
],
|
||||||
|
loader: "handlebars-loader",
|
||||||
|
query: {
|
||||||
|
helperDirs: [
|
||||||
|
path.resolve(__dirname, "client/js/libs/handlebars")
|
||||||
|
],
|
||||||
|
extensions: [
|
||||||
|
".tpl"
|
||||||
|
],
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new webpack.optimize.CommonsChunkPlugin(
|
||||||
|
"vendor", // chunkName
|
||||||
|
"bundle.vendor.js" // filename
|
||||||
|
),
|
||||||
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
|
compress: {
|
||||||
|
warnings: false
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user