Javascript: page 1
The release of Jest 26 brought a new timer faking interface, which now supports Date mocks. I couldn’t readily find any documentation for this feature so, here is how I used in a project recently. Read more ⇒
To make the construction and maintenance of more advanced types easier it can be helpful to write some tests that ensure their correct function. This sounds a little easier than it turns out to be. As part of the ecosystem for TypeScript Microsoft have written and released the dtslint tool. It can be used to link and compile TypeScript types for static analysis and mostly serves to keep the @types/* packages in line. Read more ⇒
As TypeScript applications get more complex so do the types required to describe it. There are a number of built-in types that can be used for this purpose or combined to create more specialised types. What I term modifying types such as Partial and Required are included in the language and I will quickly cover these first to warm up for the deeper types we’ll address later. This article will quickly move on to focus on the slightly more advanced types beginning with Extract. Read more ⇒
TypeScript constructors and generic types
I have recently found myself needing a type for class constructors that is at once generic and tight enough to ensure a genuine constructor. This is useful in situations where you must handle a variety of classes - those that come from other libraries or applications that you cannot control. When writing your own dependency injection container or some other generalised library you cannot know what class constructors might be passed in. Read more ⇒
Conditionally loaded responsive content on the client side
Sometimes it is helpful to entirely change chunks of markup when a certain CSS media query is triggered. This could because a certain layout will not work on smaller screen sizes or because it refers to media that you would not want a mobile to download. Recently I had this exact problem when dealing with a site that included a grid based layout in a carousel/slider. When the browser was sized down from desktop it needed to change the number of columns in the grid. Read more ⇒
Firefox with Radio Inputs and it’s Annoying Autocomplete I recently had problem with Firefox’s autocomplete when using a jQuery star rating plugin. The linked article explains the problem more in depth and the code snippet below should get you going. if ($.browser.mozilla) { $("form").attr("autocomplete", "off"); } Read more ⇒
jQuery UI Datepicker appearing below Dialog
When creating a dialogue with jQuery that contains a Datepicker text input the Datepicker calendar will appear below the dialogue due to the dialogue’s z-index being higher. The easiest universal way to work around this is to include a one liner in the open event function of the initial dialogue call. $("#dialogue").dialog({ modal: true, open: function () { $("#ui-datepicker-div").css( "z-index", $(this).parents(".ui-dialog").css("z-index") + 1, ); }, }); Read more ⇒
I worked on a project while ago that required the use of iFrames to create “AJAX” file uploads. It took me a little while but I finally worked out how to get the contents of an iFrame using jQuery. To get the contents of an iFrame we need to wait until the iFramed content has finished loading as well. var iFrameBody = ""; $("#iframe").load(function () { iFrameBody = $(this).contents().find("body"); }); Read more ⇒
jQuery Using and Manipulating Select Lists
JQuery is a fantastic tool but sometimes its functionality can be obscure or doing it one way might not work in a certain browser (MSIE6 anybody!). I have often found myself trying to remember the best way to work with HTML select lists so I am compiling this list of hints for future use and I hope that you find it useful. All the examples below are written where this represents the select element of the select list. Read more ⇒
Firefox 3.1 has Web Workers (threading) and Geolocation
The latest beta 2 release includes web workers, which are essentially threads allowing you to farm off Javascript heavy lifting to background processes so that the interface can continue to load without being impacted upon. The Mozilla developer center [sic] has an interesting article on implementing them; Using web workers, which includes a couple of worked examples based on the Fibonacci sequence. Geolocation is an interesting one for services like Twitter, Jaiku and possibly Facebook as it would allow users an easy way of updating all the services with their current location simply by Firefox broadcasting the information. Read more ⇒