qshare.js
4.83 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
/*
[Discuz!] (C)2001-2009 Comsenz Inc.
This is NOT a freeware, use is subject to license terms
$Id$
*/
var _share_tencent_weibo = function() {
var share_btn = function(_arr) {
if (_arr[0]) {
return _arr[0];
}
else {
var o = document.createElement("a"),
_ostyle = "width:92px;height:22px;background:url(http://open.t.qq.com/apps/qshare/images/icon.gif) no-repeat #f00;position:absolute;display:none;";
o.setAttribute("style", _ostyle);
o.style.cssText = _ostyle;
o.setAttribute("href", "javascript:;");
document.body.insertBefore(o, document.body.childNodes[0]);
return o;
}
} (arguments);
var share_area = function(_arr) {
if (_arr[1]) {
if ((typeof _arr[1] == "object" && _arr[1].length) || (_arr[1].constructor == Array)) {
return _arr[1];
} else {
return [_arr[1]];
}
}
else {
return [document.body];
}
} (arguments);
var current_area = share_area[0];
var _site = arguments[2] ? arguments[2] : "";
var _appkey = encodeURI(arguments[3] ? arguments[3] : "");
var _web = {
"name": arguments[4] || "",
"href": location.href,
"hash": location.hash
};
var _pic = function(area) {
var _imgarr = area.getElementsByTagName("img");
var _srcarr = [];
for (var i = 0; i < _imgarr.length; i++) {
_srcarr.push(_imgarr[i].src);
}
return _srcarr.join("|");
};
var _u = 'http://v.t.qq.com/share/share.php?url=$url$&appkey=' + _appkey + '&site=' + _site + '&title=$title$&pic=$pic$';
var _select = function() {
return (document.selection ? document.selection.createRange().text: document.getSelection()).toString().replace(/[\s\n]+/g, " ");
};
if ( !! window.find) {
HTMLElement.prototype.contains = function(B) {
return this.compareDocumentPosition(B) - 19 > 0
}
}
String.prototype.elength = function() {
return this.replace(/[^\u0000-\u00ff]/g, "aa").length;
}
document.onmouseup = function(e) {
e = e || window.event;
var o = e.target || e.srcElement;
for (var i = 0; i < share_area.length; i++) {
if (share_area[i].contains(o) || share_area[i] == o) {
var _e = {
"x": e.clientX,
"y": e.clientY
};
var _o = {
"w": share_btn.clientWidth,
"h": share_btn.clientHeight
};
var _d = window.pageYOffset || (document.documentElement || document.body).scrollTop || 0;
var x = (_e.x - _o.w < 0) ? _e.x + _o.w: _e.x - _o.w,
y = (_e.y - _o.h < 0) ? _e.y + _d - _o.h: _e.y + _d - _o.h + ( - [1, ] ? 10 : 0);
if (_select() && _select().length >= 10) {
with(share_btn.style) {
display = "inline-block";
left = (x - 5) + "px";
top = y + "px";
position = "absolute";
zIndex = "999999";
}
current_area = share_area[i];
break;
} else {
share_btn.style.display = "none";
}
} else {
share_btn.style.display = "none";
}
}
};
share_btn.onclick = function() {
var _str = _select();
var _strmaxlen = 280 - ("\u6211\u6765\u81EA\u4E8E\u817E\u8BAF\u5FAE\u535A\u5F00\u653E\u5E73\u53F0" + " " + _web.name).elength();
var _resultstr = "";
if (_str.elength() > _strmaxlen) {
_strmaxlen = _strmaxlen - 3;
for (var i = _strmaxlen >> 1; i <= _strmaxlen; i++) {
if ((_str.slice(0, i)).elength() > _strmaxlen) {
break;
}
else {
_resultstr = _str.slice(0, i);
}
}
_resultstr += "...";
} else {
_resultstr = _str;
}
if (_str) {
var url = _u.replace("$title$", encodeURIComponent(_resultstr + " " + _web.name)).replace("$pic$", _pic(current_area));
url = url.replace("$url$", encodeURIComponent(_web.href.replace(_web.hash, "") + "#" + (current_area["name"] || current_area["id"] || "")));
if (!- [1, ]) {
url = url.substr(0, 2048);
}
window.open(url, 'null', 'width=700,height=680,top=0,left=0,toolbar=no,menubar=no,scrollbars=no,location=yes,resizable=no,status=no');
}
};
};