Skip to content

Instantly share code, notes, and snippets.

View digitarald's full-sized avatar
🏳️‍🌈

Harald Kirschner digitarald

🏳️‍🌈
View GitHub Profile
@digitarald
digitarald / build.coffee
Created May 1, 2012 20:54
Building require.js
requirejs = require('requirejs')
jspath = __dirname + '/views/scripts';
requirejs.optimize(
baseUrl: jspath
wrap:
start: ';(function(undefined) { "use strict";'
end: '}).call(this);'
class Pubsub
constructor: ->
@topics = []
@scopes = []
@methods = []
acquire: (host) ->
@acquired = true
host.pubsub = @
@digitarald
digitarald / bookmarklet.url
Created September 14, 2012 00:11
Bookmarklet mozApps.install and launch - Reads manifest from text selection or current URL
javascript:(function(a,b){if(/\/$/.test(b))b+="manifest.webapp";var c=a.install(b);c.onsuccess=c.onerror=function(){if(c.error)alert(b+"/n"+c.error.name);else c.result.launch()}})(navigator.mozApps,(getSelection().toString()||location.href).trim());
@digitarald
digitarald / manifest.webapp
Created September 17, 2012 21:27
Remix this App Manifest!
{
"name": "My App",
"description": "My elevator pitch goes here",
"launch_path": "/",
"icons": {
"128": "/img/icon-128.png"
},
"developer": {
"name": "Your Name or Organization",
"url": "http: //your-homepage-here.org"
@digitarald
digitarald / robot.js
Created December 3, 2012 23:16
Defendor 2.0 Beta
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
var target = 0;
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
@digitarald
digitarald / MozActivity.js
Last active December 13, 2015 18:29
Image selection via Web Activity on Firefox OS
if ('MozActivity' in window) {
document.getElementById('my-file-input').addEventListener('click', function(evt) {
evt.preventDefault();
var picking = new MozActivity({
name: 'pick',
data: {
type: 'image/jpg'
}
@digitarald
digitarald / moz-runtime.js
Last active December 13, 2015 22:49
Open links in new window for apps
var selfReq = navigator.mozApps.getSelf();
isMozRuntime = false;
selfReq.onsuccess = function() {
isMozRuntime = selfReq.result;
if (isMozRuntime) {
// Responsive action to mozilla apps runtime (force links in new window
respondToMozRuntime();
}
};
function respondToMozRuntime() {
if ('MozActivity' in window) { // feature detection
// When getting elements, like document.getElementsByClassName('video-links')
// rather use event delegation, like
// `jQuery(document).on('click', 'video', fn)
document.getElementById('video-1').onclick = function(evt) {
evt.preventDefault(); // Prevent click behaviour
console.log("Launching Video!");
var activity = new MozActivity({
@digitarald
digitarald / index.js
Last active December 16, 2015 17:18
Push2B2G
/**
* Issue a register() call
* To register to listen for a notification, you simply call push.register
*/
var pushReq = navigator.push.register();
pushReq.onsuccess = function(e) {
alert('pushReq.onsuccess');
var endpoint = pushReq.result;
// Store it
@digitarald
digitarald / language-detect.js
Last active December 17, 2015 04:19
Detect language changes when switching to app. I personally recommend setting current language only on app launch. Reacting to changes later benefits only a small set of users, focus on the 99%!
// Example code, use with caution!
// Events and .hidden property requires no prefix since 18
// Set current language on launch
document.documentElement.lang = navigator.language;
function visibilityChange() {
// user went off page, ignore
if (document.hidden) return;