Demo Time
Keeping in mind that the intention of the presentation was to give a brief overview, I built a demo page to illustrate some of the more user event-driven aspects of JavaScript to provide the biggest “wow” factor for the team. To speed up the development of this page I used a few pre-existing JavaScript libraries namely jQuery and Semantic-UI.
Using JavaScript libraries provides you with out-of-the-box functionality for common features without needing to write out that functionality yourself. Semantic-UI, as used on the page, makes creating a popup, accordion menu and show/hide animations trivial. There are a plethora of other libraries available offering wide features – from D3.js to help create rich charts to ClippyJS that lets you bring back an old Microsoft favorite character.
I used these libraries to help me create four sections of interactions – all showing their corresponding code – for highlighting ways in which JavaScript, in the browser, without an internet connection, can affect one’s web experience. The sections in the demo are:
Abracadabra
In this section, there is a paragraph of plain text and a button that toggles the visibility of that paragraph element. Here I highlight how, using JavaScript, it is possible to manipulate a webpage’s content after it has been loaded.
Using JavaScript to show/hide elements.
Login to Skynet
Unlike Abracadabra which was a more frivolous, warmup demo, this section presents standard-looking username and password fields prevalent on websites today. In this demo, we see that with JavaScript it’s possible to access data a user types into a webpage. On clicking submit, the username and hidden password get copied and displayed – including the previously hidden password – in fields to the right of where the user typed.
Copying input field data, including a password field into another element.
Mousing Around
This section, as its name alludes to, involves four purely mouse-based activities. The first highlights how it is possible to be aware of when the mouse cursor is placed over a particular element on a webpage and then carry out an action when that happens. The second item does the same but is based on a user double-clicking an element, at which point a third-party JavaScript library (Semantic UI) is used to display a popup. The last two items show how JavaScript is even able to disable right-clicking for context menus.
Experiment with mouse events: hovering, double-click and right-click.
Keyboard Fun
With all of the demo activities above, I had members of our Growth team show them off. This last section was the most sinister fun to show off. For this demo the user was asked to type the following phrase into a texarea element:
The quick brown fox jumps over the lazy dog.
On typing the input, as you’ll see in the demo, one of the keys is barred from being input. After noticing that, I then asked our participant to get the phrase into the element using any other means. One could copy the text but then they would see that right clicking is disabled when trying to use the context menu to paste the value in. Using the keyboard shortcuts for the Control/Command (on Mac) + V were also barred. Both restricted activities triggered popups.
Playing with the keydown keyboard events.
Bonus Goodie!
As a bonus, almost hidden goodie, I added functionality to demonstrate that a webpage can be aware of whether or not a user is actively in the webpage window – i.e., it is the currently focused window. Try it out.
I hope you enjoyed this overview as much as I enjoyed spending way too much time crafting the demo page for it which was fun. Feel free to reach out to me at dsmall [at] brightgauge [dot] com if you have any feedback, questions or praise.