Blog

JavaScript

I regularly work on medium to large scale websites using both Laravel and CakePHP. A common part of the development process is building in some additional JavaScript functionality to improve the user experience. This can often be functionality that is only relevant to specific pages. For a example, on an ecommerce site the checkout process may consist of several steps each with functionality unique to that page; the basket step may need the ability to update quantities and totals whilst the payment screen may need to toggle fields depending on the card type.

Earlier this week I was helping a colleague write some vanilla JavaScript to prevent a form from being submitted multiple times by an overzealous button clicker. The solution needed to be some framework-free JavaScript code. Thankfully this is pretty simple to do, so I thought I’d share some of the options here.

TinyMCE’s pagebreak plugin is a handy way of providing users a way of marking breaks in content by placing a HTML comment in the source code denoting the break. However, if you are using the editor’s valid_elements attribute to restrict HTML elements used in the content (a good idea if you don’t want all sorts of messy markup getting added) you need to make sure you allow comment tags.

The TinyMCE link dialog.

If you’re using the link plugin for TinyMCE to add links to content and want to get rid of the target attribute options then the trick is to set target_list to false in the editor’s configuration.

5 Functions of the Console Object You Didn’t Know

#

If you’re debugging JavaScript you’ve probably heard of and used console.log(), but there’s much more to the Console object. This article discusses 5 functions of the Console object that you may not have heard of, but you’ll want to start using from now.

JavaScript: Taking Off the Training Wheels

#

A good motivational article on getting to grips with coding JavaScript (without using libraries like jQuery).

If nothing else, learning JavaScript will improve your jQuery code; you’ll be comfortable writing jQuery from scratch and feel happy bending others’ code to your own purposes. Writing efficient, fast and bug-free jQuery is also made much easier when you have a good appreciation of JavaScript, because you can look at what jQuery is really doing.

The inclusion of jQuery in a custom Drupal theme seems to cause a lot of confusion to people new to Drupal. There is, of course, a proper way of doing it and it's not that difficult once you know how.