<div dir="ltr">I wrote an fbjs library to help speed up development of some of my applications. I plan to have some sort of "official" release with a blog entry and github repository at some point, but I thought you guys might want to have it earlier.<br>
<br>It's still a work in progress. I've been using every method at least once in my application but it's still possible there is a bug or two I missed. Let me know if you find any bugs.<br><br><br>Javascript (stand alone)<br>
<a href="http://pastie.org/256150">http://pastie.org/256150</a><br><br>Rails Helpers:<br><a href="http://pastie.org/256153">http://pastie.org/256153</a><br><br><br>Examples of use:<br> Select Element<br> $('noelement');<br>
<br> Select 2 Elements<br> $('test1','test2');<br> <br> Select elements by class<br> getElementsByClass('test2c')<br> <br> Select elements by tag<br> getElementsByTagName('strike')<br>
<br> Use Javascript version of .map<br> ['a2','b2'].toSource() == map(['a','b'], function(val) { return val+2 }).toSource()<br> <br> Recurse through the dom under a selected element and return nodes for which test is true as an array<br>
collect($('test1'), function(element){ return (element.getClassName() == 'test2c') })<br> <br> Check if an element is visible<br> $('test1').visible()<br> <br> Hide an element<br>
$('test1').hide()<br> <br> Show an element<br> $('test1').show()<br> <br> Toggle element visibility<br> $('test1').toggle();<br> <br> Remove an element from the dom<br> $('test1').remove();<br>
<br> Get a hash of calculated element dimensions width/height as integers<br> $('test1').getDimensions()<br> <br> Update remote<br> Update: function(target_element, response_type, action_path, callbacks, post_parameters)<br>
(FBML/RAW) <br> Ajax.Update('test1', 'FBML', 'http://...',{ success: function(){} })<br> <br> Load Remote<br> Load: function(response_type, action_path, callbacks, post_parameters)<br>
(FBML/RAW/JSON) <br> Ajax.Load('JSON','http://...',{ success: function(result){console.log(result)} }, {'json':test_content})<br> <br> Remote Form<br> <%= fbjs_form_remote_tag :update => 'a', :html => { :action => '<a href="http://inigral.ath.cx:3003/javascript_test/test_helpers_res">http://inigral.ath.cx:3003/javascript_test/test_helpers_res</a>' }, :response => 'RAW' %><br>
<input type="hidden" name="test_hidden" value="test value"/><br> <input type="checkbox" name="test_box" checked="true"/><br> <input name="test_input"/> <br>
<input type="submit" value="submit"/><br> </form><br> <div id="a"/><br> <br> In place Edit<br> Will post: {txt_field_name:'Text inside editable field'}<br>
<%= fbjs_in_place_editor_text_div('txt_field_name', 'Text inside editable field', 'http://...', { :class => 'test' }) %><br> <a href="#" onclick="txt_field_name_editor.edit()">edit</a><br>
<a href="#" onclick="txt_field_name_editor.save()">save</a><br></div>