diff options
Diffstat (limited to 'public/assets/javascripts/ui/reader/ShareView.js')
| -rw-r--r-- | public/assets/javascripts/ui/reader/ShareView.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/public/assets/javascripts/ui/reader/ShareView.js b/public/assets/javascripts/ui/reader/ShareView.js new file mode 100644 index 0000000..dbe6f64 --- /dev/null +++ b/public/assets/javascripts/ui/reader/ShareView.js @@ -0,0 +1,62 @@ +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() + }, + +}) |
