nexmo-oas-renderer 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/.env.example +1 -0
  3. data/.github/workflows/push-docker-publish.yml +19 -0
  4. data/.gitignore +6 -0
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +135 -0
  7. data/.travis.yml +9 -0
  8. data/CHANGELOG.md +58 -0
  9. data/CONTRIBUTING.md +46 -0
  10. data/Dockerfile +6 -0
  11. data/Gemfile +6 -0
  12. data/Gemfile.lock +248 -0
  13. data/LICENSE.txt +21 -0
  14. data/README.md +103 -0
  15. data/Rakefile +2 -0
  16. data/bin/console +14 -0
  17. data/bin/setup +8 -0
  18. data/exe/nexmo-oas-renderer +5 -0
  19. data/lib/nexmo/oas/engine.rb +11 -0
  20. data/lib/nexmo/oas/renderer.rb +13 -0
  21. data/lib/nexmo/oas/renderer/app.rb +201 -0
  22. data/lib/nexmo/oas/renderer/config.ru +9 -0
  23. data/lib/nexmo/oas/renderer/config/code_languages.yml +138 -0
  24. data/lib/nexmo/oas/renderer/config/dynamic_content.yml +1 -0
  25. data/lib/nexmo/oas/renderer/decorators/response_parser_decorator.rb +55 -0
  26. data/lib/nexmo/oas/renderer/helpers/navigation.rb +66 -0
  27. data/lib/nexmo/oas/renderer/helpers/render.rb +25 -0
  28. data/lib/nexmo/oas/renderer/helpers/summary.rb +33 -0
  29. data/lib/nexmo/oas/renderer/helpers/url.rb +19 -0
  30. data/lib/nexmo/oas/renderer/presenters/api_specification.rb +54 -0
  31. data/lib/nexmo/oas/renderer/presenters/endpoint.rb +21 -0
  32. data/lib/nexmo/oas/renderer/presenters/groups.rb +39 -0
  33. data/lib/nexmo/oas/renderer/presenters/navigation.rb +26 -0
  34. data/lib/nexmo/oas/renderer/presenters/open_api_specification.rb +62 -0
  35. data/lib/nexmo/oas/renderer/presenters/request_body_raw.rb +141 -0
  36. data/lib/nexmo/oas/renderer/presenters/response_format.rb +29 -0
  37. data/lib/nexmo/oas/renderer/presenters/response_tab/link.rb +36 -0
  38. data/lib/nexmo/oas/renderer/presenters/response_tab/panel.rb +45 -0
  39. data/lib/nexmo/oas/renderer/presenters/response_tabs.rb +58 -0
  40. data/lib/nexmo/oas/renderer/presenters/versions.rb +51 -0
  41. data/lib/nexmo/oas/renderer/public/500.html +66 -0
  42. data/lib/nexmo/oas/renderer/public/assets/images/brands/android.svg +1 -0
  43. data/lib/nexmo/oas/renderer/public/assets/images/brands/curl.svg +1 -0
  44. data/lib/nexmo/oas/renderer/public/assets/images/brands/dotnet.svg +1 -0
  45. data/lib/nexmo/oas/renderer/public/assets/images/brands/ios.svg +1 -0
  46. data/lib/nexmo/oas/renderer/public/assets/images/brands/java.svg +1 -0
  47. data/lib/nexmo/oas/renderer/public/assets/images/brands/javascript.svg +1 -0
  48. data/lib/nexmo/oas/renderer/public/assets/images/brands/node.svg +1 -0
  49. data/lib/nexmo/oas/renderer/public/assets/images/brands/php.svg +1 -0
  50. data/lib/nexmo/oas/renderer/public/assets/images/brands/python.svg +11 -0
  51. data/lib/nexmo/oas/renderer/public/assets/images/brands/ruby.svg +1 -0
  52. data/lib/nexmo/oas/renderer/public/assets/images/lost.svg +37 -0
  53. data/lib/nexmo/oas/renderer/public/assets/javascripts/components/format.js +47 -0
  54. data/lib/nexmo/oas/renderer/public/assets/javascripts/nexmo-oas-renderer.js +65 -0
  55. data/lib/nexmo/oas/renderer/public/assets/javascripts/popper.min.js +5 -0
  56. data/lib/nexmo/oas/renderer/public/assets/javascripts/prism.js +22 -0
  57. data/lib/nexmo/oas/renderer/public/assets/javascripts/tooltip.min.js +5 -0
  58. data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.accordion.js +307 -0
  59. data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.core.js +230 -0
  60. data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.modal.js +300 -0
  61. data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.tabs.js +143 -0
  62. data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.tooltip.js +76 -0
  63. data/lib/nexmo/oas/renderer/public/assets/stylesheets/nexmo-oas-renderer.css +287 -0
  64. data/lib/nexmo/oas/renderer/public/assets/stylesheets/nexmo-oas-renderer.css.map +7 -0
  65. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/api.scss +341 -0
  66. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/mediaqueries.scss +48 -0
  67. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/style.scss +6 -0
  68. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/themes/dark.scss +89 -0
  69. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/themes/light.scss +68 -0
  70. data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/variables.scss +91 -0
  71. data/lib/nexmo/oas/renderer/public/assets/stylesheets/volta-prism.min.css +1 -0
  72. data/lib/nexmo/oas/renderer/public/assets/stylesheets/volta.min.css +1 -0
  73. data/lib/nexmo/oas/renderer/public/assets/symbol/volta-icons.svg +1 -0
  74. data/lib/nexmo/oas/renderer/public/favicon.ico +0 -0
  75. data/lib/nexmo/oas/renderer/public/fonts/Spezia-Regular.eot +0 -0
  76. data/lib/nexmo/oas/renderer/public/fonts/Spezia-Regular.ttf +0 -0
  77. data/lib/nexmo/oas/renderer/public/fonts/Spezia-Regular.woff +0 -0
  78. data/lib/nexmo/oas/renderer/public/fonts/Spezia-Regular.woff2 +0 -0
  79. data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiBold.eot +0 -0
  80. data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiBold.ttf +0 -0
  81. data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiBold.woff +0 -0
  82. data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiBold.woff2 +0 -0
  83. data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiMonoSemiBold.eot +0 -0
  84. data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiMonoSemiBold.ttf +0 -0
  85. data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiMonoSemiBold.woff +0 -0
  86. data/lib/nexmo/oas/renderer/public/fonts/Spezia-SemiMonoSemiBold.woff2 +0 -0
  87. data/lib/nexmo/oas/renderer/public/fonts/Spezia-WideMedium.eot +0 -0
  88. data/lib/nexmo/oas/renderer/public/fonts/Spezia-WideMedium.ttf +0 -0
  89. data/lib/nexmo/oas/renderer/public/fonts/Spezia-WideMedium.woff +0 -0
  90. data/lib/nexmo/oas/renderer/public/fonts/Spezia-WideMedium.woff2 +0 -0
  91. data/lib/nexmo/oas/renderer/services/oas_parser.rb +23 -0
  92. data/lib/nexmo/oas/renderer/services/open_api_definition_resolver.rb +35 -0
  93. data/lib/nexmo/oas/renderer/version.rb +9 -0
  94. data/lib/nexmo/oas/renderer/views/api/index.erb +19 -0
  95. data/lib/nexmo/oas/renderer/views/api/show.erb +1 -0
  96. data/lib/nexmo/oas/renderer/views/concepts/list/plain.html.erb +5 -0
  97. data/lib/nexmo/oas/renderer/views/layouts/_head.erb +6 -0
  98. data/lib/nexmo/oas/renderer/views/layouts/_javascripts.erb +14 -0
  99. data/lib/nexmo/oas/renderer/views/layouts/api.erb +23 -0
  100. data/lib/nexmo/oas/renderer/views/layouts/open_api.erb +12 -0
  101. data/lib/nexmo/oas/renderer/views/open_api/_auth.erb +74 -0
  102. data/lib/nexmo/oas/renderer/views/open_api/_available_endpoints.erb +25 -0
  103. data/lib/nexmo/oas/renderer/views/open_api/_callback.erb +5 -0
  104. data/lib/nexmo/oas/renderer/views/open_api/_callback_endpoint.erb +38 -0
  105. data/lib/nexmo/oas/renderer/views/open_api/_callbacks.erb +5 -0
  106. data/lib/nexmo/oas/renderer/views/open_api/_code_examples.erb +16 -0
  107. data/lib/nexmo/oas/renderer/views/open_api/_endpoint.erb +54 -0
  108. data/lib/nexmo/oas/renderer/views/open_api/_header.erb +71 -0
  109. data/lib/nexmo/oas/renderer/views/open_api/_model.erb +43 -0
  110. data/lib/nexmo/oas/renderer/views/open_api/_navigation.erb +68 -0
  111. data/lib/nexmo/oas/renderer/views/open_api/_parameter_groups.erb +56 -0
  112. data/lib/nexmo/oas/renderer/views/open_api/_parameters.erb +115 -0
  113. data/lib/nexmo/oas/renderer/views/open_api/_request_json.erb +4 -0
  114. data/lib/nexmo/oas/renderer/views/open_api/_request_one_of.erb +70 -0
  115. data/lib/nexmo/oas/renderer/views/open_api/_request_single.erb +53 -0
  116. data/lib/nexmo/oas/renderer/views/open_api/_requests.erb +22 -0
  117. data/lib/nexmo/oas/renderer/views/open_api/_response_description_parameters.erb +130 -0
  118. data/lib/nexmo/oas/renderer/views/open_api/_response_descriptions.erb +45 -0
  119. data/lib/nexmo/oas/renderer/views/open_api/_response_fields.erb +3 -0
  120. data/lib/nexmo/oas/renderer/views/open_api/_response_tabs.erb +18 -0
  121. data/lib/nexmo/oas/renderer/views/open_api/_responses.erb +51 -0
  122. data/lib/nexmo/oas/renderer/views/open_api/_tabbed_parameters.erb +64 -0
  123. data/lib/nexmo/oas/renderer/views/open_api/_tabbed_single_parameter.erb +56 -0
  124. data/lib/nexmo/oas/renderer/views/open_api/_webhooks.erb +30 -0
  125. data/lib/nexmo/oas/renderer/views/open_api/show.erb +26 -0
  126. data/lib/nexmo/oas/renderer/views/static/404.erb +6 -0
  127. data/nexmo-oas-renderer.gemspec +51 -0
  128. metadata +397 -0
@@ -0,0 +1,300 @@
1
+ /**
2
+ * Copyright (c) 2001-present, Vonage.
3
+ *
4
+ * Modals (requires core)
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ Volta.modal = function () {
10
+ var _class = {
11
+ auto: 'Vlt-modal--auto',
12
+ bodyModalOpen: 'Vlt-body--modal-open',
13
+ cancel: 'Vlt-modal__cancel',
14
+ confirm: 'Vlt-modal__confirm',
15
+ content: 'Vlt-modal__content',
16
+ modal: 'Vlt-modal',
17
+ out: 'Vlt-modal--out',
18
+ panel: 'Vlt-modal__panel',
19
+ trigger: 'Vlt-modal-trigger',
20
+ visible: 'Vlt-modal_visible',
21
+ dismiss: 'Vlt-modal__dismiss',
22
+ }
23
+
24
+ var body,
25
+ dismissModalHandler,
26
+ cancelModalHandler,
27
+ confirmModalHandler,
28
+ escHandler,
29
+ clickHandler,
30
+ escAttached;
31
+
32
+ function Modal() {}
33
+
34
+ Modal.prototype = {
35
+ attachButtons: function() {
36
+ var _this = this;
37
+ _this.dismissBtn = _this.modal.querySelector('.' + _class.dismiss);
38
+
39
+ if(_this.dismissBtn) {
40
+ dismissModalHandler = dismissModal.bind(_this);
41
+ _this.dismissBtn.addEventListener('click', dismissModalHandler);
42
+ }
43
+
44
+ _this.cancelBtn = _this.modal.querySelector('.' + _class.cancel);
45
+
46
+ if(_this.cancelBtn) {
47
+ cancelModalHandler = cancelModal.bind(_this);
48
+ _this.cancelBtn.addEventListener('click', cancelModalHandler);
49
+ }
50
+
51
+ _this.confirmBtn = _this.modal.querySelector('.' + _class.confirm);
52
+
53
+ if(_this.confirmBtn) {
54
+ confirmModalHandler = confirmModal.bind(_this);
55
+ _this.confirmBtn.addEventListener('click', confirmModalHandler);
56
+ }
57
+ },
58
+ html: function(newHtml) {
59
+ this.modal.innerHTML = newHtml;
60
+ return this;
61
+ },
62
+ init: function(elementOrId) {
63
+ if(elementOrId.length) {
64
+ this.modal = document.querySelector('#' + elementOrId);
65
+ } else {
66
+ this.modal = elementOrId;
67
+ }
68
+
69
+ this._callback = Volta._getFunction(this.modal.dataset.callback);
70
+ },
71
+ open: function(e) {
72
+ if(e && e.preventDefault) {
73
+ e.preventDefault();
74
+ e.stopPropagation();
75
+ }
76
+
77
+ this.modal.classList.remove(_class.out);
78
+ this.modal.classList.add(_class.visible);
79
+ this.attachButtons();
80
+
81
+ disableScroll();
82
+
83
+ if(!escAttached && !this.modal.dataset.disableEsc || this.modal.dataset.disableEsc === "false") {
84
+ escHandler = closeModalOnEscape.bind(this);
85
+ body.addEventListener('keyup', escHandler, { once: true });
86
+ escAttached = true;
87
+ }
88
+
89
+ if(!this.modal.dataset.disableClick || this.modal.dataset.disableClick === "false") {
90
+ clickHandler = closeModalOnClick.bind(this);
91
+ this.modal.addEventListener('click', clickHandler, { once: true });
92
+ }
93
+ },
94
+ dismiss: function(e, confirmed) {
95
+ var _this = this;
96
+
97
+ if(e && e.preventDefault) {
98
+ e.preventDefault();
99
+ e.stopPropagation();
100
+ }
101
+
102
+ enableScroll();
103
+
104
+ if(_this.modal){
105
+ _this.modal.classList.remove(_class.visible);
106
+ _this.modal.classList.add(_class.out);
107
+ }
108
+
109
+ if(_this._callback) {
110
+ _this._callback(confirmed);
111
+ }
112
+
113
+ removeModal(_this);
114
+ }
115
+ }
116
+
117
+ return {
118
+ create: create,
119
+ init: attachModalHandlers
120
+ }
121
+
122
+ /**
123
+ * @public
124
+ *
125
+ * @description Attach a click listener to each modals trigger on the screen, which will open the modal
126
+ */
127
+ function attachModalHandlers() {
128
+ if(!body) {
129
+ body = document.querySelector('body');
130
+ }
131
+
132
+ var triggers = document.querySelectorAll('.' + _class.trigger);
133
+
134
+ if(triggers.length > 0) {
135
+ triggers.forEach(attachTriggerHandler);
136
+ }
137
+
138
+ //Not the recommended way to use modals
139
+ var modals = document.querySelectorAll('.' + _class.modal);
140
+
141
+ if(modals.length > 0) {
142
+ modals.forEach(attachModalHandler);
143
+ }
144
+
145
+ function attachModalHandler(modal) {
146
+ if(Volta._hasClass(modal, _class.auto)) {
147
+ var trigger = document.querySelector('#' + modal.dataset.trigger);
148
+ trigger.addEventListener('click', function() {
149
+ create(modal).open();
150
+ });
151
+ }
152
+ }
153
+
154
+ function attachTriggerHandler(trigger) {
155
+ if(trigger.dataset.modal) {
156
+ var modal = document.querySelector('#' + trigger.dataset.modal);
157
+
158
+ if(!modal) {
159
+ console.warn('Volta: modal ' + trigger.dataset.modal + ' cannot be found');
160
+ }
161
+
162
+ trigger.addEventListener('click', function() {
163
+ create(modal).open();
164
+ });
165
+ }
166
+ }
167
+ }
168
+
169
+ /**
170
+ * @private
171
+ *
172
+ * @description Close the modal, triggered by cancel button, passes false to callback function
173
+ * @param {event} e
174
+ */
175
+ function cancelModal(e) {
176
+ return this.dismiss(e, false);
177
+ }
178
+
179
+ /**
180
+ * @private
181
+ *
182
+ * @description Close the modal, triggered by confirm button, passes true to callback function
183
+ * @param {event} e
184
+ */
185
+ function confirmModal(e) {
186
+ return this.dismiss(e, true);
187
+ }
188
+
189
+ /**
190
+ * @private
191
+ *
192
+ * @description Close the modal, triggered by 'x' button, passes false to callback function
193
+ * @param {event} e
194
+ */
195
+ function dismissModal(e) {
196
+ return this.dismiss(e, false);
197
+ }
198
+
199
+ /** @private
200
+ *
201
+ * @description Close the modal, triggered by 'esc' key, passes false to callback function
202
+ * @param {event} e
203
+ */
204
+ function closeModalOnEscape(e){
205
+ if(e && e.keyCode === 27) {
206
+ this.dismiss(e, false);
207
+ } else {
208
+ body.addEventListener('click', escHandler, { once: true });
209
+ }
210
+ }
211
+
212
+
213
+ /** @private
214
+ *
215
+ * @description Close the modal, triggered by 'body click, passes false to callback function
216
+ * @param {event} e
217
+ */
218
+ function closeModalOnClick(e){
219
+ if(!Volta._hasClass(e.target, _class.trigger)
220
+ && !Volta._closest(e.target, '.' + _class.trigger, '.' + _class.trigger)
221
+ && !Volta._closest(e.target, '.' + _class.panel, '.' + _class.panel)) {
222
+ this.dismiss(e, false);
223
+ } else if(this.modal) {
224
+ this.modal.addEventListener('click', clickHandler, { once: true });
225
+ }
226
+ }
227
+
228
+ /**
229
+ * @public
230
+ *
231
+ * @description Create the modal object
232
+ * @param {HTMLElement|string} elementOrId Reference to the modal element or the id
233
+ *. @return {Object} A modal object
234
+ */
235
+ function create(elementOrId) {
236
+ if(!body) {
237
+ body = document.querySelector('body');
238
+ }
239
+ var modal = Object.create(Modal.prototype, {})
240
+ modal.init(elementOrId);
241
+ return modal;
242
+ }
243
+
244
+ /**
245
+ * Private functions to disable body scroll when modal is open
246
+ */
247
+ function disableScroll() {
248
+ body.classList.add(_class.bodyModalOpen);
249
+ body.addEventListener('touchmove', preventScroll);
250
+ body.querySelector('main').addEventListener('touchmove', preventScroll);
251
+ body.querySelector('.' + _class.content).addEventListener('touchmove', allowScroll);
252
+ }
253
+
254
+ function enableScroll() {
255
+ body.classList.remove(_class.bodyModalOpen);
256
+ body.removeEventListener('touchmove', preventScroll);
257
+ body.querySelector('main').removeEventListener('touchmove', preventScroll);
258
+ var modalContent = body.querySelector('.' + _class.content);
259
+ if(modalContent) modalContent.removeEventListener('touchmove', allowScroll);
260
+ }
261
+
262
+ function allowScroll(e) {
263
+ e.stopPropagation();
264
+ }
265
+
266
+ function preventScroll(e) {
267
+ e.preventDefault();
268
+ }
269
+
270
+ /**
271
+ * @private
272
+ *
273
+ * @description Remove the modal after dismiss, makes sure to delete the modal properties so it can be garbage collected, and removes event listeners
274
+ * @param {HTMLElement|string} elementOrId Reference to the modal element or the id
275
+ */
276
+ function removeModal(modal) {
277
+ delete modal.modal;
278
+
279
+ if(modal.dismissBtn) {
280
+ modal.dismissBtn.removeEventListener('click', dismissModalHandler);
281
+ }
282
+
283
+ if(modal.cancelBtn) {
284
+ modal.cancelBtn.removeEventListener('click', cancelModalHandler);
285
+ }
286
+
287
+ if(modal.confirmBtn) {
288
+ modal.confirmBtn.removeEventListener('click', confirmModalHandler);
289
+ }
290
+
291
+ if(clickHandler) {
292
+ body.removeEventListener('click', clickHandler);
293
+ }
294
+
295
+ if(escHandler) {
296
+ body.removeEventListener('keyup', escHandler);
297
+ escAttached = false;
298
+ }
299
+ }
300
+ }();
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Copyright (c) 2001-present, Vonage.
3
+ *
4
+ * Tabs (requires core)
5
+ */
6
+
7
+ 'use strict';
8
+
9
+ Volta.tab = function () {
10
+ var _class = {
11
+ link: 'Vlt-tabs__link',
12
+ linkJs: 'Vlt-js-tabs__link',
13
+ linkActive: 'Vlt-tabs__link_active',
14
+ linkDisabled: 'Vlt-tabs__link_disabled',
15
+ linkJsActive: 'Vlt-js-tabs__link_active',
16
+ panel: 'Vlt-tabs__panel',
17
+ panelActive: 'Vlt-tabs__panel_active',
18
+ panelJsActive: 'Vlt-js-tabs__panel_active',
19
+ tabs: 'Vlt-tabs',
20
+ }
21
+
22
+ function Tabs() {}
23
+
24
+ Tabs.prototype = {
25
+ init: function(element, isWrapper) {
26
+ var _this = this,
27
+ tabsHeader,
28
+ tabsContent;
29
+
30
+ if(isWrapper) {
31
+ tabsHeader = element.children.item(0);
32
+ tabsContent = element.children.item(1);
33
+ } else {
34
+ _this.isJs = true;
35
+ tabsHeader = element;
36
+ tabsContent = element.dataset.tabContent ?
37
+ document.querySelector('#' + element.dataset.tabContent)
38
+ : null;
39
+ }
40
+
41
+ var linkClass = _this.isJs ? _class.linkJs : _class.link;
42
+ _this._links = tabsHeader.querySelectorAll('.' + linkClass);
43
+ _this._panels = tabsContent ? tabsContent.children : undefined;
44
+
45
+ this._setActiveElements();
46
+
47
+ if(_this._panels && _this._panels.length === _this._links.length) {
48
+ _this._links.forEach(function(link){
49
+ var link = link;
50
+
51
+ link.addEventListener('toggle', function() {
52
+ _this.toggle(link);
53
+ });
54
+
55
+ link.addEventListener('click', function() {
56
+ _this.toggle(link);
57
+ });
58
+ });
59
+ } else if (_this._panels && _this._panels.length > 0) {
60
+ console.log('Volta: Tabs, number of links and panels do not match');
61
+ }
62
+ },
63
+ toggle: function(linkElement) {
64
+ var linkActiveClass = this.isJs ? _class.linkJsActive : _class.linkActive;
65
+ var panelActiveClass = this.isJs ? _class.panelJsActive : _class.panelActive;
66
+
67
+ if(!Volta._hasClass(linkElement, _class.linkDisabled) && (!this._activeLink || this._activeLink !== linkElement)) {
68
+ if(this._activeLink) {
69
+ this._activeLink.classList.remove(linkActiveClass);
70
+ this._activePanel.classList.remove(panelActiveClass);
71
+ }
72
+
73
+ this._setActiveElements(linkElement);
74
+
75
+ this._activeLink.classList.add(linkActiveClass);
76
+ this._activePanel.classList.add(panelActiveClass);
77
+
78
+ if(Volta.tooltip) {
79
+ Volta.tooltip.init();
80
+ }
81
+ }
82
+ },
83
+ _setActiveElements: function(linkElement){
84
+ var linkActiveClass = this.isJs ? _class.linkJsActive :_class.linkActive;
85
+
86
+ if(!linkElement) {
87
+ this._activeLink = this._links.item(linkActiveClass);
88
+ } else {
89
+ this._activeLink = linkElement;
90
+ }
91
+
92
+ var tabIndex;
93
+ var currentNode = 0;
94
+
95
+ while(!tabIndex && currentNode < this._links.length) {
96
+ if(this._links.item(currentNode) === this._activeLink) {
97
+ tabIndex = currentNode;
98
+ break;
99
+ }
100
+ currentNode++;
101
+ }
102
+
103
+ if(this._panels) {
104
+ this._activePanel = this._panels.item(tabIndex);
105
+ }
106
+ }
107
+ }
108
+
109
+ return {
110
+ create: create,
111
+ init: attachTabHandlers
112
+ }
113
+
114
+ /**
115
+ * @public
116
+ *
117
+ * @description Attach a listener to the tab header
118
+ */
119
+ function attachTabHandlers() {
120
+ //traditional tabs
121
+ document.querySelectorAll('.' + _class.tabs).forEach(create);
122
+
123
+ document.querySelectorAll('[data-tab-content]').forEach(create);
124
+ }
125
+
126
+ /**
127
+ * @public
128
+ *
129
+ * @description Create a tabs component
130
+ * @param {HTMLElement} element
131
+ */
132
+ function create(element) {
133
+ var tabs = Object.create(Tabs.prototype, {})
134
+
135
+ if(Volta._hasClass(element, _class.tabs)) {
136
+ tabs.init(element, true);
137
+ } else {
138
+ tabs.init(element);
139
+ }
140
+
141
+ return tabs;
142
+ }
143
+ }();
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Copyright (c) 2001-present, Vonage.
3
+ *
4
+ * Tooltips (requires popper.js, tooltip.js)
5
+ */
6
+ 'use strict';
7
+
8
+ Volta.tooltip = function () {
9
+ var _class = {
10
+ bottom: 'Vlt-tooltip--bottom',
11
+ left: 'Vlt-tooltip--left',
12
+ tooltip: 'Vlt-tooltip',
13
+ top: 'Vlt-tooltip--top',
14
+ right: 'Vlt-tooltip--right',
15
+ large: 'Vlt-tooltip--large'
16
+ }
17
+
18
+ return {
19
+ create: create,
20
+ init: attachTooltipHandlers
21
+ }
22
+
23
+ /**
24
+ * @public
25
+ *
26
+ * @description Create a Tooltip instance for every Vlt-tooltip
27
+ */
28
+ function attachTooltipHandlers() {
29
+ document.querySelectorAll('.' + _class.tooltip).forEach(create);
30
+ }
31
+
32
+ /**
33
+ * @public
34
+ *
35
+ * @description Create a Tooltip instance
36
+ * @param {HTMLElement} tooltip
37
+ * @return {object} a Tooltip element
38
+ */
39
+ function create(tooltip) {
40
+ var placement;
41
+ var size;
42
+
43
+ if (Volta._hasClass(tooltip, _class.bottom)) {
44
+ placement = 'bottom';
45
+ } else if (Volta._hasClass(tooltip, _class.top)) {
46
+ placement = 'top';
47
+ } else if (Volta._hasClass(tooltip, _class.left)) {
48
+ placement = 'left';
49
+ } else if (Volta._hasClass(tooltip, _class.right)) {
50
+ placement = 'right';
51
+ }
52
+
53
+ if (Volta._hasClass(tooltip, _class.large)) {
54
+ size = ' Vlt-tooltip--large';
55
+ } else {
56
+ size='';
57
+ }
58
+
59
+ var template =
60
+ '<div class="Vlt-tooltip--js' + size + '" role="tooltip">' +
61
+ '<div class="tooltip-arrow Vlt-tooltip__arrow"></div>' +
62
+ '<div class="tooltip-inner Vlt-tooltip__content"></div>' +
63
+ '</div>';
64
+
65
+ var title = tooltip.title;
66
+ //remove the title so deafult title does not show
67
+ tooltip.title = "";
68
+
69
+ return new Tooltip(tooltip, {
70
+ html: true,
71
+ template: template,
72
+ title: title,
73
+ placement: placement
74
+ });
75
+ }
76
+ }();