Readme_en_us.md
Usage
configuration
To use the funifier in production, insert the following line in tag head of all the pages you want to enable:
<script src="//client2.funifier.com/2.0.0/funifier.min.js" type="text/javascript"></script>
Initiation Async mode
To start the funifier of asynchronous way, insert a function before the script funifier:
window.funifierAsyncInit = function(){
Funifier.init({
apiKey : 'SUA API KEY'
});
};
Thus, once the funifier has been processed , it will call the function 'funifierAsyncInit' if any.
Initiation Sync mode
You can also boot the funifier at any time after loading the funifier script calling its start method:
Funifier.init({
apiKey : 'SUA API KEY'
});
Documentation
Components
The funifier has some integrated libraries, which can be used in your widgets / integrations note however, that they have the prefix '_' are using the core Funifier and therefore has no guarantee of being present in a future release.
Funifier contain the following components:
-
jquery:
Funifier._$
1.11.1 -
async:
Funifier._async
-
lodash:
Funifier._
-
validator:
Funifier._validator
-
mustache:
Funifier._mustache
-
headjs:
Funifier.headjs
-
magnificPopup:
Funifier._$.magnificPopup
-
qs:
Funifier._qs
For documentation of the above components , check the website of the respective component.
methods
init(config, callback)
Used to start the api funifier. Receives as a parameter an object and a callback.
config
-
apiKey
: String - Apikey configured in studio. -
hideInline
: Boolean - Sets the inline mode display for admin. default : false -
showNotification
: Boolean - Show / hide notifications. default : true -
disableCustomCss
: Boolean - Sets the wrath funifier load the css widgets. default : custom-{api_key}-v{version}.css. -
disableCustomJs
: Boolean - Sets the wrath funifier load the js with widgets functions. default : custom-{api_key}-v{version}.js. -
url
-
service
: String - Url do service. default : '//service2.funifier.com/2.0.0/' -
client
: String - Url do client. default : '//client2.funifier.com/2.0.0' -
studio
: String - Url do studio. default : '//studio2.funifier.com' -
css
: String - Css path to override the default. default : null -
js
: String - Js the way to override the default. default : null
-
callback
Receives a function that is performed once the funifier finished initializing objects for informed apiKey , with which already loaded all the dependencies , scripts and styles.
Parameters:
-
err
You receive an error if you have one
Example
Funifier.init({
apiKey : 'SUA API KEY',
hideInline: false,
url : {
css : 'http://www.meudominio.com/custom-css-replace.css'
}
},function(err){
if(err){
console.log('Ocorreu um erro');
}
});
listen(name, callback)
Monitors a funifier event
-
name
: String - Event name to be monitored -
callback
: Function - Function to be performed.
unlisten(name)
To remove funifier events monitored by the listen.
-
name
: String - Event name to exclude the listen.
*
api(endpoint,params,callback)
Method for communication with the Servicen.
-
endpoint
: String - Method to be required in service. -
params
: Object - Parameters to be sent to the service. -
callback
: Function - return
Examples
Funifier.api('get_leaderboard',
{sort: 1, limit: 10, view: 0, group : 1},
function(err,data){
if(err==null){
alert('Received leaderboards list')
console.log(data);
}else{
alert('an error occurred :(')
}
}
);
Funifier.api('get_widget_data',
null,
function(err,data){
if(err==null){
alert('received return')
console.log(date);
}else{
alert('an error occurred :(')
}
}
);
api(endpoint,params,options,callback)
Method for communication with the service.
-
endpoint
: String - Method to be required in service. -
params
: Object - Parameters to be sent to the service. -
options
: Object - additional parameters. -
callback
: Function - return
Examples
Funifier.api('get_leaderboard',
{sort: 1, limit: 10, view: 0, group : 1},
{type:'GET',contentType:'application/json'},
function(err,data){
if(err==null){
alert('Received leaderboards list')
console.log(date);
}else{
alert('an error occurred :(')
}
}
);
track(options,callback)
Trachea action
options
-
action
: String - Id ou nome da action. -
attributes
: Array - list of attributes , optional.
callback
Function performed after the track.
-
err
- You receive a zero or. -
data
- Server Response.
Example
Funifier.track({
action: 'visitarPagina'
},function(err,data){
if(err==null){
alert('Action traqueada')
}
});
auth
authenticate(options,callback)
Function used to authenticate players.
options
-
auth_mode
: String - Authentication type , available values.- IMPLICIT
- PASSWORD
-
player
: String - Player ID, required to auth_mode ' IMPLICIT ' and ' PASSWORD'. (String) -
password
: String - Password Player , required to auth_mode 'PASSWORD' -
modal
: Boolean - Sets the authentication via google or facebook will be made through a popup, (optional used only for auth_mode ' google' and ' facebook')
callback
Function to return. (It is not performed if the auth_mode for facebook or google and modal equals false )
-
err
- You receive a zero or. -
data
- Server Response:
Example Facebook
Funifier.auth.authenticate({
auth_mode: 'facebook',
modal: true
},function(err,data){
if(err==null){
alert('Welcome')
}
});
Example via Password
Funifier.auth.authenticate({
auth_mode: 'PASSWORD',
player: 'jogador1',
password: 'pass@123'
},function(err,data){
if(err==null){
alert('Welcome')
}
});
isAuthenticate(callback)
Checks if the player is authenticated.
callback
-
isAuthenticate
:Bollean
Example
Funifier.auth.isAuthenticate(function(_isAuthenticate){
if(isAuthenticate){
alert('Welcome , you are logged');
}else{
alert('Sorry , log , you're not logged in');
}
});
logout(callback)
Log out Player.
callback
err
data
Example
Funifier.auth.logout(function(err){
if(err==null){
alert('Successfully offline player');
}else{
alert('an error occurred');
}
});
Widget
The basic structure of a widget:
var ct = '<div><a href="#">Hello World!</a></div>'
render(ct,function(config){
var elemento = config.element;
elemento.find('a').click(function(){
alert('You clicked the link');
});
});
The render method takes a string or a jquery object and a feedback method which can include events.
Within the script you have access to variable 'json' ,'theme_html', '$' e 'jQuery'. The jquery available on the widget is a jquery Funifier object if you want to access the jquery page , use window . $ Or window.jQuery.
The json variable is available in some types of widgets.
You can use the mustache to render your html.
Funifier.auth.isAuthenticate(function(isAuthenticate) {
json.isAuthenticate = isAuthenticate;
var str = Mustache.render(theme_html,json);
render(str,function(config){
var el = config.element;
//your code
});
});
You can request a resource on the server before rendering.
Funifier.auth.isAuthenticate(function(isAuthenticate) {
Funifier.api('get_widget_data', {include_challenges: true}, function(err,json){
json.isAuthenticate = isAuthenticate;
var str = Mustache.render(theme_html,json);
render(str,function(config){
var el = config.element;
//your code
});
});
});
Debug
By default Funifier Client does not display any error information / info on the island is necessary to enable. To enable all funifier messages , open the console and type javascript:
Funifier.debug.enable('*');
You can enable logging for specific messages:
Funifier.debug.enable('Funifier:social:*');
Funifier.debug.enable('Funifier:core:*');
If you want to disable messages:
Funifier.debug.disable();