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 = 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);
56 window.addEventListener('resize', this.resizeHack.bind(this), false);
57 this.setNotice('Swipe for more...');
59 setNotice: function(notice) {
60 this.$.notice.setContent(notice);
63 infoFade: function() {
64 this.$.info.setStyle('opacity: 1');
66 clearTimeout(this.noticeTimer);
67 this.noticeTimer = setTimeout(function() {
68 this.$.info.setStyle('opacity: 0');
69 setTimeout(function() {
70 this.$.notice.setContent('');
74 openPreferences: function() {
75 var view = this.$.hacksCarousel.fetchView('center');
77 var meta = view.getPreferencesMetadata();
80 var values = view.getPreferences();
81 this.$.preferencesView.load(this.hacksList[this.index].name, meta, values);
82 this.selectView(this.$.preferencesView);
84 this.$.noPrefsDialog.openAtCenter();
87 savePreferences: function(inSender, prefs) {
88 var view = this.$.hacksCarousel.fetchView('center');
90 enyo.log("Clearing prefs");
91 view.resetPreferences(prefs);
92 this.selectHack(this, this.index);
94 enyo.log("Saving prefs: " + JSON.stringify(prefs));
95 view.setPreferences(prefs);
100 windowActivated: function() {
103 windowDeactivated: function() {
106 selectHack: function(inSender, inValue) {
108 this.index = inValue;
109 this.lastScrollPos = 0;
110 this.$.hacksCarousel.setCenterView(this.getHack(this.index));
111 this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
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');
160 this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
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');
173 this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
175 if (this.index == this.hacksList.length - 1)
178 return this.getHack(this.index + 1);
180 scrolling: function(inSender) {
181 if (inSender.scrollLeft == 0 || inSender.scrollLeft == inSender.getBoundaries().right)
184 startScroll: function(inSender) {
187 stopScroll: function(inSender) {
188 this.lastScrollPos = this.$.hacksCarousel.scrollLeft;
191 closeNoPrefsDialog: function() {
192 this.$.noPrefsDialog.close();