Highlighting text selections

This is a discussion on "Highlighting text selections" within the JavaScript Forum section. This forum, and the thread "Highlighting text selections are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 15th, 2008, 16:17
New Member
Join Date: Mar 2008
Location: United Kingdom
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Highlighting text selections

Dear all,

Hi, I'm an undergraduate currently embarking on my final year project. The objective is to implement a sticky note annotation system where the stickies must be linked to the text on the webpages. Also, the system is to provide a function to highlight selected texts.

SO my design is:

1) capture the selected text
2) encapsulate the selected text with a <span id="spanTag"> tag
3) to add a sticky, just append a new <div id="sticky"> to the span
3) to highlight, just change the background color property of the <span id="spanTag"> to yellow

Problem:

Initially, I have tried first capturing the selected text, then find the parent element of the text node handling the selection event and split the whole text node into three sections. The purpose is to capture the substring before the selected text and the substring after the selected texts. This method was no good since it prevents the page to be highlighted more than once.

Secondly, I have tried using W3C Range object and IE's TextRange. I use the W3C Range object's insertNode method to insert a <span> tag encapsulating the range. With IE, I used the TextRange object's pasteHTML method to add <span tag. This method works much better than the first and it's more stable. However, problem arises when a user wants to highlight text across two paragraphs e.g. end of paragraph 1 and start of paragaph 2. The Range just starts a new line with the selected texts hence changing the appearance of the web page.

Can anyone please suggest a better way of doing this!?OR any other way to achieve the objective???

NB: I also need to save the information in a database so that a user can see his/her annotations + other user's annotations on a webpage.

THANK YOU VERY MUCH for your attention.

Regards,

Mike
Reply With Quote

  #2 (permalink)  
Old Mar 15th, 2008, 16:35
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 825
Blog Entries: 6
Thanks: 0
Thanked 11 Times in 11 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: Highlighting text selections

Try innerHTML:

Code: Select all
myobj.innerHTML = myobj.innerHTML + "<div id="new_note!"></div>";
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: Nerd Poster (Jun 2nd, 2008)
Reply With Quote
  #3 (permalink)  
Old Mar 15th, 2008, 17:00
New Member
Join Date: Mar 2008
Location: United Kingdom
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Highlighting text selections

I have tried innerHTML and it works the same as the first method. For the first method I initially parse the whole text node that's handling the selection into three parts, the substring BEFORE the selected string, the substring AFTER the selected substring and the selected subtring. Then I created a text node contianing the BEFORE substring, a text node containing the AFTER substring and a text node containing the "<span>" + the selected substring.
Then I removed the entire text node containing the selected substring and append the newly created text nodes back on. It worked but not in a very stable way. Also, no other highlighting could be done on texts appearing after the highlighted string! I did the same using innerHTML and the result is the same.
Reply With Quote
  #4 (permalink)  
Old Mar 15th, 2008, 17:54
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 825
Blog Entries: 6
Thanks: 0
Thanked 11 Times in 11 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: Highlighting text selections

im still not quite seeing what your trying to get at, but possibly use js to mess around with the CSS styling to acheive your affect.
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: Nerd Poster (Jun 2nd, 2008)
Reply With Quote
  #5 (permalink)  
Old Mar 15th, 2008, 20:15
New Member
Join Date: Mar 2008
Location: United Kingdom
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Highlighting text selections

I have posted my work online. Please go to http://www.geocities.com/mailsation99/addtoolbar.html. It's a bookmarklet and only two functions (add sticky and highlight) work but annotations are not saved because server side is done implemented yet. What I'm trying achieve is something like the Diigo annotation system. A system where users can annotate on a web page by adding sticky notes or highlighting texts and they can be saved for retrieval later and by other users of the application.
Reply With Quote
  #6 (permalink)  
Old Mar 15th, 2008, 20:46
CloudedVision's Avatar
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 825
Blog Entries: 6
Thanks: 0
Thanked 11 Times in 11 Posts
Send a message via AIM to CloudedVision Send a message via MSN to CloudedVision Send a message via Skype™ to CloudedVision
Re: Highlighting text selections

The link is broken.
__________________
echo "Take it easy, ".$CloudedVision;
.links { site: other-road-design; blog: only-nerds-allowed; project: resource-fish; organization: ARMIES6; }
<quote>&quot;I think it's wrong that only one company makes the game Monopoly&quot; - <name>Steven Wright</name></quote>
Last Blog Entry: Nerd Poster (Jun 2nd, 2008)
Reply With Quote
  #7 (permalink)  
Old Mar 15th, 2008, 21:24
New Member
Join Date: Mar 2008
Location: United Kingdom
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Highlighting text selections

Sorry, it's http://www.geocities.com/mailstation99/addtoolbar.html
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Navigation from 2 pulldown selections? svoltmer JavaScript Forum 2 Apr 28th, 2008 12:28
Highlighting the active link lmc148 Web Page Design 4 Mar 3rd, 2008 19:14
[SOLVED] color-box selections pesho318i JavaScript Forum 6 Dec 22nd, 2007 20:57
Highlighting Text bovverboi Web Page Design 4 Nov 5th, 2006 11:36
selections within textareas benbacardi JavaScript Forum 16 Feb 16th, 2005 13:59


All times are GMT. The time now is 11:16.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43