PageSourceSearch

https://onhospital.org/addons/autolink/autolink.js?t=1742353872

js onhospital.org collected 2026-09-26 13:22:27 UTC 3,449 bytes, 111 lines download raw bytes

1/**
2 * @file autolink.js
3 * @brief javascript code for autolink addon
4 * @author NAVER ([email protected])
5 */
6(function($){
7	var protocol_re = '(?:(?:https?|ftp|news|telnet|irc|mms)://)';
8	var domain_re   = '(?:[^\\s./)>]+\\.)+[^\\s./)>]+';
9	var max_255_re  = '(?:1[0-9]{2}|2[0-4][0-9]|25[0-5]|[1-9]?[0-9])';
10	var ip_re       = '(?:'+max_255_re+'\\.){3}'+max_255_re;
11	var port_re     = '(?::([0-9]+))?';
12	var user_re     = '(?:/~\\w+)?';
13	var path_re     = '(?:/[^\\s]*)?';
14	var hash_re     = '(?:#[^\\s]*)?';
15
16	var url_regex = new RegExp('('+protocol_re+'('+domain_re+'|'+ip_re+'|localhost'+')'+port_re+user_re+path_re+hash_re+')', 'ig');
17
18	var AutoLink = xe.createPlugin("autolink", {
19		targets : [],
20		init : function() {
21			this.targets = [];
22		},
23		API_ONREADY : function() {
24			var thisPlugin = this;
25
26			// extract target text nodes
27			this.extractTargets($('.rhymix_content, .xe_content'));
28
29			$(this.targets).each(function(){
30				thisPlugin.cast('AUTOLINK', [this]);
31			});
32		},
33		API_AUTOLINK : function(oSender, params) {
34			var textNode = params[0];
35			if(!$(textNode).parent().length || $(textNode).parent().get(0).nodeName.toLowerCase() == 'a') return;
36			var content  = textNode.nodeValue;
37			var dummy    = $('<span>');
38
39			content = content.replace(/</g, '&lt;').replace(/>/g, '&gt;');
40			content = content.replace(url_regex, function(match, p1, offset, string) {
41				var match;
42				var suffix = '';
43				var attribute = '';
44				if (p1.indexOf('(') < 0 && p1.match(/\)$/)) {
45					p1 = p1.replace(/\)$/, '');
46					suffix = ')';
47				} else if (p1.indexOf('[') < 0 && p1.match(/\]$/)) {
48					p1 = p1.replace(/\]$/, '');
49					suffix = ']';
50				} else if (p1.indexOf('&lt;') < 0 && p1.match(/&gt;$/)) {
51					p1 = p1.replace(/&gt;$/, '');
52					suffix = '&gt;';
53				} else if (match = /^([\x21-\x7E]+\.[a-z]+)([가-힣]{1,3})$/.exec(p1)) {
54					p1 = match[1];
55					suffix = match[2];
56				}
57				if(!isSameOrigin(location.href, p1)) {
58					attribute = ' target="_blank"';
59				}
60				return '<a href="' + p1 + '"' + attribute + '>' + p1 + '</a>' + suffix;
61			});
62
63			$(textNode).before(dummy);
64			$(textNode).replaceWith(content);
65			params[0] = dummy.next('a');
66			dummy.remove();
67		},
68		extractTargets : function(obj) {
69			var thisPlugin = this;
70			var wrap = $('.rhymix_content, .xe_content', obj);
71			if(wrap.length) {
72				this.extractTargets(wrap);
73				return;
74			}
75
76			$(obj).contents().each(function(){
77				var node_name = this.nodeName.toLowerCase();
78				if($.inArray(node_name, ['a', 'pre', 'xml', 'textarea', 'input', 'select', 'option', 'code', 'script', 'style', 'iframe', 'button', 'img', 'embed', 'object', 'ins']) != -1) return;
79
80				// FIX ME : When this meanless code wasn't executed, url_regex do not run correctly. why?
81				url_regex.exec('');
82
83				if(this.nodeType == 3) { // text node
84					var content = this.nodeValue;
85
86					if(content.length < 5) return;
87
88					if(!/(http|https|ftp|news|telnet|irc|mms):\/\//i.test(content)) return;
89
90					thisPlugin.targets.push(this);
91				} else {
92					thisPlugin.extractTargets(this);
93				}
94			});
95		}
96	});
97
98	xe.registerPlugin(new AutoLink());
99
100	$(document).on('click', '.rhymix_content a, .xe_content a', function() {
101		var $this = $(this);
102		var href = $this.attr('href');
103		if(!href || /^(?:javascript|mailto):|#/.test(href)) {
104			return;
105		}
106		if (!$this.attr("target") && !isSameOrigin(location.href, href)) {
107			$this.attr("target", "_blank");
108		}
109	});
110	
111})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.