Created
November 9, 2015 13:53
-
-
Save dariuszparys/4fe5267d2a31df4cd52e to your computer and use it in GitHub Desktop.
Office365 TaskPane Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <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