Follow me: @D_mitar

Most read posts recently



Dec 15th 2010 × Intermoos Part 4: Mark Obcena. Keetology, a book and more

Great timing is essential to great interviews (cough) but this one really is a cracker. Mark Obcena only had the official announcement / release of his new book “Pro JavaScript with MooTools” earlier today (after great anticipation, if I may add).

So, what better time to get a few answers from the man of the moment than right now? I present to you the “Dr. Keeto” intermoo. Brush up on your “keetology” and start reading!

Name: Mark Obcena
Nickname: Keeto
Country: Philippines
Age: 23
Blog: http://www.keetology.com/
Twitter: @keeto
GitHub: http://github.com/keeto/
Famous for: Up The Moo herd series, Pro Javascript with MooTools book
A little bit about yourself, your background…
I’m a software developer and graphic designer from Manila, Philippines.
How and when did you get involved with MooTools?
MooTools has always been my framework of choice, but I actually got involved with the community later than most of the early adopters. It was mid-2008 when I started hanging out in the official IRC channels, and that was mostly an accident. I was doing early contributions to Appcelerator Titanium back then, and I had the idea of porting Snippely (an old MooTools project from Valerio and Tom) to Titanium. So I went to the IRC channel to ask for permission to port.

Around the same time as my appearance, Jan was working on a project called Fire, which was a MooTools extension framework for Adobe Air. Since I had some experience with Adobe Air, Jan asked me if I would like to contribute to the project, to which I agreed. We worked on the project for a few weeks but we abandoned it at the end due to being too busy with other stuff. However, the project forced me to be constantly online in the channels, and I’ve never been away for more than a few days since then.

Eventually, I got the idea of writing a series of advance MooTools articles for my blog, and that eventually became the Up the MooTools Herd series which really started my community work.

Why MooTools, what makes it special?
There are two kinds of JavaScript frameworks available today: those that rely on abstraction and those that rely on extension. Frameworks that rely on abstraction are very easy to spot, since they produce code that look nothing like native JavaScript. They stick out like a Java class declaration in the middle of an Erlang source file. Extension frameworks, on the other hand, are subtle; they blend in with the language and appear like part of the standard library.

MooTools is one of those frameworks that fall into the extension category. I really don’t see MooTools as a framework but rather as an extension to the language itself. MooTools is to JavaScript what Objective-C is to C: it’s not a new language per se, but a thin layer that adds features to the language itself. The fact that it implements both a Type and a Class system–both language level features–is a testament to this extension nature of MooTools.

This difference between abstraction-based and extension-based frameworks is important for people who actually love the languages they use. The more you like a language, the more you’ll tend to lean towards frameworks that magnify rather than mask it. You’ll want to work more closely with the language in terms of syntax and philosophy–and burying it under heavy (and often leaky) abstractions would simply be daft.

What are you working on at the moment (on the framework itself, related or otherwise)?
I’m working on a lot of stuff, most of them related to MooTools and CommonJS. Perhaps the most exciting of them is Meso, which is a cross-engine MooTools library for CommonJS. Another thing that’s keeping me busy is Deck, which is an HTTP Server layer that runs on top of Meso.
Are there any other Open Source technologies or projects you are involved with?
I’m quite involved in a lot of things, at varying extents. I used to be very active with Appcelerator’s Titanium platform, but my involvement tappered off a bit because of work. I’m also experimenting a lot with Apache’s CouchDB and Steve Dekorte’s VertexDB, and I plan on hacking the latter in the coming weeks for a project I’m building. And of course there are my own projects that I’m working on together with other MooTools devs.
I know you are working very hard on your book, “Pro JavaScript with MooTools”. How is that going, when is it coming out and are you happy with it? Do you think less advanced MooTools users will benefit from reading it and be able to improve their coding standard and practices?

Depending on when this interview is published, the book would either be coming out in a few days or has already been released. I’m quite happy with it, although I would really like to expand some chapters in the future. Print publishing places very big constraints when it comes to writing time and publishing dates, and that really affected the book. I do think it turned out good, although–like many authors–I do believe that there is a big room for improvement.

Whether or not “less advanced” MooTools users will benefit from reading the book is totally up to them. After all, the MooTools source code has been open-source from the start, and there’s nothing about MooTools in this book that you won’t learn just by reading and examing the source code. If someone really wants to learn MooTools from the inside, all they have to do is look through the source code–they don’t need my book.

It’s also not my intention to promote coding standards and best practices in this book, since it’s not a book about how to develop with MooTools. It’s a JavaScript book that examines MooTools internals to help people understand what’s going on inside the framework. The goal then is to give people a starting point in exploring the capabilities of MooTools. How they apply what they learn from the book is totally up to them.

Would you share your thoughts on what the future holds in terms of HTML5, CSS3, V8, next gen browsers, server-side javascript, the role of frameworks and MooTools in web application development?
I believe that things are just gonna get better. Even though HTML5 is uttered like a buzzword these days, the attention its been getting represents a very real acceptance of the technology from the people–not just from the web community. It’s reflective of the excitement everyone has for a better web ecosystem.

JavaScript will remain the de facto language of the web. You might think that I’m happy about this, since I like JavaScript, but it also saddens me a bit. I do want to see something like Native Client to succeed, if only to add some healthy competition on the client-side. But I don’t think that this will happen any time soon, as most browser vendors have disregarded the technology–explicitly and implicitly by not commenting on it.

Server-side JavaScript will continue to grow, but it won’t take over anything. In as much as we JavaScript people would love to think that SSJS would conquer the whole of the server-side, the truth is there are already a lot of established languages that have been offering what SSJS is selling–and a lot of them are way better at this. Fans of the popular SSJS engines like to think that they’re using something novel, but most of the ideas that these new engines are touting are simply JavaScript rehashes of things already included (by default or by extension) in other languages. JavaScript is only playing catch-up.

One advantage of SSJS, though, is the fact that JavaScript reigns supreme (for now) on the client-side, and it’s the only language that can actually claim to be *realistically* usable for both the client-side and server-side. This is why I support CommonJS as a whole rather than individual engines, because CommonJS represents an ideal rather than a solid API. Getting bound to a new-fangled engine’s APIs is dangerous once the hype dies down.

If time and resources were not an issue, what new features or changes would you like to see most come into the framework or the website?
For MooTools Core, I’d personally want to see it split up into two main projects: one for ECMAScript and one for JavaScript. This is needed if MooTools branches out into the CommonJS space in the future, since CommonJS by default is more concerned about the ECMAScript rather than the JavaScript part.

I’d also like to see some additional metaprogramming APIs for Core. The biggest strength of MooTools is its extensibility, and I’d love to see some of the internals exposed via safe APIs. This will benefit those who’d like to extend MooTools without touching Core.

If you had not been involved in MooTools, what do you think you’d be doing instead?
I’d probably be running around the office right now looking for my editor to get him to approve my story for next morning’s paper.
MooTools is now officially the 2nd largest framework / library out there, how do you think it will grow from here?
There are a lot of factors, really. For one, it still depends on the people. As more and more developers start building more complex applications, the bigger the need is to use the proper tools for the job. MooTools is a very good framework to work with, since it can actually scale pretty well–but even that depends on the person using it. Not everyone who touches a paint produces a Picasso.

And even if people start flocking towards better frameworks, it does not mean that they’ll automatically choose MooTools. MooTools is awesome, but it’s not the only awesome framework. There are other scalable and well designed JavaScript frameworks competing in the space, and MooTools is simply one of the choices.

If you could give one tip to new MooTools / javascript developers, what would it be?
Be a scientist. The developers I respect and admire the most are those who always feed their curiosity, are always hungry for new information and are always exploring. They don’t sit around and wait for someone to answer their questions; they find out the answers for themselves. They experiment, they observe, and they share their results to the world.
Your favourite MooTools website:
The official one.
Your top 5 resources for web developers (can be websites like jsFiddle, IDEs, tutorials, CSS frameworks like boilerplate, etc)
- Google (with proper search keywords).
- Reddit and Hacker News, or basically any site that aggregates a lot of stuff.
- The documentation for the technologies you use, and their source code.
- The documentation for your text editor.
- Your creativity.
If you want to share some examples of your work…
All my public code are available on Github (http://github.com/keeto/)

Thank you for your time!

P.S. Now that the book is hot off the press, I should mention Keeto is available to pester with _interesting_ problems on IRC (just like most other teams in the MooTools community) – freenode.net #mootools. Go and say “hi” and say Dimitar sent you :)


Dec 13th 2010 × Intermoo series, Part 2: Piotr “Zalun” Zalewa, jsFiddle creator

Here’s “Intermoos“, part two: we sit and talk to Piotr Zalewa, aka Zalun of jsFiddle fame. If you’ve not heard of jsFiddle or used it, you should stop reading this and visit it first, play with it and come back because you’d be missing out.

Whereas Zalun is not an official MooTools team member, his contribution to the MooTools community (and to the javascript community at large) through jsFiddle has been nothing short of outstanding. Oh, and yes, he prefers and uses MooTools. So here we go…

Name: Piotr Zalewa
Nickname: zalun
Country: Poland
Company: Mozilla
Blog: http://piotr.zalewa.info/
Website(s): http://jsfiddle.net/, http://builder.addons.mozilla.org/
Twitter: @zalun
GitHub: http://github.com/zalun
Famous for: mooshell and jsfiddle
A little bit about yourself, your background…
I am a father, an aquarist and a web developer. I enjoy designing and maintaining my never too big “nature style” aquarium. I like watching my children grow and learn. I also like free stuff a lot. That’s why I created jsFiddle and didn’t hesitate too long to join Mozilla Team.

I started programming when I was 19. It was Turbo Pascal on XT’s and AT’s. At university I realised I like Gopher, IRC and FTP. Then in our university library someone placed 3 public computers connected to the new thing called World Wide Web. I was usually not consuming the content, but looking at how it was build. Soon I had my own website…

How and when did you get involved with MooTools or javascript?
I was hired by Moving Picture Company to create an intranet tool for movie management. They gave 10 working days to find out the best technology for the front-end. On the back-end Django was set from beginning. I was investigating all possible JavaScript frameworks and MooTools was something which I found the best, although I didn’t know anything about it at day 0.
Why MooTools, what makes it special?
Classes, clean code, ability to shape things in a way developer wants. I found a lot similarities to Python which is good as I write back-end in this language. I think it’s the best tool for someone who writes code, not only uses plugins.
What are you working on at the moment (on the framework itself, related or otherwise)?
I’d like to make Accordion better. It is considered as a bad UX, but I can’t imagine jsFiddle without it. I also started to rewrite jsFiddle – beta is coming (we aim for January). There is also another launch coming at Mozilla. We would like to have the Addon Builder 1.0 ready for the Firefox 4.0.
Are there any other Open Source technologies or projects you are involved with?
FlightDeck is open-source (as whole Mozilla), otherwise nothing I could call “involved”.
You have arguably created the most useful / groundbreaking tool for online collaborative javascript / web development testing to come out recently in jsFiddle. What gave you the idea and prompted you to do it?
I needed it. I would guess it’s the most honest answer for majority of start-ups. I was on #mootools IRC channel and we were helping new users with JavaScript/MooTools issues. We were even playing who will answer first, but the rule was – code has to fit in one line. Soon there was a question which was longer then that – although we do have pastebin I wanted to check if my idea was right before posting. I thought creating file with right DocType, including files and then loading into the browser was too much trouble. The question remained unanswered, but the next day I had a working prototype.

Just as a side note – jsFiddle wouldn’t be as awesome if not help from Oskar Krawczyk who is the “front-end guy” and other members mostly around MooToos community. Thank you all very much.

What technologies power jsFiddle? How is it holding up with the huge attention and traffic it is getting, particularly due to MooTools and jQuery adopting it as the de-facto platform for testing and case building / examples?
Back-end is all Django, MySQL and memcache. It still uses Apache, but I think beta will run from within Nginx or something similar. On the front-end we do use MooTools with a bunch of plugins such as ClientCide. CodeMirror is highlighting the code.
jsFiddle started off from mooShell, a tool initially MooTools specific and Open Sourced. Does that mean that mooShell development has now ended and do you have any plans for Open Sourcing jsFiddle?
Yes – mooShell will be closed when jsFiddle beta will start. It is currently in read only mode. I am still uncertain what type of license should I use for the new jsFiddle. It is a rewrite… I’d like to make it open source, but the business model I have in mind might be against it.
What future plans can you reveal about changes and growth for jsFiddle? Anything exciting you would like to share? That ‘business model’, perhaps?
I think the most awaited is user profile with ability to personalize jsFiddle – change editor application (there is a choice now!), the way it displays code, manage the framework drop down, etc. We will also add PRO accounts with many features around private fiddles.
What requirements do you have for accepting a new framework and how should development teams approach you about getting added?
This is a hard question – it’s mostly the community behind the project. We tried to add every framework which is a “must have”. There are few exceptions (like Processing js or Raphael which aren’t even frameworks), which we simply wanted to use. Beta version will be more specified and with the ability to tweak the “hot list” we will be able to implement much more frameworks. Some will be simply hidden by default. I am also adding the “Framework manager” badge. Users with such privileges will be able to maintain the framework – upload/link new versions, add best plugins, etc. More power for the users.
If time and resources were not an issue, what new features or changes would you like to change or refactor and why?
The way the dependencies and frameworks are bond together is wrong – this is invisible for the end-user, but adding new version of the framework is currently a pain.

On the front-end side – it would be fixing the layout for small touch screen devices.

If you had not been involved in jsFiddle, what do you think you’d be doing instead? I know you are currently working for Mozilla on JetPack, would you like to comment on that and give us an overview?
I had a few other ideas in mind, but these needed much more work on the beginning, which is a pain for free projects – not enough hype.

“Jetpack” is a working name for the new Firefox add-ons type. Firefox 4 will have it build in. It allows to install add-ons without restarting and is really easy to write. CommonJS style. SDK currently uses Python (I think it will use NodeJS in the future) and involves some work to be done to install on the developers computer. Mozilla thought it would be good to make this a lot easier and the idea for Addon Builder aka FlightDeck arised. It could be name jsFiddle for Firefox Addons. Users are able to edit and test addons without leaving the browser.

If you could give one tip to new javascript developers, what would it be?
JavaScript developer to me is a person who writes the code – classes, plugins. The knowledge of vanilla JavaScript is essential. So the tip would be – learn vanilla JavaScript. If I would be able to give another it would be: read framework’s code. It is interesting and enlightening.
Your top 5 resources for web developers (can be websites like jsfiddle, IDEs, tutorials, CSS frameworks like boilerplate, etc)
Github, documentation sites from framework developers, VIM, IRC, Linux, Twitter. I don’t need much :)
If you want to share some examples of your work…
It would be http://webdev.zalewa.info/. It’s a really old site, half of the examples there are from the time when I thought I could be a web designer, but clearly I’m not made for it. I guess you’ll find quite a few 404 on it as well.

Thank you for your time!


Dec 12th 2010 × Intermoos series, Part 1 – David Walsh: MooTools FTW, didn’t you know.

Hello and welcome to our new series: “Intermoos“. What it is, is a series of interviews with members of the MooTools team and community that have the time to spare. We ask them a few annoying questions, we get a few interesting answers, you get the idea.

And what better way than to start it all off with a one-to-one with none other than David Walsh, the extraordinary blogger and MooTools contributor (also famous for being Arsenal’s only American supporter). Without further adieu, here is what he had to tell us…

Name: David Walsh
Nickname: davidwalsh
Country: USA
Blog: http://davidwalsh.name/
Website(s): http://scriptandstyle.com/
Twitter: @davidwalshblog
GitHub: http://github.com/darkwing
Famous for: being an awesome mootools rockstar, “mootools ftw”
A little bit about yourself, your background…
My name is David Walsh and I’m a 27 year old Web Developer living in Madison, WI. I’m a self-taught developer that is obsessed with learning everything there is to know about front-end web development. My expertise is in HTML, CSS, JavaScript, and PHP. I work with jQuery, MooTools, and Dojo on a daily basis. I don’t design the websites, I make them work.
How and when did you get involved with MooTools?
My first exposure to MooTools involved a project that required smoothly animated elements. I found jQuery and its animations where laboring to say the least. MooTools’ animations were as smooth, efficient, and the the syntax was logical. From there I was hooked. I started a blog to share my findings and experimentations. I got better MooTools and started getting noticed by the community. A few commits and dozens of blog posts later, I was asked to join the MooTools team. Joining the MooTools team is one of the proudest moments of my career.
Why MooTools, what makes it special?
MooTools is special for several reasons. The MooTools API is as coherent and logical as you will find in a framework of any language. The code is as well written as you’ll find. MooTools is modular, efficient, and provides an outstanding inheritance pattern. The MooTools team cares about its community. MooTools isn’t about marketing itself and begging for attention – MooTools is about outstanding code to create dynamic, fast websites. MooTools is magic!
What are you working on at the moment (on the framework itself or related)?
Per the framework itself, I always have two goals: making the community aware of new features and strategies, and creating useful, well-coded plugins to display the power of MooTools. I don’t spend much time on committing to the repository other than quick fixes and documentation updates – my strength is spreading the good word Moo.
Are there any other Open Source technologies or projects you are involved with?
I work for SitePen so I occasionally commit quick fixes to the Dojo Toolkit. I write exclusively about open source projects on my blog, and give my code away for free.
You have always tried to work very hard through your excellent blog on promoting MooTools and helping out new (and seasoned users). You are now pretty much _the_ most celebrated MooTools team member and community figure out there (going by readership and Twitter popularity, at the least). What drives you daily to spare the time and show such dedication?
I work so hard because I love JavaScript, MooTools, and its community. Let’s face it – we’ve all faced a technical problem that we’ve needed to scour the internet to figure out. Most people find their solution and move on. I’ve vowed not to do that – any solution to a complex problem that I find ends up on my blog so that other people don’t need to suffer the same pain that I did.

Per the MooTools project specifically, I strive so hard because I’m so passionate about the project. I love the codebase, respect the hell out of the developers creating the code, and appreciate the MooTools community. I could write a million blog posts about MooTools and not feel I’ve given as much to the project as its given me. MooTools FTW.

You have recently adopted a practice whereby you post similar snippets of code for MooTools, jQuery and Dojo, demonstrating the similarities and differences in their respective approaches. Isn’t that even more taxing and difficult to do? Does MooTools still remain as your framework of choice?
The motive behind writing code to accomplish similar tasks with each framework is to show my readers that, in the end, it’s just JavaScript. Dojo, MooTools, and jQuery are very different but in the end, they’re just an abstraction of JavaScript patterns and APIs. I also do it to show developers the different coding patterns available and the differences in syntax.

What’s important, more so than preferring one framework over another, is find the framework that best fits a project. You can love jQuery but what if it’s not a great match for a specific project? You’d be wasting time using it. In the end though, if all things are equal, I’d use MooTools before any other project. Extendible, compact, logical… those are what MooTools is all about.

Would you share your thoughts on what the future holds in terms of HTML5, CSS3, V8, next gen browsers, server-side javascript, the role of frameworks and MooTools in web application development?
The future is looking up! Let’s be honest: the reason we create (and use) CSS and JavaScript frameworks is because the tools we need aren’t available at the present time. HTML5′s markup rules bring us back to a more common-sense approach, and its new JavaScript APIs like WebSocket, classList, and storage APIs are outstanding. V8 and server-side JavaScript are also exciting – imagine writing and entire website, front and back-end, in just JavaScript! MooTools works on both the server and client side which is even more exciting! WebKit-based browsers continue to amaze me – the capabilities they provide, especially with CSS animation, are percolating. Using CSS-driven animations instead of JavaScript animation will lead to faster, smoother interfaces. I’m excited to see what’s next!
If time and resources were not an issue, what new features or changes would you like to see most come into the framework or the website?
I would like to see some of the MooTools 2.0 features incorporated ASAP, including CSS animations and the unified Fx timer. These features have been coded but not implemented so as to not create such a jump in upgrading. There are many other features in the 2.0wip branch that I would love to see implemented. Unfortunately, now is not the best time to release these features due to other API changes that would be required.
If you had not been involved in MooTools, what do you think you’d be doing instead?
I owe much of my career advancement to MooTools. MooTools ignited a fire the fire which made me dedicate my career to JavaScript and front-end development. I’d likely be working at an average Web Development shop, waiting for the clock to hit 5:00.
MooTools is now officially the 2nd largest framework / library out there, how do you think it will grow from here?
Like other web technologies, MooTools’s future is nothing but up. Our development team continues to grow, as does our loyal, intelligent community. As far as features I’d like to see, I’d love to see a Dijit (Dojo Toolkit) UI competitor created for MooTools. I’m also hopeful that the Forge continues to grow at its current pace – it’s a treasure chest of great MooTools plugins!
If you could give one tip to new MooTools / javascript developers, what would it be?
My tip would be this: when you create a plugin/class, take a step back and ask yourself:
`Can I make this class more generic so that it could be used for other purposes?`
If so, create that base class and use MooTools’s Extend/Implements methods to create your more specific class. MooTools is founded on flexibility – learn how to properly use its inheritance methods and you’ll be an unstoppable programming force.
Your favourite MooTools website:
This will sound insanely vain but I have to say my own. I refer to my own website often to grab code I’ve posted in the past. I also get user feedback so I can improve my code. I also love the MooTools Forge – its code holds the value of Fort Knox.
Your top 5 resources for web developers (can be websites like jsfiddle, IDEs, tutorials, CSS frameworks like boilerplate, etc)
A few people you should really be following if you’re into MooTools, jQuery, or just JavaScript in general:

Ryan Florence (http://ryanflorence.com/) – Ryan’s an outstanding JavaScript developer that writes interesting tutorials about jQuery, MooTools, and CSS animation. He’s the creator of MooTools SlideShow, Moo4q, and MooTools’ pub/sub plugin: Channels.

Kris Zyp (http://twitter.com/kriszyp) – Kris is a Dojo committer, author of the JSON Schema spec, and creator of Persevere, a server-side JSON technology. Kris is a JSON guru, server-side expert, and overall JavaScript nut.

You have written a plugin for everything conceivably possible, from the ever so popular ScrollSpy (no.1 plugin on the forge) to tackling heatmapping, custom pseudo selectors, history/visited spying and Twitter feed parsers. There are over 800 demos on your site with most of them being MooTools-based. Is there anything left you have not been able to write? What is your favourite plugin of all time (yours or otherwise)
There are a billion more plugins left for me to write! I’m hoping to write a Facebook photo-tagging clone soon, as well as anything else I see that tickles my fancy. Wherever there’s an idea there’s a MooTools plugin to write. There are only two limitations to MooTools plugin creation: inspiration and time. I could write MooTools plugins forever!
If you want to share some examples of your work…
I’m not big into self-promotion, but a few of my more popular posts and MooTools plugins include:

  • ScrollSpy – A MooTools plugin which monitors scrolling to fire events based on page position.
  • LightFace – A Facebook Lightbox clone which handles AJAX, IFrames, Images, and more.

If you want to see what I’m all about, visit my blog: http://davidwalsh.name

Are you a javascript / MooTools ninja and what do you think of the new ‘ninja’ culture out there?
‘Ninja’ is a lame term to try to make JavaScript development seem exciting to outsiders. In any event, the boom in JavaScript popularity is nothing but exciting. More bright minds to solve client side problems is a boost to JavaScript development and provides more ideas to the development pool. JavaScript is the future of web development.

Thank you for your time!


Aug 13th 2010 × mootools Request.JSONP to decode shortened url hashes

I tend to get annoyed about URL baiting that takes place over social networks – you really don’t know what’s behind a shortened URL until you click it. Or… until you run a URL resolver that can help. In building my Twitter Trend Aggregator, I came to explore this and found an invaluable service through the API of longurl.org that can uncrunch almost any shortened URL to its original.

Here is the extended Class (http://www.jsfiddle.net/dimitar/3Ntnr/)

Request.longURL = new Class({
    // decode a long url
    Extends: Request.JSONP,
    options: {
        log: !true,
        url: "http://api.longurl.org/v2/expand",
        data: {
            url: "",
            format: "json"
        }
    },
    initialize: function(loc, options) {
        this.parent(options);
        this.options.data.url = loc;
    },
    success: function(data, script) {
        this.parent(data, script);
    }
});
// example usage
var urls = [
    "http://bit.ly/b5Ukzp",
    "http://tinyurl.com/33wz7sv",
    "http://is.gd/e7S7R",
    "http://post.ly/r49y",
    "http://www.google.com/" // won't do anything to it.
];

var output = document.id("output");
urls.each(function(url) {
    new Request.longURL(url, {
        onSuccess: function(data) {
            new Element("a", {
                href: data["long-url"],
                text: url + " -> " + data["long-url"]
            }).inject(output);
        }
    }).send();
});

For a better example of this, visit the Twitter Trends Thingie I wrote and mouseover any encoded URL (or press the ‘Unshorten Tiny URLs’ link in the top right bar).

If you want to just deal with the good old bit.ly, then you can go to them direct like so:

// get all links on page that are bit.ly and decode them
document.getElements("a[href^=http://bit.ly]").each(function(el) {
    var url = el.get("href");
    new Request.JSONP({
        url: 'http://api.bit.ly/v3/expand',
        data: {
            shortUrl: url,
            apiKey: 'R_e744c730bdde44a7eacc88cb892074e7', // change
            login: 'webtogs2' //change this
        },
        onComplete: function(response) {
            el.set({
                href: response.data.expand[0].long_url,
                text: response.data.expand[0].long_url
            });
        }
    }).send();
});

Happy social networking


Jul 9th 2010 × Create bit.ly addresses on the fly with mootools and Request.JSONP

I was writing my own re-tweet class and found that I need to crunch URLs on the fly to make them fit within the 140 character limit on Twitter. Come bit.ly and their API, easily accessible via REST and with a JSONP callback interface, just the job for extending Request.JSONP:

Request.bitly = new Class({
    // shorten urls via bit.ly
    Extends: Request.JSONP,
    options: {
        log: !true,
        bitly: {
            api: "R_e744c730bdde44a7eacc88cb892074e7", // GET YOUR OWN API KEY
            login: "webtogs2" // GET YOUR OWN LOGIN
        },
        url: "http://api.bit.ly/v3/shorten?login={login}&apiKey={api}&longUrl={longUrl}&format=json"
    },
    initialize: function(loc, options) {
        this.parent(options);
        this.options.bitly.longUrl = loc;
        this.options.url = this.options.url.substitute(this.options.bitly);
    },
    success: function(data, script) {
        this.parent(data, script);
    }
});

This is the class, now for the example uses, this will convert all links from the page into bit.ly URLs (if they are shorter than the original)

document.getElements("a").each(function(el) {
    new Request.bitly(el.get("href"), {
        onSuccess: function(data) {
            if (data && data.data && data.status_code == 200) {
                var orig = data.data.long_url, hash = data.data.url, difference = orig.length - hash.length;

                if (difference > 0) {
                    el.set({
                        href: hash,
                        title: hash + " - saved " + difference + " chars"
                    }).addClass("shortened");
                }
                else {
                    var error = "ERROR:\n your bit.ly hash '" + hash + "' is longer than the original '" + orig + "'";
                    el.set("html", el.get("html") + error);
                }
            }
        }
    }).send();

});

See it all in action on the little jsfilddle here: http://www.jsfiddle.net/dimitar/xVtZy/


Jun 3rd 2010 × beware: googlebot understands javascript, mootools and ajax now

This came as a complete shock to me: due to the Google Mayday update, I have been monitoring how the bot accesses our sites in a futile search for clues as to the page rankings changes. Very surprised to discover googlebot fetching URLs that are _strictly_ available through Ajax only.

Here is a sample request from earlier today that fetched a small worker thread that produces additional product images:

66.249.65.25 - - [03/Jun/2010:11:25:43 +0100] "GET /angles.php?id=102257&version=Brown HTTP/1.1" 200 801 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"

We have all spoken of Google’s increased capability of following and deciphering javascript logic but it goes beyond the scope of reasonable effort, in my opinion. Is the scraping done based upon URLs detected in the javascript blocks or does it actually evaluate, run and monitor the calls? If the scraping works based upon regex that catches URLs, would obfuscation / base64 encoding help? Does googlebot support XHR via POST or only via GET? Too many questions without an answer at this point, I will update this post as more info becomes available to me.

Such fetches can often be undesirable–certain AJAX calls we do are tied in with sessions and can cause errors / notifications when being requested w/o due cause, session or event. I am currently trying to find if there is a plausible way to apply a “nofollow” to such calls at all that does not involve a lot of editing and blocking of googlebot from any scripts that it has no place reading. If it comes to it, I will revert all ajax handling to a /xhr/ folder and disallow it in robots.txt, wonder what the best practice is…

As for the Mayday Update, the less said about it, the better. I have never seen Google SERPs get things so very wrong – for instance, ranking disabled products with 0 links anywhere on the net that redirect their traffic instead of what used to be the landing pages. Longtail relevance? With 2k organic in-links to the landing page, PR4 and quality content built over 2 years, this is not bizarre enough…


May 7th 2010 × mooPlaceholder: input placeholder behaviour class

Some of the HTML5 features just won’t come fast enough. One such feature is the ability to apply a placeholder input attribute, something like placeholder=’your text’ which takes the text and sets it as a pseudo default input value until it’s focused or changed. Currently (at time of writing), this only works in webkit-based browsers like Chrome and Safari but it’s not difficult to bring it into all other browsers.

Here’s a little class / mootools plugin that I wrote to do it:

var mooPlaceholder = new Class({
    // behaviour for default values of inputs class
    Implements: [Options],

    options: {
        // default options
        htmlPlaceholder: "placeholder", // the element attribute, eg, data-placeholder="MM/YY" -> "data-placeholder"
        unmoddedClass: "unchanged", // apply a class to the unmodded input, say, to grey it out
        parentNode: document, // limit to a particular set of child nodes
        defaultSelector: "input[placeholder]"
    },

    initialize: function(options) {
        this.setOptions(options);
        // detect native support (nothing gets done if true)
        this.nativeSupport = 'placeholder' in document.createElement('input');
    },

    attachToElements: function(selector) {
        // basic function example that uses a class selector to
        var inputs = this.options.parentNode.getElements(selector || this.options.defaultSelector);

        if (inputs.length) {
            inputs.each(function(el) {
                this.attachEvents(el);
            }, this);
        }
    }, // end attachToElements

    attachEvents: function(el, placeholder) {
        // method that attaches the events to an input element.
        var placeholder = placeholder || el.get(this.options.htmlPlaceholder);
        if (this.nativeSupport || !$(el) || !placeholder || !placeholder.length)
            return;

        el.set("value", placeholder).store("placeholder", placeholder);

        // append unmodded class to input at start
        if (this.options.unmoddedClass)
            el.addClass(this.options.unmoddedClass);

        // now cater for the events
        el.addEvents({
            change: function() {
                // when value changes
                var value = el.get("value").trim(), placeholder = el.retrieve("placeholder");
                if (value != placeholder) {
                    // once it changes, remove this check and remove the unmoddedClass
                    el.removeClass(this.options.unmoddedClass).removeEvents("change");
                }
            }.bind(this),

            focus: function() {
                var value = el.get("value").trim(), placeholder = el.retrieve("placeholder");
                if (value == placeholder) {
                    el.set("value", "").removeClass(this.options.unmoddedClass);
                }
            }.bind(this),
            blur: function() {
                var value = el.get("value").trim(), placeholder = el.retrieve("placeholder");
                if (value == placeholder || value == "") {
                    el.set("value", placeholder).addClass(this.options.unmoddedClass);
                }
            }.bind(this)
        });
    }
});

// example use for a single element:
new mooPlaceholder().attachEvents($("searchfield"), "type here to search site..."); // override placeholder

new mooPlaceholder().attachEvents($("searchfield")); // use placeholder= value instead

// example use for any input element that has a placeholder property:
new mooPlaceholder().attachToElements(); // defaults to "input[placeholder]"

// or a custom selector
new mooPlaceholder().attachToElements("input.foo");

// or only inputs of a particular form with a particular class (required)
new mooPlaceholder({
    parentNode: $("mysignupform"),
}).attachToElements("input.required[placeholder]");

Clearly, many ways to use it. It will only work as progressive enhancement and won’t attach anything if the browser already supports placeholders.

Make sue you set the CSS class for the unmodded input (look at the CSS tab on JSFIDDLE for an example) – it seems that natively, the text goes to #A9A9A9 but you may be able to override that. Vendor specific CSS styles allow you to work with this:

input.unmodded::-webkit-input-placeholder {
    color: rgb(100, 0, 0);
}

Have fun.


Apr 28th 2010 × mootools 1.3 beta 1 is finally out for grabs

In what promises to be the most significant update thus far (well, perhaps the mootools 1.11 to 1.2 is still worth mentioning as a milestone), the mootools team have finally released a public beta.

Why is it significant? You can read the blog post but here is the short summary: in addition to being set as the groundwork for the transition to mootools 2.0, here are the most significant changes I have found out about (list will expand as I find out more):

  • The introduction of slick (new css pseudo selector engine) – awesome news for DOM manipulation speeds
  • Move away from `Native` to `Type` (semantics) – internal change mostly, unless you hack into Natives
  • Move away from $names – all things like $chk, $type, $A and so forth are now being renamed to plain function names that make more sense and look more javascript-y.
  • Move away from feature detection where possible and a larger reliance on UA parsing instead – not sure I appreciate this as I do not trust UA strings at all, not least of all due to the fact that I often browse with the googlebot UA string when chasing SEO issues around our competitors. There was a nasty post by slicknet a while back in which he ripped into mootools for still using feature detection but I fail to see his point (just as many others do). Both are somewhat unreliable but one does not allow for the user to directly interfere with the framework behaviour.

Additionally, it seems as if the framework has been largely rewritten – most of the source code is totally new to me and it will take me some time to get a better understanding on how it works. Thus far, there’s been no mootools-more 1.3 so I suppose Aaron Newton will be working hard on releasing it soon.

The new documentation is live (courtesy of fakedarren) here: http://mootools.fakedarren.com/docs/core

P.S. Oskar reported earlier via twitter that JS Fiddle has updated and included the beta as framework option so you can play with it.

The


Mar 31st 2010 × mooSelecta – an accessible mootools select/dropdown element replacement

Don’t you just love how different browsers style (or rather, don’t style) select and option elements? One of the things I dread most as a developer is when the design team come in and produce forms with controls that are totally bespoke and unobtainable due to the browser limitations.

This prompted me to write a mootools class that replaces the existing select items on the page with custom style-able controls through CSS as a progressive enhancement. Here is an example of what the resulting dropdowns can look like:

mooSelecta dropdowns screenshot

The idea of skinnable dropdowns is nothing new but not many solutions are done in a way that mimics the select element’s behaviour and events correctly. Here is what mooSelecta does feature:

  • support for any type of skins, all through CSS
  • support for native element events (will work with scripting)
  • support for keyboard look-ups when dropdown is open
  • support for input labels
  • support for tabindex

Have a look on the mooSelecta example page or on the mootools forge page for the plug-in itself (download etc).

One thing you need to be aware of is that if you want to dynamically change the selected value of a skinned select, you need to fire it’s onChange event for mooSelecta to update. For example, if you have a dropdown with id=”country” and class=”selecta”:

new mooSelecta({
    selector: "selecta"
});

// change default selected value via js later:
$("country").set("value", "United Kingdom").fireEvent("change");
// the event will make mooSelecta update

Aside from that, it’s fine, tested and working in IE6, IE7, IE8, Firefox 2, Firefox 3.6, Safari 4, Chrominum 5. Known issues with Opera keyboard events not being raised as expected. Enjoy!


Mar 22nd 2010 × Another javascript test

This time I found a fun javascript test on StackOverflow on the PerfectionKills blog: Javascript Quiz, once again it has been suggested to use through the interview process for a javascript / front-end engineer role.

Good luck and have fun (as they say…)