Skip to content

Instantly share code, notes, and snippets.

@dariuszparys
Created November 9, 2015 13:53
Show Gist options
  • Select an option

  • Save dariuszparys/4fe5267d2a31df4cd52e to your computer and use it in GitHub Desktop.

Select an option

Save dariuszparys/4fe5267d2a31df4cd52e to your computer and use it in GitHub Desktop.
Office365 TaskPane Demo
/// <reference path="../App.js" />
// global app
(function () {
'use strict';
// The initialize function must be run each time a new page is loaded
Office.initialize = function (reason) {
$(document).ready(function () {
app.initialize();
$('#get-data-from-selection').click(getDataFromSelection);
});
};
// Reads data from current document selection and displays a notification
function getDataFromSelection() {
Office.context.document.getSelectedDataAsync(Office.CoercionType.Text,
function (result) {
if (result.status === Office.AsyncResultStatus.Succeeded) {
app.showNotification('The selected text is:', '"' + result.value + '"');
showImages(result.value);
} else {
app.showNotification('Error:', result.error.message);
}
}
);
}
function showImages(selectedText) {
app.showNotification("calling flickr with parameter: " + selectedText);
$('#Images').empty();
$.getJSON("https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=e6ef6867ce3985905c0da90aa0cd76b8&tags=" + selectedText + "&format=json&nojsoncallback=1", function(results) {
app.showNotification("Found " + results.photos.photo.length + " photos");
$("#images").empty();
$.each(results.photos.photo, function( index, item ) {
var url = "https://farm" + item.farm + ".staticflickr.com/" + item.server + "/" + item.id + "_" + item.secret + "_m.jpg";
var img = $("<img>");
img.attr("src", url);
img.appendTo($("#images"));
});
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment