PageSourceSearch

https://mportal.cau.ac.kr/common/js/portalCommonDirective.js?20221201

js cau.ac.kr collected 2026-09-24 08:44:08 UTC 10,143 bytes, 318 lines download raw bytes

1(function(){
2	'use strict';
3
4	angular.module('portal.commonDirective', []);
5
6	angular
7
8		.module('portal.commonDirective')
9		//공통적으로 추가할로직 대비하여 공통 디렉티브로 만듬 ozFrame
10		.directive("ozFrame", function(){
11			return {
12				restrict : "E",
13				scope : {},
14				template :  "<iframe name=\"ozFrame\" id=\"ozFrame\" frameborder=\"0\" scrolling=\"no\" width=\"100%\" height=\"500px\"></iframe>",
15				link : function( scope, element, attrs ){
16					element.attr("name", attrs.name || "ozFrame");
17					element.attr("width", attrs.width || "100%");
18					element.attr("height", attrs.height || "500px");
19				}
20			}
21		})
22        .directive('convertToNumber', function() {
23            return {
24                require: 'ngModel',
25                link: function(scope, element, attrs, ngModel) {
26                    ngModel.$parsers.push(function(val) {
27                        return val != null ? parseInt(val, 10) : null;
28                    });
29                    ngModel.$formatters.push(function(val) {
30                        return val != null ? '' + val : null;
31                    });
32                }
33            };
34        })
35		.directive('ngEnter', function() {
36				return function(scope, element, attrs) {
37					element.bind("keydown keypress", function(event) {
38						if(event.which === 13) {
39							scope.$apply(function(){
40								scope.$eval(attrs.ngEnter);
41							});
42
43							event.preventDefault();
44						}
45					});
46				};
47			})
48		.directive("gridViewBtn", function(){
49			return {
50				restrict : "E",
51				scope : {
52					target : "=",
53					type : "@"
54				},
55				replace : true,
56				template : "<div class=\"nb-btn-default btn-grid-{{type}}\">\n" +
57                "                <button ng-click=\"target['setMobileScroll' + type.substr(0,1).toUpperCase() + type.substr(1) ]()\"\n" +
58                "                        ng-class=\"target['isMobile' + type.substr(0,1).toUpperCase() + type.substr(1) ]() ? 'active' : ''\"></button>\n" +
59                "            </div>"
60			}
61		})
62        .directive('spRadio', function($compile){
63            return {
64                restrict : 'E',
65                transclude : true,
66                scope : {
67                    ngModel : "=",
68                    onClick : "&onClick",
69                    onChange : "&onChange"
70                },
71                replace : true,
72                template :  '<div class="nb-radio">' +
73								'<label>' +
74									'<input type="radio" ng-model="ngModel" value="{{value}}" name="{{name}}" ng-click="onClick()" ng-change="onChange()">' +
75									'<span>' +
76									'<i></i>' +
77									'<em ng-transclude></em>'+
78									'</span>' +
79								'</label>' +
80							'</div>' ,
81                link : function ( $scope, $elem , $attr ){
82                    var $radioInput = $elem.find('input[type=radio]');
83                    $scope.value = $attr.value;
84                    $scope.name = $attr.name;
85                }
86            }
87        })
88
89		.directive("fileread", function () {
90            return {
91            	restrict : 'A',
92				priority : 99,
93                scope: {
94                    fileread: "=",
95					filename: "="
96                },
97                link: function (scope, element, attributes) {
98                    element.on("change", function (changeEvent) {
99                        scope.$apply(function() {
100                            scope.fileread = element.get(0).files[0];
101                            scope.filename = element.val();
102                        });
103
104                    });
105                }
106            }
107        })
108    	.directive('uploadfile', function () {
109			return {
110				restrict: 'A',
111				link: function(scope, element) {
112
113					element.bind('click', function(e) {
114						angular.element(e.target).siblings('input[type=file]').trigger('click');
115					});
116				}
117			};
118		})
119		.directive("scmsKeyupControl", function(){
120			var linker = function (scope, element, attr, ngModelCtrl) {
121				var controlType = attr.scmsKeyupControl,
122					arrControlType = controlType.split(','),
123					regx = '';
124
125				angular.forEach(arrControlType, function(item, idx, a, b){
126					if(idx < 1){
127						regx += '[^';
128					}
129					switch(item.trim()){
130						case 'N':
131							regx += '0-9';
132							break;
133						case 'E':
134							regx += 'a-zA-Z';
135							break;
136						case 'H':
137							regx += 'ㄱ-ㅎ|ㅏ-ㅣ|가-힣';
138							break;
139						case 'P':
140							regx += '0-9-';
141							break;
142					}
143					if(idx === arrControlType.length-1){
144						regx += ']';
145					}
146				});
147
148				function fromUser(text) {
149					if (text) {
150						var transformedInput = text.replace(new RegExp(regx, 'g'), '');
151						if (transformedInput !== text) {
152							ngModelCtrl.$setViewValue(transformedInput);
153		                    ngModelCtrl.$render();
154		                }
155						return transformedInput;
156		            }
157		            // return true;
158		        }
159				ngModelCtrl.$parsers.push(fromUser);
160			}
161			return {
162				require: '?ngModel',
163				restrict: 'A',
164			    link: linker
165			}
166		})
167		.directive('calculateToBytes', function($compile){
168			var linker = function(scope, element, attrs){
169				var bytes = scope.bytes,
170					s = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB'],
171					e = Math.floor(Math.log(bytes) / Math.log(1024)),
172					result = '';
173
174				if (e == "-Infinity"){
175					result = "0" + s[0];
176				}
177				else{
178					result = (bytes / Math.pow(1024, Math.floor(e))).toFixed(2) + s[e];
179				}
180				element.html(result);
181			}
182
183			return {
184				restrict : 'E',
185				scope: {
186	                bytes : '@'
187	            },
188	            replace: true,
189				link : linker
190			}
191		})
192    // 한글, 영어를 체크하여 계산된 바이트 길이를 최소 길이와 비교(ex. minbytelength="4")
193     .directive('minbytelength', function() {
194        return {
195            restrict : 'A',
196            require : 'ngModel',
197            link : function(scope, elem, attrs, ctrl) {
198                if( !ctrl ) return;
199
200                function MinByteLength(value) {
201                    var intVal = parseInt(scope.$eval(attrs.minbytelength), 10);
202                    var nMin = isNaN(intVal) ? 0 : intVal;
203                    var nBytes = ctrl.$isEmpty(value) ? 0 : value.byteLength();      // 문자열의 Byte 길이를 반환(한글은 2byte이며 영숫자는 1byte)
204
205                    ctrl.$setValidity('minbytelength', (nBytes == 0 || nBytes >= nMin));
206
207                    return value;
208                }
209
210                ctrl.$parsers.push(MinByteLength);
211            }
212        };
213    })
214
215// 한글, 영어를 체크하여 계산된 바이트 길이를 최대 길이와 비교(ex. maxbytelength="20")
216     .directive('maxbytelength', function() {
217        return {
218            restrict : 'A',
219            require : 'ngModel',
220            link : function(scope, elem, attrs, ctrl) {
221                if( !ctrl ) return;
222
223                function MaxByteLength(value) {
224                    var intVal = parseInt(scope.$eval(attrs.maxbytelength), 10);
225                    var nMax = isNaN(intVal) ? Infinity : intVal;
226                    var nBytes = ctrl.$isEmpty(value) ? 0 : value.byteLength();      // 문자열의 Byte 길이를 반환(한글은 2byte이며 영숫자는 1byte)
227
228					if(  nBytes > nMax ){
229                        ctrl.$setViewValue(value.cut(nMax));
230                        ctrl.$render();
231					}
232
233
234                    return value.cut(nMax);
235                }
236
237                ctrl.$parsers.push(MaxByteLength);
238            }
239        };
240    })
241
242// 한글, 영어를 체크하여 계산된 바이트 길이를 최소, 최대 길이와 비교(ex. bytelength="[4, 20]")
243    .directive('bytelength', function() {
244        return {
245            restrict : 'A',
246            require : 'ngModel',
247            link : function(scope, elem, attrs, ctrl) {
248                if( !ctrl ) return;
249
250                function ByteLength(value) {
251                    var arrRange = scope.$eval(attrs.bytelength);
252                    var intMinVal = parseInt(arrRange[0], 10);
253                    var intMaxVal = parseInt(arrRange[1], 10);
254
255                    var nMin = isNaN(intMinVal) ? 0 : intMinVal;                    // 최소 바이트
256                    var nMax = isNaN(intMaxVal) ? Infinity : intMaxVal;             // 최대 바이트
257                    var nBytes = ctrl.$isEmpty(value) ? 0 : value.byteLength();  // 문자열의 Byte 길이를 반환(한글은 2byte이며 영숫자는 1byte)
258
259                    ctrl.$setValidity('bytelength', (nBytes == 0 || (nBytes >= nMin && nBytes <= nMax)));
260
261                    return value;
262                }
263
264                ctrl.$parsers.push(ByteLength);
265            }
266        };
267    })
268		.directive('disableClick', function() {
269			return {
270		        restrict:'A',
271		        link: function(scope, element){
272		            element.bind('click', function(event){
273		            	event.stopPropagation();
274		            });
275		        }
276		    }
277		})
278		.directive('onDoubleClick', function($timeout) {
279			return {
280				restrict: 'A',
281		        link: function($scope, $elm, $attrs) {
282		            var clicks=0;
283		            $elm.bind('click', function(evt) {
284		                clicks++;
285		                if (clicks == 1) {
286		                	$timeout(function(){
287		                		if(clicks == 1) {
288		                			//single_click_callback.call(self, event);
289		                		} else {
290		                			$scope.$apply(function() {
291		                				$scope.$eval($attrs.onDoubleClick)
292		                			});
293		                		}
294		                		clicks = 0;
295		                	},  300);
296		                }
297		            });
298		        }
299		    }
300	    })
301		.directive('focusOn', function() {
302	        return function(scope, elem, attr) {
303	            scope.$on('focusOn', function(e, name) {
304	                if(name === attr.focusOn) {
305	                    elem[0].focus();
306	                }
307	            });
308	        };
309	    })
310	    .factory('focus', function ($rootScope, $timeout) {
311	        return function(name) {
312	            $timeout(function (){
313	                $rootScope.$broadcast('focusOn', name);
314	            });
315	        }
316	    });
317})();
318

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.