* Places Facebook's "social plugins" inside a div ( http://developers.facebook.com/docs/plugins/ )
* Sets options according to user input or default values
* Options parameter will need a target and a type
- * Type is the name of the plugin in fbxml format. i.e: <fb:like> would have a type of like, respectively
+ * Type is the name of the plugin in fbxml format. Options: LIKE (default), LIKE-BOX, ACTIVITY, FACEPILE
* Target is the id of the document element that the text needs to be
* attached to, this target element must exist on the DOM
*
type: "LIKE-BOX",
show_faces: "true",
header: "false",
- target: 'likeboxdiv'
+ target: "likeboxdiv"
} )
This will show how many people "like" Seneca College's Facebook page, and show their profile pictures (show_faces)
website: "dsventura.blogspot.com"
},
options:{
- id : {elem:'input', type:'text', label:'Id'},
- type : {elem:"input", type:'text', label:"Type"},
- target : 'facebook-container'
+ id : {elem:"input", type:"text", label:"Id"},
+ type : {elem:"input", type:"text", label:"Type"},
+ target : "facebook-container"
}
},
_setup: function( options ) {
// facebook script requires a div named fb-root
- if( !document.getElementById('fb-root') ) {
- var fbRoot = document.createElement( 'div' );
- fbRoot.setAttribute('id', "fb-root");
+ if( !document.getElementById( "fb-root" ) ) {
+ var fbRoot = document.createElement( "div" );
+ fbRoot.setAttribute( "id", "fb-root" );
document.body.appendChild( fbRoot );
- //initialize facebook JS SDK
+
+ // initialize facebook JS SDK
+ Popcorn.getScript("http://connect.facebook.net/en_US/all.js");
window.fbAsyncInit = function() {
FB.init({
- appId : 'YOUR APP ID',
+ appId : "YOUR APP ID",
status : true,
cookie : true,
xfbml : true
});
};
- //load facebook script asynchronously
- (function() {
- var e = document.createElement( 'script' );
- e.setAttribute( 'src', 'http://connect.facebook.net/en_US/all.js' );
- e.setAttribute( 'async', 'true' );
- document.getElementById( 'fb-root' ).appendChild( e );
- }());
}
- options._container = document.createElement( 'fb:' + options.type.toLowerCase() );
+ var validType = function( type ){
+ var valid = false;
+ var existing = [ "like", "like-box", "activity", "facepile" ];
+
+ for(var i in existing){
+ if ( type.toLowerCase() === existing[i] ) {
+ valid = true;
+ }
+ }
+
+ return valid;
+ };
+
+ // default plugin is like button
+ if( typeof( options.type ) === "undefined"){
+ options.type = "like";
+ } else if ( !validType( options.type ) ){
+ return;
+ }
+
+ options._container = document.createElement( "fb:" + ( options.type.toLowerCase() || "like" ) );
- //setOptions property list doesn't accept dashes
- if(options.type === "LIKE-BOX") {
+ // setOptions property list doesn't accept dashes
+ if( options.type === "LIKE-BOX" ) {
options.type = "likebox";
}
var setOptions = (function ( options ) {
- options._container.setAttribute( 'href', ( options.href || document.URL ) );
+ options._container.setAttribute( "href", ( options.href || document.URL ) );
return {
like: function () {
- options._container.setAttribute( 'width', ( options.width || "450" ) );
- options._container.setAttribute( 'show_faces', ( options.show_faces || "false" ) );
- options._container.setAttribute( 'layout', ( options.layout || "standard" ) );
- options._container.setAttribute( 'font', options.font );
+ options._container.setAttribute( "width", ( options.width || "450" ) );
+ options._container.setAttribute( "show_faces", ( options.show_faces || "false" ) );
+ options._container.setAttribute( "layout", ( options.layout || "standard" ) );
+ options._container.setAttribute( "font", options.font );
},
likebox: function () {
- options._container.setAttribute( 'width', ( options.width || "292" ) );
- options._container.setAttribute( 'show_faces', ( options.show_faces || "false" ) );
- options._container.setAttribute( 'stream', ( options.stream || "false" ) );
- options._container.setAttribute( 'header', ( options.header || "true" ) );
+ options._container.setAttribute( "width", ( options.width || "292" ) );
+ options._container.setAttribute( "show_faces", ( options.show_faces || "false" ) );
+ options._container.setAttribute( "stream", ( options.stream || "false" ) );
+ options._container.setAttribute( "header", ( options.header || "true" ) );
},
facepile: function () {
- options._container.setAttribute( 'width', ( options.width || "200" ) );
- options._container.setAttribute( 'max_rows', ( options.max_rows || "1" ) );
+ options._container.setAttribute( "width", ( options.width || "200" ) );
+ options._container.setAttribute( "max_rows", ( options.max_rows || "1" ) );
},
activity: function () {
- options._container.setAttribute( 'width', ( options.width || "300" ) );
- options._container.setAttribute( 'height', ( options.height || "300" ) );
- options._container.setAttribute( 'header', ( options.header || "true" ) );
- options._container.setAttribute( 'border_color', ( options.border_color || "#000000" ) );
- options._container.setAttribute( 'recommendations', ( options.recommendations || "false" ) );
- options._container.setAttribute( 'font', options.font );
+ options._container.setAttribute( "width", ( options.width || "300" ) );
+ options._container.setAttribute( "height", ( options.height || "300" ) );
+ options._container.setAttribute( "header", ( options.header || "true" ) );
+ options._container.setAttribute( "border_color", ( options.border_color || "#000000" ) );
+ options._container.setAttribute( "recommendations", ( options.recommendations || "false" ) );
+ options._container.setAttribute( "font", options.font );
}
};
})( options );
--- /dev/null
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Popcorn Facebook Plug-in Test</title>
+ <link rel="stylesheet" href="../../test/qunit/qunit.css" type="text/css" media="screen">
+ <script src="../../test/qunit/qunit.js"></script>
+ <!--
+ do not move - this must be called immediately prior to
+ popcorn-api-draft.js
+ -->
+
+ <script src="../../popcorn.js"></script>
+
+ <script src="popcorn.facebook.js"></script>
+ <script src="popcorn.facebook.unit.js"></script>
+</head>
+<body>
+ <h1 id="qunit-header">Popcorn Facebook Plugin</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture"> </div>
+
+ <video id='video'
+ controls preload='none'
+ width= '250px'
+ poster="../../test/poster.png">
+
+ <source id='mp4'
+ src="../../test/trailer.mp4"
+ type='video/mp4; codecs="avc1, mp4a"'>
+
+ <source id='ogv'
+ src="../../test/trailer.ogv"
+ type='video/ogg; codecs="theora, vorbis"'>
+
+ <p>Your user agent does not support the HTML5 Video element.</p>
+
+ </video>
+ <div>
+ <div id="likediv"></div>
+ <div id="likeboxdiv"></div>
+ </div>
+ <div style="position:absolute;left:300px;top:150px">
+ <div id="facepilediv"></div>
+ <div id="activitydiv"></div>
+ </div>
+</body>
+</html>
<ul id="menuItems">
<li><a onclick="clearEvents();" target="out" href="attribution/popcorn.attribution.unit.html">attribution</a></li>
<li><a onclick="clearEvents();" target="out" href="code/popcorn.code.unit.html">code</a></li>
+ <li><a onclick="clearEvents();" target="out" href="facebook/popcorn.facebook.unit.html">facebook</a></li>
<li><a onclick="clearEvents();" target="out" href="flickr/popcorn.flickr.unit.html">flickr</a></li>
<li><a onclick="clearEvents();" target="out" href="footnote/popcorn.footnote.unit.html">footnote</a></li>
<li><a onclick="clearEvents();" target="out" href="googlemap/popcorn.googlemap.unit.html">googlemap</a></li>
<script>
var eventList = [];
function runAllTests(){
- var testUrl = [ "attribution", "code", "flickr", "footnote", "googlemap",
- "googlenews", "image", "lastfm", "lowerthird", "mustache",
- "subtitle", "tagthisperson", "twitter", "webpage", "wikipedia" ];
+ var testUrl = [ "attribution", "code", "facebook", "flickr", "footnote",
+ "googlemap", "googlenews", "image", "lastfm", "lowerthird",
+ "mustache", "subtitle", "tagthisperson", "twitter", "webpage",
+ "wikipedia" ];
//googlenews and lowerthird tests do not exist, therefore their test time is set to 0
- var testDur = [ 17000, 20000, 10000, 20000, 11000,
- 0, 10000, 10000, 0, 15000,
- 25000, 21000, 10000, 21000, 21000 ];
+ var testDur = [ 17000, 20000, 10000, 10000, 20000,
+ 11000, 0, 10000, 10000, 0,
+ 15000, 25000, 21000, 10000, 21000,
+ 21000 ];
var setTest = function( index ) {
var url = function( str ) {