Sha256: 29c8de0403b2b1b2cb669bc50674a80156abbfe7cb3435840eb4e3ec0c76f5b6
Contents?: true
Size: 1.26 KB
Versions: 3
Compression:
Stored size: 1.26 KB
Contents
(function() { NodeList.prototype.dismissible = function(options) { for (var i = 0; i < this.length; i++) { this[i].dismissible(options); } } HTMLElement.prototype.dismissible = function(options) { var hide = this.querySelector('[data-dismissible-hide]'); if (hide) { hide.addEventListener('click', function(event) { event.preventDefault(); this.dismiss(options); }); } } HTMLElement.prototype.dismiss = function(options) { var block_name = this.getAttribute('data-dismissible-hide'); var block = document.querySelector('[data-dismissible=' + block_name + ']'); var csrf = document.querySelector('meta[name=csrf-token]'); var token = csrf != null ? csrf.getAttribute('content') : null; var xhr = new XMLHttpRequest(); xhr.open('PUT', '/dismissible_blocks.json'); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onload = function() { if (xhr.status === 200) { if (options !== undefined && options.dismiss !== undefined) { return options.dismiss(block); } else { return block.parentNode.removeChild(block); } } }; xhr.send(JSON.stringify({ block: block_name, authenticity_token: token })); } })();
Version data entries
3 entries across 3 versions & 1 rubygems