Created
March 27, 2015 23:12
-
-
Save premkumr/e2649b220e93cd3379bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function clone(o) { | |
return JSON.parse(JSON.stringify(o)); | |
} | |
function insert_fds_button(imageAttributes, params){ | |
// check for the correct page | |
if (! (!!document.querySelector(params.existsInPage))) { | |
return; | |
} | |
var img = document.createElement('img'), | |
button = document.createElement('button'), | |
wrapperDiv = document.querySelector(params.wrapper), | |
handleClick = function(e){ | |
var textarea = document.querySelector(params.form + ' ' + params.textarea), | |
form = document.querySelector(params.form); | |
e.preventDefault(); | |
if (-1 == textarea.value.indexOf(params.text)) { | |
textarea.value = textarea.value + "\n" + params.text + "\n"; | |
} | |
if (params.submit) { | |
//console.log('form will submit'); | |
//console.log(form); | |
form.submit(); | |
textarea.value = ''; | |
} | |
}, | |
key; | |
for(key in imageAttributes){ | |
img.setAttribute(key, imageAttributes[key]); | |
} | |
button.setAttribute('class', 'btn ' + params.buttonclass ); | |
button.appendChild(img); | |
button.addEventListener('click', handleClick, false); | |
wrapperDiv.appendChild(button); | |
} | |
var imageAttributes = { | |
width: "20", | |
height: "20", | |
align: "absmiddle", | |
src: "https://assets-cdn.github.com/images/icons/emoji/thumbsup.png", | |
alt: "Alrite ! Ship It!", | |
title: "Alrite ! Ship It!", | |
class: "emoji" | |
}; | |
var params = { | |
wrapper: '.js-new-comment-form .form-actions div', | |
existsInPage: 'div.view-pull-request', | |
submit: true, | |
form: '.js-new-comment-form', | |
textarea: '.js-comment-field', | |
text: ':thumbsup:', | |
buttonclass: 'btn-info' | |
}; | |
imageAttributes.src = "https://assets-cdn.github.com/images/icons/emoji/thumbsup.png"; | |
imageAttributes.title= "Alrite ! Ship It!"; | |
imageAttributes.alt= "Alrite ! Ship It!"; | |
insert_fds_button(clone(imageAttributes), clone(params)); | |
params.text = '[Radioactive reviewers: @umesh-fds, @nbayyana, @sanjay-fds, @davec-fds, @premkumr]'; | |
imageAttributes.src = "http://www.ipharmd.net/images/medium/tn_round_radioactive_symbol_clipart.png"; | |
imageAttributes.title= "Radioactive Review"; | |
imageAttributes.alt= "Radioactive Review"; | |
insert_fds_button(clone(imageAttributes), clone(params)); | |
params.text = 'Retest this please'; | |
params.buttonclass = 'btn-danger'; | |
imageAttributes.src = "https://assets-cdn.github.com/images/icons/emoji/repeat.png" | |
imageAttributes.title= "Retest this"; | |
imageAttributes.alt= "Retest"; | |
insert_fds_button(clone(imageAttributes), clone(params)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment