From d4f35bb906404c630a1eb38bbbcd3c07ae86566b Mon Sep 17 00:00:00 2001 From: taggon Date: Tue, 27 Oct 2009 02:34:10 +0000 Subject: [PATCH] =?UTF-8?q?1.=20JS=20App=20Framework=EC=9D=84=20=EA=B8=B0?= =?UTF-8?q?=EB=B3=B8=20=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=EB=A1=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=202.=20autolink=20=EC=95=A0=EB=93=9C?= =?UTF-8?q?=EC=98=A8=EC=9D=84=20JS-App=EC=97=90=20=EB=A7=9E=EA=B2=8C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://xe-core.googlecode.com/svn/sandbox@6892 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- addons/autolink/autolink.js | 69 ++++++++++++++++++------------- classes/context/Context.class.php | 1 + common/js/{app.js => js_app.js} | 2 +- 3 files changed, 42 insertions(+), 30 deletions(-) rename common/js/{app.js => js_app.js} (99%) diff --git a/addons/autolink/autolink.js b/addons/autolink/autolink.js index 59e5dc43d..4fec3010a 100644 --- a/addons/autolink/autolink.js +++ b/addons/autolink/autolink.js @@ -1,36 +1,47 @@ +(function($){ + var url_regex = /((http|https|ftp|news|telnet|irc):\/\/(([0-9a-z\-._~!$&'\(\)*+,;=:]|(%[0-9a-f]{2}))*\@)?((\[(((([0-9a-f]{1,4}:){6}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|(::([0-9a-f]{1,4}:){5}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|(([0-9a-f]{1,4})?::([0-9a-f]{1,4}:){4}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:)?[0-9a-f]{1,4})?::([0-9a-f]{1,4}:){3}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::([0-9a-f]{1,4}:){2}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4})|((([0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::))|(v[0-9a-f]+.[0-9a-z\-._~!$&'\(\)*+,;=:]+))\])|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5]))|(([0-9a-z\-._~!$&'\(\)*+,;=]|(%[0-9a-f]{2}))+))(:[0-9]*)?(\/([0-9a-z\-._~!$&'\(\)*+,;=:@]|(%[0-9a-f]{2}))*)*(\?([0-9a-z\-._~!$&'\(\)*+,;=:@\/\?]|(%[0-9a-f]{2}))*)?(#([0-9a-z\-._~!$&'\(\)*+,;=:@\/\?]|(%[0-9a-f]{2}))*)?)/i; -jQuery(function($) { - var url_regx = /((http|https|ftp|news|telnet|irc):\/\/(([0-9a-z\-._~!$&'\(\)*+,;=:]|(%[0-9a-f]{2}))*\@)?((\[(((([0-9a-f]{1,4}:){6}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|(::([0-9a-f]{1,4}:){5}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|(([0-9a-f]{1,4})?::([0-9a-f]{1,4}:){4}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:)?[0-9a-f]{1,4})?::([0-9a-f]{1,4}:){3}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::([0-9a-f]{1,4}:){2}([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::([0-9a-f]{1,4}:[0-9a-f]{1,4})|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])))|((([0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4})|((([0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::))|(v[0-9a-f]+.[0-9a-z\-._~!$&'\(\)*+,;=:]+))\])|(([0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5])){3}[0-9]|([1-9][0-9])|(1[0-9][0-9])|(2[0-4][0-9])|(25[0-5]))|(([0-9a-z\-._~!$&'\(\)*+,;=]|(%[0-9a-f]{2}))+))(:[0-9]*)?(\/([0-9a-z\-._~!$&'\(\)*+,;=:@]|(%[0-9a-f]{2}))*)*(\?([0-9a-z\-._~!$&'\(\)*+,;=:@\/\?]|(%[0-9a-f]{2}))*)?(#([0-9a-z\-._~!$&'\(\)*+,;=:@\/\?]|(%[0-9a-f]{2}))*)?)/i; + var AutoLink = xe.createPlugin("autolink", { + targets : [], + init : function() { + this.targets = []; + }, + API_ONREADY : function() { + var thisPlugin = this; - function replaceHrefLink(obj) { - var obj_list = obj.childNodes; + // extract target text nodes + this.extractTargets($('.xe_content')); - for(var i = 0; i < obj_list.length; ++i) { - var obj = obj_list[i]; - var pObj = obj.parentNode; - if(!pObj) continue; + $(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 pN = pObj.nodeName.toLowerCase(); - if($.inArray(pN, ['a', 'pre', 'xml', 'textarea', 'input', 'select', 'option', 'code', 'script', 'style']) != -1) continue; + content = content.replace(//g, '>'); + content = content.replace(url_regex, '$1'); - if(obj.nodeType == 3 && obj.length >= 10) { - var content = obj.nodeValue; - if(!/(http|https|ftp|news|telnet|irc):\/\//i.test(content)) continue; + $(textNode).replaceWith(params[0] = $(content)); + }, + extractTargets : function(obj) { + var thisPlugin = this; - content = content.replace(//g, '>'); - content = content.replace(url_regx, '$1'); + $(obj) + .contents() + .each(function(){ + if (!$(this).is('a,pre,xml,code,script,style,:input')) { + if (this.nodeType == 3) { // text node + thisPlugin.targets.push(this); + } else { + thisPlugin.extractTargets(this); + } + } + }); + } + }); - $(obj).replaceWith(content); - delete(content); - - } else if(obj.nodeType == 1 && obj.childNodes.length) { - replaceHrefLink(obj); - } - } - } - - $('.xe_content').each(function() { - replaceHrefLink(this); - }); -}); + xe.registerPlugin(new AutoLink()); +})(jQuery); \ No newline at end of file diff --git a/classes/context/Context.class.php b/classes/context/Context.class.php index 002def5c0..a16fafdb6 100644 --- a/classes/context/Context.class.php +++ b/classes/context/Context.class.php @@ -163,6 +163,7 @@ $this->addJsFile("./common/js/jquery.js"); $this->addJsFile("./common/js/x.js"); $this->addJsFile("./common/js/common.js"); + $this->addJsFile("./common/js/js_app.js"); $this->addJsFile("./common/js/xml_handler.js"); $this->addJsFile("./common/js/xml_js_filter.js"); $this->addCSSFile("./common/css/default.css"); diff --git a/common/js/app.js b/common/js/js_app.js similarity index 99% rename from common/js/app.js rename to common/js/js_app.js index 709f43edb..fb5d620d1 100644 --- a/common/js/app.js +++ b/common/js/js_app.js @@ -279,7 +279,7 @@ function getTypeBase() { if ($.isArray(this._binded_fn)) this._binded_fn = []; if ($.isFunction(this.init)) { - this.$init.apply(this, arguments); + this.init.apply(this, arguments); } };