Created
August 3, 2012 22:13
-
-
Save ferclaverino/3252058 to your computer and use it in GitHub Desktop.
Pin to a secondary tile
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
(function () { | |
"use strict"; | |
function pinByElementAsync(element, newTileID, newTileShortName, newTileDisplayName, tileActivationArguments) { | |
// Sometimes it's convenient to create our tile and pin it, all in a single asynchronous call. | |
// We're pinning a secondary tile, so let's build up the tile just like we did in pinByElement | |
var uriLogo = new Windows.Foundation.Uri("ms-appx:///images/30x30.png"); | |
//var uriSmallLogo = new Windows.Foundation.Uri("ms-appx:///images/pin/smallLogoSecondaryTile-sdk.png"); | |
var tile = new Windows.UI.StartScreen.SecondaryTile(newTileID, newTileShortName, newTileDisplayName, tileActivationArguments, Windows.UI.StartScreen.TileOptions.showNameOnLogo, uriLogo); | |
tile.foregroundText = Windows.UI.StartScreen.ForegroundText.light; | |
//tile.smallLogo = uriSmallLogo; | |
// Let's place the focus rectangle near the button, just like we did in pinByElement | |
var selectionRect = element.getBoundingClientRect(); | |
// Now let's try to pin the tile. | |
// We'll make the same fundamental call as we did in pinByElement, but this time we'll return a promise. | |
return new WinJS.Promise(function (complete, error, progress) { | |
tile.requestCreateAsync({ x: selectionRect.left, y: selectionRect.top }).done(function (isCreated) { | |
if (isCreated) { | |
// Secondary tile successfully pinned. | |
complete(true); | |
} else { | |
// Secondary tile not pinned. | |
complete(false); | |
} | |
}); | |
}); | |
} | |
function pinSection(element, section, url) { | |
var pinTitle = "Clarín - " + section.NombreSeccion; | |
var pinId = getSectionPinId(section.alias); | |
var pinData = { section: section, url: url } | |
var pinActivationArguments = JSON.stringify(pinData); | |
return pinByElementAsync(element, pinId, pinTitle, pinTitle, pinActivationArguments) | |
} | |
function getSectionPinId(sectionAlias) { | |
return "section." + sectionAlias; | |
} | |
function existPinForSection(section) { | |
return Windows.UI.StartScreen.SecondaryTile.exists(getSectionPinId(section.alias)); | |
} | |
// Export public methods | |
WinJS.Namespace.define("Pin", | |
{ | |
pinSection: pinSection, | |
existPinForSection: existPinForSection | |
} | |
); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment