Skip to content

Instantly share code, notes, and snippets.

View scottharvey's full-sized avatar

Scott Harvey scottharvey

View GitHub Profile
git clone http://github.com/ry/node.git
cd node
./configure
make
sudo make install
Var Room = function (elementId) {
// public properties
this.element = $("#" + elementId);
this.tooltip = this.element.find(".tooltip");
// Any function calls in here will be executed when a room object is instantiated
this.initalizeTooltip();
}
// Here we are defining a class method that can be called like this: Room.count();
var Room = function (elementId) {
function Room(elementId) {
// public properties
this.element = $("#" + elementId);
this.tooltip = this.element.find(".tooltip");
// Any function calls in here will be executed when a room object is instantiated
this.initalizeTooltip();
Room.count = function() {
return $(".room").length;
}
Room.prototype.roomText = function() {
return this.element.find("p").text();
};
<div id="#rooms">
<div id="room_1">Room 1</div>
<div id="room_2">Room 2</div>
</div>
var room1 = new Room("room_1");
var room2 = new Room("room_2");
room1.roomText(); // Room 1
room1.next(); // <div id="room_2">Room 2</div>
(function () {
// For each room div that is on the page we want to create a new Room object.
// In this example we are then saving the objects into a global 'rooms' array.
window.rooms = [];
$(".room").each(function() {
rooms.push(new Room(this.id));
});
// Here we are defining an event listener to listen for when a room div is clicked.
$("#rooms").delegate(".room", "click", function () {