diff --git a/frontend_tests/node_tests/list_render.js b/frontend_tests/node_tests/list_render.js
index 29ac789dec..89025760dd 100644
--- a/frontend_tests/node_tests/list_render.js
+++ b/frontend_tests/node_tests/list_render.js
@@ -1,17 +1,5 @@
-// TODO: make an initialize function for list_render.
-const initialize = (function () {
- var initalize_function;
-
- set_global('$', (f) => {
- initalize_function = f;
- });
-
- // We can move this module scope when we have
- // an explicit initialize function.
- zrequire('list_render');
-
- return initalize_function;
-}());
+set_global('$', () => {});
+zrequire('list_render');
// We need these stubs to get by instanceof checks.
// The list_render library allows you to insert objects
@@ -22,11 +10,6 @@ set_global('Element', function () {
return { };
});
-// This function will be the anonymous click handler
-// for clicking on any element that matches the
-// CSS selector of "[data-sort]".
-var handle_sort_click;
-
// We only need very simple jQuery wrappers for when the
// "real" code wraps html or sets up click handlers.
// We'll simulate most other objects ourselves.
@@ -35,16 +18,6 @@ set_global('$', (arg) => {
return arg.to_jquery();
}
- if (arg === 'body') {
- return {
- on: (event_name, selector, f) => {
- assert.equal(event_name, 'click');
- assert.equal(selector, '[data-sort]');
- handle_sort_click = f;
- },
- };
- }
-
return {
html: () => arg,
};
@@ -266,7 +239,6 @@ run_test('sorting', () => {
}
list_render.create(container, list, opts);
- initialize();
var button_opts;
var button;
@@ -281,7 +253,7 @@ run_test('sorting', () => {
button = sort_button(button_opts);
- handle_sort_click.call(button);
+ list_render.handle_sort.call(button);
assert(cleared);
assert(button.siblings_deactivated);
@@ -302,7 +274,7 @@ run_test('sorting', () => {
cleared = false;
button.siblings_deactivated = false;
- handle_sort_click.call(button);
+ list_render.handle_sort.call(button);
assert(cleared);
assert(button.siblings_deactivated);
diff --git a/static/js/list_render.js b/static/js/list_render.js
index 542efb7298..dd4478e3b7 100644
--- a/static/js/list_render.js
+++ b/static/js/list_render.js
@@ -329,35 +329,26 @@ var list_render = (function () {
return DEFAULTS.instances[name] || false;
};
- return exports;
-}());
+ exports.handle_sort = function () {
+ /*
+ one would specify sort parameters like this:
+ - name => sort alphabetic.
+ - age => sort numeric.
-if (typeof module !== 'undefined') {
- module.exports = list_render;
-}
+ you MUST specify the `data-list-render` in the `.progressive-table-wrapper`
-$(function () {
- /*
- one would specify sort parameters like this:
- - name => sort alphabetic.
- - age => sort numeric.
-
- you MUST specify the `data-list-render` in the `.progressive-table-wrapper`
- otherwise it will not know what `list_render` instance to look up.
-
-
-
- */
- $("body").on("click", "[data-sort]", function () {
+
+ */
var $this = $(this);
var sort_type = $this.data("sort");
var prop_name = $this.data("sort-prop");
@@ -388,5 +379,15 @@ $(function () {
$this.siblings(".active").removeClass("active");
$this.addClass("active");
- });
+ };
+
+ return exports;
+}());
+
+$(function () {
+ $("body").on("click", "[data-sort]", list_render.handle_sort);
});
+
+if (typeof module !== 'undefined') {
+ module.exports = list_render;
+}