Created
November 10, 2008 02:51
-
-
Save plasticine/23408 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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<script type="text/javascript" src="http://digitalmash.com/assets/js/jquery.js"></script> | |
</head> | |
<body> | |
<script type="text/javascript" charset="utf-8"> | |
$(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; | |
}) | |
}); | |
</script> | |
<div id="name"> | |
<p> | |
<strong>some sample text</strong> | |
</p> | |
<p> | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
</p> | |
</div> | |
<ul> | |
<li> | |
<a href="/normal-comment-link" class="openform">normal comment link...</a> | |
</li> | |
<li> | |
<a href="/reply-to-comment" class="openform" id="reply-1-justin">reply comment link...</a> | |
</li> | |
</ul> | |
<div id="slider" style="display: none;"> | |
content... | |
<textarea name="comment" id="comment" rows="8" cols="40"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment