PageSourceSearch

https://culturalaction.org/js/site_form.js?1744005846

js culturalaction.org collected 2026-10-01 15:47:09 UTC 18,651 bytes, 546 lines download raw bytes

1var SITE_FORM = function(){
2	var init = function(){
3	};
4
5	var itemFileUpload = function($obj, code){
6		$obj.fileupload({
7			url : '/ajax/form_file_upload.cm',
8			dataType : 'json',
9			singleFileUploads : false,
10			limitMultiFileUploads : 1,
11			dropZone : null,
12			maxFileSize : 100000000, //100mb
13			limitMultiFileUploadSize : 110000000, //110 mb
14			formData : {'code' : code},
15			add : function(e, data){
16				if(data.files[0].size > 100000000){
17					alert(LOCALIZE.설명_최대업로드용량안내());
18					return false;
19				}else{
20					data.submit();
21				}
22			},
23			start : function(e, data){
24				dozProgress.start();
25			},
26			progress : function(e, data){
27			},
28			done : function(e, data){
29				dozProgress.done();
30				var form_file = '';
31				form_file = 'form_file_' + code;
32				if(data.result[form_file][0].error){
33					showModal('error',data.result[form_file][0].error);
34				}else{
35					if(data.result[form_file][0].tmp_idx > 0){
36						$obj.find('._form_file_list').show();
37						$obj.find('._holder').hide();
38						$obj.find('._filename').text(data.result[form_file][0].org_name);
39						$obj.find('._filesize').text('(' + GetFileSize(data.result[form_file][0].size) + ')');
40						$obj.find('._temp_file').val(data.result[form_file][0].tmp_idx);
41						$obj.find('._upload_file').val('');
42					}
43				}
44			},
45			fail : function(e, data){
46			}
47		})
48			.find('._fileremove').click(function(){
49			$obj.find('._form_file_list').hide();
50			$obj.find('._holder').show();
51			$obj.find('._temp_file').val('');
52			$obj.find('._upload_file').val('');
53		});
54	};
55
56	var itemRequiredCk = function($obj){
57		var required_ck = true;
58		$obj.find('.form-group').each(function(){
59			var $form_group = $(this);
60			var type = this.id.split('_');
61			if($form_group.find('label i').hasClass('icon-required') === true){ // 필수입력 항
62				switch(type[0]){
63					case 'privacy':
64						if($form_group.find("input").is(":checked") === false){
65							required_ck = 'privacy_required';
66							return false;
67						}
68						break;
69					case 'thirdparty':
70						if($form_group.find('input').is(":checked") === false){
71							required_ck = 'third_party_required';
72							return false;
73						}
74						break;
75					case 'input':
76						if(!$form_group.find('input').val()){
77							required_ck = false;
78							return false;
79						}
80						break;
81					case 'textarea':
82						if(!$form_group.find('textarea').val()){
83							required_ck = false;
84							return false;
85						}
86						break;
87					case 'radio':
88						if(!$form_group.find('input:radio[name="' + this.id + '"]:checked').val()){
89							required_ck = false;
90							return false;
91						}
92						//기타 옵션 직접입력란 null체크
93						$($form_group.find('input:radio[name="' + this.id + '"]').each(function(){
94							if($(this).is(":checked") === true){
95								if($(this).data('type') === 'etc'){
96									if($form_group.find("input:text[name='" + type[0] + "_etc_" + type[1] + "']").val() === ''){
97										required_ck = 'etc_null';
98										return false;
99									}
100								}
101							}
102						}));
103						break;
104					case 'checkbox':
105						if($form_group.find("input:checkbox[name='" + this.id + "[]']").is(":checked") === false){
106							required_ck = false;
107							return false;
108						}
109
110						//기타 옵션 직접입력란 null체크
111						$form_group.find("input:checkbox[name='" + this.id + "[]']").each(function(){
112							if($(this).is(":checked") === true){
113								if($(this).data('type') === 'etc'){
114									if($form_group.find("input:text[name='" + type[0] + "_etc_" + type[1] + "']").val() === ''){
115										required_ck = 'etc_null';
116										return false;
117									}
118								}
119							}
120						});
121						break;
122					case 'file':
123						if(!$obj.find("input[name='temp_files_" + type[1] + "']").val()){
124							if(!$obj.find("input[name='upload_files_" + type[1] + "']").val()){
125								required_ck = false;
126								return false;
127							}
128						}
129						break;
130					case 'phonenumber':
131						$form_group.find('input:not([type="text"])').each(function(){
132							if(!$(this).val()){
133								required_ck = false;
134								return false;
135							}
136						});
137						break;
138					case 'email':
139						if(!$form_group.find('input').val()){
140							required_ck = false;
141							return false;
142						}
143						break;
144					case 'datetime':
145						$form_group.find('input').each(function(){
146							if(!$(this).val()){
147								required_ck = false;
148								return false;
149							}
150						});
151						break;
152					case 'address':
153						$form_group.find('input').each(function(){
154							if(!$(this).val()){
155								required_ck = false;
156								return false;
157							}
158						});
159						break;
160					case 'select':
161						$form_group.find('select').each(function(){
162							if(!$(this).val()){
163								required_ck = false;
164								return false;
165							}
166						});
167						break;
168				}
169			}else{ // 필수입력 항목이 아닌
170				switch(type[0]){
171					case 'checkbox' :
172						//기타 옵션 직접입력란 null체크
173						$form_group.find("input:checkbox[name='" + this.id + "[]']").each(function(){
174							if($(this).is(":checked") === true){
175								if($(this).data('type') === 'etc'){
176									if($form_group.find("input:text[name='" + type[0] + "_etc_" + type[1] + "']").val() === ''){
177										required_ck = 'etc_null';
178										return false;
179									}
180								}
181							}
182						});
183						break;
184					case 'radio' :
185						//기타 옵션 직접입력란 null체크
186						$form_group.find("input:radio[name='" + this.id + "']").each(function(){
187							if($(this).is(":checked") === true){
188								if($(this).data('type') === 'etc'){
189									if($form_group.find("input:text[name='" + type[0] + "_etc_" + type[1] + "']").val() === ''){
190										required_ck = 'etc_null';
191										return false;
192									}
193								}
194							}
195						});
196						break;
197				}
198			}
199			if(required_ck === 'etc_null'){
200				return false;
201			}
202			// 입력폼 체크박스 갯수 제한 추가
203			if(type[0] == 'checkbox'){
204				var checkmax = $('#'+this.id).attr('check-limit');
205				if(checkmax > 0 && ($form_group.find("input:checkbox[name='" + this.id + "[]']:checked").length > checkmax)){
206					required_ck = 'checkbox_limit_'+checkmax;
207					return false;
208				}
209			}
210		});
211		return required_ck;
212	};
213
214	var itemEtcSetting = function(widget_code, item_code, type){
215		var $obj = $('#addForm' + widget_code);
216		var $target = $obj.find('#' + type + '_' + item_code);
217		if($target.length > 0){
218			var $etc_input = $target.find('input[name="' + type + '_etc_' + item_code + '"]');
219			var $etc_btn = $target.find('input[data-type=etc]');
220			$etc_input.off('keyup').on('keyup', function(){
221				if($etc_input.val() != ''){
222					if(!$etc_btn.prop('checked')){
223						$etc_btn.click();
224					}
225				}
226			})
227		}
228	}
229
230	var is_submitting= false;
231	var form_url_data = {};
232	var submit = function(widget_code, callback){
233		var $obj = $('#addForm' + widget_code);
234		if(!is_submitting){
235			is_submitting = true;
236			$.ajax({
237				type : 'POST',
238				data : $obj.serialize(),
239				url : ('/ajax/form_add.cm'),
240				dataType : 'json',
241				async : true,
242				cache : false,
243				success : function(result){
244					is_submitting=false;
245					if(result.msg == 'SUCCESS'){
246						if ( typeof FB_PIXEL != 'undefined' && result.fb_registration_check == 'Y') FB_PIXEL.CompleteRegistration('form',result.currency);
247						if ( typeof DAUM_CTS != 'undefined' && result.daum_registration_check) DAUM_CTS.OrderForm();
248						if ( typeof NP_LOG != 'undefined' ) NP_LOG.EtcPage();
249						if ( typeof GOOGLE_ADWORDS_TRACE != 'undefined' && result.google_registration_check) GOOGLE_ADWORDS_TRACE.EtcTrace(result.google_registration_id);
250						if ( typeof CHANNEL_PLUGIN != 'undefined') CHANNEL_PLUGIN.CompleteSubmit();
251
252						//입력폼 입력후 이동 URL 데이터 보관
253						form_url_data = result.form_url_data;
254
255						//완료 메세지 변경
256						if(result.form_add_end_msg.trim() != ''){
257							showModal('complete',result.form_add_end_msg, widget_code);
258						}
259
260						if(typeof callback === 'function'){
261							callback();
262						}
263
264
265
266					}else{
267						showModal('error',result.msg, widget_code);
268					}
269				}
270			});
271		}
272	};
273
274	var confirmInputForm = function(widget_code, modify_permit){
275		var $obj = $('#addForm' + widget_code);
276		var chk_res = itemRequiredCk($obj);
277		if(chk_res === true){
278			if(modify_permit === 'N'){ //응답수정 허용 off
279				submit(widget_code,function(){
280					showModal('complete',null,widget_code);
281				});
282			}else{ //응답수정 허용 on
283				showModal('complete',null,widget_code);
284			}
285		}else{
286			if(chk_res === "privacy_required"){
287				showModal('error',LOCALIZE.설명_개인정보처리방침에동의하여주시기바랍니다(), widget_code);
288			} else if(chk_res == 'third_party_required'){
289				showModal('error',LOCALIZE.설명_개인정보제3자제공에동
289의하여주시기바랍니다(), widget_code);
290			} else if(chk_res === 'etc_null'){
291				showModal('error', getLocalizeString('설명_기타선택의직접입력부분입력', '', '직접 입력란을 입력해 주세요.'), widget_code);
292			} else {
293				var checkbox_reg = /^checkbox_limit_[0-9]{1,}$/;
294				if(checkbox_reg.test(chk_res)){
295					chk_res = chk_res.replace(/[^0-9]/g,'');
296					showModal('error',LOCALIZE.설명_최대n개까지선택가능합니다(chk_res), widget_code);
297				}else{
298					showModal('error',LOCALIZE.설명_필수항목을입력하여주시기바랍니다(), widget_code);
299				}
300			}
301		}
302	};
303
304	var hideModal = function(){
305		//$('#input_form_complete_modal').hide();
306		var $body = $('body');
307		$('.modal.in.modal_site_alert').hide();
308		$body.toggleClass('site_alert_open', false);
309	};
310
311	var showModal = function(type,msg,widget_code){
312		hideModal();
313		var modal_target;
314		var $body = $('body');
315		$body.toggleClass('site_alert_open', true);
316		if(type == 'complete'){
317			modal_target = 'input_form_complete_modal_' + widget_code;
318		} else {
319			modal_target = 'input_form_error_modal_' + widget_code;
320		}
321		if(msg != undefined && msg.trim() != ''){
322			$('#'+modal_target+' .modal-content .container-fluid p').html(msg);
323			if(type == 'complete'){
324
325				var form_url_link = ' onclick="SITE_FORM.completeMoveUrl()"';
326
327				$('#'+modal_target+' .btn-group-justified').html('<a '+form_url_link+' class="btn right" >'+LOCALIZE.버튼_확인()+'</a>');
328			}
329		}
330		$('#'+modal_target).show();
331	};
332
333	var completeMoveUrl = function(){
334		hideModal();
335
336		if(form_url_data.form_url !== ''){
337
338			if(form_url_data.new_window === 'Y'){
339				window.open(form_url_data.form_url, '_blank');
340				location.reload();
341			}else{
342				window.open(form_url_data.form_url, '_self');
343			}
344		}else{
345			location.reload();
346		}
347
348
349	};
350
351	var onlyNumber = function(){
352		$("._only_number").on('keydown').check_callnum();
353	};
354
355	/**
356	 * 국제 번호 검색창 연결
357	 * @param widget_code		대시보드 컨텐츠 관리에서는 ''
358	 * @param item_code
359	 * @param country_code
360	 */
361	var setDialNumber = function(widget_code, item_code,country_code){
362		var $obj = $('#addForm' + widget_code);
363		var imgMap = {};
364		var imgCountryCode = {};
365		var $phone = $obj.find('._phone_' + item_code);
366		var $phonenumber = $obj.find('#phonenumber_' + item_code);
367		$phone.find("option").filter(function(){
368			return $(this).text();
369		}).each(function(i) {
370			imgMap[i] = $(this).attr("data-img-src");
371			imgCountryCode[i] = $(this).attr("data-country-code");
372
373			imgMap[imgCountryCode[i]]=imgMap[i];
374		});
375		$phone.chosen({
376			allow_single_deselect : true,
377			search_contains : true,
378			no_results_text : getLocalizeString('설명_검색결과가없습니다', '', '검색 결과가 없습니다.') + " : ",
379			placeholder_text_single : getLocalizeString('설명_국가선택', '', '국가 선택'),
380			width: 'auto'
381		});
382		var $chosen = $phone.next('.chosen-container');
383		var touchStartY, touchEndY, touchStartScrollTop;
384		$chosen.on('click.chosen, mousedown.chosen, keyup.chosen, touchstart.chosen', function(event){
385			var $chosen_search_input = $chosen.find('.chosen-search input');
386			var now_country_code = $phonenumber.find('input[name="phone_country_' + item_code + '"]').val();
387			var now_country_index = 0;
388			$chosen_search_input.attr('placeholder', getLocalizeString('설명_검색어를입력하세요', '', '검색어를 입력하세요.'));
389			var $chosen_result = $chosen.find('.chosen-results');
390			var $chosen_result_li = $chosen_result.find('li');
391			$chosen_result_li.each(function() {
392				var $that = $(this);
393				if($that.find('.flag').length === 0){
394					// allow_single_deselect 옵션에 의해 초기값이 제외되어 index가 하나씩 밀림
395					var imgIndex = $that.attr('data-option-array-index') - 1;
396					if(imgMap[imgIndex]){
397						// 레이아웃 중앙 정렬 문제로 태그 구조 변경
398						// 국가명과 국제 번호 분리(국제 번호도 검색 내용에 포함시킴)
399						var text = $that.text();
400						var splited_text = text.split('+');
401						var $div = $('<div></div>');
402						$div.html('<span>' + splited_text[0] + '</span><span class="opacity-50" data-title="dial">+' + splited_text[1] + '</span>');
403						// 국기 추가
404						var $flag = $('<span class="flag" data-title="flag" data-country-code="'+imgCountryCode[imgIndex]+'" data-img-src="' + imgMap[imgIndex] + '"></span>').css('background-image', 'url("' + imgMap[imgIndex] + '")');
405						$div.prepend($flag);
406						$that.html($div);
407						if(now_country_code != '' && imgCountryCode[imgIndex] === now_country_code){
408							now_country_index = imgIndex;
409						}
410					}
411				}
412			});
413			$chosen_result_li.off('click.chosen_result').on('click.chosen_result', function(event){
414				selectDial(event.target);
415			});
416			// 엔터에 대한 케이스
417			if (event.type === 'keyup' && event.key === 'Enter') {
418				const $selected = $(event.currentTarget).find('.chosen-results .active-result.result-selected');
419
420				// 선택된 것이 1개일 경우
421				if ($selected.length === 1) {
422					selectDial($selected);
423				}
424
425				/**
426				 * Notice:
427				 * 	엔터로 선택 시 선택된 요소가 2개가 존재하는 경우가 있음
428				 * 	기존 선택을 필터하기 위해 아래와 같이 처리함
429				 * 	만약, 3개 이상인 경우가 발생될 경우 수정 필요
430				 */
431				if ($selected.length > 1) {
432					const $target = $(event.currentTarget)
433						.find('.chosen-results .active-result.result-selected')
434						.filter(function() {
435							const targetCountryCode = $(this).find('span[data-title="flag"]').attr('data-country-code') || '';
436
437							return targetCountryCode !== now_country_code;
438						});
439
440					selectDial($target);
441				}
442			}
443			if(now_country_index > 0){
444				// 선택된 국기를 상위에 표시
445				$chosen_result.scrollTop($($chosen_result_li[now_country_index]).offset().top - $($chosen_result_li[0]).offset().top);
446			}
447			if(IS_MOBILE){
448				$chosen_result.off('touchstart.chosen_result').on('touchstart.chosen_result', function(event){
449					touchStartY = event.originalEvent.touches[0].pageY;
450					touchEndY = touchStartY;
451					touchStartScrollTop = $(this).scrollTop();
452				});
453				$chosen_result.off('touchmove.chosen_result').on('touchmove.chosen_result', function(event){
454					touchEndY = event.originalEvent.touches[0].pageY;
455					// 터치 스크롤
456					$(this).scrollTop(touchStartScrollTop + (touchStartY - touchEndY));
457				});
458				$chosen_result.off('touchend.chosen_result').on('touchend.chosen_result', function(event){
459					// 터치 시작과 끝이 10px 이하일 때 탭으로 간주
460					if(Math.abs(touchStartY - touchEndY) < 10){
461						selectDial(event.target);
462						$chosen.removeClass('chosen-container-active chosen-with-drop');
463						$chosen_search_input.val('');
464					}
465				});
466			}
467
468			function selectDial($target){
469				$phonenumber.find(".chosen-single").show();
470				var $target = $($target).closest('#phonenumber_' + item_code + ' .chosen-results li');
471				if($target.length > 0){
472					var flag = $target.find('span[data-title="flag"]').attr('data-img-src') || '';
473					var dial = $target.find('span[data-title="dial"]').text();
474					var country_code = $target.find('span[data-title="flag"]').attr('data-country-code')|| '';
475					if(dial){
476						if(flag){
477							var $flag = $('<span class="flag" data-title="flag"></span>').css('background-image', 'url("' + flag + '")');
478							$phonenumber.find(".chosen-single > span").html("<span>"+ dial +"</span>").prepend($flag);
479							$phonenumber.find('input[name=phonenumber1_'+ item_code+']').val(dial.replace('+',''));
480							$phonenumber.find('input[name=phone_country_'+ item_code+']').val(country_code);
481						}else{
482							$phonenumber.find(".chosen-single > span").html(dial);
483							$phonenumber.find('input[name=phonenumber1_'+ item_code+']').val(dial.replace('+',''));
484							$phonenumber.find('input[name=phone_country_'+ item_code+']').val(country_code);
485						}
486						$phone.val(dial);
487					}
488				}
489			}
490		});
491		if(IS_MOBILE){
492			$chosen.on('touchstart.chosen', function(){
493				// 모바일에서 자동으로 focus 되어 가상 키보드가 올라오지 않도록 처리
494				var $chosen_search_input = $chosen.find('.chosen-search input');
495				$chosen_search_input.blur();
496				$chosen_search_input.off('touchend.chosen_search').on('touchend.chosen_search', function(){
497					$chosen_search_input.focus();
498				})
499			})
500		}
501
502		//대시보드 : 수정시 번호가 존재할 경우
503		var dial_number = $phone.val();
504		var $phonenumber1_val = $('<input type="hidden" name="phonenumber1_'+item_code+'" value='+ dial_number +'>');
505		var $phone_country_val = $('<input type="hidden" name="phone_country_'+item_code+'" value='+ country_code +'>');
506		$phonenumber.prepend($phonenumber1_val);
507		$phonenumber.prepend($phone_country_val);
508		if(dial_number != ""){
509			var $flag = $('<span class="flag" name="flag"></span>').css('background-image', 'url("' + imgMap[country_code] + '")');
510			$phonenumber.find(".chosen-single span").html("<span> +" + dial_number + "</span>").prepend($flag);
511		}
512	};
513
514	return {
515		init:function(){
516			init();
517		},
518		itemFileUpload:function($obj,$code){
519			itemFileUpload($obj,$code);
520		},
521		itemRequiredCk:function($obj){
522			return itemRequiredCk($obj);
523		},
524		itemEtcSetting:function(widget_code, item_code, type){
525			return itemEtcSetting(widget_code, item_code, type);
526		},
527		submit:function(widget_code){
528			return submit(widget_code);
529		},
530		confirmInputForm:function(widget_code, modify_permit){
531			return confirmInputForm(widget_code, modify_permit);
532		},
533		hideModal:function(){
534			return hideModal();
535		},
536		onlyNumber: function(){
537			return onlyNumber();
538		},
539		completeMoveUrl : function(){
540			return completeMoveUrl();
541		},
542		setDialNumber : function(widget_code, item_code,country_code){
543			return setDialNumber(widget_code, item_code,country_code);
544		}
545	}
546}();

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.