File: CLIENT/js/XajaClient.js

Recommend this page to a friend!
  Classes of Ettore Moretti  >  Xaja Notifier  >  CLIENT/js/XajaClient.js  >  Download  
File: CLIENT/js/XajaClient.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Xaja Notifier
Notify user browsing a site in real time with AJAX
Author: By
Last change:
Date: 4 years ago
Size: 1,477 bytes
 

Contents

Download
/* 
 * Author: Ettore Moretti
 * Description: This JavaScript code includes functions for calls to the server and for displaying the final notification.
*/

var SERVERLNK="http://localhost/laboratorio/xajanotifier/SERVER/";

function longPollNotification() {
    $.ajax({
        type: "GET",
        url: SERVERLNK+"HttpLongPoll.php?timestamp=" + XajaSettings.timestamp + "&id=" + XajaSettings.uid,
        async: true,
        cache: false,

        success: function(data) {
            var json = eval('(' + data + ')');
            if (json['msg'] != "") {
                $("#notification").empty();
                $("#notification").append(json['msg']);
                $('#notification').animate({
                    top: "0"
                }, 500);
            }
            timestamp = json["last_server_timestamp"];
            setTimeout("longPollNotification()", 1000);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            setTimeout("longPollNotification()", 15000);
        }
    });
}

$(document).ready(function() {
    //Start long polling
	longPollNotification();

    //Hide notification div
    messagesHeight = $('#notification').outerHeight();
    $('#notification').css('top', -messagesHeight); //move element outside viewport  

    // When notification is clicked, hide it
    $('#notification').click(function() {
        $(this).animate({
            top: -$(this).outerHeight()
        }, 500);
    });

});

For more information send a message to info at phpclasses dot org.