Skip to content

Instantly share code, notes, and snippets.

View HendrikRoth's full-sized avatar

Hendrik Roth HendrikRoth

  • Dusseldorf, Germany
View GitHub Profile
/*****************************************
/* DOM touch support module
/*****************************************/
(function(document) {
var TAPTRESHOLD = 200, // time within a double tap should have happend
TAPPRECISION = 60 / 2, // distance to identify a swipe gesture
touch = { },
tapCount = 0, // counts the number of touchstart events
tapTimer = 0, // timer to detect double tap
isTouchSwipe = false, // set to true whenever
m.createComponent = function(proto) {
function _component(attrs, children) {
// always return a fresh instance, allows for call without new
if(!(this instanceof _component)) {
return new _component(attrs, children);
}
if(!children && Array.isArray(attrs)) {
children = attrs;
var z = (function (){
//helpers
var cache = {};
var target;
var type = {}.toString;
var tenant=function(componentName, component) {
return {
controller: component.controller,
view: function(ctrl) {
var args=[];
var Router = function(module, name) {
return {
controller: function() {
// Do something generic like calling Google Analytics from here
console.log("Router", name)
return new module.controller()
},
view: module.view
}
}
var slice = Array.prototype.slice;
function multi(){
var handlers = slice.call( arguments );
return function execute(){
var args = slice.call( arguments );
var ctxt = this;
handlers.map( function applyCtxt( fn ){
var onKey = (function(){
var keymap = {
'enter' : 13,
'space' : 31,
'tab' : 9,
'esc' : 27,
'left' : 37,
'up' : 38,
'right' : 39,
'down' : 40
// var ListComponent = m.component({ ... }) -> component
// var list = ListComponent() -> component instance
// list.view() -> view
m.component = function (component) {
return function (options, content) {
var controller = new component.controller(options)
controller.view = function () {
return component.view(controller, arguments[0] || options, arguments[1] || content)
}
'use strict';
var m = require('mithril');
var icons = require('client/utils/icons');
var remove = require('lodash/array/remove');
var transform = require('lodash/object/transform');
var last = require('lodash/array/last');
var code = require('yields-keycode');
function sameAs(filterA) {
var test = {};
test.getnews = function(exa) {
return m.request({
method: 'GET',
dataType: "jsonp",
url: "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=50&q=" + exa,
unwrapSuccess: function(response) {
return response.responseData.feed.entries;
},
@HendrikRoth
HendrikRoth / plural
Last active August 29, 2015 14:22 — forked from ArthurClemens/plural
/*
This code uses a regular expression to make the json safer.
An potentially safer alternative is https://github.com/joewalnes/filtrex (untested) at the cost of 130Kb.
Can be used for example with this JSON structure:
{
"_meta_po_header": "nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);",
"COLLECTION_CONTENTS[0]": "Kolekcja zawiera %@ przepis.",
"COLLECTION_CONTENTS[1]": "Kolekcja zawiera %@ przepisy.",
"COLLECTION_CONTENTS[2]": "Kolekcja zawiera %@ przepisów."