share.js
7.61 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/**
* @author DELL
*/
/**
* @share 分享插件
* @author:王威
* @date:2014-09-19
* yohoo-share-button-sina
* yohoo-share-button-facebook
* yohoo-share-button-tweet
* fbAppId:YohoConfig.girl.fbAppId,'657464311006064',
fbUrl:YohoConfig.girl.mainUrl+'/channel/yohood/closedialog',
*/
define('plugins/share', function(require, exports) {
var $ = require("jquery");
exports.init = function(info) {
var defaults = {
width: 800,
height: 500,
img: "",
imgFunction: null,
sinaText: "",
sinaTextFunction: null,
tweetText: "",
tweetTextFunction: null,
fbCaption: "",
fbDescription: "",
fbName: "",
fbTextFunction: null,
shareUrl: "",
shareUrlFunction: null,
fbAppId: "",
fbUrl: "",
qqText: ""
}
var options = $.extend(defaults, info);
$(".yohoo-share-button-sina").unbind().on("click", function() {
if (options.sinaTextFunction != null) {
options.sinaText = (function() {
return options.sinaTextFunction.apply($(".yohoo-share-button-sina"));
})();
}
options.sinaText = options.sinaText.replace(/[ ]/g, "%20")
.replace(/[&]/g, "%26")
.replace(/[#]/g, "%23")
.replace(/[+]/g, "%2B");
window.sharetitle = options.sinaText;
if (options.imgFunction != null) {
options.img = (function() {
return options.imgFunction.apply($(".yohoo-share-button-sina"));
})();
}
window.shareUrl = options.img
share();
});
if (options.shareUrlFunction != null) {
options.shareUrl = (function() {
return options.shareUrlFunction.apply({
sina: $(".yohoo-share-button-sina"),
facebook: $(".yohoo-share-button-facebook"),
tweet: $(".yohoo-share-button-tweet")
});
})();
} else {
options.shareUrl = options.shareUrl == "" ? document.location.href : options.shareUrl;
}
function share() {
(function(s, d, e) {
try {} catch (e) {}
var f = 'http://v.t.sina.com.cn/share/share.php?',
u = options.shareUrl,
p = ['url=', e(u), '&title=', e(window.sharetitle), '&appkey=2924220432', '&pic=', e(window.shareUrl)].join('');
function a() {
if (!window.open([f, p].join(''), 'mb', ['toolbar=0,status=0,resizable=1,width=620,height=450,left=', (s.width - 620) / 2, ',top=', (s.height - 450) / 2].join('')))
u.href = [f, p].join('');
};
if (/Firefox/.test(navigator.userAgent)) {
setTimeout(a, 0)
} else {
a()
}
})(screen, document, encodeURIComponent);
}
var iTop = (window.screen.availHeight - 30 - options.height) / 2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth - 10 - options.width) / 2; //获得窗口的水平位置;
$(".yohoo-share-button-facebook").unbind().on("click", function() {
if (options.imgFunction != null) {
options.img = (function() {
return options.imgFunction.apply($(".yohoo-share-button-facebook"));
})();
}
var tmpResult = {
des: "",
name: "",
caption: ""
};
if (options.fbTextFunction != null) {
tmpResult = (function() {
return options.fbTextFunction.apply($(".yohoo-share-button-facebook"));
})();
if (!tmpResult.url) {
options.fbCaption = tmpResult.caption;
options.fbDescription = tmpResult.des;
options.fbName = tmpResult.name;
} else {
options.fbUrl = tmpResult.url;
}
}
if (options.fbUrl) {
window.open("https://www.facebook.com/sharer/sharer.php?u=" + options.fbUrl, "",
"height=" + options.height + ",width=" + options.width + ",left=" + iLeft + ",top=" + iTop);
} else {
options.fbCaption = options.fbCaption.replace(/[ ]/g, "%20")
.replace(/[&]/g, "%26")
.replace(/[#]/g, "%23")
.replace(/[+]/g, "%2B");
options.fbDescription = tmpResult.des.replace(/[ ]/g, "%20")
.replace(/[&]/g, "%26")
.replace(/[#]/g, "%23")
.replace(/[+]/g, "%2B");
options.fbName = tmpResult.name.replace(/[ ]/g, "%20")
.replace(/[&]/g, "%26")
.replace(/[#]/g, "%23")
.replace(/[+]/g, "%2B");
window.open("http://www.facebook.com/dialog/feed?app_id=1431491300468916&redirect_uri=http://www.yohoboys.com/channel/yohood/closedialog&" +
"link=" + options.shareUrl +
"&picture=" + options.img +
"&caption=" + options.fbName +
"&description=" + options.fbDescription + (options.fbDescription == "" ? "" : "(分享自 @yohoboy)") +
"&name=" + options.fbCaption,
"",
"height=" + options.height + ",width=" + options.width + ",left=" + iLeft + ",top=" + iTop);
}
});
$(".yohoo-share-button-tweet").unbind().on("click", function() {
if (options.tweetTextFunction != null) {
options.tweetText = (function() {
return options.tweetTextFunction.apply($(".yohoo-share-button-tweet"));
})();
}
options.tweetText = options.tweetText.replace(/[ ]/g, "%20")
.replace(/[&]/g, "%26")
.replace(/[#]/g, "%23")
.replace(/[+]/g, "%2B");
window.open("http://twitter.com/intent/tweet?url=" + options.shareUrl +
"&text=" + options.tweetText,
"",
"height=" + options.height + ",width=" + options.width + ",left=" + iLeft + ",top=" + iTop);
});
$(".yohoo-share-button-qq").unbind().on("click", function() {
window.open('http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + encodeURIComponent(location.href) +
'&title=' + options.qqText +
'&pics=' + options.img, '_blank', 'height=' + options.height + ',width=' + options.width + ',left=' + iLeft + ',top=' + iTop);
});
};
$(".yohoo-share-button-wx").on("mouseover", function() {
$(".wx-qrcode-dialog").show();
}).on("mouseout", function() {
$(".wx-qrcode-dialog").hide();
});
//ipad微信
$('.bd').on("click.closeWxDialog", function(event) {
if ($(event.target).is(".yohoo-share-button-wx") || $(event.target).parents(".yohoo-share-button-wx").size() > 0) {
$(".wx-qrcode-dialog").show();
} else {
$(".wx-qrcode-dialog").hide();
}
})
$(".bottom-content").on("click.closeWxDialog", function() {
$(".detail-container").trigger("click.closeWxDialog");
})
$(".enterprise").on("click.closeWxDialog", function() {
$(".detail-container").trigger("click.closeWxDialog");
})
});