PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/files/xe-core/1.7.5.3/modules/widget/tpl/js/widget.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 1275 lines | 978 code | 215 blank | 82 comment | 366 complexity | 5a92d0154f30ae812bec38309063ef2a MD5 | raw file
  1. /**
  2. * @file modules/widget/js/widget.js
  3. * @author NAVER (developers@xpressengine.com)
  4. * @brief 위젯 관리용 자바스크립트
  5. **/
  6. /* DOM 속성을 구하기 위한 몇가지 함수들.. */
  7. // style의 값을 구하는게 IE랑 그외가 다름.
  8. function getStyle(obj) {
  9. var style = obj.getAttribute("style");
  10. if(!style)
  11. {
  12. style = obj.style;
  13. }
  14. if(typeof(style)=="object") style = style.cssText;
  15. style = style.replace(/\burl\s*\(\s*"(.*?)"\s*\)/i, "url('$1')");
  16. return style;
  17. }
  18. // float: 값을 구하는게 IE랑 그외가 다름
  19. function getFloat(obj) {
  20. return jQuery(obj).css('float');
  21. }
  22. function setFloat(obj, fl) {
  23. jQuery(obj).css('float', fl);
  24. }
  25. // padding값을 구하는 함수 (없을 경우 0으로 세팅), zbxe의 위젯에서만 사용
  26. function getPadding(obj, direct) {
  27. var padding = obj.getAttribute("widget_padding_"+direct);
  28. if(!padding || padding === null) padding = 0;
  29. return padding;
  30. }
  31. /* 위젯 핸들링 시작 */
  32. var zonePageObj = null;
  33. var zoneModuleSrl = 0;
  34. function doStartPageModify(zoneID, module_srl) {
  35. zonePageObj = get_by_id(zoneID);
  36. zoneModuleSrl = module_srl;
  37. // 위젯 크기/여백 조절 레이어를 가장 밖으로 뺌
  38. jQuery('#tmpPageSizeLayer')
  39. .appendTo('body')
  40. .hide()
  41. .attr('id', 'pageSizeLayer')
  42. .css({position:'fixed'})
  43. .before('<div class="x_modal-backdrop" />')
  44. .find('>form')
  45. .submit(function(){ doApplyWidgetSize(this); return false; });
  46. // 드래그와 리사이즈와 관련된 이벤트 리스너 생성
  47. jQuery('#zonePageContent')
  48. .on('click', doCheckWidget)
  49. .on('mousedown', doCheckWidgetDrag)
  50. .on('mouseover', widgetSetup);
  51. }
  52. // 내용 모두 삭제
  53. function removeAllWidget() {
  54. if(!confirm(confirm_delete_msg)) return;
  55. restoreWidgetButtons();
  56. jQuery(zonePageObj).html('');
  57. }
  58. /**
  59. * 특정 영역에 편집된 위젯들을 약속된 태그로 변환하여 return
  60. **/
  61. function getWidgetContent(obj) {
  62. var html = "";
  63. if(typeof(obj)=='undefined' || !obj) obj = zonePageObj;
  64. var widget = null;
  65. jQuery('div.widgetOutput',obj).each(function(){
  66. if(jQuery(this).parent().get(0) != obj) return;
  67. widget = jQuery(this).attr('widget');
  68. switch(widget) {
  69. case 'widgetBox' :
  70. html += getWidgetBoxCode(this, widget);
  71. break;
  72. case 'widgetContent' :
  73. html += getContentWidgetCode(this, widget);
  74. break;
  75. default :
  76. html += getWidgetCode(this, widget);
  77. break;
  78. }
  79. });
  80. return html;
  81. }
  82. // 컨텐츠 위젯 코드 구함
  83. function getContentWidgetCode(childObj, widget) {
  84. var cobj = childObj.firstChild;
  85. var widgetContent = jQuery('div.widgetContent',childObj);
  86. var body = '', attrs = '', code = '', name;
  87. var document_srl = 0;
  88. var toIgnore = 'contenteditable,id,style,src,widget,body,class,widget_width,widget_width_type,xdpx,xdpy,height,document_srl,widget_padding_left,widget_padding_right,widget_padding_top,widget_padding_bottom,hascontent';
  89. if(widgetContent.size() > 0){
  90. document_srl = jQuery(childObj).attr('document_srl');
  91. if(document_srl>0){
  92. body = '';
  93. }else{
  94. body = widgetContent.html();
  95. }
  96. var reIgnore = new RegExp('^('+toIgnore.replace(/,/g, '|')+')$','i');
  97. var value;
  98. for(var i=0;i<childObj.attributes.length;i++) {
  99. if(!(name=childObj.attributes[i].nodeName) || !childObj.attributes[i].nodeValue) continue;
  100. if(reIgnore.test(name)) continue;
  101. if(!(value=childObj.attributes[i].nodeValue)) continue;
  102. attrs += name+'="'+encodeURIComponent(value)+'" ';
  103. }
  104. return '<img hasContent="true" class="zbxe_widget_output" widget="widgetContent" style="'+getStyle(childObj)+'" body="'+body+'" document_srl="'+document_srl+'" widget_padding_left="'+getPadding(childObj,'left')+'" widget_padding_right="'+getPadding(childObj, 'right')+'" widget_padding_top="'+getPadding(childObj, 'top')+'" widget_padding_bottom="'+getPadding(childObj,'bottom')+'" '+attrs+' />';
  105. }else{
  106. return '';
  107. }
  108. return code;
  109. }
  110. // 위젯 박스 코드 구함
  111. function getWidgetBoxCode(childObj, widget) {
  112. var attrs = "";
  113. for(var i=0;i<childObj.attributes.length;i++) {
  114. if(!childObj.attributes[i].nodeName || !childObj.attributes[i].nodeValue || /^jquery[0-9]+/i.test(childObj.attributes[i].nodeName)) continue;
  115. var name = childObj.attributes[i].nodeName.toLowerCase();
  116. if(name == "widget_padding_left" || name == "widget_padding_right" || name == "widget_padding_top" || name == "widget_padding_bottom" || name == "contenteditable" || name == "id" || name=="style" || name=="src" || name=="widget" || name == "body" || name == "class" || name == "widget_width" || name == "widget_width_type" || name == "xdpx" || name == "xdpy" || name == "height") continue;
  117. var value = childObj.attributes[i].nodeValue;
  118. if(!value || value == "Array") continue;
  119. attrs += name+'="'+encodeURIComponent(value)+'" ';
  120. }
  121. var o;
  122. if(jQuery('.widget_inner',childObj).size()>0){
  123. o = jQuery('.widget_inner',childObj);
  124. o = o.get(0);
  125. }else{
  126. o = jQuery('.nullWidget',childObj).get(0);
  127. }
  128. var body = getWidgetContent(o);
  129. return '<div widget="widgetBox" style="'+getStyle(childObj)+'" widget_padding_left="'+getPadding(childObj,'left')+'" widget_padding_right="'+getPadding(childObj,'right')+'" widget_padding_top="'+getPadding(childObj, 'top')+'" widget_padding_bottom="'+getPadding(childObj, 'bottom')+'" '+attrs+'><div><div>'+body+'</div></div></div>';
  130. }
  131. // 일반 위젯 컨텐츠 코드 구함
  132. function getWidgetCode(childObj, widget) {
  133. var attrs = "";
  134. var code = "";
  135. for(var i=0;i<childObj.attributes.length;i++) {
  136. if(!childObj.attributes[i].nodeName || !childObj.attributes[i].nodeValue || /^jquery[0-9]+/i.test(childObj.attributes[i].nodeName)) continue;
  137. var name = childObj.attributes[i].nodeName.toLowerCase();
  138. if(name == "contenteditable" || name == "id" || name=="style" || name=="src" || name=="widget" || name == "body" || name == "class" || name == "widget_width" || name == "widget_width_type" || name == "xdpx" || name == "xdpy" || name == "height") continue;
  139. var value = childObj.attributes[i].nodeValue;
  140. if(!value || value == "Array" || value == "null") continue;
  141. attrs += name+'="'+encodeURIComponent(value)+'" ';
  142. }
  143. var style = childObj.getAttribute("style");
  144. return '<img class="zbxe_widget_output" style="'+getStyle(childObj)+'" widget="'+widget+'" '+attrs+' />';
  145. }
  146. /**
  147. * 직접 내용을 입력하는 위젯을 추가
  148. **/
  149. // 팝업 띄움
  150. function doAddContent(mid) {
  151. var url = request_uri.setQuery('module','widget').setQuery('act','dispWidgetAdminAddContent').setQuery('module_srl',zoneModuleSrl).setQuery('mid',mid);
  152. popopen(url, "addContent");
  153. }
  154. // 직접 내용을 입력하기 위한 에디터 활성화 작업 및 form 데이터 입력
  155. function doSyncPageContent() {
  156. if(opener && opener.selectedWidget) {
  157. var fo_obj = get_by_id("content_fo");
  158. var sel_obj = opener.selectedWidget;
  159. fo_obj.style.value = getStyle(opener.selectedWidget);
  160. fo_obj.widget_padding_left.value = getPadding(sel_obj, 'left');
  161. fo_obj.widget_padding_right.value = getPadding(sel_obj,'right');
  162. fo_obj.widget_padding_bottom.value = getPadding(sel_obj,'bottom');
  163. fo_obj.widget_padding_top.value = getPadding(sel_obj,'top');
  164. var obj = sel_obj.firstChild;
  165. while(obj && !jQuery(obj).hasClass("widgetContent")) obj = obj.nextSibling;
  166. if(obj && jQuery(obj).hasClass("widgetContent")) {
  167. if(!fo_obj.document_srl || fo_obj.document_srl.value == '0') {
  168. try {
  169. var content = Base64.decode(xInnerHtml(obj));
  170. content = editorReplacePath(content);
  171. get_by_id("content_fo").content.value = content;
  172. xe.Editors["1"].exec("SET_IR", [content]);
  173. }
  174. catch(e)
  175. {
  176. }
  177. }
  178. }
  179. }
  180. if(typeof(editorStart)!='undefined') editorStart(1, "module_srl", "content", false, 400 );
  181. }
  182. // 부모창에 위젯을 추가
  183. function addContentWidget(fo_obj) {
  184. var editor_sequence = fo_obj.getAttribute('editor_sequence');
  185. var mid = fo_obj.mid.value;
  186. var module_srl = fo_obj.module_srl.value;
  187. var document_srl = fo_obj.document_srl.value;
  188. var content = editorGetContent(editor_sequence);
  189. var params = {
  190. editor_sequence : editor_sequence,
  191. content : content,
  192. module_srl : module_srl,
  193. document_srl : document_srl
  194. };
  195. // issue 979
  196. if(/^\s*<p>.*<\/p>\s*$/i.test(params.content)) {
  197. // get count of paragraphs
  198. var lowerContent = params.content.toLowerCase();
  199. var idx = lowerContent.indexOf('</p>');
  200. var last_idx = lowerContent.lastIndexOf('</p>');
  201. if(idx > 0 && last_idx > 0 && idx == last_idx) {
  202. params.content = content = params.content.replace(/^\s*<p>|<\/p>\s*$/ig, '');
  203. }
  204. }
  205. exec_xml(
  206. 'widget',
  207. 'procWidgetInsertDocument',
  208. params,
  209. function(ret_obj, response_tags) {
  210. if(!ret_obj || ret_obj.error != '0') return;
  211. var document_srl = ret_obj.document_srl;
  212. var contentWidget = opener.jQuery('div.widgetOutput[widget=widgetContent][document_srl='+document_srl+']'), attr = [];
  213. if(contentWidget.size() > 0) {
  214. attr = contentWidget.get(0).attributes;
  215. }
  216. var tpl = ''+
  217. '<div class="widgetOutput" style="'+fo_obj.style.value+'" widget_padding_left="'+fo_obj.widget_padding_left.value+'" widget_padding_right="'+fo_obj.widget_padding_right.value+'" widget_padding_top="'+fo_obj.widget_padding_top.value+'" widget_padding_bottom="'+fo_obj.widget_padding_bottom.value+'" document_srl="'+document_srl+'" widget="widgetContent">'+
  218. '<button type="button" class="widgetResize"></button>'+
  219. '<button type="button" class="widgetResizeLeft"></button>'+
  220. '<div class="widgetBorder">'+
  221. '<div style="padding:'+fo_obj.widget_padding_top.value+'px '+fo_obj.widget_padding_right.value+'px '+fo_obj.widget_padding_bottom.value+'px '+fo_obj.widget_padding_left.value+'px"></div>'+content+
  222. '</div>'+
  223. '<div class="widgetContent" style="display:none;width:1px;height:1px;overflow:hidden;"></div>'+
  224. '</div>';
  225. var $tpl = jQuery(tpl);
  226. for(var i=0,l=attr.length; i < l; i++) {
  227. if(!$tpl.attr(attr[i].name)) $tpl.attr(attr[i].name, attr[i].value);
  228. }
  229. tpl = jQuery('<div>').append($tpl).html();
  230. opener.doAddWidgetCode(tpl);
  231. window.close();
  232. },
  233. 'document_srl'.split(',') // response tags
  234. );
  235. return false;
  236. }
  237. /* 박스 위젯 추가 */
  238. function doAddWidgetBox() {
  239. var tpl = ''+
  240. '<div class="widgetOutput" style="float:left;width:100%;height:20px;" widget="widgetBox" >'+
  241. '<button type="button" class="widgetBoxResize"></button>'+
  242. '<button type="button" class="widgetBoxResizeLeft"></button>'+
  243. '<div class="widgetBoxBorder">'+
  244. '<div class="nullWidget" style="width:100%;height:100px;"></div>'+
  245. '</div>'+
  246. '</div>';
  247. zonePageObj.innerHTML += tpl;
  248. }
  249. /* 일반 위젯을 추가하기 위해 위젯 팝업창을 띄움 */
  250. function doAddWidget(fo) {
  251. var sel = fo.widget_list;
  252. var idx = sel.selectedIndex;
  253. var val = sel.options[idx].value;
  254. var module_srl = fo.module_srl.value;
  255. var url = request_uri.setQuery('module','widget').setQuery('act','dispWidgetGenerateCodeInPage').setQuery('selected_widget', val).setQuery('module_srl', module_srl);
  256. popopen(url,'GenerateWidgetCode');
  257. }
  258. var selectedWidget = null;
  259. var writedText = null;
  260. var checkDocumentWrite = false;
  261. // document.write(ln)의 경우 ajax로 처리시 가로채기 위한 함수
  262. // 아래 함수는 str 내용을 단지 전역 변수에 보관 후 doAddWidgetCode 에서 재사용하기 위해 사용됨.
  263. window.document.write = window.document.writeln = function(str){
  264. if(checkDocumentWrite) {
  265. writedText = str;
  266. return;
  267. }
  268. if ( str.match(/^<\//) ) return;
  269. if ( !window.opera ) str = str.replace(/&(?![#a-z0-9]+;)/g, "&");
  270. str = str.replace(/(<[a-z]+)/g, "$1 xmlns='http://www.w3.org/1999/xhtml'");
  271. var div = jQuery('<div>').html(str)[0];
  272. var pos;
  273. pos = document.getElementsByTagName("*");
  274. pos = pos[pos.length - 1];
  275. var nodes = div.childNodes;
  276. while ( nodes.length ) {
  277. pos.parentNode.appendChild( nodes[0] );
  278. }
  279. };
  280. // 위젯 추가
  281. function doAddWidgetCode(widget_code) {
  282. restoreWidgetButtons();
  283. // css 추가
  284. var tmp = widget_code;
  285. while(tmp.indexOf("<!--#Meta:")>-1) {
  286. var pos = tmp.indexOf("<!--#Meta:");
  287. tmp = tmp.substr(pos);
  288. var eos = tmp.indexOf("-->");
  289. var cssfile = tmp.substr(10,eos-10);
  290. if(cssfile.indexOf('.js')>-1) {
  291. tmp = tmp.substr(eos);
  292. continue;
  293. }
  294. if(!cssfile) break;
  295. tmp = tmp.substr(eos);
  296. cssfile = request_uri+cssfile;
  297. if(typeof(document.createStyleSheet)=='undefined') {
  298. var css ='<link rel="stylesheet" href="'+cssfile+'" />';
  299. var dummy = xCreateElement("DIV");
  300. xInnerHtml(dummy , css);
  301. document.body.appendChild(dummy);
  302. } else {
  303. document.createStyleSheet(cssfile,0);
  304. }
  305. }
  306. // widget 코드에서 javascript 부분을 빼서 eval후 결과값을 대체함
  307. checkDocumentWrite = true; ///< document.write(ln)등의 함수값을 바로 사용하기 위한 check flag
  308. // widget_code의 javascript 부분 수정
  309. tmp = widget_code.toLowerCase();
  310. while(tmp.indexOf("<script")>-1) {
  311. /*jshint -W004, -W061*/
  312. var pos = tmp.indexOf("<script");
  313. tmp = tmp.substr(pos);
  314. var length = tmp.indexOf("</script>")+9;
  315. var script = widget_code.substr(pos,length);
  316. script = script.replace(/^<script([^>]*)>/i,'').replace(/<\/script>$/i,'');
  317. writedText = null;
  318. try{
  319. eval(script);
  320. }catch(e){}
  321. widget_code = widget_code.substr(0,pos)+writedText+widget_code.substr(pos+length);
  322. tmp = widget_code.toLowerCase();
  323. }
  324. // html 추가
  325. var dummy = xCreateElement('div');
  326. xInnerHtml(dummy, widget_code);
  327. var obj = dummy.childNodes[0];
  328. if(selectedWidget && selectedWidget.getAttribute("widget")) {
  329. var o = jQuery('div.widget_inner',selectedWidget);
  330. var n = jQuery('div.widget_inner',obj);
  331. if(n.size() === 0) n = jQuery('div.nullWidget',obj);
  332. if(o.size() === 0) o = jQuery('div.nullWidget',selectedWidget);
  333. n.html(o.html());
  334. selectedWidget.parentNode.insertBefore(obj, selectedWidget);
  335. selectedWidget.parentNode.removeChild(selectedWidget);
  336. } else {
  337. get_by_id('zonePageContent').appendChild(obj);
  338. }
  339. checkDocumentWrite = false;
  340. selectedWidget = null;
  341. }
  342. // 클릭 이벤트시 위젯의 수정/제거/이벤트 무효화 처리
  343. function doCheckWidget(e) {
  344. if(!e.target) return;
  345. var obj = e.target;
  346. var $obj = jQuery(obj);
  347. selectedWidget = null;
  348. doHideWidgetSizeSetup();
  349. // 위젯 설정
  350. if($obj.hasClass('widgetSetup')) {
  351. var p_obj = obj.parentNode.parentNode;
  352. var widget = p_obj.getAttribute("widget");
  353. if(!widget) return;
  354. selectedWidget = p_obj;
  355. if(widget == 'widgetContent') popopen(request_uri+"?module=widget&act=dispWidgetAdminAddContent&module_srl="+zoneModuleSrl+"&document_srl="+p_obj.getAttribute("document_srl"), "addContent");
  356. else popopen(request_uri+"?module=widget&act=dispWidgetGenerateCodeInPage&selected_widget="+widget+"&widgetstyle="+widgetstyle,'GenerateCodeInPage');
  357. return;
  358. // 위젯 스타일
  359. } else if($obj.hasClass('widgetStyle')) {
  360. /*jshint -W004*/
  361. var p_obj = obj.parentNode.parentNode;
  362. var widget = p_obj.getAttribute("widget");
  363. var widgetstyle = p_obj.getAttribute("widgetstyle");
  364. if(!widget) return;
  365. selectedWidget = p_obj;
  366. popopen(request_uri+"?module=widget&act=dispWidgetStyleGenerateCodeInPage&selected_widget="+widget+"&widgetstyle="+widgetstyle,'GenerateCodeInPage');
  367. return;
  368. // 위젯 복사
  369. } else if($obj.hasClass('widgetCopy') && jQuery(obj.parentNode.parentNode).hasClass('widgetOutput')) {
  370. /*jshint -W004*/
  371. var p_obj = obj.parentNode.parentNode;
  372. restoreWidgetButtons();
  373. if(p_obj.getAttribute('widget')=='widgetContent' && p_obj.getAttribute('document_srl') ) {
  374. var response_tags = ['error','message','document_srl'];
  375. var params = [];
  376. params.document_srl =p_obj.getAttribute('document_srl');
  377. exec_xml('widget','procWidgetCopyDocument', params, completeCopyWidgetContent, response_tags, params, p_obj);
  378. return;
  379. } else {
  380. var dummy = xCreateElement("DIV");
  381. xInnerHtml(dummy,xInnerHtml(p_obj));
  382. dummy.widget_sequence = '';
  383. dummy.className = "widgetOutput";
  384. for(var i=0;i<p_obj.attributes.length;i++) {
  385. if(!p_obj.attributes[i].nodeName || !p_obj.attributes[i].nodeValue) continue;
  386. var name = p_obj.attributes[i].nodeName.toLowerCase();
  387. var value = p_obj.attributes[i].nodeValue;
  388. if(!value) continue;
  389. if(value && typeof(value)=="string") value = value.replace(/\"/ig,'&quot;');
  390. dummy.setAttribute(name, value);
  391. }
  392. if(xIE4Up) dummy.style.cssText = p_obj.style.cssText;
  393. p_obj.parentNode.insertBefore(dummy, p_obj);
  394. }
  395. return;
  396. // 위젯 사이트/ 여백 조절
  397. } else if($obj.hasClass('widgetSize') || $obj.hasClass('widgetBoxSize')) {
  398. var p_obj = obj.parentNode.parentNode;
  399. var widget = p_obj.getAttribute("widget");
  400. if(!widget) return;
  401. selectedWidget = p_obj;
  402. doShowWidgetSizeSetup(e.pageX, e.pageY, selectedWidget);
  403. return;
  404. // 위젯 제거
  405. } else if($obj.hasClass('widgetRemove') || $obj.hasClass('widgetBoxRemove')) {
  406. var p_obj = obj.parentNode.parentNode;
  407. var widget = p_obj.getAttribute("widget");
  408. if(confirm(confirm_delete_msg)) {
  409. restoreWidgetButtons();
  410. p_obj.parentNode.removeChild(p_obj);
  411. }
  412. return;
  413. }
  414. // 내용 클릭 무효화
  415. var p_obj = obj;
  416. while(p_obj) {
  417. if(jQuery(p_obj).hasClass('widgetOutput')) {
  418. e.cancelBubble = true;
  419. e.returnValue = false;
  420. e.preventDefault();
  421. e.stopPropagation();
  422. break;
  423. }
  424. p_obj = p_obj.parentNode;
  425. }
  426. }
  427. // content widget 복사
  428. function completeCopyWidgetContent(ret_obj, response_tags, params, p_obj) {
  429. var document_srl = ret_obj.document_srl;
  430. var dummy = xCreateElement("DIV");
  431. xInnerHtml(dummy,xInnerHtml(p_obj));
  432. dummy.widget_sequence = '';
  433. dummy.className = "widgetOutput";
  434. for(var i=0;i<p_obj.attributes.length;i++) {
  435. if(!p_obj.attributes[i].nodeName || !p_obj.attributes[i].nodeValue) continue;
  436. var name = p_obj.attributes[i].nodeName.toLowerCase();
  437. var value = p_obj.attributes[i].nodeValue;
  438. if(!value) continue;
  439. if(value && typeof(value)=="string") value = value.replace(/\"/ig,'&quot;');
  440. dummy.setAttribute(name, value);
  441. }
  442. p_obj.setAttribute('document_srl', document_srl);
  443. if(xIE4Up) dummy.style.cssText = p_obj.getAttribute("style").cssText;
  444. p_obj.parentNode.insertBefore(dummy, p_obj);
  445. }
  446. // content widget 제거
  447. function completeDeleteWidgetContent(ret_obj, response_tags, params, p_obj) {
  448. restoreWidgetButtons();
  449. p_obj.parentNode.removeChild(p_obj);
  450. }
  451. // 마우스 다운 이벤트 발생시 위젯의 이동을 처리
  452. function doCheckWidgetDrag(e) {
  453. if(!e.target) return;
  454. var obj = e.target;
  455. var $obj = jQuery(obj);
  456. if($obj.parents('#pageSizeLayer').size() > 0) return;
  457. doHideWidgetSizeSetup();
  458. if($obj.hasClass('widgetSetup') || $obj.hasClass('widgetStyle') || $obj.hasClass('widgetCopy') || $obj.hasClass('widgetBoxCopy') || $obj.hasClass('widgetSize') || $obj.hasClass('widgetBoxSize') || $obj.hasClass('widgetRemove') || $obj.hasClass('widgetBoxRemove')) return;
  459. p_obj = obj;
  460. while(p_obj) {
  461. var $p_obj = jQuery(p_obj);
  462. if($p_obj.hasClass('widgetOutput') || $p_obj.hasClass('widgetResize') || $p_obj.hasClass('widgetResizeLeft') || $p_obj.hasClass('widgetBoxResize') || $p_obj.hasClass('widgetBoxResizeLeft')) {
  463. widgetDragEnable(p_obj, widgetDragStart, widgetDrag, widgetDragEnd);
  464. widgetMouseDown(e);
  465. return;
  466. }
  467. p_obj = p_obj.parentNode;
  468. }
  469. }
  470. function _getInt(val) {
  471. if(!val || val == "null") return 0;
  472. if(isNaN(parseInt(val, 10))) return 0;
  473. return parseInt(val,10);
  474. }
  475. // 위젯 크기 조절 레이어를 보여줌
  476. var selectedSizeWidget = null;
  477. function doShowWidgetSizeSetup(px, py, obj) {
  478. /*jshint -W004*/
  479. var layer = jQuery('#pageSizeLayer');
  480. var form = layer.find('>form:first');
  481. var $obj = jQuery(obj);
  482. if (!form.length) return;
  483. selectedSizeWidget = obj;
  484. var $selectedSizeWidget = jQuery(selectedSizeWidget);
  485. var opts = {
  486. widget_align : $obj.css('float'),
  487. css_class : ($selectedSizeWidget.attr('css_class')) ? $selectedSizeWidget.attr('css_class') : '',
  488. width : $obj[0].style.width,
  489. height : $obj[0].style.height,
  490. padding_left : _getInt($obj.attr('widget_padding_left')),
  491. padding_right : _getInt($obj.attr('widget_padding_right')),
  492. padding_top : _getInt($obj.attr('widget_padding_top')),
  493. padding_bottom : _getInt($obj.attr('widget_padding_bottom')),
  494. margin_left : _getInt($obj.css('marginLeft')),
  495. margin_right : _getInt($obj.css('marginRight')),
  496. margin_top : _getInt($obj.css('marginTop')),
  497. margin_bottom : _getInt($obj.css('marginBottom')),
  498. border_top_color : transRGB2Hex($obj.css('borderTopColor')),
  499. border_top_thick : $obj.css('borderTopWidth').replace(/px$/i, ''),
  500. border_top_type : $obj.css('borderTopStyle'),
  501. border_bottom_color : transRGB2Hex($obj.css('borderBottomColor')),
  502. border_bottom_thick : $obj.css('borderBottomWidth').replace(/px$/i, ''),
  503. border_bottom_type : $obj.css('borderBottomStyle'),
  504. border_right_color : transRGB2Hex($obj.css('borderRightColor')),
  505. border_right_thick : $obj.css('borderRightWidth').replace(/px$/i, ''),
  506. border_right_type : $obj.css('borderRightStyle'),
  507. border_left_color : transRGB2Hex($obj.css('borderLeftColor')),
  508. border_left_thick : $obj.css('borderLeftWidth').replace(/px$/i, ''),
  509. border_left_type : $obj.css('borderLeftStyle'),
  510. background_color : transRGB2Hex($obj.css('backgroundColor')),
  511. background_image_url : $obj.css('backgroundImage').replace(/^url\(/i,'').replace(/\)$/i,''),
  512. background_x : 0,
  513. background_y : 0,
  514. background_repeat : $obj.css('backgroundRepeat')
  515. };
  516. // background position
  517. var pos = $obj.css('backgroundPosition');
  518. if(pos) {
  519. pos = pos.split(' ');
  520. if(pos.length == 2) {
  521. opts.background_x = pos[0];
  522. opts.background_y = pos[1];
  523. }
  524. }
  525. layer.show();
  526. jQuery(function($){
  527. var $psLayer = $('#pageSizeLayer');
  528. var $backdrop = $('.x_modal-backdrop');
  529. var ww = $(window).width();
  530. var wh = $(window).height();
  531. var pw = $psLayer.width();
  532. var ph = $psLayer.height();
  533. if(ww>pw && wh>ph){
  534. $backdrop.show();
  535. $psLayer.css({
  536. position : 'fixed',
  537. top : wh/2 - ph/2 + 'px',
  538. left : ww/2 - pw/2 + 'px',
  539. width : '700px'
  540. });
  541. }else{
  542. $backdrop.hide();
  543. $psLayer.css({
  544. position : 'static',
  545. top : 'auto',
  546. left : 'auto',
  547. width : 'auto'
  548. });
  549. }
  550. });
  551. jQuery.each(opts, function(key, val){
  552. var el = form[0].elements[key];
  553. var $el = jQuery(el);
  554. if(el) {
  555. $el.val(val);
  556. if($el.hasClass('color-indicator')) {
  557. if(val != 'transparent') {
  558. val = val.toUpperCase();
  559. $el.css('background', '#' + val);
  560. $el.val('#' + val);
  561. }
  562. }
  563. }
  564. if(el.tagName.toLowerCase() == "select") {
  565. if(el.selectedIndex == -1) {
  566. el.selectedIndex = 0;
  567. }
  568. }
  569. });
  570. try { form[0].elements[0].focus(); } catch(e) {}
  571. }
  572. function doHideWidgetSizeSetup() {
  573. jQuery('#pageSizeLayer, .x_modal-backdrop, .jPicker.Container').hide();
  574. }
  575. jQuery(function($){
  576. $(document).keydown(function(e){
  577. var $jpicker = $('.jPicker.Container:visible');
  578. if(e.which == 27 && !$jpicker.length){
  579. doHideWidgetSizeSetup();
  580. return false;
  581. }else if(e.which == 27 && $jpicker.length){
  582. $jpicker.hide();
  583. return false;
  584. }else{
  585. return true;
  586. }
  587. });
  588. });
  589. function _getSize(value) {
  590. if(!value) return 0;
  591. var type = "px";
  592. if(value.lastIndexOf("%")>=0) type = "%";
  593. var num = parseInt(value,10);
  594. if(num<1) return 0;
  595. if(type == "%" && num > 100) num = 100;
  596. return ""+num+type;
  597. }
  598. function _getBorderStyle(fld_color, fld_thick, fld_type) {
  599. var color = fld_color.value;
  600. color = color.replace(/^#/,'');
  601. if(!color) color = '#FFFFFF';
  602. else color = '#'+color;
  603. var width = fld_thick.value;
  604. if(!width) width = '0px';
  605. else width = parseInt(width,10)+'px';
  606. var style = fld_type.options[fld_type.selectedIndex].value;
  607. if(!style) style = 'solid';
  608. var str = color+' '+width+' '+style;
  609. return str;
  610. }
  611. function _getBGColorStyle(fld_color) {
  612. var color = fld_color.replace(/^#/,'');
  613. if(!color) color = '#FFFFFF';
  614. else color = '#'+color;
  615. return color;
  616. }
  617. function doApplyWidgetSize(fo_obj) {
  618. if(selectedSizeWidget) {
  619. if(fo_obj.widget_align.selectedIndex == 1) setFloat(selectedSizeWidget, 'right');
  620. else setFloat(selectedSizeWidget, 'left');
  621. var $form = jQuery(fo_obj);
  622. var $selectedSizeWidget = jQuery(selectedSizeWidget);
  623. var css_class = $form.find('#css_class').val();
  624. if(css_class) $selectedSizeWidget.attr('css_class', css_class);
  625. var width = _getSize(fo_obj.width.value);
  626. if(width) selectedSizeWidget.style.width = width;
  627. var height = _getSize(fo_obj.height.value);
  628. if(height && height != "100%") selectedSizeWidget.style.height = height;
  629. else {
  630. selectedSizeWidget.style.height = '';
  631. var widgetBorder = xGetElementsByClassName('widgetBorder',selectedSizeWidget);
  632. for(var i=0;i<widgetBorder.length;i++) {
  633. var obj = widgetBorder[i];
  634. obj.style.height = '';
  635. }
  636. }
  637. selectedSizeWidget.style.borderTop = _getBorderStyle(fo_obj.border_top_color, fo_obj.border_top_thick, fo_obj.border_top_type);
  638. selectedSizeWidget.style.borderBottom = _getBorderStyle(fo_obj.border_bottom_color, fo_obj.border_bottom_thick, fo_obj.border_bottom_type);
  639. selectedSizeWidget.style.borderLeft = _getBorderStyle(fo_obj.border_left_color, fo_obj.border_left_thick, fo_obj.border_left_type);
  640. selectedSizeWidget.style.borderRight = _getBorderStyle(fo_obj.border_right_color, fo_obj.border_right_thick, fo_obj.border_right_type);
  641. selectedSizeWidget.style.marginTop = _getSize(fo_obj.margin_top.value);
  642. selectedSizeWidget.style.marginRight = _getSize(fo_obj.margin_right.value);
  643. selectedSizeWidget.style.marginBottom = _getSize(fo_obj.margin_bottom.value);
  644. selectedSizeWidget.style.marginLeft = _getSize(fo_obj.margin_left.value);
  645. if(!fo_obj.background_color.value || fo_obj.background_color.value == '#' || fo_obj.background_color.value == 'transparent') selectedSizeWidget.style.backgroundColor = 'transparent';
  646. else selectedSizeWidget.style.backgroundColor = _getBGColorStyle(fo_obj.background_color.value);
  647. var image_url = fo_obj.background_image_url.value;
  648. if(image_url && image_url != 'none') selectedSizeWidget.style.backgroundImage = "url("+image_url+")";
  649. else selectedSizeWidget.style.backgroundImage = 'none';
  650. switch(fo_obj.background_repeat.selectedIndex) {
  651. case 1 : selectedSizeWidget.style.backgroundRepeat = 'no-repeat'; break;
  652. case 2 : selectedSizeWidget.style.backgroundRepeat = 'repeat-x'; break;
  653. case 3 : selectedSizeWidget.style.backgroundRepeat = 'repeat-y'; break;
  654. default : selectedSizeWidget.style.backgroundRepeat = 'repeat'; break;
  655. }
  656. selectedSizeWidget.style.backgroundPosition = fo_obj.background_x.value+' '+fo_obj.background_y.value;
  657. var borderObj = selectedSizeWidget.firstChild;
  658. while(borderObj) {
  659. var $borderObj = jQuery(borderObj);
  660. if(borderObj.nodeName == "DIV" && ($borderObj.hasClass("widgetBorder") || $borderObj.hasClass("widgetBoxBorder"))) {
  661. var contentObj = borderObj.firstChild;
  662. while(contentObj) {
  663. if(contentObj.nodeName == "DIV") {
  664. contentObj.style.padding = "";
  665. var paddingLeft = _getSize(fo_obj.padding_left.value);
  666. if(paddingLeft) {
  667. contentObj.style.paddingLeft = paddingLeft;
  668. selectedSizeWidget.setAttribute('widget_padding_left', paddingLeft);
  669. } else {
  670. contentObj.style.paddingLeft = '';
  671. selectedSizeWidget.setAttribute('widget_padding_left', '');
  672. }
  673. var paddingRight = _getSize(fo_obj.padding_right.value);
  674. if(paddingRight) {
  675. contentObj.style.paddingRight = paddingRight;
  676. selectedSizeWidget.setAttribute('widget_padding_right', paddingRight);
  677. } else {
  678. contentObj.style.paddingRight = '';
  679. selectedSizeWidget.setAttribute('widget_padding_right', '');
  680. }
  681. var paddingTop = _getSize(fo_obj.padding_top.value);
  682. if(paddingTop) {
  683. contentObj.style.paddingTop = paddingTop;
  684. selectedSizeWidget.setAttribute('widget_padding_top', paddingTop);
  685. } else {
  686. contentObj.style.paddingTop = '';
  687. selectedSizeWidget.setAttribute('widget_padding_top', '');
  688. }
  689. var paddingBottom = _getSize(fo_obj.padding_bottom.value);
  690. if(paddingBottom) {
  691. contentObj.style.paddingBottom = paddingBottom;
  692. selectedSizeWidget.setAttribute('widget_padding_bottom', paddingBottom);
  693. } else {
  694. contentObj.style.paddingBottom = '';
  695. selectedSizeWidget.setAttribute('widget_padding_bottom', '');
  696. }
  697. break;
  698. }
  699. contentObj = contentObj.nextSibling;
  700. }
  701. break;
  702. }
  703. borderObj = borderObj.nextSibling;
  704. }
  705. selectedWidget = selectedSizeWidget;
  706. selectedSizeWidget = null;
  707. var widget = selectedWidget.getAttribute("widget");
  708. var params = [];
  709. /*jshint -W004*/
  710. for(var i=0;i<selectedWidget.attributes.length;i++) {
  711. if(!selectedWidget.attributes[i].nodeName || !selectedWidget.attributes[i].nodeValue) continue;
  712. var name = selectedWidget.attributes[i].nodeName.toLowerCase();
  713. if(name == "contenteditable" || name == "id" || name=="src" || name=="widget" || name == "body" || name == "class" || name == "widget_width" || name == "widget_width_type" || name == "xdpx" || name == "xdpy" || name == "height") continue;
  714. var value = selectedWidget.attributes[i].nodeValue;
  715. if(!value || value == "Array") continue;
  716. params[name] = value;
  717. }
  718. params.style = getStyle(selectedWidget);
  719. params.selected_widget = widget;
  720. params.module_srl = get_by_id("pageFo").module_srl.value;
  721. exec_xml('widget','procWidgetGenerateCodeInPage',params,function(ret_obj) { doAddWidgetCode(ret_obj.widget_code); }, ['error','message','widget_code','tpl','css_header']);
  722. }
  723. doHideWidgetSizeSetup();
  724. }
  725. var hideElements = [];
  726. function restoreWidgetButtons() {
  727. var widgetButton = get_by_id('widgetButton');
  728. var boxWidgetButton = get_by_id('widgetBoxButton');
  729. if(!widgetButton || !boxWidgetButton) return;
  730. widgetButton.style.visibility = 'hidden';
  731. get_by_id("zonePageContent").parentNode.appendChild(widgetButton);
  732. boxWidgetButton.style.visibility = 'hidden';
  733. get_by_id("zonePageContent").parentNode.appendChild(boxWidgetButton);
  734. for(var i=0;i<hideElements.length;i++) {
  735. var obj = hideElements[0];
  736. obj.style.paddingTop = 0;
  737. }
  738. hideElements = [];
  739. }
  740. function showWidgetButton(name, obj) {
  741. var widgetButton = get_by_id(name);
  742. if(!widgetButton) return;
  743. widgetButton.style.visibility = 'visible';
  744. obj.insertBefore(widgetButton, obj.firstChild);
  745. }
  746. function widgetSetup(e) {
  747. var obj = e.target;
  748. if(jQuery(obj).is('.widgetButtons') || jQuery(obj).parents('.widgetButtons').size() > 0) return;
  749. if(jQuery(obj).is('.buttonBox') || jQuery(obj).parents('.buttonBox').size() > 0) return;
  750. var o = jQuery(obj).parents('.widgetOutput');
  751. if(o.size() === 0){
  752. restoreWidgetButtons();
  753. return;
  754. }
  755. obj = o.get(0);
  756. var widget = o.attr('widget');
  757. if(!widget) return;
  758. if(widget == 'widgetBox') {
  759. restoreWidgetButtons();
  760. showWidgetButton('widgetBoxButton', obj);
  761. } else {
  762. restoreWidgetButtons();
  763. showWidgetButton('widgetButton', obj);
  764. var p_obj = obj.parentNode;
  765. if(p_obj) {
  766. while(p_obj) {
  767. if(p_obj.nodeName == 'DIV' && p_obj.getAttribute('widget')=='widgetBox') {
  768. showWidgetButton('widgetBoxButton', p_obj);
  769. break;
  770. }
  771. p_obj = p_obj.parentNode;
  772. }
  773. }
  774. }
  775. }
  776. /* 위젯 드래그 */
  777. // 드래그 중이라는 상황을 간직할 변수
  778. var widgetDragManager = {obj:null, isDrag:false};
  779. var widgetTmpObject = [];
  780. var widgetDisappear = 0;
  781. function widgetCreateTmpObject(obj) {
  782. var id = obj.getAttribute('id');
  783. tmpObj = xCreateElement('DIV');
  784. tmpObj.id = id + '_tmp';
  785. tmpObj.className = obj.className;
  786. tmpObj.style.overflow = 'hidden';
  787. tmpObj.style.margin= '0px';
  788. tmpObj.style.padding = '0px';
  789. tmpObj.style.width = obj.style.width;
  790. tmpObj.style.display = 'none';
  791. tmpObj.style.position = 'absolute';
  792. tmpObj.style.opacity = 1;
  793. tmpObj.style.filter = 'alpha(opacity=100)';
  794. xLeft(tmpObj, xPageX(obj));
  795. xTop(tmpObj, xPageY(obj));
  796. document.body.appendChild(tmpObj);
  797. widgetTmpObject[obj.id] = tmpObj;
  798. return tmpObj;
  799. }
  800. // 기생성된 임시 object를 찾아서 return, 없으면 만들어서 return
  801. var idStep = 0;
  802. function widgetGetTmpObject(obj) {
  803. if(!obj.id) obj.id = 'widget_'+idStep++;
  804. var tmpObj = widgetTmpObject[obj.id];
  805. if(!tmpObj) tmpObj = widgetCreateTmpObject(obj);
  806. return tmpObj;
  807. }
  808. // 메뉴에 마우스 클릭이 일어난 시점에 드래그를 위한 제일 첫 동작 (해당 object에 각종 함수나 상태변수 설정)
  809. function widgetDragEnable(obj, funcDragStart, funcDrag, funcDragEnd) {
  810. // 상위 object에 드래그 가능하다는 상태와 각 드래그 관련 함수를 설정
  811. obj.draggable = true;
  812. obj.dragStart = funcDragStart;
  813. obj.drag = funcDrag;
  814. obj.dragEnd = funcDragEnd;
  815. // 드래그 가능하지 않다면 드래그 가능하도록 상태 지정하고 mousemove이벤트 등록
  816. if (!widgetDragManager.isDrag) {
  817. widgetDragManager.isDrag = true;
  818. jQuery(document).on('mousemove', widgetDragMouseMove);
  819. }
  820. }
  821. // 드래그를 시작할때 호출되는 함수 (이동되는 형태를 보여주기 위한 작업을 함)
  822. function widgetDragStart(tobj, px, py) {
  823. var $tobj = jQuery(tobj);
  824. if($tobj.hasClass('widgetResize') || $tobj.hasClass('widgetResizeLeft') || $tobj.hasClass('widgetBoxResize') || $tobj.hasClass('widgetBoxResizeLeft')) return;
  825. var obj = widgetGetTmpObject(tobj);
  826. xInnerHtml(obj, xInnerHtml(tobj));
  827. xLeft(obj, xPageX(tobj));
  828. xTop(obj, xPageY(tobj));
  829. xWidth(obj, xWidth(tobj));
  830. xHeight(obj, xHeight(tobj));
  831. xDisplay(obj, 'block');
  832. }
  833. // 드래그 시작후 마우스를 이동할때 발생되는 이벤트에 의해 실행되는 함수
  834. function widgetDrag(tobj, dx, dy) {
  835. var $tobj = jQuery(tobj);
  836. var minWidth = 40;
  837. var minHeight = 10;
  838. var sx = xPageX(tobj.parentNode);
  839. var sy = xPageY(tobj.parentNode);
  840. var nx = tobj.xDPX;
  841. var ny = tobj.xDPY;
  842. var zoneWidth = xWidth(zonePageObj);
  843. var zoneLeft = xPageX(zonePageObj);
  844. var zoneRight = zoneLeft + zoneWidth;
  845. var pWidth = xWidth(tobj.parentNode);
  846. var cssFloat = getFloat(tobj.parentNode);
  847. if(!cssFloat) cssFloat = 'left';
  848. // 위젯 리사이즈 (우측)
  849. if($tobj.hasClass('widgetResize') || $tobj.hasClass('widgetBoxResize')) {
  850. if(nx < sx+minWidth) nx = sx+minWidth;
  851. if(nx > zoneRight) nx = zoneRight;
  852. if(cssFloat == 'right') nx = sx + pWidth;
  853. var new_width = nx - sx;
  854. if(new_width < minWidth) new_width = minWidth;
  855. var new_height = ny - sy;
  856. if(new_height < minHeight) new_height = minHeight;
  857. if(zoneRight < sx+new_width) new_width = zoneRight - sx;
  858. xWidth(tobj.parentNode, new_width);
  859. xHeight(tobj.parentNode, new_height);
  860. // 위젯 리사이즈 (좌측)
  861. } else if($tobj.hasClass('widgetResizeLeft') || $tobj.hasClass('widgetBoxResizeLeft')) {
  862. /*jshint -W004*/
  863. if(nx < zoneLeft) nx = zoneLeft;
  864. if(cssFloat == 'left') nx = sx;
  865. var new_width = pWidth + (sx - nx);
  866. if(new_width < minWidth) new_width = minWidth;
  867. var new_height = ny - sy;
  868. if(new_height < minHeight) new_height = minHeight;
  869. xWidth(tobj.parentNode, new_width);
  870. xHeight(tobj.parentNode, new_height);
  871. // 위젯 드래그
  872. } else {
  873. var obj = widgetGetTmpObject(tobj);
  874. xLeft(obj, parseInt(xPageX(obj),10) + parseInt(dx,10));
  875. xTop(obj, parseInt(xPageY(obj),10) + parseInt(dy,10));
  876. // 박스 안에 있을 경우에는 박스내의 위젯하고 자리를 바꾸고 그 외의 경우에는 박스를 빠져 나간다
  877. if(tobj.parentNode != zonePageObj) {
  878. // 박스내에 있는 위젯들을 구함
  879. var widgetList = xGetElementsByClassName("widgetOutput",tobj.parentNode);
  880. for(var i=0;i<widgetList.length;i++) {
  881. var target_obj = widgetList[i];
  882. var l = xPageX(target_obj);
  883. var t = xPageY(target_obj);
  884. var ll = parseInt(l,10) + parseInt(xWidth(target_obj),10);
  885. var tt = parseInt(t,10) + parseInt(xHeight(target_obj),10);
  886. if( tobj != target_obj && tobj.xDPX >= l && tobj.xDPX <= ll && tobj.xDPY >= t && tobj.xDPY <= tt && tobj.parentNode == target_obj.parentNode) {
  887. var next1 = target_obj.nextSibling;
  888. if(!next1) {
  889. next1 = xCreateElement("DIV");
  890. target_obj.parentNode.appendChild(next1);
  891. }
  892. var next2 = tobj.nextSibling;
  893. if(!next2) {
  894. next2 = xCreateElement("DIV");
  895. tobj.parentNode.appendChild(next2);
  896. }
  897. if(next1) next1.parentNode.insertBefore(tobj, next1);
  898. if(next2) next2.parentNode.insertBefore(target_obj, next2);
  899. widgetList = null;
  900. return;
  901. }
  902. }
  903. widgetList = null;
  904. // 만약 다른 위젯과 자리를 바꾸지 못하였는데 자기 부모창밖에 있는게 확인이 되면 박스 밖으로 내보낸다.
  905. var p_tobj = jQuery(tobj).parents('div.nullWidget').get(0);
  906. var l = xPageX(p_tobj);
  907. var t = xPageY(p_tobj);
  908. var ll = parseInt(l,10) + parseInt(xWidth(p_tobj),10);
  909. var tt = parseInt(t,10) + parseInt(xHeight(p_tobj),10);
  910. if( (tobj.xDPX < l || tobj.xDPX > ll) || (tobj.xDPY < t || tobj.xDPY > tt) ) {
  911. zonePageObj.insertBefore(tobj, jQuery(tobj).parents('div.widgetOutput[widget=widgetBox]').get(0));
  912. return;
  913. }
  914. // 박스 밖에 있을 경우에는 다른 위젯과 자리를 바꾸거나 박스내에 들어가도록 한다
  915. } else {
  916. // 이동하려는 위젯이 박스 위젯이 아니라면 박스 위젯들을 구해서 입력 유무를 검사한다
  917. if(tobj.getAttribute("widget")!="widgetBox") {
  918. var boxList = xGetElementsByClassName("nullWidget", zonePageObj);
  919. for(var i=0;i<boxList.length;i++) {
  920. var target_obj = boxList[i];
  921. var $target_obj = jQuery(target_obj);
  922. xHeight(target_obj, xHeight(target_obj.parentNode));
  923. xWidth(target_obj, xWidth(target_obj.parentNode));
  924. var l = xPageX(target_obj);
  925. var t = xPageY(target_obj);
  926. var ll = parseInt(l,10) + parseInt(xWidth(target_obj),10);
  927. var tt = parseInt(t,10) + parseInt(xHeight(target_obj),10);
  928. if( tobj.xDPX >= l && tobj.xDPX <= ll && tobj.xDPY >= t && tobj.xDPY <= tt) {
  929. //박스 위젯이다
  930. if($target_obj.hasClass("nullWidget")) {
  931. var wb_ws = jQuery('div.widget_inner', $target_obj);
  932. //박스 위젯에 위젯스타일이 적용 안된경우
  933. if(wb_ws.size() === 0){
  934. target_obj.appendChild(tobj);
  935. //박스 위젯에 위젯스타일이 적용된경우 또는 박스안에 위젯이 위젯스타일이 적용된겅우
  936. }else{
  937. wb_ws.get(0).appendChild(tobj);
  938. }
  939. // 이동을 멈춤
  940. widgetManualEnd();
  941. boxList = null;
  942. return;
  943. }
  944. }
  945. }
  946. boxList = null;
  947. }
  948. // 다른 위젯들을 구해서 자리를 바꿈
  949. var widgetList = xGetElementsByClassName("widgetOutput",zonePageObj);
  950. for(var i=0;i<widgetList.length;i++) {
  951. var target_obj = widgetList[i];
  952. var widget = target_obj.getAttribute("widget");
  953. if(widget == 'widgetBox' || target_obj.parentNode != zonePageObj) continue;
  954. var l = xPageX(target_obj);
  955. var t = xPageY(target_obj);
  956. var ll = parseInt(l,10) + parseInt(xWidth(target_obj),10);
  957. var tt = parseInt(t,10) + parseInt(xHeight(target_obj),10);
  958. if( tobj != target_obj && tobj.xDPX >= l && tobj.xDPX <= ll && tobj.xDPY >= t && tobj.xDPY <= tt && tobj.parentNode == target_obj.parentNode) {
  959. var next1 = target_obj.nextSibling;
  960. if(!next1) next1 = target_obj.parentNode.lastChild;
  961. if(!next1) {
  962. next1 = xCreateElement("DIV");
  963. target_obj.parentNode.appendChild(next1);
  964. }
  965. var next2 = tobj.nextSibling;
  966. if(!next2) {
  967. next2 = xCreateElement("DIV");
  968. tobj.parentNode.appendChild(next2);
  969. }
  970. if(next1) next1.parentNode.insertBefore(tobj, next1);
  971. if(next2) next2.parentNode.insertBefore(target_obj, next2);
  972. widgetList = null;
  973. return;
  974. }
  975. }
  976. widgetList = null;
  977. }
  978. }
  979. }
  980. // 드래그 종료 (이동되는 object가 이동할 곳에 서서히 이동되는 것처럼 보이는 효과)
  981. function widgetDragEnd(tobj, px, py) {
  982. var obj = widgetGetTmpObject(tobj);
  983. widgetDisapear = widgetDisapearObject(obj, tobj);
  984. widgetDragDisable(tobj.getAttribute('id'));
  985. }
  986. // 스르르 사라지게 함 (일단 사라지게 하는 기능을 제거.. 속도 문제)
  987. function widgetDisapearObject(obj, tobj) {
  988. xInnerHtml(tobj,xInnerHtml(obj));
  989. xInnerHtml(obj,'');
  990. jQuery(obj).hide();
  991. obj.parentNode.removeChild(obj);
  992. widgetTmpObject[tobj.id] = null;
  993. return;
  994. }
  995. // 마우스다운 이벤트 발생시 호출됨
  996. function widgetMouseDown(e) {
  997. var obj = e.target;
  998. while(obj && !obj.draggable) {
  999. obj = xParent(obj, true);
  1000. }
  1001. if(obj) {
  1002. e.preventDefault();
  1003. obj.xDPX = e.pageX;
  1004. obj.xDPY = e.pageY;
  1005. widgetDragManager.obj = obj;
  1006. jQuery(document).on('mouseup', widgetMouseUp);
  1007. if (obj.dragStart) obj.dragStart(obj, e.pageX, e.pageY);
  1008. }
  1009. }
  1010. // 마우스 버튼을 놓았을때 동작될 함수 (각종 이벤트 해제 및 변수 설정 초기화)
  1011. function widgetMouseUp(e) {
  1012. if (widgetDragManager.obj) {
  1013. e.preventDefault();
  1014. jQuery(document).off('mouseup', widgetMouseUp);
  1015. if (widgetDragManager.obj.dragEnd) {
  1016. widgetDragManager.obj.dragEnd(widgetDragManager.obj, e.pageX, e.pageY);
  1017. }
  1018. widgetDragManager.obj = null;
  1019. widgetDragManager.isDrag = false;
  1020. }
  1021. }
  1022. // 드래그할때의 object이동등을 담당
  1023. function widgetDragMouseMove(e) {
  1024. if(widgetDragManager.obj) {
  1025. e.preventDefault();
  1026. var obj = widgetDragManager.obj;
  1027. var dx = e.pageX - obj.xDPX;
  1028. var dy = e.pageY - obj.xDPY;
  1029. obj.xDPX = e.pageX;
  1030. obj.xDPY = e.pageY;
  1031. if (obj.drag) {
  1032. obj.drag(obj, dx, dy);
  1033. } else {
  1034. xMoveTo(obj, xLeft(obj) + dx, xTop(obj) + dy);
  1035. }
  1036. }
  1037. }
  1038. // 해당 object 에 더 이상 drag가 되지 않도록 설정
  1039. function widgetDragDisable(id) {
  1040. if (!widgetDragManager) return;
  1041. var obj = get_by_id(id);
  1042. obj.draggable = false;
  1043. obj.dragStart = null;
  1044. obj.drag = null;
  1045. obj.dragEnd = null;
  1046. jQuery(obj).off('mousedown', widgetMouseDown);
  1047. return;
  1048. }
  1049. // 강제로 드래그를 종료시킴
  1050. function widgetManualEnd() {
  1051. var tobj = widgetDragManager.obj;
  1052. if(!tobj) return;
  1053. jQuery(document).off('mouseup', widgetMouseUp);
  1054. jQuery(document).on('mousemove', widgetDragMouseMove);
  1055. var obj = widgetGetTmpObject(tobj);
  1056. widgetDisapear = widgetDisapearObject(obj, tobj);
  1057. widgetDragDisable(tobj.getAttribute('id'));
  1058. widgetDragManager.obj = null;
  1059. widgetDragManager.isDrag = false;
  1060. }