# Anything A plugin for [Reveal.js](https://github.com/hakimel/reveal.js) allowing to add anything inside an HTML object using a JSON string and a javascript function. The plugin allows you to define a class for which the content of all HTML object of this class will be modified by a given javascript function. Inside the HTML object you can provide a comment containing a JSON string that will be used by function to customise the content. [Check out the live demo](http://courses.telematique.eu/reveal.js-plugins/anything-demo.html) ## Installation Copy the files ```anything.js``` into the plugin folder of your reveal.js presentation, i.e. ```plugin/anything```. Add the plugins to the dependencies in your presentation, as below. ```javascript Reveal.initialize({ // ... dependencies: [ // ... { src: 'plugin/anything/anything.js' }, // ... ] }); ``` ## Configuration & basic usage The plugin can be configured by providing an ```anything``` option containing an array of ```className```, ```defaults```, and ```f``` within the reveal.js initialization options. ```javascript Reveal.initialize({ // ... anything: [ { className: "random", defaults: {min: 0, max: 9}, initialize: (function(container, options){ container.innerHTML = Math.trunc( options.min + Math.random()*(options.max-options.min + 1) ); }) }, // ... ], ``` With the above configuration the plugin searches for all HTML object with class ```random```. For each of the HTML objects it checks whether there is a JSON string within a comment inside the HTML object. Then, it calls the function ```function(container, options)``` where ```container``` is the HTML object and ```options``` is the JSON string. It is possible to specify the ```defaults``` parameter to be used if no JSON string is provided or not all values required by the function are given in the JSON string. The code ```html

Today's winning 3 digit number is : , , .

``` produces the output ```html

Today's winning 3 digit number is : 3, 8, 0.

``` The code ```html

Today's roll of a die is: .

``` produces the output ```html

Today's roll of a die is: 4.

``` ## Advanced usage The plugin can be used to easily integrate external javascript libraries. ### Charts.js With the plugin charts created by [Chart.js v2.0](http://www.chartjs.org/) can easily be included in the slides. ```javascript Reveal.initialize({ // ... anything: [ { className: "chart", initialize: (function(container, options){ container.chart = new Chart(container.getContext("2d"), options); }) }, // ... ], dependencies: [ // ... { src: 'Chart.min.js' }, { src: 'plugin/anything/anything.js' }, // ... ] }); ``` A chart can be included in a slide by adding a ```canvas``` element and a JSON string specifying the chart options. ```html ``` Note, that the [Chart plugin](https://github.com/rajgoel/reveal.js-plugins/tree/master/chart) provides an easier way to use Chart.js. ### Function-plot.js With the plugin plots of functions created by [Function-plot.js](https://github.com/maurizzzio/function-plot) can easily be included in the slides. ```javascript Reveal.initialize({ // ... anything: [ { className: "plot", defaults: {width:500, height: 500, grid:true}, initialize: (function(container, options){ options.target = "#"+container.id; functionPlot(options) }) }, // ... ], dependencies: [ // ... { src: 'reveal.js-plugins/function-plot/site/js/vendor/jquery-1.11.2.min.js' }, { src: 'reveal.js-plugins/function-plot/site/js/vendor/d3.js' }, { src: 'reveal.js-plugins/function-plot/site/js/function-plot.js' }, { src: 'plugin/anything/anything.js' }, // ... ] }); ``` A plot can be included in a slide by adding a ```div``` element and a JSON string specifying the options. ```html
``` With the above ```defaults```, the input can be eased, e.g. ```html
``` ## More advanced usage The plugin allows to define functions within the JSON options. ### Example In the following example, the function ```options.initialize(container)``` is called for each element of the class ```anything```. The function is defined within the JSON string. ```javascript Reveal.initialize({ // ... anything: [ { className: "anything", initialize: (function(container, options){ if (options && options.initialize) { options.initialize(container)} }) }, // ... ], dependencies: [ // ... { src: 'reveal.js-plugins/anything/d3/d3.v3.min.js' }, { src: 'reveal.js-plugins/anything/d3/topojson.v1.min.js' }, { src: 'plugin/anything/anything.js' }, // ... ] }); ``` The [d3.js](d3js.org) library can now be used to draw a [globe](http://bl.ocks.org/mbostock/ba63c55dd2dbc3ab0127) within a canvas element. ```html ``` ## License MIT licensed Copyright (C) 2016 Asvin Goel