X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=Main.js;h=20c5fdb0f2f6059b3ffdfa35a53166204d820211;hb=HEAD;hp=eb02da9e0ce90ec0f878f3e46661e18d797946c1;hpb=7f476a519a8abeecf6c1e19e4e91635ea324d608;p=Hacks.git diff --git a/Main.js b/Main.js index eb02da9..20c5fdb 100644 --- a/Main.js +++ b/Main.js @@ -2,49 +2,61 @@ * See COPYING for licensing information */ enyo.kind({ name: "Main", - kind: "VFlexBox", - style: "background-color: black", + kind: "Pane", components: [ {kind: "ApplicationEvents", onWindowActivated: "windowActivated", onWindowDeactivated: "windowDeactivated"}, - {name: "hacksCarousel", kind: "Carousel", flex: 1, onGetLeft: "getLeft", onGetRight: "getRight", onScroll: "scrolling", onScrollStart: "startScroll", onScrollStop: "stopScroll"}, - //{name: "hacksSelector", kind: "HacksSelector"} - {name: "info", kind: "HFlexBox", className: "info", style: "opacity: 0", showing: false, components: [ - {name: "title"}, - {kind: "Spacer"}, - {name: "notice", className: "notice"} - ]} + {name: "mainView", kind: "VFlexBox", components: [ + {name: "hacksCarousel", kind: "Carousel", flex: 1, onGetLeft: "getLeft", onGetRight: "getRight", onScroll: "scrolling", onScrollStart: "startScroll", onScrollStop: "stopScroll"}, + {name: "info", kind: "HFlexBox", className: "info", align: "center", style: "opacity: 0", onclick: "infoFade", components: [ + {className: "wrench", onclick: "openPreferences"}, + {name: "hacksListSelector", kind: "ListSelector", popupAlign: "left", onChange: "selectHack", style: "width: 200px"}, + {kind: "Spacer"}, + {name: "notice", className: "notice"} + ]}, + {name: "noPrefsDialog", kind: "ModalDialog", caption: "No Preferences", components: [ + {kind: "Button", content: "Okay", onclick: "closeNoPrefsDialog"} + ]} + ]}, + {name: "preferencesView", kind: "HackPreferences", onClose: "savePreferences"} ], hacksList: [ - {name: "Nimbus", kind: "Nimbus", dark: false}, - {name: "Landscape", kind: "Landscape", dark: false}, - {name: "Munch", kind: "Munch", dark: true}, - {name: "Orbit", kind: "Orbit", dark: false}, - {name: "Pixelfade", kind: "Pixelfade", dark: true}, - //{name: "Swarm", kind: "Swarm", dark: false}, // crashy - //{name: "Spinner.CGA", kind: "XSpinnerCGA", dark: true}, // no webfont support - {name: "Spinner", kind: "XSpinner", dark: true} + {name: "Labyrinth", kind: "Labyrinth"}, + {name: "Nimbus", kind: "Nimbus"}, + {name: "HexaSpinner", kind: "HexaSpinnerHack"}, + {name: "Landscape", kind: "Landscape"}, + {name: "Munch", kind: "Munch"}, + {name: "Orbit", kind: "Orbit"}, + {name: "Pixelfade", kind: "Pixelfade"}, + //{name: "Swarm", kind: "Swarm"}, // crashy + //{name: "Spinner.CGA", kind: "XSpinnerCGA"}, // no webfont support + {name: "Spinner", kind: "XSpinner"} ], create: function() { this.inherited(arguments); - /* - this.index = localStorage.getItem('hack.index'); - if (!this.index) + try { + this.index = parseInt(localStorage.getItem('hack.index')); + if (!this.index) + this.index = 0; + } catch(e) { + enyo.log("Could not load last hack index"); this.index = 0; - */ - this.index = 0; + } this.lastScrollPos = 0; this.$.hacksCarousel.setCenterView(this.getHack(this.index)); - //this.$.hacksSelector.setHacksList(this.hacksList); }, ready: function() { + var displayList = []; + for (var i = 0; i < this.hacksList.length; i++) { + displayList.push({ + caption: this.hacksList[i].name, + value: i + }); + } + this.$.hacksListSelector.setItems(displayList); + this.$.hacksListSelector.setValue(this.index); this.startHack(); window.addEventListener('resize', this.resizeHack.bind(this), false); this.setNotice('Swipe for more...'); - this.setTitle(this.hacksList[this.index].name); - }, - setTitle: function(title) { - this.$.title.setContent(title); - this.infoFade(); }, setNotice: function(notice) { this.$.notice.setContent(notice); @@ -52,30 +64,67 @@ enyo.kind({ }, infoFade: function() { this.$.info.setStyle('opacity: 1'); - this.$.info.show(); clearTimeout(this.noticeTimer); this.noticeTimer = setTimeout(function() { this.$.info.setStyle('opacity: 0'); setTimeout(function() { - this.$.info.hide(); - this.setNotice(''); - this.setTitle(''); + this.$.notice.setContent(''); }.bind(this), 600); }.bind(this), 5000); }, + openPreferences: function() { + var view = this.$.hacksCarousel.fetchView('center'); + + var meta = view.getPreferencesMetadata(); + if (meta.length) { + view.stop(); + var values = view.getPreferences(); + this.$.preferencesView.load(this.hacksList[this.index].name, meta, values); + this.selectView(this.$.preferencesView); + } else { + this.$.noPrefsDialog.openAtCenter(); + } + }, + savePreferences: function(inSender, prefs) { + var view = this.$.hacksCarousel.fetchView('center'); + if (prefs == null) { + enyo.log("Clearing prefs"); + view.resetPreferences(prefs); + this.selectHack(this, this.index); + } else { + enyo.log("Saving prefs: " + JSON.stringify(prefs)); + view.setPreferences(prefs); + view.start(); + } + this.back(); + }, windowActivated: function() { this.startHack(); }, windowDeactivated: function() { this.stopHack(); }, + selectHack: function(inSender, inValue) { + this.stopHack(); + this.index = inValue; + this.lastScrollPos = 0; + this.$.hacksCarousel.setCenterView(this.getHack(this.index)); + // For some reason, setCenterView above fires the startScroll + // event without a subsequent stopScroll event. To work around + // this, we defer the start until later. + setTimeout(function() { this.startHack() }.bind(this), 20); + }, startHack: function(direction) { var view = this.$.hacksCarousel.fetchView(direction || 'center'); //enyo.log('starting view ' + view); if (view) view.start(); - //localStorage.setItem('hack.index', this.index); + try { + localStorage.setItem('hack.index', this.index); + } catch(e) { + enyo.log("Could not set hack index"); + } }, stopHack: function(direction) { var view = this.$.hacksCarousel.fetchView(direction || 'center'); @@ -85,8 +134,12 @@ enyo.kind({ }, resizeHack: function() { var view = this.$.hacksCarousel.fetchView('center'); - - //enyo.log('resizing view ' + view); + if (view) + view.resize(window.innerWidth, window.innerHeight); + var view = this.$.hacksCarousel.fetchView('left'); + if (view) + view.resize(window.innerWidth, window.innerHeight); + var view = this.$.hacksCarousel.fetchView('right'); if (view) view.resize(window.innerWidth, window.innerHeight); }, @@ -102,9 +155,9 @@ enyo.kind({ getLeft: function(inSender, inSnap) { if (inSnap && this.index > 0) { this.index--; + this.$.hacksListSelector.setValue(this.index); this.hackHidden('right'); - this.setTitle(this.hacksList[this.index].name); - this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark); + this.infoFade(); } if (this.index == 0) return null; @@ -114,9 +167,9 @@ enyo.kind({ getRight: function(inSender, inSnap) { if (inSnap && this.index < this.hacksList.length) { this.index++; + this.$.hacksListSelector.setValue(this.index); this.hackHidden('left'); - this.setTitle(this.hacksList[this.index].name); - this.$.info.addRemoveClass('dark', this.hacksList[this.index].dark); + this.infoFade(); } if (this.index == this.hacksList.length - 1) return null; @@ -126,8 +179,6 @@ enyo.kind({ scrolling: function(inSender) { if (inSender.scrollLeft == 0 || inSender.scrollLeft == inSender.getBoundaries().right) this.startHack(); - //this.$.hacksSelector.index = this.index + ((inSender.scrollLeft - this.lastScrollPos) / window.innerWidth); - //this.$.hacksSelector.draw(); }, startScroll: function(inSender) { this.stopHack(); @@ -135,5 +186,8 @@ enyo.kind({ stopScroll: function(inSender) { this.lastScrollPos = this.$.hacksCarousel.scrollLeft; this.startHack(); + }, + closeNoPrefsDialog: function() { + this.$.noPrefsDialog.close(); } });