PageSourceSearch

https://postech.ac.kr/_res/postech/_share/js/cms-common.js

js postech.ac.kr collected 2026-09-24 08:33:00 UTC 4,871 bytes, 178 lines download raw bytes

1if(!window.Common) {
2	Common = {};
3}
4
5$(document).ready(function () {
6	
7	Common.SnsShareCommon.init();
8	
9	// 푸터에 관련사이트 클릭 시 
10	$('div.related-site-wrap .related-select').change(function() {
11        var selectedOption = $(this).find('option:selected'); // 선택된 <option> 가져오기
12        var target = selectedOption.data('target'); // data-target 값 가져오기
13        var url = selectedOption.val(); // value 값 가져오기
14
15        if (url) { // URL이 존재하는 경우만 실행
16            if (target === '_blank') {
17                window.open(url, '_blank'); // 새 창에서 열기
18            } else {
19                window.location.href = url; // 현재 창에서 이동
20            }
21        }
22    });
23	
24});
25
26//sns 공유
27Common.SnsShareCommon = function() {
28	
29	var self;
30	var sns = {
31		"facebook": "https://www.facebook.com/sharer/sharer.php?u=",
32		"twitter": "https://twitter.com/intent/tweet?url=",
33		"instagram": "#" // 인스타그램은 링크 복사를 처리할 예정
34	};
35
36	var _thisHost = location.protocol + '//' + location.host;
37	
38	return {
39		init: function () {
40			self = this;
41
42			// SNS 공유 기능 초기화
43			self.snsShare();
44			
45			self.copyUrl();
46		},
47
48		snsShare: function () {
49			$('.sns_pop > ul > li:not(.url)').click(function (e) {
50				var shortUrl;
51				e.preventDefault();
52				
53				var $this = $(this), id = $this.attr('class'),
54					url, title;
55				var className = $this.attr('class').replace(/\s{2,20}/g, ' '),
56					classes = className.split(' '); // 클래스 분리
57
58				if (classes.length > 0) {
59					url = sns[classes[0]];
60				}
61				
62				if (typeof (url) != 'undefined') {
63
64					var paramMap = $.unparam();
65
66					// 각 파라미터를 순회하며 'article.offset'와 'articleLimit'를 제외한 파라미터들을 newQueryString에 추가
67					var excludes = ['article.offset', 'articleLimit', 'pager.offset', 'pagerLimit'];
68
69					var newQueryString = '';
70
71					for (var key in paramMap) {
72						if (!key) continue;
73						if (excludes.indexOf(key) >= -1) continue;
74
75						if (newQueryString) {
76							newQueryString += '&';
77						}
78						newQueryString += key + '=' + paramMap[key];
79					}
80
81					if (newQueryString) {
82						newQueryString = '?' + newQueryString;
83					}
84
85					// 짧은 URL 구하기
86					$.ajax({
87						url: '/cms/util/getShortUrl.do',
88						data: {
89							url: location.pathname + newQueryString
90						},
91						success: function (json) {
92							if (json.success) {
93								shortUrl = _thisHost + '/s.do?' + json.shortUrl;
94							}
95						},
96						async: false,
97						dataType: 'json'
98					});
99
100					if ($this.attr('data-title')) {
101						title = encodeURIComponent($this.attr('data-title'));
102					} else {
103						title = encodeURIComponent(document.title);
104					}
105
106					// 각 SNS에 맞는 URL 설정
107					if ($this.hasClass('facebook')) {
108						url += encodeURIComponent(shortUrl);
109					}
110					if ($this.hasClass('twitter')) {
111						url += encodeURIComponent(shortUrl) + '&text=' + title;
112					}
113					if ($this.hasClass('instagram')) {
114						// 인스타그램은 직접적인 URL 공유를 제공하지 않기 때문에, 링크 복사 방식으로 처리
115						prompt('인스타그램에 링크를 복사하여 붙여넣기:', shortUrl);
116						return;
117					}
118
119					window.open(url, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=680,width=830');
120				}
121			});
122		},
123
124		copyUrl : function () {
125			
126			$(document).on('click', 'a[data-copy-url]', function(e) {
127				e.preventDefault();
128			});
129			
130			if( $('[data-copy-url]').length > 0 ){
131
132				var btns = document.querySelectorAll('[data-copy-url]');
133				//var currentUrl = window.location.href;		//일반 링크 복사
134				var shortUrl = window.location.href;
135
136				// 짧은 주소 구하기
137                $.ajax({
138					url: '/cms/util/getShortUrl.do',
139					data: {
140                    	url: location.pathname + location.search
141                  	},
142                  	success: function(json) {
143                    	if(json.success) {
144                      		shortUrl = _thisHost+'/s.do?'+ json.shortUrl;
145                    	}
146                  	},
147                  	async: false,
148                  	dataType: 'json'
149            	});
150
151				//링크복사 버튼이 1개 이상존재함, 기존 id로 제어하는 방식에서 classë¡
151œ 제어하는 코드로 변경
152				for(var i = 0; i < btns.length; i++){
153					var btn = btns[i];
154
155					btn.setAttribute('data-copy-url', shortUrl);		//짧은 링크 복사
156					
157					var clipboard = new ClipboardJS(btn, {
158					  text: function(trigger) {
159						return trigger.getAttribute('data-copy-url');
160					  }
161					});
162
163				    clipboard.on('success', function(e) {
164				        alert('복사되었습니다.');
165				    });
166				    clipboard.on('error', function(e) {
167				        console.log('fail...');
168						console.log(e);
169				    });
170
171				}
172
173			}
174		}
175	};
176	
177}();
178

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.