Skip to content

Instantly share code, notes, and snippets.

View gilbert's full-sized avatar
🪐
Security in space

Gilbert gilbert

🪐
Security in space
View GitHub Profile
@gilbert
gilbert / definition.js
Last active August 5, 2016 18:07
Expand / Collapse Animation with Mithril v1.x
var animateHeight = {
oncreate: function (vnode) {
var height = vnode.dom.clientHeight
vnode.dom.style.maxHeight = 0
vnode.dom.offsetHeight // Trick to recalc layout
window.requestAnimationFrame( ()=> (vnode.dom.style.maxHeight = height+1+"px") )
},
onbeforeremove: function (vnode, done) {
vnode.dom.addEventListener('transitionend', done)
vnode.dom.style.maxHeight = 0
@gilbert
gilbert / example.js
Last active August 3, 2016 21:19
Mithril.js - Avoiding m.props
// m.prop is a great pattern, but Plain-old JavaScript Objects (POJO) are
// much more pleasant to work with.
// Here's an example of using POJOs with one- and two-way data binding.
// First, the helper methods
m.setValue = function (obj, prop) {
return m.withAttr('value', function(value) { obj[prop] = value })
}

Exercise 1.1

Draw a diagram of the result of following code.

var businessName = "Trader Joe's";
var location     = "Austin";

Exercise 1.2

@gilbert
gilbert / widget.js
Created March 25, 2015 17:09
Mithril + JSS
Widget = {
controller: function () {
this.css = Widget.stylesheet().classes
},
view: function (ctrl) {
return m('.widget', [
m('h3', { class: ctrl.css.head }),
m('div', { class: ctrl.css.body })
])
},
Step 1: Create the cheatsheet.
@gilbert
gilbert / ajax-loader.scss
Created July 8, 2015 16:15
Global Mithril.js AJAX Loader
// Taken from http://loading.io/
uiload {
display: inline-block;
position: relative;
& > div {
position: relative;
}
}
@-webkit-keyframes ajax-loader {
@gilbert
gilbert / Coupon.js
Last active October 2, 2015 19:27
Mithril.js Tutorial Part 2
window.Coupon = {}
Coupon.controller = function (attrs) {
var ctrl = this
ctrl.code = ""
ctrl.submit = function (e) {
e.preventDefault()
ctrl.error = null
@gilbert
gilbert / Autocomplete.scss
Last active August 29, 2015 14:23
Basic Autocomplete Widget
@mixin li-hover {
background: #3875d7;
color: #fff;
}
.autocomplete-input--select-drop {
background: white;
border: 1px solid #aaa;
margin-top: -1px;
position: absolute;
@gilbert
gilbert / m.ext.js
Last active August 29, 2015 14:18
Mithril.js Extensions
m.deferred.resolve = function (value) {
var deferred = m.deferred()
deferred.resolve(value)
return deferred.promise
}
m.deferred.reject = function (value) {
var deferred = m.deferred()
deferred.reject(value)
return deferred.promise
@gilbert
gilbert / globals.js
Last active August 29, 2015 14:17
Global Function Helpers
(function (global) {
global.getProp = function (propName) {
return function (obj) { return obj[propName] }
}
global.queryProp = function (query) {
var segments = query.split('.')
return function (obj) {
var result = obj