(function (window, document, $) {
function getPickerHtml() {
var html = '';
html += '#';
html += 'A';
html += 'B';
html += 'C';
html += 'D';
html += 'E';
html += 'F';
html += 'G';
html += 'H';
html += 'I';
html += 'J';
html += 'K';
html += 'L';
html += 'M';
html += 'N';
html += 'O';
html += 'P';
html += 'Q';
html += 'R';
html += 'S';
html += 'T';
html += 'U';
html += 'V';
html += 'W';
html += 'X';
html += 'Y';
html += 'Z';
return html;
}
$(document).on('pageinitdepends', ".libraryPage", function () {
var page = this;
var picker = $('.alphabetPicker', page);
if (!picker.length) {
return;
}
$('.itemsContainer', page).addClass('itemsContainerWithAlphaPicker');
picker.html(getPickerHtml()).trigger('create').on('click', 'a', function () {
var elem = $(this);
var isSelected = elem.hasClass('selectedCharacter');
$('.selectedCharacter', picker).removeClass('selectedCharacter');
if (!isSelected) {
elem.addClass('selectedCharacter');
picker.trigger('alphaselect', [this.innerHTML]);
} else {
picker.trigger('alphaclear');
}
});
});
$.fn.alphaValue = function (val) {
if (val == null) {
return $('.selectedCharacter', this).html();
}
val = val.toLowerCase();
$('.selectedCharacter', this).removeClass('selectedCharacter');
$('a', this).each(function () {
if (this.innerHTML.toLowerCase() == val) {
$(this).addClass('selectedCharacter');
} else {
$(this).removeClass('selectedCharacter');
}
});
return this;
};
$.fn.alphaClear = function (val) {
return this.alphaValue('');
};
})(window, document, jQuery);