Introducing ESV Plugin 3.9.0

Just posted a new version of my ESV Plugin. This new version includes a mix of bug fixes and new features. The big news on the bug fix side is that matching has been further tweaked, correcting all known issues with reference matching.

For new features, the ESV Plugin can now recognize ‘chapter’ and ‘verse’ as references if they follow a passage that has already been recognized. So, for instance, putting verse 1 here will do nothing since no previous reference has been noticed. But if I mention John 3 then address verses 16-18, ESV Plugin will pick up the verses as coming from John 3. The same works for chapters: now that my context is the book of John, I can mention chapter 1 and it gets tagged as John 1.

Learn more about the ESV Plugin at its plugin page or download it from the WordPress repository.

New home

After major performance issues with my previous host, I have finally jumped ship and am in the process of moving everything to a Bluehost Pro account. I had been with Dreamhost for nearly 10 years, but problems were only getting worse and recent changes on their end were going to increase the problems. So far, things look good with Bluehost. Hopefully performance will be a lot better on the new host.

croberts.me Goes Responsive

It has not been long since I made my last major revision to the croberts.me theme yet I’ve just recently made more. While not as comprehensive as the last round of changes, the new modifications make this a responsive site. Prior to this, I had not made use of media queries or proportional layouts and I decided it was past time to give them a go. Resize the width to see how things snap around. View it in your phone or tablet device and see what you think. I’m still making some tweaks and I have a few other responsive adjustments planned, but so far I’m pleased with the results.

The main content area now (potentially) has more room while less essential elements snap to different locations at different screen sizes. I was not able to completely avoid hiding elements (the top social links and search bar are hidden below a certain size; the right sidebar also gets hidden when the layout goes single column) but was able to make use of snapping some elements around. I’m particularly proud of the top nav menu which uses a modified version of Mensy to display differently depending on screen width.

Other changes include using rgba for the wrapper background color, placing the gears behind that wrapper but making them visible by adding a slight transparency to the background. I’m also playing with font-face using Google Web Fonts but results are mixed so that’s one thing I’m still tweaking. I’ve used various css3 rules for some time now, but this site marks my heaviest use yet. I have also switched to an html5 doctype, though I haven’t yet incorporated html5 tags.

Since this is my first responsive layout, and since it was an update of an existing theme rather than something built responsive from the ground up, I’m sure there are places where I could have done it better. Going forward, I hope to improve the code for this site as well as add responsive options to my plugins.

Tippy 5.0.0 is Out!

I’ve just posted the latest version of Tippy: 5.0.0. For some time now I have intended to come along and write a thorough api documenting direct usage of the javascript object, the php functions, and the various shortcode attributes. That’s all still on my to-do list. But what I have done is updated Tippy to another great version.

Tippy 5.0.0 features:

  • tippy.php is now object-oriented. This has been on my to-do for a while; all major plugin functions are now wrapped in the Tippy class. I have left a few functions outside the class as helpers and for backwards-compatibility.
  • Tooltips have a new draggable option. This cannot yet be set on a per-tooltip basis, but you can globally specify whether or not to allow tooltips to be drug around, and if dragging should only occur when the user click-drags the header.
  • Renamed dom_tooltip.css and dom_tooltip.js to tippy.css/.js to help standardize naming.
  • Also renamed classes, ie, domTip_tipHeader is now .tippy_header. All elements still retain the original class name, the new names are additions. You won’t have to rework any existing styling, but this should make things more straightforward going forward.
  • Modified the default styling. I did this with some trepidation because Tippy now sets fewer options by default, relying on global theme styling. This could be a good thing, making the tooltip fit in to the site’s theme better, or it could be a problem for sites which don’t have universal styling for links and such (like mine until I get around to updating that). Let me know what you think.
  • Fixed an issue with the close link text not displaying when the tooltip didn’t have a header.
  • A few other tweaks and improvements throughout.

That’s about it! As always, get more info from the Tippy page. And one of these days I will finally put together a complete reference.

Howto: Rotating gears when user scrolls

If you have spent any time on this site, you have likely noticed the gears on the left side that rotate as you scroll through the site. This effect is produced through a combination of JavaScript and CSS3, in particular the css3 transform rule.

The code is fairly straightforward. Using jQuery, scroll events are captured and trigger the function that rotates the gears. I’ll walk through the various parts and the whole thing is at the bottom of this post via jsFiddle.

First, the initial css. I have something like this in my site’s main stylesheet:

#container {
    width: 200px;
    margin: 20px auto;
    padding: 20px;
    border: 1px dotted #ccc;
    background-color: #fff;
    
    position: relative;
}

/* Gears */
#gears {
    position: fixed;
    display: none;
}

.gear_md {
    position: absolute;
    
    width: 145px;
    height: 145px;
}

#gear1 {
    top: 50px;
    left: -203px;
}

#gear2 {
    top: 50px;
    left: -64px;
}

#gear3 {
    top: 173px;
    left: -269px;
}

Notice that the #container element has position set to relative while #gears is position: fixed. As we will see in a moment, #container and #gears are adjacent divs. Setting #container to position: relative; pulls it above its sibling so that the gears appear to be behind the container. #gears starts as display: none; jQuery will make it visible.

#gears position is fixed but no position is set in css. jQuery will track the position of the container element and set the left position for #gears. The reason all three gears have negative left edges is the left edge of #gears lines up with the left edge of #container, so the gears have to be pulled out to the left to make them visible.

.gear_md is the class for the medium sized gear. It sets position: absolute; for all gears, allowing them to be positioned within the #gears div. The positioning of the three gears is up to you; I like the way this looks, you can adjust to taste. It is easy to add or remove as many gears as you like, just add additional rules from more gears in css, add another gear in the html, and duplicate a gear in JavaScript.

I have extra styling on #container; this is just to make it obvious while testing. The only rule really needed for #container is position: relative;

Now let’s see the html:

<div id="gears">
    <img class="gear_md" id="gear1" src="http://croberts.me/wp-content/themes/croberts/images/gear.png" />
    
    <img class="gear_md" id="gear2" src="http://croberts.me/wp-content/themes/croberts/images/gear.png" />
    
    <img class="gear_md" id="gear3" src="http://croberts.me/wp-content/themes/croberts/images/gear.png" />
</div><!-- #gears -->

<div id="container">
    <div id="content">
        Add your content here. For testing, this needs to be enough to allow vertical scrolling.
    </div><!-- #content -->
</div><!-- #container -->

Easy peasy, nothing fancy about the html. Make sure each of your gears uses the gear class and has a distinct id.

The image I created for my gears, gear.png, is a little larger than I wanted so reduced them via css. I should have just created smaller versions, but I kept it large so I could create a chain of large and small gears, if desired. Feel free to download and use it, but please load it in your own server, not from mine.

Now the JavaScript. This is where the magic happens.

// Control the spinning gears
$(document).ready(function() {
    // Get the container position
    var containerPos = $('#container').offset();
    
    // Get the initial scroll position. This will be needed later when determining
    // if we are scrolling up or down.
    var scrollPos = $(window).scrollTop();
    var degreeRotate = 0;
    
    // We will use these to track how much we are rotating our gears. Need to track
    // the gears separately since they will not be going the same direction
    var gear1Rotate = 0;
    var gear2Rotate = 0;
    var gear3Rotate = 0;
    
    $('#gears').css('display', 'block');
    $('#gears').css('left', containerPos.left + "px");
    browser_transform('#gear2', 11);
    browser_transform('#gear3', 90);
    
    $(document).scroll(function() {
        // Are we moving up or down?
        var newScroll = $(window).scrollTop();
        
        if (scrollPos > newScroll) {
            degreeRotate -= 5;
        } else {
            degreeRotate += 5;
        }
        
        // Calculate rotations. These will be slightly different for each gear, even
        // for the ones spinning the same direction, in order to line up the teeth of
        // the gears.
        gear1Rotate = degreeRotate;
        gear2Rotate = ((degreeRotate + 11) * -1);
        gear3Rotate = ((degreeRotate + 90) * -1);
        
        // Store the current scroll for comparison next scroll event.
        scrollPos = newScroll;
        
        browser_transform('#gear1', gear1Rotate);
        browser_transform('#gear2', gear2Rotate);
        browser_transform('#gear3', gear3Rotate);
    });
});

// Handle automatic output of multiple vendor tags for css3 transforms
function browser_transform(transTarget, transValue)
{
    $(transTarget).css('-ms-transform', 'rotate(' + transValue + 'deg)');
    $(transTarget).css('-moz-transform', 'rotate(' + transValue + 'deg)');
    $(transTarget).css('-webkit-transform', 'rotate(' + transValue + 'deg)');
    $(transTarget).css('-o-transform', 'rotate(' + transValue + 'deg)');
    $(transTarget).css('transform', 'rotate(' + transValue + 'deg)');
}

Comments in the code should explain most of what is happening.

When the dom is ready, jQuery(document).ready() gets called, triggering the initial code. The #container position is retrieved and #gears is positioned underneath it and is made visible. Default values are set for the gear rotations.

Because we are trying to make it look like the gears are turning each other, gear teeth need to line up. Before any scrolling takes place, two of the gears are rotated so that their teeth fit into the grooves of the adjacent gears:

browser_transform('#gear2', 11);
browser_transform('#gear3', 90);

The script then registers the scroll event. Every time the user scrolls, the script compares the current scroll position with the previous scroll position. If our position is greater, we are scrolling down. If less, we are scrolling up. The gears rotate in opposite directions to the user scroll.

I have my gears rotate 5 degrees at a time. Keep in mind that a complete rotation is 360 degrees. 5 degrees may seem small, but it moves this much every single time the user scrolls. The gears are rotated by the same amount, so the variable degreeRotate gets applied to all three with variations to account for lining up gear teeth and grooves:

gear1Rotate = degreeRotate;
gear2Rotate = ((degreeRotate + 11) * -1);
gear3Rotate = ((degreeRotate + 90) * -1);

Notice the two gears that are multiplied by -1, this is because the two side gears rotate opposite the direction of the center gear.

With rotation amounts calculated, a helper function is called:

browser_transform('#gear1', gear1Rotate);

Since the css3 transform rule is not yet fully supported, vendor prefixes should be added so the rotations work in a cross-section of browsers. This function does the trick:

function browser_transform(transTarget, transValue)
{
    $(transTarget).css('-ms-transform', 'rotate(' + transValue + 'deg)');
    $(transTarget).css('-moz-transform', 'rotate(' + transValue + 'deg)');
    $(transTarget).css('-webkit-transform', 'rotate(' + transValue + 'deg)');
    $(transTarget).css('-o-transform', 'rotate(' + transValue + 'deg)');
    $(transTarget).css('transform', 'rotate(' + transValue + 'deg)');
}

Pass in the element to be rotated and how much rotation should be applied and the script (via jQuery) ensures the various vendor prefixes are applied.

There you have it, gears that rotate while scrolling through a document. Now see the whole thing via jsFiddle:

New features in Tippy 4.2.0

The latest version of Tippy adds three new shortcode attributes:

  • delay="numeric duration in milliseconds" ie delay="900"
  • autoclose="true/false"
  • swaptitle="alternate title"

To increase or decrease the amount of time a specific tooltip stays visible, specify the delay. The default value is 900. Increase the delay to make the tooltip visible longer. Decrease to make it go away fast. Here is a fast example. And here is a slow example.

Autoclose allows you to override your default sticky setting. If you have set Tippy to auto close tooltips when the visitor mouses away from the link, but you want one tooltip to remain even if they mouse away, set autoclose=”false”; set it to true to autoclose tooltips if your global setting makes tooltips sticky.

Swaptitle provides an alternate title to display when a visitor hovers over a tippy link. Keep in mind that changing text will usually cause the paragraph to reflow, as it does in this example.

Learn more about Tippy at the Tippy page.

Glossy and displaying definitions inline

I’ve just posted Glossy 1.3.0. The new version adds a feature which allows you to specify if definitions should appear inline or in tooltips. If you are not familiar with Glossy, it makes it easy to define terms that can be used throughout your site. Want to provide a definition for the New York Stock Exchange that can be shown anywhere on your site? Just define the term in your WordPress dashboard and display it in your post with a simple shortcode: New York Stock Exchange.

Originally, Glossy only showed definitions in tooltips via Tippy. The new version makes it possible to display definitions inline with your text. I am a fan of the sci-fi author Alastair Reynolds. If I want to provide a little info every time I mention him, I could do so with Glossy showing in a tooltip: Alastair Reynolds. But perhaps I’m writing a little more about sci-fi writers and I want to include my definition in the body of a post. I can do so with the new inline option: Alastair Reynolds is one of today's finest authors of hard sci-fi. House of Suns is one of his best. Using this approach provides greater flexibility to showing your terms throughout your site.

Learn more at the Glossy page.

Introducing the Multi-Slider plugin for WordPress

I am pleased to announce my seventh WordPress plugin: Multi Slider. This plugin makes it easy to create and display a variety of sliders on any WordPress site. It can handle sliding images or text (any text/html markup), provides a variety of transitions, adds very basic click tracking for image sliders, and makes it easy to create as many sliders as you like for your website. Want to have one rotating graphic for you homepage header, another small one for the sidebar, a final one in the footer? Create them easily with Multi Slider and add all the slides you desire.

Once a slider is defined and slides are added, there are three ways to add them to your site: through the mslider_show_slide() function, the mslider shortcode, or through theme widgets. The functions make it easy to drag/drop the slider to any widget container, while the function allows you to code the slider into your site and the shortcode lets you add sliders to any post. For example, enjoy these quotes from astronauts:

To look out at this kind of creation out here and not believe in God is to me impossible, … It just strengthens my faith. I wish there were words to describe what it’s like.

- John Glenn

Problems look mighty small from 150 miles up.

- Roger Chaffee

Beautiful, beautiful. Magnificent desolation.

- Buzz Aldrin

It suddenly struck me that that tiny pea, pretty and blue, was the Earth. I put up my thumb and shut one eye, and my thumb blotted out the planet Earth. I didn’t feel like a giant. I felt very, very small.

- Neil Armstrong

Mystery creates wonder and wonder is the basis of man’s desire to understand.

- Neil Armstrong

This is one small step for a man, one giant leap for mankind.

- Neil Armstrong

The good lord only gave men so many hormones, and if others want to waste theirs growing hair that’s up to them

- John Glenn

The above was generated via shortcode:

[mslider slug=”space-quotes”]

If I wanted to display that in my theme directly, I would have put the following in a theme file:

mslider_show_slide(‘space-quotes’);

Multi slider isn’t just for text:

GPN-2000-001870
GPN-2000-001091

Download Multi Slider through your dashboard or via WordPress. Learn more on the Multi Slider page.

Tippy 4.1.0 and the new approach to images

People often ask how to use Tippy with an image. My normal approach is to point to a post I wrote a while back which lays out a straightforward but not necessarily easy approach, requiring users to hardcode the Tippy JavaScript onto their images. No more.

With Tippy 4.1.0, using Tippy on an image is as easy as specifying another attribute. If you want Tippy to trigger on an image rather than a text link, just set img to your image url. If you specify a title, that gets used for the image alt text. If you specify a class, that class is set on the image with _img appended, allowing you to style specific images. For example:

[tippy title="This is at the zoo" class="myGiraffe" img="http://www.croberts.me/wp-content/uploads/2011/05/giraffe.jpg"]Just something to demonstrate how to trigger Tippy on an image.[/tippy]

This produces:
This is at the zoo

Tippy 4.1.0 adds one additional new feature: the headertext attribute. Previously, the Tippy link and header both displayed whatever you specify for the title. Now, if you want the header to display something different than the title, use headertext. For example:

[tippy title="mouse over me" headertext="See? I'm different!"]This is my nifty tooltip.[/tippy]

This gets you: mouse over me.

Head on over to the Tippy page for more info about this nifty plugin.

Announcing Tippy 4.0.0

Hot off the coding window, Tippy 4.0.0 should be showing up in your Dashboard updates soon. This version adds and enhances several requested features. For instance:

  • Ability to specify per-tooltip offset. Use the offsetx=”" and offsety=”" to specify the desired offset for your tooltip. As with the dashboard setting, it should be a simple integer pixel value, though without putting px at the end. For example, offsetx=”200″ offsety=”100″ would move the tooltip 200px to the right and 100px down, as here.
  • Ability to specify per-tooltip class and id values that get set on both the Tippy link and the tooltip itself. In the shortcode, set class=”" or id=”" to your desired values and those get set on the link. The tooltip gets the same value with _tip appended. For example, setting id=”myNiftyTip” will put that id on the Tippy link and myNiftyTip_tip on the tooltip itself. This makes it easy to manually style specific tooltips or groups of tooltips.
  • Various improvements to both the php and javascript functions to make it easier for developers to use them. Look for more specific documentation on these soon.

Look for Tippy 4.1.0 to come out within the next few days with a few additional features, such as the ability to specify the header text separate from the link text and to give the tooltip header a different href from the tippy link. I also plan to include additional styling options in the Dashboard Tippy settings.

Enjoy! Please post any questions, comments, suggestions, etc, and if you love Tippy, don’t forget to make a large cash donation using the Donate link on found on the sidebar!

More information on Tippy can be found on the Tippy page.