How clean "semantic" markup can power simple Facebook Connect integrations

The Guardian Open Platform
The Guardian Open PlatformThe Guardian Open Platform
How clean semantic
 markup in your HTML can
 power Facebook Connect
 Chris Thorpe




FACEBOOK DEVELOPER GARAGE FOWA EDITION


So this looks like a bit of an odd title
Semantic
                                         Web




FACEBOOK DEVELOPER GARAGE FOWA EDITION


Do I mean this? Well no not yet, although RDF and other forms of semantic markup are gaining ground
but some of the principles which underly RDF’s precursor - semantically marked up HTML or XHTML
FACEBOOK DEVELOPER GARAGE FOWA EDITION


Stuff more like this, either marked up in real microformats like hAtom or the wonderful hRecipe. If
more publishers can build these sorts of formats into their products then we’ll be able to make really
simple little bits of code which can extract, scrape and most importantly extend the information and
functionality of pages and sites
<ul id="clippings">
     
     <li class="a-clipping">
     
     
     <div class="clipping-contents" id="clipping-265621">
     
     
     
    <h2><a href="http://www.guardian.co.uk/media/2009/aug/26/big-brother-dropped-
     channel-4">Big Brother axed by Channel 4</a></h2>
     
     
     
    <div class="clipping-trail-text" id="clipping-trail-text-265621">Broadcaster
     confirms that reality show will be dropped after 11th series in 2010. By Mark Sweney and Leigh
     Holmwood</div>
     
     
     
    <p class="clipped-on" id="clipped-on-265621">Clipped on 26 August 2009&nbsp;
     
     
     
    
    <a class="show-edit-clipping" href="http://www.guardian.co.uk/tools/clipping/
     265621/edit">Edit</a>
     
     
     
    </p>
     
     
     </div>
     
     </li>
     
     <li class="a-clipping">
     
     
     <div class="clipping-contents" id="clipping-265614">
     
     
     
    <h2><a href="http://www.guardian.co.uk/world/2009/aug/26/us-senator-ted-kennedy-
     dies" >Senator Ted Kennedy dies aged 77</a></h2>
     
     
     
    <div id="clipping-trail-text-265614">One of the most influential and longest
     serving senators in US history had battled brain cancer since May 2008</div>
     
     
     
    <p class="clipped-on" id="clipped-on-265614">Clipped on 26 August 2009&nbsp;
     
     
     
    
    <a class="show-edit-clipping" href="http://www.guardian.co.uk/tools/clipping/
     265614/edit" name="&lid={yourClippings}{Edit}&lpos={yourClippings}{5}">Edit</a>
     
     
     
    </p>
     
     
     </div>
     
     </li>
     </ul>




FACEBOOK DEVELOPER GARAGE FOWA EDITION


But we can start today with HTML with some simple semantic markup telling us what each bit does, like
this rather simplified bit from The Guardian
FACEBOOK DEVELOPER GARAGE FOWA EDITION


Which outputs something which looks a bit like this
<ul>
       
     <li>
       
     
     <div>
       
     
     
     <h2><a href="">Title</a></h2>
       
     
     
     <div>Trail text</div>
       
     
     
     <p>Date
       
     
     
     
    <a href="">Edit</a>
       
     
     
     </p>
       
     
     </div>
       
     </li>
       </ul>




FACEBOOK DEVELOPER GARAGE FOWA EDITION


And if we simplify it further we get this... not too interesting or useful... and certainly not semantic, but
it shows the structure
URL          title


                                                          trail text


                                                          actions




FACEBOOK DEVELOPER GARAGE FOWA EDITION


What we get from this sort of structure is this
<ul id="clippings">
       
     <li class="a-clipping">
       
     
     <div class="clipping-contents" id="clipping-XXXXXX">
       
     
     
    <h2><a href="">Title</a></h2>
       
     
     
    <div class="clipping-trail-text" id="clipping-trail-text-XXXXXX">Trail text</div>
       
     
     
    <p class="clipped-on" id="clipped-on-XXXXXX">Date
       
     
     
    
    <a class="show-edit-clipping" href="">Edit</a>
       
     
     
    </p>
       
     
     </div>
       
     </li>
       </ul>




FACEBOOK DEVELOPER GARAGE FOWA EDITION


We can make it more semantic with a few id’s and classes which relate to the function of the text
contained within some of the nodes
URL   title


                                                   trail text




FACEBOOK DEVELOPER GARAGE FOWA EDITION


And when you look at it, this
FACEBOOK DEVELOPER GARAGE FOWA EDITION


has a lot in common with the sort of things you’d want to go into the stream
<ul id="clippings">
       
     <li class="a-clipping">
       
     
     <div class="clipping-contents" id="clipping-XXXXXX">
       
     
     
    <h2><a href="">Title</a></h2>
       
     
     
    <div class="clipping-trail-text" id="clipping-trail-text-XXXXXX">Trail text</div>
       
     
     
    <p class="clipped-on" id="clipped-on-XXXXXX">Date
       
     
     
    
    <a class="show-edit-clipping" href="">Edit</a>
       
     
     
    </p>
       
     
     </div>
       
     </li>
       </ul>




FACEBOOK DEVELOPER GARAGE FOWA EDITION


So how do we get from this on The Guardian
FACEBOOK DEVELOPER GARAGE FOWA EDITION


to this on Facebook
FACEBOOK DEVELOPER GARAGE FOWA EDITION


which brings us to this...

The Guardian is interested in all sorts of things to do with identity and distributed/aggregated identity
and one really great way to learn is to experiment and prototype
<ul id="clippings">
       
     <li class="a-clipping">
       
     
     <div class="clipping-contents" id="clipping-XXXXXX">
       
     
     
    <h2><a href="">Title</a></h2>
       
     
     
    <div class="clipping-trail-text" id="clipping-trail-text-XXXXXX">Trail text</div>
       
     
     
    <p class="clipped-on" id="clipped-on-XXXXXX">Date
       
     
     
    
    <a class="show-edit-clipping" href="">Edit</a>
       
     
     
    </p>
       
     
     </div>
       
     </li>
       </ul>




FACEBOOK DEVELOPER GARAGE FOWA EDITION


So if we want to go from this
FACEBOOK DEVELOPER GARAGE FOWA EDITION


to this sort of thing, how do we do it simply and in a prototype way, in say about an hour to test out
how it works so we can make a case for it to go into production and help the engineers
FACEBOOK DEVELOPER GARAGE FOWA EDITION


this is a good start, JQuery is a really lovely JavaScript framework and since at it’s most basic level
Facebook Connect is a client side development environment a good JavaScript libary is all we need to
build a prototype
<ul id="clippings">
       
     <li class="a-clipping">
       
     
     <div class="clipping-contents" id="clipping-XXXXXX">
       
     
     
    <h2><a href="">Title</a></h2>
       
     
     
    <div class="clipping-trail-text" id="clipping-trail-text-XXXXXX">Trail text</div>
       
     
     
    <p class="clipped-on" id="clipped-on-XXXXXX">Date
       
     
     
    
    <a class="show-edit-clipping" href="">Edit</a>
       
     
     
    </p>
       
     
     </div>
       
     </li>
       </ul>




FACEBOOK DEVELOPER GARAGE FOWA EDITION


So how do we get the good bits from this...
<ul id="clippings">
        
     <li class="a-clipping">
        
     
     <div class="clipping-contents" id="clipping-XXXXXX">
        
     
     
    <h2><a href="">Title</a></h2>
        
     
     
    <div class="clipping-trail-text" id="clipping-trail-text-XXXXXX">Trail text</div>
        
     
     
    <p class="clipped-on" id="clipped-on-XXXXXX">Date
        
     
     
    
    <a class="show-edit-clipping" href="">Edit</a>
        
     
     
    </p>
        
     
     </div>
        
     </li>
        </ul>





      var title = $('a', $('#clipping-'+ id)).html();

      var trailtext = $('#clipping-trail-text-'+ id).html();

      var href = $('a', $('#clipping-'+ id)).attr('href');




FACEBOOK DEVELOPER GARAGE FOWA EDITION


    it’s pretty easy, it’s actually about 3 lines of JQuery get us the relevant bits of content if the content is
    marked up well, so how do we put it together with Connect
actions




FACEBOOK DEVELOPER GARAGE FOWA EDITION


but how would we add some actions to post to Facebook
1
                            2
                                                                                        actions




FACEBOOK DEVELOPER GARAGE FOWA EDITION


well actually part of the clue is that within the UL there is an iterator waiting to be unlocked
<ul id="clippings">
     
     <li class="a-clipping">
     
     
     <div class="clipping-contents" id="clipping-XXXXXX">
     
     
     
    <h2><a href="">Title</a></h2>

    1
     
     
     
    <div class="clipping-trail-text" id="clipping-trail-text-XXXXXX">Trail text</div>
     
     
     
    <p class="clipped-on" id="clipped-on-XXXXXX">Date
     
     
     
    
    <a class="show-edit-clipping" href="">Edit</a>
     
     
     
    </p>
     
     
     </div>
     
     </li>
     
     <li class="a-clipping">
     
     
     <div class="clipping-contents" id="clipping-YYYYYY">


    2
     
     
     
    <h2><a href="">Title</a></h2>
     
     
     
    <div class="clipping-trail-text" id="clipping-trail-text-YYYYYY">Trail text</div>
     
     
     
    <p class="clipped-on" id="clipped-on-YYYYYY">Date
     
     
     
    
    <a class="show-edit-clipping" href="">Edit</a>
     
     
     
    </p>
     
     
     </div>
     
     </li>
     </ul>




FACEBOOK DEVELOPER GARAGE FOWA EDITION


We can build the iterator out of the HTML and JQuery, within the UL which has the unique id of
clippings there are DIVs which have a class of clipping-contents

and because we’ve got the HTML maked up with the clipping id we can do something interesting with
this
<ul id="clippings">
     
     <li class="a-clipping">
     
     
     <div class="clipping-contents" id="clipping-265621">
     
     
     </div>
     
     </li>
     
     <li class="a-clipping">
     
     
     <div class="clipping-contents" id="clipping-265614">
     
     
     </div>
     
     </li>
     </ul>


     $("#clippings .clipping-contents").each( function() {
     
    var currentid = $(this).attr('id').replace('clipping-', '');
     
    $('#clipped-on-'+ currentid).append(" | <a href="javascript:onPost("+ currentid +")">share
     on Facebook</a>");
     });




FACEBOOK DEVELOPER GARAGE FOWA EDITION


like this, which basically says for each time you find a something with a class of clipping-contents then
get the content id of it through a bit of JavaScript string manipulation
<ul id="clippings">
     
     <li class="a-clipping">
     
     
     <div class="clipping-contents" id="clipping-265621">
     
     
     </div>
     
     </li>
     
     <li class="a-clipping">
     
     
     <div class="clipping-contents" id="clipping-265614">
     
     
     </div>
     
     </li>
     </ul>


     $("#clippings .clipping-contents").each( function() {
     
    var currentid = $(this).attr('id').replace('clipping-', '');
     
    $('#clipped-on-'+ currentid).append(" | <a href="javascript:onPost("+ currentid +")">share
     on Facebook</a>");
     });




FACEBOOK DEVELOPER GARAGE FOWA EDITION




then in the node which has an id of clipped-on and that content id append a piece of HTML which gives
the link to share on Facebook
new actions



FACEBOOK DEVELOPER GARAGE FOWA EDITION




then in the node which has an id of clipped-on and that content id append a piece of HTML which gives
the link to share on Facebook
<script type="text/javascript">
     
     function onConnected() {
     
    
    
    $('#connectbutton').remove();
     
    
    
    $('#connectdetails').show();
     
    $("#clippings .clipping-contents").each( function() {
     
    var currentid = $(this).attr('id').replace('clipping-', '');
     
    $('#clipped-on-'+ currentid).append(" | <a href="javascript:onPost("+ currentid +")">share
     on Facebook</a>");
             
      });
     
    
    }

     
    
     FB.init("MY_API_KEY_FOR_MY_APP", "/xd_receiver.htm", {"ifUserConnected":onConnected});

     </script>




FACEBOOK DEVELOPER GARAGE FOWA EDITION


we can now add in some of the simple Connect stuff
<script type="text/javascript">
     
     function onConnected() {
     
    
    
    $('#connectbutton').remove();
     
    
    
    $('#connectdetails').show();
     
    $("#clippings .clipping-contents").each( function() {
     
    var currentid = $(this).attr('id').replace('clipping-', '');
     
    $('#clipped-on-'+ currentid).append(" | <a href="javascript:onPost("+ currentid +")">share
     on Facebook</a>");
             
      });
     
    
    }

     
    
     FB.init("MY_API_KEY_FOR_MY_APP", "/xd_receiver.htm", {"ifUserConnected":onConnected});

     </script>




FACEBOOK DEVELOPER GARAGE FOWA EDITION


we can now add in some of the simple Connect stuff
<script type="text/javascript">
     
     function onConnected() {
     
    
    
    $('#connectbutton').remove();
     
    
    
    $('#connectdetails').show();
     
    $("#clippings .clipping-contents").each( function() {
     
    var currentid = $(this).attr('id').replace('clipping-', '');
     
    $('#clipped-on-'+ currentid).append(" | <a href="javascript:onPost("+ currentid +")">share
     on Facebook</a>");
             
      });
     
    
    }

     
    
     FB.init("MY_API_KEY_FOR_MY_APP", "/xd_receiver.htm", {"ifUserConnected":onConnected});

     </script>




FACEBOOK DEVELOPER GARAGE FOWA EDITION


we can now add in some of the simple Connect stuff
<div id="connectbutton">
     
    <h2>Share your clippings with your friends on Facebook</h2>
     
    <fb:login-button size="large" background="white" length="long"></fb:login-button>
     </div>

     <div id="connectdetails">
     
    <fb:profile-pic uid="loggedinuser" facebook-logo="true" size="thumb" linked="true"></
     fb:profile-pic> <fb:name uid="loggedinuser" useyou="false"></fb:name>
     </div>



     <script type="text/javascript">
     
     function onConnected() {
     
    $('#connectbutton').remove();
     
    $('#connectdetails').show();
     
    $("#clippings .clipping-contents").each( function() {
     
    var currentid = $(this).attr('id').replace('clipping-', '');
     
    $('#clipped-on-'+ currentid).append(" | <a href="javascript:onPost("+ currentid +")">share
     on Facebook</a>");
             
      });
     
    
    }

     $('#connectdetails').hide();
     FB.init("MY_API_KEY_FOR_MY_APP", "/xd_receiver.htm", {"ifUserConnected":onConnected});

     </script>




FACEBOOK DEVELOPER GARAGE FOWA EDITION


and can add in a pair of divs to contain the Connect login button and the Connect details, we’ll hide the
Connect details div by default on page load and if the user connects or is connected we’ll hide the
Connect button div and show the Connect details one
function onPost(id) {
     
     var title = $('a', $('#clipping-'+ id)).html();
     
     var trailtext = $('#clipping-trail-text-'+ id).html();
     
     var href = $('a', $('#clipping-'+ id)).attr('href');
     
     var attachment = {
     
     
    
    
    
    'name': title,
     
     
    
    
    
    'href': href,
     
     
    
    
    
    'caption': '{*actor*} just clipped a link on The Guardian and shared
     it.',
     
     
    
    
    
    'description': trailtext,
     
     
    
    
    };
     
     FB.Connect.streamPublish('', attachment, null, null, 'Tell people about your
     clipping');
    
    
     }
     
     




FACEBOOK DEVELOPER GARAGE FOWA EDITION


and then we’ll roll up the pieces of JavaScript where we were assembling the content to go into the
stream into a handler for when the user clicks the link and pass them as an attachment to the
FB.Connect.streamPublish method
function onPost(id) {
     
     var title = $('a', $('#clipping-'+ id)).html();
     
     var trailtext = $('#clipping-trail-text-'+ id).html();
     
     var href = $('a', $('#clipping-'+ id)).attr('href');
     
     var attachment = {
     
     
    
    
    
    'name': title,
     
     
    
    
    
    'href': href,
     
     
    
    
    
    'caption': '{*actor*} just clipped a link on The Guardian and shared
     it.',
     
     
    
    
    
    'description': trailtext,
     
     
    
    
    };
     
     FB.Connect.streamPublish('', attachment, null, null, 'Tell people about your
     clipping');
    
    
     }
     
     




FACEBOOK DEVELOPER GARAGE FOWA EDITION


and then we’ll roll up the pieces of JavaScript where we were assembling the content to go into the
stream into a handler for when the user clicks the link and pass them as an attachment to the
FB.Connect.streamPublish method
FACEBOOK DEVELOPER GARAGE FOWA EDITION


and here’s how it works...
FACEBOOK DEVELOPER GARAGE FOWA EDITION


time to connect
FACEBOOK DEVELOPER GARAGE FOWA EDITION


click Share on Facebook
FACEBOOK DEVELOPER GARAGE FOWA EDITION


Up pops the feed box
FACEBOOK DEVELOPER GARAGE FOWA EDITION


Up pops the feed box
What next?
 Well we have an API for our
 content, so it could be that
 you could make socially
 connected content widgets
 for your site.



FACEBOOK DEVELOPER GARAGE FOWA EDITION
Thank you
 http://www.guardian.co.uk/open-platform
 Twitter: @openplatform

 chris.thorpe@guardian.co.uk




FACEBOOK DEVELOPER GARAGE FOWA EDITION
1 of 37

Recommended

HTML5 and the web of tomorrow! by
HTML5  and the  web of tomorrow!HTML5  and the  web of tomorrow!
HTML5 and the web of tomorrow!Christian Heilmann
20.7K views95 slides
Introduction to HTML5 by
Introduction to HTML5Introduction to HTML5
Introduction to HTML5Terry Ryan
7.5K views107 slides
HTML5: Smart Markup for Smarter Websites [Future of Web Apps, Las Vegas 2011] by
HTML5: Smart Markup for Smarter Websites [Future of Web Apps, Las Vegas 2011]HTML5: Smart Markup for Smarter Websites [Future of Web Apps, Las Vegas 2011]
HTML5: Smart Markup for Smarter Websites [Future of Web Apps, Las Vegas 2011]Aaron Gustafson
2.1K views179 slides
An Introduction To HTML5 by
An Introduction To HTML5An Introduction To HTML5
An Introduction To HTML5Robert Nyman
21.9K views96 slides
Upload[1] by
Upload[1]Upload[1]
Upload[1]lenimartina
923 views16 slides
WordPress and PHP - It Takes One to Know One by
WordPress and PHP - It Takes One to Know OneWordPress and PHP - It Takes One to Know One
WordPress and PHP - It Takes One to Know OneLorelle VanFossen
19K views49 slides

More Related Content

What's hot

10 Tips to make your Website lightning-fast - SMX Stockholm 2012 by
10 Tips to make your Website lightning-fast - SMX Stockholm 201210 Tips to make your Website lightning-fast - SMX Stockholm 2012
10 Tips to make your Website lightning-fast - SMX Stockholm 2012Bastian Grimm
6.4K views65 slides
Technical SEO: Crawl Space Management - SEOZone Istanbul 2014 by
Technical SEO: Crawl Space Management - SEOZone Istanbul 2014Technical SEO: Crawl Space Management - SEOZone Istanbul 2014
Technical SEO: Crawl Space Management - SEOZone Istanbul 2014Bastian Grimm
10.1K views56 slides
WordPress Performance Optimization for Mere Mortals by
WordPress Performance Optimization for Mere MortalsWordPress Performance Optimization for Mere Mortals
WordPress Performance Optimization for Mere MortalsJohn Levandowski
1.4K views51 slides
Real World Web Standards by
Real World Web StandardsReal World Web Standards
Real World Web Standardsgleddy
18K views111 slides
HTML5 workshop, part 1 by
HTML5 workshop, part 1HTML5 workshop, part 1
HTML5 workshop, part 1Robert Nyman
5.7K views66 slides
Advanced WordPress Optimization - iGaming Supershow 2012 by
Advanced WordPress Optimization - iGaming Supershow 2012Advanced WordPress Optimization - iGaming Supershow 2012
Advanced WordPress Optimization - iGaming Supershow 2012Bastian Grimm
2.1K views58 slides

What's hot(20)

10 Tips to make your Website lightning-fast - SMX Stockholm 2012 by Bastian Grimm
10 Tips to make your Website lightning-fast - SMX Stockholm 201210 Tips to make your Website lightning-fast - SMX Stockholm 2012
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
Bastian Grimm6.4K views
Technical SEO: Crawl Space Management - SEOZone Istanbul 2014 by Bastian Grimm
Technical SEO: Crawl Space Management - SEOZone Istanbul 2014Technical SEO: Crawl Space Management - SEOZone Istanbul 2014
Technical SEO: Crawl Space Management - SEOZone Istanbul 2014
Bastian Grimm10.1K views
WordPress Performance Optimization for Mere Mortals by John Levandowski
WordPress Performance Optimization for Mere MortalsWordPress Performance Optimization for Mere Mortals
WordPress Performance Optimization for Mere Mortals
John Levandowski1.4K views
Real World Web Standards by gleddy
Real World Web StandardsReal World Web Standards
Real World Web Standards
gleddy18K views
HTML5 workshop, part 1 by Robert Nyman
HTML5 workshop, part 1HTML5 workshop, part 1
HTML5 workshop, part 1
Robert Nyman5.7K views
Advanced WordPress Optimization - iGaming Supershow 2012 by Bastian Grimm
Advanced WordPress Optimization - iGaming Supershow 2012Advanced WordPress Optimization - iGaming Supershow 2012
Advanced WordPress Optimization - iGaming Supershow 2012
Bastian Grimm2.1K views
You too can be a bedwetting antfucker: Bruce Lawson, Opera, Fronteers 2011 by brucelawson
You too can be a bedwetting antfucker: Bruce Lawson, Opera, Fronteers 2011You too can be a bedwetting antfucker: Bruce Lawson, Opera, Fronteers 2011
You too can be a bedwetting antfucker: Bruce Lawson, Opera, Fronteers 2011
brucelawson20.5K views
HTML5 Introduction by dynamis
HTML5 IntroductionHTML5 Introduction
HTML5 Introduction
dynamis 4.1K views
Ss 36932418[1] by Ya Jinda
Ss 36932418[1]Ss 36932418[1]
Ss 36932418[1]
Ya Jinda1.6K views
Hardening WordPress - Friends of Search 2014 (WordPress Security) by Bastian Grimm
Hardening WordPress - Friends of Search 2014 (WordPress Security)Hardening WordPress - Friends of Search 2014 (WordPress Security)
Hardening WordPress - Friends of Search 2014 (WordPress Security)
Bastian Grimm13.5K views
Extend Joomla Forms Using Plugins by Yireo
Extend Joomla Forms Using PluginsExtend Joomla Forms Using Plugins
Extend Joomla Forms Using Plugins
Yireo1.4K views
HTML5 - Introduction by Davy De Pauw
HTML5 - IntroductionHTML5 - Introduction
HTML5 - Introduction
Davy De Pauw2.1K views
Building mobile applications with DrupalGap by Alex S
Building mobile applications with DrupalGapBuilding mobile applications with DrupalGap
Building mobile applications with DrupalGap
Alex S16.7K views
Web Standards: Fueling Innovation [Web Design World Boston '08] by Aaron Gustafson
Web Standards: Fueling Innovation [Web Design World Boston '08]Web Standards: Fueling Innovation [Web Design World Boston '08]
Web Standards: Fueling Innovation [Web Design World Boston '08]
Aaron Gustafson1.5K views
Structured Data & Schema.org - SMX Milan 2014 by Bastian Grimm
Structured Data & Schema.org - SMX Milan 2014Structured Data & Schema.org - SMX Milan 2014
Structured Data & Schema.org - SMX Milan 2014
Bastian Grimm6.1K views
State of jQuery '09 by jeresig
State of jQuery '09State of jQuery '09
State of jQuery '09
jeresig18.2K views

Similar to How clean "semantic" markup can power simple Facebook Connect integrations

Practical progressive enhancement by
Practical progressive enhancementPractical progressive enhancement
Practical progressive enhancementGraham Bird
812 views76 slides
TOSSUG HTML5 讀書會 新標籤與表單 by
TOSSUG HTML5 讀書會 新標籤與表單TOSSUG HTML5 讀書會 新標籤與表單
TOSSUG HTML5 讀書會 新標籤與表單偉格 高
1.2K views81 slides
Copy of-a-walk-around-westfall-plaza by
Copy of-a-walk-around-westfall-plazaCopy of-a-walk-around-westfall-plaza
Copy of-a-walk-around-westfall-plazahelgawerth
959 views8 slides
2022 HTML5: The future is now by
2022 HTML5: The future is now2022 HTML5: The future is now
2022 HTML5: The future is nowGonzalo Cordero
1.6K views85 slides
WordPress Accessibility: WordCamp Chicago by
WordPress Accessibility: WordCamp ChicagoWordPress Accessibility: WordCamp Chicago
WordPress Accessibility: WordCamp ChicagoJoseph Dolson
9.7K views51 slides
Expression Engine Designer by
Expression Engine   DesignerExpression Engine   Designer
Expression Engine DesignerMatias
1K views61 slides

Similar to How clean "semantic" markup can power simple Facebook Connect integrations(20)

Practical progressive enhancement by Graham Bird
Practical progressive enhancementPractical progressive enhancement
Practical progressive enhancement
Graham Bird812 views
TOSSUG HTML5 讀書會 新標籤與表單 by 偉格 高
TOSSUG HTML5 讀書會 新標籤與表單TOSSUG HTML5 讀書會 新標籤與表單
TOSSUG HTML5 讀書會 新標籤與表單
偉格 高1.2K views
Copy of-a-walk-around-westfall-plaza by helgawerth
Copy of-a-walk-around-westfall-plazaCopy of-a-walk-around-westfall-plaza
Copy of-a-walk-around-westfall-plaza
helgawerth959 views
2022 HTML5: The future is now by Gonzalo Cordero
2022 HTML5: The future is now2022 HTML5: The future is now
2022 HTML5: The future is now
Gonzalo Cordero1.6K views
WordPress Accessibility: WordCamp Chicago by Joseph Dolson
WordPress Accessibility: WordCamp ChicagoWordPress Accessibility: WordCamp Chicago
WordPress Accessibility: WordCamp Chicago
Joseph Dolson9.7K views
Expression Engine Designer by Matias
Expression Engine   DesignerExpression Engine   Designer
Expression Engine Designer
Matias1K views
Why ExpressionEngine is Great for Designers by FortySeven Media
Why ExpressionEngine is Great for DesignersWhy ExpressionEngine is Great for Designers
Why ExpressionEngine is Great for Designers
FortySeven Media4.3K views
How to Prepare a WordPress Theme for Public Release by David Yeiser
How to Prepare a WordPress Theme for Public ReleaseHow to Prepare a WordPress Theme for Public Release
How to Prepare a WordPress Theme for Public Release
David Yeiser22.1K views
Stop reinventing the wheel: Build Responsive Websites Using Bootstrap by freshlybakedpixels
Stop reinventing the wheel: Build Responsive Websites Using BootstrapStop reinventing the wheel: Build Responsive Websites Using Bootstrap
Stop reinventing the wheel: Build Responsive Websites Using Bootstrap
freshlybakedpixels9.1K views
HTML5+CSS3 (入門編) by 博史 高木
HTML5+CSS3 (入門編)HTML5+CSS3 (入門編)
HTML5+CSS3 (入門編)
博史 高木1.4K views
Creating HTML Pages by Mike Crabb
Creating HTML PagesCreating HTML Pages
Creating HTML Pages
Mike Crabb22.4K views
Take Your Markup to 11 by Emily Lewis
Take Your Markup to 11Take Your Markup to 11
Take Your Markup to 11
Emily Lewis7.3K views
ViA Bootstrap 4 by imdurgesh
ViA Bootstrap 4ViA Bootstrap 4
ViA Bootstrap 4
imdurgesh578 views
Index of jquery template 2 Minuteman Summer Web Dev. by Daniel Downs
Index of jquery template 2 Minuteman Summer Web Dev.Index of jquery template 2 Minuteman Summer Web Dev.
Index of jquery template 2 Minuteman Summer Web Dev.
Daniel Downs1.1K views
Presentation html5 css3 by thibaut by Thibaut Baillet
Presentation html5 css3 by thibautPresentation html5 css3 by thibaut
Presentation html5 css3 by thibaut
Thibaut Baillet1.4K views
Xxx by syfwan
XxxXxx
Xxx
syfwan8.6K views
webcomponents (Jfokus 2015) by Hendrik Ebbers
webcomponents (Jfokus 2015)webcomponents (Jfokus 2015)
webcomponents (Jfokus 2015)
Hendrik Ebbers2.9K views

Recently uploaded

Web Dev - 1 PPT.pdf by
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdfgdsczhcet
55 views45 slides
Uni Systems for Power Platform.pptx by
Uni Systems for Power Platform.pptxUni Systems for Power Platform.pptx
Uni Systems for Power Platform.pptxUni Systems S.M.S.A.
50 views21 slides
Perth MeetUp November 2023 by
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023 Michael Price
15 views44 slides
Future of Learning - Yap Aye Wee.pdf by
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdfNUS-ISS
41 views11 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
28 views73 slides

Recently uploaded(20)

Web Dev - 1 PPT.pdf by gdsczhcet
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet55 views
Perth MeetUp November 2023 by Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price15 views
Future of Learning - Yap Aye Wee.pdf by NUS-ISS
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdf
NUS-ISS41 views
Future of Learning - Khoong Chan Meng by NUS-ISS
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan Meng
NUS-ISS33 views
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by Vadym Kazulkin
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin75 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2216 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software225 views
Data-centric AI and the convergence of data and model engineering: opportunit... by Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier34 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu... by NUS-ISS
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
Architecting CX Measurement Frameworks and Ensuring CX Metrics are fit for Pu...
NUS-ISS37 views
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma17 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi120 views

How clean "semantic" markup can power simple Facebook Connect integrations

  • 1. How clean semantic markup in your HTML can power Facebook Connect Chris Thorpe FACEBOOK DEVELOPER GARAGE FOWA EDITION So this looks like a bit of an odd title
  • 2. Semantic Web FACEBOOK DEVELOPER GARAGE FOWA EDITION Do I mean this? Well no not yet, although RDF and other forms of semantic markup are gaining ground but some of the principles which underly RDF’s precursor - semantically marked up HTML or XHTML
  • 3. FACEBOOK DEVELOPER GARAGE FOWA EDITION Stuff more like this, either marked up in real microformats like hAtom or the wonderful hRecipe. If more publishers can build these sorts of formats into their products then we’ll be able to make really simple little bits of code which can extract, scrape and most importantly extend the information and functionality of pages and sites
  • 4. <ul id="clippings"> <li class="a-clipping"> <div class="clipping-contents" id="clipping-265621"> <h2><a href="http://www.guardian.co.uk/media/2009/aug/26/big-brother-dropped- channel-4">Big Brother axed by Channel 4</a></h2> <div class="clipping-trail-text" id="clipping-trail-text-265621">Broadcaster confirms that reality show will be dropped after 11th series in 2010. By Mark Sweney and Leigh Holmwood</div> <p class="clipped-on" id="clipped-on-265621">Clipped on 26 August 2009&nbsp; <a class="show-edit-clipping" href="http://www.guardian.co.uk/tools/clipping/ 265621/edit">Edit</a> </p> </div> </li> <li class="a-clipping"> <div class="clipping-contents" id="clipping-265614"> <h2><a href="http://www.guardian.co.uk/world/2009/aug/26/us-senator-ted-kennedy- dies" >Senator Ted Kennedy dies aged 77</a></h2> <div id="clipping-trail-text-265614">One of the most influential and longest serving senators in US history had battled brain cancer since May 2008</div> <p class="clipped-on" id="clipped-on-265614">Clipped on 26 August 2009&nbsp; <a class="show-edit-clipping" href="http://www.guardian.co.uk/tools/clipping/ 265614/edit" name="&lid={yourClippings}{Edit}&lpos={yourClippings}{5}">Edit</a> </p> </div> </li> </ul> FACEBOOK DEVELOPER GARAGE FOWA EDITION But we can start today with HTML with some simple semantic markup telling us what each bit does, like this rather simplified bit from The Guardian
  • 5. FACEBOOK DEVELOPER GARAGE FOWA EDITION Which outputs something which looks a bit like this
  • 6. <ul> <li> <div> <h2><a href="">Title</a></h2> <div>Trail text</div> <p>Date <a href="">Edit</a> </p> </div> </li> </ul> FACEBOOK DEVELOPER GARAGE FOWA EDITION And if we simplify it further we get this... not too interesting or useful... and certainly not semantic, but it shows the structure
  • 7. URL title trail text actions FACEBOOK DEVELOPER GARAGE FOWA EDITION What we get from this sort of structure is this
  • 8. <ul id="clippings"> <li class="a-clipping"> <div class="clipping-contents" id="clipping-XXXXXX"> <h2><a href="">Title</a></h2> <div class="clipping-trail-text" id="clipping-trail-text-XXXXXX">Trail text</div> <p class="clipped-on" id="clipped-on-XXXXXX">Date <a class="show-edit-clipping" href="">Edit</a> </p> </div> </li> </ul> FACEBOOK DEVELOPER GARAGE FOWA EDITION We can make it more semantic with a few id’s and classes which relate to the function of the text contained within some of the nodes
  • 9. URL title trail text FACEBOOK DEVELOPER GARAGE FOWA EDITION And when you look at it, this
  • 10. FACEBOOK DEVELOPER GARAGE FOWA EDITION has a lot in common with the sort of things you’d want to go into the stream
  • 11. <ul id="clippings"> <li class="a-clipping"> <div class="clipping-contents" id="clipping-XXXXXX"> <h2><a href="">Title</a></h2> <div class="clipping-trail-text" id="clipping-trail-text-XXXXXX">Trail text</div> <p class="clipped-on" id="clipped-on-XXXXXX">Date <a class="show-edit-clipping" href="">Edit</a> </p> </div> </li> </ul> FACEBOOK DEVELOPER GARAGE FOWA EDITION So how do we get from this on The Guardian
  • 12. FACEBOOK DEVELOPER GARAGE FOWA EDITION to this on Facebook
  • 13. FACEBOOK DEVELOPER GARAGE FOWA EDITION which brings us to this... The Guardian is interested in all sorts of things to do with identity and distributed/aggregated identity and one really great way to learn is to experiment and prototype
  • 14. <ul id="clippings"> <li class="a-clipping"> <div class="clipping-contents" id="clipping-XXXXXX"> <h2><a href="">Title</a></h2> <div class="clipping-trail-text" id="clipping-trail-text-XXXXXX">Trail text</div> <p class="clipped-on" id="clipped-on-XXXXXX">Date <a class="show-edit-clipping" href="">Edit</a> </p> </div> </li> </ul> FACEBOOK DEVELOPER GARAGE FOWA EDITION So if we want to go from this
  • 15. FACEBOOK DEVELOPER GARAGE FOWA EDITION to this sort of thing, how do we do it simply and in a prototype way, in say about an hour to test out how it works so we can make a case for it to go into production and help the engineers
  • 16. FACEBOOK DEVELOPER GARAGE FOWA EDITION this is a good start, JQuery is a really lovely JavaScript framework and since at it’s most basic level Facebook Connect is a client side development environment a good JavaScript libary is all we need to build a prototype
  • 17. <ul id="clippings"> <li class="a-clipping"> <div class="clipping-contents" id="clipping-XXXXXX"> <h2><a href="">Title</a></h2> <div class="clipping-trail-text" id="clipping-trail-text-XXXXXX">Trail text</div> <p class="clipped-on" id="clipped-on-XXXXXX">Date <a class="show-edit-clipping" href="">Edit</a> </p> </div> </li> </ul> FACEBOOK DEVELOPER GARAGE FOWA EDITION So how do we get the good bits from this...
  • 18. <ul id="clippings"> <li class="a-clipping"> <div class="clipping-contents" id="clipping-XXXXXX"> <h2><a href="">Title</a></h2> <div class="clipping-trail-text" id="clipping-trail-text-XXXXXX">Trail text</div> <p class="clipped-on" id="clipped-on-XXXXXX">Date <a class="show-edit-clipping" href="">Edit</a> </p> </div> </li> </ul> var title = $('a', $('#clipping-'+ id)).html(); var trailtext = $('#clipping-trail-text-'+ id).html(); var href = $('a', $('#clipping-'+ id)).attr('href'); FACEBOOK DEVELOPER GARAGE FOWA EDITION it’s pretty easy, it’s actually about 3 lines of JQuery get us the relevant bits of content if the content is marked up well, so how do we put it together with Connect
  • 19. actions FACEBOOK DEVELOPER GARAGE FOWA EDITION but how would we add some actions to post to Facebook
  • 20. 1 2 actions FACEBOOK DEVELOPER GARAGE FOWA EDITION well actually part of the clue is that within the UL there is an iterator waiting to be unlocked
  • 21. <ul id="clippings"> <li class="a-clipping"> <div class="clipping-contents" id="clipping-XXXXXX"> <h2><a href="">Title</a></h2> 1 <div class="clipping-trail-text" id="clipping-trail-text-XXXXXX">Trail text</div> <p class="clipped-on" id="clipped-on-XXXXXX">Date <a class="show-edit-clipping" href="">Edit</a> </p> </div> </li> <li class="a-clipping"> <div class="clipping-contents" id="clipping-YYYYYY"> 2 <h2><a href="">Title</a></h2> <div class="clipping-trail-text" id="clipping-trail-text-YYYYYY">Trail text</div> <p class="clipped-on" id="clipped-on-YYYYYY">Date <a class="show-edit-clipping" href="">Edit</a> </p> </div> </li> </ul> FACEBOOK DEVELOPER GARAGE FOWA EDITION We can build the iterator out of the HTML and JQuery, within the UL which has the unique id of clippings there are DIVs which have a class of clipping-contents and because we’ve got the HTML maked up with the clipping id we can do something interesting with this
  • 22. <ul id="clippings"> <li class="a-clipping"> <div class="clipping-contents" id="clipping-265621"> </div> </li> <li class="a-clipping"> <div class="clipping-contents" id="clipping-265614"> </div> </li> </ul> $("#clippings .clipping-contents").each( function() { var currentid = $(this).attr('id').replace('clipping-', ''); $('#clipped-on-'+ currentid).append(" | <a href="javascript:onPost("+ currentid +")">share on Facebook</a>"); }); FACEBOOK DEVELOPER GARAGE FOWA EDITION like this, which basically says for each time you find a something with a class of clipping-contents then get the content id of it through a bit of JavaScript string manipulation
  • 23. <ul id="clippings"> <li class="a-clipping"> <div class="clipping-contents" id="clipping-265621"> </div> </li> <li class="a-clipping"> <div class="clipping-contents" id="clipping-265614"> </div> </li> </ul> $("#clippings .clipping-contents").each( function() { var currentid = $(this).attr('id').replace('clipping-', ''); $('#clipped-on-'+ currentid).append(" | <a href="javascript:onPost("+ currentid +")">share on Facebook</a>"); }); FACEBOOK DEVELOPER GARAGE FOWA EDITION then in the node which has an id of clipped-on and that content id append a piece of HTML which gives the link to share on Facebook
  • 24. new actions FACEBOOK DEVELOPER GARAGE FOWA EDITION then in the node which has an id of clipped-on and that content id append a piece of HTML which gives the link to share on Facebook
  • 25. <script type="text/javascript"> function onConnected() { $('#connectbutton').remove(); $('#connectdetails').show(); $("#clippings .clipping-contents").each( function() { var currentid = $(this).attr('id').replace('clipping-', ''); $('#clipped-on-'+ currentid).append(" | <a href="javascript:onPost("+ currentid +")">share on Facebook</a>"); }); } FB.init("MY_API_KEY_FOR_MY_APP", "/xd_receiver.htm", {"ifUserConnected":onConnected}); </script> FACEBOOK DEVELOPER GARAGE FOWA EDITION we can now add in some of the simple Connect stuff
  • 26. <script type="text/javascript"> function onConnected() { $('#connectbutton').remove(); $('#connectdetails').show(); $("#clippings .clipping-contents").each( function() { var currentid = $(this).attr('id').replace('clipping-', ''); $('#clipped-on-'+ currentid).append(" | <a href="javascript:onPost("+ currentid +")">share on Facebook</a>"); }); } FB.init("MY_API_KEY_FOR_MY_APP", "/xd_receiver.htm", {"ifUserConnected":onConnected}); </script> FACEBOOK DEVELOPER GARAGE FOWA EDITION we can now add in some of the simple Connect stuff
  • 27. <script type="text/javascript"> function onConnected() { $('#connectbutton').remove(); $('#connectdetails').show(); $("#clippings .clipping-contents").each( function() { var currentid = $(this).attr('id').replace('clipping-', ''); $('#clipped-on-'+ currentid).append(" | <a href="javascript:onPost("+ currentid +")">share on Facebook</a>"); }); } FB.init("MY_API_KEY_FOR_MY_APP", "/xd_receiver.htm", {"ifUserConnected":onConnected}); </script> FACEBOOK DEVELOPER GARAGE FOWA EDITION we can now add in some of the simple Connect stuff
  • 28. <div id="connectbutton"> <h2>Share your clippings with your friends on Facebook</h2> <fb:login-button size="large" background="white" length="long"></fb:login-button> </div> <div id="connectdetails"> <fb:profile-pic uid="loggedinuser" facebook-logo="true" size="thumb" linked="true"></ fb:profile-pic> <fb:name uid="loggedinuser" useyou="false"></fb:name> </div> <script type="text/javascript"> function onConnected() { $('#connectbutton').remove(); $('#connectdetails').show(); $("#clippings .clipping-contents").each( function() { var currentid = $(this).attr('id').replace('clipping-', ''); $('#clipped-on-'+ currentid).append(" | <a href="javascript:onPost("+ currentid +")">share on Facebook</a>"); }); } $('#connectdetails').hide(); FB.init("MY_API_KEY_FOR_MY_APP", "/xd_receiver.htm", {"ifUserConnected":onConnected}); </script> FACEBOOK DEVELOPER GARAGE FOWA EDITION and can add in a pair of divs to contain the Connect login button and the Connect details, we’ll hide the Connect details div by default on page load and if the user connects or is connected we’ll hide the Connect button div and show the Connect details one
  • 29. function onPost(id) { var title = $('a', $('#clipping-'+ id)).html(); var trailtext = $('#clipping-trail-text-'+ id).html(); var href = $('a', $('#clipping-'+ id)).attr('href'); var attachment = { 'name': title, 'href': href, 'caption': '{*actor*} just clipped a link on The Guardian and shared it.', 'description': trailtext, }; FB.Connect.streamPublish('', attachment, null, null, 'Tell people about your clipping'); } FACEBOOK DEVELOPER GARAGE FOWA EDITION and then we’ll roll up the pieces of JavaScript where we were assembling the content to go into the stream into a handler for when the user clicks the link and pass them as an attachment to the FB.Connect.streamPublish method
  • 30. function onPost(id) { var title = $('a', $('#clipping-'+ id)).html(); var trailtext = $('#clipping-trail-text-'+ id).html(); var href = $('a', $('#clipping-'+ id)).attr('href'); var attachment = { 'name': title, 'href': href, 'caption': '{*actor*} just clipped a link on The Guardian and shared it.', 'description': trailtext, }; FB.Connect.streamPublish('', attachment, null, null, 'Tell people about your clipping'); } FACEBOOK DEVELOPER GARAGE FOWA EDITION and then we’ll roll up the pieces of JavaScript where we were assembling the content to go into the stream into a handler for when the user clicks the link and pass them as an attachment to the FB.Connect.streamPublish method
  • 31. FACEBOOK DEVELOPER GARAGE FOWA EDITION and here’s how it works...
  • 32. FACEBOOK DEVELOPER GARAGE FOWA EDITION time to connect
  • 33. FACEBOOK DEVELOPER GARAGE FOWA EDITION click Share on Facebook
  • 34. FACEBOOK DEVELOPER GARAGE FOWA EDITION Up pops the feed box
  • 35. FACEBOOK DEVELOPER GARAGE FOWA EDITION Up pops the feed box
  • 36. What next? Well we have an API for our content, so it could be that you could make socially connected content widgets for your site. FACEBOOK DEVELOPER GARAGE FOWA EDITION
  • 37. Thank you http://www.guardian.co.uk/open-platform Twitter: @openplatform chris.thorpe@guardian.co.uk FACEBOOK DEVELOPER GARAGE FOWA EDITION