var ShareView = View.extend({ el: ".share", events: { "keydown": "stopPropagation", "click #share_facebook": "facebook", "click #share_twitter": "twitter", "click #share_embed": "embed", }, initialize: function(opt){ this.parent = opt.parent this.embedView = new EmbedView ({ parent: this }) this.$link = this.$("#share_link") }, toggle: function(state){ if (typeof state == "boolean") { this.$el.toggleClass("active", state) } else { this.$el.toggleClass("active") } }, show: function(){ this.toggle(true) }, hide: function(){ this.toggle(false) }, setLink: function(url){ this.$link.val( url ) }, getLink: function(){ var link = window.location.origin + window.location.pathname link = link.replace(/\/edit\/?$/, "") return link }, facebook: function (e) { e.preventDefault() var link = this.getLink() var msg = app.controller.data.name + " on VValls" var url = "https://www.facebook.com/share.php?u=" + encodeURIComponent(link) + "&t=" + encodeURIComponent(msg) window.open(url, "_blank") }, twitter: function (e) { e.preventDefault() var link = this.getLink() var msg = app.controller.data.name + " on VValls" var url = "https://twitter.com/home?status=" + encodeURIComponent(link + " " + msg) window.open(url, "_blank") }, embed: function (e) { e.preventDefault() this.embedView.show() }, })