var baseApps = (function () { 'use strict'; var ignore = {}; return newApps; function newApps(d, t, uf, bf) { return new Apps(d, t, uf, bf); } function Apps(d, cid, uf, bf) { var events = new EventManager, template = getTemplate(d), appList = uf.data['apps/list/short'] || {}, e = getElementFromString(template), ele = new Elements(e, getApps()), isSet = false, sht = null; if (!!ele.__shout__) { resetDropdown(); } this.getE = function () { return e; }; this.getApp = function (k) { return ele[k]; }; this.addApp = function (id, v) { addApp(id, v); }; this.set = set; this.exit = exit; function getApps() { var o = { '__shout__': { 'selector': 'shout' } }; loop(d.apps, function (k, v) { addApp(k, v, o); }); return o; } function resetDropdown() { if (ele.__appList__) ele.__appList__.exit(); ele.__appList__ = new Dropdown(e.querySelector('.qAppList'), { 'data': getData() }, function (e) { addApp(e); resetDropdown(); uf.setSuccess('Successfully added "' + appList[e].name + '" to your apps!'); }); return ele.__appList__; function getData() { var o = [{ title: 'Add an app', placeholder: true }]; loop(appList, function (k, v) { if (ele[k]) return; o.push({ title: v.name, value: k }); }); o.sort(function (a, b) { return a.placeholder || a.title < b.title ? -1 : a.title > b.title; }); return o; } } function addApp(k, v, o) { var fn = window[k]; if (!ignore[k] && typeof fn === 'function') { d.apps[k] = v || {}; var tmp = fn(d.apps[k], e, uf); if (isSet && typeof tmp.set === 'function') tmp.set(); if (o) { o[k] = { 'target': tmp }; } else { ele[k] = tmp; } } } function set() { if (!isSet) { if (!!ele.weather) ele.weather.set(); } isSet = true; } function leaveConfirm(e) { preventDefault(e); new AlertModal({ 'title': 'Alert!', 'message': 'Hey! We noticed you are in the process of building a campaign. If you leave now, you will lose your progress. Please save your campaign before exiting.', 'actionOne': 'Let\'s finish building!', 'actionTwo': 'It\'s ok' }, function (evt) { return function (e) { leaveConfirmCb(e, evt); }; }(e)); } function leaveConfirmCb(e, evt) { if (!!e) popAnchor(evt); } function exit() { if (!!ele) ele.exit(); if (!!events) events.reset(); events = e = ele = null; } } function getTemplate(d) { var shoutH = '

New! Use advanced ' + d.brand.name + ' apps to craft unreal campaign performance. Add apps using the dropdown below:

', shoutAnchor = '
', appShout = '' + shoutH + shoutAnchor + ''; return '
' + appShout + '
'; } })();