-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateLiteContainer.js
50 lines (44 loc) · 1.54 KB
/
generateLiteContainer.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
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.type == "generateLiteContainer_pageAction") {
generateLiteContainer(clicked_item);
}
if (request.type == "generateLiteContainer_context") {
generateLiteContainer(rightclicked_item);
}
});
function generateLiteContainer(item) {
// In some cases, we are not the correct frame ;-)
if (item == null) {
return;
}
var textbox = $(item);
$.post("http://collabeverywhere.net/publicapi/0/createPad", { "text" : textbox.val() }, function (data) {
var padURL = data.data.host + data.data.baseUrl + data.data.padID;
var frame = $("<iframe>") .attr("src", padURL + "?showControls=false")
.css("border", "0px")
.attr("height", "100%")
.attr("width", "100%");
var button = $("<button>") .text(chrome.i18n.getMessage("cancelButtonLabel"));
var linkText = $("<input>") .attr("type", "text")
.val(padURL)
.click(function() {$(this).select();});
var control = $("<div>") .append(button).append(linkText).append(frame)
.addClass("control")
.attr("height", textbox.height())
.attr("width", textbox.width());
textbox.parent("form").submit(function() {
if ($(this).find(".hiddenTextbox").size() > 0) {
alert(chrome.i18n.getMessage("padsStillOpen"));
return false;
}
});
button.click(function () {
$.get(padURL + "/export/txt", function (text) {
textbox.val(text);
});
textbox.removeClass("hiddenTextbox");
control.detach();
});
textbox.addClass("hiddenTextbox").after(control);
}, "json");
}