views:

578

answers:

6

I'd like to display a tree on a Facebook page with JavaScript. Therefore there can be no dependencies on frameworks such as jQuery or Ext which won't run on Facebook, at least as far as I know when I last worked on that platform (April 2009). Can anybody recommend a "framework-free" JavaScript/tree library? I have ported some fairly complex JavaScript to Facebook so I'm sure I'll be able to port just about any existing pure JavaScript library.

Clarification points:

  • I am targeting FBJS
  • I too can (and did) google for JavaScript/tree engines but am seeking recommendations as to which one(s)
+1  A: 

I looked at the munging in FBJS. Not sure why it would make jQuery not work, but if someone has some insight, I'd love to hear it.

I do know that you probably can't use jQuery's $ due to conflicts. But that can be changed from $() to jQuery() easily enough.

I could tell you what treeview I like, but without trying it in Facebook it might fail for the same reasons as jQuery.

Robert Harvey
He might be running FBJS instead of JavaScript.
Nosredna
indeed i am running FBJS
George Jempty
Nosredna
Thanks, Nosredna.
Robert Harvey
Another reason why JQuery does not work on FB is that the FBJS/sandbox disallows access to the necessary facets of Javascript and the DOM API needed by JQuery's (dom) "ready" functionality
George Jempty
+1  A: 

Even if you work mostly in FBML and FBJS, you can use <fb:iframe/> to render raw HTML and JavaScript without the FB munging going on.

What kind of page are you targeting? <fb:iframe/> works on canvas pages but not on a user's profile page.

Nosredna
Well I think I want to target FBJS. This will start on a canvas page, but eventually may grow into an application, and if I recall, fb/iframe is not applicable for an "app in a tab"
George Jempty
+2  A: 

You didn't describe the requirements for your JS tree, so I would suggest you write one yourself. It's a relatively simple task unless you need more complex functionality.

A simple tree is just a matter of having a bunch of DOM nodes that have other DOM nodes inside them that can be toggled on and off (display block/none)

Jani Hartikainen
A: 

What are your requirements? Can you post a snippet of code that you'd like to work with the library? Eg:

<div id="mytree"></div>
(function(){
  var tree = new TreeLib("mytree", {
    name: "Root", 
    expanded: true, 
    children: [
      {name: "first child"},
      {name: "another child"}
    ]
  });
  tree.onclick = function(node){
    alert("You clicked " + node.name);
  };
})();
svinto
+5  A: 

Look at this implementation... http://www.destroydrop.com/javascripts/tree/

dacracot
Posted a much less simple/direct method, then saw this one and deleted mine. :) This seems like exactly what the OP is looking for! Bravo.
Skeolan
+1  A: 

You really should write and test your own to get exactly what you want, and you didn't describe exactly what you want from a tree, but perhaps you could try the free version of treeview.

dlamblin