diff options
Diffstat (limited to 'public/assets/js/lib')
| -rw-r--r-- | public/assets/js/lib/_router.js | 60 | ||||
| -rw-r--r-- | public/assets/js/lib/views/HomeView.js | 21 | ||||
| -rw-r--r-- | public/assets/js/lib/views/LinksView.js | 31 | ||||
| -rw-r--r-- | public/assets/js/lib/views/UploadView.js | 69 |
4 files changed, 181 insertions, 0 deletions
diff --git a/public/assets/js/lib/_router.js b/public/assets/js/lib/_router.js new file mode 100644 index 0000000..69640f4 --- /dev/null +++ b/public/assets/js/lib/_router.js @@ -0,0 +1,60 @@ +var SiteRouter = Router.extend({ + + el: 'body', + routeByHash: false, + + routes: { + '/': 'home', + }, + + 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 + }, + +}) + diff --git a/public/assets/js/lib/views/HomeView.js b/public/assets/js/lib/views/HomeView.js new file mode 100644 index 0000000..7e2ea24 --- /dev/null +++ b/public/assets/js/lib/views/HomeView.js @@ -0,0 +1,21 @@ +var HomeView = View.extend({ + + el: "body", + + events: { + }, + + grid_template: $("#grid_template").html(), + + initialize: function(){ + this.LinksView = new LinksView ({ parent: this }) + }, + + show: function(){ + this.LinksView.show() + }, + + done: false, + isFirstLoad: true, + +})
\ No newline at end of file diff --git a/public/assets/js/lib/views/LinksView.js b/public/assets/js/lib/views/LinksView.js new file mode 100644 index 0000000..c8603a9 --- /dev/null +++ b/public/assets/js/lib/views/LinksView.js @@ -0,0 +1,31 @@ +var LinksView = View.extend({ + + el: "#links", + + events: { + "click a": function(){ + }, + }, + + template: $("#link_template").html(), + + initialize: function(){ + }, + + show: function(){ + $.getJSON("/_irc/links", function(data){ + data.forEach(this.append.bind(this)) + }.bind(this)) + }, + + append: function(links){ + var tmpl = this.template.replace(/{{url}}/, sanitize(data.url)) + .replace(/{{nick}}/, sanitize(data.nick)) + this.$el.append(tmpl) + }, + + loadMembers: function(){ + this.queue.forEach(this.appendMember.bind(this)) + }, + +})
\ No newline at end of file diff --git a/public/assets/js/lib/views/UploadView.js b/public/assets/js/lib/views/UploadView.js new file mode 100644 index 0000000..89ebac4 --- /dev/null +++ b/public/assets/js/lib/views/UploadView.js @@ -0,0 +1,69 @@ +var WebcamView = View.extend({ + + el: "#photobooth", + + events: { + "change #upload-btn input": "handleFileSelect", + }, + + initialize: function(){ + this.$input = this.$('#file') + this.$snapBtn = this.$("#snap-btn") + }, + + loaded: false, + ready: function(){ + this.canvas = document.createElement("canvas") + this.ctx = this.canvas.getContext('2d') + this.$overlayer.append(this.canvas) + this.draw() + }, + + handleFileSelect: function(e) { + e.stopPropagation() + e.preventDefault() + + var files = e.dataTransfer ? e.dataTransfer.files : e.target.files + + var file = files[0] + if (! file) return + if ( ! file.type.match('image.*')) return + // this.upload(file) + var img = new Image + img.onload = function() { + var w, h + var ratio = img.naturalWidth / img.naturalHeight + if (ratio >= 4/3) { + h = 480 + w = 480 * ratio + } + else { + w = 640 + h = 640 / ratio + } + ctx.drawImage(img, 0, 0, w, h) + }.bind(this) + img.src = URL.createObjectURL(file) + }, + + upload: function(file){ + var _csrf = $("meta[name=_csrf]").attr("value") + var fd = new FormData() + fd.append('image', file) + + var request = $.ajax({ + url: "/irc/image?_csrf=" + _csrf, + type: "post", + data: fd, + dataType: "json", + processData: false, + contentType: false, + }) + request.done(this.success.bind(this)) + }, + + success: function(data){ + // probably append image.. + }, + +})
\ No newline at end of file |
