Created
November 10, 2008 02:00
-
-
Save plasticine/23403 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
$(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