Tree

loaded.fu.tree bug

loaded.fu.tree gets called before the tree is fully initialized (the data is not yet added to the tree object on the DOM). Attaching a method to the `loaded.fu.tree` event that then calls any methods on the tree gets you caught in a loop, because at that point it looks at the tree, thinks it isn't loaded (based on the return of $.data('fu.tree') call in the plugin definition) and tries to re-initialize the tree all over again, thus causing loaded.fu.tree to fire off again, loop forever, stack overflow, die.

Therefore, `loaded.fu.tree` cannot be relied upon to ascertain when the tree has been initialized. For that purpose, `initialized.fu.tree` has been added to the tree.

In short, using `loaded.fu.tree` to fire events that in turn call the tree when the tree is loaded causes an infinite loop. Use `initialized.fu.tree` instead.

Right:

			$tree.on('initialized.fu.tree', function triggerDiscloseFolder () {
				var $initialBranch = $($tree.find('li:not(".hidden"):first'));
				$tree.tree('discloseFolder', $initialBranch);
			});
			

Wrong:

			$tree.on('loaded.fu.tree', function triggerDiscloseFolder () {
				var $initialBranch = $($tree.find('li:not(".hidden"):first'));
				// Causes infinite loop
				$tree.tree('discloseFolder', $initialBranch);
			});
			

To see the bug in action, change line 231 in this file and load the page in the browser. You will see "loading..." show up below two of the folders (even though they appear closed). Another workaround is to change the "on" to "one" instead, but this is sub-optimal in that it just ducks under the bug.