@ -10,6 +10,9 @@
} ) ;
} ) ;
}
}
} ( function ( utils , Benchpress , relative _path ) {
} ( function ( utils , Benchpress , relative _path ) {
Benchpress . setGlobal ( 'true' , true ) ;
Benchpress . setGlobal ( 'false' , false ) ;
var helpers = {
var helpers = {
displayMenuItem : displayMenuItem ,
displayMenuItem : displayMenuItem ,
buildMetaTag : buildMetaTag ,
buildMetaTag : buildMetaTag ,
@ -26,6 +29,7 @@
renderTopicImage : renderTopicImage ,
renderTopicImage : renderTopicImage ,
renderDigestAvatar : renderDigestAvatar ,
renderDigestAvatar : renderDigestAvatar ,
userAgentIcons : userAgentIcons ,
userAgentIcons : userAgentIcons ,
buildAvatar : buildAvatar ,
register : register ,
register : register ,
_ _escape : identity ,
_ _escape : identity ,
} ;
} ;
@ -269,6 +273,49 @@
return icons ;
return icons ;
}
}
function buildAvatar ( userObj , size , rounded , classNames , component ) {
/ * *
* userObj requires :
* - uid , picture , icon : bgColor , icon : text ( getUserField w / "picture" should return all 4 ) , username
* size : one of "xs" , "sm" , "md" , "lg" , or "xl" ( required ) , or an integer
* rounded : true or false ( optional , default false )
* classNames : additional class names to prepend ( optional , default none )
* component : overrides the default component ( optional , default none )
* /
var attributes = [
'alt="' + userObj . username + '"' ,
'title="' + userObj . username + '"' ,
'data-uid="' + userObj . uid + '"' ,
] ;
var styles = [ ] ;
classNames = classNames || '' ;
// Validate sizes, handle integers, otherwise fall back to `avatar-sm`
if ( [ 'xs' , 'sm' , 'md' , 'lg' , 'xl' ] . includes ( size ) ) {
classNames += ' avatar-' + size ;
} else if ( ! isNaN ( parseInt ( size , 10 ) ) ) {
styles . push ( 'width: ' + size + 'px;' , 'height: ' + size + 'px;' , 'line-height: ' + size + 'px;' , 'font-size: ' + ( parseInt ( size , 10 ) / 16 ) + 'rem;' ) ;
} else {
classNames += ' avatar-sm' ;
}
attributes . unshift ( 'class="avatar ' + classNames + ( rounded ? ' avatar-rounded' : '' ) + '"' ) ;
// Component override
if ( component ) {
attributes . push ( 'component="' + component + '"' ) ;
} else {
attributes . push ( 'component="avatar/' + ( userObj . picture ? 'picture' : 'icon' ) + '"' ) ;
}
if ( userObj . picture ) {
return '<img ' + attributes . join ( ' ' ) + ' src="' + userObj . picture + '" style="' + styles . join ( ' ' ) + '" />' ;
}
styles . push ( 'background-color: ' + userObj [ 'icon:bgColor' ] + ';' ) ;
return '<div ' + attributes . join ( ' ' ) + ' style="' + styles . join ( ' ' ) + '">' + userObj [ 'icon:text' ] + '</div>' ;
}
function register ( ) {
function register ( ) {
Object . keys ( helpers ) . forEach ( function ( helperName ) {
Object . keys ( helpers ) . forEach ( function ( helperName ) {
Benchpress . registerHelper ( helperName , helpers [ helperName ] ) ;
Benchpress . registerHelper ( helperName , helpers [ helperName ] ) ;