Home
Documentation
FML Sandbox
Discussion Board
Release Notes
Blog
Visit Flux.com
You are not logged in.
Log In
or
Sign Up
Widget Developer Kit Samples
These Widget Developer Kit examples demonstrate the use of custom markup and custom java script logic to create your own very customized widgets. It is a good idea to use these as a starting point when trying to customize widgets as they demonstrate the steps needed to take a default widget and through WDK customization create very specific UI or functionality to suit your needs.
Thumbs Up/Down Widget
Simple Rating Widget
Thumbs Up/Down Widget
Click here
to download source files
Note - ensure to specify the correct
Community UCID
,
Access Key
,
Permalink/URI
,
Markup URL
and
Javascript URL
in the Widget Code
WIDGET CODE:
CUSTOM MARKUP:
Comments
0
Rating
Thumbs up
Thumbs down
CUSTOM JAVA SCRIPT LOGIC:
Flux.Widgets.ContentAction2.prototype._initialize = function(params) { this._requestInfo = this.createRequestInfo({contentUri: params.uri}); this._commentCount = 0; this._contentType = 'Clip'; if (params.contentType) { this._contentType = params.contentType; } this.render2(); this.applyStyle(); $addHandler(this.$get('rateUpButton'), 'click', Function.createDelegate(this, this._rateUpClickHandler)); $addHandler(this.$get('rateDownButton'), 'click', Function.createDelegate(this, this._rateDownClickHandler)); this._contentUri = params.uri; this.dataBind(); Flux.EventManager.registerWidget(this); } Flux.Widgets.ContentAction2.prototype.dataBind = function(reason) { this.getJsonData(this._getDataUrl(), Function.createDelegate(this, this._onDataLoad)); } Flux.Widgets.ContentAction2.prototype._onDataLoad= function(result) { this._renderData(result.CommentCount, result.OverallThumbRating, result.CurrentUserVote); this._commentCount = result.CommentCount; } Flux.Widgets.ContentAction2.prototype._renderData = function(commentCount, rating, currentUserVote) { this.$get('commentCount').innerHTML = commentCount; var ratingInformation = this.$get('ratingInformation'); Sys.UI.DomElement.removeCssClass(ratingInformation, 'vote-up'); Sys.UI.DomElement.removeCssClass(ratingInformation, 'vote-down'); if (rating >= 0) { Sys.UI.DomElement.addCssClass(ratingInformation, 'vote-up'); } else { Sys.UI.DomElement.addCssClass(ratingInformation, 'vote-down'); } ratingInformation.innerHTML = String.format('{0}%', Math.abs(rating)); this._setButtonsState(currentUserVote); } Flux.Widgets.ContentAction2.prototype._setButtonsState = function(rating) { var rateUpButton = this.$get('rateUpButton'); var rateDownButton = this.$get('rateDownButton'); Sys.UI.DomElement.removeCssClass(rateUpButton, 'voted-y'); Sys.UI.DomElement.removeCssClass(rateUpButton, 'voted-n'); Sys.UI.DomElement.removeCssClass(rateDownButton, 'voted-y'); Sys.UI.DomElement.removeCssClass(rateDownButton, 'voted-n'); var title; if (rating != 0) { title = 'Your rating'; if (rating > 0) { Sys.UI.DomElement.addCssClass(rateUpButton, 'voted-y'); Sys.UI.DomElement.addCssClass(rateDownButton, 'voted-n'); } else { Sys.UI.DomElement.addCssClass(rateUpButton, 'voted-n'); Sys.UI.DomElement.addCssClass(rateDownButton, 'voted-y'); } } else { title = String.format('Rate this {0}', this._contentType); } this.$get('ratingTitle').innerHTML = title; } Flux.Widgets.ContentAction2.prototype._setContentRating = function(rating) { Flux.API.Services.Rating.SetContentRating(this._requestInfo, rating, Flux.API.RatingMode.Thumb, this._setContentRatingHandler, null, this); Flux.DataAccess.CookieHelper.set('preventCache_rating', (new Date()).getTime(), 10); this._setButtonsState(rating); } Flux.Widgets.ContentAction2.prototype._setContentRatingHandler = function(result, instance, methodName) { if (result.StatusCode == Flux.API.StatusCode.Ok) { instance.onAfterAction('rating'); var rating = 0; var votesUp = result.Value; var votesDown = result.Count - result.Value; if (votesUp + votesDown) { var rating = Math.max(votesUp, votesDown) / (votesUp + votesDown) * 100; if (votesUp < votesDown) { rating *= -1; } } instance._renderData(instance._commentCount, Math.floor(rating), result.CurrentUserVote); } else { Flux.Debug.traceServiceError('Rating', methodName, result); } } Flux.Widgets.ContentAction2.prototype._rateUpClickHandler = function(e) { if (this.onBeforeAction()) { this._setContentRating(1); } e.preventDefault(); } Flux.Widgets.ContentAction2.prototype._rateDownClickHandler = function(e) { if (this.onBeforeAction()) { this._setContentRating(-1); } e.preventDefault(); } Flux.Widgets.ContentAction2.prototype._getDataUrl = function() { // .replace call is made to prevent MTV contentdetail page to retrieve data via AKAMAI and instead make it get data directly from Flux daapi server if (Flux.Context.isUserAuthenticated()) return Flux.DataAccess.UrlBuilder.buildContentUsageUrl(this._contentUri, 'rating').replace(/daapiak-mtv/, 'daapi'); else return Flux.DataAccess.UrlBuilder.buildContentUsageUrl(this._contentUri, 'rating'); }
TOP
Simple Rating Widget
Click here
to download source files
Note - ensure to specify the correct
Community UCID
,
Access Key
,
Permalink/URI
,
Markup URL
and
Javascript URL
in the Widget Code
WIDGET CODE:
CUSTOM MARKUP:
Share
Favorites
{addToMyProfileConfirm}Added!{/addToMyProfileConfirm}
{item_rated}
{THUMBS_UP_COUNT}
Thumbs up{/item_rated} {item_default}Click to Rate{/item_default} {item_signup}Sign in to rate{/item_signup} {item_thanks}Thanks for rating{/item_thanks}
Permalink
Flagged...
Flag
Adult
Hate
Spam
Other
CUSTOM JAVA SCRIPT LOGIC:
Flux.Widgets.ContentAction2.prototype._renderRating = function() { var container = this.$get('voteCount'); var template = ''; if (this._hover) { if (Flux.Context.isUserAuthenticated()) { if (this._isUserVoted) { template = this.getTemplateItem('item_thanks'); } else { template = this.getTemplateItem('item_default'); } } else { template = this.getTemplateItem('item_signup'); } } else { if (this._gainRatingCount > 0) { template = this.getTemplateItem('item_rated').replace(/\{THUMBS_UP_COUNT\}/g, this._gainRatingCount); } else { template = this.getTemplateItem('item_default'); } } container.innerHTML = template; } Flux.Widgets.ContentAction2.prototype._ratingInitialize = function(params) { this._thumbUpButton = this.$get('rateButton'); this.addClickHandler(this._thumbUpButton, this.thumbUpClickHandler); $addHandler(this._thumbUpButton, 'mouseover', Function.createDelegate( {instance: this, hover: true}, this._hoverHandler)); $addHandler(this._thumbUpButton, 'mouseout', Function.createDelegate( {instance: this, hover: false}, this._hoverHandler)); } Flux.Widgets.ContentAction2.prototype._hoverHandler = function(e) { this.instance._hover = this.hover; this.instance._renderRating(); e.preventDefault(); } Flux.Widgets.ContentAction2.prototype._getContentRatingHandler = function(result) { this._gainRatingCount = result.GainRatingCount; this._renderRating(); if (Flux.Context.isUserAuthenticated()) { this.setVotingState(true); } } Flux.Widgets.ContentAction2.prototype.thumbUpClickHandler = function(e) { if (!Flux.Context.isUserAuthenticated()) { Flux.Context.redirectToSignInPage(); } if (this._userCanVote) { Flux.API.Services.Rating.SetContentRating(this.createRequestInfo({contentUri: this._contentUri}), 1, Flux.API.RatingMode.Gain, Function.createDelegate(this, function(result) { if (result.StatusCode == Flux.API.StatusCode.Ok) { if (result.CurrentUserVote == 1) { this._isUserVoted = true; } this._userHasVoted = true; this.onAfterAction(); } })); this.setVotingState(false); } e.preventDefault(); }
TOP
© 2009 MTV Networks. All Rights Reserved.
Learn More
Signup
Overview
Getting Started
Customizing Your Community
Support
Documentation
Examples
Forums
Release Notes
Developer API
Your Privacy Matters
Privacy Policy
Terms of Use
Copyright Policy
Online Safety
About flux
Blog
Company
Contact us
X
You will be taken to another site to view this content
Do you want to continue on to
?
Continue
Cancel