HTML and CSS Reference
In-Depth Information
Conditional sharing
There might be situations in which an application that shares data is unable to do so. A common
example is when the user is required to select some data in order for the data to be shared.
For example, in the TodoList application it might be wise to require that data is shared only if a
non-empty description has been provided.
You deal with conditional sharing in the handler of the datarequested event. Here's how to modify
the code you previously added to the TodoList.init method to enable the Share source contract:
TodoList.clipboard.addEventListener("datarequested", function (e) {
var currentTask = TodoList.getTaskFromUI();
if (currentTask.description.length === 0) {
e.request.failWithDisplayText("Indicate a description of the task.");
TodoList.shareDataAsHtml(e, currentTask);
TodoList.shareDataAsPlainText(e, currentTask);
The failWithDisplayText method causes the share action to fail. The optional text is displayed to the
user. If you don't provide any help text, then the user will receive a generic message stating that the
application is not currently able to share anything.
programmatic sharing
Using the Charms bar is not the only way to trigger the Share panel. Each application can offer its
own user interface for the user to start the sharing process. For example, you can add a new button to
default.html that sits side by side with the existing Add Task button.
<button id="buttonShare">Share</button>
In TodoList.init , you also add a click handler for the button:
document.getElementById("buttonShare").addEventListener("click", TodoList.
Finally, here's the code for the new function TodoList.shareClick which does the trick of program-
matically displaying the Share panel out of the Charms bar.
TodoList.shareClick = function () {
Search WWH ::

Custom Search