Moves the roomname generator to util, reuses a function.
This commit is contained in:
parent
fb6367d687
commit
4009fed35d
|
@ -16,7 +16,7 @@ var EventEmitter = require("events");
|
||||||
var SettingsMenu = require("./side_pannels/settings/SettingsMenu");
|
var SettingsMenu = require("./side_pannels/settings/SettingsMenu");
|
||||||
var Settings = require("./../settings/Settings");
|
var Settings = require("./../settings/Settings");
|
||||||
var PanelToggler = require("./side_pannels/SidePanelToggler");
|
var PanelToggler = require("./side_pannels/SidePanelToggler");
|
||||||
var RoomNameGenerator = require("./welcome_page/RoomnameGenerator");
|
var RoomnameGenerator = require("../util/RoomnameGenerator");
|
||||||
UI.messageHandler = require("./util/MessageHandler");
|
UI.messageHandler = require("./util/MessageHandler");
|
||||||
var messageHandler = UI.messageHandler;
|
var messageHandler = UI.messageHandler;
|
||||||
var Authentication = require("./authentication/Authentication");
|
var Authentication = require("./authentication/Authentication");
|
||||||
|
@ -718,7 +718,7 @@ UI.getRoomNode = function () {
|
||||||
if (path.length > 1) {
|
if (path.length > 1) {
|
||||||
roomNode = path.substr(1).toLowerCase();
|
roomNode = path.substr(1).toLowerCase();
|
||||||
} else {
|
} else {
|
||||||
var word = RoomNameGenerator.generateRoomWithoutSeparator();
|
var word = RoomnameGenerator.generateRoomWithoutSeparator();
|
||||||
roomNode = word.toLowerCase();
|
roomNode = word.toLowerCase();
|
||||||
window.history.pushState('VideoChat',
|
window.history.pushState('VideoChat',
|
||||||
'Room: ' + word, window.location.pathname + word);
|
'Room: ' + word, window.location.pathname + word);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* global $, interfaceConfig */
|
/* global $, interfaceConfig */
|
||||||
var animateTimeout, updateTimeout;
|
var animateTimeout, updateTimeout;
|
||||||
|
|
||||||
var RoomNameGenerator = require("./RoomnameGenerator");
|
var RoomnameGenerator = require("../../util/RoomnameGenerator");
|
||||||
|
|
||||||
function enter_room() {
|
function enter_room() {
|
||||||
var val = $("#enter_room_field").val();
|
var val = $("#enter_room_field").val();
|
||||||
|
@ -22,7 +22,7 @@ function animate(word) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_roomname() {
|
function update_roomname() {
|
||||||
var word = RoomNameGenerator.generateRoomWithoutSeparator();
|
var word = RoomnameGenerator.generateRoomWithoutSeparator();
|
||||||
$("#enter_room_field").attr("room_name", word);
|
$("#enter_room_field").attr("room_name", word);
|
||||||
$("#enter_room_field").attr("placeholder", "");
|
$("#enter_room_field").attr("placeholder", "");
|
||||||
clearTimeout(animateTimeout);
|
clearTimeout(animateTimeout);
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
var RandomUtil = require('./RandomUtil');
|
||||||
//var nouns = [
|
//var nouns = [
|
||||||
//];
|
//];
|
||||||
var pluralNouns = [
|
var pluralNouns = [
|
||||||
|
@ -160,14 +161,6 @@ var PATTERNS = [
|
||||||
//"_ADJECTIVE__PLURALNOUN_AtThe_PLACE_",
|
//"_ADJECTIVE__PLURALNOUN_AtThe_PLACE_",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Returns a random element from the array 'arr'
|
|
||||||
*/
|
|
||||||
function randomElement(arr) {
|
|
||||||
return arr[Math.floor(Math.random() * arr.length)];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns true if the string 's' contains one of the
|
* Returns true if the string 's' contains one of the
|
||||||
* template strings.
|
* template strings.
|
||||||
|
@ -183,17 +176,17 @@ function hasTemplate(s) {
|
||||||
/**
|
/**
|
||||||
* Generates new room name.
|
* Generates new room name.
|
||||||
*/
|
*/
|
||||||
var RoomNameGenerator = {
|
var RoomnameGenerator = {
|
||||||
generateRoomWithoutSeparator: function() {
|
generateRoomWithoutSeparator: function() {
|
||||||
// Note that if more than one pattern is available, the choice of
|
// Note that if more than one pattern is available, the choice of
|
||||||
// 'name' won't have a uniform distribution amongst all patterns (names
|
// 'name' won't have a uniform distribution amongst all patterns (names
|
||||||
// from patterns with fewer options will have higher probability of
|
// from patterns with fewer options will have higher probability of
|
||||||
// being chosen that names from patterns with more options).
|
// being chosen that names from patterns with more options).
|
||||||
var name = randomElement(PATTERNS);
|
var name = RandomUtil.randomElement(PATTERNS);
|
||||||
var word;
|
var word;
|
||||||
while (hasTemplate(name)) {
|
while (hasTemplate(name)) {
|
||||||
for (var template in CATEGORIES) {
|
for (var template in CATEGORIES) {
|
||||||
word = randomElement(CATEGORIES[template]);
|
word = RandomUtil.randomElement(CATEGORIES[template]);
|
||||||
name = name.replace(template, word);
|
name = name.replace(template, word);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,4 +195,4 @@ var RoomNameGenerator = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = RoomNameGenerator;
|
module.exports = RoomnameGenerator;
|
Loading…
Reference in New Issue