Skip to content

Instantly share code, notes, and snippets.

@yobennett
Created May 31, 2012 16:38
Show Gist options
  • Save yobennett/2844634 to your computer and use it in GitHub Desktop.
Save yobennett/2844634 to your computer and use it in GitHub Desktop.
Create SecondaryTile in Windows 8 Metro with JavaScript
(function () {
"use strict";
var nav = WinJS.Navigation;
function pin() {
// This demo code comes from
// http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.startscreen.secondarytile.aspx
// Prepare package images for use as the Tile Logo and Small Logo in our tile to be pinned.
var uriLogo = new Windows.Foundation.Uri("ms-resource:images/logo-310x150.png");
var uriSmallLogo = new Windows.Foundation.Uri("ms-resource:images/logo-30x30.png");
// Create a tile to be be pinned.
// During creation of secondary tiles, an application can set additional arguments on the tile
// that will be passed in during activation. These arguments should be meaningful to the application.
// In this example, we'll pass in the date and time that the Secondary Tile was pinned.
var currentTime = new Date();
var TileActivationArguments = "timeTileWasPinned=" + currentTime;
// Specify the short name to display on the tile, the display name, arguments to be passed in
// during activation, attributes regarding how to display the tile by default, and the tile logo.
// Note that you should pick an ID that is descriptive and meaningful to your application.
// In this case, we explicitly code a single ID to focus our attention on the pinning operation.
// TODO Update SecondaryTile initialization for CP2
// ERROR: Could not initialize secondary tile with provided arguments.
var tile = new Windows.UI.StartScreen.SecondaryTile("SecondaryTile.01",
"A Secondary Tile",
"Secondary Tile Sample Secondary Tile",
TileActivationArguments,
Windows.UI.StartScreen.TileOptions.showNameOnLogo,
uriLogo);
// Specify a foreground text value.
// The secondary tile background color over which this text is shown is inherited from the
// parent app unless a separate value is specified.
tile.foregroundText = Windows.UI.StartScreen.ForegroundText.dark;
// The small tile logo is inherited from the parent app unless overridden as we do here.
tile.smallLogo = uriSmallLogo;
// Attempt to pin the tile.
// Note that the status message is updated when the async operation to pin the tile completes.
tile.requestCreateAsync().then(function (isCreated) {
if (isCreated) {
// Secondary tile successfully pinned.
} else {
// Secondary tile not pinned.
}
});
}
WinJS.Namespace.define("Franchise", {
pin: pin
});
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment