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", dark: false},
24 {name: "HexaSpinner", kind: "HexaSpinnerHack", dark: false},
25 {name: "Landscape", kind: "Landscape", dark: false},
26 {name: "Munch", kind: "Munch", dark: true},
27 {name: "Orbit", kind: "Orbit", dark: false},
28 {name: "Pixelfade", kind: "Pixelfade", dark: true},
29 //{name: "Swarm", kind: "Swarm", dark: false}, // crashy
30 //{name: "Spinner.CGA", kind: "XSpinnerCGA", dark: true}, // no webfont support
31 {name: "Spinner", kind: "XSpinner", dark: true}
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.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
59 this.setNotice('Swipe for more...');
61 setNotice: function(notice) {
62 this.$.notice.setContent(notice);
65 infoFade: function() {
66 this.$.info.setStyle('opacity: 1');
68 clearTimeout(this.noticeTimer);
69 this.noticeTimer = setTimeout(function() {
70 this.$.info.setStyle('opacity: 0');
71 setTimeout(function() {
72 this.$.notice.setContent('');
76 openPreferences: function() {
77 var view = this.$.hacksCarousel.fetchView('center');
79 var meta = view.getPreferencesMetadata();
82 var values = view.getPreferences();
83 this.$.preferencesView.load(this.hacksList[this.index].name, meta, values);
84 this.selectView(this.$.preferencesView);
86 this.$.noPrefsDialog.openAtCenter();
89 savePreferences: function(inSender, prefs) {
90 var view = this.$.hacksCarousel.fetchView('center');
92 enyo.log("Clearing prefs");
93 view.resetPreferences(prefs);
94 this.selectHack(this, this.index);
96 enyo.log("Saving prefs: " + JSON.stringify(prefs));
97 view.setPreferences(prefs);
102 windowActivated: function() {
105 windowDeactivated: function() {
108 selectHack: function(inSender, inValue) {
110 this.index = inValue;
111 this.lastScrollPos = 0;
112 this.$.hacksCarousel.setCenterView(this.getHack(this.index));
113 this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
114 // For some reason, setCenterView above fires the startScroll
115 // event without a subsequent stopScroll event. To work around
116 // this, we defer the start until later.
117 setTimeout(function() { this.startHack() }.bind(this), 20);
119 startHack: function(direction) {
120 var view = this.$.hacksCarousel.fetchView(direction || 'center');
121 //enyo.log('starting view ' + view);
125 localStorage.setItem('hack.index', this.index);
127 enyo.log("Could not set hack index");
130 stopHack: function(direction) {
131 var view = this.$.hacksCarousel.fetchView(direction || 'center');
132 //enyo.log('stopping view ' + view);
136 resizeHack: function() {
137 var view = this.$.hacksCarousel.fetchView('center');
139 view.resize(window.innerWidth, window.innerHeight);
140 var view = this.$.hacksCarousel.fetchView('left');
142 view.resize(window.innerWidth, window.innerHeight);
143 var view = this.$.hacksCarousel.fetchView('right');
145 view.resize(window.innerWidth, window.innerHeight);
147 hackHidden: function(direction) {
148 var view = this.$.hacksCarousel.fetchView(direction);
149 //enyo.log('view ' + view + ' hidden');
153 getHack: function(index) {
154 return {kind: this.hacksList[index].kind};
156 getLeft: function(inSender, inSnap) {
157 if (inSnap && this.index > 0) {
159 this.$.hacksListSelector.setValue(this.index);
160 this.hackHidden('right');
162 this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
167 return this.getHack(this.index - 1);
169 getRight: function(inSender, inSnap) {
170 if (inSnap && this.index < this.hacksList.length) {
172 this.$.hacksListSelector.setValue(this.index);
173 this.hackHidden('left');
175 this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
177 if (this.index == this.hacksList.length - 1)
180 return this.getHack(this.index + 1);
182 scrolling: function(inSender) {
183 if (inSender.scrollLeft == 0 || inSender.scrollLeft == inSender.getBoundaries().right)
186 startScroll: function(inSender) {
189 stopScroll: function(inSender) {
190 this.lastScrollPos = this.$.hacksCarousel.scrollLeft;
193 closeNoPrefsDialog: function() {
194 this.$.noPrefsDialog.close();