Daniel@0: "use strict";
Daniel@0:
Daniel@0: App.addInitializer(function(options){
Daniel@0:
Daniel@0: var $document = $(document);
Daniel@0:
Daniel@0: // A box that randomly changes colour when css assets become new
Daniel@0: if (window.location.href.indexOf("track_assets_version") > 0) {
Daniel@0: var cssHref = $("link[rel=stylesheet]").attr("href");
Daniel@0: var assetsVersion = cssHref.slice(cssHref.indexOf("?") + 1);
Daniel@0: var $cssUpdateIndicator = $.bem.generateElement("app", "assets-version-indicator");
Daniel@0: $cssUpdateIndicator.text("assets version: " + assetsVersion);
Daniel@0: $cssUpdateIndicator.appendTo($(".app"));
Daniel@0: $cssUpdateIndicator.click(function() {
Daniel@0: App.showNotification({id: "assets-version-indicator", content: "This element changes colour when the css file recomplies."});
Daniel@0: });
Daniel@0: }
Daniel@0: var codeVersion = "2015-03-12";
Daniel@0: var latestChange = "Comparison views and also three new views for collections were added (tuning stats, tonic histogram and pitch class histogram). All three demo states now have the same sets of rows."
Daniel@0: var previouslyOpenedCodeVersion = App.DataModule.Storage.getStrCache(null, "code-version");
Daniel@0: if (codeVersion != previouslyOpenedCodeVersion) {
Daniel@0: App.DataModule.Storage.setStrCache(null, "introductory-hint-was-read", undefined);
Daniel@0: App.DataModule.Storage.setStrCache(null, "code-version", codeVersion);
Daniel@0: }
Daniel@0:
Daniel@0: if (previouslyOpenedCodeVersion < "2015-03-12") {
Daniel@0: App.contextManager.restoreDefault(App.context, "empty");
Daniel@0: };
Daniel@0:
Daniel@0: // introductory hint
Daniel@0: // if (!App.DataModule.Storage.getStrCache(null, "introductory-hint-was-read")) {
Daniel@0: // setTimeout(function() {
Daniel@0: // App.showNotification({
Daniel@0: // content: Backbone.Marionette.TemplateCache.get("#notification-content_tmp-instructions")({
Daniel@0: // codeVersion: codeVersion,
Daniel@0: // latestChange: latestChange,
Daniel@0: // ctrl: App.keyboardMappings.ctrlTitle,
Daniel@0: // }),
Daniel@0: // onClose: function() {
Daniel@0: // App.DataModule.Storage.setStrCache(null, "introductory-hint-was-read", "yes")
Daniel@0: // },
Daniel@0: // modifiers: ["ttl_ever"]
Daniel@0: // });
Daniel@0: // }, 3000);
Daniel@0: // //}, 0);
Daniel@0: // }
Daniel@0:
Daniel@0: // scrollable data in vis instances for Samer (if he adds ?scroll)
Daniel@0: if (window.location.href.indexOf("scroll") > 0) {
Daniel@0: $("body").addClass("scrollable-pres-in-vis-instances");
Daniel@0: }
Daniel@0:
Daniel@0: var latestVisit = App.DataModule.Storage.getStrCache(null, "latest-visit");
Daniel@0:
Daniel@0: // Flash help when a user sees the vis for the first time
Daniel@0: if (!latestVisit) {
Daniel@0: setTimeout(function() {
Daniel@0: if (!App.helpIsShowing()) {
Daniel@0: App.MainMenuModule.flashItem("help", 20);
Daniel@0: // Show help when a user sees the vis for the first time
Daniel@0: // App.MainMenuModule.flashItem("help", 20, function() {
Daniel@0: // App.showHelp();
Daniel@0: // });
Daniel@0: }
Daniel@0: }, 5000);
Daniel@0: }
Daniel@0:
Daniel@0:
Daniel@0: App.DataModule.Storage.setStrCache(null, "latest-visit", (new Date().toString()));
Daniel@0:
Daniel@0:
Daniel@0: // A warning that a backup api is being used
Daniel@0: var defaultURIIdentifier = options.musicLibrary.defaultApiRootPaths[0];
Daniel@0: if (options.musicLibrary.apiRootPaths[0].indexOf(defaultURIIdentifier) == -1) {
Daniel@0: var currentURIIdentifier = options.musicLibrary.apiRootPaths[0].replace(/^[a-zA-Z]*:?\/\//, "").replace(/\/$/, "");
Daniel@0: setTimeout(function() {
Daniel@0: App.showNotification({
Daniel@0: content: Backbone.Marionette.TemplateCache.get("#notification-content_alternative-api")({
Daniel@0: defaultURIIdentifier: defaultURIIdentifier,
Daniel@0: currentURIIdentifier: currentURIIdentifier,
Daniel@0: stuffToRemoveFromAddess: "api2",
Daniel@0: }),
Daniel@0: modifiers: ["ttl_30", "type_warning"]
Daniel@0: });
Daniel@0: }, 1000);
Daniel@0: }
Daniel@0:
Daniel@0: // Debug API on / off
Daniel@0: var debugAPIShortcut = App.keyboardMappings.ctrlShift + "+8";
Daniel@0: var debugAPIShortcutTitle = App.keyboardMappings.ctrlShiftTitle + "+8";
Daniel@0: var debugAPIMessageVersion = 1;
Daniel@0: var showDebugAPIModeNotificationIfNeeded = function() {
Daniel@0: if (App.options.debugAPI && App.DataModule.Storage.getStrCache(null, "debug-api-message-shown") != debugAPIMessageVersion) {
Daniel@0: App.showNotification({
Daniel@0: id: "debug-api",
Daniel@0: content: Backbone.Marionette.TemplateCache.get("#notification-content_debug-api")({
Daniel@0: debugAPIShortcut: debugAPIShortcutTitle,
Daniel@0: }),
Daniel@0: onClose: function() {
Daniel@0: App.DataModule.Storage.setStrCache(null, "debug-api-message-shown", debugAPIMessageVersion ? "1" : 0);
Daniel@0: },
Daniel@0: modifiers: ["ttl_ever", "type_warning"]
Daniel@0: });
Daniel@0: }
Daniel@0: };
Daniel@0:
Daniel@0: $document.bind("keydown", debugAPIShortcut, function(event) {
Daniel@0: App.options.debugAPI = !App.options.debugAPI;
Daniel@0: if (!App.options.debugAPI) {
Daniel@0: App.hideNotification("debug-api");
Daniel@0: }
Daniel@0: showDebugAPIModeNotificationIfNeeded();
Daniel@0: App.mainRegionView.render(true);
Daniel@0: App.DataModule.Storage.setStrCache(null, "debug-api", App.options.debugAPI ? "1" : "");
Daniel@0: });
Daniel@0: showDebugAPIModeNotificationIfNeeded();
Daniel@0:
Daniel@0: // Change entity width
Daniel@0:
Daniel@0: //var widths = [100, 200, 300, 500, 750, 1000, 1]
Daniel@0: var minWidth = 100;
Daniel@0: var step = 20;
Daniel@0: var maxWidth = 2000;
Daniel@0: var changeEntityWidth = function(direction) {
Daniel@0: var currentGrid = App.context.get("state").getConfigGridBeingShown();
Daniel@0: var currentEntityWidth = (currentGrid.get("entityWidth") || App.options.defaultEntityWidth) * 1;
Daniel@0:
Daniel@0: var diff = direction > 0 ? step : -step;
Daniel@0: var newEntityWidth = currentEntityWidth + diff;
Daniel@0: if (newEntityWidth > maxWidth) {
Daniel@0: newEntityWidth = maxWidth;
Daniel@0: }
Daniel@0:
Daniel@0: if (newEntityWidth < minWidth) {
Daniel@0: newEntityWidth = minWidth;
Daniel@0: }
Daniel@0:
Daniel@0: currentGrid.set("entityWidth", newEntityWidth);
Daniel@0: };
Daniel@0:
Daniel@0: $document.bind("keydown", "pageup", function(event) {
Daniel@0: changeEntityWidth(1);
Daniel@0: event.preventDefault();
Daniel@0: });
Daniel@0: $document.bind("keydown", "pagedown", function(event) {
Daniel@0: changeEntityWidth(-1);
Daniel@0: event.preventDefault();
Daniel@0: });
Daniel@0: });