<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CSS Archives - Michael Soriano</title>
	<atom:link href="https://michaelsoriano.com/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>https://michaelsoriano.com/category/css/</link>
	<description>I turn code into captivating user experiences for the web</description>
	<lastBuildDate>Mon, 09 Dec 2024 18:32:18 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.4</generator>
	<item>
		<title>Modern CSS Features Every Front-End Dev Should Know</title>
		<link>https://michaelsoriano.com/modern-css-features-every-front-end-dev-should-know/</link>
					<comments>https://michaelsoriano.com/modern-css-features-every-front-end-dev-should-know/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Mon, 09 Dec 2024 18:32:18 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<guid isPermaLink="false">https://michaelsoriano.com/?p=8165</guid>

					<description><![CDATA[<p>Ready to level up your CSS game? Let&#8217;s dive into some modern CSS features that are changing the way we style our websites. Whether you&#8217;re a seasoned pro or just starting out, these tricks will add some serious firepower to your toolkit. 1. CSS Subgrid: Nested Grids, Unleashed Remember when aligning nested grid items was [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/modern-css-features-every-front-end-dev-should-know/">Modern CSS Features Every Front-End Dev Should Know</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Ready to level up your CSS game? Let&#8217;s dive into some <strong>modern CSS features</strong> that are changing the way we style our websites. Whether you&#8217;re a seasoned pro or just starting out, these tricks will add some serious firepower to your toolkit.</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img fetchpriority="high" decoding="async" width="706" height="372" src="https://michaelsoriano.com/wp-content/uploads/2024/12/image.png" alt="" class="wp-image-8193"/></figure></div>


<h2 class="wp-block-heading">1. CSS Subgrid: Nested Grids, Unleashed</h2>



<p>Remember when aligning nested grid items was a pain? <strong>CSS Subgrid</strong> is here to save the day. It allows child elements to align with the parent grid, creating more complex and flexible layouts.</p>



<pre class="wp-block-code"><code lang="css" class="language-css">.parent-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.child-grid {
  display: grid;
  grid-template-columns: subgrid;
}</code></pre>



<p>With this setup, your child grid items will align perfectly with the parent grid columns. No more manual calculations or nested grid headaches!</p>



<h2 class="wp-block-heading">2. CSS Scroll Snap: Smooth Scrolling, Simplified</h2>



<p>Want to create that slick, app-like scrolling experience? <strong>CSS Scroll Snap</strong> has got you covered. It&#8217;s perfect for image galleries, paginated content, or any situation where you want controlled, smooth scrolling.</p>



<pre class="wp-block-code"><code lang="css" class="language-css">.container {
  scroll-snap-type: x mandatory;
  overflow-x: scroll;
}

.item {
  scroll-snap-align: start;
}</code></pre>



<p>Just like that, you&#8217;ve got a smooth-scrolling container. Your users will thank you!</p>



<h2 class="wp-block-heading">3. CSS Backdrop Filter: Blurring the Lines</h2>



<p>Ever wanted to apply cool effects to the area behind an element? <strong>CSS Backdrop Filter</strong> lets you do just that. Blur, color shift, or add other graphical effects to create stunning visual designs.</p>



<pre class="wp-block-code"><code lang="css" class="language-css">.overlay {
  backdrop-filter: blur(10px) brightness(80%);
}</code></pre>



<p>This simple line can transform a plain overlay into a captivating visual element. The possibilities are endless!</p>



<h2 class="wp-block-heading">4. CSS Custom Properties: Variables Get a Makeover</h2>



<p>While not brand new, <strong>CSS Custom Properties</strong> (also known as CSS Variables) have gained wide support and are a game-changer for creating dynamic, reusable styles.</p>



<pre class="wp-block-code"><code lang="css" class="language-css">:root {
  --main-color: #3498db;
}

.button {
  background-color: var(--main-color);
}</code></pre>



<p>With this setup, changing your site&#8217;s color scheme becomes a breeze. One change at the root, and it propagates throughout your entire site!</p>



<h2 class="wp-block-heading">5. CSS @property: Taking Control of Custom Properties</h2>



<p>Want more control over your custom properties? The <strong>@property</strong> rule lets you define the type, inheritance, and initial value of your CSS custom properties.</p>



<pre class="wp-block-code"><code lang="css" class="language-css">@property --gradient-angle {
  syntax: '&lt;angle&gt;';
  initial-value: 0deg;
  inherits: false;
}</code></pre>



<p>This level of control opens up new possibilities for animations and dynamic styling that were previously difficult or impossible.</p>



<h2 class="wp-block-heading">6. CSS Container Queries: Responsive Design 2.0</h2>



<p>Last but certainly not least, we have <strong>CSS Container Queries</strong>. This feature is set to revolutionize responsive design by allowing you to style elements based on the size of a containing element, not just the viewport.</p>



<pre class="wp-block-code"><code lang="css" class="language-css">.container {
  container-type: inline-size;
}

@container (min-width: 400px) {
  .card {
    display: grid;
    grid-template-columns: 2fr 1fr;
  }
}</code></pre>



<p>This approach allows for truly modular design, where components can adapt to their container regardless of where they&#8217;re placed in the layout.</p>



<h2 class="wp-block-heading">Wrapping Up</h2>



<p>These <strong>modern CSS features</strong> are just the tip of the iceberg. They represent a shift towards more powerful, flexible, and intuitive web design. By incorporating these techniques into your workflow, you&#8217;ll be able to create more dynamic, responsive, and visually appealing websites.</p>



<p>Remember, the key to mastering these features is practice. So go ahead, experiment with them in your next project. Your future self (and your users) will thank you!</p>



<p>Keep coding, keep learning, and keep pushing the boundaries of what&#8217;s possible with CSS. The future of web design is looking brighter than ever!</p>
<p>The post <a href="https://michaelsoriano.com/modern-css-features-every-front-end-dev-should-know/">Modern CSS Features Every Front-End Dev Should Know</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/modern-css-features-every-front-end-dev-should-know/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Convert WordPress default Gallery into a simple Carousel without a plugin</title>
		<link>https://michaelsoriano.com/convert-wordpress-default-gallery-into-a-simple-carousel-without-a-plugin/</link>
					<comments>https://michaelsoriano.com/convert-wordpress-default-gallery-into-a-simple-carousel-without-a-plugin/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Sat, 02 Sep 2017 17:57:04 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">http://michaelsoriano.com/?p=6300</guid>

					<description><![CDATA[<p>I had the fun task to turn the default WordPress gallery into a carousel. Our users didn&#8217;t really like the grid of images, that WordPress ships with. Instead, our designers came up with something like below: It&#8217;s basically a carousel, with the caption in a grey area in the side, along with control buttons in [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/convert-wordpress-default-gallery-into-a-simple-carousel-without-a-plugin/">Convert WordPress default Gallery into a simple Carousel without a plugin</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>I had the fun task to turn the default WordPress gallery into a carousel. Our users didn&#8217;t really like the grid of images, that WordPress ships with. Instead, our designers came up with something like below:</p>



<p><br><img decoding="async" width="661" height="412" class="alignnone size-full wp-image-6385" src="https://michaelsoriano.com/wp-content/uploads/2017/09/carousel.png" alt="" srcset="https://michaelsoriano.com/wp-content/uploads/2017/09/carousel.png 661w, https://michaelsoriano.com/wp-content/uploads/2017/09/carousel-300x187.png 300w" sizes="(max-width: 661px) 100vw, 661px" /><br></p>



<p>It&#8217;s basically a carousel, with the caption in a grey area in the side, along with control buttons in the bottom. When clicked, the next image is shown.</p>



<p>At first, I thought of using a plugin, which would&#8217;ve been fine. Except this would&#8217;ve added some level of training on how to use carousel plugins. Most of which are quite complicated to use. Besides, our users are already familiar with using the default WordPress gallery option. They just want to change the way it looks!</p>



<p>So the solution was to use a little bit of JavaScript and CSS. Note that this requires jQuery, Bootstrap for the grid, as well as Handlebars for templating.</p>



<p>Let&#8217;s begin:</p>



<p>First, let&#8217;s add a gallery to our page.<br><img decoding="async" width="759" height="549" class="alignnone size-full wp-image-6308" src="https://michaelsoriano.com/wp-content/uploads/2017/11/insert-gallery.png" alt="Insert a Gallery" srcset="https://michaelsoriano.com/wp-content/uploads/2017/11/insert-gallery.png 759w, https://michaelsoriano.com/wp-content/uploads/2017/11/insert-gallery-300x217.png 300w" sizes="(max-width: 759px) 100vw, 759px" /><br>Make sure that each image has a caption to go with it:</p>



<p><img decoding="async" width="850" height="562" class="alignnone size-full wp-image-6309" src="https://michaelsoriano.com/wp-content/uploads/2017/11/item-caption.png" alt="Caption included" srcset="https://michaelsoriano.com/wp-content/uploads/2017/11/item-caption.png 850w, https://michaelsoriano.com/wp-content/uploads/2017/11/item-caption-300x198.png 300w, https://michaelsoriano.com/wp-content/uploads/2017/11/item-caption-768x508.png 768w" sizes="(max-width: 850px) 100vw, 850px" /><br></p>



<p>This will ouput the default gallery in WordPress. Now note that each gallery will have a &#8220;.gallery&#8221; class in them. So let&#8217;s grab all of them, and create an object with it.</p>



<pre class="wp-block-code"><code lang="JavaScript" class="language-JavaScript">var galleries = {};
    $('.gallery').each(function(i,item){
        var id = $(this).attr('id');
        var imgs = Array();
        var children = $(this).find('.gallery-item');
        $.each(children,function(){
            var imgSrc = $(this).find('img').attr('src');
            var caption = $(this).find('.wp-caption-text').html();
            var imgItem = imgSrc + "::" + caption;
            imgItem = imgItem.trim()
                        .replace(/[\n\r]+/g, '')
                        .replace(/\s{2,10}/g, '')
                        .replace('undefined','');
            imgs.push(imgItem);
        })
        galleries[id] = imgs;
    });</code></pre>



<p>Now we have a &#8220;galleries&#8221; object, with the gallery id as the indexing property. This will support multiple galleries in a page, hence the index.</p>



<p>Inside each gallery object contains properties for the source and caption (separated by a &#8220;::&#8221;).</p>



<p>So we&#8217;ll have something like below:</p>



<p><br><img decoding="async" width="776" height="307" class="alignnone size-full wp-image-6317" src="https://michaelsoriano.com/wp-content/uploads/2017/11/galleries-obj.png" alt="gallery object" srcset="https://michaelsoriano.com/wp-content/uploads/2017/11/galleries-obj.png 776w, https://michaelsoriano.com/wp-content/uploads/2017/11/galleries-obj-300x119.png 300w, https://michaelsoriano.com/wp-content/uploads/2017/11/galleries-obj-768x304.png 768w" sizes="(max-width: 776px) 100vw, 776px" /><br></p>



<p>With our object in place, we can create our carousel.</p>



<p>Let&#8217;s create the HTML. The below code is simply HTML but using Handlebars syntax.</p>



<pre class="wp-block-code"><code lang="markup" class="language-markup">&lt;script id="carousel-template" type="text/x-handlebars-template">
        &lt;div class="carousel-wrap" data-gallery="{{gallery}}">
        {{#each imgObj}}
        &lt;div class="boxed-style clearfix {{hiddenOrNot @index}}" data-index="box-index-{{@index}}">
        &lt;div class="box-style col-lg-8 col-md-8 col-sm-8 col-xs-12" style="background-image:url('{{imgSrc}}')">
            &lt;div class="triangle-left-large hidden-xs">&lt;/div>
            &lt;div class="triangle-top-large visible-xs">&lt;/div>
        &lt;/div>
        &lt;div class="box-style-copy col-lg-4 col-md-4 col-sm-4 col-xs-12">{{txt}}&lt;/div>
        &lt;/div>
        {{/each}}
        &lt;a href="#" class="carousel-previous visible-xs">Previous&lt;/a>
        &lt;a href="#" class="carousel-next visible-xs">Next&lt;/a>
        &lt;div class="carousel-controls">
        {{#each imgObj}}
            &lt;a class="trig"
                data-index="box-index-{{@index}}"
                href="#">&lt;span class="fa fa-circle" aria-hidden="true">&lt;/span>&lt;/a>
        {{/each}}
        &lt;/div> &lt;/div>
&lt;/script></code></pre>



<p>As you can see above, we are wrapping everything in it&#8217;s own &#8220;carousel-wrap&#8221;, with an attribute of &#8220;data-gallery&#8221;, along with the gallery index as the value.</p>



<p>We loop through each image and assign the values to the HTML.</p>



<p>We are using Boostrap col classes, and using a &#8220;background&#8221; for the image (not img tag). This makes our image behave properly in different viewports.</p>



<p>Note that we have &#8220;Previous&#8221; and &#8220;Next&#8221; buttons &#8211; which we&#8217;re adding for now &#8211; and will explain later.<br>Also, we&#8217;re creating the controls in the bottom, which will look like below:</p>



<p><br><img decoding="async" width="759" height="499" class="alignnone size-full wp-image-6307" src="https://michaelsoriano.com/wp-content/uploads/2017/11/desktop-view.png" alt="" srcset="https://michaelsoriano.com/wp-content/uploads/2017/11/desktop-view.png 759w, https://michaelsoriano.com/wp-content/uploads/2017/11/desktop-view-300x197.png 300w" sizes="(max-width: 759px) 100vw, 759px" /><br> <br>Back in our JavaScript, let&#8217;s register a helper called &#8220;hiddenOrNot&#8221; &#8211; which simply decides if it&#8217;s not the first image &#8211; hide everything:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">Handlebars.registerHelper('hiddenOrNot', function(ind) {
         return ind === 0 ? '' : 'hidden';
    });
    var source   = $("#carousel-template").html();</code></pre>



<p>Now let&#8217;s compile our object and output to our template.</p>



<p>Remember our delimiter &#8220;::&#8221;, that&#8217;s what we&#8217;re doing in line 8 below. Also, we&#8217;re binding events to each of the controls along with assigning hidden and active classes to both itself and the large images.<br>Finally, we remove the default WordPress gallery by using jQuery&#8217;s .<strong>remove</strong>().</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">for(gallery in galleries){
        // console.log(gallery);
        var col = {};
        col.gallery = '#' + gallery;
        col.imgObj = {};
        for($i=0;$i&lt;galleries['gallery'].length;$i++){
            var imgObj = {};
            var img = galleries['gallery'][$i].split('::');
            imgObj.txt = img[1];
            imgObj.imgSrc = img[0];
            col.imgObj[$i] = imgObj;
        } //end for each img
        var template = Handlebars.compile(source);
        $('#'+gallery).before(template(col));
        $('[data-gallery="#'+gallery+'"] a.trig').each(function(index,item){
            if(index == 0){
                $(this).addClass('active');
            }
            $(this).on('click',function(){
                var imgId = $(this).attr('data-index');
                var galleryId = $(this).closest('.carousel-wrap').attr('data-gallery');
                $('[data-gallery="'+galleryId+'"]' + ' .carousel-controls a').removeClass('active');
                $(this).addClass('active');
                $('[data-gallery="'+galleryId+'"]' + ' .boxed-style[data-index]').addClass('hidden');
                $('[data-gallery="'+galleryId+'"]' + ' [data-index="'+imgId+'"]').removeClass('hidden');
                return false;
            })
        })
        $('#'+gallery).remove();
    } //end for each gallery</code></pre>



<p>Remember our Previous and Next buttons, this is only to show up in viewports for mobile devices. That is made possible by using the &#8220;visible-xs&#8221; Bootstrap class. So, it looks like below in small devices:</p>



<p><br><img decoding="async" width="481" height="530" class="alignnone size-full wp-image-6306" src="https://michaelsoriano.com/wp-content/uploads/2017/11/mobile-view.png" alt="Carousel view" srcset="https://michaelsoriano.com/wp-content/uploads/2017/11/mobile-view.png 481w, https://michaelsoriano.com/wp-content/uploads/2017/11/mobile-view-272x300.png 272w" sizes="(max-width: 481px) 100vw, 481px" /><br>Now let&#8217;s add some events to those buttons:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">$('[data-gallery]').each(function(i,item){
        var previous = $(this).children('.carousel-previous');
        var next = $(this).children('.carousel-next');
        previous.on('click',function(){
            var currentGallery = $(this).closest('.carousel-wrap').attr('data-gallery');
            var previousBox = $('[data-gallery="'+currentGallery+'"]'+' [data-index="'+getCurrentBox(currentGallery)+'"]')
                            .prev('.boxed-style');
            if(previousBox.length !== 0){
                hideBoxes(currentGallery);
                previousBox.removeClass('hidden');
                updateDots(currentGallery);
            }
            return false;
        });
        next.on('click',function(){
            var currentGallery = $(this).closest('.carousel-wrap').attr('data-gallery');
            var nextBox = $('[data-gallery="'+currentGallery+'"]'+' [data-index="'+getCurrentBox(currentGallery)+'"]')
                            .next('.boxed-style');
            if(nextBox.length !== 0){
                hideBoxes(currentGallery);
                nextBox.removeClass('hidden');
                updateDots(currentGallery);
            }
            return false;
        })
        function updateDots(currentGallery){
            $('[data-gallery="'+currentGallery+'"] a.trig').removeClass('active');
            $('[data-gallery="'+currentGallery+'"] a[data-index="'+getCurrentBox(currentGallery)+'"]')
                .addClass('active');
        }
        function hideBoxes(currentGallery){
            $('[data-gallery="'+currentGallery+'"] .boxed-style').addClass('hidden');
        }
        function getCurrentBox(gallery){
            var curBox = $('[data-gallery="'+gallery+'"]' + ' .boxed-style').not(':hidden');
            var curBoxIndex = $(curBox).attr('data-index');
            return curBoxIndex
        }
    })</code></pre>



<p>For each button, we&#8217;re doing some logic &#8211; each of them are in functions that we can reuse.<br>Finally, let&#8217;s add some CSS styles:</p>



<pre class="wp-block-code"><code lang="css" class="language-css">.boxed-style {
    clear:both;
    display: block;
    margin-bottom: 50px;
    overflow: hidden;
    position: relative;
}
.boxed-style .box-style,
.boxed-style-vertical .box-style-vertical {
    display: flex;
    flex-direction: column;
    justify-content: center;
    height: 380px;
    background-position-x: center !important;
    background-position-y: center !important;
    background-size: cover !important;
    padding-bottom:100px;
    box-shadow: inset 0px 0px 1px 1px rgb(234, 234, 234);
}</code></pre>



<p>This is for the carousel itself:</p>



<pre class="wp-block-code"><code lang="css" class="language-css">.carousel-wrap {
    clear: both;
    display: block;
    overflow: hidden;
    margin-bottom: 45px;
    margin-top:40px;
    position: relative;
}
.carousel-previous,
.carousel-next {
    position: absolute;
    width:48px;
    height:48px;
    text-indent: -9999px;
    top:35%;
}
.carousel-next {
    background:url('images/chevron-right.png') 0px 0px no-repeat;
    right:0;
}
.carousel-previous {
    background:url('images/chevron-left.png') 0px 0px no-repeat;
}
.carousel-wrap .boxed-style {
    margin-bottom: 0;
}
.carousel-controls {
    text-align: center;
    margin:15px 0;
}
.carousel-controls a {
    font-size:13px;
    margin-right: 3px;
    color: #ccc;
}
.carousel-controls a:hover,
.carousel-controls a:focus,
.carousel-controls a.active {
    color: #0077C8;
}</code></pre>



<p>Now you might have noticed a little triangle in our caption. This is the CSS that made that possible:</p>



<pre class="wp-block-code"><code lang="css" class="language-css">.triangle-left-large {
    width: 0;
    height: 0;
    border-top: 12px solid transparent;
    border-bottom: 12px solid transparent;
    border-right: 12px solid #eaeaea;
    position: absolute;
    right: 0;
}</code></pre>



<p>Below is the finished result. In desktop and mobile view. A live example can be found <a href="https://www.parsons.com/project/sand-creek-byway/" target="_blank" rel="nofollow noopener">here</a> (scroll down to the middle of the page).</p>



<p><br><img decoding="async" width="797" height="563" class="alignnone size-full wp-image-6310" src="https://michaelsoriano.com/wp-content/uploads/2017/11/final.gif" alt="Final output"></p>



<p><br>And that&#8217;s about it! We&#8217;ve just created a carousel without a plugin. This may be a simplistic carousel &#8211; one that can be enhanced even further. Maybe add some animations, previews, swipe events etc.</p>



<p>Hope you try it out in your projects. Leave your comments below.</p>
<p>The post <a href="https://michaelsoriano.com/convert-wordpress-default-gallery-into-a-simple-carousel-without-a-plugin/">Convert WordPress default Gallery into a simple Carousel without a plugin</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/convert-wordpress-default-gallery-into-a-simple-carousel-without-a-plugin/feed/</wfw:commentRss>
			<slash:comments>8</slash:comments>
		
		
			</item>
		<item>
		<title>How to create Better Tooltips with plain JavaScript and CSS</title>
		<link>https://michaelsoriano.com/better-tooltips-with-plain-javascript-css/</link>
					<comments>https://michaelsoriano.com/better-tooltips-with-plain-javascript-css/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Sun, 07 Aug 2016 16:26:51 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<guid isPermaLink="false">http://michaelsoriano.com/?p=5911</guid>

					<description><![CDATA[<p>Today we&#8217;ll be building tooltips with JavaScript. Tooltips are the small snippet of text that shows when you hover over a link. The text is from the &#8220;Title&#8221; attribute of the anchor tag &#8211; which is supposed to describe to the user what the link is about, before they click it. View Demo The default [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/better-tooltips-with-plain-javascript-css/">How to create Better Tooltips with plain JavaScript and CSS</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Today we&#8217;ll be building tooltips with JavaScript. Tooltips are the small snippet of text that shows when you hover over a link. The text is from the &#8220;Title&#8221; attribute of the anchor tag &#8211; which is supposed to describe to the user what the link is about, before they click it.<br />
<a href="http://demo.michaelsoriano.com/tooltips/">View Demo</a><br />
The default browser tooltip is already in place. However, it doesn&#8217;t look so good. So let&#8217;s go ahead and create our own.<br />
Below is how our tooltips will look once we&#8217;re finished:<br />
<img decoding="async" class="alignnone size-full wp-image-5919" style="border: 1px solid #e5e5e5;" src="https://michaelsoriano.com/wp-content/uploads/2016/08/js-tooltip.gif" alt="js-tooltip" width="719" height="315" /><br />
You may be thinking, why create something that has been done by many in the past? Why not just use a plugin like jQuery UI? Why reinvent the wheel?<br />
I always feel that developers write code to hone their skill. The more you write, the better you get. There may be hundreds of plugins that take care of this functionality &#8211; and most likely they are going to be better than what we build.<br />
But that&#8217;s what&#8217;s important here. To me, it&#8217;s the act of building and writing code. Knowing what&#8217;s going on under the hood. Gaining the knowledge it takes to understand how things work.<br />
I guess my point is, we&#8217;re building our own tooltip &#8211; to learn how. That&#8217;s all.<br />
So ready to get started? Note that we&#8217;re not using jQuery &#8211; just plain JavaScript. Doing it this way will expose us to the inner workings of the raw script.<br />
Let&#8217;s begin.</p>
<h6>Get all the links</h6>
<p>First of all, we need to get all the links in the page. We have a simple utility called &#8220;document.links&#8221; &#8211; which returns an array of links! What a way to get started! Let&#8217;s go ahead and create a wrapper for our code.</p>
<pre>(function(){
  //all code goes in here
})()
</pre>
<p>The above is also known as an &#8220;<a href="https://en.wikipedia.org/wiki/Immediately-invoked_function_expression">Immediately Invoked Function Expression</a>&#8220;. This code is immediately run as soon as the page is loaded. It&#8217;s similar to jQuery&#8217;s &#8220;document.ready()&#8221; handler.<br />
Now it&#8217;s time to grab all the links in the page. Notice that we&#8217;re simply doing a &#8220;for&#8221; loop, and checking if the link has a &#8220;title&#8221; attribute.</p>
<pre>var links = document.links;
  for(var i=0; i &lt; links.length; i++){
     var a = links[i];
     if(a.title !== ''){
       a.addEventListener('mouseover',createTip);
       a.addEventListener('mouseout',cancelTip);
     }
    //  console.log(a);
  }
</pre>
<p>We then bind two functions to our links using &#8220;addEventListener()&#8221;. One during &#8220;mouseover&#8221; and &#8220;mouseout&#8221;. The functions are named &#8220;createTip&#8221; and &#8220;cancelTip&#8221; (which we haven&#8217;t created yet). Know that &#8220;addEventListener()&#8221; is similar to jQuery&#8217;s &#8220;.on()&#8221;.<br />
It&#8217;s funny that I&#8217;m writing a tutorial on pure JavaScript and comparing functions to jQuery. Usually, it&#8217;s the other way around.<br />
Moving on&#8230;</p>
<h6>Remove the default browser tip</h6>
<p>Before we create the tooltip, we need to get rid of the default browser behavior of showing the ugly tip:<br />
<img decoding="async" class="alignnone size-full wp-image-5923" src="https://michaelsoriano.com/wp-content/uploads/2016/08/tooltip1.jpg" alt="tooltip1" width="450" height="220" srcset="https://michaelsoriano.com/wp-content/uploads/2016/08/tooltip1.jpg 450w, https://michaelsoriano.com/wp-content/uploads/2016/08/tooltip1-300x147.jpg 300w" sizes="(max-width: 450px) 100vw, 450px" /><br />
The trick is to remove the &#8220;title&#8221; attribute, and putting it in a temporary location (like another attribute). This way we can retrieve it for later use (like for our own tooltip and putting the title back).<br />
Let&#8217;s create our first function that happens on &#8220;mouseover&#8221;. Then let&#8217;s add the code that strips out the title and adding it to a new attribute called &#8220;tooltip&#8221;:</p>
<pre>function createTip(ev){
    var title = this.title;
    this.title = '';
    this.setAttribute("tooltip", title);
}
</pre>
<p>Let&#8217;s create our second function that happens during &#8220;mouseout&#8221;. This time, setting the attributes to its original state:</p>
<pre>function cancelTip(ev){
    var title = this.getAttribute("tooltip");
    this.title = title;
    this.removeAttribute("tooltip");
}
</pre>
<p>Now, when you hover over the link, you will see our attributes are being manipulated by our function:<br />
<img decoding="async" class="alignnone size-full wp-image-5925" style="border: 1px solid #e5e5e5;" src="https://michaelsoriano.com/wp-content/uploads/2016/08/js-tooltip2.gif" alt="js-tooltip2" width="761" height="310" /><br />
Let&#8217;s continue building the tooltip.</p>
<h6>Create the new Tip</h6>
<p>Now that we got that out of the way, and we have both functions in place, it&#8217;s time to build our tooltip. In summary, we need to create a div, add our text inside and put it inside the body of the HTML.<br />
Add the code below inside our already existing createTip() function &#8211; just underneath the setting attribute code:</p>
<pre>
    var tooltipWrap = document.createElement("div"); //creates div
    tooltipWrap.className = 'tooltip'; //adds class
    tooltipWrap.appendChild(document.createTextNode(title)); //add the text node to the newly created div.
    var firstChild = document.body.firstChild;//gets the first elem after body
    firstChild.parentNode.insertBefore(tooltipWrap, firstChild); //adds tt before elem
</pre>
<p>Notice the new DIV we&#8217;ve created and added our class &#8220;tooltip&#8221;. This allows us to style our tip &#8211; which is why we&#8217;re doing this in the first place. We then append our text inside the div using .createTextNode() and .appendChild().<br />
Finally, we insert the new DIV right underneath the BODY tag. We do this by finding the first child of the BODY element, then we do a &#8220;insertBefore()&#8221; it with our new DIV.<br />
But wait, our DIV is in place &#8211; but it&#8217;s all the way at the top! We continue below by positioning our tip.</p>
<h6>Positioning</h6>
<p>Now this is probably the trickiest part of the code. It also depends on how you want the tooltip to appear, so you must adjust accordingly. In my case, I want the default position of the tip to be right above the link I&#8217;m hovering. Plus the tips have a little arrow pointing down &#8211; so we need to make room for that as well.<br />
First, let&#8217;s plugin some styles so we get a better idea of how much to adjust. I wanted my tooltip to have a darker background, with a slight orange font color.</p>
<pre>  .tooltip {
    position: absolute;
    background: #646464;
    border-radius:4px;
    padding: 6px 12px;
    font-family: arial;
    font-size: 12px;
    text-shadow: 0px 1px 1px #000;
    color: #ffc64a;
  }
  .tooltip:before {
    content : " ";
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #646464;
    position:absolute;
    bottom:-5px;
    left:5px;
  }
</pre>
<p>You will also notice a :before pseudo class. This is to create the &#8220;arrow&#8221; that&#8217;s pointing down. Now that we have our styles, we know how much to adjust.<br />
Next we get the coordinates and dimensions of the link and the tip itself. We do this by doing a &#8220;getBoundingClientRect()&#8221;. Once you do a console.log, you should see an objects that has the tooltip and link properties that we need:<br />
<img decoding="async" class="alignnone size-full wp-image-5936" src="https://michaelsoriano.com/wp-content/uploads/2016/08/tooltip2.jpg" alt="tooltip2" width="428" height="333" srcset="https://michaelsoriano.com/wp-content/uploads/2016/08/tooltip2.jpg 428w, https://michaelsoriano.com/wp-content/uploads/2016/08/tooltip2-300x233.jpg 300w" sizes="(max-width: 428px) 100vw, 428px" /><br />
The top and left properties is the X and Y coordinates (or where it is in the window), plus the height and width. We need the height to calculate and offset our tip.<br />
Let&#8217;s add our new code below inside the createTip():</p>
<pre>   var padding = 5;
   var linkProps = this.getBoundingClientRect();
   var tooltipProps = tooltipWrap.getBoundingClientRect();
   var topPos = linkProps.top - (tooltipProps.height + padding);
   tooltipWrap.setAttribute('style','top:'+topPos+'px;'+'left:'+linkProps.left+'px;')
</pre>
<p>As I was saying, we simply calculate the position of our tooltip by offsetting based on where the link is. We also add some padding and take in account the height of the tip. We add this new position to the tip by adding an inline &#8220;style&#8221; with &#8220;top&#8221; and &#8220;left&#8221;.<br />
Now hover over a link and you should see our newly styled tip, positioned nicely above the link.<br />
<img decoding="async" class="alignnone size-full wp-image-5937" src="https://michaelsoriano.com/wp-content/uploads/2016/08/tooltip3.jpg" alt="tooltip3" width="389" height="257" srcset="https://michaelsoriano.com/wp-content/uploads/2016/08/tooltip3.jpg 389w, https://michaelsoriano.com/wp-content/uploads/2016/08/tooltip3-300x198.jpg 300w" sizes="(max-width: 389px) 100vw, 389px" /><br />
We can also simply remove all tips from the page by adding the code below to our &#8220;cancelTip()&#8221; function:</p>
<pre>   document.querySelector(".tooltip").remove();
</pre>
<p>And that&#8217;s basically it.</p>
<h3>Conclusion</h3>
<p>This is probably the simplest tooltip we can build. There are plenty of things to consider &#8211; such as image links, or positioning the tips below or to the left or right. These things we can add as an enhancement in the our next session. I will also build a Git repository and a demo in my next tutorial &#8211; so stay tuned.</p>
<p>The post <a href="https://michaelsoriano.com/better-tooltips-with-plain-javascript-css/">How to create Better Tooltips with plain JavaScript and CSS</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/better-tooltips-with-plain-javascript-css/feed/</wfw:commentRss>
			<slash:comments>17</slash:comments>
		
		
			</item>
		<item>
		<title>Build a SharePoint Single-Page App using nothing but Front-End Code</title>
		<link>https://michaelsoriano.com/build-sharepoint-single-page-app-front-end-code/</link>
					<comments>https://michaelsoriano.com/build-sharepoint-single-page-app-front-end-code/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Wed, 15 Jun 2016 15:49:28 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Handlebars]]></category>
		<category><![CDATA[REST]]></category>
		<guid isPermaLink="false">http://michaelsoriano.com/?p=5501</guid>

					<description><![CDATA[<p>For this session, I would like to show you how to build a &#8220;mini&#8221; single page application in SharePoint 2013. A single page application that is ALL Front-end code (JavaScript, HTML and CSS); while using SP&#8217;s REST services. We&#8217;re also using Bootstrap for the responsiveness and tab interface, Handlebars for the templating, as well as [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/build-sharepoint-single-page-app-front-end-code/">Build a SharePoint Single-Page App using nothing but Front-End Code</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>For this session, I would like to show you how to build a &#8220;mini&#8221; single page application in SharePoint 2013. A single page application that is ALL Front-end code (JavaScript, HTML and CSS); while using SP&#8217;s <a href="https://msdn.microsoft.com/en-us/library/office/fp142380.aspx">REST services</a>. We&#8217;re also using <a href="http://getbootstrap.com/">Bootstrap</a> for the responsiveness and tab interface, <a href="http://handlebarsjs.com/">Handlebars</a> for the templating, as well as <a href="https://jquery.com/">jQuery</a> for everything else.</p>



<h5 class="wp-block-heading"><a id="user-content-note-that-this-will-require-the-following-files" class="anchor" href="https://github.com/michaelsoriano/sp-tabbed-containers#note-that-this-will-require-the-following-files" aria-hidden="true"></a>Note that this will require the following files:</h5>



<ul class="wp-block-list">
<li>jquery.min.js</li>



<li>bootstrap.min.js</li>



<li>handlebars.min.js</li>



<li>moment.min.js</li>



<li>editor.js</li>



<li>editor.css</li>



<li>bootstrap.min.css</li>



<li>font-awesome.min.css</li>
</ul>



<h5 class="wp-block-heading">The plugin already includes the above files via CDN.</h5>



<p class="btn"><a href="https://github.com/michaelsoriano/sp-tabbed-containers">View in Github</a></p>



<p>We are building &#8220;<em>Tab Containers</em>&#8220;. Basically, content that is shown in different tabs in a page. The entire CRUD interface also comes with it &#8211; so we&#8217;ll be able to add, edit and delete tab content and items, all in one page (without refreshing).</p>



<h3 class="wp-block-heading">Why is this Useful?</h3>



<p>Well there really is no way to achieve this in SharePoint. If you want to add Tabs inside an SP page, you would have to paste the whole code inside their editor. But updating this is quite cumbersome to most users.</p>



<p>This solution provides you with a nice interface to manage your tab content, while the data is stored in an SP list. The good thing about this is, you can use multiple apps and utilize just one list. So if you convert this into a webpart or an app &#8211; you simply need one list per site to make it work.</p>



<p>Ready to get started? Also, I&#8217;m only going to discuss the meat of the logic. You will need some basic JavaScript and SharePoint to follow and complete this tutorial.</p>



<h3 class="wp-block-heading">Create the List</h3>



<p>The data for our application will be stored in a custom list. The list will basically contain four columns: 1) <strong>Title</strong>: which is the default title field, 2) <strong>content</strong> which is a Rich Text type 3) <strong>tab-order</strong> a single line text value 4) <strong>webpart-id</strong> &#8211; this will be the identifier for our webpart (in case you want multiple webparts in the site).</p>



<p><img decoding="async" width="509" height="474" class="alignnone size-full wp-image-5634" src="https://michaelsoriano.com/wp-content/uploads/2016/04/sp-tabs7.jpg" alt="sp-tabs7" srcset="https://michaelsoriano.com/wp-content/uploads/2016/04/sp-tabs7.jpg 509w, https://michaelsoriano.com/wp-content/uploads/2016/04/sp-tabs7-300x279.jpg 300w" sizes="(max-width: 509px) 100vw, 509px" /></p>



<p>The title column will hold tab title, content is the contents of the tab, tab order is for ordering the tabs from left to right. You can go ahead and fill it out with dummy data for now, so we can go ahead and fetch the data for our front end. Note that that I have the list template also included in the Github page.</p>



<h3 class="wp-block-heading">Fetch the Items</h3>



<p>We are going to use a slight variation of the &#8220;<a href="https://toddmotto.com/mastering-the-module-pattern/">Revealing Module</a>&#8221; pattern to construct our code. This is especially useful when you are expecting your code to be reused multiple times in a page. In our case, users might want multiple of these web parts in a page, so a &#8220;modularized&#8221; approach is needed.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">var SpTabs = function(){
   //ENTER REST OF CODE HERE
return {
    init : init,
    getContent : getContent
  }
}</code></pre>



<p>As you can see, we are returning two public functions from our &#8220;SpTabs&#8221; object. The &#8220;init()&#8221; method will make the object unique per instance, while the &#8220;getContent()&#8221; will fetch the items for our view. Let&#8217;s build our init() function right below:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">var init = function(obj){
    setListName(obj.listName);
    setWebPartId(obj.webPartId);
    setListItemEntityTypeFullName();
    checkPermissions();
}</code></pre>



<p>Inside our &#8220;init()&#8221;, we have some setters. It simply sets our module up for execution. The setter functions are pretty self explanatory &#8211; and you can simply investigate what each of them does in the source code. Let&#8217;s continue getting our items:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">var getContent = function(obj){
    var endpoint = "/_api/web/lists/getbytitle('"+listName+"')/Items?";
    endpoint = _spPageContextInfo.webAbsoluteUrl + endpoint + '$orderby=tab_x002d_order asc';
    endpoint += "&amp;$filter=(webpart_x002d_id eq '"+webPartId+"')";
    var ajax = $.ajax({
      url: endpoint,
      method: "GET",
      headers: { "Accept": "application/json; odata=verbose" },
      success : function(data){
        items = data.d.results;
        buildTabsHtml();
        buildTabsContentHtml();
      },
      error : function(data){
        console.log(data);
      }
    });
    return ajax;
  }
</code></pre>



<p>This is the AJAX call that goes into our API to fetch our items. As you can see, we are returning the variable &#8220;ajax&#8221; from the getContent() function, in cases where we want to add additional stuff once the response is received. But the default behavior is inside the &#8220;success&#8221; method of jQuery&#8217;s $.ajax(). </p>



<p>Note the two methods <strong>buildTabsHtml()</strong> and <strong>buildTabsContentHtml()</strong>, and our results are in our global var &#8220;items&#8221;. So we&#8217;re ready to build some output.</p>



<h3 class="wp-block-heading">Output with Handlebars</h3>



<p>Let&#8217;s create our <a href="http://handlebarsjs.com/">Handlebars</a> templates so we can use it to produce our content. In case you haven&#8217;t used it, Handlebars is a minimal template language for JavaScript. It just makes life easier. Note that we have to include our handlebars source to make it work. Also, we are using <a href="http://getbootstrap.com/">Bootstrap </a>for our tab styles. So you have to include that in your source as well.</p>



<p>The code that will make this work is inside our two methods <strong>buildTabsHtml()</strong> and <strong>buildTabsContentHtml()</strong>. Let&#8217;s go ahead and build that now:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">function buildTabsHtml(){
    var source = $("#tabs-navigation-template").html();
    var template = Handlebars.compile(source);
    $(getId() + '.tabs-navigation').html(template(items));
    //atach handlers
    $(getId()+'.tabs-navigation li a').on('click',function(){
      $(getId()+'.tabs-navigation li').removeClass('active');
      $(this).closest('li').addClass('active');
      var id = $(this).attr('data-id');
      $(getId()+'.tab-item').addClass('hidden');
      $(getId()+'div.tab-item[data-id="'+id+'"]').removeClass('hidden');
      if(id === 'addNew'){
        addNewForm();
      }
    })
  }
</code></pre>



<p>The above will output the content of our tabs. It also attaches the handlers to the tab navigation elements. Next up is the <strong>buildTabsContentHtml()</strong> method:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">function buildTabsContentHtml(){
    var source = $("#tabs-content-template").html();
    var template = Handlebars.compile(source);
    Handlebars.registerPartial("tabForm", $("#tabs-content-form-template").html());
    $(getId() + '.tabs-content').html(template(items));
    $.each(items,function(i,item){
      $(getId()+'[data-id="'+item.Id+'"] .editable-content').Editor(EditorOptions);
      $(getId()+'[data-id="'+item.Id+'"] .Editor-editor').html(item.content);
    })
    $(getId()+'.save-changes').on('click',function(){
      var id =$(this).closest('.tab-item').attr('data-id');
      if(validateFields(id)){
        $(this).addClass('fetching').html('<i class="fa fa-refresh fa-spin"></i> Saving...');
        $(getId()+'.editmode').css({'opacity':'.4'});
        setTimeout(function(){
          var ajax = submitChanges(id);
          ajax.done(function(data, xhr){
              var ajax2 = getContent();
              ajax2.done(function(){
                $(getId()+'.tabs-navigation li a[data-id="'+id+'"]').trigger('click');
                addButton();
              });
          });
        },1000);
      }else{
        showErrorMessage(id);
      }
      return false;
    })
</code></pre>



<p>Now things got a bit hairy. First you&#8217;ll notice our handlebars compile &#8211; which is normal, but note the &#8220;registerPartial()&#8221; method. This means that we&#8217;re adding another handlebars template into our existing template. This is the form that handles our inline editing. I&#8217;m not going to post the code on here, instead you can see the #tabs-content-form-template from our <a href="https://github.com/michaelsoriano/sp-tabbed-containers/blob/master/sp-tabbed-containers.txt">text</a> file &#8211; which simply contains a few input forms for our app.</p>



<h3 class="wp-block-heading">Why use partials within templates?</h3>



<p>This is another powerful feature of handlebars. This allows for more re-usability and &#8220;modularity&#8221; for your applications. In other words, we write once and re-use multiple times. In our case, the form can be reused multiple times across our application &#8211; in &#8220;edit&#8221; and &#8220;new&#8221; mode. This will become evident as you write along.</p>



<p>We&#8217;re also using a lightweight WYSWG editor called &#8220;<a href="http://suyati.github.io/line-control">Line Control</a>&#8220;. Since we&#8217;re already using Bootstrap and FontAwesome, it just makes sense that we use a plugin that requires the same libraries. So this is what&#8217;s happening on lines 8-9 above: &#8220;.Editor(EditorOptions)&#8221;, where &#8220;<em>EditorOptions</em>&#8221; is declared on top of of our file as an array.</p>



<h3 class="wp-block-heading">Insert, Update and Delete</h3>



<p>Finally, we attach our &#8220;Save&#8221; and &#8220;Delete&#8221; buttons to do a couple of REST calls to our server when clicked. First our &#8220;Save&#8221; button is connected to our &#8220;<em>submitChanges</em>(id)&#8221; method (which takes care of both &#8220;edits&#8221; and &#8220;inserts&#8221;), while the next call is to &#8220;<em>getContent</em>()&#8221; &#8211; which is our main function to grab the tab items.</p>



<p>The &#8220;Delete&#8221; will also consist of two main REST calls, which is to delete and fetch the records. Our &#8220;<em>deleteRecord</em>()&#8221; function is shown below:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">function deleteRecord(tab){
    var ajax = $.ajax({
       url: tab.__metadata.uri,
       type: "POST",
       headers: {
           "Accept": "application/json;odata=verbose",
           "X-RequestDigest": $("#__REQUESTDIGEST").val(),
           "X-HTTP-Method": "DELETE",
           "If-Match": tab.__metadata.etag
       },
       success: function (data) {
          console.log('record has been deleted');
       },
       error: function (data) {
          console.log('there was a problem with deleting the record');
       }
   });
   return ajax;
  }</code></pre>



<p>While our &#8220;submitChanges()&#8221; method looks like so:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">function submitChanges(id){
      var item = {
        "__metadata": { "type": ListItemEntityTypeFullName },
        "Title" :   $(getId()+'[data-id="'+id+'"] input[name="title"]').val(),
        "content" : $(getId()+'[data-id="'+id+'"] .Editor-editor').html(),
        "tab_x002d_order" : $(getId()+'[data-id="'+id+'"] input[name="tab-order"]').val()
      };
      if(id === 'addNew'){
        item.webpart_x002d_id = webPartId;
        var endpoint = "/_api/web/lists/getbytitle('" + listName + "')/items";
        ajax = $.ajax({
           url: _spPageContextInfo.webAbsoluteUrl + endpoint,
           type: "POST",
           contentType: "application/json;odata=verbose",
           data: JSON.stringify(item),
           headers: {
               "Accept": "application/json;odata=verbose",
               "X-RequestDigest": $("#__REQUESTDIGEST").val()
           },
           error: function (data) {
              console.log(data);
           }
       });
       return ajax;
      } //end addNew;
      var tabItem = findItem(id);
      ajax = $.ajax({
         url: tabItem.__metadata.uri,
         type: "POST",
         contentType: "application/json;odata=verbose",
         data: JSON.stringify(item),
         headers: {
             "Accept": "application/json;odata=verbose",
             "X-RequestDigest": $("#__REQUESTDIGEST").val(),
             "X-HTTP-Method": "MERGE",
             "If-Match": tabItem.__metadata.etag
         },
         error: function (data) {
            console.log(data);
         }
     });
     return ajax;
  }
</code></pre>



<p>Note that all of the REST calls all look similar, with a select few nodes that changes. First you&#8217;ll notice the &#8220;X-HTTP-Method&#8221; for edits is &#8220;MERGE&#8221; and &#8220;DELETE&#8221; for deleting. The rest are pretty much SharePoint REST API requirements &#8211; which you can find more on <a href="https://msdn.microsoft.com/en-us/library/office/jj860569.aspx">this page</a>. Our &#8220;item&#8221; object is also mapped to the names of the list columns that we have. Depending on your list &#8211; you may need to modify this area as well.</p>



<p>In our UI, note the placement of our buttons and our form:<br><img decoding="async" width="509" height="557" class="alignnone size-full wp-image-5632" src="https://michaelsoriano.com/wp-content/uploads/2016/04/sp-tabs5.jpg" alt="sp-tabs5" srcset="https://michaelsoriano.com/wp-content/uploads/2016/04/sp-tabs5.jpg 509w, https://michaelsoriano.com/wp-content/uploads/2016/04/sp-tabs5-274x300.jpg 274w" sizes="(max-width: 509px) 100vw, 509px" /><br>Lastly, you notice a couple of helper functions &#8220;getId()&#8221; and &#8220;findItem()&#8221;. The <strong>getId()</strong> simply returns our current div &#8211; with the &#8220;#&#8221; and a space as a string (or the CSS selector for the current div), while our <strong>findItem()</strong> loops through our global <strong>items</strong> object and returns the current item.</p>



<p>Moving forward, let&#8217;s look at a couple of important internal methods which includes our validation and error messaging mechanism.</p>



<h3 class="wp-block-heading">Form Validation</h3>



<p>Since we&#8217;re entering our data into our SharePoint lists through client side, we can implement a validation method using JavaScript as well. The cool thing about SP&#8217;s REST API has it&#8217;s own validation in the server side so all we have to worry about is the user experience.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">function validateFields(id){
    errors = [];
    $('.error').remove();
    var title = $(getId()+'[data-id="'+id+'"] input[name="title"]');
    var content = $(getId()+'[data-id="'+id+'"] .Editor-editor');
    var tabOrder = $(getId()+'[data-id="'+id+'"] input[name="tab-order"]');
    if(title.val() == ''){
      var obj = {};
      obj.field = 'title';
      obj.message = 'Title cannot be empty'
      errors.push(obj);
    }
    if(content.html() == ''){
      var obj = {};
      obj.field = 'content';
      obj.message = 'Content cannot be empty'
      errors.push(obj);
    }
    if(tabOrder.val() == ''){
      var obj = {};
      obj.field = 'tab-order';
      obj.message = 'Tab order cannot be empty'
      errors.push(obj);
    }
    if(errors.length &gt; 0){
      return false;
    }
    return true;
  }
</code></pre>



<p>Our very simple validation code is above. Note that this happens every time that &#8220;submit&#8221; button is clicked. So it simply goes through the fields &#8211; check for empty and puts the errors in an array. I&#8217;m not checking for anything else like valid data etc &#8211; and feel free to add your own rules. Simply keep pushing the error messages into our array when invalid. Our messaging is handled in the code below:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">function showErrorMessage(id){
    $.each(errors,function(i,er){
      var field = '';
      if(er.field === 'content'){
        field = $(getId()+'[data-id="'+id+'"] .Editor-container');
      }else{
        field = $(getId()+'[data-id="'+id+'"] input[name="'+er.field+'"]');
      }</code></pre>



<p><em>[the code above has been truncated due to an error w syntax highlighter&#8230; sorry]</em></p>



<p>The following screenshot shows our validation code in action. Error messaging is placed underneath each label and at the same time. This way, users can see where they had made an error and fix. Remember to add your own rules as necessary.</p>



<p><br><img decoding="async" width="516" height="502" class="alignnone size-full wp-image-5764" src="https://michaelsoriano.com/wp-content/uploads/2016/05/tabs-validation.png" alt="tabs-validation" srcset="https://michaelsoriano.com/wp-content/uploads/2016/05/tabs-validation.png 516w, https://michaelsoriano.com/wp-content/uploads/2016/05/tabs-validation-300x292.png 300w" sizes="(max-width: 516px) 100vw, 516px" /></p>



<h3 class="wp-block-heading">Checking Permissions</h3>



<p>Finally, since we&#8217;re not using the regular SharePoint process in updating a page with tabs, we need to come up with our own. See, the entity we&#8217;re updating is not the current page &#8211; but a list. So we need to check if the current user has permission to edit the list &#8211; and give them access to our newly created UI.<br>I found this <a href="http://www.lifeonplanetgroove.com/checking-user-permissions-from-the-sharepoint-2013-rest-api/">great article</a> on how to effectively do this &#8211; since Microsoft&#8217;s documentation is a bit vague. </p>



<p>We&#8217;re using the &#8220;effectiveBasePermissions&#8221; REST endpoint along with SP.BasePermissions() class &#8211; which we need from SP.ClientContext object. Yes, it&#8217;s a bit of a mess so simply check the code below:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">function checkPermissions() {
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () {
      var call = jQuery.ajax({
          url: _spPageContextInfo.webAbsoluteUrl +
              "/_api/Web/lists/getbytitle('"+listName+"')/effectiveBasePermissions",
          type: "GET",
          dataType: "json",
          headers: {
              Accept: "application/json;odata=verbose"
          }
      });
      call.done(function (data, textStatus, jqXHR) {
          var permissions = new SP.BasePermissions();
          permissions.initPropertiesFromJson(data.d.EffectiveBasePermissions);
          var permLevels = [];
          for(var permLevelName in SP.PermissionKind.prototype) {
              if (SP.PermissionKind.hasOwnProperty(permLevelName)) {
                  var permLevel = SP.PermissionKind.parse(permLevelName);
                  if(permissions.has(permLevel)){
                        permLevels.push(permLevelName);
                  }
              }
          }
          // console.log(permLevels);
          if($.inArray('editListItems',permLevels) != -1){
            userCanEdit = true;
            addButton();
          }else{
            console.log('You dont have "editListItems" permissions on '+ listName);
          }
      });  //end done
    });
  }
</code></pre>



<p>We&#8217;re still using jQuery&#8217;s ajax to get information, though it&#8217;s wrapped inside a &#8220;SP.SOD.executeFunc()&#8221; method &#8211; which is Microsoft&#8217;s way of loading and executing internal scripts. What we get back is an array we&#8217;re calling &#8220;permLevels&#8221; This array contains all the permissions a user has against our list. </p>



<p>We&#8217;re simply looking for the &#8220;editListItems&#8221; &#8211; and if found, we&#8217;re show the button and let the user edit.<br><img decoding="async" width="638" height="495" class="alignnone size-full wp-image-5767" src="https://michaelsoriano.com/wp-content/uploads/2016/05/tabs-45.jpg" alt="tabs-45" srcset="https://michaelsoriano.com/wp-content/uploads/2016/05/tabs-45.jpg 638w, https://michaelsoriano.com/wp-content/uploads/2016/05/tabs-45-300x233.jpg 300w" sizes="(max-width: 638px) 100vw, 638px" /></p>



<h3 class="wp-block-heading">Final Steps</h3>



<p>Our code is now complete. Note that there is not a single line of .NET code above &#8211; it&#8217;s all JavaScript, HTML and CSS. All server interactions are done through the REST API. This code can be applied whichever way you want to implement &#8211; may it be a custom web part, an app part or simply add the code to a Content Editor.</p>



<p>Remember to update the initialize settings like below: The important part is the &#8220;webPartId&#8221; and &#8220;listName&#8221; parameters &#8211; which connects the plugin to the data you need.</p>



<p><img decoding="async" width="432" height="330" class="alignnone size-full wp-image-5631" src="https://michaelsoriano.com/wp-content/uploads/2016/04/sp-tabs4.jpg" alt="sp-tabs4" srcset="https://michaelsoriano.com/wp-content/uploads/2016/04/sp-tabs4.jpg 432w, https://michaelsoriano.com/wp-content/uploads/2016/04/sp-tabs4-300x229.jpg 300w" sizes="(max-width: 432px) 100vw, 432px" /></p>



<p>Once that&#8217;s done, simply reload the page and you should see your SPA in action. Note that the code editor I used is very basic &#8211; so you might need to go to the list itself when updating content.</p>



<p><img decoding="async" width="581" height="597" class="alignnone size-full wp-image-5858" style="border: 1px solid #ebebeb;" src="https://michaelsoriano.com/wp-content/uploads/2016/06/sp-tabs2.gif" alt="sp-tabs2"></p>



<p>This editor was mostly designed for quick updates to your content.</p>



<p>Remember, the purpose of this article was really to expose you to the inner workings of REST and how to build a single page application right inside SharePoint with existing open technologies such as jQuery, Handlebars and Bootstrap. </p>



<p>Hope you enjoy this piece. Let me know your comments below.</p>
<p>The post <a href="https://michaelsoriano.com/build-sharepoint-single-page-app-front-end-code/">Build a SharePoint Single-Page App using nothing but Front-End Code</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/build-sharepoint-single-page-app-front-end-code/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
		<item>
		<title>How to fully customize your Google Map Info Windows with Infobox</title>
		<link>https://michaelsoriano.com/customize-google-map-info-windows-infobox/</link>
					<comments>https://michaelsoriano.com/customize-google-map-info-windows-infobox/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Fri, 04 Mar 2016 04:43:51 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[google maps]]></category>
		<category><![CDATA[Handlebars]]></category>
		<guid isPermaLink="false">http://michaelsoriano.com/?p=5499</guid>

					<description><![CDATA[<p>So I had a recent task of designing an infowindow for a Google map. Just in case you do not know, Google maps API has the ability of overlaying some HTML on top of a marker, also known as an &#8220;infowindow&#8220;. The problem is, the default infowindow has limited options for HTML styling. View Demo [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/customize-google-map-info-windows-infobox/">How to fully customize your Google Map Info Windows with Infobox</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>So I had a recent task of designing an infowindow for a Google map. Just in case you do not know, Google maps API has the ability of overlaying some HTML on top of a marker, also known as an &#8220;<a href="https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple">infowindow</a>&#8220;. </p>



<p>The problem is, the default infowindow has limited options for HTML styling.</p>



<p class="btn"><a href="http://demo.michaelsoriano.com/infobox/">View Demo</a></p>



<p>The default infowindow looks like below:</p>



<p><img decoding="async" width="354" height="261" class="alignnone size-full wp-image-5511" src="https://michaelsoriano.com/wp-content/uploads/2016/03/regular.png" alt="regular" srcset="https://michaelsoriano.com/wp-content/uploads/2016/03/regular.png 354w, https://michaelsoriano.com/wp-content/uploads/2016/03/regular-300x221.png 300w" sizes="(max-width: 354px) 100vw, 354px" /></p>



<p>You can only style the inside of the window. We need a bit more flexibility and style the entire window. </p>



<p>Thankfully there&#8217;s this plugin called &#8220;<a href="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/examples.html">Infobox</a>&#8220;. With InfoBox, you can style the entire window by simply passing a few parameters. In my case, I need to make the window look like below:</p>



<p><img decoding="async" width="354" height="261" class="alignnone size-full wp-image-5519" src="https://michaelsoriano.com/wp-content/uploads/2016/03/modified2.jpg" alt="modified2" srcset="https://michaelsoriano.com/wp-content/uploads/2016/03/modified2.jpg 354w, https://michaelsoriano.com/wp-content/uploads/2016/03/modified2-300x221.jpg 300w" sizes="(max-width: 354px) 100vw, 354px" /></p>



<p>Ready to get started? Let&#8217;s start by adding our script to InfoBox. Note that if you&#8217;re loading Google Maps asynchronously, you need to add your script in your callback method.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">var initMap = function() {
  var s = document.createElement("script");
  s.type = "text/javascript";
  s.src = "js/infobox.js";
  $("head").append(s);
  var map = new google.maps.Map(document.getElementById('map-wrap'), {
    center: {lat: 33.78444500, lng: -118.15378000},
    zoom: 8
  });
}</code></pre>



<p>Once your scripts are loaded, you should see your map, and add a simple marker like so:</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">var marker, i;
marker = new google.maps.Marker({
   position: new google.maps.LatLng(22.556444, -44.565),
   map: map
})</code></pre>



<p>Now, InfoBox has plenty of options &#8211; so I just leave the defaults alone. What we really need is the &#8220;boxStyle&#8221; object. This we can pass our CSS as key/value pairs. This is the style of the outermost box &#8211; the box that the default infowindow doesn&#8217;t let you customize easily.</p>



<pre class="wp-block-code"><code lang="javascript" class="language-javascript">var ibOptions = {
    		disableAutoPan: false
    		,maxWidth: 0
    		,pixelOffset: new google.maps.Size(-140, 0)
    		,zIndex: null
    		,boxStyle: {
          padding: "0px 0px 0px 0px",
          width: "252px",
          height: "40px"
        },
        closeBoxURL : "",
        infoBoxClearance: new google.maps.Size(1, 1),
    		isHidden: false,
    		pane: "floatPane",
    		enableEventPropagation: false
    	};</code></pre>



<p>Once that&#8217;s done, let&#8217;s create a click handler, so our InfoBox will pop out when our marker is clicked. The code below is an example of a closure. We&#8217;re only including the &#8220;non static&#8221; properties inside our closure, so you&#8217;ll notice that our &#8220;<em>innerHTML</em>&#8221; property is inside.</p>



<pre class="wp-block-code"><code class="">google.maps.event.addListener(marker, 'click', (function(marker, i) {
      return function() {
        var source   = $("#infobox-template").html();
        var template = Handlebars.compile(source);
        var boxText = document.createElement("div");
        boxText.style.cssText = "margin-top: 8px; background: #fff; padding: 0px;";
        boxText.innerHTML = template(subSet[i]);
        ibOptions.content = boxText
        var ib = new InfoBox(ibOptions);
      	ib.open(map, marker);
        map.panTo(ib.getPosition());
      }
  })</code></pre>



<p>I am also using <a href="http://handlebarsjs.com/">Handlebars</a> for templating, so the template is compiled multiple times. Also inside click handler above, and only shows up when the marker is actually clicked. My template will look like below. Remember that I have multiple of these boxes.</p>



<pre class="wp-block-code"><code lang="markup" class="language-markup">&lt;div class="info-box-wrap">
  &lt;img src="{{img_src}}" />
  &lt;div class="info-box-text-wrap">
  &lt;h6 class="address">{{address}}, {{city}} {{zip}} {{state}}&lt;/h6>
  &lt;p class="price">{{price}}&lt;/p>
&lt;/div>
&lt;div class="action-btns">&lt;/div>
&lt;/div></code></pre>



<p>Finally, the styles. Remember, InfoBox has already done the outer shell styles. Now it&#8217;s up to us to style the inner part of our box. So simply hack away with your CSS chops:</p>



<pre class="wp-block-code"><code lang="css" class="language-css">.info-box-wrap {
  background:#fff;
  overflow: hidden;
  box-shadow: 5px 5px 0px rgba(0, 0, 0, 0.08);
}
.info-box-text-wrap {
  height:40px !important;
  width:120px;
  float:left;
  overflow: hidden;
}
.action-btns {
  float:left;
  width:70px;
  overflow: hidden;
  position: relative;
  top:12px;
  left: 6px;
}
.action-btns i {
  font-size: 18px;
  color: #78A737;
  margin-left: 3px;
}
.action-btns i:hover {
  transition: color 0.5s ease;
  color:#ccc;
  cursor: pointer;
}
.action-btns i.fa-heart-o {
  font-weight: bold;
}
.info-box-text-wrap h6.address {
  padding:6px 5px 1px 0;
  margin:0 0 0 0;
  font-family:"Roboto Slab";
  color: #0c99c8;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.info-box-text-wrap p {
  padding:0 0 0 0;
  margin:0 0 0 0;
}
.info-box-text-wrap p.price {
  color:#B25B00;
}
.info-box-wrap  img {
  width:40px !important;
  height:40px;
  float:left;
  margin-right: 10px;
  padding-top:0;
  margin-top:0;
}</code></pre>



<p>With the above code everything should be in place. All we need is an arrow that points back from our box to our marker.</p>



<h3 class="wp-block-heading">Creating the Arrow</h3>



<p>There is an awesome article on how to create <a href="https://css-tricks.com/snippets/css/css-triangle/">traingles</a> that is pure CSS. We really don&#8217;t need an image for this type of thing. Another thing, we&#8217;re going to use the <strong>::before</strong> pseudo selector to insert our triangle. This prevents us from adding unnecessary DIVs into our markup.</p>



<pre class="wp-block-code"><code lang="css" class="language-css">.infoBox:before{
  content : " ";
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 10px solid #fff;
  position:absolute;
  top:-10px;
  left:130px;
}</code></pre>



<p>Note the &#8220;content&#8221; property with the value of &#8221; &#8220;. This makes it so the ::before selector is actually visible in the DOM.</p>



<p>And the final result looks like below. Note that the map automatically centers to the marker that is clicked. That is in our click handler &#8220;<em>map.panTo(ib.getPosition())</em>&#8221; method.</p>



<p><img decoding="async" width="489" height="293" class="alignnone size-full wp-image-5520" src="https://michaelsoriano.com/wp-content/uploads/2016/03/infobox2.gif" alt="infobox2"></p>



<p>Note that in the <a href="http://demo.michaelsoriano.com/infobox/">demo</a>, it&#8217;s loading sample data from a text file. I&#8217;m also outputting which property is clicked on the left side.</p>



<p>Until next time, please leave your comments below.</p>
<p>The post <a href="https://michaelsoriano.com/customize-google-map-info-windows-infobox/">How to fully customize your Google Map Info Windows with Infobox</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/customize-google-map-info-windows-infobox/feed/</wfw:commentRss>
			<slash:comments>21</slash:comments>
		
		
			</item>
		<item>
		<title>Exploring the Bootstrap 3.0 Grid System</title>
		<link>https://michaelsoriano.com/exploring-the-bootstrap-3-0-grid-system/</link>
					<comments>https://michaelsoriano.com/exploring-the-bootstrap-3-0-grid-system/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Thu, 14 Nov 2013 03:57:06 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[Responsive Design]]></category>
		<guid isPermaLink="false">http://fearlessflyer.com/?p=3767</guid>

					<description><![CDATA[<p>Understanding what this framework can do for your next responsive site The idea of a grid system has been around since the 960.gs framework days. Web designers from all over the world began realizing the importance of pixel perfect alignment, gutter spacing and the rule of thirds. Gone are the days of grid-less web pages. [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/exploring-the-bootstrap-3-0-grid-system/">Exploring the Bootstrap 3.0 Grid System</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Understanding what this framework can do for your next responsive site<br />
The idea of a grid system has been around since the <a href="http://960.gs/">960.gs</a> framework days. Web designers from all over the world began realizing the importance of pixel perfect alignment, gutter spacing and the rule of thirds. Gone are the days of grid-less web pages. And yes, things were great. Up until recently. <strong>Responsive web design</strong> was born.<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/bstrap.jpg" alt="bstrap" width="600" height="392" class="alignnone size-full wp-image-3768" /><br />
The problem was 960.gs, along with older frameworks had static page widths. Since we are now designing for multiple screen sizes, web frameworks had to adapt quickly.<br />
Enter Zurb <a href="http://foundation.zurb.com/">Foundation</a>. The first responsive framework that had web designers pee in their pants. Big sites such as <a href="http://www.esquire.co.uk/">Esquire UK</a>, <a href="http://upmagazine-tap.com/">Up Magazine</a> and <a href="http://thenextweb.com/">The Next Web</a> redesigned and we kept resizing our browsers in awe. We were simply amazed on how elements of the pages shifted gracefully. Horizontal scrollbars were a thing of the past and modern web design became &#8211; well, more modern.<br />
Now we have the latest and the greatest Bootstrap 3. Despite their awesome <a href="http://getbootstrap.com/css/">documentation</a>, my focus is to elaborate on just the heart of the framework &#8211; the grid system.<br />
Let&#8217;s dive in and see what Bootstrap&#8217;s grid system is all about.</p>
<h3>The Basic .col-xx-xx Classes</h3>
<p>Bootstraps column classes are what makes up the individual columns of the grid. It&#8217;s main purpose is to align your components into &#8211; you guessed it, columns. They&#8217;re designed to have 3 sections:<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/col-classes.jpg" alt="col-classes" width="557" height="223" class="noborder alignnone size-full wp-image-3769" /><br />
The prefix part &#8220;col&#8221; &#8211; just organizes all the col classes together, sort of like a namespace. And if you&#8217;ve worked with other frameworks in the past, the 3rd section &#8220;12&#8221; just tells us to occupy 12 columns out of the maximum 12. Pretty basic right?<br />
But what about the 2nd part? In our example, it&#8217;s the &#8220;lg&#8221;. This tells the browser to primarily use this for large screens only (default is 1170 pixels and above). Meaning, since we can use multiple classes on any element, <strong>we can <u>now</u> design for multiple sizes of the screen</strong>. Pretty powerful eh?<br />
<strong><u>So how does it do that?</u></strong><br />
So if you investigate the css, and look for that particular class (.col-lg-12), you will see that it&#8217;s enclosed in a media query:</p>
<pre>
@media (min-width: 1200px) {
.col-lg-12 {
    width: 100%;
  }
}
</pre>
<p>As a matter of fact, ALL of the &#8220;lg&#8221; classes are inside this media query. So the rule only applies to a specific screen resolution. The rest of the sizes (md for 970px, sm for 768px and xs for less than 768px) contains the rules for its respective classes. Pretty forward thinking right?<br />
<strong><u>Show me an example of its usefulness:</u></strong><br />
A common scenario is a two-column layout, with content on the left and sidebar on the right. With just a single class applied to both areas: red div has a class of <strong>col-lg-9</strong> and green div has <strong>col-lg-3</strong>.<br />
But most of the time &#8211; your sidebar&#8217;s content is not ready for a full page width in medium and small view ports. So you wish the sidebar doesn&#8217;t snap to the bottom right away right?<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/example1.gif" alt="example1" width="650" height="384" class="alignnone size-full wp-image-3770" /><br />
<strong>The solution:</strong> apply multiple .col classes into the same divs (one for each of the view port sizes). Take a look at the next example &#8211; where we apply a different column number ONLY on the extra small (<strong>.col-xs-12</strong>).<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/example2.gif" alt="example2" width="650" height="384" class="alignnone size-full wp-image-3771" /><br />
You see how the divs retained their 2 column layout all the way until the extra small view port is reached. Only then, did our sidebar snap to the bottom at full width. So you see how <strong>useful</strong> this is yet?</p>
<h3>Classes &#8220;row&#8221; and &#8220;container&#8221;</h3>
<p>Let&#8217;s jump out of the columns and look at the classes that wrap them. We have two important classes that do just that.<br />
<strong><u>.row</u></strong><br />
Just as the word describes &#8211; a row is something that is on one horizontal layer. Similar to a &#8220;record&#8221; in a database, or a &#8220;row&#8221; in a table. In Bootstrap, if you want elements to be in one horizontal layer &#8211; use a class <strong>.row</strong>.<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/example3.gif" alt="example3" width="650" height="384" class="alignnone size-full wp-image-3772" /><br />
The dark grey divs both have a class &#8220;.row&#8221;. A <strong>row</strong> basically acts as a traditional div tag, but instead can be applied as a class. I&#8217;ve used class .row on a header or footer tag &#8211; and it works really well.<br />
<strong><u>.container</u></strong><br />
Ideally, you add your HTML elements that need to be grouped together inside a class .container. The &#8220;max-width&#8221; properties for each break point (the media queries) are defined in this class. It is a very important class. One that is required to make things work the way they do.<br />
According to Bootstrap&#8217;s docs, containers are:</p>
<blockquote><p>
Easily center a page&#8217;s contents by wrapping its contents in a .container. Containers set max-width at various media query breakpoints to match our grid system.
</p></blockquote>
<p>Containers also follow the default padding rule of 15 pixels on each side. So the contents are automatically flushed together with just the right amount of gutter space all the time.</p>
<h3>How does Nesting work?</h3>
<p>Nesting means adding more .col classes inside of existing .col classes. Most of the time, you would need to add a .row class first &#8211; before nesting your .col divs inside in order to see desired results.<br />
<strong>So when do you need to nest?</strong><br />
All the time! If you inspect most HTML documents &#8211; it&#8217;s already a series of nested DOM elements so nesting your .col classes is already expected behavior. Although in Bootstrap, nesting will save you a lot of work calculating and deciding how wide a column has to be.<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/example4.gif" alt="example4" width="650" height="384" class="alignnone size-full wp-image-3773" /><br />
See both green divs have that have .col-lg-6 classes? These are nested inside the red div (the parent div).  Also, notice that a nested .col-lg-6 class takes up 50% of the parent div&#8217;s width. In other words, all you really need to remember is the 12 grid rule &#8211; no matter how deep the nesting goes.<br />
Note that I also applied the multiple classes technique (discussed above) to the child classes shown in the screenshot above. This is so that when resized, both div&#8217;s retain it&#8217;s 6 column width &#8211; until the last view port kicks in.</p>
<h3>Pushing, Pulling and Offsetting</h3>
<p>For even deeper customization of the grid elements, Bootstrap allows you to shift the columns around. Push and pull classes allow you to move the column # times to the left (also know as pull), or # times to the right (push).<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/ordering.jpg" alt="ordering" width="475" height="228" class="noborder alignnone size-full wp-image-3775" /><br />
So consider the markup below. Even though the green div is written right above the red div, the push and pull classes allows us to order them as if they were otherwise.</p>
<pre>
<div class="col-md-4 col-md-push-4"><p>green pushed 4</p></div>
<div class="col-md-4 col-md-pull-4"><p>red pulled 4</p></div>
</pre>
<p>The code above makes it so the divs appear in the browser in a different order.<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/push-pull.png" alt="push-pull" width="600" height="226" class="alignnone size-full wp-image-3776" /><br />
<strong><u>What makes it work?</u></strong><br />
If you inspect the push and pull classes, it utilizes the right and left property respectively &#8211; in percents. Since everything in Bootstrap is positioned relatively, using left and right will automatically just work.</p>
<pre>
@media (min-width: 992px)
   .col-md-pull-4 {
      right: 33.33333333333333%;
   }
   .col-md-push-4 {
      left: 33.33333333333333%;
   }
}
</pre>
<p><strong><u>Offsets</u></strong><br />
Offsetting classes is similar to push and pull classes &#8211; except for the &#8220;offset&#8221; keyword in the class name. Also similar to push and pull, the number in the class tells the browser how many columns to offset the element.<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2013/11/offsetting.jpg" alt="offsetting" width="525" height="235" class="alignnone noborder size-full wp-image-3774" /><br />
The difference with offsetting is that it uses the margin left property. So if your element is right next to another element &#8211; it will simply push itself against it by the designated percentage. See the code below for a <strong>.col-md-offset-4</strong> class:</p>
<pre>
@media (min-width: 992px)
 .col-md-offset-4 {
    margin-left: 33.33333333333333%;
 }
</pre>
<p>You see how this can be useful? You can simply apply this class to whichever you want to offset and still retain the responsive margins effectively. Pretty good right?</p>
<h3>Visibility Classes</h3>
<p>Although this has nothing to do with the grid, I thought it is worth a mention. We&#8217;ve all worked with a system that has a default class for a &#8220;display:none&#8221;. Well not only does Bootstrap have this (it&#8217;s called .hidden), but they&#8217;ve taken it an extra step. I like to call them the &#8220;visibility&#8221; classes.<br />
These classes do just that &#8211; controls the visibility of elements &#8211; across multiple views. Now, when designing your web site, you just now have to pick which elements to show, hide in large, medium and small views &#8211; then simply apply the visibility classes. The table below (taken from Bootstrap&#8217;s website) explains what the classes do in specific view ports.</p>
<style>
.is-visible {
color: #468847;
background-color: #dff0d8 !important;
}
</style>
<table class="table table-bordered table-striped responsive-utilities" style="margin-top:35px; margin-bottom:45px;">
<thead>
<tr>
<th></th>
<th>
              Extra small devices<br />
              <small>Phones (&lt;768px)</small>
            </th>
<th>
              Small devices<br />
              <small>Tablets (≥768px)</small>
            </th>
<th class="hidden-xs">
              Medium devices<br />
              <small>Desktops (≥992px)</small>
            </th>
<th class="hidden-xs">
              Large devices<br />
              <small>Desktops (≥1200px)</small>
            </th>
</tr>
</thead>
<tbody>
<tr>
<th><code>.visible-xs</code></th>
<td class="is-visible">Visible</td>
<td class="is-hidden">Hidden</td>
<td class="is-hidden hidden-xs">Hidden</td>
<td class="is-hidden hidden-xs">Hidden</td>
</tr>
<tr>
<th><code>.visible-sm</code></th>
<td class="is-hidden">Hidden</td>
<td class="is-visible">Visible</td>
<td class="is-hidden hidden-xs">Hidden</td>
<td class="is-hidden hidden-xs">Hidden</td>
</tr>
<tr>
<th><code>.visible-md</code></th>
<td class="is-hidden">Hidden</td>
<td class="is-hidden">Hidden</td>
<td class="is-visible hidden-xs">Visible</td>
<td class="is-hidden hidden-xs">Hidden</td>
</tr>
<tr>
<th><code>.visible-lg</code></th>
<td class="is-hidden">Hidden</td>
<td class="is-hidden">Hidden</td>
<td class="is-hidden hidden-xs">Hidden</td>
<td class="is-visible hidden-xs">Visible</td>
</tr>
</tbody>
<tbody>
<tr>
<th><code>.hidden-xs</code></th>
<td class="is-hidden">Hidden</td>
<td class="is-visible">Visible</td>
<td class="is-visible hidden-xs">Visible</td>
<td class="is-visible hidden-xs">Visible</td>
</tr>
<tr>
<th><code>.hidden-sm</code></th>
<td class="is-visible">Visible</td>
<td class="is-hidden">Hidden</td>
<td class="is-visible hidden-xs">Visible</td>
<td class="is-visible hidden-xs">Visible</td>
</tr>
<tr>
<th><code>.hidden-md</code></th>
<td class="is-visible">Visible</td>
<td class="is-visible">Visible</td>
<td class="is-hidden hidden-xs">Hidden</td>
<td class="is-visible hidden-xs">Visible</td>
</tr>
<tr>
<th><code>.hidden-lg</code></th>
<td class="is-visible">Visible</td>
<td class="is-visible">Visible</td>
<td class="is-visible hidden-xs">Visible</td>
<td class="is-hidden hidden-xs">Hidden</td>
</tr>
</tbody>
</table>
<h3>Conclusion</h3>
<p>I believe we&#8217;ve looked at the core classes that will get you up and running with Bootstrap&#8217;s grid system. This alone, if used properly &#8211; will save you countless hours of development time. Don&#8217;t forget to read up on the rest of Bootstrap&#8217;s many features such as the built-in components, Javascript plugins and of course, the rest of the styles. Good luck and have fun coding!<br />
Last of all, I would like to keep this an open discussion. If there&#8217;s anything that you would like to add, please leave a comment. I will be more than happy to answer questions or append to the article.</p>
<p>The post <a href="https://michaelsoriano.com/exploring-the-bootstrap-3-0-grid-system/">Exploring the Bootstrap 3.0 Grid System</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/exploring-the-bootstrap-3-0-grid-system/feed/</wfw:commentRss>
			<slash:comments>21</slash:comments>
		
		
			</item>
		<item>
		<title>Build a Simple Responsive Navigation Menu from scratch with jQuery and CSS</title>
		<link>https://michaelsoriano.com/build-a-simple-responsive-navigation-menu-from-scratch/</link>
					<comments>https://michaelsoriano.com/build-a-simple-responsive-navigation-menu-from-scratch/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Mon, 21 Oct 2013 05:12:48 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<guid isPermaLink="false">http://fearlessflyer.com/?p=3686</guid>

					<description><![CDATA[<p>Follow this tutorial to create your own responsive navigation menu without a plugin. So far one of the hardest parts of designing a responsive website is the dreaded navigation menu. I know because I&#8217;ve always struggled with it. I&#8217;ve seen plenty of plugins that convert your menu into a drop down list, or a fancy [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/build-a-simple-responsive-navigation-menu-from-scratch/">Build a Simple Responsive Navigation Menu from scratch with jQuery and CSS</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Follow this tutorial to create your own responsive navigation menu without a plugin.<br />
So far one of the hardest parts of designing a responsive website is the dreaded navigation menu. I know because I&#8217;ve always struggled with it. I&#8217;ve seen plenty of plugins that convert your menu into a drop down list, or a fancy side menu that pushes your content to the left. But I wasn&#8217;t happy with them. So I decided to write one of my own.<br />
<a class="viewdemo" href="http://demo.michaelsoriano.com/responsive-menu/" rel="nofollow">View Demo</a><br />
<img decoding="async" class="alignnone size-full wp-image-4376" src="https://michaelsoriano.com/wp-content/uploads/2013/10/responsive-menu.gif" alt="responsive-menu" width="598" height="358" /><br />
Nothing fancy here. I just want to simply hide the horizontal menu, show an icon and when clicked &#8211; have the &#8220;mini-navigation&#8221; show as a standard list &#8211; pushing the rest of the content down. Ready to get started? Let&#8217;s begin.</p>
<h3>The Problem</h3>
<p>Most navigation menus is marked up with list items that are floated left. While this is good with desktop resolutions, it doesn&#8217;t work well when the view port is for small screens.<br />
<img decoding="async" class="alignnone noborder size-full wp-image-3688" src="https://michaelsoriano.com/wp-content/uploads/2013/10/resp-nav-11.jpg" alt="resp-nav-1" width="600" height="251" /><br />
As I&#8217;ve mentioned above, we&#8217;ll get our way around this problem by hiding the original menu and showing a new one. This can all be achieved by CSS and a little jQuery. Take a look at the existing markup for the menu.<br />
<em>code taken out &#8211; due to problems with my plugin</em></p>
<h3>Create the Media Query</h3>
<p>Let&#8217;s add a media query in our CSS for max width of 796 pixels. We then hide the list items by setting a &#8220;display none&#8221; inside the query.</p>
<pre>@media (max-width: 796px) {
 .navigation.responsive ul li {
   display:none;
}
</pre>
<p>Now try re-sizing your browser to less than 796 pixels and see that the contents of our menu disappears.</p>
<h3>Add the Trigger and Empty Div into the Markup</h3>
<p>We&#8217;re going to need a new anchor tag into our existing menu, also known as the &#8220;trigger&#8221;. We can simply add a last list item to our navigation menu &#8211; but set it to &#8220;display:none&#8221;. I&#8217;ve created a class in our CSS called &#8220;hidden&#8221;, to simply use that with our trigger.<br />
Then add an empty DIV outside of our current navigation. I&#8217;ve named our new DIV &#8220;mini-navigation&#8221;. I also added the &#8220;hidden&#8221; class to this DIV, so both our trigger and mini-nav won&#8217;t be visible by default. Our markup should now look like below:<br />
<em>code taken out &#8211; due to problems with my plugin</em></p>
<div class="navigation responsive"></div>
<p>Note the last list item and our empty DIV above.</p>
<h3>Show the Trigger in our Media Query</h3>
<p>Inside our media query, add these lines to our CSS:</p>
<pre>.navigation.responsive ul li.hidden {
  display:block;
}
.navigation.responsive ul li.hidden:hover {
  border-radius:4px 0 0 4px;
}
.navigation.responsive ul li.hidden a{
  background:url('menu.png')no-repeat 0 -5px;
  padding-left:24px;
}
</pre>
<p>Note that the key code in the above is the &#8220;display:block&#8221;. This will make our trigger be visible. The rest of the code simply styles our trigger so it will look like below:<br />
<img decoding="async" class="alignnone noborder size-full wp-image-3689" src="https://michaelsoriano.com/wp-content/uploads/2013/10/resp-nav-2.jpg" alt="resp-nav-2" width="512" height="123" /></p>
<h3>Add the Javascript</h3>
<p>Now that we have our trigger, we need Javascript to handle what happens when it is clicked. First, make sure you&#8217;re hooked up with jQuery in your page.<br />
Then let&#8217;s add the following code in a set of script tags. I&#8217;ll explain what it does after the source.</p>
<pre>$(document).ready(function(){
	var trigger = $(".trigger a");
	var menu = $(".mini-navigation");
	trigger.on('click', function(){
		var html = $(".navigation.responsive").html();
		menu.html(html).toggle(0, function(){
		  if($(this).is(":visible")){
			trigger.html('Hide Menu');
				}else{
					trigger.html('Show Menu');
				}
			$('.mini-navigation li.trigger').remove();
			});
		});
		$(window).resize(function(){
			menu.hide();
			trigger.html('Show Menu');
		});
	})
</pre>
<p>Let me explain the code above. First we open the document.ready() function. We then set two variables: trigger(our trigger link) and menu(our hidden div). We bind the click event by using doing trigger.on(). Everything inside the .on() anonymous function is the heart of the code.<br />
We create another variable called &#8220;hmtl&#8221; &#8211; which is the contents of our existing navigation. We then add it to our hidden div by doing: menu.html(html). So our hidden div (mini-navigation) now has our list items from the original menu.<br />
We then chain the .toggle() function right after the .html(). This will show or hide our hidden div. We add an if else statement as a callback inside the .toggle(), just to change the label of our trigger from &#8220;Show Menu&#8221; to &#8220;Hide Menu&#8221;.<br />
We also remove the last list item (which is the duplicate trigger).<br />
Finally, we have window.resize() function &#8211; which simply resets our menu back to hidden and the label to &#8220;Show Menu&#8221; &#8211; which are the default states.</p>
<h3>Style the Mini Navigation</h3>
<p>This is of course, open to your customization. But what I&#8217;ve done is simply make our new menu a list item, with some bottom borders, appropriate padding and hover states.</p>
<pre>.mini-navigation {
	border-left:1px solid #ccc;
	border-bottom:1px solid #ccc;
	border-right:1px solid #ccc;
	padding:0 0 0 0;
	margin-left:5px;
	margin-right:5px;
	border-radius:0 0 8px 8px;
}
.mini-navigation ul {
	padding:0 0 0 0;
	margin:0 0 0 0;
}
.mini-navigation ul li {
	margin:0 0 0 0;
	padding:10px 18px 12px 23px;
	list-style:none;
	border-bottom:1px solid #ebebeb;
}
.mini-navigation ul li:hover {
	background:#f6f6f6;
}
.mini-navigation ul li a {
	text-decoration:none;
	font-size:12px;
	color:#1e7759;
}
.mini-navigation ul li a:hover {
	text-decoration:underline;
}
.mini-navigation ul li:last-child{
	border-bottom:none;
	padding-bottom:15px;
}
.mini-navigation ul li:last-child:hover {
	border-radius:0 0 8px 8px;
}
</pre>
<p>Our mini navigation should look like below:<br />
<img decoding="async" class="alignnone noborder size-full wp-image-3690" src="https://michaelsoriano.com/wp-content/uploads/2013/10/resp-nav-3.jpg" alt="resp-nav-3" width="577" height="423" /><br />
Note that typically, the navigation is right above the rest of your content. When our menu appears &#8211; it simply pushes the rest of the content downwards. And when the new page loads &#8211; our menu returns to hidden by default.</p>
<h3>Conclusion</h3>
<p>And I believe that should do it. That&#8217;s as simple as it gets. Our very own responsive navigation menu system. Please leave your comments below.</p>
<p>The post <a href="https://michaelsoriano.com/build-a-simple-responsive-navigation-menu-from-scratch/">Build a Simple Responsive Navigation Menu from scratch with jQuery and CSS</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/build-a-simple-responsive-navigation-menu-from-scratch/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
		<item>
		<title>Create Rotating (Full Paged) Background Images with CSS and jQuery</title>
		<link>https://michaelsoriano.com/create-rotating-full-paged-background-images-with-css-and-jquery/</link>
					<comments>https://michaelsoriano.com/create-rotating-full-paged-background-images-with-css-and-jquery/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Wed, 05 Oct 2011 07:30:56 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>
		<guid isPermaLink="false">http://fearlessflyer.com/?p=2207</guid>

					<description><![CDATA[<p>Full page background images on web sites has become more popular than ever. Its a good way to utilize the remaining real estate of the browser, without having to sacrifice content. But what about rotating these images? Wouldn&#8217;t that even be better? This tutorial will walk you through how to create full page background images [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/create-rotating-full-paged-background-images-with-css-and-jquery/">Create Rotating (Full Paged) Background Images with CSS and jQuery</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Full page background images on web sites has become more popular than ever. Its a good way to utilize the remaining real estate of the browser, without having to sacrifice content. But what about rotating these images? Wouldn&#8217;t that even be better?</p>
<p><img decoding="async" class="alignnone size-full wp-image-7754" src="https://michaelsoriano.com/wp-content/uploads/2022/07/jquery.png" alt="jquery" width="600" height="270" srcset="https://michaelsoriano.com/wp-content/uploads/2022/07/jquery.png 600w, https://michaelsoriano.com/wp-content/uploads/2022/07/jquery-300x135.png 300w" sizes="(max-width: 600px) 100vw, 600px" /><br />
This tutorial will walk you through how to create full page background images that rotate like a slideshow. We will be using CSS and jQuery &#8211; particularly the nifty <a href="http://jquery.malsup.com/cycle/">cycle plugin</a>. Ready to get started? Let&#8217;s begin:</p>
<h3>The HTML Markup:</h3>
<p>First we create the background images. Place them in your root folder, in a directory called &#8220;images&#8221;. We wrap them around a special DIV which houses all the images. We need this DIV so we can target it from our script later:<br />
<script src="https://gist.github.com/michaelsoriano/575d7ac92aecadf8d8a9.js"></script><br />
Make sure your image is a good sized horizontal shot. For almost all screen resolutions have wider width vs height. Our images will scale to the width of the screen. The DIV id=&#8221;wrap&#8221; is the container for your content. This is directly underneath our slideshow container. Save your HTML and view it in the browser. You should see a series of images on top of each other.</p>
<h3>The CSS</h3>
<p>Add this code to your page. This will set the images width to span the entire page.<br />
<script src="https://gist.github.com/michaelsoriano/db3a47cef703f732aa56.js"></script><br />
View Refresh your page. You should see only the first image. The rest of the images are tucked away underneath the first one. This is what &#8220;z-index&#8221; and &#8220;position&#8221; properties in our code did. Now for the slideshow effect, we use some jQuery magic.</p>
<h3>The jQuery</h3>
<p>Download the jQuery Cycle plugin from <a href="http://jquery.malsup.com/cycle/download.html">here</a>, and place it inside a directory called &#8220;scripts&#8221; in your root folder. Add the jQuery library and a reference to the plugin inside the head section of your HTML.<br />
Then add the following code that will pickup our slideshow DIV, and apply the cycle functionality from our plugin:<br />
<script src="https://gist.github.com/michaelsoriano/07b62137c49a9e033faa.js"></script><br />
You can choose to edit the plugin options by tweaking the above code. For the list of available options such as transition effects, timing and callbacks &#8211; refer to the jQuery Cycle <a href="http://jquery.malsup.com/cycle/options.html">docs</a>.</p>
<h3>Conclusion:</h3>
<p>Now refresh your browser and you should see your background fade into the next image and to another. Like I said, this style can be quite refreshing &#8211; to vary your page from a million other websites out there with large image backgrounds. There is a bug in some browsers when re-sized, the image stays in the original size and doesn&#8217;t adjust on the fly. Maybe someone out there can improve through Javascript or CSS. Please leave a comment below.</p>
<p>The post <a href="https://michaelsoriano.com/create-rotating-full-paged-background-images-with-css-and-jquery/">Create Rotating (Full Paged) Background Images with CSS and jQuery</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/create-rotating-full-paged-background-images-with-css-and-jquery/feed/</wfw:commentRss>
			<slash:comments>117</slash:comments>
		
		
			</item>
		<item>
		<title>Create an Awesome Photo Gallery with FancyBox and TimThumb</title>
		<link>https://michaelsoriano.com/create-an-awesome-photo-gallery-with-fancybox-and-timthumb/</link>
					<comments>https://michaelsoriano.com/create-an-awesome-photo-gallery-with-fancybox-and-timthumb/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Thu, 13 Jan 2011 18:41:46 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Fancybox]]></category>
		<category><![CDATA[jQuery]]></category>
		<guid isPermaLink="false">http://fearlessflyer.com/?p=1978</guid>

					<description><![CDATA[<p>Time for a little tutorial eh? Let’s make a Photo Gallery – one that is a combination of already made scripts and plugins; one that is loaded automatically; and of course – one that looks awesome. We are using PHP, FancyBox jQuery plugin and TimThumb. Important: You should use the latest version of TimThumb due [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/create-an-awesome-photo-gallery-with-fancybox-and-timthumb/">Create an Awesome Photo Gallery with FancyBox and TimThumb</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Time for a little tutorial eh? Let’s make a Photo Gallery – one that is a combination of already made scripts and plugins; one that is loaded automatically; and of course – one that looks awesome. We are using PHP, FancyBox jQuery plugin and TimThumb.<br />
Important: You should use the latest version of TimThumb due to vulnerability issues with old code. Make sure you keep updated to keep your site secure.<br />
Ready to get started? Let’s begin:</p>
<h3>Set up the Environment:</h3>
<p>In order for our PHP scripts to run, you need to have a web server. A good example is XAMPP, which is free and can be downloaded from <a href="http://www.apachefriends.org/en/xampp.html">http://www.apachefriends.org/en/xampp.html</a>.  Create a root folder – name it anything, and inside it, create the following folders:</p>
<ul>
<li><strong>Images </strong> &#8211; this is where the image of the gallery will go. </li>
<li><strong>Scripts </strong> – this is where our scripts will go</li>
</ul>
<p>Download <strong>Timthumb </strong>script: <a href="http://www.darrenhoyt.com/2008/04/02/timthumb-php-script-released/">http://www.darrenhoyt.com/2008/04/02/timthumb-php-script-released/</a>. Timthumb is an image resizer script that is written in PHP.  Save <strong>timthumb.php</strong> inside scripts.<br />
Let’s create a new HMTL file inside the root, name it<strong> index.php</strong>. Add this line of code:<br />
<script src="https://gist.github.com/michaelsoriano/284b9bd79a3d49ea5aff.js"></script><br />
The above code creates 2 variables:</p>
<ul>
<li><strong>$path</strong> – is the full image path of our images</li>
<li><strong>$files</strong> – is an array of filenames from a specified folder that we’ve scanned through the<strong> scandir()</strong> function</li>
</ul>
<p>Then add the code below:<br />
<script src="https://gist.github.com/michaelsoriano/6acc208b7569fd5bb333.js"></script><br />
This loops through each item in the array $files – and assign it to another variable $file. For each one found, we’re printing a list item with an anchor and image tags. Within these tags you’ll notice the variables we’ve created earlier. The timthumb script is inserted at the beginning of the src attribute of our thumbnails. The width and the height parameters are hard coded in there as well. Note that we are going to randomize this section a little bit later.<br />
Assuming that you already have photos in your image folder &#8211; fire up your web browser and navigate to index.php. You should have something like the screenshot below:<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2011/01/screenshot1.jpg" alt="" title="screenshot1" width="576" height="500" class="alignnone size-full wp-image-1979" /><br />
As you can see – we’re swiftly on our way. Our thumbnails are resizing right. Once clicked, the larger image appears. Though there are mysterious images that are returning empty (<em>file name is shows as “.” and “..”</em>). This may not be the case with yours &#8211; but with me, I just decided to fix this by wrapping our list items inside an ‘if &#8211; else’ statement:<br />
<script src="https://gist.github.com/michaelsoriano/b4058033e75c0fbc260a.js"></script><br />
Now we move on to the Fancy Box script:</p>
<h3>Add Fancy Box</h3>
<p>I almost always use jQuery for all my projects. It is one of the most versatile and powerful javascript libraries to date. Download the latest version from <a href=" http://jquery.com/ "> http://jquery.com/ </a> and include it in your document.<br />
Download the Fancybox files from <a href="http://fancybox.net/">http://fancybox.net/</a>. Once again, include the script right under the jQuery one. Note that Fancy box comes with its own image folder and css file. You need to include that css as well:<br />
Now let’s add a “<strong>rel</strong>” attribute to our anchor tag, with a value of “<strong>lightbox</strong>”. This makes it easier for our script to target which elements to add an effect on.<br />
Finally, create a new script tag and add our line of code:<br />
<script src="https://gist.github.com/michaelsoriano/64a2dcb02f55f6f6e1c5.js"></script><br />
The above code states that when the document is ready – grab all the anchor tags with an attribute value of “lightbox” and hook it up with the fancybox function. I’ve chosen the effect  ‘Elastic’  for the transitions – you can replace this with your own liking.<br />
Now go back to the browser and hit F5 to refresh. Click on a thumbnail – you should see Fancy Box in action with smooth and eye popping animation added to your photo gallery.<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2011/01/screenshot2.jpg" alt="" title="screenshot2" width="576" height="500" class="alignnone size-full wp-image-1980" /><br />
Next up – some styling with <strong>CSS</strong>.</p>
<h3>Pretty &#8216;er up.</h3>
<p>Now it is always good practice to separate your formatting and markup. Create a new file named <strong>style.css</strong>, go back to index.php and link the stylesheet we just created.<br />
In the last screenshot you notice that I marked the little buttons. That’s because of two things – if you’ve configured Fancybox correctly – those icons should be visible. The other thing is, I’ve created an icon that is very identical to those of Fancybox’s – and we’ll include in our thumbnails.  Take a look at the couple of images below:<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2011/01/screenshot3.jpg" alt="" title="screenshot3" width="576" height="127" class="alignnone size-full wp-image-1981" /><br />
These images (available in the download) I’ve saved inside the root folder. In your style.css – add these lines of code:<br />
<script src="https://gist.github.com/michaelsoriano/c20a35ee70d4d3ae712f.js"></script><br />
The code above adds a nice texture to our gallery background. Next, it floats each item to the left – aligning them all side by side. Then it adds a nice white background to each image, along with proper paddings and margins:<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2011/01/screenshot4.jpg" alt="" title="screenshot4" width="576" height="250" class="alignnone size-full wp-image-1982" /><br />
Remember our custom script tag just above our closing head tag? – add, this line of code just in between the <strong>$(document).ready()</strong> function:<br />
<script src="https://gist.github.com/michaelsoriano/a2e82a37d43a3cc2cebb.js"></script><br />
This will insert an empty span tag inside each of our list items (this is for the small magnifying glass icon). If you’re thinking – why not just add an inline span tag in our “for each” loop inside index.php – that’s an excellent question. This is because for users  without javascript enabled – they won’t see this magnifying button.<br />
Add these lines of code inside our style.css:<br />
<script src="https://gist.github.com/michaelsoriano/237981be4ce6ae4a0818.js"></script><br />
The above styles adds the subtle details that will make our thumbnails beautiful. This includes – of course our magnify.png, CSS3 box shadows (box-shadow) and rounded corners (border-radius).<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2011/01/screenshot5.jpg" alt="" title="screenshot5" width="576" height="250" class="alignnone size-full wp-image-1983" /><br />
Our gallery looks really good so far, but not good enough. Let’s add some embellishments.</p>
<h3>Randomize the Images and Orientation:</h3>
<p>Let’s make the thumbnail images be mixed orientation – some tall and some wide. Remember our thumbnail dimensions declared right after the timthumb script? All we need to do is switch the height and width values. So let’s create a PHP function. Append this code on top of index.php (right before the <strong>html</strong> tag):<br />
<script src="https://gist.github.com/michaelsoriano/c6945c58624acfd74bd0.js"></script><br />
The code above randomizes the two strings (‘<strong>&#038;h=194&#038;w=224</strong>&#8216; and &#8216;<strong>&#038;h=224&#038;w=194</strong>’). Then we call this function where our image tag is:<br />
<script src="https://gist.github.com/michaelsoriano/2c1a3e235e2ab1ebb707.js"></script><br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2011/01/screenshot6.jpg" alt="" title="screenshot6" width="576" height="350" class="alignnone size-full wp-image-1984" /><br />
Now our thumbnails have different orientation each time we refresh. But as you can see, we need to fix the float – some thumbnails get stuck where portrait ends. We also need to fix the magnify icon positioning.<br />
We need a way to tell what the current thumbnail orientation is, and somehow apply a class to that specific list item. This way we can fix the padding and margins accordingly. Add this line of code inside our “else” statement:<br />
<script src="https://gist.github.com/michaelsoriano/dca21d8d1fcc5fd8cf62.js"></script><br />
This grabs the current orientation and assigns it to a variable. Now, inside our li tag – paste this line of code:<br />
<script src="https://gist.github.com/michaelsoriano/840e8d274126f9c9a0b7.js"></script><br />
This adds a class name of “tall” for each list item – if the $current_o variable equals to the portrait dimension. We also need to replace our image thumbnail script to this new code:<br />
<script src="https://gist.github.com/michaelsoriano/ba0a75b34026a75a7a9e.js"></script><br />
Refresh your browser and if we inspect our code – you should see list items with a class of “tall” for images that have 224 x 194 dimensions:<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2011/01/screenshot7.jpg" alt="" title="screenshot7" width="576" height="200" class="alignnone size-full wp-image-1985" /><br />
Also, add these lines of code to our style.css file:<br />
<script src="https://gist.github.com/michaelsoriano/267bea0ce089711febbf.js"></script><br />
The above code overrides the default styling for the list items.<br />
Note that you also have to delete some previous styling for our list items (see the comments in the download). If you’re following this tutorial – I apologize for the replacements. As you see, I’m developing this as I go.<br />
Lastly, add this code inside index.php:<br />
<script src="https://gist.github.com/michaelsoriano/9f60bc3e00804428271f.js"></script><br />
This will randomize the images. So now we’ve fixed the list items, magnify icon – as well as randomized the images:<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2011/01/screenshot8.jpg" alt="" title="screenshot8" width="576" height="350" class="alignnone size-full wp-image-1986" /></p>
<h3>Final Touches:</h3>
<p>So our gallery is so done. Except I like to add those final details that make it really good. Let’s add a pre-loader image. This is when you see a “<strong>loading</strong>” message for each thumbnail before they appear. To do this, we go back to jQuery. Inside our document ready event, add this line of code:<br />
<script src="https://gist.github.com/michaelsoriano/a7bc92bbcfabd8d8ce24.js"></script><br />
The above code delays our images just a tad bit &#8211; just enough to see a preloader image. Save your “<strong>loading.png</strong>” image in the root directory. In your styles.css, add these lines of code:<br />
<script src="https://gist.github.com/michaelsoriano/70c66b7d23c96635913f.js"></script><br />
This just sets a background image to our list items. So next time you load the page – you should see our preloaders:<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2011/01/screenshot9.jpg" alt="" title="screenshot9" width="576" height="197" class="alignnone size-full wp-image-1987" /><br />
Finally, download the fancy box <strong>mousewheel.js</strong> pack inside your scripts folder and include it in your document. You should now be able to view next and previous images once you scroll your mouse wheel.</p>
<h3>Conclusion:</h3>
<p>Well now, I think our gallery is ready for prime time. The good thing about this is you never have to re-size a thumbnail again. All you need to do is add the large image inside the &#8220;images&#8221; folder and presto! Another good thing is that your gallery doesn&#8217;t look the same all the time. With our randomized order and orientation, the gallery looks fresh at each refresh. <strong>So go ahead and grab the <a href="https://app.box.com/s/wtuwv6xn2bwvbezrmvou">download</a> files</strong>. Play around with it &#8211; and maybe even improve the code. Be sure to include your comments below:</p>
<p>The post <a href="https://michaelsoriano.com/create-an-awesome-photo-gallery-with-fancybox-and-timthumb/">Create an Awesome Photo Gallery with FancyBox and TimThumb</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/create-an-awesome-photo-gallery-with-fancybox-and-timthumb/feed/</wfw:commentRss>
			<slash:comments>64</slash:comments>
		
		
			</item>
		<item>
		<title>Yet Another jQuery Accordion Tutorial</title>
		<link>https://michaelsoriano.com/yet-another-jquery-accordion-tutorial/</link>
					<comments>https://michaelsoriano.com/yet-another-jquery-accordion-tutorial/#comments</comments>
		
		<dc:creator><![CDATA[Michael Soriano]]></dc:creator>
		<pubDate>Sat, 06 Nov 2010 20:22:15 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<guid isPermaLink="false">http://fearlessflyer.com/?p=1905</guid>

					<description><![CDATA[<p>It just about that time some good old fashioned web programming. Today we’re learning how to create an accordion style page – using my most favorite of tools: jQuery and CSS. We will try to accomplish an accordion that is so simple, yet useful enough for you to use in your existing pages. Ready to [&#8230;]</p>
<p>The post <a href="https://michaelsoriano.com/yet-another-jquery-accordion-tutorial/">Yet Another jQuery Accordion Tutorial</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>It just about that time some good old fashioned web programming. Today we’re learning how to create an accordion style page – using my most favorite of tools: jQuery and CSS. We will try to accomplish an accordion that is so simple, yet useful enough for you to use in your existing pages. Ready to get started – let’s begin.</p>
<h3>The Goal:</h3>
<p>We will use clean markup. We’re trying to integrate this into exsting HTML – so we will be generating all extra classes and tags using Javascript.  I imagine most web documents follow the same constant pattern: Heading tags, followed by some content which are a mixture of different DIVS, paragraphs, images etc. This goes on until the next heading tag &#8211; which is usually the same type as the first heading.<br />
Look at the sample mark up below:<br />
<script src="https://gist.github.com/michaelsoriano/b0f9d265439f8ce8334f.js"></script><br />
We will use the H5 tags as our “<strong>Clicker</strong>” – once clicked, will hide the contents right underneath it. Click it again, and it will show the contents again.</p>
<h3>The Script:</h3>
<p>We start by calling the jQuery library, followed by the document.ready() call:<br />
<script src="https://gist.github.com/michaelsoriano/c7cf359bbc62e8174c13.js"></script><br />
We then loop through each of our particular heading tag (in this case, all of H5).  Once it finds all of them, it checks to see if right next to it is another H5 tag; if it’s not, it adds a class of “<strong>clicker</strong>” to it and appends a span with a minus (-) sign in it:<br />
<script src="https://gist.github.com/michaelsoriano/c3eaa9b52de43e76b1eb.js"></script><br />
If you investigate your code so far – you will see that only the H5 tags that have content OTHER than H5 tags have the class “<strong>clicker</strong>” and the span tag with a minus (-) sign in it:<br />
<img decoding="async" src="https://michaelsoriano.com/wp-content/uploads/2010/11/accordion1.jpg" alt="" title="accordion1" width="576" height="298" class="alignnone size-full wp-image-1906" /><br />
Now let’s code the click events:<br />
<script src="https://gist.github.com/michaelsoriano/c338f51121538da16ee9.js"></script><br />
Now that we have our designated clickers, we create a couple of functions that toggle at every click.<br />
The first action, hides the contents below &#8220;<strong>$(this)</strong>&#8221; – which is the tag you just clicked. Remember &#8211; we only want to hide the contents up until the next H5 tag. It also changes the content of the span into a plus (+) symbol.<br />
The second action shows the contents below, and changes the span to a minus (-) symbol.</p>
<h3>Optional Styling:</h3>
<p>At this point you already have a functional accordion. If you’re applying the code to an existing page, you are already working with the current styles.  Although, using CSS3 for say the plus (+) and minus (-) span looks pretty cool – which I’m sure you’d want to use.<br />
Add this code to your styles:<br />
<script src="https://gist.github.com/michaelsoriano/9857fdda4cf7836fd255.js"></script><br />
Of course you have to replace the #wrap h5 with your own class / ids. This creates the css3 button you see in the demo. This code is courtesy of <a href="http://www.zurb.com/article/266/super-awesome-buttons-with-css3-and-rgba"> Zurb’s Super Awesome buttons with CSS3 and RGBA:</a></p>
<h3>Conclusion</h3>
<p>And that is it! You have yourself an accordion page powered by jQuery.  Feel free to grab this code and improve it. Maybe refactor it into a more plugin like code – make it more reusable. Or even &#8211; fix the choppiness issue in the slideUp / slideDown animation in certain browsers. In any case, please leave a comment on what you think of this code.<br />
You might also be interested in these articles regarding jQuery accordions:</p>
<ul>
<li><a href="http://www.sohtanaka.com/web-design/simple-accordion-w-css-and-jquery/">Simple Accordion w/ CSS and jQuery</a></li>
<li><a href="http://net.tutsplus.com/tutorials/javascript-ajax/exactly-how-to-create-a-custom-jquery-accordion/">Exactly How to Create a Custom jQuery Accordion </a></li>
<li><a href="http://css-tricks.com/grid-accordion-with-jquery/">Grid Accordion with jQuery</a></li>
</ul>
<div class="special">There are no downloads for this tutorial because it&#8217;s pretty simple to follow. I also had to disable the demo &#8211; for housekeeping purposes.</div>
<p>The post <a href="https://michaelsoriano.com/yet-another-jquery-accordion-tutorial/">Yet Another jQuery Accordion Tutorial</a> appeared first on <a href="https://michaelsoriano.com">Michael Soriano</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://michaelsoriano.com/yet-another-jquery-accordion-tutorial/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
			</item>
	</channel>
</rss>
