// Pacing app // =============================================== // Takes in data obj, an element to append to, and utility functions // // Data is a boolean // - true: Spend as fast as possible // - false: Spend evenly over a pacing period // // Example data: // true // var pacing = (function(){ 'use strict' var template = getTemplate(), optArr = [ { 'title': 'Spend evenly over period', 'value' : true }, { 'title': 'Spend as fast as possible', 'value' : false } ]; return newPacing; function newPacing(d, t, fns){ return new Pacing(d, t, fns); } function Pacing(d, t, fns){ var e = getElementFromString(template, fns.getAppName('pacing')), eles = new Elements(e, { "remove" : { 'target' : new ConfirmationButton(e.querySelector(".remove"), { 'text' : 'Remove app', 'noClass' : true, 'confirmText' : 'Confirm?' }, removeAction) }, "toggle" : { "target" : new ToggleNavigation(e, { 'data': optArr, 'className': 'toggle', 'initialValue': d.status !== false }, updateToggle) } }); this.exit = exit; t.appendChild(e); function updateToggle(e){ d.status = e.value; } function removeAction(e){ fns.removeApp("pacing"); } function exit(){ if(!!e) removeChild(t, e); if(!!eles) eles.exit(); e = eles = null; } } function getTemplate(){ return '

{{ . }}:

'; } })();