Update to ES5 standards

Also fix ESLint issues
This commit is contained in:
Jonathan Rehm
2017-08-12 22:24:56 -07:00
parent 29e2658e53
commit 8171943b8e
8 changed files with 220 additions and 190 deletions

View File

@@ -1,4 +1,6 @@
$( document ).ready(function() {
/* global _ */
$(function() {
$("#have_read_form").ajaxForm();
});
@@ -6,34 +8,51 @@ $("#have_read_cb").on("change", function() {
$(this).closest("form").submit();
});
$("#shelf-actions").on("click", "[data-shelf-action]", function (e) {
e.preventDefault();
(function() {
var templates = {
add: _.template(
$("#template-shelf-add").html()
),
remove: _.template(
$("#template-shelf-remove").html()
)
};
$.get(this.href)
.done(() => {
const $this = $(this);
switch ($this.data("shelf-action")) {
case "add":
$("#remove-from-shelves").append(`<a href="${$this.data("remove-href")}"
data-add-href="${this.href}"
class="btn btn-sm btn-default" data-shelf-action="remove"
><span class="glyphicon glyphicon-remove"></span> ${this.textContent}</a>`);
break;
case "remove":
$("#add-to-shelves").append(`<li><a href="${$this.data("add-href")}"
data-remove-href="${this.href}"
data-shelf-action="add"
>${this.textContent}</a></li>`);
break;
}
this.parentNode.removeChild(this);
})
.fail((xhr) => {
const $msg = $("<span/>", { "class": "text-danger"}).text(xhr.responseText);
$("#shelf-action-status").html($msg);
$("#shelf-actions").on("click", "[data-shelf-action]", function (e) {
e.preventDefault();
setTimeout(() => {
$msg.remove();
}, 10000);
});
});
$.get(this.href)
.done(function() {
var $this = $(this);
switch ($this.data("shelf-action")) {
case "add":
$("#remove-from-shelves").append(
templates.remove({
add: this.href,
remove: $this.data("remove-href"),
content: this.textContent
})
);
break;
case "remove":
$("#add-to-shelves").append(
templates.add({
add: $this.data("add-href"),
remove: this.href,
content: this.textContent
})
);
break;
}
this.parentNode.removeChild(this);
}.bind(this))
.fail(function(xhr) {
var $msg = $("<span/>", { "class": "text-danger"}).text(xhr.responseText);
$("#shelf-action-status").html($msg);
setTimeout(function() {
$msg.remove();
}, 10000);
});
});
})();