JavaScript Garden

JavaScript Garden is a growing collection of documentation about the most quirky parts of the JavaScript programming language. It gives advice to avoid common mistakes, subtle bugs, as well as performance issues and bad practices that non-expert JavaScript programmers may encounter on their endeavours into the depths of the language.

JavaScript Garden does not aim to teach you JavaScript. Former knowledge of the language is strongly recommended in order to understand the topics covered in this guide

Clusterize.js

Small JavaScript library for rendering huge tables and lists by keeping only visible rows in the DOM, reducing browser load for data-heavy views.

Handling Keyboard Shortcuts in JavaScript

Despite the many JavaScript libraries that are available today, I cannot find one that makes it easy to add keyboard shortcuts(or accelerators) to your javascript app. This is because keyboard shortcuts where only used in JavaScript games - no serious web application used keyboard shortcuts to navigate around its interface. But Google apps like Google Reader and Gmail changed that. So, I have created a function to make adding shortcuts to your application much easier.

Jasmine: Reset the location when testing code that uses pushState / replaceState

Browser navigation during pushState or replaceState tests can leave Jasmine on the wrong URL and break test reruns. Saving and restoring the location keeps the suite on the spec page.

Caution when using the || operator to set defaults

|| can overwrite valid falsy values like false, 0, and '' when setting defaults; use nil or null checks, fetch, or nullish coalescing instead.

Ruby on Rails 4 and Batman.js

Batman.js is a lightweight JavaScript MVC framework with a Rails-friendly style for building small client-side apps and blog tutorials.

Mocking time in Jasmine specs

Control time in Jasmine tests with the built-in jasmine.clock() to fake timers and new Date() without adding SinonJS.

Defining "partials" in pure HTML without additional rendering helpers

Define reusable page fragments directly in HTML without server or client rendering helpers; a tiny JavaScript snippet enables custom elements and partial-like reuse.

How to make your application assets cachable in Rails

Rails asset URLs need fingerprints or timestamps to let browsers cache images, stylesheets, and scripts long-term without serving stale files after updates.

Webpack: Automatically generating an icon font from .svg files

Vector icons are easy to use but tedious to build; webpack plugins can automate SVG-to-icon-font generation and keep icons aligned, scalable, and JavaScript-free.

hyphenator

Javascript that implements client-side hyphenation of HTML-Documents.

OscarGodson/jKey - GitHub

jQuery plugin to register callback functions to keyboard shortkuts. Keyboard events in vanilla Javascripts are super-painful to work with, so hopefully this library can help.

kangax's protolicious - GitHub

Added utility methods for the Prototype Javascript framework.

Prototip 2 - Create beautiful tooltips with ease

Prototip allows you to easily create both simple and complex tooltips using the Prototype javascript framework.

Please note: "Permission to use Prototip on your domain is required and can be obtained by paying a small fee."

flot - Google Code

Flot is a pure Javascript plotting library for jQuery. It produces graphical plots of arbitrary datasets on-the-fly client-side.

biilly's doodle.js at master - GitHub

Javascript sprite library for Canvas

mynyml's holygrail at master - GitHub

The Holy Grail of testing for front-end development; execute browser-less, console-based, javascript + DOM code right from within your Rails test suite.

Scroll a textarea to a given line with jQuery

Scrolling a textarea to a specific line depends on pixel line height and can drift when wrapped lines change the visual line count.

Async/Await Will Make Your Code Simpler

Async JavaScript can become long and deeply nested when promises are handled awkwardly; async/await offers a cleaner syntax for readable asynchronous code.

Tearing Down Capybara Tests of AJAX Pages

Pending AJAX requests can die when a Capybara test ends or switches scenarios, causing flaky JavaScript specs. Waiting for the page to load helps avoid the failure.

PhantomJS: Headless WebKit with JavaScript API

PhantomJS is a minimalistic headless WebKit.

It has fast and native support for various web standards:

DOM handling, CSS selector, JSON, Canvas, and SVG.

PhantomJS can be fully scripted using JavaScript. It is an optimal solution for headless testing of web-based applications, site scraping, pages capture, SVG renderer, PDF converter and many other usages.

Escape a string for transportation in a URL

Safely transporting arbitrary text in URLs requires percent-encoding reserved characters like & and =; Rails helpers do this automatically, while manual URLs need CGI.escape or encodeURIComponent.

Event delegation (without jQuery)

Single-listener event handling can cut setup cost and support dynamically added elements, but it can slow fast events and limits bubbling control.

hint.css - A tooltip library in CSS

CSS-only tooltip library for projects with many tooltips, avoiding JavaScript overhead and working in IE9+.