Skip to content

Instantly share code, notes, and snippets.

View Gr8Gatsby's full-sized avatar
🎯
Focusing

Kevin Hill Gr8Gatsby

🎯
Focusing
View GitHub Profile
if(typeof Windows != 'undefined') {
// Create the picker
var picker = new Windows.ApplicationModel.Contacts.ContactPicker();
picker.desiredFieldsWithContactFieldType.append(Windows.ApplicationModel.Contacts.ContactFieldType.email);
// Open the picker for the user to select a contact
picker.pickContactAsync().done(function (contact) {
if (contact !== null) {
var output = "Selected contact:\n" + contact.displayName;
console.log(output);
} else {
@Gr8Gatsby
Gr8Gatsby / Windows.UI.Notifications.js
Last active September 30, 2020 13:16
Windows.UI.Notifications JavaScript example
if(Windows !== 'undefined' &&
Windows.UI !== 'undefined' &&
Windows.UI.Notifications !== 'undefined') {
var notifications = Windows.UI.Notifications;
//Get the XML template where the notification content will be suplied
var template = notifications.ToastTemplateType.toastImageAndText01;
var toastXml = notifications.ToastNotificationManager.getTemplateContent(template);
//Supply the text to the XML content
var toastTextElements = toastXml.getElementsByTagName("text");
toastTextElements[0].appendChild(toastXml.createTextNode(message));
@Gr8Gatsby
Gr8Gatsby / Windows.UI.Popups.MessageDialog.js
Last active September 10, 2015 16:27
This shows how to create a Windows System prompt.
if(typeof Windows !== 'undefined' &&
typeof Windows.UI !== 'undefined' &&
typeof Windows.UI.Popups !== 'undefined' ) {
// Create the message dialog and set its content
var msg = new Windows.UI.Popups.MessageDialog(message);
// Add commands
msg.commands.append(new Windows.UI.Popups.UICommand("Okay", systemAlertCommandInvokedHandler));
// Set default command
msg.defaultCommandIndex = 0;
// Show the message dialog
@Gr8Gatsby
Gr8Gatsby / Windows.ApplicationModel.Appointments.js
Last active August 29, 2015 14:15
Windows.ApplicationModel.Appointments JavaScript example
if(Windows && Windows.ApplicationModel && Windows.ApplicationModel.Appointments) {}
// Create an Appointment that should be added the user's appointments provider app.
var appointment = new Windows.ApplicationModel.Appointments.Appointment();
// Get the selection rect of the button pressed to add this appointment
var boundingRect = e.srcElement.getBoundingClientRect();
var selectionRect = { x: boundingRect.left, y: boundingRect.top, width: boundingRect.width, height: boundingRect.height };
// ShowAddAppointmentAsync returns an appointment id if the appointment given was added to the user's calendar.
// This value should be stored in app data and roamed so that the appointment can be replaced or removed in the future.
// An empty string return value indicates that the user canceled the operation before the appointment was added.
Windows.ApplicationModel.Appointments.AppointmentManager.showAddAppointmentAsync(appointment, selectionRect, Windows.UI.Popups.Placement.default)
@Gr8Gatsby
Gr8Gatsby / createToast.js
Created June 29, 2015 00:46
This Gist shows how to create a simple toast message on Windows using JavaScript.
function createToast(message, imgUrl, imgAlt) {
// Namespace: Windows.UI.Notifications
if (typeof Windows.UI.Notifications === 'undefined') {
return;
}
// Setup variables for shorthand
var notifications = Windows.UI.Notifications,
templateType = notifications.ToastTemplateType.toastImageAndText01,
templateContent = notifications.ToastNotificationManager.getTemplateContent(templateType),
toastMessage = templateContent.getElementsByTagName('text'),
@Gr8Gatsby
Gr8Gatsby / changeAppTitleBarColors.js
Created June 30, 2015 21:43
This Gist shows how to set the application titlebar colors. There is a helper function that accepts an HTML hexString and converts it to an RGBA color object for Windows.
/*
This function expects two hexStrings and relies on hexStrToRGBA to convert
to a JSON object that represents RGBA for the underlying Windows API to
understand.
Examples of valid values:
setAppBarColors('#FFFFFF','#000000');
setAppBarColors('#FFF','#000');
setAppBarColors('FFFFFF','000000');
setAppBarColors('FFF','000');
@Gr8Gatsby
Gr8Gatsby / SystemBackButton.js
Created June 30, 2015 22:20
This Gist shows you how to integrate with the AppTitleBar Back button for Windows 10 JavaScript Apps.
// Hardcoded Navigation Stack
var navigationStack = [
{ "url": "http://www.bing.com" },
{ "url": "http://www.msn.com" }
]
// GoBack function
function goBack() {
var place = navigationStack.pop();
// TODO: Navigate to place.url;
@Gr8Gatsby
Gr8Gatsby / default.css
Last active August 29, 2015 14:24
This is showing how to use tryEnterFullScreen() from Windows.UI.ViewManagement.ApplicationView.getForCurrentView();
.hide {
display:none;
}
.show {
display:block;
}
.message {
font-family:'Segoe UI', Arial, Helvetica, sans-serif;
@Gr8Gatsby
Gr8Gatsby / toast.js
Last active January 24, 2020 11:09
Create a custom toast message and respond to the activation event recieved from the user selection.
(function () {
"use strict";
function createToast(message, imgUrl, imgAlt) {
// Namespace: Windows.UI.Notifications
if (typeof Windows !== 'undefined' &&
typeof Windows.UI !== 'undefined' &&
typeof Windows.UI.Notifications !== 'undefined') {
// Setup variables for shorthand
var notifications = Windows.UI.Notifications,
Rapid.onResponse(async (res) => {
const main = document.querySelector("main");
if (!res) {
main.innerHTML = "<pre>Response is empty</pre>";
return;
}
const data = await res.json();
main.innerHTML =
`<div> ${data.results[0].name.first} ${data.results[0].name.last} </div>