[Proto-Scripty] Re: Events in own Class

2009-06-30 Thread Matt Foster

This will work, but remember that the instance isn't going to actually
fire an event, its just really acting as liaison to the document
object to fire off events via document.  You've somewhat namespaced
the event with your reference ID which is going to make things
difficult for anything attempting to observe an event from an
instance.

document.observe(observable_ + myInstance._refID + :onFoo);

Prototype's custom events are events that can fire from a DOM
instance, which will bubble to parents and can be caught at the top or
wherever along the propagation chain.  What I believe you are looking
for is events fired from a function/class instance.  You can get the
function instance to throw an event by using the scripts i posted
above.

--

http://positionabsolute.net




On Jun 29, 5:07 pm, Sven stuebe...@googlemail.com wrote:
 ok

 i tryed something...

 var Observable = Class.create({
     initialize : function(){
         this._refID = Observable.prototype.refCount++;
     },

     observe : function(name, handler){
         document.observe('observable_' + this._refID + ':' + name,
 handler);
     },

     fire    : function(name){
         document.fire('observable_' + this._refID + ':' + name);
     }

 });

 Object.extend(Observable.prototype, {refCount : 0});

 var Test = Class.create(Observable, {
     initialize : function($super){
         $super();
     },

     foo : function(){
         this.fire('onFoo');
     }

 });

 is only a prototype for testing. Is it the right way or not?

 thanks,

 rgds sven

 On 29 Jun., 20:17, Matt Foster mattfoste...@gmail.com wrote:

  I ran into this same issue and made a class to extend others from to
  inherit this sort of functionality.

  This is the article but the JS itself is a bit 
  outdatedhttp://positionabsolute.net/blog/2007/06/event-dispatcher.php

  To get the freshest 
  JS...http://positionabsolute.net/includes/javascripts/EventDispatcher.js

  On Jun 29, 12:56 pm, Sven stuebe...@googlemail.com wrote:

   hmm but wait

   this is a global event...
   i want a instance-based event.

   xyz.foo(); //alert(barbarbar);
   abc.foo(); // alert(1234); and second $('bla').hide();

   rgds sven

   On 29 Jun., 18:41, Sven stuebe...@googlemail.com wrote:

wow thank you ;)

On 29 Jun., 18:38, Rick Waldron waldron.r...@gmail.com wrote:

 Dig it:

http://jsbin.com/uhogi

 (view the source)

 Rick

 On Mon, Jun 29, 2009 at 12:19 PM, Sven stuebe...@googlemail.com 
 wrote:

  Hi,

  is it possible to add Events to own classes?

  something like this:

  var myClass = Class.create({
         foo : function(){
                 this.fire('bar');
         }
  });

  var xyz = new MyClass();
  xyz.observe('bar', function(){alert(barbarbar);});

  rgds sven
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Events in own Class

2009-06-29 Thread Rick Waldron
Dig it:


http://jsbin.com/uhogi

(view the source)



Rick




On Mon, Jun 29, 2009 at 12:19 PM, Sven stuebe...@googlemail.com wrote:


 Hi,

 is it possible to add Events to own classes?

 something like this:

 var myClass = Class.create({
foo : function(){
this.fire('bar');
}
 });

 var xyz = new MyClass();
 xyz.observe('bar', function(){alert(barbarbar);});

 rgds sven
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Events in own Class

2009-06-29 Thread Sven

wow thank you ;)

On 29 Jun., 18:38, Rick Waldron waldron.r...@gmail.com wrote:
 Dig it:

 http://jsbin.com/uhogi

 (view the source)

 Rick



 On Mon, Jun 29, 2009 at 12:19 PM, Sven stuebe...@googlemail.com wrote:

  Hi,

  is it possible to add Events to own classes?

  something like this:

  var myClass = Class.create({
         foo : function(){
                 this.fire('bar');
         }
  });

  var xyz = new MyClass();
  xyz.observe('bar', function(){alert(barbarbar);});

  rgds sven
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Events in own Class

2009-06-29 Thread Rick Waldron
No problem

Rick

On Mon, Jun 29, 2009 at 12:41 PM, Sven stuebe...@googlemail.com wrote:


 wow thank you ;)

 On 29 Jun., 18:38, Rick Waldron waldron.r...@gmail.com wrote:
  Dig it:
 
  http://jsbin.com/uhogi
 
  (view the source)
 
  Rick
 
 
 
  On Mon, Jun 29, 2009 at 12:19 PM, Sven stuebe...@googlemail.com wrote:
 
   Hi,
 
   is it possible to add Events to own classes?
 
   something like this:
 
   var myClass = Class.create({
  foo : function(){
  this.fire('bar');
  }
   });
 
   var xyz = new MyClass();
   xyz.observe('bar', function(){alert(barbarbar);});
 
   rgds sven
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Events in own Class

2009-06-29 Thread Sven

hmm but wait

this is a global event...
i want a instance-based event.

xyz.foo(); //alert(barbarbar);
abc.foo(); // alert(1234); and second $('bla').hide();

rgds sven

On 29 Jun., 18:41, Sven stuebe...@googlemail.com wrote:
 wow thank you ;)

 On 29 Jun., 18:38, Rick Waldron waldron.r...@gmail.com wrote:



  Dig it:

 http://jsbin.com/uhogi

  (view the source)

  Rick

  On Mon, Jun 29, 2009 at 12:19 PM, Sven stuebe...@googlemail.com wrote:

   Hi,

   is it possible to add Events to own classes?

   something like this:

   var myClass = Class.create({
          foo : function(){
                  this.fire('bar');
          }
   });

   var xyz = new MyClass();
   xyz.observe('bar', function(){alert(barbarbar);});

   rgds sven
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Events in own Class

2009-06-29 Thread Rick Waldron
I think I set you on the right path... copy the code a gave you and see what
you can come up with.

Rick



On Mon, Jun 29, 2009 at 12:56 PM, Sven stuebe...@googlemail.com wrote:


 hmm but wait

 this is a global event...
 i want a instance-based event.

 xyz.foo(); //alert(barbarbar);
 abc.foo(); // alert(1234); and second $('bla').hide();

 rgds sven

 On 29 Jun., 18:41, Sven stuebe...@googlemail.com wrote:
  wow thank you ;)
 
  On 29 Jun., 18:38, Rick Waldron waldron.r...@gmail.com wrote:
 
 
 
   Dig it:
 
  http://jsbin.com/uhogi
 
   (view the source)
 
   Rick
 
   On Mon, Jun 29, 2009 at 12:19 PM, Sven stuebe...@googlemail.com
 wrote:
 
Hi,
 
is it possible to add Events to own classes?
 
something like this:
 
var myClass = Class.create({
   foo : function(){
   this.fire('bar');
   }
});
 
var xyz = new MyClass();
xyz.observe('bar', function(){alert(barbarbar);});
 
rgds sven
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Events in own Class

2009-06-29 Thread Matt Foster

I ran into this same issue and made a class to extend others from to
inherit this sort of functionality.

This is the article but the JS itself is a bit outdated
http://positionabsolute.net/blog/2007/06/event-dispatcher.php

To get the freshest JS...
http://positionabsolute.net/includes/javascripts/EventDispatcher.js




On Jun 29, 12:56 pm, Sven stuebe...@googlemail.com wrote:
 hmm but wait

 this is a global event...
 i want a instance-based event.

 xyz.foo(); //alert(barbarbar);
 abc.foo(); // alert(1234); and second $('bla').hide();

 rgds sven

 On 29 Jun., 18:41, Sven stuebe...@googlemail.com wrote:

  wow thank you ;)

  On 29 Jun., 18:38, Rick Waldron waldron.r...@gmail.com wrote:

   Dig it:

  http://jsbin.com/uhogi

   (view the source)

   Rick

   On Mon, Jun 29, 2009 at 12:19 PM, Sven stuebe...@googlemail.com wrote:

Hi,

is it possible to add Events to own classes?

something like this:

var myClass = Class.create({
       foo : function(){
               this.fire('bar');
       }
});

var xyz = new MyClass();
xyz.observe('bar', function(){alert(barbarbar);});

rgds sven
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Events in own Class

2009-06-29 Thread Sven

ok

i tryed something...

var Observable = Class.create({
initialize : function(){
this._refID = Observable.prototype.refCount++;
},

observe : function(name, handler){
document.observe('observable_' + this._refID + ':' + name,
handler);
},

fire: function(name){
document.fire('observable_' + this._refID + ':' + name);
}
});

Object.extend(Observable.prototype, {refCount : 0});

var Test = Class.create(Observable, {
initialize : function($super){
$super();
},

foo : function(){
this.fire('onFoo');
}
});


is only a prototype for testing. Is it the right way or not?

thanks,

rgds sven


On 29 Jun., 20:17, Matt Foster mattfoste...@gmail.com wrote:
 I ran into this same issue and made a class to extend others from to
 inherit this sort of functionality.

 This is the article but the JS itself is a bit 
 outdatedhttp://positionabsolute.net/blog/2007/06/event-dispatcher.php

 To get the freshest 
 JS...http://positionabsolute.net/includes/javascripts/EventDispatcher.js

 On Jun 29, 12:56 pm, Sven stuebe...@googlemail.com wrote:



  hmm but wait

  this is a global event...
  i want a instance-based event.

  xyz.foo(); //alert(barbarbar);
  abc.foo(); // alert(1234); and second $('bla').hide();

  rgds sven

  On 29 Jun., 18:41, Sven stuebe...@googlemail.com wrote:

   wow thank you ;)

   On 29 Jun., 18:38, Rick Waldron waldron.r...@gmail.com wrote:

Dig it:

   http://jsbin.com/uhogi

(view the source)

Rick

On Mon, Jun 29, 2009 at 12:19 PM, Sven stuebe...@googlemail.com wrote:

 Hi,

 is it possible to add Events to own classes?

 something like this:

 var myClass = Class.create({
        foo : function(){
                this.fire('bar');
        }
 });

 var xyz = new MyClass();
 xyz.observe('bar', function(){alert(barbarbar);});

 rgds sven
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~--~~~~--~~--~--~---