Home | Projects | Tutorials | Articles | live chat | Submit Project | Big Vote
 
Ajax Projects
.NET Frameworks
Java Frameworks
PHP Frameworks
Ruby Frameworks
Other Frameworks
Cool AJAX sites
Ajax Resources
Ajax Tools
JavaScript frameworks

 Home /  Tutorials / How To Use JQuery With APE

How To Use JQuery With APE





In this tutorial you will know how to use jQuery with APE by create a new class calling DUI.Class.create(obj, fn) like this code:

Read The Full Tutorial.
































In this tutorial you will know how to use jQuery with APE by create a new class calling DUI.Class.create(obj, fn) like this code:

   1. /**
   2.  * @author Paul Price
   3.  * Who needs MooTools' Class() method?
   4.  */  
   5.   
   6. APE.bgColor = DUI.Class.create(APE.Client.prototype, {  
   7.     // set default options  
   8.     options:{  
   9.         debug: false,  
  10.         select: null  
  11.     },  
  12.   
  13.     init: function(core, options){  
  14.         this.core = core;  
  15.         this.options = options;  
  16.   
  17.         // do the following every time we get a new user  
  18.         this.addEvent('pipeCreate', this.setup);
  19.  
  20.         // when a user joins, update the user list
  21.         this.addEvent('userJoin', this.createUser);
  22.  
  23.         // when a user leaves, destroy them with mighty thunder!
  24.         this.addEvent('userLeft', this.deleteUser);
  25.  
  26.         // when we want to send data
  27.         this.onCmd('send', this.cmdSend);
  28.  
  29.         // and when we recieve data
  30.         this.onRaw('data', this.rawData);
  31.  
  32.         // start the session with a random name!
  33.         var username = prompt("Hey good lookin', what's your name?", String((new Date()).getTime()).replace(/\D/gi,''));
  34.         this.core.start(username);
  35.     },
  36.  
  37.     setup: function(type, pipe, options){
  38.         // add an event listener on our selectbox
  39.         this.options.select.change(function(){
  40.             // get the select box value
  41.             color = $("option:selected", this).val();
  42.  
  43.             // set the background of the document to the color chosen
  44.             $("body").css("background-color", color);
  45.  
  46.             // send the new color to the APE server
  47.             pipe.send(color);
  48.         });
  49.     },
  50.  
  51.     cmdSend: function(pipe, sessid, pubid, message){
  52.         if(this.options.debug)
  53.             $("<span>&nbsp;&nbsp;&nbsp;&nbsp;" + this.core.user.properties.name + " changed the bg color to " + message + "</span><br />").prependTo("#debug");
  54.     },
  55.  
  56.     rawData: function(raw, pipe){
  57.         if(this.options.debug)
  58.             $("<span>&nbsp;&nbsp;&nbsp;&nbsp;" + raw.datas.sender.properties.name + " changed the bg color to " + raw.datas.msg + "</span><br />").prependTo("#debug");
  59.  
  60.         // set the selectboxes value to match
  61.         this.options.select.val(raw.datas.msg);
  62.  
  63.         // set the color
  64.         $("body").css("background-color", raw.datas.msg);
  65.     },
  66.  
  67.     createUser: function(user, pipe){
  68.         user.element = $("<span>" + user.properties.name + " has joined bgColor</span><br />").prepend("<img src='bullet_green.png' />").prependTo("#debug");
  69.     },
  70.  
  71.     deleteUser: function(user, pipe){
  72.         $(user.element).text(user.properties.name + " has left bgColor").css("color", "#666666").prepend("<img src='bullet_red.png' />");  
  73.     }  
  74. });   

Next step is to update the bit of code that creates the class (from):

   1. new colorChanger(ape, debug).initialize();  

(to)

   1. var bgcolor = new APE.bgColor(ape,{  
   2.     debug: true,  
   3.     select: $("#wrapper select[name=selectColor]")  
   4. });  
AddThis Social Bookmark Button
Top Projects
MSN Web Messenger
MessengerFX
ebuddy
e-messenger
ILoveIM
You Tube
AJAX file upload
KoolIM.com
Meebo
Ajax.NET Professional
Tutorials
How To Creating Horizontal CSS Menu
AJAX Based Shopping Cart with PHP CSS and jQuery
Spring MVC and AJAX with JSON
Using HTTP Status Codes for Rails AJAX Error Handling
How to add Google Maps to your website?
ASP.Net Ajax CheckBoxList with data binding
Developing Ajax Portlets with Eclipse WTP
Some thoughts on ASP.NET AJAX Roadmap
Database-enabled Ajax with PHP
How to rotate JavaScript ads during ASP.NET AJAX requests