1 /* Copyright 2011 The Dominion of Awesome
2 * See COPYING for licensing information */
7 {kind: "ApplicationEvents", onWindowActivated: "windowActivated", onWindowDeactivated: "windowDeactivated"},
8 {name: "mainView", kind: "VFlexBox", components: [
9 {name: "hacksCarousel", kind: "Carousel", flex: 1, onGetLeft: "getLeft", onGetRight: "getRight", onScroll: "scrolling", onScrollStart: "startScroll", onScrollStop: "stopScroll"},
10 {name: "info", kind: "HFlexBox", className: "info", align: "center", style: "opacity: 0", onclick: "infoFade", components: [
11 {className: "wrench", onclick: "openPreferences"},
12 {name: "hacksListSelector", kind: "ListSelector", popupAlign: "left", onChange: "selectHack", style: "width: 200px"},
14 {name: "notice", className: "notice"}
16 {name: "noPrefsDialog", kind: "ModalDialog", caption: "No Preferences", components: [
17 {kind: "Button", content: "Okay", onclick: "closeNoPrefsDialog"}
20 {name: "preferencesView", kind: "HackPreferences", onClose: "savePreferences"}
23 {name: "Nimbus", kind: "Nimbus"},
24 {name: "HexaSpinner", kind: "HexaSpinnerHack"},
25 {name: "Landscape", kind: "Landscape"},
26 {name: "Munch", kind: "Munch"},
27 {name: "Orbit", kind: "Orbit"},
28 {name: "Pixelfade", kind: "Pixelfade"},
29 //{name: "Swarm", kind: "Swarm"}, // crashy
30 //{name: "Spinner.CGA", kind: "XSpinnerCGA"}, // no webfont support
31 {name: "Spinner", kind: "XSpinner"}
34 this.inherited(arguments);
36 this.index = parseInt(localStorage.getItem('hack.index'));
40 enyo.log("Could not load last hack index");
43 this.lastScrollPos = 0;
44 this.$.hacksCarousel.setCenterView(this.getHack(this.index));
48 for (var i = 0; i < this.hacksList.length; i++) {
50 caption: this.hacksList[i].name,
54 this.$.hacksListSelector.setItems(displayList);
55 this.$.hacksListSelector.setValue(this.index);
57 window.addEventListener('resize', this.resizeHack.bind(this), false);
58 this.setNotice('Swipe for more...');
60 setNotice: function(notice) {
61 this.$.notice.setContent(notice);
64 infoFade: function() {
65 this.$.info.setStyle('opacity: 1');
67 clearTimeout(this.noticeTimer);
68 this.noticeTimer = setTimeout(function() {
69 this.$.info.setStyle('opacity: 0');
70 setTimeout(function() {
71 this.$.notice.setContent('');
75 openPreferences: function() {
76 var view = this.$.hacksCarousel.fetchView('center');
78 var meta = view.getPreferencesMetadata();
81 var values = view.getPreferences();
82 this.$.preferencesView.load(this.hacksList[this.index].name, meta, values);
83 this.selectView(this.$.preferencesView);
85 this.$.noPrefsDialog.openAtCenter();
88 savePreferences: function(inSender, prefs) {
89 var view = this.$.hacksCarousel.fetchView('center');
91 enyo.log("Clearing prefs");
92 view.resetPreferences(prefs);
93 this.selectHack(this, this.index);
95 enyo.log("Saving prefs: " + JSON.stringify(prefs));
96 view.setPreferences(prefs);
101 windowActivated: function() {
104 windowDeactivated: function() {
107 selectHack: function(inSender, inValue) {
109 this.index = inValue;
110 this.lastScrollPos = 0;
111 this.$.hacksCarousel.setCenterView(this.getHack(this.index));
112 // For some reason, setCenterView above fires the startScroll
113 // event without a subsequent stopScroll event. To work around
114 // this, we defer the start until later.
115 setTimeout(function() { this.startHack() }.bind(this), 20);
117 startHack: function(direction) {
118 var view = this.$.hacksCarousel.fetchView(direction || 'center');
119 //enyo.log('starting view ' + view);
123 localStorage.setItem('hack.index', this.index);
125 enyo.log("Could not set hack index");
128 stopHack: function(direction) {
129 var view = this.$.hacksCarousel.fetchView(direction || 'center');
130 //enyo.log('stopping view ' + view);
134 resizeHack: function() {
135 var view = this.$.hacksCarousel.fetchView('center');
137 view.resize(window.innerWidth, window.innerHeight);
138 var view = this.$.hacksCarousel.fetchView('left');
140 view.resize(window.innerWidth, window.innerHeight);
141 var view = this.$.hacksCarousel.fetchView('right');
143 view.resize(window.innerWidth, window.innerHeight);
145 hackHidden: function(direction) {
146 var view = this.$.hacksCarousel.fetchView(direction);
147 //enyo.log('view ' + view + ' hidden');
151 getHack: function(index) {
152 return {kind: this.hacksList[index].kind};
154 getLeft: function(inSender, inSnap) {
155 if (inSnap && this.index > 0) {
157 this.$.hacksListSelector.setValue(this.index);
158 this.hackHidden('right');
164 return this.getHack(this.index - 1);
166 getRight: function(inSender, inSnap) {
167 if (inSnap && this.index < this.hacksList.length) {
169 this.$.hacksListSelector.setValue(this.index);
170 this.hackHidden('left');
173 if (this.index == this.hacksList.length - 1)
176 return this.getHack(this.index + 1);
178 scrolling: function(inSender) {
179 if (inSender.scrollLeft == 0 || inSender.scrollLeft == inSender.getBoundaries().right)
182 startScroll: function(inSender) {
185 stopScroll: function(inSender) {
186 this.lastScrollPos = this.$.hacksCarousel.scrollLeft;
189 closeNoPrefsDialog: function() {
190 this.$.noPrefsDialog.close();