diff options
| author | Jelmer Vernooij <jelmer@samba.org> | 2014-09-27 12:19:07 +0200 | 
|---|---|---|
| committer | Jelmer Vernooij <jelmer@samba.org> | 2014-09-27 12:19:07 +0200 | 
| commit | 69a6ac3c1e0650ac712306ed2988b497a731dc23 (patch) | |
| tree | 588ad0569ebf464fa7165aedb91803b559ebb097 /isso/js/app | |
| parent | 71a21e062ef06e472ef6a792478ebd2ff305cf11 (diff) | |
| parent | 278f5c74bcd5b9068b0c3e4ccbad974411716056 (diff) | |
Imported Upstream version 0.9.7
Diffstat (limited to 'isso/js/app')
| -rw-r--r-- | isso/js/app/config.js | 3 | ||||
| -rw-r--r-- | isso/js/app/dom.js | 18 | ||||
| -rw-r--r-- | isso/js/app/i18n/fr.js | 2 | ||||
| -rw-r--r-- | isso/js/app/isso.js | 63 | ||||
| -rw-r--r-- | isso/js/app/jade.js | 13 | ||||
| -rw-r--r-- | isso/js/app/text/comment.jade | 17 | ||||
| -rw-r--r-- | isso/js/app/text/postbox.jade | 9 | ||||
| -rw-r--r-- | isso/js/app/utils.js | 8 | 
8 files changed, 80 insertions, 53 deletions
| diff --git a/isso/js/app/config.js b/isso/js/app/config.js index 043cdb4..bae5b77 100644 --- a/isso/js/app/config.js +++ b/isso/js/app/config.js @@ -11,7 +11,8 @@ define(function() {          "avatar": true,          "avatar-bg": "#f0f0f0",          "avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6", -                      "#be5168", "#f19670", "#e4bf80", "#447c69"].join(" ") +                      "#be5168", "#f19670", "#e4bf80", "#447c69"].join(" "), +        "vote": true      };      var js = document.getElementsByTagName("script"); diff --git a/isso/js/app/dom.js b/isso/js/app/dom.js index 364ece0..6338d1f 100644 --- a/isso/js/app/dom.js +++ b/isso/js/app/dom.js @@ -39,31 +39,31 @@ define(function() {          });      }; -    window.Element.prototype.toggle = function(type, on, off) { +    window.Element.prototype.toggle = function(type, a, b) {          /*          Toggle between two internal states on event :param type: e.g. to -        cycle form visibility. Callback :param on: is called on first event, -        :param off: next time. +        cycle form visibility. Callback :param a: is called on first event, +        :param b: next time.          You can skip to the next state without executing the callback with          `toggler.next()`. You can prevent a cycle when you call `toggler.wait()`          during an event.           */ -        function Toggle(el, on, off) { +        function Toggle(el, a, b) {              this.state = false;              this.el = el; -            this.on = on; -            this.off = off; +            this.a = a; +            this.b = b;          }          Toggle.prototype.next = function next() {              if (! this.state) {                  this.state = true; -                this.on(this); +                this.a(this);              } else {                  this.state = false; -                this.off(this); +                this.b(this);              }          }; @@ -71,7 +71,7 @@ define(function() {              this.state = ! this.state;          }; -        var toggler = new Toggle(this, on, off); +        var toggler = new Toggle(this, a, b);          this.on(type, function() {              toggler.next();          }); diff --git a/isso/js/app/i18n/fr.js b/isso/js/app/i18n/fr.js index cb0c006..e29d024 100644 --- a/isso/js/app/i18n/fr.js +++ b/isso/js/app/i18n/fr.js @@ -17,7 +17,7 @@ define({      "comment-queued": "Commentaire en attente de modération.",      "comment-anonymous": "Anonyme",      "comment-hidden": "1 caché\n{{ n }} cachés", -    "date-now": "À l'instant'", +    "date-now": "À l'instant",      "date-minute": "Il y a une minute\nIl y a {{ n }} minutes",      "date-hour": "Il y a une heure\nIl y a {{ n }} heures ",      "date-day": "Hier\nIl y a {{ n }} jours", diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index 4312d45..ec97d63 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -7,7 +7,11 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",      var Postbox = function(parent) { -        var el = $.htmlify(jade.render("postbox")); +        var el = $.htmlify(jade.render("postbox", { +            "author":  JSON.parse(localStorage.getItem("author")), +            "email":   JSON.parse(localStorage.getItem("email")), +            "website": JSON.parse(localStorage.getItem("website")) +        }));          // callback on success (e.g. to toggle the reply button)          el.onsuccess = function() {}; @@ -29,16 +33,19 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",                  return;              } +            var author = $("[name=author]", el).value || null, +                email = $("[name=email]", el).value || null, +                website = $("[name=website]", el).value || null; + +            localStorage.setItem("author", JSON.stringify(author)); +            localStorage.setItem("email", JSON.stringify(email)); +            localStorage.setItem("website", JSON.stringify(website)); +              api.create($("#isso-thread").getAttribute("data-isso-id"), { -                author: $("[name=author]", el).value || null, -                email: $("[name=email]", el).value || null, -                website: $("[name=website]", el).value || null, +                author: author, email: email, website: website,                  text: utils.text($(".textarea", el).innerHTML),                  parent: parent || null              }).then(function(comment) { -                $("[name=author]", el).value = ""; -                $("[name=email]", el).value = ""; -                $("[name=website]", el).value = "";                  $(".textarea", el).innerHTML = "";                  $(".textarea", el).blur();                  insert(comment, true); @@ -101,7 +108,7 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",          // update datetime every 60 seconds          var refresh = function() { -            $(".permalink > date", el).textContent = utils.ago( +            $(".permalink > time", el).textContent = utils.ago(                  globals.offset.localTime(), new Date(parseInt(comment.created, 10) * 1000));              setTimeout(refresh, 60*1000);          }; @@ -144,31 +151,33 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n",              }          ); -        // update vote counter, but hide if votes sum to 0 -        var votes = function(value) { -            var span = $("span.votes", footer); -            if (span === null && value !== 0) { -                footer.prepend($.new("span.votes", value)); -            } else { -                if (value === 0) { -                    span.remove(); +        if (config.vote) { +            // update vote counter, but hide if votes sum to 0 +            var votes = function (value) { +                var span = $("span.votes", footer); +                if (span === null && value !== 0) { +                    footer.prepend($.new("span.votes", value));                  } else { -                    span.textContent = value; +                    if (value === 0) { +                        span.remove(); +                    } else { +                        span.textContent = value; +                    }                  } -            } -        }; +            }; -        $("a.upvote", footer).on("click", function() { -            api.like(comment.id).then(function(rv) { -                votes(rv.likes - rv.dislikes); +            $("a.upvote", footer).on("click", function () { +                api.like(comment.id).then(function (rv) { +                    votes(rv.likes - rv.dislikes); +                });              }); -        }); -        $("a.downvote", footer).on("click", function() { -            api.dislike(comment.id).then(function(rv) { -                votes(rv.likes - rv.dislikes); +            $("a.downvote", footer).on("click", function () { +                api.dislike(comment.id).then(function (rv) { +                    votes(rv.likes - rv.dislikes); +                });              }); -        }); +        }          $("a.edit", footer).toggle("click",              function(toggler) { diff --git a/isso/js/app/jade.js b/isso/js/app/jade.js index 805338c..46d6269 100644 --- a/isso/js/app/jade.js +++ b/isso/js/app/jade.js @@ -21,6 +21,13 @@ define(["libjs-jade-runtime", "app/utils", "jade!app/text/postbox", "jade!app/te      load("comment-loader", tt_comment_loader);      set("bool", function(arg) { return arg ? true : false; }); +    set("humanize", function(date) { +        if (typeof date !== "object") { +            date = new Date(parseInt(date, 10) * 1000); +        } + +        return date.toString(); +    });      set("datetime", function(date) {          if (typeof date !== "object") {              date = new Date(parseInt(date, 10) * 1000); @@ -30,7 +37,11 @@ define(["libjs-jade-runtime", "app/utils", "jade!app/text/postbox", "jade!app/te              date.getUTCFullYear(),              utils.pad(date.getUTCMonth(), 2),              utils.pad(date.getUTCDay(), 2) -        ].join("-"); +        ].join("-") + "T" + [ +            utils.pad(date.getUTCHours(), 2), +            utils.pad(date.getUTCMinutes(), 2), +            utils.pad(date.getUTCSeconds(), 2) +        ].join(":") + "Z";      });      return { diff --git a/isso/js/app/text/comment.jade b/isso/js/app/text/comment.jade index 1167d5b..faa6618 100644 --- a/isso/js/app/text/comment.jade +++ b/isso/js/app/text/comment.jade @@ -12,7 +12,7 @@ div(class='isso-comment' id='isso-#{comment.id}')                      = bool(comment.author) ? comment.author : i18n('comment-anonymous')              span(class="spacer") •              a(class='permalink' href='#isso-#{comment.id}') -                date(datetime='#{datetime(comment.created)}') +                time(title='#{humanize(comment.created)}' datetime='#{datetime(comment.created)}')              span(class='note')                  = comment.mode == 2 ? i18n('comment-queued') : comment.mode == 4 ? i18n('comment-deleted') : '' @@ -23,13 +23,14 @@ div(class='isso-comment' id='isso-#{comment.id}')                  != comment.text          div(class='isso-comment-footer') -            if comment.likes - comment.dislikes != 0 -                span(class='votes') #{comment.likes - comment.dislikes} -            a(class='upvote' href='#') -                i!= svg['arrow-up'] -            span(class='spacer') | -            a(class='downvote' href='#') -                i!= svg['arrow-down'] +            if conf.vote +                if comment.likes - comment.dislikes != 0 +                    span(class='votes') #{comment.likes - comment.dislikes} +                a(class='upvote' href='#') +                    != svg['arrow-up'] +                span(class='spacer') | +                a(class='downvote' href='#') +                    != svg['arrow-down']              a(class='reply' href='#') #{i18n('comment-reply')}              a(class='edit' href='#') #{i18n('comment-edit')}              a(class='delete' href='#') #{i18n('comment-delete')} diff --git a/isso/js/app/text/postbox.jade b/isso/js/app/text/postbox.jade index a2428de..0a85ae1 100644 --- a/isso/js/app/text/postbox.jade +++ b/isso/js/app/text/postbox.jade @@ -5,10 +5,13 @@ div(class='isso-postbox')                  = i18n('postbox-text')          section(class='auth-section')              p(class='input-wrapper') -                input(type='text' name='author' placeholder=i18n('postbox-author')) +                input(type='text' name='author' placeholder=i18n('postbox-author') +                      value=author !== null ? '#{author}' : '')              p(class='input-wrapper') -                input(type='email' name='email' placeholder=i18n('postbox-email')) +                input(type='email' name='email' placeholder=i18n('postbox-email') +                      value=email != null ? '#{email}' : '')              p(class='input-wrapper') -                input(type='text' name='website' placeholder=i18n('postbox-website')) +                input(type='text' name='website' placeholder=i18n('postbox-website') +                      value=website != null ? '#{website}' : '')              p(class='post-action')                  input(type='submit' value=i18n('postbox-submit')) diff --git a/isso/js/app/utils.js b/isso/js/app/utils.js index f5f4992..d7bddf4 100644 --- a/isso/js/app/utils.js +++ b/isso/js/app/utils.js @@ -57,13 +57,15 @@ define(["app/i18n"], function(i18n) {          var _ = document.createElement("div");          _.innerHTML = html.replace(/<div><br><\/div>/gi, '<br>')                            .replace(/<div>/gi,'<br>') -                          .replace(/<br>/gi, '\n'); +                          .replace(/<br>/gi, '\n') +                          .replace(/ /gi, ' ');          return _.textContent.trim();      };      var detext = function(text) { -        return escape(text.replace(/\n\n/gi, '<br><div><br></div>') -                          .replace(/\n/gi, '<br>')); +        text = escape(text); +        return text.replace(/\n\n/gi, '<br><div><br></div>') +                   .replace(/\n/gi, '<br>');      };      return { | 
