diff options
Diffstat (limited to 'tree/public/assets/js/lib')
| -rw-r--r-- | tree/public/assets/js/lib/_router.js | 82 | ||||
| -rw-r--r-- | tree/public/assets/js/lib/nav/DesktopNav.js | 102 | ||||
| -rw-r--r-- | tree/public/assets/js/lib/nav/MobileNav.js | 32 | ||||
| -rw-r--r-- | tree/public/assets/js/lib/view/AboutView.js | 28 | ||||
| -rw-r--r-- | tree/public/assets/js/lib/view/HomeView.js | 59 | ||||
| -rw-r--r-- | tree/public/assets/js/lib/view/PressView.js | 28 |
6 files changed, 331 insertions, 0 deletions
diff --git a/tree/public/assets/js/lib/_router.js b/tree/public/assets/js/lib/_router.js new file mode 100644 index 0000000..248b532 --- /dev/null +++ b/tree/public/assets/js/lib/_router.js @@ -0,0 +1,82 @@ +var SiteRouter = Router.extend({ + + el: 'body', + routeByHash: false, + + routes: { + '/': 'home', + '/about': 'about', + '/press': 'press', + '/team': 'team', + '/festivals': 'festivals', + '/lectures': 'lectures', + }, + + initialize: function(){ + var fn + for (var route in this.routes) { + fn = this.routes[route] + if (! this[fn]) { + this[fn] = this.default_view(fn) + } + } + }, + + initial_route: null, + launch: function(){ + if (this.initial_route) { + this.parseRoute( this.initial_route ) + } + else { + this.route() + } + this.initial_route = null + }, + + go: function(url){ + if (app.view && app.view.hide) { + app.view.hide() + } + this.pushState(url) + this.parseRoute(url) + }, + + default_view: function(name){ + var fn = function(){ + if (app.view != app.login && app.view != app.signin) { + app.last_view = app.view + } + if (app.view && app.view.hide) { + app.view.hide() + } + if (name.match(/\./)) { + var n = name.split(".") + app.view = app.views[n[0]][n[1]] + } + else { + app.view = app.views[name] + } + app.view.show() + }.bind(this) + return fn + }, + + experimentById: function(id){ + if (app.view && app.view.hide) { + app.view.hide() + } + app.view = app.views.experiments + app.views.experiments.show() + app.views.experiments.load(id) + }, + + projectById: function(id){ + if (app.view && app.view.hide) { + app.view.hide() + } + app.view = app.views.projects + app.views.projects.show() + app.views.projects.load(id) + } +}) + diff --git a/tree/public/assets/js/lib/nav/DesktopNav.js b/tree/public/assets/js/lib/nav/DesktopNav.js new file mode 100644 index 0000000..6c4a140 --- /dev/null +++ b/tree/public/assets/js/lib/nav/DesktopNav.js @@ -0,0 +1,102 @@ +var NavView = View.extend({ + + el: "#nav", + + events: { + "click .logo": "home", + "click li": "go", + "click #corner": "corner", + "mouseenter ul": "show_menu", + "mouseleave ul": "hide_menu", + }, + + initialize: function(){ + this.$categories = this.$("ul") + this.$headings = this.$categories.find("li:first-child") + this.$experiments_nav = $("#experiments_nav") + "breakout clock dendrite draw fireworks harp hypercube life rain sequencer snow starfield trails waves webcam".split(" ").forEach(function(name){ + var $tag = $("<li>").attr("href", "/experiments/" + name) + $tag.html("<span>" + name + "</span>") + this.$experiments_nav.append($tag) + }.bind(this)) + this.$categories.each(function(){ + $(this).data("width", $(this).width()) + }) + }, + + home: function(){ + app.router.go("/") + this.$headings.find(".active").removeClass("active") + if (app.mobile_nav && app.mobile_nav.state.open) { + app.mobile_nav.hamburger() + } + }, + + resetWidths: function(){ + this.$categories.each(function(){ + $(this).width( $(this).data("width") ) + }) + }, + + go: function(e){ + e.preventDefault() + + this.resetWidths() + + var $t = $(e.currentTarget) + var $parent = $t.parent() + var $parentHeading = $parent.find(":first-child") + this.$("li").removeClass("active") + this.$headings.addClass("active") + $parentHeading.removeClass("active") + $t.addClass("active") + + var hover_width = $t.find("span").width() + $parent.data( "hover-width", hover_width ) + $parent.width( hover_width ) + this.$(".hover").removeClass("hover") + var href = $t.attr("href") + app.router.go(href) + if (is_mobile) { + app.mobile_nav.hamburger() + } + this.after_go() + }, + + after_go: function(){ + + }, + + setActive: function(id){ + var href = '/' + id + var $el = $('[href="' + href + '"]') + this.$('.active').removeClass('active') + if ($el.length) { + $el.addClass('active') + } + }, + + show_menu: function(e){ + var $el = $(e.currentTarget) + $el.addClass("hover") + + // var $parent = $el.parent() + var width = $el.data( "width" ) + $el.width(width) + console.log(width) + }, + + hide_menu: function(e){ + var $el = $(e.currentTarget) + $el.removeClass("hover") + + // var $parent = $el.parent() + var hover_width = $el.data( "hover-width" ) + $el.width(hover_width) + }, + + corner: function(){ + app.view && app.view.corner() + }, + +}); diff --git a/tree/public/assets/js/lib/nav/MobileNav.js b/tree/public/assets/js/lib/nav/MobileNav.js new file mode 100644 index 0000000..aec7090 --- /dev/null +++ b/tree/public/assets/js/lib/nav/MobileNav.js @@ -0,0 +1,32 @@ +var MobileNav = View.extend({ + + el: '#mobile_nav', + + events: { + 'touchstart .logo': 'home', + 'touchstart .hamburger': 'hamburger' + }, + + initialize: function(options){ + options = options || {} + this.state = { + open: false + } + }, + + home: function (){ + app.nav.home() + }, + + hamburger: function (e){ + $('html').toggleClass('navopen') + app.mobile_nav.state.open = ! app.mobile_nav.state.open + if (app.mobile_nav.state.open) { + $(".page-set").on("click", app.mobile_nav.hamburger) + } + else { + $(".page-set").off("click", app.mobile_nav.hamburger) + } + }, + +}) diff --git a/tree/public/assets/js/lib/view/AboutView.js b/tree/public/assets/js/lib/view/AboutView.js new file mode 100644 index 0000000..c2daf70 --- /dev/null +++ b/tree/public/assets/js/lib/view/AboutView.js @@ -0,0 +1,28 @@ +var AboutView = View.extend({ + + el: "#about", + + // template: liquid($('#tmpl-about').html()), + + events: { + }, + + initialize: function(options){ + options = options || {} + var data = this.data = options.data + }, + + render: function(){ + if (this.rendered) return + this.rendered = true + }, + + show: function(){ + document.body.className = "about" + this.render(this.data) + }, + + hide: function(){ + }, + +}) diff --git a/tree/public/assets/js/lib/view/HomeView.js b/tree/public/assets/js/lib/view/HomeView.js new file mode 100644 index 0000000..a235dc5 --- /dev/null +++ b/tree/public/assets/js/lib/view/HomeView.js @@ -0,0 +1,59 @@ +var HomeView = View.extend({ + + el: "#home", + + // template: liquid($('#tmpl-home').html()), + + events: { + }, + + initialize: function(options){ + options = options || {} + var data = this.data = options.data + }, + + render: function(){ + if (this.rendered) return + this.rendered = true + }, + + show: function(){ + document.body.className = "home" + this.render(this.data) + environment.load({ + module: 'welcome', + }) + corner.animate({ + to: 'zeroes', + tween: 'gradient_diagonal', + delay: 1000, + duration: 200, + }).then({ + to: corner.ascii.snake, + tween: 'ascii', + duration: 600, + }).then({ + from: corner.ascii.snake, + to: 'zeroes', + tween: 'ascii_from', + }).then({ + to: corner.ascii.snake, + tween: 'ascii', + duration: 600, + }).then({ + from: corner.ascii.snake, + to: 'zeroes', + tween: 'ascii_from', + }).then({ + to: corner.ascii.letter_v, + tween: 'ascii', + }) + }, + + hide: function(){ + }, + + corner: function(){ + }, + +}) diff --git a/tree/public/assets/js/lib/view/PressView.js b/tree/public/assets/js/lib/view/PressView.js new file mode 100644 index 0000000..2bc574d --- /dev/null +++ b/tree/public/assets/js/lib/view/PressView.js @@ -0,0 +1,28 @@ +var PressView = View.extend({ + + el: "#press", + + // template: liquid($('#tmpl-home').html()), + + events: { + }, + + initialize: function(options){ + options = options || {} + var data = this.data = options.data + }, + + render: function(){ + if (this.rendered) return + this.rendered = true + }, + + show: function(){ + document.body.className = "press" + this.render(this.data) + }, + + hide: function(){ + }, + +}) |
