@@ -67,6 +67,35 @@ define([
6767 'action' : function ( ) {
6868 that . split ( ) ;
6969 }
70+ } ,
71+ { 'type' : "divider" } ,
72+ {
73+ 'type' : "action" ,
74+ 'text' : "Auto Grid" ,
75+ 'action' : function ( ) {
76+ that . tabs . setLayout ( ) ;
77+ }
78+ } ,
79+ {
80+ 'type' : "action" ,
81+ 'text' : "Columns: 2" ,
82+ 'action' : function ( ) {
83+ that . tabs . setLayout ( 2 ) ;
84+ }
85+ } ,
86+ {
87+ 'type' : "action" ,
88+ 'text' : "Columns: 3" ,
89+ 'action' : function ( ) {
90+ that . tabs . setLayout ( 3 ) ;
91+ }
92+ } ,
93+ {
94+ 'type' : "action" ,
95+ 'text' : "Columns: 4" ,
96+ 'action' : function ( ) {
97+ that . tabs . setLayout ( 4 ) ;
98+ }
7099 }
71100 ] ) ;
72101
@@ -248,6 +277,9 @@ define([
248277 // Constructor
249278 initialize : function ( options ) {
250279 TabsView . __super__ . initialize . apply ( this , arguments ) ;
280+
281+ this . layout = null ; // null: mode auto
282+
251283 this . tabs = { } ;
252284 this . activeTab = null ;
253285 return this ;
@@ -264,17 +296,30 @@ define([
264296 // Calcul number of sections
265297 var sections = this . getSections ( ) ;
266298 var sections_n = _ . max ( [ 1 , _ . size ( sections ) ] ) ;
267- var section_width = Math . floor ( 100 / sections_n ) ;
268299
269300
301+ var layout = this . layout || Math . floor ( Math . sqrt ( sections_n ) ) ; // Number of columns
302+
303+ var nColumns = Math . min ( layout , sections_n ) ;
304+ var nLines = Math . ceil ( sections_n / layout ) ;
305+
306+ var sectionWidth = Math . floor ( 100 / nColumns ) ;
307+ var sectionHeight = Math . floor ( 100 / nLines ) ;
308+
309+ var sectionLeft = 0 ;
310+ var sectionTop = 0 ;
311+
270312 // Add different section
271313 _ . each ( sections , function ( section , sectionIndex ) {
272314 var section_el , section_tabs , section_tabs_content , css ;
315+
273316 section_el = $ ( "<div>" , {
274317 "class" : "section" ,
275318 "css" : {
276- "width" : section_width + "%" ,
277- "left" : ( sectionIndex * section_width ) + "%"
319+ "width" : sectionWidth + "%" ,
320+ "height" : sectionHeight + "%" ,
321+ "top" : sectionTop + "%" ,
322+ "left" : sectionLeft + "%"
278323 } ,
279324 } ) . appendTo ( this . $el ) ;
280325 section_el . on ( 'dragleave' , function ( e ) {
@@ -310,6 +355,13 @@ define([
310355 tab . tab . $el . appendTo ( section_tabs ) ;
311356 tab . view . $el . appendTo ( section_tabs_content ) ;
312357 } , this ) ;
358+
359+ // Calcul next position
360+ sectionLeft = sectionLeft + sectionWidth ;
361+ if ( Math . ceil ( sectionLeft / sectionWidth ) >= nColumns ) {
362+ sectionLeft = 0 ;
363+ sectionTop = sectionTop + sectionHeight ;
364+ }
313365 } , this ) ;
314366 this . delegateEvents ( ) ;
315367
@@ -491,6 +543,12 @@ define([
491543 // Open default new tab
492544 openDefaultNew : function ( e ) {
493545 this . trigger ( "tabs:opennew" ) ;
546+ } ,
547+
548+ // Define tabs layout
549+ setLayout : function ( l ) {
550+ this . layout = l ;
551+ this . render ( ) ;
494552 }
495553 } , {
496554 Panel : TabPanelView
0 commit comments