mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 17:21:39 +09:00
변경전의 xe.less 파일도 rhymix.less와 함께 load 하여 호환정 유지
CSS 충돌 예)
bootstrap의 .btn
사용 예)
bootstrap 사용시엔 {Context::unloadBasicFiles('xe')}으로 unload 시키면 문제없음
102 lines
3.1 KiB
JavaScript
102 lines
3.1 KiB
JavaScript
/**
|
|
* @file autolink.js
|
|
* @brief javascript code for autolink addon
|
|
* @author NAVER (developers@xpressengine.com)
|
|
*/
|
|
(function($){
|
|
var protocol_re = '(?:(?:https?|ftp|news|telnet|irc|mms)://)';
|
|
var domain_re = '(?:[^\\s./)>]+\\.)+[^\\s./)>]+';
|
|
var max_255_re = '(?:1[0-9]{2}|2[0-4][0-9]|25[0-5]|[1-9]?[0-9])';
|
|
var ip_re = '(?:'+max_255_re+'\\.){3}'+max_255_re;
|
|
var port_re = '(?::([0-9]+))?';
|
|
var user_re = '(?:/~\\w+)?';
|
|
var path_re = '(?:/[^\\s]*)?';
|
|
var hash_re = '(?:#[^\\s]*)?';
|
|
|
|
var url_regex = new RegExp('('+protocol_re+'('+domain_re+'|'+ip_re+'|localhost'+')'+port_re+user_re+path_re+hash_re+')', 'ig');
|
|
|
|
var AutoLink = xe.createPlugin("autolink", {
|
|
targets : [],
|
|
init : function() {
|
|
this.targets = [];
|
|
},
|
|
API_ONREADY : function() {
|
|
var thisPlugin = this;
|
|
|
|
// extract target text nodes
|
|
this.extractTargets($('.rhymix_content, .xe_content'));
|
|
|
|
$(this.targets).each(function(){
|
|
thisPlugin.cast('AUTOLINK', [this]);
|
|
});
|
|
},
|
|
API_AUTOLINK : function(oSender, params) {
|
|
var textNode = params[0];
|
|
if(!$(textNode).parent().length || $(textNode).parent().get(0).nodeName.toLowerCase() == 'a') return;
|
|
var content = textNode.nodeValue;
|
|
var dummy = $('<span>');
|
|
|
|
content = content.replace(/</g, '<').replace(/>/g, '>');
|
|
content = content.replace(url_regex, function(match, p1, offset, string) {
|
|
var match;
|
|
var suffix = '';
|
|
if (p1.indexOf('(') < 0 && p1.match(/\)$/)) {
|
|
p1 = p1.replace(/\)$/, '');
|
|
suffix = ')';
|
|
} else if (p1.indexOf('[') < 0 && p1.match(/\]$/)) {
|
|
p1 = p1.replace(/\]$/, '');
|
|
suffix = ']';
|
|
} else if (p1.indexOf('<') < 0 && p1.match(/>$/)) {
|
|
p1 = p1.replace(/>$/, '');
|
|
suffix = '>';
|
|
} else if (match = /^([\x21-\x7E]+\.[a-z]+)([가-힣]{1,3})$/.exec(p1)) {
|
|
p1 = match[1];
|
|
suffix = match[2];
|
|
}
|
|
return '<a href="' + p1 + '" target="_blank">' + p1 + '</a>' + suffix;
|
|
});
|
|
|
|
$(textNode).before(dummy);
|
|
$(textNode).replaceWith(content);
|
|
params[0] = dummy.next('a');
|
|
dummy.remove();
|
|
},
|
|
extractTargets : function(obj) {
|
|
var thisPlugin = this;
|
|
var wrap = $('.rhymix_content, .xe_content', obj);
|
|
if(wrap.length) {
|
|
this.extractTargets(wrap);
|
|
return;
|
|
}
|
|
|
|
$(obj).contents().each(function(){
|
|
var node_name = this.nodeName.toLowerCase();
|
|
if($.inArray(node_name, ['a', 'pre', 'xml', 'textarea', 'input', 'select', 'option', 'code', 'script', 'style', 'iframe', 'button', 'img', 'embed', 'object', 'ins']) != -1) return;
|
|
|
|
// FIX ME : When this meanless code wasn't executed, url_regex do not run correctly. why?
|
|
url_regex.exec('');
|
|
|
|
if(this.nodeType == 3) { // text node
|
|
var content = this.nodeValue;
|
|
|
|
if(content.length < 5) return;
|
|
|
|
if(!/(http|https|ftp|news|telnet|irc|mms):\/\//i.test(content)) return;
|
|
|
|
thisPlugin.targets.push(this);
|
|
} else {
|
|
thisPlugin.extractTargets(this);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
xe.registerPlugin(new AutoLink());
|
|
|
|
$(document).on('click', '.rhymix_content a, .xe_content a', function() {
|
|
if (!$(this).attr("target")) {
|
|
$(this).attr("target", "_blank");
|
|
}
|
|
});
|
|
|
|
})(jQuery);
|