mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-05 09:41:40 +09:00
#18402493 : 링크가 포함된 문장에서 링크만 보이고 다른 텍스트는 나타나지 않던 문제 수정 + 유닛 테스트 추가
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@6897 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
7d690f9acd
commit
e3eaf8de97
2 changed files with 101 additions and 3 deletions
|
|
@ -13,18 +13,21 @@
|
|||
this.extractTargets($('.xe_content'));
|
||||
|
||||
$(this.targets).each(function(){
|
||||
if (!url_regex.test(this.nodeValue)) return true;
|
||||
thisPlugin.cast('AUTOLINK', [this]);
|
||||
});
|
||||
},
|
||||
API_AUTOLINK : function(oSender, params) {
|
||||
var textNode = params[0];
|
||||
var content = textNode.nodeValue;
|
||||
var dummy = $('<span>');
|
||||
|
||||
content = content.replace(/</g, '<').replace(/>/g, '>');
|
||||
content = content.replace(url_regex, '<a href="$1" target="_blank">$1</a>');
|
||||
|
||||
$(textNode).replaceWith(params[0] = $(content));
|
||||
$(textNode).before(dummy);
|
||||
$(textNode).replaceWith(content);
|
||||
params[0] = dummy.next('a');
|
||||
dummy.remove();
|
||||
},
|
||||
extractTargets : function(obj) {
|
||||
var thisPlugin = this;
|
||||
|
|
@ -33,7 +36,7 @@
|
|||
.contents()
|
||||
.each(function(){
|
||||
if (!$(this).is('a,pre,xml,code,script,style,:input')) {
|
||||
if (this.nodeType == 3) { // text node
|
||||
if (this.nodeType == 3 && url_regex.test(this.nodeValue)) { // text node
|
||||
thisPlugin.targets.push(this);
|
||||
} else {
|
||||
thisPlugin.extractTargets(this);
|
||||
|
|
|
|||
95
addons/autolink/autolink.spec.html
Normal file
95
addons/autolink/autolink.spec.html
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html lang="ko" xml:lang="ko" xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
||||
<title>Autolink Addon Unit Test</title>
|
||||
<link rel="stylesheet" type="text/css" href="../../common/js/unittest/css/JSSpec.css" />
|
||||
<script type="text/javascript" src="../../common/js/jquery.js"></script>
|
||||
<script type="text/javascript" src="../../common/js/common.js"></script>
|
||||
<script type="text/javascript" src="../../common/js/js_app.js"></script>
|
||||
<script type="text/javascript" src="autolink.js"></script>
|
||||
<script type="text/javascript" src="../../common/js/unittest/JSSpec/diff_match_patch.js"></script>
|
||||
<script type="text/javascript" src="../../common/js/unittest/JSSpec/JSSpec.js"></script>
|
||||
<script type="text/javascript">// <![CDATA[
|
||||
|
||||
var testParam = null;
|
||||
var TestSuite = xe.createPlugin("TestSuite", {
|
||||
API_BEFORE_AUTOLINK : function(oSender, params) {
|
||||
return !jQuery(params[0]).parent().is('#test7');
|
||||
},
|
||||
API_AFTER_AUTOLINK : function(oSender, params) {
|
||||
testParam = params[0];
|
||||
}
|
||||
});
|
||||
|
||||
xe.registerPlugin(new TestSuite);
|
||||
|
||||
jQuery(function($){
|
||||
|
||||
describe('AutoLink functionality', {
|
||||
"#test1 - plain text don't have any link text" : function() {
|
||||
value_of( $('#test1').children().length ).should_be(0);
|
||||
},
|
||||
"#test2 - simple link text only" : function() {
|
||||
value_of( $('#test2 > a').length > 0 ).should_be_true();
|
||||
value_of( $('#test2 > a').attr('href') ).should_be($('#test2 > a').text());
|
||||
value_of( $('#test2').children().length ).should_be(1);
|
||||
},
|
||||
"#test3 - simple link text and some text" : function() {
|
||||
value_of( $('#test3 > a').length > 0 ).should_be_true();
|
||||
value_of( $('#test3 > a').attr('href') ).should_be($('#test3 > a').text());
|
||||
value_of( $('#test3').contents().length ).should_be(2);
|
||||
},
|
||||
"#test4 - complex link text only" : function() {
|
||||
value_of( $('#test4 > a').length > 0 ).should_be_true();
|
||||
value_of( $('#test4 > a').attr('href') ).should_be($('#test4 > a').text());
|
||||
value_of( $('#test4').children().length ).should_be(1);
|
||||
},
|
||||
"#test5 - complex link text and some text" : function() {
|
||||
value_of( $('#test5 > a').length > 0 ).should_be_true();
|
||||
value_of( $('#test5 > a').attr('href') ).should_be($('#test5 > a').text());
|
||||
value_of( $('#test5').contents().length ).should_be(3);
|
||||
},
|
||||
"#test6 - complex example" : function() {
|
||||
value_of( $('#test6 a').length ).should_be(3);
|
||||
value_of( $('#test6 a').eq(0).attr('href') ).should_be($('#test6 a').eq(0).text());
|
||||
value_of( $('#test6 a').eq(1).parent().is('b') ).should_be_true();
|
||||
value_of( $('#test6 > textarea > a').length ).should_be(0);
|
||||
value_of( $('#test6 > div > a').attr("target") ).should_be("_self");
|
||||
}
|
||||
});
|
||||
|
||||
describe('Autolink trigger', {
|
||||
"#test7 - ignored" : function() {
|
||||
value_of( $('#test7 > a').length ).should_be(0);
|
||||
},
|
||||
"#test8 - parameter on after trigger" : function() {
|
||||
value_of( $(testParam).is('a') ).should_be_true();
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
// ]]></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="xe_content" style="display:none">
|
||||
<div id="test1">This is autolink test. This text don't have any link text.</div>
|
||||
<div id="test2">http://mygony.com</div>
|
||||
<div id="test3">Go to http://mygony.com</div>
|
||||
<div id="test4">http://www.abc.com/some_program?hello=world&encoded=%ED%C2%C1</div>
|
||||
<div id="test5">Before text. http://www.abc.com/some_program?hello=world&encoded=%ED%C2%C1 After Text</div>
|
||||
<div id="test6">
|
||||
This is text. http://www.abc.com/some_program?hello=world&encoded=%ED%C2%C1 Text Text
|
||||
<b>Bold text and http://mail.abc.com/path/to/some_program?hello=world#hash_text Bold text end</b>
|
||||
<textarea>this text should be ignored http://mygony.com ignored?</textarea>
|
||||
<div>
|
||||
Hello~
|
||||
<a href="http://mygony.com" target="_self">http://mygony.com</a>
|
||||
Sayonara~
|
||||
</div>
|
||||
</div>
|
||||
<div id="test7">http://mygony.com</div>
|
||||
<div id="test8">Go to http://mygony.com</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue