(function() { var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; if (ELA.Views == null) { ELA.Views = {}; } ELA.Views.BaseApp = (function(superClass) { extend(BaseApp, superClass); function BaseApp() { this.render = bind(this.render, this); this.renderHelp = bind(this.renderHelp, this); this.relatedApps = bind(this.relatedApps, this); this.deactivate = bind(this.deactivate, this); this.activate = bind(this.activate, this); this.setActive = bind(this.setActive, this); this.liveChangeEnd = bind(this.liveChangeEnd, this); this.liveChangeStart = bind(this.liveChangeStart, this); this.toggleAside = bind(this.toggleAside, this); this.backToOverview = bind(this.backToOverview, this); this.hideAsides = bind(this.hideAsides, this); this.setCurrentAside = bind(this.setCurrentAside, this); this.copyShareLink = bind(this.copyShareLink, this); this.selectShareLink = bind(this.selectShareLink, this); this.share = bind(this.share, this); this.showHelp = bind(this.showHelp, this); this.openSubapp = bind(this.openSubapp, this); this.hideMenus = bind(this.hideMenus, this); this.toggleContextMenu = bind(this.toggleContextMenu, this); this.hideSubappOptions = bind(this.hideSubappOptions, this); this.viewSubappOptions = bind(this.viewSubappOptions, this); this.remove = bind(this.remove, this); return BaseApp.__super__.constructor.apply(this, arguments); } BaseApp.prototype.template = JST['general/app']; BaseApp.prototype.id = function() { return this.model.name.toDash(); }; BaseApp.prototype.tagName = 'section'; BaseApp.prototype.className = 'active'; BaseApp.prototype.asides = []; BaseApp.prototype.views = []; BaseApp.prototype.events = { 'tap header .overview.icon': 'backToOverview', 'tap header .help': 'showHelp', 'tap header .share-link': 'share', 'tap header .share-form input': 'selectShareLink', 'tap header .share-form button': 'copyShareLink', 'submit header .share-form form': function(e) { return e.preventDefault(); }, 'tap header *[data-toggle-aside]': 'setCurrentAside', 'tap header .poised.subapps.select': 'viewSubappOptions', 'tap header .poised.subapps.select .option': 'openSubapp', 'tap header .context.icon': 'toggleContextMenu', 'tap article.graph:has(~ aside.active)': 'hideAsides', 'tap section:has(.subapps.select.view)': 'hideSubappOptions', 'tap section:has(.menu.view)': 'hideMenus' }; BaseApp.prototype.hammerjs = true; BaseApp.prototype.remove = function() { return this.$el.afterTransitionForRemovingClass('active', (function(_this) { return function() { return BaseApp.__super__.remove.apply(_this, arguments); }; })(this)); }; BaseApp.prototype.initialize = function() { var aside, base, i, len, ref; this.listenTo(this.model, 'change:currentAside', this.toggleAside); this.listenTo(this.model, 'change:showHelp', this.renderHelp); this.on('controlLiveChangeStart', this.liveChangeStart); this.on('controlLiveChangeEnd', this.liveChangeEnd); ref = this.asides; for (i = 0, len = ref.length; i < len; i++) { aside = ref[i]; if (aside.link == null) { aside.link = 'icon'; } } return (base = this.model).displayParams != null ? base.displayParams : base.displayParams = {}; }; BaseApp.prototype.viewSubappOptions = function() { return this.$('.subapps.select').toggleClass('view'); }; BaseApp.prototype.hideSubappOptions = function() { return this.$('.subapps.select').removeClass('view'); }; BaseApp.prototype.toggleContextMenu = function() { return this.$('.menu:has(.icon.context)').toggleClass('view'); }; BaseApp.prototype.hideMenus = function(e) { if (!((e != null) && $(e.target).closest(this.$shareLink.add(this.$shareForm)).length)) { this.$('.menu').removeClass('view'); this.$shareForm.addClass('hidden'); this.$shareCopyButton.removeClass('success failure').addClass('copy'); return this.$shareLink.removeClass('hidden'); } }; BaseApp.prototype.openSubapp = function(e) { var $target; $target = $(e.target); return ELA.router.navigate("app/" + ($target.data('path')), { trigger: true }); }; BaseApp.prototype.showHelp = function() { return ELA.router.navigate("app/" + this.model.path + "/help", { trigger: true }); }; BaseApp.prototype.share = function() { this.$shareUrlInput.val(ELA.app.url()); this.$shareLink.addClass('hidden'); return this.$shareForm.removeClass('hidden'); }; BaseApp.prototype.selectShareLink = function() { return this.$shareUrlInput.select(); }; BaseApp.prototype.copyShareLink = function() { this.selectShareLink(); if (document.execCommand('copy')) { return this.$shareCopyButton.removeClass('copy').addClass('success'); } else { return this.$shareCopyButton.removeClass('copy').addClass('failure'); } }; BaseApp.prototype.setCurrentAside = function(e) { var asideToToggle, currentAside; asideToToggle = $(e.currentTarget).data('toggle-aside'); currentAside = this.model.get('currentAside'); if (currentAside === asideToToggle) { return this.model.set({ currentAside: null }); } else { return this.model.set({ currentAside: asideToToggle }); } }; BaseApp.prototype.hideAsides = function() { return this.model.set({ currentAside: null }); }; BaseApp.prototype.iconAsideNames = function() { return this._iconAsideNames != null ? this._iconAsideNames : this._iconAsideNames = (function(_this) { return function() { return _.compact(_.map(_this.asides, function(aside) { if (aside.link === 'icon') { return aside.name; } })); }; })(this)(); }; BaseApp.prototype.contextAsides = function() { return this._contextAsideNames != null ? this._contextAsideNames : this._contextAsideNames = (function(_this) { return function() { return _.compact(_.map(_this.asides, function(aside) { if (aside.link === 'contextMenu') { return { name: aside.name, label: _this.loadLocale("contextMenu." + aside.name) }; } })); }; })(this)(); }; BaseApp.prototype.backToOverview = function() { return ELA.router.navigate('/', { trigger: true }); }; BaseApp.prototype.toggleAside = function(model, value) { var previous; previous = model.previousAttributes().currentAside; if (previous != null) { this.$("header ." + previous + ".aside.icon").toggleClass('active', false); this.$("aside." + previous).toggleClass('active', false); } if (value != null) { this.$("header ." + value + ".aside.icon").toggleClass('active', true); return this.$("aside." + value).toggleClass('active', true); } }; BaseApp.prototype.liveChangeStart = function(slider) { if ($(window).width() <= 768) { this.$('aside.active').addClass('hidden'); return this.subviews.headup.activate(slider); } }; BaseApp.prototype.liveChangeEnd = function() { if ($(window).width() <= 768) { this.$('aside.active').removeClass('hidden'); return this.subviews.headup.deactivate(); } }; BaseApp.prototype.setActive = function(active) { return this.$el.toggleClass('active', active); }; BaseApp.prototype.activate = function() { return this.$el.toggleClass('active', true); }; BaseApp.prototype.deactivate = function() { return this.$el.toggleClass('active', false); }; BaseApp.prototype.relatedApps = function() { var ref; return ((ref = this.model.parentApp) != null ? ref.subappInfo() : void 0) || []; }; BaseApp.prototype.renderHelp = function() { var showHelp, view; showHelp = this.model.get('showHelp'); if (showHelp && (this.subviews.help == null)) { this.subviews.help = view = new ELA.Views.Help({ model: this.model }); this.$el.append(view.render().el); } return delay((function(_this) { return function() { var ref; if ((ref = _this.subviews.help) != null) { ref.setActive(showHelp); } return _this.$app.toggleClass('active', !showHelp); }; })(this)); }; BaseApp.prototype.render = function() { var AsideView, aside, i, len, ref, view; this.$el.html(this.template({ name: this.model.name, path: this.model.path, hasHelpText: this.model.hasHelpText, iconAsideNames: this.iconAsideNames(), contextAsides: this.contextAsides(), relatedApps: this.relatedApps(), currentPath: this.model.path })); this.$shareLink = this.$('li.share-link'); this.$shareForm = this.$('li.share-form'); this.$shareUrlInput = this.$shareForm.find('input'); this.$shareCopyButton = this.$shareForm.find('button'); this.$app = this.$('section.app'); ref = this.asides; for (i = 0, len = ref.length; i < len; i++) { aside = ref[i]; AsideView = aside.view.toFunction(); view = this.subviews[aside.name] = new AsideView({ model: this.model, parentView: this, name: aside.name, localePrefix: this.localePrefix }); this.$app.append(view.render().el); } if (this.subviews.headup == null) { this.$headup = this.$('aside.headup'); this.subviews.headup = new ELA.Views.Headup({ el: this.$headup, localePrefix: this.localePrefix }); } if (!this.subviews.viewport) { view = this.subviews.viewport = new ELA.Views.Viewport({ model: this.model, parentView: this, views: this.views, localePrefix: this.localePrefix }); this.$('.viewport').replaceWith(view.render().el); } this.renderHelp(); this.toggleAside(this.model, this.model.get('currentAside')); return this; }; return BaseApp; })(Backbone.Poised.View); }).call(this);