Activate your free membership today | Log-in

Friday, February 5th, 2010

AT AT Walking with CSS

Category: CSS, Examples

Anthony Calzadilla has a fun Friday example for us. He has a tutorial on how he animated an AT AT using CSS.

He goes over the different areas and how he uses animation and transforms.

For example, the head of the beast:

CSS:
  1.  
  2. @-webkit-keyframes rotate-head{
  3.   0% {-webkit-transform:rotate(0deg) translate(0px,0px);}
  4.   40% {-webkit-transform:rotate(10deg) translate(15px,5px);}
  5.   80% {-webkit-transform:rotate(-5deg) translate(8px,5px);}
  6.   100% {-webkit-transform:rotate(0deg) translate(0px,0px);}
  7. }
  8. #atat #head {
  9.   -webkit-animation-name: rotate-head;
  10.   -webkit-animation-duration: 7s;
  11.   -webkit-animation-iteration-count: infinite;
  12.   -webkit-transform-origin: 0 50%;
  13. }
  14.  

Posted by Dion Almaer at 6:17 am
13 Comments

+++--
3.2 rating from 25 votes

Friday, January 29th, 2010

Addmap.js – automatically analyse a text for geo locations and add a map

Category: Examples, Geo, Google, JavaScript, Mapping, Yahoo!

As part of an upcoming article on geo location I am putting together a few Geo Toys for myself and here is the first one. Addmap.js is a JavaScript that analyses an elements text content, finds geographical locations and links them to Google Maps. It also adds a map preview and a list of the found locations to the element.

See addmap.js in action below - all the content in the green box is generated from the paragraph of text above it. You can try it out for yourself by clicking the screenshot.

Demonstration screenshot of addmap.js

Using addmap.js is easy - sign up for a Google Maps Key and provide it as a configuration parameter. Then call the analyse function with the ID of the element to analyse as the parameter:

XML:
  1. <script src="http://github.com/codepo8/geotoys/raw/master/addmap.js"></script>
  2. <script>
  3. addmap.config.mapkey = 'YOUR_API_KEY';
  4. addmap.analyse('content');
  5. </script>

The script uses YQL and Yahoo PlaceMaker under the hood, for more info and updates on this, check the blog.

Posted by Chris Heilmann at 10:17 am
3 Comments

+++--
3.1 rating from 17 votes

Thursday, December 31st, 2009

Web 2.Snow

Category: CSS, Examples, Fun, JavaScript

When I talked about some snow related CSS3 experiment, I could not imagine @Natbat was already preparing something like snowflakes, an almost fully CSS3 featured snow FX created for clearleft, specially suited for Chrome and Safari.

And what about @zacharyjohnson? He put snow all over the network via its Winternetizer, the first snow proxy I have ever seen.

Am I missing anybody? ... sure, me!

Above FX is dedicated to all Ajaxian readers and created via some CSS3 rule handled via JavaScript for a partial cross browser implementation. WebKit based browsers, included Android and iPhone, plus Firefox 3.6, should render properly, while the most interesting thing, snow a part, is that for the first time rather than browser sniffing, I have implemented a sort of "screen resolution to power computation" sniff:

JAVASCRIPT:
  1.  
  2. var totalSnowFlakes = Math.max(
  3.     Math.min((
  4.         document.documentElement.offsetWidth *
  5.         document.documentElement.offsetHeight /
  6.         15000
  7.     )>> 0, 40), 10
  8. );
  9.  

Probably not perfect, the aim is to avoid same number of flakes in mobile devices, netbooks, or desktop PCs.
I guess one day we'll have exposed CPU model and RAM amount as read only userAgent properties, so that all new effects could avoid stress for web surfers.
Something like System namespace in ActionScript, with capabilities for audio and video and extra info about the current navigator ... maybe just an AS to JS bridge 'till that day? We'll see, today the important thing is simply one: Have Fun!

Posted by webreflection at 8:13 am
11 Comments

+++--
3 rating from 23 votes

Tuesday, December 1st, 2009

Star Wars HTML and CSS: A NEW HOPE

Category: CSS, Examples, Safari

There are a lot of CSS transitions experiments going on right now. Yesterday I discovered another HTML and CSS experiment which went "far far away", compared with my simple CSS gallery.

Guillermo Esteves presented a piece of history translated for tomorrows browsers:  the Star Wars Episode IV opening crawl in HTML and CSS:

Unfortunately, the live experiment is not suitable for all browsers and the ideal target seems to be only OSX 10.6 and its latest Safari browser but it partially worked via Google Chrome as well.

Something To Learn About

We are moving complex computations into our favorite "decoration layer": CSS
We also want as much control as possible, and the above concept is brilliant to understand how to tame CSS transitions.
This example includes new and different techniques. Here is what I found interesting:

@font-face

OK, this is not new at all, but in this case I could not find a single valid reason to avoid the original font: a must! The only point here is that the author could have saved a bit of bandwidth via pre-deflated or gzipped fonts rather than serving them without any apparent optimization.

CSS:
  1.  
  2. @font-face {
  3.    font-family: FGB;
  4.    src: url("/experiments/frabk.ttf") format("truetype");
  5. }
  6.  

It's a shame there is not the real STAR WARS font as well but just an image ... anyway, let's move into more concrete stuff ...

Perspective

CSS:
  1.  
  2. #stage {
  3.   height:600px;
  4.   width:1000px;
  5.   overflow:hidden;
  6.   margin: 0 auto;
  7.   -webkit-perspective:800;
  8.   -webkit-perspective-origin:center 300px;
  9. }
  10.  

The stage is the block element where the magic happens. The perspective property is able to give us a "deep space" 3D feeling making closer objects look larger than further ones. Via origin modification we can decide where things should disappear, in this case a bit higher point than a central 400px, to create a similar atmosphere respecting the movie choice (and I guess to make content readable as well).

Iteration-count and Custom transitions

CSS:
  1.  
  2. #far-far-away {
  3.   color:rgb(75,213,238);
  4.   font-family:FGB, sans-serif;
  5.   font-size:48px;
  6.   line-height:1.5;
  7.   position:absolute;
  8.   top:200px;
  9.   left:190px;
  10.   opacity:0;
  11.   -webkit-animation:fade-in-out 6s linear;
  12.   -webkit-animation-iteration-count: 1;
  13.   -webkit-animation-delay:5s;
  14. }
  15.  

Far far away is the initial text. As we can see with other browsers as well this appears and disappear in 6 seconds.
This fade-in-out happens just once, so at the end of the effect, unless we won't modify the node class, the element won't be displayed anymore. This is what the animation-iteration-count property does while next snippet is the fade-in-out customization:

CSS:
  1.  
  2. @-webkit-keyframes fade-in-out {
  3.   0% { opacity:0; }
  4.   16%   { opacity:1; }
  5.   84%   { opacity:1; }
  6.   100%   { opacity:0; }
  7. }
  8.  

Via keyframes <transition_name> we can blend FX linearity deciding the amount of opacity, or other properties, at certain moments.
A generic normal linear fade-in-out would be visible 100% only in the middle of the transition while in this case it is forced to be visible for 68% of the time, making fade in and out still homogeneous but controlling the full opacity for longer.
We could have used an ease-in-out effect over opacity property to obtain a similar result but I find definitively more interesting this kind of approach.

Warp Speed: Action!

Thanks to Z axis transitions the initial STAR WARS image can appear and disappear using again a customized FX:

CSS:
  1.  
  2. @-webkit-keyframes logo {
  3.   0% { -webkit-transform: translateZ(0); opacity:1;}
  4.   50% { -webkit-transform: translateZ(-50000px); opacity:1; }
  5.   60% { -webkit-transform: translateZ(-60000px); opacity:0; }
  6.   100%   { -webkit-transform: translateZ(-100000px); opacity:0;}
  7. }
  8.  
  9. /* few lines after, img is the only logo image */
  10. img {
  11.   opacity:0;
  12.   position:absolute;
  13.   top:100px;
  14.   width:1000px;
  15.   -webkit-transform-origin:center center;
  16.   /* above custom logo animation */
  17.   -webkit-animation:logo 25s linear;
  18.   -webkit-animation-iteration-count: 1;
  19.   /* suspance before the logo ... */
  20.   -webkit-animation-delay: 12s;
  21.   /* logo appears slower and fly away faster */
  22.   -webkit-animation-timing-function: ease-in;
  23. }
  24.  

Above mix of webkit properties suggests me that new JavaScript libraries will use run-time actions to CSS transformations soon, rather than hard and manual JS computations over computed styles or similar expensive operations.
We can control delays, we can stop FXs removing classes or simply overwriting existent directives and, moreover, we can split the CSS itself into logical parts as the same @gesteves did, putting custom animations all together: good hint!

The Crawl

Last piece to check out is the text plus its title.

CSS:
  1.  
  2. /* custom crawl FX */
  3. @-webkit-keyframes crawl {
  4.   /* axis management until it disappears */
  5.   0% { -webkit-transform:rotateX(80deg) translateZ(300px) translateY(1100px);opacity:1;}
  6.   40% { -webkit-transform:rotateX(80deg) translateZ(300px) translateY(-340px);opacity:1;}
  7.   80% { -webkit-transform:rotateX(80deg) translateZ(300px) translateY(-1780px);opacity:0;}
  8.   100% { -webkit-transform:rotateX(80deg) translateZ(300px) translateY(-2500px);opacity:0;}
  9. }
  10.  
  11. #crawl {
  12.   color:rgb(252,223,43);
  13.   font-family:FGD, sans-serif;
  14.   text-align:center;
  15.   font-size:36px;
  16.   opacity:0;
  17.   /* long animation */
  18.   -webkit-animation:crawl 120s linear;
  19.   /* again just once */
  20.   -webkit-animation-iteration-count: 1;
  21.   /* starting while the logo is still there */
  22.   -webkit-animation-delay:16s;
  23.   /* preserving 3D aspect for the entire animation */
  24.   -webkit-transform-style:preserve-3d;
  25. }
  26.  
  27. #crawl p.title {
  28.   font-family:FGDC, sans-serif;
  29.   /* it's a title */
  30.   text-transform:uppercase;
  31.   /* it's massive */
  32.   font-size:96px;
  33.   /* but scaled to fit inside margins */
  34.   -webkit-transform:scaleX(0.6);
  35. }
  36.  
  37. #crawl p {
  38.   /* preserve spaces */
  39.   white-space:pre;
  40. }
  41.  

The Mythical Song

Well, this demo could not miss a proper audio element:

HTML:
  1.  
  2. <audio src="/experiments/starwars.m4a" id="audio" autobuffer="autobuffer" />
  3.  

Apparently the used compression is truly good and the sound loud and clear. But who is in charge to start above song?

JavaScript

Quite hilarious all this demo does not basically need JavaScript at all except for an audio delay forced via interval:

JAVASCRIPT:
  1.  
  2. setTimeout("document.getElementById('audio').play()", 12000);
  3.  

If we have a good broadband connection and we are sure in 12 seconds we have buffered enough audio, the synchronization between JavaScript and the transition delay is almost perfect and the demo experience unique.

It is great to see this work, and I look forward to seeing what he comes up with next. It feels that with HTML5, CSS3, and the Web.Next we will be able to be much more creative. Finally, it's December, I can already imagine a CSS3 based snow effect for our pages ... no?

Posted by webreflection at 7:00 am
18 Comments

+++--
3.8 rating from 51 votes

Thursday, November 26th, 2009

If That Is An Awesome CSS3 Gallery, How Would You Call Mine?

Category: CSS, Examples

Tutorialzine is a nice blog but I think sometimes it should should re-dimension chosen titles.
I have discovered only yesterday and thanks to my good old favorite Web related italian blog, a nice (or if you prefer another) jQuery lightbox style experiment.

The post is complete with examples and explanation over PHP, CSS, jQuery, and finally jQuery UI.
So what is the problem? The title: An Awesome CSS3 Lightbox Gallery With jQuery

At the end of the day, the total size of the demo is massive, compared with what it offers, plus the only piece of CSS3 in the stylesheet is a box-shadow and a rotation via -webkit-transform.

Is That It?

If we can define awesome a basic usage of CSS3 requiring both jQuery and jQuery UI to create a Gallery, included a server side language, how can we define my latest experiment realized in half an hour and without using JavaScript, PHP, or whatever programming language at all?

The answer is simple: CSS3 and we can read how I did it via the not-minified and hopefully well commented css file.
OK, agreed my page is dynamically fake and a proof of concept, but honestly, which title would consider appropriate for above example?
Thanks in any case to Tutorialzine for the interesting step by step explanation and to let me try above experiment which works with latest WebKit, Chrome, Safari, and somehow with Firefox, I've not tried the nightly, and Opera as well but in latter cases without transitions.

P.S. for those with poor computation performances like me, here there is a fluid concept variation ;-)

Posted by webreflection at 6:00 am
35 Comments

+----
1.9 rating from 114 votes

Tuesday, September 29th, 2009

Cappuccino is a Push over

Category: Cappuccino, Examples

Elias Klughammer has implemented the Juggernaut push server in a Cappuccino app.

Always nice to have an open source bare bones sample app for a marriage like this. Nothing beats looking at the source.

Posted by Dion Almaer at 6:11 am
4 Comments

++---
2.6 rating from 40 votes

Tuesday, July 28th, 2009

Developer evangelism handbook released

Category: Examples, Presentation, Workshop

As developers, it can be hard to get your voice heard in a company. Whilst our products depend on developers building them the right way, other people seem to call the shots about where they are going.

This becomes disastrous when a company tries to reach developers with their product. Normal marketing and PR stunts normally fail to get us excited. To work around this issue, clever companies allow developers to move into a role of developer evangelists.

A developer evangelist is a spokesperson, mediator and translator between a company and both its technical staff and outside developers.

This is my job at the moment, and I was asked by people I trained if there is a handbook about the skills needed to do this job, so I wrote one.

Check out the The Developer Evangelist handbook

The handbook explains several things:

  • What developer evangelism is
  • What makes a good developer evangelist
  • How to write for the web
  • How to use social media and the web to promote content
  • How to deliver great presentations
  • How to deal with criticism of your company and what to do with the competition
  • How to write easy to understand and useful code examples
  • The handbook is Creative Commons and free to use. I am working on getting a printed version out, too.

    Posted by Chris Heilmann at 3:59 pm
    3 Comments

    ++++-
    4.5 rating from 21 votes

    Friday, July 3rd, 2009

    It’s Friday. Play some drums…. HTML5 style

    Category: Examples, Sound

    Brian Arnold created a fun sample drum machine simulator using HTML5 <audio>.

    JAVASCRIPT:
    1.  
    2. function playBeat() {
    3.         if (isPlaying) {
    4.                 var nextBeat = 60000 / curTempo / 4;
    5.                 // Turn off all lights on the tracker's row
    6.                 $("#tracker li.pip").removeClass("active");
    7.                 // Stop all audio
    8.                 stopAllAudio();
    9.                 // Light up the tracker on the current pip
    10.                 $("#tracker li.pip.col_" + curBeat).addClass("active");
    11.                 // Find each active beat, play it
    12.                 $(".soundrow[id^=control] li.pip.active.col_" + curBeat).each(function(i){
    13.                         document.getElementById($(this).data('sound_id')).play();
    14.                 });
    15.                 // Move the pip forward
    16.                 curBeat = (curBeat + 1) % 16;
    17.                 // Schedule the next one
    18.                 setTimeout(playBeat, nextBeat);
    19.         }
    20. }
    21.  

    That's not all Brian is working on:

    I'm also working on something like the ToneMatrix or Tenori-on (Flash and actual devices, respectively) in pure HTML/JS. It works too, but the sounds aren't exactly designed to be great together (it's currently working on a C scale) and so if you're careful, you can get some decent sound but otherwise, it'll hurt your ears.

    Posted by Dion Almaer at 8:11 am
    11 Comments

    +++--
    3.8 rating from 24 votes

    Friday, June 26th, 2009

    Fun with text-shadow

    Category: CSS, Examples

    Zach Johnson is at it again, this time giving us a fun Friday treat with CSS text shadow, all via:

    JAVASCRIPT:
    1.  
    2. document.getElementById('text-shadow-box').onmousemove = function(e) {
    3.     var xm = e.clientX - 300;
    4.     var ym = e.clientY - 175;
    5.     var d = Math.sqrt(xm*xm + ym*ym);
    6.     text.style.textShadow = -xm + 'px ' + -ym + 'px ' + (d / 5 + 10) + 'px black';
    7.    
    8.     xm = e.clientX - 600;
    9.     ym = e.clientY - 450;
    10.     spot.style.backgroundPosition = xm + 'px ' + ym + 'px';
    11. }
    12.  

    Posted by Dion Almaer at 11:26 am
    14 Comments

    +++--
    3.9 rating from 36 votes

    Thursday, June 11th, 2009

    Animating SVG with Canvas and Burst

    Category: Examples

    Christopher Blizzard and his team are doing great write-ups on hacks.mozilla.org as they celebrate 35 days of Open Web goodness.

    They just posted on the work of Alistair MacDonald who used his Burst engine to demonstrate taking SVG and having Burst load it and convert it all to JavaScript objects that are rendered inside of a canvas.

    To get a feel for the code, view source:

    JAVASCRIPT:
    1.  
    2.     Burst.defaults.debug=false;
    3.    
    4.     Burst.defaults.ease="easeOutQuad";
    5.     Burst.timeline("chassis", 0, 100, 1, true)
    6.       .shape("car", "car.svg", "svg", 0, 0, 1, 0)
    7.         .cut("wheel1;wheel2")       
    8.         .group("chassis")
    9.           .track("top").key(0,0).key(50,-20).key(70,0)       
    10.     ;
    11.    
    12.     Burst.defaults.ease="linear";
    13.     Burst.timeline("wheels", 0, 100, 1, true)
    14.       .shape("car", "car.svg", "svg", 0, 0, 1, 0)
    15.         .cut("chassis")         
    16.         .group("wheel1").track("centerX").key(0,230).track("centerY").key(0,350)
    17.           .track("rot").key(0,0).key(100,-360)
    18.         .group("wheel2").track("centerX").key(0,430).track("centerY").key(0,350)
    19.           .track("rot").key(0,0).key(100,-360)
    20.     ;
    21.    
    22.     Burst.timeline("carObject", 0, 300, 3, false)     
    23.       .track("scl").key(0,.5)
    24.       .track("left").key(0,400).key(300,-195)
    25.       .inherit("wheels")
    26.       .inherit("chassis")
    27.     ;
    28.    
    29.  
    30.     Burst.timeline("boom", 0, 10, 1, true)
    31.       .shape("boom", "boom.svg", "svg", 0, 0, 1, 0)
    32.     ;
    33.    
    34.     Burst.start("carObject", function(){
    35.         Burst.timeline("chassis").paused=true;
    36.         Burst.timeline("wheels").paused=true;
    37.         Burst.start("boom");
    38.     });
    39.  

    and then watch the tutorial that shows how you can take Inkscape and quickly get animating.

    View the Ogg or mp4 versions.

    Also check out the other items:

    Posted by Dion Almaer at 7:54 am
    7 Comments

    ++++-
    4.4 rating from 17 votes

    Wednesday, June 10th, 2009

    Styling buttons as links allowing you to POST away

    Category: CSS, Examples

    Have you ever wanted to just <a href="path" action="post">? Remember the hub-ub with the old Google Web Accelerator and how it started to crawl links to delete actions that were mistakenly using GET?

    Natalie Downe has written up a piece on styling HTML buttons as links which means that you can somewhat get the same effect. It shows how you can use an inline span to get the hover effect, taking:

    HTML:
    1.  
    2. <button type="submit" class="link"><span>Hello there I am a button</span></button>
    3.  

    and styling it with:

    CSS:
    1.  
    2. button {
    3.         overflow: visible;
    4.         width: auto;
    5. }
    6. button.link {
    7.         font-family: "Verdana" sans-serif;
    8.         font-size: 1em;
    9.         text-align: left;
    10.         color: blue;
    11.         background: none;
    12.         margin: 0;
    13.         padding: 0;
    14.         border: none;
    15.         cursor: pointer;
    16.        
    17.         -moz-user-select: text;
    18.  
    19.         /* override all your button styles here if there are any others */
    20. }
    21. button.link span {
    22.         text-decoration: underline;
    23. }
    24. button.link:hover span,
    25. button.link:focus span {
    26.         color: black;
    27. }
    28.  

    You can see the simple example in action.

    Posted by Dion Almaer at 3:15 am
    16 Comments

    ++++-
    4 rating from 14 votes

    Thursday, June 4th, 2009

    Image thumbnail crop tool with Processing.js and PHP GD

    Category: Examples

    Matt Schoen has written a nice image thumbnail tool that lets you zoom in on the part of the image that you want to crop for a thumbnail.

    You can check out the Processing code that does the work:

    JAVASCRIPT:
    1.  
    2. void setup(){
    3.     size(600, 600);     //for internal size variables
    4.     frameRate(30);      //set our draw rate
    5.     stroke(0);    //all lines will be black
    6.     color c = color(128,128,128,128);
    7.     fill(c);        //all filled rects will be 50% gray with 50% transparency
    8. }
    9.  
    10. int xoffset = 0;        //temp variable while we're dragging the mouse
    11. int yoffset = 0;
    12. int xpos = 0;      //where to draw the image
    13. int ypos = 0;
    14. int startx, starty;
    15. int prsd = 0;
    16. PImage a;  // Declare variable "a" of type PImage 
    17. a = loadImage("img.jpg"); // Load the images into the program
    18. double s = 1.0;
    19. double r = 1.0;
    20.  
    21. void draw(){    //this method is called by processingjs at the above frame rate
    22.         background(0)//draw a black background
    23.                 //for testing purposes, to figure out the scaling
    24.         scale(s);
    25.         image(a, xpos - xoffset, ypos - yoffset);       //draw scaled image
    26.         scale(1/s);     
    27.         //for whatever reason, using "scale(1.0);" didn't reset the scale here.  I have no idea why...
    28.        
    29.         //draw ghosting frame
    30.         noStroke();     //we don't want borders on these rects
    31.         rect(0,0,600,100);
    32.         rect(0,500,600,100);
    33.         rect(0,100,100,400);
    34.         rect(500,100,100,400);
    35.         line(0,560,600,560);
    36.        
    37.         //draw the "button" regions
    38.         line(300,560,300,600);
    39.         line(570, 0, 570, 30);
    40.         line(570, 30, 600, 30);
    41. }
    42. void mousePressed(){
    43.         if(mouseY> 560){
    44.                 if(mouseX> 300){
    45.                         s += .1;
    46.                 }
    47.                 else{
    48.                          s -= .1;
    49.                 }
    50.         }
    51.         if(mouseY <30 && mouseX> 570)
    52.                 link("http://www.pagefoundry.net/matt/jquery/renderthumb.php?x=" + xpos + "&y=" + ypos + "&s=" + s);
    53.         prsd = 1;
    54.         startx = mouseX;
    55.         starty = mouseY;
    56. }
    57. void mouseDragged(){
    58.         if(prsd> 0){
    59.         xoffset = startx - mouseX;
    60.         yoffset = starty - mouseY;
    61.         }
    62. }
    63. void mouseReleased(){
    64.         prsd = 0;
    65.         xpos -= xoffset;
    66.         ypos -= yoffset;
    67.         xoffset = 0;
    68.         yoffset = 0;   
    69. }
    70.  

    Posted by Dion Almaer at 7:08 am
    9 Comments

    ++---
    2.5 rating from 33 votes

    Friday, May 22nd, 2009

    JSPlacemaker – Geo data extraction in pure JavaScript

    Category: Examples, JavaScript

    Content extraction is still a hot topic on the web. We have lots of great text content but not much clue as to what those texts are. To make it more obvious we do term extraction for tagging but also geo location extraction for giving the text some spacial reference.

    A fairly new web service that does this for us is Yahoo's Placemaker. What it does is analyze a text (or the document defined by an HTML or feed URL) and give you back all the geographical locations that are mentioned in it. Pretty awesome, but the problem is that the API only allows for POST values and has either XML or RSS output. This means you can't do it in simple XHR because of the cross-domain problem and you can't use generated script nodes as there is no JSON output. You'd have to use a server-side proxy service. This is pretty easy with PHP and cURL as explained in this blog post but can be annoying, too.

    That's why I wrote a small wrapper in JavaScript that allows JS access to the Placemaker service called JS-Placemaker. I am not hosting a proxy for you, all you need to do is get your own application ID for Placemaker and use the JavaScript which you can host yourself if you wanted to.

    Analyzing a text using JS-Placemaker is as easy as this:

    JAVASCRIPT:
    1. Placemaker.config.appID='YOUR-APP-ID';
    2. Placemaker.getPlaces('Hi I am Chris, I live in London. Originally I am from Germany',
    3.  function(o){
    4.    console.log(o);
    5.  },
    6.  'en-uk');

    The console output is an object or an array of places the service returned from the text:

    JS-Placemaker - geolocate texts in JavaScript by you.

    The first parameter is the text you want to analyze (this could be a pointer to the innerHTML of a DOM element, for example), the second is the callback function and the third the locale of the text - the demo page shows that Placemaker groks several languages.

    Under the hood, JS-Placemaker uses YQL to work around the issue of proxying the request. YQL allows you to define your own data tables and even allows for doing JavaScript conversion of data on the server-side before sending it on. YQL has JSON output, so I was able to use that to access Placemaker in JavaScript.

    The geo.placemaker Open Table was built by Balaji Narayanan and Tom Hughes-Croucher and can be used in YQL directly. Say you want to get the geo location data from the Slashdot Homepage in JavaScript, you can do this with the following statement in YQL.

    CODE:
    1. select * from geo.placemaker where documentURL="http://slashdot.org" and documentType="text/html" and appid="...the app id..."

    You can choose JSON as the output and you get the data a a nice object.. Define a callback method and you could use it directly in a script node.

    Have a Play with the YQL console using the Open Table, but better get your own AppID, before this one exceeds the daily limits.

    Posted by Chris Heilmann at 9:28 am
    3 Comments

    +++--
    3.7 rating from 23 votes

    Thursday, April 30th, 2009

    YQL execute now allows you to convert scraped data with server side JavaScript

    Category: Examples, JavaScript, Yahoo!

    I am a big fan of YQL, a terribly easy and fuss-free way to access APIs and mix data retrieved from them in a simple, SQL style language. Say for example you want photos of Paris,France from Flickr that are licensed with Creative Commons attribution, you can do this with a single command:

    CODE:
    1. select * from flickr.photos.info where photo_id in (select id from flickr.photos.search where woe_id in (select woeid from geo.places where text='paris,france') and license=4)

    Try it out here and you see what I mean.

    The next step of this interface was to open it out to the public. You can define an "Open Table" as a simple XML schema and bring your own API into this interface with that.

    One thing that's been burning on my tongue to tell the world about has been finally released now: YQL execute. Instead of making the YQL language itself much more complex (and thus running in circles) we now allow you to embed JavaScript in the Open Table XML that will run on the YQL server and allow you to access other web services, authenticate and scrape HTML with JavaScript and E4X. As Simon Willison put it:

    This is nuts (in a good way). Yahoo!’s intriguing universal SQL-style XML/JSONP web service interface now supports JavaScript as a kind of stored procedure language, meaning you can use JavaScript and E4X to screen-scrape web pages, then query the results with YQL.

    Using this, you can augment the original functionality of YQL to whatever you need. For example, you can scrape HTML with YQL using XPATH, but there was no way to use CSS selectors. Using an open table that invokes James Padolsey's css2xpath JavaScript on the server side, this is now possible.

    CODE:
    1. use 'http://yqlblog.net/samples/data.html.cssselect.xml' as data.html.cssselect; select * from data.html.cssselect where url="www.yahoo.com" and css="#news a"

    Run this query in YQL

    The data table is pretty easy:

    XML:
    1. <?xml version="1.0" encoding="UTF-8" ?>
    2. <table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
    3.   <meta>
    4.     <samplequery>select * from {table} where url="www.yahoo.com" and css="#news a"</samplequery>
    5.   </meta>
    6.   <bindings>
    7.   <select itemPath="" produces="XML">
    8.     <urls>
    9.       <url></url>
    10.  
    11.     </urls>
    12.     <inputs>
    13.       <key id="url" type="xs:string" paramType="variable" required="true" />
    14.       <key id="css" type="xs:string" paramType="variable" />
    15.     </inputs>
    16.       <execute><![CDATA[
    17.    //include css to xpath convert function
    18.    y.include("http://james.padolsey.com/scripts/javascript/css2xpath.js");
    19.    var query = null;
    20.    if (css) {
    21.       var xpath = CSS2XPATH(css);
    22.       y.log("xpath "+xpath);
    23.       query = y.query("select * from html where url=@url and xpath=\""+xpath+"\"",{url:url});
    24.    } else {
    25.       query = y.query("select * from html where url=@url",{url:url});
    26.    }
    27.    response.object = query.results;
    28.       ]]></execute>
    29.     </select>
    30.   </bindings>
    31. </table>

    Check the official Yahoo Developer Network blog post on YQL execute for more examples, including authentication examples for flickr and netflix.

    Posted by Chris Heilmann at 9:28 am
    15 Comments

    +++--
    3.9 rating from 27 votes

    Wednesday, April 22nd, 2009

    Dynamic Content Injection with HTML5 Canvas and Video

    Category: Canvas, Examples, Firefox, Video

    Paul Rouget and Tristan Nitot are having a lot of obvious fun with Canvas and <video> these days. The latest goodness is a demo by Paul that shows real-time dynamic content injection.

    Notice the Firefox logo in between the two phones with bright screens? That is injected into the world thanks to Canvas.

    How did Paul do this? He told us:

    Obviously, I use the <video/> tag.
    But what you see is not the video element (display: none;), but a
    <canvas/> tag.
    All the patterns you see on the top right are regular <img/>,
    <video/> and <canvas/> elements. The play/pause button is
    a <svg/> element
    (position: absolute;) on the top of the main <canvas/> element.

    A canvas element provides a method named drawImage which let you
    inject the content of a DOM element in the canvas (like a screenshot). It works
    with three kinds of elements: <img/>, <canvas/> and
    <video/>.

    When you click on the <svg/> button, the Javascript code launches the
    main video. Then, the main javascript loop is executed each 10
    milliseconds.

    Here are key things that occur during the main loop:

    • first, the content of the video is injected in the main canvas. That's why
      the canvas element looks like a video element;
    • second, the position of the 2 brighter areas of the canvas are computed
      (you have access to all pixels values);
    • third, the required transformation is computed (rotation, scale,
      translation);
    • fourth, the content of the selected pattern is injected in the main canvas
      following the transformation.

    A little drawing:

    DCI

    Check out the demo in a bleeding edge Firefox browser, or watch the video:

    Crazy cool stuff :)

    Posted by Dion Almaer at 8:50 am
    5 Comments

    ++++-
    4.5 rating from 41 votes

    Friday, April 3rd, 2009

    Auto Scrolling Parallax Effect in CSS

    Category: CSS, Examples

    Paul Hayes is off doing more fun things, this time creating an auto scrolling parallax effect with CSS, specifically using multiple background images on a single element and the -webkit-transition property to provide the auto-scrolling.

    All with a bit o' CSS:

    CSS:
    1.  
    2. #background {
    3.         background: url('../images/foreground.png') 5% 5%,
    4.                 url('../images/midground.png') 20% 20%,
    5.                 url('../images/background.png') 90% 110%;
    6.         top: 218px;
    7.         left: 0;
    8.         right: 0;
    9.         bottom: 0;
    10.         position: fixed;
    11.         -webkit-transition: left 300s linear;
    12. }
    13.  
    14. #experiment:target #background {
    15.         left: -5000px;
    16. }
    17.  
    18. #experiment:hover #background {
    19.         left: -9999px;
    20. }
    21.  

    Posted by Dion Almaer at 1:01 am
    5 Comments

    +----
    1.4 rating from 252 votes

    Next Page »