SitePoint Sponsor

User Tag List

Results 1 to 22 of 22
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2001
    Location
    Panhandle of Florida (White Sand/Brown Skin)
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    go to this page
    http://www.emedicine.com/emerg/topic470.htm

    now highlight a word in one of the paragraphs and watch what happens...

    Can someone explain how this is done to me?

    thanks!

  2. #2
    Team SitePoint AlexW's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne
    Posts
    832
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    It's awesome.

    It has to be a service that Merrian Webster are marketing. Very clever. I'm going to research it a bit. Could be quite useful for SitePoint.

    You seem to just add this script to your page 'http://www.emedicine.com/medlook.js' and that selects and sends the text to a CGI script at M-W, which sends back the result.

    Nice.
    Alex Walker
    SitePoint Developer
    SitePoint - Learnable

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I know little about JavaScript but this is awesome. But I can't for the life of me work out where the selection event is handled. I can see that function display(e) is the driving function that makes everything happen - so this is the function that would need to be triggered by an event handler. But where is the event being handled. Wow!?!

  4. #4
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Amazing indeed! WOW
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  5. #5
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It might help if this thread was moved to the Client Side Scripting forum

  6. #6
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But where is the event being handled.
    Right at the bottom of the page they're pulling in another js file that contains the event handler, which calls the display function on the event onmouseup.

    Pretty cool stuff.

  7. #7
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This code is copied for fair use for the purpose of critique:
    Code:
    // Trigger.js 2.0
    if (window.Event)
       document.captureEvents(Event.MOUSEUP);
    document.onmouseup = display;
    Why did they put the event handling code at the bottom of the body of the page? Is that simply so that the onmouseup | MOUSUP event doesn't get handled before the page has fully loaded?

  8. #8
    SitePoint Wizard silver trophy TheOriginalH's Avatar
    Join Date
    Aug 2000
    Location
    Thailand
    Posts
    4,810
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Pile of pooh !

    Didn't work in Opera

    H
    ~The Artist Latterly Known as Crazy Hamster~
    922ee590a26bd62eb9b33cf2877a00df
    Currently delving into Django, GIT & CentOS

  9. #9
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by freakysid
    MOUSUP event doesn't get handled before the page has fully loaded?
    Make sense freakysid. or it could be at the bottom so the entire page contents will work with the script?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  10. #10
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If they put the event at the top of the page, and you did click your mouse, the OS would fire the event. Even if Javascript doesn't handle it yet, the event will be there and could cause errors in bad implementations of the Javascript specification.
    Wayne Luke
    ------------


  11. #11
    SitePoint Zealot
    Join Date
    Mar 2001
    Location
    Panhandle of Florida (White Sand/Brown Skin)
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well its awesome as hell...

    And NBCi.com thought they were revolutionizing the internet hah!

    this page hasnt been edited since 2000/09/08 ROFL

    that means this whole "any word, click it, get instant information" has been out long before NBCi "invented" it


    Another funny thing is that the page doesnt even tell you about this dictionary program... I just happened to highlight something to copy and paste it into a search engine heh

  12. #12
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    D¨n ╔ideann, Alba
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trusting every1 here is using (Opera-fiends apart) IE5+, since I reckon this will only work in W3C-DOM browsers such as IE5+ or NS6+. Certainly, highlighting a piece of text uses (i believe, though somebody might want to correct me on this) the text-range method, which is unavailable to Navigator users and most likely IE4 users too. (Opera users can go jump, since Opera (despite what Opera may say) has poor JS support.) Nonetheless, the website is awesome.

    If any1 wants to learn how to do this sort of thing, then go to msdn.microsoft.com/webworkshop

  13. #13
    Team SitePoint AlexW's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne
    Posts
    832
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Seems to work fine in NS6.

    Great thing is users with browsers that aren't supported, just get what they always got, nothing less.
    Alex Walker
    SitePoint Developer
    SitePoint - Learnable

  14. #14
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey, what does this do exactly? When I select a word or two, it says in the status bar "You have selected a large amount of text. This text is copyrighted by eMedicine, Inc." and then freezes my IE. I'm using IE 5.01 on Win2k.

  15. #15
    Team SitePoint AlexW's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne
    Posts
    832
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I'm using IE5 on win98.

    When you high-light or double-click a word in the body of text it automatically pops up a window that gives an explanation and pronunciation of the term from the merrian-webster site.
    Alex Walker
    SitePoint Developer
    SitePoint - Learnable

  16. #16
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Scot-Bot
    I'm trusting every1 here is using (Opera-fiends apart) IE5+, since I reckon this will only work in W3C-DOM browsers such as IE5+ or NS6+. Certainly, highlighting a piece of text uses (i believe, though somebody might want to correct me on this) the text-range method, which is unavailable to Navigator users and most likely IE4 users too. (Opera users can go jump, since Opera (despite what Opera may say) has poor JS support.) Nonetheless, the website is awesome.

    If any1 wants to learn how to do this sort of thing, then go to msdn.microsoft.com/webworkshop
    I believe you may be mistaken. It works fine on NN 4.08 (NS4.7) for Mac. Because I don't know much about JavaScript and event handling I read this last night when I was pondering over the code.

    http://developer.netscape.com/docs/t...enthandler.htm

    As you can see from the code I cut-and-pasted from the site in my last post, the event being handled is the onMouseUp event.

    From reading over the two javascript files used in that page the gist of the logic appears to be this:

    When a onMouseUp event is triggered call function display()

    Function display() uses getSelection method (from memory - or something similar - like I said I'm not very well versed with JavaScript) to return the currently selected text in the document. It then uses a couple of utility functions to trim the selection string. If the string is empty the function exits. If the string is a hyperlink it allows the hyperlink event to occur. Otherwise another function popup() is called and passed the string. popup() creates a popup window and calls a url which includes the string. The resulting document is generated from a CGI which is essentially a dictionary and reference for the search string.

    That's mumbled off the top of my head from my memory of looking over the code last night.
    Last edited by freakysid; May 10, 2001 at 18:19.

  17. #17
    Irritability Defined
    Join Date
    Jul 2000
    Location
    80,000 feet below the surface
    Posts
    1,442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Event handlers are reasonably well implemented in version 4 browsers (particularly mouse-up/down)..... You may get sketchy results in NN4 but I know for a fact that it should be right in IE4.

    Very, very cool technique.....
    My 2 Cents (or is that 2.2 Cents including GST?)

  18. #18
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    D¨n ╔ideann, Alba
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just checked out getSelection() and it appears to be Netscape only.

    There must have been another IE method that achieves the same thing, so does any1 know what it is?

  19. #19
    SitePoint Addict Percipient's Avatar
    Join Date
    Jun 2000
    Location
    Summerland, BC, Canada.
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by qslack
    Hey, what does this do exactly? When I select a word or two, it says in the status bar "You have selected a large amount of text. This text is copyrighted by eMedicine, Inc." and then freezes my IE. I'm using IE 5.01 on Win2k.
    Don't select a large amount of text. It's in the script for someone to get the message you got if more than 40 chars are selected. Just select a word of phrase, like a medical term.
    Ed Rands

  20. #20
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Scot-bot, have you looked at the code?

    The code below is from http://www.emedicine.com/medlook.js and is shown here for fair use for the purpose of review and critique:
    Code:
    function display(e) {
    
    if (document.getSelection) {
    var str = document.getSelection();
    } else if (document.selection && document.selection.createRange) {
    var range = document.selection.createRange();
    var str = range.text;
    } else {
    var str = "";
    alert("Sorry, Medical Dictionary Lookup is not possible with your browser. Please upgrade to Netscape's or Microsoft's latest browser.");
    return;
    }
    I also found some information about this topic here http://www.webreference.com/js/colum...ssbrowser.html

  21. #21
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the link freakysid...i guess you did alot of research into this?
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein

  22. #22
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    D¨n ╔ideann, Alba
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx, Freaky, I thought the MS way might have had something to do with text-ranges.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •