## Usage ### configuration To use the funifier in production, insert the following line in tag head of all the pages you want to enable: ```html ``` ### Initiation Async mode To start the funifier of asynchronous way, insert a function before the script funifier: ```javascript 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: ```javascript 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](https://jquery.com/): `Funifier._$` 1.11.1 - [async](https://github.com/caolan/async): `Funifier._async` - [lodash](https://lodash.com/): `Funifier._` - [validator](https://github.com/chriso/validator.js): `Funifier._validator` - [mustache](https://github.com/janl/mustache.js/): `Funifier._mustache` - [headjs](http://headjs.com/): `Funifier.headjs` - [magnificPopup](http://dimsemenov.com/plugins/magnific-popup/): `Funifier._$.magnificPopup` - [qs](https://github.com/hapijs/qs): `Funifier._qs` For documentation of the above components , check the website of the respective component. ### methods * [`init`](#init) * [`listen`](#listen) * [`unlisten`](#unlisten) * [`api`](#api) * [`track`](#track) * [`auth`](#auth) * [`authenticate`](#authenticate) * [`isAuthenticate`](#isAuthenticate) * [`logout`](#logout) --------------------------------------- ### 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__ ```js 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__ ```js 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 :(') } } ); ``` ```js 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__ ```js 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__ ```js 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. * facebook * google * 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__ ```js Funifier.auth.authenticate({ auth_mode: 'facebook', modal: true },function(err,data){ if(err==null){ alert('Welcome') } }); ``` __Example via Password__ ```js 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__ ```js 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__ ```js Funifier.auth.logout(function(err){ if(err==null){ alert('Successfully offline player'); }else{ alert('an error occurred'); } }); ``` ## Widget The basic structure of a widget: ```javascript var ct = '
Hello World!
' 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. ```javascript 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. ```javascript Funifier.auth.isAuthenticate(function(isAuthenticate) { Funifier.api('get_widget_data', { include_teams: false, include_levels: false, include_challenges: true, include_catalogs: false, include_leaderboards: true, include_friends: true, include_actions: true, include_points: true, include_game: 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: ```javascript Funifier.debug.enable('*'); ``` You can enable logging for specific messages: ```javascript Funifier.debug.enable('Funifier:social:*'); ``` ```javascript Funifier.debug.enable('Funifier:core:*'); ``` If you want to disable messages: ```javascript Funifier.debug.disable(); ```