Skip to content

Instantly share code, notes, and snippets.

@DigiTec
DigiTec / ImportWebSiteToWWA.cs
Created November 6, 2012 06:59
Imports files from a web site project into a WWA application to enable deploying to both without copying files.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.IO;
public class ImportWebSiteToWWA
{
private static void Main(string[] args)
{
@DigiTec
DigiTec / UnsafeOverride.js
Created November 7, 2012 07:08
Polyfills unsafe functions in WWA so you can inject any content you want without security exceptions
"use strict";
if (window.MSApp && window.MSApp.execUnsafeLocalFunction) {
(function () {
var _originalWrite = Document.prototype.write;
var _originalWriteln = Document.prototype.writeln;
Object.defineProperties(Document.prototype, {
write: {
value: function write() {
@DigiTec
DigiTec / PackImages.cs
Created November 26, 2012 06:40
CSS Image Sprite Packer
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
public class PackImagesApplication
{
private static string cssFormat =
@DigiTec
DigiTec / PolyfillTransform.js
Created November 28, 2012 03:59
Quick and optimized poly-fill for transform that has fallbacks for IE 9 and WebKit based browsers.
(function () {
if (CSSStyleDeclaration.prototype.hasOwnProperty("transform")) {
}
else if (CSSStyleDeclaration.prototype.hasOwnProperty("msTransform")) {
Object.defineProperties(CSSStyleDeclaration.prototype, {
transform: {
get: function get_transform() {
return this.msTransform;
},
set: function set_transform(transform) {
@DigiTec
DigiTec / ServiceWrapper.js
Created December 2, 2012 04:21
A sample service wrapper that I'm using for wrapping all of my GET based Azure services.
"use strict";
if (typeof(Services) === "undefined")
{
Object.defineProperties(this, {
Services: {
value: {},
configurable: false,
writable: false
}
@DigiTec
DigiTec / ResourceTimingArbiter.js
Created December 16, 2012 00:35
Utilize the new PerformanceResourceTiming specification in order to figure out programmatically which resources in your website are misnamed by case only. This can help reduce redundant requests. This is a first crack at the API and only limited testing has been done. There may be URL canonicalization steps that could be made and restriction of …
"use strict";
Object.defineProperties(this, {
"ResourceTimingArbiter": {
value: (function () {
var _oldResources = [];
var _allDupes = [];
var _resourceArbiter = {};
var _escape = function(str) {
return "".replace.call(str, /[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
@DigiTec
DigiTec / LightDarkColorPicker.html
Last active December 10, 2015 07:58
A simple gist for picking lighter and darker colors based on a current color. Outputs the values in hex, rgb, and rgba for direct use in your CSS. This is inspired by a task I had to pick a darker background color for a UI element so that it would stand out on top of a lighter background. The elements still needed to be themed to their color pro…
<!-- saved from url=(0014)about:internet -->
<!DOCTYPE HTML>
<script>
function Color(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
}
Object.defineProperties(Color, {
colorFromHex: {
@DigiTec
DigiTec / DomMeasureText.js
Last active December 14, 2015 04:19
This Gist uses a cached, hidden div in order to measure height/width of text. Imperfect since I'm still technically inheriting styles through the body that could affect my offsetWidth and offsetHeight but most likely a better approximation than measuring the width of the "M" character which is often a suggestion when dealing with the lack of hei…
(function () {
var _cachedDiv;
function domMeasureText(text, font) {
if (!_cachedDiv) {
_cachedDiv = document.createElement("div");
_cachedDiv.style.visibility = "hidden";
_cachedDiv.style.position = "absolute";
document.body.appendChild(_cachedDiv);
}
@DigiTec
DigiTec / PrivacyPolicy.js
Created March 11, 2013 01:51
Add a privacy policy to your Windows 8 based WWA. Note, all of the samples utilized WinJS and I needed a non WinJS version. I don't claim in any way this is novel, but it took me nearly an hour to pull this together since there were no fully baked samples.
var settingsPane = Windows.UI.ApplicationSettings.SettingsPane.getForCurrentView();
settingsPane.addEventListener("commandsrequested", foo);
function foo(args) {
var cmdPrivacy = new Windows.UI.ApplicationSettings.SettingsCommand("privacy", "Privacy Policy", privacyPolicyInvoked);
args.request.applicationCommands.push(cmdPrivacy);
}
function privacyPolicyInvoked(args) {
switch (args.id) {
@DigiTec
DigiTec / ClassList.js
Last active December 23, 2015 03:39
This is a short polyfill to add classList support to SVG in Internet Explorer. It takes advantage of the duck typing of property and method implementations to be able to simply move the existing property descriptor from HTMLElement up to Element. Note that FIreFox already puts their implementation on Element. And Chrome uses instance properties …
"use strict";
// IE supports duck typed classList so move it from HTMLElement to Element to support SVG.
// FireFox already has classList on Element so make sure not to tweak anything there.
// Chrome supports classList on every element, but as an instance property so no need to move anything there.
(function _initClassListPolyFill() {
if (!Element.prototype.hasOwnProperty("classList") && HTMLElement.prototype.hasOwnProperty("classList")) {
Object.defineProperty(Element.prototype, "classList", Object.getOwnPropertyDescriptor(HTMLElement.prototype, "classList"));
}