fomantic-ui-sass 2.8.8.1 → 2.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/app/assets/fonts/semantic-ui/Lato-Bold.woff +0 -0
  4. data/app/assets/fonts/semantic-ui/Lato-Bold.woff2 +0 -0
  5. data/app/assets/fonts/semantic-ui/Lato-BoldItalic.woff +0 -0
  6. data/app/assets/fonts/semantic-ui/Lato-BoldItalic.woff2 +0 -0
  7. data/app/assets/fonts/semantic-ui/Lato-Italic.woff +0 -0
  8. data/app/assets/fonts/semantic-ui/Lato-Italic.woff2 +0 -0
  9. data/app/assets/fonts/semantic-ui/Lato-Regular.woff +0 -0
  10. data/app/assets/fonts/semantic-ui/Lato-Regular.woff2 +0 -0
  11. data/app/assets/fonts/semantic-ui/LatoLatin-Bold.woff +0 -0
  12. data/app/assets/fonts/semantic-ui/LatoLatin-Bold.woff2 +0 -0
  13. data/app/assets/fonts/semantic-ui/LatoLatin-BoldItalic.woff +0 -0
  14. data/app/assets/fonts/semantic-ui/LatoLatin-BoldItalic.woff2 +0 -0
  15. data/app/assets/fonts/semantic-ui/LatoLatin-Italic.woff +0 -0
  16. data/app/assets/fonts/semantic-ui/LatoLatin-Italic.woff2 +0 -0
  17. data/app/assets/fonts/semantic-ui/LatoLatin-Regular.woff +0 -0
  18. data/app/assets/fonts/semantic-ui/LatoLatin-Regular.woff2 +0 -0
  19. data/app/assets/fonts/semantic-ui/brand-icons.eot +0 -0
  20. data/app/assets/fonts/semantic-ui/brand-icons.svg +41 -6
  21. data/app/assets/fonts/semantic-ui/brand-icons.ttf +0 -0
  22. data/app/assets/fonts/semantic-ui/brand-icons.woff +0 -0
  23. data/app/assets/fonts/semantic-ui/brand-icons.woff2 +0 -0
  24. data/app/assets/fonts/semantic-ui/icons.eot +0 -0
  25. data/app/assets/fonts/semantic-ui/icons.svg +245 -7
  26. data/app/assets/fonts/semantic-ui/icons.ttf +0 -0
  27. data/app/assets/fonts/semantic-ui/icons.woff +0 -0
  28. data/app/assets/fonts/semantic-ui/icons.woff2 +0 -0
  29. data/app/assets/fonts/semantic-ui/outline-icons.eot +0 -0
  30. data/app/assets/fonts/semantic-ui/outline-icons.svg +2 -2
  31. data/app/assets/fonts/semantic-ui/outline-icons.ttf +0 -0
  32. data/app/assets/fonts/semantic-ui/outline-icons.woff +0 -0
  33. data/app/assets/fonts/semantic-ui/outline-icons.woff2 +0 -0
  34. data/app/assets/javascripts/semantic-ui/accordion.js +569 -590
  35. data/app/assets/javascripts/semantic-ui/api.js +1153 -1116
  36. data/app/assets/javascripts/semantic-ui/calendar.js +1941 -1698
  37. data/app/assets/javascripts/semantic-ui/checkbox.js +862 -854
  38. data/app/assets/javascripts/semantic-ui/dimmer.js +697 -713
  39. data/app/assets/javascripts/semantic-ui/dropdown.js +4196 -4192
  40. data/app/assets/javascripts/semantic-ui/embed.js +646 -672
  41. data/app/assets/javascripts/semantic-ui/flyout.js +1579 -0
  42. data/app/assets/javascripts/semantic-ui/form.js +2024 -2000
  43. data/app/assets/javascripts/semantic-ui/modal.js +1546 -1384
  44. data/app/assets/javascripts/semantic-ui/nag.js +521 -527
  45. data/app/assets/javascripts/semantic-ui/popup.js +1457 -1463
  46. data/app/assets/javascripts/semantic-ui/progress.js +970 -995
  47. data/app/assets/javascripts/semantic-ui/rating.js +508 -520
  48. data/app/assets/javascripts/semantic-ui/search.js +1521 -1508
  49. data/app/assets/javascripts/semantic-ui/shape.js +784 -811
  50. data/app/assets/javascripts/semantic-ui/sidebar.js +1061 -1002
  51. data/app/assets/javascripts/semantic-ui/site.js +437 -477
  52. data/app/assets/javascripts/semantic-ui/slider.js +1311 -1297
  53. data/app/assets/javascripts/semantic-ui/state.js +639 -658
  54. data/app/assets/javascripts/semantic-ui/sticky.js +848 -891
  55. data/app/assets/javascripts/semantic-ui/tab.js +895 -941
  56. data/app/assets/javascripts/semantic-ui/toast.js +911 -851
  57. data/app/assets/javascripts/semantic-ui/transition.js +1049 -1073
  58. data/app/assets/javascripts/semantic-ui/visibility.js +1214 -1246
  59. data/app/assets/stylesheets/semantic-ui/collections/_breadcrumb.scss +7 -7
  60. data/app/assets/stylesheets/semantic-ui/collections/_form.scss +389 -407
  61. data/app/assets/stylesheets/semantic-ui/collections/_grid.scss +203 -345
  62. data/app/assets/stylesheets/semantic-ui/collections/_menu.scss +372 -501
  63. data/app/assets/stylesheets/semantic-ui/collections/_message.scss +154 -226
  64. data/app/assets/stylesheets/semantic-ui/collections/_table.scss +2065 -880
  65. data/app/assets/stylesheets/semantic-ui/elements/_button.scss +867 -1232
  66. data/app/assets/stylesheets/semantic-ui/elements/_container.scss +101 -6
  67. data/app/assets/stylesheets/semantic-ui/elements/_divider.scss +75 -93
  68. data/app/assets/stylesheets/semantic-ui/elements/_emoji.scss +11148 -9190
  69. data/app/assets/stylesheets/semantic-ui/elements/_flag.scss +1037 -929
  70. data/app/assets/stylesheets/semantic-ui/elements/_header.scss +124 -146
  71. data/app/assets/stylesheets/semantic-ui/elements/_icon.scss +2728 -2759
  72. data/app/assets/stylesheets/semantic-ui/elements/_image.scss +41 -65
  73. data/app/assets/stylesheets/semantic-ui/elements/_input.scss +982 -163
  74. data/app/assets/stylesheets/semantic-ui/elements/_label.scss +432 -479
  75. data/app/assets/stylesheets/semantic-ui/elements/_list.scss +80 -101
  76. data/app/assets/stylesheets/semantic-ui/elements/_loader.scss +452 -540
  77. data/app/assets/stylesheets/semantic-ui/elements/_placeholder.scss +56 -76
  78. data/app/assets/stylesheets/semantic-ui/elements/_rail.scss +17 -22
  79. data/app/assets/stylesheets/semantic-ui/elements/_reveal.scss +46 -85
  80. data/app/assets/stylesheets/semantic-ui/elements/_segment.scss +263 -255
  81. data/app/assets/stylesheets/semantic-ui/elements/_step.scss +106 -179
  82. data/app/assets/stylesheets/semantic-ui/elements/_text.scss +33 -33
  83. data/app/assets/stylesheets/semantic-ui/globals/_reset.scss +14 -18
  84. data/app/assets/stylesheets/semantic-ui/globals/_site.scss +132 -48
  85. data/app/assets/stylesheets/semantic-ui/modules/_accordion.scss +196 -74
  86. data/app/assets/stylesheets/semantic-ui/modules/_calendar.scss +43 -29
  87. data/app/assets/stylesheets/semantic-ui/modules/_checkbox.scss +210 -280
  88. data/app/assets/stylesheets/semantic-ui/modules/_dimmer.scss +78 -182
  89. data/app/assets/stylesheets/semantic-ui/modules/_dropdown.scss +339 -423
  90. data/app/assets/stylesheets/semantic-ui/modules/_embed.scss +24 -35
  91. data/app/assets/stylesheets/semantic-ui/modules/_flyout.scss +546 -0
  92. data/app/assets/stylesheets/semantic-ui/modules/_modal.scss +150 -153
  93. data/app/assets/stylesheets/semantic-ui/modules/_nag.scss +55 -65
  94. data/app/assets/stylesheets/semantic-ui/modules/_popup.scss +530 -310
  95. data/app/assets/stylesheets/semantic-ui/modules/_progress.scss +108 -213
  96. data/app/assets/stylesheets/semantic-ui/modules/_rating.scss +88 -168
  97. data/app/assets/stylesheets/semantic-ui/modules/_search.scss +73 -102
  98. data/app/assets/stylesheets/semantic-ui/modules/_shape.scss +16 -32
  99. data/app/assets/stylesheets/semantic-ui/modules/_sidebar.scss +126 -215
  100. data/app/assets/stylesheets/semantic-ui/modules/_slider.scss +110 -138
  101. data/app/assets/stylesheets/semantic-ui/modules/_sticky.scss +3 -7
  102. data/app/assets/stylesheets/semantic-ui/modules/_tab.scss +16 -20
  103. data/app/assets/stylesheets/semantic-ui/modules/_toast.scss +111 -141
  104. data/app/assets/stylesheets/semantic-ui/modules/_transition.scss +371 -1282
  105. data/app/assets/stylesheets/semantic-ui/views/_ad.scss +39 -50
  106. data/app/assets/stylesheets/semantic-ui/views/_card.scss +949 -458
  107. data/app/assets/stylesheets/semantic-ui/views/_comment.scss +44 -62
  108. data/app/assets/stylesheets/semantic-ui/views/_feed.scss +50 -72
  109. data/app/assets/stylesheets/semantic-ui/views/_item.scss +89 -136
  110. data/app/assets/stylesheets/semantic-ui/views/_statistic.scss +78 -119
  111. data/lib/fomantic/ui/sass/version.rb +2 -2
  112. data/tasks/converter.rb +1 -1
  113. metadata +21 -3
@@ -1,1452 +1,1614 @@
1
1
  /*!
2
2
  * # Fomantic-UI - Modal
3
- * http://github.com/fomantic/Fomantic-UI/
3
+ * https://github.com/fomantic/Fomantic-UI/
4
4
  *
5
5
  *
6
6
  * Released under the MIT license
7
- * http://opensource.org/licenses/MIT
7
+ * https://opensource.org/licenses/MIT
8
8
  *
9
9
  */
10
10
 
11
- ;(function ($, window, document, undefined) {
12
-
13
- 'use strict';
14
-
15
- $.isFunction = $.isFunction || function(obj) {
16
- return typeof obj === "function" && typeof obj.nodeType !== "number";
17
- };
18
-
19
- window = (typeof window != 'undefined' && window.Math == Math)
20
- ? window
21
- : (typeof self != 'undefined' && self.Math == Math)
22
- ? self
23
- : Function('return this')()
24
- ;
25
-
26
- $.fn.modal = function(parameters) {
27
- var
28
- $allModules = $(this),
29
- $window = $(window),
30
- $document = $(document),
31
- $body = $('body'),
32
-
33
- moduleSelector = $allModules.selector || '',
34
-
35
- time = new Date().getTime(),
36
- performance = [],
37
-
38
- query = arguments[0],
39
- methodInvoked = (typeof query == 'string'),
40
- queryArguments = [].slice.call(arguments, 1),
41
-
42
- requestAnimationFrame = window.requestAnimationFrame
43
- || window.mozRequestAnimationFrame
44
- || window.webkitRequestAnimationFrame
45
- || window.msRequestAnimationFrame
46
- || function(callback) { setTimeout(callback, 0); },
47
-
48
- returnedValue
49
- ;
50
-
51
- $allModules
52
- .each(function() {
53
- var
54
- settings = ( $.isPlainObject(parameters) )
55
- ? $.extend(true, {}, $.fn.modal.settings, parameters)
56
- : $.extend({}, $.fn.modal.settings),
57
-
58
- selector = settings.selector,
59
- className = settings.className,
60
- namespace = settings.namespace,
61
- fields = settings.fields,
62
- error = settings.error,
63
-
64
- eventNamespace = '.' + namespace,
65
- moduleNamespace = 'module-' + namespace,
66
-
67
- $module = $(this),
68
- $context = $(settings.context),
69
- $close = $module.find(selector.close),
70
-
71
- $allModals,
72
- $otherModals,
73
- $focusedElement,
74
- $dimmable,
75
- $dimmer,
76
-
77
- element = this,
78
- instance = $module.hasClass('modal') ? $module.data(moduleNamespace) : undefined,
79
-
80
- ignoreRepeatedEvents = false,
81
-
82
- initialMouseDownInModal,
83
- initialMouseDownInScrollbar,
84
- initialBodyMargin = '',
85
- tempBodyMargin = '',
86
-
87
- elementEventNamespace,
88
- id,
89
- observer,
90
- module
91
- ;
92
- module = {
93
-
94
- initialize: function() {
95
- if(!$module.hasClass('modal')) {
96
- module.create.modal();
97
- if(!$.isFunction(settings.onHidden)) {
98
- settings.onHidden = function () {
99
- module.destroy();
100
- $module.remove();
101
- };
102
- }
103
- }
104
- $module.addClass(settings.class);
105
- if (settings.title !== '') {
106
- $module.find(selector.title).html(module.helpers.escape(settings.title, settings.preserveHTML)).addClass(settings.classTitle);
107
- }
108
- if (settings.content !== '') {
109
- $module.find(selector.content).html(module.helpers.escape(settings.content, settings.preserveHTML)).addClass(settings.classContent);
110
- }
111
- if(module.has.configActions()){
112
- var $actions = $module.find(selector.actions).addClass(settings.classActions);
113
- if ($actions.length === 0) {
114
- $actions = $('<div/>', {class: className.actions + ' ' + (settings.classActions || '')}).appendTo($module);
115
- } else {
116
- $actions.empty();
117
- }
118
- settings.actions.forEach(function (el) {
119
- var icon = el[fields.icon] ? '<i class="' + module.helpers.deQuote(el[fields.icon]) + ' icon"></i>' : '',
120
- text = module.helpers.escape(el[fields.text] || '', settings.preserveHTML),
121
- cls = module.helpers.deQuote(el[fields.class] || ''),
122
- click = el[fields.click] && $.isFunction(el[fields.click]) ? el[fields.click] : function () {};
123
- $actions.append($('<button/>', {
124
- html: icon + text,
125
- class: className.button + ' ' + cls,
126
- click: function () {
127
- if (click.call(element, $module) === false) {
128
- return;
129
- }
130
- module.hide();
131
- }
132
- }));
133
- });
134
- }
135
- module.cache = {};
136
- module.verbose('Initializing dimmer', $context);
137
-
138
- module.create.id();
139
- module.create.dimmer();
140
-
141
- if ( settings.allowMultiple ) {
142
- module.create.innerDimmer();
143
- }
144
- if (!settings.centered){
145
- $module.addClass('top aligned');
146
- }
147
- module.refreshModals();
148
-
149
- module.bind.events();
150
- if(settings.observeChanges) {
151
- module.observeChanges();
152
- }
153
- module.instantiate();
154
- if(settings.autoShow){
155
- module.show();
156
- }
157
- },
11
+ (function ($, window, document) {
12
+ 'use strict';
158
13
 
159
- instantiate: function() {
160
- module.verbose('Storing instance of modal');
161
- instance = module;
162
- $module
163
- .data(moduleNamespace, instance)
164
- ;
165
- },
14
+ function isFunction(obj) {
15
+ return typeof obj === 'function' && typeof obj.nodeType !== 'number';
16
+ }
166
17
 
167
- create: {
168
- modal: function() {
169
- $module = $('<div/>', {class: className.modal});
170
- if (settings.closeIcon) {
171
- $close = $('<i/>', {class: className.close})
172
- $module.append($close);
173
- }
174
- if (settings.title !== '') {
175
- $('<div/>', {class: className.title}).appendTo($module);
176
- }
177
- if (settings.content !== '') {
178
- $('<div/>', {class: className.content}).appendTo($module);
179
- }
180
- if (module.has.configActions()) {
181
- $('<div/>', {class: className.actions}).appendTo($module);
182
- }
183
- $context.append($module);
184
- },
185
- dimmer: function() {
18
+ window = window !== undefined && window.Math === Math
19
+ ? window
20
+ : globalThis;
21
+
22
+ $.fn.modal = function (parameters) {
23
+ var
24
+ $allModules = $(this),
25
+ $window = $(window),
26
+ $document = $(document),
27
+ $body = $('body'),
28
+
29
+ moduleSelector = $allModules.selector || '',
30
+
31
+ time = Date.now(),
32
+ performance = [],
33
+
34
+ query = arguments[0],
35
+ methodInvoked = typeof query === 'string',
36
+ queryArguments = [].slice.call(arguments, 1),
37
+
38
+ returnedValue
39
+ ;
40
+
41
+ $allModules.each(function () {
186
42
  var
187
- defaultSettings = {
188
- debug : settings.debug,
189
- dimmerName : 'modals'
190
- },
191
- dimmerSettings = $.extend(true, defaultSettings, settings.dimmerSettings)
43
+ settings = $.isPlainObject(parameters)
44
+ ? $.extend(true, {}, $.fn.modal.settings, parameters)
45
+ : $.extend({}, $.fn.modal.settings),
46
+
47
+ selector = settings.selector,
48
+ className = settings.className,
49
+ namespace = settings.namespace,
50
+ fields = settings.fields,
51
+ error = settings.error,
52
+
53
+ eventNamespace = '.' + namespace,
54
+ moduleNamespace = 'module-' + namespace,
55
+
56
+ $module = $(this),
57
+ $context = [window, document].indexOf(settings.context) < 0 ? $document.find(settings.context) : $body,
58
+ isBody = $context[0] === $body[0],
59
+ $closeIcon = $module.find(selector.closeIcon),
60
+ $inputs,
61
+
62
+ $allModals,
63
+ $otherModals,
64
+ $focusedElement,
65
+ $dimmable,
66
+ $dimmer,
67
+
68
+ isModalComponent = $module.hasClass('modal'),
69
+
70
+ element = this,
71
+ instance = isModalComponent ? $module.data(moduleNamespace) : undefined,
72
+
73
+ ignoreRepeatedEvents = false,
74
+
75
+ initialMouseDownInModal,
76
+ initialMouseDownInScrollbar,
77
+ initialBodyMargin = '',
78
+ tempBodyMargin = '',
79
+ keepScrollingClass = false,
80
+ hadScrollbar = false,
81
+
82
+ elementEventNamespace,
83
+ id,
84
+ observer,
85
+ module
192
86
  ;
193
- if($.fn.dimmer === undefined) {
194
- module.error(error.dimmer);
195
- return;
196
- }
197
- module.debug('Creating dimmer');
198
- $dimmable = $context.dimmer(dimmerSettings);
199
- if(settings.detachable) {
200
- module.verbose('Modal is detachable, moving content into dimmer');
201
- $dimmable.dimmer('add content', $module);
202
- }
203
- else {
204
- module.set.undetached();
205
- }
206
- $dimmer = $dimmable.dimmer('get dimmer');
207
- },
208
- id: function() {
209
- id = (Math.random().toString(16) + '000000000').substr(2, 8);
210
- elementEventNamespace = '.' + id;
211
- module.verbose('Creating unique id for element', id);
212
- },
213
- innerDimmer: function() {
214
- if ( $module.find(selector.dimmer).length == 0 ) {
215
- $module.prepend('<div class="ui inverted dimmer"></div>');
216
- }
217
- }
218
- },
87
+ module = {
88
+
89
+ initialize: function () {
90
+ module.create.id();
91
+ if (!isModalComponent) {
92
+ module.create.modal();
93
+ if (!isFunction(settings.onHidden)) {
94
+ settings.onHidden = function () {
95
+ module.destroy();
96
+ $module.remove();
97
+ };
98
+ }
99
+ }
100
+ $module.addClass(settings.class);
101
+ if (settings.title !== '') {
102
+ $module.find(selector.title).html(module.helpers.escape(settings.title, settings.preserveHTML)).addClass(settings.classTitle);
103
+ }
104
+ if (settings.content !== '') {
105
+ $module.find(selector.content).html(module.helpers.escape(settings.content, settings.preserveHTML)).addClass(settings.classContent);
106
+ }
107
+ if (module.has.configActions()) {
108
+ var $actions = $module.find(selector.actions).addClass(settings.classActions);
109
+ if ($actions.length === 0) {
110
+ $actions = $('<div/>', { class: className.actions + ' ' + (settings.classActions || '') }).appendTo($module);
111
+ } else {
112
+ $actions.empty();
113
+ }
114
+ settings.actions.forEach(function (el) {
115
+ var
116
+ icon = el[fields.icon]
117
+ ? '<i ' + (el[fields.text] ? 'aria-hidden="true"' : '') + ' class="' + module.helpers.deQuote(el[fields.icon]) + ' icon"></i>'
118
+ : '',
119
+ text = module.helpers.escape(el[fields.text] || '', settings.preserveHTML),
120
+ cls = module.helpers.deQuote(el[fields.class] || ''),
121
+ click = el[fields.click] && isFunction(el[fields.click])
122
+ ? el[fields.click]
123
+ : function () {}
124
+ ;
125
+ $actions.append($('<button/>', {
126
+ html: icon + text,
127
+ 'aria-label': (el[fields.text] || el[fields.icon] || '').replace(/<[^>]+(>|$)/g, ''),
128
+ class: className.button + ' ' + cls,
129
+ on: {
130
+ click: function () {
131
+ var button = $(this);
132
+ if (button.is(selector.approve) || button.is(selector.deny) || click.call(element, $module) === false) {
133
+ return;
134
+ }
135
+ module.hide();
136
+ },
137
+ },
138
+ }));
139
+ });
140
+ }
141
+ module.cache = {};
142
+ module.verbose('Initializing dimmer', $context);
219
143
 
220
- destroy: function() {
221
- if (observer) {
222
- observer.disconnect();
223
- }
224
- module.verbose('Destroying previous modal');
225
- $module
226
- .removeData(moduleNamespace)
227
- .off(eventNamespace)
228
- ;
229
- $window.off(elementEventNamespace);
230
- $dimmer.off(elementEventNamespace);
231
- $close.off(eventNamespace);
232
- $context.dimmer('destroy');
233
- },
144
+ module.create.dimmer();
234
145
 
235
- observeChanges: function() {
236
- if('MutationObserver' in window) {
237
- observer = new MutationObserver(function(mutations) {
238
- module.debug('DOM tree modified, refreshing');
239
- module.refresh();
240
- });
241
- observer.observe(element, {
242
- childList : true,
243
- subtree : true
244
- });
245
- module.debug('Setting up mutation observer', observer);
246
- }
247
- },
146
+ if (settings.allowMultiple) {
147
+ module.create.innerDimmer();
148
+ }
149
+ if (!settings.centered) {
150
+ $module.addClass('top aligned');
151
+ }
152
+ module.refreshModals();
153
+ module.bind.events();
154
+ module.observeChanges();
155
+ module.instantiate();
156
+ if (settings.autoShow) {
157
+ module.show();
158
+ }
159
+ },
248
160
 
249
- refresh: function() {
250
- module.remove.scrolling();
251
- module.cacheSizes();
252
- if(!module.can.useFlex()) {
253
- module.set.modalOffset();
254
- }
255
- module.set.screenHeight();
256
- module.set.type();
257
- },
161
+ instantiate: function () {
162
+ module.verbose('Storing instance of modal');
163
+ instance = module;
164
+ $module
165
+ .data(moduleNamespace, instance)
166
+ ;
167
+ },
258
168
 
259
- refreshModals: function() {
260
- $otherModals = $module.siblings(selector.modal);
261
- $allModals = $otherModals.add($module);
262
- },
169
+ create: {
170
+ modal: function () {
171
+ $module = $('<div/>', { class: className.modal, role: 'dialog', 'aria-modal': true });
172
+ if (settings.closeIcon) {
173
+ $closeIcon = $('<i/>', {
174
+ class: className.close,
175
+ role: 'button',
176
+ tabindex: 0,
177
+ 'aria-label': settings.text.close,
178
+ });
179
+ $module.append($closeIcon);
180
+ }
181
+ if (settings.title !== '') {
182
+ var titleId = '_' + module.get.id() + 'title';
183
+ $module.attr('aria-labelledby', titleId);
184
+ $('<div/>', { class: className.title, id: titleId }).appendTo($module);
185
+ }
186
+ if (settings.content !== '') {
187
+ var descId = '_' + module.get.id() + 'desc';
188
+ $module.attr('aria-describedby', descId);
189
+ $('<div/>', { class: className.content, id: descId }).appendTo($module);
190
+ }
191
+ if (module.has.configActions()) {
192
+ $('<div/>', { class: className.actions }).appendTo($module);
193
+ }
194
+ $context.append($module);
195
+ element = $module[0];
196
+ },
197
+ dimmer: function () {
198
+ var
199
+ defaultSettings = {
200
+ debug: settings.debug,
201
+ dimmerName: 'modals',
202
+ },
203
+ dimmerSettings = $.extend(true, defaultSettings, settings.dimmerSettings)
204
+ ;
205
+ if ($.fn.dimmer === undefined) {
206
+ module.error(error.dimmer);
207
+
208
+ return;
209
+ }
210
+ module.debug('Creating dimmer');
211
+ $dimmable = $context.dimmer(dimmerSettings);
212
+ keepScrollingClass = module.is.scrolling();
213
+ if (settings.detachable) {
214
+ module.verbose('Modal is detachable, moving content into dimmer');
215
+ $dimmable.dimmer('add content', $module);
216
+ } else {
217
+ module.set.undetached();
218
+ }
219
+ $dimmer = $dimmable.dimmer('get dimmer');
220
+ },
221
+ id: function () {
222
+ id = (Math.random().toString(16) + '000000000').slice(2, 10);
223
+ elementEventNamespace = '.' + id;
224
+ module.verbose('Creating unique id for element', id);
225
+ },
226
+ innerDimmer: function () {
227
+ if ($module.find(selector.dimmer).length === 0) {
228
+ $('<div/>', { class: className.innerDimmer }).prependTo($module);
229
+ }
230
+ },
231
+ },
263
232
 
264
- attachEvents: function(selector, event) {
265
- var
266
- $toggle = $(selector)
267
- ;
268
- event = $.isFunction(module[event])
269
- ? module[event]
270
- : module.toggle
271
- ;
272
- if($toggle.length > 0) {
273
- module.debug('Attaching modal events to element', selector, event);
274
- $toggle
275
- .off(eventNamespace)
276
- .on('click' + eventNamespace, event)
277
- ;
278
- }
279
- else {
280
- module.error(error.notFound, selector);
281
- }
282
- },
233
+ destroy: function () {
234
+ if (observer) {
235
+ observer.disconnect();
236
+ }
237
+ module.verbose('Destroying previous modal');
238
+ $module
239
+ .removeData(moduleNamespace)
240
+ .off(eventNamespace)
241
+ ;
242
+ $window.off(elementEventNamespace);
243
+ $dimmer.off(elementEventNamespace);
244
+ $closeIcon.off(elementEventNamespace);
245
+ if ($inputs) {
246
+ $inputs.off(elementEventNamespace);
247
+ }
248
+ $context.dimmer('destroy');
249
+ },
283
250
 
284
- bind: {
285
- events: function() {
286
- module.verbose('Attaching events');
287
- $module
288
- .on('click' + eventNamespace, selector.close, module.event.close)
289
- .on('click' + eventNamespace, selector.approve, module.event.approve)
290
- .on('click' + eventNamespace, selector.deny, module.event.deny)
291
- ;
292
- $window
293
- .on('resize' + elementEventNamespace, module.event.resize)
294
- ;
295
- },
296
- scrollLock: function() {
297
- // touch events default to passive, due to changes in chrome to optimize mobile perf
298
- $dimmable.get(0).addEventListener('touchmove', module.event.preventScroll, { passive: false });
299
- }
300
- },
251
+ observeChanges: function () {
252
+ if ('MutationObserver' in window) {
253
+ observer = new MutationObserver(function (mutations) {
254
+ var collectNodes = function (parent) {
255
+ var nodes = [];
256
+ for (var c = 0, cl = parent.length; c < cl; c++) {
257
+ Array.prototype.push.apply(nodes, collectNodes(parent[c].childNodes));
258
+ nodes.push(parent[c]);
259
+ }
260
+
261
+ return nodes;
262
+ },
263
+ shouldRefresh = false,
264
+ shouldRefreshInputs = false
265
+ ;
266
+ mutations.every(function (mutation) {
267
+ if (mutation.type === 'attributes') {
268
+ if (mutation.attributeName === 'disabled' || $(mutation.target).find(':input').addBack(':input')) {
269
+ shouldRefreshInputs = true;
270
+ }
271
+ } else {
272
+ shouldRefresh = true;
273
+ // mutationobserver only provides the parent nodes
274
+ // so let's collect all childs as well to find nested inputs
275
+ var $addedInputs = $(collectNodes(mutation.addedNodes)).filter('a[href], [tabindex], :input:enabled').filter(':visible'),
276
+ $removedInputs = $(collectNodes(mutation.removedNodes)).filter('a[href], [tabindex], :input');
277
+ if ($addedInputs.length > 0 || $removedInputs.length > 0) {
278
+ shouldRefreshInputs = true;
279
+ }
280
+ }
281
+
282
+ return !shouldRefreshInputs;
283
+ });
284
+
285
+ if (shouldRefresh && settings.observeChanges) {
286
+ module.debug('DOM tree modified, refreshing');
287
+ module.refresh();
288
+ }
289
+ if (shouldRefreshInputs) {
290
+ module.refreshInputs();
291
+ }
292
+ });
293
+ observer.observe(element, {
294
+ attributeFilter: ['class', 'disabled'],
295
+ attributes: true,
296
+ childList: true,
297
+ subtree: true,
298
+ });
299
+ module.debug('Setting up mutation observer', observer);
300
+ }
301
+ },
301
302
 
302
- unbind: {
303
- scrollLock: function() {
304
- $dimmable.get(0).removeEventListener('touchmove', module.event.preventScroll, { passive: false });
305
- }
306
- },
303
+ refresh: function () {
304
+ module.remove.scrolling();
305
+ module.cacheSizes();
306
+ if (!module.can.useFlex()) {
307
+ module.set.modalOffset();
308
+ }
309
+ module.set.screenHeight();
310
+ module.set.type();
311
+ },
307
312
 
308
- get: {
309
- id: function() {
310
- return (Math.random().toString(16) + '000000000').substr(2, 8);
311
- },
312
- element: function() {
313
- return $module;
314
- },
315
- settings: function() {
316
- return settings;
317
- }
318
- },
313
+ refreshModals: function () {
314
+ $otherModals = $module.siblings(selector.modal);
315
+ $allModals = $otherModals.add($module);
316
+ },
319
317
 
320
- event: {
321
- approve: function() {
322
- if(ignoreRepeatedEvents || settings.onApprove.call(element, $(this)) === false) {
323
- module.verbose('Approve callback returned false cancelling hide');
324
- return;
325
- }
326
- ignoreRepeatedEvents = true;
327
- module.hide(function() {
328
- ignoreRepeatedEvents = false;
329
- });
330
- },
331
- preventScroll: function(event) {
332
- if(event.target.className.indexOf('dimmer') !== -1) {
333
- event.preventDefault();
334
- }
335
- },
336
- deny: function() {
337
- if(ignoreRepeatedEvents || settings.onDeny.call(element, $(this)) === false) {
338
- module.verbose('Deny callback returned false cancelling hide');
339
- return;
340
- }
341
- ignoreRepeatedEvents = true;
342
- module.hide(function() {
343
- ignoreRepeatedEvents = false;
344
- });
345
- },
346
- close: function() {
347
- module.hide();
348
- },
349
- mousedown: function(event) {
350
- var
351
- $target = $(event.target),
352
- isRtl = module.is.rtl();
353
- ;
354
- initialMouseDownInModal = ($target.closest(selector.modal).length > 0);
355
- if(initialMouseDownInModal) {
356
- module.verbose('Mouse down event registered inside the modal');
357
- }
358
- initialMouseDownInScrollbar = module.is.scrolling() && ((!isRtl && $(window).outerWidth() - settings.scrollbarWidth <= event.clientX) || (isRtl && settings.scrollbarWidth >= event.clientX));
359
- if(initialMouseDownInScrollbar) {
360
- module.verbose('Mouse down event registered inside the scrollbar');
361
- }
362
- },
363
- mouseup: function(event) {
364
- if(!settings.closable) {
365
- module.verbose('Dimmer clicked but closable setting is disabled');
366
- return;
367
- }
368
- if(initialMouseDownInModal) {
369
- module.debug('Dimmer clicked but mouse down was initially registered inside the modal');
370
- return;
371
- }
372
- if(initialMouseDownInScrollbar){
373
- module.debug('Dimmer clicked but mouse down was initially registered inside the scrollbar');
374
- return;
375
- }
376
- var
377
- $target = $(event.target),
378
- isInModal = ($target.closest(selector.modal).length > 0),
379
- isInDOM = $.contains(document.documentElement, event.target)
380
- ;
381
- if(!isInModal && isInDOM && module.is.active() && $module.hasClass(className.front) ) {
382
- module.debug('Dimmer clicked, hiding all modals');
383
- if(settings.allowMultiple) {
384
- if(!module.hideAll()) {
385
- return;
386
- }
387
- }
388
- else if(!module.hide()){
389
- return;
390
- }
391
- module.remove.clickaway();
392
- }
393
- },
394
- debounce: function(method, delay) {
395
- clearTimeout(module.timer);
396
- module.timer = setTimeout(method, delay);
397
- },
398
- keyboard: function(event) {
399
- var
400
- keyCode = event.which,
401
- escapeKey = 27
402
- ;
403
- if(keyCode == escapeKey) {
404
- if(settings.closable) {
405
- module.debug('Escape key pressed hiding modal');
406
- if ( $module.hasClass(className.front) ) {
407
- module.hide();
408
- }
409
- }
410
- else {
411
- module.debug('Escape key pressed, but closable is set to false');
412
- }
413
- event.preventDefault();
414
- }
415
- },
416
- resize: function() {
417
- if( $dimmable.dimmer('is active') && ( module.is.animating() || module.is.active() ) ) {
418
- requestAnimationFrame(module.refresh);
419
- }
420
- }
421
- },
318
+ refreshInputs: function () {
319
+ if ($inputs) {
320
+ $inputs
321
+ .off('keydown' + elementEventNamespace)
322
+ ;
323
+ }
324
+ $inputs = $module.find('a[href], [tabindex], :input:enabled').filter(':visible').filter(function () {
325
+ return $(this).closest('.disabled').length === 0;
326
+ });
327
+ $module.removeAttr('tabindex');
328
+ if ($inputs.length === 0) {
329
+ $inputs = $module;
330
+ $module.attr('tabindex', -1);
331
+ }
332
+ $inputs.first()
333
+ .on('keydown' + elementEventNamespace, module.event.inputKeyDown.first)
334
+ ;
335
+ $inputs.last()
336
+ .on('keydown' + elementEventNamespace, module.event.inputKeyDown.last)
337
+ ;
338
+ if (settings.autofocus && $inputs.filter(':focus').length === 0) {
339
+ module.set.autofocus();
340
+ }
341
+ },
422
342
 
423
- toggle: function() {
424
- if( module.is.active() || module.is.animating() ) {
425
- module.hide();
426
- }
427
- else {
428
- module.show();
429
- }
430
- },
343
+ attachEvents: function (selector, event) {
344
+ var
345
+ $toggle = $(selector)
346
+ ;
347
+ event = isFunction(module[event])
348
+ ? module[event]
349
+ : module.toggle;
350
+ if ($toggle.length > 0) {
351
+ module.debug('Attaching modal events to element', selector, event);
352
+ $toggle
353
+ .off(eventNamespace)
354
+ .on('click' + eventNamespace, event)
355
+ ;
356
+ } else {
357
+ module.error(error.notFound, selector);
358
+ }
359
+ },
431
360
 
432
- show: function(callback) {
433
- callback = $.isFunction(callback)
434
- ? callback
435
- : function(){}
436
- ;
437
- module.refreshModals();
438
- module.set.dimmerSettings();
439
- module.set.dimmerStyles();
361
+ bind: {
362
+ events: function () {
363
+ module.verbose('Attaching events');
364
+ $module
365
+ .on('click' + eventNamespace, selector.close, module.event.close)
366
+ .on('click' + eventNamespace, selector.approve, module.event.approve)
367
+ .on('click' + eventNamespace, selector.deny, module.event.deny)
368
+ ;
369
+ $closeIcon
370
+ .on('keyup' + elementEventNamespace, module.event.closeKeyUp)
371
+ ;
372
+ $window
373
+ .on('resize' + elementEventNamespace, module.event.resize)
374
+ .on('focus' + elementEventNamespace, module.event.focus)
375
+ ;
376
+ },
377
+ scrollLock: function () {
378
+ // touch events default to passive, due to changes in chrome to optimize mobile perf
379
+ $dimmable[0].addEventListener('touchmove', module.event.preventScroll, { passive: false });
380
+ },
381
+ },
440
382
 
441
- module.showModal(callback);
442
- },
383
+ unbind: {
384
+ scrollLock: function () {
385
+ $dimmable[0].removeEventListener('touchmove', module.event.preventScroll, { passive: false });
386
+ },
387
+ },
443
388
 
444
- hide: function(callback) {
445
- callback = $.isFunction(callback)
446
- ? callback
447
- : function(){}
448
- ;
449
- module.refreshModals();
450
- return module.hideModal(callback);
451
- },
389
+ get: {
390
+ id: function () {
391
+ return id;
392
+ },
393
+ element: function () {
394
+ return $module;
395
+ },
396
+ settings: function () {
397
+ return settings;
398
+ },
399
+ },
452
400
 
453
- showModal: function(callback) {
454
- callback = $.isFunction(callback)
455
- ? callback
456
- : function(){}
457
- ;
458
- if( module.is.animating() || !module.is.active() ) {
459
- module.showDimmer();
460
- module.cacheSizes();
461
- module.set.bodyMargin();
462
- if(module.can.useFlex()) {
463
- module.remove.legacy();
464
- }
465
- else {
466
- module.set.legacy();
467
- module.set.modalOffset();
468
- module.debug('Using non-flex legacy modal positioning.');
469
- }
470
- module.set.screenHeight();
471
- module.set.type();
472
- module.set.clickaway();
401
+ event: {
402
+ approve: function () {
403
+ if (ignoreRepeatedEvents || settings.onApprove.call(element, $(this)) === false) {
404
+ module.verbose('Approve callback returned false cancelling hide');
405
+
406
+ return;
407
+ }
408
+ ignoreRepeatedEvents = true;
409
+ module.hide(function () {
410
+ ignoreRepeatedEvents = false;
411
+ });
412
+ },
413
+ preventScroll: function (event) {
414
+ if (event.target.className.indexOf('dimmer') !== -1) {
415
+ event.preventDefault();
416
+ }
417
+ },
418
+ deny: function () {
419
+ if (ignoreRepeatedEvents || settings.onDeny.call(element, $(this)) === false) {
420
+ module.verbose('Deny callback returned false cancelling hide');
421
+
422
+ return;
423
+ }
424
+ ignoreRepeatedEvents = true;
425
+ module.hide(function () {
426
+ ignoreRepeatedEvents = false;
427
+ });
428
+ },
429
+ close: function () {
430
+ module.hide();
431
+ },
432
+ closeKeyUp: function (event) {
433
+ var
434
+ keyCode = event.which
435
+ ;
436
+ if ((keyCode === settings.keys.enter || keyCode === settings.keys.space) && $module.hasClass(className.front)) {
437
+ module.hide();
438
+ }
439
+ },
440
+ inputKeyDown: {
441
+ first: function (event) {
442
+ var
443
+ keyCode = event.which
444
+ ;
445
+ if (keyCode === settings.keys.tab && event.shiftKey) {
446
+ $inputs.last().trigger('focus');
447
+ event.preventDefault();
448
+ }
449
+ },
450
+ last: function (event) {
451
+ var
452
+ keyCode = event.which
453
+ ;
454
+ if (keyCode === settings.keys.tab && !event.shiftKey) {
455
+ $inputs.first().trigger('focus');
456
+ event.preventDefault();
457
+ }
458
+ },
459
+ },
460
+ mousedown: function (event) {
461
+ var
462
+ $target = $(event.target),
463
+ isRtl = module.is.rtl()
464
+ ;
465
+ initialMouseDownInModal = $target.closest(selector.modal).length > 0;
466
+ if (initialMouseDownInModal) {
467
+ module.verbose('Mouse down event registered inside the modal');
468
+ }
469
+ initialMouseDownInScrollbar = module.is.scrolling() && ((!isRtl && $window.outerWidth() - settings.scrollbarWidth <= event.clientX) || (isRtl && settings.scrollbarWidth >= event.clientX));
470
+ if (initialMouseDownInScrollbar) {
471
+ module.verbose('Mouse down event registered inside the scrollbar');
472
+ }
473
+ },
474
+ mouseup: function (event) {
475
+ if (!settings.closable) {
476
+ module.verbose('Dimmer clicked but closable setting is disabled');
477
+
478
+ return;
479
+ }
480
+ if (initialMouseDownInModal) {
481
+ module.debug('Dimmer clicked but mouse down was initially registered inside the modal');
482
+
483
+ return;
484
+ }
485
+ if (initialMouseDownInScrollbar) {
486
+ module.debug('Dimmer clicked but mouse down was initially registered inside the scrollbar');
487
+
488
+ return;
489
+ }
490
+ var
491
+ $target = $(event.target),
492
+ isInModal = $target.closest(selector.modal).length > 0,
493
+ isInDOM = $.contains(document.documentElement, event.target)
494
+ ;
495
+ if (!isInModal && isInDOM && module.is.active() && $module.hasClass(className.front)) {
496
+ module.debug('Dimmer clicked, hiding all modals');
497
+ if (settings.allowMultiple) {
498
+ if (!module.hideAll()) {
499
+ return;
500
+ }
501
+ } else if (!module.hide()) {
502
+ return;
503
+ }
504
+ module.remove.clickaway();
505
+ }
506
+ },
507
+ debounce: function (method, delay) {
508
+ clearTimeout(module.timer);
509
+ module.timer = setTimeout(method, delay);
510
+ },
511
+ keyboard: function (event) {
512
+ var
513
+ keyCode = event.which
514
+ ;
515
+ if (keyCode === settings.keys.escape) {
516
+ if (settings.closable) {
517
+ module.debug('Escape key pressed hiding modal');
518
+ if ($module.hasClass(className.front)) {
519
+ module.hide();
520
+ }
521
+ } else {
522
+ module.debug('Escape key pressed, but closable is set to false');
523
+ }
524
+ event.preventDefault();
525
+ }
526
+ },
527
+ resize: function () {
528
+ if ($dimmable.dimmer('is active') && (module.is.animating() || module.is.active())) {
529
+ requestAnimationFrame(module.refresh);
530
+ }
531
+ },
532
+ focus: function () {
533
+ if ($dimmable.dimmer('is active') && module.is.active() && settings.autofocus) {
534
+ requestAnimationFrame(module.set.autofocus);
535
+ }
536
+ },
537
+ },
473
538
 
474
- if( !settings.allowMultiple && module.others.active() ) {
475
- module.hideOthers(module.showModal);
476
- }
477
- else {
478
- ignoreRepeatedEvents = false;
479
- if( settings.allowMultiple ) {
480
- if ( module.others.active() ) {
481
- $otherModals.filter('.' + className.active).find(selector.dimmer).addClass('active');
482
- }
539
+ toggle: function () {
540
+ if (module.is.active() || module.is.animating()) {
541
+ module.hide();
542
+ } else {
543
+ module.show();
544
+ }
545
+ },
483
546
 
484
- if ( settings.detachable ) {
485
- $module.detach().appendTo($dimmer);
486
- }
487
- }
488
- settings.onShow.call(element);
489
- if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
490
- module.debug('Showing modal with css animations');
491
- $module
492
- .transition({
493
- debug : settings.debug,
494
- animation : (settings.transition.showMethod || settings.transition) + ' in',
495
- queue : settings.queue,
496
- duration : settings.transition.showDuration || settings.duration,
497
- useFailSafe : true,
498
- onComplete : function() {
499
- settings.onVisible.apply(element);
500
- if(settings.keyboardShortcuts) {
501
- module.add.keyboardShortcuts();
502
- }
503
- module.save.focus();
504
- module.set.active();
505
- if(settings.autofocus) {
506
- module.set.autofocus();
507
- }
508
- callback();
547
+ show: function (callback) {
548
+ callback = isFunction(callback)
549
+ ? callback
550
+ : function () {};
551
+ module.refreshModals();
552
+ module.set.dimmerSettings();
553
+ module.set.dimmerStyles();
554
+
555
+ module.showModal(callback);
556
+ },
557
+
558
+ hide: function (callback) {
559
+ callback = isFunction(callback)
560
+ ? callback
561
+ : function () {};
562
+ module.refreshModals();
563
+
564
+ return module.hideModal(callback);
565
+ },
566
+
567
+ showModal: function (callback) {
568
+ callback = isFunction(callback)
569
+ ? callback
570
+ : function () {};
571
+ if (module.is.animating() || !module.is.active()) {
572
+ if (settings.onShow.call(element) === false) {
573
+ module.verbose('Show callback returned false cancelling show');
574
+
575
+ return;
576
+ }
577
+ hadScrollbar = module.has.scrollbar();
578
+ module.showDimmer();
579
+ module.cacheSizes();
580
+ if (hadScrollbar) {
581
+ module.set.bodyMargin();
582
+ }
583
+ if (module.can.useFlex()) {
584
+ module.remove.legacy();
585
+ } else {
586
+ module.set.legacy();
587
+ module.set.modalOffset();
588
+ module.debug('Using non-flex legacy modal positioning.');
589
+ }
590
+ module.set.screenHeight();
591
+ module.set.type();
592
+ module.set.clickaway();
593
+
594
+ if (!settings.allowMultiple && module.others.active()) {
595
+ module.hideOthers(module.showModal);
596
+ } else {
597
+ ignoreRepeatedEvents = false;
598
+ if (settings.allowMultiple) {
599
+ if (module.others.active()) {
600
+ $otherModals.filter('.' + className.active).find(selector.dimmer).addClass('active');
601
+ }
602
+
603
+ if (settings.detachable) {
604
+ $module.detach().appendTo($dimmer);
605
+ }
606
+ }
607
+ if (settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
608
+ module.debug('Showing modal with css animations');
609
+ $module
610
+ .transition({
611
+ debug: settings.debug,
612
+ verbose: settings.verbose,
613
+ silent: settings.silent,
614
+ animation: (settings.transition.showMethod || settings.transition) + ' in',
615
+ queue: settings.queue,
616
+ duration: settings.transition.showDuration || settings.duration,
617
+ useFailSafe: true,
618
+ onComplete: function () {
619
+ settings.onVisible.apply(element);
620
+ if (settings.keyboardShortcuts) {
621
+ module.add.keyboardShortcuts();
622
+ }
623
+ module.save.focus();
624
+ module.set.active();
625
+ module.refreshInputs();
626
+ callback();
627
+ },
628
+ })
629
+ ;
630
+ } else {
631
+ module.error(error.noTransition);
632
+ }
633
+ }
634
+ } else {
635
+ module.debug('Modal is already visible');
509
636
  }
510
- })
511
- ;
512
- }
513
- else {
514
- module.error(error.noTransition);
515
- }
516
- }
517
- }
518
- else {
519
- module.debug('Modal is already visible');
520
- }
521
- },
637
+ },
638
+
639
+ hideModal: function (callback, keepDimmed, hideOthersToo) {
640
+ var
641
+ $previousModal = $otherModals.filter('.' + className.active).last()
642
+ ;
643
+ callback = isFunction(callback)
644
+ ? callback
645
+ : function () {};
646
+ if (settings.onHide.call(element, $(this)) === false) {
647
+ module.verbose('Hide callback returned false cancelling hide');
648
+ ignoreRepeatedEvents = false;
649
+
650
+ return false;
651
+ }
652
+
653
+ if (module.is.animating() || module.is.active()) {
654
+ module.debug('Hiding modal');
655
+ if (settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
656
+ module.remove.active();
657
+ $module
658
+ .transition({
659
+ debug: settings.debug,
660
+ verbose: settings.verbose,
661
+ silent: settings.silent,
662
+ animation: (settings.transition.hideMethod || settings.transition) + ' out',
663
+ queue: settings.queue,
664
+ duration: settings.transition.hideDuration || settings.duration,
665
+ useFailSafe: true,
666
+ onStart: function () {
667
+ if (!module.others.active() && !module.others.animating() && !keepDimmed) {
668
+ module.hideDimmer();
669
+ }
670
+ if (settings.keyboardShortcuts && !module.others.active()) {
671
+ module.remove.keyboardShortcuts();
672
+ }
673
+ },
674
+ onComplete: function () {
675
+ module.unbind.scrollLock();
676
+ if (settings.allowMultiple) {
677
+ $previousModal.addClass(className.front);
678
+ $module.removeClass(className.front);
679
+
680
+ if (hideOthersToo) {
681
+ $allModals.find(selector.dimmer).removeClass('active');
682
+ } else {
683
+ $previousModal.find(selector.dimmer).removeClass('active');
684
+ }
685
+ }
686
+ if (isFunction(settings.onHidden)) {
687
+ settings.onHidden.call(element);
688
+ }
689
+ module.remove.dimmerStyles();
690
+ module.restore.focus();
691
+ callback();
692
+ },
693
+ })
694
+ ;
695
+ } else {
696
+ module.error(error.noTransition);
697
+ }
698
+ }
699
+ },
522
700
 
523
- hideModal: function(callback, keepDimmed, hideOthersToo) {
524
- var
525
- $previousModal = $otherModals.filter('.' + className.active).last()
526
- ;
527
- callback = $.isFunction(callback)
528
- ? callback
529
- : function(){}
530
- ;
531
- module.debug('Hiding modal');
532
- if(settings.onHide.call(element, $(this)) === false) {
533
- module.verbose('Hide callback returned false cancelling hide');
534
- ignoreRepeatedEvents = false;
535
- return false;
536
- }
537
-
538
- if( module.is.animating() || module.is.active() ) {
539
- if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
540
- module.remove.active();
541
- $module
542
- .transition({
543
- debug : settings.debug,
544
- animation : (settings.transition.hideMethod || settings.transition) + ' out',
545
- queue : settings.queue,
546
- duration : settings.transition.hideDuration || settings.duration,
547
- useFailSafe : true,
548
- onStart : function() {
549
- if(!module.others.active() && !module.others.animating() && !keepDimmed) {
550
- module.hideDimmer();
701
+ showDimmer: function () {
702
+ if ($dimmable.dimmer('is animating') || !$dimmable.dimmer('is active')) {
703
+ if (hadScrollbar) {
704
+ if (!isBody) {
705
+ $dimmer.css('top', $dimmable.scrollTop());
706
+ }
707
+ module.save.bodyMargin();
708
+ }
709
+ module.debug('Showing dimmer');
710
+ $dimmable.dimmer('show');
711
+ } else {
712
+ module.debug('Dimmer already visible');
551
713
  }
552
- if( settings.keyboardShortcuts && !module.others.active() ) {
553
- module.remove.keyboardShortcuts();
714
+ },
715
+
716
+ hideDimmer: function () {
717
+ if ($dimmable.dimmer('is animating') || $dimmable.dimmer('is active')) {
718
+ module.unbind.scrollLock();
719
+ $dimmable.dimmer('hide', function () {
720
+ if (hadScrollbar) {
721
+ module.restore.bodyMargin();
722
+ }
723
+ module.remove.clickaway();
724
+ module.remove.screenHeight();
725
+ });
726
+ } else {
727
+ module.debug('Dimmer is not visible cannot hide');
554
728
  }
555
- },
556
- onComplete : function() {
557
- module.unbind.scrollLock();
558
- if ( settings.allowMultiple ) {
559
- $previousModal.addClass(className.front);
560
- $module.removeClass(className.front);
561
-
562
- if ( hideOthersToo ) {
563
- $allModals.find(selector.dimmer).removeClass('active');
564
- }
565
- else {
566
- $previousModal.find(selector.dimmer).removeClass('active');
567
- }
729
+ },
730
+
731
+ hideAll: function (callback) {
732
+ var
733
+ $visibleModals = $allModals.filter('.' + className.active + ', .' + className.animating)
734
+ ;
735
+ callback = isFunction(callback)
736
+ ? callback
737
+ : function () {};
738
+ if ($visibleModals.length > 0) {
739
+ module.debug('Hiding all visible modals');
740
+ var hideOk = true;
741
+ // check in reverse order trying to hide most top displayed modal first
742
+ $($visibleModals.get().reverse()).each(function (index, element) {
743
+ if (hideOk) {
744
+ hideOk = $(element).modal('hide modal', callback, false, true);
745
+ }
746
+ });
747
+ if (hideOk) {
748
+ module.hideDimmer();
749
+ }
750
+
751
+ return hideOk;
568
752
  }
569
- if($.isFunction(settings.onHidden)) {
570
- settings.onHidden.call(element);
753
+ },
754
+
755
+ hideOthers: function (callback) {
756
+ var
757
+ $visibleModals = $otherModals.filter('.' + className.active + ', .' + className.animating)
758
+ ;
759
+ callback = isFunction(callback)
760
+ ? callback
761
+ : function () {};
762
+ if ($visibleModals.length > 0) {
763
+ module.debug('Hiding other modals', $otherModals);
764
+ $visibleModals
765
+ .modal('hide modal', callback, true)
766
+ ;
571
767
  }
572
- module.remove.dimmerStyles();
573
- module.restore.focus();
574
- callback();
575
- }
576
- })
577
- ;
578
- }
579
- else {
580
- module.error(error.noTransition);
581
- }
582
- }
583
- },
768
+ },
584
769
 
585
- showDimmer: function() {
586
- if($dimmable.dimmer('is animating') || !$dimmable.dimmer('is active') ) {
587
- module.save.bodyMargin();
588
- module.debug('Showing dimmer');
589
- $dimmable.dimmer('show');
590
- }
591
- else {
592
- module.debug('Dimmer already visible');
593
- }
594
- },
770
+ others: {
771
+ active: function () {
772
+ return $otherModals.filter('.' + className.active).length > 0;
773
+ },
774
+ animating: function () {
775
+ return $otherModals.filter('.' + className.animating).length > 0;
776
+ },
777
+ },
595
778
 
596
- hideDimmer: function() {
597
- if( $dimmable.dimmer('is animating') || ($dimmable.dimmer('is active')) ) {
598
- module.unbind.scrollLock();
599
- $dimmable.dimmer('hide', function() {
600
- module.restore.bodyMargin();
601
- module.remove.clickaway();
602
- module.remove.screenHeight();
603
- });
604
- }
605
- else {
606
- module.debug('Dimmer is not visible cannot hide');
607
- return;
608
- }
609
- },
779
+ add: {
780
+ keyboardShortcuts: function () {
781
+ module.verbose('Adding keyboard shortcuts');
782
+ $document
783
+ .on('keydown' + eventNamespace, module.event.keyboard)
784
+ ;
785
+ },
786
+ },
610
787
 
611
- hideAll: function(callback) {
612
- var
613
- $visibleModals = $allModals.filter('.' + className.active + ', .' + className.animating)
614
- ;
615
- callback = $.isFunction(callback)
616
- ? callback
617
- : function(){}
618
- ;
619
- if( $visibleModals.length > 0 ) {
620
- module.debug('Hiding all visible modals');
621
- var hideOk = true;
622
- //check in reverse order trying to hide most top displayed modal first
623
- $($visibleModals.get().reverse()).each(function(index,element){
624
- if(hideOk){
625
- hideOk = $(element).modal('hide modal', callback, false, true);
788
+ save: {
789
+ focus: function () {
790
+ var
791
+ $activeElement = $(document.activeElement),
792
+ inCurrentModal = $activeElement.closest($module).length > 0
793
+ ;
794
+ if (!inCurrentModal) {
795
+ $focusedElement = $(document.activeElement).trigger('blur');
796
+ }
797
+ },
798
+ bodyMargin: function () {
799
+ initialBodyMargin = $context.css((isBody ? 'margin-' : 'padding-') + (module.can.leftBodyScrollbar() ? 'left' : 'right'));
800
+ var
801
+ bodyMarginRightPixel = parseInt(initialBodyMargin.replace(/[^\d.]/g, ''), 10),
802
+ bodyScrollbarWidth = isBody ? window.innerWidth - document.documentElement.clientWidth : $context[0].offsetWidth - $context[0].clientWidth
803
+ ;
804
+ tempBodyMargin = bodyMarginRightPixel + bodyScrollbarWidth;
805
+ },
806
+ },
807
+
808
+ restore: {
809
+ focus: function () {
810
+ if ($focusedElement && $focusedElement.length > 0 && settings.restoreFocus) {
811
+ $focusedElement.trigger('focus');
812
+ }
813
+ },
814
+ bodyMargin: function () {
815
+ var position = module.can.leftBodyScrollbar() ? 'left' : 'right';
816
+ $context.css((isBody ? 'margin-' : 'padding-') + position, initialBodyMargin);
817
+ $context.find(selector.bodyFixed.replace('right', position)).each(function () {
818
+ var
819
+ el = $(this),
820
+ attribute = el.css('position') === 'fixed' ? 'padding-' + position : position
821
+ ;
822
+ el.css(attribute, '');
823
+ });
824
+ },
825
+ },
826
+
827
+ remove: {
828
+ active: function () {
829
+ $module.removeClass(className.active);
830
+ },
831
+ legacy: function () {
832
+ $module.removeClass(className.legacy);
833
+ },
834
+ clickaway: function () {
835
+ if (!settings.detachable) {
836
+ $module
837
+ .off('mousedown' + elementEventNamespace)
838
+ ;
839
+ }
840
+ $dimmer
841
+ .off('mousedown' + elementEventNamespace)
842
+ ;
843
+ $dimmer
844
+ .off('mouseup' + elementEventNamespace)
845
+ ;
846
+ },
847
+ dimmerStyles: function () {
848
+ $dimmer.removeClass(className.inverted);
849
+ $dimmable.removeClass(className.blurring);
850
+ },
851
+ bodyStyle: function () {
852
+ if ($context.attr('style') === '') {
853
+ module.verbose('Removing style attribute');
854
+ $context.removeAttr('style');
855
+ }
856
+ },
857
+ screenHeight: function () {
858
+ module.debug('Removing page height');
859
+ $context
860
+ .css('height', '')
861
+ ;
862
+ module.remove.bodyStyle();
863
+ },
864
+ keyboardShortcuts: function () {
865
+ module.verbose('Removing keyboard shortcuts');
866
+ $document
867
+ .off('keydown' + eventNamespace)
868
+ ;
869
+ },
870
+ scrolling: function () {
871
+ if (!keepScrollingClass) {
872
+ $dimmable.removeClass(className.scrolling);
873
+ }
874
+ $module.removeClass(className.scrolling);
875
+ },
876
+ },
877
+
878
+ cacheSizes: function () {
879
+ $module.addClass(className.loading);
880
+ var
881
+ scrollHeight = $module.prop('scrollHeight'),
882
+ modalWidth = $module.outerWidth(),
883
+ modalHeight = $module.outerHeight()
884
+ ;
885
+ if (module.cache.pageHeight === undefined || modalHeight !== 0) {
886
+ $.extend(module.cache, {
887
+ pageHeight: $document.outerHeight(),
888
+ width: modalWidth,
889
+ height: modalHeight + settings.offset,
890
+ scrollHeight: scrollHeight + settings.offset,
891
+ contextHeight: isBody
892
+ ? $window.height()
893
+ : $dimmable.height(),
894
+ });
895
+ module.cache.topOffset = -(module.cache.height / 2);
896
+ }
897
+ $module.removeClass(className.loading);
898
+ module.debug('Caching modal and container sizes', module.cache);
899
+ },
900
+ helpers: {
901
+ deQuote: function (string) {
902
+ return String(string).replace(/"/g, '');
903
+ },
904
+ escape: function (string, preserveHTML) {
905
+ if (preserveHTML) {
906
+ return string;
907
+ }
908
+ var
909
+ badChars = /["'<>`]/g,
910
+ shouldEscape = /["&'<>`]/,
911
+ escape = {
912
+ '<': '&lt;',
913
+ '>': '&gt;',
914
+ '"': '&quot;',
915
+ "'": '&#x27;',
916
+ '`': '&#x60;',
917
+ },
918
+ escapedChar = function (chr) {
919
+ return escape[chr];
920
+ }
921
+ ;
922
+ if (shouldEscape.test(string)) {
923
+ string = string.replace(/&(?![\d#a-z]{1,12};)/gi, '&amp;');
924
+
925
+ return string.replace(badChars, escapedChar);
926
+ }
927
+
928
+ return string;
929
+ },
930
+ },
931
+ can: {
932
+ leftBodyScrollbar: function () {
933
+ if (module.cache.leftBodyScrollbar === undefined) {
934
+ module.cache.leftBodyScrollbar = module.is.rtl() && ((module.is.iframe && !module.is.firefox()) || module.is.safari() || module.is.edge() || module.is.ie());
935
+ }
936
+
937
+ return module.cache.leftBodyScrollbar;
938
+ },
939
+ useFlex: function () {
940
+ if (settings.useFlex === 'auto') {
941
+ return settings.detachable && !module.is.ie();
942
+ }
943
+ if (settings.useFlex && module.is.ie()) {
944
+ module.debug('useFlex true is not supported in IE');
945
+ } else if (settings.useFlex && !settings.detachable) {
946
+ module.debug('useFlex true in combination with detachable false is not supported');
947
+ }
948
+
949
+ return settings.useFlex;
950
+ },
951
+ fit: function () {
952
+ var
953
+ contextHeight = module.cache.contextHeight,
954
+ verticalCenter = module.cache.contextHeight / 2,
955
+ topOffset = module.cache.topOffset,
956
+ scrollHeight = module.cache.scrollHeight,
957
+ height = module.cache.height,
958
+ paddingHeight = settings.padding,
959
+ startPosition = verticalCenter + topOffset
960
+ ;
961
+
962
+ return scrollHeight > height
963
+ ? startPosition + scrollHeight + paddingHeight < contextHeight
964
+ : height + (paddingHeight * 2) < contextHeight;
965
+ },
966
+ },
967
+ has: {
968
+ configActions: function () {
969
+ return Array.isArray(settings.actions) && settings.actions.length > 0;
970
+ },
971
+ scrollbar: function () {
972
+ return isBody || $context.css('overflow-y') !== 'hidden';
973
+ },
974
+ },
975
+ is: {
976
+ active: function () {
977
+ return $module.hasClass(className.active);
978
+ },
979
+ ie: function () {
980
+ if (module.cache.isIE === undefined) {
981
+ var
982
+ isIE11 = !window.ActiveXObject && 'ActiveXObject' in window,
983
+ isIE = 'ActiveXObject' in window
984
+ ;
985
+ module.cache.isIE = isIE11 || isIE;
986
+ }
987
+
988
+ return module.cache.isIE;
989
+ },
990
+ animating: function () {
991
+ return $module.transition('is supported')
992
+ ? $module.transition('is animating')
993
+ : $module.is(':visible');
994
+ },
995
+ scrolling: function () {
996
+ return $dimmable.hasClass(className.scrolling);
997
+ },
998
+ modernBrowser: function () {
999
+ // appName for IE11 reports 'Netscape' can no longer use
1000
+ return !(window.ActiveXObject || 'ActiveXObject' in window);
1001
+ },
1002
+ rtl: function () {
1003
+ if (module.cache.isRTL === undefined) {
1004
+ module.cache.isRTL = $module.attr('dir') === 'rtl' || $module.css('direction') === 'rtl' || $body.attr('dir') === 'rtl' || $body.css('direction') === 'rtl' || $context.attr('dir') === 'rtl' || $context.css('direction') === 'rtl';
1005
+ }
1006
+
1007
+ return module.cache.isRTL;
1008
+ },
1009
+ safari: function () {
1010
+ if (module.cache.isSafari === undefined) {
1011
+ module.cache.isSafari = /constructor/i.test(window.HTMLElement) || !!window.ApplePaySession;
1012
+ }
1013
+
1014
+ return module.cache.isSafari;
1015
+ },
1016
+ edge: function () {
1017
+ if (module.cache.isEdge === undefined) {
1018
+ module.cache.isEdge = !!window.setImmediate && !module.is.ie();
1019
+ }
1020
+
1021
+ return module.cache.isEdge;
1022
+ },
1023
+ firefox: function () {
1024
+ if (module.cache.isFirefox === undefined) {
1025
+ module.cache.isFirefox = !!window.InstallTrigger;
1026
+ }
1027
+
1028
+ return module.cache.isFirefox;
1029
+ },
1030
+ iframe: function () {
1031
+ return !(self === top);
1032
+ },
1033
+ },
1034
+
1035
+ set: {
1036
+ autofocus: function () {
1037
+ var
1038
+ $autofocus = $inputs.filter('[autofocus]'),
1039
+ $rawInputs = $inputs.filter(':input'),
1040
+ $input = $autofocus.length > 0
1041
+ ? $autofocus.first()
1042
+ : ($rawInputs.length > 0
1043
+ ? $rawInputs
1044
+ : $inputs.filter(':not(i.close)')
1045
+ ).first()
1046
+ ;
1047
+ // check if only the close icon is remaining
1048
+ if ($input.length === 0 && $inputs.length > 0) {
1049
+ $input = $inputs.first();
1050
+ }
1051
+ if ($input.length > 0) {
1052
+ $input.trigger('focus');
1053
+ }
1054
+ },
1055
+ bodyMargin: function () {
1056
+ var position = module.can.leftBodyScrollbar() ? 'left' : 'right';
1057
+ if (settings.detachable || module.can.fit()) {
1058
+ $context.css((isBody ? 'margin-' : 'padding-') + position, tempBodyMargin + 'px');
1059
+ }
1060
+ $context.find(selector.bodyFixed.replace('right', position)).each(function () {
1061
+ var
1062
+ el = $(this),
1063
+ attribute = el.css('position') === 'fixed' ? 'padding-' + position : position
1064
+ ;
1065
+ el.css(attribute, 'calc(' + el.css(attribute) + ' + ' + tempBodyMargin + 'px)');
1066
+ });
1067
+ },
1068
+ clickaway: function () {
1069
+ if (!settings.detachable) {
1070
+ $module
1071
+ .on('mousedown' + elementEventNamespace, module.event.mousedown)
1072
+ ;
1073
+ }
1074
+ $dimmer
1075
+ .on('mousedown' + elementEventNamespace, module.event.mousedown)
1076
+ ;
1077
+ $dimmer
1078
+ .on('mouseup' + elementEventNamespace, module.event.mouseup)
1079
+ ;
1080
+ },
1081
+ dimmerSettings: function () {
1082
+ if ($.fn.dimmer === undefined) {
1083
+ module.error(error.dimmer);
1084
+
1085
+ return;
1086
+ }
1087
+ var
1088
+ defaultSettings = {
1089
+ debug: settings.debug,
1090
+ dimmerName: 'modals',
1091
+ closable: 'auto',
1092
+ useFlex: module.can.useFlex(),
1093
+ duration: {
1094
+ show: settings.transition.showDuration || settings.duration,
1095
+ hide: settings.transition.hideDuration || settings.duration,
1096
+ },
1097
+ },
1098
+ dimmerSettings = $.extend(true, defaultSettings, settings.dimmerSettings)
1099
+ ;
1100
+ if (settings.inverted) {
1101
+ dimmerSettings.variation = dimmerSettings.variation !== undefined
1102
+ ? dimmerSettings.variation + ' inverted'
1103
+ : 'inverted';
1104
+ }
1105
+ $context.dimmer('setting', dimmerSettings);
1106
+ },
1107
+ dimmerStyles: function () {
1108
+ if (settings.inverted) {
1109
+ $dimmer.addClass(className.inverted);
1110
+ } else {
1111
+ $dimmer.removeClass(className.inverted);
1112
+ }
1113
+ if (settings.blurring) {
1114
+ $dimmable.addClass(className.blurring);
1115
+ } else {
1116
+ $dimmable.removeClass(className.blurring);
1117
+ }
1118
+ },
1119
+ modalOffset: function () {
1120
+ if (!settings.detachable) {
1121
+ var canFit = module.can.fit();
1122
+ $module
1123
+ .css({
1124
+ top: !$module.hasClass('aligned') && canFit
1125
+ ? $document.scrollTop() + (module.cache.contextHeight - module.cache.height) / 2
1126
+ : (!canFit || $module.hasClass('top')
1127
+ ? $document.scrollTop() + settings.padding
1128
+ : $document.scrollTop() + (module.cache.contextHeight - module.cache.height - settings.padding)),
1129
+ marginLeft: -(module.cache.width / 2),
1130
+ })
1131
+ ;
1132
+ } else {
1133
+ $module
1134
+ .css({
1135
+ marginTop: !$module.hasClass('aligned') && module.can.fit()
1136
+ ? -(module.cache.height / 2)
1137
+ : settings.padding / 2,
1138
+ marginLeft: -(module.cache.width / 2),
1139
+ })
1140
+ ;
1141
+ }
1142
+ module.verbose('Setting modal offset for legacy mode');
1143
+ },
1144
+ screenHeight: function () {
1145
+ if (module.can.fit()) {
1146
+ $context.css('height', '');
1147
+ } else if (!$module.hasClass('bottom')) {
1148
+ module.debug('Modal is taller than page content, resizing page height');
1149
+ $context
1150
+ .css('height', module.cache.height + (settings.padding * 2) + 'px')
1151
+ ;
1152
+ }
1153
+ },
1154
+ active: function () {
1155
+ $module.addClass(className.active + ' ' + className.front);
1156
+ $otherModals.filter('.' + className.active).removeClass(className.front);
1157
+ },
1158
+ scrolling: function () {
1159
+ $dimmable.addClass(className.scrolling);
1160
+ $module.addClass(className.scrolling);
1161
+ module.unbind.scrollLock();
1162
+ },
1163
+ legacy: function () {
1164
+ $module.addClass(className.legacy);
1165
+ },
1166
+ type: function () {
1167
+ if (module.can.fit()) {
1168
+ module.verbose('Modal fits on screen');
1169
+ if (!module.others.active() && !module.others.animating()) {
1170
+ module.remove.scrolling();
1171
+ module.bind.scrollLock();
1172
+ }
1173
+ } else if (!$module.hasClass('bottom')) {
1174
+ module.verbose('Modal cannot fit on screen setting to scrolling');
1175
+ module.set.scrolling();
1176
+ } else {
1177
+ module.verbose('Bottom aligned modal not fitting on screen is unsupported for scrolling');
1178
+ }
1179
+ },
1180
+ undetached: function () {
1181
+ $dimmable.addClass(className.undetached);
1182
+ },
1183
+ },
1184
+
1185
+ setting: function (name, value) {
1186
+ module.debug('Changing setting', name, value);
1187
+ if ($.isPlainObject(name)) {
1188
+ $.extend(true, settings, name);
1189
+ } else if (value !== undefined) {
1190
+ if ($.isPlainObject(settings[name])) {
1191
+ $.extend(true, settings[name], value);
1192
+ } else {
1193
+ settings[name] = value;
1194
+ }
1195
+ } else {
1196
+ return settings[name];
1197
+ }
1198
+ },
1199
+ internal: function (name, value) {
1200
+ if ($.isPlainObject(name)) {
1201
+ $.extend(true, module, name);
1202
+ } else if (value !== undefined) {
1203
+ module[name] = value;
1204
+ } else {
1205
+ return module[name];
1206
+ }
1207
+ },
1208
+ debug: function () {
1209
+ if (!settings.silent && settings.debug) {
1210
+ if (settings.performance) {
1211
+ module.performance.log(arguments);
1212
+ } else {
1213
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
1214
+ module.debug.apply(console, arguments);
1215
+ }
1216
+ }
1217
+ },
1218
+ verbose: function () {
1219
+ if (!settings.silent && settings.verbose && settings.debug) {
1220
+ if (settings.performance) {
1221
+ module.performance.log(arguments);
1222
+ } else {
1223
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
1224
+ module.verbose.apply(console, arguments);
1225
+ }
1226
+ }
1227
+ },
1228
+ error: function () {
1229
+ if (!settings.silent) {
1230
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
1231
+ module.error.apply(console, arguments);
1232
+ }
1233
+ },
1234
+ performance: {
1235
+ log: function (message) {
1236
+ var
1237
+ currentTime,
1238
+ executionTime,
1239
+ previousTime
1240
+ ;
1241
+ if (settings.performance) {
1242
+ currentTime = Date.now();
1243
+ previousTime = time || currentTime;
1244
+ executionTime = currentTime - previousTime;
1245
+ time = currentTime;
1246
+ performance.push({
1247
+ Name: message[0],
1248
+ Arguments: [].slice.call(message, 1) || '',
1249
+ Element: element,
1250
+ 'Execution Time': executionTime,
1251
+ });
1252
+ }
1253
+ clearTimeout(module.performance.timer);
1254
+ module.performance.timer = setTimeout(module.performance.display, 500);
1255
+ },
1256
+ display: function () {
1257
+ var
1258
+ title = settings.name + ':',
1259
+ totalTime = 0
1260
+ ;
1261
+ time = false;
1262
+ clearTimeout(module.performance.timer);
1263
+ $.each(performance, function (index, data) {
1264
+ totalTime += data['Execution Time'];
1265
+ });
1266
+ title += ' ' + totalTime + 'ms';
1267
+ if (moduleSelector) {
1268
+ title += ' \'' + moduleSelector + '\'';
1269
+ }
1270
+ if (performance.length > 0) {
1271
+ console.groupCollapsed(title);
1272
+ if (console.table) {
1273
+ console.table(performance);
1274
+ } else {
1275
+ $.each(performance, function (index, data) {
1276
+ console.log(data.Name + ': ' + data['Execution Time'] + 'ms');
1277
+ });
1278
+ }
1279
+ console.groupEnd();
1280
+ }
1281
+ performance = [];
1282
+ },
1283
+ },
1284
+ invoke: function (query, passedArguments, context) {
1285
+ var
1286
+ object = instance,
1287
+ maxDepth,
1288
+ found,
1289
+ response
1290
+ ;
1291
+ passedArguments = passedArguments || queryArguments;
1292
+ context = context || element;
1293
+ if (typeof query === 'string' && object !== undefined) {
1294
+ query = query.split(/[ .]/);
1295
+ maxDepth = query.length - 1;
1296
+ $.each(query, function (depth, value) {
1297
+ var camelCaseValue = depth !== maxDepth
1298
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
1299
+ : query;
1300
+ if ($.isPlainObject(object[camelCaseValue]) && (depth !== maxDepth)) {
1301
+ object = object[camelCaseValue];
1302
+ } else if (object[camelCaseValue] !== undefined) {
1303
+ found = object[camelCaseValue];
1304
+
1305
+ return false;
1306
+ } else if ($.isPlainObject(object[value]) && (depth !== maxDepth)) {
1307
+ object = object[value];
1308
+ } else if (object[value] !== undefined) {
1309
+ found = object[value];
1310
+
1311
+ return false;
1312
+ } else {
1313
+ module.error(error.method, query);
1314
+
1315
+ return false;
1316
+ }
1317
+ });
1318
+ }
1319
+ if (isFunction(found)) {
1320
+ response = found.apply(context, passedArguments);
1321
+ } else if (found !== undefined) {
1322
+ response = found;
1323
+ }
1324
+ if (Array.isArray(returnedValue)) {
1325
+ returnedValue.push(response);
1326
+ } else if (returnedValue !== undefined) {
1327
+ returnedValue = [returnedValue, response];
1328
+ } else if (response !== undefined) {
1329
+ returnedValue = response;
1330
+ }
1331
+
1332
+ return found;
1333
+ },
1334
+ };
1335
+
1336
+ if (methodInvoked) {
1337
+ if (instance === undefined) {
1338
+ if (isFunction(settings.templates[query])) {
1339
+ settings.autoShow = true;
1340
+ settings.className.modal = settings.className.template;
1341
+ settings = $.extend(true, {}, settings, settings.templates[query].apply(module, queryArguments));
1342
+
1343
+ // reassign shortcuts
1344
+ className = settings.className;
1345
+ namespace = settings.namespace;
1346
+ fields = settings.fields;
1347
+ error = settings.error;
1348
+ }
1349
+ module.initialize();
626
1350
  }
627
- });
628
- if(hideOk) {
629
- module.hideDimmer();
1351
+ if (!isFunction(settings.templates[query])) {
1352
+ module.invoke(query);
1353
+ }
1354
+ } else {
1355
+ if (instance !== undefined) {
1356
+ instance.invoke('destroy');
1357
+ }
1358
+ module.initialize();
1359
+ returnedValue = $module;
630
1360
  }
631
- return hideOk;
632
- }
633
- },
1361
+ });
634
1362
 
635
- hideOthers: function(callback) {
636
- var
637
- $visibleModals = $otherModals.filter('.' + className.active + ', .' + className.animating)
638
- ;
639
- callback = $.isFunction(callback)
640
- ? callback
641
- : function(){}
642
- ;
643
- if( $visibleModals.length > 0 ) {
644
- module.debug('Hiding other modals', $otherModals);
645
- $visibleModals
646
- .modal('hide modal', callback, true)
647
- ;
648
- }
1363
+ return returnedValue !== undefined
1364
+ ? returnedValue
1365
+ : this;
1366
+ };
1367
+ $.modal = $.fn.modal;
1368
+
1369
+ $.fn.modal.settings = {
1370
+
1371
+ name: 'Modal',
1372
+ namespace: 'modal',
1373
+
1374
+ useFlex: 'auto',
1375
+ offset: 0,
1376
+
1377
+ silent: false,
1378
+ debug: false,
1379
+ verbose: false,
1380
+ performance: true,
1381
+
1382
+ observeChanges: false,
1383
+
1384
+ allowMultiple: false,
1385
+ detachable: true,
1386
+ closable: true,
1387
+ autofocus: true,
1388
+ restoreFocus: true,
1389
+ autoShow: false,
1390
+
1391
+ inverted: false,
1392
+ blurring: false,
1393
+
1394
+ centered: true,
1395
+
1396
+ dimmerSettings: {
1397
+ closable: false,
1398
+ useCSS: true,
649
1399
  },
650
1400
 
651
- others: {
652
- active: function() {
653
- return ($otherModals.filter('.' + className.active).length > 0);
654
- },
655
- animating: function() {
656
- return ($otherModals.filter('.' + className.animating).length > 0);
657
- }
1401
+ // whether to use keyboard shortcuts
1402
+ keyboardShortcuts: true,
1403
+
1404
+ context: 'body',
1405
+
1406
+ queue: false,
1407
+ duration: 500,
1408
+ transition: 'scale',
1409
+
1410
+ // padding with edge of page
1411
+ padding: 50,
1412
+ scrollbarWidth: 10,
1413
+
1414
+ // dynamic content
1415
+ title: '',
1416
+ content: '',
1417
+ class: '',
1418
+ classTitle: '',
1419
+ classContent: '',
1420
+ classActions: '',
1421
+ closeIcon: false,
1422
+ actions: false,
1423
+ preserveHTML: true,
1424
+
1425
+ fields: {
1426
+ class: 'class',
1427
+ text: 'text',
1428
+ icon: 'icon',
1429
+ click: 'click',
658
1430
  },
659
1431
 
1432
+ // called before show animation
1433
+ onShow: function () {},
660
1434
 
661
- add: {
662
- keyboardShortcuts: function() {
663
- module.verbose('Adding keyboard shortcuts');
664
- $document
665
- .on('keyup' + eventNamespace, module.event.keyboard)
666
- ;
667
- }
1435
+ // called after show animation
1436
+ onVisible: function () {},
1437
+
1438
+ // called before hide animation
1439
+ onHide: function () {
1440
+ return true;
668
1441
  },
669
1442
 
670
- save: {
671
- focus: function() {
672
- var
673
- $activeElement = $(document.activeElement),
674
- inCurrentModal = $activeElement.closest($module).length > 0
675
- ;
676
- if(!inCurrentModal) {
677
- $focusedElement = $(document.activeElement).blur();
678
- }
679
- },
680
- bodyMargin: function() {
681
- initialBodyMargin = $body.css('margin-'+(module.can.leftBodyScrollbar() ? 'left':'right'));
682
- var bodyMarginRightPixel = parseInt(initialBodyMargin.replace(/[^\d.]/g, '')),
683
- bodyScrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
684
- tempBodyMargin = bodyMarginRightPixel + bodyScrollbarWidth;
685
- }
1443
+ // called after hide animation
1444
+ onHidden: false,
1445
+
1446
+ // called after approve selector match
1447
+ onApprove: function () {
1448
+ return true;
686
1449
  },
687
1450
 
688
- restore: {
689
- focus: function() {
690
- if($focusedElement && $focusedElement.length > 0 && settings.restoreFocus) {
691
- $focusedElement.focus();
692
- }
693
- },
694
- bodyMargin: function() {
695
- var position = module.can.leftBodyScrollbar() ? 'left':'right';
696
- $body.css('margin-'+position, initialBodyMargin);
697
- $body.find(selector.bodyFixed.replace('right',position)).each(function(){
698
- var el = $(this),
699
- attribute = el.css('position') === 'fixed' ? 'padding-'+position : position
700
- ;
701
- el.css(attribute, '');
702
- });
703
- }
1451
+ // called after deny selector match
1452
+ onDeny: function () {
1453
+ return true;
704
1454
  },
705
1455
 
706
- remove: {
707
- active: function() {
708
- $module.removeClass(className.active);
709
- },
710
- legacy: function() {
711
- $module.removeClass(className.legacy);
712
- },
713
- clickaway: function() {
714
- if (!settings.detachable) {
715
- $module
716
- .off('mousedown' + elementEventNamespace)
717
- ;
718
- }
719
- $dimmer
720
- .off('mousedown' + elementEventNamespace)
721
- ;
722
- $dimmer
723
- .off('mouseup' + elementEventNamespace)
724
- ;
725
- },
726
- dimmerStyles: function() {
727
- $dimmer.removeClass(className.inverted);
728
- $dimmable.removeClass(className.blurring);
729
- },
730
- bodyStyle: function() {
731
- if($body.attr('style') === '') {
732
- module.verbose('Removing style attribute');
733
- $body.removeAttr('style');
734
- }
735
- },
736
- screenHeight: function() {
737
- module.debug('Removing page height');
738
- $body
739
- .css('height', '')
740
- ;
741
- },
742
- keyboardShortcuts: function() {
743
- module.verbose('Removing keyboard shortcuts');
744
- $document
745
- .off('keyup' + eventNamespace)
746
- ;
747
- },
748
- scrolling: function() {
749
- $dimmable.removeClass(className.scrolling);
750
- $module.removeClass(className.scrolling);
751
- }
1456
+ keys: {
1457
+ space: 32,
1458
+ enter: 13,
1459
+ escape: 27,
1460
+ tab: 9,
752
1461
  },
753
1462
 
754
- cacheSizes: function() {
755
- $module.addClass(className.loading);
756
- var
757
- scrollHeight = $module.prop('scrollHeight'),
758
- modalWidth = $module.outerWidth(),
759
- modalHeight = $module.outerHeight()
760
- ;
761
- if(module.cache.pageHeight === undefined || modalHeight !== 0) {
762
- $.extend(module.cache, {
763
- pageHeight : $(document).outerHeight(),
764
- width : modalWidth,
765
- height : modalHeight + settings.offset,
766
- scrollHeight : scrollHeight + settings.offset,
767
- contextHeight : (settings.context == 'body')
768
- ? $(window).height()
769
- : $dimmable.height(),
770
- });
771
- module.cache.topOffset = -(module.cache.height / 2);
772
- }
773
- $module.removeClass(className.loading);
774
- module.debug('Caching modal and container sizes', module.cache);
1463
+ selector: {
1464
+ title: '> .header',
1465
+ content: '> .content',
1466
+ actions: '> .actions',
1467
+ close: '> .close',
1468
+ closeIcon: '> .close',
1469
+ approve: '.actions .positive, .actions .approve, .actions .ok',
1470
+ deny: '.actions .negative, .actions .deny, .actions .cancel',
1471
+ modal: '.ui.modal',
1472
+ dimmer: '> .ui.dimmer',
1473
+ bodyFixed: '> .ui.fixed.menu, > .ui.right.toast-container, > .ui.right.sidebar, > .ui.fixed.nag, > .ui.fixed.nag > .close',
1474
+ prompt: '.ui.input > input',
775
1475
  },
776
- helpers: {
777
- deQuote: function(string) {
778
- return String(string).replace(/"/g,"");
779
- },
780
- escape: function(string, preserveHTML) {
781
- if (preserveHTML){
782
- return string;
783
- }
784
- var
785
- badChars = /[<>"'`]/g,
786
- shouldEscape = /[&<>"'`]/,
787
- escape = {
788
- "<": "&lt;",
789
- ">": "&gt;",
790
- '"': "&quot;",
791
- "'": "&#x27;",
792
- "`": "&#x60;"
793
- },
794
- escapedChar = function(chr) {
795
- return escape[chr];
796
- }
797
- ;
798
- if(shouldEscape.test(string)) {
799
- string = string.replace(/&(?![a-z0-9#]{1,6};)/, "&amp;");
800
- return string.replace(badChars, escapedChar);
801
- }
802
- return string;
803
- }
1476
+ error: {
1477
+ dimmer: 'UI Dimmer, a required component is not included in this page',
1478
+ method: 'The method you called is not defined.',
1479
+ notFound: 'The element you specified could not be found',
804
1480
  },
805
- can: {
806
- leftBodyScrollbar: function(){
807
- if(module.cache.leftBodyScrollbar === undefined) {
808
- module.cache.leftBodyScrollbar = module.is.rtl() && ((module.is.iframe && !module.is.firefox()) || module.is.safari() || module.is.edge() || module.is.ie());
809
- }
810
- return module.cache.leftBodyScrollbar;
811
- },
812
- useFlex: function() {
813
- if (settings.useFlex === 'auto') {
814
- return settings.detachable && !module.is.ie();
815
- }
816
- if(settings.useFlex && module.is.ie()) {
817
- module.debug('useFlex true is not supported in IE');
818
- } else if(settings.useFlex && !settings.detachable) {
819
- module.debug('useFlex true in combination with detachable false is not supported');
820
- }
821
- return settings.useFlex;
822
- },
823
- fit: function() {
824
- var
825
- contextHeight = module.cache.contextHeight,
826
- verticalCenter = module.cache.contextHeight / 2,
827
- topOffset = module.cache.topOffset,
828
- scrollHeight = module.cache.scrollHeight,
829
- height = module.cache.height,
830
- paddingHeight = settings.padding,
831
- startPosition = (verticalCenter + topOffset)
832
- ;
833
- return (scrollHeight > height)
834
- ? (startPosition + scrollHeight + paddingHeight < contextHeight)
835
- : (height + (paddingHeight * 2) < contextHeight)
836
- ;
837
- }
1481
+ className: {
1482
+ active: 'active',
1483
+ animating: 'animating',
1484
+ blurring: 'blurring',
1485
+ inverted: 'inverted',
1486
+ legacy: 'legacy',
1487
+ loading: 'loading',
1488
+ scrolling: 'scrolling',
1489
+ undetached: 'undetached',
1490
+ front: 'front',
1491
+ close: 'close icon',
1492
+ button: 'ui button',
1493
+ modal: 'ui modal',
1494
+ title: 'header',
1495
+ content: 'content',
1496
+ actions: 'actions',
1497
+ template: 'ui tiny modal',
1498
+ ok: 'positive',
1499
+ cancel: 'negative',
1500
+ prompt: 'ui fluid input',
1501
+ innerDimmer: 'ui inverted dimmer',
838
1502
  },
839
- has: {
840
- configActions: function () {
841
- return Array.isArray(settings.actions) && settings.actions.length > 0;
842
- }
1503
+ text: {
1504
+ ok: 'Ok',
1505
+ cancel: 'Cancel',
1506
+ close: 'Close',
843
1507
  },
844
- is: {
845
- active: function() {
846
- return $module.hasClass(className.active);
847
- },
848
- ie: function() {
849
- if(module.cache.isIE === undefined) {
850
- var
851
- isIE11 = (!(window.ActiveXObject) && 'ActiveXObject' in window),
852
- isIE = ('ActiveXObject' in window)
853
- ;
854
- module.cache.isIE = (isIE11 || isIE);
855
- }
856
- return module.cache.isIE;
857
- },
858
- animating: function() {
859
- return $module.transition('is supported')
860
- ? $module.transition('is animating')
861
- : $module.is(':visible')
862
- ;
863
- },
864
- scrolling: function() {
865
- return $dimmable.hasClass(className.scrolling);
866
- },
867
- modernBrowser: function() {
868
- // appName for IE11 reports 'Netscape' can no longer use
869
- return !(window.ActiveXObject || 'ActiveXObject' in window);
870
- },
871
- rtl: function() {
872
- if(module.cache.isRTL === undefined) {
873
- module.cache.isRTL = $body.attr('dir') === 'rtl' || $body.css('direction') === 'rtl';
874
- }
875
- return module.cache.isRTL;
876
- },
877
- safari: function() {
878
- if(module.cache.isSafari === undefined) {
879
- module.cache.isSafari = /constructor/i.test(window.HTMLElement) || !!window.ApplePaySession;
880
- }
881
- return module.cache.isSafari;
882
- },
883
- edge: function(){
884
- if(module.cache.isEdge === undefined) {
885
- module.cache.isEdge = !!window.setImmediate && !module.is.ie();
886
- }
887
- return module.cache.isEdge;
888
- },
889
- firefox: function(){
890
- if(module.cache.isFirefox === undefined) {
891
- module.cache.isFirefox = !!window.InstallTrigger;
892
- }
893
- return module.cache.isFirefox;
894
- },
895
- iframe: function() {
896
- return !(self === top);
897
- }
1508
+ };
1509
+
1510
+ $.fn.modal.settings.templates = {
1511
+ getArguments: function (args) {
1512
+ var queryArguments = [].slice.call(args);
1513
+ if ($.isPlainObject(queryArguments[0])) {
1514
+ return $.extend({
1515
+ handler: function () {},
1516
+ content: '',
1517
+ title: '',
1518
+ }, queryArguments[0]);
1519
+ }
1520
+ if (!isFunction(queryArguments[queryArguments.length - 1])) {
1521
+ queryArguments.push(function () {});
1522
+ }
1523
+
1524
+ return {
1525
+ handler: queryArguments.pop(),
1526
+ content: queryArguments.pop() || '',
1527
+ title: queryArguments.pop() || '',
1528
+ };
898
1529
  },
899
-
900
- set: {
901
- autofocus: function() {
1530
+ alert: function () {
902
1531
  var
903
- $inputs = $module.find('[tabindex], :input').filter(':visible').filter(function() {
904
- return $(this).closest('.disabled').length === 0;
905
- }),
906
- $autofocus = $inputs.filter('[autofocus]'),
907
- $input = ($autofocus.length > 0)
908
- ? $autofocus.first()
909
- : $inputs.first()
1532
+ settings = this.get.settings(),
1533
+ args = settings.templates.getArguments(arguments),
1534
+ approveFn = args.handler
910
1535
  ;
911
- if($input.length > 0) {
912
- $input.focus();
913
- }
914
- },
915
- bodyMargin: function() {
916
- var position = module.can.leftBodyScrollbar() ? 'left':'right';
917
- if(settings.detachable || module.can.fit()) {
918
- $body.css('margin-'+position, tempBodyMargin + 'px');
919
- }
920
- $body.find(selector.bodyFixed.replace('right',position)).each(function(){
921
- var el = $(this),
922
- attribute = el.css('position') === 'fixed' ? 'padding-'+position : position
923
- ;
924
- el.css(attribute, 'calc(' + el.css(attribute) + ' + ' + tempBodyMargin + 'px)');
925
- });
926
- },
927
- clickaway: function() {
928
- if (!settings.detachable) {
929
- $module
930
- .on('mousedown' + elementEventNamespace, module.event.mousedown)
931
- ;
932
- }
933
- $dimmer
934
- .on('mousedown' + elementEventNamespace, module.event.mousedown)
935
- ;
936
- $dimmer
937
- .on('mouseup' + elementEventNamespace, module.event.mouseup)
938
- ;
939
- },
940
- dimmerSettings: function() {
941
- if($.fn.dimmer === undefined) {
942
- module.error(error.dimmer);
943
- return;
944
- }
1536
+
1537
+ return {
1538
+ title: args.title,
1539
+ content: args.content,
1540
+ onApprove: approveFn,
1541
+ actions: [{
1542
+ text: settings.text.ok,
1543
+ class: settings.className.ok,
1544
+ click: approveFn,
1545
+ }],
1546
+ };
1547
+ },
1548
+ confirm: function () {
945
1549
  var
946
- defaultSettings = {
947
- debug : settings.debug,
948
- dimmerName : 'modals',
949
- closable : 'auto',
950
- useFlex : module.can.useFlex(),
951
- duration : {
952
- show : settings.transition.showDuration || settings.duration,
953
- hide : settings.transition.hideDuration || settings.duration
1550
+ settings = this.get.settings(),
1551
+ args = settings.templates.getArguments(arguments),
1552
+ approveFn = function () {
1553
+ args.handler(true);
1554
+ },
1555
+ denyFn = function () {
1556
+ args.handler(false);
954
1557
  }
955
- },
956
- dimmerSettings = $.extend(true, defaultSettings, settings.dimmerSettings)
957
1558
  ;
958
- if(settings.inverted) {
959
- dimmerSettings.variation = (dimmerSettings.variation !== undefined)
960
- ? dimmerSettings.variation + ' inverted'
961
- : 'inverted'
962
- ;
963
- }
964
- $context.dimmer('setting', dimmerSettings);
965
- },
966
- dimmerStyles: function() {
967
- if(settings.inverted) {
968
- $dimmer.addClass(className.inverted);
969
- }
970
- else {
971
- $dimmer.removeClass(className.inverted);
972
- }
973
- if(settings.blurring) {
974
- $dimmable.addClass(className.blurring);
975
- }
976
- else {
977
- $dimmable.removeClass(className.blurring);
978
- }
979
- },
980
- modalOffset: function() {
981
- if (!settings.detachable) {
982
- var canFit = module.can.fit();
983
- $module
984
- .css({
985
- top: (!$module.hasClass('aligned') && canFit)
986
- ? $(document).scrollTop() + (module.cache.contextHeight - module.cache.height) / 2
987
- : !canFit || $module.hasClass('top')
988
- ? $(document).scrollTop() + settings.padding
989
- : $(document).scrollTop() + (module.cache.contextHeight - module.cache.height - settings.padding),
990
- marginLeft: -(module.cache.width / 2)
991
- })
992
- ;
993
- } else {
994
- $module
995
- .css({
996
- marginTop: (!$module.hasClass('aligned') && module.can.fit())
997
- ? -(module.cache.height / 2)
998
- : settings.padding / 2,
999
- marginLeft: -(module.cache.width / 2)
1000
- })
1001
- ;
1002
- }
1003
- module.verbose('Setting modal offset for legacy mode');
1004
- },
1005
- screenHeight: function() {
1006
- if( module.can.fit() ) {
1007
- $body.css('height', '');
1008
- }
1009
- else if(!$module.hasClass('bottom')) {
1010
- module.debug('Modal is taller than page content, resizing page height');
1011
- $body
1012
- .css('height', module.cache.height + (settings.padding * 2) )
1013
- ;
1014
- }
1015
- },
1016
- active: function() {
1017
- $module.addClass(className.active + ' ' + className.front);
1018
- $otherModals.filter('.' + className.active).removeClass(className.front);
1019
- },
1020
- scrolling: function() {
1021
- $dimmable.addClass(className.scrolling);
1022
- $module.addClass(className.scrolling);
1023
- module.unbind.scrollLock();
1024
- },
1025
- legacy: function() {
1026
- $module.addClass(className.legacy);
1027
- },
1028
- type: function() {
1029
- if(module.can.fit()) {
1030
- module.verbose('Modal fits on screen');
1031
- if(!module.others.active() && !module.others.animating()) {
1032
- module.remove.scrolling();
1033
- module.bind.scrollLock();
1034
- }
1035
- }
1036
- else if (!$module.hasClass('bottom')){
1037
- module.verbose('Modal cannot fit on screen setting to scrolling');
1038
- module.set.scrolling();
1039
- } else {
1040
- module.verbose('Bottom aligned modal not fitting on screen is unsupported for scrolling');
1041
- }
1042
- },
1043
- undetached: function() {
1044
- $dimmable.addClass(className.undetached);
1045
- }
1046
- },
1047
1559
 
1048
- setting: function(name, value) {
1049
- module.debug('Changing setting', name, value);
1050
- if( $.isPlainObject(name) ) {
1051
- $.extend(true, settings, name);
1052
- }
1053
- else if(value !== undefined) {
1054
- if($.isPlainObject(settings[name])) {
1055
- $.extend(true, settings[name], value);
1056
- }
1057
- else {
1058
- settings[name] = value;
1059
- }
1060
- }
1061
- else {
1062
- return settings[name];
1063
- }
1064
- },
1065
- internal: function(name, value) {
1066
- if( $.isPlainObject(name) ) {
1067
- $.extend(true, module, name);
1068
- }
1069
- else if(value !== undefined) {
1070
- module[name] = value;
1071
- }
1072
- else {
1073
- return module[name];
1074
- }
1075
- },
1076
- debug: function() {
1077
- if(!settings.silent && settings.debug) {
1078
- if(settings.performance) {
1079
- module.performance.log(arguments);
1080
- }
1081
- else {
1082
- module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
1083
- module.debug.apply(console, arguments);
1084
- }
1085
- }
1086
- },
1087
- verbose: function() {
1088
- if(!settings.silent && settings.verbose && settings.debug) {
1089
- if(settings.performance) {
1090
- module.performance.log(arguments);
1091
- }
1092
- else {
1093
- module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
1094
- module.verbose.apply(console, arguments);
1095
- }
1096
- }
1097
- },
1098
- error: function() {
1099
- if(!settings.silent) {
1100
- module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
1101
- module.error.apply(console, arguments);
1102
- }
1560
+ return {
1561
+ title: args.title,
1562
+ content: args.content,
1563
+ onApprove: approveFn,
1564
+ onDeny: denyFn,
1565
+ actions: [{
1566
+ text: settings.text.ok,
1567
+ class: settings.className.ok,
1568
+ click: approveFn,
1569
+ }, {
1570
+ text: settings.text.cancel,
1571
+ class: settings.className.cancel,
1572
+ click: denyFn,
1573
+ }],
1574
+ };
1103
1575
  },
1104
- performance: {
1105
- log: function(message) {
1106
- var
1107
- currentTime,
1108
- executionTime,
1109
- previousTime
1110
- ;
1111
- if(settings.performance) {
1112
- currentTime = new Date().getTime();
1113
- previousTime = time || currentTime;
1114
- executionTime = currentTime - previousTime;
1115
- time = currentTime;
1116
- performance.push({
1117
- 'Name' : message[0],
1118
- 'Arguments' : [].slice.call(message, 1) || '',
1119
- 'Element' : element,
1120
- 'Execution Time' : executionTime
1121
- });
1122
- }
1123
- clearTimeout(module.performance.timer);
1124
- module.performance.timer = setTimeout(module.performance.display, 500);
1125
- },
1126
- display: function() {
1576
+ prompt: function () {
1127
1577
  var
1128
- title = settings.name + ':',
1129
- totalTime = 0
1578
+ $this = this,
1579
+ settings = this.get.settings(),
1580
+ args = settings.templates.getArguments(arguments),
1581
+ input = $($.parseHTML(args.content)).filter('.ui.input'),
1582
+ approveFn = function () {
1583
+ var
1584
+ settings = $this.get.settings(),
1585
+ inputField = $this.get.element().find(settings.selector.prompt)[0]
1586
+ ;
1587
+ args.handler($(inputField).val());
1588
+ },
1589
+ denyFn = function () {
1590
+ args.handler(null);
1591
+ }
1130
1592
  ;
1131
- time = false;
1132
- clearTimeout(module.performance.timer);
1133
- $.each(performance, function(index, data) {
1134
- totalTime += data['Execution Time'];
1135
- });
1136
- title += ' ' + totalTime + 'ms';
1137
- if(moduleSelector) {
1138
- title += ' \'' + moduleSelector + '\'';
1139
- }
1140
- if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
1141
- console.groupCollapsed(title);
1142
- if(console.table) {
1143
- console.table(performance);
1144
- }
1145
- else {
1146
- $.each(performance, function(index, data) {
1147
- console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
1148
- });
1149
- }
1150
- console.groupEnd();
1151
- }
1152
- performance = [];
1153
- }
1593
+ if (input.length === 0) {
1594
+ args.content += '<p><div class="' + this.helpers.deQuote(settings.className.prompt) + '"><input placeholder="' + this.helpers.deQuote(args.placeholder || '') + '" type="text" value="' + this.helpers.deQuote(args.defaultValue || '') + '"></div></p>';
1595
+ }
1596
+
1597
+ return {
1598
+ title: args.title,
1599
+ content: args.content,
1600
+ onApprove: approveFn,
1601
+ onDeny: denyFn,
1602
+ actions: [{
1603
+ text: settings.text.ok,
1604
+ class: settings.className.ok,
1605
+ click: approveFn,
1606
+ }, {
1607
+ text: settings.text.cancel,
1608
+ class: settings.className.cancel,
1609
+ click: denyFn,
1610
+ }],
1611
+ };
1154
1612
  },
1155
- invoke: function(query, passedArguments, context) {
1156
- var
1157
- object = instance,
1158
- maxDepth,
1159
- found,
1160
- response
1161
- ;
1162
- passedArguments = passedArguments || queryArguments;
1163
- context = element || context;
1164
- if(typeof query == 'string' && object !== undefined) {
1165
- query = query.split(/[\. ]/);
1166
- maxDepth = query.length - 1;
1167
- $.each(query, function(depth, value) {
1168
- var camelCaseValue = (depth != maxDepth)
1169
- ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
1170
- : query
1171
- ;
1172
- if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
1173
- object = object[camelCaseValue];
1174
- }
1175
- else if( object[camelCaseValue] !== undefined ) {
1176
- found = object[camelCaseValue];
1177
- return false;
1178
- }
1179
- else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
1180
- object = object[value];
1181
- }
1182
- else if( object[value] !== undefined ) {
1183
- found = object[value];
1184
- return false;
1185
- }
1186
- else {
1187
- return false;
1188
- }
1189
- });
1190
- }
1191
- if ( $.isFunction( found ) ) {
1192
- response = found.apply(context, passedArguments);
1193
- }
1194
- else if(found !== undefined) {
1195
- response = found;
1196
- }
1197
- if(Array.isArray(returnedValue)) {
1198
- returnedValue.push(response);
1199
- }
1200
- else if(returnedValue !== undefined) {
1201
- returnedValue = [returnedValue, response];
1202
- }
1203
- else if(response !== undefined) {
1204
- returnedValue = response;
1205
- }
1206
- return found;
1207
- }
1208
- };
1209
-
1210
- if(methodInvoked) {
1211
- if(instance === undefined) {
1212
- if ($.isFunction(settings.templates[query])) {
1213
- settings.autoShow = true;
1214
- settings.className.modal = settings.className.template;
1215
- settings = $.extend(true, {}, settings, settings.templates[query].apply(module ,queryArguments));
1216
-
1217
- // reassign shortcuts
1218
- className = settings.className;
1219
- namespace = settings.namespace;
1220
- fields = settings.fields;
1221
- error = settings.error;
1222
- }
1223
- module.initialize();
1224
- }
1225
- if (!$.isFunction(settings.templates[query])) {
1226
- module.invoke(query);
1227
- }
1228
- }
1229
- else {
1230
- if(instance !== undefined) {
1231
- instance.invoke('destroy');
1232
- }
1233
- module.initialize();
1234
- returnedValue = $module;
1235
- }
1236
- })
1237
- ;
1238
-
1239
- return (returnedValue !== undefined)
1240
- ? returnedValue
1241
- : this
1242
- ;
1243
- };
1244
-
1245
- $.fn.modal.settings = {
1246
-
1247
- name : 'Modal',
1248
- namespace : 'modal',
1249
-
1250
- useFlex : 'auto',
1251
- offset : 0,
1252
-
1253
- silent : false,
1254
- debug : false,
1255
- verbose : false,
1256
- performance : true,
1257
-
1258
- observeChanges : false,
1259
-
1260
- allowMultiple : false,
1261
- detachable : true,
1262
- closable : true,
1263
- autofocus : true,
1264
- restoreFocus : true,
1265
- autoShow : false,
1266
-
1267
- inverted : false,
1268
- blurring : false,
1269
-
1270
- centered : true,
1271
-
1272
- dimmerSettings : {
1273
- closable : false,
1274
- useCSS : true
1275
- },
1276
-
1277
- // whether to use keyboard shortcuts
1278
- keyboardShortcuts: true,
1279
-
1280
- context : 'body',
1281
-
1282
- queue : false,
1283
- duration : 500,
1284
- transition : 'scale',
1285
-
1286
- // padding with edge of page
1287
- padding : 50,
1288
- scrollbarWidth: 10,
1289
-
1290
- //dynamic content
1291
- title : '',
1292
- content : '',
1293
- class : '',
1294
- classTitle : '',
1295
- classContent : '',
1296
- classActions : '',
1297
- closeIcon : false,
1298
- actions : false,
1299
- preserveHTML : true,
1300
-
1301
- fields : {
1302
- class : 'class',
1303
- text : 'text',
1304
- icon : 'icon',
1305
- click : 'click'
1306
- },
1307
-
1308
- // called before show animation
1309
- onShow : function(){},
1310
-
1311
- // called after show animation
1312
- onVisible : function(){},
1313
-
1314
- // called before hide animation
1315
- onHide : function(){ return true; },
1316
-
1317
- // called after hide animation
1318
- onHidden : false,
1319
-
1320
- // called after approve selector match
1321
- onApprove : function(){ return true; },
1322
-
1323
- // called after deny selector match
1324
- onDeny : function(){ return true; },
1325
-
1326
- selector : {
1327
- title : '> .header',
1328
- content : '> .content',
1329
- actions : '> .actions',
1330
- close : '> .close',
1331
- approve : '.actions .positive, .actions .approve, .actions .ok',
1332
- deny : '.actions .negative, .actions .deny, .actions .cancel',
1333
- modal : '.ui.modal',
1334
- dimmer : '> .ui.dimmer',
1335
- bodyFixed: '> .ui.fixed.menu, > .ui.right.toast-container, > .ui.right.sidebar, > .ui.fixed.nag, > .ui.fixed.nag > .close',
1336
- prompt : '.ui.input > input'
1337
- },
1338
- error : {
1339
- dimmer : 'UI Dimmer, a required component is not included in this page',
1340
- method : 'The method you called is not defined.',
1341
- notFound : 'The element you specified could not be found'
1342
- },
1343
- className : {
1344
- active : 'active',
1345
- animating : 'animating',
1346
- blurring : 'blurring',
1347
- inverted : 'inverted',
1348
- legacy : 'legacy',
1349
- loading : 'loading',
1350
- scrolling : 'scrolling',
1351
- undetached : 'undetached',
1352
- front : 'front',
1353
- close : 'close icon',
1354
- button : 'ui button',
1355
- modal : 'ui modal',
1356
- title : 'header',
1357
- content : 'content',
1358
- actions : 'actions',
1359
- template : 'ui tiny modal',
1360
- ok : 'positive',
1361
- cancel : 'negative',
1362
- prompt : 'ui fluid input'
1363
- },
1364
- text: {
1365
- ok : 'Ok',
1366
- cancel: 'Cancel'
1367
- }
1368
- };
1369
-
1370
- $.fn.modal.settings.templates = {
1371
- getArguments: function(args) {
1372
- var queryArguments = [].slice.call(args);
1373
- if($.isPlainObject(queryArguments[0])){
1374
- return $.extend({
1375
- handler:function(){},
1376
- content:'',
1377
- title: ''
1378
- }, queryArguments[0]);
1379
- } else {
1380
- if(!$.isFunction(queryArguments[queryArguments.length-1])) {
1381
- queryArguments.push(function() {});
1382
- }
1383
- return {
1384
- handler: queryArguments.pop(),
1385
- content: queryArguments.pop() || '',
1386
- title: queryArguments.pop() || ''
1387
- };
1388
- }
1389
- },
1390
- alert: function () {
1391
- var settings = this.get.settings(),
1392
- args = settings.templates.getArguments(arguments)
1393
- ;
1394
- return {
1395
- title : args.title,
1396
- content: args.content,
1397
- actions: [{
1398
- text : settings.text.ok,
1399
- class: settings.className.ok,
1400
- click: args.handler
1401
- }]
1402
- }
1403
- },
1404
- confirm: function () {
1405
- var settings = this.get.settings(),
1406
- args = settings.templates.getArguments(arguments)
1407
- ;
1408
- return {
1409
- title : args.title,
1410
- content: args.content,
1411
- actions: [{
1412
- text : settings.text.ok,
1413
- class: settings.className.ok,
1414
- click: function(){args.handler(true)}
1415
- },{
1416
- text: settings.text.cancel,
1417
- class: settings.className.cancel,
1418
- click: function(){args.handler(false)}
1419
- }]
1420
- }
1421
- },
1422
- prompt: function () {
1423
- var $this = this,
1424
- settings = this.get.settings(),
1425
- args = settings.templates.getArguments(arguments),
1426
- input = $($.parseHTML(args.content)).filter('.ui.input')
1427
- ;
1428
- if (input.length === 0) {
1429
- 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>';
1430
- }
1431
- return {
1432
- title : args.title,
1433
- content: args.content,
1434
- actions: [{
1435
- text: settings.text.ok,
1436
- class: settings.className.ok,
1437
- click: function(){
1438
- var settings = $this.get.settings(),
1439
- inputField = $this.get.element().find(settings.selector.prompt)[0]
1440
- ;
1441
- args.handler($(inputField).val());
1442
- }
1443
- },{
1444
- text: settings.text.cancel,
1445
- class: settings.className.cancel,
1446
- click: function(){args.handler(null)}
1447
- }]
1448
- }
1449
- }
1450
- }
1451
-
1452
- })( jQuery, window, document );
1613
+ };
1614
+ })(jQuery, window, document);