Daniel@0
|
1 "use strict";
|
Daniel@0
|
2
|
Daniel@0
|
3 App.addInitializer(function(options){
|
Daniel@0
|
4
|
Daniel@0
|
5 var $document = $(document);
|
Daniel@0
|
6
|
Daniel@0
|
7 // A box that randomly changes colour when css assets become new
|
Daniel@0
|
8 if (window.location.href.indexOf("track_assets_version") > 0) {
|
Daniel@0
|
9 var cssHref = $("link[rel=stylesheet]").attr("href");
|
Daniel@0
|
10 var assetsVersion = cssHref.slice(cssHref.indexOf("?") + 1);
|
Daniel@0
|
11 var $cssUpdateIndicator = $.bem.generateElement("app", "assets-version-indicator");
|
Daniel@0
|
12 $cssUpdateIndicator.text("assets version: " + assetsVersion);
|
Daniel@0
|
13 $cssUpdateIndicator.appendTo($(".app"));
|
Daniel@0
|
14 $cssUpdateIndicator.click(function() {
|
Daniel@0
|
15 App.showNotification({id: "assets-version-indicator", content: "This element changes colour when the css file recomplies."});
|
Daniel@0
|
16 });
|
Daniel@0
|
17 }
|
Daniel@0
|
18 var codeVersion = "2015-03-12";
|
Daniel@0
|
19 var latestChange = "Comparison views and also three new views for collections were added (<b>tuning stats</b>, <b>tonic histogram</b> and <b>pitch class histogram</b>). All three demo states now have the same sets of rows."
|
Daniel@0
|
20 var previouslyOpenedCodeVersion = App.DataModule.Storage.getStrCache(null, "code-version");
|
Daniel@0
|
21 if (codeVersion != previouslyOpenedCodeVersion) {
|
Daniel@0
|
22 App.DataModule.Storage.setStrCache(null, "introductory-hint-was-read", undefined);
|
Daniel@0
|
23 App.DataModule.Storage.setStrCache(null, "code-version", codeVersion);
|
Daniel@0
|
24 }
|
Daniel@0
|
25
|
Daniel@0
|
26 if (previouslyOpenedCodeVersion < "2015-03-12") {
|
Daniel@0
|
27 App.contextManager.restoreDefault(App.context, "empty");
|
Daniel@0
|
28 };
|
Daniel@0
|
29
|
Daniel@0
|
30 // introductory hint
|
Daniel@0
|
31 // if (!App.DataModule.Storage.getStrCache(null, "introductory-hint-was-read")) {
|
Daniel@0
|
32 // setTimeout(function() {
|
Daniel@0
|
33 // App.showNotification({
|
Daniel@0
|
34 // content: Backbone.Marionette.TemplateCache.get("#notification-content_tmp-instructions")({
|
Daniel@0
|
35 // codeVersion: codeVersion,
|
Daniel@0
|
36 // latestChange: latestChange,
|
Daniel@0
|
37 // ctrl: App.keyboardMappings.ctrlTitle,
|
Daniel@0
|
38 // }),
|
Daniel@0
|
39 // onClose: function() {
|
Daniel@0
|
40 // App.DataModule.Storage.setStrCache(null, "introductory-hint-was-read", "yes")
|
Daniel@0
|
41 // },
|
Daniel@0
|
42 // modifiers: ["ttl_ever"]
|
Daniel@0
|
43 // });
|
Daniel@0
|
44 // }, 3000);
|
Daniel@0
|
45 // //}, 0);
|
Daniel@0
|
46 // }
|
Daniel@0
|
47
|
Daniel@0
|
48 // scrollable data in vis instances for Samer (if he adds ?scroll)
|
Daniel@0
|
49 if (window.location.href.indexOf("scroll") > 0) {
|
Daniel@0
|
50 $("body").addClass("scrollable-pres-in-vis-instances");
|
Daniel@0
|
51 }
|
Daniel@0
|
52
|
Daniel@0
|
53 var latestVisit = App.DataModule.Storage.getStrCache(null, "latest-visit");
|
Daniel@0
|
54
|
Daniel@0
|
55 // Flash help when a user sees the vis for the first time
|
Daniel@0
|
56 if (!latestVisit) {
|
Daniel@0
|
57 setTimeout(function() {
|
Daniel@0
|
58 if (!App.helpIsShowing()) {
|
Daniel@0
|
59 App.MainMenuModule.flashItem("help", 20);
|
Daniel@0
|
60 // Show help when a user sees the vis for the first time
|
Daniel@0
|
61 // App.MainMenuModule.flashItem("help", 20, function() {
|
Daniel@0
|
62 // App.showHelp();
|
Daniel@0
|
63 // });
|
Daniel@0
|
64 }
|
Daniel@0
|
65 }, 5000);
|
Daniel@0
|
66 }
|
Daniel@0
|
67
|
Daniel@0
|
68
|
Daniel@0
|
69 App.DataModule.Storage.setStrCache(null, "latest-visit", (new Date().toString()));
|
Daniel@0
|
70
|
Daniel@0
|
71
|
Daniel@0
|
72 // A warning that a backup api is being used
|
Daniel@0
|
73 var defaultURIIdentifier = options.musicLibrary.defaultApiRootPaths[0];
|
Daniel@0
|
74 if (options.musicLibrary.apiRootPaths[0].indexOf(defaultURIIdentifier) == -1) {
|
Daniel@0
|
75 var currentURIIdentifier = options.musicLibrary.apiRootPaths[0].replace(/^[a-zA-Z]*:?\/\//, "").replace(/\/$/, "");
|
Daniel@0
|
76 setTimeout(function() {
|
Daniel@0
|
77 App.showNotification({
|
Daniel@0
|
78 content: Backbone.Marionette.TemplateCache.get("#notification-content_alternative-api")({
|
Daniel@0
|
79 defaultURIIdentifier: defaultURIIdentifier,
|
Daniel@0
|
80 currentURIIdentifier: currentURIIdentifier,
|
Daniel@0
|
81 stuffToRemoveFromAddess: "api2",
|
Daniel@0
|
82 }),
|
Daniel@0
|
83 modifiers: ["ttl_30", "type_warning"]
|
Daniel@0
|
84 });
|
Daniel@0
|
85 }, 1000);
|
Daniel@0
|
86 }
|
Daniel@0
|
87
|
Daniel@0
|
88 // Debug API on / off
|
Daniel@0
|
89 var debugAPIShortcut = App.keyboardMappings.ctrlShift + "+8";
|
Daniel@0
|
90 var debugAPIShortcutTitle = App.keyboardMappings.ctrlShiftTitle + "+8";
|
Daniel@0
|
91 var debugAPIMessageVersion = 1;
|
Daniel@0
|
92 var showDebugAPIModeNotificationIfNeeded = function() {
|
Daniel@0
|
93 if (App.options.debugAPI && App.DataModule.Storage.getStrCache(null, "debug-api-message-shown") != debugAPIMessageVersion) {
|
Daniel@0
|
94 App.showNotification({
|
Daniel@0
|
95 id: "debug-api",
|
Daniel@0
|
96 content: Backbone.Marionette.TemplateCache.get("#notification-content_debug-api")({
|
Daniel@0
|
97 debugAPIShortcut: debugAPIShortcutTitle,
|
Daniel@0
|
98 }),
|
Daniel@0
|
99 onClose: function() {
|
Daniel@0
|
100 App.DataModule.Storage.setStrCache(null, "debug-api-message-shown", debugAPIMessageVersion ? "1" : 0);
|
Daniel@0
|
101 },
|
Daniel@0
|
102 modifiers: ["ttl_ever", "type_warning"]
|
Daniel@0
|
103 });
|
Daniel@0
|
104 }
|
Daniel@0
|
105 };
|
Daniel@0
|
106
|
Daniel@0
|
107 $document.bind("keydown", debugAPIShortcut, function(event) {
|
Daniel@0
|
108 App.options.debugAPI = !App.options.debugAPI;
|
Daniel@0
|
109 if (!App.options.debugAPI) {
|
Daniel@0
|
110 App.hideNotification("debug-api");
|
Daniel@0
|
111 }
|
Daniel@0
|
112 showDebugAPIModeNotificationIfNeeded();
|
Daniel@0
|
113 App.mainRegionView.render(true);
|
Daniel@0
|
114 App.DataModule.Storage.setStrCache(null, "debug-api", App.options.debugAPI ? "1" : "");
|
Daniel@0
|
115 });
|
Daniel@0
|
116 showDebugAPIModeNotificationIfNeeded();
|
Daniel@0
|
117
|
Daniel@0
|
118 // Change entity width
|
Daniel@0
|
119
|
Daniel@0
|
120 //var widths = [100, 200, 300, 500, 750, 1000, 1]
|
Daniel@0
|
121 var minWidth = 100;
|
Daniel@0
|
122 var step = 20;
|
Daniel@0
|
123 var maxWidth = 2000;
|
Daniel@0
|
124 var changeEntityWidth = function(direction) {
|
Daniel@0
|
125 var currentGrid = App.context.get("state").getConfigGridBeingShown();
|
Daniel@0
|
126 var currentEntityWidth = (currentGrid.get("entityWidth") || App.options.defaultEntityWidth) * 1;
|
Daniel@0
|
127
|
Daniel@0
|
128 var diff = direction > 0 ? step : -step;
|
Daniel@0
|
129 var newEntityWidth = currentEntityWidth + diff;
|
Daniel@0
|
130 if (newEntityWidth > maxWidth) {
|
Daniel@0
|
131 newEntityWidth = maxWidth;
|
Daniel@0
|
132 }
|
Daniel@0
|
133
|
Daniel@0
|
134 if (newEntityWidth < minWidth) {
|
Daniel@0
|
135 newEntityWidth = minWidth;
|
Daniel@0
|
136 }
|
Daniel@0
|
137
|
Daniel@0
|
138 currentGrid.set("entityWidth", newEntityWidth);
|
Daniel@0
|
139 };
|
Daniel@0
|
140
|
Daniel@0
|
141 $document.bind("keydown", "pageup", function(event) {
|
Daniel@0
|
142 changeEntityWidth(1);
|
Daniel@0
|
143 event.preventDefault();
|
Daniel@0
|
144 });
|
Daniel@0
|
145 $document.bind("keydown", "pagedown", function(event) {
|
Daniel@0
|
146 changeEntityWidth(-1);
|
Daniel@0
|
147 event.preventDefault();
|
Daniel@0
|
148 });
|
Daniel@0
|
149 });
|