Sha256: ce75d7cb84d057ed0f8664a0cfc26e9ea80e927047185be89b3f229c83a3ebca
Contents?: true
Size: 1.21 KB
Versions: 1
Compression:
Stored size: 1.21 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) { this.querySelector('[data-dismissible-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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
dismissible_blocks-2.0.1 | app/assets/javascripts/dismissible_blocks.js |