From 5d68db92b37545fb03332a46b01d0f1aad8ce64b Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 17 Sep 2015 21:26:52 -0400 Subject: populate selector --- .../platforms/ios/www/js/lib/blogs/ArchiveView.js | 15 +++++++++- .../platforms/ios/www/js/lib/blogs/BlogView.js | 33 ++++++++++++++++++++++ .../platforms/ios/www/js/lib/blogs/HubView.js | 18 +++++++++++- .../platforms/ios/www/js/lib/blogs/StoryView.js | 16 +++++++++-- 4 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 StoneIsland/platforms/ios/www/js/lib/blogs/BlogView.js (limited to 'StoneIsland/platforms/ios/www/js/lib/blogs') diff --git a/StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js b/StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js index 742ee0f2..31dfd743 100644 --- a/StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js +++ b/StoneIsland/platforms/ios/www/js/lib/blogs/ArchiveView.js @@ -8,13 +8,26 @@ var ArchiveView = View.extend({ initialize: function(){ this.$content = this.$(".content") + this.$loader = this.$(".loader") + this.scroller = new IScroll('#archive .scroll') }, show: function(){ document.body.className = "archive" }, - populate: function(){ + populate: function(data){ + this.data = data + this.$loader.hide() + this.$content.empty() + this.data.forEach(function(row){ + var t = this.template.replace({{image}}, row.image.url) + .replace({{code}}, row.code) + .replace({{title}}, row.title) + .replace({{body}}, row.body) + this.$content.append(t) + }.bind(this)) }, + }) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/blogs/BlogView.js b/StoneIsland/platforms/ios/www/js/lib/blogs/BlogView.js new file mode 100644 index 00000000..70fc910a --- /dev/null +++ b/StoneIsland/platforms/ios/www/js/lib/blogs/BlogView.js @@ -0,0 +1,33 @@ +var BlogView = View.extend({ + + data: null, + loaded: false, + initialize: function(){ + this.loader = new Loader () + this.fetch() + }, + + fetch: function(){ + $.ajax({ + method: "GET", + url: "http://stone.sup.land/db.json", + success: this.success.bind(this), + cache: true, + }) + }, + + success: function(data){ + this.loaded = true + this.data = data + this.loader.preloadImage(data.archive[0].image.url, function(img){ + app.archive.populate(data.archive) + }) + this.loader.preloadImage(data.hub[0].image.url, function(img){ + app.hub.populate(data.hub) + }) + this.loader.preloadImage(data.story[0].image.url, function(img){ + app.story.populate(data.story) + }) + }, + +}) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/blogs/HubView.js b/StoneIsland/platforms/ios/www/js/lib/blogs/HubView.js index 430464b1..88ae6f1f 100644 --- a/StoneIsland/platforms/ios/www/js/lib/blogs/HubView.js +++ b/StoneIsland/platforms/ios/www/js/lib/blogs/HubView.js @@ -8,13 +8,29 @@ var HubView = View.extend({ initialize: function(){ this.$content = this.$(".content") + this.$loader = this.$(".loader") + this.scroller = new IScroll('#hub .scroll') }, show: function(){ document.body.className = "hub" }, - populate: function(){ + populate: function(data){ + this.data = data + this.$loader.hide() + this.$content.empty() + this.data.forEach(function(row){ + var t = this.template.replace({{image}}, row.image.url) + .replace({{date}}, row.date) + .replace({{code}}, row.code) + .replace({{title}}, row.title) + .replace({{subtitle}}, row.subtitle) + .replace({{link}}, row.link) + .replace({{body}}, row.body) + this.$content.append(t) + }.bind(this)) }, + }) \ No newline at end of file diff --git a/StoneIsland/platforms/ios/www/js/lib/blogs/StoryView.js b/StoneIsland/platforms/ios/www/js/lib/blogs/StoryView.js index ed46af31..0f03a518 100644 --- a/StoneIsland/platforms/ios/www/js/lib/blogs/StoryView.js +++ b/StoneIsland/platforms/ios/www/js/lib/blogs/StoryView.js @@ -8,13 +8,25 @@ var StoryView = View.extend({ initialize: function(){ this.$content = this.$(".content") + this.$loader = this.$(".loader") + this.scroller = new IScroll('#story .scroll') }, show: function(){ document.body.className = "story" }, - - populate: function(){ + + populate: function(data){ + this.data = data + this.$loader.hide() + this.$content.empty() + this.data.forEach(function(row){ + var t = this.template.replace({{image}}, row.image.url) + .replace({{date}}, row.date) + .replace({{title}}, row.title) + .replace({{body}}, row.body) + this.$content.append(t) + }.bind(this)) }, }) \ No newline at end of file -- cgit v1.2.3-70-g09d2