(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; } function init(container, picker) { $('.itemsContainer', container).addClass('itemsContainerWithAlphaPicker'); picker.innerHTML = getPickerHtml(); $(picker).on('click', 'a', function () { var elem = this; var isSelected = elem.classList.contains('selectedCharacter'); $('.selectedCharacter', picker).removeClass('selectedCharacter'); if (!isSelected) { elem.classList.add('selectedCharacter'); $(picker).trigger('alphaselect', [this.innerHTML]); } else { $(picker).trigger('alphaclear'); } }); } pageClassOn('pageinit', "libraryPage", function () { var page = this; var pickers = page.querySelectorAll('.alphabetPicker'); if (!pickers.length) { return; } if (page.classList.contains('pageWithAbsoluteTabs')) { for (var i = 0, length = pickers.length; i < length; i++) { init($(pickers[i]).parents('.pageTabContent'), pickers[i]); } } else { init(page, pickers[0]); } }); $.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.classList.add('selectedCharacter'); } else { this.classList.remove('selectedCharacter'); } }); return this; }; $.fn.alphaClear = function (val) { return this.alphaValue(''); }; })(window, document, jQuery);