@@ -302,15 +302,15 @@ $.nette.ext('validation', {
302
302
} ) ;
303
303
304
304
$ . nette . ext ( 'forms' , {
305
- success : function ( payload ) {
305
+ init : function ( ) {
306
306
var snippets ;
307
- if ( ! window . Nette || ! payload . snippets || ! ( snippets = this . ext ( 'snippets' ) ) ) return ;
307
+ if ( ! window . Nette || ! ( snippets = this . ext ( 'snippets' ) ) ) return ;
308
308
309
- for ( var id in payload . snippets ) {
310
- snippets . getElement ( id ) . find ( 'form' ) . each ( function ( ) {
309
+ snippets . after ( function ( $el ) {
310
+ $el . find ( 'form' ) . each ( function ( ) {
311
311
window . Nette . initForm ( this ) ;
312
312
} ) ;
313
- }
313
+ } ) ;
314
314
} ,
315
315
prepare : function ( settings ) {
316
316
var analyze = settings . nette ;
@@ -345,15 +345,38 @@ $.nette.ext('forms', {
345
345
// default snippet handler
346
346
$ . nette . ext ( 'snippets' , {
347
347
success : function ( payload ) {
348
+ var snippets = [ ] ;
348
349
if ( payload . snippets ) {
349
350
for ( var i in payload . snippets ) {
350
- this . updateSnippet ( i , payload . snippets [ i ] ) ;
351
+ var $el = this . getElement ( i ) ;
352
+ $ . each ( this . beforeQueue , function ( index , callback ) {
353
+ if ( typeof callback == 'function' ) {
354
+ callback ( $el ) ;
355
+ }
356
+ } ) ;
357
+ this . updateSnippet ( $el , payload . snippets [ i ] ) ;
358
+ $ . each ( this . afterQueue , function ( index , callback ) {
359
+ if ( typeof callback == 'function' ) {
360
+ callback ( $el ) ;
361
+ }
362
+ } ) ;
351
363
}
352
364
}
365
+ this . before ( snippets ) ;
353
366
}
354
367
} , {
355
- updateSnippet : function ( id , html , back ) {
356
- var $el = this . getElement ( id ) ;
368
+ beforeQueue : [ ] ,
369
+ afterQueue : [ ] ,
370
+ before : function ( callback ) {
371
+ this . beforeQueue . push ( callback ) ;
372
+ } ,
373
+ after : function ( callback ) {
374
+ this . afterQueue . push ( callback ) ;
375
+ } ,
376
+ updateSnippet : function ( $el , html , back ) {
377
+ if ( typeof $el == 'string' ) {
378
+ $el = this . getElement ( $el ) ;
379
+ }
357
380
// Fix for setting document title in IE
358
381
if ( $el . get ( 0 ) . tagName == 'TITLE' ) {
359
382
document . title = html ;
0 commit comments