views:

49

answers:

1

Hi!

I need to convert one script from Prototype to Jquery, but I'm no good with Jquery.

If someone can do this, i will thank so much =)

Here's the code in Prototype:

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
replace_ids = function(s){
  var new_id = new Date().getTime();
  return s.replace(/NEW_RECORD/g, new_id);
}

var myrules = {
  '.remove': function(e){
    el = Event.findElement(e);
    target = el.href.replace(/.*#/, '.')
    el.up(target).hide();
    if(hidden_input = el.previous("input[type=hidden]")) hidden_input.value = '1'
  },
  '.add_nested_item': function(e){
    el = Event.findElement(e);
    template = eval(el.href.replace(/.*#/, ''))
    $(el.rel).insert({     
      bottom: replace_ids(template)
    });
  },
  '.add_nested_item_lvl2': function(e){
    el = Event.findElement(e);
    elements = el.rel.match(/(\w+)/g)
    parent = '.'+elements[0]
    child = '.'+elements[1]

    child_container = el.up(parent).down(child)    
    parent_object_id = el.up(parent).down('input').name.match(/.*\[(\d+)\]/)[1]

    template = eval(el.href.replace(/.*#/, ''))

    template = template.replace(/(attributes[_\]\[]+)\d+/g, "$1"+parent_object_id)

   // console.log(template)
    child_container.insert({     
      bottom: replace_ids(template)
     });
  }
};

Event.observe(window, 'load', function(){
  $('container').delegate('click', myrules);
});

Thank you guys!

A: 
  1. Google "convert prototype to jquery"
  2. Look for a page where someone blogged about how to do it
  3. Read page
  4. Apply learned knowledge to task at hand

If you run into problems, post them here in the form of specific questions

zetetic
Hi zetetic, Sorry for the question, I'm not normally ask for help in this way. I really know very little about JQuery and Prototype, I'm learning Ruby on Rails and I had to do this conversion.It was not my intention to abuse the goodwill of members of stackoverflow. I hope you understand. Maikon
Maikon
No problem, and sorry for the snarky answer. You'll get better responses if you show that you've done some legwork first, and at least taken a crack at trying to answer the question yourself. I was serious about point #1 -- the first page of results give some good info on how to translate Prototype to jQuery.
zetetic