-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code.js
73 lines (66 loc) · 1.79 KB
/
Code.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
function onInstall(e) {
onOpen(e);
}
function onOpen(e) {
SlidesApp.getUi()
.createMenu("Insert Images")
.addItem("Insert Images", "init")
.addToUi();
}
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}
function getHTML() {
return HtmlService.createTemplateFromFile("index.html")
.evaluate()
.setTitle("CC Search");
}
function init() {
var htmlOut = getHTML();
// Display the sidebar
SlidesApp.getUi().showSidebar(htmlOut);
}
function insertImage(url, attribution, numImages, attribLoc) {
var currentSlide = SlidesApp.getActivePresentation()
.getSelection()
.getCurrentPage()
.asSlide();
var numOfSlideGroups = currentSlide.getGroups().length + 1;
if (numOfSlideGroups < numImages) {
numImages = numOfSlideGroups;
}
var offset = numImages * 10 + 10;
var fontSize = 8;
var currentImage = currentSlide.insertImage(url);
var currentImageText;
if (attribLoc.image) {
currentImageText = currentSlide.insertTextBox(attribution);
} else {
currentImageText = currentSlide.insertTextBox(numImages + "*");
}
currentImageText
.getText()
.getTextStyle()
.setFontSize(fontSize)
.setBackgroundColor(0, 0, 0)
.setForegroundColor(255, 152, 0);
var groupList = [currentImage, currentImageText];
currentSlide.group(groupList);
var slideWidth = SlidesApp.getActivePresentation().getPageWidth();
var slideHeight = SlidesApp.getActivePresentation().getPageHeight();
if (attribLoc.footer) {
currentSlide
.insertTextBox(
"[" + numImages + "] " + attribution,
0,
slideHeight - offset,
720,
20
)
.bringToFront()
.getText()
.getTextStyle()
.setFontSize(fontSize)
.setBackgroundColor(255, 152, 0);
}
}