# HG changeset patch # User hamidouk # Date 1325079703 -3600 # Node ID 3ba5b82aebb641b4202ba24a02e4117d0af33867 # Parent b778b2f93ef4ec1ac18bd744ffa968030fd88437 added code to select widgets to the layoutmanager, similar to what jquery does. diff -r b778b2f93ef4 -r 3ba5b82aebb6 src/js/init.js --- a/src/js/init.js Wed Dec 28 12:03:29 2011 +0100 +++ b/src/js/init.js Wed Dec 28 14:41:43 2011 +0100 @@ -143,6 +143,7 @@ var arr = IriSP.jQuery.extend({}, widgetConfig); arr.container = container; arr.spacer = spacer; + arr.layoutManager = layoutManager; var serializer = serialFactory.getSerializer(widgetConfig.metadata); diff -r b778b2f93ef4 -r 3ba5b82aebb6 src/js/layout.js --- a/src/js/layout.js Wed Dec 28 12:03:29 2011 +0100 +++ b/src/js/layout.js Wed Dec 28 14:41:43 2011 +0100 @@ -49,16 +49,16 @@ } /** create a subdiv with an unique id, and a spacer div as well. - @param stem stem is a string to append to the id of the widget + @param widgetName the name of the widget. @return an array of the form [createdivId, spacerdivId]. */ -IriSP.LayoutManager.prototype.createDiv = function(stem) { - if (typeof(stem) === "undefined") - stem = ""; +IriSP.LayoutManager.prototype.createDiv = function(widgetName) { + if (typeof(widgetName) === "undefined") + widgetName = ""; - var newDiv = IriSP.guid(this._div + "_widget_" + stem + "_"); + var newDiv = IriSP.guid(this._div + "_widget_" + widgetName + "_"); var spacerDiv = IriSP.guid("LdtPlayer_spacer_"); - this._widgets.push(newDiv); + this._widgets.push([widgetName, newDiv]); var divTempl = "
0) ? this._widgets.length - 1 : 0; + var s = new IriSP.LayoutManager.sliceObject(0, end, this) + return s; +}; + +/** sliceObjects represent a group of widget managed by a layout manager. + They expose convenient methods for selecting portions of widgets + They can be chained in this way : + layoutManager.slice().before("ArrowWidget").after("PolemicWidget"); +*/ +IriSP.LayoutManager.sliceObject = function(start, end, layoutManager) { + this.start = start; + this.end = end; + this._layoutManager = layoutManager; +}; + +/** returns a slice of the array corresponding to the objects after widget + @param widget the widget to filter with */ +IriSP.LayoutManager.sliceObject.prototype.after = function(widget) { + var i; + for(i = this.start; i < this.end; i++) + if (this._layoutManager._widgets[i][0] === widget) + break; + + this.start = i; + console.log(this.start); + return this; +} + +/** returns a slice of the array corresponding to the objects before widget + @param widget the widget to filter with */ +IriSP.LayoutManager.sliceObject.prototype.before = function(widget) { + var i; + for(i = this.start; i < this.end; i++) + if (this._layoutManager._widgets[i][0] === widget) + break; + + this.end = i; + + return this; +} + +/** return a jquery selector corresponding to the defined slice */ +IriSP.LayoutManager.sliceObject.prototype.jQuerySelector = function() { + return this._layoutManager.selector.children("").slice(this.start, this.end); +}; \ No newline at end of file diff -r b778b2f93ef4 -r 3ba5b82aebb6 src/js/widgets.js --- a/src/js/widgets.js Wed Dec 28 12:03:29 2011 +0100 +++ b/src/js/widgets.js Wed Dec 28 14:41:43 2011 +0100 @@ -47,6 +47,10 @@ if (config.hasOwnProperty("widthmax")) { this.widthmax = config.widthmax; + } + + if (config.hasOwnProperty("layoutManager")) { + this.layoutManager = config.layoutManager; } };