PageSourceSearch

https://www.nasmedia.co.kr/wp-content/themes/nasmedia/js/jt.js?v=d020c62e

js nasmedia.co.kr collected 2026-09-24 09:42:57 UTC 15,464 bytes, 603 lines download raw bytes

1'use strict';
2
3/**
4 * JT javascript UI library
5 * @namespace
6 * @description UI library create to help front end developement
7 */
8var JT = JT || {};
9
10(function(win, $) {
11
12	/**
13	 * Custom Alert helper
14	 *
15	 * @version 1.1.0
16	 * @since 2018-02-12
17	 * @author STUDIO-JT (NICO)
18	 *
19	 * @param {string|object} args - the message or an options object for more custom.
20	 * @param {string} args.message - 알림 메시지 내용.
21	 * @param {string} [args.title=false] - 알림 메시지 제목.
22	 * @param {string} [args.is_confirm=false] - if need display confirm modal (with cancel button).
23	 * @param {string} [args.ok=확인] - 확인 버튼 커스텀 텍스트.
24	 * @param {string} [args.cancel=취소] - 취소 버튼 커스텀 텍스트.
25	 * @param {string} [args.style=basic] - predefined style are "basic" or "classic" can bee extended by adding what ever classname you want.
26	 * @param {string} [args.type=none] - predefined style are "info", "success", "warning", "error" can bee extended by adding what ever classname you want.
27	 * @param {string} [args.primary_title=false]
28	 * @param {string} [args.primary_button=true]
29	 * @param {string} [args.button_icon=true]
30	 * @param {string} [args.has_icon=false]
31	 * @param {callback} [args.on_confirm] - callback if press confirm.
32	 * @param {callback} [args.on_cancel] - callback if press cancel button for confirm modal.
33	 * @param {callback} [cb] - on confirm callback for simple.
34	 *
35	 * @todo create custom ui
36	 *
37	 * @example
38	 * // String minimal required option :
39	 * JT.alert('Some alert message');
40	 *
41	 * // String type with callback :
42	 * JT.alert('Some alert message', function(){
43	 *     console.log('Alert 끝!');
44	 * });
45	 *
46	 * // Object type parameter옵션 :
47	 * JT.alert({
48		   title    : '상태 변경 완료',
49		   primary_title : true,
50	 *     message  : '개인정보수집 및 이용안내에 동의하여 주십시오.',
51	 *     ok       : '확인 버튼 커스텀 텍스트',
52	 *     cancel   : '취소 버튼 커스텀 텍스트',
53	 *     style    : 'classic',
54	 *     type     : 'success',
55	 *     button_icon : false,
56     *     on_confirm : function(){
57	 *         console.log('Alert 끝!');
58     *     },
59     *     on_cancel : function(){
60	 *         console.log('Alert 취소!');
61     *     }
62	 * });
63	 *
64	 */
65	JT.alert = function(args,cb){
66
67        if(typeof args !== 'object' && typeof args !== 'string') return;
68
69		if(typeof cb == 'undefined') {
70			cb = '';
71		}
72
73        var title, message, on_confirm, on_cancel, ok, cancel, is_confirm, style, type, primary_title, primary_button, button_icon, has_icon;
74
75        // string or object parameter
76        if(typeof args == 'object'){
77            message = args.message;
78            on_confirm = args.on_confirm;
79			on_cancel = args.on_cancel;
80        }else{
81            message = args;
82        }
83
84		// if has on_confirm callback second parameter  (TODO : improve the parameter 확인 logic)
85		if(typeof cb == 'function' && typeof args != 'object'){
86		    on_confirm = cb;
87		}
88
89		// set default value
90        ok = (typeof args.ok != 'undefined') ? args.ok : '확인';
91        cancel = (typeof args.cancel != 'undefined') ? args.cancel : '취소';
92		is_confirm = (typeof args.is_confirm != 'undefined') ? args.is_confirm : false;
93		title = (typeof args.title != 'undefined') ? args.title : false;
94		style = (typeof args.style != 'undefined') ? args.style : 'basic';
95		type = (typeof args.type != 'undefined') ? args.type : 'none';
96		primary_title = (typeof args.primary_title != 'undefined') ? args.primary_title : false;
97		primary_button = (typeof args.primary_button != 'undefined') ? args.primary_button : true;
98		button_icon = (typeof args.button_icon != 'undefined') ? args.button_icon : true;
99		has_icon = (type != 'none') ? true : false ;
100
101        // Get a unique id
102        var now  = new Date().getTime();
103        var uid  = now / 1000 | 0;
104        var id   = 'jt_alert_'+ uid ;
105
106		// defined class
107		var css_class = "jt_alert";
108
109		css_class += " jt_alert_style_"+style;
110		css_class += " jt_alert_type_"+type;
111
112		if(is_confirm){
113		    css_class += " jt_alert_confirm";
114		}
115
116		if(primary_title){
117		    css_class += " jt_alert_primary_title";
118		}
119
120		if(primary_button){
121		    css_class += " jt_alert_primary_button";
122		}
123
124		//if(button_icon){
125		//    css_class += " jt_alert_button_icon";
126		//}
127
128		if(has_icon){
129		    css_class += " jt_alert_has_icon";
130		}
131
132        // html 생성
133        var html    = "";
134
135        html +=  '<div id="'+ id +'" class="'+css_class+'" role="alert">';
136            html +=  '<div class="jt_alert_container">';
137                html +=  '<div class="jt_alert_content">';
138				    if(title){
139					html +=  '<h1>'+ title+'</h1>';
140					}
141					html +=  '<p>'+ message+'</p>';
142				html +=  '</div> ';
143                html +=  '<div class="jt_alert_actions">';
144                    if(is_confirm){
145				    html +=  '<button class="jt_alert_cancel">'+cancel+'</button>';
146				    }
147				    html +=  '<button class="jt_alert_ok">'+ok+'</button>';
148                html +=  '</div>';
149            html +=  '</div> ';
150        html +=  '</div> ';
151
152        // Body 안에 추가
153        $('body').append(html);
154
155        // 접근성 포커스
156        $('#'+ id +' .jt_alert_ok').attr("tabindex", 0).focus();
157
158        // 이벤트 추가
159        $('#'+ id).find('.jt_alert_ok').on('click', function(e) {
160            e.preventDefault();
161            $('#'+ id).remove();
162
163            if(typeof on_confirm === 'function'){
164                on_confirm();
165            }
166
167        });
168
169		$('#'+ id).find('.jt_alert_cancel').on('click', function(e) {
170            e.preventDefault();
171            $('#'+ id).remove();
172
173            if(typeof on_cancel === 'function'){
174                on_cancel();
175            }
176
177        });
178
179        // Esc 키누르시면 알림 팝업
180		var esc = function(e){
181            if (e.which == '27') {
182                $('#'+ id).remove();
183            }
184        };
185        $(document).off('keyup', esc);
186        $(document).on('keyup', function(e){
187             esc(e);
188        });
189
190	};
191
192	/**
193	 * Custom confirm helper
194	 *
195	 * @version 1.0.0
196	 * @since 2018-02-12
197	 * @author STUDIO-JT (NICO)
198	 *
199	 * @todo create custom ui
200	 *
201	 * @example
202	 * // Basic usage :
203	 * JT.confirm('Some confirm message');
204	 */
205	JT.confirm = function(msg){
206		confirm(msg);
207	};
208
209	/**
210	 * Animated ScrollTo helper
211	 *
212	 * @version 1.0.0
213	 * @since 2018-02-12
214	 * @author STUDIO-JT (NICO)
215	 *
216	 * @todo Add call when transition ended
217	 *
218	 * @example
219	 * // Basic usage :
220	 * JT.scrollTo('#my_traget');
221	 */
222	JT.scrollTo = function(target,container){
223		var $target = $(target);
224		var offset = 10;
225		var $container, container;
226
227		if($target.length > 0){
228			if(container == undefined || $(container).length <= 0){
229				$container = $("html");
230			} else {
231				$container = $(container);
232			}
233
234			$container.stop().animate({
235				scrollTop: ($target.offset().top - $container.offset().top + $container.scrollTop()) - offset
236			},function(){
237				//console.log('complete');
238			});
239
240		}
241	};
242
243
244
245	/**
246	 * Smooth scroll with TweenMax (TODO : make a plugin)
247	 *
248	 * @version 1.0.0
249	 * @since 2018-02-03
250	 * @author STUDIO-JT (NICO)
251	 * @requires TweenMax.min.js
252	 * @requires ScrollToPlugin.min.js
253	 */
254	JT.smoothscroll = {
255
256		passive : function(){
257			var supportsPassive = false;
258			try {
259			  document.addEventListener("test", null, { get passive() { supportsPassive = true }});
260			} catch(e) { }
261
262			return supportsPassive;
263		},
264		init : function(){
265
266			if($('html').hasClass('mobile') || $('html').hasClass('mac')) return;
267
268			var $window = $(window);
269			//var scrollTime = 1;
270			var distance_offset = 2.5;
271			//var scrollDistance = $window.height() / distance_offset;
272
273			if(this.passive()){
274			    window.addEventListener("wheel",this.scrolling,{passive: false});
275			}else{
276                $window.on("mousewheel DOMMouseScroll", this.scrolling);
277			}
278
279		},
280		destroy : function(){
281
282			if(this.passive()){
283			    window.removeEventListener("wheel",this.scrolling);
284			}else{
285               $(window).off("mousewheel DOMMouseScroll", this.scrolling);
286			}
287			gsap.killTweensOf($(window),{scrollTo:true});
288
289		},
290		scrolling : function(event){
291
292			event.preventDefault();
293
294			var $window = $(window);
295			var scrollTime = 1;
296			var distance_offset = 2.5;
297			var scrollDistance = $window.height() / distance_offset;
298			var delta = 0;
299
300			if(JT.smoothscroll.passive()){
301			    delta = event.wheelDelta/120 || -event.deltaY/3;
302			}else{
303				if(typeof event.originalEvent.deltaY != "undefined"){
304					delta = -event.originalEvent.deltaY/120;
305				}else{
306				    delta = event.originalEvent.wheelDelta/120 || -event.originalEvent.detail/3;
307				}
308			}
309
310			var scrollTop = $window.scrollTop();
311			var finalScroll = scrollTop - parseInt(delta*scrollDistance);
312
313			TweenMax.to($window, scrollTime, {
314				scrollTo : { y: finalScroll, autoKill:true },
315				ease: Power3.easeOut,
316				overwrite: 5
317			});
318
319
320		},
321        disable : function () {
322            this.destroy();
323
324            if ( this.passive() ) {
325
326                window.addEventListener( 'wheel', this.scroll_destory, { passive: false } );
327
328            } else {
329
330                $( window ).on( 'mousewheel DOMMouseScroll', this.scroll_destory );
331
332            }
333        },
334        enable : function () {
335
336            JT.smoothscroll.init();
337
338            if ( this.passive() ) {
339
340                window.removeEventListener( 'wheel', this.scroll_destroy );
341
342            } else {
343
344                $( window ).off( 'mousewheel DOMMouseScroll', this.scroll_destroy );
345
346            }
347
348        },
349        scroll_destory : function ( event ) {
350
351            event.preventDefault();
352
353        }
354
355	};
356
357
358
359
360	/**
361	 * Check if screen is smaller than
362	 *
363	 * @description egal to css mediaqueries max-width
364	 * @version 1.0.0
365	 * @since 2018-02-12
366	 * @author STUDIO-JT (NICO)
367	 *
368	 * @example
369	 * // Basic usage :
370	 * JT.is_screen('767');
371	 */
372	JT.is_screen = function(max_width){
373		if(win.matchMedia){
374			return win.matchMedia('(max-width:'+ max_width +'px)').matches;
375		}else{
376			return win.innerWidth <= max_width;
377		}
378	};
379
380
381
382	/**
383	 * Modal helper
384	 *
385	 * @description modal layer using maginific-popup.js
386	 *
387	 * @version 1.0.0
388	 * @since 2018-02-12
389	 * @author STUDIO-JT (NICO)
390	 * @requires jquery.magnific-popup.js
391	 * @see {@link http://dimsemenov.com/plugins/magnific-popup/|magnific-popup API}
392	 * @todo Nedd to be implement
393	 *
394	 */
395	JT.modal = function(){
396		//todo
397	};
398
399
400	/**
401	 * Empty object will store all custom global of the site
402	 *
403	 * @description Sometime variables or functions need to be accessible globally.
404	 * Use this object to store them, it avoid potentiel conflict with third party script.
405	 * Please use this functionality with wisdom you avoid memory issue
406	 *
407	 * @version 1.0.0
408	 * @since 2018-02-12
409	 * @author STUDIO-JT (NICO)
410	 *
411	 * @example
412	 * // Add global variable :
413	 * JT.globals.my_var = 'somthing';
414	 *
415	 * // Add global fucntion :
416	 * JT.globals.my_function = function(){
417	 *   // alert('something')
418	 * };
419	 */
420	JT.globals = {};
421
422
423
424
425	/**
426	 * Cookies helper
427	 *
428	 * @Crud your cookies
429	 *
430	 * @version 1.0.0
431	 * @since 2019-04-04
432	 * @author STUDIO-JT (NICO)
433	 * @see {@link https://www.quirksmode.org/js/cookies.html}
434	 *
435	 * @example
436	 * // Cookie 추가 (7일):
437	 * JT.cookies.create('jt_my_cookie_id','Cookie 내용',7);
438	 *
439	 * // Cookie 일기
440     * JT.cookies.read('jt_my_cookie_id');
441	 *
442	 * // Cookie 삭제
443     * JT.cookies.destroy('jt_my_cookie_id');
444	 */
445	JT.cookies = {
446
447		create : function(name,value,days) {
448			if (days) {
449				var date = new Date();
450				date.setTime(date.getTime()+(days*24*60*60*1000));
451				var expires = "; expires="+date.toGMTString();
452			}
453			else var expires = "";
454			document.cookie = name+"="+value+expires+"; path=/";
455		},
456
457		read : function(name) {
458			var nameEQ = name + "=";
459			var ca = document.cookie.split(';');
460			for(var i=0;i < ca.length;i++) {
461				var c = ca[i];
462				while (c.charAt(0)==' ') c = c.substring(1,c.length);
463				if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
464			}
465			return null;
466		},
467
468		destroy : function(name) {
469			JT.cookies.create(name,"",-1);
470		}
471
472	};
473
474	/**
475	 * Check Webgl support helper
476     *
477	 * @version 1.0.0
478	 * @since 2019-07-25
479	 * @author STUDIO-JT (NICO)
480	 *
481	 * @example
482     * // Add webgl class
483	 * function add_no_webgl_class() {
484	 *     if(!is_webgl_support()){
485	 *        $('html').addClass('no_webgl');
486	 *     }
487	 * }
488	 */
489	JT.has_webgl = function () {
490		try {
491		    var canvas = document.createElement('canvas');
492		    return !!window.WebGLRenderingContext && (canvas.getContext('webgl') || canvas.getContext('experimental-webgl'));
493		} catch(e) {
494		    return false;
495		}
496	};
497
498
499
500
501    /**
502     * UI Helper
503     *
504     * @description UI 관련 함수 관리용 헬퍼
505     *
506     * @version 1.0.0
507     * @since 2018-04-12
508     * @author STUDIO-JT (201)
509     *
510     * @example
511     * // 등록된 모든 함수 실행하기
512     * JT.ui.init();
513     *
514     * @example
515     * // 함수 등록하기
516     * JT.ui.add( function () {
517     *   // alert('something')
518     * };
519     * JT.ui.add( test_func );
520     * function test_func () {
521     *     // alert( 'somethid' );
522     * };
523     *
524     * @example
525     * // 함수 삭제하기
526     * JT.ui.del( index );
527     *
528     * @example
529     * // 인덱스를 통해 함수 가져오기
530     * JT.ui.get( idx );
531     *
532     * @example
533     * // 인덱스를 통해 함수 실행하기
534     * JT.ui.call( idx );
535     */
536    JT.ui = {
537
538        list: [],
539
540		init: function () {
541
542            for ( var i = 0; i < this.list.length; i++ ) {
543                try {
544                    if ( typeof this.list[ i ] === 'function' ) {
545                        this.list[ i ].call();
546                    }
547                } catch ( e ) { }
548            }
549
550        },
551
552		add: function ( func, exec_flag ) {
553
554            try {
555                if ( typeof func === 'function' ) {
556                    this.list.push( func );
557                    if ( typeof exec_flag !== 'undefined' && exec_flag === true ) {
558                        func.call();
559                    }
560                }
561
562            } catch ( e ) { }
563
564        },
565
566		del: function ( idx ) {
567            try {
568                this.list.splice( parseInt( idx ), 1 );
569            } catch ( e ) { }
570        },
571
572		replace: function ( idx, func ) {
573
574            try {
575                if ( typeof func === 'function' ) {
576                    this.list[ idx ] = func;
577                }
578            } catch ( e ) { }
579
580        },
581
582		get: function ( idx ) {
583
584            try {
585                return this.list[ idx ];
586            } catch ( e ) {
587                return null;
588            }
589
590        },
591
592		call: function ( idx ) {
593
594            try {
595                this.list[ idx ].call();
596            } catch ( e ) { }
597
598        }
599
600    };
601
602
603})(window, 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.