0

ok so I have two codes, issues with both. They go hand in hand, so please don't say make two separate post. I need the scrollTop to work after the second code is finished. Thank You


This part is DONE~!

$('html,body').animate({
   scrollTop: '+=' + $('a[name="quickreply"]').offset().top + 'px'
 }, '3000');

Changed it to

$('html,body').animate({
   scrollTop: $('a[name="quickreply"]').offset().top;
 }, '3000');

Next I found this code here on stackoverflow from tim down I believe?

Updated fiddle: http://jsfiddle.net/dKaJ3/340/

I need that to only be able to select in a certain div I choose, and only text not the HTML since my site only accepts BBcodes.

Here is the full code I was using but grabbing the entire post, instead I want only what the user selects.

$('.post').each(function() {
  var text = $('#text_editor_textarea');
  var uid = $(this).find('.username a').text();
  var usermess = $(this).find('.entry-content div div').text();
    $(this).find('.quote').click(function() {
    text.val(text.val()+'[quote="'+ uid +'"]'+ usermess +'[/quote]');
 $('html,body').animate({
    scrollTop: '+=' + $('a[name="quickreply"]').offset().top + 'px'
  }, '3000');
 });
});

Any assistance would be nice, as I've been working on the .getSelection for a few hours now and this is my first time using it. Thank you.

EasyBB
  • 6,176
  • 9
  • 47
  • 77
  • Really need some help with this, I am struggling lol. The two codes go hand in hand thank you. – EasyBB Mar 07 '13 at 05:37

2 Answers2

1

I think it should not say += indoor animate call but just =. This is because the offset is not calculated relative to the visible top of the document, but to the absolute top of the document.

yunzen
  • 32,854
  • 11
  • 73
  • 106
  • Hey now, that sounds logical, thank you, I'll try it out. Could you possibly help with the .getSelection part? I want to grab the selection of `.entry-content` and not the entire window... Any suggestions on that?---Page just scrolls to top instead of element now by removing the + – EasyBB Mar 07 '13 at 17:12
  • Ive gotten closer to it now, I have deleted the '+=' and the 'px' part so now all that is left after scrollTop is `$('a[name="quickreply"]').offset().top` which is the closest I've gotten. Just not perfect yet – EasyBB Mar 07 '13 at 17:27
0

Firstly, your question would get more attention if you split it into its component parts.

Anyway, part 1: in the user's selection, does the formatting need to be converted to bbcode? That could get complicated. Or is plain text ok? You could use a regular expression for that to remove the html tags.

Part 2: Here are several questions on how to prevent/allow selection of text:

Part 3: The scrolling. I can't see anything wrong with the code you've posted. Your JSFiddle doesn't seem to cover this problem. Any chance you could extract what you've got into one? I think it's another part of your code that's the issue.

Community
  • 1
  • 1
Jodes
  • 14,118
  • 26
  • 97
  • 156
  • Plain text is ok. I don't want any images, this is one question, since I don't want to use the one core code I have above, I want to use the .getSelection, then once the click the quote button itll quote and jump down to the textarea. So yeah they are hand in hand on this. Also the fiddle is Tim Downs and I just started editing it very little. I don't want to prevent selection, I want to use the getSelection for my quotes. – EasyBB Mar 07 '13 at 01:50