$.urlParam = function(name) { var results = new RegExp("[\?&]" + name + "=([^&#]*)").exec(window.location.href); if (results == null) { return null; } else { return results[1] || 0; } }; /** * 시스템 로그 저장 * 메뉴 클릭 단위가 아닌 항목 보기(생성 및 보기) 일 때만 로그를 저장한다. * 서버로 정보를 보내고 난 다음에는 아무 액션도 취하지 않는다. * @param menuCd : 메뉴 코드 * @param contId : 컨텐츠 Id */ function appLogging(menuCd, contsId) { try { $.ajax({ url: '/api/v1/appLogging.do', data: {menuCd : menuCd, contsId : contsId}, type: 'GET', dataType: "json", success: function(resp, url) {}, error: function(resp, status, err) {} }); } catch(exception) { //console.log(exception); } }; var ShareData = { mapZoom: null, mousePosition: null, engage: "dmVyeSB2ZXJ5IGhhcmQgdG8gdHlwaW5n", apiPath: "/api/v1/", contentsListYear: "2014", regionMousemoveBusy: false, userKey: "", userId: "", userName: "", userProfileImage: "", groupKey: "", groupName: "", userH1: null, userH2: null, userType: "", adminType: "", teamCd: "", authCd: "", callHandler: function(type, url, data, callback, error, dataType) { "use strict"; url += this.getDefaultParams(url); // if(data == null){ // data = {apiKey:Globals.ApiKey}; // } else{ // data.apiKey = Globals.ApiKey; // } if (type === "PUT") { type = "POST"; } dataType = dataType || 'json'; $.ajax({ url: url, data: data, type: type, dataType: dataType || "json", success: function(resp, url) { if (typeof callback === "function") { callback(resp, url); } }, error: function(resp, status, err) { if (typeof error === "function") { error(resp.responseText); } else { if(resp.responseText.indexOf("java.lang.Exception") > 0){ var respStr = resp.responseText; var tmpStr = respStr.substring(respStr.indexOf("java.lang.Exception"), respStr.length); var errStr = tmpStr.substring(tmpStr.indexOf(":")+1, tmpStr.indexOf("<")); alert(errStr); } console.log(status); console.log(err); } var contentType = resp.getResponseHeader("Content-Type"); if (dataType == 'json' && resp.status === 200 && contentType.toLowerCase().indexOf("text/html") >= 0) { // assume that our login has expired - reload our current page window.location.reload(); } } }); }, getDefaultParams: function(url) { var param = ""; var defaultParam = "&"; if(url.indexOf("?") < 0){ defaultParam = "?"; } if(url.indexOf("http://") == 0){ param = "&apiKey=" + Globals.ApiKey; } if(this.mousePosition != null && (this.mousePosition.lon || this.engage)) { return defaultParam + "engage=" + this.engage + "&x=" + this.mousePosition.lon + "&y=" + this.mousePosition.lat + "&z=" + this.mapZoom + param; } else { return param == "" ? "" : defaultParam + param.substr(1); } }, changeImagePath: function(target, filePath) { "use strict"; var url = window.location.href; if(url.indexOf("test") === -1) { var imgTags = $(target + " img"); if(imgTags.length > 0) { imgTags.each(function(index, img) { $(img).attr("src", $(img).attr("src").replace("../", filePath)); $(img).attr("draggable", false); }); } } }, comma: function(num) { "use strict"; var len, point, str; try { num = num.toFixed(0) + ""; point = num.length % 3 ; len = num.length; str = num.substring(0, point); while (point < len) { if (str != "") str += ","; str += num.substring(point, point + 3); point += 3; } } catch(e) { return num; } return str; } }; WidgetOptions = function() { return { $eventManager: $("body"), cssOptions: null }; }; WidgetFactory = (function() { "use strict"; /** * Widget 이 위치한 web root path * Widget 을 호출하는 파일이 widget 경로 외부에 있을때 * WidgetFactory._setWidgetRootPath() 를 이용하여 widget root path 를 설정한다. */ var _widgetRootPath = ""; var _widgetList = null; function _loadScript(url, callback) { var $script = document.createElement("script"); $script.type = "text/javascript"; if ($script.readyState) { //IE $script.onreadystatechange = function () { if ($script.readyState === "loaded" || $script.readyState === "complete") { $script.onreadystatechange = null; if(typeof callback === "function") { callback(); } } }; } else { //Others $script.onload = function () { if(typeof callback === "function") { callback(); } }; } $script.src = url; document.getElementsByTagName("head")[0].appendChild($script); } function _loadCSS(url, callback) { $(document.createElement("link")).attr({ href: url, type: "text/css", rel: "stylesheet" }).appendTo("head") .on("load", function() { if(typeof callback === "function") { callback(); } }); } function _loadView(url, imgURL, callback) { $.ajax({ dataType: "html", url:url, success: function(data) { if(url.indexOf("test") === -1 && data !== "") { data = data.replace(/.\/images\//g, imgURL); } if(typeof callback === "function") { callback(data); } } }); } function _disableImageDraggable() { var imgTags = $("body").find("img"); if(imgTags.length > 0) { imgTags.each(function(index, img) { $(img).attr("draggable", false); }); } } function _getWidgetPath(widget) { var widgetPath = { folder: null, css: null, view: null, javascript: null, images: null }; var widgetFolderPath = _getUrl() + "widget/"; if(widget.group != null) { widgetFolderPath += widget.group + "/"; } widgetFolderPath += widget.name + "/"; widgetPath.folder = widgetFolderPath; widgetPath.css = _getCSSURL(widgetFolderPath, widget); widgetPath.view = _getViewURL(widgetFolderPath, widget); widgetPath.javascript = _getScriptURL(widgetFolderPath, widget); widgetPath.images = _getImageURL(widgetFolderPath, widget); return widgetPath; } function _getCSSURL(widgetFolderPath, widget) { var widgetCSSPath = widgetFolderPath; if(widget.css != null) { widgetCSSPath += widget.css; } else { widgetCSSPath += widget.name + ".css"; } return widgetCSSPath; } function _getViewURL(widgetFolderPath, widget) { var widgetViewPath = widgetFolderPath; if(widget.view != null) { widgetViewPath += widget.view; } else { widgetViewPath += widget.name + ".html"; } return widgetViewPath; } function _getScriptURL(widgetFolderPath, widget) { var widgetScriptPath = widgetFolderPath; if(widget.js != null) { widgetScriptPath += widget.js; } else { widgetScriptPath += widget.name + ".js"; } return widgetScriptPath; } function _getImageURL(widgetFolderPath, widget) { var widgetImagePath = widgetFolderPath; widgetImagePath += "images/"; return widgetImagePath; // var imgURL = _getUrl() + "widget/"; // //var imgURL = window.location.origin + "/widget/"; // if(widget.group != null) { // imgURL += widget.group + "/"; // } // return imgURL; } function _createWidgetFromList(widgetList, index) { if(widgetList != null && widgetList.length > 0) { _widgetList = widgetList; if(index == null) { index = 0; } var widget = widgetList[index]; if(widget != null) { // 1. CSS, HTML, javascript Loaging widget.container = widget.container || "body"; var $widget = $("
").hide(); var widgetPath = _getWidgetPath(widget); widget.Path = widgetPath; if ((widget.loadOnly == null || widget.loadOnly === false) && (widget.scriptOnly == null || widget.scriptOnly === false)) { if (widget.loadCss == null || widget.loadCss === true) { _loadCSS(widgetPath.css, function() { _loadView(widgetPath.view, widgetPath.images, function(data) { $widget.append(data); if(typeof widget.styles !== 'undefined') $widget.css(widget.styles); // css 는 WidgetMap.css 에서 설정 // if(widget.name == 'WidgetMap' && $widget.height() == 0) // $widget.css({position:'absolute', left:0, top:0, right:0, bottom:0}); $(widget.container).append($widget); _loadScript(widgetPath.javascript, function() { _createWidgetFromList(widgetList, ++index); }); }); }); } else { // CSS 를 로딩하지 않을 경우 _loadView(widgetPath.view, widgetPath.images, function(data) { $widget.append(data); if(typeof widget.styles !== 'undefined') $widget.css(widget.styles); // css 는 WidgetMap.css 에서 설정 // if(widget.name == 'WidgetMap' && $widget.height() == 0) // $widget.css({position:'absolute', left:0, top:0, right:0, bottom:0}); $(widget.container).append($widget); _loadScript(widgetPath.javascript, function() { _createWidgetFromList(widgetList, ++index); }); }); } } else { // JavaScript 만 로딩 할 경우 (HTML,CSS 로딩하지 않음) _loadScript(widgetPath.javascript, function() { _createWidgetFromList(widgetList, ++index); }); } } else { // 2. Create Instance _disableImageDraggable(); widgetList.forEach(function(widget, index) { if(widget.loadOnly == null || widget.loadOnly === false) { var show = false; if(widget.show != undefined) { show = widget.show; } var obj = new window[widget.name](); obj.id = (widget.id || widget.name); obj.$view = $("#" + obj.id); // obj.filePath = widget.Path.images; obj.filePath = widget.Path.folder; obj.Path = _getWidgetPath(widget); if (widget.data != null) { for(var key in widget.data) { obj[key] = widget.data[key]; } } if(widget.show === true) { obj.show(); } obj.init(); } }); } } } function _createWidget(widget) { widget.container = widget.container || "body"; var $widget = $("
").hide(); var widgetPath = _getWidgetPath(widget); _loadCSS(widgetPath.css, function() { _loadView(widgetPath.view, widgetPath.images, function(data) { $widget.append(data); if(typeof widget.styles !== 'undefined') $widget.css(widget.styles); // if(widget.name == 'WidgetMap' && $widget.height() == 0) // $widget.css({position:'absolute', left:0, top:0, right:0, bottom:0}); if(widget.show != null && widget.show === true) { $widget.show(); } $(widget.container).append($widget); _loadScript(widgetPath.javascript); _disableImageDraggable(); }); }); return $widget; } /** * widget 디렉토리를 중심으로 file의 절대경로를 구해준다. * file : widget 부터 시작되는 되는 경로로 widget 디렉토리 하위에 있는 파일, 입력되지 않으면 widget 포함하지 않는 패스까지 구해짐. */ function _getUrl(file) { var url = ""; if (_widgetRootPath != "") { url = _widgetRootPath; } else { var path = window.location.href; var i = path.indexOf("/widget/"); if(window.location.href != window.location.origin) path = path.substring(0, path.lastIndexOf("/")); url = (i > 0) ? path.substring(0, i) : path; url += "/"; } return url + ((typeof file === 'string') ? file : ''); } function _setWidgetRootPath(path) { _widgetRootPath = path; } function _getWidgetRootPath() { return _widgetRootPath; } function _getWidgetList() { return _widgetList; } return { createWidgetFromList:_createWidgetFromList, createWidget:_createWidget, getUrl:_getUrl, setWidgetRootPath:_setWidgetRootPath, getWidgetRootPath:_getWidgetRootPath, getWidgetList: _getWidgetList }; })(); (function(window) { if (!window.location.origin) { window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ":" + window.location.port : ""); } if(typeof Array.prototype.forEach != 'function') { Array.prototype.forEach = function(callback){ var max = this.length; for (var i = 0; i < max; i++){ callback.apply(this, [this[i], i, this]); } }; } if(Array.isArray == null) { Array.isArray = function(arg) { return Object.prototype.toString.call(arg) === '[object Array]'; }; } })(typeof window !== "undefined" ? window : this);