This repository has been archived by the owner on Apr 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 127
/
frame-modal.js
85 lines (63 loc) · 2.31 KB
/
frame-modal.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
$.fn.center = function () {
this.css("top", Math.max(( $(window).height() - this.height() ) / 2+$(window).scrollTop(), 10) + "px");
this.css("left", Math.max(( $(window).width() - this.width() ) / 2+$(window).scrollLeft(), 10) + "px");
return this;
};
$(window).resize(function() {
$('.modal:visible').center();
});
function showFrameModal(options) {
var modal = $('#frame-modal');
var top_right = '';
if (options.top_right) {
top_right = '<span style="float:right;padding-top:5px;padding-right:10px;">'+options.top_right+'</a></span>'
}
try {
modal.modal('hide');
modal.remove();
} catch (e) {
console.log(e);
}
var el_name = 'iframe'
//Special case for chrome extension
if (APP_NAME == 'javascript_chrome') {
el_name = 'webview';
}
$('body').append('<div id="frame-modal" class="modal hide"><div class="modal-header"><button type="button" class="close" data-dismiss="modal">×</button>'+top_right+'<h3>'+options.title+'</h3></div><div class="modal-body" style="overflow-y:hidden;"><'+el_name+' border="0" scrolling="auto" style="overflow-y:hidden;border-style:none;"></'+el_name+'></div><div class="modal-footer btn-group">'+options.description+' <a class="btn btn-secondary">Close</a></div></div>');
modal = $('#frame-modal');
modal.modal({
keyboard: true,
backdrop: "static",
show: true
});
var frame = modal.find(el_name);
//For chrome extension
if (el_name == 'webview') {
frame.get(0).addEventListener('newwindow', function(e) {
e.preventDefault();
window.open(e.targetUrl);
});
frame.get(0).addEventListener('permissionrequest', function(e) {
if (e.permission === 'download') {
e.request.allow();
}
});
}
try {
hidePopovers()
} catch(e) {};
if (options.width) {
modal.find('.modal-body').css('width', options.width);
}
if (options.height) {
frame.css('height', options.height);
}
modal.find('.btn.btn-primary').unbind().click(function() {
modal.modal('hide');
});
modal.find('.btn.btn-secondary').unbind().click(function() {
modal.modal('hide');
});
frame.attr('src', options.src);
modal.center();
}