Object initialization is surely among the most requested features in OOP with JavaScript. JavaScript has no constructor methods like PHP, so we need to take inspiration from existing JavaScript frameworks, such as Prototype. This library provides an
initialize()
method to be used with any new object that is being created. I've tried to emulate this behavior but I found only a quick-and-dirty solution that works with objects that make use of the functional constructor patter. Here's the code:
CSS: styling a video gallery
In this post I will show you how to style a video gallery with CSS. We're going to apply the same principle used for fluid image galleries, that is, element dimensions expressed in percentages, including the
object
element. As you will see, since this kind of element is just a replaced element as images, everything will work as expected. Now let's start with a basic HTML structure that makes use of an unordered list to contain our gallery:
jQuery: convert new lines to br
Replacing new lines with the
br
element is a required task that we need to perform especially when we want to normalize the default behavior of browsers with the innerHTML
property. Browsers such as Internet Explorer, for instance, don't preserve new lines when they have to copy and reproduce the HTML content of an element. Characters such as \n
or \r
must therefore be converted into br
before dealing with this HTML content. In this post I'm going to show you how to accomplish this task with jQuery.