Skip to content

Instantly share code, notes, and snippets.

@seksenov
Last active March 4, 2016 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seksenov/9ef2d8a3211918f0696f to your computer and use it in GitHub Desktop.
Save seksenov/9ef2d8a3211918f0696f to your computer and use it in GitHub Desktop.
function showToast () {
console.log("yo");
var notifications = Windows.UI.Notifications,
templateType = notifications.ToastTemplateType.toastImageAndText02,
templateContent = notifications.ToastNotificationManager.getTemplateContent(templateType),
toastMessage = templateContent.getElementsByTagName('text'),
toastImage = templateContent.getElementsByTagName('image'),
toastElement = templateContent.selectSingleNode('/toast');
console.log("here");
var launchParams = {
type: 'toast',
id: 'demoToast',
heading: 'Demo title',
body: 'Demo message'
};
console.log("here2");
var launchString = JSON.stringify(launchParams);
// Set message & image in toast template
toastMessage[0].appendChild(templateContent.createTextNode('Demo message'));
toastImage[0].setAttribute('src', 'https://unsplash.it/150/?random');
toastImage[0].setAttribute('alt', 'Random sample image');
toastElement.setAttribute('duration', 'long');
toastElement.setAttribute('launch', launchString); // Optional Launch Parameter
// Add actions
var actions = templateContent.createElement('actions');
templateContent.firstChild.appendChild(actions);
// Create an input box
var input = templateContent.createElement('input');
input.setAttribute('type', 'text');
input.setAttribute('title', 'Reply with');
input.setAttribute('id', 'textReply');
actions.appendChild(input);
// Create a yes button
var btnYes = templateContent.createElement('action');
btnYes.setAttribute('content', 'Yes');
btnYes.setAttribute('arguments', 'yes');
btnYes.setAttribute('launchType', 'foreground');
actions.appendChild(btnYes);
//Create a no button
var btnNo = templateContent.createElement('action');
btnNo.setAttribute('content', 'No');
btnNo.setAttribute('arguments', 'no');
btnNo.setAttribute('launchType', 'foreground');
actions.appendChild(btnNo);
// Show the toast
var toast = new notifications.ToastNotification(templateContent);
var toastNotifier = new notifications.ToastNotificationManager.createToastNotifier();
toast.tag = 'demoToast';
console.log(toast);
toastNotifier.show(toast);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment