moksha/public/javascript/ui/moksha.ui.grid.js | 33 +++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-)
New commits: commit 31c345918ea28988506a2c506ffd06b85402fd3d Author: John (J5) Palmieri johnp@redhat.com Date: Tue May 5 18:10:38 2009 -0400
allow controls to be placed outside the containing grid
* grid-control elements can now specify the attach and ancestor attributes * attach specifies a jQuery selector relative to ancestor * ancestor specifies an integer which determines how many iterations to walk up the parent tree relative to the control element. If this is undefined attach is relative to the whole document. If it is 0 then we are relative to the grid element (which is pretty useless since you could have placed the control element instead of having the code do it for you)
* Example: <div id="second_ancestor"> <h4>title</h4> <div id="first_ancestor"> <span id="grid-controls" attach="h4:first" ancestor="2"> ... </div> </div>
this states that all controls inside this span will be moved to the first H4 which is a child of the second ancestor.
diff --git a/moksha/public/javascript/ui/moksha.ui.grid.js b/moksha/public/javascript/ui/moksha.ui.grid.js index 077379a..3607526 100644 --- a/moksha/public/javascript/ui/moksha.ui.grid.js +++ b/moksha/public/javascript/ui/moksha.ui.grid.js @@ -226,7 +226,7 @@ var self = this;
// get our controls - var $controls = $('#grid-controls', this.element.parent()); + var $controls = self._control_list;
// iterate through all of our control plugins // and get any id that matches @@ -240,15 +240,42 @@
_init_controls: function() { var self = this; + + $controls = $('#grid-controls', this.element.parent()); + self._control_list = $controls; + + $.each($controls, function(i, c) { + var $c = $(c); + var attach = $c.attr('attach'); + if (attach) { + // attach is a jQuery selector relative to the ancestor + // ancestor is specified by an integer indicating how many + // levels we should traverse up the parent tree + parent_nest = $c.attr('ancestor'); + + $parent = $(document); + if (typeof(parent_nest) != 'undefined') { + $parent = $c; + for (var i=0; i<parent_nest; i++) { + $parent = $parent.parent(); + } + } + + var $attach_node = $(attach, $parent); + $attach_node.append($c); + } + }); + var f = function(plugin, i, c) { // for each matched control call the // _init method of the plugin if it has one + $c = $(c); + $c.data('grid.moksha_grid', self);
- $(c).data('grid.moksha_grid', self); if (plugin._init) plugin._init.call(plugin, self, - $(c)); + $c); }
this._foreach_controls(f);
moksha-commits@lists.fedorahosted.org