HTML and CSS Reference
In-Depth Information
!tddjs.namespace("chat").userFormController) {
alert("Browser is not supported");
return;
}
var chat = tddjs.chat;
var model = {};
var userForm = document.getElementById("userForm");
var userController =
Object.create(chat.userFormController);
userController.setModel(model);
userController.setView(userForm);
userController.observe("user", function (user) {
alert("Welcome, " + user);
});
}());
Now start the server and bring up http://localhost:8000/ in your browser of
choice. You should be presented with an unstyled form. Upon submitting it, the
browser should alert you with a greeting and hide the form. It's not much, but it's
working code, and having a working testbed for the client means we can easily take
new components for a spin as they are completed.
15.4 The Message List
The message list will consist of a definition list, in which messages are represented
by a dt element containing the user and a dd element containing the message. The
controller will observe the model's “message” channel to receive messages, and will
build DOM elements and inject them into the view. As with the user form controller,
it will add the “js-chat” class to the view when it is set.
15.4.1 Setting the Model
For this controller, we will start by adding the model object. In contrast to the user
form controller, the message list will need to do more than simply assign the model.
15.4.1.1 Defining the Controller and Method
Listing 15.42 shows the initial test case that asserts that the controller exists. Save it
in test/message _ list _ controller _ test.js .
 
 
Search WWH ::




Custom Search