Skip to content

Commit

Permalink
Merge pull request #121 from glogiotatidis/snippet-xout-button
Browse files Browse the repository at this point in the history
[bug 1172579] Add handle clicks on block-snippet-button.
  • Loading branch information
glogiotatidis committed Aug 20, 2015
2 parents 79d962f + bb3a3c3 commit a5b1811
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions snippets/base/templates/base/includes/snippet_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
var parameters = ('sample_rate=' + SNIPPET_METRICS_SAMPLE_RATE + '&snippet_name=' +
show_snippet_id);
modifyLinks(show_snippet.getElementsByTagName('a'), parameters);
addSnippetBlockLinks(show_snippet.getElementsByClassName('block-snippet-button'));
} else {
showDefaultSnippets();
}
Expand Down Expand Up @@ -319,6 +320,21 @@
}
}

// Add links to buttons that block snippets.
function addSnippetBlockLinks(elements) {
var snippet_id = document.getElementById('snippet_set').getAttribute('data-snippet-id');
var blockSnippet = function (event) {
event.preventDefault();
addToBlockList(snippet_id);
sendMetric('snippet-blocked', function() { window.location.reload(); })
};

for (var k = 0; k < elements.length; k++) {
var button = elements[k];
button.addEventListener('click', blockSnippet);
}
}

// Check for localStorage support. Copied from Modernizr.
function supportsLocalStorage() {
var s = 'snippets-test';
Expand Down

0 comments on commit a5b1811

Please sign in to comment.