提交 | 用户 | 时间
|
1ac2bc
|
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
懒 |
2 |
"http://www.w3.org/TR/html4/loose.dtd"> |
|
3 |
<html> |
|
4 |
<head> |
|
5 |
<title></title> |
|
6 |
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> |
|
7 |
<script type="text/javascript" src="../internal.js"></script> |
|
8 |
<style type="text/css"> |
|
9 |
*{margin:0;padding:0;color: #838383;} |
|
10 |
table{font-size: 12px;margin: 10px;line-height: 30px} |
|
11 |
.txt{width:300px;height:21px;line-height:21px;border:1px solid #d7d7d7;} |
|
12 |
</style> |
|
13 |
</head> |
|
14 |
<body> |
|
15 |
<table> |
|
16 |
<tr> |
|
17 |
<td><label for="text"> <var id="lang_input_text"></var></label></td> |
|
18 |
<td><input class="txt" id="text" type="text" disabled="true"/></td> |
|
19 |
</tr> |
|
20 |
<tr> |
|
21 |
<td><label for="href"> <var id="lang_input_url"></var></label></td> |
|
22 |
<td><input class="txt" id="href" type="text" /></td> |
|
23 |
</tr> |
|
24 |
<tr> |
|
25 |
<td><label for="title"> <var id="lang_input_title"></var></label></td> |
|
26 |
<td><input class="txt" id="title" type="text"/></td> |
|
27 |
</tr> |
|
28 |
<tr> |
|
29 |
<td colspan="2"> |
|
30 |
<label for="target"><var id="lang_input_target"></var></label> |
|
31 |
<input id="target" type="checkbox"/> |
|
32 |
</td> |
|
33 |
</tr> |
|
34 |
<tr> |
|
35 |
<td colspan="2" id="msg"></td> |
|
36 |
</tr> |
|
37 |
</table> |
|
38 |
<script type="text/javascript"> |
|
39 |
var range = editor.selection.getRange(), |
|
40 |
link = range.collapsed ? editor.queryCommandValue( "link" ) : editor.selection.getStart(), |
|
41 |
url, |
|
42 |
text = $G('text'), |
|
43 |
rangeLink = domUtils.findParentByTagName(range.getCommonAncestor(),'a',true), |
|
44 |
orgText; |
|
45 |
link = domUtils.findParentByTagName( link, "a", true ); |
|
46 |
if(link){ |
|
47 |
url = utils.html(link.getAttribute( '_href' ) || link.getAttribute( 'href', 2 )); |
|
48 |
|
|
49 |
if(rangeLink === link && !link.getElementsByTagName('img').length){ |
|
50 |
text.removeAttribute('disabled'); |
|
51 |
orgText = text.value = link[browser.ie ? 'innerText':'textContent']; |
|
52 |
}else{ |
|
53 |
text.setAttribute('disabled','true'); |
|
54 |
text.value = lang.validLink; |
|
55 |
} |
|
56 |
|
|
57 |
}else{ |
|
58 |
if(range.collapsed){ |
|
59 |
text.removeAttribute('disabled'); |
|
60 |
text.value = ''; |
|
61 |
}else{ |
|
62 |
text.setAttribute('disabled','true'); |
|
63 |
text.value = lang.validLink; |
|
64 |
} |
|
65 |
|
|
66 |
} |
|
67 |
$G("title").value = url ? link.title : ""; |
|
68 |
$G("href").value = url ? url: ''; |
|
69 |
$G("target").checked = url && link.target == "_blank" ? true : false; |
|
70 |
$focus($G("href")); |
|
71 |
|
|
72 |
function handleDialogOk(){ |
|
73 |
var href =$G('href').value.replace(/^\s+|\s+$/g, ''); |
|
74 |
if(href){ |
|
75 |
if(!hrefStartWith(href,["http","/","ftp://",'#'])) { |
|
76 |
href = "http://" + href; |
|
77 |
} |
|
78 |
var obj = { |
|
79 |
'href' : href, |
|
80 |
'target' : $G("target").checked ? "_blank" : '_self', |
|
81 |
'title' : $G("title").value.replace(/^\s+|\s+$/g, ''), |
|
82 |
'_href':href |
|
83 |
}; |
|
84 |
//修改链接内容的情况太特殊了,所以先做到这里了 |
|
85 |
//todo:情况多的时候,做到command里 |
|
86 |
if(orgText && text.value != orgText){ |
|
87 |
link[browser.ie ? 'innerText' : 'textContent'] = obj.textValue = text.value; |
|
88 |
range.selectNode(link).select() |
|
89 |
} |
|
90 |
if(range.collapsed){ |
|
91 |
obj.textValue = text.value; |
|
92 |
} |
|
93 |
editor.execCommand('link',utils.clearEmptyAttrs(obj) ); |
|
94 |
dialog.close(); |
|
95 |
} |
|
96 |
} |
|
97 |
dialog.onok = handleDialogOk; |
|
98 |
$G('href').onkeydown = $G('title').onkeydown = function(evt){ |
|
99 |
evt = evt || window.event; |
|
100 |
if (evt.keyCode == 13) { |
|
101 |
handleDialogOk(); |
|
102 |
return false; |
|
103 |
} |
|
104 |
}; |
|
105 |
$G('href').onblur = function(){ |
|
106 |
if(!hrefStartWith(this.value,["http","/","ftp://",'#'])){ |
|
107 |
$G("msg").innerHTML = "<span style='color: red'>"+lang.httpPrompt+"</span>"; |
|
108 |
}else{ |
|
109 |
$G("msg").innerHTML = ""; |
|
110 |
} |
|
111 |
}; |
|
112 |
|
|
113 |
function hrefStartWith(href,arr){ |
|
114 |
href = href.replace(/^\s+|\s+$/g, ''); |
|
115 |
for(var i=0,ai;ai=arr[i++];){ |
|
116 |
if(href.indexOf(ai)==0){ |
|
117 |
return true; |
|
118 |
} |
|
119 |
} |
|
120 |
return false; |
|
121 |
} |
|
122 |
|
|
123 |
|
|
124 |
</script> |
|
125 |
</body> |
|
126 |
</html> |