Skip to content

Commit d59daab

Browse files
committed
Make EmoteList self-contained instead of referencing globals
1 parent 4e011c0 commit d59daab

File tree

10 files changed

+59
-50
lines changed

10 files changed

+59
-50
lines changed

templates/channel.jade

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ html(lang="en")
184184
h4 Emote List
185185
.modal-body
186186
.pull-left
187-
input#emotelist-search.form-control(type="text", placeholder="Search")
187+
input.emotelist-search.form-control(type="text", placeholder="Search")
188188
.pull-right
189189
.checkbox
190190
label
191-
input#emotelist-alphabetical(type="checkbox")
191+
input.emotelist-alphabetical(type="checkbox")
192192
| Sort alphabetically
193-
#emotelist-paginator-container
194-
table
193+
.emotelist-paginator-container
194+
table.emotelist-table
195195
tbody
196196
.modal-footer
197197
#channeloptions.modal.fade(tabindex="-1", role="dialog", aria-hidden="true")

www/css/cytube.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ table td {
593593
border-top-width: 0;
594594
}
595595

596-
#emotelist table {
596+
.emotelist-table {
597597
margin: auto;
598598
}
599599

@@ -618,7 +618,7 @@ table td {
618618
cursor: pointer;
619619
}
620620

621-
#emotelist-paginator-container {
621+
.emotelist-paginator-container {
622622
text-align: center;
623623
}
624624

www/css/themes/bootstrap-theme.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/css/themes/cyborg.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/css/themes/light.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/css/themes/modern.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/css/themes/slate.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

www/js/callbacks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ Callbacks = {
10181018
var tbl = $("#cs-emotes table");
10191019
tbl.data("entries", data);
10201020
formatCSEmoteList();
1021-
EMOTELIST.emoteListChanged = true;
1021+
EMOTELIST.handleChange();
10221022
},
10231023

10241024
updateEmote: function (data) {

www/js/ui.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -828,30 +828,17 @@ applyOpts();
828828
}
829829
})();
830830

831+
var EMOTELISTMODAL = $("#emotelist");
832+
EMOTELISTMODAL.on("hidden.bs.modal", unhidePlayer);
831833
$("#emotelistbtn").click(function () {
832-
EMOTELIST.show();
834+
EMOTELISTMODAL.modal();
833835
});
834836

835-
$("#emotelist-search").keyup(function () {
836-
var value = this.value.toLowerCase();
837-
if (value) {
838-
EMOTELIST.filter = function (emote) {
839-
return emote.name.toLowerCase().indexOf(value) >= 0;
840-
};
841-
} else {
842-
EMOTELIST.filter = null;
843-
}
844-
EMOTELIST.handleChange();
845-
EMOTELIST.loadPage(0);
846-
});
847-
848-
$("#emotelist-alphabetical").prop("checked", USEROPTS.emotelist_sort);
849-
$("#emotelist-alphabetical").change(function () {
837+
EMOTELISTMODAL.find(".emotelist-alphabetical").change(function () {
850838
USEROPTS.emotelist_sort = this.checked;
851839
setOpt("emotelist_sort", USEROPTS.emotelist_sort);
852-
EMOTELIST.handleChange();
853-
EMOTELIST.loadPage(0);
854840
});
841+
EMOTELISTMODAL.find(".emotelist-alphabetical").prop("checked", USEROPTS.emotelist_sort);
855842

856843
$("#fullscreenbtn").click(function () {
857844
var elem = document.querySelector("#videowrap .embed-responsive");

www/js/util.js

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,20 +2901,51 @@ function googlePlusSimulator2014(data) {
29012901
return data;
29022902
}
29032903

2904-
function EmoteList() {
2905-
this.modal = $("#emotelist");
2906-
this.modal.on("hidden.bs.modal", unhidePlayer);
2907-
this.table = document.querySelector("#emotelist table");
2904+
function EmoteList(selector) {
2905+
this.elem = $(selector);
2906+
this.initSearch();
2907+
this.initSortOption();
2908+
this.table = this.elem.find(".emotelist-table")[0];
2909+
this.paginatorContainer = this.elem.find(".emotelist-paginator-container");
29082910
this.cols = 5;
29092911
this.itemsPerPage = 25;
29102912
this.emotes = [];
2911-
this.emoteListChanged = true;
29122913
this.page = 0;
29132914
}
29142915

2916+
EmoteList.prototype.initSearch = function () {
2917+
this.searchbar = this.elem.find(".emotelist-search");
2918+
var self = this;
2919+
2920+
this.searchbar.keyup(function () {
2921+
var value = this.value.toLowerCase();
2922+
if (value) {
2923+
self.filter = function (emote) {
2924+
return emote.name.toLowerCase().indexOf(value) >= 0;
2925+
};
2926+
} else {
2927+
self.filter = null;
2928+
}
2929+
self.handleChange();
2930+
self.loadPage(0);
2931+
});
2932+
};
2933+
2934+
EmoteList.prototype.initSortOption = function () {
2935+
this.sortOption = this.elem.find(".emotelist-alphabetical");
2936+
this.sortAlphabetical = false;
2937+
var self = this;
2938+
2939+
this.sortOption.change(function () {
2940+
self.sortAlphabetical = this.checked;
2941+
self.handleChange();
2942+
self.loadPage(0);
2943+
});
2944+
};
2945+
29152946
EmoteList.prototype.handleChange = function () {
29162947
this.emotes = CHANNEL.emotes.slice();
2917-
if (USEROPTS.emotelist_sort) {
2948+
if (this.sortAlphabetical) {
29182949
this.emotes.sort(function (a, b) {
29192950
var x = a.name.toLowerCase();
29202951
var y = b.name.toLowerCase();
@@ -2935,19 +2966,9 @@ EmoteList.prototype.handleChange = function () {
29352966

29362967
this.paginator = new NewPaginator(this.emotes.length, this.itemsPerPage,
29372968
this.loadPage.bind(this));
2938-
var container = document.getElementById("emotelist-paginator-container");
2939-
container.innerHTML = "";
2940-
container.appendChild(this.paginator.elem);
2969+
this.paginatorContainer.html("");
2970+
this.paginatorContainer.append(this.paginator.elem);
29412971
this.paginator.loadPage(this.page);
2942-
this.emoteListChanged = false;
2943-
};
2944-
2945-
EmoteList.prototype.show = function () {
2946-
if (this.emoteListChanged) {
2947-
this.handleChange();
2948-
}
2949-
2950-
this.modal.modal();
29512972
};
29522973

29532974
EmoteList.prototype.loadPage = function (page) {
@@ -3002,7 +3023,8 @@ EmoteList.prototype.loadPage = function (page) {
30023023
this.page = page;
30033024
};
30043025

3005-
window.EMOTELIST = new EmoteList();
3026+
window.EMOTELIST = new EmoteList("#emotelist");
3027+
window.EMOTELIST.sortAlphabetical = USEROPTS.emotelist_sort;
30063028

30073029
function showChannelSettings() {
30083030
hidePlayer();

0 commit comments

Comments
 (0)