From 1cfed2612fd1042a15d470a44ec87588c966dc12 Mon Sep 17 00:00:00 2001 From: julian laplace Date: Tue, 25 Oct 2022 23:26:31 +0200 Subject: hootstream... dark mode only --- public/assets/js/lib/views/index/hootbox.js | 93 ++++++++++++++++------------- public/assets/js/lib/views/index/index.js | 78 ++++++++++++------------ 2 files changed, 90 insertions(+), 81 deletions(-) (limited to 'public/assets/js/lib/views/index') diff --git a/public/assets/js/lib/views/index/hootbox.js b/public/assets/js/lib/views/index/hootbox.js index 72fbfde..a5d2270 100644 --- a/public/assets/js/lib/views/index/hootbox.js +++ b/public/assets/js/lib/views/index/hootbox.js @@ -1,56 +1,63 @@ var HootBox = FormView.extend({ - el: "#hootbox", - - events: { - }, - + + events: {}, + action: "/api/thread/1/comment", - - initialize: function(){ - this.__super__.initialize.call(this) - this.template = this.$(".template").html() - this.$hoots = this.$("#hoots") - this.$comment = this.$("[name=comment]") - }, - - load: function(comments){ - if (!comments || !comments.length && ! this.options.required) { - this.$el.hide() - return + + initialize: function () { + this.__super__.initialize.call(this); + this.template = this.$(".template").html(); + this.$hoots = this.$("#hoots"); + this.$comment = this.$("[name=comment]"); + }, + + show: function () { + this.$el.show(); + }, + + hide: function () { + this.$el.hide(); + }, + + load: function (comments) { + if (!comments || (!comments.length && !this.options.required)) { + this.$el.hide(); + return; } - comments.forEach(this.appendComment.bind(this)) + comments.forEach(this.appendComment.bind(this)); }, - - parse: function(comment){ - var t = this.template.replace(/{{image}}/g, profile_image(comment.username)) - .replace(/{{username}}/g, comment.username) - .replace(/{{comment}}/g, tidy_urls(comment.comment, true)) - var $t = $(t) - return $t + + parse: function (comment) { + var t = this.template + .replace(/{{image}}/g, profile_image(comment.username)) + .replace(/{{username}}/g, comment.username) + .replace(/{{comment}}/g, tidy_urls(comment.comment, true)); + var $t = $(t); + return $t; }, - - prependComment: function(comment){ - var $el = this.parse(comment) - this.$hoots.prepend($el) + + prependComment: function (comment) { + var $el = this.parse(comment); + this.$hoots.prepend($el); }, - appendComment: function(comment){ - var $el = this.parse(comment) - this.$hoots.append($el) + appendComment: function (comment) { + var $el = this.parse(comment); + this.$hoots.append($el); }, - validate: function(){ - var errors = [] - var comment = $("[name=comment]").val() - if (! comment || ! comment.length) { - errors.push("Please enter a comment.") + validate: function () { + var errors = []; + var comment = $("[name=comment]").val(); + if (!comment || !comment.length) { + errors.push("Please enter a comment."); } - return errors.length ? errors : null + return errors.length ? errors : null; }, - success: function(data){ - this.prependComment(data.comment) - this.$("[name=comment]").val("") - } -}) \ No newline at end of file + success: function (data) { + this.prependComment(data.comment); + this.$("[name=comment]").val(""); + }, +}); diff --git a/public/assets/js/lib/views/index/index.js b/public/assets/js/lib/views/index/index.js index 08da455..cd5f650 100644 --- a/public/assets/js/lib/views/index/index.js +++ b/public/assets/js/lib/views/index/index.js @@ -1,57 +1,59 @@ var IndexView = View.extend({ - - events: { - }, + events: {}, action: "/api/index", keywordAction: "/api/keyword/", - initialize: function(opt){ + initialize: function (opt) { // opt.parent = parent - this.hootbox = new HootBox ({ parent: this }) - this.threadbox = new ThreadBox ({ parent: this }) - this.lastlog = new LastLog ({ parent: this }) - this.countdown = new Countdown ({ parent: this }) + this.hootbox = new HootBox({ parent: this }); + this.threadbox = new ThreadBox({ parent: this }); + this.lastlog = new LastLog({ parent: this }); + this.countdown = new Countdown({ parent: this }); }, - load: function(keyword){ - $("body").addClass("index") + load: function (keyword) { + $("body").addClass("index"); if (keyword) { - $(".subtitle").html('< Home · Keywords') - this.threadbox.options.latest = false - this.threadbox.options.welcome = false - $.get(this.keywordAction + keyword, this.populate.bind(this)) - } - else { - this.hootbox.options.required = true - this.threadbox.options.latest = true - this.threadbox.options.welcome = true - $.get(this.action, this.populate.bind(this)) + $(".subtitle").html( + '< Home · Keywords' + ); + this.threadbox.options.latest = false; + this.threadbox.options.welcome = false; + $.get(this.keywordAction + keyword, this.populate.bind(this)); + } else { + this.hootbox.options.required = true; + this.threadbox.options.latest = true; + this.threadbox.options.welcome = true; + $.get(this.action, this.populate.bind(this)); } }, - populate: function(data){ - $("body").removeClass('loading') - this.hootbox.load(data.hootbox) - this.threadbox.load(data) - this.lastlog.load(data.lastlog) + populate: function (data) { + $("body").removeClass("loading"); + this.data = data; + this.hootbox.load(data.hootbox); + this.threadbox.load(data); + this.lastlog.load(data.lastlog); if (data.mail.count) { - $(".alert").show().html( - "" + - "You have " + - data.mail.count + - " new message" + - courtesy_s(data.mail.count) + - "!") + $(".alert") + .show() + .html( + "" + + "You have " + + data.mail.count + + " new message" + + courtesy_s(data.mail.count) + + "!" + ); if (is_mobile) { - $("#content").prepend( $(".alert") ) + $("#content").prepend($(".alert")); } } - $(".search_form input").focus() + $(".search_form input").focus(); }, - success: function(){ - window.location.href = "/index" + success: function () { + window.location.href = "/index"; }, - -}) +}); -- cgit v1.2.3-70-g09d2