module ActionView::Helpers::PrototypeHelper def build_observer(klass, name, options={}) if options[:with] && !options[:with].include?("=") options[:with] = "'#{options[:with]}=' + value" else options[:with] ||= 'value' if options[:update] end element_ref = options[:inline] ? "'#{name}'" : 'this' callback = options[:function] || remote_function(options) javascript = "new #{klass}(#{element_ref}, " javascript << "#{options[:frequency]}, " if options[:frequency] javascript << "function(element, value) {" javascript << "#{callback}}" javascript << ", '#{options[:on]}'" if options[:on] javascript << ")" if options[:inline] javascript_tag(javascript) else @controller.apply_behaviour("##{name}", javascript) return '' end end end