Opensocial.Album (v0.9)
From OpenSocial
opensocial.Album
Class for Album features.
Methods
opensocial.Album.getField
String getField(key, opt_params)
- Parameters
- Returns
Type Description String The data
- Description
Gets the album data that's associated with the specified key.
opensocial.Album.setField
setField(key, data)
- Parameters
Name Type Description key String The key to set data for data String The data to set
- Description
Sets data for this album associated with the given key.
opensocial.Album.Field
All of the fields that albums can have. It is only required to set ID. Other possible fields to set are: THUMBNAIL_URL, TITLE, DESCRIPTION, LOCATION, OWNER_ID, MEDIA_TYPE, MEDIA_MIME_TYPE, MEDIA_ITEM_COUNT. See also: opensocial.Album.getField()
opensocial.Album.Field.DESCRIPTION
- string, description of the album. May be used interchangeably with the string 'description'.
opensocial.Album.Field.ID
- string, unique identifier for the album. May be used interchangeably with the string 'id'.
opensocial.Album.Field.LOCATION
- opensocial.Address, location corresponding to the album. May be used interchangeably with the string 'location'.
opensocial.Album.Field.MEDIA_ITEM_COUNT
- integer, number of items in the album. May be used interchangeably with the string 'mediaItemCount'.
opensocial.Album.Field.MEDIA_MIME_TYPE
- array of strings identifying the mime-types of media items in the Album. May be used interchangeably with the string 'mediaMimeType'.
opensocial.Album.Field.MEDIA_TYPE
- array of MediaItem.TYPE, types of MediaItems in the Album. May be used interchangeably with the string 'mediaType'.
opensocial.Album.Field.OWNER_ID
- string, ID of the owner of the album. May be used interchangeably with the string 'ownerId'.
opensocial.Album.Field.THUMBNAIL_URL
- string, URL to a thumbnail cover of the album. May be used interchangeably with the string 'thumbnailUrl'.
opensocial.Album.Field.TITLE
- string, the title of the album. May be used interchangeably with the string 'title'.
Example
Requesting orkut Albums and Photos, by Jason Cooper, orkut Team, Februrary 2009
CSS
img { border: solid gray 1px; } #photoGrid img { float: left; width: auto; margin-right: 10px; } table { border: solid gray 1px; background-color: #EEEEEE; margin-bottom: 15px; }
HTML
<!-- Table to display album thumbnail and metadata --> <table id="albumTable" cellspacing="5"></table> <h2>Photos from selected album:</h2> <!-- Styled div to display photos from selected album --> <div id="photoGrid"></div>
JavaScript
// Fetches all of the viewer's albums that are publicly viewable (i.e. // "shared with everyone" function fetchAlbums() { var req = opensocial.newDataRequest(); var idspec = opensocial.newIdSpec( { 'userId' : 'VIEWER', 'groupId' : 'SELF' }); req.add(req.newFetchAlbumsRequest(idspec), 'viewerAlbums'); req.send(fetchAlbumsHandler); }; // Callback function, executed when it finishes fetching the viewer's // public albums function fetchAlbumsHandler(resp) { var viewerAlbumsResp = resp.get('viewerAlbums'); if (!viewerAlbumsResp.hadError()) { var viewerAlbums = viewerAlbumsResp.getData(); // Add a table row for each album viewerAlbums.each(function(album) { createAlbumRow(album); }); } }; // Adds a new table row for the passed album, displaying its thumbnail, // name, and description function createAlbumRow(album) { var row = document.createElement('tr'); var thumbnailCell = document.createElement('td'); var descriptionCell = document.createElement('td'); // Add an image tag to the first cell with the album's thumbnail; // also include an event handler which executes fetchPhotos // when the image is clicked, passing in the album's ID. thumbnailCell.innerHTML = '<img src="' + album.getThumbnailUrl() + '" onclick="fetchPhotos(\'' + album.getId() + '\')"/>'; // Output the album's title... descriptionCell.innerHTML = '<b>' + gadgets.util.escapeString(album .getTitle()) + '</b>'; // ... and description descriptionCell.innerHTML += '<p>' + gadgets.util.escapeString(album .getDescription()) + '</p>'; row.appendChild(thumbnailCell); row.appendChild(descriptionCell); // Add the new row to the table document.getElementById('albumTable').appendChild(row); }; // Fetches all photos from the album with the passed ID function fetchPhotos(albumId) { var req = opensocial.newDataRequest(); var idspec = opensocial.newIdSpec( { 'userId' : 'VIEWER', 'groupId' : 'SELF' }); req.add(req.newFetchMediaItemsRequest(idspec, albumId), 'albumPhotos'); req.send(fetchPhotosHandler); }; // Callback function, executed when orkut finishes fetching the // requested media items function fetchPhotosHandler(resp) { document.getElementById('photoGrid').innerHTML = ''; var albumPhotosResp = resp.get('albumPhotos'); if (!albumPhotosResp.hadError()) { var albumPhotos = albumPhotosResp.getData(); // Add each photo's thumbnail to the photo grid albumPhotos.each(function(photo) { addToPhotoGrid(photo); }); } }; // Adds the passed photo's thumbnail to the photo grid function addToPhotoGrid(photo) { document.getElementById('photoGrid').innerHTML += '<img src="' + photo .getThumbnailUrl() + '"/>'; }; // Execute fetchAlbums function when gadget loads gadgets.util.registerOnLoadHandler(fetchAlbums);
| OpenSocial (v0.9) | |||
| opensocial
opensocial.Album | |||
