summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/reader/ShareView.js
blob: 8a205ba02765825d09f955468b8e3112f11f4421 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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.$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()
	},

})