var fluid_1_4=fluid_1_4||{};(function($,fluid){fluid.registerNamespace("fluid.moduleLayout");fluid.moduleLayout.findColumnAndItemIndices=function(item,layout){return fluid.find(layout.columns,function(column,colIndex){var index=$.inArray(item,column.elements);return index===-1?undefined:{columnIndex:colIndex,itemIndex:index}},{columnIndex:-1,itemIndex:-1})};fluid.moduleLayout.findColIndex=function(item,layout){return fluid.find(layout.columns,function(column,colIndex){return item===column.container?colIndex:undefined},-1)};fluid.moduleLayout.updateLayout=function(item,target,position,layout){item=fluid.unwrap(item);target=fluid.unwrap(target);var itemIndices=fluid.moduleLayout.findColumnAndItemIndices(item,layout);layout.columns[itemIndices.columnIndex].elements.splice(itemIndices.itemIndex,1);var targetCol;if(position===fluid.position.INSIDE){targetCol=layout.columns[fluid.moduleLayout.findColIndex(target,layout)].elements;targetCol.splice(targetCol.length,0,item)}else{var relativeItemIndices=fluid.moduleLayout.findColumnAndItemIndices(target,layout);targetCol=layout.columns[relativeItemIndices.columnIndex].elements;position=fluid.normalisePosition(position,itemIndices.columnIndex===relativeItemIndices.columnIndex,relativeItemIndices.itemIndex,itemIndices.itemIndex);var relative=position===fluid.position.BEFORE?0:1;targetCol.splice(relativeItemIndices.itemIndex+relative,0,item)}};fluid.moduleLayout.layoutFromFlat=function(container,columns,portlets){var layout={};layout.container=container;layout.columns=fluid.transform(columns,function(column){return{container:column,elements:$.makeArray(portlets.filter(function(){return fluid.dom.isContainer(column,this)}))}});return layout};fluid.moduleLayout.layoutFromIds=function(idLayout){return{container:fluid.byId(idLayout.id),columns:fluid.transform(idLayout.columns,function(column){return{container:fluid.byId(column.id),elements:fluid.transform(column.children,fluid.byId)}})}};fluid.moduleLayout.layoutToIds=function(idLayout){return{id:fluid.getId(idLayout.container),columns:fluid.transform(idLayout.columns,function(column){return{id:fluid.getId(column.container),children:fluid.transform(column.elements,fluid.getId)}})}};var defaultOnShowKeyboardDropWarning=function(item,dropWarning){if(dropWarning){var offset=$(item).offset();dropWarning=$(dropWarning);dropWarning.css("position","absolute");dropWarning.css("top",offset.top);dropWarning.css("left",offset.left)}};fluid.defaults(true,"fluid.moduleLayoutHandler",{orientation:fluid.orientation.VERTICAL,containerRole:fluid.reorderer.roles.REGIONS,selectablesTabindex:-1,sentinelize:true});fluid.moduleLayoutHandler=function(container,options,dropManager,dom){var that={};function computeLayout(){var togo;if(options.selectors.modules){togo=fluid.moduleLayout.layoutFromFlat(container,dom.locate("columns"),dom.locate("modules"))}if(!togo){var idLayout=fluid.get(options,"moduleLayout.layout");fluid.moduleLayout.layoutFromIds(idLayout)}return togo}var layout=computeLayout();that.layout=layout;function isLocked(item){var lockedModules=options.selectors.lockedModules?dom.fastLocate("lockedModules"):[];return $.inArray(item,lockedModules)!==-1}that.getRelativePosition=fluid.reorderer.relativeInfoGetter(options.orientation,fluid.reorderer.WRAP_LOCKED_STRATEGY,fluid.reorderer.GEOMETRIC_STRATEGY,dropManager,dom,options.disableWrap);that.getGeometricInfo=function(){var extents=[];var togo={extents:extents,sentinelize:options.sentinelize};togo.elementMapper=function(element){return isLocked(element)?"locked":null};togo.elementIndexer=function(element){var indices=fluid.moduleLayout.findColumnAndItemIndices(element,that.layout);return{index:indices.itemIndex,length:layout.columns[indices.columnIndex].elements.length,moduleIndex:indices.columnIndex,moduleLength:layout.columns.length}};for(var col=0;col<layout.columns.length;col++){var column=layout.columns[col];var thisEls={orientation:options.orientation,elements:$.makeArray(column.elements),parentElement:column.container};extents.push(thisEls)}return togo};function computeModules(all){return function(){var modules=fluid.accumulate(layout.columns,function(column,list){return list.concat(column.elements)},[]);if(!all){fluid.remove_if(modules,isLocked)}return modules}}that.returnedOptions={selectors:{movables:computeModules(false),dropTargets:computeModules(false),selectables:computeModules(true)},listeners:{onMove:{priority:"last",listener:function(item,requestedPosition){fluid.moduleLayout.updateLayout(item,requestedPosition.element,requestedPosition.position,layout)}},onRefresh:function(){layout=computeLayout();that.layout=layout},"onShowKeyboardDropWarning.setPosition":defaultOnShowKeyboardDropWarning}};that.getModel=function(){return fluid.moduleLayout.layoutToIds(layout)};return that}})(jQuery,fluid_1_4);