fomantic-ui-sass 2.9.0 → 2.9.2

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