Created
December 22, 2014 12:17
-
-
Save barneycarroll/991de7dbcaf909c4721e to your computer and use it in GitHub Desktop.
A Mithril popup pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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 ); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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