@@ -146,6 +146,9 @@ $.fn.modal = function(parameters) {
146
146
module . observeChanges ( ) ;
147
147
}
148
148
module . instantiate ( ) ;
149
+ if ( settings . autoShow ) {
150
+ module . show ( ) ;
151
+ }
149
152
} ,
150
153
151
154
instantiate : function ( ) {
@@ -158,19 +161,19 @@ $.fn.modal = function(parameters) {
158
161
159
162
create : {
160
163
modal : function ( ) {
161
- $module = $ ( '<div/>' , { class : 'ui modal' } ) ;
164
+ $module = $ ( '<div/>' , { class : className . modal } ) ;
162
165
if ( settings . closeIcon ) {
163
166
$close = $ ( '<i/>' , { class : className . close } )
164
167
$module . append ( $close ) ;
165
168
}
166
169
if ( settings . title !== '' ) {
167
- $ ( '<div/>' , { class : 'header' } ) . appendTo ( $module ) ;
170
+ $ ( '<div/>' , { class : className . title } ) . appendTo ( $module ) ;
168
171
}
169
172
if ( settings . content !== '' ) {
170
- $ ( '<div/>' , { class : ' content' } ) . appendTo ( $module ) ;
173
+ $ ( '<div/>' , { class : className . content } ) . appendTo ( $module ) ;
171
174
}
172
175
if ( module . has . configActions ( ) ) {
173
- $ ( '<div/>' , { class : ' actions' } ) . appendTo ( $module ) ;
176
+ $ ( '<div/>' , { class : className . actions } ) . appendTo ( $module ) ;
174
177
}
175
178
$context . append ( $module ) ;
176
179
} ,
@@ -300,6 +303,12 @@ $.fn.modal = function(parameters) {
300
303
get : {
301
304
id : function ( ) {
302
305
return ( Math . random ( ) . toString ( 16 ) + '000000000' ) . substr ( 2 , 8 ) ;
306
+ } ,
307
+ element : function ( ) {
308
+ return $module ;
309
+ } ,
310
+ settings : function ( ) {
311
+ return settings ;
303
312
}
304
313
} ,
305
314
@@ -477,9 +486,9 @@ $.fn.modal = function(parameters) {
477
486
$module
478
487
. transition ( {
479
488
debug : settings . debug ,
480
- animation : settings . transition + ' in' ,
489
+ animation : ( settings . transition . showMethod || settings . transition ) + ' in' ,
481
490
queue : settings . queue ,
482
- duration : settings . duration ,
491
+ duration : settings . transition . showDuration || settings . duration ,
483
492
useFailSafe : true ,
484
493
onComplete : function ( ) {
485
494
settings . onVisible . apply ( element ) ;
@@ -527,9 +536,9 @@ $.fn.modal = function(parameters) {
527
536
$module
528
537
. transition ( {
529
538
debug : settings . debug ,
530
- animation : settings . transition + ' out' ,
539
+ animation : ( settings . transition . hideMethod || settings . transition ) + ' out' ,
531
540
queue : settings . queue ,
532
- duration : settings . duration ,
541
+ duration : settings . transition . hideDuration || settings . duration ,
533
542
useFailSafe : true ,
534
543
onStart : function ( ) {
535
544
if ( ! module . others . active ( ) && ! module . others . animating ( ) && ! keepDimmed ) {
@@ -935,8 +944,8 @@ $.fn.modal = function(parameters) {
935
944
closable : 'auto' ,
936
945
useFlex : module . can . useFlex ( ) ,
937
946
duration : {
938
- show : settings . duration ,
939
- hide : settings . duration
947
+ show : settings . transition . showDuration || settings . duration ,
948
+ hide : settings . transition . hideDuration || settings . duration
940
949
}
941
950
} ,
942
951
dimmerSettings = $ . extend ( true , defaultSettings , settings . dimmerSettings )
@@ -1195,9 +1204,22 @@ $.fn.modal = function(parameters) {
1195
1204
1196
1205
if ( methodInvoked ) {
1197
1206
if ( instance === undefined ) {
1207
+ if ( $ . isFunction ( settings . templates [ query ] ) ) {
1208
+ settings . autoShow = true ;
1209
+ settings . className . modal = settings . className . template ;
1210
+ settings = $ . extend ( true , { } , settings , settings . templates [ query ] . apply ( module , queryArguments ) ) ;
1211
+
1212
+ // reassign shortcuts
1213
+ className = settings . className ;
1214
+ namespace = settings . namespace ;
1215
+ fields = settings . fields ;
1216
+ error = settings . error ;
1217
+ }
1198
1218
module . initialize ( ) ;
1199
1219
}
1200
- module . invoke ( query ) ;
1220
+ if ( ! $ . isFunction ( settings . templates [ query ] ) ) {
1221
+ module . invoke ( query ) ;
1222
+ }
1201
1223
}
1202
1224
else {
1203
1225
if ( instance !== undefined ) {
@@ -1235,6 +1257,7 @@ $.fn.modal.settings = {
1235
1257
closable : true ,
1236
1258
autofocus : true ,
1237
1259
restoreFocus : true ,
1260
+ autoShow : false ,
1238
1261
1239
1262
inverted : false ,
1240
1263
blurring : false ,
@@ -1304,7 +1327,8 @@ $.fn.modal.settings = {
1304
1327
deny : '.actions .negative, .actions .deny, .actions .cancel' ,
1305
1328
modal : '.ui.modal' ,
1306
1329
dimmer : '> .ui.dimmer' ,
1307
- bodyFixed : '> .ui.fixed.menu, > .ui.right.toast-container, > .ui.right.sidebar, > .ui.fixed.nag, > .ui.fixed.nag > .close'
1330
+ bodyFixed : '> .ui.fixed.menu, > .ui.right.toast-container, > .ui.right.sidebar, > .ui.fixed.nag, > .ui.fixed.nag > .close' ,
1331
+ prompt : '.ui.input > input'
1308
1332
} ,
1309
1333
error : {
1310
1334
dimmer : 'UI Dimmer, a required component is not included in this page' ,
@@ -1322,9 +1346,102 @@ $.fn.modal.settings = {
1322
1346
undetached : 'undetached' ,
1323
1347
front : 'front' ,
1324
1348
close : 'close icon' ,
1325
- button : 'ui button'
1349
+ button : 'ui button' ,
1350
+ modal : 'ui modal' ,
1351
+ title : 'header' ,
1352
+ content : 'content' ,
1353
+ actions : 'actions' ,
1354
+ template : 'ui tiny modal' ,
1355
+ ok : 'positive' ,
1356
+ cancel : 'negative' ,
1357
+ prompt : 'ui fluid input'
1358
+ } ,
1359
+ text : {
1360
+ ok : 'Ok' ,
1361
+ cancel : 'Cancel'
1326
1362
}
1327
1363
} ;
1328
1364
1365
+ $ . fn . modal . settings . templates = {
1366
+ getArguments : function ( args ) {
1367
+ var queryArguments = [ ] . slice . call ( args ) ;
1368
+ if ( $ . isPlainObject ( queryArguments [ 0 ] ) ) {
1369
+ return $ . extend ( {
1370
+ handler :function ( ) { } ,
1371
+ content :'' ,
1372
+ title : ''
1373
+ } , queryArguments [ 0 ] ) ;
1374
+ } else {
1375
+ if ( ! $ . isFunction ( queryArguments [ queryArguments . length - 1 ] ) ) {
1376
+ queryArguments . push ( function ( ) { } ) ;
1377
+ }
1378
+ return {
1379
+ handler : queryArguments . pop ( ) ,
1380
+ content : queryArguments . pop ( ) || '' ,
1381
+ title : queryArguments . pop ( ) || ''
1382
+ } ;
1383
+ }
1384
+ } ,
1385
+ alert : function ( ) {
1386
+ var settings = this . get . settings ( ) ,
1387
+ args = settings . templates . getArguments ( arguments )
1388
+ ;
1389
+ return {
1390
+ title : args . title ,
1391
+ content : args . content ,
1392
+ actions : [ {
1393
+ text : settings . text . ok ,
1394
+ class : settings . className . ok ,
1395
+ click : args . handler
1396
+ } ]
1397
+ }
1398
+ } ,
1399
+ confirm : function ( ) {
1400
+ var settings = this . get . settings ( ) ,
1401
+ args = settings . templates . getArguments ( arguments )
1402
+ ;
1403
+ return {
1404
+ title : args . title ,
1405
+ content : args . content ,
1406
+ actions : [ {
1407
+ text : settings . text . ok ,
1408
+ class : settings . className . ok ,
1409
+ click : function ( ) { args . handler ( true ) }
1410
+ } , {
1411
+ text : settings . text . cancel ,
1412
+ class : settings . className . cancel ,
1413
+ click : function ( ) { args . handler ( false ) }
1414
+ } ]
1415
+ }
1416
+ } ,
1417
+ prompt : function ( ) {
1418
+ var $this = this ,
1419
+ settings = this . get . settings ( ) ,
1420
+ args = settings . templates . getArguments ( arguments ) ,
1421
+ input = $ ( $ . parseHTML ( args . content ) ) . filter ( '.ui.input' )
1422
+ ;
1423
+ if ( input . length === 0 ) {
1424
+ args . content += '<p><div class="' + settings . className . prompt + '"><input placeholder="' + this . helpers . deQuote ( args . placeholder || '' ) + '" type="text" value="' + this . helpers . deQuote ( args . defaultValue || '' ) + '"></div></p>' ;
1425
+ }
1426
+ return {
1427
+ title : args . title ,
1428
+ content : args . content ,
1429
+ actions : [ {
1430
+ text : settings . text . ok ,
1431
+ class : settings . className . ok ,
1432
+ click : function ( ) {
1433
+ var settings = $this . get . settings ( ) ,
1434
+ inputField = $this . get . element ( ) . find ( settings . selector . prompt ) [ 0 ]
1435
+ ;
1436
+ args . handler ( $ ( inputField ) . val ( ) ) ;
1437
+ }
1438
+ } , {
1439
+ text : settings . text . cancel ,
1440
+ class : settings . className . cancel ,
1441
+ click : function ( ) { args . handler ( null ) }
1442
+ } ]
1443
+ }
1444
+ }
1445
+ }
1329
1446
1330
1447
} ) ( jQuery , window , document ) ;
0 commit comments