Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 5 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
Showing with 220 additions and 28 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 app.html
  3. +17 −3 css/app.css
  4. +1 −0 depends.js
  5. +24 −3 js/EntryItem.js
  6. +13 −2 js/ServiceItem.js
  7. +54 −0 js/Storage.js
  8. +106 −20 js/app.js
View
1 .gitignore
@@ -1 +1,2 @@
.project
+build
View
4 app.html
@@ -3,12 +3,16 @@
<head>
<title>MTA Status</title>
+ <meta name="viewport" content="height=device-height"/>
<script src="js/enyo/enyo.js"></script>
<script src="depends.js"></script>
</head>
<body>
<script type="text/javascript">
+ if (window.PalmSystem) {
+ window.PalmSystem.stageReady();
+ };
new App().renderInto(document.body);
</script>
</body>
View
20 css/app.css
@@ -1,11 +1,12 @@
.panels > * {
- width: 350px;
+ width: 300px;
}
/* be responsive */
-@media all and (max-width: 450px) {
+@media all and (max-width: 480px) {
.panels > * {
min-width: 100%;
+/* width: 100%;*/
}
}
@@ -84,4 +85,17 @@ p {
.entry-item {
font-size: 16px;
-}
+}
+
+.entry-item-selected {
+ background-color: #00688B;
+}
+
+.itemFavorite {
+ background-image: url("../images/star.png");
+}
+
+.itemFavoriteSelected {
+ background-position: 0px -24px !important;
+}
+}
View
1 depends.js
@@ -4,6 +4,7 @@ enyo.depends(
"$lib/layout/",
"$lib/layout/panels",
"$lib/../parseData.js",
+ "$lib/../Storage.js",
"$lib/../EntryItem.js",
"$lib/../ServiceItem.js",
"$lib/../app.js",
View
27 js/EntryItem.js
@@ -5,6 +5,7 @@ enyo.kind({
style: "position: relative;",
events: {
onItemSelected: "",
+ onItemFavorite: "",
},
handlers: {
ontap: "handleTap"
@@ -18,13 +19,20 @@ enyo.kind({
{
name: "itemStatus",
caption: "",
- style: "position: absolute; top: 10px; right: 10px;"
+ style: "position: absolute; top: 10px; right: 39px;"
+ },
+ {
+ name: "itemFavorite",
+ caption: "",
+ classes: "itemFavorite",
+ style: "position: absolute; top: 10px; right: 10px; height: 24px; width: 24px;"
}
],
// ontap: "handleTap",
published: {
title: "",
- data: null,
+ data: null,
+ favorite: false
},
titleChanged: function(inSender, inEvent) {
this.$.itemTitle.setContent(this.getTitle());
@@ -50,7 +58,20 @@ enyo.kind({
return statuses[inString];
},
+ favoriteChanged: function(inSender, inEvent) {
+ this.$.itemFavorite.addRemoveClass('itemFavoriteSelected', this.getFavorite());
+ },
handleTap: function(inSender, inEvent) {
- this.doItemSelected(this.getData());
+ var favorite, d;
+ if (inSender.name === "itemFavorite") {
+ d = this.getData();
+ favorite = !d.favorite;
+ d.favorite = favorite;
+ this.setFavorite(favorite);
+ this.doItemFavorite(d);
+ }
+ else {
+ this.doItemSelected(this.getData());
+ }
}
});
View
15 js/ServiceItem.js
@@ -37,9 +37,19 @@ enyo.kind({
published: {
title: "",
data: null,
+ key: "",
+ open: false
+ },
+ events: {
+ onServiceTap: "",
},
titleTap: function(inSender, inEvent) {
- this.$.EntryListDrawer.setOpen(!this.$.EntryListDrawer.open);
+ this.setOpen(!this.$.EntryListDrawer.open)
+ this.doServiceTap({"open": this.getOpen()})
+ },
+ openChanged: function(inSender, inEvent) {
+ // enyo.log("openChanged" + this.getKey());
+ this.$.EntryListDrawer.setOpen(this.getOpen());
},
titleChanged: function(inSender, inEvent) {
this.$.Title.setContent(this.getTitle());
@@ -57,7 +67,8 @@ enyo.kind({
itemControl.setTitle(k);
itemControl.setData(d);
-
+ itemControl.setFavorite(d.favorite);
+ this.$.EntryListDrawer.setOpen(this.getOpen());
return true;
},
getLines: function() {
View
54 js/Storage.js
@@ -0,0 +1,54 @@
+enyo.kind({
+ name: "Storage",
+ kind: "Component",
+
+ statics: {
+ set: function(name, obj){
+ if(typeof name === "string") {
+ if(typeof obj === "object") {
+ localStorage.setItem(name, JSON.stringify(obj));
+ }
+ else if(typeof obj === "string") {
+ localStorage.setItem(name, obj);
+ }
+ }
+ },
+
+ /* Get the item with the key 'name'. */
+ get: function(name){
+ var result;
+ if(typeof name === "string") {
+ result = localStorage.getItem(name);
+ }
+
+ if(typeof result === "string"){
+ return JSON.parse(result);
+ } else if(typeof result === "object" && result !== null) {
+ enyo.log("OBJECT: " + result);
+ throw "ERROR [Storage.get]: getItem returned an object. Should be a string.";
+ } else if(typeof result === "undefined" || result === null){
+ //TODO: what to do? log?
+ }
+
+ },
+
+ /* Remove the item with the key 'name'. */
+ remove: function(name){
+ if(typeof name === "string") {
+ localStorage.remove(name);
+ } else {
+ throw "ERROR [Storage.remove]: 'name' was not a String.";
+ }
+ },
+
+ /* Returns length of all localStorage objects. */
+ __getSize: function(){
+ var i, count = 0;
+ for(i = 0; i < localStorage.length; i++){
+ count += localStorage.getItem(localStorage.key()).length;
+ }
+ return count;
+ }
+ }
+
+});
View
126 js/app.js
@@ -32,35 +32,55 @@ enyo.kind({
draggable: false,
components: [
{
- name: "MainList",
- kind: "Repeater",
- style: "overflow: auto;",
+ kind: "Scroller",
id: "mainList",
- rows: 0,
- onSetupItem: "setUpRow",
components: [
{
- name: "ServiceItem",
- kind: "ServiceItem"
+ name: "MainList",
+ kind: "Repeater",
+ style: "overflow: auto;",
+ rows: 0,
+ onSetupItem: "setUpRow",
+ components: [
+ {
+ name: "ServiceItem",
+ kind: "ServiceItem"
+ }
+ ]
}
]
},
{
- id: "detailPane",
- name: "DetailPane",
+ kind: "Scroller",
classes: "onyx",
- style: "overflow: auto;",
- allowHtml: true,
- content: ""
+ components: [
+ {
+ id: "detailPane",
+ name: "DetailPane",
+ style: "overflow: auto;",
+ allowHtml: true,
+ content: ""
+ }
+ ]
}
]
}
],
published: {
data: "",
+ favorites: "",
},
handlers: {
- onItemSelected: "entryItemSelected"
+ onItemSelected: "entryItemSelected",
+ onItemFavorite: "entryItemFavorite",
+ onServiceTap: "serviceTap"
+ },
+ create: function() {
+ this.inherited(arguments);
+ this.storage = Storage;
+ this.setFavorites(this.storage.get("favorites") || []);
+ this.opened = this.storage.get("opened") || {};
+ this.setData(this.storage.get("feedData") || {});
},
getMTAData: function() {
var ajax = new enyo.Ajax({
@@ -75,24 +95,30 @@ enyo.kind({
this.setData(parseData(inResponse));
},
dataChanged: function(inSender, inResponse) {
+ this.markFavorites();
this.$.MainList.setCount(this.getServices().length);
+ this.storage.set("feedData", this.getData());
+ return true;
},
setUpRow: function(inSender, inEvent) {
var i = inEvent.index;
var s = this.getServices()[i];
var rowControl = inEvent.item.controls[0];
rowControl.setTitle(s.display);
- if ( s.key.length ) {
+ if ( s.key !== '_favorites_') {
rowControl.setData(this.getData()[s.key]);
}
-
- //set the data too
-
+ else {
+ rowControl.setData(this.parseFavorites());
+ }
+ rowControl.setKey(s.key);
+ rowControl.setOpen(this.opened[s.key]);
+ // enyo.log("setUpRow " + s.key);
return true;
},
getServices: function() {
var services = [
- { display: 'Favorites', key: '' },
+ { display: 'Favorites', key: '_favorites_' },
{ display: 'Subway', key: 'subway' },
{ display: 'Bus', key: 'bus' },
{ display: 'LIRR', key: 'LIRR' },
@@ -101,19 +127,79 @@ enyo.kind({
];
return services;
},
+ parseFavorites: function() {
+ var f = this.getFavorites().sort();
+ var i = 0;
+ var l = f.length;
+ var keyParts = [];
+ var d = {};
+ var favorites = {}
+
+ for (i = 0; i < l; i += 1) {
+ keyParts = f[i].split(".");
+ d[keyParts[1]] = this.getData()[keyParts[0]][keyParts[1]];
+ }
+
+ return d;
+ },
+ markFavorites: function() {
+ var f = this.parseFavorites();
+ var fKeys = Object.keys(f);
+ var i = 0;
+ var l = fKeys.length;
+
+ for (i = 0; i < l; i += 1) {
+ f[fKeys[i]].favorite = true;
+ }
+ },
entryItemSelected: function(inSender, inEvent) {
if(this.isSmall()) {
this.$.Main.setIndex(1);
this.$.BackButton.setShowing(true);
}
+ if (this.lastSelectedItem) {
+ this.lastSelectedItem.addRemoveClass("entry-item-selected", false);
+ }
+ inEvent.originator.addRemoveClass("entry-item-selected", true);
+ this.lastSelectedItem = inEvent.originator;
this.$.DetailPane.setContent(inEvent.text);
},
backTap: function(inSender, inEvent) {
this.$.BackButton.setShowing(false);
+ if (this.lastSelectedItem) {
+ this.lastSelectedItem.addRemoveClass("entry-item-selected", false);
+ }
this.$.Main.setIndex(0);
},
isSmall: function() {
- return window.matchMedia && window.matchMedia("all and (max-width:450px)").matches;
+ // console.log("client width: " + document.documentElement.clientWidth);
+ return document.documentElement.clientWidth <= 480;
+ // return window.matchMedia && window.matchMedia("all and (max-width:481px)").matches;
+ },
+ entryItemFavorite: function(inSender, inEvent) {
+ // enyo.log(inSender);
+ // enyo.log(inEvent);
+ var favorites = this.getFavorites() || [];
+ var idx;
+
+ if ( inEvent.favorite ) {
+ favorites.push(inEvent.favoriteKey);
+ }
+ else {
+ idx = favorites.indexOf(inEvent.favoriteKey);
+ favorites.splice(idx, 1);
+ }
+ // enyo.log(this.$.MainList.$);
+ this.setFavorites(favorites);
+ this.storage.set("favorites", favorites);
+ delete inEvent.originator;
+ this.dataChanged();
+ return true;
+ },
+ serviceTap: function(inSender, inEvent) {
+ var opened = this.opened || [];
+ opened[inEvent.originator.getKey()] = inEvent.open;
+ this.opened = opened;
+ this.storage.set("opened", opened);
}
-
});

No commit comments for this range

Something went wrong with that request. Please try again.