Week 9 Project: JavaScript something-or-other…

This “week’s” project started with a desire to write some JavaScript. I added the sub-directory (or folder, in more common parlance) and copied the index.html and style.css files used for the site’s main page (found at http://dev.kobayashicoding.net) into it. I then removed the text variables used to populate the various panel components, and also removed the “About” and “Contact” buttons, and the “Projects” drop-down menu. I then made changes in the code to display two empty Bootstrap “panel” elements, even though I had not yet determined exactly what I was going to put in them. Finally, I wanted to change the remaining “Home” button so that it would open the base site’s main page again, as this week’s project replaces the main page instead of opening and new tab or window.

Go to http://dev.kobayashicoding.net/, drop down the “Projects” menu, and choose “Week 9 (2018-08-01)” to see the result of this week’s tinkering.

Changing the “Home” button to reload the main page sent me searching for a simple, clean, and efficient way to effect this that would work both when opening the site’s files on my local PC and when viewing the live site on the public Internet. Because button elements don’t have an href  attribute, I went looking for how to accomplish this. My search quickly turned up the way to do this (setting the onclick event to assign ‘../index.html’ to window.location, which is part of the Browser Object Model (BOM)). This also got me thinking about the BOM, which I hadn’t really paid too much attention to before. So I decided to delve into it a bit. Which I did. Briefly. Because that’s all it took, really.

The next thing to do was to set sizes for the two panels. Because I’m using Bootstrap, and the panels are created using the div tag with a class of “panel,” I went to the Bootstrap site’s documentation to get the details of how to size and modify them. Alas, the version of Bootstrap I’d used was v3.7.3, and the “panel” class had been removed in the new version of Bootstrap (currently v4.1.3). So… part of this week’s project was to update the site from Bootstrap v3.7.3 to v4.1.3. In was… interesting… and informative.

The first task of the migration was to read the Migrating to v4 summary on the Bootstrap site. This was quite helpful in pointing out things that would break the site and would have to be changed. The main changes for me were going to entail replacing the “panel” references with references to the new “card” component.

As an aside, in upgrading from Bootstrap v3.7.3 to v4.1.3, I also had to decide how I wanted to implement Bootstrap. There are basically two ways to use the various, required files, either (1) download them and put them in a sub-directory of the site being developed or deployed, or (2) link to the files on the Bootstrap CDN. Previously, I had downloaded the files and stored them on the server with my project’s code. This time, I decided to use the link approach. The advantage of downloading the code and including it on the server is that if any changes are made to the framework, they won’t affect the site, so nothing breaks unexpectedly. And, that’s also the disadvantage – if errors are corrected or new features added, they won’t affect the site or be useful until the version on the site is replaced with the newest code. I figure it’s better to get bug fixes and take a chance on something breaking unexpectedly.

It turned out that the only major change I needed to make to accommodate the changes in Bootstrap was switching from “Panels” to “Cards.” The “Panel” component has been removed from Bootstrap and replaced by the “Card” component. Actually, the Card component is the new flexible content container that replaces Panels, Wells, and Thumbnails. It took only a few minutes to do a global search-and-replace, followed by a few more minutes of cleaning up to replace the Panels with Cards.

There were a few minor changes that I had to accommodate as well. The previously used “hidden” class has been replaced with the HTML 5 “hidden” attribute for elements that need to be displayed only at certain times. I also had to adjust some of the padding around the navbar as well as the margins around navbar-btn buttons and navbar-text text strings.

After getting the site back to its previous functionality, it was time to think about what to actually do this week. Working with the BOM, as I mentioned above, combined with a desire to become more familiar with the Document Object Model (DOM), as well as recent interest in Progressive Web Apps (PWAs) got me thinking about using JavaScript to generate the HTML for the page. This was easily done using the DOM methods createElement(), setAttribute(), createTextNode(), and appendChild(). Using these to create the body of the main page allowed me to use nested loops to create the HTML for the rows and columns of Card components. That saved a lot of typing (or, let’s be real – cutting and pasting) and also allowed me to pass in variables to control how many rows and columns to create. Using the DOM methods to create the navigation bar for the page was a bit more tedious, but it helped solidify my mental picture of the Document model and how all of the HTML elements fit together.

So, this week’s page looks fine, but doesn’t do anything. Maybe that will be next week’s project. Maybe.

Week 8 Project: Spans and Divs

Well, it’s been so long since I started/published this “week’s” project that I don’t rightly remember exactly what I was planning to do or even what I did. The code is a “refinement” of Week 7’s project, but not much has been changed. Because I don’t remember what I was planning to do, and because the code was published to the site, I’ll leave it there as a memorial to my (so far) inconsistent approach to the site.

<sigh>Enjoy! http://dev.kobayashicoding.net, then “Projects” and choose “Week 8.”</sigh>

Week 7 Project: CSS Grids

Well, after a lapse of 8 months, I finally have a new project up and running at Kobayashi Coding – an example of using CSS Grid layout. (Click on the “Projects” dropdown and choose “Week 7.”)

The result is similar to what Bootstrap and other grid frameworks provide, but without the additional Javascript and CSS files. The example on my project site is basically taken directly from the Mozilla Developer Network tutorial titled “Introduction to CSS Grid Layout” with very minor changes to the HTML and CSS. I found this particular tutorial through a Facebook post on the Firefox page – https://www.facebook.com/Firefox/videos/4910150590250/.

While this has increased my understanding of both CSS and grid layouts, I did have one problem that manifested itself in a couple of ways. You’ll notice that there are no spaces around the two links in the “Header” panel. This is so even though there are spaces around them in the HTML for the page. This same problem also prevented me from arranging the text in the “Header” panel in the way I really wanted – with the word “Header” centered on one line, and the rest of the text centered below the first on a second line. I could get the two lines by using the CSS property “display: block” in the definition for the “.header” class, but I could never get it centered. Also, using a <br /> between the word “Header” and the opening parenthesis before the word “Note” did not yield two separate lines. Finally, putting paragraph tags (<p></p>) around the two desired lines also did not render the correct result. Sigh.

Update 2017-12-05: After watching the YouTube video of Morten Rand-Hendriksen’s excellent talk, “CSS Grid Changes EVERYTHING”, I made a few changes and now the result is what I wanted. I removed the “display: flex;” from the CSS for the .item class, and also removed the “display: block:” from the CSS for the “a” tags. Finally, I added a “margin: 5px;” to the CSS for the “a” tags, which put the desired spaces around them.

Finally, the page works fine in both Firefox and Chrome, but does not seem to work in any version of Internet Explorer or Edge. Hmmm…