function shareReady()

in archived/ShareTarget/js/js/share-target.js [151:279]


    function shareReady() {
        var data = shareOperation.data;

        // Display properties of the data package.
        showProperties();

        // If this app was activated via a QuickLink, display the QuickLinkId
        if (shareOperation.quickLinkId) {
            document.getElementById("selectedQuickLinkId").innerText = shareOperation.quickLinkId;
            document.getElementById("quickLinkArea").className = "hidden";
        }

        // Display the data received based on data type
        var container = document.getElementById("dataPackageContents");

        if (data.contains(StandardDataFormats.text)) {
            data.getTextAsync().done(function (text) {
                addTextContent(container, "Text", text);
            }, function (e) {
                addError(container, "Text", e);
            });
        }
        if (data.contains(StandardDataFormats.webLink)) {
            data.getWebLinkAsync().done(function (webLink) {
                addTextContent(container, "WebLink", webLink.rawUri);
            }, function (e) {
                addError(container, "WebLink", e);
            });
        }
        if (data.contains(StandardDataFormats.applicationLink)) {
            data.getApplicationLinkAsync().done(function (applicationLink) {
                addTextContent(container, "ApplicationLink", applicationLink.rawUri);
            }, function (e) {
                addError(container, "ApplicationLink", e);
            });
        }
        if (data.contains(StandardDataFormats.storageItems)) {
            data.getStorageItemsAsync().done(function (storageItems) {
                var itemCount = storageItems.size;
                // Display info about the first 10 files.
                if (storageItems.size > 10) {
                    storageItems = storageItems.slice(0, 10);
                }
                var fileList = storageItems.map(item => item.name).join(", ");
                if (itemCount > 10) {
                    fileList += ` and ${itemCount - 10} more`;
                }
                addTextContent(container, "Storage Items", fileList);
            }, function (e) {
                addError(container, "Storage Items", e);
            });
        }
        if (data.contains(StandardDataFormats.bitmap)) {
            data.getBitmapAsync().done(function (bitmapStreamReference) {
                addImageContent(container, "Bitmap", bitmapStreamReference, "package-bitmap");
            }, function (e) {
                addError(container, "Bitmap", e);
            });
        }

        if (data.contains(StandardDataFormats.html)) {
            data.getHtmlFormatAsync().done(function (htmlFormat) {
                addTextContent(container, "HTML", "");

                // Extract the HTML fragment from the HTML format
                var htmlFragment = HtmlFormatHelper.getStaticFragment(htmlFormat);

                // Create an iframe and add it to the content.
                var iframe = document.createElement("iframe");
                iframe.style.width = "600px";
                container.appendChild(iframe);

                // Set the innerHTML of the iframe to the HTML fragment
                iframe.contentDocument.documentElement.innerHTML = htmlFragment;

                // Now we loop through any images and use the resourceMap to map each image element's src
                var images = iframe.contentDocument.documentElement.getElementsByTagName("img");
                if (images.length > 0) {
                    data.getResourceMapAsync().done(function (resourceMap) {
                        Array.prototype.forEach.call(images, function (image) {
                            var streamReference = resourceMap[image.src];
                            if (streamReference) {
                                // Call a helper function to map the image element's src to a corresponding blob URL generated from the streamReference
                                setResourceMapURL(streamReference, image);
                            }
                        });
                    }, function (e) {
                        addError(container, "Resource Map", e);
                    });
                }
            }, function (e) {
                addError(container, "HTML", e);
            });
        }

        if (data.contains(customFormatName)) {
            data.getTextAsync(customFormatName).done(function (customFormatString) {
                var customFormatObject = {};
                try {
                    customFormatObject = JSON.parse(customFormatString);
                } catch (e) {
                    // invalid JSON
                }
                // This sample expects the custom format to be of type http://schema.org/Book
                if (customFormatObject.type === "http://schema.org/Book") {
                    var lines = ["Type: " + customFormatObject.type];
                    var properties = customFormatObject.properties;
                    if (properties) {
                        lines.push(
                            `Image: ${properties.image}`,
                            `Name: ${properties.name}`,
                            `Book Format: ${properties.bookFormat}`,
                            `Author: ${properties.author}`,
                            `Number of Pages: ${properties.numberOfPages}`,
                            `Publisher: ${properties.publisher}`,
                            `Date Published: ${properties.datePublished}`,
                            `In Language: ${properties.inLanguage}`,
                            `ISBN: ${properties.isbn}`);
                    }
                    addTextContent(container, "Custom data", lines.join("\n"));
                } else {
                    addError(container, "Custom data", "Malformed data");

                }
            }, function (e) {
                addError(container, "Custom data", e);
            });
        }
    }