Skip to content

Instantly share code, notes, and snippets.

@videlais
videlais / detectNodeWebkit.js
Last active August 29, 2015 14:05
Node-Webkit Detection
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 August 29, 2015 14:05
Detecting Apache Cordova
<!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 March 16, 2014 20:19
determineFontHeightInPixels -- proposed fix for Pixi.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 March 16, 2014 20:01
determineFontHeight from Pixi.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 March 13, 2014 22:10
Twine: Targeting one link for CSS change
:: 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 February 28, 2014 18:31
Gamepad axis 'moved' function for CocoonJS on the Ouya using a high-precision radial deadzone algorithm
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 January 17, 2020 21:17
No-click Twine (1.4) using jQuery
// 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 January 3, 2016 22:19
Highlighting 'visited' links in Twine
@videlais
videlais / loadJS.js
Created January 19, 2014 00:12
LoadJS Twine Macro
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 December 30, 2013 15:52
Complete 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