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 enyo.log("Saving prefs: " + JSON.stringify(prefs));
88 var view = this.$.hacksCarousel.fetchView('center');
89 view.setPreferences(prefs);
92 windowActivated: function() {
95 windowDeactivated: function() {
98 selectHack: function(inSender, inValue, inOldValue) {
100 this.index = inValue;
101 this.lastScrollPos = 0;
102 this.$.hacksCarousel.setCenterView(this.getHack(this.index));
103 this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
104 // For some reason, setCenterView above fires the startScroll
105 // event without a subsequent stopScroll event. To work around
106 // this, we defer the start until later.
107 setTimeout(function() { this.startHack() }.bind(this), 20);
109 startHack: function(direction) {
110 var view = this.$.hacksCarousel.fetchView(direction || 'center');
111 //enyo.log('starting view ' + view);
114 //localStorage.setItem('hack.index', this.index);
116 stopHack: function(direction) {
117 var view = this.$.hacksCarousel.fetchView(direction || 'center');
118 //enyo.log('stopping view ' + view);
122 resizeHack: function() {
123 var view = this.$.hacksCarousel.fetchView('center');
125 view.resize(window.innerWidth, window.innerHeight);
126 var view = this.$.hacksCarousel.fetchView('left');
128 view.resize(window.innerWidth, window.innerHeight);
129 var view = this.$.hacksCarousel.fetchView('right');
131 view.resize(window.innerWidth, window.innerHeight);
133 hackHidden: function(direction) {
134 var view = this.$.hacksCarousel.fetchView(direction);
135 //enyo.log('view ' + view + ' hidden');
139 getHack: function(index) {
140 return {kind: this.hacksList[index].kind};
142 getLeft: function(inSender, inSnap) {
143 if (inSnap && this.index > 0) {
145 this.$.hacksListSelector.setValue(this.index);
146 this.hackHidden('right');
148 this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
153 return this.getHack(this.index - 1);
155 getRight: function(inSender, inSnap) {
156 if (inSnap && this.index < this.hacksList.length) {
158 this.$.hacksListSelector.setValue(this.index);
159 this.hackHidden('left');
161 this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark);
163 if (this.index == this.hacksList.length - 1)
166 return this.getHack(this.index + 1);
168 scrolling: function(inSender) {
169 if (inSender.scrollLeft == 0 || inSender.scrollLeft == inSender.getBoundaries().right)
172 startScroll: function(inSender) {
175 stopScroll: function(inSender) {
176 this.lastScrollPos = this.$.hacksCarousel.scrollLeft;
179 closeNoPrefsDialog: function() {
180 this.$.noPrefsDialog.close();