{"id":1838,"date":"2018-02-06T18:31:20","date_gmt":"2018-02-06T18:31:20","guid":{"rendered":"http:\/\/websterart.com\/wordpress\/?p=1838"},"modified":"2018-02-06T18:33:21","modified_gmt":"2018-02-06T18:33:21","slug":"vantage-image-gallery","status":"publish","type":"post","link":"https:\/\/websterart.com\/wordpress\/2018\/02\/vantage-image-gallery\/","title":{"rendered":"Vantage and an image gallery"},"content":{"rendered":"<p>I studied Sunday so I could play hooky with Christine on Monday at Vantage. Chris was super strong and led Sinsemilla 10c and George and Martha cleanly. \u00a0I was very rusty after 6 weeks of not climbing. I can&#8217;t afford the climbing gym so my arms have become weak. As I said after lowering down from hanging on Pony Keg: &#8220;That was not the climber who came back from Joshua Tree on January 2!&#8221;<\/p>\n<p>Chris: &#8220;I know, I wanted to meet that guy.&#8221;<\/p>\n<p>Me: &#8220;He is gone, and I wonder if he ever really existed. Perhaps that was just a fairytale from some bizarre alternate universe.&#8221;<\/p>\n<p>Such is my life as a 64 year old rock climber. It&#8217;s a sport for young people. Trying to do it at my advanced age of decrepitude requires a lot more work than it does for young people. I do the work, and happily, but it requires climbing every weekend, or 5 days straight, whichever comes first.<\/p>\n<p>So now I&#8217;m back to my JavaScript studies at this super cool free website:<\/p>\n<p><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/JavaScript\/Building_blocks\/Image_gallery\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/JavaScript\/Building_blocks\/Image_gallery<\/a><\/p>\n<p>I&#8217;ve been using Evernote to take notes of the stuff I&#8217;m learning. But Evernote doesn&#8217;t have syntax highlighting. It&#8217;s going to clog up this blog with a bunch of code&#8230;but I suspect this blog never gets read by anyone but me anyway. Probably I screwed up the search engine functionality or something. Not that I care enough to sort it out. I have bigger priorities, like learning high end JavaScript.<\/p>\n<p>So here is my latest &#8220;homework&#8221;. I built a barebones image gallery switcher. It&#8217;s too boring to show the working example in an iframe. But this is the code that makes it work, which is the fun part for me. On my main website, I use a awesome image gallery function called Photoswipe. <a href=\"http:\/\/websterart.com\/html\/still-lifes-v4.php\">You can see it here<\/a>.<\/p>\n<p>Whoever built that had the job that I want.<\/p>\n<p>Meanwhile, back on the farm, this is the code for the one I built in my lesson. They gave me the images, html and JavaScript. But they only gave me clues as to how to write the script. I&#8217;m fairly happy I figured it all out. Baby steps&#8230;<\/p>\n<p>Here is the html:<\/p>\n<pre class=\"lang:default decode:true \">&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n  &lt;head&gt;\r\n    &lt;meta charset=\"utf-8\"&gt;\r\n\r\n    &lt;title&gt;Image gallery&lt;\/title&gt;\r\n\r\n    &lt;link rel=\"stylesheet\" href=\"style.css\"&gt;\r\n    \r\n  &lt;\/head&gt;\r\n\r\n  &lt;body&gt;\r\n    &lt;h1&gt;Image gallery example&lt;\/h1&gt;\r\n\r\n    &lt;div class=\"full-img\"&gt;\r\n      &lt;img class=\"displayed-img\" src=\"images\/pic1.jpg\"&gt;\r\n      &lt;div class=\"overlay\"&gt;&lt;\/div&gt;\r\n      &lt;button class=\"dark\"&gt;Darken&lt;\/button&gt;\r\n    &lt;\/div&gt;\r\n\r\n    &lt;div class=\"thumb-bar\"&gt;\r\n\r\n\r\n    &lt;\/div&gt;\r\n    &lt;script src=\"main.js\"&gt;&lt;\/script&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p>And here is the script that I wrote:<\/p>\n<pre class=\"lang:default decode:true \">\/\/ the big images in the gallery\r\nvar displayedImage = document.querySelector('.displayed-img');\r\n\r\n\/\/the div that contains the dynamically generated thumbs\r\nvar thumbBar = document.querySelector('.thumb-bar');\r\n\r\nbtn = document.querySelector('button');\r\n\r\n\/\/a dumb transparent overlay\r\nvar overlay = document.querySelector('.overlay');\r\n\r\n\/* Looping through images in the image folder*\/\r\nvar allImages = ['pic1', 'pic2', 'pic3', 'pic4', 'pic5'];\r\n\r\nfor(let i = 0; i &lt; allImages.length; i++){\r\n\r\n  \/\/makes a virtual &lt;img &gt; tag\r\n  var newImage = document.createElement('img');\r\n\r\n  \/\/changes to &lt;img src=\"images\/pic1.jpg\"&gt;\r\n  newImage.setAttribute('src', 'images\/' + allImages[i] + '.jpg');\r\n\r\n  \/* below line changes vritual image  class to\r\n  &lt;img src=\"images\/pic1.jpg\" class=\"pic1\"&gt;\r\n  Have to add 1 to i because in first loop i = 0, but the first\r\n  item in the array, which I'm trying to access, is pic1  *\/\r\n  newImage.classList.add('pic' + (i+1));\r\n\r\n  \/\/adds the new &lt;img ...&gt; to dom at bottom inside of div.thumbBar\r\n  thumbBar.appendChild(newImage);\r\n\r\n  \/*thumbClass = pic1. Now that I have image on the displayedImage\r\n  I need to grab it's class so I can talk to it*\/\r\n    var thumbClass = newImage.getAttribute('class');\r\n\r\n    \/\/ finds the new &lt;img ...&gt; based on the class added in the loop\r\n    var thumbReady = document.querySelector('.' + thumbClass);\r\n\r\n    \/\/makes the new &lt;img ...&gt; be clickable and fires showBig\r\n    thumbReady.addEventListener('click', showBig);\r\n\r\n\r\n  function showBig(){\r\n    \/\/changes big image to match thumbnail clicked\r\n    \/\/changes path of big image to images\/pic1.jpg\r\n    displayedImage.setAttribute('src', 'images\/' + allImages[i] + '.jpg');\r\n  }\r\n}\/\/end for loop\r\n\/* Wiring up the Darken\/Lighten button, not important*\/\r\nbtn.addEventListener('click', darkLight);\r\nfunction darkLight(){\r\n  if(btn.getAttribute('class') === 'dark'){\r\n    btn.setAttribute('class','light');\r\n    btn.textContent = 'Lighten';\r\n    overlay.style.backgroundColor = 'rgba(0,0,0,0.5)';\r\n  } else {\r\n    btn.setAttribute('class','dark');\r\n    btn.textContent = 'Darken';\r\n    overlay.style.backgroundColor = 'rgba(0,0,0,0)';\r\n  }\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I studied Sunday so I could play hooky with Christine on Monday at Vantage. Chris was super strong and led Sinsemilla 10c and George and Martha cleanly. \u00a0I was very rusty after 6 weeks of not climbing. I can&#8217;t afford the climbing gym so my arms have become weak. As I said after lowering down [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,179,3],"tags":[],"class_list":["post-1838","post","type-post","status-publish","format-standard","hentry","category-blog","category-programming","category-rock_climbing"],"_links":{"self":[{"href":"https:\/\/websterart.com\/wordpress\/wp-json\/wp\/v2\/posts\/1838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/websterart.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/websterart.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/websterart.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/websterart.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1838"}],"version-history":[{"count":3,"href":"https:\/\/websterart.com\/wordpress\/wp-json\/wp\/v2\/posts\/1838\/revisions"}],"predecessor-version":[{"id":1841,"href":"https:\/\/websterart.com\/wordpress\/wp-json\/wp\/v2\/posts\/1838\/revisions\/1841"}],"wp:attachment":[{"href":"https:\/\/websterart.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/websterart.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/websterart.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}