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: "Labyrinth", kind: "Labyrinth"},
24 {name: "Nimbus", kind: "Nimbus"},
25 {name: "HexaSpinner", kind: "HexaSpinnerHack"},
26 {name: "Landscape", kind: "Landscape"},
27 {name: "Munch", kind: "Munch"},
28 {name: "Orbit", kind: "Orbit"},
29 {name: "Pixelfade", kind: "Pixelfade"},
30 //{name: "Swarm", kind: "Swarm"}, // crashy
31 //{name: "Spinner.CGA", kind: "XSpinnerCGA"}, // no webfont support
32 {name: "Spinner", kind: "XSpinner"}
35 this.inherited(arguments);
37 this.index = parseInt(localStorage.getItem('hack.index'));
41 enyo.log("Could not load last hack index");
44 this.lastScrollPos = 0;
45 this.$.hacksCarousel.setCenterView(this.getHack(this.index));
49 for (var i = 0; i < this.hacksList.length; i++) {
51 caption: this.hacksList[i].name,
55 this.$.hacksListSelector.setItems(displayList);
56 this.$.hacksListSelector.setValue(this.index);
58 window.addEventListener('resize', this.resizeHack.bind(this), false);
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 // For some reason, setCenterView above fires the startScroll
114 // event without a subsequent stopScroll event. To work around
115 // this, we defer the start until later.
116 setTimeout(function() { this.startHack() }.bind(this), 20);
118 startHack: function(direction) {
119 var view = this.$.hacksCarousel.fetchView(direction || 'center');
120 //enyo.log('starting view ' + view);
124 localStorage.setItem('hack.index', this.index);
126 enyo.log("Could not set hack index");
129 stopHack: function(direction) {
130 var view = this.$.hacksCarousel.fetchView(direction || 'center');
131 //enyo.log('stopping view ' + view);
135 resizeHack: function() {
136 var view = this.$.hacksCarousel.fetchView('center');
138 view.resize(window.innerWidth, window.innerHeight);
139 var view = this.$.hacksCarousel.fetchView('left');
141 view.resize(window.innerWidth, window.innerHeight);
142 var view = this.$.hacksCarousel.fetchView('right');
144 view.resize(window.innerWidth, window.innerHeight);
146 hackHidden: function(direction) {
147 var view = this.$.hacksCarousel.fetchView(direction);
148 //enyo.log('view ' + view + ' hidden');
152 getHack: function(index) {
153 return {kind: this.hacksList[index].kind};
155 getLeft: function(inSender, inSnap) {
156 if (inSnap && this.index > 0) {
158 this.$.hacksListSelector.setValue(this.index);
159 this.hackHidden('right');
165 return this.getHack(this.index - 1);
167 getRight: function(inSender, inSnap) {
168 if (inSnap && this.index < this.hacksList.length) {
170 this.$.hacksListSelector.setValue(this.index);
171 this.hackHidden('left');
174 if (this.index == this.hacksList.length - 1)
177 return this.getHack(this.index + 1);
179 scrolling: function(inSender) {
180 if (inSender.scrollLeft == 0 || inSender.scrollLeft == inSender.getBoundaries().right)
183 startScroll: function(inSender) {
186 stopScroll: function(inSender) {
187 this.lastScrollPos = this.$.hacksCarousel.scrollLeft;
190 closeNoPrefsDialog: function() {
191 this.$.noPrefsDialog.close();