Most read posts this month



Mar 24th 2009 × mooProgress: an element javascript progress bar method

Ever needed to show something on-screen as a percentage / bar in javascript? Yes, it has been done a countless number of times before. Sometimes, even in mootools. But we like adding our own functions to the dci_core.js mini library whenever possible. So … here is a very easy and good-looking way of doing it (well, subject of what background images you can come up with, of course). The idea is simple: have a container element with a background image that is offset to outside the element’s boundaries via the background-position CSS property. As the percentage is being calculated, the background image is bring brought into view.

Our progress images look like this:

200px wide, so each percent is represented by 2px, something that is reflected in the script below. Here is the target element, styled as per our CSS:

Some more examples of various options for the progress bar, settings are contained within the actual elements:



Here’s the relevant CSS:

.progress {
    width: 200px;
    border: 1px solid #000;
    background-color: #d81e05;
    background-image: url(/gallery/img/progress.gif);
    background-repeat: no-repeat;
    background-position: -210px 0;
    height: 16px;
    line-height: 1;
    color: #F4F4F4;
    font-weight: bold;
    margin-bottom: 4px;
}
.progress2 {
    width: 202px;
    border: 1px solid #000;
    background-color: #555;
    background-image: url(/images/progressbar-orange.gif);
    background-repeat: no-repeat;
    background-position: -210px 0px;
    height: 21px;
    color: #000;
    font-weight: bold;
    margin-left: 1px;
}



The actual div and html:

<div class="progress" id="someid"></div>

Some more examples of various options for the progress bar, settings are contained within the actual elements:
<a href="#" class="barbar" data-data="{count:23,total:26,message:'loaded...',className:'progress2'}">23 of 26, "images loaded..." with cubic tween, class: progress2</a>
<a href="#" class="barbar" data-data="{count:4,total:5,message:'completed',tween:false}">4 of 5, 'completed', no tween</a>
<a href="#" class="barbar" data-data="{count:14,total:80,message:'Questions'}">14 of 80, 'Questions', cubic tween</a>
You may notice the element has a CSS dropshadow applied to it, unless you are in IE. If you are interested how this works, have a look at our mooShadow element method for absolutely positioned elements (hence the need to setStyle to absolute and back to relative afterwards, something of an issue with IE)

Here’s how we extend the element in mootools and call the methods we need:

Element.implement({
    showProgress: function(options) {
        options = $merge({
            count: 0,
            total: 10,
            message: "",
            className: "progress", // default css class
            backgroundPosition: 200, // start pos
            tween: true // animate or static
        }, options);

        // calculate % of progress
        var percent = options.total / 100, donePercent = (options.count / percent).round(), BGoffset = options.backgroundPosition - (donePercent*2).round();

        // set inline message
        this.set({
            styles: {
                "background-position": "-" + options.backgroundPosition + "px"
            },
            html: "  " + options.count + " of " + options.total + " " + options.message + " ("+donePercent+"%)",
            "class": options.className
        });

        if (options.tween)
            new Fx.Tween(this, {
                duration: 500,
                transition: Fx.Transitions.Cubic.easeIn
            }).start("background-position", "-" + BGoffset);
        else
            this.setStyle("background-position", "-" + BGoffset + "px");

        this.store("percent", donePercent); // element storage, use element.retrieve("data-percent") to get current progress.
        return this;
    }
}); // end extending elements

// apply initial state
$("someid").showProgress({count:3,total:10}); 

// bind the links to change the bar graph to real time data.
$$("a.barbar").addEvents({
    click: function(e) {
        new Event(e).stop();
        $("someid").showProgress(JSON.decode(this.get("data-data")));
    }
});

// show / read percent from element storage
$("fetchPercent").addEvent("mouseenter", function(e) {
    this.tooltip("This bar at " + $("someid").retrieve("percent") + "%");
});


That’s it, I hope it helps you. In an ideal world, this could be refactored into a mootools class but who has the time…


Mar 19th 2009 × Google Street View goes live in the UK

It’s what it says, really. Now go and find your street and house. No, really, go…

no

Mar 19th 2009 × mootools goodies: PBB MagicWheel and MooStack

From the bookmarks gallore… PBB MagicWheel is an Apple-style fully featured carousel effect.

mootools pbb magic wheel

Granted, it uses a lot of space so it is not something you’d need every day. But with the Apple Wheel coming soon, it may be all the rage…

And MooStack – an image (or any other content) swapping script that leaves you feeling like you are shuffling a pack of cards. Great idea for an effect, will certainly make for some unusual gallery scripts.

moostack


Mar 16th 2009 × QuakeLive monetisation: it has begun, in-game adverts as of today

Hot off the press, ID have managed to sign on an advertising partner (play.com, no less) for in-game animated banners in QuakeLive that eat away your FPS. Took these screenshots of DM6 earlier with the irresistible offer to purchase the Quantum of Solace DVD…

This really helps my already struggling laptop to cope with things… I wonder if there will be an adblock plus version for QuakeLive :)


Mar 11th 2009 × mootools 1.2 form validations, input masks and updates to .more

Just a round-up. First off, Aaron Newton announced yesterday on the mootools blog that the new mootools-more has been released (as RC1) on the mootools site. It features updates, fixes and mostly, new additions that were previously unavailable outside of the CNET/Clientside libraries. This does not mean to say he lifted the CNET code and pasted it into the mootools repository – a lot of it has been refactored and fixed.

Second, in having to work with forms in a hurry recently, I went and played with 2 such mootools ‘plugins’ from my bookmarks (whilst I was avoiding having to reinvent the wheel and being lazy…)

mootools formcheck is a class-based semantic solution which relies on css classes to define a ruleset for each input field. For example: <input type=”text” class=”validate['required', 'length[4, -1]‘, ‘differs[email]‘, ‘digit’]” />. Pretty flexible and pretty cool, thumbs up from me and the idea of a hash based ruleset within the element’s class is just great.

mootools iMask by Fabio Nagao is something similar to formcheck, but it takes matters further. iMask actually attaches itself to the input element and helps the user populate their data as per a pre-set ‘mask’. The mask is just a patterned format that cannot be broken. In reality, it allows you to ask your user to enter really complex data blocks, for example, you can have a field that contains (+NN)-NNN-AZ, hyphens, brackets and plus sign included. The end-user can only enter numerics or alpha characters in their designated places. Check it out, it’s really impressive.


Mar 9th 2009 × Internet Explorer 8 RC1 and IE7 compatibility mode: not really compatible

Lately I have been playing with the RC1 release of IE8 and to my shock-horror, it makes a total mockery of many of the pages I administer and run. To the rescue is the so called ‘compatibility’ mode, created as a layer that allows your sites to look, feel and function exactly as they did in IE7. Allegedly, the magic code is:


<meta http-equiv="X-UA-Compatible" content="IE=7" />

My initial testing concluded that it seemed to do the job and I let it rest, hoping to have survived yet another Microsoft blunder on the cheap… Not so. Turns out that you still get differences and issues in CSS. This is non-fatal but the fact that certain JS scrolling modules I had written now seemed to output nothing at all worried me. A google search revealed that Microsoft are managing a list of 2500+ sites, submitted by testers and reported to still have problems despite of the compatibility layer! Nice… I guess I will be submitting my own entries — and so should you… As if the Safari 4 beta was not bad enough…

Word to the wise, do not install a RC (release candidate) on a machine that you value – to be safe, download a copy of the Microsoft Virtual Machine and an XP image, then install on it.


Mar 2nd 2009 × Object Orientated CSS, no, really?

Stubbornella, who fancies herself as a bit of a CSS guru, has some up with a concept that has thus far received nothing but praise from all sorts of people. You can check it out on her blog, not the worst of ideas… Only wish the slidecast had audio with it…

no