Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Cox videlais

View GitHub Profile
@videlais
videlais / detectNodeWebkit.js
Last active Aug 29, 2015
Node-Webkit Detection
View detectNodeWebkit.js
var isNode = (typeof process !== "undefined" && typeof require !== "undefined");
var isNodeWebkit = false;
//Is this Node.js?
if(isNode) {
//If so, test for Node-Webkit
try {
isNodeWebkit = (typeof require('nw.gui') !== "undefined");
} catch(e) {
isNodeWebkit = false;
@videlais
videlais / deviceEvent.html
Last active Aug 29, 2015
Detecting Apache Cordova
View deviceEvent.html
<!DOCTYPE html>
<html>
<head>
<title>Device Ready Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for device API libraries to load
//
@videlais
videlais / determineFontHeightInPixels.js
Created Mar 16, 2014
determineFontHeightInPixels -- proposed fix for Pixi.js
View determineFontHeightInPixels.js
/*
* http://stackoverflow.com/posts/13730758/revisions
*
* @method determineFontHeightInPixels
* @param fontStyle {String}
* @private
*/
PIXI.Text.prototype.determineFontHeightInPixels = function(fontStyle)
{
var result = PIXI.Text.heightCache[fontStyle];
@videlais
videlais / fontHeight.js
Created Mar 16, 2014
determineFontHeight from Pixi.js
View fontHeight.js
/* @license
* pixi.js - v1.5.1
* Copyright (c) 2012-2014, Mat Groves
* http://goodboydigital.com/
*
* pixi.js is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license.php
*
* http://stackoverflow.com/users/34441/ellisbben
* great solution to the problem!
@videlais
videlais / oneLinkCSS.twee
Created Mar 13, 2014
Twine: Targeting one link for CSS change
View oneLinkCSS.twee
:: Start
Your story will display this passage first. Edit it by double clicking it.
[[Passage]]
:: Passage
[[PassageName]]
More text not affected any changes.
@videlais
videlais / gamepad.js
Created Feb 28, 2014
Gamepad axis 'moved' function for CocoonJS on the Ouya using a high-precision radial deadzone algorithm
View gamepad.js
Phaser.Plugin.CocoonJSOuyaGamepad.prototype.moved = function(pad, axisId) {
var movedAmount = 0;
var magitudeLeft = 0;
var magitudeRight = 0;
if (_gamepads[pad]) {
magitudeLeft = Math.sqrt((_gamepads[pad].axes[0] * _gamepads[pad].axes[0]) +
(_gamepads[pad].axes[1] * _gamepads[pad].axes[1]));
magitudeRight = Math.sqrt((_gamepads[pad].axes[2] * _gamepads[pad].axes[2]) +
(_gamepads[pad].axes[3] * _gamepads[pad].axes[3]));
if (axisId === "AXIS_0" && _gamepads[pad].axes[0] <= 1) {
@videlais
videlais / noclickjQueryTwine.js
Last active Jan 17, 2020
No-click Twine (1.4) using jQuery
View noclickjQueryTwine.js
// First, create a reference to the Wikifier.createInternalLink function.
// (Internally, this is what Twine uses to connect passages together.
// It is the last step in parsing double-bracked content into links.)
var oldCreateInternalLink = Wikifier.createInternalLink;
// Then, create a new function that mimics its functionality.
Wikifier.createInternalLink = function(place, title) {
// By calling the old function, it returns
// the DOM element (the link) it was about to
@videlais
videlais / visitedLinks.js
Last active Jan 3, 2016
Highlighting 'visited' links in Twine
View visitedLinks.js
@videlais
videlais / loadJS.js
Created Jan 19, 2014
LoadJS Twine Macro
View loadJS.js
macros['loadJS'] =
{
handler: function(place, object, parameters)
{
var se = document.createElement("script");
se.type = 'text/javascript';
se.src = parameters[0];
var hT = document.getElementsByTagName("HEAD")[0];
hT.appendChild(se);
if(se.innerText) {eval(se.innerText);}
@videlais
videlais / geolocation.js
Created Dec 30, 2013
Complete Geolocation.js
View geolocation.js
/*
* A Geolocation object
*
* Note: Uses GPS or similar hardware for data if available through
* the browser, but will fall back to using (Google) geolocation
* services with current IP address automatically.
*
* @property {boolean} supported If the geolocation functions are available in the current context
* @property {function} onsuccess The function to be called if the geolocation services are successful
* @property {function} onerror The function to be called if an error occurs
You can’t perform that action at this time.