diff --git a/modules/UI/UI.js b/modules/UI/UI.js index da5e5ab92..62bcd0a17 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -16,7 +16,7 @@ var EventEmitter = require("events"); var SettingsMenu = require("./side_pannels/settings/SettingsMenu"); var Settings = require("./../settings/Settings"); var PanelToggler = require("./side_pannels/SidePanelToggler"); -var RoomNameGenerator = require("./welcome_page/RoomnameGenerator"); +var RoomnameGenerator = require("../util/RoomnameGenerator"); UI.messageHandler = require("./util/MessageHandler"); var messageHandler = UI.messageHandler; var Authentication = require("./authentication/Authentication"); @@ -718,7 +718,7 @@ UI.getRoomNode = function () { if (path.length > 1) { roomNode = path.substr(1).toLowerCase(); } else { - var word = RoomNameGenerator.generateRoomWithoutSeparator(); + var word = RoomnameGenerator.generateRoomWithoutSeparator(); roomNode = word.toLowerCase(); window.history.pushState('VideoChat', 'Room: ' + word, window.location.pathname + word); diff --git a/modules/UI/welcome_page/WelcomePage.js b/modules/UI/welcome_page/WelcomePage.js index 3a7b9692d..8d2a05d15 100644 --- a/modules/UI/welcome_page/WelcomePage.js +++ b/modules/UI/welcome_page/WelcomePage.js @@ -1,7 +1,7 @@ /* global $, interfaceConfig */ var animateTimeout, updateTimeout; -var RoomNameGenerator = require("./RoomnameGenerator"); +var RoomnameGenerator = require("../../util/RoomnameGenerator"); function enter_room() { var val = $("#enter_room_field").val(); @@ -22,7 +22,7 @@ function animate(word) { } function update_roomname() { - var word = RoomNameGenerator.generateRoomWithoutSeparator(); + var word = RoomnameGenerator.generateRoomWithoutSeparator(); $("#enter_room_field").attr("room_name", word); $("#enter_room_field").attr("placeholder", ""); clearTimeout(animateTimeout); diff --git a/modules/UI/welcome_page/RoomnameGenerator.js b/modules/util/RoomnameGenerator.js similarity index 96% rename from modules/UI/welcome_page/RoomnameGenerator.js rename to modules/util/RoomnameGenerator.js index 0fb738fe4..198838091 100644 --- a/modules/UI/welcome_page/RoomnameGenerator.js +++ b/modules/util/RoomnameGenerator.js @@ -1,3 +1,4 @@ +var RandomUtil = require('./RandomUtil'); //var nouns = [ //]; var pluralNouns = [ @@ -160,14 +161,6 @@ var PATTERNS = [ //"_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 * template strings. @@ -183,17 +176,17 @@ function hasTemplate(s) { /** * Generates new room name. */ -var RoomNameGenerator = { +var RoomnameGenerator = { generateRoomWithoutSeparator: function() { // Note that if more than one pattern is available, the choice of // 'name' won't have a uniform distribution amongst all patterns (names // from patterns with fewer options will have higher probability of // being chosen that names from patterns with more options). - var name = randomElement(PATTERNS); + var name = RandomUtil.randomElement(PATTERNS); var word; while (hasTemplate(name)) { for (var template in CATEGORIES) { - word = randomElement(CATEGORIES[template]); + word = RandomUtil.randomElement(CATEGORIES[template]); name = name.replace(template, word); } } @@ -202,4 +195,4 @@ var RoomNameGenerator = { } }; -module.exports = RoomNameGenerator; +module.exports = RoomnameGenerator;