Changeset - 58d27c7ad80e
[Not reviewed]
default
0 3 0
domruf - 8 years ago 2017-10-10 21:33:16
dominikruf@gmail.com
gravatar: use icon-gravatar for default gravatar sizing and styling instead of icon-empty

We may want to use a different style for gravatar then for icon-empty,
so we should give it its own class, but still consider it an icon, like the
default icon-user is.
3 files changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/helpers.py
Show inline comments
 
@@ -833,97 +833,97 @@ def action_parser(user_log, feed=False, 
 

	
 
#==============================================================================
 
# PERMS
 
#==============================================================================
 
from kallithea.lib.auth import HasPermissionAny, \
 
    HasRepoPermissionLevel, HasRepoGroupPermissionLevel
 

	
 

	
 
#==============================================================================
 
# GRAVATAR URL
 
#==============================================================================
 
def gravatar_div(email_address, cls='', size=30, **div_attributes):
 
    """Return an html literal with a span around a gravatar if they are enabled.
 
    Extra keyword parameters starting with 'div_' will get the prefix removed
 
    and '_' changed to '-' and be used as attributes on the div. The default
 
    class is 'gravatar'.
 
    """
 
    from tg import tmpl_context as c
 
    if not c.visual.use_gravatar:
 
        return ''
 
    if 'div_class' not in div_attributes:
 
        div_attributes['div_class'] = "gravatar"
 
    attributes = []
 
    for k, v in sorted(div_attributes.items()):
 
        assert k.startswith('div_'), k
 
        attributes.append(' %s="%s"' % (k[4:].replace('_', '-'), escape(v)))
 
    return literal("""<span%s>%s</span>""" %
 
                   (''.join(attributes),
 
                    gravatar(email_address, cls=cls, size=size)))
 

	
 

	
 
def gravatar(email_address, cls='', size=30):
 
    """return html element of the gravatar
 

	
 
    This method will return an <img> with the resolution double the size (for
 
    retina screens) of the image. If the url returned from gravatar_url is
 
    empty then we fallback to using an icon.
 

	
 
    """
 
    from tg import tmpl_context as c
 
    if not c.visual.use_gravatar:
 
        return ''
 

	
 
    src = gravatar_url(email_address, size * 2)
 

	
 
    if src:
 
        # here it makes sense to use style="width: ..." (instead of, say, a
 
        # stylesheet) because we using this to generate a high-res (retina) size
 
        html = ('<i class="icon-empty {cls}"'
 
        html = ('<i class="icon-gravatar {cls}"'
 
                ' style="font-size: {size}px;background-size: {size}px;background-image: url(\'{src}\')"'
 
                '></i>').format(cls=cls, size=size, src=src)
 

	
 
    else:
 
        # if src is empty then there was no gravatar, so we use a font icon
 
        html = ("""<i class="icon-user {cls}" style="font-size: {size}px;"></i>"""
 
            .format(cls=cls, size=size, src=src))
 

	
 
    return literal(html)
 

	
 

	
 
def gravatar_url(email_address, size=30, default=''):
 
    # doh, we need to re-import those to mock it later
 
    from kallithea.config.routing import url
 
    from kallithea.model.db import User
 
    from tg import tmpl_context as c
 
    if not c.visual.use_gravatar:
 
        return ""
 

	
 
    _def = 'anonymous@kallithea-scm.org'  # default gravatar
 
    email_address = email_address or _def
 

	
 
    if email_address == _def:
 
        return default
 

	
 
    parsed_url = urlparse.urlparse(url.current(qualified=True))
 
    url = (c.visual.gravatar_url or User.DEFAULT_GRAVATAR_URL ) \
 
               .replace('{email}', email_address) \
 
               .replace('{md5email}', hashlib.md5(safe_str(email_address).lower()).hexdigest()) \
 
               .replace('{netloc}', parsed_url.netloc) \
 
               .replace('{scheme}', parsed_url.scheme) \
 
               .replace('{size}', safe_str(size))
 
    return url
 

	
 

	
 
def changed_tooltip(nodes):
 
    """
 
    Generates a html string for changed nodes in changeset page.
 
    It limits the output to 30 entries
 

	
 
    :param nodes: LazyNodesGenerator
 
    """
 
    if nodes:
 
        pref = ': <br/> '
 
        suf = ''
 
        if len(nodes) > 30:
 
            suf = '<br/>' + _(' and %s more') % (len(nodes) - 30)
 
        return literal(pref + '<br/> '.join([safe_unicode(x.path)
kallithea/public/css/contextbar.css
Show inline comments
 
/**
 
 * Stylesheets for the context bar
 
 */
 
i[class^='icon-'] {
 
  background-repeat: no-repeat;
 
  background-position: center;
 
  display: inline-block;
 
  min-width: 16px;
 
  min-height: 16px;
 
  margin: -2px 0 -4px 0;
 
  /* background-color: red; /* for debugging */
 
}
 
/* Note: class 'icon-empty' can be used to get this styling without an actual glyph */
 
/* Note: class 'icon-empty' or 'icon-gravatar' can be used to get icon styling without an actual glyph */
 
/* css classes for diff file status ... it'd be nice if css had a way to
 
   inherit from another class but alas, we must make sure this content is the
 
   same from the icon font file */
 
.icon-diff-M:before {
 
  font-family: 'kallithea';
 
  content: '\22a1';
 
  color: #d0b44c;
 
}
 
.icon-diff-D:before {
 
  font-family: 'kallithea';
 
  content: '\229f';
 
  color: #bd2c00;
 
}
 
.icon-diff-A:before {
 
  font-family: 'kallithea';
 
  content: '\229e';
 
  color: #6cc644;
 
}
 
.icon-diff-R:before {
 
  font-family: 'kallithea';
 
  content: '\e81f';
 
  color: #677a85;
 
}
 
nav.navbar #quick a,
 
#content #context-bar,
 
#content #context-bar a {
 
  color: #FFFFFF;
 
}
 
nav.navbar #quick a:hover,
 
#content #context-bar a:hover {
 
  text-decoration: none;
 
  background: inherit;
 
}
 
.navbar-text {
 
  margin-top: 0;
 
  margin-bottom: 0;
 
}
 
ul#quick ul.dropdown-menu > li {
 
  border-bottom: 1px solid rgba(0,0,0,0.1);
 
  border-top: 1px solid rgba(255,255,255,0.1);
 
}
 
ul#quick ul.dropdown-menu > li:first-child {
 
  border-top: none;
 
}
 
ul#quick ul.dropdown-menu > li:last-child {
 
  border-bottom: none;
 
}
 
nav.navbar #quick ul,
kallithea/public/js/base.js
Show inline comments
 
@@ -1025,97 +1025,97 @@ var autocompleteMatchUsers = function (s
 
        var contact = myUsers[i];
 
        if (((contact.fname+"").toLowerCase().indexOf(query) > -1) ||
 
             ((contact.lname+"").toLowerCase().indexOf(query) > -1) ||
 
             ((contact.nname) && ((contact.nname).toLowerCase().indexOf(query) > -1))) {
 
            matches[matches.length] = contact;
 
        }
 
    }
 
    return matches;
 
};
 

	
 
// Custom search function for the DataSource of userGroups
 
var autocompleteMatchGroups = function (sQuery, myGroups) {
 
    // Case insensitive matching
 
    var query = sQuery.toLowerCase();
 
    var i = 0;
 
    var l = myGroups.length;
 
    var matches = [];
 

	
 
    // Match against each name of each group
 
    for (; i < l; i++) {
 
        var matched_group = myGroups[i];
 
        if (matched_group.grname.toLowerCase().indexOf(query) > -1) {
 
            matches[matches.length] = matched_group;
 
        }
 
    }
 
    return matches;
 
};
 

	
 
// Highlight the snippet if it is found in the full text.
 
// Snippet must be lowercased already.
 
var autocompleteHighlightMatch = function (full, snippet) {
 
    var matchindex = full.toLowerCase().indexOf(snippet);
 
    if (matchindex <0)
 
        return full;
 
    return full.substring(0, matchindex)
 
        + '<span class="select2-match">'
 
        + full.substr(matchindex, snippet.length)
 
        + '</span>' + full.substring(matchindex + snippet.length);
 
};
 

	
 
// Return html snippet for showing the provided gravatar url
 
var gravatar = function(gravatar_lnk, size, cssclass) {
 
    if (!gravatar_lnk) {
 
        return '';
 
    }
 
    if (gravatar_lnk == 'default') {
 
        return '<i class="icon-user {1}" style="font-size: {0}px;"></i>'.format(size, cssclass);
 
    }
 
    return ('<i class="icon-empty {2}"' +
 
    return ('<i class="icon-gravatar {2}"' +
 
            ' style="font-size: {0}px;background-image: url(\'{1}\'); background-size: {0}px"' +
 
            '></i>').format(size, gravatar_lnk, cssclass);
 
}
 

	
 
var autocompleteGravatar = function(res, gravatar_lnk, size, group) {
 
    var elem;
 
    if (group !== undefined) {
 
        elem = '<i class="perm-gravatar-ac icon-users"></i>';
 
    } else {
 
        elem = gravatar(gravatar_lnk, size, "perm-gravatar-ac");
 
    }
 
    return '<div class="ac-container-wrap">{0}{1}</div>'.format(elem, res);
 
}
 

	
 
// Custom formatter to highlight the matching letters
 
var autocompleteFormatter = function (oResultData, sQuery, sResultMatch) {
 
    var query;
 
    if (sQuery && sQuery.toLowerCase) // YAHOO AutoComplete
 
        query = sQuery.toLowerCase();
 
    else if (sResultMatch && sResultMatch.term) // select2 - parameter names doesn't match
 
        query = sResultMatch.term.toLowerCase();
 

	
 
    // group
 
    if (oResultData.grname) {
 
        return autocompleteGravatar(
 
            "{0}: {1}".format(
 
                _TM['Group'],
 
                autocompleteHighlightMatch(oResultData.grname, query)),
 
            null, null, true);
 
    }
 

	
 
    // users
 
    if (oResultData.nname) {
 
        var displayname = autocompleteHighlightMatch(oResultData.nname, query);
 
        if (oResultData.fname && oResultData.lname) {
 
            displayname = "{0} {1} ({2})".format(
 
                autocompleteHighlightMatch(oResultData.fname, query),
 
                autocompleteHighlightMatch(oResultData.lname, query),
 
                displayname);
 
        }
 

	
 
        return autocompleteGravatar(displayname, oResultData.gravatar_lnk, oResultData.gravatar_size);
 
    }
 

	
 
    return '';
 
};
 

	
 
// Generate a basic autocomplete instance that can be tweaked further by the caller
0 comments (0 inline, 0 general)