Unicode Character Browser
Displays a pagable list of Unicode Characters
by Troy Alford
HTML
<wrapper>
<bag></bag>
<pager></pager>
</wrapper>
CSS
wrapper {
border: 1px solid #eee;
border-radius: 5px;
display: block;
padding: 0;
}
wrapper>bag {
display: block;
padding: 2px;
}
wrapper>pager {
background-color: #f6f6f6;
border-top: 1px solid #ddd;
display: block;
height: 35px;
padding: 3px;
}
wrapper>bag>char {
border: 1px solid #eee;
cursor: pointer;
display: inline-block;
font-size: 16px;
height: 25px;
line-height: 25px;
margin: 3px;
overflow: hidden;
padding: 5px;
text-align: center;
vertical-align: middle;
width: 25px;
}
wrapper>bag>char:hover {
background: #eeeeff;
font-weight: bold;
font-size: 28px;
height: 37px;
line-height: 37px;
margin: 0;
padding: 2px;
width: 37px;
}
wrapper>pager>span {
color: #666;
float: right;
font-size: 10pt;
height: 35px;
line-height: 16px;
padding: 2px 5px;
text-align: right;
}
wrapper>pager>span.clicked-info {
color: #333;
float: none;
font-weight: bold;
font-size: 28px;
font-weight: bold;
position: relative;
left: 60px;
top: 8px;
text-shadow: 1px 1px #ccc;
}
wrapper>pager>span.display-info {
font-family: Calibri, Arial, Verdana, Tahoma;
}
btn {
background-color: rgba(0, 0, 0, .2);
border-radius: 3px;
border-width: 0 0 0 7px;
box-shadow: inset 1px 1px 0 rgba(0,0,0,.1), inset 0 -1px 0 rgba(0,0,0,.07);
color: #444;
display: inline-block;
font-size: 16px;
font-weight: bold;
height: 25px;
line-height: 24px;
opacity: .55;
padding: 5px;
text-align: center;
vertical-align: middle;
width: 25px;
}
btn[disabled] {
background: #fff;
color: #d6d6d6;
}
btn:not([disabled]):hover {
background: #dfdfdf;
box-shadow: 2px 2px 0 rgba(0,0,0,.18), 0 -1px 0 rgba(0,0,0,.15);
cursor: pointer;
user-select: none;
}
JavaScript
$(function() {
var $bag = $('wrapper>bag');
var $pager = $('wrapper>pager');
var page = 0;
var pageSize = 120;
var maxChar = parseInt('ffff', 16);
var maxPage = Math.ceil(maxChar / pageSize);
var $firstBtn = $('<btn />')
.html('⋘')
.appendTo($pager)
.bind('click', function () {
page = 0;
showPage(page, pageSize);
});
var $prevBtn = $('<btn />')
.html('≪')
.appendTo($pager)
.bind('click', function () {
if (page > 0) {
page--;
showPage(page, pageSize);
}
});
var $nextBtn = $('<btn />')
.html('≫')
.appendTo($pager)
.bind('click', function () {
if (page < maxPage) {
page++;
showPage(page, pageSize);
}
});
var $lastBtn = $('<btn />')
.html('⋙')
.appendTo($pager)
.bind('click', function () {
page = maxPage;
showPage(page, pageSize);
});
var $clicked = $('<span />')
.addClass('clicked-info')
.html(' ')
.appendTo($pager);
$('bag>char').on('click', function (ev) {
var $char = $(ev.target);
$clicked.html('\'' + $char.html() + '\' = &#' + $char.attr('hex') + '; = \\' + $char.attr('code'));
});
var $status = $('<span />')
.html(' ')
.appendTo($pager)
.addClass('display-info');
var setup = function() {
showPage(page, pageSize);
};
var showPage = function(page, pageSize) {
var min = 0;
var start = min + (pageSize * page);
$bag.empty();
for (var i = 0; i <= pageSize - 1; i++) {
var code = start + i;
$('<char />')
.html('&#' + code + ';')
.attr('code', code)
...