nexmo-oas-renderer 0.11.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +135 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +92 -72
- data/README.md +8 -0
- data/Rakefile +2 -2
- data/bin/console +3 -3
- data/lib/nexmo/oas/engine.rb +2 -0
- data/lib/nexmo/oas/renderer.rb +5 -5
- data/lib/nexmo/oas/renderer/app.rb +71 -46
- data/lib/nexmo/oas/renderer/config.ru +4 -2
- data/lib/nexmo/oas/renderer/decorators/response_parser_decorator.rb +18 -18
- data/lib/nexmo/oas/renderer/helpers/navigation.rb +2 -2
- data/lib/nexmo/oas/renderer/helpers/render.rb +2 -1
- data/lib/nexmo/oas/renderer/helpers/summary.rb +4 -1
- data/lib/nexmo/oas/renderer/helpers/url.rb +2 -0
- data/lib/nexmo/oas/renderer/presenters/api_specification.rb +2 -1
- data/lib/nexmo/oas/renderer/presenters/endpoint.rb +2 -0
- data/lib/nexmo/oas/renderer/presenters/groups.rb +4 -0
- data/lib/nexmo/oas/renderer/presenters/navigation.rb +2 -0
- data/lib/nexmo/oas/renderer/presenters/open_api_specification.rb +5 -2
- data/lib/nexmo/oas/renderer/presenters/request_body_raw.rb +141 -0
- data/lib/nexmo/oas/renderer/presenters/response_format.rb +4 -2
- data/lib/nexmo/oas/renderer/presenters/response_tab/link.rb +3 -0
- data/lib/nexmo/oas/renderer/presenters/response_tab/panel.rb +8 -5
- data/lib/nexmo/oas/renderer/presenters/response_tabs.rb +6 -2
- data/lib/nexmo/oas/renderer/presenters/versions.rb +11 -10
- data/lib/nexmo/oas/renderer/public/assets/javascripts/components/format.js +12 -7
- data/lib/nexmo/oas/renderer/public/assets/javascripts/nexmo-oas-renderer.js +51 -24
- data/lib/nexmo/oas/renderer/public/assets/javascripts/popper.min.js +5 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/tooltip.min.js +5 -0
- data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.accordion.js +301 -243
- data/lib/nexmo/oas/renderer/public/assets/javascripts/volta.tooltip.js +76 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/nexmo-oas-renderer.css +255 -823
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/nexmo-oas-renderer.css.map +2 -2
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/api.scss +287 -90
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/style.scss +2 -6
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/themes/dark.scss +89 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/themes/light.scss +68 -0
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/volta-prism.min.css +1 -1
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/volta.min.css +1 -1
- data/lib/nexmo/oas/renderer/services/oas_parser.rb +2 -0
- data/lib/nexmo/oas/renderer/services/open_api_definition_resolver.rb +3 -1
- data/lib/nexmo/oas/renderer/version.rb +3 -1
- data/lib/nexmo/oas/renderer/views/layouts/_head.erb +1 -0
- data/lib/nexmo/oas/renderer/views/layouts/_javascripts.erb +5 -4
- data/lib/nexmo/oas/renderer/views/layouts/open_api.erb +3 -1
- data/lib/nexmo/oas/renderer/views/open_api/_auth.erb +74 -0
- data/lib/nexmo/oas/renderer/views/open_api/_available_endpoints.erb +25 -0
- data/lib/nexmo/oas/renderer/views/open_api/_callback_endpoint.erb +18 -27
- data/lib/nexmo/oas/renderer/views/open_api/_callbacks.erb +5 -0
- data/lib/nexmo/oas/renderer/views/open_api/_endpoint.erb +39 -124
- data/lib/nexmo/oas/renderer/views/open_api/_header.erb +71 -0
- data/lib/nexmo/oas/renderer/views/open_api/_model.erb +31 -26
- data/lib/nexmo/oas/renderer/views/open_api/_navigation.erb +54 -78
- data/lib/nexmo/oas/renderer/views/open_api/_parameter_groups.erb +2 -5
- data/lib/nexmo/oas/renderer/views/open_api/_parameters.erb +98 -153
- data/lib/nexmo/oas/renderer/views/open_api/_request_json.erb +4 -0
- data/lib/nexmo/oas/renderer/views/open_api/_request_one_of.erb +70 -0
- data/lib/nexmo/oas/renderer/views/open_api/_request_single.erb +53 -0
- data/lib/nexmo/oas/renderer/views/open_api/_requests.erb +22 -0
- data/lib/nexmo/oas/renderer/views/open_api/_response_description_parameters.erb +88 -90
- data/lib/nexmo/oas/renderer/views/open_api/_response_descriptions.erb +17 -12
- data/lib/nexmo/oas/renderer/views/open_api/_response_fields.erb +1 -16
- data/lib/nexmo/oas/renderer/views/open_api/_response_tabs.erb +2 -2
- data/lib/nexmo/oas/renderer/views/open_api/_responses.erb +35 -0
- data/lib/nexmo/oas/renderer/views/open_api/_tabbed_parameters.erb +15 -4
- data/lib/nexmo/oas/renderer/views/open_api/_tabbed_single_parameter.erb +56 -0
- data/lib/nexmo/oas/renderer/views/open_api/_webhooks.erb +30 -0
- data/lib/nexmo/oas/renderer/views/open_api/show.erb +10 -115
- data/nexmo-oas-renderer.gemspec +26 -26
- metadata +61 -49
- data/lib/nexmo/oas/renderer/public/assets/javascripts/components/scroll.js +0 -21
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/core.scss +0 -137
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/navigation.scss +0 -102
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/nexmo.scss +0 -61
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/syntax.scss +0 -63
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/typography.scss +0 -248
- data/lib/nexmo/oas/renderer/public/assets/stylesheets/sass/volta-templates.scss +0 -119
@@ -0,0 +1,5 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (C) Federico Zivolo 2018
|
3
|
+
Distributed under the MIT License (license terms are at http://opensource.org/licenses/MIT).
|
4
|
+
*/(function(a,b){'object'==typeof exports&&'undefined'!=typeof module?module.exports=b(require('popper.js')):'function'==typeof define&&define.amd?define(['popper.js'],b):a.Tooltip=b(a.Popper)})(this,function(a){'use strict';function b(a){return a&&'[object Function]'==={}.toString.call(a)}a=a&&a.hasOwnProperty('default')?a['default']:a;var c=function(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')},d=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,'value'in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),e=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},f={container:!1,delay:0,html:!1,placement:'top',title:'',template:'<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',trigger:'hover focus',offset:0},g=function(){function g(a,b){c(this,g),h.call(this),b=e({},f,b),a.jquery&&(a=a[0]),this.reference=a,this.options=b;var d='string'==typeof b.trigger?b.trigger.split(' ').filter(function(a){return-1!==['click','hover','focus'].indexOf(a)}):[];this._isOpen=!1,this._popperOptions={},this._setEventListeners(a,d,b)}return d(g,[{key:'_create',value:function(a,b,c,d){var e=window.document.createElement('div');e.innerHTML=b.trim();var f=e.childNodes[0];f.id='tooltip_'+Math.random().toString(36).substr(2,10),f.setAttribute('aria-hidden','false');var g=e.querySelector(this.innerSelector);return this._addTitleContent(a,c,d,g),f}},{key:'_addTitleContent',value:function(a,c,d,e){if(1===c.nodeType||11===c.nodeType)d&&e.appendChild(c);else if(b(c)){var f=c.call(a);d?e.innerHTML=f:e.textContent=f}else d?e.innerHTML=c:e.textContent=c}},{key:'_show',value:function(b,c){if(this._isOpen&&!this._isOpening)return this;if(this._isOpen=!0,this._tooltipNode)return this._tooltipNode.style.display='',this._tooltipNode.setAttribute('aria-hidden','false'),this.popperInstance.update(),this;var d=b.getAttribute('title')||c.title;if(!d)return this;var f=this._create(b,c.template,d,c.html);b.setAttribute('aria-describedby',f.id);var g=this._findContainer(c.container,b);return this._append(f,g),this._popperOptions=e({},c.popperOptions,{placement:c.placement}),this._popperOptions.modifiers=e({},this._popperOptions.modifiers,{arrow:{element:this.arrowSelector},offset:{offset:c.offset}}),c.boundariesElement&&(this._popperOptions.modifiers.preventOverflow={boundariesElement:c.boundariesElement}),this.popperInstance=new a(b,f,this._popperOptions),this._tooltipNode=f,this}},{key:'_hide',value:function(){return this._isOpen?(this._isOpen=!1,this._tooltipNode.style.display='none',this._tooltipNode.setAttribute('aria-hidden','true'),this):this}},{key:'_dispose',value:function(){var a=this;return this._events.forEach(function(b){var c=b.func,d=b.event;a.reference.removeEventListener(d,c)}),this._events=[],this._tooltipNode&&(this._hide(),this.popperInstance.destroy(),!this.popperInstance.options.removeOnDestroy&&(this._tooltipNode.parentNode.removeChild(this._tooltipNode),this._tooltipNode=null)),this}},{key:'_findContainer',value:function(a,b){return'string'==typeof a?a=window.document.querySelector(a):!1===a&&(a=b.parentNode),a}},{key:'_append',value:function(a,b){b.appendChild(a)}},{key:'_setEventListeners',value:function(a,b,c){var d=this,e=[],f=[];b.forEach(function(a){'hover'===a?(e.push('mouseenter'),f.push('mouseleave')):'focus'===a?(e.push('focus'),f.push('blur')):'click'===a?(e.push('click'),f.push('click')):void 0}),e.forEach(function(b){var e=function(b){!0===d._isOpening||(b.usedByTooltip=!0,d._scheduleShow(a,c.delay,c,b))};d._events.push({event:b,func:e}),a.addEventListener(b,e)}),f.forEach(function(b){var e=function(b){!0===b.usedByTooltip||d._scheduleHide(a,c.delay,c,b)};d._events.push({event:b,func:e}),a.addEventListener(b,e)})}},{key:'_scheduleShow',value:function(a,b,c){var d=this;this._isOpening=!0;var e=b&&b.show||b||0;this._showTimeout=window.setTimeout(function(){return d._show(a,c)},e)}},{key:'_scheduleHide',value:function(a,b,c,d){var e=this;this._isOpening=!1;var f=b&&b.hide||b||0;window.setTimeout(function(){if((window.clearTimeout(e._showTimeout),!1!==e._isOpen)&&document.body.contains(e._tooltipNode)){if('mouseleave'===d.type){var f=e._setTooltipNodeEvent(d,a,b,c);if(f)return}e._hide(a,c)}},f)}},{key:'_updateTitleContent',value:function(a){if('undefined'==typeof this._tooltipNode)return void('undefined'!=typeof this.options.title&&(this.options.title=a));var b=this._tooltipNode.parentNode.querySelector(this.innerSelector);this._clearTitleContent(b,this.options.html,this.reference.getAttribute('title')||this.options.title),this._addTitleContent(this.reference,a,this.options.html,b),this.options.title=a,this.popperInstance.update()}},{key:'_clearTitleContent',value:function(a,b,c){1===c.nodeType||11===c.nodeType?b&&a.removeChild(c):b?a.innerHTML='':a.textContent=''}}]),g}(),h=function(){var a=this;this.show=function(){return a._show(a.reference,a.options)},this.hide=function(){return a._hide()},this.dispose=function(){return a._dispose()},this.toggle=function(){return a._isOpen?a.hide():a.show()},this.updateTitleContent=function(b){return a._updateTitleContent(b)},this.arrowSelector='.tooltip-arrow, .tooltip__arrow',this.innerSelector='.tooltip-inner, .tooltip__inner',this._events=[],this._setTooltipNodeEvent=function(b,c,d,e){var f=b.relatedreference||b.toElement||b.relatedTarget;return!!a._tooltipNode.contains(f)&&(a._tooltipNode.addEventListener(b.type,function d(f){var g=f.relatedreference||f.toElement||f.relatedTarget;a._tooltipNode.removeEventListener(b.type,d),c.contains(g)||a._scheduleHide(c,e.delay,e,f)}),!0)}};return g});
|
5
|
+
//# sourceMappingURL=tooltip.min.js.map
|
@@ -4,246 +4,304 @@
|
|
4
4
|
* Accordions (requires core)
|
5
5
|
*/
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
Volta.accordion = function () {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
7
|
+
"use strict";
|
8
|
+
|
9
|
+
Volta.accordion = (function () {
|
10
|
+
var _class = {
|
11
|
+
standard: {
|
12
|
+
container: "Vlt-accordion",
|
13
|
+
containerGroup: "Vlt-accordion--group",
|
14
|
+
trigger: "Vlt-accordion__trigger",
|
15
|
+
triggerActive: "Vlt-accordion__trigger_active",
|
16
|
+
content: "Vlt-accordion__content",
|
17
|
+
contentOpen: "Vlt-accordion__content_open",
|
18
|
+
contentOpening: "Vlt-accordion__content_opening",
|
19
|
+
contentClosing: "Vlt-accordion__content_closing",
|
20
|
+
},
|
21
|
+
js: {
|
22
|
+
content: "Vlt-js-accordion__content",
|
23
|
+
contentOpen: "Vlt-js-accordion__content_open",
|
24
|
+
contentOpening: "Vlt-js-accordion__content_opening",
|
25
|
+
contentClosing: "Vlt-js-accordion__content_closing",
|
26
|
+
trigger: "Vlt-js-accordion__trigger",
|
27
|
+
triggerActive: "Vlt-js-accordion__trigger_active",
|
28
|
+
},
|
29
|
+
};
|
30
|
+
|
31
|
+
function Accordion() {}
|
32
|
+
|
33
|
+
Accordion.prototype = {
|
34
|
+
init: function (element, suppressClickHandler, triggerElem) {
|
35
|
+
if (this.isStandard) {
|
36
|
+
this._initStandard(element, suppressClickHandler);
|
37
|
+
} else {
|
38
|
+
this._initJs(element, suppressClickHandler, triggerElem);
|
39
|
+
}
|
40
|
+
},
|
41
|
+
_initStandard: function (element, suppressClickHandler) {
|
42
|
+
var self = this;
|
43
|
+
|
44
|
+
if (!suppressClickHandler) {
|
45
|
+
element
|
46
|
+
.querySelectorAll("." + _class.standard.trigger)
|
47
|
+
.forEach(function (trigger) {
|
48
|
+
var parent = Volta._closest(
|
49
|
+
trigger,
|
50
|
+
"." + _class.standard.container,
|
51
|
+
_class.standard.container
|
52
|
+
);
|
53
|
+
|
54
|
+
if (parent && parent == element) {
|
55
|
+
trigger.addEventListener("click", function () {
|
56
|
+
self.toggle(trigger);
|
57
|
+
});
|
58
|
+
trigger.addEventListener("toggle", function () {
|
59
|
+
self.toggle(trigger);
|
60
|
+
});
|
61
|
+
}
|
62
|
+
});
|
63
|
+
}
|
64
|
+
},
|
65
|
+
_initJs: function (element, suppressClickHandler, triggerElem) {
|
66
|
+
this._content = element;
|
67
|
+
|
68
|
+
if (triggerElem) {
|
69
|
+
this.trigger = triggerElem;
|
70
|
+
} else if (this._content.dataset.trigger) {
|
71
|
+
var triggerId = this._content.dataset.trigger;
|
72
|
+
this.trigger = document.querySelector("#" + triggerId);
|
73
|
+
} else {
|
74
|
+
console.warn("Volta: js accordion trigger missing");
|
75
|
+
}
|
76
|
+
|
77
|
+
var self = this;
|
78
|
+
if (!suppressClickHandler && this.trigger) {
|
79
|
+
this.trigger.addEventListener("click", function () {
|
80
|
+
self.toggle();
|
81
|
+
});
|
82
|
+
}
|
83
|
+
},
|
84
|
+
close: function (trigger) {
|
85
|
+
var panel = this._content || trigger.nextElementSibling;
|
86
|
+
var trigger = this.trigger || trigger;
|
87
|
+
var classes = this.trigger ? _class.js : _class.standard;
|
88
|
+
|
89
|
+
trigger.classList.remove(classes.triggerActive);
|
90
|
+
panel.classList.add(classes.contentClosing);
|
91
|
+
|
92
|
+
panel.style.height = window.getComputedStyle(panel).height;
|
93
|
+
panel.offsetHeight; // force repaint
|
94
|
+
panel.style.height = "0px";
|
95
|
+
panel.classList.remove(classes.contentOpen);
|
96
|
+
|
97
|
+
var self = this;
|
98
|
+
panel.addEventListener(
|
99
|
+
"transitionend",
|
100
|
+
function closingTransitionEndEvent(event) {
|
101
|
+
if (
|
102
|
+
event.propertyName == "height" &&
|
103
|
+
Volta._hasClass(panel, classes.contentClosing)
|
104
|
+
) {
|
105
|
+
panel.classList.remove(classes.contentClosing);
|
106
|
+
panel.style.height = "0px";
|
107
|
+
panel.removeEventListener(
|
108
|
+
"transitionend",
|
109
|
+
closingTransitionEndEvent,
|
110
|
+
false
|
111
|
+
);
|
112
|
+
|
113
|
+
if (self.isGroup && self._isTriggerActive(trigger, true)) {
|
114
|
+
self._activeGroupTrigger = undefined;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
},
|
118
|
+
{ passive: true, once: true }
|
119
|
+
);
|
120
|
+
},
|
121
|
+
isOpening: false,
|
122
|
+
_activeGroupTrigger: undefined,
|
123
|
+
_isTriggerActive: function (trigger, match) {
|
124
|
+
return (
|
125
|
+
(this.isGroup &&
|
126
|
+
this._activeGroupTrigger &&
|
127
|
+
(!match || this._activeGroupTrigger === trigger)) ||
|
128
|
+
Volta._hasClass(trigger, _class.standard.triggerActive)
|
129
|
+
);
|
130
|
+
},
|
131
|
+
open: function (trigger) {
|
132
|
+
if (!this.trigger) {
|
133
|
+
if (this._isTriggerActive(trigger, false)) {
|
134
|
+
this.close(this._activeGroupTrigger || trigger);
|
135
|
+
}
|
136
|
+
if (this.isGroup) {
|
137
|
+
this._activeGroupTrigger = trigger;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
var trig = this.trigger || trigger;
|
142
|
+
var classes = this.trigger ? _class.js : _class.standard;
|
143
|
+
var panel = this._content || trig.nextElementSibling;
|
144
|
+
|
145
|
+
this.isOpening = true;
|
146
|
+
|
147
|
+
trig.classList.add(classes.triggerActive);
|
148
|
+
panel.classList.add(classes.contentOpening);
|
149
|
+
|
150
|
+
var startHeight = panel.style.height;
|
151
|
+
panel.style.height = "auto";
|
152
|
+
var endHeight = window.getComputedStyle(panel).height;
|
153
|
+
panel.style.height = startHeight;
|
154
|
+
panel.offsetHeight; // force repaint
|
155
|
+
panel.style.height = endHeight;
|
156
|
+
|
157
|
+
var self = this;
|
158
|
+
panel.addEventListener(
|
159
|
+
"transitionend",
|
160
|
+
function openingTransitionEndEvent(event) {
|
161
|
+
if (
|
162
|
+
event.propertyName == "height" &&
|
163
|
+
Volta._hasClass(panel, classes.contentOpening)
|
164
|
+
) {
|
165
|
+
panel.style.height = "auto";
|
166
|
+
panel.classList.remove(classes.contentOpening);
|
167
|
+
panel.classList.add(classes.contentOpen);
|
168
|
+
panel.removeEventListener(
|
169
|
+
"transitionend",
|
170
|
+
openingTransitionEndEvent,
|
171
|
+
false
|
172
|
+
);
|
173
|
+
self.isOpening = false;
|
174
|
+
}
|
175
|
+
},
|
176
|
+
{ passive: true, once: true }
|
177
|
+
);
|
178
|
+
},
|
179
|
+
toggle: function (trigger) {
|
180
|
+
if (this.isOpening) {
|
181
|
+
return false;
|
182
|
+
}
|
183
|
+
if (
|
184
|
+
(this.trigger &&
|
185
|
+
Volta._hasClass(this._content, _class.js.contentOpen)) ||
|
186
|
+
(!this.trigger && this._isTriggerActive(trigger, true))
|
187
|
+
) {
|
188
|
+
this.close(trigger);
|
189
|
+
} else {
|
190
|
+
this.open(trigger);
|
191
|
+
}
|
192
|
+
},
|
193
|
+
};
|
194
|
+
|
195
|
+
return {
|
196
|
+
create: create,
|
197
|
+
init: initialise,
|
198
|
+
};
|
199
|
+
|
200
|
+
/**
|
201
|
+
* @public
|
202
|
+
*
|
203
|
+
* @description Create an individual accordion object
|
204
|
+
* @param {Element|string} elementOrId Reference to the accordion content element or the id
|
205
|
+
* @param {Boolean} suppressClickHandler Whether click events should be attached on creation
|
206
|
+
* @param {Element} trigger Private required for legacy accordions
|
207
|
+
* @param {Boolean} isGroup Private required for legacy accordions
|
208
|
+
* @return {Object}
|
209
|
+
*/
|
210
|
+
function create(
|
211
|
+
elementOrId,
|
212
|
+
suppressClickHandler,
|
213
|
+
trigger,
|
214
|
+
isGroup,
|
215
|
+
isStandard
|
216
|
+
) {
|
217
|
+
if (!elementOrId) {
|
218
|
+
console.warn("Volta: no parameter supplied to accordion.create()");
|
219
|
+
}
|
220
|
+
var accordion = Object.create(Accordion.prototype, {});
|
221
|
+
var element = getElement(elementOrId);
|
222
|
+
|
223
|
+
Object.defineProperties(accordion, {
|
224
|
+
isStandard: {
|
225
|
+
value:
|
226
|
+
isStandard || Volta._hasClass(element, _class.standard.container),
|
227
|
+
writable: false,
|
228
|
+
},
|
229
|
+
});
|
230
|
+
|
231
|
+
Object.defineProperties(accordion, {
|
232
|
+
isGroup: {
|
233
|
+
value: isGroup,
|
234
|
+
writable: false,
|
235
|
+
},
|
236
|
+
});
|
237
|
+
|
238
|
+
accordion.init(element, suppressClickHandler, trigger);
|
239
|
+
|
240
|
+
return accordion;
|
241
|
+
}
|
242
|
+
|
243
|
+
/**
|
244
|
+
* @public
|
245
|
+
*
|
246
|
+
* @description Initialise all the accordions on the current screen
|
247
|
+
*/
|
248
|
+
function initialise() {
|
249
|
+
//standard
|
250
|
+
var standardAccordions = document.querySelectorAll(
|
251
|
+
"." + _class.standard.container
|
252
|
+
);
|
253
|
+
|
254
|
+
if (standardAccordions.length) {
|
255
|
+
standardAccordions.forEach(function (accordion) {
|
256
|
+
create(
|
257
|
+
accordion,
|
258
|
+
false,
|
259
|
+
null,
|
260
|
+
Volta._hasClass(accordion, _class.standard.containerGroup),
|
261
|
+
true
|
262
|
+
);
|
263
|
+
});
|
264
|
+
}
|
265
|
+
|
266
|
+
//js
|
267
|
+
var triggers = document.querySelectorAll(
|
268
|
+
"." + _class.js.trigger + "[data-accordion]"
|
269
|
+
);
|
270
|
+
if (triggers.length > 0) {
|
271
|
+
triggers.forEach(function (trigger) {
|
272
|
+
var accordionId = trigger.dataset.accordion;
|
273
|
+
if (!accordionId) {
|
274
|
+
return;
|
275
|
+
}
|
276
|
+
create(accordionId, false, trigger);
|
277
|
+
});
|
278
|
+
}
|
279
|
+
|
280
|
+
//js - legacy
|
281
|
+
var jsAccordions = document.querySelectorAll(
|
282
|
+
"." + _class.js.content + "[data-trigger]"
|
283
|
+
);
|
284
|
+
if (jsAccordions.length > 0) {
|
285
|
+
jsAccordions.forEach(function (jsLegacy) {
|
286
|
+
create(jsLegacy);
|
287
|
+
});
|
288
|
+
}
|
289
|
+
}
|
290
|
+
|
291
|
+
/**
|
292
|
+
* @private
|
293
|
+
*/
|
294
|
+
function getElement(elementOrId) {
|
295
|
+
var element;
|
296
|
+
|
297
|
+
if (elementOrId.classList) {
|
298
|
+
element = elementOrId;
|
299
|
+
} else if (elementOrId.substring(0, 1) === "#") {
|
300
|
+
element = document.querySelector(elementOrId);
|
301
|
+
} else {
|
302
|
+
element = document.querySelector("#" + elementOrId);
|
303
|
+
}
|
304
|
+
|
305
|
+
return element;
|
306
|
+
}
|
307
|
+
})();
|