Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions initial.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@
textColor: '#ffffff',
height: 100,
width: 100,
fontSize: 60,
fontSize: 0.45, // default font size is 45% of height
fontWeight: 400,
fontFamily: 'HelveticaNeue-Light,Helvetica Neue Light,Helvetica Neue,Helvetica, Arial,Lucida Grande, sans-serif'
}, options);

// overriding from data attributes
settings = $.extend(settings, e.data());

if (settings.fontSize < 1) {
// if font size < 1 presume that this is a percentage of height
// e.g. - settings.fontSize: .45
settings.fontSize = parseInt(settings.height * settings.fontSize);
}
else if (settings.fontSize.toString().indexOf("%") > 1) {
// if font size has % character calculate it from height
// e.g. - settings.fontSize: "45%"
settings.fontSize = parseInt(settings.height * (parseInt(settings.fontSize.replace("%", "")) / 100));
}

// making the text object
var c = settings.name.substr(0, settings.charCount).toUpperCase();
Expand All @@ -33,7 +44,7 @@
'font-family': settings.fontFamily
}).html(c).css({
'font-weight': settings.fontWeight,
'font-size': settings.fontSize+'px',
'font-size': settings.fontSize + 'px',
});

var colorIndex = Math.floor((c.charCodeAt(0) - 65) % colors.length);
Expand All @@ -45,8 +56,8 @@
'height': settings.height
}).css({
'background-color': colors[colorIndex],
'width': settings.width+'px',
'height': settings.height+'px'
'width': settings.width + 'px',
'height': settings.height + 'px'
});

svg.append(cobj);
Expand All @@ -58,4 +69,4 @@
})
};

}(jQuery));
}(jQuery));