Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created December 22, 2014 12:17
Show Gist options
  • Save barneycarroll/991de7dbcaf909c4721e to your computer and use it in GitHub Desktop.
Save barneycarroll/991de7dbcaf909c4721e to your computer and use it in GitHub Desktop.
A Mithril popup pattern
.canvas {
height : 100%;
left : 0;
position : fixed;
top : 0;
width : 100%;
}
.popup {
position: fixed;
-webkit-transform : translate3d( -50%, -100%, 0 );
-moz-transform : translate3d( -50%, -100%, 0 );
-ms-transform : translate3d( -50%, -100%, 0 );
-o-transform : translate3d( -50%, -100%, 0 );
transform : translate3d( -50%, -100%, 0 );
}
function popup( contents, x, y ){
function view(){
return contents ? m( '.canvas', {
onclick : getterSetter( false ),
}, m( '.popup', {
style : {
left : x + 'px',
top : y + 'px'
}
}, m( '.content', contents ) ) ) : '';
}
function getterSetter( input ){
if( arguments.length ) {
return function trigger( event ){
contents = input;
if( event ){
x = event.x || x;
y = event.y || y;
}
};
}
else {
return view();
}
}
return getterSetter;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment