Created
April 23, 2018 14:15
-
-
Save robinaar/571e02437bbd8240b14991d5e61165af to your computer and use it in GitHub Desktop.
Performs a basic Word API call using plain JavaScript & Promises. - Shared with Script Lab
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
name: Basic API call (JavaScript) | |
description: Performs a basic Word API call using plain JavaScript & Promises. | |
author: robinaar | |
host: WORD | |
api_set: {} | |
script: | |
content: |- | |
$("#run").click(() => tryCatch(run)); | |
function run() { | |
return Word.run(function (context) { | |
var range = context.document.getSelection(); | |
range.font.color = "blue"; | |
range.load("text"); | |
return context.sync() | |
.then(function() { | |
console.log("The selected text was \"" + range.text + "\"."); | |
}); | |
}); | |
} | |
/** Default helper for invoking an action and handling errors. */ | |
function tryCatch(callback) { | |
Promise.resolve() | |
.then(callback) | |
.catch(function (error) { | |
OfficeHelpers.UI.notify(error); | |
OfficeHelpers.Utilities.log(error); | |
}); | |
} | |
language: typescript | |
template: | |
content: |- | |
<p class="ms-font-m">Executes a simple code snippet</p> | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Run code</span> | |
</button> | |
language: html | |
style: | |
content: |- | |
body { | |
margin: 0; | |
padding: 10px; | |
} | |
/* Button customization, including overwriting some Fabric defaults */ | |
.ms-Button, .ms-Button:focus { | |
background: #2b579a; | |
border: #2b579a; | |
} | |
.ms-Button > .ms-Button-label, | |
.ms-Button:focus > .ms-Button-label, | |
.ms-Button:hover > .ms-Button-label { | |
color: white; | |
} | |
.ms-Button:hover, .ms-Button:active { | |
background: #204072; | |
} | |
.ms-Button.is-disabled, .ms-Button:disabled { | |
background-color: #f4f4f4; | |
border-color: #f4f4f4; | |
} | |
.ms-Button.is-disabled .ms-Button-label, | |
.ms-Button:disabled .ms-Button-label { | |
color: #a6a6a6; | |
} | |
language: css | |
libraries: | | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.d.ts | |
[email protected]/dist/css/fabric.min.css | |
[email protected]/dist/css/fabric.components.min.css | |
[email protected]/client/core.min.js | |
@types/core-js | |
@microsoft/[email protected]/dist/office.helpers.min.js | |
@microsoft/[email protected]/dist/office.helpers.d.ts | |
[email protected] | |
@types/jquery |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment