1/** 2 * @file 3 * JavaScript for agov_favorites. 4 */ 5 6(function ($, Drupal) { 7 8 /** 9 * Create a bookmark. 10 */ 11 Drupal.behaviors.agovCreateBookmark = { 12 attach: function (context, settings) { 13 const elements = once('agovCreateBookmark', '#favorites-create-bookmark', context); 14 $(elements).each(function () { 15 $(this).click(function (evt) { 16 evt.preventDefault(); 17 Drupal.behaviors.agovAddBookmark.ajaxCall(evt, 'create-bookmark', TRUE); 18 $("#favorites-container").css("display", "none"); 19 setTimeout(function () { 20 Drupal.behaviors.agovAddBookmark.openFavorites(); 21 }, 1500); 22 }); 23 }); 24 }, 25 }; 26 27 Drupal.behaviors.agovAddBookmark = { 28 /** 29 * Display messages. 30 */ 31 showMessage: function (content) { 32 $(".messages-overlay").addClass("visible"); 33 $('#messages-menu-container').html(content); 34 35 setTimeout(function () { 36 $(".messages-overlay").removeClass("visible"); 37 }, 1500); 38 }, 39 40 /** 41 * Open bookmarks. 42 */ 43 openFavorites: function () { 44 45 // Add token to prevent CDN cache 46 var rand = function () { 47 return Math.random().toString(36).substr(2); // remove `0.` 48 }; 49 50 var token = function () { 51 return rand() + rand(); // to make it longer 52 }; 53 54 $.ajax({
55 url : '/get-bookmarks?token=' + token(), 56 type : 'GET', 57 dataType:'json', 58 success : function (data) { 59 if (!data.ifdata) { 60 Drupal.behaviors.agovAddBookmark.showMessage(data.content); 61 } else { 62 $("#favorites-container").css("display", "block"); 63 $("#favorites-container").css("margin-bottom"); 64 $("#favorites-container").css("margin-bottom", "25px"); 65 $("#favorites-container").css("transition-duration", "1000ms"); 66 $("#favorites-container").css("transition-property", "margin-bottom"); 67 $('#favorites-menu-container').html(data.content); 68 $('.favorites-remove').click(function (evt) { 69 evt.preventDefault(); 70 Drupal.behaviors.agovAddBookmark.ajaxCall(evt, 'remove-bookmark', FALSE); 71 $("#favorites-container").css("display", "none"); 72 setTimeout(function () { 73 Drupal.behaviors.agovAddBookmark.openFavorites(); 74 }, 1000); 75 }); 76 } 77 }, 78 error : function (request, error) { 79 if (window.console) { 80 console.log("Response: " + JSON.stringify(request)); 81 } else { 82 alert("Response: " + JSON.stringify(request)); 83 } 84 } 85 }); 86 }, 87 88 /** 89 * Make ajax calls. 90 */ 91 ajaxCall: function (evt, path, ifAdd) { 92 let formData = []; 93 if (ifAdd) { 94 formData['node_id'] = evt.target.parentNode.attributes['data-node'].nodeValue; 95 formData['node_title'] = evt.target.parentNode.attributes['data-title'].nodeValue; 96 } else { 97 formData['node_id'] = evt.target.attributes['data-node'].nodeValue; 98 formData['node_title'] = evt.target.attributes['data-title'].nodeValue; 99 } 100 101 $.ajax({ 102 url: Drupal.url(path), 103 type: 'POST', 104 data: { 105 'id': formData['node_id'], 106 'title': formData['node_title'] 107 }, 108 dataType: 'json', 109 success : function (data) { 110 Drupal.behaviors.agovAddBookmark.showMessage(data.content); 111 }, 112 error : function (request, error) { 113 if (window.console) { 114 console.log("Response: " + JSON.stringify(request)); 115 } else { 116 alert("Response: " + JSON.stringify(request)); 117 } 118 } 119 }); 120 }, 121 }; 122 123 /** 124 * Open bookmarks click function. 125 */ 126 Drupal.behaviors.agovOpenBookmarks = { 127 attach: function (context, settings) { 128 const elements = once('agovOpenBookmarks', '#favorites-open-bookmarks', context); 129 $(elements).each(function () { 130 $(this).click(function (evt) { 131 evt.preventDefault(); 132 Drupal.behaviors.agovAddBookmark.openFavorites(); 133 }); 134 }); 135 }, 136 }; 137 138 /** 139 * Close bookmarks. 140 */ 141 Drupal.behaviors.agovCloseBookmarks = { 142 attach: function (context, settings) { 143 const elements = once('agovCloseBookmarks', '#favorites-close-bookmarks', context); 144 $(elements).each(function () { 145 $(this).click(function (evt) { 146 evt.preventDefault(); 147 $("#favorites-container").css("display", "none"); 148 }); 149 }); 150 }, 151 }; 152 153 window.addEventListener('resize', function () { 154 $('#favorites-close-bookmarks').click(); 155 }); 156})(jQuery, Drupal);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.