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');
41 this.lastScrollPos = 0;
42 this.$.hacksCarousel.setCenterView(this.getHack(this.index));
46 for (var i = 0; i < this.hacksList.length; i++) {
48 caption: this.hacksList[i].name,
52 this.$.hacksListSelector.setItems(displayList);
54 window.addEventListener('resize', this.resizeHack.bind(this), false);
55 this.setNotice('Swipe for more...');
57 setNotice: function(notice) {
58 this.$.notice.setContent(notice);
61 infoFade: function() {
62 this.$.info.setStyle('opacity: 1');
64 clearTimeout(this.noticeTimer);
65 this.noticeTimer = setTimeout(function() {
66 this.$.info.setStyle('opacity: 0');
67 setTimeout(function() {
68 this.$.notice.setContent('');
72 openPreferences: function() {
73 var view = this.$.hacksCarousel.fetchView('center');
75 var meta = view.getPreferencesMetadata();
78 var values = view.getPreferences();
79 this.$.preferencesView.load(this.hacksList[this.index].name, meta, values);
80 this.selectView(this.$.preferencesView);
82 this.$.noPrefsDialog.openAtCenter();
85 savePreferences: function(inSender, prefs) {
86 var view = this.$.hacksCarousel.fetchView('center');
88 enyo.log("Clearing prefs");
89 view.resetPreferences(prefs);
90 this.selectHack(this, this.index);
92 enyo.log("Saving prefs: " + JSON.stringify(prefs));
93 view.setPreferences(prefs);
98 windowActivated: function() {
101 windowDeactivated: function() {
104 selectHack: function(inSender, inValue) {
106 this.index = inValue;
107 this.lastScrollPos = 0;
108 this.$.hacksCarousel.setCenterView(this.getHack(this.index));
109 this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
110 // For some reason, setCenterView above fires the startScroll
111 // event without a subsequent stopScroll event. To work around
112 // this, we defer the start until later.
113 setTimeout(function() { this.startHack() }.bind(this), 20);
115 startHack: function(direction) {
116 var view = this.$.hacksCarousel.fetchView(direction || 'center');
117 //enyo.log('starting view ' + view);
120 //localStorage.setItem('hack.index', this.index);
122 stopHack: function(direction) {
123 var view = this.$.hacksCarousel.fetchView(direction || 'center');
124 //enyo.log('stopping view ' + view);
128 resizeHack: function() {
129 var view = this.$.hacksCarousel.fetchView('center');
131 view.resize(window.innerWidth, window.innerHeight);
132 var view = this.$.hacksCarousel.fetchView('left');
134 view.resize(window.innerWidth, window.innerHeight);
135 var view = this.$.hacksCarousel.fetchView('right');
137 view.resize(window.innerWidth, window.innerHeight);
139 hackHidden: function(direction) {
140 var view = this.$.hacksCarousel.fetchView(direction);
141 //enyo.log('view ' + view + ' hidden');
145 getHack: function(index) {
146 return {kind: this.hacksList[index].kind};
148 getLeft: function(inSender, inSnap) {
149 if (inSnap && this.index > 0) {
151 this.$.hacksListSelector.setValue(this.index);
152 this.hackHidden('right');
154 this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
159 return this.getHack(this.index - 1);
161 getRight: function(inSender, inSnap) {
162 if (inSnap && this.index < this.hacksList.length) {
164 this.$.hacksListSelector.setValue(this.index);
165 this.hackHidden('left');
167 this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
169 if (this.index == this.hacksList.length - 1)
172 return this.getHack(this.index + 1);
174 scrolling: function(inSender) {
175 if (inSender.scrollLeft == 0 || inSender.scrollLeft == inSender.getBoundaries().right)
178 startScroll: function(inSender) {
181 stopScroll: function(inSender) {
182 this.lastScrollPos = this.$.hacksCarousel.scrollLeft;
185 closeNoPrefsDialog: function() {
186 this.$.noPrefsDialog.close();