Skip to content

Instantly share code, notes, and snippets.

@adriancmiranda
Last active August 29, 2015 14:21
Show Gist options
  • Save adriancmiranda/46703440bdc4e73eb004 to your computer and use it in GitHub Desktop.
Save adriancmiranda/46703440bdc4e73eb004 to your computer and use it in GitHub Desktop.
Esboço framework
'isobar/uri'
scope.uri.replace(url);
scope.uri.assign(url);
scope.uri.reload(forcedReload);
scope.uri.queryfy({ param1: 'value', param2: 'value' });
scope.uri.hash;
scope.uri.href = 'http://www.ambox.io';
scope.uri.origin;
scope.uri.protocol;
scope.uri.host;
scope.uri.hostname;
scope.uri.port;
scope.uri.pathname;
scope.uri.search;
scope.uri.vars.yourUrlParam;
scope.uri.assets;
scope.uri.base;
scope.uri.site;
scope.uri.cdn;
'isobar/math'
scope.math.PI;
scope.math.toDegrees(radians);
scope.math.toRadians(degrees);
scope.math.interpolate(value, min, max);
scope.math.normalize(value, min, max);
scope.math.distance(x1, x2, y1, y2);
scope.math.clamp(value, min, max);
scope.math.map(value, min1, max1, min2, max2);
scope.math.mod(value, min, max);
'isobar/type'
scope.type.of(value) === 'object';
scope.type.isString(value);
scope.type.isNumber(value);
scope.type.isUint(value);
scope.type.isInt(value);
scope.type.isFunction(value);
scope.type.isObject(value);
scope.type.isBlankObject(value);
scope.type.isDate(value);
scope.type.isArray(value);
scope.type.isArrayLike(value);
scope.type.isRegExp(value);
scope.type.isBoolean(value);
scope.type.isElement(value);
scope.type.isFile(value);
scope.type.isWindow(value);
scope.type.toBoolean(value);
scope.type.toObject(value);
scope.type.toString(value);
scope.type.toFloat(value);
scope.type.toArray(value);
scope.type.toUint(value);
scope.type.toInt(value);
'isobar/scope'
scope.register('samsung', scope.register);
'isobar/class'
scope.samsung('templates.UI', scope.class({
ui: {
cloak: '[data-cloak]', // retorna um objeto jQuery/Zepto/Sizzle/(HTMLElement com fallback) this.ui.cloak:HTMLElement
title: 'html>title',
menu: 'a[href^="#"]',
html: 'html',
body: 'body'
},
events: {
'ready document': 'render', // trigger de evento 'eventType1,eventType2 selector': 'functionName',
'click,touchstart @ui.menu': 'onClickA'
},
constructor: ['$super', function($super, element, data) {// Declaração opcional para compilação usando `mangle`
$super(element, data).unbind('onClickA', 'onTouchB', 'onSwipeC');// Todos os métodos declarados diretamente na classe são retornos de bind para manter o scope, se não quiser, por algum motivo, use unbind
},
onClickA: ['$type', function($type, evt) {
evt.preventDefault();
trace($type.of(evt));// $type é um objeto retornado a partir de qualquer coisa que esteja no namespace `scope` ...
}],
onTouchB: ['$math', function($math, evt) {
evt.stopPropagation();
trace($math.PI);// ... podendo ser o `math`
}],
onSwipeC: function(evt) {
evt.stopPropagation();
trace(this); // Não é o UI
},
render: function($super, template) {// posso injetar os módulos assim também, mas preciso usar o `mangle:false` na compilação
return $super(template);
},
ready: function() {
this.ui.cloak.css('[data-cloak]');// só um exemplo de uso do ui
return true;
}
}));
return scope.samsung('templates.UI') || scope.samsung.templates.UI;// duas formas de retornar a classe a partir do console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment