• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
 

In prototype.js, Event.observe method is very useful. But it is a bit inconvenient if you want to handle events only once such as an initialization. I have often encountered such situation, so I wrote a small utility function being as follows.

   1  Event.observeOnce = function(element, event, observer){
   2    var handler = function(){
   3      Event.stopObserving(element, event, handler);
   4      return observer.apply(null, $A(arguments));
   5    };
   6    Event.observe(element, event, handler);
   7  };

The usage is same to Event.observe.

   1  Event.observeOnce(document, 'dom:loaded', function(){
   2    /* some code goes here */
   3  });

It may be useful if you copy this into public/javascripts/application.js for Rails applications.

posted by Png takiuchi on Thu 28 Feb 2008 at 17:23
27th Wed

About Me

My name is Genki Takiuchi. I was born in Tokyo at 1980, so I am 27.

I've started programming when I was 8 years old. Simple games brought me to the world defined by BASIC. 20 years made me pass through many languages such as C/C++, HDL, HLSL, Java, D, Perl, Scheme, Erlang, Haskell and Ruby.

I won the Minister of Education prize at the programming contest in Japan when I was 19. I had studied concentratedly about computer graphics (photorealistic rendering) and statistics.

And now, I have worked with Ruby on Rails for more than 2 years. I wrote some articles to "WEB+DB press" and "Nikkei Software" which are magazines published in Japan.

I have a life work that is to solve the problem in the computer graphics.

posted by Png takiuchi on Wed 27 Feb 2008 at 15:24

I decided to separate entries into two blogs according to its language. This is the first entry which has written in English to this weblog.

I had decided learn about English about two years ago, but that is not achieved yet. The goal is so far. I want to communicate with cool programmers using English as a native or second language.

By the way, I plan to write something about Ruby on Rails, computer graphics (especially about offline rendering) and so on to this blog.

If you are familiar with Japanse, please visit "Hello, world!" the another weblog which is written Japanese.

Thank you.

posted by Png takiuchi on Wed 27 Feb 2008 at 13:27
Contents
Handling Event Once by Using Event.observeOnce
About Me
I Started New Weblog in English
Comments
Spencer: You don't have to re-compile it, this version w... '14-4
staiano: Any chance we can get a recompile for 10.9? '14-1
falsefalse: @tiancongxin try using this one https://github.... '12-2
tiancongxin: TerminalCopyOnSelect not work on OS X 'Lion' , ... '11-7
staiano: Roderick you rock for recompiling it. Thanks. '11-3
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ