Polymer code hinting

polymerBrackets

While watching the recent Google I/O videos, I was intrigued by the 1.0 release of the Polymer Project. I had been watching the effort for sometime, but never really exploring it too deeply. Given I know my way around the code hinter in Brackets, I thought why not make another one. The documentation is not a clean as one would expect from a company like Google, so if you find an issue, please let me know. I am not doing much active development in Polymer at the moment, so I can’t discover those issues like I have with other code hinters. Since Polymer is very extensible, I am thinking of a method for people to insert their custom mark up into their code hinter. This could be applied to some of the Angular code hinters as well.

You can download it directly from its GitHub repo (https://github.com/chrisgriffith/Polymer-Brackets-Extension), or install it via the Extension Manager within Brackets.

The Smyth Report – Kindle version

Atomic Energy for Military Purposes

Atomic Energy for Military Purposes: The Official Report on the Development of the Atomic Bomb Under the Auspices of the United States Government As part of my ongoing efforts to digitally preserve aspects of the atomic age, I recently published a Kindle version of what is generally known as “The Smyth Report”. My good friend, Geoff Williams helped in recreating the cover. The text is available on atomicarchive.com, but thought I should make a proper ebook out of it.

With the 70th anniversary of the first atomic test in the desert of New Mexico, and the bombings of Hiroshima and Nagasaki, expect to see some more atomic themed posts here.

Even More Brackets!

angularMaterialBrackets

In exploring the various Angular UI solutions I stumbled on the Angular Material Project. In reading the documentation, I thought, why not create a code-hinter for it? I got started and was mostly finished except for the layout section. I put it aside for sometime. When I decided to do the Zurb Foundation for Apps code hinter, I promised that I would take the time to finish this one off as well.

You can download it directly from its GitHub repo (https://github.com/chrisgriffith/Angular-Material-Brackets-Extension), or install it via the Extension Manager within Brackets.

Presenting on the Ionic Framework

ionic-logo

I will speaking at the next North County JS Monthly Meeting on the Ionic Framework! What is the Ionic Framework? The Ionic Framework combines Google’s AngularJS with Apache’s Cordova to create fast and beautiful cross-platform mobile apps for iOS and Android. In this talk I will explore Ionic, show how to install it, and finally build a quick and dirty app and deploy it to both iOS and Android.

When: Tuesday, May 26, 2015 @ 7:00 PM
Where: WalmartLabs | 1530 Faraday Avenue, Carlsbad, CA

The slide are available here. Thanks to the Ionic Team for having a ‘starter’ deck available (and the stickers!)

Centering Gallery Elements

Recently, I was rebuilding one of my websites to be responsive. It is important to take advantage of the capabilities of modern browsers and be responsive, to support the growing use of the site on mobile devices. One portion of the design was a set of image gallery pages. These pages are pretty straight-forward, up to 5 columns of photos per row centered within the width of the page. As the window width reduces, the number of columns reduces. Again, nothing out of the ordinary with this design.

figure1

Block version of the design

 

I began by centering the containing div by setting the CSS properties of margin-left and the margin-right values to “auto”. That positioned the containing div correctly and it responded as expected as the browser width was changed. However, as the width of the window reduced, the thumbnails would begin to start to flow down to the next row, but they would display centered within the containing div. Not exactly the design I was looking for.

Centered elements

Centered elements

I applied a float:left to the thumbnails, and my centering last row was fixed! However, it introduced a new problem–the thumbnails no longer appeared to be centered as a group within the page. Adding the float to the thumbnails introduced extra spacing between the last column and the right boundary of the containing div.

Highlighting the margin right issue

Highlighting the margin right issue

I knew that had to be solved, so I began looking at many of my favorite tutorial sites, and found nothing. Lots of great samples of gallery pages, but all using the full width of browser in their samples or the thumbnail sizes would adapt to their widths. Nothing seemed to fit my design.

Next, I decided to look at using Flexbox. I had made the choice to only support “modern” browsers, so I knew that I did not need to worry too much about compatibility issues. But the same issues remained as I experimented with the various flex layout options; the last row items would be centered, or the gap on the right existed. Back to the drawing board!

Then I got to thinking about how the layout was computed. Each thumbnail would take the same fixed amount of space. Each would position itself to the left due to setting the float property to left. If the thumbnail did not have enough space within the width of the container, it would move to the next row. Float 101, right? But how did it know the space it had? I only defined the containing div to have a max-width and to center itself, and the width would vary based on the width of the window. It then struck me that if the width of the containing div matched the number of allowable columns, then there would not be extra space along the right.

Eureka!

If I can set the containing div to match my column widths, that container will still be properly centered. So I calculated the computed widths for 2,3,4, and 5 columns of thumbnails. So, when the browser’s width reaches specific widths, the containing div’s width is fixed to match the allowable number of columns. With a fixed width instead of a dynamic width, it can be properly centered on the page. Design problem solved!
The resulting CSS looks like this

<style> 
 #photoMenu {
   margin-left: auto;
   margin-right: auto;
   height: auto;
   min-height: 220px;
 }
 
 .thumbnail {
   position: relative;
   border: 5px solid #ddd;
   float: left;
   margin: 20px;
   width: 160px;
 }
 
 .thumbnail img {
  max-width: 100%;
 }
 
 .thumbnail h3 {
   position: absolute;
   bottom: 0;
   left: 0;
   width: 100%;
   margin: 0;
   text-align: center;
   color: white;
   font: bold 1em/1.5em Verdana, Sans-Serif;
   background: rgb(0, 0, 0);
 }
 
 @media (min-width: 315px) {
   #photoMenu {
     background-color:darkred;
     width: 210px;
   }
 }
 
 @media (min-width: 525px) {
   #photoMenu {
     background-color: darkseagreen;
     width: 420px;
   }
 }
 
 @media (min-width: 735px) {
   #photoMenu {
     background-color: rebeccapurple;
     width: 630px;
   }
 }
 
 @media (min-width: 945px) {
   #photoMenu {
     background-color: bisque;
     width: 840px;
   }
 }
 
 @media (min-width: 1155px) {
   #photoMenu {
     background-color: aqua;
     width: 1050px;
   }
 }
 </style>

For each of the media query breakpoints, I added a background color just to highlight it. Here is what the HTML looks like:

<div id="photoMenu">
  <div class="thumbnail">
    <img src="thumbnail.png" alt="">
    <h3>Title</h3>
  </div>
  <div class="thumbnail">
    <img src="thumbnail.png" alt="">
    <h3>Title</h3>
  </div>
  <div class="thumbnail">
    <img src="thumbnail.png" alt="">
    <h3>Title</h3>
  </div>
  <div class="thumbnail">
    <img src="thumbnail.png" alt="">
    <h3>Title</h3>
  </div>
  <div class="thumbnail">
    <img src="thumbnail.png" alt="">
    <h3>Title</h3>
  </div>
  <div class="thumbnail">
    <img src="thumbnail.png" alt="">
    <h3>Title</h3>
  </div>
  <div class="thumbnail">
    <img src="thumbnail.png" alt="">
    <h3>Title</h3>
  </div>
</div>

You can see the completed sample here.