This repository has been archived by the owner on Nov 25, 2024. It is now read-only.
forked from ryanramage/garden
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpopup.js
66 lines (60 loc) · 1.75 KB
/
popup.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
var templates = require('handlebars').templates;
var id_counter = 0;
exports.resize = function (el, options) {
$('.note', el).css({
width: options.width + 'px',
height: (options.height - 20) + 'px',
marginLeft: (0 - options.width/2) + 'px',
marginTop: (0 - options.height/2 + 20) + 'px'
});
$('.note-top', el).css({
width: (options.width - 19) + 'px',
marginLeft: (0 - options.width/2) + 'px',
marginTop: (0 - options.height/2) + 'px'
});
$('.note-corner', el).css({
marginLeft: (options.width/2 - 19) + 'px',
marginTop: (0 - options.height/2 + 1) + 'px'
});
$('.note-corner-border', el).css({
marginLeft: (options.width/2 - 18) + 'px',
marginTop: (0 - options.height/2) + 'px'
});
$('.note-inner', el).css({
height: (options.height - 20) + 'px'
});
$('.note-actions', el).css({
width: (options.width - 20) + 'px'
});
};
exports.open = function (req, options) {
if (!options) {
throw new Error("missing options");
}
if (!options.width) {
throw new Error("missing options.width");
}
if (!options.height) {
throw new Error("missing options.height");
}
var el = $(templates.render('popup.html', req, {
options: options
}));
el.attr('id', 'popup' + id_counter);
id_counter++;
$('.closebtn', el).click(function (ev) {
ev.preventDefault();
exports.close(el);
return false;
});
exports.resize(el, options);
$('.note-inner', el).html(options.content || '');
$('body').append(el);
return el;
};
exports.close = function (el) {
el.remove();
};
exports.closeAll = function () {
$('.note-container').remove();
};