notepad_wev8.js
3.28 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
var notepad=function(objtag){
var init=function(){
var eleShare =jQuery("#imgSinaShare");
if(eleShare.length==0){
var newNode = document.createElement("span");
newNode.innerHTML ='<img id="imgSinaShare" class="img_sina_share" style="display:none; position:absolute; cursor:pointer;" title="将选中内容发送到微博便签" src="/blog/images/blog_notes_wev8.png" width="24" />';
document.body.appendChild(newNode);
eleShare =jQuery("#imgSinaShare");
eleShare.click(function() {
var txt = funGetSelectTxt();
if (txt) {
window.top.Dialog.confirm("确定将选中内容发送到微博便签?",function(){
jQuery.post("/blog/blogOperation.jsp",{'operation':'saveNotepad','content':txt,'saveType':'append'},function(data){
window.top.Dialog.alert("发送成功");
eleShare.hide();
window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
});
});
}
});
eleShare.hover(function(){
jQuery(this).attr("src","/blog/images/blog_notes_over_wev8.png");
},function(){
jQuery(this).attr("src","/blog/images/blog_notes_wev8.png");
});
}
};
var funGetSelectTxt = function() {
var txt = "";
if(document.selection) {
txt = document.selection.createRange().htmlText; // IE
} else {
var range=window.getSelection().getRangeAt(0);
var container = document.createElement('div');
container.appendChild(range.cloneContents());
txt=container.innerHTML;
}
var txtdiv=jQuery("<div>"+txt+"</div>");
if(txtdiv.find(objtag).length>0){
txt="";
txtdiv.find(objtag).each(function(){
txt=txt+this.innerHTML+"<br>";
});
}
return txt;
};
init();
//var eleContainer =$(this);
$(objtag).die().live('mouseup',function(e){
e = e || window.event;
var target=e.srcElement||e.target;
if(target.id=="imgSinaShare")
return ;
var txt = funGetSelectTxt(), sh = window.pageYOffset ||document.body.scrollTop||document.documentElement.scrollTop || document.body.scrollTop || 0;
var left = (e.clientX - 10 < 0) ? e.clientX + 10 : e.clientX -10, top = (e.clientY - 35 < 0) ? e.clientY + sh + 20 : e.clientY + sh - 35;
var eleShare = document.getElementById("imgSinaShare");
if (txt) {
eleShare.style.display = "inline";
eleShare.style.left = left + "px";
eleShare.style.top = top + "px";
} else {
eleShare.style.display = "none";
}
});
/*
eleContainer.each(function(){
this.onmouseup=function(e) {
e = e || window.event;
var target=e.srcElement||e.target;
if(target.id=="imgSinaShare")
return ;
var txt = funGetSelectTxt(), sh = window.pageYOffset ||document.body.scrollTop||document.documentElement.scrollTop || document.body.scrollTop || 0;
var left = (e.clientX - 10 < 0) ? e.clientX + 10 : e.clientX -10, top = (e.clientY - 35 < 0) ? e.clientY + sh + 20 : e.clientY + sh - 35;
var eleShare = document.getElementById("imgSinaShare");
if (txt) {
eleShare.style.display = "inline";
eleShare.style.left = left + "px";
eleShare.style.top = top + "px";
} else {
eleShare.style.display = "none";
}
};
});
*/
}