Created
August 8, 2017 18:13
-
-
Save JuaneloJuanelo/ba040571e5575280ea6daa2ea423fcad to your computer and use it in GitHub Desktop.
create a binding on a selection - Shared with Script Lab
This file contains 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: 'create a binding on a selection ' | |
description: 'create a binding on a selection ' | |
author: JuaneloJuanelo | |
host: WORD | |
api_set: {} | |
script: | |
content: |+ | |
$("#run").click(run); | |
function run() { | |
Word.run(function (context) { | |
//first we get the first word in the selection by using the split method, and using space as delimiter and then we add a content control | |
var firstWordContentControl = context.document.getSelection().split([" "], true, false, true).getFirst().insertContentControl(); | |
firstWordContentControl.title = "BindingID"; | |
return context.sync() | |
.then(function () { | |
Office.context.document.bindings.addFromNamedItemAsync("BindingID", "text", {}, function (result) { | |
console.log(result.status); | |
if (result.status == "succeeded") { | |
// lets create an event! | |
result.value.addHandlerAsync(Office.EventType.BindingSelectionChanged, function () { | |
console.log("event happened"); | |
}) | |
} | |
}); | |
}) | |
}) | |
.catch(function(exception) { | |
OfficeHelpers.Utilities.log(exception); | |
}) | |
} | |
language: typescript | |
template: | |
content: | | |
<button id="run" class="ms-Button"> | |
<span class="ms-Button-label">Run</span> | |
</button> | |
language: html | |
style: | |
content: | | |
/* Your style goes here */ | |
language: css | |
libraries: | | |
# Office.js | |
https://appsforoffice.microsoft.com/lib/1/hosted/office.js | |
# CSS Libraries | |
office-ui-fabric-js@1.4.0/dist/css/fabric.min.css | |
office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css | |
# NPM libraries | |
core-js@2.4.1/client/core.min.js | |
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.min.js | |
jquery@3.1.1 | |
# IntelliSense: @types/library or node_modules paths or URL to d.ts files | |
@types/office-js | |
@types/core-js | |
@microsoft/office-js-helpers@0.7.4/dist/office.helpers.d.ts | |
@types/jquery |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment