# sIFR Documentation and FAQ
How to use

Here you'll find how to use sIFR on your website. If you are wondering about interacting with the JavaScript, please see Javascript Implementation.

## Designing your site

Design your site as normal, and make sure your headlines are styled with CSS. Users who do not have the Flash player or have Javascript disabled will see these CSS-styled headlines, so it is important to get things looking the way you want before beginning to add sIFR.

### What you should use sIFR for

sIFR is intended for headlines. While it is possible to use sIFR to replace other elements, such as paragraphs or list items, this is not recommended. Please also be careful with replacing links: browsers treat links in Flash movies differently than normal HTML links, so you may hurt usability if you use sIFR to replace links.

## Exporting the Flash file

The second step is to export the Flash (.swf) file that will generate your new typeface.

To begin with, ensure that both the `customize_me.as` (see Protecting Commercial Fonts) and `dont_customize_me.as` files are in the same folder as the `sifr.fla` file. You do not need to upload any of these three files to your server, but they must all be in the same folder when you export your `.swf` file.

To export your new typeface, open the `sifr.fla` file which is included with the download, and double-click the invisible textbox in the middle of the stage. If the "Properties" palette is not already visible, open it by selecting "Window > Properties", and select which font you'd like to use from the drop down menu. If you select a TrueType font, you can also create bold and italic styles for your font by clicking on the "I" or "B" buttons.

To export the new file, choose "File > Export" and save as `fontname.swf`

The standard `sifr.fla` file contains most of the English characters you will generally need. If you need to embed additional characters or languages, click the "Character" button and select more characters from there and re-export.

## Applying CSS print styles

Copy and paste (or even better: learn and apply) the CSS rules found in the `sIFR-print.css` file to your own print style sheet. These ensure that your original headline styling will be printed, rather than the Flash replacements.

## Applying CSS screen styles

Apply the styles in the `sIFR-screen.css` file into your own screen style sheet. These are the styles which will be applied by the Javascript if Flash is found to be present on the user's browser.

## Including the magic Javascript

You must call the `sifr.js` script on any page that will be replacing headlines. The following line in the `<head>` should do the trick:

    <script src="sifr.js" type="text/javascript"></script>

## Configuring sIFR

There are some settings you can change which alter the behaviour of sIFR. These settings are all booleans, which means they can be `true` or `false`. Here they are:

- `sIFR.bAutoInit`: Initialize sIFR on load.
- `sIFR.bFixFragIdBug`: Determines whether the Fragment Identifier Bug will be fixed or not.

- `sIFR.bIsDisabled`: Determines whether sIFR will work or not.

- `sIFR.bHideBrowserText`: Determines whether sIFR will hide the text you want to replace or not.

  By default sIFR will hide the text you want to replace while the page is loading. If you want to, you can change this behavior so sIFR will hide the text when the elements are actually replaced. To do this open `sifr.js` and add `sIFR.bHideBrowserText = false;` before `sIFR.setup();`.

  (Actually sIFR sets the sIFR-hasFlash class, and CSS rules you specify, to control the hiding of the text. What this option really does is wait before setting the class.)

An example of how you configure these settings:

    if(typeof sIFR == "function"){
        sIFR.bHideBrowserText = false;
        sIFR.bFixFragIdBug = false; // not recommended!
        sIFR.setup();
    };

If you want to enable/disable sIFR for a specific browser, you can use the UA object as described below and you'll have to edit the following code in `sifr.js`:

    if(typeof sIFR == "function" && !sIFR.UA.bIsIEMac){
        sIFR.setup();
    };

In this example sIFR is disabled for IE/Mac. Remove the `&& !sIFR.UA.bIsIEMac` part to enable it again. You can also add other browsers here.

## Adding replace statements

This step involves adding the (JavaScript) replace statements into the mix. These are the heart and soul of the script and are used to ensure the correct headlines are replaced, and in the way you want. They can be added in the `sifr.js` file, or at the end of your (X)HTML file.

If you put the replace statements in the JavaScript file, they'll be executed on onload or when you call `sIFR()`. If you put the replace statements in the body, they'll be executed immediately.

Effectively, this means that you could put the replacement code in the JavaScript and call `sIFR()` in the body. It won't make any difference.

The reason there are two methods to replace elements in sIFR is that the onload event is only fired when the page has fully loaded - including all images and other external files. This can take much longer than the actual rendering of the page, so replacing inside the body will make the replacement begin earlier, and thus sIFR looks to render faster.

To save bandwidth you can put the replace statements in the JavaScript file, and then call `sIFR()` in the body. The exact code you have to use in the body in this case is:

    <script type="text/javascript">

    if(typeof sIFR == "function"){
        sIFR();
    };
    </script>

You can find more info in Where to Replace.

## Replacement Syntax

To replace the fonts you call `sIFR.replaceElement`. This method takes the following arguments, in this specific order:

- `sSelector`: This is the CSS selector you use to select the elements you want to replace. The supported CSS selectors are `#`, `>` and `.`. Whitespace is used to select descendants. Please use whitespace only for this, so instead of `#foo > p` use `#foo>p`. You can use multiple selectors by seperating them with a comma ("`,`").
- `sFlashSrc`: location of the Flash movie. You might need to use a relative (`./movie.swf`) or absolute (`/movie.swf`) here.
- `sColor`: Text color. All colors are in hex notation (`#000000`).
- `sLinkColor`: Text color for links.
- `sHoverColor`: Color for hovered links.
- `sBgColor`: Background color.

- `nPaddingTop`, `nPaddingRight`, `nPaddingBottom`, `nPaddingLeft`: if you use padding in the elements you want to replace, you have to set the amount of padding here (in pixels, but without the `px` part).

- `sFlashVars`: extra variables you want to pass on to the Flash. These variables are seperated by `&`. You can use:

  - `textalign=center`: Center text horizontally
  - `offsetLeft=5`: Pushes text 5px to the right. Of course you can use any number here.
  - `offsetTop=5`: Pushes text 5px down.
  - `underline=true`: Adds underline to links on hover

- `sCase`: Use `upper` to transform the text to upper-case, use `lower` to transform the text to lower-case. Depending on the browser this might give problems when you want to change the casing of special characters.

- `sWmode`: Set this argument to `transparent` if you want to use a transparent background. If you want to stack elements above the Flash movies, you need to set it to `opaque`. Mozilla browsers can have some difficulty rendering Flash movies with the `wmode` set. Therefore setting this is not recommended.

  Transparency is not supported in Opera 7.x, Safari < 1.2 & Flash 6, in Linux, and in very old (pre 1.0) Mozilla versions. In these browsers sIFR will fall back to the background color instead of using transparency.

You are advised to use named arguments instead of placing the arguments in the correct order. Here's an example:

    if(typeof sIFR == "function"){
        sIFR.replaceElement("h1", named({sFlashSrc: "./vandenkeere.swf", sColor: "#000", sCase: "upper"}));
    };

Read the named arguments article for more information.

## Tuning your fonts

The final step in implementing sIFR is to "tune" your fonts. As explained in "What is sIFR" sIFR works by measuring the size of the element you are replacing, and then generating the Flash text at a size that matches it. This is a fairly straightforward process, however, when, for example, your sIFR font has a different character width or letter spacing than the font used on the website, the scaling can cause the sIFR text to look really awkward. This can be solved by changing the size of the elements just before they are replaced.

When sIFR detects the right Flash version it sets a CSS class on the `html` element. Now, let's say you are only replacing `h1`'s. If you want to create a specific style for those elements to change their sizes, you have use the following CSS rule:

    .sIFR-hasFlash h1 {
        visibility: hidden;
        /* other CSS properties go here */
    }

This is what we will call your decoy style. It will never be seen by users (because of `visibility: hidden`) but it will fine-tune the text a split-second before it is replaced.

In order to fine-tune the text you need to play around with the `font-size`, `letter-spacing`, `line-height` and `height` CSS properties.

You can use the `debug` method to prepare your page for fine-tuning. In the `sifr.js` file comment out the `sIFR.setup()` line and add `sIFR.debug()`:

    if(typeof sIFR == "function"){
        sIFR.setup();
    };

Becomes:

    if(typeof sIFR == "function"){
        // sIFR.setup();
        sIFR.debug();
    };

With sIFR in debugging mode and the decoy styles working you can start tweaking the sizes. If you can't match it exactly, make the browser text a bit narrower than the sIFR text. You will want to also comment out the `visibility: hidden;` property.

If you want to test your changes you can run the following code in the address bar:

    javascript:sIFR.debug.replaceNow();

Here's a handy bookmarklet you can use: sIFR: Replace now. Add it to your favorites and run it to see the elements being replaced.

When you're done restore the `sifr.js` file so `sIFR.setup()` is called again and enable `visibility: hidden;` again.

### Helpful tips to keep in mind while tuning your fonts:

- If you're using relative sizing for your font values in your regular CSS, the first thing you'll want to do is place pixel sizes into the font-size values of your decoy styles. This will give you a more level playing field. (Keep in mind that increasing and decreasing the pixel size in the decoy style can also change the size of your sIFR replacement text.) From there, you can begin tweaking the letter-spacing and then the line-height. This order seems to work well.

- If you've used more detailed descendant selectors in your style sheet, you'll want to change your decoy styles from this: `.sIFR-hasFlash h2` to something like `.sIFR-hasFlash #content h2` (or whatever mirrors your regular CSS selector). If you have a heading with a class on it, you can write a selector like: `.sIFR-hasFlash #content h2.separate` without a problem. Don't be afraid to get specific where you need to. If you don't do this, the values in your regular styles will override the `.sIFR-hasFlash` decoy styles for the same declarations since they will have greater specificity. For example, if you have line-height in both selectors, and you don't write a decoy style with higher specificity, the value of your regular descendant h* selector will override the decoy style and you'll be stumped as to why the decoy isn't obeying.

- If you have long headlines, watch where the line break happens in the sIFR and try to match it in the decoy if possible. This is usually done with letter-spacing.

- If you notice slight page shifting or jumping as you switch from decoy to sIFR, this can mean that one style is taking up more space vertically. Try adjusting your line-height to make them match more closely.

- In the bottom of your page, in the actual JavaScript replacement statements, the order they're entered can matter. In a page with an `h4` styled as a callout (with borders, padding and margins) it was found that Internet Explorer Mac was shifting the next heading, an `h3`, to the right about 30px. Changing the order of the replacements so that the `h4` was loaded before the `h3` fixed that little problem.

- If, in your main CSS styles, you've written any values for `font-size`, `line-height` or `letter-spacing`, you will definitely want to overwrite these values in your decoy styles using pure pixels. This will give you cross-browser consistency. As always, browsers have different default values. These differences (especially in line height) can be one of the causes of a heading that is large in one browser and small in another. Placing a background color behind the heading, temporarily, should allow you to measure the amount of space taken in each browser and correct it.

## Dealing with FlashBlock

The FlashBlock extension for Mozilla browsers will show the alternate text instead of the Flash headlines. This means you'll have to style `span.sIFR-alternate` to override the decoy styles. You can test this by installing FlashBlock, or by installing Greasemonkey and the sIFR Tools script. Now, if you go to `Tools > User Script Commands > sIFR - Act like FlashBlock` you'll see the alternate text as FlashbBlock users see it.

## Marvelling at your beautiful headlines

This is absolutely the easiest and most enjoyable step involved with sIFR. Mark Wubben is known to view all new entries on iPod411.com just because of their use of sIFR.