Plugin Directory

Changeset 1106580


Ignore:
Timestamp:
03/06/2015 04:59:36 AM (11 years ago)
Author:
guavaworks
Message:

added in auto scroll chat when new message if needed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chat-rooms-powered-by-firebase/trunk/js/chatroom_app.js

    r1106539 r1106580  
     1var $ = jQuery;
    12var chat_app = angular.module( 'chat_app', ['firebase'] );
    23
     
    67   
    78    $scope.startChat = function( post ) {
    8         console.log( post );
    99        $http.get( wpAngularVars.base +'/posts/' + post ).then(function(res) {
    1010            $scope.chatroom = res.data;
    1111           
    1212            var fire_chatroom = $firebase( new Firebase( fireData.fire_url ).child( $scope.chatroom.ID )).$asObject();
    13             fire_chatroom.$bindTo( $scope, 'fireChat' );
    14            
     13            fire_chatroom.$bindTo( $scope, 'fireChat' ).then(function(){
     14                console.log('chat messages init..');
     15                $scope.scrollChat();
     16            });
    1517        });
    1618    }
     
    1820    $scope.resetMsg = function( name ) {
    1921        $scope.msg = {
     22            name: name,
    2023            msg: ''
    2124        }
     
    3336       
    3437        $scope.resetMsg( name );
     38        $scope.scrollChat();
    3539       
     40    }
     41   
     42    $scope.scrollChat = function() {
     43        if( $('#fire_chat_messages')[0].scrollHeight > $('#fire_chat_messages').outerHeight() ) {
     44            $('#fire_chat_messages').animate({
     45                scrollTop: $('#fire_chat_messages')[0].scrollHeight
     46            })
     47        }
    3648    }
    3749   
Note: See TracChangeset for help on using the changeset viewer.