JS – Avoid duplicating addEventListener()

I see this mistake way more often than I should. Someone adds an event listener with an anonymous function callback to an element (like a button) then puts it in a a function that may get called multiple times. While this very common setup may seem harmless, it can create some serious issues.

The problem is this setup will add multiple listeners to the element, a new one each time the function is called, meaning three calls will add three listeners, then when the event is triggered the callback will be run three times. This JSFiddle demo clearly shows the scenario in action.

Continue reading “JS – Avoid duplicating addEventListener()”

Watch what you name your form inputs!

I came across this little snafu yesterday while working on my capstone, which I was able to reproduce in all the major browsers.

If your form has any form of <input> or <button> with a name attribute of “submit” (name="submit"), it will override the <form>‘s JavaScript .submit() method and throw an error when you try to call it (as I do in the same code above)!

form-submit-firefox

Firefox

form-submit-chrome

Chrome

form-submit-ie

Internet Explorer 11

Changing the attribute’s value to anything else, even “form-submit”, will prevent the method from being overwritten. So be aware of what you name those inputs! They could introduce some pretty nasty bugs! It took me a bit to track this down because it was behavior I did not expect!

-Caleb

Android version fragmentation needs fixing

If you own a smart phone, tablet, “phablet” or follow the tech industry at all, you will have heard this one word used over and over again in a ton of blog posts (including this one), news articles, and pretty much anything else you can think of:

Fragmentation.

In the context of phones, tablets, and the like, fragmentation is defined in a basic form as:

Fragmentation is the result of many generations of smartphones or tablets running various versions of the same operating system.

While fragmentation has been primarily used in reference to Android and iOS, it is also present in Windows, Mac OS X, and Linux operating systems, though it is not near as severe there as it is in mobile devices. Further, fragmentation does not occur solely in the core of an operating system (arguably the worst kind), it can occur to any form of software. For example, Niels Leenheer wrote an excellent article on Android web browser fragmentation.

Continue reading “Android version fragmentation needs fixing”

Possible move from WordPress.com?

There is something I have been thinking about lately, and I would love it if you, my readers, would express your opinion on the matter. 🙂

As you may know, I recently celebrated four years on WordPress. This blog was some of my first real exposure to the Web. Though at times it has been hard for me to publish anything, I have blogged long enough that I feel guilty if I do not publish something on a consistent basis. I enjoy blogging and only wish I had more time to write out all my thoughts, observations, and experiences as primarily related to programming and website development.

Continue reading “Possible move from WordPress.com?”

Notepad.exe in HTML5 and JavaScript

On the morning of 10 October, I tired of working on my capstone and had finished contributing a patch to an open-source project, I decided I needed a small, fun, project to quickly create as a change of pace. A few minutes later, either inspirational or pure randomness stuck: recreate Windows Notepad.

Continue reading “Notepad.exe in HTML5 and JavaScript”

WordPress – Load enqueued JavaScript in async or defer

Lately I have been working with WordPress, creating a complete website (even original theme) with it for my college capstone. Generally, things have been fair but there have been some things I have wanted to write a rant-y blog post about (but will not because I value my readers too much 🙂 ). One of those things is loading JavaScript into a site.

According to the documentation, wp_enqueue_script is “the recommended method of linking JavaScript to a WordPress generated page.” So as a good developer I have used this for loading my JavaScript. Aside from the rather crazy parameter order and defaults, I was quickly irked by the inability to load scripts asynchronously. After much searching though the WordPress docs and various programming sites, I came across the following article which uses a simple hash to denote async scripts, use the clean_url hook to filter all external URLs for JavaScript files (although file extensions are only hints) and add the async HTML attribute. However, the function was a bit too naive and limited for my taste (what if I wanted to defer a script?), so I wrote my own function using the basic idea of that snippet, which is the topic of this article. 🙂

Continue reading “WordPress – Load enqueued JavaScript in async or defer”

4 years of Triangles!

Today is 13 of October, 2015. Today is a very special day, for today marks the four year anniversary of this blog! 😀 Well, actually yesterday marked the 4th anniversary, but I have never seemed to be able to get that date right, so one day late is close enough. 😛

It has been quite a four years. In four years I have published over 200 blog posts, nearly 40 tutorials, and received over 50,000 views. I have written on topics from Python and JavaScript code snippets to observations on ethics and code styles, analysis of behavior on the Internet and Internet Explorer’s problem with vector graphics, to lighthearted examination of paradoxes and blown lightbulbs. Yes, in four years I have done quite a lot, and despite my regularly irregular posting schedule and super long times without activity, I continue to gain readers and occasional comments from people who enjoyed an article or had something to add.

It has been a great four years and I look forward to the next four (and beyond) years. I may not still be using this domain and WordPress in four years, nor may my writings be the same as they are now in style or topic, but I do know I will continue to write on whatever topics I write on, for it is something I enjoy and hopefully you enjoy reading.

So thank you, my readers. Thank you for giving me the motivation I need to continue writing. Thank you for reading what I write and commenting on the article with your thoughts and questions. Without your support I would not be writing (and you not reading) this milestone post. 🙂

Now to God be the glory for gifting me the knowledge, talent, and abilities to work and labor for His honor,

-Caleb