<commit_before>module ActionView
  module Helpers
    module PrototypeHelper
      
      def periodically_call_remote(options = {})
        frequency = options[:frequency] || 10 # every ten seconds by default
        code = "setInterval(function() {#{remote_function(options)}}, #{frequency} * 1000)"
        javascript_tag(code)
      end
      
      def remote_function(options)
        javascript_options = options_for_ajax(options)

        update = ''
        if options[:update] && options[:update].is_a?(Hash)
          update  = []
          update << "success:'#{options[:update][:success]}'" if options[:update][:success]
          update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure]
          update  = '{' + update.join(',') + '}'
        elsif options[:update]
          update << "'#{options[:update]}'"
        end

        function = "$.ajax(#{javascript_options})"

        function = "#{options[:before]}; #{function}" if options[:before]
        function = "#{function}; #{options[:after]}"  if options[:after]
        function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
        function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]
        return function
      end
      
      class JavaScriptGenerator
        module GeneratorMethods
          
          def select(pattern)
            record "$('#{pattern}')"
          end
          
          def insert_html(position, id, *options_for_render)
            insertion = position.to_s.downcase
            insertion = 'append' if insertion == 'bottom'
            insertion = 'prepend' if insertion == 'top'
            record "$('##{id}').#{insertion}('#{render(*options_for_render)}')"
          end
          
          def replace_html(id, *options_for_render)
            insert_html(:html, id, *options_for_render)
          end
          
          def replace(id, *options_for_render)
            record "$('##{ids.join(',#')}').replaceWith('#{render(*options_for_render)}')"
          end
          
          def remove(*ids)
            record "$('##{ids.join(',#')}').remove()"
          end
          
          def show(*ids)
            record "$('##{ids.join(',#')}').show()"
          end
          
          def hide(*ids)
            record "$('##{ids.join(',#')}').hide()"     
          end

          def toggle(*ids)<commit_msg>escape_javascript fix for rjs<commit_after>module ActionView
  module Helpers
    module PrototypeHelper
      
      def periodically_call_remote(options = {})
        frequency = options[:frequency] || 10 # every ten seconds by default
        code = "setInterval(function() {#{remote_function(options)}}, #{frequency} * 1000)"
        javascript_tag(code)
      end
      
      def remote_function(options)
        javascript_options = options_for_ajax(options)

        update = ''
        if options[:update] && options[:update].is_a?(Hash)
          update  = []
          update << "success:'#{options[:update][:success]}'" if options[:update][:success]
          update << "failure:'#{options[:update][:failure]}'" if options[:update][:failure]
          update  = '{' + update.join(',') + '}'
        elsif options[:update]
          update << "'#{options[:update]}'"
        end

        function = "$.ajax(#{javascript_options})"

        function = "#{options[:before]}; #{function}" if options[:before]
        function = "#{function}; #{options[:after]}"  if options[:after]
        function = "if (#{options[:condition]}) { #{function}; }" if options[:condition]
        function = "if (confirm('#{escape_javascript(options[:confirm])}')) { #{function}; }" if options[:confirm]
        return function
      end
      
      class JavaScriptGenerator
        module GeneratorMethods
          
          def select(pattern)
            record "$('#{pattern}')"
          end
          
          def insert_html(position, id, *options_for_render)
            insertion = position.to_s.downcase
            insertion = 'append' if insertion == 'bottom'
            insertion = 'prepend' if insertion == 'top'
            record "$('##{id}').#{insertion}('#{escape_javascript(render(*options_for_render))}')"
          end
          
          def replace_html(id, *options_for_render)
            insert_html(:html, id, *options_for_render)
          end
          
          def replace(id, *options_for_render)
            record "$('##{ids.join(',#')}').replaceWith('#{escape_javascript(render(*options_for_render))}')"
          end
          
          def remove(*ids)
            record "$('##{ids.join(',#')}').remove()"
          end
          
          def show(*ids)
            record "$('##{ids.join(',#')}').show()"
          end
          
          def hide(*ids)
            record "$('##{ids.join(',#')}').hide()"     
          end

          def toggle(*ids)
{'fraction_non_alphanumeric': 0.16214025131738954, 'fraction_numerical': 0.0024321037697608433, 'mean_word_length': 2.212890625, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2677567', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1337, 'n_words': 266}