Permalink
Browse files

abstract the js for chat and rest of application. rename 'fluid' layo…

…ut to 'chat' to be more descript since we only use that layout for the chat room view.
  • Loading branch information...
1 parent 94a3cbb commit abe0757249bdaed7bbe6e562f1c71b3f2c763112 Blake Lucchesi committed May 26, 2010
@@ -12,7 +12,7 @@ def show
if (session[@room.id].nil?)
redirect_to "/rooms/enter/#{@room.id}"
else
- render :layout => 'fluid'
+ render :layout => 'chat'
end
end
@@ -17,7 +17,7 @@
<%= render :partial => 'layouts/footer' %>
- <%= javascript_include_tag :jquery %>
+ <%= javascript_include_tag :jquery, %w(chat) %>
<%= yield :js %>
</body>
@@ -1,14 +1,8 @@
// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
-var Application = { vars: {} }
-
-var running = true;
$().ready(function() {
- // Setup the window.
- $('input[type=text]', '#chatbox').focus();
-
$('#room_password').hide();
$('#password_label').hide().val('Enter password').focus(function() {
$(this).hide();
@@ -23,52 +17,7 @@ $().ready(function() {
$('#password_label').hide();
$('#room_password').hide();
}
- })[0].checked = false; // Always reset to unchecked for when we fail validation.
+ }).val(false); // Always reset to unchecked for when we fail validation.
- // Poll for updates.
- if ($('#rooms-show').size() > 0 && running) {
-
- // Listen for window resizing
- $(window).resize(resize_window);
- resize_window();
- scroll_bottom();
-
- // Poll for updates
- $.PeriodicalUpdater('/rooms/'+Application.vars.room_id+'/updates', {
- method: 'get', // method; get or post
- data: {message_id: get_last_id }, // array of values to be passed to the page - e.g. {name: "John", greeting: "hello"}
- minTimeout: 500, // starting value for the timeout in milliseconds
- maxTimeout: 5000, // maximum length of time between requests
- multiplier: 1.5, // if set to 2, timerInterval will double each time the response hasn't changed (up to maxTimeout)
- type: 'html', // response type - text, xml, json, etc. See $.ajax config options
- maxCalls: 0, // maximum number of calls. 0 = no limit.
- autoStop: 0 // automatically stop requests after this many returns of the same data. 0 = disabled.
- }, function(response) {
- if (response) {
- $('#messages').append(response);
- scroll_bottom();
- }
- });
- }
});
-function resize_window() {
- var sideoffset = 70;
- $('#room-main').width($('#wrapper').width() - $('#room-sidebar').width() - sideoffset+'px');
-
- var voffset = 165;
- var height = $(window).height() - $('#room-header').height() - $('#chatbox').height() - voffset;
- $('#messages').css('height', height+'px');
-
- var hoffset = 60;
- var width = $('#chatbox').width() - hoffset;
- $('input[type=text]', '#chatbox').css('width', width+'px');
-}
-
-function get_last_id() {
- return $('.message:last', '#messages').attr('id');
-}
-
-function scroll_bottom() {
- $('#messages').animate({scrollTop: $('#messages')[0].scrollHeight+'px'});
-}
@@ -0,0 +1,56 @@
+var Application = { vars: {} }
+
+var running = true; // Disable polling during debug.
+
+$().ready(function() {
+
+ // Focus on the chat text input.
+ $('input[type=text]', '#chatbox').focus();
+
+ // Listen for window resizing.
+ resize_window();
+ scroll_bottom();
+
+ // Poll for updates.
+ if ($('#rooms-show').size() > 0 && running) {
+ // Poll for updates
+ $.PeriodicalUpdater('/rooms/'+Application.vars.room_id+'/updates', {
+ method: 'get', // method; get or post
+ data: {message_id: get_last_id }, // array of values to be passed to the page - e.g. {name: "John", greeting: "hello"}
+ minTimeout: 500, // starting value for the timeout in milliseconds
+ maxTimeout: 5000, // maximum length of time between requests
+ multiplier: 1.5, // if set to 2, timerInterval will double each time the response hasn't changed (up to maxTimeout)
+ type: 'html', // response type - text, xml, json, etc. See $.ajax config options
+ maxCalls: 0, // maximum number of calls. 0 = no limit.
+ autoStop: 0 // automatically stop requests after this many returns of the same data. 0 = disabled.
+ }, function(response) {
+ if (response) {
+ $('#messages').append(response);
+ scroll_bottom();
+ }
+ });
+ }
+});
+
+$(window).resize(resize_window);
+
+function resize_window() {
+ var sideoffset = 70;
+ $('#room-main').width($('#wrapper').width() - $('#room-sidebar').width() - sideoffset+'px');
+
+ var voffset = 165;
+ var height = $(window).height() - $('#room-header').height() - $('#chatbox').height() - voffset;
+ $('#messages').css('height', height+'px');
+
+ var hoffset = 60;
+ var width = $('#chatbox').width() - hoffset;
+ $('input[type=text]', '#chatbox').css('width', width+'px');
+}
+
+function get_last_id() {
+ return $('.message:last', '#messages').attr('id');
+}
+
+function scroll_bottom() {
+ $('#messages').animate({scrollTop: $('#messages')[0].scrollHeight+'px'});
+}

0 comments on commit abe0757

Please sign in to comment.