summaryrefslogtreecommitdiff
path: root/public/assets/js
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-11 04:25:19 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-11 04:25:19 +0100
commit4c775f12ff6eda48fc22bec9ed336e60c1a0e07e (patch)
tree792b3906107442dc6823440fa0bf21a7bea1a224 /public/assets/js
parent6702125f12820c504ae18114f99fee3e13b2616f (diff)
cssssssss
Diffstat (limited to 'public/assets/js')
-rw-r--r--public/assets/js/lib/router.js5
-rw-r--r--public/assets/js/lib/views/details/comments.js27
-rw-r--r--public/assets/js/lib/views/details/index.js2
-rw-r--r--public/assets/js/lib/views/index/hootbox.js4
-rw-r--r--public/assets/js/lib/views/index/index.js13
-rw-r--r--public/assets/js/lib/views/index/lastlog.js4
-rw-r--r--public/assets/js/lib/views/index/threadbox.js2
-rw-r--r--public/assets/js/vendor/view/router.js2
8 files changed, 47 insertions, 12 deletions
diff --git a/public/assets/js/lib/router.js b/public/assets/js/lib/router.js
index 122822b..8146906 100644
--- a/public/assets/js/lib/router.js
+++ b/public/assets/js/lib/router.js
@@ -4,8 +4,8 @@ var SiteRouter = Router.extend({
routes: {
"/": 'login',
- "/index": 'index',
"/index/:keyword": 'index',
+ "/index": 'index',
"/login": 'login',
"/details/:id": 'details',
"/post": 'post',
@@ -22,7 +22,8 @@ var SiteRouter = Router.extend({
},
index: function(keyword){
- app.view = new IndexView (keyword)
+ app.view = new IndexView ()
+ app.view.load(keyword)
},
login: function(){
diff --git a/public/assets/js/lib/views/details/comments.js b/public/assets/js/lib/views/details/comments.js
index c031efc..65473c6 100644
--- a/public/assets/js/lib/views/details/comments.js
+++ b/public/assets/js/lib/views/details/comments.js
@@ -5,6 +5,7 @@ var CommentsView = FormView.extend({
events: {
"focus textarea": "focus",
"blur textarea": "blur",
+ "click .remove": "remove",
},
initialize: function(){
@@ -18,22 +19,26 @@ var CommentsView = FormView.extend({
},
parse: function(comment){
- if (! comment.comment.length) return ""
+ if (! comment.comment.length) return $('<div></div>')
var datetime = verbose_date(comment.date, true)
var t = this.template.replace(/{{username}}/g, comment.username)
+ .replace(/{{id}}/g, comment.id)
.replace(/{{comment}}/g, tidy_urls(comment.comment))
.replace(/{{date}}/g, datetime[0])
.replace(/{{time}}/g, datetime[1])
- return t
+ console.log(t)
+ var $t = $(t)
+ return $t
},
prependComment: function(comment){
- var $el = $( this.parse(comment) )
+ var $el = this.parse(comment)
this.$el.prepend($el)
},
appendComment: function(comment){
- var $el = $( this.parse(comment) )
+ var $el = this.parse(comment)
+ console.log($el)
$el.insertBefore(this.$formRow)
},
@@ -48,5 +53,19 @@ var CommentsView = FormView.extend({
blur: function(){
app.typing = false
},
+
+ remove: function(e){
+ var id = $(e.target).data('id')
+ var should_remove = confirm("Are you sure you want to delete this comment? #" + id)
+ if (should_remove) {
+ $.ajax({
+ method: "DELETE",
+ url: "/api/comment/" + id,
+ success: function(){
+ window.location.reload()
+ },
+ })
+ }
+ },
}) \ No newline at end of file
diff --git a/public/assets/js/lib/views/details/index.js b/public/assets/js/lib/views/details/index.js
index feba246..8dc92f6 100644
--- a/public/assets/js/lib/views/details/index.js
+++ b/public/assets/js/lib/views/details/index.js
@@ -5,7 +5,7 @@ var DetailsView = View.extend({
action: "/api/thread/",
keywordAction: "/api/keyword/",
-
+
initialize: function(opt){
this.comments = new CommentsView ({ parent: this })
this.files = new FilesView ({ parent: this })
diff --git a/public/assets/js/lib/views/index/hootbox.js b/public/assets/js/lib/views/index/hootbox.js
index cdd3eb0..64fc756 100644
--- a/public/assets/js/lib/views/index/hootbox.js
+++ b/public/assets/js/lib/views/index/hootbox.js
@@ -15,6 +15,10 @@ var HootBox = FormView.extend({
},
load: function(comments){
+ if (!comments || !comments.length) {
+ this.$el.hide()
+ return
+ }
comments.forEach(this.appendComment.bind(this))
},
diff --git a/public/assets/js/lib/views/index/index.js b/public/assets/js/lib/views/index/index.js
index 840f150..5acfe8b 100644
--- a/public/assets/js/lib/views/index/index.js
+++ b/public/assets/js/lib/views/index/index.js
@@ -4,17 +4,24 @@ var IndexView = View.extend({
},
action: "/api/index",
+ keywordAction: "/api/keyword/",
initialize: function(opt){
// opt.parent = parent
this.hootbox = new HootBox ({ parent: this })
this.threadbox = new ThreadBox ({ parent: this, latest: true, welcome: true, })
this.lastlog = new LastLog ({ parent: this })
- this.load()
},
- load: function(){
- $.get(this.action, this.populate.bind(this))
+ load: function(keyword){
+ if (keyword) {
+ $(".subtitle").html('<a href="/">&lt; Home</a>')
+ this.threadbox.options.welcome = false
+ $.get(this.keywordAction + keyword, this.populate.bind(this))
+ }
+ else {
+ $.get(this.action, this.populate.bind(this))
+ }
},
populate: function(data){
diff --git a/public/assets/js/lib/views/index/lastlog.js b/public/assets/js/lib/views/index/lastlog.js
index fe50e0f..02b3cca 100644
--- a/public/assets/js/lib/views/index/lastlog.js
+++ b/public/assets/js/lib/views/index/lastlog.js
@@ -18,6 +18,10 @@ var LastLog = View.extend({
},
load: function(lastlog){
+ if (!lastlog || !lastlog.length) {
+ this.$el.hide()
+ return
+ }
var s = lastlog.map(this.parse.bind(this)).filter(s => s).join(', ')
this.$el.html(s)
},
diff --git a/public/assets/js/lib/views/index/threadbox.js b/public/assets/js/lib/views/index/threadbox.js
index 6efce22..79dc4bc 100644
--- a/public/assets/js/lib/views/index/threadbox.js
+++ b/public/assets/js/lib/views/index/threadbox.js
@@ -25,7 +25,7 @@ var ThreadBox = View.extend({
return b.lastmodified - a.lastmodified
}).slice(0, 15)
this.appendThreads(latest)
- data.threads = data.threads.filter((thread) => thread && !! thread.keyword)
+ data.threads = data.threads.slice(15).filter((thread) => thread && !! thread.keyword)
}
var keywords = {}
data.threads.forEach((thread) => {
diff --git a/public/assets/js/vendor/view/router.js b/public/assets/js/vendor/view/router.js
index 36f86b5..5371f80 100644
--- a/public/assets/js/vendor/view/router.js
+++ b/public/assets/js/vendor/view/router.js
@@ -11,7 +11,7 @@ var Router = View.extend({
parseRoute: function(pathname){
- var routes = is_mobile ? this.mobileRoutes : this.routes,
+ var routes = is_mobile && this.mobileRoutes ? this.mobileRoutes : this.routes,
path = pathname.split("/");
for (var i = 0; i < path.length; i++) {