Skip to content

Commit d8a965c

Browse files
committed
Buttons added for inserting images and links into the document in a new paragraph after the current position in the document.
1 parent f60f720 commit d8a965c

6 files changed

Lines changed: 167 additions & 13 deletions

File tree

Code.gs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,73 @@ function inArray( elem, arr, arrKey) {
345345
}
346346

347347
return -1;
348+
}
349+
350+
function insertLink(link, displayName) {
351+
var doc = DocumentApp.getActiveDocument();
352+
var body = doc.getBody();
353+
var paragraphIndex;
354+
355+
var cursor = doc.getCursor();
356+
var paragraph;
357+
358+
if (cursor) {
359+
paragraph = cursor.getElement();
360+
}
361+
362+
var selection = doc.getSelection();
363+
364+
if (selection) {
365+
var selectedElements = selection.getSelectedElements();
366+
var selectedElement = selectedElements[0];
367+
368+
//holds the paragraph
369+
var paragraph = selectedElement.getElement();
370+
}
371+
372+
if (paragraph) {
373+
while (paragraph.getType() !== DocumentApp.ElementType.PARAGRAPH) {
374+
paragraph = paragraph.getParent();
375+
}
376+
377+
//get the index of the paragraph in the body
378+
paragraphIndex = body.getChildIndex(paragraph) + 1;
379+
380+
body.insertParagraph(paragraphIndex, '').appendText(displayName).setLinkUrl(link);
381+
}
382+
}
383+
384+
function insertImage(uri) {
385+
var doc = DocumentApp.getActiveDocument();
386+
var body = doc.getBody();
387+
var img = UrlFetchApp.fetch(uri).getBlob();
388+
var paragraphIndex;
389+
390+
var cursor = doc.getCursor();
391+
var paragraph;
392+
393+
if (cursor) {
394+
paragraph = cursor.getElement();
395+
}
396+
397+
var selection = doc.getSelection();
398+
399+
if (selection) {
400+
var selectedElements = selection.getSelectedElements();
401+
var selectedElement = selectedElements[0];
402+
403+
//holds the paragraph
404+
var paragraph = selectedElement.getElement();
405+
}
406+
407+
if (paragraph) {
408+
while (paragraph.getType() !== DocumentApp.ElementType.PARAGRAPH) {
409+
paragraph = paragraph.getParent();
410+
}
411+
412+
//get the index of the paragraph in the body
413+
paragraphIndex = body.getChildIndex(paragraph) + 1;
414+
415+
body.insertParagraph(paragraphIndex, '').appendInlineImage(img);
416+
}
348417
}

SearchResultList.html

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@
134134
var item = items[i];
135135

136136
var li = $('<li></li>');
137+
var leftColumn = $('<div class="left-column"></div>');
138+
li.append(leftColumn);
139+
var rightColumn = $('<div class="right-column"></div>');
140+
li.append(rightColumn);
137141

138142
// description
139143
var description = item.description;
@@ -146,7 +150,7 @@
146150
// link
147151
var uri = item.documentBadge.uri;
148152
var link = $('<a href="' + uri + '" target="_blank" title="' + description + '"></a>');
149-
li.append(link);
153+
leftColumn.append(link);
150154

151155
// item containers
152156
var contentDiv = $('<div class="result-content"></div>');
@@ -163,6 +167,18 @@
163167
}
164168
contentDiv.append($('<span class="result-title">' + title + '</span>'));
165169

170+
// insert link buttons
171+
var insertAsLinkButton = $(
172+
'<div class="image-button">' +
173+
'<img title="<?!= msg('SEARCH_RESULT_LIST_INSERT_LINK') ?>" src="http://www.dimis.fim.uni-passau.de/eexcess/link.png">' +
174+
'</div>');
175+
insertAsLinkButton.data('uri', uri);
176+
insertAsLinkButton.data('title', title);
177+
insertAsLinkButton.click(function() {
178+
google.script.run.insertLink($(this).data('uri'), $(this).data('title'));
179+
});
180+
rightColumn.append(insertAsLinkButton);
181+
166182
// type
167183
var mediaType = item.mediaType;
168184
if (typeof mediaType === 'undefined' || mediaType === '') {
@@ -176,8 +192,19 @@
176192
var image = item.previewImage;
177193
if (typeof image === 'undefined' || image === '') {
178194
image = "http://eexcess-dev.joanneum.at/eexcess-federated-recommender-web-service-1.0-SNAPSHOT/recommender/getPreviewImage?type=" + mediaType;
179-
} else { // add item to image gallery
195+
} else { // add item to image gallery and insert button
180196
this._addImageToGallery(image, title, uri);
197+
198+
// insert image button
199+
var insertImageButton = $(
200+
'<div class="image-button result-btn-insert-image">' +
201+
'<img title="<?!= msg('SEARCH_RESULT_LIST_INSERT_IMAGE') ?>" src="http://www.dimis.fim.uni-passau.de/eexcess/photo.png">' +
202+
'</div>');
203+
insertImageButton.data('uri', image);
204+
insertImageButton.click(function() {
205+
google.script.run.insertImage($(this).data('uri'));
206+
});
207+
rightColumn.append(insertImageButton);
181208
}
182209
var img = $('<img align="left" class="result-image" mediatype="' + mediaType + '" src="' + image + '"/>');
183210
contentDiv.prepend(img);
@@ -279,23 +306,38 @@
279306
* @param uri recommendation's uri
280307
*/
281308
SearchResultList.prototype._addImageToGallery = function(image, title, uri) {
309+
var div = $('<div class="gallery-item"></div>');
310+
311+
// add image
282312
var link = $('<a title="<?!= msg('SEARCH_RESULT_LIST_TITLE') ?>:\n' + title + '" href="' + uri + '" target="_blank"></a>');
313+
div.append(link);
283314
var img = document.createElement('img');
284315
img.className = 'gallery-img';
285316
link.append(img);
286317

287318
var _this = this;
288319
img.onload = function(){
289320
if (_this._galleryLeftHeight > _this._galleryRightHeight) {
290-
_this._galleryRight.append(link);
321+
_this._galleryRight.append(div);
291322
_this._galleryRightHeight += this.height;
292323
} else {
293-
_this._galleryLeft.append(link);
324+
_this._galleryLeft.append(div);
294325
_this._galleryLeftHeight += this.height;
295326
}
296327
};
297328

298329
img.src = image;
330+
331+
// add insert button
332+
var insertButton = $(
333+
'<div class="image-button gallery-btn-insert-image">' +
334+
'<img title="<?!= msg('SEARCH_RESULT_LIST_INSERT_IMAGE') ?>" src="http://www.dimis.fim.uni-passau.de/eexcess/photo.png">' +
335+
'</div>');
336+
insertButton.data('uri', image);
337+
insertButton.click(function() {
338+
google.script.run.insertImage($(this).data('uri'));
339+
});
340+
div.append(insertButton);
299341
};
300342

301343
/**

Sidebar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<a title="<?!= msg('SEARCH_RESULT_LIST_SCHOLARLY_TOOLTIP') ?>"><?!= msg('SEARCH_RESULT_LIST_SCHOLARLY') ?></a>
2121
</li>
2222
</ul>
23-
<div id="settings-button">
23+
<div id="settings-button" class="image-button">
2424
<img title="<?!= msg('SETTINGS') ?>" src="http://www.dimis.fim.uni-passau.de/eexcess/settings.png">
2525
</div>
2626
</div>

Stylesheet.html

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,41 @@
3939
height: 37px;
4040
}
4141

42-
#settings-button {
42+
.image-button {
4343
background: -webkit-linear-gradient(top, #f5f5f5, #f1f1f1);
4444
background: linear-gradient(top, #f5f5f5, #f1f1f1);
4545
border: 1px solid #dcdcdc;
4646
-moz-border-radius: 2px;
4747
-webkit-border-radius: 2px;
4848
border-radius: 2px;
49-
50-
position: absolute;
51-
right: 12px;
52-
top: 46px;
5349
width: 25px;
5450
height: 25px;
5551
}
5652

57-
#settings-button:hover {
53+
.image-button:hover {
5854
background: -webkit-linear-gradient(top, #f8f8f8, #f1f1f1);
5955
background: linear-gradient(top, #f8f8f8, #f1f1f1);
6056
border: 1px solid #c6c6c6;
57+
cursor: pointer;
6158
}
6259

63-
#settings-button img {
60+
.image-button img {
6461
width: 20px;
6562
height: 20px;
6663
margin: 2.5px;
6764
opacity: 0.7;
6865
}
6966

70-
#settings-button:hover img {
67+
.image-button:hover img {
7168
opacity: 1;
7269
}
7370

71+
#settings-button {
72+
position: absolute;
73+
right: 12px;
74+
top: 46px;
75+
}
76+
7477
/* SearchResultList styling */
7578
.eexcess-tabs {
7679
list-style: none;
@@ -159,6 +162,7 @@
159162
border-collapse: collapse;
160163
width: 260px;
161164
padding: 10px;
165+
min-height: 60px;
162166
}
163167

164168
#result-list li:last-child {
@@ -169,10 +173,23 @@
169173
background-color: #eeeeee;
170174
}
171175

176+
#result-list .left-column {
177+
width: 228px;
178+
float: left;
179+
}
180+
181+
#result-list .right-column {
182+
float: right;
183+
}
184+
172185
#result-list a:hover {
173186
text-decoration: none;
174187
}
175188

189+
.result-btn-insert-image {
190+
margin-top: 5px;
191+
}
192+
176193
.result-content {
177194
display: inline-block;
178195
}
@@ -244,6 +261,28 @@
244261
margin-top: 5px;
245262
}
246263

264+
.gallery-item {
265+
position: relative;
266+
}
267+
268+
.gallery-btn-insert-image {
269+
position: absolute;
270+
bottom: 20px;
271+
margin-left: auto;
272+
margin-right: auto;
273+
left: 0;
274+
right: 0;
275+
display: none;
276+
}
277+
278+
.gallery-item:hover .gallery-btn-insert-image {
279+
display: block;
280+
}
281+
282+
.gallery-item:hover .gallery-img {
283+
opacity: 0.7;
284+
}
285+
247286
/* bottom branding */
248287
.branding-container {
249288
padding-top: 12px;

messages.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"SEARCH_RESULT_LIST_MEDIATYPE_VIDEO": "Video",
2727
"SEARCH_RESULT_LIST_MEDIATYPE_OTHER": "Other",
2828
"SEARCH_RESULT_LIST_MEDIATYPE_UNKNOWN": "Unknown",
29+
"SEARCH_RESULT_LIST_INSERT_LINK": "Insert link",
30+
"SEARCH_RESULT_LIST_INSERT_IMAGE": "Insert image",
2931

3032
"BRANDING_TEXT": "Search digital library content",
3133

messages_de.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"SEARCH_RESULT_LIST_MEDIATYPE_VIDEO": "Video",
2727
"SEARCH_RESULT_LIST_MEDIATYPE_OTHER": "Sonstiges",
2828
"SEARCH_RESULT_LIST_MEDIATYPE_UNKNOWN": "Unbekannt",
29+
"SEARCH_RESULT_LIST_INSERT_LINK": "Link einfügen",
30+
"SEARCH_RESULT_LIST_INSERT_IMAGE": "Bild einfügen",
2931

3032
"BRANDING_TEXT": "Suche digitale Bibliotheksinhalte",
3133

0 commit comments

Comments
 (0)