@ntlab/ntjs-assets 2.0.2 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/assets/js/bootstrap-icons/bootstrap-icons.svg +1 -1
  2. package/assets/js/bootstrap-icons/folder-plus.svg +2 -2
  3. package/assets/js/bootstrap-icons/font/bootstrap-icons.css +1981 -0
  4. package/assets/js/bootstrap-icons/font/bootstrap-icons.json +1955 -0
  5. package/assets/js/bootstrap-icons/font/bootstrap-icons.min.css +5 -0
  6. package/assets/js/bootstrap-icons/font/bootstrap-icons.scss +1993 -0
  7. package/assets/js/bootstrap-icons/font/fonts/bootstrap-icons.woff +0 -0
  8. package/assets/js/bootstrap-icons/font/fonts/bootstrap-icons.woff2 +0 -0
  9. package/assets/js/bootstrap-icons/postcard-heart-fill.svg +1 -1
  10. package/assets/js/bootstrap-icons/trash.svg +2 -2
  11. package/assets/js/jquery/jquery.js +840 -1045
  12. package/assets/js/jquery/jquery.min.js +2 -2
  13. package/assets/js/jquery/jquery.min.map +1 -1
  14. package/assets/js/jquery/jquery.slim.js +834 -1039
  15. package/assets/js/jquery/jquery.slim.min.js +2 -2
  16. package/assets/js/jquery/jquery.slim.min.map +1 -1
  17. package/assets/js/popper.js/cjs/enums.js +1 -1
  18. package/assets/js/popper.js/cjs/popper-base.js +12 -170
  19. package/assets/js/popper.js/cjs/popper-base.js.map +1 -1
  20. package/assets/js/popper.js/cjs/popper-lite.js +14 -184
  21. package/assets/js/popper.js/cjs/popper-lite.js.map +1 -1
  22. package/assets/js/popper.js/cjs/popper.js +14 -197
  23. package/assets/js/popper.js/cjs/popper.js.map +1 -1
  24. package/assets/js/popper.js/esm/createPopper.js +6 -66
  25. package/assets/js/popper.js/esm/modifiers/arrow.js +1 -12
  26. package/assets/js/popper.js/esm/modifiers/computeStyles.js +2 -14
  27. package/assets/js/popper.js/esm/utils/computeAutoPlacement.js +0 -4
  28. package/assets/js/popper.js/esm/utils/userAgent.js +1 -1
  29. package/assets/js/popper.js/umd/enums.js +1 -1
  30. package/assets/js/popper.js/umd/enums.min.js +1 -1
  31. package/assets/js/popper.js/umd/popper-base.js +12 -170
  32. package/assets/js/popper.js/umd/popper-base.js.map +1 -1
  33. package/assets/js/popper.js/umd/popper-base.min.js +2 -2
  34. package/assets/js/popper.js/umd/popper-base.min.js.map +1 -1
  35. package/assets/js/popper.js/umd/popper-lite.js +14 -184
  36. package/assets/js/popper.js/umd/popper-lite.js.map +1 -1
  37. package/assets/js/popper.js/umd/popper-lite.min.js +2 -2
  38. package/assets/js/popper.js/umd/popper-lite.min.js.map +1 -1
  39. package/assets/js/popper.js/umd/popper.js +14 -197
  40. package/assets/js/popper.js/umd/popper.js.map +1 -1
  41. package/assets/js/popper.js/umd/popper.min.js +2 -2
  42. package/assets/js/popper.js/umd/popper.min.js.map +1 -1
  43. package/assets/js/semantic-ui/components/accordion.css +196 -74
  44. package/assets/js/semantic-ui/components/accordion.js +570 -591
  45. package/assets/js/semantic-ui/components/accordion.min.css +4 -4
  46. package/assets/js/semantic-ui/components/accordion.min.js +6 -6
  47. package/assets/js/semantic-ui/components/ad.css +40 -51
  48. package/assets/js/semantic-ui/components/ad.min.css +4 -4
  49. package/assets/js/semantic-ui/components/api.js +1154 -1117
  50. package/assets/js/semantic-ui/components/api.min.js +6 -6
  51. package/assets/js/semantic-ui/components/breadcrumb.css +7 -7
  52. package/assets/js/semantic-ui/components/breadcrumb.min.css +4 -4
  53. package/assets/js/semantic-ui/components/button.css +895 -1227
  54. package/assets/js/semantic-ui/components/button.min.css +4 -4
  55. package/assets/js/semantic-ui/components/calendar.css +60 -33
  56. package/assets/js/semantic-ui/components/calendar.js +1952 -1575
  57. package/assets/js/semantic-ui/components/calendar.min.css +4 -4
  58. package/assets/js/semantic-ui/components/calendar.min.js +6 -6
  59. package/assets/js/semantic-ui/components/card.css +1004 -441
  60. package/assets/js/semantic-ui/components/card.min.css +4 -4
  61. package/assets/js/semantic-ui/components/checkbox.css +275 -303
  62. package/assets/js/semantic-ui/components/checkbox.js +863 -855
  63. package/assets/js/semantic-ui/components/checkbox.min.css +4 -4
  64. package/assets/js/semantic-ui/components/checkbox.min.js +6 -6
  65. package/assets/js/semantic-ui/components/comment.css +45 -63
  66. package/assets/js/semantic-ui/components/comment.min.css +4 -4
  67. package/assets/js/semantic-ui/components/container.css +98 -4
  68. package/assets/js/semantic-ui/components/container.min.css +4 -4
  69. package/assets/js/semantic-ui/components/dimmer.css +95 -196
  70. package/assets/js/semantic-ui/components/dimmer.js +698 -717
  71. package/assets/js/semantic-ui/components/dimmer.min.css +4 -4
  72. package/assets/js/semantic-ui/components/dimmer.min.js +6 -6
  73. package/assets/js/semantic-ui/components/divider.css +75 -93
  74. package/assets/js/semantic-ui/components/divider.min.css +4 -4
  75. package/assets/js/semantic-ui/components/dropdown.css +490 -413
  76. package/assets/js/semantic-ui/components/dropdown.js +4203 -4068
  77. package/assets/js/semantic-ui/components/dropdown.min.css +4 -4
  78. package/assets/js/semantic-ui/components/dropdown.min.js +6 -6
  79. package/assets/js/semantic-ui/components/embed.css +27 -38
  80. package/assets/js/semantic-ui/components/embed.js +647 -673
  81. package/assets/js/semantic-ui/components/embed.min.css +4 -4
  82. package/assets/js/semantic-ui/components/embed.min.js +6 -6
  83. package/assets/js/semantic-ui/components/emoji.css +11156 -9192
  84. package/assets/js/semantic-ui/components/emoji.min.css +3 -3
  85. package/assets/js/semantic-ui/components/feed.css +56 -78
  86. package/assets/js/semantic-ui/components/feed.min.css +4 -4
  87. package/assets/js/semantic-ui/components/flag.css +1037 -929
  88. package/assets/js/semantic-ui/components/flag.min.css +4 -4
  89. package/assets/js/semantic-ui/components/flyout.css +552 -0
  90. package/assets/js/semantic-ui/components/flyout.js +1567 -0
  91. package/assets/js/semantic-ui/components/flyout.min.css +9 -0
  92. package/assets/js/semantic-ui/components/flyout.min.js +11 -0
  93. package/assets/js/semantic-ui/components/form.css +536 -530
  94. package/assets/js/semantic-ui/components/form.js +2037 -1945
  95. package/assets/js/semantic-ui/components/form.min.css +4 -4
  96. package/assets/js/semantic-ui/components/form.min.js +6 -6
  97. package/assets/js/semantic-ui/components/grid.css +218 -345
  98. package/assets/js/semantic-ui/components/grid.min.css +4 -4
  99. package/assets/js/semantic-ui/components/header.css +137 -154
  100. package/assets/js/semantic-ui/components/header.min.css +4 -4
  101. package/assets/js/semantic-ui/components/icon.css +3000 -2750
  102. package/assets/js/semantic-ui/components/icon.min.css +4 -4
  103. package/assets/js/semantic-ui/components/image.css +54 -49
  104. package/assets/js/semantic-ui/components/image.min.css +4 -4
  105. package/assets/js/semantic-ui/components/input.css +1081 -227
  106. package/assets/js/semantic-ui/components/input.min.css +4 -4
  107. package/assets/js/semantic-ui/components/item.css +91 -138
  108. package/assets/js/semantic-ui/components/item.min.css +4 -4
  109. package/assets/js/semantic-ui/components/label.css +470 -481
  110. package/assets/js/semantic-ui/components/label.min.css +4 -4
  111. package/assets/js/semantic-ui/components/list.css +93 -114
  112. package/assets/js/semantic-ui/components/list.min.css +4 -4
  113. package/assets/js/semantic-ui/components/loader.css +452 -536
  114. package/assets/js/semantic-ui/components/loader.min.css +4 -4
  115. package/assets/js/semantic-ui/components/menu.css +408 -510
  116. package/assets/js/semantic-ui/components/menu.min.css +9 -1
  117. package/assets/js/semantic-ui/components/message.css +188 -213
  118. package/assets/js/semantic-ui/components/message.min.css +4 -4
  119. package/assets/js/semantic-ui/components/modal.css +174 -166
  120. package/assets/js/semantic-ui/components/modal.js +1558 -1146
  121. package/assets/js/semantic-ui/components/modal.min.css +4 -4
  122. package/assets/js/semantic-ui/components/modal.min.js +6 -6
  123. package/assets/js/semantic-ui/components/nag.css +183 -41
  124. package/assets/js/semantic-ui/components/nag.js +527 -467
  125. package/assets/js/semantic-ui/components/nag.min.css +4 -4
  126. package/assets/js/semantic-ui/components/nag.min.js +6 -6
  127. package/assets/js/semantic-ui/components/placeholder.css +62 -76
  128. package/assets/js/semantic-ui/components/placeholder.min.css +4 -4
  129. package/assets/js/semantic-ui/components/popup.css +681 -312
  130. package/assets/js/semantic-ui/components/popup.js +1470 -1463
  131. package/assets/js/semantic-ui/components/popup.min.css +4 -4
  132. package/assets/js/semantic-ui/components/popup.min.js +6 -6
  133. package/assets/js/semantic-ui/components/progress.css +149 -217
  134. package/assets/js/semantic-ui/components/progress.js +945 -1002
  135. package/assets/js/semantic-ui/components/progress.min.css +4 -4
  136. package/assets/js/semantic-ui/components/progress.min.js +6 -6
  137. package/assets/js/semantic-ui/components/rail.css +17 -22
  138. package/assets/js/semantic-ui/components/rail.min.css +3 -3
  139. package/assets/js/semantic-ui/components/rating.css +89 -184
  140. package/assets/js/semantic-ui/components/rating.js +509 -521
  141. package/assets/js/semantic-ui/components/rating.min.css +4 -4
  142. package/assets/js/semantic-ui/components/rating.min.js +6 -6
  143. package/assets/js/semantic-ui/components/reset.css +12 -17
  144. package/assets/js/semantic-ui/components/reset.min.css +4 -4
  145. package/assets/js/semantic-ui/components/reveal.css +46 -85
  146. package/assets/js/semantic-ui/components/reveal.min.css +4 -4
  147. package/assets/js/semantic-ui/components/search.css +157 -96
  148. package/assets/js/semantic-ui/components/search.js +1522 -1479
  149. package/assets/js/semantic-ui/components/search.min.css +4 -4
  150. package/assets/js/semantic-ui/components/search.min.js +6 -6
  151. package/assets/js/semantic-ui/components/segment.css +317 -249
  152. package/assets/js/semantic-ui/components/segment.min.css +4 -4
  153. package/assets/js/semantic-ui/components/shape.css +16 -32
  154. package/assets/js/semantic-ui/components/shape.js +763 -812
  155. package/assets/js/semantic-ui/components/shape.min.css +4 -4
  156. package/assets/js/semantic-ui/components/shape.min.js +6 -6
  157. package/assets/js/semantic-ui/components/sidebar.css +128 -216
  158. package/assets/js/semantic-ui/components/sidebar.js +1042 -1003
  159. package/assets/js/semantic-ui/components/sidebar.min.css +4 -4
  160. package/assets/js/semantic-ui/components/sidebar.min.js +6 -6
  161. package/assets/js/semantic-ui/components/site.css +123 -48
  162. package/assets/js/semantic-ui/components/site.js +438 -478
  163. package/assets/js/semantic-ui/components/site.min.css +4 -4
  164. package/assets/js/semantic-ui/components/site.min.js +6 -6
  165. package/assets/js/semantic-ui/components/slider.css +133 -141
  166. package/assets/js/semantic-ui/components/slider.js +1312 -1274
  167. package/assets/js/semantic-ui/components/slider.min.css +9 -1
  168. package/assets/js/semantic-ui/components/slider.min.js +6 -6
  169. package/assets/js/semantic-ui/components/state.js +640 -659
  170. package/assets/js/semantic-ui/components/state.min.js +6 -6
  171. package/assets/js/semantic-ui/components/statistic.css +83 -124
  172. package/assets/js/semantic-ui/components/statistic.min.css +4 -4
  173. package/assets/js/semantic-ui/components/step.css +118 -184
  174. package/assets/js/semantic-ui/components/step.min.css +4 -4
  175. package/assets/js/semantic-ui/components/sticky.css +3 -8
  176. package/assets/js/semantic-ui/components/sticky.js +849 -892
  177. package/assets/js/semantic-ui/components/sticky.min.css +4 -4
  178. package/assets/js/semantic-ui/components/sticky.min.js +6 -6
  179. package/assets/js/semantic-ui/components/tab.css +16 -20
  180. package/assets/js/semantic-ui/components/tab.js +896 -941
  181. package/assets/js/semantic-ui/components/tab.min.css +4 -4
  182. package/assets/js/semantic-ui/components/tab.min.js +6 -6
  183. package/assets/js/semantic-ui/components/table.css +2073 -884
  184. package/assets/js/semantic-ui/components/table.min.css +4 -4
  185. package/assets/js/semantic-ui/components/text.css +51 -30
  186. package/assets/js/semantic-ui/components/text.min.css +4 -4
  187. package/assets/js/semantic-ui/components/toast.css +200 -137
  188. package/assets/js/semantic-ui/components/toast.js +912 -832
  189. package/assets/js/semantic-ui/components/toast.min.css +4 -4
  190. package/assets/js/semantic-ui/components/toast.min.js +6 -6
  191. package/assets/js/semantic-ui/components/transition.css +371 -1282
  192. package/assets/js/semantic-ui/components/transition.js +999 -1074
  193. package/assets/js/semantic-ui/components/transition.min.css +4 -4
  194. package/assets/js/semantic-ui/components/transition.min.js +6 -6
  195. package/assets/js/semantic-ui/components/visibility.js +1215 -1247
  196. package/assets/js/semantic-ui/components/visibility.min.js +6 -6
  197. package/assets/js/semantic-ui/semantic.css +43777 -37429
  198. package/assets/js/semantic-ui/semantic.js +29152 -26694
  199. package/assets/js/semantic-ui/semantic.min.css +6 -399
  200. package/assets/js/semantic-ui/semantic.min.js +6 -6
  201. package/assets/js/semantic-ui/themes/basic/assets/fonts/icons.woff2 +0 -0
  202. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-Bold.woff +0 -0
  203. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-Bold.woff2 +0 -0
  204. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-BoldItalic.woff +0 -0
  205. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-BoldItalic.woff2 +0 -0
  206. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-Italic.woff +0 -0
  207. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-Italic.woff2 +0 -0
  208. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-Regular.woff +0 -0
  209. package/assets/js/semantic-ui/themes/default/assets/fonts/Lato-Regular.woff2 +0 -0
  210. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-Bold.woff +0 -0
  211. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-Bold.woff2 +0 -0
  212. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-BoldItalic.woff +0 -0
  213. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-BoldItalic.woff2 +0 -0
  214. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-Italic.woff +0 -0
  215. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-Italic.woff2 +0 -0
  216. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-Regular.woff +0 -0
  217. package/assets/js/semantic-ui/themes/default/assets/fonts/LatoLatin-Regular.woff2 +0 -0
  218. package/assets/js/semantic-ui/themes/default/assets/fonts/brand-icons.woff +0 -0
  219. package/assets/js/semantic-ui/themes/default/assets/fonts/brand-icons.woff2 +0 -0
  220. package/assets/js/semantic-ui/themes/default/assets/fonts/icons.woff +0 -0
  221. package/assets/js/semantic-ui/themes/default/assets/fonts/icons.woff2 +0 -0
  222. package/assets/js/semantic-ui/themes/default/assets/fonts/outline-icons.woff +0 -0
  223. package/assets/js/semantic-ui/themes/default/assets/fonts/outline-icons.woff2 +0 -0
  224. package/assets/js/semantic-ui/themes/famfamfam/assets/images/flags.png +0 -0
  225. package/assets/js/semantic-ui/themes/github/assets/fonts/octicons.woff2 +0 -0
  226. package/assets/js/socket.io/socket.io.esm.min.js +3 -3
  227. package/assets/js/socket.io/socket.io.esm.min.js.map +1 -1
  228. package/assets/js/socket.io/socket.io.js +841 -333
  229. package/assets/js/socket.io/socket.io.js.map +1 -1
  230. package/assets/js/socket.io/socket.io.min.js +3 -3
  231. package/assets/js/socket.io/socket.io.min.js.map +1 -1
  232. package/assets/js/socket.io/socket.io.msgpack.min.js +3 -3
  233. package/assets/js/socket.io/socket.io.msgpack.min.js.map +1 -1
  234. package/cdn.json +19 -4
  235. package/package.json +1 -1
@@ -1,1540 +1,1547 @@
1
1
  /*!
2
- * # Fomantic-UI - Popup
3
- * http://github.com/fomantic/Fomantic-UI/
2
+ * # Fomantic-UI 2.9.2 - Popup
3
+ * https://github.com/fomantic/Fomantic-UI/
4
4
  *
5
5
  *
6
6
  * Released under the MIT license
7
- * http://opensource.org/licenses/MIT
7
+ * https://opensource.org/licenses/MIT
8
8
  *
9
9
  */
10
10
 
11
- ;(function ($, window, document, undefined) {
12
-
13
- 'use strict';
14
-
15
- $.isFunction = $.isFunction || function(obj) {
16
- return typeof obj === "function" && typeof obj.nodeType !== "number";
17
- };
18
-
19
- window = (typeof window != 'undefined' && window.Math == Math)
20
- ? window
21
- : (typeof self != 'undefined' && self.Math == Math)
22
- ? self
23
- : Function('return this')()
24
- ;
25
-
26
- $.fn.popup = function(parameters) {
27
- var
28
- $allModules = $(this),
29
- $document = $(document),
30
- $window = $(window),
31
- $body = $('body'),
32
-
33
- moduleSelector = $allModules.selector || '',
34
-
35
- clickEvent = ('ontouchstart' in document.documentElement)
36
- ? 'touchstart'
37
- : 'click',
38
-
39
- time = new Date().getTime(),
40
- performance = [],
41
-
42
- query = arguments[0],
43
- methodInvoked = (typeof query == 'string'),
44
- queryArguments = [].slice.call(arguments, 1),
45
-
46
- returnedValue
47
- ;
48
- $allModules
49
- .each(function() {
50
- var
51
- settings = ( $.isPlainObject(parameters) )
52
- ? $.extend(true, {}, $.fn.popup.settings, parameters)
53
- : $.extend({}, $.fn.popup.settings),
54
-
55
- selector = settings.selector,
56
- className = settings.className,
57
- error = settings.error,
58
- metadata = settings.metadata,
59
- namespace = settings.namespace,
60
-
61
- eventNamespace = '.' + settings.namespace,
62
- moduleNamespace = 'module-' + namespace,
63
-
64
- $module = $(this),
65
- $context = $(settings.context),
66
- $scrollContext = $(settings.scrollContext),
67
- $boundary = $(settings.boundary),
68
- $target = (settings.target)
69
- ? $(settings.target)
70
- : $module,
71
-
72
- $popup,
73
- $offsetParent,
74
-
75
- searchDepth = 0,
76
- triedPositions = false,
77
- openedWithTouch = false,
78
-
79
- element = this,
80
- instance = $module.data(moduleNamespace),
81
-
82
- documentObserver,
83
- elementNamespace,
84
- id,
85
- module
86
- ;
87
-
88
- module = {
89
-
90
- // binds events
91
- initialize: function() {
92
- module.debug('Initializing', $module);
93
- module.createID();
94
- module.bind.events();
95
- if(!module.exists() && settings.preserve) {
96
- module.create();
97
- }
98
- if(settings.observeChanges) {
99
- module.observeChanges();
100
- }
101
- module.instantiate();
102
- },
11
+ (function ($, window, document) {
12
+ 'use strict';
103
13
 
104
- instantiate: function() {
105
- module.verbose('Storing instance', module);
106
- instance = module;
107
- $module
108
- .data(moduleNamespace, instance)
109
- ;
110
- },
14
+ function isFunction(obj) {
15
+ return typeof obj === 'function' && typeof obj.nodeType !== 'number';
16
+ }
111
17
 
112
- observeChanges: function() {
113
- if('MutationObserver' in window) {
114
- documentObserver = new MutationObserver(module.event.documentChanged);
115
- documentObserver.observe(document, {
116
- childList : true,
117
- subtree : true
118
- });
119
- module.debug('Setting up mutation observer', documentObserver);
120
- }
121
- },
18
+ window = window !== undefined && window.Math === Math
19
+ ? window
20
+ : globalThis;
122
21
 
123
- refresh: function() {
124
- if(settings.popup) {
125
- $popup = $(settings.popup).eq(0);
126
- }
127
- else {
128
- if(settings.inline) {
129
- $popup = $target.nextAll(selector.popup).eq(0);
130
- settings.popup = $popup;
131
- }
132
- }
133
- if(settings.popup) {
134
- $popup.addClass(className.loading);
135
- $offsetParent = module.get.offsetParent();
136
- $popup.removeClass(className.loading);
137
- if(settings.movePopup && module.has.popup() && module.get.offsetParent($popup)[0] !== $offsetParent[0]) {
138
- module.debug('Moving popup to the same offset parent as target');
139
- $popup
140
- .detach()
141
- .appendTo($offsetParent)
142
- ;
143
- }
144
- }
145
- else {
146
- $offsetParent = (settings.inline)
147
- ? module.get.offsetParent($target)
148
- : module.has.popup()
149
- ? module.get.offsetParent($popup)
150
- : $body
151
- ;
152
- }
153
- if( $offsetParent.is('html') && $offsetParent[0] !== $body[0] ) {
154
- module.debug('Setting page as offset parent');
155
- $offsetParent = $body;
156
- }
157
- if( module.get.variation() ) {
158
- module.set.variation();
159
- }
160
- },
22
+ $.fn.popup = function (parameters) {
23
+ var
24
+ $allModules = $(this),
25
+ $document = $(document),
26
+ $window = $(window),
27
+ $body = $('body'),
161
28
 
162
- reposition: function() {
163
- module.refresh();
164
- module.set.position();
165
- },
29
+ moduleSelector = $allModules.selector || '',
166
30
 
167
- destroy: function() {
168
- module.debug('Destroying previous module');
169
- if(documentObserver) {
170
- documentObserver.disconnect();
171
- }
172
- // remove element only if was created dynamically
173
- if($popup && !settings.preserve) {
174
- module.removePopup();
175
- }
176
- // clear all timeouts
177
- clearTimeout(module.hideTimer);
178
- clearTimeout(module.showTimer);
179
- // remove events
180
- module.unbind.close();
181
- module.unbind.events();
182
- $module
183
- .removeData(moduleNamespace)
184
- ;
185
- },
31
+ clickEvent = 'ontouchstart' in document.documentElement
32
+ ? 'touchstart'
33
+ : 'click',
186
34
 
187
- event: {
188
- start: function(event) {
189
- var
190
- delay = ($.isPlainObject(settings.delay))
191
- ? settings.delay.show
192
- : settings.delay
193
- ;
194
- clearTimeout(module.hideTimer);
195
- if(!openedWithTouch || (openedWithTouch && settings.addTouchEvents) ) {
196
- module.showTimer = setTimeout(module.show, delay);
197
- }
198
- },
199
- end: function() {
200
- var
201
- delay = ($.isPlainObject(settings.delay))
202
- ? settings.delay.hide
203
- : settings.delay
204
- ;
205
- clearTimeout(module.showTimer);
206
- module.hideTimer = setTimeout(module.hide, delay);
207
- },
208
- touchstart: function(event) {
209
- openedWithTouch = true;
210
- if(settings.addTouchEvents) {
211
- module.show();
212
- }
213
- },
214
- resize: function() {
215
- if( module.is.visible() ) {
216
- module.set.position();
217
- }
218
- },
219
- documentChanged: function(mutations) {
220
- [].forEach.call(mutations, function(mutation) {
221
- if(mutation.removedNodes) {
222
- [].forEach.call(mutation.removedNodes, function(node) {
223
- if(node == element || $(node).find(element).length > 0) {
224
- module.debug('Element removed from DOM, tearing down events');
225
- module.destroy();
226
- }
227
- });
228
- }
229
- });
230
- },
231
- hideGracefully: function(event) {
35
+ time = Date.now(),
36
+ performance = [],
37
+
38
+ query = arguments[0],
39
+ methodInvoked = typeof query === 'string',
40
+ queryArguments = [].slice.call(arguments, 1),
41
+
42
+ returnedValue
43
+ ;
44
+ $allModules.each(function () {
232
45
  var
233
- $target = $(event.target),
234
- isInDOM = $.contains(document.documentElement, event.target),
235
- inPopup = ($target.closest(selector.popup).length > 0)
46
+ settings = $.isPlainObject(parameters)
47
+ ? $.extend(true, {}, $.fn.popup.settings, parameters)
48
+ : $.extend({}, $.fn.popup.settings),
49
+
50
+ selector = settings.selector,
51
+ className = settings.className,
52
+ error = settings.error,
53
+ metadata = settings.metadata,
54
+ namespace = settings.namespace,
55
+
56
+ eventNamespace = '.' + settings.namespace,
57
+ moduleNamespace = 'module-' + namespace,
58
+
59
+ $module = $(this),
60
+ $context = [window, document].indexOf(settings.context) < 0 ? $document.find(settings.context) : $(settings.context),
61
+ $scrollContext = [window, document].indexOf(settings.scrollContext) < 0 ? $document.find(settings.scrollContext) : $(settings.scrollContext),
62
+ $boundary = [window, document].indexOf(settings.boundary) < 0 ? $document.find(settings.boundary) : $(settings.boundary),
63
+ $target = settings.target
64
+ ? ([window, document].indexOf(settings.target) < 0 ? $document.find(settings.target) : $(settings.target))
65
+ : $module,
66
+
67
+ $popup,
68
+ $offsetParent,
69
+
70
+ searchDepth = 0,
71
+ triedPositions = false,
72
+ openedWithTouch = false,
73
+
74
+ element = this,
75
+ instance = $module.data(moduleNamespace),
76
+
77
+ documentObserver,
78
+ elementNamespace,
79
+ id,
80
+ module
236
81
  ;
237
- // don't close on clicks inside popup
238
- if(event && !inPopup && isInDOM) {
239
- module.debug('Click occurred outside popup hiding popup');
240
- module.hide();
241
- }
242
- else {
243
- module.debug('Click was inside popup, keeping popup open');
244
- }
245
- }
246
- },
247
82
 
248
- // generates popup html from metadata
249
- create: function() {
250
- var
251
- html = module.get.html(),
252
- title = module.get.title(),
253
- content = module.get.content()
254
- ;
255
-
256
- if(html || content || title) {
257
- module.debug('Creating pop-up html');
258
- if(!html) {
259
- html = settings.templates.popup({
260
- title : title,
261
- content : content
262
- });
263
- }
264
- $popup = $('<div/>')
265
- .addClass(className.popup)
266
- .data(metadata.activator, $module)
267
- .html(html)
268
- ;
269
- if(settings.inline) {
270
- module.verbose('Inserting popup element inline', $popup);
271
- $popup
272
- .insertAfter($module)
273
- ;
274
- }
275
- else {
276
- module.verbose('Appending popup element to body', $popup);
277
- $popup
278
- .appendTo( $context )
279
- ;
280
- }
281
- module.refresh();
282
- module.set.variation();
83
+ module = {
84
+
85
+ // binds events
86
+ initialize: function () {
87
+ module.debug('Initializing', $module);
88
+ module.createID();
89
+ module.bind.events();
90
+ if (!module.exists() && settings.preserve) {
91
+ module.create();
92
+ }
93
+ if (settings.observeChanges) {
94
+ module.observeChanges();
95
+ }
96
+ module.instantiate();
97
+ },
283
98
 
284
- if(settings.hoverable) {
285
- module.bind.popup();
286
- }
287
- settings.onCreate.call($popup, element);
288
- }
289
- else if(settings.popup) {
290
- $(settings.popup).data(metadata.activator, $module);
291
- module.verbose('Used popup specified in settings');
292
- module.refresh();
293
- if(settings.hoverable) {
294
- module.bind.popup();
295
- }
296
- }
297
- else if($target.next(selector.popup).length !== 0) {
298
- module.verbose('Pre-existing popup found');
299
- settings.inline = true;
300
- settings.popup = $target.next(selector.popup).data(metadata.activator, $module);
301
- module.refresh();
302
- if(settings.hoverable) {
303
- module.bind.popup();
304
- }
305
- }
306
- else {
307
- module.debug('No content specified skipping display', element);
308
- }
309
- },
99
+ instantiate: function () {
100
+ module.verbose('Storing instance', module);
101
+ instance = module;
102
+ $module
103
+ .data(moduleNamespace, instance)
104
+ ;
105
+ },
310
106
 
311
- createID: function() {
312
- id = (Math.random().toString(16) + '000000000').substr(2, 8);
313
- elementNamespace = '.' + id;
314
- module.verbose('Creating unique id for element', id);
315
- },
107
+ observeChanges: function () {
108
+ if ('MutationObserver' in window) {
109
+ documentObserver = new MutationObserver(module.event.documentChanged);
110
+ documentObserver.observe(document, {
111
+ childList: true,
112
+ subtree: true,
113
+ });
114
+ module.debug('Setting up mutation observer', documentObserver);
115
+ }
116
+ },
316
117
 
317
- // determines popup state
318
- toggle: function() {
319
- module.debug('Toggling pop-up');
320
- if( module.is.hidden() ) {
321
- module.debug('Popup is hidden, showing pop-up');
322
- module.unbind.close();
323
- module.show();
324
- }
325
- else {
326
- module.debug('Popup is visible, hiding pop-up');
327
- module.hide();
328
- }
329
- },
118
+ refresh: function () {
119
+ if (settings.popup) {
120
+ $popup = $document.find(settings.popup).eq(0);
121
+ } else {
122
+ if (settings.inline) {
123
+ $popup = $target.nextAll(selector.popup).eq(0);
124
+ settings.popup = $popup;
125
+ }
126
+ }
127
+ if (settings.popup) {
128
+ module.set.invisible();
129
+ $offsetParent = module.get.offsetParent();
130
+ module.remove.invisible();
131
+ if (settings.movePopup && module.has.popup() && module.get.offsetParent($popup)[0] !== $offsetParent[0]) {
132
+ module.debug('Moving popup to the same offset parent as target');
133
+ $popup
134
+ .detach()
135
+ .appendTo($offsetParent)
136
+ ;
137
+ }
138
+ } else {
139
+ $offsetParent = settings.inline
140
+ ? module.get.offsetParent($target)
141
+ : (module.has.popup()
142
+ ? module.get.offsetParent($popup)
143
+ : $body);
144
+ }
145
+ if ($offsetParent.is('html') && $offsetParent[0] !== $body[0]) {
146
+ module.debug('Setting page as offset parent');
147
+ $offsetParent = $body;
148
+ }
149
+ if (module.get.variation()) {
150
+ module.set.variation();
151
+ }
152
+ },
330
153
 
331
- show: function(callback) {
332
- callback = callback || function(){};
333
- module.debug('Showing pop-up', settings.transition);
334
- if(module.is.hidden() && !( module.is.active() && module.is.dropdown()) ) {
335
- if( !module.exists() ) {
336
- module.create();
337
- }
338
- if(settings.onShow.call($popup, element) === false) {
339
- module.debug('onShow callback returned false, cancelling popup animation');
340
- return;
341
- }
342
- else if(!settings.preserve && !settings.popup) {
343
- module.refresh();
344
- }
345
- if( $popup && module.set.position() ) {
346
- module.save.conditions();
347
- if(settings.exclusive) {
348
- module.hideAll();
349
- }
350
- module.animate.show(callback);
351
- }
352
- }
353
- },
154
+ reposition: function () {
155
+ module.refresh();
156
+ module.set.position();
157
+ },
354
158
 
159
+ destroy: function () {
160
+ module.debug('Destroying previous module');
161
+ if (documentObserver) {
162
+ documentObserver.disconnect();
163
+ }
164
+ // remove element only if was created dynamically
165
+ if ($popup && !settings.preserve) {
166
+ module.removePopup();
167
+ }
168
+ // clear all timeouts
169
+ clearTimeout(module.hideTimer);
170
+ clearTimeout(module.showTimer);
171
+ // remove events
172
+ module.unbind.close();
173
+ module.unbind.events();
174
+ $module
175
+ .removeData(moduleNamespace)
176
+ ;
177
+ },
355
178
 
356
- hide: function(callback) {
357
- callback = callback || function(){};
358
- if( module.is.visible() || module.is.animating() ) {
359
- if(settings.onHide.call($popup, element) === false) {
360
- module.debug('onHide callback returned false, cancelling popup animation');
361
- return;
362
- }
363
- module.remove.visible();
364
- module.unbind.close();
365
- module.restore.conditions();
366
- module.animate.hide(callback);
367
- }
368
- },
179
+ event: {
180
+ start: function (event) {
181
+ var
182
+ delay = $.isPlainObject(settings.delay)
183
+ ? settings.delay.show
184
+ : settings.delay
185
+ ;
186
+ clearTimeout(module.hideTimer);
187
+ if (!openedWithTouch || (openedWithTouch && settings.addTouchEvents)) {
188
+ module.showTimer = setTimeout(module.show, delay);
189
+ }
190
+ },
191
+ end: function () {
192
+ var
193
+ delay = $.isPlainObject(settings.delay)
194
+ ? settings.delay.hide
195
+ : settings.delay
196
+ ;
197
+ clearTimeout(module.showTimer);
198
+ module.hideTimer = setTimeout(module.hide, delay);
199
+ },
200
+ touchstart: function (event) {
201
+ openedWithTouch = true;
202
+ if (settings.addTouchEvents) {
203
+ module.show();
204
+ }
205
+ },
206
+ resize: function () {
207
+ if (module.is.visible()) {
208
+ module.set.position();
209
+ }
210
+ },
211
+ documentChanged: function (mutations) {
212
+ [].forEach.call(mutations, function (mutation) {
213
+ if (mutation.removedNodes) {
214
+ [].forEach.call(mutation.removedNodes, function (node) {
215
+ if (node === element || $(node).find(element).length > 0) {
216
+ module.debug('Element removed from DOM, tearing down events');
217
+ module.destroy();
218
+ }
219
+ });
220
+ }
221
+ });
222
+ },
223
+ hideGracefully: function (event) {
224
+ var
225
+ $target = $(event.target),
226
+ isInDOM = $.contains(document.documentElement, event.target),
227
+ inPopup = $target.closest(selector.popup).length > 0
228
+ ;
229
+ // don't close on clicks inside popup
230
+ if (event && !inPopup && isInDOM) {
231
+ module.debug('Click occurred outside popup hiding popup');
232
+ module.hide();
233
+ } else {
234
+ module.debug('Click was inside popup, keeping popup open');
235
+ }
236
+ },
237
+ },
369
238
 
370
- hideAll: function() {
371
- $(selector.popup)
372
- .filter('.' + className.popupVisible)
373
- .each(function() {
374
- $(this)
375
- .data(metadata.activator)
376
- .popup('hide')
377
- ;
378
- })
379
- ;
380
- },
381
- exists: function() {
382
- if(!$popup) {
383
- return false;
384
- }
385
- if(settings.inline || settings.popup) {
386
- return ( module.has.popup() );
387
- }
388
- else {
389
- return ( $popup.closest($context).length >= 1 )
390
- ? true
391
- : false
392
- ;
393
- }
394
- },
239
+ // generates popup html from metadata
240
+ create: function () {
241
+ var
242
+ html = module.get.html(),
243
+ title = module.get.title(),
244
+ content = module.get.content()
245
+ ;
246
+
247
+ if (html || content || title) {
248
+ module.debug('Creating pop-up html');
249
+ if (!html) {
250
+ html = settings.templates.popup({
251
+ title: title,
252
+ content: content,
253
+ });
254
+ }
255
+ $popup = $('<div/>')
256
+ .addClass(className.popup)
257
+ .data(metadata.activator, $module)
258
+ .html(html)
259
+ ;
260
+ if (settings.inline) {
261
+ module.verbose('Inserting popup element inline', $popup);
262
+ $popup
263
+ .insertAfter($module)
264
+ ;
265
+ } else {
266
+ module.verbose('Appending popup element to body', $popup);
267
+ $popup
268
+ .appendTo($context)
269
+ ;
270
+ }
271
+ module.refresh();
272
+ module.set.variation();
273
+
274
+ if (settings.hoverable) {
275
+ module.bind.popup();
276
+ }
277
+ settings.onCreate.call($popup, element);
278
+ } else if (settings.popup) {
279
+ $document.find(settings.popup).data(metadata.activator, $module);
280
+ module.verbose('Used popup specified in settings');
281
+ module.refresh();
282
+ if (settings.hoverable) {
283
+ module.bind.popup();
284
+ }
285
+ } else if ($target.next(selector.popup).length > 0) {
286
+ module.verbose('Pre-existing popup found');
287
+ settings.inline = true;
288
+ settings.popup = $target.next(selector.popup).data(metadata.activator, $module);
289
+ module.refresh();
290
+ if (settings.hoverable) {
291
+ module.bind.popup();
292
+ }
293
+ } else {
294
+ module.debug('No content specified skipping display', element);
295
+ }
296
+ },
395
297
 
396
- removePopup: function() {
397
- if( module.has.popup() && !settings.popup) {
398
- module.debug('Removing popup', $popup);
399
- $popup.remove();
400
- $popup = undefined;
401
- settings.onRemove.call($popup, element);
402
- }
403
- },
298
+ createID: function () {
299
+ id = (Math.random().toString(16) + '000000000').slice(2, 10);
300
+ elementNamespace = '.' + id;
301
+ module.verbose('Creating unique id for element', id);
302
+ },
404
303
 
405
- save: {
406
- conditions: function() {
407
- module.cache = {
408
- title: $module.attr('title')
409
- };
410
- if (module.cache.title) {
411
- $module.removeAttr('title');
412
- }
413
- module.verbose('Saving original attributes', module.cache.title);
414
- }
415
- },
416
- restore: {
417
- conditions: function() {
418
- if(module.cache && module.cache.title) {
419
- $module.attr('title', module.cache.title);
420
- module.verbose('Restoring original attributes', module.cache.title);
421
- }
422
- return true;
423
- }
424
- },
425
- supports: {
426
- svg: function() {
427
- return (typeof SVGGraphicsElement !== 'undefined');
428
- }
429
- },
430
- animate: {
431
- show: function(callback) {
432
- callback = $.isFunction(callback) ? callback : function(){};
433
- if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
434
- module.set.visible();
435
- $popup
436
- .transition({
437
- animation : settings.transition + ' in',
438
- queue : false,
439
- debug : settings.debug,
440
- verbose : settings.verbose,
441
- duration : settings.duration,
442
- onComplete : function() {
443
- module.bind.close();
444
- callback.call($popup, element);
445
- settings.onVisible.call($popup, element);
446
- }
447
- })
448
- ;
449
- }
450
- else {
451
- module.error(error.noTransition);
452
- }
453
- },
454
- hide: function(callback) {
455
- callback = $.isFunction(callback) ? callback : function(){};
456
- module.debug('Hiding pop-up');
457
- if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
458
- $popup
459
- .transition({
460
- animation : settings.transition + ' out',
461
- queue : false,
462
- duration : settings.duration,
463
- debug : settings.debug,
464
- verbose : settings.verbose,
465
- onComplete : function() {
466
- module.reset();
467
- callback.call($popup, element);
468
- settings.onHidden.call($popup, element);
469
- }
470
- })
471
- ;
472
- }
473
- else {
474
- module.error(error.noTransition);
475
- }
476
- }
477
- },
304
+ // determines popup state
305
+ toggle: function () {
306
+ module.debug('Toggling pop-up');
307
+ if (module.is.hidden()) {
308
+ module.debug('Popup is hidden, showing pop-up');
309
+ module.unbind.close();
310
+ module.show();
311
+ } else {
312
+ module.debug('Popup is visible, hiding pop-up');
313
+ module.hide();
314
+ }
315
+ },
478
316
 
479
- change: {
480
- content: function(html) {
481
- $popup.html(html);
482
- }
483
- },
317
+ show: function (callback) {
318
+ callback = callback || function () {};
319
+ module.debug('Showing pop-up', settings.transition);
320
+ if (module.is.hidden() && !(module.is.active() && module.is.dropdown())) {
321
+ if (!module.exists()) {
322
+ module.create();
323
+ }
324
+ if (settings.onShow.call($popup, element) === false) {
325
+ module.debug('onShow callback returned false, cancelling popup animation');
326
+
327
+ return;
328
+ }
329
+ if (!settings.preserve && !settings.popup) {
330
+ module.refresh();
331
+ }
332
+ if ($popup && module.set.position()) {
333
+ module.save.conditions();
334
+ if (settings.exclusive) {
335
+ module.hideAll();
336
+ }
337
+ module.animate.show(callback);
338
+ }
339
+ }
340
+ },
484
341
 
485
- get: {
486
- html: function() {
487
- $module.removeData(metadata.html);
488
- return $module.data(metadata.html) || settings.html;
489
- },
490
- title: function() {
491
- $module.removeData(metadata.title);
492
- return $module.data(metadata.title) || settings.title;
493
- },
494
- content: function() {
495
- $module.removeData(metadata.content);
496
- return $module.data(metadata.content) || settings.content || $module.attr('title');
497
- },
498
- variation: function() {
499
- $module.removeData(metadata.variation);
500
- return $module.data(metadata.variation) || settings.variation;
501
- },
502
- popup: function() {
503
- return $popup;
504
- },
505
- popupOffset: function() {
506
- return $popup.offset();
507
- },
508
- calculations: function() {
509
- var
510
- $popupOffsetParent = module.get.offsetParent($popup),
511
- targetElement = $target[0],
512
- isWindow = ($boundary[0] == window),
513
- targetPosition = (settings.inline || (settings.popup && settings.movePopup))
514
- ? $target.position()
515
- : $target.offset(),
516
- screenPosition = (isWindow)
517
- ? { top: 0, left: 0 }
518
- : $boundary.offset(),
519
- calculations = {},
520
- scroll = (isWindow)
521
- ? { top: $window.scrollTop(), left: $window.scrollLeft() }
522
- : { top: 0, left: 0},
523
- screen
524
- ;
525
- calculations = {
526
- // element which is launching popup
527
- target : {
528
- element : $target[0],
529
- width : $target.outerWidth(),
530
- height : $target.outerHeight(),
531
- top : targetPosition.top,
532
- left : targetPosition.left,
533
- margin : {}
534
- },
535
- // popup itself
536
- popup : {
537
- width : $popup.outerWidth(),
538
- height : $popup.outerHeight()
539
- },
540
- // offset container (or 3d context)
541
- parent : {
542
- width : $offsetParent.outerWidth(),
543
- height : $offsetParent.outerHeight()
544
- },
545
- // screen boundaries
546
- screen : {
547
- top : screenPosition.top,
548
- left : screenPosition.left,
549
- scroll: {
550
- top : scroll.top,
551
- left : scroll.left
342
+ hide: function (callback) {
343
+ callback = callback || function () {};
344
+ if (module.is.visible() || module.is.animating()) {
345
+ if (settings.onHide.call($popup, element) === false) {
346
+ module.debug('onHide callback returned false, cancelling popup animation');
347
+
348
+ return;
349
+ }
350
+ module.remove.visible();
351
+ module.unbind.close();
352
+ module.restore.conditions();
353
+ module.animate.hide(callback);
354
+ }
552
355
  },
553
- width : $boundary.width(),
554
- height : $boundary.height()
555
- }
556
- };
557
356
 
558
- // if popup offset context is not same as target, then adjust calculations
559
- if($popupOffsetParent.get(0) !== $offsetParent.get(0)) {
560
- var
561
- popupOffset = $popupOffsetParent.offset()
562
- ;
563
- calculations.target.top -= popupOffset.top;
564
- calculations.target.left -= popupOffset.left;
565
- calculations.parent.width = $popupOffsetParent.outerWidth();
566
- calculations.parent.height = $popupOffsetParent.outerHeight();
567
- }
357
+ hideAll: function () {
358
+ $document.find(selector.popup)
359
+ .filter('.' + className.popupVisible)
360
+ .each(function () {
361
+ $(this)
362
+ .data(metadata.activator)
363
+ .popup('hide')
364
+ ;
365
+ })
366
+ ;
367
+ },
368
+ exists: function () {
369
+ if (!$popup) {
370
+ return false;
371
+ }
372
+ if (settings.inline || settings.popup) {
373
+ return module.has.popup();
374
+ }
375
+
376
+ return $popup.closest($context).length > 0;
377
+ },
568
378
 
569
- // add in container calcs if fluid
570
- if( settings.setFluidWidth && module.is.fluid() ) {
571
- calculations.container = {
572
- width: $popup.parent().outerWidth()
573
- };
574
- calculations.popup.width = calculations.container.width;
575
- }
379
+ removePopup: function () {
380
+ if (module.has.popup() && !settings.popup) {
381
+ module.debug('Removing popup', $popup);
382
+ $popup.remove();
383
+ $popup = undefined;
384
+ settings.onRemove.call($popup, element);
385
+ }
386
+ },
576
387
 
577
- // add in margins if inline
578
- calculations.target.margin.top = (settings.inline)
579
- ? parseInt( window.getComputedStyle(targetElement).getPropertyValue('margin-top'), 10)
580
- : 0
581
- ;
582
- calculations.target.margin.left = (settings.inline)
583
- ? module.is.rtl()
584
- ? parseInt( window.getComputedStyle(targetElement).getPropertyValue('margin-right'), 10)
585
- : parseInt( window.getComputedStyle(targetElement).getPropertyValue('margin-left'), 10)
586
- : 0
587
- ;
588
- // calculate screen boundaries
589
- screen = calculations.screen;
590
- calculations.boundary = {
591
- top : screen.top + screen.scroll.top,
592
- bottom : screen.top + screen.scroll.top + screen.height,
593
- left : screen.left + screen.scroll.left,
594
- right : screen.left + screen.scroll.left + screen.width
595
- };
596
- return calculations;
597
- },
598
- id: function() {
599
- return id;
600
- },
601
- startEvent: function() {
602
- if(settings.on == 'hover') {
603
- return 'mouseenter';
604
- }
605
- else if(settings.on == 'focus') {
606
- return 'focus';
607
- }
608
- return false;
609
- },
610
- scrollEvent: function() {
611
- return 'scroll';
612
- },
613
- endEvent: function() {
614
- if(settings.on == 'hover') {
615
- return 'mouseleave';
616
- }
617
- else if(settings.on == 'focus') {
618
- return 'blur';
619
- }
620
- return false;
621
- },
622
- distanceFromBoundary: function(offset, calculations) {
623
- var
624
- distanceFromBoundary = {},
625
- popup,
626
- boundary
627
- ;
628
- calculations = calculations || module.get.calculations();
629
-
630
- // shorthand
631
- popup = calculations.popup;
632
- boundary = calculations.boundary;
633
-
634
- if(offset) {
635
- distanceFromBoundary = {
636
- top : (offset.top - boundary.top),
637
- left : (offset.left - boundary.left),
638
- right : (boundary.right - (offset.left + popup.width) ),
639
- bottom : (boundary.bottom - (offset.top + popup.height) )
640
- };
641
- module.verbose('Distance from boundaries determined', offset, distanceFromBoundary);
642
- }
643
- return distanceFromBoundary;
644
- },
645
- offsetParent: function($element) {
646
- var
647
- element = ($element !== undefined)
648
- ? $element[0]
649
- : $target[0],
650
- parentNode = element.parentNode,
651
- $node = $(parentNode)
652
- ;
653
- if(parentNode) {
654
- var
655
- is2D = ($node.css('transform') === 'none'),
656
- isStatic = ($node.css('position') === 'static'),
657
- isBody = $node.is('body')
658
- ;
659
- while(parentNode && !isBody && isStatic && is2D) {
660
- parentNode = parentNode.parentNode;
661
- $node = $(parentNode);
662
- is2D = ($node.css('transform') === 'none');
663
- isStatic = ($node.css('position') === 'static');
664
- isBody = $node.is('body');
665
- }
666
- }
667
- return ($node && $node.length > 0)
668
- ? $node
669
- : $()
670
- ;
671
- },
672
- positions: function() {
673
- return {
674
- 'top left' : false,
675
- 'top center' : false,
676
- 'top right' : false,
677
- 'bottom left' : false,
678
- 'bottom center' : false,
679
- 'bottom right' : false,
680
- 'left center' : false,
681
- 'right center' : false
388
+ save: {
389
+ conditions: function () {
390
+ module.cache = {
391
+ title: $module.attr('title'),
392
+ };
393
+ if (module.cache.title) {
394
+ $module.removeAttr('title');
395
+ }
396
+ module.verbose('Saving original attributes', module.cache.title);
397
+ },
398
+ },
399
+ restore: {
400
+ conditions: function () {
401
+ if (module.cache && module.cache.title) {
402
+ $module.attr('title', module.cache.title);
403
+ module.verbose('Restoring original attributes', module.cache.title);
404
+ }
405
+
406
+ return true;
407
+ },
408
+ },
409
+ supports: {
410
+ svg: function () {
411
+ return typeof SVGGraphicsElement !== 'undefined';
412
+ },
413
+ },
414
+ animate: {
415
+ show: function (callback) {
416
+ callback = isFunction(callback) ? callback : function () {};
417
+ if (settings.transition && module.can.useElement('transition')) {
418
+ module.set.visible();
419
+ $popup
420
+ .transition({
421
+ animation: (settings.transition.showMethod || settings.transition) + ' in',
422
+ queue: false,
423
+ debug: settings.debug,
424
+ verbose: settings.verbose,
425
+ silent: settings.silent,
426
+ duration: settings.transition.showDuration || settings.duration,
427
+ onComplete: function () {
428
+ module.bind.close();
429
+ callback.call($popup, element);
430
+ settings.onVisible.call($popup, element);
431
+ },
432
+ })
433
+ ;
434
+ }
435
+ },
436
+ hide: function (callback) {
437
+ callback = isFunction(callback) ? callback : function () {};
438
+ module.debug('Hiding pop-up');
439
+ if (settings.transition && $.fn.transition !== undefined) {
440
+ $popup
441
+ .transition({
442
+ animation: (settings.transition.hideMethod || settings.transition) + ' out',
443
+ queue: false,
444
+ duration: settings.transition.hideDuration || settings.duration,
445
+ debug: settings.debug,
446
+ verbose: settings.verbose,
447
+ silent: settings.silent,
448
+ onComplete: function () {
449
+ module.reset();
450
+ callback.call($popup, element);
451
+ settings.onHidden.call($popup, element);
452
+ },
453
+ })
454
+ ;
455
+ } else {
456
+ module.error(error.noTransition);
457
+ }
458
+ },
459
+ },
460
+
461
+ change: {
462
+ content: function (html) {
463
+ $popup.html(html);
464
+ },
465
+ },
466
+
467
+ get: {
468
+ html: function () {
469
+ $module.removeData(metadata.html);
470
+
471
+ return $module.data(metadata.html) || settings.html;
472
+ },
473
+ title: function () {
474
+ $module.removeData(metadata.title);
475
+
476
+ return $module.data(metadata.title) || settings.title;
477
+ },
478
+ content: function () {
479
+ $module.removeData(metadata.content);
480
+
481
+ return $module.data(metadata.content) || settings.content || $module.attr('title');
482
+ },
483
+ variation: function () {
484
+ $module.removeData(metadata.variation);
485
+
486
+ return $module.data(metadata.variation) || settings.variation;
487
+ },
488
+ popup: function () {
489
+ return $popup;
490
+ },
491
+ popupOffset: function () {
492
+ return $popup.offset();
493
+ },
494
+ calculations: function () {
495
+ var
496
+ $popupOffsetParent = module.get.offsetParent($popup),
497
+ targetElement = $target[0],
498
+ isWindowEl = $boundary[0] === window,
499
+ targetOffset = $target.offset(),
500
+ parentOffset = settings.inline || (settings.popup && settings.movePopup)
501
+ ? $target.offsetParent().offset()
502
+ : { top: 0, left: 0 },
503
+ screenPosition = isWindowEl
504
+ ? { top: 0, left: 0 }
505
+ : $boundary.offset(),
506
+ calculations = {},
507
+ scroll = isWindowEl
508
+ ? { top: $window.scrollTop(), left: $window.scrollLeft() }
509
+ : { top: 0, left: 0 },
510
+ screen
511
+ ;
512
+ calculations = {
513
+ // element which is launching popup
514
+ target: {
515
+ element: $target[0],
516
+ width: $target.outerWidth(),
517
+ height: $target.outerHeight(),
518
+ top: targetOffset.top - parentOffset.top,
519
+ left: targetOffset.left - parentOffset.left,
520
+ margin: {},
521
+ },
522
+ // popup itself
523
+ popup: {
524
+ width: $popup.outerWidth(),
525
+ height: $popup.outerHeight(),
526
+ },
527
+ // offset container (or 3d context)
528
+ parent: {
529
+ width: $offsetParent.outerWidth(),
530
+ height: $offsetParent.outerHeight(),
531
+ },
532
+ // screen boundaries
533
+ screen: {
534
+ top: screenPosition.top,
535
+ left: screenPosition.left,
536
+ scroll: {
537
+ top: scroll.top,
538
+ left: scroll.left,
539
+ },
540
+ width: $boundary.width(),
541
+ height: $boundary.height(),
542
+ },
543
+ };
544
+
545
+ // if popup offset context is not same as target, then adjust calculations
546
+ if ($popupOffsetParent[0] !== $offsetParent[0]) {
547
+ var
548
+ popupOffset = $popupOffsetParent.offset()
549
+ ;
550
+ calculations.target.top -= popupOffset.top;
551
+ calculations.target.left -= popupOffset.left;
552
+ calculations.parent.width = $popupOffsetParent.outerWidth();
553
+ calculations.parent.height = $popupOffsetParent.outerHeight();
554
+ }
555
+
556
+ // add in container calcs if fluid
557
+ if (settings.setFluidWidth && module.is.fluid()) {
558
+ calculations.container = {
559
+ width: $popup.parent().outerWidth(),
560
+ };
561
+ calculations.popup.width = calculations.container.width;
562
+ }
563
+
564
+ // add in margins if inline
565
+ calculations.target.margin.top = settings.inline
566
+ ? parseInt(window.getComputedStyle(targetElement).getPropertyValue('margin-top'), 10)
567
+ : 0;
568
+ calculations.target.margin.left = settings.inline
569
+ ? (module.is.rtl()
570
+ ? parseInt(window.getComputedStyle(targetElement).getPropertyValue('margin-right'), 10)
571
+ : parseInt(window.getComputedStyle(targetElement).getPropertyValue('margin-left'), 10))
572
+ : 0;
573
+ // calculate screen boundaries
574
+ screen = calculations.screen;
575
+ calculations.boundary = {
576
+ top: screen.top + screen.scroll.top,
577
+ bottom: screen.top + screen.scroll.top + screen.height,
578
+ left: screen.left + screen.scroll.left,
579
+ right: screen.left + screen.scroll.left + screen.width,
580
+ };
581
+
582
+ return calculations;
583
+ },
584
+ id: function () {
585
+ return id;
586
+ },
587
+ startEvent: function () {
588
+ if (settings.on === 'hover') {
589
+ return 'mouseenter';
590
+ }
591
+ if (settings.on === 'focus') {
592
+ return 'focus';
593
+ }
594
+
595
+ return false;
596
+ },
597
+ scrollEvent: function () {
598
+ return 'scroll';
599
+ },
600
+ endEvent: function () {
601
+ if (settings.on === 'hover') {
602
+ return 'mouseleave';
603
+ }
604
+ if (settings.on === 'focus') {
605
+ return 'blur';
606
+ }
607
+
608
+ return false;
609
+ },
610
+ distanceFromBoundary: function (offset, calculations) {
611
+ var
612
+ distanceFromBoundary = {},
613
+ popup,
614
+ boundary
615
+ ;
616
+ calculations = calculations || module.get.calculations();
617
+
618
+ // shorthand
619
+ popup = calculations.popup;
620
+ boundary = calculations.boundary;
621
+
622
+ if (offset) {
623
+ distanceFromBoundary = {
624
+ top: offset.top - boundary.top,
625
+ left: offset.left - boundary.left,
626
+ right: boundary.right - (offset.left + popup.width),
627
+ bottom: boundary.bottom - (offset.top + popup.height),
628
+ };
629
+ module.verbose('Distance from boundaries determined', offset, distanceFromBoundary);
630
+ }
631
+
632
+ return distanceFromBoundary;
633
+ },
634
+ offsetParent: function ($element) {
635
+ var
636
+ element = $element !== undefined
637
+ ? $element[0]
638
+ : $target[0],
639
+ parentNode = element.parentNode,
640
+ $node = $(parentNode)
641
+ ;
642
+ if (parentNode) {
643
+ var
644
+ is2D = $node.css('transform') === 'none',
645
+ isStatic = $node.css('position') === 'static',
646
+ isBody = $node.is('body')
647
+ ;
648
+ while (parentNode && !isBody && isStatic && is2D) {
649
+ parentNode = parentNode.parentNode;
650
+ $node = $(parentNode);
651
+ is2D = $node.css('transform') === 'none';
652
+ isStatic = $node.css('position') === 'static';
653
+ isBody = $node.is('body');
654
+ }
655
+ }
656
+
657
+ return $node && $node.length > 0
658
+ ? $node
659
+ : $();
660
+ },
661
+ positions: function () {
662
+ return {
663
+ 'top left': false,
664
+ 'top center': false,
665
+ 'top right': false,
666
+ 'bottom left': false,
667
+ 'bottom center': false,
668
+ 'bottom right': false,
669
+ 'left center': false,
670
+ 'right center': false,
671
+ };
672
+ },
673
+ nextPosition: function (position) {
674
+ var
675
+ positions = position.split(' '),
676
+ verticalPosition = positions[0],
677
+ horizontalPosition = positions[1],
678
+ opposite = {
679
+ top: 'bottom',
680
+ bottom: 'top',
681
+ left: 'right',
682
+ right: 'left',
683
+ },
684
+ adjacent = {
685
+ left: 'center',
686
+ center: 'right',
687
+ right: 'left',
688
+ },
689
+ backup = {
690
+ 'top left': 'top center',
691
+ 'top center': 'top right',
692
+ 'top right': 'right center',
693
+ 'right center': 'bottom right',
694
+ 'bottom right': 'bottom center',
695
+ 'bottom center': 'bottom left',
696
+ 'bottom left': 'left center',
697
+ 'left center': 'top left',
698
+ },
699
+ adjacentsAvailable = verticalPosition === 'top' || verticalPosition === 'bottom',
700
+ oppositeTried = false,
701
+ adjacentTried = false,
702
+ nextPosition = false
703
+ ;
704
+ if (!triedPositions) {
705
+ module.verbose('All available positions available');
706
+ triedPositions = module.get.positions();
707
+ }
708
+
709
+ module.debug('Recording last position tried', position);
710
+ triedPositions[position] = true;
711
+
712
+ if (settings.prefer === 'opposite') {
713
+ nextPosition = [opposite[verticalPosition], horizontalPosition];
714
+ nextPosition = nextPosition.join(' ');
715
+ oppositeTried = triedPositions[nextPosition] === true;
716
+ module.debug('Trying opposite strategy', nextPosition);
717
+ }
718
+ if ((settings.prefer === 'adjacent') && adjacentsAvailable) {
719
+ nextPosition = [verticalPosition, adjacent[horizontalPosition]];
720
+ nextPosition = nextPosition.join(' ');
721
+ adjacentTried = triedPositions[nextPosition] === true;
722
+ module.debug('Trying adjacent strategy', nextPosition);
723
+ }
724
+ if (adjacentTried || oppositeTried) {
725
+ module.debug('Using backup position', nextPosition);
726
+ nextPosition = backup[position];
727
+ }
728
+
729
+ return nextPosition;
730
+ },
731
+ },
732
+
733
+ set: {
734
+ position: function (position, calculations) {
735
+ // exit conditions
736
+ if ($target.length === 0 || $popup.length === 0) {
737
+ module.error(error.notFound);
738
+
739
+ return;
740
+ }
741
+ var
742
+ offset,
743
+ distanceAway,
744
+ target,
745
+ popup,
746
+ parent,
747
+ positioning,
748
+ popupOffset,
749
+ distanceFromBoundary
750
+ ;
751
+
752
+ calculations = calculations || module.get.calculations();
753
+ position = position || $module.data(metadata.position) || settings.position;
754
+
755
+ offset = $module.data(metadata.offset) || settings.offset;
756
+ distanceAway = settings.distanceAway;
757
+
758
+ // shorthand
759
+ target = calculations.target;
760
+ popup = calculations.popup;
761
+ parent = calculations.parent;
762
+
763
+ if (module.should.centerArrow(calculations)) {
764
+ module.verbose('Adjusting offset to center arrow on small target element');
765
+ if (position === 'top left' || position === 'bottom left') {
766
+ offset += target.width / 2;
767
+ offset -= settings.arrowPixelsFromEdge;
768
+ }
769
+ if (position === 'top right' || position === 'bottom right') {
770
+ offset -= target.width / 2;
771
+ offset += settings.arrowPixelsFromEdge;
772
+ }
773
+ }
774
+
775
+ if (target.width === 0 && target.height === 0 && !module.is.svg(target.element)) {
776
+ module.debug('Popup target is hidden, no action taken');
777
+
778
+ return false;
779
+ }
780
+
781
+ if (settings.inline) {
782
+ module.debug('Adding margin to calculation', target.margin);
783
+ if (position === 'left center' || position === 'right center') {
784
+ offset += target.margin.top;
785
+ distanceAway += -target.margin.left;
786
+ } else if (position === 'top left' || position === 'top center' || position === 'top right') {
787
+ offset += target.margin.left;
788
+ distanceAway -= target.margin.top;
789
+ } else {
790
+ offset += target.margin.left;
791
+ distanceAway += target.margin.top;
792
+ }
793
+ }
794
+
795
+ module.debug('Determining popup position from calculations', position, calculations);
796
+
797
+ if (module.is.rtl()) {
798
+ position = position.replace(/left|right/g, function (match) {
799
+ return match === 'left'
800
+ ? 'right'
801
+ : 'left';
802
+ });
803
+ module.debug('RTL: Popup position updated', position);
804
+ }
805
+
806
+ // if last attempt use specified last resort position
807
+ if (searchDepth === settings.maxSearchDepth && typeof settings.lastResort === 'string') {
808
+ position = settings.lastResort;
809
+ }
810
+
811
+ switch (position) {
812
+ case 'top left': {
813
+ positioning = {
814
+ top: 'auto',
815
+ bottom: parent.height - target.top + distanceAway,
816
+ left: target.left + offset,
817
+ right: 'auto',
818
+ };
819
+
820
+ break;
821
+ }
822
+ case 'top center': {
823
+ positioning = {
824
+ bottom: parent.height - target.top + distanceAway,
825
+ left: target.left + (target.width / 2) - (popup.width / 2) + offset,
826
+ top: 'auto',
827
+ right: 'auto',
828
+ };
829
+
830
+ break;
831
+ }
832
+ case 'top right': {
833
+ positioning = {
834
+ bottom: parent.height - target.top + distanceAway,
835
+ right: parent.width - target.left - target.width - offset,
836
+ top: 'auto',
837
+ left: 'auto',
838
+ };
839
+
840
+ break;
841
+ }
842
+ case 'left center': {
843
+ positioning = {
844
+ top: target.top + (target.height / 2) - (popup.height / 2) + offset,
845
+ right: parent.width - target.left + distanceAway,
846
+ left: 'auto',
847
+ bottom: 'auto',
848
+ };
849
+
850
+ break;
851
+ }
852
+ case 'right center': {
853
+ positioning = {
854
+ top: target.top + (target.height / 2) - (popup.height / 2) + offset,
855
+ left: target.left + target.width + distanceAway,
856
+ bottom: 'auto',
857
+ right: 'auto',
858
+ };
859
+
860
+ break;
861
+ }
862
+ case 'bottom left': {
863
+ positioning = {
864
+ top: target.top + target.height + distanceAway,
865
+ left: target.left + offset,
866
+ bottom: 'auto',
867
+ right: 'auto',
868
+ };
869
+
870
+ break;
871
+ }
872
+ case 'bottom center': {
873
+ positioning = {
874
+ top: target.top + target.height + distanceAway,
875
+ left: target.left + (target.width / 2) - (popup.width / 2) + offset,
876
+ bottom: 'auto',
877
+ right: 'auto',
878
+ };
879
+
880
+ break;
881
+ }
882
+ case 'bottom right': {
883
+ positioning = {
884
+ top: target.top + target.height + distanceAway,
885
+ right: parent.width - target.left - target.width - offset,
886
+ left: 'auto',
887
+ bottom: 'auto',
888
+ };
889
+
890
+ break;
891
+ }
892
+ }
893
+ if (positioning === undefined) {
894
+ module.error(error.invalidPosition, position);
895
+ }
896
+
897
+ module.debug('Calculated popup positioning values', positioning);
898
+
899
+ // tentatively place on stage
900
+ $popup
901
+ .css(positioning)
902
+ .removeClass(className.position)
903
+ .addClass(position)
904
+ ;
905
+ module.set.invisible();
906
+
907
+ popupOffset = module.get.popupOffset();
908
+
909
+ // see if any boundaries are surpassed with this tentative position
910
+ distanceFromBoundary = module.get.distanceFromBoundary(popupOffset, calculations);
911
+
912
+ if (!settings.forcePosition && module.is.offstage(distanceFromBoundary, position)) {
913
+ module.debug('Position is outside viewport', position);
914
+ if (searchDepth < settings.maxSearchDepth) {
915
+ searchDepth++;
916
+ position = module.get.nextPosition(position);
917
+ module.debug('Trying new position', position);
918
+
919
+ return $popup
920
+ ? module.set.position(position, calculations)
921
+ : false;
922
+ }
923
+ if (settings.lastResort) {
924
+ module.debug('No position found, showing with last position');
925
+ } else {
926
+ module.debug('Popup could not find a position to display', $popup);
927
+ module.error(error.cannotPlace, element);
928
+ module.remove.attempts();
929
+ module.remove.invisible();
930
+ module.reset();
931
+ settings.onUnplaceable.call($popup, element);
932
+
933
+ return false;
934
+ }
935
+ }
936
+ module.debug('Position is on stage', position);
937
+ module.remove.attempts();
938
+ module.remove.invisible();
939
+ if (settings.setFluidWidth && module.is.fluid()) {
940
+ module.set.fluidWidth(calculations);
941
+ }
942
+
943
+ return true;
944
+ },
945
+
946
+ fluidWidth: function (calculations) {
947
+ calculations = calculations || module.get.calculations();
948
+ module.debug('Automatically setting element width to parent width', calculations.parent.width);
949
+ $popup.css('width', calculations.container.width);
950
+ },
951
+
952
+ loading: function () {
953
+ $popup.addClass(className.loading);
954
+ },
955
+
956
+ invisible: function () {
957
+ $popup.addClass(className.invisible);
958
+ },
959
+
960
+ variation: function (variation) {
961
+ variation = variation || module.get.variation();
962
+ if (variation && module.has.popup()) {
963
+ module.verbose('Adding variation to popup', variation);
964
+ $popup.addClass(variation);
965
+ }
966
+ },
967
+
968
+ visible: function () {
969
+ $module.addClass(className.visible);
970
+ },
971
+ },
972
+
973
+ remove: {
974
+ loading: function () {
975
+ $popup.removeClass(className.loading);
976
+ },
977
+ invisible: function () {
978
+ $popup.removeClass(className.invisible);
979
+ },
980
+ variation: function (variation) {
981
+ variation = variation || module.get.variation();
982
+ if (variation) {
983
+ module.verbose('Removing variation', variation);
984
+ $popup.removeClass(variation);
985
+ }
986
+ },
987
+ visible: function () {
988
+ $module.removeClass(className.visible);
989
+ },
990
+ attempts: function () {
991
+ module.verbose('Resetting all searched positions');
992
+ searchDepth = 0;
993
+ triedPositions = false;
994
+ },
995
+ },
996
+
997
+ bind: {
998
+ events: function () {
999
+ module.debug('Binding popup events to module');
1000
+ if (settings.on === 'click') {
1001
+ $module
1002
+ .on(clickEvent + eventNamespace, module.toggle)
1003
+ ;
1004
+ }
1005
+ if (settings.on === 'hover') {
1006
+ $module
1007
+ .on('touchstart' + eventNamespace, module.event.touchstart)
1008
+ ;
1009
+ }
1010
+ if (module.get.startEvent()) {
1011
+ $module
1012
+ .on(module.get.startEvent() + eventNamespace, module.event.start)
1013
+ .on(module.get.endEvent() + eventNamespace, module.event.end)
1014
+ ;
1015
+ }
1016
+ if (settings.target) {
1017
+ module.debug('Target set to element', $target);
1018
+ }
1019
+ $window.on('resize' + elementNamespace, module.event.resize);
1020
+ },
1021
+ popup: function () {
1022
+ module.verbose('Allowing hover events on popup to prevent closing');
1023
+ if ($popup && module.has.popup()) {
1024
+ $popup
1025
+ .on('mouseenter' + eventNamespace, module.event.start)
1026
+ .on('mouseleave' + eventNamespace, module.event.end)
1027
+ ;
1028
+ }
1029
+ },
1030
+ close: function () {
1031
+ if (settings.hideOnScroll === true || (settings.hideOnScroll === 'auto' && settings.on !== 'click')) {
1032
+ module.bind.closeOnScroll();
1033
+ }
1034
+ if (module.is.closable()) {
1035
+ module.bind.clickaway();
1036
+ } else if (settings.on === 'hover' && openedWithTouch) {
1037
+ module.bind.touchClose();
1038
+ }
1039
+ },
1040
+ closeOnScroll: function () {
1041
+ module.verbose('Binding scroll close event to document');
1042
+ $scrollContext
1043
+ .one(module.get.scrollEvent() + elementNamespace, module.event.hideGracefully)
1044
+ ;
1045
+ },
1046
+ touchClose: function () {
1047
+ module.verbose('Binding popup touchclose event to document');
1048
+ $document
1049
+ .on('touchstart' + elementNamespace, function (event) {
1050
+ module.verbose('Touched away from popup');
1051
+ module.event.hideGracefully.call(element, event);
1052
+ })
1053
+ ;
1054
+ },
1055
+ clickaway: function () {
1056
+ module.verbose('Binding popup close event to document');
1057
+ $document
1058
+ .on(clickEvent + elementNamespace, function (event) {
1059
+ module.verbose('Clicked away from popup');
1060
+ module.event.hideGracefully.call(element, event);
1061
+ })
1062
+ ;
1063
+ },
1064
+ },
1065
+
1066
+ unbind: {
1067
+ events: function () {
1068
+ $window
1069
+ .off(elementNamespace)
1070
+ ;
1071
+ $module
1072
+ .off(eventNamespace)
1073
+ ;
1074
+ },
1075
+ close: function () {
1076
+ $document
1077
+ .off(elementNamespace)
1078
+ ;
1079
+ $scrollContext
1080
+ .off(elementNamespace)
1081
+ ;
1082
+ },
1083
+ },
1084
+
1085
+ can: {
1086
+ useElement: function (element) {
1087
+ if ($.fn[element] !== undefined) {
1088
+ return true;
1089
+ }
1090
+ module.error(error.noElement.replace('{element}', element));
1091
+
1092
+ return false;
1093
+ },
1094
+ },
1095
+
1096
+ has: {
1097
+ popup: function () {
1098
+ return $popup && $popup.length > 0;
1099
+ },
1100
+ },
1101
+
1102
+ should: {
1103
+ centerArrow: function (calculations) {
1104
+ return !module.is.basic() && calculations.target.width <= (settings.arrowPixelsFromEdge * 2);
1105
+ },
1106
+ },
1107
+
1108
+ is: {
1109
+ closable: function () {
1110
+ if (settings.closable === 'auto') {
1111
+ return settings.on !== 'hover';
1112
+ }
1113
+
1114
+ return settings.closable;
1115
+ },
1116
+ offstage: function (distanceFromBoundary, position) {
1117
+ var
1118
+ offstage = []
1119
+ ;
1120
+ // return boundaries that have been surpassed
1121
+ $.each(distanceFromBoundary, function (direction, distance) {
1122
+ if (distance < -settings.jitter) {
1123
+ module.debug('Position exceeds allowable distance from edge', direction, distance, position);
1124
+ offstage.push(direction);
1125
+ }
1126
+ });
1127
+
1128
+ return offstage.length > 0;
1129
+ },
1130
+ svg: function (element) {
1131
+ return module.supports.svg() && (element instanceof SVGGraphicsElement);
1132
+ },
1133
+ basic: function () {
1134
+ return $module.hasClass(className.basic);
1135
+ },
1136
+ active: function () {
1137
+ return $module.hasClass(className.active);
1138
+ },
1139
+ animating: function () {
1140
+ return $popup !== undefined && $popup.hasClass(className.animating);
1141
+ },
1142
+ fluid: function () {
1143
+ return $popup !== undefined && $popup.hasClass(className.fluid);
1144
+ },
1145
+ visible: function () {
1146
+ return $popup !== undefined && $popup.hasClass(className.popupVisible);
1147
+ },
1148
+ dropdown: function () {
1149
+ return $module.hasClass(className.dropdown);
1150
+ },
1151
+ hidden: function () {
1152
+ return !module.is.visible();
1153
+ },
1154
+ rtl: function () {
1155
+ return $module.attr('dir') === 'rtl' || $module.css('direction') === 'rtl' || $body.attr('dir') === 'rtl' || $body.css('direction') === 'rtl' || $context.attr('dir') === 'rtl' || $context.css('direction') === 'rtl';
1156
+ },
1157
+ },
1158
+
1159
+ reset: function () {
1160
+ module.remove.visible();
1161
+ if (settings.preserve) {
1162
+ if ($.fn.transition !== undefined) {
1163
+ $popup
1164
+ .transition('remove transition')
1165
+ ;
1166
+ }
1167
+ } else {
1168
+ module.removePopup();
1169
+ }
1170
+ },
1171
+
1172
+ setting: function (name, value) {
1173
+ if ($.isPlainObject(name)) {
1174
+ $.extend(true, settings, name);
1175
+ } else if (value !== undefined) {
1176
+ settings[name] = value;
1177
+ } else {
1178
+ return settings[name];
1179
+ }
1180
+ },
1181
+ internal: function (name, value) {
1182
+ if ($.isPlainObject(name)) {
1183
+ $.extend(true, module, name);
1184
+ } else if (value !== undefined) {
1185
+ module[name] = value;
1186
+ } else {
1187
+ return module[name];
1188
+ }
1189
+ },
1190
+ debug: function () {
1191
+ if (!settings.silent && settings.debug) {
1192
+ if (settings.performance) {
1193
+ module.performance.log(arguments);
1194
+ } else {
1195
+ module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
1196
+ module.debug.apply(console, arguments);
1197
+ }
1198
+ }
1199
+ },
1200
+ verbose: function () {
1201
+ if (!settings.silent && settings.verbose && settings.debug) {
1202
+ if (settings.performance) {
1203
+ module.performance.log(arguments);
1204
+ } else {
1205
+ module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
1206
+ module.verbose.apply(console, arguments);
1207
+ }
1208
+ }
1209
+ },
1210
+ error: function () {
1211
+ if (!settings.silent) {
1212
+ module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
1213
+ module.error.apply(console, arguments);
1214
+ }
1215
+ },
1216
+ performance: {
1217
+ log: function (message) {
1218
+ var
1219
+ currentTime,
1220
+ executionTime,
1221
+ previousTime
1222
+ ;
1223
+ if (settings.performance) {
1224
+ currentTime = Date.now();
1225
+ previousTime = time || currentTime;
1226
+ executionTime = currentTime - previousTime;
1227
+ time = currentTime;
1228
+ performance.push({
1229
+ Name: message[0],
1230
+ Arguments: [].slice.call(message, 1) || '',
1231
+ Element: element,
1232
+ 'Execution Time': executionTime,
1233
+ });
1234
+ }
1235
+ clearTimeout(module.performance.timer);
1236
+ module.performance.timer = setTimeout(module.performance.display, 500);
1237
+ },
1238
+ display: function () {
1239
+ var
1240
+ title = settings.name + ':',
1241
+ totalTime = 0
1242
+ ;
1243
+ time = false;
1244
+ clearTimeout(module.performance.timer);
1245
+ $.each(performance, function (index, data) {
1246
+ totalTime += data['Execution Time'];
1247
+ });
1248
+ title += ' ' + totalTime + 'ms';
1249
+ if (moduleSelector) {
1250
+ title += ' \'' + moduleSelector + '\'';
1251
+ }
1252
+ if (performance.length > 0) {
1253
+ console.groupCollapsed(title);
1254
+ if (console.table) {
1255
+ console.table(performance);
1256
+ } else {
1257
+ $.each(performance, function (index, data) {
1258
+ console.log(data.Name + ': ' + data['Execution Time'] + 'ms');
1259
+ });
1260
+ }
1261
+ console.groupEnd();
1262
+ }
1263
+ performance = [];
1264
+ },
1265
+ },
1266
+ invoke: function (query, passedArguments, context) {
1267
+ var
1268
+ object = instance,
1269
+ maxDepth,
1270
+ found,
1271
+ response
1272
+ ;
1273
+ passedArguments = passedArguments || queryArguments;
1274
+ context = context || element;
1275
+ if (typeof query === 'string' && object !== undefined) {
1276
+ query = query.split(/[ .]/);
1277
+ maxDepth = query.length - 1;
1278
+ $.each(query, function (depth, value) {
1279
+ var camelCaseValue = depth !== maxDepth
1280
+ ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
1281
+ : query
1282
+ ;
1283
+ if ($.isPlainObject(object[camelCaseValue]) && (depth !== maxDepth)) {
1284
+ object = object[camelCaseValue];
1285
+ } else if (object[camelCaseValue] !== undefined) {
1286
+ found = object[camelCaseValue];
1287
+
1288
+ return false;
1289
+ } else if ($.isPlainObject(object[value]) && (depth !== maxDepth)) {
1290
+ object = object[value];
1291
+ } else if (object[value] !== undefined) {
1292
+ found = object[value];
1293
+
1294
+ return false;
1295
+ } else {
1296
+ module.error(error.method, query);
1297
+
1298
+ return false;
1299
+ }
1300
+ });
1301
+ }
1302
+ if (isFunction(found)) {
1303
+ response = found.apply(context, passedArguments);
1304
+ } else if (found !== undefined) {
1305
+ response = found;
1306
+ }
1307
+ if (Array.isArray(returnedValue)) {
1308
+ returnedValue.push(response);
1309
+ } else if (returnedValue !== undefined) {
1310
+ returnedValue = [returnedValue, response];
1311
+ } else if (response !== undefined) {
1312
+ returnedValue = response;
1313
+ }
1314
+
1315
+ return found;
1316
+ },
682
1317
  };
683
- },
684
- nextPosition: function(position) {
685
- var
686
- positions = position.split(' '),
687
- verticalPosition = positions[0],
688
- horizontalPosition = positions[1],
689
- opposite = {
690
- top : 'bottom',
691
- bottom : 'top',
692
- left : 'right',
693
- right : 'left'
694
- },
695
- adjacent = {
696
- left : 'center',
697
- center : 'right',
698
- right : 'left'
699
- },
700
- backup = {
701
- 'top left' : 'top center',
702
- 'top center' : 'top right',
703
- 'top right' : 'right center',
704
- 'right center' : 'bottom right',
705
- 'bottom right' : 'bottom center',
706
- 'bottom center' : 'bottom left',
707
- 'bottom left' : 'left center',
708
- 'left center' : 'top left'
709
- },
710
- adjacentsAvailable = (verticalPosition == 'top' || verticalPosition == 'bottom'),
711
- oppositeTried = false,
712
- adjacentTried = false,
713
- nextPosition = false
714
- ;
715
- if(!triedPositions) {
716
- module.verbose('All available positions available');
717
- triedPositions = module.get.positions();
1318
+
1319
+ if (methodInvoked) {
1320
+ if (instance === undefined) {
1321
+ module.initialize();
1322
+ }
1323
+ module.invoke(query);
1324
+ } else {
1325
+ if (instance !== undefined) {
1326
+ instance.invoke('destroy');
1327
+ }
1328
+ module.initialize();
718
1329
  }
1330
+ });
719
1331
 
720
- module.debug('Recording last position tried', position);
721
- triedPositions[position] = true;
1332
+ return returnedValue !== undefined
1333
+ ? returnedValue
1334
+ : this;
1335
+ };
722
1336
 
723
- if(settings.prefer === 'opposite') {
724
- nextPosition = [opposite[verticalPosition], horizontalPosition];
725
- nextPosition = nextPosition.join(' ');
726
- oppositeTried = (triedPositions[nextPosition] === true);
727
- module.debug('Trying opposite strategy', nextPosition);
728
- }
729
- if((settings.prefer === 'adjacent') && adjacentsAvailable ) {
730
- nextPosition = [verticalPosition, adjacent[horizontalPosition]];
731
- nextPosition = nextPosition.join(' ');
732
- adjacentTried = (triedPositions[nextPosition] === true);
733
- module.debug('Trying adjacent strategy', nextPosition);
734
- }
735
- if(adjacentTried || oppositeTried) {
736
- module.debug('Using backup position', nextPosition);
737
- nextPosition = backup[position];
738
- }
739
- return nextPosition;
740
- }
741
- },
1337
+ $.fn.popup.settings = {
742
1338
 
743
- set: {
744
- position: function(position, calculations) {
1339
+ name: 'Popup',
745
1340
 
746
- // exit conditions
747
- if($target.length === 0 || $popup.length === 0) {
748
- module.error(error.notFound);
749
- return;
750
- }
751
- var
752
- offset,
753
- distanceAway,
754
- target,
755
- popup,
756
- parent,
757
- positioning,
758
- popupOffset,
759
- distanceFromBoundary
760
- ;
1341
+ // module settings
1342
+ silent: false,
1343
+ debug: false,
1344
+ verbose: false,
1345
+ performance: true,
1346
+ namespace: 'popup',
761
1347
 
762
- calculations = calculations || module.get.calculations();
763
- position = position || $module.data(metadata.position) || settings.position;
764
-
765
- offset = $module.data(metadata.offset) || settings.offset;
766
- distanceAway = settings.distanceAway;
767
-
768
- // shorthand
769
- target = calculations.target;
770
- popup = calculations.popup;
771
- parent = calculations.parent;
772
-
773
- if(module.should.centerArrow(calculations)) {
774
- module.verbose('Adjusting offset to center arrow on small target element');
775
- if(position == 'top left' || position == 'bottom left') {
776
- offset += (target.width / 2);
777
- offset -= settings.arrowPixelsFromEdge;
778
- }
779
- if(position == 'top right' || position == 'bottom right') {
780
- offset -= (target.width / 2);
781
- offset += settings.arrowPixelsFromEdge;
782
- }
783
- }
1348
+ // whether it should use dom mutation observers
1349
+ observeChanges: true,
784
1350
 
785
- if(target.width === 0 && target.height === 0 && !module.is.svg(target.element)) {
786
- module.debug('Popup target is hidden, no action taken');
787
- return false;
788
- }
1351
+ // callback only when element added to dom
1352
+ onCreate: function () {},
789
1353
 
790
- if(settings.inline) {
791
- module.debug('Adding margin to calculation', target.margin);
792
- if(position == 'left center' || position == 'right center') {
793
- offset += target.margin.top;
794
- distanceAway += -target.margin.left;
795
- }
796
- else if (position == 'top left' || position == 'top center' || position == 'top right') {
797
- offset += target.margin.left;
798
- distanceAway -= target.margin.top;
799
- }
800
- else {
801
- offset += target.margin.left;
802
- distanceAway += target.margin.top;
803
- }
804
- }
1354
+ // callback before element removed from dom
1355
+ onRemove: function () {},
805
1356
 
806
- module.debug('Determining popup position from calculations', position, calculations);
1357
+ // callback before show animation
1358
+ onShow: function () {},
807
1359
 
808
- if (module.is.rtl()) {
809
- position = position.replace(/left|right/g, function (match) {
810
- return (match == 'left')
811
- ? 'right'
812
- : 'left'
813
- ;
814
- });
815
- module.debug('RTL: Popup position updated', position);
816
- }
1360
+ // callback after show animation
1361
+ onVisible: function () {},
817
1362
 
818
- // if last attempt use specified last resort position
819
- if(searchDepth == settings.maxSearchDepth && typeof settings.lastResort === 'string') {
820
- position = settings.lastResort;
821
- }
1363
+ // callback before hide animation
1364
+ onHide: function () {},
822
1365
 
823
- switch (position) {
824
- case 'top left':
825
- positioning = {
826
- top : 'auto',
827
- bottom : parent.height - target.top + distanceAway,
828
- left : target.left + offset,
829
- right : 'auto'
830
- };
831
- break;
832
- case 'top center':
833
- positioning = {
834
- bottom : parent.height - target.top + distanceAway,
835
- left : target.left + (target.width / 2) - (popup.width / 2) + offset,
836
- top : 'auto',
837
- right : 'auto'
838
- };
839
- break;
840
- case 'top right':
841
- positioning = {
842
- bottom : parent.height - target.top + distanceAway,
843
- right : parent.width - target.left - target.width - offset,
844
- top : 'auto',
845
- left : 'auto'
846
- };
847
- break;
848
- case 'left center':
849
- positioning = {
850
- top : target.top + (target.height / 2) - (popup.height / 2) + offset,
851
- right : parent.width - target.left + distanceAway,
852
- left : 'auto',
853
- bottom : 'auto'
854
- };
855
- break;
856
- case 'right center':
857
- positioning = {
858
- top : target.top + (target.height / 2) - (popup.height / 2) + offset,
859
- left : target.left + target.width + distanceAway,
860
- bottom : 'auto',
861
- right : 'auto'
862
- };
863
- break;
864
- case 'bottom left':
865
- positioning = {
866
- top : target.top + target.height + distanceAway,
867
- left : target.left + offset,
868
- bottom : 'auto',
869
- right : 'auto'
870
- };
871
- break;
872
- case 'bottom center':
873
- positioning = {
874
- top : target.top + target.height + distanceAway,
875
- left : target.left + (target.width / 2) - (popup.width / 2) + offset,
876
- bottom : 'auto',
877
- right : 'auto'
878
- };
879
- break;
880
- case 'bottom right':
881
- positioning = {
882
- top : target.top + target.height + distanceAway,
883
- right : parent.width - target.left - target.width - offset,
884
- left : 'auto',
885
- bottom : 'auto'
886
- };
887
- break;
888
- }
889
- if(positioning === undefined) {
890
- module.error(error.invalidPosition, position);
891
- }
1366
+ // callback when popup cannot be positioned in visible screen
1367
+ onUnplaceable: function () {},
892
1368
 
893
- module.debug('Calculated popup positioning values', positioning);
1369
+ // callback after hide animation
1370
+ onHidden: function () {},
894
1371
 
895
- // tentatively place on stage
896
- $popup
897
- .css(positioning)
898
- .removeClass(className.position)
899
- .addClass(position)
900
- .addClass(className.loading)
901
- ;
1372
+ // when to show popup
1373
+ on: 'hover',
902
1374
 
903
- popupOffset = module.get.popupOffset();
1375
+ // element to use to determine if popup is out of boundary
1376
+ boundary: window,
904
1377
 
905
- // see if any boundaries are surpassed with this tentative position
906
- distanceFromBoundary = module.get.distanceFromBoundary(popupOffset, calculations);
1378
+ // whether to add touchstart events when using hover
1379
+ addTouchEvents: true,
907
1380
 
908
- if(!settings.forcePosition && module.is.offstage(distanceFromBoundary, position) ) {
909
- module.debug('Position is outside viewport', position);
910
- if(searchDepth < settings.maxSearchDepth) {
911
- searchDepth++;
912
- position = module.get.nextPosition(position);
913
- module.debug('Trying new position', position);
914
- return ($popup)
915
- ? module.set.position(position, calculations)
916
- : false
917
- ;
918
- }
919
- else {
920
- if(settings.lastResort) {
921
- module.debug('No position found, showing with last position');
922
- }
923
- else {
924
- module.debug('Popup could not find a position to display', $popup);
925
- module.error(error.cannotPlace, element);
926
- module.remove.attempts();
927
- module.remove.loading();
928
- module.reset();
929
- settings.onUnplaceable.call($popup, element);
930
- return false;
931
- }
932
- }
933
- }
934
- module.debug('Position is on stage', position);
935
- module.remove.attempts();
936
- module.remove.loading();
937
- if( settings.setFluidWidth && module.is.fluid() ) {
938
- module.set.fluidWidth(calculations);
939
- }
940
- return true;
941
- },
942
-
943
- fluidWidth: function(calculations) {
944
- calculations = calculations || module.get.calculations();
945
- module.debug('Automatically setting element width to parent width', calculations.parent.width);
946
- $popup.css('width', calculations.container.width);
947
- },
948
-
949
- variation: function(variation) {
950
- variation = variation || module.get.variation();
951
- if(variation && module.has.popup() ) {
952
- module.verbose('Adding variation to popup', variation);
953
- $popup.addClass(variation);
954
- }
955
- },
1381
+ // default position relative to element
1382
+ position: 'top left',
956
1383
 
957
- visible: function() {
958
- $module.addClass(className.visible);
959
- }
960
- },
1384
+ // if given position should be used regardless if popup fits
1385
+ forcePosition: false,
961
1386
 
962
- remove: {
963
- loading: function() {
964
- $popup.removeClass(className.loading);
965
- },
966
- variation: function(variation) {
967
- variation = variation || module.get.variation();
968
- if(variation) {
969
- module.verbose('Removing variation', variation);
970
- $popup.removeClass(variation);
971
- }
972
- },
973
- visible: function() {
974
- $module.removeClass(className.visible);
975
- },
976
- attempts: function() {
977
- module.verbose('Resetting all searched positions');
978
- searchDepth = 0;
979
- triedPositions = false;
980
- }
981
- },
1387
+ // name of variation to use
1388
+ variation: '',
982
1389
 
983
- bind: {
984
- events: function() {
985
- module.debug('Binding popup events to module');
986
- if(settings.on == 'click') {
987
- $module
988
- .on(clickEvent + eventNamespace, module.toggle)
989
- ;
990
- }
991
- if(settings.on == 'hover') {
992
- $module
993
- .on('touchstart' + eventNamespace, module.event.touchstart)
994
- ;
995
- }
996
- if( module.get.startEvent() ) {
997
- $module
998
- .on(module.get.startEvent() + eventNamespace, module.event.start)
999
- .on(module.get.endEvent() + eventNamespace, module.event.end)
1000
- ;
1001
- }
1002
- if(settings.target) {
1003
- module.debug('Target set to element', $target);
1004
- }
1005
- $window.on('resize' + elementNamespace, module.event.resize);
1006
- },
1007
- popup: function() {
1008
- module.verbose('Allowing hover events on popup to prevent closing');
1009
- if( $popup && module.has.popup() ) {
1010
- $popup
1011
- .on('mouseenter' + eventNamespace, module.event.start)
1012
- .on('mouseleave' + eventNamespace, module.event.end)
1013
- ;
1014
- }
1015
- },
1016
- close: function() {
1017
- if(settings.hideOnScroll === true || (settings.hideOnScroll == 'auto' && settings.on != 'click')) {
1018
- module.bind.closeOnScroll();
1019
- }
1020
- if(module.is.closable()) {
1021
- module.bind.clickaway();
1022
- }
1023
- else if(settings.on == 'hover' && openedWithTouch) {
1024
- module.bind.touchClose();
1025
- }
1026
- },
1027
- closeOnScroll: function() {
1028
- module.verbose('Binding scroll close event to document');
1029
- $scrollContext
1030
- .one(module.get.scrollEvent() + elementNamespace, module.event.hideGracefully)
1031
- ;
1032
- },
1033
- touchClose: function() {
1034
- module.verbose('Binding popup touchclose event to document');
1035
- $document
1036
- .on('touchstart' + elementNamespace, function(event) {
1037
- module.verbose('Touched away from popup');
1038
- module.event.hideGracefully.call(element, event);
1039
- })
1040
- ;
1041
- },
1042
- clickaway: function() {
1043
- module.verbose('Binding popup close event to document');
1044
- $document
1045
- .on(clickEvent + elementNamespace, function(event) {
1046
- module.verbose('Clicked away from popup');
1047
- module.event.hideGracefully.call(element, event);
1048
- })
1049
- ;
1050
- }
1051
- },
1390
+ // whether popup should be moved to context
1391
+ movePopup: true,
1052
1392
 
1053
- unbind: {
1054
- events: function() {
1055
- $window
1056
- .off(elementNamespace)
1057
- ;
1058
- $module
1059
- .off(eventNamespace)
1060
- ;
1061
- },
1062
- close: function() {
1063
- $document
1064
- .off(elementNamespace)
1065
- ;
1066
- $scrollContext
1067
- .off(elementNamespace)
1068
- ;
1069
- },
1070
- },
1393
+ // element which popup should be relative to
1394
+ target: false,
1071
1395
 
1072
- has: {
1073
- popup: function() {
1074
- return ($popup && $popup.length > 0);
1075
- }
1076
- },
1396
+ // jq selector or element that should be used as popup
1397
+ popup: false,
1077
1398
 
1078
- should: {
1079
- centerArrow: function(calculations) {
1080
- return !module.is.basic() && calculations.target.width <= (settings.arrowPixelsFromEdge * 2);
1081
- },
1082
- },
1399
+ // popup should remain inline next to activator
1400
+ inline: false,
1083
1401
 
1084
- is: {
1085
- closable: function() {
1086
- if(settings.closable == 'auto') {
1087
- if(settings.on == 'hover') {
1088
- return false;
1089
- }
1090
- return true;
1091
- }
1092
- return settings.closable;
1093
- },
1094
- offstage: function(distanceFromBoundary, position) {
1095
- var
1096
- offstage = []
1097
- ;
1098
- // return boundaries that have been surpassed
1099
- $.each(distanceFromBoundary, function(direction, distance) {
1100
- if(distance < -settings.jitter) {
1101
- module.debug('Position exceeds allowable distance from edge', direction, distance, position);
1102
- offstage.push(direction);
1103
- }
1104
- });
1105
- if(offstage.length > 0) {
1106
- return true;
1107
- }
1108
- else {
1109
- return false;
1110
- }
1111
- },
1112
- svg: function(element) {
1113
- return module.supports.svg() && (element instanceof SVGGraphicsElement);
1114
- },
1115
- basic: function() {
1116
- return $module.hasClass(className.basic);
1117
- },
1118
- active: function() {
1119
- return $module.hasClass(className.active);
1120
- },
1121
- animating: function() {
1122
- return ($popup !== undefined && $popup.hasClass(className.animating) );
1123
- },
1124
- fluid: function() {
1125
- return ($popup !== undefined && $popup.hasClass(className.fluid));
1126
- },
1127
- visible: function() {
1128
- return ($popup !== undefined && $popup.hasClass(className.popupVisible));
1129
- },
1130
- dropdown: function() {
1131
- return $module.hasClass(className.dropdown);
1132
- },
1133
- hidden: function() {
1134
- return !module.is.visible();
1135
- },
1136
- rtl: function () {
1137
- return $module.attr('dir') === 'rtl' || $module.css('direction') === 'rtl';
1138
- }
1139
- },
1402
+ // popup should be removed from page on hide
1403
+ preserve: false,
1140
1404
 
1141
- reset: function() {
1142
- module.remove.visible();
1143
- if(settings.preserve) {
1144
- if($.fn.transition !== undefined) {
1145
- $popup
1146
- .transition('remove transition')
1147
- ;
1148
- }
1149
- }
1150
- else {
1151
- module.removePopup();
1152
- }
1153
- },
1405
+ // popup should not close when being hovered on
1406
+ hoverable: false,
1154
1407
 
1155
- setting: function(name, value) {
1156
- if( $.isPlainObject(name) ) {
1157
- $.extend(true, settings, name);
1158
- }
1159
- else if(value !== undefined) {
1160
- settings[name] = value;
1161
- }
1162
- else {
1163
- return settings[name];
1164
- }
1165
- },
1166
- internal: function(name, value) {
1167
- if( $.isPlainObject(name) ) {
1168
- $.extend(true, module, name);
1169
- }
1170
- else if(value !== undefined) {
1171
- module[name] = value;
1172
- }
1173
- else {
1174
- return module[name];
1175
- }
1176
- },
1177
- debug: function() {
1178
- if(!settings.silent && settings.debug) {
1179
- if(settings.performance) {
1180
- module.performance.log(arguments);
1181
- }
1182
- else {
1183
- module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
1184
- module.debug.apply(console, arguments);
1185
- }
1186
- }
1187
- },
1188
- verbose: function() {
1189
- if(!settings.silent && settings.verbose && settings.debug) {
1190
- if(settings.performance) {
1191
- module.performance.log(arguments);
1192
- }
1193
- else {
1194
- module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
1195
- module.verbose.apply(console, arguments);
1196
- }
1197
- }
1198
- },
1199
- error: function() {
1200
- if(!settings.silent) {
1201
- module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
1202
- module.error.apply(console, arguments);
1203
- }
1204
- },
1205
- performance: {
1206
- log: function(message) {
1207
- var
1208
- currentTime,
1209
- executionTime,
1210
- previousTime
1211
- ;
1212
- if(settings.performance) {
1213
- currentTime = new Date().getTime();
1214
- previousTime = time || currentTime;
1215
- executionTime = currentTime - previousTime;
1216
- time = currentTime;
1217
- performance.push({
1218
- 'Name' : message[0],
1219
- 'Arguments' : [].slice.call(message, 1) || '',
1220
- 'Element' : element,
1221
- 'Execution Time' : executionTime
1222
- });
1223
- }
1224
- clearTimeout(module.performance.timer);
1225
- module.performance.timer = setTimeout(module.performance.display, 500);
1226
- },
1227
- display: function() {
1228
- var
1229
- title = settings.name + ':',
1230
- totalTime = 0
1231
- ;
1232
- time = false;
1233
- clearTimeout(module.performance.timer);
1234
- $.each(performance, function(index, data) {
1235
- totalTime += data['Execution Time'];
1236
- });
1237
- title += ' ' + totalTime + 'ms';
1238
- if(moduleSelector) {
1239
- title += ' \'' + moduleSelector + '\'';
1240
- }
1241
- if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
1242
- console.groupCollapsed(title);
1243
- if(console.table) {
1244
- console.table(performance);
1245
- }
1246
- else {
1247
- $.each(performance, function(index, data) {
1248
- console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
1249
- });
1250
- }
1251
- console.groupEnd();
1252
- }
1253
- performance = [];
1254
- }
1255
- },
1256
- invoke: function(query, passedArguments, context) {
1257
- var
1258
- object = instance,
1259
- maxDepth,
1260
- found,
1261
- response
1262
- ;
1263
- passedArguments = passedArguments || queryArguments;
1264
- context = element || context;
1265
- if(typeof query == 'string' && object !== undefined) {
1266
- query = query.split(/[\. ]/);
1267
- maxDepth = query.length - 1;
1268
- $.each(query, function(depth, value) {
1269
- var camelCaseValue = (depth != maxDepth)
1270
- ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
1271
- : query
1272
- ;
1273
- if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
1274
- object = object[camelCaseValue];
1275
- }
1276
- else if( object[camelCaseValue] !== undefined ) {
1277
- found = object[camelCaseValue];
1278
- return false;
1279
- }
1280
- else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
1281
- object = object[value];
1282
- }
1283
- else if( object[value] !== undefined ) {
1284
- found = object[value];
1285
- return false;
1286
- }
1287
- else {
1288
- return false;
1289
- }
1290
- });
1291
- }
1292
- if ( $.isFunction( found ) ) {
1293
- response = found.apply(context, passedArguments);
1294
- }
1295
- else if(found !== undefined) {
1296
- response = found;
1297
- }
1298
- if(Array.isArray(returnedValue)) {
1299
- returnedValue.push(response);
1300
- }
1301
- else if(returnedValue !== undefined) {
1302
- returnedValue = [returnedValue, response];
1303
- }
1304
- else if(response !== undefined) {
1305
- returnedValue = response;
1306
- }
1307
- return found;
1308
- }
1309
- };
1310
-
1311
- if(methodInvoked) {
1312
- if(instance === undefined) {
1313
- module.initialize();
1314
- }
1315
- module.invoke(query);
1316
- }
1317
- else {
1318
- if(instance !== undefined) {
1319
- instance.invoke('destroy');
1320
- }
1321
- module.initialize();
1322
- }
1323
- })
1324
- ;
1325
-
1326
- return (returnedValue !== undefined)
1327
- ? returnedValue
1328
- : this
1329
- ;
1330
- };
1331
-
1332
- $.fn.popup.settings = {
1333
-
1334
- name : 'Popup',
1335
-
1336
- // module settings
1337
- silent : false,
1338
- debug : false,
1339
- verbose : false,
1340
- performance : true,
1341
- namespace : 'popup',
1342
-
1343
- // whether it should use dom mutation observers
1344
- observeChanges : true,
1345
-
1346
- // callback only when element added to dom
1347
- onCreate : function(){},
1348
-
1349
- // callback before element removed from dom
1350
- onRemove : function(){},
1351
-
1352
- // callback before show animation
1353
- onShow : function(){},
1354
-
1355
- // callback after show animation
1356
- onVisible : function(){},
1357
-
1358
- // callback before hide animation
1359
- onHide : function(){},
1360
-
1361
- // callback when popup cannot be positioned in visible screen
1362
- onUnplaceable : function(){},
1363
-
1364
- // callback after hide animation
1365
- onHidden : function(){},
1366
-
1367
- // when to show popup
1368
- on : 'hover',
1369
-
1370
- // element to use to determine if popup is out of boundary
1371
- boundary : window,
1372
-
1373
- // whether to add touchstart events when using hover
1374
- addTouchEvents : true,
1375
-
1376
- // default position relative to element
1377
- position : 'top left',
1378
-
1379
- // if given position should be used regardless if popup fits
1380
- forcePosition : false,
1381
-
1382
- // name of variation to use
1383
- variation : '',
1384
-
1385
- // whether popup should be moved to context
1386
- movePopup : true,
1387
-
1388
- // element which popup should be relative to
1389
- target : false,
1390
-
1391
- // jq selector or element that should be used as popup
1392
- popup : false,
1393
-
1394
- // popup should remain inline next to activator
1395
- inline : false,
1396
-
1397
- // popup should be removed from page on hide
1398
- preserve : false,
1399
-
1400
- // popup should not close when being hovered on
1401
- hoverable : false,
1402
-
1403
- // explicitly set content
1404
- content : false,
1405
-
1406
- // explicitly set html
1407
- html : false,
1408
-
1409
- // explicitly set title
1410
- title : false,
1411
-
1412
- // whether automatically close on clickaway when on click
1413
- closable : true,
1414
-
1415
- // automatically hide on scroll
1416
- hideOnScroll : 'auto',
1408
+ // explicitly set content
1409
+ content: false,
1410
+
1411
+ // explicitly set html
1412
+ html: false,
1413
+
1414
+ // explicitly set title
1415
+ title: false,
1417
1416
 
1418
- // hide other popups on show
1419
- exclusive : false,
1417
+ // whether automatically close on clickaway when on click
1418
+ closable: true,
1420
1419
 
1421
- // context to attach popups
1422
- context : 'body',
1420
+ // automatically hide on scroll
1421
+ hideOnScroll: 'auto',
1423
1422
 
1424
- // context for binding scroll events
1425
- scrollContext : window,
1423
+ // hide other popups on show
1424
+ exclusive: false,
1426
1425
 
1427
- // position to prefer when calculating new position
1428
- prefer : 'opposite',
1426
+ // context to attach popups
1427
+ context: 'body',
1429
1428
 
1430
- // specify position to appear even if it doesn't fit
1431
- lastResort : false,
1429
+ // context for binding scroll events
1430
+ scrollContext: window,
1432
1431
 
1433
- // number of pixels from edge of popup to pointing arrow center (used from centering)
1434
- arrowPixelsFromEdge: 20,
1432
+ // position to prefer when calculating new position
1433
+ prefer: 'opposite',
1435
1434
 
1436
- // delay used to prevent accidental refiring of animations due to user error
1437
- delay : {
1438
- show : 50,
1439
- hide : 70
1440
- },
1435
+ // specify position to appear even if it doesn't fit
1436
+ lastResort: false,
1441
1437
 
1442
- // whether fluid variation should assign width explicitly
1443
- setFluidWidth : true,
1438
+ // number of pixels from edge of popup to pointing arrow center (used from centering)
1439
+ arrowPixelsFromEdge: 20,
1444
1440
 
1445
- // transition settings
1446
- duration : 200,
1447
- transition : 'scale',
1441
+ // delay used to prevent accidental refiring of animations due to user error
1442
+ delay: {
1443
+ show: 50,
1444
+ hide: 70,
1445
+ },
1446
+
1447
+ // whether fluid variation should assign width explicitly
1448
+ setFluidWidth: true,
1448
1449
 
1449
- // distance away from activating element in px
1450
- distanceAway : 0,
1450
+ // transition settings
1451
+ duration: 200,
1452
+ transition: 'scale',
1451
1453
 
1452
- // number of pixels an element is allowed to be "offstage" for a position to be chosen (allows for rounding)
1453
- jitter : 2,
1454
+ // distance away from activating element in px
1455
+ distanceAway: 0,
1454
1456
 
1455
- // offset on aligning axis from calculated position
1456
- offset : 0,
1457
+ // number of pixels an element is allowed to be "offstage" for a position to be chosen (allows for rounding)
1458
+ jitter: 2,
1457
1459
 
1458
- // maximum times to look for a position before failing (9 positions total)
1459
- maxSearchDepth : 15,
1460
+ // offset on aligning axis from calculated position
1461
+ offset: 0,
1460
1462
 
1461
- error: {
1462
- invalidPosition : 'The position you specified is not a valid position',
1463
- cannotPlace : 'Popup does not fit within the boundaries of the viewport',
1464
- method : 'The method you called is not defined.',
1465
- noTransition : 'This module requires ui transitions <https://github.com/Semantic-Org/UI-Transition>',
1466
- notFound : 'The target or popup you specified does not exist on the page'
1467
- },
1463
+ // maximum times to look for a position before failing (9 positions total)
1464
+ maxSearchDepth: 15,
1468
1465
 
1469
- metadata: {
1470
- activator : 'activator',
1471
- content : 'content',
1472
- html : 'html',
1473
- offset : 'offset',
1474
- position : 'position',
1475
- title : 'title',
1476
- variation : 'variation'
1477
- },
1478
-
1479
- className : {
1480
- active : 'active',
1481
- basic : 'basic',
1482
- animating : 'animating',
1483
- dropdown : 'dropdown',
1484
- fluid : 'fluid',
1485
- loading : 'loading',
1486
- popup : 'ui popup',
1487
- position : 'top left center bottom right',
1488
- visible : 'visible',
1489
- popupVisible : 'visible'
1490
- },
1491
-
1492
- selector : {
1493
- popup : '.ui.popup'
1494
- },
1495
-
1496
- templates: {
1497
- escape: function(string) {
1498
- var
1499
- badChars = /[<>"'`]/g,
1500
- shouldEscape = /[&<>"'`]/,
1501
- escape = {
1502
- "<": "&lt;",
1503
- ">": "&gt;",
1504
- '"': "&quot;",
1505
- "'": "&#x27;",
1506
- "`": "&#x60;"
1466
+ error: {
1467
+ invalidPosition: 'The position you specified is not a valid position',
1468
+ cannotPlace: 'Popup does not fit within the boundaries of the viewport',
1469
+ method: 'The method you called is not defined.',
1470
+ noElement: 'This module requires ui {element}',
1471
+ notFound: 'The target or popup you specified does not exist on the page',
1507
1472
  },
1508
- escapedChar = function(chr) {
1509
- return escape[chr];
1510
- }
1511
- ;
1512
- if(shouldEscape.test(string)) {
1513
- string = string.replace(/&(?![a-z0-9#]{1,6};)/, "&amp;");
1514
- return string.replace(badChars, escapedChar);
1515
- }
1516
- return string;
1517
- },
1518
- popup: function(text) {
1519
- var
1520
- html = '',
1521
- escape = $.fn.popup.settings.templates.escape
1522
- ;
1523
- if(typeof text !== undefined) {
1524
- if(typeof text.title !== undefined && text.title) {
1525
- text.title = escape(text.title);
1526
- html += '<div class="header">' + text.title + '</div>';
1527
- }
1528
- if(typeof text.content !== undefined && text.content) {
1529
- text.content = escape(text.content);
1530
- html += '<div class="content">' + text.content + '</div>';
1531
- }
1532
- }
1533
- return html;
1534
- }
1535
- }
1536
1473
 
1537
- };
1474
+ metadata: {
1475
+ activator: 'activator',
1476
+ content: 'content',
1477
+ html: 'html',
1478
+ offset: 'offset',
1479
+ position: 'position',
1480
+ title: 'title',
1481
+ variation: 'variation',
1482
+ },
1483
+
1484
+ className: {
1485
+ active: 'active',
1486
+ basic: 'basic',
1487
+ animating: 'animating',
1488
+ dropdown: 'dropdown',
1489
+ invisible: 'invisible',
1490
+ fluid: 'fluid',
1491
+ loading: 'loading',
1492
+ popup: 'ui popup',
1493
+ position: 'top left center bottom right',
1494
+ visible: 'visible',
1495
+ popupVisible: 'visible',
1496
+ },
1497
+
1498
+ selector: {
1499
+ popup: '.ui.popup',
1500
+ },
1501
+
1502
+ templates: {
1503
+ escape: function (string) {
1504
+ var
1505
+ badChars = /["'<>`]/g,
1506
+ shouldEscape = /["&'<>`]/,
1507
+ escape = {
1508
+ '<': '&lt;',
1509
+ '>': '&gt;',
1510
+ '"': '&quot;',
1511
+ "'": '&#x27;',
1512
+ '`': '&#x60;',
1513
+ },
1514
+ escapedChar = function (chr) {
1515
+ return escape[chr];
1516
+ }
1517
+ ;
1518
+ if (shouldEscape.test(string)) {
1519
+ string = string.replace(/&(?![\d#a-z]{1,12};)/gi, '&amp;');
1538
1520
 
1521
+ return string.replace(badChars, escapedChar);
1522
+ }
1523
+
1524
+ return string;
1525
+ },
1526
+ popup: function (text) {
1527
+ var
1528
+ html = '',
1529
+ escape = $.fn.popup.settings.templates.escape
1530
+ ;
1531
+ if (text !== undefined) {
1532
+ if (text.title) {
1533
+ text.title = escape(text.title);
1534
+ html += '<div class="header">' + text.title + '</div>';
1535
+ }
1536
+ if (text.content) {
1537
+ text.content = escape(text.content);
1538
+ html += '<div class="content">' + text.content + '</div>';
1539
+ }
1540
+ }
1541
+
1542
+ return html;
1543
+ },
1544
+ },
1539
1545
 
1540
- })( jQuery, window, document );
1546
+ };
1547
+ })(jQuery, window, document);