/
iframe.js
68 lines (57 loc) · 2.27 KB
/
iframe.js
1
2
3
4
5
6
7
8
9
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
/* Garrett Seward | @spectralsun | GPLv2 */
/**
* Icinga.Behavior.Iframe
*
* Merges content for containers when iframes are present to prevent reloading.
*/
(function(Icinga, $) {
'use strict';
function Iframe(icinga) {
Icinga.EventListener.call(this, icinga);
}
Iframe.prototype = new Icinga.EventListener();
/**
* Mutates the HTML before it is placed in the DOM after a reload
*
* @param content {string} The content to be rendered
* @param $container {jQuery} The target container
* @param action {string} The URL that caused the reload
* @param autorefresh {bool} Whether the rendering is due to an auto-refresh
*
* @return {string|null} The content to be rendered or null, when nothing should be changed
*/
Iframe.prototype.renderHook = function(content, $container, action, autorefresh) {
if (!autorefresh) {
return content;
} else {
var containerId = $container.attr('id');
if (containerId === 'menu' || containerId === 'application-state') {
return content;
}
}
if (!$container.find('iframe').length) {
return content;
}
var $children = $container.children();
var $contentChildren = $container.find('.content').children();
var $content = $('<div>').html(content);
$content.children().each(function(idx) {
var $child = $(this);
if (!$child.hasClass('content')) {
$($children[idx]).html($child.html());
} else {
$child.children().each(function(contentIdx) {
var $contentChild = $(this);
// All the iframes we use have this class, overwrite any others
if (!$contentChild.hasClass('module-grafana') || $contentChild.hasClass('quick-actions')) {
$($contentChildren[contentIdx]).html($contentChild.html());
}
});
}
});
$container.find('.controls .tabs').after('<div class="tabs-spacer">');
return null;
};
Icinga.Behaviors = Icinga.Behaviors || {};
Icinga.Behaviors.Iframe = Iframe;
}) (Icinga, jQuery);