diff --git a/src/definitions/modules/modal.js b/src/definitions/modules/modal.js index d03ba0911f..d69e723d56 100755 --- a/src/definitions/modules/modal.js +++ b/src/definitions/modules/modal.js @@ -146,6 +146,9 @@ $.fn.modal = function(parameters) { module.observeChanges(); } module.instantiate(); + if(settings.autoShow){ + module.show(); + } }, instantiate: function() { @@ -158,19 +161,19 @@ $.fn.modal = function(parameters) { create: { modal: function() { - $module = $('
', {class: 'ui modal'}); + $module = $('', {class: className.modal}); if (settings.closeIcon) { $close = $('', {class: className.close}) $module.append($close); } if (settings.title !== '') { - $('', {class: 'header'}).appendTo($module); + $('', {class: className.title}).appendTo($module); } if (settings.content !== '') { - $('', {class: 'content'}).appendTo($module); + $('', {class: className.content}).appendTo($module); } if (module.has.configActions()) { - $('', {class: 'actions'}).appendTo($module); + $('', {class: className.actions}).appendTo($module); } $context.append($module); }, @@ -300,6 +303,12 @@ $.fn.modal = function(parameters) { get: { id: function() { return (Math.random().toString(16) + '000000000').substr(2, 8); + }, + element: function() { + return $module; + }, + settings: function() { + return settings; } }, @@ -477,9 +486,9 @@ $.fn.modal = function(parameters) { $module .transition({ debug : settings.debug, - animation : settings.transition + ' in', + animation : (settings.transition.showMethod || settings.transition) + ' in', queue : settings.queue, - duration : settings.duration, + duration : settings.transition.showDuration || settings.duration, useFailSafe : true, onComplete : function() { settings.onVisible.apply(element); @@ -527,9 +536,9 @@ $.fn.modal = function(parameters) { $module .transition({ debug : settings.debug, - animation : settings.transition + ' out', + animation : (settings.transition.hideMethod || settings.transition) + ' out', queue : settings.queue, - duration : settings.duration, + duration : settings.transition.hideDuration || settings.duration, useFailSafe : true, onStart : function() { if(!module.others.active() && !module.others.animating() && !keepDimmed) { @@ -935,8 +944,8 @@ $.fn.modal = function(parameters) { closable : 'auto', useFlex : module.can.useFlex(), duration : { - show : settings.duration, - hide : settings.duration + show : settings.transition.showDuration || settings.duration, + hide : settings.transition.hideDuration || settings.duration } }, dimmerSettings = $.extend(true, defaultSettings, settings.dimmerSettings) @@ -1195,9 +1204,22 @@ $.fn.modal = function(parameters) { if(methodInvoked) { if(instance === undefined) { + if ($.isFunction(settings.templates[query])) { + settings.autoShow = true; + settings.className.modal = settings.className.template; + settings = $.extend(true, {}, settings, settings.templates[query].apply(module ,queryArguments)); + + // reassign shortcuts + className = settings.className; + namespace = settings.namespace; + fields = settings.fields; + error = settings.error; + } module.initialize(); } - module.invoke(query); + if (!$.isFunction(settings.templates[query])) { + module.invoke(query); + } } else { if(instance !== undefined) { @@ -1235,6 +1257,7 @@ $.fn.modal.settings = { closable : true, autofocus : true, restoreFocus : true, + autoShow : false, inverted : false, blurring : false, @@ -1304,7 +1327,8 @@ $.fn.modal.settings = { deny : '.actions .negative, .actions .deny, .actions .cancel', modal : '.ui.modal', dimmer : '> .ui.dimmer', - bodyFixed: '> .ui.fixed.menu, > .ui.right.toast-container, > .ui.right.sidebar, > .ui.fixed.nag, > .ui.fixed.nag > .close' + bodyFixed: '> .ui.fixed.menu, > .ui.right.toast-container, > .ui.right.sidebar, > .ui.fixed.nag, > .ui.fixed.nag > .close', + prompt : '.ui.input > input' }, error : { dimmer : 'UI Dimmer, a required component is not included in this page', @@ -1322,9 +1346,102 @@ $.fn.modal.settings = { undetached : 'undetached', front : 'front', close : 'close icon', - button : 'ui button' + button : 'ui button', + modal : 'ui modal', + title : 'header', + content : 'content', + actions : 'actions', + template : 'ui tiny modal', + ok : 'positive', + cancel : 'negative', + prompt : 'ui fluid input' + }, + text: { + ok : 'Ok', + cancel: 'Cancel' } }; +$.fn.modal.settings.templates = { + getArguments: function(args) { + var queryArguments = [].slice.call(args); + if($.isPlainObject(queryArguments[0])){ + return $.extend({ + handler:function(){}, + content:'', + title: '' + }, queryArguments[0]); + } else { + if(!$.isFunction(queryArguments[queryArguments.length-1])) { + queryArguments.push(function() {}); + } + return { + handler: queryArguments.pop(), + content: queryArguments.pop() || '', + title: queryArguments.pop() || '' + }; + } + }, + alert: function () { + var settings = this.get.settings(), + args = settings.templates.getArguments(arguments) + ; + return { + title : args.title, + content: args.content, + actions: [{ + text : settings.text.ok, + class: settings.className.ok, + click: args.handler + }] + } + }, + confirm: function () { + var settings = this.get.settings(), + args = settings.templates.getArguments(arguments) + ; + return { + title : args.title, + content: args.content, + actions: [{ + text : settings.text.ok, + class: settings.className.ok, + click: function(){args.handler(true)} + },{ + text: settings.text.cancel, + class: settings.className.cancel, + click: function(){args.handler(false)} + }] + } + }, + prompt: function () { + var $this = this, + settings = this.get.settings(), + args = settings.templates.getArguments(arguments), + input = $($.parseHTML(args.content)).filter('.ui.input') + ; + if (input.length === 0) { + args.content += ''; + } + return { + title : args.title, + content: args.content, + actions: [{ + text: settings.text.ok, + class: settings.className.ok, + click: function(){ + var settings = $this.get.settings(), + inputField = $this.get.element().find(settings.selector.prompt)[0] + ; + args.handler($(inputField).val()); + } + },{ + text: settings.text.cancel, + class: settings.className.cancel, + click: function(){args.handler(null)} + }] + } + } +} })( jQuery, window, document ); diff --git a/src/definitions/modules/modal.less b/src/definitions/modules/modal.less index 0138d50c68..ef850c75cb 100755 --- a/src/definitions/modules/modal.less +++ b/src/definitions/modules/modal.less @@ -40,9 +40,9 @@ will-change: top, left, margin, transform, opacity; } -.ui.modal > :first-child:not(.icon):not(.dimmer), +.ui.modal > :first-child:not(.close):not(.dimmer), .ui.modal > i.icon:first-child + *, -.ui.modal > .dimmer:first-child + *:not(.icon), +.ui.modal > .dimmer:first-child + *:not(.close), .ui.modal > .dimmer:first-child + i.icon + * { border-top-left-radius: @borderRadius; border-top-right-radius: @borderRadius; @@ -477,8 +477,8 @@ border-radius:0; } } - .ui.modal > .close.inside + .header, - .ui.fullscreen.modal > .close + .header { + .ui.modal > .close.inside + .header:not(.centered):not(.center):not(.icon), + .ui.fullscreen.modal > .close + .header:not(.centered):not(.center):not(.icon) { padding-right: @closeHitbox; } .ui.modal > .close.inside,