Skip to content

Instantly share code, notes, and snippets.

@plasticine
Created November 10, 2008 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plasticine/23403 to your computer and use it in GitHub Desktop.
Save plasticine/23403 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
jQuery.fn.commentform = function(){
return this.each(function(){
$("#slider").slideToggle("slow").toggleClass('open');
$(this).toggleClass("active");
if($(this).attr('id')){
var replyData = /reply-([\d]{1,})-([\w]{1,})/.exec($(this).attr('id'));
var userSelection = getSelectedText();
if(userSelection){
$('textarea#comment').val("'"+userSelection+"'" + '\n\n' + '@'+replyData[2]+': ').focus();
}else{
$('textarea#comment').val('@'+replyData[2]+': ').focus();
}
}else{
$('textarea#comment').val('');
};
});
};
function getSelectedText(){
if (window.getSelection){ return window.getSelection().toString(); }
else if (document.getSelection){return document.getSelection(); }
else if (document.selection){ return document.selection.createRange().text; } // this is specifically for IE
return false;
};
$('a.openform').click(function(){
if(!$("#slider").hasClass('open')){
$(this).commentform();
}
return false;
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment