HTML5 Boilerplate

Scratch is built on the HTML5 Boilerplate. Here are the Javascript features that Scratch utilizes in full:

  • HTML5 ready. Use the new elements with confidence.
  • Designed with progressive enhancement in mind.
  • Includes:
    • jQuery via CDN, with a local fallback
    • A custom build of Modernizr for feature detection
  • An optimized version of the Google Universal Analytics snippet.
  • Protection against any stray console statements causing JavaScript errors in older browsers.
  • Extensive inline and accompanying documentation.

Modals via Magnific Popup

Scratch is bundled with Magnific Popup for the best responsive modals in the biz. main.js includes several helper functions to make modal usage trivial.

This is what it would look like if you added the image via the WordPress content editor, and then added the class .image-link to its parent link in the advanced options. See Inserting Images into Posts and Pages.

Basically all you need is an <a> tag with an href of the image source and a class of .image-link.EXAMPLE

Click to view larger image.

The code is generated automatically, but it should look like this:

<div id="attachment_112" style="width: 310px" class="wp-caption aligncenter">
  <a class="image-link" href="https://unsplash.it/600/600/?image=0">
    <img class="wp-image-112 size-medium" src="https://unsplash.it/300/200/?image=0" alt="Click to view larger image" width="300" height="200">
  </a>
  <p class="wp-caption-text">
    Click to view larger image.
  </p>
</div>

Add class .popup-link to an <a> tag with an href that matches the target popup’s id.EXAMPLE

<p>
  <a href="#popup" class="button popup-link">Click</a>
</p>

Add class .iframe-link to an <a> tag with an href that is a YouTube or Vimeo video URL.EXAMPLE

<p>
  <a href="https://www.youtube.com/watch?v=ndnjBq8ROpo" class="button iframe-link">Click</a>
</p>

Use Magnific Popup Directly

Check out the Magnific Popup API if you need something more custom than what Scratch comes with.


jQuery Waypoints

Scratch comes with jQuery Waypoints. Scratch does not use this library by default, but it’s a great utility, especially for sticky navs. This documentation page uses Waypoints to set its sticky nav:

jQuery(document).ready(function($) {
  if (!Modernizr.touch) {
    $('#docs-main').waypoint(function(dir) {
      if (dir === 'down') {
        $('#docs-nav').addClass('fixed').css('width', $('#sidebar').width());
      } else {
        $('#docs-nav').removeClass('fixed').css('width', 'auto');
      }
    });
  }
});

Animations with Velocity.js

Scratch comes with Velocity.js, a JavaScript library for highly performant animations. main.js includes snippets for smooth “scroll-to” links and accordions, or “toggles” as we call them.

EXAMPLE

Scroll here.

<p>
  <a href="#scroll-here" class="button scroll-link">Click</a>
</p>
<div id="scroll-here" class="scratch-bg gray-bg">
  <div class="valign-always center">
    Scroll here.
  </div>
</div>

Toggles

EXAMPLE

Toggle Heading 1
Toggle Heading 2
Toggle Heading 3
<h5 class="toggle-heading"
    data-direction="down">
  Toggle Heading 1
</h5>
<div class="toggle-content">
  <p>Toggle content 1.</p>
</div>
<h5 class="toggle-heading"
    data-direction="down">
  Toggle Heading 2
</h5>
<div class="toggle-content">
  <p>Toggle content 2.</p>
</div>
<h5 class="toggle-heading"
    data-direction="down">
  Toggle Heading 3
</h5>
<div class="toggle-content">
  <p>Toggle content 3.</p>
</div>

Use Velocity.js Directly

Never use jQuery’s $.animate() and $.fade() functions. They slow everything else down, including other animation libraries. Always use Velocity’s built-in solutions instead of rolling your own (or relying on jQuery): looping, reversing, delaying, hiding/showing elements, property math (+, -, *, /), and hardware acceleration can all be done within Velocity.

Example usage:

jQuery(document).ready(function($) {
  $element.velocity("fadeIn", {
    duration: 1500
  }).velocity("fadeOut", {
    delay: 500,
    duration: 1500
  });
});

Check out Velocity’s excellent documentation for more info.


Sliders via Glide.js

Scratch includes Glide.js, a simple, responsive, and fast slider. Use a slider in your project:EXAMPLE

<div id="Glide" class="glide">

  <div class="glide__arrows">
    <button class="glide__arrow prev" data-glide-dir="<">
      <i class="ion-chevron-left"></i>
    </button>
    <button class="glide__arrow next" data-glide-dir=">">
      <i class="ion-chevron-right"></i>
    </button>
  </div>

  <div class="glide__wrapper">
    <ul class="glide__track">
      <li class="glide__slide"
          style="background-image: url('https://unsplash.it/1800/1200?image=1');">
      </li>
      <li class="glide__slide"
          style="background-image: url('https://unsplash.it/1800/1200?image=2');">
      </li>
      <li class="glide__slide"
          style="background-image: url('https://unsplash.it/1800/1200?image=3');">
      </li>
    </ul>
  </div>

  <div class="glide__bullets"></div>

</div>

Armed with the knowledge of Glide.js’s options, control the slider’s configuration in main.js:

jQuery(document).ready(function($) {
  $('.glide').glide({
    autoplay: false
  });
});

Using MAMP to Complete the WordPress Installation

Open the MAMP start page, and then head over to phpMyAdmin. Click on the Users tab, then scroll down and click Add User. Create a memorable username, strong password, and set the host to localhost. Check Create database with same name and grant all privileges, then click Go.

Now, navigate to the host you configured in MAMP. Complete the WordPress installation and log in. (You won’t need to do this specific part if you ran wp core install.)

Once logged in to WordPress, navigate to Appearance > Themes and activate Scratch. Follow the subsequent prompts to install the recommended plugins. If you want, delete Akismet and Hello Dolly.

Running Grunt, BrowserSync, and Compiling SCSS and JavaScript

Run npm install in the assets/grunt/ directory from your command line to install all of the Node packages. Make sure to change your proxied host for BrowserSync. Once that’s done, you can run grunt from the same directory to begin your automated workflow.

Update: as of v1.5.9, Gulp is also available. Run npm install and then gulp in the assets/gulp/ directory.

Adding Scratch’s Style Guide and Main Navigation Menu

Navigate to Appearance > Menus and click Create Menu. Make sure the menu points to the Main Nav location, and then save it again. Next, go to Pages > Add New and set the Page Template to Style Guide. Publish and view the page.

Update: as of v1.6.8, the pages and navigation menu are automatically generated on theme activation.

Implementing Your Own Typography with Scratch

This example uses Google Fonts and sets them to SCSS variables in config/_variables.scss.

Implementing Your Own Color Scheme with Scratch

Edit config/_variables.scss and page-style_guide.php.

Basically, root/ contains files that should be moved to the root of your site if you desire to use the configuration that comes with HTML5 Boilerplate.

Navigate to Settings > Permalinks, and change the Permalink Structure to Post Name for cleaner, SEO-friendly URLs.

Congratulations!

High fives, you’re all finished! If you’re having trouble, feel free to submit an issue on GitHub.