mirror of
				https://github.com/janeczku/calibre-web
				synced 2025-10-31 15:23:02 +00:00 
			
		
		
		
	 693c26c2b3
			
		
	
	693c26c2b3
	
	
	
		
			
			Since this is closer to the elements, we can be more sure that we won't have events fire when we don't want them to. For example, if we're viewing the page in a modal, we don't want the event handler living longer than the content itself.
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| $( document ).ready(function() {
 | |
|     $("#have_read_form").ajaxForm();
 | |
| });
 | |
| 
 | |
| $("#have_read_cb").on("change", function() {
 | |
|     $(this).closest("form").submit();
 | |
| });
 | |
| 
 | |
| $("#shelf-actions").on("click", "[data-shelf-action]", function (e) {
 | |
|     e.preventDefault();
 | |
| 
 | |
|     $.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);
 | |
| 
 | |
|             setTimeout(() => {
 | |
|                 $msg.remove();
 | |
|             }, 10000);
 | |
|         });
 | |
| }); |