Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
An example of bad code for Simple Modules
<script src="jquery.js"></script>
<script src="jquery-ui.combined.js"></script>
<script src="AwesomeCommunicationsLibrary"></script>
<script src="helperFuncs.js"></script>
<input id="my-username" placeholder="Your Username" >
<script type="text/javascript">
$('#my-username').val('<?php echo(default_username) ?>');
var spaceIsPressed = false;
var roomId = getUrlVars().roomId;
var sessionId = getUrlVars().sessId;
var userJoinedEmphasizedFor = 60 * 1000;
var apiKey = '<?php echo(comm_library_api_key); ?>';
//If it is possible ot talk, start transmitting audio when space is pressed down
$(document).on('keydown', function(e){
if(!audioChannel || e.keyCode != 32)
spaceIsPressed = true
}).on('keyup', function(e){
if(!audioChannel || e.keyCode != 32 || !spaceIsPressed)
spaceIsPressed = false;
//Initialize communicationsLib
communicationsLib = new AwesomeCommunicationsLibrary(apiKey);
communicationsLib.setUsername( $('#my_username').val() );
//Change the username used by communicationsLib if the username input changes
$('#my_username').on('blur', function(){
communicationsLib.setUsername( $('#my_username').val() );
<section id="current-messages">
<section id="current-user-list">
<ul class="users">
<button class="join-conversation">Join the Conversation</button>
<form id="send-message" action="/#">
<input placeholder="Your Message" />
<button type=submit>Send</button>
//local helper function to add messages
function addMessage(text) {
//need to get this from communicationsLib, used to send audio
var audioChannel = null;
//Join the configured room. once that is done we can
//populate the ui and get the audioChannel
communicationsLib.joinRoom(getUrlVars().roomName, function(room){
addMessage("Joined room "; { showInRoom(u, true) });
room.getAudioChannel(function(channel) {
audioChannel = channel;
room.on('user-joined', showInRoom);
room.on('message-recieved', addMessage);
var $sendMsg = $('form#send-message').on('submit', function(e){
var $inpt = $('input', $sendMsg);
addMessage("You: "+$inpt.val());
function showInRoom(user, previouslyInRoom) {
var $el = $('<li>').text('#current-user-list>ul.users');
setTimeout(function(){ $el.removeClass('just-joined')}, userJoinedEmphasizedFor);
showDialog("Join the chat and press space to start talking");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment