diff options
Diffstat (limited to 'docroot/classes/application.js')
-rwxr-xr-x | docroot/classes/application.js | 227 |
1 files changed, 227 insertions, 0 deletions
diff --git a/docroot/classes/application.js b/docroot/classes/application.js new file mode 100755 index 0000000..d8776d8 --- /dev/null +++ b/docroot/classes/application.js | |||
@@ -0,0 +1,227 @@ | |||
1 | /* | ||
2 | * Material Experience - Main Application Code | ||
3 | * | ||
4 | * EYEMG - Interactive Media Group | ||
5 | * Created by Mike Crute (mcrute@eyemg.com) | ||
6 | * Updated by Mike Crute (mcrute@eyemg.com) on 9/26/07 | ||
7 | * | ||
8 | * Core application code that is responsible for starting up the application | ||
9 | * and initializing the core objects. | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * Register global actions for AJAX responders. | ||
14 | */ | ||
15 | Ajax.Responders.register( | ||
16 | { | ||
17 | /* | ||
18 | * When an AJAX connection is created show the bezel that says | ||
19 | * "loading data". | ||
20 | */ | ||
21 | onCreate: function() | ||
22 | { | ||
23 | if (!SME.AJAXBezel) | ||
24 | { | ||
25 | SME.AJAXBezel = new Bezel({ displayTime: 0, destroy: false }).show(Strings.loadingAnim); | ||
26 | } | ||
27 | else | ||
28 | { | ||
29 | SME.AJAXBezel.show(Strings.loadingAnim); | ||
30 | } | ||
31 | }, | ||
32 | |||
33 | /* | ||
34 | * Each time a requester completes we check to see if it was the last | ||
35 | * one, if it is then we take down the loading bezel. | ||
36 | */ | ||
37 | onComplete: function() | ||
38 | { | ||
39 | if (Ajax.activeRequestCount == 0) | ||
40 | { | ||
41 | SME.AJAXBezel.hide(); | ||
42 | } | ||
43 | }, | ||
44 | |||
45 | /* | ||
46 | * When something goes wrong with loading data we die. | ||
47 | */ | ||
48 | onException: function(transport, exception) | ||
49 | { | ||
50 | if (SME.debug) | ||
51 | { | ||
52 | console.error(exception); | ||
53 | } | ||
54 | |||
55 | SME.AJAXBezel.hide(); | ||
56 | new Bezel({ displayTime: 0 }).show(Strings.ajaxError); | ||
57 | } | ||
58 | }); | ||
59 | |||
60 | /* | ||
61 | * Load the data for the card tables. | ||
62 | */ | ||
63 | function loadTables() | ||
64 | { | ||
65 | new Ajax.Request(SME.url.tableList, | ||
66 | { | ||
67 | method: "get", | ||
68 | |||
69 | onSuccess: function(transport) | ||
70 | { | ||
71 | transport.responseText.evalJSON().each(function(data) | ||
72 | { | ||
73 | var windowDims = window.getDimensions(); | ||
74 | |||
75 | var table = new CardTable( | ||
76 | { | ||
77 | color: data.color, | ||
78 | name: data.name, | ||
79 | id: data.tid, | ||
80 | decorate: data.decorate | ||
81 | }); | ||
82 | |||
83 | // Push the table onto the global table cache (see the SME namespace | ||
84 | // for more information about the global table cache) | ||
85 | SME.tables.push(table); | ||
86 | |||
87 | // Subtracting the max chip width and height ensures that cards don't | ||
88 | // fall too far off the tables | ||
89 | table.loadChipData(SME.url.cardTables, | ||
90 | { | ||
91 | table: data.tid, | ||
92 | w: windowDims.width - (SME.sizes.chipMax.width / 2), | ||
93 | h: windowDims.height - (SME.sizes.chipMax.height / 2) | ||
94 | }, false); | ||
95 | }); | ||
96 | |||
97 | // Initialize the sketchbook | ||
98 | SME.sketchbook = new Sketchbook(); | ||
99 | |||
100 | // By default show the home table. When the history manager loads for the | ||
101 | // first time (after this step) it will load the right table from the URL | ||
102 | // if applicable. This just ensures that a table is always displayed. | ||
103 | CardTable.showTable("home"); | ||
104 | |||
105 | // Show the tool box in the upper right | ||
106 | showToolBox(); | ||
107 | } | ||
108 | }); | ||
109 | |||
110 | // Start up the history manager | ||
111 | SME.history = new HistoryManager().pollEvents(); | ||
112 | } | ||
113 | |||
114 | /* | ||
115 | * Show an intro card. This function will gracefully pass if there are no | ||
116 | * intro cards to be shown. | ||
117 | */ | ||
118 | function showIntro() | ||
119 | { | ||
120 | new Ajax.Request(SME.url.introCards, | ||
121 | { | ||
122 | method: "get", | ||
123 | |||
124 | onSuccess: function(transport) | ||
125 | { | ||
126 | var data = transport.responseText.cleanJSON(); | ||
127 | |||
128 | // If there is no intro card then just pass | ||
129 | if (data == "" || data == "\n") | ||
130 | { | ||
131 | return loadTables(); | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | data = data.evalJSON(); | ||
136 | |||
137 | // By default just show the first card in the | ||
138 | // feed | ||
139 | var myCard = data[0]; | ||
140 | |||
141 | // If more than one card then pick one at random | ||
142 | // to display (per client requirements). | ||
143 | if (data.length > 1) | ||
144 | { | ||
145 | myCard = data[Math.floor(1 + (data.length - 1) * Math.random())]; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | var card = new Card( | ||
150 | { | ||
151 | color: SME.colors.grey, | ||
152 | title: '', | ||
153 | addExtraButtons: false, | ||
154 | contID: myCard, | ||
155 | |||
156 | onFadeComplete: function() | ||
157 | { | ||
158 | loadTables(); | ||
159 | } | ||
160 | }).show(); | ||
161 | } | ||
162 | }); | ||
163 | } | ||
164 | |||
165 | /* | ||
166 | * Show the toolbox in the upper right side of the screen. | ||
167 | */ | ||
168 | function showToolBox() | ||
169 | { | ||
170 | new Effect.Appear($$("div#header div.history")[0]); | ||
171 | |||
172 | // On mouseover of the history link show the dropdown | ||
173 | $$("div.history a.history")[0].observe("mouseover", function() | ||
174 | { | ||
175 | SME.history.getDropDown(); | ||
176 | }); | ||
177 | |||
178 | // Show the login screen when the login link is clicked | ||
179 | $("loginLink").observe("click", Sketchbook.showLoginScreen); | ||
180 | |||
181 | // Check the login when they first hit the page, saves people logging | ||
182 | // in again | ||
183 | Sketchbook.checkLogin(); | ||
184 | } | ||
185 | |||
186 | /* | ||
187 | * Main program function, this starts up the interface and does various | ||
188 | * little fixups of interface elements. | ||
189 | */ | ||
190 | function main() | ||
191 | { | ||
192 | if (SME.debug) | ||
193 | { | ||
194 | new Bezel({ displayTime: 5 }).show("Full Debug Mode is Enabled"); | ||
195 | } | ||
196 | |||
197 | // Check the resolution at load and when the screen size changes | ||
198 | window.checkResolution(); | ||
199 | Event.observe(window, "resize", window.checkResolution); | ||
200 | |||
201 | // Show the intro card or load the tables | ||
202 | if (SME.skipIntro || window.location.hash.length > 1) | ||
203 | { | ||
204 | loadTables(); | ||
205 | } | ||
206 | else | ||
207 | { | ||
208 | showIntro(); | ||
209 | } | ||
210 | |||
211 | // Per Bryan this should be a single year if 2007 otherwise it should | ||
212 | // be a date range starting on the year that the site was released. | ||
213 | if (new Date().getFullYear() > 2007) | ||
214 | { | ||
215 | $("copyright").innerHTML = $("copyright").innerHTML.replace(/####/, "2007-" + | ||
216 | new Date().getFullYear()); | ||
217 | } | ||
218 | else | ||
219 | { | ||
220 | $("copyright").innerHTML = $("copyright").innerHTML.replace(/####/, "2007"); | ||
221 | } | ||
222 | } | ||
223 | |||
224 | /* | ||
225 | * Start the program up when the window loads. | ||
226 | */ | ||
227 | Event.observe(window, "load", main); \ No newline at end of file | ||