@@ -113,22 +113,40 @@ var ALMCSS = function() {
113113
114114 } ( basePath ) ;
115115
116+
117+ // The Full Layout Process
118+ // -----------------------
119+
120+ var doLayout = function ( ) {
121+
122+ var templates = ALMCSS . template . templates ,
123+ computeWidths = ALMCSS . template . layout . computeWidths ,
124+ computeHeights = ALMCSS . template . layout . computeHeights ,
125+ paint = ALMCSS . template . dom . paint ,
126+ LoggerLevel = ALMCSS . debug . LoggerLevel ,
127+ logger = ALMCSS . debug . getLogger ( 'Layout' , LoggerLevel . all ) ;
128+
129+ logger . group ( 'Starting layout...' ) ;
130+ computeWidths ( templates ) ;
131+ computeHeights ( templates ) ;
132+ paint ( templates ) ;
133+ logger . groupEnd ( ) ;
134+
135+ } ;
136+
116137 // Main Function
117138 // -------------
118139 var init = function ( ) {
119140
120- var LoggerLevel = ALMCSS . debug . LoggerLevel ,
141+ var templates = ALMCSS . template . templates ,
142+ createTemplateElements = ALMCSS . template . dom . createTemplateElements ,
143+ positionedElements = ALMCSS . template . positionedElements ,
144+ moveElementsIntoSlots = ALMCSS . template . dom . moveElementsIntoSlots ,
145+ LoggerLevel = ALMCSS . debug . LoggerLevel ,
121146 logger = ALMCSS . debug . getLogger ( 'ALMCSS3 Main Function' , LoggerLevel . all ) ,
122147 parser = ALMCSS . stylesheet . parser . Parser ,
123148 log = logger . log ,
124149 info = logger . info ,
125- templates = ALMCSS . template . templates ,
126- createTemplateElements = ALMCSS . template . dom . createTemplateElements ,
127- positionedElements = ALMCSS . template . positionedElements ,
128- moveElementsIntoSlots = ALMCSS . template . dom . moveElementsIntoSlots ,
129- computeWidths = ALMCSS . template . layout . computeWidths ,
130- computeHeights = ALMCSS . template . layout . computeHeights ,
131- paint = ALMCSS . template . dom . paint ,
132150 i ;
133151
134152 info ( 'Starting the main function of ALMCSS3...' ) ;
@@ -146,14 +164,9 @@ var ALMCSS = function() {
146164 info ( 'No templates were found' ) ;
147165 }
148166
149- // The Full Process
150- // ----------------
151-
152167 createTemplateElements ( templates ) ;
153168 moveElementsIntoSlots ( positionedElements ) ;
154- computeWidths ( templates ) ;
155- computeHeights ( templates ) ;
156- paint ( templates ) ;
169+ doLayout ( ) ;
157170 } ;
158171
159172 // Loading Modules
@@ -183,18 +196,27 @@ var ALMCSS = function() {
183196 ] , init ) ;
184197 } ;
185198
186- var setOnloadEvent = function ( start ) {
187- var obj = window , event = 'load' ;
199+
200+ // Events
201+ // ------
202+
203+ var addEvent = function ( obj , event , whenDone ) {
188204 if ( obj && obj . addEventListener ) { // W3C
189- obj . addEventListener ( event , start , false ) ;
205+ obj . addEventListener ( event , whenDone , false ) ;
190206 } else if ( obj && obj . attachEvent ) { // Older IE
191- obj . attachEvent ( "on" + event , start ) ;
192- } else {
193- throw new AlmcssError ( 'The load event could not be added' ) ;
207+ obj . attachEvent ( "on" + event , whenDone ) ;
194208 }
195209 } ;
196210
197- setOnloadEvent ( loadModules ) ;
211+ var resizeTimer ;
212+
213+ var whenResize = function ( ) {
214+ clearTimeout ( resizeTimer ) ;
215+ resizeTimer = setTimeout ( doLayout , 30 ) ;
216+ } ;
217+
218+ addEvent ( window , 'load' , loadModules ) ;
219+ addEvent ( window , 'resize' , whenResize ) ;
198220
199221 return {
200222 AlmcssError : AlmcssError ,
0 commit comments