Skip to content

Commit

Permalink
more UI stuffs for feed item and content
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiefu committed Nov 13, 2014
1 parent 79e0963 commit d9a1d0d
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 71 deletions.
2 changes: 1 addition & 1 deletion projects/pica/elements/google-apis/google-feeds.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
query: 'queryChanged'
},
beforeCreated: function() {
this.count = 27;
this.count = 32;
this.pendingFeeds = [];
},
feedChanged: function() {
Expand Down
35 changes: 30 additions & 5 deletions projects/pica/elements/pi-app.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pi-app {
x-icon, item {
cursor: pointer;
}
#drawer {
[drawer] {
background-color: white;
box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2);
}
Expand All @@ -20,7 +20,7 @@ x-icon, item {
[header] > * {
margin: 4px 8px;
}
#drawer [header] {
[drawer] > [header] {
color: #fafafa;
background-color: #02a8f3;
}
Expand All @@ -42,11 +42,21 @@ x-repeater {
text-align: center;
}
x-repeater > * {
-moz-box-sizing: border-box;
box-sizing: border-box;
height: 245px;
width: 210px;
margin: 4px;
text-align: left;
overflow: hidden;
}
@media screen and (max-width: 450px) {
x-repeater > * {
width: 174px;
height: 260px;
margin: 2px;
font-size: 13px;
}
}

/* main */
Expand Down Expand Up @@ -100,10 +110,25 @@ x-repeater > * {
color: #fafafa;
background-color: #069bde;
}
#article #content {
#article > .main-outer {
width: 100%;
}
#articleMain {
background-color: white;
max-width: 600px;
padding: 24px 64px;
max-width: 760px;
padding: 40px;
margin: 0 auto;
}
#articleMain > .title {
padding: 0 0 20px;
font-size: 26px;
}
#articleMain > .info {
padding-bottom: 16px;
color: #666;
}
#articleMain > #content {
overflow: hidden;
}
.animate > * {
transition: -webkit-transform ease-out 500ms;
Expand Down
33 changes: 22 additions & 11 deletions projects/pica/elements/pi-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<x-drawer-panel2 id="drawerPanel" flex>

<div drawer id="drawer" vertical layout>
<div drawer vertical layout>

<div flex none header>
<div horizontal layout>
Expand Down Expand Up @@ -53,7 +53,7 @@
<div id="topic" flex vertical layout>
<div flex none header horizontal layout>
<x-icon icon="back" on-click="topicsAction"></x-icon>
<span flex>Topic</span>
<span flex>{{topicName}}</span>
<x-icon icon="apps" on-click="toggleLayoutAction"></x-icon>
<x-icon icon="refresh"></x-icon>
<x-icon icon="more-vert"></x-icon>
Expand All @@ -68,11 +68,17 @@
<div id="article" flex vertical center layout>
<div flex none self-stretch header horizontal layout>
<x-icon icon="back" on-click="topicAction"></x-icon>
<span flex>Article</span>
<span flex>{{topicName}}</span>
<x-icon icon="refresh"></x-icon>
<x-icon icon="more-vert"></x-icon>
</div>
<div id="content" flex vertical layout></div>
<div class="main-outer" flex scroll>
<div id="articleMain">
<div class="title">{{articleTitle}}</div>
<div class="info">{{articleInfo}}</div>
<div id="content"></div>
</div>
</div>
</div>

</x-pages>
Expand Down Expand Up @@ -103,18 +109,23 @@
this.animatize(this.$.topics);
},
topicAction: function(e) {
this.items = this.$.topicsSelector.selected.item.items;
var t = this.$.topicsSelector.selected.item;
this.items = t.items;
this.topicName = t.topic;
this.page = 1;
this.animatize(this.$.articles);
},
articleAction: function() {
var content = this.$.articlesSelector.selected.item.content;
var a = this.$.articlesSelector.selected.item;
this.articleTitle = a.title;
this.articleInfo = 'by ' + a.author + ' on ' + a.publishedDate;
var content = a.content;
if (content) {
content = content.replace(/(<iframe.*?>.*?<\/iframe>)/g, '');
this.$.content.innerHTML =
content.replace(/(<iframe.*?>.*?<\/iframe>)/g, '');
}
this.$.content.innerHTML = content;
this.page = 2;
this.animatize(this.$.content);
this.animatize(this.$.articleMain);
},
toggleLayoutAction: function() {
this.quilt = !this.quilt;
Expand All @@ -128,13 +139,13 @@
a$.className = '';
for (var i=0, c=a$.firstElementChild; c; c=c.nextElementSibling, i++) {
c.style.transform = c.style.webkitTransform =
'translateY(' + (Math.pow(i, 2.2)*3 + 50) + 'px)';
'translate3d(0,' + (Math.pow(i, 2.2)*3 + 50) + 'px,0)';
}
requestAnimationFrame(function() {
requestAnimationFrame(function() {
a$.className = 'animate';
for (var c=a$.firstElementChild; c; c=c.nextElementSibling) {
c.style.transform = c.style.webkitTransform = 'translateY(0px)';
c.style.transform = c.style.webkitTransform = 'translate3d(0,0,0)';
}
});
});
Expand Down
129 changes: 87 additions & 42 deletions projects/pica/elements/pi-feed.html
Original file line number Diff line number Diff line change
@@ -1,49 +1,94 @@
<script>

Polymer({
name: 'pi-feed',
bind: {
topic: 'topicChanged'
},
topicChanged: function() {
if (this.topic) {
this.populateFeed(this.topic);
(function() {

Polymer({
name: 'pi-feed',
bind: {
topic: 'topicChanged'
},
topicChanged: function() {
if (this.topic) {
this.populateFeed(this.topic);
}
},
populateFeed: function(topic) {
var googleFeeds = document.createElement('google-feeds');
googleFeeds.addEventListener('google-feeds-response', function(e) {
var feed = e.detail.feed;
var items = feed && feed.entries || [];
topic.items = items;
// favicon
var icon = GET_FAVICON_URL + feed.link;
//
items.forEach(function(item) {
// scrape image url
var m$ = item.content.match(/<img[^>]+src="([^">]+)"/);
item.thumb = m$ && m$[1];
// time since
if (item.publishedDate) {
var d = item._date || new Date(item.publishedDate);
item._date = d;
item.since = timeSince(d);
}
//
item.label = feed.title;
item.icon = icon;
item.blurb = item.contentSnippet;
});
this.fire('feed-load');
this.findTopicThumbnail();
}.bind(this));
googleFeeds.feed = topic.feed;
},
findTopicThumbnail: function(index) {
index = index || 0;
var item = this.topic.items[index];
if (!this.topic.thumb && item) {
var image = new Image();
image.src = item.thumb;
image.onload = this.thumbnailLoaded.bind(this, index);
}
},
thumbnailLoaded: function(index, e) {
var img = e.currentTarget;
// use the image if the size > 10 x 10px
if (img.width > 10 && img.height > 10) {
this.topic.thumb = img.src;
this.fire('topic-thumb-change');
} else {
this.findTopicThumbnail(++index);
}
}
},
populateFeed: function(topic) {
var googleFeeds = document.createElement('google-feeds');
googleFeeds.addEventListener('google-feeds-response', function(e) {
var items = e.detail.feed && e.detail.feed.entries || [];
topic.items = items;
items.forEach(function(item) {
var m$ = item.content.match(/<img[^>]+src="([^">]+)"/);
item.thumb = m$ && m$[1];
item.blurb = item.contentSnippet;
});
this.fire('feed-load');
this.findTopicThumbnail();
}.bind(this));
googleFeeds.feed = topic.feed;
},
findTopicThumbnail: function(index) {
index = index || 0;
var item = this.topic.items[index];
if (!this.topic.thumb && item) {
var image = new Image();
image.src = item.thumb;
image.onload = this.thumbnailLoaded.bind(this, index);
});

var GET_FAVICON_URL = 'http://s2.googleusercontent.com/s2/favicons?alt=feed&domain_url=';

function timeSince(date) {
var s = Math.floor(((new Date()) - date) / 1000);
var t = Math.floor(s / 31536000);
if (t > 1) {
return t + 'y';
}
},
thumbnailLoaded: function(index, e) {
var img = e.currentTarget;
// use the image if the size > 10 x 10px
if (img.width > 10 && img.height > 10) {
this.topic.thumb = img.src;
this.fire('topic-thumb-change');
} else {
this.findTopicThumbnail(++index);
t = Math.floor(s / 2592000);
if (t > 1) {
return t + 'M';
}
}
});
t = Math.floor(s / 86400);
if (t >= 1) {
return t + 'd';
}
t = Math.floor(s / 3600);
if (t >= 1) {
return t + 'h';
}
t = Math.floor(s / 60);
if (t > 1) {
return t + 'm';
}
return Math.floor(s) + 's';
};

})();

</script>
26 changes: 14 additions & 12 deletions projects/pica/elements/pi-item.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@
pi-item > #thumb {
background-size: cover;
}
pi-item #info > span {
font-size: 12px;
opacity: 0.8;
}

</style>

<template>

<div id="thumb" flex></div>
<span flex vertical layout>
<span id="blurb"></span>
<span id="blurb">{{blurb}}</span>
<div flex></div>
<span id="info" horizontal layout>
<img flex none src="{{icon}}">&nbsp;<span flex>The Verge</span><span flex none>2h</span>
<span id="info" horizontal center layout>
<img flex none src="{{icon}}">&nbsp;<span flex>{{label}}</span><span flex none>{{since}}</span>
</span>
</span>

Expand All @@ -35,18 +39,19 @@
name: 'pi-item',
hostAttributes: 'vertical inline layout',
bind: {
blurb: 'blurb',
item: 'itemChanged',
visibility: 'visibilityChanged',
background: 'backgroundChanged'
},
computed: {
blurb: 'computeBlurb(item)',
visibility: 'computeVisibility(item)',
background: 'computeBackground(item)',
icon: 'computeIcon(item)'
background: 'computeBackground(item)'
},
computeBlurb: function(item) {
return item.blurb;
itemChanged: function(item) {
this.blurb = item.blurb;
this.label = item.label;
this.icon = item.icon;
this.since = item.since;
},
computeVisibility: function(item) {
return item && Boolean(item.blurb) ? '' : 'hidden';
Expand All @@ -59,9 +64,6 @@
},
backgroundChanged: function() {
this.$.thumb.style.backgroundImage = this.background;
},
computeIcon: function(item) {
return item && item.icon ? 'assets/' + item.icon : '';
}
});

Expand Down

0 comments on commit d9a1d0d

Please sign in to comment.