From commits-return-347-apmail-whimsical-commits-archive=whimsical.apache.org@whimsical.apache.org Fri Jan 22 02:41:06 2016 Return-Path: X-Original-To: apmail-whimsical-commits-archive@minotaur.apache.org Delivered-To: apmail-whimsical-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E066A18C93 for ; Fri, 22 Jan 2016 02:41:06 +0000 (UTC) Received: (qmail 98778 invoked by uid 500); 22 Jan 2016 02:41:06 -0000 Delivered-To: apmail-whimsical-commits-archive@whimsical.apache.org Received: (qmail 98734 invoked by uid 500); 22 Jan 2016 02:41:06 -0000 Mailing-List: contact commits-help@whimsical.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@whimsical.apache.org Delivered-To: mailing list commits@whimsical.apache.org Received: (qmail 98718 invoked by uid 99); 22 Jan 2016 02:41:06 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jan 2016 02:41:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 4CEB4C1CF3 for ; Fri, 22 Jan 2016 02:41:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.8 X-Spam-Level: * X-Spam-Status: No, score=1.8 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 9D-mMuvi8tUt for ; Fri, 22 Jan 2016 02:40:54 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id 43A6520EBF for ; Fri, 22 Jan 2016 02:40:54 +0000 (UTC) Received: from matt.apache.org (unknown [207.244.88.130]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id A5DBAE1003 for ; Fri, 22 Jan 2016 02:40:53 +0000 (UTC) Received: by matt.apache.org (ASF Mail Server at matt.apache.org, from userid 33) id B3D81803F; Fri, 22 Jan 2016 02:40:52 +0000 (UTC) From: Sam Ruby Reply-To: commits@whimsical.apache.org To: commits@whimsical.apache.org Subject: [whimsy.git] [8/50] Commit f79bbd5: more cleanly split client/server; set title Message-Id: <20160122024052.B3D81803F@matt.apache.org> Date: Fri, 22 Jan 2016 02:40:52 +0000 (UTC) Commit f79bbd5b065f12e85be9a2e2daad9f2282136b99: more cleanly split client/server; set title Branch: refs/heads/master Author: Sam Ruby Committer: Sam Ruby Pusher: rubys ------------------------------------------------------------ views/main.js.rb | ++++ ----- ------------------------------------------------------------ 64 changes: 30 additions, 34 deletions. ------------------------------------------------------------ diff --git a/views/main.js.rb b/views/main.js.rb index 0b4b05a..61ec85c 100644 --- a/views/main.js.rb +++ b/views/main.js.rb @@ -1,31 +1,10 @@ class Main < React - def initialize - Agenda.load(@@parsed) - Agenda._date = @@agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-') - Agenda._agendas = @@agendas - end - - def componentWillMount() - Main.navigate = self.navigate - self.navigate(@@path, true) - end - - def navigate(path, replace) + def route(path) if path - item = Agenda.find(path) + @item = Agenda.find(path) else - item = Agenda + @item = Agenda end - - if defined? history - if replace - history.replaceState({path: path}, nil, path) - else - history.pushState({path: path}, nil, path) - end - end - - @item = item end def render @@ -54,9 +33,35 @@ def render end end + def componentWillMount() + Agenda.load(@@parsed) + Agenda._date = @@agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-') + Agenda._agendas = @@agendas + self.route(@@path) + end + + def navigate(path) + self.route(path) + history.pushState({path: path}, nil, path) + document.getElementsByTagName('title')[0].textContent = @item.title + end + def componentDidMount() + Main.navigate = self.navigate + history.replaceState({path: @@path}, nil, @@path) + document.getElementsByTagName('title')[0].textContent = @item.title + window.addEventListener :popstate do |event| - self.navigate(event.state.path, true) + self.route(event.state.path) + document.getElementsByTagName('title')[0].textContent = @item.title + end + + def (document.getElementsByTagName('body')[0]).onkeyup(event) + if event.keyCode == 37 + self.navigate document.querySelector("a[rel=prev]").getAttribute('href') + elsif event.keyCode == 39 + self.navigate document.querySelector("a[rel=next]").getAttribute('href') + end end def window.onresize() @@ -67,16 +72,7 @@ def window.onresize() main.style.marginBottom = "#{footer.clientHeight}px" end - document.getElementsByTagName('title')[0].textContent = @item.title window.onresize() - - def (document.getElementsByTagName('body')[0]).onkeyup(event) - if event.keyCode == 37 - self.navigate document.querySelector("a[rel=prev]").getAttribute('href') - elsif event.keyCode == 39 - self.navigate document.querySelector("a[rel=next]").getAttribute('href') - end - end end def componentDidUpdate()