Solved

JavaScript from JSFiddle

Posted on 2014-03-01
3
300 Views
Last Modified: 2014-03-01
I found the following html and JavaScript on JSFiddle.  http://jsfiddle.net/qfmsy/1/

What code is needed to make this work in an html file I would create using notepad?


The code expands text from an abbreviation into full text.

html section:

<textarea id="comment" rows="20" cols="30"></textarea>

JavaScript Section:

shortcuts = {
    "cci": "customer called in",
        "rfc": "request for comments",
        "www": "world wide web"
}


window.onload = function () {
    var ta = document.getElementById("comment");
    var timer = 0;
    var re = new RegExp("\\b(" + Object.keys(shortcuts).join("|") + ")\\b", "g");



    update = function () {
        ta.value = ta.value.replace(re, function ($0, $1) {
            return shortcuts[$1.toLowerCase()];
        });
    }

    ta.onkeydown = function () {
        clearTimeout(timer);
        timer = setTimeout(update, 200);

    }


}
0
Comment
Question by:rreiss60
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39897530
<!DOCTYPE html>
<html>
<head></head>
<body>
<textarea id="comment" rows="20" cols="30"></textarea>

<script>
shortcuts = {
    "cci": "customer called in",
        "rfc": "request for comments",
        "www": "world wide web"
}

window.onload = function () {
    var ta = document.getElementById("comment");
    var timer = 0;
    var re = new RegExp("\\b(" + Object.keys(shortcuts).join("|") + ")\\b", "g");

    update = function () {
        ta.value = ta.value.replace(re, function ($0, $1) {
            return shortcuts[$1.toLowerCase()];
        });
    }

    ta.onkeydown = function () {
        clearTimeout(timer);
        timer = setTimeout(update, 200);

    }
} 
</script>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:rreiss60
ID: 39897673
Dynamite!
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39897706
That's pretty cool, I like that.
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question