You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22478 lines
740 KiB

7 years ago
  1. /*
  2. Copyright (C) NAVER corp.
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with this library; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  14. */
  15. if(typeof window.nhn=='undefined'){window.nhn = {};}
  16. if (!nhn.husky){nhn.husky = {};}
  17. /**
  18. * @fileOverview This file contains Husky framework core
  19. * @name HuskyCore.js
  20. */
  21. (function(){
  22. var _rxMsgHandler = /^\$(LOCAL|BEFORE|ON|AFTER)_/,
  23. _rxMsgAppReady = /^\$(BEFORE|ON|AFTER)_MSG_APP_READY$/,
  24. _aHuskyCores = [], // HuskyCore instance list
  25. _htLoadedFile = {}; // lazy-loaded file list
  26. nhn.husky.HuskyCore = jindo.$Class({
  27. name : "HuskyCore",
  28. aCallerStack : null,
  29. bMobile : jindo.$Agent().navigator().mobile || jindo.$Agent().navigator().msafari,
  30. $init : function(htOptions){
  31. this.htOptions = htOptions||{};
  32. _aHuskyCores.push(this);
  33. if( this.htOptions.oDebugger ){
  34. nhn.husky.HuskyCore.getCore = function() {
  35. return _aHuskyCores;
  36. };
  37. this.htOptions.oDebugger.setApp(this);
  38. }
  39. // To prevent processing a Husky message before all the plugins are registered and ready,
  40. // Queue up all the messages here until the application's status is changed to READY
  41. this.messageQueue = [];
  42. this.oMessageMap = {};
  43. this.oDisabledMessage = {};
  44. this.oLazyMessage = {};
  45. this.aPlugins = [];
  46. this.appStatus = nhn.husky.APP_STATUS.NOT_READY;
  47. this.aCallerStack = [];
  48. this._fnWaitForPluginReady = jindo.$Fn(this._waitForPluginReady, this).bind();
  49. // Register the core as a plugin so it can receive messages
  50. this.registerPlugin(this);
  51. },
  52. setDebugger: function(oDebugger) {
  53. this.htOptions.oDebugger = oDebugger;
  54. oDebugger.setApp(this);
  55. },
  56. exec : function(msg, args, oEvent){
  57. // If the application is not yet ready just queue the message
  58. if(this.appStatus == nhn.husky.APP_STATUS.NOT_READY){
  59. this.messageQueue[this.messageQueue.length] = {'msg':msg, 'args':args, 'event':oEvent};
  60. return true;
  61. }
  62. this.exec = this._exec;
  63. this.exec(msg, args, oEvent);
  64. },
  65. delayedExec : function(msg, args, nDelay, oEvent){
  66. var fExec = jindo.$Fn(this.exec, this).bind(msg, args, oEvent);
  67. setTimeout(fExec, nDelay);
  68. },
  69. _exec : function(msg, args, oEvent){
  70. return (this._exec = this.htOptions.oDebugger?this._execWithDebugger:this._execWithoutDebugger).call(this, msg, args, oEvent);
  71. },
  72. _execWithDebugger : function(msg, args, oEvent){
  73. this.htOptions.oDebugger.log_MessageStart(msg, args);
  74. var bResult = this._doExec(msg, args, oEvent);
  75. this.htOptions.oDebugger.log_MessageEnd(msg, args);
  76. return bResult;
  77. },
  78. _execWithoutDebugger : function(msg, args, oEvent){
  79. return this._doExec(msg, args, oEvent);
  80. },
  81. _doExec : function(msg, args, oEvent){
  82. var bContinue = false;
  83. // Lazy메시지가 있으면 파일을 로딩한다.
  84. if(this.oLazyMessage[msg]){
  85. var htLazyInfo = this.oLazyMessage[msg];
  86. this._loadLazyFiles(msg, args, oEvent, htLazyInfo.aFilenames, 0);
  87. return false;
  88. }
  89. if(!this.oDisabledMessage[msg]){
  90. var allArgs = [];
  91. if(args && args.length){
  92. var iLen = args.length;
  93. for(var i=0; i<iLen; i++){allArgs[i] = args[i];}
  94. }
  95. if(oEvent){allArgs[allArgs.length] = oEvent;}
  96. bContinue = this._execMsgStep("BEFORE", msg, allArgs);
  97. if(bContinue){bContinue = this._execMsgStep("ON", msg, allArgs);}
  98. if(bContinue){bContinue = this._execMsgStep("AFTER", msg, allArgs);}
  99. }
  100. return bContinue;
  101. },
  102. registerPlugin : function(oPlugin){
  103. if(!oPlugin){throw("An error occured in registerPlugin(): invalid plug-in");}
  104. oPlugin.nIdx = this.aPlugins.length;
  105. oPlugin.oApp = this;
  106. this.aPlugins[oPlugin.nIdx] = oPlugin;
  107. // If the plugin does not specify that it takes time to be ready, change the stauts to READY right away
  108. if(oPlugin.status != nhn.husky.PLUGIN_STATUS.NOT_READY){oPlugin.status = nhn.husky.PLUGIN_STATUS.READY;}
  109. // If run() function had been called already, need to recreate the message map
  110. if(this.appStatus != nhn.husky.APP_STATUS.NOT_READY){
  111. for(var funcName in oPlugin){
  112. if(_rxMsgHandler.test(funcName)){
  113. this.addToMessageMap(funcName, oPlugin);
  114. }
  115. }
  116. }
  117. this.exec("MSG_PLUGIN_REGISTERED", [oPlugin]);
  118. return oPlugin.nIdx;
  119. },
  120. disableMessage : function(sMessage, bDisable){this.oDisabledMessage[sMessage] = bDisable;},
  121. registerBrowserEvent : function(obj, sEvent, sMessage, aParams, nDelay){
  122. aParams = aParams || [];
  123. var func = (nDelay)?jindo.$Fn(this.delayedExec, this).bind(sMessage, aParams, nDelay):jindo.$Fn(this.exec, this).bind(sMessage, aParams);
  124. return jindo.$Fn(func, this).attach(obj, sEvent);
  125. },
  126. run : function(htOptions){
  127. this.htRunOptions = htOptions || {};
  128. // Change the status from NOT_READY to let exec to process all the way
  129. this._changeAppStatus(nhn.husky.APP_STATUS.WAITING_FOR_PLUGINS_READY);
  130. // Process all the messages in the queue
  131. var iQueueLength = this.messageQueue.length;
  132. for(var i=0; i<iQueueLength; i++){
  133. var curMsgAndArgs = this.messageQueue[i];
  134. this.exec(curMsgAndArgs.msg, curMsgAndArgs.args, curMsgAndArgs.event);
  135. }
  136. this._fnWaitForPluginReady();
  137. },
  138. acceptLocalBeforeFirstAgain : function(oPlugin, bAccept){
  139. // LOCAL_BEFORE_FIRST will be fired again if oPlugin._husky_bRun == false
  140. oPlugin._husky_bRun = !bAccept;
  141. },
  142. // Use this also to update the mapping
  143. createMessageMap : function(sMsgHandler){
  144. this.oMessageMap[sMsgHandler] = [];
  145. var nLen = this.aPlugins.length;
  146. for(var i=0; i<nLen; i++){this._doAddToMessageMap(sMsgHandler, this.aPlugins[i]);}
  147. },
  148. addToMessageMap : function(sMsgHandler, oPlugin){
  149. // cannot "ADD" unless the map is already created.
  150. // the message will be added automatically to the mapping when it is first passed anyways, so do not add now
  151. if(!this.oMessageMap[sMsgHandler]){return;}
  152. this._doAddToMessageMap(sMsgHandler, oPlugin);
  153. },
  154. _changeAppStatus : function(appStatus){
  155. this.appStatus = appStatus;
  156. // Initiate MSG_APP_READY if the application's status is being switched to READY
  157. if(this.appStatus == nhn.husky.APP_STATUS.READY){this.exec("MSG_APP_READY");}
  158. },
  159. _execMsgStep : function(sMsgStep, sMsg, args){
  160. return (this._execMsgStep = this.htOptions.oDebugger?this._execMsgStepWithDebugger:this._execMsgStepWithoutDebugger).call(this, sMsgStep, sMsg, args);
  161. },
  162. _execMsgStepWithDebugger : function(sMsgStep, sMsg, args){
  163. this.htOptions.oDebugger.log_MessageStepStart(sMsgStep, sMsg, args);
  164. var bStatus = this._execMsgHandler("$"+sMsgStep+"_"+sMsg, args);
  165. this.htOptions.oDebugger.log_MessageStepEnd(sMsgStep, sMsg, args);
  166. return bStatus;
  167. },
  168. _execMsgStepWithoutDebugger : function(sMsgStep, sMsg, args){
  169. return this._execMsgHandler ("$"+sMsgStep+"_"+sMsg, args);
  170. },
  171. _execMsgHandler : function(sMsgHandler, args){
  172. var i;
  173. if(!this.oMessageMap[sMsgHandler]){
  174. this.createMessageMap(sMsgHandler);
  175. }
  176. var aPlugins = this.oMessageMap[sMsgHandler];
  177. var iNumOfPlugins = aPlugins.length;
  178. if(iNumOfPlugins === 0){return true;}
  179. var bResult = true;
  180. // two similar codes were written twice due to the performace.
  181. if(_rxMsgAppReady.test(sMsgHandler)){
  182. for(i=0; i<iNumOfPlugins; i++){
  183. if(this._execHandler(aPlugins[i], sMsgHandler, args) === false){
  184. bResult = false;
  185. break;
  186. }
  187. }
  188. }else{
  189. for(i=0; i<iNumOfPlugins; i++){
  190. if(!aPlugins[i]._husky_bRun){
  191. aPlugins[i]._husky_bRun = true;
  192. if(typeof aPlugins[i].$LOCAL_BEFORE_FIRST == "function" && this._execHandler(aPlugins[i], "$LOCAL_BEFORE_FIRST", [sMsgHandler, args]) === false){continue;}
  193. }
  194. if(typeof aPlugins[i].$LOCAL_BEFORE_ALL == "function"){
  195. if(this._execHandler(aPlugins[i], "$LOCAL_BEFORE_ALL", [sMsgHandler, args]) === false){continue;}
  196. }
  197. if(this._execHandler(aPlugins[i], sMsgHandler, args) === false){
  198. bResult = false;
  199. break;
  200. }
  201. }
  202. }
  203. return bResult;
  204. },
  205. _execHandler : function(oPlugin, sHandler, args){
  206. return (this._execHandler = this.htOptions.oDebugger?this._execHandlerWithDebugger:this._execHandlerWithoutDebugger).call(this, oPlugin, sHandler, args);
  207. },
  208. _execHandlerWithDebugger : function(oPlugin, sHandler, args){
  209. this.htOptions.oDebugger.log_CallHandlerStart(oPlugin, sHandler, args);
  210. var bResult;
  211. try{
  212. this.aCallerStack.push(oPlugin);
  213. bResult = oPlugin[sHandler].apply(oPlugin, args);
  214. this.aCallerStack.pop();
  215. }catch(e){
  216. this.htOptions.oDebugger.handleException(e);
  217. bResult = false;
  218. }
  219. this.htOptions.oDebugger.log_CallHandlerEnd(oPlugin, sHandler, args);
  220. return bResult;
  221. },
  222. _execHandlerWithoutDebugger : function(oPlugin, sHandler, args){
  223. this.aCallerStack.push(oPlugin);
  224. var bResult = oPlugin[sHandler].apply(oPlugin, args);
  225. this.aCallerStack.pop();
  226. return bResult;
  227. },
  228. _doAddToMessageMap : function(sMsgHandler, oPlugin){
  229. if(typeof oPlugin[sMsgHandler] != "function"){return;}
  230. var aMap = this.oMessageMap[sMsgHandler];
  231. // do not add if the plugin is already in the mapping
  232. for(var i=0, iLen=aMap.length; i<iLen; i++){
  233. if(this.oMessageMap[sMsgHandler][i] == oPlugin){return;}
  234. }
  235. this.oMessageMap[sMsgHandler][i] = oPlugin;
  236. },
  237. _waitForPluginReady : function(){
  238. var bAllReady = true;
  239. for(var i=0; i<this.aPlugins.length; i++){
  240. if(this.aPlugins[i].status == nhn.husky.PLUGIN_STATUS.NOT_READY){
  241. bAllReady = false;
  242. break;
  243. }
  244. }
  245. if(bAllReady){
  246. this._changeAppStatus(nhn.husky.APP_STATUS.READY);
  247. }else{
  248. setTimeout(this._fnWaitForPluginReady, 100);
  249. }
  250. },
  251. /**
  252. * Lazy로딩을 실행한다.
  253. * @param {Object} oPlugin 플러그인 인스턴스
  254. * @param {String} sMsg 메시지명
  255. * @param {Array} aArgs 메시지에 전달되는 매개변수
  256. * @param {Event} oEvent 메시지에 전달되는 이벤트
  257. * @param {Array} aFilenames Lazy로딩할 파일명
  258. * @param {Integer} nIdx 로딩할 파일인덱스
  259. */
  260. _loadLazyFiles : function(sMsg, aArgs, oEvent, aFilenames, nIdx){
  261. var nLen = aFilenames.length;
  262. if(nLen <= nIdx){
  263. // 파일이 모두 로딩된 상태라면 oLazyMessage 에서 정보를 제거하고 메시지를 실행한다.
  264. this.oLazyMessage[sMsg] = null;
  265. this.oApp.exec(sMsg, aArgs, oEvent);
  266. return;
  267. }
  268. var sFilename = aFilenames[nIdx];
  269. if(_htLoadedFile[sFilename]){
  270. // 파일이 이미 로딩된 경우 다음 파일을 로딩한다.
  271. this._loadLazyFiles(sMsg, aArgs, oEvent, aFilenames, nIdx+1);
  272. }else{
  273. // 파일을 Lazy로딩한다.
  274. // TODO: 진도컴포넌트 디펜던시 제거?
  275. // TODO: 응답결과가 정상적이지 않을 경우에 대한 처리?
  276. jindo.LazyLoading.load(nhn.husky.SE2M_Configuration.LazyLoad.sJsBaseURI+"/"+sFilename,
  277. jindo.$Fn(function(sMsg, aArgs, oEvent, aFilenames, nIdx){
  278. // 로딩완료된 파일은 상태를 변경하고
  279. var sFilename = aFilenames[nIdx];
  280. _htLoadedFile[sFilename] = 1;
  281. // 다음 파일을 로딩한다.
  282. this._loadLazyFiles(sMsg, aArgs, oEvent, aFilenames, nIdx+1);
  283. }, this).bind(sMsg, aArgs, oEvent, aFilenames, nIdx),
  284. "utf-8"
  285. );
  286. }
  287. },
  288. /**
  289. * Lazy로딩으로 처리할 메시지를 등록한다.
  290. * @param {Array} aMsgs 메시지명
  291. * @param {Array} aFilenames Lazy로딩할 파일명
  292. */
  293. registerLazyMessage : function(aMsgs, aFilenames){
  294. aMsgs = aMsgs || [];
  295. aFilenames = aFilenames || [];
  296. for(var i = 0, sMsg, htLazyInfo; (sMsg = aMsgs[i]); i++){
  297. htLazyInfo = this.oLazyMessage[sMsg];
  298. if(htLazyInfo){
  299. htLazyInfo.aFilenames = htLazyInfo.aFilenames.concat(aFilenames);
  300. }else{
  301. this.oLazyMessage[sMsg] = {
  302. sMsg : sMsg,
  303. aFilenames : aFilenames
  304. };
  305. }
  306. }
  307. }
  308. });
  309. /**
  310. * Lazy로딩완료된 파일목록
  311. */
  312. nhn.husky.HuskyCore._htLoadedFile = {};
  313. /**
  314. * Lazy로딩완료된 파일목록에 파일명을 추가한다.
  315. * @param {String} sFilename Lazy로딩완료될 경우 마킹할 파일명
  316. */
  317. nhn.husky.HuskyCore.addLoadedFile = function(sFilename){
  318. _htLoadedFile[sFilename] = 1;
  319. };
  320. /**
  321. * 플러그인 일부분을 Lazy로딩하여 쉽게 확장할 있도록 믹스인 기능을 제공한다.
  322. * @param {Class} oClass 믹스인을 적용할 클래스
  323. * @param {Object} htMixin 덧붙일 프로토타입 데이터
  324. * @param {Boolean} bOverride 원본 클래스에 프로토타입을 덮어씌울지 여부
  325. */
  326. nhn.husky.HuskyCore.mixin = function(oClass, htMixin, bOverride, sFilename){
  327. //TODO: error handling?
  328. // if(typeof oClass != "function"){
  329. // throw new Error("SmartEditor: can't mixin (oClass is invalid)");
  330. // }
  331. var aPlugins = [];
  332. // 믹스인을 적용할 클래스가 이미 플러그인으로 등록된 상태라면
  333. for(var i = 0, oHuskyCore; (oHuskyCore = _aHuskyCores[i]); i++){
  334. for(var j = 0, oPlugin; (oPlugin = oHuskyCore.aPlugins[j]); j++){
  335. if(oPlugin instanceof oClass){
  336. // 1. 메시지 추가등록을 위해 해당 플러그인 인스턴스를 담아두고
  337. aPlugins.push(oPlugin);
  338. // 2. 해당 플러그인 인스턴스에 $LOCAL_BEFORE_FIRST 핸들러가 없으면 핸들러처리를 위한 플래그를 리셋한다.
  339. // if there were no $LOCAL_BEFORE_FIRST in already-loaded script, set to accept $LOCAL_BEFORE_FIRST next time as the function could be included in the lazy-loaded script.
  340. if(typeof oPlugin["$LOCAL_BEFORE_FIRST"] !== "function"){
  341. oPlugin.oApp.acceptLocalBeforeFirstAgain(oPlugin, true);
  342. }
  343. }else if(oPlugin._$superClass === oClass){
  344. // [SMARTEDITORSUS-1697]
  345. // jindo 클래스를 상속받아 확장된 클래스의 경우,
  346. // 1. instanceof 로 확인이 안되며
  347. // 2. super 클래스에 mixin 처리한 것이 반영이 안된다.
  348. // 따라서 상속된 jindo 클래스의 인스턴스는 인스턴스에 직접 mixin 처리한다.
  349. if(typeof oPlugin["$LOCAL_BEFORE_FIRST"] !== "function"){
  350. oPlugin.oApp.acceptLocalBeforeFirstAgain(oPlugin, true);
  351. }
  352. for(var k in htMixin){
  353. if(bOverride || !oPlugin.hasOwnProperty(k)){
  354. oPlugin[k] = htMixin[k];
  355. if(_rxMsgHandler.test(k)){
  356. oPlugin.oApp.addToMessageMap(k, oPlugin);
  357. }
  358. }
  359. }
  360. }
  361. }
  362. }
  363. // mixin 처리
  364. for(var k in htMixin){
  365. if(bOverride || !oClass.prototype.hasOwnProperty(k)){
  366. oClass.prototype[k] = htMixin[k];
  367. // 새로 추가되는 함수가 메시지 핸들러라면 메시지 매핑에 추가 해준다.
  368. if(_rxMsgHandler.test(k)){
  369. for(var j = 0, oPlugin; (oPlugin = aPlugins[j]); j++){
  370. oPlugin.oApp.addToMessageMap(k, oPlugin);
  371. }
  372. }
  373. }
  374. }
  375. };
  376. nhn.husky.APP_STATUS = {
  377. 'NOT_READY' : 0,
  378. 'WAITING_FOR_PLUGINS_READY' : 1,
  379. 'READY' : 2
  380. };
  381. nhn.husky.PLUGIN_STATUS = {
  382. 'NOT_READY' : 0,
  383. 'READY' : 1
  384. };
  385. })();
  386. if(typeof window.nhn=='undefined'){window.nhn = {};}
  387. nhn.CurrentSelection_IE = function(){
  388. this.getCommonAncestorContainer = function(){
  389. try{
  390. this._oSelection = this._document.selection;
  391. if(this._oSelection.type == "Control"){
  392. return this._oSelection.createRange().item(0);
  393. }else{
  394. return this._oSelection.createRangeCollection().item(0).parentElement();
  395. }
  396. }catch(e){
  397. return this._document.body;
  398. }
  399. };
  400. this.isCollapsed = function(){
  401. this._oSelection = this._document.selection;
  402. return this._oSelection.type == "None";
  403. };
  404. };
  405. nhn.CurrentSelection_FF = function(){
  406. this.getCommonAncestorContainer = function(){
  407. return this._getSelection().commonAncestorContainer;
  408. };
  409. this.isCollapsed = function(){
  410. var oSelection = this._window.getSelection();
  411. if(oSelection.rangeCount<1){ return true; }
  412. return oSelection.getRangeAt(0).collapsed;
  413. };
  414. this._getSelection = function(){
  415. try{
  416. return this._window.getSelection().getRangeAt(0);
  417. }catch(e){
  418. return this._document.createRange();
  419. }
  420. };
  421. };
  422. nhn.CurrentSelection = new (jindo.$Class({
  423. $init : function(){
  424. var oAgentInfo = jindo.$Agent().navigator();
  425. if(oAgentInfo.ie && document.selection){
  426. nhn.CurrentSelection_IE.apply(this);
  427. }else{
  428. nhn.CurrentSelection_FF.apply(this);
  429. }
  430. },
  431. setWindow : function(oWin){
  432. this._window = oWin;
  433. this._document = oWin.document;
  434. }
  435. }))();
  436. /**
  437. * @fileOverview This file contains a cross-browser implementation of W3C's DOM Range
  438. * @name W3CDOMRange.js
  439. */
  440. nhn.W3CDOMRange = jindo.$Class({
  441. $init : function(win){
  442. this.reset(win);
  443. },
  444. reset : function(win){
  445. this._window = win;
  446. this._document = this._window.document;
  447. this.collapsed = true;
  448. this.commonAncestorContainer = this._document.body;
  449. this.endContainer = this._document.body;
  450. this.endOffset = 0;
  451. this.startContainer = this._document.body;
  452. this.startOffset = 0;
  453. this.oBrowserSelection = new nhn.BrowserSelection(this._window);
  454. this.selectionLoaded = this.oBrowserSelection.selectionLoaded;
  455. },
  456. cloneContents : function(){
  457. var oClonedContents = this._document.createDocumentFragment();
  458. var oTmpContainer = this._document.createDocumentFragment();
  459. var aNodes = this._getNodesInRange();
  460. if(aNodes.length < 1){return oClonedContents;}
  461. var oClonedContainers = this._constructClonedTree(aNodes, oTmpContainer);
  462. // oTopContainer = aNodes[aNodes.length-1].parentNode and this is not part of the initial array and only those child nodes should be cloned
  463. var oTopContainer = oTmpContainer.firstChild;
  464. if(oTopContainer){
  465. var elCurNode = oTopContainer.firstChild;
  466. var elNextNode;
  467. while(elCurNode){
  468. elNextNode = elCurNode.nextSibling;
  469. oClonedContents.appendChild(elCurNode);
  470. elCurNode = elNextNode;
  471. }
  472. }
  473. oClonedContainers = this._splitTextEndNodes({oStartContainer: oClonedContainers.oStartContainer, iStartOffset: this.startOffset,
  474. oEndContainer: oClonedContainers.oEndContainer, iEndOffset: this.endOffset});
  475. if(oClonedContainers.oStartContainer && oClonedContainers.oStartContainer.previousSibling){
  476. nhn.DOMFix.parentNode(oClonedContainers.oStartContainer).removeChild(oClonedContainers.oStartContainer.previousSibling);
  477. }
  478. if(oClonedContainers.oEndContainer && oClonedContainers.oEndContainer.nextSibling){
  479. nhn.DOMFix.parentNode(oClonedContainers.oEndContainer).removeChild(oClonedContainers.oEndContainer.nextSibling);
  480. }
  481. return oClonedContents;
  482. },
  483. _constructClonedTree : function(aNodes, oClonedParentNode){
  484. var oClonedStartContainer = null;
  485. var oClonedEndContainer = null;
  486. var oStartContainer = this.startContainer;
  487. var oEndContainer = this.endContainer;
  488. var _recurConstructClonedTree = function(aAllNodes, iCurIdx, oClonedParentNode){
  489. if(iCurIdx < 0){return iCurIdx;}
  490. var iChildIdx = iCurIdx-1;
  491. var oCurNodeCloneWithChildren = aAllNodes[iCurIdx].cloneNode(false);
  492. if(aAllNodes[iCurIdx] == oStartContainer){oClonedStartContainer = oCurNodeCloneWithChildren;}
  493. if(aAllNodes[iCurIdx] == oEndContainer){oClonedEndContainer = oCurNodeCloneWithChildren;}
  494. while(iChildIdx >= 0 && nhn.DOMFix.parentNode(aAllNodes[iChildIdx]) == aAllNodes[iCurIdx]){
  495. iChildIdx = this._recurConstructClonedTree(aAllNodes, iChildIdx, oCurNodeCloneWithChildren);
  496. }
  497. // this may trigger an error message in IE when an erroneous script is inserted
  498. oClonedParentNode.insertBefore(oCurNodeCloneWithChildren, oClonedParentNode.firstChild);
  499. return iChildIdx;
  500. };
  501. this._recurConstructClonedTree = _recurConstructClonedTree;
  502. aNodes[aNodes.length] = nhn.DOMFix.parentNode(aNodes[aNodes.length-1]);
  503. this._recurConstructClonedTree(aNodes, aNodes.length-1, oClonedParentNode);
  504. return {oStartContainer: oClonedStartContainer, oEndContainer: oClonedEndContainer};
  505. },
  506. cloneRange : function(){
  507. return this._copyRange(new nhn.W3CDOMRange(this._window));
  508. },
  509. _copyRange : function(oClonedRange){
  510. oClonedRange.collapsed = this.collapsed;
  511. oClonedRange.commonAncestorContainer = this.commonAncestorContainer;
  512. oClonedRange.endContainer = this.endContainer;
  513. oClonedRange.endOffset = this.endOffset;
  514. oClonedRange.startContainer = this.startContainer;
  515. oClonedRange.startOffset = this.startOffset;
  516. oClonedRange._document = this._document;
  517. return oClonedRange;
  518. },
  519. collapse : function(toStart){
  520. if(toStart){
  521. this.endContainer = this.startContainer;
  522. this.endOffset = this.startOffset;
  523. }else{
  524. this.startContainer = this.endContainer;
  525. this.startOffset = this.endOffset;
  526. }
  527. this._updateRangeInfo();
  528. },
  529. compareBoundaryPoints : function(how, sourceRange){
  530. switch(how){
  531. case nhn.W3CDOMRange.START_TO_START:
  532. return this._compareEndPoint(this.startContainer, this.startOffset, sourceRange.startContainer, sourceRange.startOffset);
  533. case nhn.W3CDOMRange.START_TO_END:
  534. return this._compareEndPoint(this.endContainer, this.endOffset, sourceRange.startContainer, sourceRange.startOffset);
  535. case nhn.W3CDOMRange.END_TO_END:
  536. return this._compareEndPoint(this.endContainer, this.endOffset, sourceRange.endContainer, sourceRange.endOffset);
  537. case nhn.W3CDOMRange.END_TO_START:
  538. return this._compareEndPoint(this.startContainer, this.startOffset, sourceRange.endContainer, sourceRange.endOffset);
  539. }
  540. },
  541. _findBody : function(oNode){
  542. if(!oNode){return null;}
  543. while(oNode){
  544. if(oNode.tagName == "BODY"){return oNode;}
  545. oNode = nhn.DOMFix.parentNode(oNode);
  546. }
  547. return null;
  548. },
  549. _compareEndPoint : function(oContainerA, iOffsetA, oContainerB, iOffsetB){
  550. return this.oBrowserSelection.compareEndPoints(oContainerA, iOffsetA, oContainerB, iOffsetB);
  551. var iIdxA, iIdxB;
  552. if(!oContainerA || this._findBody(oContainerA) != this._document.body){
  553. oContainerA = this._document.body;
  554. iOffsetA = 0;
  555. }
  556. if(!oContainerB || this._findBody(oContainerB) != this._document.body){
  557. oContainerB = this._document.body;
  558. iOffsetB = 0;
  559. }
  560. var compareIdx = function(iIdxA, iIdxB){
  561. // iIdxX == -1 when the node is the commonAncestorNode
  562. // if iIdxA == -1
  563. // -> [[<nodeA>...<nodeB></nodeB>]]...</nodeA>
  564. // if iIdxB == -1
  565. // -> <nodeB>...[[<nodeA></nodeA>...</nodeB>]]
  566. if(iIdxB == -1){iIdxB = iIdxA+1;}
  567. if(iIdxA < iIdxB){return -1;}
  568. if(iIdxA == iIdxB){return 0;}
  569. return 1;
  570. };
  571. var oCommonAncestor = this._getCommonAncestorContainer(oContainerA, oContainerB);
  572. // ================================================================================================================================================
  573. // Move up both containers so that both containers are direct child nodes of the common ancestor node. From there, just compare the offset
  574. // Add 0.5 for each contaienrs that has "moved up" since the actual node is wrapped by 1 or more parent nodes and therefore its position is somewhere between idx & idx+1
  575. // <COMMON_ANCESTOR>NODE1<P>NODE2</P>NODE3</COMMON_ANCESTOR>
  576. // The position of NODE2 in COMMON_ANCESTOR is somewhere between after NODE1(idx1) and before NODE3(idx2), so we let that be 1.5
  577. // container node A in common ancestor container
  578. var oNodeA = oContainerA;
  579. var oTmpNode = null;
  580. if(oNodeA != oCommonAncestor){
  581. while((oTmpNode = nhn.DOMFix.parentNode(oNodeA)) != oCommonAncestor){oNodeA = oTmpNode;}
  582. iIdxA = this._getPosIdx(oNodeA)+0.5;
  583. }else{
  584. iIdxA = iOffsetA;
  585. }
  586. // container node B in common ancestor container
  587. var oNodeB = oContainerB;
  588. if(oNodeB != oCommonAncestor){
  589. while((oTmpNode = nhn.DOMFix.parentNode(oNodeB)) != oCommonAncestor){oNodeB = oTmpNode;}
  590. iIdxB = this._getPosIdx(oNodeB)+0.5;
  591. }else{
  592. iIdxB = iOffsetB;
  593. }
  594. return compareIdx(iIdxA, iIdxB);
  595. },
  596. _getCommonAncestorContainer : function(oNode1, oNode2){
  597. oNode1 = oNode1 || this.startContainer;
  598. oNode2 = oNode2 || this.endContainer;
  599. var oComparingNode = oNode2;
  600. while(oNode1){
  601. while(oComparingNode){
  602. if(oNode1 == oComparingNode){return oNode1;}
  603. oComparingNode = nhn.DOMFix.parentNode(oComparingNode);
  604. }
  605. oComparingNode = oNode2;
  606. oNode1 = nhn.DOMFix.parentNode(oNode1);
  607. }
  608. return this._document.body;
  609. },
  610. deleteContents : function(){
  611. if(this.collapsed){return;}
  612. this._splitTextEndNodesOfTheRange();
  613. var aNodes = this._getNodesInRange();
  614. if(aNodes.length < 1){return;}
  615. var oPrevNode = aNodes[0].previousSibling;
  616. while(oPrevNode && this._isBlankTextNode(oPrevNode)){oPrevNode = oPrevNode.previousSibling;}
  617. var oNewStartContainer, iNewOffset = -1;
  618. if(!oPrevNode){
  619. oNewStartContainer = nhn.DOMFix.parentNode(aNodes[0]);
  620. iNewOffset = 0;
  621. }
  622. for(var i=0; i<aNodes.length; i++){
  623. var oNode = aNodes[i];
  624. if(!oNode.firstChild || this._isAllChildBlankText(oNode)){
  625. if(oNewStartContainer == oNode){
  626. iNewOffset = this._getPosIdx(oNewStartContainer);
  627. oNewStartContainer = nhn.DOMFix.parentNode(oNode);
  628. }
  629. oNode.parentNode.removeChild(oNode);
  630. }else{
  631. // move the starting point to out of the parent container if the starting point of parent container is meant to be removed
  632. // [<span>A]B</span>
  633. // -> []<span>B</span>
  634. // without these lines, the result would yeild to
  635. // -> <span>[]B</span>
  636. if(oNewStartContainer == oNode && iNewOffset === 0){
  637. iNewOffset = this._getPosIdx(oNewStartContainer);
  638. oNewStartContainer = nhn.DOMFix.parentNode(oNode);
  639. }
  640. }
  641. }
  642. if(!oPrevNode){
  643. this.setStart(oNewStartContainer, iNewOffset, true, true);
  644. }else{
  645. if(oPrevNode.tagName == "BODY"){
  646. this.setStartBefore(oPrevNode, true);
  647. }else{
  648. this.setStartAfter(oPrevNode, true);
  649. }
  650. }
  651. this.collapse(true);
  652. },
  653. extractContents : function(){
  654. var oClonedContents = this.cloneContents();
  655. this.deleteContents();
  656. return oClonedContents;
  657. },
  658. getInsertBeforeNodes : function(){
  659. var oFirstNode = null;
  660. var oParentContainer;
  661. if(this.startContainer.nodeType == "3"){
  662. oParentContainer = nhn.DOMFix.parentNode(this.startContainer);
  663. if(this.startContainer.nodeValue.length <= this.startOffset){
  664. oFirstNode = this.startContainer.nextSibling;
  665. }else{
  666. oFirstNode = this.startContainer.splitText(this.startOffset);
  667. }
  668. }else{
  669. oParentContainer = this.startContainer;
  670. oFirstNode = nhn.DOMFix.childNodes(this.startContainer)[this.startOffset];
  671. }
  672. if(!oFirstNode || !nhn.DOMFix.parentNode(oFirstNode)){oFirstNode = null;}
  673. return {elParent: oParentContainer, elBefore: oFirstNode};
  674. },
  675. insertNode : function(newNode){
  676. var oInsertBefore = this.getInsertBeforeNodes();
  677. oInsertBefore.elParent.insertBefore(newNode, oInsertBefore.elBefore);
  678. this.setStartBefore(newNode);
  679. },
  680. selectNode : function(refNode){
  681. this.reset(this._window);
  682. this.setStartBefore(refNode);
  683. this.setEndAfter(refNode);
  684. },
  685. selectNodeContents : function(refNode){
  686. this.reset(this._window);
  687. this.setStart(refNode, 0, true);
  688. this.setEnd(refNode, nhn.DOMFix.childNodes(refNode).length);
  689. },
  690. _endsNodeValidation : function(oNode, iOffset){
  691. if(!oNode || this._findBody(oNode) != this._document.body){throw new Error("INVALID_NODE_TYPE_ERR oNode is not part of current document");}
  692. if(oNode.nodeType == 3){
  693. if(iOffset > oNode.nodeValue.length){iOffset = oNode.nodeValue.length;}
  694. }else{
  695. if(iOffset > nhn.DOMFix.childNodes(oNode).length){iOffset = nhn.DOMFix.childNodes(oNode).length;}
  696. }
  697. return iOffset;
  698. },
  699. setEnd : function(refNode, offset, bSafe, bNoUpdate){
  700. if(!bSafe){offset = this._endsNodeValidation(refNode, offset);}
  701. this.endContainer = refNode;
  702. this.endOffset = offset;
  703. if(!bNoUpdate){
  704. if(!this.startContainer || this._compareEndPoint(this.startContainer, this.startOffset, this.endContainer, this.endOffset) != -1){
  705. this.collapse(false);
  706. }else{
  707. this._updateRangeInfo();
  708. }
  709. }
  710. },
  711. setEndAfter : function(refNode, bNoUpdate){
  712. if(!refNode){throw new Error("INVALID_NODE_TYPE_ERR in setEndAfter");}
  713. if(refNode.tagName == "BODY"){
  714. this.setEnd(refNode, nhn.DOMFix.childNodes(refNode).length, true, bNoUpdate);
  715. return;
  716. }
  717. this.setEnd(nhn.DOMFix.parentNode(refNode), this._getPosIdx(refNode)+1, true, bNoUpdate);
  718. },
  719. setEndBefore : function(refNode, bNoUpdate){
  720. if(!refNode){throw new Error("INVALID_NODE_TYPE_ERR in setEndBefore");}
  721. if(refNode.tagName == "BODY"){
  722. this.setEnd(refNode, 0, true, bNoUpdate);
  723. return;
  724. }
  725. this.setEnd(nhn.DOMFix.parentNode(refNode), this._getPosIdx(refNode), true, bNoUpdate);
  726. },
  727. setStart : function(refNode, offset, bSafe, bNoUpdate){
  728. if(!bSafe){offset = this._endsNodeValidation(refNode, offset);}
  729. this.startContainer = refNode;
  730. this.startOffset = offset;
  731. if(!bNoUpdate){
  732. if(!this.endContainer || this._compareEndPoint(this.startContainer, this.startOffset, this.endContainer, this.endOffset) != -1){
  733. this.collapse(true);
  734. }else{
  735. this._updateRangeInfo();
  736. }
  737. }
  738. },
  739. setStartAfter : function(refNode, bNoUpdate){
  740. if(!refNode){throw new Error("INVALID_NODE_TYPE_ERR in setStartAfter");}
  741. if(refNode.tagName == "BODY"){
  742. this.setStart(refNode, nhn.DOMFix.childNodes(refNode).length, true, bNoUpdate);
  743. return;
  744. }
  745. this.setStart(nhn.DOMFix.parentNode(refNode), this._getPosIdx(refNode)+1, true, bNoUpdate);
  746. },
  747. setStartBefore : function(refNode, bNoUpdate){
  748. if(!refNode){throw new Error("INVALID_NODE_TYPE_ERR in setStartBefore");}
  749. if(refNode.tagName == "BODY"){
  750. this.setStart(refNode, 0, true, bNoUpdate);
  751. return;
  752. }
  753. this.setStart(nhn.DOMFix.parentNode(refNode), this._getPosIdx(refNode), true, bNoUpdate);
  754. },
  755. surroundContents : function(newParent){
  756. newParent.appendChild(this.extractContents());
  757. this.insertNode(newParent);
  758. this.selectNode(newParent);
  759. },
  760. toString : function(){
  761. var oTmpContainer = this._document.createElement("DIV");
  762. oTmpContainer.appendChild(this.cloneContents());
  763. return oTmpContainer.textContent || oTmpContainer.innerText || "";
  764. },
  765. // this.oBrowserSelection.getCommonAncestorContainer which uses browser's built-in API runs faster but may return an incorrect value.
  766. // Call this function to fix the problem.
  767. //
  768. // In IE, the built-in API would return an incorrect value when,
  769. // 1. commonAncestorContainer is not selectable
  770. // AND
  771. // 2. The selected area will look the same when its child node is selected
  772. // eg)
  773. // when <P><SPAN>TEST</SPAN></p> is selected, <SPAN>TEST</SPAN> will be returned as commonAncestorContainer
  774. fixCommonAncestorContainer : function(){
  775. if(!jindo.$Agent().navigator().ie){
  776. return;
  777. }
  778. this.commonAncestorContainer = this._getCommonAncestorContainer();
  779. },
  780. _isBlankTextNode : function(oNode){
  781. if(oNode.nodeType == 3 && oNode.nodeValue == ""){return true;}
  782. return false;
  783. },
  784. _isAllChildBlankText : function(elNode){
  785. for(var i=0, nLen=elNode.childNodes.length; i<nLen; i++){
  786. if(!this._isBlankTextNode(elNode.childNodes[i])){return false;}
  787. }
  788. return true;
  789. },
  790. _getPosIdx : function(refNode){
  791. var idx = 0;
  792. for(var node = refNode.previousSibling; node; node = node.previousSibling){idx++;}
  793. return idx;
  794. },
  795. _updateRangeInfo : function(){
  796. if(!this.startContainer){
  797. this.reset(this._window);
  798. return;
  799. }
  800. // isCollapsed may not function correctly when the cursor is located,
  801. // (below a table) AND (at the end of the document where there's no P tag or anything else to actually hold the cursor)
  802. this.collapsed = this.oBrowserSelection.isCollapsed(this) || (this.startContainer === this.endContainer && this.startOffset === this.endOffset);
  803. // this.collapsed = this._isCollapsed(this.startContainer, this.startOffset, this.endContainer, this.endOffset);
  804. this.commonAncestorContainer = this.oBrowserSelection.getCommonAncestorContainer(this);
  805. // this.commonAncestorContainer = this._getCommonAncestorContainer(this.startContainer, this.endContainer);
  806. },
  807. _isCollapsed : function(oStartContainer, iStartOffset, oEndContainer, iEndOffset){
  808. var bCollapsed = false;
  809. if(oStartContainer == oEndContainer && iStartOffset == iEndOffset){
  810. bCollapsed = true;
  811. }else{
  812. var oActualStartNode = this._getActualStartNode(oStartContainer, iStartOffset);
  813. var oActualEndNode = this._getActualEndNode(oEndContainer, iEndOffset);
  814. // Take the parent nodes on the same level for easier comparison when they're next to each other
  815. // eg) From
  816. // <A>
  817. // <B>
  818. // <C>
  819. // </C>
  820. // </B>
  821. // <D>
  822. // <E>
  823. // <F>
  824. // </F>
  825. // </E>
  826. // </D>
  827. // </A>
  828. // , it's easier to compare the position of B and D rather than C and F because they are siblings
  829. //
  830. // If the range were collapsed, oActualEndNode will precede oActualStartNode by doing this
  831. oActualStartNode = this._getNextNode(this._getPrevNode(oActualStartNode));
  832. oActualEndNode = this._getPrevNode(this._getNextNode(oActualEndNode));
  833. if(oActualStartNode && oActualEndNode && oActualEndNode.tagName != "BODY" &&
  834. (this._getNextNode(oActualEndNode) == oActualStartNode || (oActualEndNode == oActualStartNode && this._isBlankTextNode(oActualEndNode)))
  835. ){
  836. bCollapsed = true;
  837. }
  838. }
  839. return bCollapsed;
  840. },
  841. _splitTextEndNodesOfTheRange : function(){
  842. var oEndPoints = this._splitTextEndNodes({oStartContainer: this.startContainer, iStartOffset: this.startOffset,
  843. oEndContainer: this.endContainer, iEndOffset: this.endOffset});
  844. this.startContainer = oEndPoints.oStartContainer;
  845. this.startOffset = oEndPoints.iStartOffset;
  846. this.endContainer = oEndPoints.oEndContainer;
  847. this.endOffset = oEndPoints.iEndOffset;
  848. },
  849. _splitTextEndNodes : function(oEndPoints){
  850. oEndPoints = this._splitStartTextNode(oEndPoints);
  851. oEndPoints = this._splitEndTextNode(oEndPoints);
  852. return oEndPoints;
  853. },
  854. _splitStartTextNode : function(oEndPoints){
  855. var oStartContainer = oEndPoints.oStartContainer;
  856. var iStartOffset = oEndPoints.iStartOffset;
  857. var oEndContainer = oEndPoints.oEndContainer;
  858. var iEndOffset = oEndPoints.iEndOffset;
  859. if(!oStartContainer){return oEndPoints;}
  860. if(oStartContainer.nodeType != 3){return oEndPoints;}
  861. if(iStartOffset === 0){return oEndPoints;}
  862. if(oStartContainer.nodeValue.length <= iStartOffset){return oEndPoints;}
  863. var oLastPart = oStartContainer.splitText(iStartOffset);
  864. if(oStartContainer == oEndContainer){
  865. iEndOffset -= iStartOffset;
  866. oEndContainer = oLastPart;
  867. }
  868. oStartContainer = oLastPart;
  869. iStartOffset = 0;
  870. return {oStartContainer: oStartContainer, iStartOffset: iStartOffset, oEndContainer: oEndContainer, iEndOffset: iEndOffset};
  871. },
  872. _splitEndTextNode : function(oEndPoints){
  873. var oStartContainer = oEndPoints.oStartContainer;
  874. var iStartOffset = oEndPoints.iStartOffset;
  875. var oEndContainer = oEndPoints.oEndContainer;
  876. var iEndOffset = oEndPoints.iEndOffset;
  877. if(!oEndContainer){return oEndPoints;}
  878. if(oEndContainer.nodeType != 3){return oEndPoints;}
  879. if(iEndOffset >= oEndContainer.nodeValue.length){return oEndPoints;}
  880. if(iEndOffset === 0){return oEndPoints;}
  881. oEndContainer.splitText(iEndOffset);
  882. return {oStartContainer: oStartContainer, iStartOffset: iStartOffset, oEndContainer: oEndContainer, iEndOffset: iEndOffset};
  883. },
  884. _getNodesInRange : function(){
  885. if(this.collapsed){return [];}
  886. var oStartNode = this._getActualStartNode(this.startContainer, this.startOffset);
  887. var oEndNode = this._getActualEndNode(this.endContainer, this.endOffset);
  888. return this._getNodesBetween(oStartNode, oEndNode);
  889. },
  890. _getActualStartNode : function(oStartContainer, iStartOffset){
  891. var oStartNode = oStartContainer;
  892. if(oStartContainer.nodeType == 3){
  893. if(iStartOffset >= oStartContainer.nodeValue.length){
  894. oStartNode = this._getNextNode(oStartContainer);
  895. if(oStartNode.tagName == "BODY"){oStartNode = null;}
  896. }else{
  897. oStartNode = oStartContainer;
  898. }
  899. }else{
  900. if(iStartOffset < nhn.DOMFix.childNodes(oStartContainer).length){
  901. oStartNode = nhn.DOMFix.childNodes(oStartContainer)[iStartOffset];
  902. }else{
  903. oStartNode = this._getNextNode(oStartContainer);
  904. if(oStartNode.tagName == "BODY"){oStartNode = null;}
  905. }
  906. }
  907. return oStartNode;
  908. },
  909. _getActualEndNode : function(oEndContainer, iEndOffset){
  910. var oEndNode = oEndContainer;
  911. if(iEndOffset === 0){
  912. oEndNode = this._getPrevNode(oEndContainer);
  913. if(oEndNode.tagName == "BODY"){oEndNode = null;}
  914. }else if(oEndContainer.nodeType == 3){
  915. oEndNode = oEndContainer;
  916. }else{
  917. oEndNode = nhn.DOMFix.childNodes(oEndContainer)[iEndOffset-1];
  918. }
  919. return oEndNode;
  920. },
  921. _getNextNode : function(oNode){
  922. if(!oNode || oNode.tagName == "BODY"){return this._document.body;}
  923. if(oNode.nextSibling){return oNode.nextSibling;}
  924. return this._getNextNode(nhn.DOMFix.parentNode(oNode));
  925. },
  926. _getPrevNode : function(oNode){
  927. if(!oNode || oNode.tagName == "BODY"){return this._document.body;}
  928. if(oNode.previousSibling){return oNode.previousSibling;}
  929. return this._getPrevNode(nhn.DOMFix.parentNode(oNode));
  930. },
  931. // includes partially selected
  932. // for <div id="a"><div id="b"></div></div><div id="c"></div>, _getNodesBetween(b, c) will yield to b, "a" and c
  933. _getNodesBetween : function(oStartNode, oEndNode){
  934. var aNodesBetween = [];
  935. this._nNodesBetweenLen = 0;
  936. if(!oStartNode || !oEndNode){return aNodesBetween;}
  937. // IE may throw an exception on "oCurNode = oCurNode.nextSibling;" when oCurNode is 'invalid', not null or undefined but somehow 'invalid'.
  938. // It happened during browser's build-in UNDO with control range selected(table).
  939. try{
  940. this._recurGetNextNodesUntil(oStartNode, oEndNode, aNodesBetween);
  941. }catch(e){
  942. return [];
  943. }
  944. return aNodesBetween;
  945. },
  946. _recurGetNextNodesUntil : function(oNode, oEndNode, aNodesBetween){
  947. if(!oNode){return false;}
  948. if(!this._recurGetChildNodesUntil(oNode, oEndNode, aNodesBetween)){return false;}
  949. var oNextToChk = oNode.nextSibling;
  950. while(!oNextToChk){
  951. if(!(oNode = nhn.DOMFix.parentNode(oNode))){return false;}
  952. aNodesBetween[this._nNodesBetweenLen++] = oNode;
  953. if(oNode == oEndNode){return false;}
  954. oNextToChk = oNode.nextSibling;
  955. }
  956. return this._recurGetNextNodesUntil(oNextToChk, oEndNode, aNodesBetween);
  957. },
  958. _recurGetChildNodesUntil : function(oNode, oEndNode, aNodesBetween){
  959. if(!oNode){return false;}
  960. var bEndFound = false;
  961. var oCurNode = oNode;
  962. if(oCurNode.firstChild){
  963. oCurNode = oCurNode.firstChild;
  964. while(oCurNode){
  965. if(!this._recurGetChildNodesUntil(oCurNode, oEndNode, aNodesBetween)){
  966. bEndFound = true;
  967. break;
  968. }
  969. oCurNode = oCurNode.nextSibling;
  970. }
  971. }
  972. aNodesBetween[this._nNodesBetweenLen++] = oNode;
  973. if(bEndFound){return false;}
  974. if(oNode == oEndNode){return false;}
  975. return true;
  976. }
  977. });
  978. nhn.W3CDOMRange.START_TO_START = 0;
  979. nhn.W3CDOMRange.START_TO_END = 1;
  980. nhn.W3CDOMRange.END_TO_END = 2;
  981. nhn.W3CDOMRange.END_TO_START = 3;
  982. /**
  983. * @fileOverview This file contains a cross-browser function that implements all of the W3C's DOM Range specification and some more
  984. * @name HuskyRange.js
  985. */
  986. nhn.HuskyRange = jindo.$Class({
  987. _rxCursorHolder : /^(?:\uFEFF|\u00A0|\u200B|<br>)$/i,
  988. _rxTextAlign : /text-align:[^"';]*;?/i,
  989. setWindow : function(win){
  990. this.reset(win || window);
  991. },
  992. $init : function(win){
  993. this.HUSKY_BOOMARK_START_ID_PREFIX = "husky_bookmark_start_";
  994. this.HUSKY_BOOMARK_END_ID_PREFIX = "husky_bookmark_end_";
  995. this.sBlockElement = "P|DIV|LI|H[1-6]|PRE";
  996. this.sBlockContainer = "BODY|TABLE|TH|TR|TD|UL|OL|BLOCKQUOTE|FORM";
  997. this.rxBlockElement = new RegExp("^("+this.sBlockElement+")$");
  998. this.rxBlockContainer = new RegExp("^("+this.sBlockContainer+")$");
  999. this.rxLineBreaker = new RegExp("^("+this.sBlockElement+"|"+this.sBlockContainer+")$");
  1000. this.rxHasBlock = new RegExp("(?:<(?:"+this.sBlockElement+"|"+this.sBlockContainer+").*?>|style=[\"']?[^>]*?(?:display\\s?:\\s?block)[^>]*?[\"']?)", "i");
  1001. this.setWindow(win);
  1002. },
  1003. select : function(){
  1004. try{
  1005. this.oBrowserSelection.selectRange(this);
  1006. }catch(e){}
  1007. },
  1008. setFromSelection : function(iNum){
  1009. this.setRange(this.oBrowserSelection.getRangeAt(iNum), true);
  1010. },
  1011. setRange : function(oW3CRange, bSafe){
  1012. this.reset(this._window);
  1013. this.setStart(oW3CRange.startContainer, oW3CRange.startOffset, bSafe, true);
  1014. this.setEnd(oW3CRange.endContainer, oW3CRange.endOffset, bSafe);
  1015. },
  1016. setEndNodes : function(oSNode, oENode){
  1017. this.reset(this._window);
  1018. this.setEndAfter(oENode, true);
  1019. this.setStartBefore(oSNode);
  1020. },
  1021. splitTextAtBothEnds : function(){
  1022. this._splitTextEndNodesOfTheRange();
  1023. },
  1024. getStartNode : function(){
  1025. if(this.collapsed){
  1026. if(this.startContainer.nodeType == 3){
  1027. if(this.startOffset === 0){return null;}
  1028. if(this.startContainer.nodeValue.length <= this.startOffset){return null;}
  1029. return this.startContainer;
  1030. }
  1031. return null;
  1032. }
  1033. if(this.startContainer.nodeType == 3){
  1034. if(this.startOffset >= this.startContainer.nodeValue.length){return this._getNextNode(this.startContainer);}
  1035. return this.startContainer;
  1036. }else{
  1037. if(this.startOffset >= nhn.DOMFix.childNodes(this.startContainer).length){return this._getNextNode(this.startContainer);}
  1038. return nhn.DOMFix.childNodes(this.startContainer)[this.startOffset];
  1039. }
  1040. },
  1041. getEndNode : function(){
  1042. if(this.collapsed){return this.getStartNode();}
  1043. if(this.endContainer.nodeType == 3){
  1044. if(this.endOffset === 0){return this._getPrevNode(this.endContainer);}
  1045. return this.endContainer;
  1046. }else{
  1047. if(this.endOffset === 0){return this._getPrevNode(this.endContainer);}
  1048. return nhn.DOMFix.childNodes(this.endContainer)[this.endOffset-1];
  1049. }
  1050. },
  1051. getNodeAroundRange : function(bBefore, bStrict){
  1052. if(!this.collapsed){return this.getStartNode();}
  1053. if(this.startContainer && this.startContainer.nodeType == 3){return this.startContainer;}
  1054. //if(this.collapsed && this.startContainer && this.startContainer.nodeType == 3) return this.startContainer;
  1055. //if(!this.collapsed || (this.startContainer && this.startContainer.nodeType == 3)) return this.getStartNode();
  1056. var oBeforeRange, oAfterRange, oResult;
  1057. if(this.startOffset >= nhn.DOMFix.childNodes(this.startContainer).length){
  1058. oAfterRange = this._getNextNode(this.startContainer);
  1059. }else{
  1060. oAfterRange = nhn.DOMFix.childNodes(this.startContainer)[this.startOffset];
  1061. }
  1062. if(this.endOffset === 0){
  1063. oBeforeRange = this._getPrevNode(this.endContainer);
  1064. }else{
  1065. oBeforeRange = nhn.DOMFix.childNodes(this.endContainer)[this.endOffset-1];
  1066. }
  1067. if(bBefore){
  1068. oResult = oBeforeRange;
  1069. if(!oResult && !bStrict){oResult = oAfterRange;}
  1070. }else{
  1071. oResult = oAfterRange;
  1072. if(!oResult && !bStrict){oResult = oBeforeRange;}
  1073. }
  1074. return oResult;
  1075. },
  1076. _getXPath : function(elNode){
  1077. var sXPath = "";
  1078. while(elNode && elNode.nodeType == 1){
  1079. sXPath = "/" + elNode.tagName+"["+this._getPosIdx4XPath(elNode)+"]" + sXPath;
  1080. elNode = nhn.DOMFix.parentNode(elNode);
  1081. }
  1082. return sXPath;
  1083. },
  1084. _getPosIdx4XPath : function(refNode){
  1085. var idx = 0;
  1086. for(var node = refNode.previousSibling; node; node = node.previousSibling){
  1087. if(node.tagName == refNode.tagName){idx++;}
  1088. }
  1089. return idx;
  1090. },
  1091. // this was written specifically for XPath Bookmark and it may not perform correctly for general purposes
  1092. _evaluateXPath : function(sXPath, oDoc){
  1093. sXPath = sXPath.substring(1, sXPath.length-1);
  1094. var aXPath = sXPath.split(/\//);
  1095. var elNode = oDoc.body;
  1096. for(var i=2; i<aXPath.length && elNode; i++){
  1097. aXPath[i].match(/([^\[]+)\[(\d+)/i);
  1098. var sTagName = RegExp.$1;
  1099. var nIdx = RegExp.$2;
  1100. var aAllNodes = nhn.DOMFix.childNodes(elNode);
  1101. var aNodes = [];
  1102. var nLength = aAllNodes.length;
  1103. var nCount = 0;
  1104. for(var ii=0; ii<nLength; ii++){
  1105. if(aAllNodes[ii].tagName == sTagName){aNodes[nCount++] = aAllNodes[ii];}
  1106. }
  1107. if(aNodes.length < nIdx){
  1108. elNode = null;
  1109. }else{
  1110. elNode = aNodes[nIdx];
  1111. }
  1112. }
  1113. return elNode;
  1114. },
  1115. _evaluateXPathBookmark : function(oBookmark){
  1116. var sXPath = oBookmark["sXPath"];
  1117. var nTextNodeIdx = oBookmark["nTextNodeIdx"];
  1118. var nOffset = oBookmark["nOffset"];
  1119. var elContainer = this._evaluateXPath(sXPath, this._document);
  1120. if(nTextNodeIdx > -1 && elContainer){
  1121. var aChildNodes = nhn.DOMFix.childNodes(elContainer);
  1122. var elNode = null;
  1123. var nIdx = nTextNodeIdx;
  1124. var nOffsetLeft = nOffset;
  1125. while((elNode = aChildNodes[nIdx]) && elNode.nodeType == 3 && elNode.nodeValue.length < nOffsetLeft){
  1126. nOffsetLeft -= elNode.nodeValue.length;
  1127. nIdx++;
  1128. }
  1129. elContainer = nhn.DOMFix.childNodes(elContainer)[nIdx];
  1130. nOffset = nOffsetLeft;
  1131. }
  1132. if(!elContainer){
  1133. elContainer = this._document.body;
  1134. nOffset = 0;
  1135. }
  1136. return {elContainer: elContainer, nOffset: nOffset};
  1137. },
  1138. // this was written specifically for XPath Bookmark and it may not perform correctly for general purposes
  1139. getXPathBookmark : function(){
  1140. var nTextNodeIdx1 = -1;
  1141. var htEndPt1 = {elContainer: this.startContainer, nOffset: this.startOffset};
  1142. var elNode1 = this.startContainer;
  1143. if(elNode1.nodeType == 3){
  1144. htEndPt1 = this._getFixedStartTextNode();
  1145. nTextNodeIdx1 = this._getPosIdx(htEndPt1.elContainer);
  1146. elNode1 = nhn.DOMFix.parentNode(elNode1);
  1147. }
  1148. var sXPathNode1 = this._getXPath(elNode1);
  1149. var oBookmark1 = {sXPath:sXPathNode1, nTextNodeIdx:nTextNodeIdx1, nOffset: htEndPt1.nOffset};
  1150. if(this.collapsed){
  1151. var oBookmark2 = {sXPath:sXPathNode1, nTextNodeIdx:nTextNodeIdx1, nOffset: htEndPt1.nOffset};
  1152. }else{
  1153. var nTextNodeIdx2 = -1;
  1154. var htEndPt2 = {elContainer: this.endContainer, nOffset: this.endOffset};
  1155. var elNode2 = this.endContainer;
  1156. if(elNode2.nodeType == 3){
  1157. htEndPt2 = this._getFixedEndTextNode();
  1158. nTextNodeIdx2 = this._getPosIdx(htEndPt2.elContainer);
  1159. elNode2 = nhn.DOMFix.parentNode(elNode2);
  1160. }
  1161. var sXPathNode2 = this._getXPath(elNode2);
  1162. var oBookmark2 = {sXPath:sXPathNode2, nTextNodeIdx:nTextNodeIdx2, nOffset: htEndPt2.nOffset};
  1163. }
  1164. return [oBookmark1, oBookmark2];
  1165. },
  1166. moveToXPathBookmark : function(aBookmark){
  1167. if(!aBookmark){return false;}
  1168. var oBookmarkInfo1 = this._evaluateXPathBookmark(aBookmark[0]);
  1169. var oBookmarkInfo2 = this._evaluateXPathBookmark(aBookmark[1]);
  1170. if(!oBookmarkInfo1["elContainer"] || !oBookmarkInfo2["elContainer"]){return;}
  1171. this.startContainer = oBookmarkInfo1["elContainer"];
  1172. this.startOffset = oBookmarkInfo1["nOffset"];
  1173. this.endContainer = oBookmarkInfo2["elContainer"];
  1174. this.endOffset = oBookmarkInfo2["nOffset"];
  1175. return true;
  1176. },
  1177. _getFixedTextContainer : function(elNode, nOffset){
  1178. while(elNode && elNode.nodeType == 3 && elNode.previousSibling && elNode.previousSibling.nodeType == 3){
  1179. nOffset += elNode.previousSibling.nodeValue.length;
  1180. elNode = elNode.previousSibling;
  1181. }
  1182. return {elContainer:elNode, nOffset:nOffset};
  1183. },
  1184. _getFixedStartTextNode : function(){
  1185. return this._getFixedTextContainer(this.startContainer, this.startOffset);
  1186. },
  1187. _getFixedEndTextNode : function(){
  1188. return this._getFixedTextContainer(this.endContainer, this.endOffset);
  1189. },
  1190. placeStringBookmark : function(){
  1191. if(this.collapsed || jindo.$Agent().navigator().ie || jindo.$Agent().navigator().firefox){
  1192. return this.placeStringBookmark_NonWebkit();
  1193. }else{
  1194. return this.placeStringBookmark_Webkit();
  1195. }
  1196. },
  1197. placeStringBookmark_NonWebkit : function(){
  1198. var sTmpId = (new Date()).getTime();
  1199. var oInsertionPoint = this.cloneRange();
  1200. oInsertionPoint.collapseToEnd();
  1201. var oEndMarker = this._document.createElement("SPAN");
  1202. oEndMarker.id = this.HUSKY_BOOMARK_END_ID_PREFIX+sTmpId;
  1203. oInsertionPoint.insertNode(oEndMarker);
  1204. var oInsertionPoint = this.cloneRange();
  1205. oInsertionPoint.collapseToStart();
  1206. var oStartMarker = this._document.createElement("SPAN");
  1207. oStartMarker.id = this.HUSKY_BOOMARK_START_ID_PREFIX+sTmpId;
  1208. oInsertionPoint.insertNode(oStartMarker);
  1209. // IE에서 빈 SPAN의 앞뒤로 커서가 이동하지 않아 문제가 발생 할 수 있어, 보이지 않는 특수 문자를 임시로 넣어 줌.
  1210. if(jindo.$Agent().navigator().ie){
  1211. // SPAN의 위치가 TD와 TD 사이에 있을 경우, 텍스트 삽입 시 알수 없는 오류가 발생한다.
  1212. // TD와 TD사이에서는 텍스트 삽입이 필요 없음으로 그냥 try/catch로 처리
  1213. try{
  1214. oStartMarker.innerHTML = unescape("%uFEFF");
  1215. }catch(e){}
  1216. try{
  1217. oEndMarker.innerHTML = unescape("%uFEFF");
  1218. }catch(e){}
  1219. }
  1220. this.moveToBookmark(sTmpId);
  1221. return sTmpId;
  1222. },
  1223. placeStringBookmark_Webkit : function(){
  1224. var sTmpId = (new Date()).getTime();
  1225. var elInsertBefore, elInsertParent;
  1226. // Do not insert the bookmarks between TDs as it will break the rendering in Chrome/Safari
  1227. // -> modify the insertion position from [<td>abc</td>]<td>abc</td> to <td>[abc]</td><td>abc</td>
  1228. var oInsertionPoint = this.cloneRange();
  1229. oInsertionPoint.collapseToEnd();
  1230. elInsertBefore = this._document.createTextNode("");
  1231. oInsertionPoint.insertNode(elInsertBefore);
  1232. elInsertParent = elInsertBefore.parentNode;
  1233. if(elInsertBefore.previousSibling && elInsertBefore.previousSibling.tagName == "TD"){
  1234. elInsertParent = elInsertBefore.previousSibling;
  1235. elInsertBefore = null;
  1236. }
  1237. var oEndMarker = this._document.createElement("SPAN");
  1238. oEndMarker.id = this.HUSKY_BOOMARK_END_ID_PREFIX+sTmpId;
  1239. elInsertParent.insertBefore(oEndMarker, elInsertBefore);
  1240. var oInsertionPoint = this.cloneRange();
  1241. oInsertionPoint.collapseToStart();
  1242. elInsertBefore = this._document.createTextNode("");
  1243. oInsertionPoint.insertNode(elInsertBefore);
  1244. elInsertParent = elInsertBefore.parentNode;
  1245. if(elInsertBefore.nextSibling && elInsertBefore.nextSibling.tagName == "TD"){
  1246. elInsertParent = elInsertBefore.nextSibling;
  1247. elInsertBefore = elInsertParent.firstChild;
  1248. }
  1249. var oStartMarker = this._document.createElement("SPAN");
  1250. oStartMarker.id = this.HUSKY_BOOMARK_START_ID_PREFIX+sTmpId;
  1251. elInsertParent.insertBefore(oStartMarker, elInsertBefore);
  1252. //elInsertBefore.parentNode.removeChild(elInsertBefore);
  1253. this.moveToBookmark(sTmpId);
  1254. return sTmpId;
  1255. },
  1256. cloneRange : function(){
  1257. return this._copyRange(new nhn.HuskyRange(this._window));
  1258. },
  1259. moveToBookmark : function(vBookmark){
  1260. if(typeof(vBookmark) != "object"){
  1261. return this.moveToStringBookmark(vBookmark);
  1262. }else{
  1263. return this.moveToXPathBookmark(vBookmark);
  1264. }
  1265. },
  1266. getStringBookmark : function(sBookmarkID, bEndBookmark){
  1267. if(bEndBookmark){
  1268. return this._document.getElementById(this.HUSKY_BOOMARK_END_ID_PREFIX+sBookmarkID);
  1269. }else{
  1270. return this._document.getElementById(this.HUSKY_BOOMARK_START_ID_PREFIX+sBookmarkID);
  1271. }
  1272. },
  1273. moveToStringBookmark : function(sBookmarkID, bIncludeBookmark){
  1274. var oStartMarker = this.getStringBookmark(sBookmarkID);
  1275. var oEndMarker = this.getStringBookmark(sBookmarkID, true);
  1276. if(!oStartMarker || !oEndMarker){return false;}
  1277. this.reset(this._window);
  1278. if(bIncludeBookmark){
  1279. this.setEndAfter(oEndMarker);
  1280. this.setStartBefore(oStartMarker);
  1281. }else{
  1282. this.setEndBefore(oEndMarker);
  1283. this.setStartAfter(oStartMarker);
  1284. }
  1285. return true;
  1286. },
  1287. removeStringBookmark : function(sBookmarkID){
  1288. /*
  1289. var oStartMarker = this._document.getElementById(this.HUSKY_BOOMARK_START_ID_PREFIX+sBookmarkID);
  1290. var oEndMarker = this._document.getElementById(this.HUSKY_BOOMARK_END_ID_PREFIX+sBookmarkID);
  1291. if(oStartMarker) nhn.DOMFix.parentNode(oStartMarker).removeChild(oStartMarker);
  1292. if(oEndMarker) nhn.DOMFix.parentNode(oEndMarker).removeChild(oEndMarker);
  1293. */
  1294. this._removeAll(this.HUSKY_BOOMARK_START_ID_PREFIX+sBookmarkID);
  1295. this._removeAll(this.HUSKY_BOOMARK_END_ID_PREFIX+sBookmarkID);
  1296. },
  1297. _removeAll : function(sID){
  1298. var elNode;
  1299. while((elNode = this._document.getElementById(sID))){
  1300. elNode.parentNode.removeChild(elNode);
  1301. }
  1302. },
  1303. collapseToStart : function(){
  1304. this.collapse(true);
  1305. },
  1306. collapseToEnd : function(){
  1307. this.collapse(false);
  1308. },
  1309. createAndInsertNode : function(sTagName){
  1310. var tmpNode = this._document.createElement(sTagName);
  1311. this.insertNode(tmpNode);
  1312. return tmpNode;
  1313. },
  1314. getNodes : function(bSplitTextEndNodes, fnFilter){
  1315. if(bSplitTextEndNodes){this._splitTextEndNodesOfTheRange();}
  1316. var aAllNodes = this._getNodesInRange();
  1317. var aFilteredNodes = [];
  1318. if(!fnFilter){return aAllNodes;}
  1319. for(var i=0; i<aAllNodes.length; i++){
  1320. if(fnFilter(aAllNodes[i])){aFilteredNodes[aFilteredNodes.length] = aAllNodes[i];}
  1321. }
  1322. return aFilteredNodes;
  1323. },
  1324. getTextNodes : function(bSplitTextEndNodes){
  1325. var txtFilter = function(oNode){
  1326. if (oNode.nodeType == 3 && oNode.nodeValue != "\n" && oNode.nodeValue != ""){
  1327. return true;
  1328. }else{
  1329. return false;
  1330. }
  1331. };
  1332. return this.getNodes(bSplitTextEndNodes, txtFilter);
  1333. },
  1334. surroundContentsWithNewNode : function(sTagName){
  1335. var oNewParent = this._document.createElement(sTagName);
  1336. this.surroundContents(oNewParent);
  1337. return oNewParent;
  1338. },
  1339. isRangeinRange : function(oAnoterRange, bIncludePartlySelected){
  1340. var startToStart = this.compareBoundaryPoints(this.W3CDOMRange.START_TO_START, oAnoterRange);
  1341. var startToEnd = this.compareBoundaryPoints(this.W3CDOMRange.START_TO_END, oAnoterRange);
  1342. var endToStart = this.compareBoundaryPoints(this.W3CDOMRange.ND_TO_START, oAnoterRange);
  1343. var endToEnd = this.compareBoundaryPoints(this.W3CDOMRange.END_TO_END, oAnoterRange);
  1344. if(startToStart <= 0 && endToEnd >= 0){return true;}
  1345. if(bIncludePartlySelected){
  1346. if(startToEnd == 1){return false;}
  1347. if(endToStart == -1){return false;}
  1348. return true;
  1349. }
  1350. return false;
  1351. },
  1352. isNodeInRange : function(oNode, bIncludePartlySelected, bContentOnly){
  1353. var oTmpRange = new nhn.HuskyRange(this._window);
  1354. if(bContentOnly && oNode.firstChild){
  1355. oTmpRange.setStartBefore(oNode.firstChild);
  1356. oTmpRange.setEndAfter(oNode.lastChild);
  1357. }else{
  1358. oTmpRange.selectNode(oNode);
  1359. }
  1360. return this.isRangeInRange(oTmpRange, bIncludePartlySelected);
  1361. },
  1362. pasteText : function(sText){
  1363. this.pasteHTML(sText.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/ /g, "&nbsp;").replace(/"/g, "&quot;"));
  1364. },
  1365. /**
  1366. * TODO: clone 으로 조작할까?
  1367. * @param {String} sHTML 삽입할 HTML
  1368. * @param {Boolean} bBlock HTML 삽입시 강제로 block 요소 처리할지 여부(true 이면 P태그 안에 삽입될 경우, P태그를 무조건 쪼개고 사이에 DIV태그로 감싸서 삽입한다.)
  1369. */
  1370. pasteHTML : function(sHTML, bBlock){
  1371. var oTmpDiv = this._document.createElement("DIV");
  1372. oTmpDiv.innerHTML = sHTML;
  1373. if(!oTmpDiv.firstChild){
  1374. this.deleteContents();
  1375. return;
  1376. }
  1377. // getLineInfo 전에 북마크를 삽입하지 않으면 IE에서 oLineBreaker가 P태그 바깥으로 잡히는 경우가 있음(P태그에 아무것도 없을때)
  1378. var clone = this.cloneRange();
  1379. var sBM = clone.placeStringBookmark();
  1380. // [SMARTEDITORSUS-1960] PrivateTag, 템플릿삽입등 P태그안에 block 요소 삽입과 관련된 처리
  1381. // P태그인 경우, block요소가 들어오면 안된다.
  1382. // 때문에 현재 위치의 컨테이너가 P태그이고 컨텐츠 내용이 block 요소인 경우 P태그를 쪼개고 그 사이에 컨텐츠를 DIV로 감싸서 넣도록 처리한다.
  1383. // [SMARTEDITORSUS-2026][SMARTEDITORSUS-2061] bBlock = true 이면 삽입되는 HTML 이 block 요소가 아니더라도 무조건 P태그를 쪼개서 DIV로 감싸도록 한다.
  1384. var oLineInfo = clone.getLineInfo(),
  1385. oStart = oLineInfo.oStart,
  1386. oEnd = oLineInfo.oEnd;
  1387. if(oStart.oLineBreaker && oStart.oLineBreaker.nodeName === "P" && (bBlock || clone.rxHasBlock.test(sHTML))){
  1388. // [SMARTEDITORSUS-2169] 선택영역 삭제시 oStart.oLineBreaker도 DOM 트리에서 제거될 수 있기 때문에 필요한 노드를 미리 참조해둔다.
  1389. var oParentNode = oStart.oLineBreaker.parentNode,
  1390. oNextSibling = oStart.oLineBreaker.nextSibling;
  1391. // 선택영역을 조작해야 하므로 현재 선택된 요소들을 제거한다.
  1392. clone.deleteContents();
  1393. // 동일한 라인에 있으면 뒷부분은 쪼개서 다음 라인으로 삽입한다.
  1394. if(oStart.oLineBreaker === oEnd.oLineBreaker){
  1395. var elBM = clone.getStringBookmark(sBM);
  1396. clone.setEndNodes(elBM, oEnd.oLineBreaker);
  1397. var oNextContents = clone.extractContents(),
  1398. oNextFirst = oNextContents.firstChild; // oNextSibling 을 교체하기 위해 쪼개진 요소 첫번째 노드를 미리 참조해둔다.
  1399. // 쪼갠 부분을 삽입하고
  1400. if(oNextSibling){
  1401. oParentNode.insertBefore(oNextContents, oNextSibling);
  1402. }else{
  1403. oParentNode.appendChild(oNextContents);
  1404. }
  1405. // [SMARTEDITORSUS-2145] oNextSibling 을 쪼갠 부분의 첫번째 노드로 교체한다.
  1406. oNextSibling = oNextFirst;
  1407. }
  1408. // 선택영역 앞쪽이 속한 P태그에서 style과 align 정보를 복사한다.
  1409. // 크롬의 경우 div의 style 에 text-align 이 있으면 align 속성은 무시되는데
  1410. // div 안의 block 요소는 text-align 의 대상이 아니라 정렬되지 않는 문제가 있기 때문에
  1411. // style 복사할 때 text-align 속성은 제외한다.
  1412. oTmpDiv.style.cssText = oStart.oLineBreaker.style.cssText.replace(this._rxTextAlign, ''); // text-align 제외
  1413. oTmpDiv.align = oStart.oLineBreaker.align; // align 복사
  1414. // 컨텐츠 삽입
  1415. if(oNextSibling){
  1416. oParentNode.insertBefore(oTmpDiv, oNextSibling);
  1417. }else{
  1418. oParentNode.appendChild(oTmpDiv);
  1419. }
  1420. // 컨텐츠 삽입 후에 북마크를 지운다.
  1421. // 컨텐츠 삽입 전에 지우면 컨텐츠 삽입시 oNextSibling 가 북마크로 잡히는 경우 에러가 발생할 수 있음
  1422. clone.removeStringBookmark(sBM);
  1423. // 컨텐츠 삽입 후 윗라인 P태그에 아무런 내용이 없으면 제거한다.
  1424. this._removeEmptyP(this._getPrevElement(oTmpDiv));
  1425. // 아래 라인 P태그에 아무런 내용이 없는 경우는 그 다음 아래 라인이 있을때만 제거한다.
  1426. // 아래 라인이 아예없으면 IE에서 커서가 들어가지 않기 때문에 라인을 추가해준다.
  1427. var elNextLine = this._getNextElement(oTmpDiv);
  1428. if(elNextLine){
  1429. var elAfterNext = this._getNextElement(elNextLine);
  1430. if(elAfterNext && this._removeEmptyP(elNextLine)){
  1431. elNextLine = elAfterNext; // 제거되었을 경우만 elNextLine 재할당
  1432. }
  1433. }else{
  1434. // 아래 라인이 없으면 윗 라인 스타일을 복사하여 추가해준다.
  1435. elNextLine = this._document.createElement("P");
  1436. elNextLine.style.cssText = oStart.oLineBreaker.style.cssText;
  1437. elNextLine.align = oStart.oLineBreaker.align;
  1438. oParentNode.appendChild(elNextLine);
  1439. }
  1440. // 커서를 다음라인으로 앞쪽으로 위치시킨다.
  1441. if(elNextLine.innerHTML === ""){
  1442. // 크롬에서 빈 <p></p> 를 선택해서 collapseToStart 하면 윗라인으로 이동하기 때문에 비어있으면 \uFEFF 를 넣어준다.
  1443. elNextLine.innerHTML = (jindo.$Agent().navigator().ie && jindo.$Agent().navigator().version > 8) ? "\u200B" : "\uFEFF";
  1444. }
  1445. this.selectNodeContents(elNextLine);
  1446. this.collapseToStart();
  1447. // IE7에서 커서가 다음라인 p태그 앞쪽이 아닌 div태그 끝쪽으로 자동으로 옮겨가는 경우가 있어서
  1448. // 커서가 멋대로 이동하지 않도록 임시북마크를 넣었다가 바로 빼준다.
  1449. // (주의) 북마크를 넣었다 빼면 IE10은 다음라인 p태그 끝쪽으로 이동되기 때문에 IE7인 경우만 넣어줌
  1450. // [SMARTEDITORSUS-2043] SE_EditingArea_WYSIWYG.$ON_PASTE_HTML 에서 IE8의 경우만 삽입시 뒤에 \uFEFF가 추가로 붙어서 들어오는데
  1451. // 이로 인해 템플릿과 커서사이가 한줄 벌어지는 문제가 있어서 \uFEFF 추가하는 부분을 삭제하니 커서가 IE7과 동일하게 동작하여 IE8도 임시북마크처리함
  1452. if(jindo.$Agent().navigator().ie && jindo.$Agent().navigator().version < 9){
  1453. sBM = this.placeStringBookmark();
  1454. this.removeStringBookmark(sBM);
  1455. }
  1456. }else{
  1457. var oFirstNode = oTmpDiv.firstChild;
  1458. var oLastNode = oTmpDiv.lastChild;
  1459. this.collapseToStart();
  1460. while(oTmpDiv.lastChild){this.insertNode(oTmpDiv.lastChild);}
  1461. this.setEndNodes(oFirstNode, oLastNode);
  1462. // delete the content later as deleting it first may mass up the insertion point
  1463. // eg) <p>[A]BCD</p> ---paste O---> O<p>BCD</p>
  1464. clone.moveToBookmark(sBM);
  1465. clone.deleteContents();
  1466. clone.removeStringBookmark(sBM);
  1467. }
  1468. },
  1469. /**
  1470. * 비어있는 P태그이면 제거한다.
  1471. * @param {Element} el 검사할 Element
  1472. * @returns {Boolean} 제거되었다면 true 반환한다.
  1473. */
  1474. _removeEmptyP : function(el){
  1475. if(el && el.nodeName === "P"){
  1476. var sInner = el.innerHTML;
  1477. if(sInner === "" || this._rxCursorHolder.test(sInner)){
  1478. el.parentNode.removeChild(el);
  1479. return true;
  1480. }
  1481. }
  1482. },
  1483. /**
  1484. * 인접한 Element 노드를 찾는다.
  1485. * @param {Node} oNode 기준 노드
  1486. * @param {Boolean} bPrev 앞뒤여부(true면 , false면 )
  1487. * @return {Element} 인접한 Element, 없으면 null 반환
  1488. */
  1489. _getSiblingElement : function(oNode, bPrev){
  1490. if(!oNode){
  1491. return null;
  1492. }
  1493. var oSibling = oNode[bPrev ? "previousSibling" : "nextSibling"];
  1494. if(oSibling && oSibling.nodeType === 1){
  1495. return oSibling;
  1496. }else{
  1497. return arguments.callee(oSibling, bPrev);
  1498. }
  1499. },
  1500. /**
  1501. * 앞쪽 인접한 Element 노드를 찾는다.
  1502. * @param {Node} oNode 기준 노드
  1503. * @return {Element} 인접한 Element, 없으면 null 반환
  1504. */
  1505. _getPrevElement : function(oNode){
  1506. return this._getSiblingElement(oNode, true);
  1507. },
  1508. /**
  1509. * 뒤쪽 인접한 Element 노드를 찾는다.
  1510. * @param {Node} oNode 기준 노드
  1511. * @return {Element} 인접한 Element, 없으면 null 반환
  1512. */
  1513. _getNextElement : function(oNode){
  1514. return this._getSiblingElement(oNode, false);
  1515. },
  1516. toString : function(){
  1517. this.toString = nhn.W3CDOMRange.prototype.toString;
  1518. return this.toString();
  1519. },
  1520. toHTMLString : function(){
  1521. var oTmpContainer = this._document.createElement("DIV");
  1522. oTmpContainer.appendChild(this.cloneContents());
  1523. return oTmpContainer.innerHTML;
  1524. },
  1525. findAncestorByTagName : function(sTagName){
  1526. var oNode = this.commonAncestorContainer;
  1527. while(oNode && oNode.tagName != sTagName){oNode = nhn.DOMFix.parentNode(oNode);}
  1528. return oNode;
  1529. },
  1530. selectNodeContents : function(oNode){
  1531. if(!oNode){return;}
  1532. var oFirstNode = oNode.firstChild?oNode.firstChild:oNode;
  1533. var oLastNode = oNode.lastChild?oNode.lastChild:oNode;
  1534. this.reset(this._window);
  1535. if(oFirstNode.nodeType == 3){
  1536. this.setStart(oFirstNode, 0, true);
  1537. }else{
  1538. this.setStartBefore(oFirstNode);
  1539. }
  1540. if(oLastNode.nodeType == 3){
  1541. this.setEnd(oLastNode, oLastNode.nodeValue.length, true);
  1542. }else{
  1543. this.setEndAfter(oLastNode);
  1544. }
  1545. },
  1546. /**
  1547. * 노드의 취소선/밑줄 정보를 확인한다
  1548. * 관련 BTS [SMARTEDITORSUS-26]
  1549. * @param {Node} oNode 취소선/밑줄을 확인할 노드
  1550. * @param {String} sValue textDecoration 정보
  1551. * @see nhn.HuskyRange#_checkTextDecoration
  1552. */
  1553. _hasTextDecoration : function(oNode, sValue){
  1554. if(!oNode || !oNode.style){
  1555. return false;
  1556. }
  1557. if(oNode.style.textDecoration.indexOf(sValue) > -1){
  1558. return true;
  1559. }
  1560. if(sValue === "underline" && oNode.tagName === "U"){
  1561. return true;
  1562. }
  1563. if(sValue === "line-through" && (oNode.tagName === "S" || oNode.tagName === "STRIKE")){
  1564. return true;
  1565. }
  1566. return false;
  1567. },
  1568. /**
  1569. * 노드에 취소선/밑줄을 적용한다
  1570. * 관련 BTS [SMARTEDITORSUS-26]
  1571. * [FF] 노드의 Style textDecoration 추가한다
  1572. * [FF ] U/STRIKE 태그를 추가한다
  1573. * @param {Node} oNode 취소선/밑줄을 적용할 노드
  1574. * @param {String} sValue textDecoration 정보
  1575. * @see nhn.HuskyRange#_checkTextDecoration
  1576. */
  1577. _setTextDecoration : function(oNode, sValue){
  1578. if (jindo.$Agent().navigator().firefox) { // FF
  1579. oNode.style.textDecoration = (oNode.style.textDecoration) ? oNode.style.textDecoration + " " + sValue : sValue;
  1580. }
  1581. else{
  1582. if(sValue === "underline"){
  1583. oNode.innerHTML = "<U>" + oNode.innerHTML + "</U>"
  1584. }else if(sValue === "line-through"){
  1585. oNode.innerHTML = "<STRIKE>" + oNode.innerHTML + "</STRIKE>"
  1586. }
  1587. }
  1588. },
  1589. /**
  1590. * 인자로 전달받은 노드 상위의 취소선/밑줄 정보를 확인하여 노드에 적용한다
  1591. * 관련 BTS [SMARTEDITORSUS-26]
  1592. * @param {Node} oNode 취소선/밑줄을 적용할 노드
  1593. */
  1594. _checkTextDecoration : function(oNode){
  1595. if(oNode.tagName !== "SPAN"){
  1596. return;
  1597. }
  1598. var bUnderline = false,
  1599. bLineThrough = false,
  1600. sTextDecoration = "",
  1601. oParentNode = null;
  1602. oChildNode = oNode.firstChild;
  1603. /* check child */
  1604. while(oChildNode){
  1605. if(oChildNode.nodeType === 1){
  1606. bUnderline = (bUnderline || oChildNode.tagName === "U");
  1607. bLineThrough = (bLineThrough || oChildNode.tagName === "S" || oChildNode.tagName === "STRIKE");
  1608. }
  1609. if(bUnderline && bLineThrough){
  1610. return;
  1611. }
  1612. oChildNode = oChildNode.nextSibling;
  1613. }
  1614. oParentNode = nhn.DOMFix.parentNode(oNode);
  1615. /* check parent */
  1616. while(oParentNode && oParentNode.tagName !== "BODY"){
  1617. if(oParentNode.nodeType !== 1){
  1618. oParentNode = nhn.DOMFix.parentNode(oParentNode);
  1619. continue;
  1620. }
  1621. if(!bUnderline && this._hasTextDecoration(oParentNode, "underline")){
  1622. bUnderline = true;
  1623. this._setTextDecoration(oNode, "underline"); // set underline
  1624. }
  1625. if(!bLineThrough && this._hasTextDecoration(oParentNode, "line-through")){
  1626. bLineThrough = true;
  1627. this._setTextDecoration(oNode, "line-through"); // set line-through
  1628. }
  1629. if(bUnderline && bLineThrough){
  1630. return;
  1631. }
  1632. oParentNode = nhn.DOMFix.parentNode(oParentNode);
  1633. }
  1634. },
  1635. /**
  1636. * Range에 속한 노드들에 스타일을 적용한다
  1637. * @param {Object} oStyle 적용할 스타일을 가지는 Object () 글꼴 적용의 경우 { color : "#0075c8" }
  1638. * @param {Object} [oAttribute] 적용할 속성을 가지는 Object () 맞춤범 검사의 경우 { _sm2_spchk: "강남콩", class: "se2_check_spell" }
  1639. * @param {String} [sNewSpanMarker] 새로 추가된 SPAN 노드를 나중에 따로 처리해야하는 경우 마킹을 위해 사용하는 문자열
  1640. * @param {Boolean} [bIncludeLI] LI 스타일 적용에 포함할 것인지의 여부 [COM-1051] _getStyleParentNodes 메서드 참고하기
  1641. * @param {Boolean} [bCheckTextDecoration] 취소선/밑줄 처리를 적용할 것인지 여부 [SMARTEDITORSUS-26] _setTextDecoration 메서드 참고하기
  1642. */
  1643. styleRange : function(oStyle, oAttribute, sNewSpanMarker, bIncludeLI, bCheckTextDecoration){
  1644. var aStyleParents = this.aStyleParents = this._getStyleParentNodes(sNewSpanMarker, bIncludeLI);
  1645. if(aStyleParents.length < 1){return;}
  1646. var sName, sValue;
  1647. for(var i=0; i<aStyleParents.length; i++){
  1648. for(var x in oStyle){
  1649. sName = x;
  1650. sValue = oStyle[sName];
  1651. if(typeof sValue != "string"){continue;}
  1652. // [SMARTEDITORSUS-26] 글꼴 색을 적용할 때 취소선/밑줄의 색상도 처리되도록 추가
  1653. if(bCheckTextDecoration && oStyle.color){
  1654. this._checkTextDecoration(aStyleParents[i]);
  1655. }
  1656. aStyleParents[i].style[sName] = sValue;
  1657. }
  1658. if(!oAttribute){continue;}
  1659. for(var x in oAttribute){
  1660. sName = x;
  1661. sValue = oAttribute[sName];
  1662. if(typeof sValue != "string"){continue;}
  1663. if(sName == "class"){
  1664. jindo.$Element(aStyleParents[i]).addClass(sValue);
  1665. }else{
  1666. aStyleParents[i].setAttribute(sName, sValue);
  1667. }
  1668. }
  1669. }
  1670. this.reset(this._window);
  1671. this.setStartBefore(aStyleParents[0]);
  1672. this.setEndAfter(aStyleParents[aStyleParents.length-1]);
  1673. },
  1674. expandBothEnds : function(){
  1675. this.expandStart();
  1676. this.expandEnd();
  1677. },
  1678. expandStart : function(){
  1679. if(this.startContainer.nodeType == 3 && this.startOffset !== 0){return;}
  1680. var elActualStartNode = this._getActualStartNode(this.startContainer, this.startOffset);
  1681. elActualStartNode = this._getPrevNode(elActualStartNode);
  1682. if(elActualStartNode.tagName == "BODY"){
  1683. this.setStartBefore(elActualStartNode);
  1684. }else{
  1685. this.setStartAfter(elActualStartNode);
  1686. }
  1687. },
  1688. expandEnd : function(){
  1689. if(this.endContainer.nodeType == 3 && this.endOffset < this.endContainer.nodeValue.length){return;}
  1690. var elActualEndNode = this._getActualEndNode(this.endContainer, this.endOffset);
  1691. elActualEndNode = this._getNextNode(elActualEndNode);
  1692. if(elActualEndNode.tagName == "BODY"){
  1693. this.setEndAfter(elActualEndNode);
  1694. }else{
  1695. this.setEndBefore(elActualEndNode);
  1696. }
  1697. },
  1698. /**
  1699. * Style 적용할 노드를 가져온다
  1700. * @param {String} [sNewSpanMarker] 새로 추가하는 SPAN 노드를 마킹을 위해 사용하는 문자열
  1701. * @param {Boolean} [bIncludeLI] LI 스타일 적용에 포함할 것인지의 여부
  1702. * @return {Array} Style 적용할 노드 배열
  1703. */
  1704. _getStyleParentNodes : function(sNewSpanMarker, bIncludeLI){
  1705. this._splitTextEndNodesOfTheRange();
  1706. var oSNode = this.getStartNode();
  1707. var oENode = this.getEndNode();
  1708. var aAllNodes = this._getNodesInRange();
  1709. var aResult = [];
  1710. var nResult = 0;
  1711. var oNode, oTmpNode, iStartRelPos, iEndRelPos, oSpan;
  1712. var nInitialLength = aAllNodes.length;
  1713. var arAllBottomNodes = jindo.$A(aAllNodes).filter(function(v){return (!v.firstChild || (bIncludeLI && v.tagName=="LI"));});
  1714. // [COM-1051] 본문내용을 한 줄만 입력하고 번호 매긴 상태에서 글자크기를 변경하면 번호크기는 변하지 않는 문제
  1715. // 부모 노드 중 LI 가 있고, 해당 LI 의 모든 자식 노드가 선택된 상태라면 LI에도 스타일을 적용하도록 처리함
  1716. // --- Range 에 LI 가 포함되지 않은 경우, LI 를 포함하도록 처리
  1717. var elTmpNode = this.commonAncestorContainer;
  1718. if(bIncludeLI){
  1719. while(elTmpNode){
  1720. if(elTmpNode.tagName == "LI"){
  1721. if(this._isFullyContained(elTmpNode, arAllBottomNodes)){
  1722. aResult[nResult++] = elTmpNode;
  1723. }
  1724. break;
  1725. }
  1726. elTmpNode = elTmpNode.parentNode;
  1727. }
  1728. }
  1729. for(var i=0; i<nInitialLength; i++){
  1730. oNode = aAllNodes[i];
  1731. if(!oNode){continue;}
  1732. // --- Range 에 LI 가 포함된 경우에 대한 LI 확인
  1733. if(bIncludeLI && oNode.tagName == "LI" && this._isFullyContained(oNode, arAllBottomNodes)){
  1734. aResult[nResult++] = oNode;
  1735. continue;
  1736. }
  1737. if(oNode.nodeType != 3){continue;}
  1738. if(oNode.nodeValue == "" || oNode.nodeValue.match(/^(\r|\n)+$/)){continue;}
  1739. var oParentNode = nhn.DOMFix.parentNode(oNode);
  1740. // 부모 노드가 SPAN 인 경우에는 새로운 SPAN 을 생성하지 않고 SPAN 을 리턴 배열에 추가함
  1741. if(oParentNode.tagName == "SPAN"){
  1742. if(this._isFullyContained(oParentNode, arAllBottomNodes, oNode)){
  1743. aResult[nResult++] = oParentNode;
  1744. continue;
  1745. }
  1746. }else{
  1747. // [SMARTEDITORSUS-1513] 선택된 영역을 single node로 감싸는 상위 span 노드가 있으면 리턴 배열에 추가
  1748. var oParentSingleSpan = this._findParentSingleSpan(oParentNode);
  1749. if(oParentSingleSpan){
  1750. aResult[nResult++] = oParentSingleSpan;
  1751. continue;
  1752. }
  1753. }
  1754. oSpan = this._document.createElement("SPAN");
  1755. oParentNode.insertBefore(oSpan, oNode);
  1756. oSpan.appendChild(oNode);
  1757. aResult[nResult++] = oSpan;
  1758. if(sNewSpanMarker){oSpan.setAttribute(sNewSpanMarker, "true");}
  1759. }
  1760. this.setStartBefore(oSNode);
  1761. this.setEndAfter(oENode);
  1762. return aResult;
  1763. },
  1764. /**
  1765. * [SMARTEDITORSUS-1513][SMARTEDITORSUS-1648] 해당노드가 single child로 묶이는 상위 span 노드가 있는지 찾는다.
  1766. * @param {Node} oNode 검사할 노드
  1767. * @return {Element} 상위 span 노드, 없으면 null
  1768. */
  1769. _findParentSingleSpan : function(oNode){
  1770. if(!oNode){
  1771. return null;
  1772. }
  1773. // ZWNBSP 문자가 같이 있는 경우도 있기 때문에 실제 노드를 카운팅해야 함
  1774. for(var i = 0, nCnt = 0, sValue, oChild, aChildNodes = oNode.childNodes; (oChild = aChildNodes[i]); i++){
  1775. sValue = oChild.nodeValue;
  1776. if(this._rxCursorHolder.test(sValue)){
  1777. continue;
  1778. }else{
  1779. nCnt++;
  1780. }
  1781. if(nCnt > 1){ // 싱글노드가 아니면 더이상 찾지 않고 null 반환
  1782. return null;
  1783. }
  1784. }
  1785. if(oNode.nodeName === "SPAN"){
  1786. return oNode;
  1787. }else{
  1788. return this._findParentSingleSpan(oNode.parentNode);
  1789. }
  1790. },
  1791. /**
  1792. * 컨테이너 엘리먼트(elContainer) 모든 자식노드가 노드 배열(waAllNodes) 속하는지 확인한다
  1793. * 번째 자식 노드와 마지막 자식 노드가 노드 배열에 속하는지를 확인한다
  1794. * @param {Element} elContainer 컨테이너 엘리먼트
  1795. * @param {jindo.$A} waAllNodes Node $A 배열
  1796. * @param {Node} [oNode] 성능을 위한 옵션 노드로 컨테이너의 번째 혹은 마지막 자식 노드와 같으면 indexOf 함수 사용을 줄일 있음
  1797. * @return {Array} Style 적용할 노드 배열
  1798. */
  1799. // check if all the child nodes of elContainer are in waAllNodes
  1800. _isFullyContained : function(elContainer, waAllNodes, oNode){
  1801. var nSIdx, nEIdx;
  1802. var oTmpNode = this._getVeryFirstRealChild(elContainer);
  1803. // do quick checks before trying indexOf() because indexOf() function is very slow
  1804. // oNode is optional
  1805. if(oNode && oTmpNode == oNode){
  1806. nSIdx = 1;
  1807. }else{
  1808. nSIdx = waAllNodes.indexOf(oTmpNode);
  1809. }
  1810. if(nSIdx != -1){
  1811. oTmpNode = this._getVeryLastRealChild(elContainer);
  1812. if(oNode && oTmpNode == oNode){
  1813. nEIdx = 1;
  1814. }else{
  1815. nEIdx = waAllNodes.indexOf(oTmpNode);
  1816. }
  1817. }
  1818. return (nSIdx != -1 && nEIdx != -1);
  1819. },
  1820. _getVeryFirstChild : function(oNode){
  1821. if(oNode.firstChild){return this._getVeryFirstChild(oNode.firstChild);}
  1822. return oNode;
  1823. },
  1824. _getVeryLastChild : function(oNode){
  1825. if(oNode.lastChild){return this._getVeryLastChild(oNode.lastChild);}
  1826. return oNode;
  1827. },
  1828. _getFirstRealChild : function(oNode){
  1829. var oFirstNode = oNode.firstChild;
  1830. while(oFirstNode && oFirstNode.nodeType == 3 && oFirstNode.nodeValue == ""){oFirstNode = oFirstNode.nextSibling;}
  1831. return oFirstNode;
  1832. },
  1833. _getLastRealChild : function(oNode){
  1834. var oLastNode = oNode.lastChild;
  1835. while(oLastNode && oLastNode.nodeType == 3 && oLastNode.nodeValue == ""){oLastNode = oLastNode.previousSibling;}
  1836. return oLastNode;
  1837. },
  1838. _getVeryFirstRealChild : function(oNode){
  1839. var oFirstNode = this._getFirstRealChild(oNode);
  1840. if(oFirstNode){return this._getVeryFirstRealChild(oFirstNode);}
  1841. return oNode;
  1842. },
  1843. _getVeryLastRealChild : function(oNode){
  1844. var oLastNode = this._getLastRealChild(oNode);
  1845. if(oLastNode){return this._getVeryLastChild(oLastNode);}
  1846. return oNode;
  1847. },
  1848. _getLineStartInfo : function(node){
  1849. var frontEndFinal = null;
  1850. var frontEnd = node;
  1851. var lineBreaker = node;
  1852. var bParentBreak = false;
  1853. var rxLineBreaker = this.rxLineBreaker;
  1854. // vertical(parent) search
  1855. function getLineStart(node){
  1856. if(!node){return;}
  1857. if(frontEndFinal){return;}
  1858. if(rxLineBreaker.test(node.tagName)){
  1859. lineBreaker = node;
  1860. frontEndFinal = frontEnd;
  1861. bParentBreak = true;
  1862. return;
  1863. }else{
  1864. frontEnd = node;
  1865. }
  1866. getFrontEnd(node.previousSibling);
  1867. if(frontEndFinal){return;}
  1868. getLineStart(nhn.DOMFix.parentNode(node));
  1869. }
  1870. // horizontal(sibling) search
  1871. function getFrontEnd(node){
  1872. if(!node){return;}
  1873. if(frontEndFinal){return;}
  1874. if(rxLineBreaker.test(node.tagName)){
  1875. lineBreaker = node;
  1876. frontEndFinal = frontEnd;
  1877. bParentBreak = false;
  1878. return;
  1879. }
  1880. if(node.firstChild && node.tagName != "TABLE"){
  1881. var curNode = node.lastChild;
  1882. while(curNode && !frontEndFinal){
  1883. getFrontEnd(curNode);
  1884. curNode = curNode.previousSibling;
  1885. }
  1886. }else{
  1887. frontEnd = node;
  1888. }
  1889. if(!frontEndFinal){
  1890. getFrontEnd(node.previousSibling);
  1891. }
  1892. }
  1893. if(rxLineBreaker.test(node.tagName)){
  1894. frontEndFinal = node;
  1895. }else{
  1896. getLineStart(node);
  1897. }
  1898. return {oNode: frontEndFinal, oLineBreaker: lineBreaker, bParentBreak: bParentBreak};
  1899. },
  1900. _getLineEndInfo : function(node){
  1901. var backEndFinal = null;
  1902. var backEnd = node;
  1903. var lineBreaker = node;
  1904. var bParentBreak = false;
  1905. var rxLineBreaker = this.rxLineBreaker;
  1906. // vertical(parent) search
  1907. function getLineEnd(node){
  1908. if(!node){return;}
  1909. if(backEndFinal){return;}
  1910. if(rxLineBreaker.test(node.tagName)){
  1911. lineBreaker = node;
  1912. backEndFinal = backEnd;
  1913. bParentBreak = true;
  1914. return;
  1915. }else{
  1916. backEnd = node;
  1917. }
  1918. getBackEnd(node.nextSibling);
  1919. if(backEndFinal){return;}
  1920. getLineEnd(nhn.DOMFix.parentNode(node));
  1921. }
  1922. // horizontal(sibling) search
  1923. function getBackEnd(node){
  1924. if(!node){return;}
  1925. if(backEndFinal){return;}
  1926. if(rxLineBreaker.test(node.tagName)){
  1927. lineBreaker = node;
  1928. backEndFinal = backEnd;
  1929. bParentBreak = false;
  1930. return;
  1931. }
  1932. if(node.firstChild && node.tagName != "TABLE"){
  1933. var curNode = node.firstChild;
  1934. while(curNode && !backEndFinal){
  1935. getBackEnd(curNode);
  1936. curNode = curNode.nextSibling;
  1937. }
  1938. }else{
  1939. backEnd = node;
  1940. }
  1941. if(!backEndFinal){
  1942. getBackEnd(node.nextSibling);
  1943. }
  1944. }
  1945. if(rxLineBreaker.test(node.tagName)){
  1946. backEndFinal = node;
  1947. }else{
  1948. getLineEnd(node);
  1949. }
  1950. return {oNode: backEndFinal, oLineBreaker: lineBreaker, bParentBreak: bParentBreak};
  1951. },
  1952. getLineInfo : function(bAfter){
  1953. var bAfter = bAfter || false;
  1954. var oSNode = this.getStartNode();
  1955. var oENode = this.getEndNode();
  1956. // oSNode && oENode will be null if the range is currently collapsed and the cursor is not located in the middle of a text node.
  1957. if(!oSNode){oSNode = this.getNodeAroundRange(!bAfter, true);}
  1958. if(!oENode){oENode = this.getNodeAroundRange(!bAfter, true);}
  1959. var oStart = this._getLineStartInfo(oSNode);
  1960. var oStartNode = oStart.oNode;
  1961. var oEnd = this._getLineEndInfo(oENode);
  1962. var oEndNode = oEnd.oNode;
  1963. if(oSNode != oStartNode || oENode != oEndNode){
  1964. // check if the start node is positioned after the range's ending point
  1965. // or
  1966. // if the end node is positioned before the range's starting point
  1967. var iRelativeStartPos = this._compareEndPoint(nhn.DOMFix.parentNode(oStartNode), this._getPosIdx(oStartNode), this.endContainer, this.endOffset);
  1968. var iRelativeEndPos = this._compareEndPoint(nhn.DOMFix.parentNode(oEndNode), this._getPosIdx(oEndNode)+1, this.startContainer, this.startOffset);
  1969. if(!(iRelativeStartPos <= 0 && iRelativeEndPos >= 0)){
  1970. oSNode = this.getNodeAroundRange(false, true);
  1971. oENode = this.getNodeAroundRange(false, true);
  1972. oStart = this._getLineStartInfo(oSNode);
  1973. oEnd = this._getLineEndInfo(oENode);
  1974. }
  1975. }
  1976. return {oStart: oStart, oEnd: oEnd};
  1977. },
  1978. /**
  1979. * 커서홀더나 공백을 제외한 child 노드가 하나만 있는 경우만 node 반환한다.
  1980. * @param {Node} oNode 확인할 노드
  1981. * @return {Node} single child node를 반환한다. 없거나 두개 이상이면 null 반환
  1982. */
  1983. _findSingleChild : function(oNode){
  1984. if(!oNode){
  1985. return null;
  1986. }
  1987. var oSingleChild = null;
  1988. // ZWNBSP 문자가 같이 있는 경우도 있기 때문에 실제 노드를 카운팅해야 함
  1989. for(var i = 0, nCnt = 0, sValue, oChild, aChildNodes = oNode.childNodes; (oChild = aChildNodes[i]); i++){
  1990. sValue = oChild.nodeValue;
  1991. if(this._rxCursorHolder.test(sValue)){
  1992. continue;
  1993. }else{
  1994. oSingleChild = oChild;
  1995. nCnt++;
  1996. }
  1997. if(nCnt > 1){ // 싱글노드가 아니면 더이상 찾지 않고 null 반환
  1998. return null;
  1999. }
  2000. }
  2001. return oSingleChild;
  2002. },
  2003. /**
  2004. * 해당요소의 최하위까지 검색해 커서홀더만 감싸고 있는지 여부를 반환
  2005. * @param {Node} oNode 확인할 노드
  2006. * @return {Boolean} 커서홀더만 있는 경우 true 반환
  2007. */
  2008. _hasCursorHolderOnly : function(oNode){
  2009. if(!oNode || oNode.nodeType !== 1){
  2010. return false;
  2011. }
  2012. if(this._rxCursorHolder.test(oNode.innerHTML)){
  2013. return true;
  2014. }else{
  2015. return this._hasCursorHolderOnly(this._findSingleChild(oNode));
  2016. }
  2017. }
  2018. }).extend(nhn.W3CDOMRange);
  2019. /**
  2020. * @fileOverview This file contains cross-browser selection function
  2021. * @name BrowserSelection.js
  2022. */
  2023. nhn.BrowserSelection = function(win){
  2024. this.init = function(win){
  2025. this._window = win || window;
  2026. this._document = this._window.document;
  2027. };
  2028. this.init(win);
  2029. // [SMARTEDITORSUS-888] IE9 이후로 document.createRange 를 지원
  2030. /* var oAgentInfo = jindo.$Agent().navigator();
  2031. if(oAgentInfo.ie){
  2032. nhn.BrowserSelectionImpl_IE.apply(this);
  2033. }else{
  2034. nhn.BrowserSelectionImpl_FF.apply(this);
  2035. }*/
  2036. if(!!this._document.createRange){
  2037. nhn.BrowserSelectionImpl_FF.apply(this);
  2038. }else{
  2039. nhn.BrowserSelectionImpl_IE.apply(this);
  2040. }
  2041. this.selectRange = function(oRng){
  2042. this.selectNone();
  2043. this.addRange(oRng);
  2044. };
  2045. this.selectionLoaded = true;
  2046. if(!this._oSelection){this.selectionLoaded = false;}
  2047. };
  2048. nhn.BrowserSelectionImpl_FF = function(){
  2049. this._oSelection = this._window.getSelection();
  2050. this.getRangeAt = function(iNum){
  2051. iNum = iNum || 0;
  2052. try{
  2053. var oFFRange = this._oSelection.getRangeAt(iNum);
  2054. }catch(e){return new nhn.W3CDOMRange(this._window);}
  2055. return this._FFRange2W3CRange(oFFRange);
  2056. };
  2057. this.addRange = function(oW3CRange){
  2058. var oFFRange = this._W3CRange2FFRange(oW3CRange);
  2059. this._oSelection.addRange(oFFRange);
  2060. };
  2061. this.selectNone = function(){
  2062. this._oSelection.removeAllRanges();
  2063. };
  2064. this.getCommonAncestorContainer = function(oW3CRange){
  2065. var oFFRange = this._W3CRange2FFRange(oW3CRange);
  2066. return oFFRange.commonAncestorContainer;
  2067. };
  2068. this.isCollapsed = function(oW3CRange){
  2069. var oFFRange = this._W3CRange2FFRange(oW3CRange);
  2070. return oFFRange.collapsed;
  2071. };
  2072. this.compareEndPoints = function(elContainerA, nOffsetA, elContainerB, nOffsetB){
  2073. var oFFRangeA = this._document.createRange();
  2074. var oFFRangeB = this._document.createRange();
  2075. oFFRangeA.setStart(elContainerA, nOffsetA);
  2076. oFFRangeB.setStart(elContainerB, nOffsetB);
  2077. oFFRangeA.collapse(true);
  2078. oFFRangeB.collapse(true);
  2079. try{
  2080. return oFFRangeA.compareBoundaryPoints(1, oFFRangeB);
  2081. }catch(e){
  2082. return 1;
  2083. }
  2084. };
  2085. this._FFRange2W3CRange = function(oFFRange){
  2086. var oW3CRange = new nhn.W3CDOMRange(this._window);
  2087. oW3CRange.setStart(oFFRange.startContainer, oFFRange.startOffset, true);
  2088. oW3CRange.setEnd(oFFRange.endContainer, oFFRange.endOffset, true);
  2089. return oW3CRange;
  2090. };
  2091. this._W3CRange2FFRange = function(oW3CRange){
  2092. var oFFRange = this._document.createRange();
  2093. oFFRange.setStart(oW3CRange.startContainer, oW3CRange.startOffset);
  2094. oFFRange.setEnd(oW3CRange.endContainer, oW3CRange.endOffset);
  2095. return oFFRange;
  2096. };
  2097. };
  2098. nhn.BrowserSelectionImpl_IE = function(){
  2099. this._oSelection = this._document.selection;
  2100. this.oLastRange = {
  2101. oBrowserRange : null,
  2102. elStartContainer : null,
  2103. nStartOffset : -1,
  2104. elEndContainer : null,
  2105. nEndOffset : -1
  2106. };
  2107. this._updateLastRange = function(oBrowserRange, oW3CRange){
  2108. this.oLastRange.oBrowserRange = oBrowserRange;
  2109. this.oLastRange.elStartContainer = oW3CRange.startContainer;
  2110. this.oLastRange.nStartOffset = oW3CRange.startOffset;
  2111. this.oLastRange.elEndContainer = oW3CRange.endContainer;
  2112. this.oLastRange.nEndOffset = oW3CRange.endOffset;
  2113. };
  2114. this.getRangeAt = function(iNum){
  2115. iNum = iNum || 0;
  2116. var oW3CRange, oBrowserRange;
  2117. if(this._oSelection.type == "Control"){
  2118. oW3CRange = new nhn.W3CDOMRange(this._window);
  2119. var oSelectedNode = this._oSelection.createRange().item(iNum);
  2120. // if the selction occurs in a different document, ignore
  2121. if(!oSelectedNode || oSelectedNode.ownerDocument != this._document){return oW3CRange;}
  2122. oW3CRange.selectNode(oSelectedNode);
  2123. return oW3CRange;
  2124. }else{
  2125. //oBrowserRange = this._oSelection.createRangeCollection().item(iNum);
  2126. oBrowserRange = this._oSelection.createRange();
  2127. var oSelectedNode = oBrowserRange.parentElement();
  2128. // if the selction occurs in a different document, ignore
  2129. if(!oSelectedNode || oSelectedNode.ownerDocument != this._document){
  2130. oW3CRange = new nhn.W3CDOMRange(this._window);
  2131. return oW3CRange;
  2132. }
  2133. oW3CRange = this._IERange2W3CRange(oBrowserRange);
  2134. return oW3CRange;
  2135. }
  2136. };
  2137. this.addRange = function(oW3CRange){
  2138. var oIERange = this._W3CRange2IERange(oW3CRange);
  2139. oIERange.select();
  2140. };
  2141. this.selectNone = function(){
  2142. this._oSelection.empty();
  2143. };
  2144. this.getCommonAncestorContainer = function(oW3CRange){
  2145. return this._W3CRange2IERange(oW3CRange).parentElement();
  2146. };
  2147. this.isCollapsed = function(oW3CRange){
  2148. var oRange = this._W3CRange2IERange(oW3CRange);
  2149. var oRange2 = oRange.duplicate();
  2150. oRange2.collapse();
  2151. return oRange.isEqual(oRange2);
  2152. };
  2153. this.compareEndPoints = function(elContainerA, nOffsetA, elContainerB, nOffsetB){
  2154. var oIERangeA, oIERangeB;
  2155. if(elContainerA === this.oLastRange.elStartContainer && nOffsetA === this.oLastRange.nStartOffset){
  2156. oIERangeA = this.oLastRange.oBrowserRange.duplicate();
  2157. oIERangeA.collapse(true);
  2158. }else{
  2159. if(elContainerA === this.oLastRange.elEndContainer && nOffsetA === this.oLastRange.nEndOffset){
  2160. oIERangeA = this.oLastRange.oBrowserRange.duplicate();
  2161. oIERangeA.collapse(false);
  2162. }else{
  2163. oIERangeA = this._getIERangeAt(elContainerA, nOffsetA);
  2164. }
  2165. }
  2166. if(elContainerB === this.oLastRange.elStartContainer && nOffsetB === this.oLastRange.nStartOffset){
  2167. oIERangeB = this.oLastRange.oBrowserRange.duplicate();
  2168. oIERangeB.collapse(true);
  2169. }else{
  2170. if(elContainerB === this.oLastRange.elEndContainer && nOffsetB === this.oLastRange.nEndOffset){
  2171. oIERangeB = this.oLastRange.oBrowserRange.duplicate();
  2172. oIERangeB.collapse(false);
  2173. }else{
  2174. oIERangeB = this._getIERangeAt(elContainerB, nOffsetB);
  2175. }
  2176. }
  2177. return oIERangeA.compareEndPoints("StartToStart", oIERangeB);
  2178. };
  2179. this._W3CRange2IERange = function(oW3CRange){
  2180. if(this.oLastRange.elStartContainer === oW3CRange.startContainer &&
  2181. this.oLastRange.nStartOffset === oW3CRange.startOffset &&
  2182. this.oLastRange.elEndContainer === oW3CRange.endContainer &&
  2183. this.oLastRange.nEndOffset === oW3CRange.endOffset){
  2184. return this.oLastRange.oBrowserRange;
  2185. }
  2186. var oStartIERange = this._getIERangeAt(oW3CRange.startContainer, oW3CRange.startOffset);
  2187. var oEndIERange = this._getIERangeAt(oW3CRange.endContainer, oW3CRange.endOffset);
  2188. oStartIERange.setEndPoint("EndToEnd", oEndIERange);
  2189. this._updateLastRange(oStartIERange, oW3CRange);
  2190. return oStartIERange;
  2191. };
  2192. this._getIERangeAt = function(oW3CContainer, iW3COffset){
  2193. var oIERange = this._document.body.createTextRange();
  2194. var oEndPointInfoForIERange = this._getSelectableNodeAndOffsetForIE(oW3CContainer, iW3COffset);
  2195. var oSelectableNode = oEndPointInfoForIERange.oSelectableNodeForIE;
  2196. var iIEOffset = oEndPointInfoForIERange.iOffsetForIE;
  2197. oIERange.moveToElementText(oSelectableNode);
  2198. oIERange.collapse(oEndPointInfoForIERange.bCollapseToStart);
  2199. oIERange.moveStart("character", iIEOffset);
  2200. return oIERange;
  2201. };
  2202. this._getSelectableNodeAndOffsetForIE = function(oW3CContainer, iW3COffset){
  2203. // var oIERange = this._document.body.createTextRange();
  2204. var oNonTextNode = null;
  2205. var aChildNodes = null;
  2206. var iNumOfLeftNodesToCount = 0;
  2207. if(oW3CContainer.nodeType == 3){
  2208. oNonTextNode = nhn.DOMFix.parentNode(oW3CContainer);
  2209. aChildNodes = nhn.DOMFix.childNodes(oNonTextNode);
  2210. iNumOfLeftNodesToCount = aChildNodes.length;
  2211. }else{
  2212. oNonTextNode = oW3CContainer;
  2213. aChildNodes = nhn.DOMFix.childNodes(oNonTextNode);
  2214. //iNumOfLeftNodesToCount = iW3COffset;
  2215. iNumOfLeftNodesToCount = (iW3COffset<aChildNodes.length)?iW3COffset:aChildNodes.length;
  2216. }
  2217. //@ room 4 improvement
  2218. var oNodeTester = null;
  2219. var iResultOffset = 0;
  2220. var bCollapseToStart = true;
  2221. for(var i=0; i<iNumOfLeftNodesToCount; i++){
  2222. oNodeTester = aChildNodes[i];
  2223. if(oNodeTester.nodeType == 3){
  2224. if(oNodeTester == oW3CContainer){break;}
  2225. iResultOffset += oNodeTester.nodeValue.length;
  2226. }else{
  2227. // oIERange.moveToElementText(oNodeTester);
  2228. oNonTextNode = oNodeTester;
  2229. iResultOffset = 0;
  2230. bCollapseToStart = false;
  2231. }
  2232. }
  2233. if(oW3CContainer.nodeType == 3){iResultOffset += iW3COffset;}
  2234. return {oSelectableNodeForIE:oNonTextNode, iOffsetForIE: iResultOffset, bCollapseToStart: bCollapseToStart};
  2235. };
  2236. this._IERange2W3CRange = function(oIERange){
  2237. var oW3CRange = new nhn.W3CDOMRange(this._window);
  2238. var oIEPointRange = null;
  2239. var oPosition = null;
  2240. oIEPointRange = oIERange.duplicate();
  2241. oIEPointRange.collapse(true);
  2242. oPosition = this._getW3CContainerAndOffset(oIEPointRange, true);
  2243. oW3CRange.setStart(oPosition.oContainer, oPosition.iOffset, true, true);
  2244. var oCollapsedChecker = oIERange.duplicate();
  2245. oCollapsedChecker.collapse(true);
  2246. if(oCollapsedChecker.isEqual(oIERange)){
  2247. oW3CRange.collapse(true);
  2248. }else{
  2249. oIEPointRange = oIERange.duplicate();
  2250. oIEPointRange.collapse(false);
  2251. oPosition = this._getW3CContainerAndOffset(oIEPointRange);
  2252. oW3CRange.setEnd(oPosition.oContainer, oPosition.iOffset, true);
  2253. }
  2254. this._updateLastRange(oIERange, oW3CRange);
  2255. return oW3CRange;
  2256. };
  2257. this._getW3CContainerAndOffset = function(oIEPointRange, bStartPt){
  2258. var oRgOrigPoint = oIEPointRange;
  2259. var oContainer = oRgOrigPoint.parentElement();
  2260. var offset = -1;
  2261. var oRgTester = this._document.body.createTextRange();
  2262. var aChildNodes = nhn.DOMFix.childNodes(oContainer);
  2263. var oPrevNonTextNode = null;
  2264. var pointRangeIdx = 0;
  2265. for(var i=0;i<aChildNodes.length;i++){
  2266. if(aChildNodes[i].nodeType == 3){continue;}
  2267. oRgTester.moveToElementText(aChildNodes[i]);
  2268. if(oRgTester.compareEndPoints("StartToStart", oIEPointRange)>=0){break;}
  2269. oPrevNonTextNode = aChildNodes[i];
  2270. }
  2271. var pointRangeIdx = i;
  2272. if(pointRangeIdx !== 0 && aChildNodes[pointRangeIdx-1].nodeType == 3){
  2273. var oRgTextStart = this._document.body.createTextRange();
  2274. var oCurTextNode = null;
  2275. if(oPrevNonTextNode){
  2276. oRgTextStart.moveToElementText(oPrevNonTextNode);
  2277. oRgTextStart.collapse(false);
  2278. oCurTextNode = oPrevNonTextNode.nextSibling;
  2279. }else{
  2280. oRgTextStart.moveToElementText(oContainer);
  2281. oRgTextStart.collapse(true);
  2282. oCurTextNode = oContainer.firstChild;
  2283. }
  2284. var oRgTextsUpToThePoint = oRgOrigPoint.duplicate();
  2285. oRgTextsUpToThePoint.setEndPoint("StartToStart", oRgTextStart);
  2286. var textCount = oRgTextsUpToThePoint.text.replace(/[\r\n]/g,"").length;
  2287. while(textCount > oCurTextNode.nodeValue.length && oCurTextNode.nextSibling){
  2288. textCount -= oCurTextNode.nodeValue.length;
  2289. oCurTextNode = oCurTextNode.nextSibling;
  2290. }
  2291. // this will enforce IE to re-reference oCurTextNode
  2292. var oTmp = oCurTextNode.nodeValue;
  2293. if(bStartPt && oCurTextNode.nextSibling && oCurTextNode.nextSibling.nodeType == 3 && textCount == oCurTextNode.nodeValue.length){
  2294. textCount -= oCurTextNode.nodeValue.length;
  2295. oCurTextNode = oCurTextNode.nextSibling;
  2296. }
  2297. oContainer = oCurTextNode;
  2298. offset = textCount;
  2299. }else{
  2300. oContainer = oRgOrigPoint.parentElement();
  2301. offset = pointRangeIdx;
  2302. }
  2303. return {"oContainer" : oContainer, "iOffset" : offset};
  2304. };
  2305. };
  2306. nhn.DOMFix = new (jindo.$Class({
  2307. $init : function(){
  2308. if(jindo.$Agent().navigator().ie || jindo.$Agent().navigator().opera){
  2309. this.childNodes = this._childNodes_Fix;
  2310. this.parentNode = this._parentNode_Fix;
  2311. }else{
  2312. this.childNodes = this._childNodes_Native;
  2313. this.parentNode = this._parentNode_Native;
  2314. }
  2315. },
  2316. _parentNode_Native : function(elNode){
  2317. return elNode.parentNode;
  2318. },
  2319. _parentNode_Fix : function(elNode){
  2320. if(!elNode){return elNode;}
  2321. while(elNode.previousSibling){elNode = elNode.previousSibling;}
  2322. return elNode.parentNode;
  2323. },
  2324. _childNodes_Native : function(elNode){
  2325. return elNode.childNodes;
  2326. },
  2327. _childNodes_Fix : function(elNode){
  2328. var aResult = null;
  2329. var nCount = 0;
  2330. if(elNode){
  2331. var aResult = [];
  2332. elNode = elNode.firstChild;
  2333. while(elNode){
  2334. aResult[nCount++] = elNode;
  2335. elNode=elNode.nextSibling;
  2336. }
  2337. }
  2338. return aResult;
  2339. }
  2340. }))();
  2341. /*[
  2342. * ADD_APP_PROPERTY
  2343. *
  2344. * 주요 오브젝트를 모든 플러그인에서 this.oApp를 통해서 직접 접근 가능 하도록 등록한다.
  2345. *
  2346. * sPropertyName string 등록명
  2347. * oProperty object 등록시킬 오브젝트
  2348. *
  2349. ---------------------------------------------------------------------------]*/
  2350. /*[
  2351. * REGISTER_BROWSER_EVENT
  2352. *
  2353. * 특정 브라우저 이벤트가 발생 했을때 Husky 메시지를 발생 시킨다.
  2354. *
  2355. * obj HTMLElement 브라우저 이벤트를 발생 시킬 HTML 엘리먼트
  2356. * sEvent string 발생 대기 브라우저 이벤트
  2357. * sMsg string 발생 Husky 메시지
  2358. * aParams array 메시지에 넘길 파라미터
  2359. * nDelay number 브라우저 이벤트 발생 Husky 메시지 발생 사이에 딜레이를 주고 싶을 경우 설정. (1/1000 단위)
  2360. *
  2361. ---------------------------------------------------------------------------]*/
  2362. /*[
  2363. * DISABLE_MESSAGE
  2364. *
  2365. * 특정 메시지를 코어에서 무시하고 라우팅 하지 않도록 비활성화 한다.
  2366. *
  2367. * sMsg string 비활성화 시킬 메시지
  2368. *
  2369. ---------------------------------------------------------------------------]*/
  2370. /*[
  2371. * ENABLE_MESSAGE
  2372. *
  2373. * 무시하도록 설정된 메시지를 무시하지 않도록 활성화 한다.
  2374. *
  2375. * sMsg string 활성화 시킬 메시지
  2376. *
  2377. ---------------------------------------------------------------------------]*/
  2378. /*[
  2379. * EXEC_ON_READY_FUNCTION
  2380. *
  2381. * oApp.run({fnOnAppReady:fnOnAppReady}) 같이 run 호출 시점에 지정된 함수가 있을 경우 이를 MSG_APP_READY 시점에 실행 시킨다.
  2382. * 코어에서 자동으로 발생시키는 메시지로 직접 발생시키지는 않도록 한다.
  2383. *
  2384. * none
  2385. *
  2386. ---------------------------------------------------------------------------]*/
  2387. /**
  2388. * @pluginDesc Husky Framework에서 자주 사용되는 메시지를 처리하는 플러그인
  2389. */
  2390. nhn.husky.CorePlugin = jindo.$Class({
  2391. name : "CorePlugin",
  2392. // nStatus = 0(request not sent), 1(request sent), 2(response received)
  2393. // sContents = response
  2394. htLazyLoadRequest_plugins : {},
  2395. htLazyLoadRequest_allFiles : {},
  2396. htHTMLLoaded : {},
  2397. $AFTER_MSG_APP_READY : function(){
  2398. this.oApp.exec("EXEC_ON_READY_FUNCTION", []);
  2399. },
  2400. $ON_ADD_APP_PROPERTY : function(sPropertyName, oProperty){
  2401. this.oApp[sPropertyName] = oProperty;
  2402. },
  2403. $ON_REGISTER_BROWSER_EVENT : function(obj, sEvent, sMsg, aParams, nDelay){
  2404. this.oApp.registerBrowserEvent(obj, sEvent, sMsg, aParams, nDelay);
  2405. },
  2406. $ON_DISABLE_MESSAGE : function(sMsg){
  2407. this.oApp.disableMessage(sMsg, true);
  2408. },
  2409. $ON_ENABLE_MESSAGE : function(sMsg){
  2410. this.oApp.disableMessage(sMsg, false);
  2411. },
  2412. $ON_LOAD_FULL_PLUGIN : function(aFilenames, sClassName, sMsgName, oThisRef, oArguments){
  2413. var oPluginRef = oThisRef.$this || oThisRef;
  2414. // var nIdx = _nIdx||0;
  2415. var sFilename = aFilenames[0];
  2416. if(!this.htLazyLoadRequest_plugins[sFilename]){
  2417. this.htLazyLoadRequest_plugins[sFilename] = {nStatus:1, sContents:""};
  2418. }
  2419. if(this.htLazyLoadRequest_plugins[sFilename].nStatus === 2){
  2420. //this.oApp.delayedExec("MSG_FULL_PLUGIN_LOADED", [sFilename, sClassName, sMsgName, oThisRef, oArguments, false], 0);
  2421. this.oApp.exec("MSG_FULL_PLUGIN_LOADED", [sFilename, sClassName, sMsgName, oThisRef, oArguments, false]);
  2422. }else{
  2423. this._loadFullPlugin(aFilenames, sClassName, sMsgName, oThisRef, oArguments, 0);
  2424. }
  2425. },
  2426. _loadFullPlugin : function(aFilenames, sClassName, sMsgName, oThisRef, oArguments, nIdx){
  2427. jindo.LazyLoading.load(nhn.husky.SE2M_Configuration.LazyLoad.sJsBaseURI+"/"+aFilenames[nIdx],
  2428. jindo.$Fn(function(aFilenames, sClassName, sMsgName, oThisRef, oArguments, nIdx){
  2429. var sCurFilename = aFilenames[nIdx];
  2430. // plugin filename
  2431. var sFilename = aFilenames[0];
  2432. if(nIdx == aFilenames.length-1){
  2433. this.htLazyLoadRequest_plugins[sFilename].nStatus=2;
  2434. this.oApp.exec("MSG_FULL_PLUGIN_LOADED", [aFilenames, sClassName, sMsgName, oThisRef, oArguments]);
  2435. return;
  2436. }
  2437. //this.oApp.exec("LOAD_FULL_PLUGIN", [aFilenames, sClassName, sMsgName, oThisRef, oArguments, nIdx+1]);
  2438. this._loadFullPlugin(aFilenames, sClassName, sMsgName, oThisRef, oArguments, nIdx+1);
  2439. }, this).bind(aFilenames, sClassName, sMsgName, oThisRef, oArguments, nIdx),
  2440. "utf-8"
  2441. );
  2442. },
  2443. $ON_MSG_FULL_PLUGIN_LOADED : function(aFilenames, sClassName, sMsgName, oThisRef, oArguments, oRes){
  2444. // oThisRef.$this는 현재 로드되는 플러그인이 parent 인스턴스일 경우 존재 함. oThisRef.$this는 현재 플러그인(oThisRef)를 parent로 삼고 있는 인스턴스
  2445. // oThisRef에 $this 속성이 없다면 parent가 아닌 일반 인스턴스
  2446. // oPluginRef는 결과적으로 상속 관계가 있다면 자식 인스턴스를 아니라면 일반적인 인스턴스를 가짐
  2447. var oPluginRef = oThisRef.$this || oThisRef;
  2448. var sFilename = aFilenames;
  2449. // now the source code is loaded, remove the loader handlers
  2450. for(var i=0, nLen=oThisRef._huskyFLT.length; i<nLen; i++){
  2451. var sLoaderHandlerName = "$BEFORE_"+oThisRef._huskyFLT[i];
  2452. // if child class has its own loader function, remove the loader from current instance(parent) only
  2453. var oRemoveFrom = (oThisRef.$this && oThisRef[sLoaderHandlerName])?oThisRef:oPluginRef;
  2454. oRemoveFrom[sLoaderHandlerName] = null;
  2455. this.oApp.createMessageMap(sLoaderHandlerName);
  2456. }
  2457. var oPlugin = eval(sClassName+".prototype");
  2458. //var oPlugin = eval("new "+sClassName+"()");
  2459. var bAcceptLocalBeforeFirstAgain = false;
  2460. // if there were no $LOCAL_BEFORE_FIRST in already-loaded script, set to accept $LOCAL_BEFORE_FIRST next time as the function could be included in the lazy-loaded script.
  2461. if(typeof oPluginRef["$LOCAL_BEFORE_FIRST"] !== "function"){
  2462. this.oApp.acceptLocalBeforeFirstAgain(oPluginRef, true);
  2463. }
  2464. for(var x in oPlugin){
  2465. // 자식 인스턴스에 parent를 override하는 함수가 없다면 parent 인스턴스에 함수 복사 해 줌. 이때 함수만 복사하고, 나머지 속성들은 현재 인스턴스에 존재 하지 않을 경우에만 복사.
  2466. if(oThisRef.$this && (!oThisRef[x] || (typeof oPlugin[x] === "function" && x != "constructor"))){
  2467. oThisRef[x] = jindo.$Fn(oPlugin[x], oPluginRef).bind();
  2468. }
  2469. // 현재 인스턴스에 함수 복사 해 줌. 이때 함수만 복사하고, 나머지 속성들은 현재 인스턴스에 존재 하지 않을 경우에만 복사
  2470. if(oPlugin[x] && (!oPluginRef[x] || (typeof oPlugin[x] === "function" && x != "constructor"))){
  2471. oPluginRef[x] = oPlugin[x];
  2472. // 새로 추가되는 함수가 메시지 핸들러라면 메시지 매핑에 추가 해 줌
  2473. if(x.match(/^\$(LOCAL|BEFORE|ON|AFTER)_/)){
  2474. this.oApp.addToMessageMap(x, oPluginRef);
  2475. }
  2476. }
  2477. }
  2478. if(bAcceptLocalBeforeFirstAgain){
  2479. this.oApp.acceptLocalBeforeFirstAgain(oPluginRef, true);
  2480. }
  2481. // re-send the message after all the jindo.$super handlers are executed
  2482. if(!oThisRef.$this){
  2483. this.oApp.exec(sMsgName, oArguments);
  2484. }
  2485. },
  2486. $ON_LOAD_HTML : function(sId){
  2487. if(this.htHTMLLoaded[sId]) return;
  2488. var elTextarea = jindo.$("_llh_"+sId);
  2489. if(!elTextarea) return;
  2490. this.htHTMLLoaded[sId] = true;
  2491. var elTmp = document.createElement("DIV");
  2492. elTmp.innerHTML = elTextarea.value;
  2493. while(elTmp.firstChild){
  2494. elTextarea.parentNode.insertBefore(elTmp.firstChild, elTextarea);
  2495. }
  2496. },
  2497. $ON_EXEC_ON_READY_FUNCTION : function(){
  2498. if(typeof this.oApp.htRunOptions.fnOnAppReady == "function"){this.oApp.htRunOptions.fnOnAppReady();}
  2499. }
  2500. });
  2501. //{
  2502. /**
  2503. * @fileOverview This file contains Husky plugin that bridges the HuskyRange function
  2504. * @name hp_HuskyRangeManager.js
  2505. */
  2506. nhn.husky.HuskyRangeManager = jindo.$Class({
  2507. name : "HuskyRangeManager",
  2508. oWindow : null,
  2509. $init : function(win){
  2510. this.oWindow = win || window;
  2511. },
  2512. $BEFORE_MSG_APP_READY : function(){
  2513. if(this.oWindow && this.oWindow.tagName == "IFRAME"){
  2514. this.oWindow = this.oWindow.contentWindow;
  2515. nhn.CurrentSelection.setWindow(this.oWindow);
  2516. }
  2517. this.oApp.exec("ADD_APP_PROPERTY", ["getSelection", jindo.$Fn(this.getSelection, this).bind()]);
  2518. this.oApp.exec("ADD_APP_PROPERTY", ["getEmptySelection", jindo.$Fn(this.getEmptySelection, this).bind()]);
  2519. },
  2520. $ON_SET_EDITING_WINDOW : function(oWindow){
  2521. this.oWindow = oWindow;
  2522. },
  2523. getEmptySelection : function(oWindow){
  2524. var oHuskyRange = new nhn.HuskyRange(oWindow || this.oWindow);
  2525. return oHuskyRange;
  2526. },
  2527. getSelection : function(oWindow){
  2528. this.oApp.exec("RESTORE_IE_SELECTION", []);
  2529. var oHuskyRange = this.getEmptySelection(oWindow);
  2530. // this may throw an exception if the selected is area is not yet shown
  2531. try{
  2532. oHuskyRange.setFromSelection();
  2533. }catch(e){}
  2534. return oHuskyRange;
  2535. }
  2536. });
  2537. //}
  2538. //{
  2539. /**
  2540. * @fileOverview This file contains Husky plugin that takes care of the operations related to the tool bar UI
  2541. * @name hp_SE2M_Toolbar.js
  2542. */
  2543. nhn.husky.SE2M_Toolbar = jindo.$Class({
  2544. name : "SE2M_Toolbar",
  2545. toolbarArea : null,
  2546. toolbarButton : null,
  2547. uiNameTag : "uiName",
  2548. // 0: unknown
  2549. // 1: all enabled
  2550. // 2: all disabled
  2551. nUIStatus : 1,
  2552. sUIClassPrefix : "husky_seditor_ui_",
  2553. aUICmdMap : null,
  2554. elFirstToolbarItem : null,
  2555. /**
  2556. * 얼럿 레이어를 닫을 사용할 이벤트 핸들러
  2557. * @param {Function} fCallback 레이어를 닫을때 실행할 콜백함수
  2558. * @returns {Boolean} 무조건 false 리턴한다. onclick 이벤트에 바로 할당하기 때문에 이벤트 전파를 막기 위해 무조건 false를 리턴
  2559. */
  2560. _hideAlert : function(fCallback){
  2561. if(typeof fCallback == "function"){
  2562. fCallback();
  2563. }
  2564. this._elAlertLayer.style.display = "none";
  2565. this.oApp.exec("HIDE_EDITING_AREA_COVER");
  2566. return false;
  2567. },
  2568. /**
  2569. * 시스템 alert/confirm 대신 얼럿 레이어를 띄우기 위한 허스키 메시지
  2570. * 얼럿 레이어는 UI 기능버튼이 동작하지 않도록 에디터 전체를 투명 커버로 씌우고
  2571. * 에디터 전체를 기준으로 중앙에 위치한다. (편집영역은 딤드처리)
  2572. * 취소콜백함수(fCancelCallback) 등록여부에 따라 "취소"버튼을 보여줄지 여부를 결정하기 때문에 alert/confirm 두가지 형태의 레이어를 모두 표현해줄 있다.
  2573. * (주의)
  2574. * 특정 UI가 동작한 상태에서 띄워질 있기 때문에 DISABLE_ALL_UI / ENABLE_ALL_UI 메시지를 수행하지 않는다.
  2575. * 또한 같은 이유로 포커스 역시 편집영역으로 자동 포커싱하지 않기 때문에 얼럿 레이어가 닫힌 편집영역으로 포커스가 필요한 경우 callback 함수에서 실행되도록 해야한다.
  2576. *
  2577. * @param {String} sMsgHTML 얼럿 레이어에 보여줄 문구 (HTML형태로 표현가능하다)
  2578. * @param {HashTable} htOption 얼럿 레이어 옵션 객체
  2579. * @param {Function} htOption.fOkCallback "확인" 버튼 클릭시 콜백함수
  2580. * @param {Function} htOption.fCloseCallback "X" 버튼 클릭시 콜백함수
  2581. * @param {Function} htOption.fCancelCallback "취소" 버튼 클릭시 콜백함수, 등록되지 않으면 "취소"버튼이 나오지 않는다.
  2582. */
  2583. $ON_ALERT : function(sMsgHTML, htOption){
  2584. if(this._elAlertLayer){
  2585. htOption = htOption || {};
  2586. this._elAlertTxts.innerHTML = sMsgHTML || "";
  2587. // 각 버튼에 클릭이벤트 핸들러를 달아준다.
  2588. this._elAlertOk.onclick = jindo.$Fn(this._hideAlert, this).bind(htOption.fOkCallback);
  2589. this._elAlertClose.onclick = jindo.$Fn(this._hideAlert, this).bind(htOption.fCloseCallback);
  2590. // 취소 콜백함수가 없는 경우는 버튼을 보여주지 않는다.
  2591. if(htOption.fCancelCallback){
  2592. this._elAlertCancel.onclick = jindo.$Fn(this._hideAlert, this).bind(htOption.fCancelCallback);
  2593. this._elAlertCancel.style.display = "";
  2594. }else{
  2595. this._elAlertCancel.style.display = "none";
  2596. }
  2597. this.oApp.exec("SHOW_EDITING_AREA_COVER", [true]);
  2598. this._elAlertLayer.style.zIndex = 100;
  2599. this._elAlertLayer.style.display = "block";
  2600. this._elAlertOk.focus();
  2601. }
  2602. },
  2603. _assignHTMLElements : function(oAppContainer){
  2604. oAppContainer = jindo.$(oAppContainer) || document;
  2605. this.rxUI = new RegExp(this.sUIClassPrefix+"([^ ]+)");
  2606. this.toolbarArea = jindo.$$.getSingle(".se2_tool", oAppContainer);
  2607. this.aAllUI = jindo.$$("[class*=" + this.sUIClassPrefix + "]", this.toolbarArea);
  2608. this.elTextTool = jindo.$$.getSingle("div.husky_seditor_text_tool", this.toolbarArea); // [SMARTEDITORSUS-1124] 텍스트 툴바 버튼의 라운드 처리
  2609. // alert 레이어 할당
  2610. this._elAlertLayer = jindo.$$.getSingle(".se2_alert_wrap", oAppContainer);
  2611. if(this._elAlertLayer){
  2612. this._elAlertTxts = jindo.$$.getSingle(".se2_alert_txts", this._elAlertLayer);
  2613. this._elAlertOk = jindo.$$.getSingle(".se2_confirm", this._elAlertLayer);
  2614. this._elAlertCancel = jindo.$$.getSingle(".se2_cancel", this._elAlertLayer);
  2615. this._elAlertClose = jindo.$$.getSingle(".btn_close", this._elAlertLayer);
  2616. }
  2617. this.welToolbarArea = jindo.$Element(this.toolbarArea);
  2618. for (var i = 0, nCount = this.aAllUI.length; i < nCount; i++) {
  2619. if (this.rxUI.test(this.aAllUI[i].className)) {
  2620. var sUIName = RegExp.$1;
  2621. if(this.htUIList[sUIName] !== undefined){
  2622. continue;
  2623. }
  2624. this.htUIList[sUIName] = this.aAllUI[i];
  2625. this.htWrappedUIList[sUIName] = jindo.$Element(this.htUIList[sUIName]);
  2626. }
  2627. }
  2628. if (jindo.$$.getSingle("DIV.se2_icon_tool") != null) {
  2629. this.elFirstToolbarItem = jindo.$$.getSingle("DIV.se2_icon_tool UL.se2_itool1>li>button");
  2630. }
  2631. },
  2632. $LOCAL_BEFORE_FIRST : function(sMsg) {
  2633. var aToolItems = jindo.$$(">ul>li[class*=" + this.sUIClassPrefix + "]>button", this.elTextTool);
  2634. var nItemLength = aToolItems.length;
  2635. this.elFirstToolbarItem = this.elFirstToolbarItem || aToolItems[0];
  2636. this.elLastToolbarItem = aToolItems[nItemLength-1];
  2637. this.oApp.registerBrowserEvent(this.toolbarArea, "keydown", "NAVIGATE_TOOLBAR", []);
  2638. },
  2639. /**
  2640. * @param {Element} oAppContainer
  2641. * @param {Object} htOptions
  2642. * @param {Array} htOptions.aDisabled 비활성화할 버튼명 배열
  2643. */
  2644. $init : function(oAppContainer, htOptions){
  2645. this._htOptions = htOptions || {};
  2646. this.htUIList = {};
  2647. this.htWrappedUIList = {};
  2648. this.aUICmdMap = {};
  2649. this._assignHTMLElements(oAppContainer);
  2650. },
  2651. $ON_MSG_APP_READY : function(){
  2652. if(this.oApp.bMobile){
  2653. this.oApp.registerBrowserEvent(this.toolbarArea, "touchstart", "EVENT_TOOLBAR_TOUCHSTART");
  2654. }else{
  2655. this.oApp.registerBrowserEvent(this.toolbarArea, "mouseover", "EVENT_TOOLBAR_MOUSEOVER");
  2656. this.oApp.registerBrowserEvent(this.toolbarArea, "mouseout", "EVENT_TOOLBAR_MOUSEOUT");
  2657. }
  2658. this.oApp.registerBrowserEvent(this.toolbarArea, "mousedown", "EVENT_TOOLBAR_MOUSEDOWN");
  2659. this.oApp.exec("ADD_APP_PROPERTY", ["getToolbarButtonByUIName", jindo.$Fn(this.getToolbarButtonByUIName, this).bind()]);
  2660. // [SMARTEDITORSUS-1679] 초기 disabled 처리가 필요한 버튼은 비활성화
  2661. if(this._htOptions.aDisabled){
  2662. this._htOptions._sDisabled = "," + this._htOptions.aDisabled.toString() + ","; // 버튼을 활성화할때 비교하기 위한 문자열구성
  2663. this.oApp.exec("DISABLE_UI", [this._htOptions.aDisabled]);
  2664. }
  2665. },
  2666. $ON_NAVIGATE_TOOLBAR : function(weEvent) {
  2667. var TAB_KEY_CODE = 9;
  2668. //이벤트가 발생한 엘리먼트가 마지막 아이템이고 TAB 키가 눌려졌다면
  2669. if ((weEvent.element == this.elLastToolbarItem) && (weEvent.key().keyCode == TAB_KEY_CODE) ) {
  2670. if (weEvent.key().shift) {
  2671. //do nothing
  2672. } else {
  2673. this.elFirstToolbarItem.focus();
  2674. weEvent.stopDefault();
  2675. }
  2676. }
  2677. //이벤트가 발생한 엘리먼트가 첫번째 아이템이고 TAB 키가 눌려졌다면
  2678. if (weEvent.element == this.elFirstToolbarItem && (weEvent.key().keyCode == TAB_KEY_CODE)) {
  2679. if (weEvent.key().shift) {
  2680. weEvent.stopDefault();
  2681. this.elLastToolbarItem.focus();
  2682. }
  2683. }
  2684. },
  2685. $ON_TOGGLE_TOOLBAR_ACTIVE_LAYER : function(elLayer, elBtn, sOpenCmd, aOpenArgs, sCloseCmd, aCloseArgs){
  2686. this.oApp.exec("TOGGLE_ACTIVE_LAYER", [elLayer, "MSG_TOOLBAR_LAYER_SHOWN", [elLayer, elBtn, sOpenCmd, aOpenArgs], sCloseCmd, aCloseArgs]);
  2687. },
  2688. $ON_MSG_TOOLBAR_LAYER_SHOWN : function(elLayer, elBtn, aOpenCmd, aOpenArgs){
  2689. this.oApp.exec("POSITION_TOOLBAR_LAYER", [elLayer, elBtn]);
  2690. if(aOpenCmd){
  2691. this.oApp.exec(aOpenCmd, aOpenArgs);
  2692. }
  2693. },
  2694. $ON_SHOW_TOOLBAR_ACTIVE_LAYER : function(elLayer, sCmd, aArgs, elBtn){
  2695. this.oApp.exec("SHOW_ACTIVE_LAYER", [elLayer, sCmd, aArgs]);
  2696. this.oApp.exec("POSITION_TOOLBAR_LAYER", [elLayer, elBtn]);
  2697. },
  2698. $ON_ENABLE_UI : function(sUIName){
  2699. this._enableUI(sUIName);
  2700. },
  2701. /**
  2702. * [SMARTEDITORSUS-1679] 여러개의 버튼을 동시에 비활성화 있도록 수정
  2703. * @param {String|Array} vUIName 비활성화할 버튼명, 배열일 경우 여러개 동시 적용
  2704. */
  2705. $ON_DISABLE_UI : function(sUIName){
  2706. if(sUIName instanceof Array){
  2707. for(var i = 0, sName; (sName = sUIName[i]); i++){
  2708. this._disableUI(sName);
  2709. }
  2710. }else{
  2711. this._disableUI(sUIName);
  2712. }
  2713. },
  2714. $ON_SELECT_UI : function(sUIName){
  2715. var welUI = this.htWrappedUIList[sUIName];
  2716. if(!welUI){
  2717. return;
  2718. }
  2719. welUI.removeClass("hover");
  2720. welUI.addClass("active");
  2721. },
  2722. $ON_DESELECT_UI : function(sUIName){
  2723. var welUI = this.htWrappedUIList[sUIName];
  2724. if(!welUI){
  2725. return;
  2726. }
  2727. welUI.removeClass("active");
  2728. },
  2729. /**
  2730. * [SMARTEDITORSUS-1646] 툴바버튼 선택상태를 토글링한다.
  2731. * @param {String} sUIName 토글링할 툴바버튼 이름
  2732. */
  2733. $ON_TOGGLE_UI_SELECTED : function(sUIName){
  2734. var welUI = this.htWrappedUIList[sUIName];
  2735. if(!welUI){
  2736. return;
  2737. }
  2738. if(welUI.hasClass("active")){
  2739. welUI.removeClass("active");
  2740. }else{
  2741. welUI.removeClass("hover");
  2742. welUI.addClass("active");
  2743. }
  2744. },
  2745. $ON_ENABLE_ALL_UI : function(htOptions){
  2746. if(this.nUIStatus === 1){
  2747. return;
  2748. }
  2749. var sUIName, className;
  2750. htOptions = htOptions || {};
  2751. var waExceptions = jindo.$A(htOptions.aExceptions || []);
  2752. for(sUIName in this.htUIList){
  2753. if(sUIName && !waExceptions.has(sUIName)){
  2754. this._enableUI(sUIName);
  2755. }
  2756. // if(sUIName) this.oApp.exec("ENABLE_UI", [sUIName]);
  2757. }
  2758. // jindo.$Element(this.toolbarArea).removeClass("off");
  2759. this.nUIStatus = 1;
  2760. },
  2761. $ON_DISABLE_ALL_UI : function(htOptions){
  2762. if(this.nUIStatus === 2){
  2763. return;
  2764. }
  2765. var sUIName;
  2766. htOptions = htOptions || {};
  2767. var waExceptions = jindo.$A(htOptions.aExceptions || []);
  2768. var bLeavlActiveLayer = htOptions.bLeaveActiveLayer || false;
  2769. if(!bLeavlActiveLayer){
  2770. this.oApp.exec("HIDE_ACTIVE_LAYER");
  2771. }
  2772. for(sUIName in this.htUIList){
  2773. if(sUIName && !waExceptions.has(sUIName)){
  2774. this._disableUI(sUIName);
  2775. }
  2776. // if(sUIName) this.oApp.exec("DISABLE_UI", [sUIName]);
  2777. }
  2778. // jindo.$Element(this.toolbarArea).addClass("off");
  2779. this.nUIStatus = 2;
  2780. },
  2781. $ON_MSG_STYLE_CHANGED : function(sAttributeName, attributeValue){
  2782. if(attributeValue === "@^"){
  2783. this.oApp.exec("SELECT_UI", [sAttributeName]);
  2784. }else{
  2785. this.oApp.exec("DESELECT_UI", [sAttributeName]);
  2786. }
  2787. },
  2788. $ON_POSITION_TOOLBAR_LAYER : function(elLayer, htOption){
  2789. var nLayerLeft, nLayerRight, nToolbarLeft, nToolbarRight;
  2790. elLayer = jindo.$(elLayer);
  2791. htOption = htOption || {};
  2792. var elBtn = jindo.$(htOption.elBtn);
  2793. var sAlign = htOption.sAlign;
  2794. var nMargin = -1;
  2795. if(!elLayer){
  2796. return;
  2797. }
  2798. if(elBtn && elBtn.tagName && elBtn.tagName == "BUTTON"){
  2799. elBtn.parentNode.appendChild(elLayer);
  2800. }
  2801. var welLayer = jindo.$Element(elLayer);
  2802. if(sAlign != "right"){
  2803. elLayer.style.left = "0";
  2804. nLayerLeft = welLayer.offset().left;
  2805. nLayerRight = nLayerLeft + elLayer.offsetWidth;
  2806. nToolbarLeft = this.welToolbarArea.offset().left;
  2807. nToolbarRight = nToolbarLeft + this.toolbarArea.offsetWidth;
  2808. if(nLayerRight > nToolbarRight){
  2809. welLayer.css("left", (nToolbarRight-nLayerRight-nMargin)+"px");
  2810. }
  2811. if(nLayerLeft < nToolbarLeft){
  2812. welLayer.css("left", (nToolbarLeft-nLayerLeft+nMargin)+"px");
  2813. }
  2814. }else{
  2815. elLayer.style.right = "0";
  2816. nLayerLeft = welLayer.offset().left;
  2817. nLayerRight = nLayerLeft + elLayer.offsetWidth;
  2818. nToolbarLeft = this.welToolbarArea.offset().left;
  2819. nToolbarRight = nToolbarLeft + this.toolbarArea.offsetWidth;
  2820. if(nLayerRight > nToolbarRight){
  2821. welLayer.css("right", -1*(nToolbarRight-nLayerRight-nMargin)+"px");
  2822. }
  2823. if(nLayerLeft < nToolbarLeft){
  2824. welLayer.css("right", -1*(nToolbarLeft-nLayerLeft+nMargin)+"px");
  2825. }
  2826. }
  2827. },
  2828. $ON_EVENT_TOOLBAR_MOUSEOVER : function(weEvent){
  2829. if(this.nUIStatus === 2){
  2830. return;
  2831. }
  2832. var aAffectedElements = this._getAffectedElements(weEvent.element);
  2833. for(var i=0; i<aAffectedElements.length; i++){
  2834. if(!aAffectedElements[i].hasClass("active")){
  2835. aAffectedElements[i].addClass("hover");
  2836. }
  2837. }
  2838. },
  2839. $ON_EVENT_TOOLBAR_MOUSEOUT : function(weEvent){
  2840. if(this.nUIStatus === 2){
  2841. return;
  2842. }
  2843. var aAffectedElements = this._getAffectedElements(weEvent.element);
  2844. for(var i=0; i<aAffectedElements.length; i++){
  2845. aAffectedElements[i].removeClass("hover");
  2846. }
  2847. },
  2848. $ON_EVENT_TOOLBAR_MOUSEDOWN : function(weEvent){
  2849. var elTmp = weEvent.element;
  2850. // Check if the button pressed is in active status and has a visible layer i.e. the button had been clicked and its layer is open already. (buttons like font styles-bold, underline-got no sub layer -> childNodes.length<=2)
  2851. // -> In this case, do not close here(mousedown). The layer will be closed on "click". If we close the layer here, the click event will open it again because it toggles the visibility.
  2852. while(elTmp){
  2853. if(elTmp.className && elTmp.className.match(/active/) && (elTmp.childNodes.length>2 || elTmp.parentNode.className.match(/se2_pair/))){
  2854. return;
  2855. }
  2856. elTmp = elTmp.parentNode;
  2857. }
  2858. this.oApp.exec("HIDE_ACTIVE_LAYER_IF_NOT_CHILD", [weEvent.element]);
  2859. },
  2860. _enableUI : function(sUIName){
  2861. // [SMARTEDITORSUS-1679] 초기 disabled 설정된 버튼은 skip
  2862. if(this._htOptions._sDisabled && this._htOptions._sDisabled.indexOf(","+sUIName+",") > -1){
  2863. return;
  2864. }
  2865. var i, nLen;
  2866. this.nUIStatus = 0;
  2867. var welUI = this.htWrappedUIList[sUIName];
  2868. var elUI = this.htUIList[sUIName];
  2869. if(!welUI){
  2870. return;
  2871. }
  2872. welUI.removeClass("off");
  2873. var aAllBtns = elUI.getElementsByTagName("BUTTON");
  2874. for(i=0, nLen=aAllBtns.length; i<nLen; i++){
  2875. aAllBtns[i].disabled = false;
  2876. }
  2877. // enable related commands
  2878. var sCmd = "";
  2879. if(this.aUICmdMap[sUIName]){
  2880. for(i=0; i<this.aUICmdMap[sUIName].length;i++){
  2881. sCmd = this.aUICmdMap[sUIName][i];
  2882. this.oApp.exec("ENABLE_MESSAGE", [sCmd]);
  2883. }
  2884. }
  2885. },
  2886. _disableUI : function(sUIName){
  2887. var i, nLen;
  2888. this.nUIStatus = 0;
  2889. var welUI = this.htWrappedUIList[sUIName];
  2890. var elUI = this.htUIList[sUIName];
  2891. if(!welUI){
  2892. return;
  2893. }
  2894. welUI.addClass("off");
  2895. welUI.removeClass("hover");
  2896. var aAllBtns = elUI.getElementsByTagName("BUTTON");
  2897. for(i=0, nLen=aAllBtns.length; i<nLen; i++){
  2898. aAllBtns[i].disabled = true;
  2899. }
  2900. // disable related commands
  2901. var sCmd = "";
  2902. if(this.aUICmdMap[sUIName]){
  2903. for(i=0; i<this.aUICmdMap[sUIName].length;i++){
  2904. sCmd = this.aUICmdMap[sUIName][i];
  2905. this.oApp.exec("DISABLE_MESSAGE", [sCmd]);
  2906. }
  2907. }
  2908. },
  2909. _getAffectedElements : function(el){
  2910. var elLi, welLi;
  2911. // 버튼 클릭시에 return false를 해 주지 않으면 chrome에서 버튼이 포커스 가져가 버림.
  2912. // 에디터 로딩 시에 일괄처리 할 경우 로딩 속도가 느려짐으로 hover시에 하나씩 처리
  2913. if(!el.bSE2_MDCancelled){
  2914. el.bSE2_MDCancelled = true;
  2915. var aBtns = el.getElementsByTagName("BUTTON");
  2916. for(var i=0, nLen=aBtns.length; i<nLen; i++){
  2917. aBtns[i].onmousedown = function(){return false;};
  2918. }
  2919. }
  2920. if(!el || !el.tagName){ return []; }
  2921. if((elLi = el).tagName == "BUTTON"){
  2922. // typical button
  2923. // <LI>
  2924. // <BUTTON>
  2925. if((elLi = elLi.parentNode) && elLi.tagName == "LI" && this.rxUI.test(elLi.className)){
  2926. return [jindo.$Element(elLi)];
  2927. }
  2928. // button pair
  2929. // <LI>
  2930. // <SPAN>
  2931. // <BUTTON>
  2932. // <SPAN>
  2933. // <BUTTON>
  2934. elLi = el;
  2935. if((elLi = elLi.parentNode.parentNode) && elLi.tagName == "LI" && (welLi = jindo.$Element(elLi)).hasClass("se2_pair")){
  2936. return [welLi, jindo.$Element(el.parentNode)];
  2937. }
  2938. return [];
  2939. }
  2940. // span in a button
  2941. if((elLi = el).tagName == "SPAN"){
  2942. // <LI>
  2943. // <BUTTON>
  2944. // <SPAN>
  2945. if((elLi = elLi.parentNode.parentNode) && elLi.tagName == "LI" && this.rxUI.test(elLi.className)){
  2946. return [jindo.$Element(elLi)];
  2947. }
  2948. // <LI>
  2949. // <SPAN>
  2950. //글감과 글양식
  2951. if((elLi = elLi.parentNode) && elLi.tagName == "LI" && this.rxUI.test(elLi.className)){
  2952. return [jindo.$Element(elLi)];
  2953. }
  2954. }
  2955. return [];
  2956. },
  2957. $ON_REGISTER_UI_EVENT : function(sUIName, sEvent, sCmd, aParams){
  2958. //[SMARTEDITORSUS-966][IE8 표준/IE 10] 호환 모드를 제거하고 사진 첨부 시 에디팅 영역의
  2959. // 커서 주위에 <sub><sup> 태그가 붙어서 글자가 매우 작게 되는 현상
  2960. //원인 : 아래의 [SMARTEDITORSUS-901] 수정 내용에서 윗첨자 아랫첨자 이벤트 등록 시
  2961. //해당 플러그인이 마크업에 없으면 this.htUIList에 존재하지 않아 getsingle 사용시 사진첨부에 이벤트가 걸렸음
  2962. //해결 : this.htUIList에 존재하지 않으면 이벤트를 등록하지 않음
  2963. if(!this.htUIList[sUIName]){
  2964. return;
  2965. }
  2966. // map cmd & ui
  2967. var elButton;
  2968. if(!this.aUICmdMap[sUIName]){this.aUICmdMap[sUIName] = [];}
  2969. this.aUICmdMap[sUIName][this.aUICmdMap[sUIName].length] = sCmd;
  2970. //[SMARTEDITORSUS-901]플러그인 태그 코드 추가 시 <li>태그와<button>태그 사이에 개행이 있으면 이벤트가 등록되지 않는 현상
  2971. //원인 : IE9, Chrome, FF, Safari 에서는 태그를 개행 시 그 개행을 text node로 인식하여 firstchild가 text 노드가 되어 버튼 이벤트가 할당되지 않음
  2972. //해결 : firstchild에 이벤트를 거는 것이 아니라, child 중 button 인 것에 이벤트를 걸도록 변경
  2973. elButton = jindo.$$.getSingle('button', this.htUIList[sUIName]);
  2974. if(!elButton){return;}
  2975. this.oApp.registerBrowserEvent(elButton, sEvent, sCmd, aParams);
  2976. },
  2977. getToolbarButtonByUIName : function(sUIName){
  2978. return jindo.$$.getSingle("BUTTON", this.htUIList[sUIName]);
  2979. }
  2980. });
  2981. //}
  2982. /*[
  2983. * LOAD_CONTENTS_FIELD
  2984. *
  2985. * 에디터 초기화 시에 넘어온 Contents(DB 저장 )필드를 읽어 에디터에 설정한다.
  2986. *
  2987. * bDontAddUndo boolean Contents를 설정하면서 UNDO 히스토리는 추가 하지않는다.
  2988. *
  2989. ---------------------------------------------------------------------------]*/
  2990. /*[
  2991. * UPDATE_IR_FIELD
  2992. *
  2993. * 에디터의 IR값을 IR필드에 설정 한다.
  2994. *
  2995. * none
  2996. *
  2997. ---------------------------------------------------------------------------]*/
  2998. /*[
  2999. * CHANGE_EDITING_MODE
  3000. *
  3001. * 에디터의 편집 모드를 변경한다.
  3002. *
  3003. * sMode string 전환 모드명
  3004. * bNoFocus boolean 모드 전환 후에 에디터에 포커스를 강제로 할당하지 않는다.
  3005. *
  3006. ---------------------------------------------------------------------------]*/
  3007. /*[
  3008. * FOCUS
  3009. *
  3010. * 에디터 편집 영역에 포커스를 준다.
  3011. *
  3012. * none
  3013. *
  3014. ---------------------------------------------------------------------------]*/
  3015. /*[
  3016. * SET_IR
  3017. *
  3018. * IR값을 에디터에 설정 한다.
  3019. *
  3020. * none
  3021. *
  3022. ---------------------------------------------------------------------------]*/
  3023. /*[
  3024. * REGISTER_EDITING_AREA
  3025. *
  3026. * 편집 영역을 플러그인을 등록 시킨다. 원활한 모드 전환과 IR값 공유등를 위해서 초기화 시에 등록이 필요하다.
  3027. *
  3028. * oEditingAreaPlugin object 편집 영역 플러그인 인스턴스
  3029. *
  3030. ---------------------------------------------------------------------------]*/
  3031. /*[
  3032. * MSG_EDITING_AREA_RESIZE_STARTED
  3033. *
  3034. * 편집 영역 사이즈 조절이 시작 되었음을 알리는 메시지.
  3035. *
  3036. * none
  3037. *
  3038. ---------------------------------------------------------------------------]*/
  3039. /*[
  3040. * RESIZE_EDITING_AREA
  3041. *
  3042. * 편집 영역 사이즈를 설정 한다. 변경 전후에 MSG_EDITIING_AREA_RESIZE_STARTED/MSG_EDITING_AREA_RESIZE_ENED를 발생 시켜 줘야 된다.
  3043. *
  3044. * ipNewWidth number
  3045. * ipNewHeight number 높이
  3046. *
  3047. ---------------------------------------------------------------------------]*/
  3048. /*[
  3049. * RESIZE_EDITING_AREA_BY
  3050. *
  3051. * 편집 영역 사이즈를 늘리거나 줄인다. 변경 전후에 MSG_EDITIING_AREA_RESIZE_STARTED/MSG_EDITING_AREA_RESIZE_ENED를 발생 시켜 줘야 된다.
  3052. * 변경치를 입력하면 원래 사이즈에서 변경하여 px로 적용하며, width가 % 설정된 경우에는 변경치가 입력되어도 적용되지 않는다.
  3053. *
  3054. * ipWidthChange number 변경치
  3055. * ipHeightChange number 높이 변경치
  3056. *
  3057. ---------------------------------------------------------------------------]*/
  3058. /*[
  3059. * MSG_EDITING_AREA_RESIZE_ENDED
  3060. *
  3061. * 편집 영역 사이즈 조절이 끝났음을 알리는 메시지.
  3062. *
  3063. * none
  3064. *
  3065. ---------------------------------------------------------------------------]*/
  3066. /**
  3067. * @pluginDesc IR 값과 복수개의 편집 영역을 관리하는 플러그인
  3068. */
  3069. nhn.husky.SE_EditingAreaManager = jindo.$Class({
  3070. name : "SE_EditingAreaManager",
  3071. // Currently active plugin instance(SE_EditingArea_???)
  3072. oActivePlugin : null,
  3073. // Intermediate Representation of the content being edited.
  3074. // This should be a textarea element.
  3075. elContentsField : null,
  3076. bIsDirty : false,
  3077. bAutoResize : false, // [SMARTEDITORSUS-677] 에디터의 자동확장 기능 On/Off 여부
  3078. $init : function(sDefaultEditingMode, elContentsField, oDimension, fOnBeforeUnload, elAppContainer){
  3079. this.sDefaultEditingMode = sDefaultEditingMode;
  3080. this.elContentsField = jindo.$(elContentsField);
  3081. this._assignHTMLElements(elAppContainer);
  3082. this.fOnBeforeUnload = fOnBeforeUnload;
  3083. this.oEditingMode = {};
  3084. this.elContentsField.style.display = "none";
  3085. this.nMinWidth = parseInt((oDimension.nMinWidth || 60), 10);
  3086. this.nMinHeight = parseInt((oDimension.nMinHeight || 60), 10);
  3087. var oWidth = this._getSize([oDimension.nWidth, oDimension.width, this.elEditingAreaContainer.offsetWidth], this.nMinWidth);
  3088. var oHeight = this._getSize([oDimension.nHeight, oDimension.height, this.elEditingAreaContainer.offsetHeight], this.nMinHeight);
  3089. this.elEditingAreaContainer.style.width = oWidth.nSize + oWidth.sUnit;
  3090. this.elEditingAreaContainer.style.height = oHeight.nSize + oHeight.sUnit;
  3091. if(oWidth.sUnit === "px"){
  3092. elAppContainer.style.width = (oWidth.nSize + 2) + "px";
  3093. }else if(oWidth.sUnit === "%"){
  3094. elAppContainer.style.minWidth = this.nMinWidth + "px";
  3095. }
  3096. },
  3097. _getSize : function(aSize, nMin){
  3098. var i, nLen, aRxResult, nSize, sUnit, sDefaultUnit = "px";
  3099. nMin = parseInt(nMin, 10);
  3100. for(i=0, nLen=aSize.length; i<nLen; i++){
  3101. if(!aSize[i]){
  3102. continue;
  3103. }
  3104. if(!isNaN(aSize[i])){
  3105. nSize = parseInt(aSize[i], 10);
  3106. sUnit = sDefaultUnit;
  3107. break;
  3108. }
  3109. aRxResult = /([0-9]+)(.*)/i.exec(aSize[i]);
  3110. if(!aRxResult || aRxResult.length < 2 || aRxResult[1] <= 0){
  3111. continue;
  3112. }
  3113. nSize = parseInt(aRxResult[1], 10);
  3114. sUnit = aRxResult[2];
  3115. if(!sUnit){
  3116. sUnit = sDefaultUnit;
  3117. }
  3118. if(nSize < nMin && sUnit === sDefaultUnit){
  3119. nSize = nMin;
  3120. }
  3121. break;
  3122. }
  3123. if(!sUnit){
  3124. sUnit = sDefaultUnit;
  3125. }
  3126. if(isNaN(nSize) || (nSize < nMin && sUnit === sDefaultUnit)){
  3127. nSize = nMin;
  3128. }
  3129. return {nSize : nSize, sUnit : sUnit};
  3130. },
  3131. _assignHTMLElements : function(elAppContainer){
  3132. this.elEditingAreaContainer = jindo.$$.getSingle("DIV.husky_seditor_editing_area_container", elAppContainer);
  3133. // [SMARTEDITORSUS-2036] 로딩 레이어는 하위 호환을 위해 마크업이 존재하는 경우만 동작하도록 한다.
  3134. var f = function(){};
  3135. this.elLoadingLayer = jindo.$$.getSingle(".se2_content_loading", elAppContainer);
  3136. if(!this.elLoadingLayer){
  3137. this.$ON_SHOW_LOADING_LAYER = f;
  3138. this.$ON_HIDE_LOADING_LAYER = f;
  3139. }
  3140. },
  3141. $BEFORE_MSG_APP_READY : function(msg){
  3142. this.oApp.exec("ADD_APP_PROPERTY", ["version", nhn.husky.SE_EditingAreaManager.version]);
  3143. this.oApp.exec("ADD_APP_PROPERTY", ["elEditingAreaContainer", this.elEditingAreaContainer]);
  3144. this.oApp.exec("ADD_APP_PROPERTY", ["welEditingAreaContainer", jindo.$Element(this.elEditingAreaContainer)]);
  3145. this.oApp.exec("ADD_APP_PROPERTY", ["getEditingAreaHeight", jindo.$Fn(this.getEditingAreaHeight, this).bind()]);
  3146. this.oApp.exec("ADD_APP_PROPERTY", ["getEditingAreaWidth", jindo.$Fn(this.getEditingAreaWidth, this).bind()]);
  3147. this.oApp.exec("ADD_APP_PROPERTY", ["getRawContents", jindo.$Fn(this.getRawContents, this).bind()]);
  3148. this.oApp.exec("ADD_APP_PROPERTY", ["getContents", jindo.$Fn(this.getContents, this).bind()]);
  3149. this.oApp.exec("ADD_APP_PROPERTY", ["getIR", jindo.$Fn(this.getIR, this).bind()]);
  3150. this.oApp.exec("ADD_APP_PROPERTY", ["setContents", this.setContents]);
  3151. this.oApp.exec("ADD_APP_PROPERTY", ["setIR", this.setIR]);
  3152. this.oApp.exec("ADD_APP_PROPERTY", ["getEditingMode", jindo.$Fn(this.getEditingMode, this).bind()]);
  3153. },
  3154. $ON_MSG_APP_READY : function(){
  3155. this.htOptions = this.oApp.htOptions[this.name] || {};
  3156. this.sDefaultEditingMode = this.htOptions["sDefaultEditingMode"] || this.sDefaultEditingMode;
  3157. this.iframeWindow = this.oApp.getWYSIWYGWindow();
  3158. this.oApp.exec("REGISTER_CONVERTERS", []);
  3159. this.oApp.exec("CHANGE_EDITING_MODE", [this.sDefaultEditingMode, true]);
  3160. this.oApp.exec("LOAD_CONTENTS_FIELD", [false]);
  3161. // [SMARTEDITORSUS-2089] fOnBeforeUnload === false 인 경우, 아예 window.onbeforeunload 를 등록하지 않도록 수정
  3162. if(this.fOnBeforeUnload !== false){
  3163. if(!!this.fOnBeforeUnload){
  3164. window.onbeforeunload = this.fOnBeforeUnload;
  3165. }else{
  3166. window.onbeforeunload = jindo.$Fn(function(){
  3167. // [SMARTEDITORSUS-1028][SMARTEDITORSUS-1517] QuickEditor 설정 API 개선으로, submit 이후 발생하게 되는 beforeunload 이벤트 핸들링 제거
  3168. //this.oApp.exec("MSG_BEFOREUNLOAD_FIRED");
  3169. // --// [SMARTEDITORSUS-1028][SMARTEDITORSUS-1517]
  3170. //if(this.getContents() != this.elContentsField.value || this.bIsDirty){
  3171. if(this.getRawContents() != this.sCurrentRawContents || this.bIsDirty){
  3172. return this.oApp.$MSG("SE_EditingAreaManager.onExit");
  3173. }
  3174. }, this).bind();
  3175. }
  3176. }
  3177. },
  3178. $AFTER_MSG_APP_READY : function(){
  3179. this.oApp.exec("UPDATE_RAW_CONTENTS");
  3180. if(!!this.oApp.htOptions[this.name] && this.oApp.htOptions[this.name].bAutoResize){
  3181. this.bAutoResize = this.oApp.htOptions[this.name].bAutoResize;
  3182. }
  3183. // [SMARTEDITORSUS-941] 아이패드에서는 자동확장기능이 항상 켜져있도록 한다.
  3184. if(this.oApp.oNavigator.msafari){
  3185. this.bAutoResize = true;
  3186. }
  3187. this.startAutoResize(); // [SMARTEDITORSUS-677] 편집영역 자동 확장 옵션이 TRUE이면 자동확장 시작
  3188. },
  3189. $ON_LOAD_CONTENTS_FIELD : function(bDontAddUndo){
  3190. var sContentsFieldValue = this.elContentsField.value;
  3191. // [SMARTEDITORSUS-177] [IE9] 글 쓰기, 수정 시에 elContentsField 에 들어간 공백을 제거
  3192. // [SMARTEDITORSUS-312] [FF4] 인용구 첫번째,두번째 디자인 1회 선택 시 에디터에 적용되지 않음
  3193. sContentsFieldValue = sContentsFieldValue.replace(/^\s+/, "");
  3194. this.oApp.exec("SET_CONTENTS", [sContentsFieldValue, bDontAddUndo]);
  3195. },
  3196. // 현재 contents를 form의 textarea에 세팅 해 줌.
  3197. // form submit 전에 이 부분을 실행시켜야 됨.
  3198. $ON_UPDATE_CONTENTS_FIELD : function(){
  3199. //this.oIRField.value = this.oApp.getIR();
  3200. this.elContentsField.value = this.oApp.getContents();
  3201. this.oApp.exec("UPDATE_RAW_CONTENTS");
  3202. //this.sCurrentRawContents = this.elContentsField.value;
  3203. },
  3204. // 에디터의 현재 상태를 기억해 둠. 페이지를 떠날 때 이 값이 변경 됐는지 확인 해서 내용이 변경 됐다는 경고창을 띄움
  3205. // RawContents 대신 contents를 이용해도 되지만, contents 획득을 위해서는 변환기를 실행해야 되기 때문에 RawContents 이용
  3206. $ON_UPDATE_RAW_CONTENTS : function(){
  3207. this.sCurrentRawContents = this.oApp.getRawContents();
  3208. },
  3209. $BEFORE_CHANGE_EDITING_MODE : function(sMode){
  3210. if(!this.oEditingMode[sMode]){
  3211. return false;
  3212. }
  3213. this.stopAutoResize(); // [SMARTEDITORSUS-677] 해당 편집 모드에서의 자동확장을 중지함
  3214. this._oPrevActivePlugin = this.oActivePlugin;
  3215. this.oActivePlugin = this.oEditingMode[sMode];
  3216. },
  3217. $AFTER_CHANGE_EDITING_MODE : function(sMode, bNoFocus){
  3218. if(this._oPrevActivePlugin){
  3219. var sIR = this._oPrevActivePlugin.getIR();
  3220. this.oApp.exec("SET_IR", [sIR]);
  3221. //this.oApp.exec("ENABLE_UI", [this._oPrevActivePlugin.sMode]);
  3222. this._setEditingAreaDimension();
  3223. }
  3224. //this.oApp.exec("DISABLE_UI", [this.oActivePlugin.sMode]);
  3225. this.startAutoResize(); // [SMARTEDITORSUS-677] 변경된 편집 모드에서의 자동확장을 시작
  3226. if(!bNoFocus){
  3227. this.oApp.delayedExec("FOCUS", [], 0);
  3228. }
  3229. },
  3230. /**
  3231. * 페이지를 떠날 alert을 표시할지 여부를 셋팅하는 함수.
  3232. */
  3233. $ON_SET_IS_DIRTY : function(bIsDirty){
  3234. this.bIsDirty = bIsDirty;
  3235. },
  3236. // [SMARTEDITORSUS-1698] 모바일에서 팝업 형태의 첨부가 사용될 때 포커스 이슈가 있음
  3237. $ON_FOCUS : function(isPopupOpening){
  3238. if(!this.oActivePlugin || typeof this.oActivePlugin.setIR != "function"){
  3239. return;
  3240. }
  3241. // [SMARTEDITORSUS-599] ipad 대응 이슈.
  3242. // ios5에서는 this.iframe.contentWindow focus가 없어서 생긴 이슈.
  3243. // document가 아닌 window에 focus() 주어야만 본문에 focus가 가고 입력이됨.
  3244. //[SMARTEDITORSUS-1017] [iOS5대응] 모드 전환 시 textarea에 포커스가 있어도 글자가 입력이 안되는 현상
  3245. //원인 : WYSIWYG모드가 아닐 때에도 iframe의 contentWindow에 focus가 가면서 focus기능이 작동하지 않음
  3246. //해결 : WYSIWYG모드 일때만 실행 되도록 조건식 추가 및 기존에 blur처리 코드 삭제
  3247. //[SMARTEDITORSUS-1594] 크롬에서 웹접근성용 키로 빠져나간 후 다시 진입시 간혹 포커싱이 안되는 문제가 있어 iframe에 포커싱을 먼저 주도록 수정
  3248. if(!!this.iframeWindow && this.iframeWindow.document.hasFocus && !this.iframeWindow.document.hasFocus() && this.oActivePlugin.sMode == "WYSIWYG"){
  3249. this.iframeWindow.focus();
  3250. }else{ // 누락된 [SMARTEDITORSUS-1018] 작업분 반영
  3251. this.oActivePlugin.focus();
  3252. }
  3253. if(isPopupOpening && this.oApp.bMobile){
  3254. return;
  3255. }
  3256. this.oActivePlugin.focus();
  3257. },
  3258. // --[SMARTEDITORSUS-1698]
  3259. $ON_IE_FOCUS : function(){
  3260. var oAgent = this.oApp.oNavigator;
  3261. if(!oAgent.ie && !oAgent.edge){ // [SMARTEDITORSUS-2257] edge도 ie와 동일하게 포커스처리해준다.
  3262. return;
  3263. }
  3264. this.oApp.exec("FOCUS");
  3265. },
  3266. $ON_SET_CONTENTS : function(sContents, bDontAddUndoHistory){
  3267. this.setContents(sContents, bDontAddUndoHistory);
  3268. },
  3269. $BEFORE_SET_IR : function(sIR, bDontAddUndoHistory){
  3270. bDontAddUndoHistory = bDontAddUndoHistory || false;
  3271. if(!bDontAddUndoHistory){
  3272. this.oApp.exec("RECORD_UNDO_ACTION", ["BEFORE SET CONTENTS", {sSaveTarget:"BODY"}]);
  3273. }
  3274. },
  3275. $ON_SET_IR : function(sIR){
  3276. if(!this.oActivePlugin || typeof this.oActivePlugin.setIR != "function"){
  3277. return;
  3278. }
  3279. this.oActivePlugin.setIR(sIR);
  3280. },
  3281. $AFTER_SET_IR : function(sIR, bDontAddUndoHistory){
  3282. bDontAddUndoHistory = bDontAddUndoHistory || false;
  3283. if(!bDontAddUndoHistory){
  3284. this.oApp.exec("RECORD_UNDO_ACTION", ["AFTER SET CONTENTS", {sSaveTarget:"BODY"}]);
  3285. }
  3286. },
  3287. $ON_REGISTER_EDITING_AREA : function(oEditingAreaPlugin){
  3288. this.oEditingMode[oEditingAreaPlugin.sMode] = oEditingAreaPlugin;
  3289. if(oEditingAreaPlugin.sMode == 'WYSIWYG'){
  3290. this.attachDocumentEvents(oEditingAreaPlugin.oEditingArea);
  3291. }
  3292. this._setEditingAreaDimension(oEditingAreaPlugin);
  3293. },
  3294. $ON_MSG_EDITING_AREA_RESIZE_STARTED : function(){
  3295. this._fitElementInEditingArea(this.elEditingAreaContainer);
  3296. this.oApp.exec("STOP_AUTORESIZE_EDITING_AREA"); // [SMARTEDITORSUS-677] 사용자가 편집영역 사이즈를 변경하면 자동확장 기능 중지
  3297. this.oApp.exec("SHOW_EDITING_AREA_COVER");
  3298. this.elEditingAreaContainer.style.overflow = "hidden";
  3299. this.iStartingHeight = parseInt(this.elEditingAreaContainer.style.height, 10);
  3300. },
  3301. /**
  3302. * [SMARTEDITORSUS-677] 편집영역 자동확장 기능을 중지함
  3303. */
  3304. $ON_STOP_AUTORESIZE_EDITING_AREA : function(){
  3305. if(!this.bAutoResize){
  3306. return;
  3307. }
  3308. this.stopAutoResize();
  3309. this.bAutoResize = false;
  3310. },
  3311. /**
  3312. * [SMARTEDITORSUS-677] 해당 편집 모드에서의 자동확장을 시작함
  3313. */
  3314. startAutoResize : function(){
  3315. if(!this.bAutoResize || !this.oActivePlugin || typeof this.oActivePlugin.startAutoResize != "function"){
  3316. return;
  3317. }
  3318. this.oActivePlugin.startAutoResize();
  3319. },
  3320. /**
  3321. * [SMARTEDITORSUS-677] 해당 편집 모드에서의 자동확장을 중지함
  3322. */
  3323. stopAutoResize : function(){
  3324. if(!this.bAutoResize || !this.oActivePlugin || typeof this.oActivePlugin.stopAutoResize != "function"){
  3325. return;
  3326. }
  3327. this.oActivePlugin.stopAutoResize();
  3328. },
  3329. $ON_RESIZE_EDITING_AREA: function(ipNewWidth, ipNewHeight){
  3330. if(ipNewWidth !== null && typeof ipNewWidth !== "undefined"){
  3331. this._resizeWidth(ipNewWidth, "px");
  3332. }
  3333. if(ipNewHeight !== null && typeof ipNewHeight !== "undefined"){
  3334. this._resizeHeight(ipNewHeight, "px");
  3335. }
  3336. this._setEditingAreaDimension();
  3337. },
  3338. _resizeWidth : function(ipNewWidth, sUnit){
  3339. var iNewWidth = parseInt(ipNewWidth, 10);
  3340. if(iNewWidth < this.nMinWidth){
  3341. iNewWidth = this.nMinWidth;
  3342. }
  3343. if(ipNewWidth){
  3344. this.elEditingAreaContainer.style.width = iNewWidth + sUnit;
  3345. }
  3346. },
  3347. _resizeHeight : function(ipNewHeight, sUnit){
  3348. var iNewHeight = parseInt(ipNewHeight, 10);
  3349. if(iNewHeight < this.nMinHeight){
  3350. iNewHeight = this.nMinHeight;
  3351. }
  3352. if(ipNewHeight){
  3353. this.elEditingAreaContainer.style.height = iNewHeight + sUnit;
  3354. }
  3355. },
  3356. $ON_RESIZE_EDITING_AREA_BY : function(ipWidthChange, ipHeightChange){
  3357. var iWidthChange = parseInt(ipWidthChange, 10);
  3358. var iHeightChange = parseInt(ipHeightChange, 10);
  3359. var iWidth;
  3360. var iHeight;
  3361. if(ipWidthChange !== 0 && this.elEditingAreaContainer.style.width.indexOf("%") === -1){
  3362. iWidth = this.elEditingAreaContainer.style.width?parseInt(this.elEditingAreaContainer.style.width, 10)+iWidthChange:null;
  3363. }
  3364. if(iHeightChange !== 0){
  3365. iHeight = this.elEditingAreaContainer.style.height?this.iStartingHeight+iHeightChange:null;
  3366. }
  3367. if(!ipWidthChange && !iHeightChange){
  3368. return;
  3369. }
  3370. this.oApp.exec("RESIZE_EDITING_AREA", [iWidth, iHeight]);
  3371. },
  3372. $ON_MSG_EDITING_AREA_RESIZE_ENDED : function(FnMouseDown, FnMouseMove, FnMouseUp){
  3373. this.oApp.exec("HIDE_EDITING_AREA_COVER");
  3374. this.elEditingAreaContainer.style.overflow = "";
  3375. this._setEditingAreaDimension();
  3376. },
  3377. /**
  3378. * 편집영역에 커서가 들어가지 않도록 투명 커버를 씌운다.
  3379. * @param {Boolean} bDimmed 반투명 처리할지 여부
  3380. */
  3381. $ON_SHOW_EDITING_AREA_COVER : function(bDimmed){
  3382. if(!this.elEditingAreaCover){
  3383. this.elEditingAreaCover = document.createElement("DIV");
  3384. this.elEditingAreaCover.style.cssText = 'position:absolute;top:0;left:0;z-index:100;background:#000000;filter:alpha(opacity=0);opacity:0.0;-moz-opacity:0.0;-khtml-opacity:0.0;height:100%;width:100%';
  3385. this.elEditingAreaContainer.appendChild(this.elEditingAreaCover);
  3386. }
  3387. if(bDimmed){
  3388. jindo.$Element(this.elEditingAreaCover).opacity(0.4);
  3389. }
  3390. this.elEditingAreaCover.style.display = "block";
  3391. },
  3392. $ON_HIDE_EDITING_AREA_COVER : function(){
  3393. if(!this.elEditingAreaCover){
  3394. return;
  3395. }
  3396. this.elEditingAreaCover.style.display = "none";
  3397. jindo.$Element(this.elEditingAreaCover).opacity(0);
  3398. },
  3399. $ON_KEEP_WITHIN_EDITINGAREA : function(elLayer, nHeight){
  3400. var nTop = parseInt(elLayer.style.top, 10);
  3401. if(nTop + elLayer.offsetHeight > this.oApp.elEditingAreaContainer.offsetHeight){
  3402. if(typeof nHeight == "number"){
  3403. elLayer.style.top = nTop - elLayer.offsetHeight - nHeight + "px";
  3404. }else{
  3405. elLayer.style.top = this.oApp.elEditingAreaContainer.offsetHeight - elLayer.offsetHeight + "px";
  3406. }
  3407. }
  3408. var nLeft = parseInt(elLayer.style.left, 10);
  3409. if(nLeft + elLayer.offsetWidth > this.oApp.elEditingAreaContainer.offsetWidth){
  3410. elLayer.style.left = this.oApp.elEditingAreaContainer.offsetWidth - elLayer.offsetWidth + "px";
  3411. }
  3412. },
  3413. $ON_EVENT_EDITING_AREA_KEYDOWN : function(){
  3414. this.oApp.exec("HIDE_ACTIVE_LAYER", []);
  3415. },
  3416. $ON_EVENT_EDITING_AREA_MOUSEDOWN : function(){
  3417. this.oApp.exec("HIDE_ACTIVE_LAYER", []);
  3418. },
  3419. $ON_EVENT_EDITING_AREA_SCROLL : function(){
  3420. this.oApp.exec("HIDE_ACTIVE_LAYER", []);
  3421. },
  3422. _setEditingAreaDimension : function(oEditingAreaPlugin){
  3423. oEditingAreaPlugin = oEditingAreaPlugin || this.oActivePlugin;
  3424. this._fitElementInEditingArea(oEditingAreaPlugin.elEditingArea);
  3425. },
  3426. _fitElementInEditingArea : function(el){
  3427. el.style.height = this.elEditingAreaContainer.offsetHeight+"px";
  3428. // el.style.width = this.elEditingAreaContainer.offsetWidth+"px";
  3429. // el.style.width = this.elEditingAreaContainer.style.width || (this.elEditingAreaContainer.offsetWidth+"px");
  3430. },
  3431. attachDocumentEvents : function(doc){
  3432. this.oApp.registerBrowserEvent(doc, "click", "EVENT_EDITING_AREA_CLICK");
  3433. this.oApp.registerBrowserEvent(doc, "dblclick", "EVENT_EDITING_AREA_DBLCLICK");
  3434. this.oApp.registerBrowserEvent(doc, "mousedown", "EVENT_EDITING_AREA_MOUSEDOWN");
  3435. this.oApp.registerBrowserEvent(doc, "mousemove", "EVENT_EDITING_AREA_MOUSEMOVE");
  3436. this.oApp.registerBrowserEvent(doc, "mouseup", "EVENT_EDITING_AREA_MOUSEUP");
  3437. this.oApp.registerBrowserEvent(doc, "mouseout", "EVENT_EDITING_AREA_MOUSEOUT");
  3438. this.oApp.registerBrowserEvent(doc, "mousewheel", "EVENT_EDITING_AREA_MOUSEWHEEL");
  3439. this.oApp.registerBrowserEvent(doc, "keydown", "EVENT_EDITING_AREA_KEYDOWN");
  3440. this.oApp.registerBrowserEvent(doc, "keypress", "EVENT_EDITING_AREA_KEYPRESS");
  3441. this.oApp.registerBrowserEvent(doc, "keyup", "EVENT_EDITING_AREA_KEYUP");
  3442. this.oApp.registerBrowserEvent(doc, "scroll", "EVENT_EDITING_AREA_SCROLL");
  3443. },
  3444. $ON_GET_COVER_DIV : function(sAttr,oReturn){
  3445. if(!!this.elEditingAreaCover) {
  3446. oReturn[sAttr] = this.elEditingAreaCover;
  3447. }
  3448. },
  3449. $ON_SHOW_LOADING_LAYER : function(){
  3450. this.elLoadingLayer.style.display = 'block';
  3451. },
  3452. $ON_HIDE_LOADING_LAYER : function(){
  3453. this.elLoadingLayer.style.display = 'none';
  3454. },
  3455. getIR : function(){
  3456. if(!this.oActivePlugin){
  3457. return "";
  3458. }
  3459. return this.oActivePlugin.getIR();
  3460. },
  3461. setIR : function(sIR, bDontAddUndo){
  3462. this.oApp.exec("SET_IR", [sIR, bDontAddUndo]);
  3463. },
  3464. getRawContents : function(){
  3465. if(!this.oActivePlugin){
  3466. return "";
  3467. }
  3468. return this.oActivePlugin.getRawContents();
  3469. },
  3470. getContents : function(){
  3471. // [SMARTEDITORSUS-2077]
  3472. this._convertLastBrToNbsp();
  3473. var sIR = this.oApp.getIR();
  3474. var sContents;
  3475. if(this.oApp.applyConverter){
  3476. sContents = this.oApp.applyConverter("IR_TO_DB", sIR, this.oApp.getWYSIWYGDocument());
  3477. }else{
  3478. sContents = sIR;
  3479. }
  3480. sContents = this._cleanContents(sContents);
  3481. return sContents;
  3482. },
  3483. /**
  3484. * [SMARTEDITORSUS-2077]
  3485. * 문단 마지막 <br> 찾아서,
  3486. * 특수한 경우를 제외하고 모두 &nbsp; 변환한다.
  3487. *
  3488. * -NBSP로 변환해야 필요성
  3489. * --[IE 문서모드 8~10] 레이아웃 문단 내부 마지막 요소가 <br> 경우,
  3490. * <br> 줄의 높이를 가진 것처럼 표현되는 현상이 있음
  3491. *
  3492. * -NBSP로 변환하지 않고 <br> 제거하는 경우
  3493. * --레이아웃 <br> 바로 앞에 <img> 위치하고,
  3494. * <img>
  3495. * parentNode가 허용하는 최대 가로폭 이상의 가로 크기를 가지고 있어
  3496. * parentNode가 허용하는 최대 가로폭으로 리사이징된 경우
  3497. * ---<br> NBSP로 변환되면, <img> 아래줄로 밀려나 줄을 차지하게
  3498. *
  3499. */
  3500. _convertLastBrToNbsp : function(){
  3501. var elBody = this.oApp.getWYSIWYGDocument().body,
  3502. aBr, elBr,
  3503. elBrContainer, elImgContainer, elNextToImgContainer, elUndesiredContainer,
  3504. aImg, elImg, nImgWidth,
  3505. elImgParent, nParentWidth,
  3506. bConvertBrToNbsp,
  3507. oNbsp = document.createTextNode('\u00A0'), oNbspClone,
  3508. elBrParent;
  3509. // br:last-child 탐색
  3510. aBr = jindo.$$('br:last-child', elBody, {oneTimeOffCache : true});
  3511. for(var i = 0, len = aBr.length; i < len; i++){
  3512. elImg = null;
  3513. elBrParent = null;
  3514. elBr = aBr[i];
  3515. // <br>부터 부모로 거슬러 올라가면서, previousSibling이 있는지 찾는다.
  3516. elImgContainer = this._findNextSiblingRecursive(elBr, {isReverse : true});
  3517. if(!(elImgContainer && (elImgContainer.nodeType === 1))){
  3518. continue;
  3519. }
  3520. elBrContainer = elImgContainer.nextSibling;
  3521. /*
  3522. * <br> container에서 부모로 거슬러 올라가면서, nextSibling이 있는지 찾는다.
  3523. * nextSibling이 없다는 것이 확인되어야만,
  3524. * <br> container가 문단 마지막에 있다는 것을
  3525. * 보장할 있기 때문이다.
  3526. */
  3527. elUndesiredContainer = this._findNextSiblingRecursive(elBrContainer);
  3528. // <br> container 뒤의 container는 존재해서는 안 된다.
  3529. if(elUndesiredContainer){
  3530. continue;
  3531. }
  3532. if(elImgContainer.tagName.toUpperCase() === 'IMG'){
  3533. // previousSibling이 <img>이면 바로 할당
  3534. elImg = elImgContainer;
  3535. }else{
  3536. // previousSibling의 img:last-child 탐색
  3537. aImg = jindo.$$('img:last-child', elImgContainer, {oneTimeOffCache : true});
  3538. // 가장 마지막 <img>가 고려 대상이다. 즉, <br> 바로 앞에 위치하고 있을 것으로 추정되는 img
  3539. if(aImg.length > 0){
  3540. elImg = aImg[aImg.length - 1];
  3541. }
  3542. }
  3543. if(elImg){
  3544. /*
  3545. * <img> container 바로 뒤가 실제로 <br> container인지 확인.
  3546. * 레이아웃 상에서 실제로 <img> 뒤에 <br> 붙어 있는지 확인하는 과정이다.
  3547. */
  3548. elNextToImgContainer = this._findNextSiblingRecursive(elImg);
  3549. if(elNextToImgContainer == elBrContainer){
  3550. elImgParent = elImg.parentNode;
  3551. if(!elImgParent){
  3552. continue;
  3553. }
  3554. // <img>의 width 확인
  3555. nImgWidth = jindo.$Element(elImg).width(),
  3556. // <img> parentNode의 width 확인
  3557. elImgParent = elImg.parentNode,
  3558. nParentWidth = jindo.$Element(elImgParent).width();
  3559. /*
  3560. * <img> parentNode의 width가 같은지 확인하여
  3561. * <img> 뒤의 <br> &nbsp; 변환할지, 아니면 제거할지 판단한다.
  3562. */
  3563. bConvertBrToNbsp = !(nImgWidth === nParentWidth);
  3564. }else{
  3565. // <img> container와 <br> container 사이에 다른 container가 존재한다면, &nbsp;로 변환
  3566. bConvertBrToNbsp = true;
  3567. }
  3568. }else{
  3569. // img:last-child 가 존재하지 않으면, <br>을 &nbsp;로 변환
  3570. bConvertBrToNbsp = true;
  3571. }
  3572. elBrParent = elBr.parentNode;
  3573. if(bConvertBrToNbsp){
  3574. // <br>을 &nbsp;로 변환
  3575. oNbspClone = oNbsp.cloneNode(false);
  3576. elBrParent.replaceChild(oNbspClone, elBr);
  3577. }else{
  3578. // <br>을 &nbsp;로 변환하지 않고 제거해 버림
  3579. this._recursiveRemoveChild(elBr);
  3580. }
  3581. }
  3582. },
  3583. /**
  3584. * 대상 element의 nextSibling이 있는지
  3585. * tree를 거슬러 올라가며 recursive 탐색
  3586. *
  3587. * @param {HTMLElement} el 탐색 시작점 element
  3588. * @param {Object} htOption
  3589. * @param {Boolean} htOption.isReverse nextSibling 아닌, previousSibling을 탐색
  3590. */
  3591. _findNextSiblingRecursive : function(el, htOption){
  3592. var elTarget = el,
  3593. elSibling,
  3594. elParent,
  3595. isReverse = (htOption && htOption.isReverse) ? true : false,
  3596. rxParagraph = new RegExp('^(P|DIV)$', 'i'),
  3597. rxContainer = new RegExp('^(TD|BODY)$', 'i');
  3598. /*
  3599. * 종료 조건
  3600. * -container 역할을 하는 태그로 지정한 TD, BODY가 parentNode가 때까지 거슬러 올라감
  3601. * -sibling 존재
  3602. */
  3603. while(!elSibling){
  3604. if(isReverse){
  3605. elSibling = elTarget.previousSibling;
  3606. }else{
  3607. elSibling = elTarget.nextSibling;
  3608. }
  3609. elTarget = elTarget.parentNode;
  3610. if(rxContainer.test(elTarget.tagName)){
  3611. elSibling = null;
  3612. break;
  3613. }
  3614. }
  3615. return elSibling;
  3616. },
  3617. /**
  3618. * 대상 element를 parentNode에서 제거한다.
  3619. *
  3620. * 이후,
  3621. * parentNode 입장에서
  3622. * childNode가 아무것도 없으면
  3623. * parentNode에서 parentNode를 제거하는 작업을
  3624. * recursive로 수행한다.
  3625. */
  3626. _recursiveRemoveChild : function(el){
  3627. var elParent = el.parentNode,
  3628. elChild = el,
  3629. aChild;
  3630. do{
  3631. elParent.removeChild(elChild);
  3632. }while((aChild = elParent.childNodes) && (aChild.length == 0) && (elChild = elParent) && (elParent = elParent.parentNode))
  3633. },
  3634. _cleanContents : function(sContents){
  3635. return sContents.replace(new RegExp("(<img [^>]*>)"+unescape("%uFEFF")+"", "ig"), "$1");
  3636. },
  3637. setContents : function(sContents, bDontAddUndo){
  3638. var sIR;
  3639. if(this.oApp.applyConverter){
  3640. sIR = this.oApp.applyConverter("DB_TO_IR", sContents, this.oApp.getWYSIWYGDocument());
  3641. }else{
  3642. sIR = sContents;
  3643. }
  3644. this.oApp.exec("SET_IR", [sIR, bDontAddUndo]);
  3645. },
  3646. getEditingMode : function(){
  3647. return this.oActivePlugin.sMode;
  3648. },
  3649. getEditingAreaWidth : function(){
  3650. return this.elEditingAreaContainer.offsetWidth;
  3651. },
  3652. getEditingAreaHeight : function(){
  3653. return this.elEditingAreaContainer.offsetHeight;
  3654. }
  3655. });
  3656. var nSE2Version = "4a256db";
  3657. nhn.husky.SE_EditingAreaManager.version = {
  3658. revision : "4a256db",
  3659. type : "open",
  3660. number : "2.9.0"
  3661. };
  3662. /*[
  3663. * ENABLE_WYSIWYG
  3664. *
  3665. * 비활성화된 WYSIWYG 편집 영역을 활성화 시킨다.
  3666. *
  3667. * none
  3668. *
  3669. ---------------------------------------------------------------------------]*/
  3670. /*[
  3671. * DISABLE_WYSIWYG
  3672. *
  3673. * WYSIWYG 편집 영역을 비활성화 시킨다.
  3674. *
  3675. * none
  3676. *
  3677. ---------------------------------------------------------------------------]*/
  3678. /*[
  3679. * PASTE_HTML
  3680. *
  3681. * HTML을 편집 영역에 삽입한다.
  3682. *
  3683. * sHTML string 삽입할 HTML
  3684. * oPSelection object 붙여 넣기 영역, 생략시 현재 커서 위치
  3685. *
  3686. ---------------------------------------------------------------------------]*/
  3687. /*[
  3688. * RESTORE_IE_SELECTION
  3689. *
  3690. * (IE전용) 에디터에서 포커스가 나가는 시점에 기억해둔 포커스를 복구한다.
  3691. *
  3692. * none
  3693. *
  3694. ---------------------------------------------------------------------------]*/
  3695. /**
  3696. * @pluginDesc WYSIWYG 모드를 제공하는 플러그인
  3697. */
  3698. nhn.husky.SE_EditingArea_WYSIWYG = jindo.$Class({
  3699. name : "SE_EditingArea_WYSIWYG",
  3700. status : nhn.husky.PLUGIN_STATUS.NOT_READY,
  3701. sMode : "WYSIWYG",
  3702. iframe : null,
  3703. doc : null,
  3704. bStopCheckingBodyHeight : false,
  3705. bAutoResize : false, // [SMARTEDITORSUS-677] 해당 편집모드의 자동확장 기능 On/Off 여부
  3706. nBodyMinHeight : 0,
  3707. nScrollbarWidth : 0,
  3708. iLastUndoRecorded : 0,
  3709. // iMinUndoInterval : 50,
  3710. _nIFrameReadyCount : 50,
  3711. bWYSIWYGEnabled : false,
  3712. $init : function(iframe){
  3713. this.iframe = jindo.$(iframe);
  3714. var oAgent = jindo.$Agent().navigator();
  3715. // IE에서 에디터 초기화 시에 임의적으로 iframe에 포커스를 반쯤(IME 입력 안되고 커서만 깜박이는 상태) 주는 현상을 막기 위해서 일단 iframe을 숨겨 뒀다가 CHANGE_EDITING_MODE에서 위지윅 전환 시 보여준다.
  3716. // 이런 현상이 다양한 요소에 의해서 발생하며 발견된 몇가지 경우는,
  3717. // - frameset으로 페이지를 구성한 후에 한개의 frame안에 버튼을 두어 에디터로 링크 할 경우
  3718. // - iframe과 동일 페이지에 존재하는 text field에 값을 할당 할 경우
  3719. if(oAgent.ie){
  3720. this.iframe.style.display = "none";
  3721. }
  3722. // IE8 : 찾기/바꾸기에서 글자 일부에 스타일이 적용된 경우 찾기가 안되는 브라우저 버그로 인해 EmulateIE7 파일을 사용
  3723. // <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
  3724. this.sBlankPageURL = "smart_editor2_inputarea.html";
  3725. this.sBlankPageURL_EmulateIE7 = "smart_editor2_inputarea_ie8.html";
  3726. this.aAddtionalEmulateIE7 = [];
  3727. this.htOptions = nhn.husky.SE2M_Configuration.SE_EditingAreaManager;
  3728. if (this.htOptions) {
  3729. this.sBlankPageURL = this.htOptions.sBlankPageURL || this.sBlankPageURL;
  3730. this.sBlankPageURL_EmulateIE7 = this.htOptions.sBlankPageURL_EmulateIE7 || this.sBlankPageURL_EmulateIE7;
  3731. this.aAddtionalEmulateIE7 = this.htOptions.aAddtionalEmulateIE7 || this.aAddtionalEmulateIE7;
  3732. }
  3733. this.aAddtionalEmulateIE7.push(8); // IE8은 Default 사용
  3734. this.sIFrameSrc = this.sBlankPageURL;
  3735. if(oAgent.ie && jindo.$A(this.aAddtionalEmulateIE7).has(oAgent.nativeVersion)) {
  3736. this.sIFrameSrc = this.sBlankPageURL_EmulateIE7;
  3737. }
  3738. var sIFrameSrc = this.sIFrameSrc,
  3739. iframe = this.iframe,
  3740. fHandlerSuccess = jindo.$Fn(this.initIframe, this).bind(),
  3741. fHandlerFail =jindo.$Fn(function(){this.iframe.src = sIFrameSrc;}, this).bind();
  3742. if(!oAgent.ie || (oAgent.version >=9 && !!document.addEventListener)){
  3743. iframe.addEventListener("load", fHandlerSuccess, false);
  3744. iframe.addEventListener("error", fHandlerFail, false);
  3745. }else{
  3746. iframe.attachEvent("onload", fHandlerSuccess);
  3747. iframe.attachEvent("onerror", fHandlerFail);
  3748. }
  3749. iframe.src = sIFrameSrc;
  3750. this.elEditingArea = iframe;
  3751. },
  3752. $BEFORE_MSG_APP_READY : function(){
  3753. this.oEditingArea = this.iframe.contentWindow.document;
  3754. this.oApp.exec("REGISTER_EDITING_AREA", [this]);
  3755. this.oApp.exec("ADD_APP_PROPERTY", ["getWYSIWYGWindow", jindo.$Fn(this.getWindow, this).bind()]);
  3756. this.oApp.exec("ADD_APP_PROPERTY", ["getWYSIWYGDocument", jindo.$Fn(this.getDocument, this).bind()]);
  3757. this.oApp.exec("ADD_APP_PROPERTY", ["isWYSIWYGEnabled", jindo.$Fn(this.isWYSIWYGEnabled, this).bind()]);
  3758. this.oApp.exec("ADD_APP_PROPERTY", ["getRawHTMLContents", jindo.$Fn(this.getRawHTMLContents, this).bind()]);
  3759. this.oApp.exec("ADD_APP_PROPERTY", ["setRawHTMLContents", jindo.$Fn(this.setRawHTMLContents, this).bind()]);
  3760. if (!!this.isWYSIWYGEnabled()) {
  3761. this.oApp.exec('ENABLE_WYSIWYG_RULER');
  3762. }
  3763. this.oApp.registerBrowserEvent(this.getDocument().body, 'paste', 'EVENT_EDITING_AREA_PASTE');
  3764. this.oApp.registerBrowserEvent(this.getDocument().body, 'drop', 'EVENT_EDITING_AREA_DROP');
  3765. },
  3766. $ON_MSG_APP_READY : function(){
  3767. if(!this.oApp.hasOwnProperty("saveSnapShot")){
  3768. this.$ON_EVENT_EDITING_AREA_MOUSEUP = function(){};
  3769. this._recordUndo = function(){};
  3770. }
  3771. // uncomment this line if you wish to use the IE-style cursor in FF
  3772. // this.getDocument().body.style.cursor = "text";
  3773. // Do not update this._oIERange until the document is actually clicked (focus was given by mousedown->mouseup)
  3774. // Without this, iframe cannot be re-selected(by RESTORE_IE_SELECTION) if the document hasn't been clicked
  3775. // mousedown on iframe -> focus goes into the iframe doc -> beforedeactivate is fired -> empty selection is saved by the plugin -> empty selection is recovered in RESTORE_IE_SELECTION
  3776. this._bIERangeReset = true;
  3777. // [SMARTEDITORSUS-2149] win10_edge 추가 (TODO: 추후 win10 정식릴리즈시 ua 재확인필요)
  3778. if(this.oApp.oNavigator.ie || navigator.userAgent.indexOf("Edge") > -1){
  3779. this._bIECursorHide = true;
  3780. jindo.$Fn(
  3781. function(weEvent){
  3782. var oSelection = this.iframe.contentWindow.document.selection;
  3783. if(oSelection && oSelection.type.toLowerCase() === 'control' && weEvent.key().keyCode === 8){
  3784. this.oApp.exec("EXECCOMMAND", ['delete', false, false]);
  3785. weEvent.stop();
  3786. }
  3787. this._bIERangeReset = false;
  3788. }, this
  3789. ).attach(this.iframe.contentWindow.document, "keydown");
  3790. jindo.$Fn(
  3791. function(weEvent){
  3792. this._oIERange = null;
  3793. this._bIERangeReset = true;
  3794. }, this
  3795. ).attach(this.iframe.contentWindow.document.body, "mousedown");
  3796. // [SMARTEDITORSUS-1810] document.createRange 가 없는 경우만(IE8이하) beforedeactivate 이벤트 등록
  3797. if(!this.getDocument().createRange){
  3798. jindo.$Fn(this._onIEBeforeDeactivate, this).attach(this.iframe.contentWindow.document.body, "beforedeactivate");
  3799. }
  3800. jindo.$Fn(
  3801. function(weEvent){
  3802. this._bIERangeReset = false;
  3803. }, this
  3804. ).attach(this.iframe.contentWindow.document.body, "mouseup");
  3805. }else if(this.oApp.oNavigator.bGPadBrowser){
  3806. // [SMARTEDITORSUS-1802] GPad 에서만 툴바 터치시 셀렉션을 저장해둔다.
  3807. this.$ON_EVENT_TOOLBAR_TOUCHSTART = function(){
  3808. this._oIERange = this.oApp.getSelection().cloneRange();
  3809. }
  3810. }
  3811. // DTD가 quirks가 아닐 경우 body 높이 100%가 제대로 동작하지 않아서 타임아웃을 돌며 높이를 수동으로 계속 할당 해 줌
  3812. // body 높이가 제대로 설정 되지 않을 경우, 보기에는 이상없어 보이나 마우스로 텍스트 선택이 잘 안된다든지 하는 이슈가 있음
  3813. this.fnSetBodyHeight = jindo.$Fn(this._setBodyHeight, this).bind();
  3814. this.fnCheckBodyChange = jindo.$Fn(this._checkBodyChange, this).bind();
  3815. this.fnSetBodyHeight();
  3816. this._nContainerHeight = this.oApp.getEditingAreaHeight(); // 편집영역이 리사이즈되었는지 체크하기 위해 초기값 할당
  3817. this._setScrollbarWidth();
  3818. },
  3819. $ON_REGISTER_CONVERTERS : function(){
  3820. this.oApp.exec("ADD_CONVERTER_DOM", ["DB_TO_IR", jindo.$Fn(this._dbToIrDOM, this).bind()]);
  3821. },
  3822. /**
  3823. * [SMARTEDITORSUS-2315] setContents가 될때 폰트태그를 정제해준다.
  3824. */
  3825. _dbToIrDOM : function(oTmpNode){
  3826. nhn.husky.SE2M_Utils.removeInvalidFont(oTmpNode);
  3827. nhn.husky.SE2M_Utils.convertFontToSpan(oTmpNode);
  3828. },
  3829. /**
  3830. * 스크롤바의 사이즈 측정하여 설정
  3831. */
  3832. _setScrollbarWidth : function(){
  3833. var oDocument = this.getDocument(),
  3834. elScrollDiv = oDocument.createElement("div");
  3835. elScrollDiv.style.width = "100px";
  3836. elScrollDiv.style.height = "100px";
  3837. elScrollDiv.style.overflow = "scroll";
  3838. elScrollDiv.style.position = "absolute";
  3839. elScrollDiv.style.top = "-9999px";
  3840. oDocument.body.appendChild(elScrollDiv);
  3841. this.nScrollbarWidth = elScrollDiv.offsetWidth - elScrollDiv.clientWidth;
  3842. oDocument.body.removeChild(elScrollDiv);
  3843. },
  3844. /**
  3845. * [SMARTEDITORSUS-677] 붙여넣기나 내용 입력에 대한 편집영역 자동 확장 처리
  3846. */
  3847. $AFTER_EVENT_EDITING_AREA_KEYUP : function(oEvent){
  3848. if(!this.bAutoResize){
  3849. return;
  3850. }
  3851. var oKeyInfo = oEvent.key();
  3852. if((oKeyInfo.keyCode >= 33 && oKeyInfo.keyCode <= 40) || oKeyInfo.alt || oKeyInfo.ctrl || oKeyInfo.keyCode === 16){
  3853. return;
  3854. }
  3855. this._setAutoResize();
  3856. },
  3857. /**
  3858. * [SMARTEDITORSUS-677] 붙여넣기나 내용 입력에 대한 편집영역 자동 확장 처리
  3859. */
  3860. $AFTER_PASTE_HTML : function(){
  3861. if(!this.bAutoResize){
  3862. return;
  3863. }
  3864. this._setAutoResize();
  3865. },
  3866. /**
  3867. * [SMARTEDITORSUS-677] WYSIWYG 편집 영역 자동 확장 처리 시작
  3868. */
  3869. startAutoResize : function(){
  3870. this.oApp.exec("STOP_CHECKING_BODY_HEIGHT");
  3871. this.bAutoResize = true;
  3872. var oBrowser = this.oApp.oNavigator;
  3873. // [SMARTEDITORSUS-887] [블로그 1단] 자동확장 모드에서 에디터 가로사이즈보다 큰 사진을 추가했을 때 가로스크롤이 안생기는 문제
  3874. if(oBrowser.ie && oBrowser.version < 9){
  3875. jindo.$Element(this.getDocument().body).css({ "overflow" : "visible" });
  3876. // { "overflowX" : "visible", "overflowY" : "hidden" } 으로 설정하면 세로 스크롤 뿐 아니라 가로 스크롤도 보이지 않는 문제가 있어
  3877. // { "overflow" : "visible" } 로 처리하고 에디터의 container 사이즈를 늘려 세로 스크롤이 보이지 않도록 처리해야 함
  3878. // [한계] 자동 확장 모드에서 내용이 늘어날 때 세로 스크롤이 보였다가 없어지는 문제
  3879. }else{
  3880. jindo.$Element(this.getDocument().body).css({ "overflowX" : "visible", "overflowY" : "hidden" });
  3881. }
  3882. this._setAutoResize();
  3883. this.nCheckBodyInterval = setInterval(this.fnCheckBodyChange, 500);
  3884. this.oApp.exec("START_FLOAT_TOOLBAR"); // set scroll event
  3885. },
  3886. /**
  3887. * [SMARTEDITORSUS-677] WYSIWYG 편집 영역 자동 확장 처리 종료
  3888. */
  3889. stopAutoResize : function(){
  3890. this.bAutoResize = false;
  3891. clearInterval(this.nCheckBodyInterval);
  3892. this.oApp.exec("STOP_FLOAT_TOOLBAR"); // remove scroll event
  3893. jindo.$Element(this.getDocument().body).css({ "overflow" : "visible", "overflowY" : "visible" });
  3894. this.oApp.exec("START_CHECKING_BODY_HEIGHT");
  3895. },
  3896. /**
  3897. * [SMARTEDITORSUS-677] 편집 영역 Body가 변경되었는지 주기적으로 확인
  3898. */
  3899. _checkBodyChange : function(){
  3900. if(!this.bAutoResize){
  3901. return;
  3902. }
  3903. var nBodyLength = this.getDocument().body.innerHTML.length;
  3904. if(nBodyLength !== this.nBodyLength){
  3905. this.nBodyLength = nBodyLength;
  3906. this._setAutoResize();
  3907. }
  3908. },
  3909. /**
  3910. * [SMARTEDITORSUS-677] WYSIWYG 자동 확장 처리
  3911. */
  3912. _setAutoResize : function(){
  3913. var elBody = this.getDocument().body,
  3914. welBody = jindo.$Element(elBody),
  3915. nBodyHeight,
  3916. nContainerHeight,
  3917. oCurrentStyle,
  3918. nStyleSize,
  3919. bExpand = false,
  3920. oBrowser = this.oApp.oNavigator;
  3921. this.nTopBottomMargin = this.nTopBottomMargin || (parseInt(welBody.css("marginTop"), 10) + parseInt(welBody.css("marginBottom"), 10));
  3922. this.nBodyMinHeight = this.nBodyMinHeight || (this.oApp.getEditingAreaHeight() - this.nTopBottomMargin);
  3923. // 내용이 줄었을 경우, height를 줄여주기 위해 height를 0으로 조정하고
  3924. // scrollHeight 를 이용해 내용의 실제 높이값을 구한다.
  3925. welBody.css("height", "0px");
  3926. this.iframe.style.height = "0px";
  3927. nBodyHeight = parseInt(elBody.scrollHeight, 10);
  3928. if(nBodyHeight < this.nBodyMinHeight){ // 최소높이값 지정
  3929. nBodyHeight = this.nBodyMinHeight;
  3930. }
  3931. if(oBrowser.ie){
  3932. // 내용 뒤로 공간이 남아 보일 수 있으나 추가로 Container높이를 더하지 않으면
  3933. // 내용 가장 뒤에서 Enter를 하는 경우 아래위로 흔들려 보이는 문제가 발생
  3934. if(nBodyHeight > this.nBodyMinHeight){
  3935. oCurrentStyle = this.oApp.getCurrentStyle();
  3936. // [SMARTEDITORSUS-1756]
  3937. //nStyleSize = parseInt(oCurrentStyle.fontSize, 10) * oCurrentStyle.lineHeight;
  3938. nStyleSize = this._getStyleSize(oCurrentStyle);
  3939. // --[SMARTEDITORSUS-1756]
  3940. if(nStyleSize < this.nTopBottomMargin){
  3941. nStyleSize = this.nTopBottomMargin;
  3942. }
  3943. nContainerHeight = nBodyHeight + nStyleSize;
  3944. nContainerHeight += 18;
  3945. bExpand = true;
  3946. }else{
  3947. nBodyHeight = this.nBodyMinHeight;
  3948. nContainerHeight = this.nBodyMinHeight + this.nTopBottomMargin;
  3949. }
  3950. // }else if(oBrowser.safari){ // -- 사파리에서 내용이 줄어들지 않는 문제가 있어 Firefox 방식으로 변경함
  3951. // // [Chrome/Safari] 크롬이나 사파리에서는 Body와 iframe높이서 서로 연관되어 늘어나므로,
  3952. // // nContainerHeight를 추가로 더하는 경우 setTimeout 시 무한 증식되는 문제가 발생할 수 있음
  3953. // nBodyHeight = nBodyHeight > this.nBodyMinHeight ? nBodyHeight - this.nTopBottomMargin : this.nBodyMinHeight;
  3954. // nContainerHeight = nBodyHeight + this.nTopBottomMargin;
  3955. }else{
  3956. // [FF] nContainerHeight를 추가로 더하였음. setTimeout 시 무한 증식되는 문제가 발생할 수 있음
  3957. if(nBodyHeight > this.nBodyMinHeight){
  3958. oCurrentStyle = this.oApp.getCurrentStyle();
  3959. // [SMARTEDITORSUS-1756]
  3960. //nStyleSize = parseInt(oCurrentStyle.fontSize, 10) * oCurrentStyle.lineHeight;
  3961. nStyleSize = this._getStyleSize(oCurrentStyle);
  3962. // --[SMARTEDITORSUS-1756]
  3963. if(nStyleSize < this.nTopBottomMargin){
  3964. nStyleSize = this.nTopBottomMargin;
  3965. }
  3966. nContainerHeight = nBodyHeight + nStyleSize;
  3967. bExpand = true;
  3968. }else{
  3969. nBodyHeight = this.nBodyMinHeight;
  3970. nContainerHeight = this.nBodyMinHeight + this.nTopBottomMargin;
  3971. }
  3972. }
  3973. welBody.css("height", nBodyHeight + "px");
  3974. this.iframe.style.height = nContainerHeight + "px"; // 편집영역 IFRAME의 높이 변경
  3975. this.oApp.welEditingAreaContainer.height(nContainerHeight); // 편집영역 IFRAME을 감싸는 DIV 높이 변경
  3976. // [SMARTEDITORSUS-2036] 자동리사이즈기능으로 편집영역 크기가 변경되면 메시지를 발생시키도록 함
  3977. if(this._nContainerHeight !== nContainerHeight){
  3978. this._nContainerHeight = nContainerHeight;
  3979. this.oApp.exec('MSG_EDITING_AREA_SIZE_CHANGED');
  3980. }
  3981. //[SMARTEDITORSUS-941][iOS5대응]아이패드의 자동 확장 기능이 동작하지 않을 때 에디터 창보다 긴 내용을 작성하면 에디터를 뚫고 나오는 현상
  3982. //원인 : 자동확장 기능이 정지 될 경우 iframe에 스크롤이 생기지 않고, 창을 뚫고 나옴
  3983. //해결 : 항상 자동확장 기능이 켜져있도록 변경. 자동 확장 기능 관련한 이벤트 코드도 모바일 사파리에서 예외 처리
  3984. if(!this.oApp.oNavigator.msafari){
  3985. this.oApp.checkResizeGripPosition(bExpand);
  3986. }
  3987. },
  3988. // [SMARTEDITORSUS-1756]
  3989. _getStyleSize : function(oCurrentStyle){
  3990. /**
  3991. * this.iframe의 height style에 반영되는 높이값인
  3992. * nContainerHeight를 결정짓는 nStyleSize의 경우,
  3993. * 기존 로직에서는
  3994. * nStyleSize = parseInt(oCurrentStyle.fontSize, 10) * oCurrentStyle.lineHeight;
  3995. * 같이 값을 산정한다.
  3996. *
  3997. * SmartEditor에서만 생산한 컨텐츠의 경우,
  3998. * font-size 값은 px 단위형 숫자이고,
  3999. * line-height 값은 배수형 숫자이다.
  4000. *
  4001. * 따라서 nStyleSize는 산정으로 px 단위의 숫자값을 가지게 된다.
  4002. *
  4003. * 하지만 외부에서 붙여넣은 컨텐츠는 다양한 형태의 font-size값과 line-height 값을 가질 있다.
  4004. * 일부 값은 nStyleSize를 NaN으로 만들기 때문에,
  4005. * 컨텐츠가 화면에서 사라진 것처럼 보이는 현상을 일으킨다.
  4006. *
  4007. * 또한 "px 단위형 - 배수형" 이라는 틀에 맞지 않으면
  4008. * 부적절한 결과를 야기할 있다.
  4009. *
  4010. * 따라서 font-size 값을 px 단위형 숫자로,
  4011. * line-height 값을 배수형 숫자로 보정해 줘서,
  4012. * nStyleSize가 숫자형이 있도록 만들어 준다.
  4013. *
  4014. * line-height의 보정은 아래를 참조한다. (http://www.w3schools.com/cssref/pr_dim_line-height.asp)
  4015. * -"normal" : 통상 120% 대응하며, 정확한 값은 font-family에 좌우 (https://developer.mozilla.org/en-US/docs/Web/CSS/line-height)
  4016. * --ex) verdana 폰트
  4017. * ---12px~15 120% 대응
  4018. * ---16 115%
  4019. * ---17 120%
  4020. * ---18~20 125%
  4021. * -배수형 숫자
  4022. * -단위형 숫자 (pt, px, em, cm )
  4023. * --pt : 12pt = 16px = 100%
  4024. * --em : 1em = 12pt = 16px = 100%
  4025. * --cm : 1inch = 2.54cm = 96px 이므로 1cm = (1/2.54*96) = 37.795px
  4026. * -%
  4027. * -"initial"
  4028. * -"inherit" : 부모 엘리먼트의 값에 의해 좌우됨
  4029. *
  4030. * font-size의 보정은 아래를 참조한다. (http://www.w3schools.com/cssref/pr_font_font-size.asp)
  4031. * -"medium" : 16px = 100%
  4032. * -단위형은 line-height와 같이 처리
  4033. * */
  4034. var nResult;
  4035. if(oCurrentStyle){
  4036. // line-height 값을 배수형으로 보정
  4037. var nLineHeight = oCurrentStyle.lineHeight;
  4038. if(nLineHeight && /[^\d\.]/.test(nLineHeight)){ // 배수형이 아닌 경우
  4039. if(/\d/.test(nLineHeight) && /[A-Za-z]/.test(nLineHeight)){ // 단위형 : 실제 원하는 최종 결과값인 만큼, px 단위형으로 변환만 거친 뒤 return
  4040. if(/px$/.test(nLineHeight)){ // px 단위형 : 최종 결과값
  4041. return parseFloat(nLineHeight, 10);
  4042. }else if(/pt$/.test(nLineHeight)){ // pt 단위형
  4043. return parseFloat(nLineHeight, 10) * 4 / 3;
  4044. }else if(/em$/.test(nLineHeight)){ // em 단위형
  4045. return parseFloat(nLineHeight, 10) * 16;
  4046. }else if(/cm$/.test(nLineHeight)){ // cm 단위형
  4047. return parseFloat(nLineHeight, 10) * 96 / 2.54;
  4048. }
  4049. }else if(/\d/.test(nLineHeight) && /%/.test(nLineHeight)){ // %형
  4050. nLineHeight = parseFloat(nLineHeight, 10) * 100;
  4051. }else if(!/[^A-Za-z]/.test(nLineHeight)){ // TODO : "normal", "inherit", "initial" 세분화
  4052. nLineHeight = 1.2;
  4053. }
  4054. }
  4055. // font-size 값을 px 단위형으로 보정
  4056. var sFontSize = oCurrentStyle.fontSize;
  4057. if(sFontSize && !/px$/.test(sFontSize)){ // px 단위형이 아닌 경우
  4058. if(/pt$/.test(sFontSize)){ // pt 단위형
  4059. sFontSize = parseFloat(sFontSize, 10) * 4 / 3 + "px";
  4060. }else if(/em$/.test(sFontSize)){ // em 단위형
  4061. sFontSize = parseFloat(sFontSize, 10) * 16 + "px";
  4062. }else if(/cm$/.test(sFontSize)){ // cm 단위형
  4063. sFontSize = parseFloat(sFontSize, 10) * 96 / 2.54 + "px";
  4064. }else if(sFontSize == "medium"){ // "medium"
  4065. sFontSize = "16px";
  4066. }else{ // TODO : 다양한 small, large 종류가 존재
  4067. sFontSize = "16px";
  4068. }
  4069. }
  4070. nResult = parseFloat(sFontSize, 10) * nLineHeight;
  4071. }else{
  4072. nResult = 12 * 1.5;
  4073. }
  4074. return nResult;
  4075. },
  4076. // --[SMARTEDITORSUS-1756]
  4077. /**
  4078. * 스크롤 처리를 위해 편집영역 Body의 사이즈를 확인하고 설정함
  4079. * 편집영역 자동확장 기능이 Off인 경우에 주기적으로 실행됨
  4080. */
  4081. _setBodyHeight : function(){
  4082. if( this.bStopCheckingBodyHeight ){ // 멈춰야 하는 경우 true, 계속 체크해야 하면 false
  4083. // 위지윅 모드에서 다른 모드로 변경할 때 "document는 css를 사용 할수 없습니다." 라는 error 가 발생.
  4084. // 그래서 on_change_mode에서 bStopCheckingBodyHeight 를 true로 변경시켜줘야 함.
  4085. return;
  4086. }
  4087. var elBody = this.getDocument().body,
  4088. welBody = jindo.$Element(elBody),
  4089. nMarginTopBottom = parseInt(welBody.css("marginTop"), 10) + parseInt(welBody.css("marginBottom"), 10),
  4090. nContainerOffset = this.oApp.getEditingAreaHeight(),
  4091. nMinBodyHeight = nContainerOffset - nMarginTopBottom,
  4092. nBodyHeight = welBody.height(),
  4093. nScrollHeight,
  4094. nNewBodyHeight;
  4095. this.nTopBottomMargin = nMarginTopBottom;
  4096. if(nBodyHeight === 0){ // [SMARTEDITORSUS-144] height 가 0 이고 내용이 없으면 크롬10 에서 캐럿이 보이지 않음
  4097. welBody.css("height", nMinBodyHeight + "px");
  4098. setTimeout(this.fnSetBodyHeight, 500);
  4099. return;
  4100. }
  4101. /**
  4102. * [SMARTEDITORSUS-1972] [IE 11] 마지막 변경된 body height에서 변화가 없는 경우 0px로 축소하지 않음
  4103. * */
  4104. var htBrowser = jindo.$Agent().navigator(),
  4105. isIE11 = (htBrowser.ie && htBrowser.nativeVersion === 11),
  4106. isShrinkingUnnecessary = (this.nBodyHeight_last === nBodyHeight);
  4107. if(!(isIE11 && isShrinkingUnnecessary)){
  4108. welBody.css("height", "0px");
  4109. }
  4110. // Previous below
  4111. /*welBody.css("height", "0px");*/
  4112. // --[SMARTEDITORSUS-1972]
  4113. // [SMARTEDITORSUS-257] IE9, 크롬에서 내용을 삭제해도 스크롤이 남아있는 문제 처리
  4114. // body 에 내용이 없어져도 scrollHeight 가 줄어들지 않아 height 를 강제로 0 으로 설정
  4115. nScrollHeight = parseInt(elBody.scrollHeight, 10);
  4116. nNewBodyHeight = (nScrollHeight > nContainerOffset ? nScrollHeight - nMarginTopBottom : nMinBodyHeight);
  4117. // nMarginTopBottom 을 빼지 않으면 스크롤이 계속 늘어나는 경우가 있음 (참고 [BLOGSUS-17421])
  4118. if(this._isHorizontalScrollbarVisible()){
  4119. nNewBodyHeight -= this.nScrollbarWidth;
  4120. }
  4121. // [SMARTEDITORSUS-1972]
  4122. if(!(isIE11 && isShrinkingUnnecessary)){
  4123. welBody.css("height", nNewBodyHeight + "px");
  4124. }
  4125. this.nBodyHeight_last = nNewBodyHeight;
  4126. // Previous below
  4127. /*welBody.css("height", nNewBodyHeight + "px");*/
  4128. // --[SMARTEDITORSUS-1972]
  4129. setTimeout(this.fnSetBodyHeight, 500);
  4130. },
  4131. /**
  4132. * 가로 스크롤바 생성 확인
  4133. */
  4134. _isHorizontalScrollbarVisible : function(){
  4135. var oDocument = this.getDocument();
  4136. if(oDocument.documentElement.clientWidth < oDocument.documentElement.scrollWidth){
  4137. //oDocument.body.clientWidth < oDocument.body.scrollWidth ||
  4138. return true;
  4139. }
  4140. return false;
  4141. },
  4142. /**
  4143. * body의 offset체크를 멈추게 하는 함수.
  4144. */
  4145. $ON_STOP_CHECKING_BODY_HEIGHT :function(){
  4146. if(!this.bStopCheckingBodyHeight){
  4147. this.bStopCheckingBodyHeight = true;
  4148. }
  4149. },
  4150. /**
  4151. * body의 offset체크를 계속 진행.
  4152. */
  4153. $ON_START_CHECKING_BODY_HEIGHT :function(){
  4154. if(this.bStopCheckingBodyHeight){
  4155. this.bStopCheckingBodyHeight = false;
  4156. this.fnSetBodyHeight();
  4157. }
  4158. },
  4159. $ON_IE_CHECK_EXCEPTION_FOR_SELECTION_PRESERVATION : function(){
  4160. // 현재 선택된 앨리먼트가 iframe이라면, 셀렉션을 따로 기억 해 두지 않아도 유지 됨으로 RESTORE_IE_SELECTION을 타지 않도록 this._oIERange을 지워준다.
  4161. // (필요 없을 뿐더러 저장 시 문제 발생)
  4162. var oSelection = this.getDocument().selection;
  4163. if(oSelection && oSelection.type === "Control"){
  4164. this._oIERange = null;
  4165. }
  4166. },
  4167. _onIEBeforeDeactivate : function(wev){
  4168. this.oApp.delayedExec("IE_CHECK_EXCEPTION_FOR_SELECTION_PRESERVATION", null, 0);
  4169. if(this._oIERange){
  4170. return;
  4171. }
  4172. // without this, cursor won't make it inside a table.
  4173. // mousedown(_oIERange gets reset) -> beforedeactivate(gets fired for table) -> RESTORE_IE_SELECTION
  4174. if(this._bIERangeReset){
  4175. return;
  4176. }
  4177. this._oIERange = this.oApp.getSelection().cloneRange();
  4178. },
  4179. $ON_CHANGE_EDITING_MODE : function(sMode, bNoFocus){
  4180. if(sMode === this.sMode){
  4181. // [SMARTEDITORSUS-1213][IE9, 10] 사진 삭제 후 zindex 1000인 div가 잔존하는데, 그 위로 썸네일 drag를 시도하다 보니 drop이 불가능.
  4182. var htBrowser = jindo.$Agent().navigator();
  4183. if(htBrowser.ie && htBrowser.nativeVersion > 8){
  4184. var elFirstChild = jindo.$$.getSingle("DIV.husky_seditor_editing_area_container").childNodes[0];
  4185. if((elFirstChild.tagName == "DIV") && (elFirstChild.style.zIndex == 1000)){
  4186. elFirstChild.parentNode.removeChild(elFirstChild);
  4187. }
  4188. }
  4189. // --[SMARTEDITORSUS-1213]
  4190. /**
  4191. * [SMARTEDITORSUS-1889]
  4192. * visibility 속성을 사용해서 Editor를 표시하고 숨김
  4193. * , 에디터 초기화 필요한 display:block 설정은 유지
  4194. *
  4195. * */
  4196. this.iframe.style.visibility = "visible";
  4197. if(this.iframe.style.display != "block"){ // 초기화 시 최초 1회
  4198. this.iframe.style.display = "block";
  4199. }
  4200. // Previous below
  4201. //this.iframe.style.display = "block";
  4202. // --[SMARTEDITORSUS-1889]
  4203. this.oApp.exec("SET_EDITING_WINDOW", [this.getWindow()]);
  4204. this.oApp.exec("START_CHECKING_BODY_HEIGHT");
  4205. }else{
  4206. /**
  4207. * [SMARTEDITORSUS-1889]
  4208. * 모드 전환 display:none과 display:block을 사용해서
  4209. * Editor 영역을 표시하고 숨기는 경우,
  4210. * iframe 요소가 때마다 다시 로드되는 과정에서
  4211. * 스크립트 오류를 유발시킴 (국내지도)
  4212. *
  4213. * 따라서 visibility 속성을 대신 사용하고,
  4214. * 경우 Editor 영역이 공간을 여전히 차지하고 있기 때문에
  4215. * 아래 위치하게 수밖에 없는
  4216. * HTML 영역이나 Text 영역은
  4217. * position:absolute와 top 속성을 사용하여
  4218. * 위로 끌어올리는 방법을 사용
  4219. * */
  4220. this.iframe.style.visibility = "hidden";
  4221. // previous below
  4222. //this.iframe.style.display = "none";
  4223. // --[SMARTEDITORSUS-1889]
  4224. this.oApp.exec("STOP_CHECKING_BODY_HEIGHT");
  4225. }
  4226. },
  4227. $AFTER_CHANGE_EDITING_MODE : function(sMode, bNoFocus){
  4228. this._oIERange = null;
  4229. },
  4230. $ON_ENABLE_WYSIWYG : function(){
  4231. this._enableWYSIWYG();
  4232. },
  4233. $ON_DISABLE_WYSIWYG : function(){
  4234. this._disableWYSIWYG();
  4235. },
  4236. $ON_IE_HIDE_CURSOR : function(){
  4237. if(!this._bIECursorHide){
  4238. return;
  4239. }
  4240. this._onIEBeforeDeactivate();
  4241. // De-select the default selection.
  4242. // [SMARTEDITORSUS-978] IE9에서 removeAllRanges로 제거되지 않아
  4243. // 이전 IE와 동일하게 empty 방식을 사용하도록 하였으나 doc.selection.type이 None인 경우 에러
  4244. // Range를 재설정 해주어 selectNone 으로 처리되도록 예외처리
  4245. var oSelection = this.oApp.getWYSIWYGDocument().selection;
  4246. if(oSelection && oSelection.createRange){
  4247. try{
  4248. oSelection.empty();
  4249. }catch(e){
  4250. // [SMARTEDITORSUS-1003] IE9 / doc.selection.type === "None"
  4251. oSelection = this.oApp.getSelection();
  4252. oSelection.select();
  4253. oSelection.oBrowserSelection.selectNone();
  4254. }
  4255. }else{
  4256. this.oApp.getEmptySelection().oBrowserSelection.selectNone();
  4257. this.getDocument().body.blur(); // [SMARTEDITORSUS-2149] win10_edge 에서 커서가 보이지 않도록 하려면 blur 해줘야 한다.
  4258. }
  4259. },
  4260. $AFTER_SHOW_ACTIVE_LAYER : function(){
  4261. this.oApp.exec("IE_HIDE_CURSOR");
  4262. this.bActiveLayerShown = true;
  4263. },
  4264. $BEFORE_EVENT_EDITING_AREA_KEYDOWN : function(oEvent){
  4265. this._bKeyDown = true;
  4266. },
  4267. $ON_EVENT_EDITING_AREA_KEYDOWN : function(oEvent){
  4268. if(this.oApp.getEditingMode() !== this.sMode){
  4269. return;
  4270. }
  4271. var oKeyInfo = oEvent.key();
  4272. if(this.oApp.oNavigator.ie){
  4273. //var oKeyInfo = oEvent.key();
  4274. switch(oKeyInfo.keyCode){
  4275. case 33:
  4276. this._pageUp(oEvent);
  4277. break;
  4278. case 34:
  4279. this._pageDown(oEvent);
  4280. break;
  4281. case 8: // [SMARTEDITORSUS-495][SMARTEDITORSUS-548] IE에서 표가 삭제되지 않는 문제
  4282. this._backspace(oEvent);
  4283. break;
  4284. case 46: // [SMARTEDITORSUS-2064] IE11은 delete 로 테이블 삭제가 안되서 추가함
  4285. this._delete(oEvent);
  4286. break;
  4287. default:
  4288. }
  4289. }else if(this.oApp.oNavigator.firefox){
  4290. // [SMARTEDITORSUS-151] FF 에서 표가 삭제되지 않는 문제
  4291. if(oKeyInfo.keyCode === 8){ // backspace
  4292. this._backspace(oEvent);
  4293. }
  4294. }
  4295. this._recordUndo(oKeyInfo); // 첫번째 Delete 키 입력 전의 상태가 저장되도록 KEYDOWN 시점에 저장
  4296. },
  4297. /**
  4298. * IE와 FF에서 백스페이스로 테이블이 삭제되지 않기 때문에 강제삭제 처리
  4299. */
  4300. _backspace : function(weEvent){
  4301. var oPrevNode = this._prepareBackspaceDelete(true);
  4302. if(!oPrevNode){
  4303. return;
  4304. }
  4305. if(this._removeUnremovable(oPrevNode, true)){
  4306. // table 처럼 키로 삭제가 안되는 경우 강제 삭제하고 이벤트를 중단한다.
  4307. weEvent.stop();
  4308. }
  4309. },
  4310. /**
  4311. * [SMARTEDITORSUS-2064] IE11은 delete 테이블 삭제가 안되서 추가함
  4312. * [SMARTEDITORSUS-2184] span > p 역전현상으로 인한 오류 보정 로직 추가
  4313. */
  4314. _delete : function(weEvent){
  4315. var oNextNode = this._prepareBackspaceDelete(false);
  4316. if(!oNextNode){
  4317. return;
  4318. }
  4319. if(this._removeUnremovable(oNextNode, false)){
  4320. // table 처럼 키로 삭제가 안되는 경우 강제 삭제하고 이벤트를 중단한다.
  4321. weEvent.stop();
  4322. }else if(oNextNode.nodeType === 3){
  4323. // [SMARTEDITORSUS-2184] 텍스트 노드이면 다음 라인을 확인하여 span > p 역전된 경우 span 만 제거하도록 처리
  4324. var oLineInfo = this.oApp.getSelection().getLineInfo(),
  4325. oEnd = oLineInfo.oEnd.oLineBreaker,
  4326. oNextLine = oEnd && oEnd.nextSibling;
  4327. this._removeWrongSpan(oNextLine);
  4328. }else{
  4329. // [SMARTEDITORSUS-2184] span > p 역전된 경우 span 만 제거하도록 처리
  4330. this._removeWrongSpan(oNextNode);
  4331. }
  4332. },
  4333. /**
  4334. * backspace/delete 키에 대한 공통 전처리 과정으로
  4335. * 셀렉션레인지가 collapsed 상태인 경우 주변의 노드를 반환한다.
  4336. * @param {Boolean} bBackspace 백스페이스키 여부 (true 앞쪽노드를 찾고 false 뒤쪽노드를 찾는다.)
  4337. * @returns {Node} 찾은 주변 노드
  4338. */
  4339. _prepareBackspaceDelete : function(bBackspace){
  4340. var oSelection = this.oApp.getSelection();
  4341. if(!oSelection.collapsed){
  4342. return;
  4343. }
  4344. var oNode = oSelection.getNodeAroundRange(bBackspace, false);
  4345. // LineFeed 텍스트노드라면 다음 노드를 할당
  4346. if(this._isLineFeed(oNode)){
  4347. oNode = bBackspace ? oSelection._getPrevNode(oNode) : oSelection._getNextNode(oNode);
  4348. }
  4349. /*
  4350. * [SMARTEDITORSUS-1575] 빈라인에 커서홀더가 삽입된 상태에서는
  4351. * 키를 두번 쳐야 빈줄이 삭제되기 때문에 미리 커서홀더문자는 제거한다.
  4352. */
  4353. this._clearCursorHolderValue(oNode);
  4354. return oNode;
  4355. },
  4356. /**
  4357. * 해당 텍스트 노드가 LineFeed(\n) 로만 이루어졌는지 여부
  4358. * @param {Node} oNode 확인할 노드
  4359. * @returns {Boolean} LineFeed(\n) 로만 이루어진 텍스트노드인지 여부
  4360. */
  4361. _isLineFeed : function(oNode){
  4362. return (oNode && oNode.nodeType === 3 && /^[\n]*$/.test(oNode.nodeValue));
  4363. },
  4364. /**
  4365. * 해당 텍스트 노드의 값이 커서홀더 문자이면 값을 비운다. (노드자체를 제거하지 않고 문자값만 비운다.)
  4366. * @param {Node} oNode 확인할 노드
  4367. */
  4368. _clearCursorHolderValue : function(oNode){
  4369. if(oNode && oNode.nodeType === 3 &&
  4370. (oNode.nodeValue === "\u200B" || oNode.nodeValue === "\uFEFF")){
  4371. oNode.nodeValue = "";
  4372. }
  4373. },
  4374. /**
  4375. * backspace나 delete 키로 삭제가 안되는 요소를 강제 삭제한다.
  4376. * @param {Node} oNode 확인할 노드
  4377. * @param {Boolean} bBackspace 백스페이스키 여부
  4378. * @returns {Boolean} 삭제되었으면 true 반환
  4379. */
  4380. _removeUnremovable : function(oNode, bBackspace){
  4381. var bRemoved = false;
  4382. if(!oNode){
  4383. return false;
  4384. }
  4385. if(oNode.nodeName === "TABLE"){
  4386. oNode.parentNode.removeChild(oNode);
  4387. bRemoved = true;
  4388. }else if(oNode.nodeName === "DIV"){
  4389. /*
  4390. * IE의 경우 텍스트가 없는 블럭요소가 삭제되지 않기 때문에 별도 처리함
  4391. * TODO: div 뿐만 아니라 다른 블럭요소도 마찬가지일 것으로 추정되나 일단 div에 대해서만 한정 처리함
  4392. */
  4393. var oChild = bBackspace ? oNode.lastChild : oNode.firstChild;
  4394. if(!oChild){
  4395. oNode.parentNode.removeChild(oNode);
  4396. bRemoved = true;
  4397. }else if(oChild.nodeName === "TABLE"){
  4398. oNode.removeChild(oChild);
  4399. bRemoved = true;
  4400. }else if(oChild.nodeType === 1 && jindo.$S(oChild.innerHTML).trim() == ""){
  4401. oNode.removeChild(oChild);
  4402. bRemoved = true;
  4403. }
  4404. }
  4405. return bRemoved;
  4406. },
  4407. /**
  4408. * [SMARTEDITORSUS-2184] span 안쪽에 p태그가 있는 경우 span의 모든 child 노드를 밖으로 빼내고 제거한다.
  4409. * known-issue: span에 스타일이 적용되어 있을 경우, 적용된 스타일이 풀려버린다.
  4410. * 잘못된 span에 적용된 스타일을 무조건 안쪽에 넣어주기에는 위험도가 있어서 별도 처리하지 않음
  4411. * @param {Node} oNode 확인할 노드
  4412. */
  4413. _removeWrongSpan : function(oNode){
  4414. if(oNode && oNode.nodeName === "SPAN" && oNode.firstChild && oNode.firstChild.nodeName === "P"){
  4415. var oParentNode = oNode.parentNode;
  4416. while(oNode.firstChild){
  4417. oParentNode.insertBefore(oNode.firstChild, oNode);
  4418. }
  4419. oParentNode.removeChild(oNode);
  4420. }
  4421. },
  4422. $BEFORE_EVENT_EDITING_AREA_KEYUP : function(oEvent){
  4423. // IE(6) sometimes fires keyup events when it should not and when it happens the keyup event gets fired without a keydown event
  4424. if(!this._bKeyDown){
  4425. return false;
  4426. }
  4427. this._bKeyDown = false;
  4428. },
  4429. $ON_EVENT_EDITING_AREA_MOUSEUP : function(oEvent){
  4430. this.oApp.saveSnapShot();
  4431. },
  4432. $BEFORE_PASTE_HTML : function(){
  4433. if(this.oApp.getEditingMode() !== this.sMode){
  4434. this.oApp.exec("CHANGE_EDITING_MODE", [this.sMode]);
  4435. }
  4436. },
  4437. /**
  4438. * @param {String} sHTML 삽입할 HTML
  4439. * @param {HuskyRange} oPSelection 재사용할 Selection 객체
  4440. * @param {HashTable} htOption 추가옵션
  4441. * @param {Boolean} htOption.bNoUndo UNDO 히스토리를 저장하지 않을지 여부
  4442. * @param {Boolean} htOption.bBlock HTML 삽입시 강제로 block 요소 처리할지 여부(true 이면 P태그 안에 삽입될 경우, P태그를 무조건 쪼개고 사이에 DIV태그로 감싸서 삽입한다.)
  4443. */
  4444. $ON_PASTE_HTML : function(sHTML, oPSelection, htOption){
  4445. htOption = htOption || {};
  4446. var oSelection, oNavigator, sTmpBookmark,
  4447. oStartContainer, aImgChild, elLastImg, elChild, elNextChild;
  4448. if(this.oApp.getEditingMode() !== this.sMode){
  4449. return;
  4450. }
  4451. // [SMARTEDITORSUS-2023] 편집영역에 포커스가 없는 상태에서 PASTE_HTML 을 수행하면
  4452. // <p>태그 바깥쪽으로 삽입되기 때문에 pasteHTML 전에 포커스를 준다.
  4453. this.focus();
  4454. if(!htOption.bNoUndo){
  4455. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["PASTE HTML"]);
  4456. }
  4457. oNavigator = jindo.$Agent().navigator();
  4458. oSelection = oPSelection || this.oApp.getSelection();
  4459. //[SMARTEDITORSUS-888] 브라우저 별 테스트 후 아래 부분이 불필요하여 제거함
  4460. // - [SMARTEDITORSUS-387] IE9 표준모드에서 엘리먼트 뒤에 어떠한 엘리먼트도 없는 상태에서 커서가 안들어가는 현상.
  4461. // if(oNavigator.ie && oNavigator.nativeVersion >= 9 && document.documentMode >= 9){
  4462. // sHTML = sHTML + unescape("%uFEFF");
  4463. // }
  4464. //[SMARTEDITORSUS-2043] IE8의 경우 FEFF 로 인해 한줄 내려가는 현상이 생겨서 아래 부분 제거함
  4465. //if(oNavigator.ie && oNavigator.nativeVersion == 8 && document.documentMode == 8){
  4466. // sHTML = sHTML + unescape("%uFEFF");
  4467. //}
  4468. oSelection.pasteHTML(sHTML, htOption.bBlock);
  4469. // every browser except for IE may modify the innerHTML when it is inserted
  4470. if(!oNavigator.ie){
  4471. sTmpBookmark = oSelection.placeStringBookmark();
  4472. this.oApp.getWYSIWYGDocument().body.innerHTML = this.oApp.getWYSIWYGDocument().body.innerHTML;
  4473. oSelection.moveToBookmark(sTmpBookmark);
  4474. oSelection.collapseToEnd();
  4475. oSelection.select();
  4476. oSelection.removeStringBookmark(sTmpBookmark);
  4477. // [SMARTEDITORSUS-56] 사진을 연속으로 첨부할 경우 연이어 삽입되지 않는 현상으로 이슈를 발견하게 되었습니다.
  4478. // 그러나 이는 비단 '다수의 사진을 첨부할 경우'에만 발생하는 문제는 아니었고,
  4479. // 원인 확인 결과 컨텐츠 삽입 후 기존 Bookmark 삭제 시 갱신된 Selection 이 제대로 반영되지 않는 점이 있었습니다.
  4480. // 이에, Selection 을 갱신하는 코드를 추가하였습니다.
  4481. oSelection = this.oApp.getSelection();
  4482. //[SMARTEDITORSUS-831] 비IE 계열 브라우저에서 스크롤바가 생기게 문자입력 후 엔터 클릭하지 않은 상태에서
  4483. //이미지 하나 삽입 시 이미지에 포커싱이 놓이지 않습니다.
  4484. //원인 : parameter로 넘겨 받은 oPSelecion에 변경된 값을 복사해 주지 않아서 발생
  4485. //해결 : parameter로 넘겨 받은 oPSelecion에 변경된 값을 복사해준다
  4486. // call by reference로 넘겨 받았으므로 직접 객체 안의 인자 값을 바꿔주는 setRange 함수 사용
  4487. if(!!oPSelection){
  4488. oPSelection.setRange(oSelection);
  4489. }
  4490. }else{
  4491. // [SMARTEDITORSUS-428] [IE9.0] IE9에서 포스트 쓰기에 접근하여 맨위에 임의의 글감 첨부 후 엔터를 클릭 시 글감이 사라짐
  4492. // PASTE_HTML 후에 IFRAME 부분이 선택된 상태여서 Enter 시 내용이 제거되어 발생한 문제
  4493. oSelection.collapseToEnd();
  4494. oSelection.select();
  4495. this._oIERange = null;
  4496. this._bIERangeReset = false;
  4497. }
  4498. // [SMARTEDITORSUS-639] 사진 첨부 후 이미지 뒤의 공백으로 인해 스크롤이 생기는 문제
  4499. if(sHTML.indexOf("<img") > -1){
  4500. oStartContainer = oSelection.startContainer;
  4501. if(oStartContainer.nodeType === 1 && oStartContainer.tagName === "P"){
  4502. aImgChild = jindo.$Element(oStartContainer).child(function(v){
  4503. return (v.$value().nodeType === 1 && v.$value().tagName === "IMG");
  4504. }, 1);
  4505. if(aImgChild.length > 0){
  4506. elLastImg = aImgChild[aImgChild.length - 1].$value();
  4507. elChild = elLastImg.nextSibling;
  4508. while(elChild){
  4509. elNextChild = elChild.nextSibling;
  4510. if (elChild.nodeType === 3 && (elChild.nodeValue === "&nbsp;" || elChild.nodeValue === unescape("%u00A0"))) {
  4511. oStartContainer.removeChild(elChild);
  4512. }
  4513. elChild = elNextChild;
  4514. }
  4515. }
  4516. }
  4517. }
  4518. if(!htOption.bNoUndo){
  4519. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["PASTE HTML"]);
  4520. }
  4521. },
  4522. /**
  4523. * [SMARTEDITORSUS-344]사진/동영상/지도 연속첨부시 포커싱 개선이슈로 추가되 함수.
  4524. */
  4525. $ON_FOCUS_N_CURSOR : function (bEndCursor, sId){
  4526. var el, oSelection;
  4527. if(sId && ( el = jindo.$(sId, this.getDocument()) )){
  4528. // ID가 지정된 경우, 무조건 해당 부분으로 커서 이동
  4529. clearTimeout(this._nTimerFocus); // 연속 삽입될 경우, 미완료 타이머는 취소한다.
  4530. this._nTimerFocus = setTimeout(jindo.$Fn(function(el){
  4531. this._scrollIntoView(el);
  4532. this.oApp.exec("FOCUS");
  4533. }, this).bind(el), 300);
  4534. return;
  4535. }
  4536. oSelection = this.oApp.getSelection();
  4537. if(!oSelection.collapsed){ // select 영역이 있는 경우
  4538. if(bEndCursor){
  4539. oSelection.collapseToEnd();
  4540. } else {
  4541. oSelection.collapseToStart();
  4542. }
  4543. oSelection.select();
  4544. }else if(bEndCursor){ // select 영역이 없는 상태에서 bEndCursor 이면 body 맨 뒤로 이동시킨다.
  4545. this.oApp.exec("FOCUS");
  4546. el = this.getDocument().body;
  4547. oSelection.selectNode(el);
  4548. oSelection.collapseToEnd();
  4549. oSelection.select();
  4550. this._scrollIntoView(el);
  4551. }else{ // select 영역이 없는 상태라면 focus만 준다.
  4552. this.oApp.exec("FOCUS");
  4553. }
  4554. },
  4555. /*
  4556. * 엘리먼트의 top, bottom 값을 반환
  4557. */
  4558. _getElementVerticalPosition : function(el){
  4559. var nTop = 0,
  4560. elParent = el,
  4561. htPos = {nTop : 0, nBottom : 0};
  4562. if(!el){
  4563. return htPos;
  4564. }
  4565. // 테스트코드를 실행하면 IE8 이하에서 offsetParent 접근시 다음과 같이 알 수 없는 exception 이 발생함
  4566. // "SCRIPT16389: 지정되지 않은 오류입니다."
  4567. // TODO: 해결방법이 없어서 일단 try/catch 처리했지만 추후 정확한 이유를 파악할 필요가 있음
  4568. try{
  4569. while(elParent) {
  4570. nTop += elParent.offsetTop;
  4571. elParent = elParent.offsetParent;
  4572. }
  4573. }catch(e){}
  4574. htPos.nTop = nTop;
  4575. htPos.nBottom = nTop + jindo.$Element(el).height();
  4576. return htPos;
  4577. },
  4578. /*
  4579. * Window에서 현재 보여지는 영역의 top, bottom 값을 반환
  4580. */
  4581. _getVisibleVerticalPosition : function(){
  4582. var oWindow, oDocument, nVisibleHeight,
  4583. htPos = {nTop : 0, nBottom : 0};
  4584. oWindow = this.getWindow();
  4585. oDocument = this.getDocument();
  4586. nVisibleHeight = oWindow.innerHeight ? oWindow.innerHeight : oDocument.documentElement.clientHeight || oDocument.body.clientHeight;
  4587. htPos.nTop = oWindow.pageYOffset || oDocument.documentElement.scrollTop;
  4588. htPos.nBottom = htPos.nTop + nVisibleHeight;
  4589. return htPos;
  4590. },
  4591. /*
  4592. * 엘리먼트가 WYSIWYG Window의 Visible 부분에서 완전히 보이는 상태인지 확인 (일부만 보이면 false)
  4593. */
  4594. _isElementVisible : function(htElementPos, htVisiblePos){
  4595. return (htElementPos.nTop >= htVisiblePos.nTop && htElementPos.nBottom <= htVisiblePos.nBottom);
  4596. },
  4597. /*
  4598. * [SMARTEDITORSUS-824] [SMARTEDITORSUS-828] 자동 스크롤 처리
  4599. */
  4600. _scrollIntoView : function(el){
  4601. var htElementPos = this._getElementVerticalPosition(el),
  4602. htVisiblePos = this._getVisibleVerticalPosition(),
  4603. nScroll = 0;
  4604. if(this._isElementVisible(htElementPos, htVisiblePos)){
  4605. return;
  4606. }
  4607. if((nScroll = htElementPos.nBottom - htVisiblePos.nBottom) > 0){
  4608. this.getWindow().scrollTo(0, htVisiblePos.nTop + nScroll); // Scroll Down
  4609. return;
  4610. }
  4611. this.getWindow().scrollTo(0, htElementPos.nTop); // Scroll Up
  4612. },
  4613. $BEFORE_MSG_EDITING_AREA_RESIZE_STARTED : function(){
  4614. // FF에서 Height조정 시에 본문의 _fitElementInEditingArea()함수 부분에서 selection이 깨지는 현상을 잡기 위해서
  4615. // StringBookmark를 사용해서 위치를 저장해둠. (step1)
  4616. if(!jindo.$Agent().navigator().ie){
  4617. var oSelection = null;
  4618. oSelection = this.oApp.getSelection();
  4619. this.sBM = oSelection.placeStringBookmark();
  4620. }
  4621. },
  4622. $AFTER_MSG_EDITING_AREA_RESIZE_ENDED : function(FnMouseDown, FnMouseMove, FnMouseUp){
  4623. if(this.oApp.getEditingMode() !== this.sMode){
  4624. return;
  4625. }
  4626. // bts.nhncorp.com/nhnbts/browse/COM-1042
  4627. // $BEFORE_MSG_EDITING_AREA_RESIZE_STARTED에서 저장한 StringBookmark를 셋팅해주고 삭제함.(step2)
  4628. if(!jindo.$Agent().navigator().ie){
  4629. var oSelection = this.oApp.getEmptySelection();
  4630. oSelection.moveToBookmark(this.sBM);
  4631. oSelection.select();
  4632. oSelection.removeStringBookmark(this.sBM);
  4633. }
  4634. },
  4635. $ON_CLEAR_IE_BACKUP_SELECTION : function(){
  4636. this._oIERange = null;
  4637. },
  4638. $ON_RESTORE_IE_SELECTION : function(){
  4639. if(this._oIERange){
  4640. // changing the visibility of the iframe can cause an exception
  4641. try{
  4642. this._oIERange.select();
  4643. this._oPrevIERange = this._oIERange;
  4644. this._oIERange = null;
  4645. }catch(e){}
  4646. }
  4647. },
  4648. /**
  4649. * EVENT_EDITING_AREA_PASTE ON 메시지 핸들러
  4650. * 위지윅 모드에서 에디터 본문의 paste 이벤트에 대한 메시지를 처리한다.
  4651. * paste 시에 내용이 붙여진 본문의 내용을 바로 가져올 없어 delay 준다.
  4652. */
  4653. $ON_EVENT_EDITING_AREA_PASTE : function(oEvent){
  4654. this.oApp.delayedExec('EVENT_EDITING_AREA_PASTE_DELAY', [oEvent], 0);
  4655. },
  4656. $ON_EVENT_EDITING_AREA_PASTE_DELAY : function(weEvent) {
  4657. this._replaceBlankToNbsp(weEvent.element);
  4658. },
  4659. // [SMARTEDITORSUS-855] IE에서 특정 블로그 글을 복사하여 붙여넣기 했을 때 개행이 제거되는 문제
  4660. _replaceBlankToNbsp : function(el){
  4661. var oNavigator = this.oApp.oNavigator;
  4662. if(!oNavigator.ie){
  4663. return;
  4664. }
  4665. if(oNavigator.nativeVersion !== 9 || document.documentMode !== 7) { // IE9 호환모드에서만 발생
  4666. return;
  4667. }
  4668. if(el.nodeType !== 1){
  4669. return;
  4670. }
  4671. if(el.tagName === "BR"){
  4672. return;
  4673. }
  4674. var aEl = jindo.$$("p:empty()", this.oApp.getWYSIWYGDocument().body, { oneTimeOffCache:true });
  4675. jindo.$A(aEl).forEach(function(value, index, array) {
  4676. value.innerHTML = "&nbsp;";
  4677. });
  4678. },
  4679. _pageUp : function(we){
  4680. var nEditorHeight = this._getEditorHeight(),
  4681. htPos = jindo.$Document(this.oApp.getWYSIWYGDocument()).scrollPosition(),
  4682. nNewTop;
  4683. if(htPos.top <= nEditorHeight){
  4684. nNewTop = 0;
  4685. }else{
  4686. nNewTop = htPos.top - nEditorHeight;
  4687. }
  4688. this.oApp.getWYSIWYGWindow().scrollTo(0, nNewTop);
  4689. we.stop();
  4690. },
  4691. _pageDown : function(we){
  4692. var nEditorHeight = this._getEditorHeight(),
  4693. htPos = jindo.$Document(this.oApp.getWYSIWYGDocument()).scrollPosition(),
  4694. nBodyHeight = this._getBodyHeight(),
  4695. nNewTop;
  4696. if(htPos.top+nEditorHeight >= nBodyHeight){
  4697. nNewTop = nBodyHeight - nEditorHeight;
  4698. }else{
  4699. nNewTop = htPos.top + nEditorHeight;
  4700. }
  4701. this.oApp.getWYSIWYGWindow().scrollTo(0, nNewTop);
  4702. we.stop();
  4703. },
  4704. _getEditorHeight : function(){
  4705. return this.oApp.elEditingAreaContainer.offsetHeight - this.nTopBottomMargin;
  4706. },
  4707. _getBodyHeight : function(){
  4708. return parseInt(this.getDocument().body.scrollHeight, 10);
  4709. },
  4710. initIframe : function(){
  4711. try {
  4712. if (!this.iframe.contentWindow.document || !this.iframe.contentWindow.document.body || this.iframe.contentWindow.document.location.href === 'about:blank'){
  4713. throw new Error('Access denied');
  4714. }
  4715. var sCSSBaseURI = (!!nhn.husky.SE2M_Configuration.SE2M_CSSLoader && nhn.husky.SE2M_Configuration.SE2M_CSSLoader.sCSSBaseURI) ?
  4716. nhn.husky.SE2M_Configuration.SE2M_CSSLoader.sCSSBaseURI : "";
  4717. if(!!nhn.husky.SE2M_Configuration.SE_EditingAreaManager.sCSSBaseURI){
  4718. sCSSBaseURI = nhn.husky.SE2M_Configuration.SE_EditingAreaManager.sCSSBaseURI;
  4719. }
  4720. // add link tag
  4721. if (sCSSBaseURI){
  4722. var sCssUrl = sCSSBaseURI;
  4723. var sLocale = this.oApp && this.oApp.htOptions.I18N_LOCALE;
  4724. if(sLocale){
  4725. sCssUrl += "/" + sLocale;
  4726. }
  4727. sCssUrl += "/smart_editor2_in.css";
  4728. var doc = this.getDocument();
  4729. var headNode = doc.getElementsByTagName("head")[0];
  4730. var linkNode = doc.createElement('link');
  4731. linkNode.type = 'text/css';
  4732. linkNode.rel = 'stylesheet';
  4733. linkNode.href = sCssUrl;
  4734. linkNode.onload = jindo.$Fn(function(){
  4735. // [SMARTEDITORSUS-1853] IE의 경우 css가 로드되어 반영되는데 시간이 걸려서 브라우저 기본폰트가 세팅되는 경우가 있음
  4736. // 때문에 css가 로드되면 SE_WYSIWYGStylerGetter 플러그인의 스타일정보를 RESET 해준다.
  4737. // 주의: 크롬의 경우, css 로딩이 더 먼저 발생해서 SE_WYSIWYGStylerGetter 플러그인에서 오류가 발생할 수 있기 때문에 RESET_STYLE_STATUS 메시지 호출이 가능한 상태인지 체크함
  4738. if(this.oApp && this.oApp.getEditingMode && this.oApp.getEditingMode() === this.sMode){
  4739. this.oApp.exec("RESET_STYLE_STATUS");
  4740. }
  4741. /*
  4742. * [SMARTEDITORSUS-2298]
  4743. * IE에서 웹폰트용 css가 import될때 이벤트핸들러가 실행되어 툴바에 선택된 폰트가 리셋되는 문제가 있음
  4744. * 때문에 한번 실행되고 후에는 연결된 이벤트핸들러를 클리어처리함
  4745. */
  4746. linkNode.onload = null;
  4747. }, this).bind();
  4748. headNode.appendChild(linkNode);
  4749. }
  4750. this._enableWYSIWYG();
  4751. this.status = nhn.husky.PLUGIN_STATUS.READY;
  4752. } catch(e) {
  4753. if(this._nIFrameReadyCount-- > 0){
  4754. setTimeout(jindo.$Fn(this.initIframe, this).bind(), 100);
  4755. }else{
  4756. throw("iframe for WYSIWYG editing mode can't be initialized. Please check if the iframe document exists and is also accessable(cross-domain issues). ");
  4757. }
  4758. }
  4759. },
  4760. getIR : function(){
  4761. var sContent = this.iframe.contentWindow.document.body.innerHTML,
  4762. sIR;
  4763. if(this.oApp.applyConverter){
  4764. sIR = this.oApp.applyConverter(this.sMode+"_TO_IR", sContent, this.oApp.getWYSIWYGDocument());
  4765. }else{
  4766. sIR = sContent;
  4767. }
  4768. return sIR;
  4769. },
  4770. setIR : function(sIR){
  4771. // [SMARTEDITORSUS-875] HTML 모드의 beautify에서 추가된 공백을 다시 제거
  4772. //sIR = sIR.replace(/(>)([\n\r\t\s]*)([^<]?)/g, "$1$3").replace(/([\n\r\t\s]*)(<)/g, "$2")
  4773. // --[SMARTEDITORSUS-875]
  4774. var sContent,
  4775. oNavigator = this.oApp.oNavigator,
  4776. bUnderIE11 = oNavigator.ie && document.documentMode < 11, // IE11미만
  4777. sCursorHolder = bUnderIE11 ? "" : "<br>";
  4778. if(this.oApp.applyConverter){
  4779. sContent = this.oApp.applyConverter("IR_TO_"+this.sMode, sIR, this.oApp.getWYSIWYGDocument());
  4780. }else{
  4781. sContent = sIR;
  4782. }
  4783. // [SMARTEDITORSUS-1279] [IE9/10] pre 태그 아래에 \n이 포함되면 개행이 되지 않는 이슈
  4784. /*if(oNavigator.ie && oNavigator.nativeVersion >= 9 && document.documentMode >= 9){
  4785. // [SMARTEDITORSUS-704] \r\n이 있는 경우 IE9 표준모드에서 정렬 시 브라우저가 <p>를 추가하는 문제
  4786. sContent = sContent.replace(/[\r\n]/g,"");
  4787. }*/
  4788. // 편집내용이 없는 경우 커서홀더로 대체
  4789. if(sContent.replace(/[\r\n\t\s]*/,"") === ""){
  4790. if(this.oApp.sLineBreaker !== "BR"){
  4791. sCursorHolder = "<p>" + sCursorHolder + "</p>";
  4792. }
  4793. sContent = sCursorHolder;
  4794. }
  4795. this.iframe.contentWindow.document.body.innerHTML = sContent;
  4796. // [COM-1142] IE의 경우 <p>&nbsp;</p> 를 <p></p> 로 변환
  4797. // [SMARTEDITORSUS-1623] IE11은 <p></p>로 변환하면 라인이 붙어버리기 때문에 IE10만 적용하도록 수정
  4798. if(bUnderIE11 && this.oApp.getEditingMode() === this.sMode){
  4799. var pNodes = this.oApp.getWYSIWYGDocument().body.getElementsByTagName("P");
  4800. for(var i=0, nMax = pNodes.length; i < nMax; i++){
  4801. if(pNodes[i].childNodes.length === 1 && pNodes[i].innerHTML === "&nbsp;"){
  4802. pNodes[i].innerHTML = '';
  4803. }
  4804. }
  4805. }
  4806. },
  4807. getRawContents : function(){
  4808. return this.iframe.contentWindow.document.body.innerHTML;
  4809. },
  4810. getRawHTMLContents : function(){
  4811. return this.getRawContents();
  4812. },
  4813. setRawHTMLContents : function(sContents){
  4814. this.iframe.contentWindow.document.body.innerHTML = sContents;
  4815. },
  4816. getWindow : function(){
  4817. return this.iframe.contentWindow;
  4818. },
  4819. getDocument : function(){
  4820. return this.iframe.contentWindow.document;
  4821. },
  4822. focus : function(){
  4823. //this.getWindow().focus();
  4824. this.getDocument().body.focus();
  4825. this.oApp.exec("RESTORE_IE_SELECTION");
  4826. },
  4827. _recordUndo : function(oKeyInfo){
  4828. /**
  4829. * 229: Korean/Eng
  4830. * 16: shift
  4831. * 33,34: page up/down
  4832. * 35,36: end/home
  4833. * 37,38,39,40: left, up, right, down
  4834. * 32: space
  4835. * 46: delete
  4836. * 8: bksp
  4837. */
  4838. if(oKeyInfo.keyCode >= 33 && oKeyInfo.keyCode <= 40){ // record snapshot
  4839. this.oApp.saveSnapShot();
  4840. return;
  4841. }
  4842. if(oKeyInfo.alt || oKeyInfo.ctrl || oKeyInfo.keyCode === 16){
  4843. return;
  4844. }
  4845. if(this.oApp.getLastKey() === oKeyInfo.keyCode){
  4846. return;
  4847. }
  4848. this.oApp.setLastKey(oKeyInfo.keyCode);
  4849. // && oKeyInfo.keyCode != 32 // 속도 문제로 인하여 Space 는 제외함
  4850. if(!oKeyInfo.enter && oKeyInfo.keyCode !== 46 && oKeyInfo.keyCode !== 8){
  4851. return;
  4852. }
  4853. this.oApp.exec("RECORD_UNDO_ACTION", ["KEYPRESS(" + oKeyInfo.keyCode + ")", {bMustBlockContainer:true}]);
  4854. },
  4855. _enableWYSIWYG : function(){
  4856. //if (this.iframe.contentWindow.document.body.hasOwnProperty("contentEditable")){
  4857. if (this.iframe.contentWindow.document.body.contentEditable !== null) {
  4858. this.iframe.contentWindow.document.body.contentEditable = true;
  4859. } else {
  4860. this.iframe.contentWindow.document.designMode = "on";
  4861. }
  4862. this.bWYSIWYGEnabled = true;
  4863. if(jindo.$Agent().navigator().firefox){
  4864. setTimeout(jindo.$Fn(function(){
  4865. //enableInlineTableEditing : Enables or disables the table row and column insertion and deletion controls.
  4866. this.iframe.contentWindow.document.execCommand('enableInlineTableEditing', false, false);
  4867. }, this).bind(), 0);
  4868. }
  4869. },
  4870. _disableWYSIWYG : function(){
  4871. //if (this.iframe.contentWindow.document.body.hasOwnProperty("contentEditable")){
  4872. if (this.iframe.contentWindow.document.body.contentEditable !== null){
  4873. this.iframe.contentWindow.document.body.contentEditable = false;
  4874. } else {
  4875. this.iframe.contentWindow.document.designMode = "off";
  4876. }
  4877. this.bWYSIWYGEnabled = false;
  4878. },
  4879. isWYSIWYGEnabled : function(){
  4880. return this.bWYSIWYGEnabled;
  4881. }
  4882. });
  4883. //}
  4884. //{
  4885. /**
  4886. * @fileOverview This file contains Husky plugin that takes care of the operations directly related to editing the HTML source code using Textarea element
  4887. * @name hp_SE_EditingArea_HTMLSrc.js
  4888. * @required SE_EditingAreaManager
  4889. */
  4890. nhn.husky.SE_EditingArea_HTMLSrc = jindo.$Class({
  4891. name : "SE_EditingArea_HTMLSrc",
  4892. sMode : "HTMLSrc",
  4893. bAutoResize : false, // [SMARTEDITORSUS-677] 해당 편집모드의 자동확장 기능 On/Off 여부
  4894. nMinHeight : null, // [SMARTEDITORSUS-677] 편집 영역의 최소 높이
  4895. $init : function(sTextArea) {
  4896. this.elEditingArea = jindo.$(sTextArea);
  4897. },
  4898. $BEFORE_MSG_APP_READY : function() {
  4899. this.oNavigator = jindo.$Agent().navigator();
  4900. this.oApp.exec("REGISTER_EDITING_AREA", [this]);
  4901. },
  4902. $ON_MSG_APP_READY : function() {
  4903. if(!!this.oApp.getEditingAreaHeight){
  4904. this.nMinHeight = this.oApp.getEditingAreaHeight(); // [SMARTEDITORSUS-677] 편집 영역의 최소 높이를 가져와 자동 확장 처리를 할 때 사용
  4905. }
  4906. },
  4907. $ON_CHANGE_EDITING_MODE : function(sMode) {
  4908. if (sMode == this.sMode) {
  4909. this.elEditingArea.style.display = "block";
  4910. /**
  4911. * [SMARTEDITORSUS-1889] Editor 영역을 표시하고 숨기는 있어서
  4912. * display 속성 대신 visibility 속성을 사용하게 되면서,
  4913. * Editor 영역이 화면에서 사라지지만
  4914. * 공간을 차지하게 되므로
  4915. * 아래로 위치하는 HTML 영역을 끌어올려 준다.
  4916. *
  4917. * @see hp_SE_EditingArea_WYSIWYG.js
  4918. * */
  4919. this.elEditingArea.style.position = "absolute";
  4920. this.elEditingArea.style.top = "0px";
  4921. // --[SMARTEDITORSUS-1889]
  4922. } else {
  4923. this.elEditingArea.style.display = "none";
  4924. // [SMARTEDITORSUS-1889]
  4925. this.elEditingArea.style.position = "";
  4926. this.elEditingArea.style.top = "";
  4927. // --[SMARTEDITORSUS-1889]
  4928. }
  4929. },
  4930. $AFTER_CHANGE_EDITING_MODE : function(sMode, bNoFocus) {
  4931. if (sMode == this.sMode && !bNoFocus) {
  4932. var o = new TextRange(this.elEditingArea);
  4933. o.setSelection(0, 0);
  4934. //[SMARTEDITORSUS-1017] [iOS5대응] 모드 전환 시 textarea에 포커스가 있어도 글자가 입력이 안되는 현상
  4935. //원인 : WYSIWYG모드가 아닐 때에도 iframe의 contentWindow에 focus가 가면서 focus기능이 작동하지 않음
  4936. //해결 : WYSIWYG모드 일때만 실행 되도록 조건식 추가 및 기존에 blur처리 코드 삭제
  4937. //모바일 textarea에서는 직접 클릭을해야만 키보드가 먹히기 때문에 우선은 커서가 안보이게 해서 사용자가 직접 클릭을 유도.
  4938. // if(!!this.oNavigator.msafari){
  4939. // this.elEditingArea.blur();
  4940. // }
  4941. }
  4942. },
  4943. /**
  4944. * [SMARTEDITORSUS-677] HTML 편집 영역 자동 확장 처리 시작
  4945. */
  4946. startAutoResize : function(){
  4947. var htOption = {
  4948. nMinHeight : this.nMinHeight,
  4949. wfnCallback : jindo.$Fn(this.oApp.checkResizeGripPosition, this).bind()
  4950. };
  4951. //[SMARTEDITORSUS-941][iOS5대응]아이패드의 자동 확장 기능이 동작하지 않을 때 에디터 창보다 긴 내용을 작성하면 에디터를 뚫고 나오는 현상
  4952. //원인 : 자동확장 기능이 정지 될 경우 iframe에 스크롤이 생기지 않고, 창을 뚫고 나옴
  4953. //해결 : 항상 자동확장 기능이 켜져있도록 변경. 자동 확장 기능 관련한 이벤트 코드도 모바일 사파리에서 예외 처리
  4954. if(this.oNavigator.msafari){
  4955. htOption.wfnCallback = function(){};
  4956. }
  4957. this.bAutoResize = true;
  4958. this.AutoResizer = new nhn.husky.AutoResizer(this.elEditingArea, htOption);
  4959. this.AutoResizer.bind();
  4960. },
  4961. /**
  4962. * [SMARTEDITORSUS-677] HTML 편집 영역 자동 확장 처리 종료
  4963. */
  4964. stopAutoResize : function(){
  4965. this.AutoResizer.unbind();
  4966. },
  4967. getIR : function() {
  4968. var sIR = this.getRawContents();
  4969. if (this.oApp.applyConverter) {
  4970. sIR = this.oApp.applyConverter(this.sMode + "_TO_IR", sIR, this.oApp.getWYSIWYGDocument());
  4971. }
  4972. return sIR;
  4973. },
  4974. setIR : function(sIR) {
  4975. if(sIR.toLowerCase() === "<br>" || sIR.toLowerCase() === "<p>&nbsp;</p>" || sIR.toLowerCase() === "<p><br></p>" || sIR.toLowerCase() === "<p></p>"){
  4976. sIR="";
  4977. }
  4978. // [SMARTEDITORSUS-1589] 문서 모드가 Edge인 IE11에서 WYSIWYG 모드와 HTML 모드 전환 시, 문말에 무의미한 <br> 두 개가 첨가되는 현상으로 필터링 추가
  4979. var htBrowser = jindo.$Agent().navigator();
  4980. if(htBrowser.ie && htBrowser.nativeVersion == 11 && document.documentMode == 11){ // Edge 모드의 documentMode 값은 11
  4981. sIR = sIR.replace(/(<br><br>$)/, "");
  4982. }
  4983. // --[SMARTEDITORSUS-1589]
  4984. var sContent = sIR;
  4985. if (this.oApp.applyConverter) {
  4986. sContent = this.oApp.applyConverter("IR_TO_" + this.sMode, sContent, this.oApp.getWYSIWYGDocument());
  4987. }
  4988. this.setRawContents(sContent);
  4989. },
  4990. setRawContents : function(sContent) {
  4991. if (typeof sContent !== 'undefined') {
  4992. this.elEditingArea.value = sContent;
  4993. }
  4994. },
  4995. getRawContents : function() {
  4996. return this.elEditingArea.value;
  4997. },
  4998. focus : function() {
  4999. this.elEditingArea.focus();
  5000. }
  5001. });
  5002. /**
  5003. * Selection for textfield
  5004. * @author hooriza
  5005. */
  5006. if (typeof window.TextRange == 'undefined') { window.TextRange = {}; }
  5007. TextRange = function(oEl, oDoc) {
  5008. this._o = oEl;
  5009. this._oDoc = (oDoc || document);
  5010. };
  5011. TextRange.prototype.getSelection = function() {
  5012. var obj = this._o;
  5013. var ret = [-1, -1];
  5014. if(isNaN(this._o.selectionStart)) {
  5015. obj.focus();
  5016. // textarea support added by nagoon97
  5017. var range = this._oDoc.body.createTextRange();
  5018. var rangeField = null;
  5019. rangeField = this._oDoc.selection.createRange().duplicate();
  5020. range.moveToElementText(obj);
  5021. rangeField.collapse(true);
  5022. range.setEndPoint("EndToEnd", rangeField);
  5023. ret[0] = range.text.length;
  5024. rangeField = this._oDoc.selection.createRange().duplicate();
  5025. range.moveToElementText(obj);
  5026. rangeField.collapse(false);
  5027. range.setEndPoint("EndToEnd", rangeField);
  5028. ret[1] = range.text.length;
  5029. obj.blur();
  5030. } else {
  5031. ret[0] = obj.selectionStart;
  5032. ret[1] = obj.selectionEnd;
  5033. }
  5034. return ret;
  5035. };
  5036. TextRange.prototype.setSelection = function(start, end) {
  5037. var obj = this._o;
  5038. if (typeof end == 'undefined') {
  5039. end = start;
  5040. }
  5041. if (obj.setSelectionRange) {
  5042. obj.setSelectionRange(start, end);
  5043. } else if (obj.createTextRange) {
  5044. var range = obj.createTextRange();
  5045. range.collapse(true);
  5046. range.moveStart("character", start);
  5047. range.moveEnd("character", end - start);
  5048. range.select();
  5049. obj.blur();
  5050. }
  5051. };
  5052. TextRange.prototype.copy = function() {
  5053. var r = this.getSelection();
  5054. return this._o.value.substring(r[0], r[1]);
  5055. };
  5056. TextRange.prototype.paste = function(sStr) {
  5057. var obj = this._o;
  5058. var sel = this.getSelection();
  5059. var value = obj.value;
  5060. var pre = value.substr(0, sel[0]);
  5061. var post = value.substr(sel[1]);
  5062. value = pre + sStr + post;
  5063. obj.value = value;
  5064. var n = 0;
  5065. if (typeof this._oDoc.body.style.maxHeight == "undefined") {
  5066. var a = pre.match(/\n/gi);
  5067. n = ( a !== null ? a.length : 0 );
  5068. }
  5069. this.setSelection(sel[0] + sStr.length - n);
  5070. };
  5071. TextRange.prototype.cut = function() {
  5072. var r = this.copy();
  5073. this.paste('');
  5074. return r;
  5075. };
  5076. //}
  5077. /**
  5078. * @fileOverview This file contains Husky plugin that takes care of the operations directly related to editing the HTML source code using Textarea element
  5079. * @name hp_SE_EditingArea_TEXT.js
  5080. * @required SE_EditingAreaManager
  5081. */
  5082. nhn.husky.SE_EditingArea_TEXT = jindo.$Class({
  5083. name : "SE_EditingArea_TEXT",
  5084. sMode : "TEXT",
  5085. sRxConverter : '@[0-9]+@',
  5086. bAutoResize : false, // [SMARTEDITORSUS-677] 해당 편집모드의 자동확장 기능 On/Off 여부
  5087. nMinHeight : null, // [SMARTEDITORSUS-677] 편집 영역의 최소 높이
  5088. $init : function(sTextArea) {
  5089. this.elEditingArea = jindo.$(sTextArea);
  5090. },
  5091. $BEFORE_MSG_APP_READY : function() {
  5092. this.oNavigator = jindo.$Agent().navigator();
  5093. this.oApp.exec("REGISTER_EDITING_AREA", [this]);
  5094. this.oApp.exec("ADD_APP_PROPERTY", ["getTextAreaContents", jindo.$Fn(this.getRawContents, this).bind()]);
  5095. },
  5096. $ON_MSG_APP_READY : function() {
  5097. if(!!this.oApp.getEditingAreaHeight){
  5098. this.nMinHeight = this.oApp.getEditingAreaHeight(); // [SMARTEDITORSUS-677] 편집 영역의 최소 높이를 가져와 자동 확장 처리를 할 때 사용
  5099. }
  5100. },
  5101. $ON_REGISTER_CONVERTERS : function() {
  5102. this.oApp.exec("ADD_CONVERTER", ["IR_TO_TEXT", jindo.$Fn(this.irToText, this).bind()]);
  5103. this.oApp.exec("ADD_CONVERTER", ["TEXT_TO_IR", jindo.$Fn(this.textToIr, this).bind()]);
  5104. },
  5105. $ON_CHANGE_EDITING_MODE : function(sMode) {
  5106. if (sMode == this.sMode) {
  5107. this.elEditingArea.style.display = "block";
  5108. /**
  5109. * [SMARTEDITORSUS-1889] Editor 영역을 표시하고 숨기는 있어서
  5110. * display 속성 대신 visibility 속성을 사용하게 되면서,
  5111. * Editor 영역이 화면에서 사라지지만
  5112. * 공간을 차지하게 되므로
  5113. * 아래로 위치하는 Text 영역을 끌어올려 준다.
  5114. *
  5115. * @see hp_SE_EditingArea_WYSIWYG.js
  5116. * */
  5117. this.elEditingArea.style.position = "absolute";
  5118. this.elEditingArea.style.top = "0px";
  5119. // --[SMARTEDITORSUS-1889]
  5120. } else {
  5121. this.elEditingArea.style.display = "none";
  5122. // [SMARTEDITORSUS-1889]
  5123. this.elEditingArea.style.position = "";
  5124. this.elEditingArea.style.top = "";
  5125. // --[SMARTEDITORSUS-1889]
  5126. }
  5127. },
  5128. $AFTER_CHANGE_EDITING_MODE : function(sMode, bNoFocus) {
  5129. if (sMode == this.sMode && !bNoFocus) {
  5130. var o = new TextRange(this.elEditingArea);
  5131. o.setSelection(0, 0);
  5132. }
  5133. //[SMARTEDITORSUS-1017] [iOS5대응] 모드 전환 시 textarea에 포커스가 있어도 글자가 입력이 안되는 현상
  5134. //원인 : WYSIWYG모드가 아닐 때에도 iframe의 contentWindow에 focus가 가면서 focus기능이 작동하지 않음
  5135. //해결 : WYSIWYG모드 일때만 실행 되도록 조건식 추가 및 기존에 blur처리 코드 삭제
  5136. //모바일 textarea에서는 직접 클릭을해야만 키보드가 먹히기 때문에 우선은 커서가 안보이게 해서 사용자가 직접 클릭을 유도.
  5137. // if(!!this.oNavigator.msafari){
  5138. // this.elEditingArea.blur();
  5139. // }
  5140. },
  5141. irToText : function(sHtml) {
  5142. var sContent = sHtml, nIdx = 0;
  5143. var aTemp = sContent.match(new RegExp(this.sRxConverter)); // applyConverter에서 추가한 sTmpStr를 잠시 제거해준다.
  5144. if (aTemp !== null) {
  5145. sContent = sContent.replace(new RegExp(this.sRxConverter), "");
  5146. }
  5147. //0.안보이는 값들에 대한 정리. (에디터 모드에 view와 text모드의 view를 동일하게 해주기 위해서)
  5148. sContent = sContent.replace(/\r/g, '');// MS엑셀 테이블에서 tr별로 분리해주는 역할이\r이기 때문에 text모드로 변경시에 가독성을 위해 \r 제거하는 것은 임시 보류. - 11.01.28 by cielo
  5149. sContent = sContent.replace(/[\n|\t]/g, ''); // 개행문자, 안보이는 공백 제거
  5150. sContent = sContent.replace(/[\v|\f]/g, ''); // 개행문자, 안보이는 공백 제거
  5151. //1. 먼저, 빈 라인 처리 .
  5152. sContent = sContent.replace(/<p><br><\/p>/gi, '\n');
  5153. sContent = sContent.replace(/<P>&nbsp;<\/P>/gi, '\n');
  5154. //2. 빈 라인 이외에 linebreak 처리.
  5155. sContent = sContent.replace(/<br(\s)*\/?>/gi, '\n'); // br 태그를 개행문자로
  5156. sContent = sContent.replace(/<br(\s[^\/]*)?>/gi, '\n'); // br 태그를 개행문자로
  5157. sContent = sContent.replace(/<\/p(\s[^\/]*)?>/gi, '\n'); // p 태그를 개행문자로
  5158. sContent = sContent.replace(/<\/li(\s[^\/]*)?>/gi, '\n'); // li 태그를 개행문자로 [SMARTEDITORSUS-107]개행 추가
  5159. sContent = sContent.replace(/<\/tr(\s[^\/]*)?>/gi, '\n'); // tr 태그를 개행문자로 [SMARTEDITORSUS-107]개행 추가
  5160. // 마지막 \n은 로직상 불필요한 linebreak를 제공하므로 제거해준다.
  5161. nIdx = sContent.lastIndexOf('\n');
  5162. if (nIdx > -1 && sContent.substring(nIdx) == '\n') {
  5163. sContent = sContent.substring(0, nIdx);
  5164. }
  5165. sContent = jindo.$S(sContent).stripTags().toString();
  5166. sContent = this.unhtmlSpecialChars(sContent);
  5167. if (aTemp !== null) { // 제거했던sTmpStr를 추가해준다.
  5168. sContent = aTemp[0] + sContent;
  5169. }
  5170. return sContent;
  5171. },
  5172. textToIr : function(sHtml) {
  5173. if (!sHtml) {
  5174. return;
  5175. }
  5176. var sContent = sHtml, aTemp = null;
  5177. // applyConverter에서 추가한 sTmpStr를 잠시 제거해준다. sTmpStr도 하나의 string으로 인식하는 경우가 있기 때문.
  5178. aTemp = sContent.match(new RegExp(this.sRxConverter));
  5179. if (aTemp !== null) {
  5180. sContent = sContent.replace(aTemp[0], "");
  5181. }
  5182. sContent = this.htmlSpecialChars(sContent);
  5183. sContent = this._addLineBreaker(sContent);
  5184. if (aTemp !== null) {
  5185. sContent = aTemp[0] + sContent;
  5186. }
  5187. return sContent;
  5188. },
  5189. _addLineBreaker : function(sContent){
  5190. if(this.oApp.sLineBreaker === "BR"){
  5191. return sContent.replace(/\r?\n/g, "<BR>");
  5192. }
  5193. var oContent = new StringBuffer(),
  5194. aContent = sContent.split('\n'), // \n을 기준으로 블럭을 나눈다.
  5195. aContentLng = aContent.length,
  5196. sTemp = "";
  5197. for (var i = 0; i < aContentLng; i++) {
  5198. sTemp = jindo.$S(aContent[i]).trim().$value();
  5199. if (i === aContentLng -1 && sTemp === "") {
  5200. break;
  5201. }
  5202. if (sTemp !== null && sTemp !== "") {
  5203. oContent.append('<P>');
  5204. oContent.append(aContent[i]);
  5205. oContent.append('</P>');
  5206. } else {
  5207. if (!jindo.$Agent().navigator().ie) {
  5208. oContent.append('<P><BR></P>');
  5209. } else {
  5210. oContent.append('<P>&nbsp;<\/P>');
  5211. }
  5212. }
  5213. }
  5214. return oContent.toString();
  5215. },
  5216. /**
  5217. * [SMARTEDITORSUS-677] HTML 편집 영역 자동 확장 처리 시작
  5218. */
  5219. startAutoResize : function(){
  5220. var htOption = {
  5221. nMinHeight : this.nMinHeight,
  5222. wfnCallback : jindo.$Fn(this.oApp.checkResizeGripPosition, this).bind()
  5223. };
  5224. //[SMARTEDITORSUS-941][iOS5대응]아이패드의 자동 확장 기능이 동작하지 않을 때 에디터 창보다 긴 내용을 작성하면 에디터를 뚫고 나오는 현상
  5225. //원인 : 자동확장 기능이 정지 될 경우 iframe에 스크롤이 생기지 않고, 창을 뚫고 나옴
  5226. //해결 : 항상 자동확장 기능이 켜져있도록 변경. 자동 확장 기능 관련한 이벤트 코드도 모바일 사파리에서 예외 처리
  5227. if(this.oNavigator.msafari){
  5228. htOption.wfnCallback = function(){};
  5229. }
  5230. this.bAutoResize = true;
  5231. this.AutoResizer = new nhn.husky.AutoResizer(this.elEditingArea, htOption);
  5232. this.AutoResizer.bind();
  5233. },
  5234. /**
  5235. * [SMARTEDITORSUS-677] HTML 편집 영역 자동 확장 처리 종료
  5236. */
  5237. stopAutoResize : function(){
  5238. this.AutoResizer.unbind();
  5239. },
  5240. getIR : function() {
  5241. var sIR = this.getRawContents();
  5242. if (this.oApp.applyConverter) {
  5243. sIR = this.oApp.applyConverter(this.sMode + "_TO_IR", sIR, this.oApp.getWYSIWYGDocument());
  5244. }
  5245. return sIR;
  5246. },
  5247. setIR : function(sIR) {
  5248. var sContent = sIR;
  5249. if (this.oApp.applyConverter) {
  5250. sContent = this.oApp.applyConverter("IR_TO_" + this.sMode, sContent, this.oApp.getWYSIWYGDocument());
  5251. }
  5252. this.setRawContents(sContent);
  5253. },
  5254. setRawContents : function(sContent) {
  5255. if (typeof sContent !== 'undefined') {
  5256. this.elEditingArea.value = sContent;
  5257. }
  5258. },
  5259. getRawContents : function() {
  5260. return this.elEditingArea.value;
  5261. },
  5262. focus : function() {
  5263. this.elEditingArea.focus();
  5264. },
  5265. /**
  5266. * HTML 태그에 해당하는 글자가 먹히지 않도록 바꿔주기
  5267. *
  5268. * 동작) & &amp; , < &lt; , > &gt; 바꿔준다
  5269. *
  5270. * @param {String} sText
  5271. * @return {String}
  5272. */
  5273. htmlSpecialChars : function(sText) {
  5274. return sText.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/ /g, '&nbsp;');
  5275. },
  5276. /**
  5277. * htmlSpecialChars 반대 기능의 함수
  5278. *
  5279. * 동작) &amp, &lt, &gt, &nbsp 각각 &, <, >, 빈칸으로 바꿔준다
  5280. *
  5281. * @param {String} sText
  5282. * @return {String}
  5283. */
  5284. unhtmlSpecialChars : function(sText) {
  5285. return sText.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&nbsp;/g, ' ').replace(/&amp;/g, '&');
  5286. }
  5287. });
  5288. //{
  5289. /**
  5290. * @fileOverview This file contains Husky plugin that takes care of the operations related to resizing the editing area vertically
  5291. * @name hp_SE_EditingAreaVerticalResizer.js
  5292. */
  5293. nhn.husky.SE_EditingAreaVerticalResizer = jindo.$Class({
  5294. name : "SE_EditingAreaVerticalResizer",
  5295. oResizeGrip : null,
  5296. sCookieNotice : "bHideResizeNotice",
  5297. nEditingAreaMinHeight : null, // [SMARTEDITORSUS-677] 편집 영역의 최소 높이
  5298. htConversionMode : null,
  5299. $init : function(elAppContainer, htConversionMode){
  5300. this.htConversionMode = htConversionMode;
  5301. this._assignHTMLElements(elAppContainer);
  5302. },
  5303. $BEFORE_MSG_APP_READY : function(){
  5304. this.oApp.exec("ADD_APP_PROPERTY", ["isUseVerticalResizer", jindo.$Fn(this.isUseVerticalResizer, this).bind()]);
  5305. },
  5306. $ON_MSG_APP_READY : function(){
  5307. if(this.oApp.bMobile){
  5308. // [SMARTEDITORSUS-941] 모바일에서는 자동확장기능이 항상 켜져있도록 한다.
  5309. // [SMARTEDITORSUS-1679] 하지만 사용자가 조절하지는 못하도록 버튼은 비활성화 한다.
  5310. this.oResizeGrip.disabled = true;
  5311. this.oResizeGrip.style.height = '0'; // 버튼의 문구를 가림. display:none을 하면 안드로이드에서 높이 계산오류 발생
  5312. }else{
  5313. this.oApp.exec("REGISTER_HOTKEY", ["shift+esc", "FOCUS_RESIZER"]);
  5314. // [SMARTEDITORSUS-906][SMARTEDITORSUS-1433] Resizbar 사용 여부 처리 (true:사용함/ false:사용하지 않음)
  5315. if(this.isUseVerticalResizer()){
  5316. this.oResizeGrip.style.display = 'block';
  5317. if(!!this.welNoticeLayer && !Number(jindo.$Cookie().get(this.sCookieNotice))){
  5318. this.welNoticeLayer.delegate("click", "BUTTON.bt_clse", jindo.$Fn(this._closeNotice, this).bind());
  5319. this.welNoticeLayer.show();
  5320. }
  5321. this.$FnMouseDown = jindo.$Fn(this._mousedown, this);
  5322. this.$FnMouseMove = jindo.$Fn(this._mousemove, this);
  5323. this.$FnMouseUp = jindo.$Fn(this._mouseup, this);
  5324. this.$FnMouseOver = jindo.$Fn(this._mouseover, this);
  5325. this.$FnMouseOut = jindo.$Fn(this._mouseout, this);
  5326. this.$FnMouseDown.attach(this.oResizeGrip, "mousedown");
  5327. this.$FnMouseOver.attach(this.oResizeGrip, "mouseover");
  5328. this.$FnMouseOut.attach(this.oResizeGrip, "mouseout");
  5329. }else{
  5330. this.oResizeGrip.style.display = 'none';
  5331. if(!this.oApp.isUseModeChanger()){
  5332. this.elModeToolbar.style.display = "none";
  5333. }
  5334. }
  5335. }
  5336. this.oApp.exec("ADD_APP_PROPERTY", ["checkResizeGripPosition", jindo.$Fn(this.checkResizeGripPosition, this).bind()]); // [SMARTEDITORSUS-677]
  5337. if(!!this.oApp.getEditingAreaHeight){
  5338. this.nEditingAreaMinHeight = this.oApp.getEditingAreaHeight(); // [SMARTEDITORSUS-677] 편집 영역의 최소 높이를 가져와 Gap 처리 시 사용
  5339. }
  5340. },
  5341. /**
  5342. * [SMARTEDITORSUS-2036][SMARTEDITORSUS-1585] DISABLE_ALL_UI 메시지가 발생하면 기능을 비활성화한다.
  5343. */
  5344. $ON_DISABLE_ALL_UI : function(){
  5345. this.oResizeGrip.style.cursor = "default";
  5346. this.welConversionMode.addClass("off");
  5347. this.oResizeGrip.disabled = true;
  5348. },
  5349. /**
  5350. * [SMARTEDITORSUS-2036][SMARTEDITORSUS-1585] ENABLE_ALL_UI 메시지가 발생하면 기능을 활성화한다.
  5351. */
  5352. $ON_ENABLE_ALL_UI : function(){
  5353. this.oResizeGrip.style.cursor = "n-resize";
  5354. this.welConversionMode.removeClass("off");
  5355. this.oResizeGrip.disabled = false;
  5356. },
  5357. isUseVerticalResizer : function(){
  5358. return (typeof(this.htConversionMode) === 'undefined' || typeof(this.htConversionMode.bUseVerticalResizer) === 'undefined' || this.htConversionMode.bUseVerticalResizer === true) ? true : false;
  5359. },
  5360. /**
  5361. * [SMARTEDITORSUS-677] [에디터 자동확장 ON인 경우]
  5362. * 입력창 크기 조절 바의 위치를 확인하여 브라우저 하단에 위치한 경우 자동확장을 멈춤
  5363. */
  5364. checkResizeGripPosition : function(bExpand){
  5365. var oDocument = jindo.$Document();
  5366. var nGap = (jindo.$Element(this.oResizeGrip).offset().top - oDocument.scrollPosition().top + 25) - oDocument.clientSize().height;
  5367. if(nGap <= 0){
  5368. return;
  5369. }
  5370. if(bExpand){
  5371. if(this.nEditingAreaMinHeight > this.oApp.getEditingAreaHeight() - nGap){ // [SMARTEDITORSUS-822] 수정 모드인 경우에 대비
  5372. nGap = (-1) * (this.nEditingAreaMinHeight - this.oApp.getEditingAreaHeight());
  5373. }
  5374. // Gap 만큼 편집영역 사이즈를 조절하여
  5375. // 사진 첨부나 붙여넣기 등의 사이즈가 큰 내용 추가가 있었을 때 입력창 크기 조절 바가 숨겨지지 않도록 함
  5376. this.oApp.exec("MSG_EDITING_AREA_RESIZE_STARTED");
  5377. this.oApp.exec("RESIZE_EDITING_AREA_BY", [0, (-1) * nGap]);
  5378. this.oApp.exec("MSG_EDITING_AREA_RESIZE_ENDED");
  5379. }
  5380. this.oApp.exec("STOP_AUTORESIZE_EDITING_AREA");
  5381. },
  5382. $ON_FOCUS_RESIZER : function(){
  5383. this.oApp.exec("IE_HIDE_CURSOR");
  5384. this.oResizeGrip.focus();
  5385. },
  5386. _assignHTMLElements : function(elAppContainer, htConversionMode){
  5387. //@ec[
  5388. this.oResizeGrip = jindo.$$.getSingle("BUTTON.husky_seditor_editingArea_verticalResizer", elAppContainer);
  5389. this.elModeToolbar = jindo.$$.getSingle("DIV.se2_conversion_mode", elAppContainer);
  5390. //@ec]
  5391. this.welNoticeLayer = jindo.$Element(jindo.$$.getSingle("DIV.husky_seditor_resize_notice", elAppContainer));
  5392. this.welConversionMode = jindo.$Element(this.oResizeGrip.parentNode);
  5393. },
  5394. _mouseover : function(oEvent){
  5395. oEvent.stopBubble();
  5396. this.welConversionMode.addClass("controller_on");
  5397. },
  5398. _mouseout : function(oEvent){
  5399. oEvent.stopBubble();
  5400. this.welConversionMode.removeClass("controller_on");
  5401. },
  5402. _mousedown : function(oEvent){
  5403. this.iStartHeight = oEvent.pos().clientY;
  5404. this.iStartHeightOffset = oEvent.pos().layerY;
  5405. this.$FnMouseMove.attach(document, "mousemove");
  5406. this.$FnMouseUp.attach(document, "mouseup");
  5407. this.iStartHeight = oEvent.pos().clientY;
  5408. this.oApp.exec("HIDE_ACTIVE_LAYER");
  5409. this.oApp.exec("HIDE_ALL_DIALOG_LAYER");
  5410. this.oApp.exec("MSG_EDITING_AREA_RESIZE_STARTED", [this.$FnMouseDown, this.$FnMouseMove, this.$FnMouseUp]);
  5411. },
  5412. _mousemove : function(oEvent){
  5413. var iHeightChange = oEvent.pos().clientY - this.iStartHeight;
  5414. this.oApp.exec("RESIZE_EDITING_AREA_BY", [0, iHeightChange]);
  5415. },
  5416. _mouseup : function(oEvent){
  5417. this.$FnMouseMove.detach(document, "mousemove");
  5418. this.$FnMouseUp.detach(document, "mouseup");
  5419. this.oApp.exec("MSG_EDITING_AREA_RESIZE_ENDED", [this.$FnMouseDown, this.$FnMouseMove, this.$FnMouseUp]);
  5420. },
  5421. _closeNotice : function(){
  5422. this.welNoticeLayer.hide();
  5423. jindo.$Cookie().set(this.sCookieNotice, 1, 365*10);
  5424. }
  5425. });
  5426. //}
  5427. /**
  5428. * @pluginDesc Enter키 입력시에 현재 줄을 P 태그로 감거나 <br> 태그를 삽입한다.
  5429. */
  5430. nhn.husky.SE_WYSIWYGEnterKey = jindo.$Class({
  5431. name : "SE_WYSIWYGEnterKey",
  5432. $init : function(sLineBreaker){
  5433. if(sLineBreaker == "BR"){
  5434. this.sLineBreaker = "BR";
  5435. }else{
  5436. this.sLineBreaker = "P";
  5437. }
  5438. this.htBrowser = jindo.$Agent().navigator();
  5439. // [SMARTEDITORSUS-227] IE 인 경우에도 에디터 Enter 처리 로직을 사용하도록 수정
  5440. if(this.htBrowser.opera && this.sLineBreaker == "P"){
  5441. this.$ON_MSG_APP_READY = function(){};
  5442. }
  5443. /**
  5444. * [SMARTEDITORSUS-230] 밑줄+색상변경 , 엔터치면 스크립트 오류
  5445. * [SMARTEDITORSUS-180] [IE9] 배경색 적용 , 엔터키 2회이상 입력시 커서위치가 다음 라인으로 이동하지 않음
  5446. * 오류 현상 : IE9 에서 엔터 생성된 P 태그가 "빈 SPAN 태그만 가지는 경우" P 태그 영역이 보이지 않거나 포커스가 위로 올라가 보임
  5447. * 해결 방법 : 커서 홀더로 IE 이외에서는 <br> 사용
  5448. * - IE 에서는 렌더링 <br> 부분에서 비정상적인 P 태그가 생성되어 [SMARTEDITORSUS-230] 오류 발생
  5449. * unescape("%uFEFF") (BOM) 추가
  5450. * - IE9 표준모드에서 [SMARTEDITORSUS-180] 문제가 발생함
  5451. * (unescape("%u2028") (Line separator) 사용하면 P 보여지나 사이드이펙트가 우려되어 사용하지 않음)
  5452. * IE 브라우저에서 Enter 처리 , &nbsp; 넣어주므로 해당 방식을 그대로 사용하도록 수정함
  5453. */
  5454. if(this.htBrowser.ie){
  5455. this._addCursorHolder = this._addCursorHolderSpace;
  5456. //[SMARTEDITORSUS-1652] 글자크기 지정후 엔터를 치면 빈SPAN으로 감싸지는데 IE에서 빈SPAN은 높이값을 갖지 않아 커서가 올라가 보이게 됨
  5457. // 따라서, IE의 경우 브라우저모드와 상관없이 다음라인의 SPAN에 무조건 ExtraCursorHolder 를 넣어주도록 코멘트처리함
  5458. // if(this.htBrowser.nativeVersion < 9 || document.documentMode < 9){
  5459. // this._addExtraCursorHolder = function(){};
  5460. // }
  5461. }else{
  5462. this._addExtraCursorHolder = function(){};
  5463. this._addBlankText = function(){};
  5464. }
  5465. },
  5466. $ON_MSG_APP_READY : function(){
  5467. this.oApp.exec("ADD_APP_PROPERTY", ["sLineBreaker", this.sLineBreaker]);
  5468. this.oSelection = this.oApp.getEmptySelection();
  5469. this.tmpTextNode = this.oSelection._document.createTextNode(unescape("%u00A0")); // 공백(&nbsp;) 추가 시 사용할 노드
  5470. jindo.$Fn(this._onKeyDown, this).attach(this.oApp.getWYSIWYGDocument(), "keydown");
  5471. },
  5472. _onKeyDown : function(oEvent){
  5473. var oKeyInfo = oEvent.key();
  5474. if(oKeyInfo.shift){
  5475. return;
  5476. }
  5477. if(oKeyInfo.enter){
  5478. if(this.sLineBreaker == "BR"){
  5479. this._insertBR(oEvent);
  5480. }else{
  5481. this._wrapBlock(oEvent);
  5482. }
  5483. }
  5484. },
  5485. /**
  5486. * [SMARTEDITORSUS-950] 에디터 적용 페이지의 Compatible meta IE=edge 설정 줄간격 벌어짐 이슈 (<BR>)
  5487. */
  5488. $ON_REGISTER_CONVERTERS : function(){
  5489. this.oApp.exec("ADD_CONVERTER", ["IR_TO_DB", jindo.$Fn(this.onIrToDB, this).bind()]);
  5490. },
  5491. /**
  5492. * IR_TO_DB 변환기 처리
  5493. */
  5494. onIrToDB : function(sHTML){
  5495. var sContents = sHTML,
  5496. rxEmptyP = /(<p[^>]*>)(?:\s*)(<\/p>)/gi;
  5497. // [SMARTEDITORSUS-2258] 글작성시 보여지는 그대로 저장이 될 수 있도록 브라우저에 따라 빈 P 태그에 대해 구분처리
  5498. if(this.htBrowser.ie && this.htBrowser.version < 11){
  5499. // IE10이하 인 경우 빈 P 태그는 공백을 넣어준다.
  5500. sContents = sContents.replace(rxEmptyP, "$1&nbsp;$2");
  5501. }else{
  5502. // 모던브라우저는 빈 P 태그가 높이값을 갖지 않기 때문에 제거해준다.
  5503. sContents = sContents.replace(rxEmptyP, "");
  5504. }
  5505. return sContents;
  5506. },
  5507. // [IE] Selection 내의 노드를 가져와 빈 노드에 unescape("%uFEFF") (BOM) 을 추가
  5508. _addBlankText : function(oSelection){
  5509. var oNodes = oSelection.getNodes(),
  5510. i, nLen, oNode, oNodeChild, tmpTextNode;
  5511. for(i=0, nLen=oNodes.length; i<nLen; i++){
  5512. oNode = oNodes[i];
  5513. if(oNode.nodeType !== 1 || oNode.tagName !== "SPAN"){
  5514. continue;
  5515. }
  5516. if(oNode.id.indexOf(oSelection.HUSKY_BOOMARK_START_ID_PREFIX) > -1 ||
  5517. oNode.id.indexOf(oSelection.HUSKY_BOOMARK_END_ID_PREFIX) > -1){
  5518. continue;
  5519. }
  5520. oNodeChild = oNode.firstChild;
  5521. if(!oNodeChild ||
  5522. (oNodeChild.nodeType == 3 && nhn.husky.SE2M_Utils.isBlankTextNode(oNodeChild)) ||
  5523. (oNodeChild.nodeType == 1 && oNode.childNodes.length == 1 &&
  5524. (oNodeChild.id.indexOf(oSelection.HUSKY_BOOMARK_START_ID_PREFIX) > -1 || oNodeChild.id.indexOf(oSelection.HUSKY_BOOMARK_END_ID_PREFIX) > -1))){
  5525. tmpTextNode = oSelection._document.createTextNode(unescape("%uFEFF"));
  5526. oNode.appendChild(tmpTextNode);
  5527. }
  5528. }
  5529. },
  5530. // [IE 이외] 빈 노드 내에 커서를 표시하기 위한 처리
  5531. _addCursorHolder : function(elWrapper){
  5532. var elStyleOnlyNode = elWrapper;
  5533. if(elWrapper.innerHTML == "" || (elStyleOnlyNode = this._getStyleOnlyNode(elWrapper))){
  5534. elStyleOnlyNode.innerHTML = "<br>";
  5535. }
  5536. if(!elStyleOnlyNode){
  5537. elStyleOnlyNode = this._getStyleNode(elWrapper);
  5538. }
  5539. return elStyleOnlyNode;
  5540. },
  5541. // [IE] 빈 노드 내에 커서를 표시하기 위한 처리 (_addSpace 사용)
  5542. _addCursorHolderSpace : function(elWrapper){
  5543. var elNode;
  5544. this._addSpace(elWrapper);
  5545. elNode = this._getStyleNode(elWrapper);
  5546. if(elNode.innerHTML == "" && elNode.nodeName.toLowerCase() != "param"){
  5547. try{
  5548. elNode.innerHTML = unescape("%uFEFF");
  5549. }catch(e) {
  5550. }
  5551. }
  5552. return elNode;
  5553. },
  5554. /**
  5555. * [SMARTEDITORSUS-1513] 시작노드와 끝노드 사이에 첫번째 BR을 찾는다. BR이 없는 경우 끝노드를 반환한다.
  5556. * @param {Node} oStart 검사할 시작노드
  5557. * @param {Node} oEnd 검사할 끝노드
  5558. * @return {Node} 첫번째 BR 혹은 끝노드를 반환한다.
  5559. */
  5560. _getBlockEndNode : function(oStart, oEnd){
  5561. if(!oStart){
  5562. return oEnd;
  5563. }else if(oStart.nodeName === "BR"){
  5564. return oStart;
  5565. }else if(oStart === oEnd){
  5566. return oEnd;
  5567. }else{
  5568. return this._getBlockEndNode(oStart.nextSibling, oEnd);
  5569. }
  5570. },
  5571. /**
  5572. * [SMARTEDITORSUS-1797] 북마크 다음노드가가 텍스트노드인 경우, 문자열 앞쪽의 공백문자(\u0020) &nbsp;(\u00A0) 문자로 변환한다.
  5573. * @param {Node} oNode 변환할 텍스트노드
  5574. */
  5575. _convertHeadSpace : function(oNode){
  5576. if(oNode && oNode.nodeType === 3){
  5577. var sText = oNode.nodeValue, sSpaces = "";
  5578. for(var i = 0, ch;(ch = sText[i]); i++){
  5579. if(ch !== "\u0020"){
  5580. break;
  5581. }
  5582. sSpaces += "\u00A0";
  5583. }
  5584. if(i > 0){
  5585. oNode.nodeValue = sSpaces + sText.substring(i);
  5586. }
  5587. }
  5588. },
  5589. /**
  5590. * 기준요소의 nextSibling을 찾는데 빈텍스트요소이면 다음 nextSibling을 찾는다.
  5591. * @param {Node} oNode nextSibling을 찾을 기준요소
  5592. * @returns {Node} 빈텍스트가 아닌 nextSibling 반환한다.
  5593. */
  5594. _getValidNextSibling : function(oNode){
  5595. var oNext = oNode.nextSibling;
  5596. if(!oNext){
  5597. return null;
  5598. }else if(oNext.nodeType == 3 && oNext.nodeValue == ""){
  5599. return arguments.callee(oNext);
  5600. }
  5601. return oNext;
  5602. },
  5603. _wrapBlock : function(oEvent){
  5604. var oSelection = this.oApp.getSelection(),
  5605. sBM = oSelection.placeStringBookmark(),
  5606. oLineInfo = oSelection.getLineInfo(),
  5607. oStart = oLineInfo.oStart,
  5608. oEnd = oLineInfo.oEnd,
  5609. oSWrapper,
  5610. oEWrapper,
  5611. elStyleOnlyNode;
  5612. // line broke by sibling
  5613. // or
  5614. // the parent line breaker is just a block container
  5615. if(!oStart.bParentBreak || oSelection.rxBlockContainer.test(oStart.oLineBreaker.tagName)){
  5616. oEvent.stop();
  5617. // 선택된 내용은 삭제
  5618. oSelection.deleteContents();
  5619. if(!!oStart.oNode.parentNode && oStart.oNode.parentNode.nodeType !== 11){
  5620. // LineBreaker 로 감싸서 분리
  5621. oSWrapper = this.oApp.getWYSIWYGDocument().createElement(this.sLineBreaker);
  5622. oSelection.moveToBookmark(sBM); //oSelection.moveToStringBookmark(sBM, true);
  5623. oSelection.setStartBefore(oStart.oNode);
  5624. oSelection.surroundContents(oSWrapper);
  5625. oSelection.collapseToEnd();
  5626. oEWrapper = this.oApp.getWYSIWYGDocument().createElement(this.sLineBreaker);
  5627. // [SMARTEDITORSUS-1513] oStart.oNode와 oEnd.oNode 사이에 BR이 있는 경우, 다음 엔터시 스타일이 비정상으로 복사되기 때문에 중간에 BR이 있으면 BR까지만 잘라서 세팅한다.
  5628. var oEndNode = this._getBlockEndNode(oStart.oNode, oEnd.oNode);
  5629. // [SMARTEDITORSUS-1743] oStart.oNode가 BR인 경우, setStartBefore와 setEndAfter에 모두 oStart.oNode로 세팅을 시도하기 때문에 스크립트 오류가 발생한다.
  5630. // 따라서, _getBlockEndNode 메서드를 통해 찾은 BR이 oStart.oNode인 경우, oEnd.oNode 를 세팅한다.
  5631. if(oEndNode === oStart.oNode){
  5632. oEndNode = oEnd.oNode;
  5633. }
  5634. oSelection.setEndAfter(oEndNode);
  5635. this._addBlankText(oSelection);
  5636. oSelection.surroundContents(oEWrapper);
  5637. oSelection.moveToStringBookmark(sBM, true); // [SMARTEDITORSUS-180] 포커스 리셋
  5638. oSelection.collapseToEnd(); // [SMARTEDITORSUS-180] 포커스 리셋
  5639. oSelection.removeStringBookmark(sBM);
  5640. oSelection.select();
  5641. // [SMARTEDITORSUS-2312] 위쪽 P에 커서홀더가 없으면 추가 (북마크가 지워진 후에 해야함)
  5642. this._addCursorHolder(oSWrapper);
  5643. // P로 분리했기 때문에 BR이 들어있으면 제거한다.
  5644. if(oEWrapper.lastChild !== null && oEWrapper.lastChild.tagName == "BR"){
  5645. oEWrapper.removeChild(oEWrapper.lastChild);
  5646. }
  5647. // Cursor Holder 추가
  5648. // insert a cursor holder(br) if there's an empty-styling-only-tag surrounding current cursor
  5649. elStyleOnlyNode = this._addCursorHolder(oEWrapper);
  5650. if(oEWrapper.nextSibling && oEWrapper.nextSibling.tagName == "BR"){
  5651. oEWrapper.parentNode.removeChild(oEWrapper.nextSibling);
  5652. }
  5653. oSelection.selectNodeContents(elStyleOnlyNode);
  5654. oSelection.collapseToStart();
  5655. oSelection.select();
  5656. this.oApp.exec("CHECK_STYLE_CHANGE");
  5657. sBM = oSelection.placeStringBookmark();
  5658. setTimeout(jindo.$Fn(function(sBM){
  5659. var elBookmark = oSelection.getStringBookmark(sBM);
  5660. if(!elBookmark){return;}
  5661. oSelection.moveToStringBookmark(sBM);
  5662. oSelection.select();
  5663. oSelection.removeStringBookmark(sBM);
  5664. }, this).bind(sBM), 0);
  5665. return;
  5666. }
  5667. }
  5668. var elBookmark = oSelection.getStringBookmark(sBM, true);
  5669. // 아래는 기본적으로 브라우저 기본 기능에 맡겨서 처리함
  5670. if(this.htBrowser.firefox){
  5671. if(elBookmark && elBookmark.nextSibling && elBookmark.nextSibling.tagName == "IFRAME"){
  5672. // [WOEDITOR-1603] FF에서 본문에 글감 삽입 후 엔터키 입력하면 글감이 복사되는 문제
  5673. setTimeout(jindo.$Fn(function(sBM){
  5674. var elBookmark = oSelection.getStringBookmark(sBM);
  5675. if(!elBookmark){return;}
  5676. oSelection.moveToStringBookmark(sBM);
  5677. oSelection.select();
  5678. oSelection.removeStringBookmark(sBM);
  5679. }, this).bind(sBM), 0);
  5680. }else{
  5681. // [SMARTEDITORSUS-1797] 엔터시 공백문자를 &nbsp; 로 변환
  5682. // FF의 경우 2번이상 엔터치면 앞쪽공백이 사라져서 setTimeout으로 처리
  5683. setTimeout(jindo.$Fn(function(elNext){
  5684. this._convertHeadSpace(elNext);
  5685. }, this).bind(elBookmark.nextSibling), 0);
  5686. // [SMARTEDITORSUS-2070] 북마크를 setTimeout 으로 지우면 연속 엔터시 글꼴이 풀리기 때문에 SMARTEDITORSUS-1797 이슈 처리 로직과 분리
  5687. oSelection.removeStringBookmark(sBM);
  5688. }
  5689. }else if(this.htBrowser.ie){
  5690. var elParentNode = elBookmark.parentNode,
  5691. bAddUnderline = false,
  5692. bAddLineThrough = false;
  5693. // [SMARTEDITORSUS-2190] 첫번째 자식노드로 BR 노드가 있으면 블럭라인으로 변환처리
  5694. this._firstBR2Line(elParentNode, oSelection, oEnd.oLineBreaker);
  5695. if(!elBookmark || !elParentNode){// || elBookmark.nextSibling){
  5696. oSelection.removeStringBookmark(sBM);
  5697. return;
  5698. }
  5699. // [SMARTEDITORSUS-1973] 북마크를 바로 제거하면 커서 위치가 잘못되어 정렬이 풀리기 때문에 setTimeout 으로 제거
  5700. setTimeout(jindo.$Fn(function(){
  5701. this.oApp.getSelection().removeStringBookmark(sBM);
  5702. },this).bind(sBM),0);
  5703. bAddUnderline = (elParentNode.tagName === "U" || nhn.husky.SE2M_Utils.findAncestorByTagName("U", elParentNode) !== null);
  5704. bAddLineThrough = (elParentNode.tagName === "S" || elParentNode.tagName === "STRIKE" ||
  5705. (nhn.husky.SE2M_Utils.findAncestorByTagName("S", elParentNode) !== null && nhn.husky.SE2M_Utils.findAncestorByTagName("STRIKE", elParentNode) !== null));
  5706. // [SMARTEDITORSUS-26] Enter 후에 밑줄/취소선이 복사되지 않는 문제를 처리 (브라우저 Enter 처리 후 실행되도록 setTimeout 사용)
  5707. if(bAddUnderline || bAddLineThrough){
  5708. setTimeout(jindo.$Fn(this._addTextDecorationTag, this).bind(bAddUnderline, bAddLineThrough), 0);
  5709. return;
  5710. }
  5711. // [SMARTEDITORSUS-180] 빈 SPAN 태그에 의해 엔터 후 엔터가 되지 않은 것으로 보이는 문제 (브라우저 Enter 처리 후 실행되도록 setTimeout 사용)
  5712. setTimeout(jindo.$Fn(this._addExtraCursorHolder, this).bind(elParentNode), 0);
  5713. }else{
  5714. var elParentNode = elBookmark.parentNode,
  5715. oNextSibling = this._getValidNextSibling(elBookmark);
  5716. /*
  5717. * [SMARTEDITORSUS-2046] 크롬에서 span으로 감싸있고 다음요소가 br 경우
  5718. * 커서 앞에 내용이 없으면 br로 line-break가 발생하고
  5719. * 커서 앞에 내용이 있으면 상위 p태그로 line-break가 발생하는데 p태그가 쪼개지지 않고 그냥 다음 라인에 p태그가 생긴다.
  5720. * 때문에 span으로 쌓여있고 br태그가 근접해있는 경우 브라우저자체 엔터처리를 막고 강제로 p태그를 쪼개주도록 처리함
  5721. * [SMARTEDITORSUS-2070] span 감싸진 br 뒤에 다른요소가 있는 경우만 해당 로직을 타도록 조건 추가
  5722. */
  5723. if(elParentNode.tagName == "SPAN" && oNextSibling && oNextSibling.nodeName == "BR" && oNextSibling.nextSibling){
  5724. // 현재 선택된 요소들을 먼저 제거한다.
  5725. oSelection.deleteContents();
  5726. // 셀렉션을 커서부터 라인 끝까지 확장한다.
  5727. oSelection.setEndNodes(elBookmark, oEnd.oLineBreaker);
  5728. // 확장된 셀렉션(즉, 커서 뒷부분)을 잘라낸다.
  5729. var oNextContents = oSelection.extractContents(),
  5730. elNextP = oNextContents.firstChild; // oNextContents 는 fragment 이므로 나중에 커서를 위치시키기 위해 firstChild를 미리 할당해 둔다.
  5731. // 잘라낸 부분을 다음 라인으로 삽입한다.
  5732. elParentNode = oStart.oLineBreaker.parentNode; // 커서가 속한 p의 parent
  5733. oNextSibling = oStart.oLineBreaker.nextSibling; // 커서가 속한 p의 다음요소
  5734. if(oNextSibling){
  5735. elParentNode.insertBefore(oNextContents, oNextSibling);
  5736. }else{
  5737. elParentNode.appendChild(oNextContents);
  5738. }
  5739. // 삽입된 라인의 앞쪽에 커서를 위치시킨다.
  5740. oSelection.selectNodeContents(elNextP);
  5741. oSelection.collapseToStart();
  5742. oSelection.select();
  5743. oSelection.removeStringBookmark(sBM);
  5744. oEvent.stop(); // 브라우저의 엔터처리를 막는다.
  5745. }else{
  5746. // [SMARTEDITORSUS-1797] 엔터시 공백문자를 &nbsp; 로 변환
  5747. this._convertHeadSpace(elBookmark.nextSibling);
  5748. oSelection.removeStringBookmark(sBM);
  5749. }
  5750. }
  5751. },
  5752. /**
  5753. * [SMARTEDITORSUS-2190] IE8이하에서 P > SPAN > BR 첫번째에 있으면 엔터시 SPAN 역전현상(IE버그) 발생한다.
  5754. * SPAN 역전현상은 잘못된 태그 구조이기 때문에 다음 엔터시 HuskyRange 에서 오류를 유발한다.
  5755. * 따라서 P태그 안쪽에 BR 첫번째노드로 존재하면 엔터가 동작하기 전에 미리 BR P태그로 변환해두어야 한다.
  5756. *
  5757. * @param {Element} elParentNode 검사할 노드
  5758. * @param {HuskyRange} oSelection 허스키레인지
  5759. * @param {Element} oLineBreaker 검사할 노드가 포함된 블럭노드
  5760. */
  5761. _firstBR2Line : function(elParentNode, oSelection, oLineBreaker){
  5762. while(elParentNode.firstChild && elParentNode.firstChild.nodeName === "BR"){
  5763. // 커서홀더노드를 만들어 미리 BR과 교체해둔다.
  5764. var oCursorHolder = oSelection._document.createTextNode('\u200B');
  5765. elParentNode.replaceChild(oCursorHolder, elParentNode.firstChild);
  5766. // P에서 커서홀더노드 까지를 추출하여 앞 라인으로 붙여넣는다. (P이하에 감싸진 SPAN이나 다른 태그들을 온전히 복사하기 위해 추출하여 삽입하는 방식을 사용함)
  5767. oSelection.setStartBefore(oLineBreaker);
  5768. oSelection.setEndAfter(oCursorHolder);
  5769. oLineBreaker.parentNode.insertBefore(oSelection.extractContents(), oLineBreaker);
  5770. }
  5771. },
  5772. // [IE9 standard mode] 엔터 후의 상/하단 P 태그를 확인하여 BOM, 공백(&nbsp;) 추가
  5773. _addExtraCursorHolder : function(elUpperNode){
  5774. var oNodeChild,
  5775. oPrevChild,
  5776. elHtml;
  5777. elUpperNode = this._getStyleOnlyNode(elUpperNode);
  5778. // 엔터 후의 상단 SPAN 노드에 BOM 추가
  5779. //if(!!elUpperNode && /^(B|EM|I|LABEL|SPAN|STRONG|SUB|SUP|U|STRIKE)$/.test(elUpperNode.tagName) === false){
  5780. if(!!elUpperNode && elUpperNode.tagName === "SPAN"){ // SPAN 인 경우에만 발생함
  5781. oNodeChild = elUpperNode.lastChild;
  5782. while(!!oNodeChild){ // 빈 Text 제거
  5783. oPrevChild = oNodeChild.previousSibling;
  5784. if(oNodeChild.nodeType !== 3){
  5785. oNodeChild = oPrevChild;
  5786. continue;
  5787. }
  5788. if(nhn.husky.SE2M_Utils.isBlankTextNode(oNodeChild)){
  5789. oNodeChild.parentNode.removeChild(oNodeChild);
  5790. }
  5791. oNodeChild = oPrevChild;
  5792. }
  5793. elHtml = elUpperNode.innerHTML;
  5794. if(elHtml.replace("\u200B","").replace("\uFEFF","") === ""){
  5795. elUpperNode.innerHTML = "\u200B";
  5796. }
  5797. }
  5798. // 엔터 후에 비어있는 하단 SPAN 노드에 BOM 추가
  5799. var oSelection = this.oApp.getSelection(),
  5800. sBM,
  5801. elLowerNode,
  5802. elParent;
  5803. if(!oSelection.collapsed){
  5804. return;
  5805. }
  5806. oSelection.fixCommonAncestorContainer();
  5807. elLowerNode = oSelection.commonAncestorContainer;
  5808. if(!elLowerNode){
  5809. return;
  5810. }
  5811. elLowerNode = oSelection._getVeryFirstRealChild(elLowerNode);
  5812. if(elLowerNode.nodeType === 3){
  5813. elLowerNode = elLowerNode.parentNode;
  5814. }
  5815. if(!elLowerNode || elLowerNode.tagName !== "SPAN"){
  5816. return;
  5817. }
  5818. elHtml = elLowerNode.innerHTML;
  5819. if(elHtml.replace("\u200B","").replace("\uFEFF","") === ""){
  5820. elLowerNode.innerHTML = "\u200B";
  5821. }
  5822. // 백스페이스시 커서가 움직이지 않도록 커서를 커서홀더 앞쪽으로 옮긴다.
  5823. oSelection.selectNodeContents(elLowerNode);
  5824. oSelection.collapseToStart();
  5825. oSelection.select();
  5826. },
  5827. // [IE] P 태그 가장 뒤 자식노드로 공백(&nbsp;)을 값으로 하는 텍스트 노드를 추가
  5828. _addSpace : function(elNode){
  5829. var tmpTextNode, elChild, elNextChild, bHasNBSP, aImgChild, elLastImg;
  5830. if(!elNode){
  5831. return;
  5832. }
  5833. if(elNode.nodeType === 3){
  5834. return elNode.parentNode;
  5835. }
  5836. if(elNode.tagName !== "P"){
  5837. return elNode;
  5838. }
  5839. aImgChild = jindo.$Element(elNode).child(function(v){
  5840. return (v.$value().nodeType === 1 && v.$value().tagName === "IMG");
  5841. }, 1);
  5842. if(aImgChild.length > 0){
  5843. elLastImg = aImgChild[aImgChild.length - 1].$value();
  5844. elChild = elLastImg.nextSibling;
  5845. while(elChild){
  5846. elNextChild = elChild.nextSibling;
  5847. if (elChild.nodeType === 3 && (elChild.nodeValue === "&nbsp;" || elChild.nodeValue === unescape("%u00A0") || elChild.nodeValue === "\u200B")) {
  5848. elNode.removeChild(elChild);
  5849. }
  5850. elChild = elNextChild;
  5851. }
  5852. return elNode;
  5853. }
  5854. elChild = elNode.firstChild;
  5855. elNextChild = elChild;
  5856. bHasNBSP = false;
  5857. while(elChild){ // &nbsp;를 붙일꺼니까 P 바로 아래의 "%uFEFF"는 제거함
  5858. elNextChild = elChild.nextSibling;
  5859. if(elChild.nodeType === 3){
  5860. if(elChild.nodeValue === unescape("%uFEFF")){
  5861. elNode.removeChild(elChild);
  5862. }
  5863. if(!bHasNBSP && (elChild.nodeValue === "&nbsp;" || elChild.nodeValue === unescape("%u00A0") || elChild.nodeValue === "\u200B")){
  5864. bHasNBSP = true;
  5865. }
  5866. }
  5867. elChild = elNextChild;
  5868. }
  5869. if(!bHasNBSP){
  5870. tmpTextNode = this.tmpTextNode.cloneNode();
  5871. elNode.appendChild(tmpTextNode);
  5872. }
  5873. return elNode; // [SMARTEDITORSUS-418] return 엘리먼트 추가
  5874. },
  5875. // [IE] 엔터 후에 취소선/밑줄 태그를 임의로 추가 (취소선/밑줄에 색상을 표시하기 위함)
  5876. _addTextDecorationTag : function(bAddUnderline, bAddLineThrough){
  5877. var oTargetNode, oNewNode,
  5878. oSelection = this.oApp.getSelection();
  5879. if(!oSelection.collapsed){
  5880. return;
  5881. }
  5882. oTargetNode = oSelection.startContainer;
  5883. while(oTargetNode){
  5884. if(oTargetNode.nodeType === 3){
  5885. oTargetNode = nhn.DOMFix.parentNode(oTargetNode);
  5886. break;
  5887. }
  5888. if(!oTargetNode.childNodes || oTargetNode.childNodes.length === 0){
  5889. // oTargetNode.innerHTML = "\u200B";
  5890. break;
  5891. }
  5892. oTargetNode = oTargetNode.firstChild;
  5893. }
  5894. if(!oTargetNode){
  5895. return;
  5896. }
  5897. if(oTargetNode.tagName === "U" || oTargetNode.tagName === "S" || oTargetNode.tagName === "STRIKE"){
  5898. return;
  5899. }
  5900. if(bAddUnderline){
  5901. oNewNode = oSelection._document.createElement("U");
  5902. oTargetNode.appendChild(oNewNode);
  5903. oTargetNode = oNewNode;
  5904. }
  5905. if(bAddLineThrough){
  5906. oNewNode = oSelection._document.createElement("STRIKE");
  5907. oTargetNode.appendChild(oNewNode);
  5908. }
  5909. oNewNode.innerHTML = "\u200B";
  5910. oSelection.selectNodeContents(oNewNode);
  5911. oSelection.collapseToEnd(); // End 로 해야 새로 생성된 노드 안으로 Selection 이 들어감
  5912. oSelection.select();
  5913. },
  5914. // returns inner-most styling node
  5915. // -> returns span3 from <span1><span2><span3>aaa</span></span></span>
  5916. _getStyleNode : function(elNode){
  5917. while(elNode.firstChild && this.oSelection._isBlankTextNode(elNode.firstChild)){
  5918. elNode.removeChild(elNode.firstChild);
  5919. }
  5920. var elFirstChild = elNode.firstChild;
  5921. if(!elFirstChild){
  5922. return elNode;
  5923. }
  5924. if(elFirstChild.nodeType === 3 ||
  5925. (elFirstChild.nodeType === 1 &&
  5926. (elFirstChild.tagName == "IMG" || elFirstChild.tagName == "BR" || elFirstChild.tagName == "HR" || elFirstChild.tagName == "IFRAME"))){
  5927. return elNode;
  5928. }
  5929. return this._getStyleNode(elNode.firstChild);
  5930. },
  5931. // returns inner-most styling only node if there's any.
  5932. // -> returns span3 from <span1><span2><span3></span></span></span>
  5933. _getStyleOnlyNode : function(elNode){
  5934. if(!elNode){
  5935. return null;
  5936. }
  5937. // the final styling node must allow appending children
  5938. // -> this doesn't seem to work for FF
  5939. if(!elNode.insertBefore){
  5940. return null;
  5941. }
  5942. if(elNode.tagName == "IMG" || elNode.tagName == "BR" || elNode.tagName == "HR" || elNode.tagName == "IFRAME"){
  5943. return null;
  5944. }
  5945. while(elNode.firstChild && this.oSelection._isBlankTextNode(elNode.firstChild)){
  5946. elNode.removeChild(elNode.firstChild);
  5947. }
  5948. if(elNode.childNodes.length>1){
  5949. return null;
  5950. }
  5951. if(!elNode.firstChild){
  5952. return elNode;
  5953. }
  5954. // [SMARTEDITORSUS-227] TEXT_NODE 가 return 되는 문제를 수정함. IE 에서 TEXT_NODE 의 innrHTML 에 접근하면 오류 발생
  5955. if(elNode.firstChild.nodeType === 3){
  5956. return nhn.husky.SE2M_Utils.isBlankTextNode(elNode.firstChild) ? elNode : null;
  5957. //return (elNode.firstChild.textContents === null || elNode.firstChild.textContents === "") ? elNode : null;
  5958. }
  5959. return this._getStyleOnlyNode(elNode.firstChild);
  5960. },
  5961. _insertBR : function(oEvent){
  5962. oEvent.stop();
  5963. var oSelection = this.oApp.getSelection();
  5964. var elBR = this.oApp.getWYSIWYGDocument().createElement("BR");
  5965. oSelection.insertNode(elBR);
  5966. oSelection.selectNode(elBR);
  5967. oSelection.collapseToEnd();
  5968. if(!this.htBrowser.ie){
  5969. var oLineInfo = oSelection.getLineInfo();
  5970. var oEnd = oLineInfo.oEnd;
  5971. // line break by Parent
  5972. // <div> 1234<br></div>인경우, FF에서는 다음 라인으로 커서 이동이 안 일어남.
  5973. // 그래서 <div> 1234<br><br type='_moz'/></div> 이와 같이 생성해주어야 에디터 상에 2줄로 되어 보임.
  5974. if(oEnd.bParentBreak){
  5975. while(oEnd.oNode && oEnd.oNode.nodeType == 3 && oEnd.oNode.nodeValue == ""){
  5976. oEnd.oNode = oEnd.oNode.previousSibling;
  5977. }
  5978. var nTmp = 1;
  5979. if(oEnd.oNode == elBR || oEnd.oNode.nextSibling == elBR){
  5980. nTmp = 0;
  5981. }
  5982. if(nTmp === 0){
  5983. oSelection.pasteHTML("<br type='_moz'/>");
  5984. oSelection.collapseToEnd();
  5985. }
  5986. }
  5987. }
  5988. // the text cursor won't move to the next line without this
  5989. oSelection.insertNode(this.oApp.getWYSIWYGDocument().createTextNode(""));
  5990. oSelection.select();
  5991. }
  5992. });
  5993. //}
  5994. //{
  5995. /**
  5996. * @fileOverview This file contains Husky plugin that takes care of the operations related to changing the editing mode using a Button element
  5997. * @name hp_SE2M_EditingModeChanger.js
  5998. */
  5999. nhn.husky.SE2M_EditingModeChanger = jindo.$Class({
  6000. name : "SE2M_EditingModeChanger",
  6001. htConversionMode : null,
  6002. $init : function(elAppContainer, htConversionMode){
  6003. this.htConversionMode = htConversionMode;
  6004. this._assignHTMLElements(elAppContainer);
  6005. },
  6006. _assignHTMLElements : function(elAppContainer){
  6007. elAppContainer = jindo.$(elAppContainer) || document;
  6008. //@ec[
  6009. this.elWYSIWYGButton = jindo.$$.getSingle("BUTTON.se2_to_editor", elAppContainer);
  6010. this.elHTMLSrcButton = jindo.$$.getSingle("BUTTON.se2_to_html", elAppContainer);
  6011. this.elTEXTButton = jindo.$$.getSingle("BUTTON.se2_to_text", elAppContainer);
  6012. this.elModeToolbar = jindo.$$.getSingle("DIV.se2_conversion_mode", elAppContainer);
  6013. //@ec]
  6014. this.welWYSIWYGButtonLi = jindo.$Element(this.elWYSIWYGButton.parentNode);
  6015. this.welHTMLSrcButtonLi = jindo.$Element(this.elHTMLSrcButton.parentNode);
  6016. this.welTEXTButtonLi = jindo.$Element(this.elTEXTButton.parentNode);
  6017. },
  6018. $BEFORE_MSG_APP_READY : function(){
  6019. this.oApp.exec("ADD_APP_PROPERTY", ["isUseModeChanger", jindo.$Fn(this.isUseModeChanger, this).bind()]);
  6020. },
  6021. $ON_MSG_APP_READY : function(){
  6022. if(this.oApp.htOptions.bOnlyTextMode){
  6023. this.elWYSIWYGButton.style.display = 'none';
  6024. this.elHTMLSrcButton.style.display = 'none';
  6025. this.elTEXTButton.style.display = 'block';
  6026. this.oApp.exec("CHANGE_EDITING_MODE", ["TEXT"]);
  6027. }else{
  6028. this.oApp.registerBrowserEvent(this.elWYSIWYGButton, "click", "EVENT_CHANGE_EDITING_MODE_CLICKED", ["WYSIWYG"]);
  6029. this.oApp.registerBrowserEvent(this.elHTMLSrcButton, "click", "EVENT_CHANGE_EDITING_MODE_CLICKED", ["HTMLSrc"]);
  6030. this.oApp.registerBrowserEvent(this.elTEXTButton, "click", "EVENT_CHANGE_EDITING_MODE_CLICKED", ["TEXT", false]);
  6031. this.showModeChanger();
  6032. if(this.isUseModeChanger() === false && this.oApp.isUseVerticalResizer() === false){
  6033. this.elModeToolbar.style.display = "none";
  6034. }
  6035. }
  6036. },
  6037. // [SMARTEDITORSUS-906][SMARTEDITORSUS-1433] Editing Mode 사용 여부 처리 (true:사용함/ false:사용하지 않음)
  6038. showModeChanger : function(){
  6039. if(this.isUseModeChanger()){
  6040. this.elWYSIWYGButton.style.display = 'block';
  6041. this.elHTMLSrcButton.style.display = 'block';
  6042. this.elTEXTButton.style.display = 'block';
  6043. }else{
  6044. this.elWYSIWYGButton.style.display = 'none';
  6045. this.elHTMLSrcButton.style.display = 'none';
  6046. this.elTEXTButton.style.display = 'none';
  6047. }
  6048. },
  6049. isUseModeChanger : function(){
  6050. return (typeof(this.htConversionMode) === 'undefined' || typeof(this.htConversionMode.bUseModeChanger) === 'undefined' || this.htConversionMode.bUseModeChanger === true) ? true : false;
  6051. },
  6052. $ON_EVENT_CHANGE_EDITING_MODE_CLICKED : function(sMode, bNoAlertMsg){
  6053. if (sMode == 'TEXT') {
  6054. //에디터 영역 내에 모든 내용 가져옴.
  6055. var sContent = this.oApp.getIR();
  6056. // 내용이 있으면 경고창 띄우기
  6057. if (sContent.length > 0 && !bNoAlertMsg) {
  6058. if ( !confirm(this.oApp.$MSG("SE2M_EditingModeChanger.confirmTextMode")) ) {
  6059. return false;
  6060. }
  6061. }
  6062. this.oApp.exec("CHANGE_EDITING_MODE", [sMode]);
  6063. }else{
  6064. this.oApp.exec("CHANGE_EDITING_MODE", [sMode]);
  6065. }
  6066. if ('HTMLSrc' == sMode) {
  6067. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['htmlmode']);
  6068. } else if ('TEXT' == sMode) {
  6069. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['textmode']);
  6070. } else {
  6071. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['editormode']);
  6072. }
  6073. },
  6074. $ON_DISABLE_ALL_UI : function(htOptions){
  6075. htOptions = htOptions || {};
  6076. var waExceptions = jindo.$A(htOptions.aExceptions || []);
  6077. if(waExceptions.has("mode_switcher")){
  6078. return;
  6079. }
  6080. if(this.oApp.getEditingMode() == "WYSIWYG"){
  6081. this.welWYSIWYGButtonLi.removeClass("active");
  6082. this.elHTMLSrcButton.disabled = true;
  6083. this.elTEXTButton.disabled = true;
  6084. } else if (this.oApp.getEditingMode() == 'TEXT') {
  6085. this.welTEXTButtonLi.removeClass("active");
  6086. this.elWYSIWYGButton.disabled = true;
  6087. this.elHTMLSrcButton.disabled = true;
  6088. }else{
  6089. this.welHTMLSrcButtonLi.removeClass("active");
  6090. this.elWYSIWYGButton.disabled = true;
  6091. this.elTEXTButton.disabled = true;
  6092. }
  6093. },
  6094. $ON_ENABLE_ALL_UI : function(){
  6095. if(this.oApp.getEditingMode() == "WYSIWYG"){
  6096. this.welWYSIWYGButtonLi.addClass("active");
  6097. this.elHTMLSrcButton.disabled = false;
  6098. this.elTEXTButton.disabled = false;
  6099. } else if (this.oApp.getEditingMode() == 'TEXT') {
  6100. this.welTEXTButtonLi.addClass("active");
  6101. this.elWYSIWYGButton.disabled = false;
  6102. this.elHTMLSrcButton.disabled = false;
  6103. }else{
  6104. this.welHTMLSrcButtonLi.addClass("active");
  6105. this.elWYSIWYGButton.disabled = false;
  6106. this.elTEXTButton.disabled = false;
  6107. }
  6108. },
  6109. $ON_CHANGE_EDITING_MODE : function(sMode){
  6110. if(sMode == "HTMLSrc"){
  6111. this.welWYSIWYGButtonLi.removeClass("active");
  6112. this.welHTMLSrcButtonLi.addClass("active");
  6113. this.welTEXTButtonLi.removeClass("active");
  6114. this.elWYSIWYGButton.disabled = false;
  6115. this.elHTMLSrcButton.disabled = true;
  6116. this.elTEXTButton.disabled = false;
  6117. this.oApp.exec("HIDE_ALL_DIALOG_LAYER");
  6118. this.oApp.exec("DISABLE_ALL_UI", [{aExceptions:["mode_switcher"]}]);
  6119. } else if (sMode == 'TEXT') {
  6120. this.welWYSIWYGButtonLi.removeClass("active");
  6121. this.welHTMLSrcButtonLi.removeClass("active");
  6122. this.welTEXTButtonLi.addClass("active");
  6123. this.elWYSIWYGButton.disabled = false;
  6124. this.elHTMLSrcButton.disabled = false;
  6125. this.elTEXTButton.disabled = true;
  6126. this.oApp.exec("HIDE_ALL_DIALOG_LAYER");
  6127. this.oApp.exec("DISABLE_ALL_UI", [{aExceptions:["mode_switcher"]}]);
  6128. }else{
  6129. this.welWYSIWYGButtonLi.addClass("active");
  6130. this.welHTMLSrcButtonLi.removeClass("active");
  6131. this.welTEXTButtonLi.removeClass("active");
  6132. this.elWYSIWYGButton.disabled = true;
  6133. this.elHTMLSrcButton.disabled = false;
  6134. this.elTEXTButton.disabled = false;
  6135. this.oApp.exec("RESET_STYLE_STATUS");
  6136. this.oApp.exec("ENABLE_ALL_UI", []);
  6137. }
  6138. }
  6139. });
  6140. //}
  6141. /**
  6142. * @pluginDesc WYSIWYG 영역에 붙여넣어지는 외부 컨텐츠를 정제하는 플러그인
  6143. */
  6144. nhn.husky.SE_PasteHandler = jindo.$Class({
  6145. name : "SE_PasteHandler",
  6146. _rxStyleTag : /<style(?:\s+[^>]*)?>(?:.|\r|\n)*?<\/style>/gi,
  6147. _rxStyleTagStrip : /<\/?style(?:\s+[^>]*)?>/gi,
  6148. _rxClassSelector : /\w*\.\w+/g,
  6149. _rxClassSelectorStart : /\w*\./g,
  6150. $init : function(){
  6151. },
  6152. /**
  6153. * 크롬에서 /붙시 style분석을 위한 임시 document
  6154. * @returns {Document} 임시 document 반환
  6155. */
  6156. _getTmpDocument : function(){
  6157. if(!this._oTmpDoc){
  6158. var elIframe = document.createElement("IFRAME");
  6159. elIframe.style.display = "none";
  6160. document.body.appendChild(elIframe);
  6161. var oDoc = elIframe.contentWindow.document;
  6162. oDoc.open();
  6163. oDoc.write('<html><head></head><body></body></html>');
  6164. oDoc.close();
  6165. this._oTmpDoc = oDoc;
  6166. }
  6167. return this._oTmpDoc;
  6168. },
  6169. /**
  6170. * CSSRuleList에서 CSSRule.STYLE_RULE만 가져와 selector키 맵핑형태로 반환한다.
  6171. * @param {CSSRuleList} cssRules 확인할 CSSRuleList
  6172. * @returns {HashTable} key(셀렉터명)/value(CSSRule) 맵핑객체
  6173. */
  6174. _getCSSStyleRule : function(cssRules) {
  6175. var htStyleRule = {};
  6176. for(var i = 0, cssRule; (cssRule = cssRules[i]); i++){
  6177. // @see https://developer.mozilla.org/en-US/docs/Web/API/CSSRule#Type_constants
  6178. if(cssRule.type === CSSRule.STYLE_RULE){
  6179. htStyleRule[cssRule.selectorText] = cssRule.style;
  6180. }
  6181. }
  6182. return htStyleRule;
  6183. },
  6184. /**
  6185. * html문자열에 style태그가 있으면 CSSStyleRule을 추출하여 저장해둔다.
  6186. * @param {String} html 확인할 HTML문자열
  6187. */
  6188. _extractStyle : function(html) {
  6189. if(!html) {
  6190. return;
  6191. }
  6192. var aMatch = html.match(this._rxStyleTag) || [];
  6193. var sStyles = aMatch.join("\n");
  6194. sStyles = sStyles.replace(this._rxStyleTagStrip, "");
  6195. var oTmpDoc = this._getTmpDocument();
  6196. var elHead = oTmpDoc.getElementsByTagName("HEAD")[0];
  6197. var elStyle = oTmpDoc.createElement("STYLE");
  6198. elStyle.innerHTML = sStyles;
  6199. elHead.appendChild(elStyle);
  6200. this._htStyleRule = this._getCSSStyleRule(elStyle.sheet.cssRules);
  6201. elStyle.parentNode.removeChild(elStyle);
  6202. },
  6203. /**
  6204. * 해당 요소에 inline style을 적용한다.
  6205. * @param {Element} el 스타일을 적용할 대상 요소
  6206. * @param {CSSStyleDeclaration} oStyle 반영할 스타일 정의 객체
  6207. * @param {Booleam} bOverride 스타일을 덮어씌울 것인지 여부
  6208. */
  6209. _applyInlineStyle : function(el, oStyle, bOverride) {
  6210. for(var i = 0, len = oStyle.length, sStyleName; i < len; i++){
  6211. sStyleName = oStyle[i];
  6212. if(bOverride || !el.style[sStyleName]){
  6213. el.style[sStyleName] = oStyle[sStyleName];
  6214. }
  6215. }
  6216. },
  6217. /**
  6218. * CSSStyleRule을 inline style로 반영해준다.
  6219. * @param {String} sSelector CSS셀렉터명
  6220. * @param {CSSStyleDeclaration} oStyle 셀렉터명에 해당하는 스타일 정의 객체
  6221. * @param {Element} el 스타일반영을 제한할 상위 요소
  6222. */
  6223. _applyStyleRuleToInline : function(sSelector, oStyle, el) {
  6224. var aClassSelector = sSelector.match(this._rxClassSelector) || [];
  6225. // 태그 셀렉터는 잘못된 영향을 줄 수 있기 때문에 클래스 셀렉터만 적용한다.
  6226. if(aClassSelector.length < 1) {
  6227. return;
  6228. }
  6229. var sRemoveClass = aClassSelector.join(" ").replace(this._rxClassSelectorStart, "");
  6230. var aelTarget = jindo.$$(sSelector, el);
  6231. for(var i = 0, elTarget; (elTarget = aelTarget[i]); i++){
  6232. this._applyInlineStyle(elTarget, oStyle);
  6233. if(sRemoveClass){
  6234. jindo.$Element(elTarget).removeClass(sRemoveClass);
  6235. }
  6236. }
  6237. },
  6238. /**
  6239. * 저장해둔 CSSStyleRule를 적용한다.
  6240. * @param {Element} el 적용범위를 제한할 상위 요소
  6241. */
  6242. _applyStyle : function(el) {
  6243. var htStyleRule = this._htStyleRule || {};
  6244. for (var sSelector in htStyleRule) {
  6245. this._applyStyleRuleToInline(sSelector, htStyleRule[sSelector], el);
  6246. }
  6247. this._htStyleRule = null;
  6248. },
  6249. /**
  6250. * 붙여넣기시 생성된 폰트태그를 보정한다.
  6251. * @param {Element} el 태그정제를 제한할 상위 요소
  6252. */
  6253. _revertFontAfterPaste : function(el){
  6254. nhn.husky.SE2M_Utils.removeInvalidFont(el);
  6255. if(document.documentMode < 11){
  6256. // [MUG-7757] IE11미만은 span 이 남아있기 때문에 그냥 제거
  6257. nhn.husky.SE2M_Utils.stripTags(el, "FONT");
  6258. }else{
  6259. // IE11미만이외는 font를 span으로 재변환
  6260. nhn.husky.SE2M_Utils.convertFontToSpan(el);
  6261. }
  6262. },
  6263. /**
  6264. * SPAN태그에 line-height 스타일속성이 있으면 제거한다.
  6265. * @param {Element} el 태그정제를 제한할 상위 요소
  6266. */
  6267. _removeLineHeightInSpan : function(el){
  6268. var aelSpans = jindo.$$('span[style*="line-height:"]', el);
  6269. for(var i = 0, elSpan; (elSpan = aelSpans[i]); i++){
  6270. elSpan.style.lineHeight = null;
  6271. }
  6272. },
  6273. /**
  6274. * paste이벤트에서 클립보드의 style태그를 추출할 있으면 CSSStyleRule을 저장해둔다.
  6275. */
  6276. $ON_EVENT_EDITING_AREA_PASTE : function(we) {
  6277. var oClipboard = we.$value().clipboardData;
  6278. if (!oClipboard) {
  6279. return;
  6280. }
  6281. var sClipboardHTML = oClipboard.getData("text/html");
  6282. if (!sClipboardHTML) {
  6283. return;
  6284. }
  6285. this._extractStyle(sClipboardHTML);
  6286. },
  6287. /**
  6288. * paste된 정제처리한다.
  6289. * 1. font태그가 삽입되었다면 보정한다.
  6290. * 2. 저장해둔 CSSStyleRule이 있다면 inline style로 반영해준다.
  6291. * 3. line-height스타일이 지정된 span이 있으면 해당 속성 제거
  6292. */
  6293. $ON_EVENT_EDITING_AREA_PASTE_DELAY : function() {
  6294. var el = this.oApp.getWYSIWYGDocument().body;
  6295. this._revertFontAfterPaste(el);
  6296. this._applyStyle(el);
  6297. this._removeLineHeightInSpan(el);
  6298. }
  6299. });
  6300. //{
  6301. /**
  6302. * @fileOverview This file contains Husky plugin that takes care of the basic editor commands
  6303. * @name hp_SE_ExecCommand.js
  6304. */
  6305. nhn.husky.SE2M_ExecCommand = jindo.$Class({
  6306. name : "SE2M_ExecCommand",
  6307. oEditingArea : null,
  6308. oUndoOption : null,
  6309. _rxCmdInline : /^(?:bold|underline|italic|strikethrough|superscript|subscript)$/i, // inline element 가 생성되는 command
  6310. $init : function(oEditingArea){
  6311. this.oEditingArea = oEditingArea;
  6312. this.nIndentSpacing = 40;
  6313. this.rxClickCr = new RegExp('^bold|underline|italic|strikethrough|justifyleft|justifycenter|justifyright|justifyfull|insertorderedlist|insertunorderedlist|outdent|indent$', 'i');
  6314. },
  6315. $BEFORE_MSG_APP_READY : function(){
  6316. // the right document will be available only when the src is completely loaded
  6317. if(this.oEditingArea && this.oEditingArea.tagName == "IFRAME"){
  6318. this.oEditingArea = this.oEditingArea.contentWindow.document;
  6319. }
  6320. },
  6321. $ON_MSG_APP_READY : function(){
  6322. // [SMARTEDITORSUS-2260] 메일 > Mac에서 ctrl 조합 단축키 모두 meta 조합으로 변경
  6323. if (jindo.$Agent().os().mac) {
  6324. this.oApp.exec("REGISTER_HOTKEY", ["meta+b", "EXECCOMMAND", ["bold", false, false]]);
  6325. this.oApp.exec("REGISTER_HOTKEY", ["meta+u", "EXECCOMMAND", ["underline", false, false]]);
  6326. this.oApp.exec("REGISTER_HOTKEY", ["meta+i", "EXECCOMMAND", ["italic", false, false]]);
  6327. this.oApp.exec("REGISTER_HOTKEY", ["meta+d", "EXECCOMMAND", ["strikethrough", false, false]]);
  6328. } else {
  6329. this.oApp.exec("REGISTER_HOTKEY", ["ctrl+b", "EXECCOMMAND", ["bold", false, false]]);
  6330. this.oApp.exec("REGISTER_HOTKEY", ["ctrl+u", "EXECCOMMAND", ["underline", false, false]]);
  6331. this.oApp.exec("REGISTER_HOTKEY", ["ctrl+i", "EXECCOMMAND", ["italic", false, false]]);
  6332. this.oApp.exec("REGISTER_HOTKEY", ["ctrl+d", "EXECCOMMAND", ["strikethrough", false, false]]);
  6333. }
  6334. this.oApp.exec("REGISTER_HOTKEY", ["tab", "INDENT"]);
  6335. this.oApp.exec("REGISTER_HOTKEY", ["shift+tab", "OUTDENT"]);
  6336. //this.oApp.exec("REGISTER_HOTKEY", ["tab", "EXECCOMMAND", ["indent", false, false]]);
  6337. //this.oApp.exec("REGISTER_HOTKEY", ["shift+tab", "EXECCOMMAND", ["outdent", false, false]]);
  6338. this.oApp.exec("REGISTER_UI_EVENT", ["bold", "click", "EXECCOMMAND", ["bold", false, false]]);
  6339. this.oApp.exec("REGISTER_UI_EVENT", ["underline", "click", "EXECCOMMAND", ["underline", false, false]]);
  6340. this.oApp.exec("REGISTER_UI_EVENT", ["italic", "click", "EXECCOMMAND", ["italic", false, false]]);
  6341. this.oApp.exec("REGISTER_UI_EVENT", ["lineThrough", "click", "EXECCOMMAND", ["strikethrough", false, false]]);
  6342. this.oApp.exec("REGISTER_UI_EVENT", ["superscript", "click", "EXECCOMMAND", ["superscript", false, false]]);
  6343. this.oApp.exec("REGISTER_UI_EVENT", ["subscript", "click", "EXECCOMMAND", ["subscript", false, false]]);
  6344. this.oApp.exec("REGISTER_UI_EVENT", ["justifyleft", "click", "EXECCOMMAND", ["justifyleft", false, false]]);
  6345. this.oApp.exec("REGISTER_UI_EVENT", ["justifycenter", "click", "EXECCOMMAND", ["justifycenter", false, false]]);
  6346. this.oApp.exec("REGISTER_UI_EVENT", ["justifyright", "click", "EXECCOMMAND", ["justifyright", false, false]]);
  6347. this.oApp.exec("REGISTER_UI_EVENT", ["justifyfull", "click", "EXECCOMMAND", ["justifyfull", false, false]]);
  6348. this.oApp.exec("REGISTER_UI_EVENT", ["orderedlist", "click", "EXECCOMMAND", ["insertorderedlist", false, false]]);
  6349. this.oApp.exec("REGISTER_UI_EVENT", ["unorderedlist", "click", "EXECCOMMAND", ["insertunorderedlist", false, false]]);
  6350. this.oApp.exec("REGISTER_UI_EVENT", ["outdent", "click", "EXECCOMMAND", ["outdent", false, false]]);
  6351. this.oApp.exec("REGISTER_UI_EVENT", ["indent", "click", "EXECCOMMAND", ["indent", false, false]]);
  6352. // this.oApp.exec("REGISTER_UI_EVENT", ["styleRemover", "click", "EXECCOMMAND", ["RemoveFormat", false, false]]);
  6353. this.oNavigator = jindo.$Agent().navigator();
  6354. if(!this.oNavigator.safari && !this.oNavigator.chrome){
  6355. this._getDocumentBR = function(){};
  6356. this._fixDocumentBR = function(){};
  6357. }
  6358. if(!this.oNavigator.ie){
  6359. this._fixCorruptedBlockQuote = function(){};
  6360. if(!this.oNavigator.safari && !this.oNavigator.chrome){
  6361. this._insertBlankLine = function(){};
  6362. }
  6363. }
  6364. if(!this.oNavigator.firefox){
  6365. this._extendBlock = function(){};
  6366. }
  6367. },
  6368. $ON_INDENT : function(){
  6369. this.oApp.delayedExec("EXECCOMMAND", ["indent", false, false], 0);
  6370. },
  6371. $ON_OUTDENT : function(){
  6372. this.oApp.delayedExec("EXECCOMMAND", ["outdent", false, false], 0);
  6373. },
  6374. $BEFORE_EXECCOMMAND : function(sCommand, bUserInterface, vValue, htOptions){
  6375. var elTmp, oSelection;
  6376. //본문에 전혀 클릭이 한번도 안 일어난 상태에서 크롬과 IE에서 EXECCOMMAND가 정상적으로 안 먹히는 현상.
  6377. this.oApp.exec("FOCUS");
  6378. this._bOnlyCursorChanged = false;
  6379. oSelection = this.oApp.getSelection();
  6380. // [SMARTEDITORSUS-1584] IE에서 테이블관련 태그 사이의 텍스트노드가 포함된 채로 execCommand 가 실행되면
  6381. // 테이블 태그들 사이에 더미 P 태그가 추가된다.
  6382. // 테이블관련 태그 사이에 태그가 있으면 문법에 어긋나기 때문에 getContents 시 이 더미 P 태그들이 밖으로 빠져나가게 된다.
  6383. // 때문에 execCommand 실행되기 전에 셀렉션에 테이블관련 태그 사이의 텍스트노드를 찾아내 지워준다.
  6384. for(var i = 0, aNodes = oSelection.getNodes(), oNode;(oNode = aNodes[i]); i++){
  6385. nhn.husky.SE2M_Utils.removeInvalidNodeInTable(oNode);
  6386. }
  6387. if(/^insertorderedlist|insertunorderedlist$/i.test(sCommand)){
  6388. this._getDocumentBR();
  6389. // [SMARTEDITORSUS-985][SMARTEDITORSUS-1740]
  6390. this._checkBlockQuoteCondition_IE();
  6391. // --[SMARTEDITORSUS-985][SMARTEDITORSUS-1740]
  6392. }
  6393. if(/^justify*/i.test(sCommand)){
  6394. // [SMARTEDITORSUS-704][SMARTEDITORSUS-2050] 메서드 통합
  6395. this._removeElementAlign('span');
  6396. }
  6397. if(this._rxCmdInline.test(sCommand)){
  6398. this.oUndoOption = {bMustBlockElement:true};
  6399. if(nhn.CurrentSelection.isCollapsed()){
  6400. this._bOnlyCursorChanged = true;
  6401. }
  6402. }
  6403. if(sCommand == "indent" || sCommand == "outdent"){
  6404. if(!htOptions){htOptions = {};}
  6405. htOptions["bDontAddUndoHistory"] = true;
  6406. }
  6407. if((!htOptions || !htOptions["bDontAddUndoHistory"]) && !this._bOnlyCursorChanged){
  6408. if(/^justify*/i.test(sCommand)){
  6409. this.oUndoOption = {sSaveTarget:"BODY"};
  6410. }else if(sCommand === "insertorderedlist" || sCommand === "insertunorderedlist"){
  6411. this.oUndoOption = {bMustBlockContainer:true};
  6412. }
  6413. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", [sCommand, this.oUndoOption]);
  6414. }
  6415. if(this.oNavigator.ie && this.oApp.getWYSIWYGDocument().selection){
  6416. if(this.oApp.getWYSIWYGDocument().selection.type === "Control"){
  6417. oSelection = this.oApp.getSelection();
  6418. oSelection.select();
  6419. }
  6420. }
  6421. if(sCommand == "insertorderedlist" || sCommand == "insertunorderedlist"){
  6422. this._insertBlankLine();
  6423. }
  6424. },
  6425. /**
  6426. * [SMARTEDITORSUS-985][SMARTEDITORSUS-1740][SMARTEDITORSUS-1798][SMARTEDITORSUS-2157]
  6427. * [Win XP - IE 8][IE 9~11][IE edge] 인용구 안에서 번호매기기, 글머리기호를 적용할 필요한 조치이다.
  6428. *
  6429. * 인용구 안의 선택한 영역을 기준으로,
  6430. *
  6431. * 선택한 영역이 없는 경우에는 해당 줄을 제외했을 ,
  6432. * 선택한 영역이 있는 경우에는 선택한 줄을 제외했을
  6433. *
  6434. * 이상의 <P> 없는 경우
  6435. * execCommand("insertorderedlist"), execCommand("insertunorderedlist") 오동작한다.
  6436. *
  6437. * 이러한 오동작을 방지하기 위해
  6438. * 인용구 안에서 번호매기기, 글머리기호를 삽입할 때는
  6439. * execCommand() 실행 전에 <P> 삽입해 주고,
  6440. * execCommand() 실행 <P> 제거해 준다.
  6441. * */
  6442. _checkBlockQuoteCondition_IE : function(){
  6443. var htBrowser = jindo.$Agent().navigator();
  6444. var bProcess = false;
  6445. var elBlockquote;
  6446. if((htBrowser.ie && (htBrowser.nativeVersion >= 9 && htBrowser.nativeVersion <= 11) && (htBrowser.version >= 9 && htBrowser.version <= 11))
  6447. || (this.oApp.oAgent.os().winxp && htBrowser.ie && htBrowser.nativeVersion <= 8) || htBrowser.edge){
  6448. var oSelection = this.oApp.getSelection();
  6449. var elCommonAncestorContainer = oSelection.commonAncestorContainer;
  6450. var htAncestor_blockquote = nhn.husky.SE2M_Utils.findAncestorByTagNameWithCount("BLOCKQUOTE", elCommonAncestorContainer);
  6451. elBlockquote = htAncestor_blockquote.elNode;
  6452. if(elBlockquote){
  6453. var htAncestor_cell = nhn.husky.SE2M_Utils.findClosestAncestorAmongTagNamesWithCount(["td", "th"], elCommonAncestorContainer);
  6454. if(htAncestor_cell.elNode){
  6455. if(htAncestor_cell.nRecursiveCount > htAncestor_blockquote.nRecursiveCount){
  6456. // blockquote가 cell 안에서 생성된 경우
  6457. bProcess = true;
  6458. }
  6459. }else{
  6460. // blockquote가 cell 안에서 생성되지 않은 경우
  6461. bProcess = true;
  6462. }
  6463. }
  6464. }
  6465. if(bProcess){
  6466. this._insertDummyParagraph_IE(elBlockquote);
  6467. }
  6468. },
  6469. /**
  6470. * [SMARTEDITORSUS-985][SMARTEDITORSUS-1740]
  6471. * [IE 9~10] 대상 엘리먼트에 <P> 삽입
  6472. * */
  6473. _insertDummyParagraph_IE : function(el){
  6474. this._elDummyParagraph = document.createElement("P");
  6475. el.appendChild(this._elDummyParagraph);
  6476. },
  6477. /**
  6478. * [SMARTEDITORSUS-985][SMARTEDITORSUS-1740]
  6479. * [IE 9~10] <P> 제거
  6480. * */
  6481. _removeDummyParagraph_IE : function(){
  6482. if(this._elDummyParagraph && this._elDummyParagraph.parentNode){
  6483. this._elDummyParagraph.parentNode.removeChild(this._elDummyParagraph);
  6484. }
  6485. },
  6486. $ON_EXECCOMMAND : function(sCommand, bUserInterface, vValue){
  6487. var bSelectedBlock = false;
  6488. var htSelectedTDs = {};
  6489. var oSelection = this.oApp.getSelection();
  6490. bUserInterface = (bUserInterface == "" || bUserInterface)?bUserInterface:false;
  6491. vValue = (vValue == "" || vValue)?vValue:false;
  6492. this.oApp.exec("IS_SELECTED_TD_BLOCK",['bIsSelectedTd',htSelectedTDs]);
  6493. bSelectedBlock = htSelectedTDs.bIsSelectedTd;
  6494. if( bSelectedBlock){
  6495. if(sCommand == "indent"){
  6496. this.oApp.exec("SET_LINE_BLOCK_STYLE", [null, jindo.$Fn(this._indentMargin, this).bind()]);
  6497. }else if(sCommand == "outdent"){
  6498. this.oApp.exec("SET_LINE_BLOCK_STYLE", [null, jindo.$Fn(this._outdentMargin, this).bind()]);
  6499. }else{
  6500. this._setBlockExecCommand(sCommand, bUserInterface, vValue);
  6501. }
  6502. } else {
  6503. switch(sCommand){
  6504. case "indent":
  6505. case "outdent":
  6506. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", [sCommand]);
  6507. // bookmark 설정
  6508. var sBookmark = oSelection.placeStringBookmark();
  6509. if(sCommand === "indent"){
  6510. this.oApp.exec("SET_LINE_STYLE", [null, jindo.$Fn(this._indentMargin, this).bind(), {bDoNotSelect : true, bDontAddUndoHistory : true}]);
  6511. }else{
  6512. this.oApp.exec("SET_LINE_STYLE", [null, jindo.$Fn(this._outdentMargin, this).bind(), {bDoNotSelect : true, bDontAddUndoHistory : true}]);
  6513. }
  6514. oSelection.moveToStringBookmark(sBookmark);
  6515. oSelection.select();
  6516. oSelection.removeStringBookmark(sBookmark); //bookmark 삭제
  6517. setTimeout(jindo.$Fn(function(sCommand){
  6518. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", [sCommand]);
  6519. }, this).bind(sCommand), 25);
  6520. break;
  6521. case "justifyleft":
  6522. case "justifycenter":
  6523. case "justifyright":
  6524. case "justifyfull":
  6525. var oSelectionClone = this._extendBlock(); // FF
  6526. this.oEditingArea.execCommand(sCommand, bUserInterface, vValue);
  6527. if(!!oSelectionClone){
  6528. oSelectionClone.select();
  6529. }
  6530. // [SMARTEDITORSUS-2050] 선택된 범위 내에 table이 있다면 align 제거
  6531. // [SMARTEDITORSUS-2114] 크롬에서 표 가운데 정렬이 되지 않는 문제가 있어서 해당 처리를 IE에서만 하도록 수정
  6532. if(this.oNavigator.ie) {
  6533. this._removeElementAlign('table');
  6534. }
  6535. break;
  6536. default:
  6537. //if(this.oNavigator.firefox){
  6538. //this.oEditingArea.execCommand("styleWithCSS", bUserInterface, false);
  6539. //}
  6540. // [SMARTEDITORSUS-1646] [SMARTEDITORSUS-1653] collapsed 상태이면 execCommand 가 실행되기 전에 ZWSP를 넣어준다.
  6541. // [SMARTEDITORSUS-1702] ul, ol 처럼 block element 가 바로 생성되는 경우는 ZWSP 삽입 제외
  6542. if(oSelection.collapsed && this._rxCmdInline.test(sCommand)){
  6543. // collapsed 인 경우
  6544. var sBM = oSelection.placeStringBookmark(),
  6545. oBM = oSelection.getStringBookmark(sBM),
  6546. oHolderNode = oBM.previousSibling;
  6547. // execCommand를 실행할때마다 ZWSP가 포함된 더미 태그가 자꾸 생길 수 있기 때문에 이미 있으면 있는 걸로 사용한다.
  6548. if(!oHolderNode || oHolderNode.nodeValue !== "\u200B"){
  6549. oHolderNode = this.oApp.getWYSIWYGDocument().createTextNode("\u200B");
  6550. oSelection.insertNode(oHolderNode);
  6551. }
  6552. oSelection.removeStringBookmark(sBM); // 미리 지워주지 않으면 더미 태그가 생길 수 있다.
  6553. oSelection.selectNodeContents(oHolderNode);
  6554. oSelection.select();
  6555. this.oEditingArea.execCommand(sCommand, bUserInterface, vValue);
  6556. oSelection.collapseToEnd();
  6557. oSelection.select();
  6558. // [SMARTEDITORSUS-1658] 뒤쪽에 더미태그가 있으면 제거해준다.
  6559. var oSingleNode = this._findSingleNode(oHolderNode);
  6560. if(oSingleNode && oSelection._hasCursorHolderOnly(oSingleNode.nextSibling)){
  6561. oSingleNode.parentNode.removeChild(oSingleNode.nextSibling);
  6562. }
  6563. }else{
  6564. this.oEditingArea.execCommand(sCommand, bUserInterface, vValue);
  6565. }
  6566. }
  6567. }
  6568. this._countClickCr(sCommand);
  6569. },
  6570. /**
  6571. * [SMARTEDITORSUS-1658] 해당노드의 상위로 검색해 single child 갖는 최상위 노드를 찾는다.
  6572. * @param {Node} oNode 확인할 노드
  6573. * @return {Node} single child 감싸고 있는 최상위 노드를 반환한다. 없으면 입력한 노드 반환
  6574. */
  6575. _findSingleNode : function(oNode){
  6576. if(!oNode){
  6577. return null;
  6578. }
  6579. if(oNode.parentNode.childNodes.length === 1){
  6580. return this._findSingleNode(oNode.parentNode);
  6581. }else{
  6582. return oNode;
  6583. }
  6584. },
  6585. $AFTER_EXECCOMMAND : function(sCommand, bUserInterface, vValue, htOptions){
  6586. if(this.elP1 && this.elP1.parentNode){
  6587. this.elP1.parentNode.removeChild(this.elP1);
  6588. }
  6589. if(this.elP2 && this.elP2.parentNode){
  6590. this.elP2.parentNode.removeChild(this.elP2);
  6591. }
  6592. if(/^insertorderedlist|insertunorderedlist$/i.test(sCommand)){
  6593. // this._fixDocumentBR(); // Chrome/Safari
  6594. // [SMARTEDITORSUS-985][SMARTEDITORSUS-1740]
  6595. this._removeDummyParagraph_IE();
  6596. // --[SMARTEDITORSUS-985][SMARTEDITORSUS-1740]
  6597. this._fixCorruptedBlockQuote(sCommand === "insertorderedlist" ? "OL" : "UL"); // IE
  6598. // [SMARTEDITORSUS-1795] 갤럭시노트_Android4.1.2 기본브라우저일 경우 내부에 생성된 BLOCKQUOTE 제거
  6599. if(this.oNavigator.bGalaxyBrowser){
  6600. this._removeBlockQuote();
  6601. }
  6602. }
  6603. if((/^justify*/i.test(sCommand))){
  6604. this._fixAlign(sCommand === "justifyfull" ? "justify" : sCommand.substring(7));
  6605. }
  6606. if(sCommand == "indent" || sCommand == "outdent"){
  6607. if(!htOptions){htOptions = {};}
  6608. htOptions["bDontAddUndoHistory"] = true;
  6609. }
  6610. if((!htOptions || !htOptions["bDontAddUndoHistory"]) && !this._bOnlyCursorChanged){
  6611. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", [sCommand, this.oUndoOption]);
  6612. }
  6613. this.oApp.exec("CHECK_STYLE_CHANGE", []);
  6614. },
  6615. /**
  6616. * [SMARTEDITORSUS-704][SMARTEDITORSUS-2050] Element에 적용된 align 제거
  6617. * @param String sTagName 대상 element의 tagName
  6618. */
  6619. _removeElementAlign : function(sTagName){
  6620. var oSelection = this.oApp.getSelection(),
  6621. aNodes = oSelection.getNodes(),
  6622. elNode = null,
  6623. rxTagName = new RegExp('^' + sTagName + '$', 'i');
  6624. for(var i=0, nLen=aNodes.length; i<nLen; i++){
  6625. elNode = aNodes[i];
  6626. if(elNode.tagName && rxTagName.test(elNode.tagName)){
  6627. elNode.style.textAlign = "";
  6628. elNode.removeAttribute("align");
  6629. }
  6630. }
  6631. },
  6632. // [SMARTEDITORSUS-851] align, text-align을 fix해야 할 대상 노드를 찾음
  6633. _getAlignNode : function(elNode){
  6634. if(elNode.tagName && (elNode.tagName === "P" || elNode.tagName === "DIV")){
  6635. return elNode;
  6636. }
  6637. elNode = elNode.parentNode;
  6638. while(elNode && elNode.tagName){
  6639. if(elNode.tagName === "P" || elNode.tagName === "DIV"){
  6640. return elNode;
  6641. }
  6642. elNode = elNode.parentNode;
  6643. }
  6644. },
  6645. _fixAlign : function(sAlign){
  6646. var oSelection = this.oApp.getSelection(),
  6647. aNodes = [],
  6648. elNode = null,
  6649. elParentNode = null;
  6650. var removeTableAlign = !this.oNavigator.ie ? function(){} : function(elNode){
  6651. if(elNode.tagName && elNode.tagName === "TABLE"){
  6652. elNode.removeAttribute("align");
  6653. return true;
  6654. }
  6655. return false;
  6656. };
  6657. if(oSelection.collapsed){
  6658. aNodes[0] = oSelection.startContainer; // collapsed인 경우에는 getNodes의 결과는 []
  6659. }else{
  6660. aNodes = oSelection.getNodes();
  6661. }
  6662. for(var i=0, nLen=aNodes.length; i<nLen; i++){
  6663. elNode = aNodes[i];
  6664. if(elNode.nodeType === 3){
  6665. elNode = elNode.parentNode;
  6666. }
  6667. if(elParentNode && (elNode === elParentNode || jindo.$Element(elNode).isChildOf(elParentNode))){
  6668. continue;
  6669. }
  6670. elParentNode = this._getAlignNode(elNode);
  6671. if(elParentNode && elParentNode.align !== elParentNode.style.textAlign){ // [SMARTEDITORSUS-704] align 속성과 text-align 속성의 값을 맞춰줌
  6672. elParentNode.style.textAlign = sAlign;
  6673. elParentNode.setAttribute("align", sAlign);
  6674. }
  6675. }
  6676. },
  6677. _getDocumentBR : function(){
  6678. var i, nLen;
  6679. // [COM-715] <Chrome/Safari> 요약글 삽입 > 더보기 영역에서 기호매기기, 번호매기기 설정할때마다 요약글 박스가 아래로 이동됨
  6680. // ExecCommand를 처리하기 전에 현재의 BR을 저장
  6681. this.aBRs = this.oApp.getWYSIWYGDocument().getElementsByTagName("BR");
  6682. this.aBeforeBRs = [];
  6683. for(i=0, nLen=this.aBRs.length; i<nLen; i++){
  6684. this.aBeforeBRs[i] = this.aBRs[i];
  6685. }
  6686. },
  6687. _fixDocumentBR : function(){
  6688. // [COM-715] ExecCommand가 처리된 후에 업데이트된 BR을 처리 전에 저장한 BR과 비교하여 생성된 BR을 제거
  6689. if(this.aBeforeBRs.length === this.aBRs.length){ // this.aBRs gets updated automatically when the document is updated
  6690. return;
  6691. }
  6692. var waBeforeBRs = jindo.$A(this.aBeforeBRs),
  6693. i, iLen = this.aBRs.length;
  6694. for(i=iLen-1; i>=0; i--){
  6695. if(waBeforeBRs.indexOf(this.aBRs[i])<0){
  6696. this.aBRs[i].parentNode.removeChild(this.aBRs[i]);
  6697. }
  6698. }
  6699. },
  6700. _setBlockExecCommand : function(sCommand, bUserInterface, vValue){
  6701. var aNodes, aChildrenNode, htSelectedTDs = {};
  6702. this.oSelection = this.oApp.getSelection();
  6703. this.oApp.exec("GET_SELECTED_TD_BLOCK",['aTdCells',htSelectedTDs]);
  6704. aNodes = htSelectedTDs.aTdCells;
  6705. for( var j = 0; j < aNodes.length ; j++){
  6706. this.oSelection.selectNodeContents(aNodes[j]);
  6707. this.oSelection.select();
  6708. if(this.oNavigator.firefox){
  6709. this.oEditingArea.execCommand("styleWithCSS", bUserInterface, false); //styleWithCSS는 ff전용임.
  6710. }
  6711. aChildrenNode = this.oSelection.getNodes();
  6712. for( var k = 0; k < aChildrenNode.length ; k++ ) {
  6713. if(aChildrenNode[k].tagName == "UL" || aChildrenNode[k].tagName == "OL" ){
  6714. jindo.$Element(aChildrenNode[k]).css("color",vValue);
  6715. }
  6716. }
  6717. this.oEditingArea.execCommand(sCommand, bUserInterface, vValue);
  6718. }
  6719. },
  6720. _indentMargin : function(elDiv){
  6721. var elTmp = elDiv,
  6722. aAppend, i, nLen, elInsertTarget, elDeleteTarget, nCurMarginLeft;
  6723. while(elTmp){
  6724. if(elTmp.tagName && elTmp.tagName === "LI"){
  6725. elDiv = elTmp;
  6726. break;
  6727. }
  6728. elTmp = elTmp.parentNode;
  6729. }
  6730. if(elDiv.tagName === "LI"){
  6731. //<OL>
  6732. // <OL>
  6733. // <LI>22</LI>
  6734. // </OL>
  6735. // <LI>33</LI>
  6736. //</OL>
  6737. //와 같은 형태라면 33을 들여쓰기 했을 때, 상단의 silbling OL과 합쳐서 아래와 같이 만들어 줌.
  6738. //<OL>
  6739. // <OL>
  6740. // <LI>22</LI>
  6741. // <LI>33</LI>
  6742. // </OL>
  6743. //</OL>
  6744. if(elDiv.previousSibling && elDiv.previousSibling.tagName && elDiv.previousSibling.tagName === elDiv.parentNode.tagName){
  6745. // 하단에 또다른 OL이 있어 아래와 같은 형태라면,
  6746. //<OL>
  6747. // <OL>
  6748. // <LI>22</LI>
  6749. // </OL>
  6750. // <LI>33</LI>
  6751. // <OL>
  6752. // <LI>44</LI>
  6753. // </OL>
  6754. //</OL>
  6755. //22,33,44를 합쳐서 아래와 같이 만들어 줌.
  6756. //<OL>
  6757. // <OL>
  6758. // <LI>22</LI>
  6759. // <LI>33</LI>
  6760. // <LI>44</LI>
  6761. // </OL>
  6762. //</OL>
  6763. if(elDiv.nextSibling && elDiv.nextSibling.tagName && elDiv.nextSibling.tagName === elDiv.parentNode.tagName){
  6764. aAppend = [elDiv];
  6765. for(i=0, nLen=elDiv.nextSibling.childNodes.length; i<nLen; i++){
  6766. aAppend.push(elDiv.nextSibling.childNodes[i]);
  6767. }
  6768. elInsertTarget = elDiv.previousSibling;
  6769. elDeleteTarget = elDiv.nextSibling;
  6770. for(i=0, nLen=aAppend.length; i<nLen; i++){
  6771. elInsertTarget.insertBefore(aAppend[i], null);
  6772. }
  6773. elDeleteTarget.parentNode.removeChild(elDeleteTarget);
  6774. }else{
  6775. elDiv.previousSibling.insertBefore(elDiv, null);
  6776. }
  6777. return;
  6778. }
  6779. //<OL>
  6780. // <LI>22</LI>
  6781. // <OL>
  6782. // <LI>33</LI>
  6783. // </OL>
  6784. //</OL>
  6785. //와 같은 형태라면 22을 들여쓰기 했을 때, 하단의 silbling OL과 합친다.
  6786. if(elDiv.nextSibling && elDiv.nextSibling.tagName && elDiv.nextSibling.tagName === elDiv.parentNode.tagName){
  6787. elDiv.nextSibling.insertBefore(elDiv, elDiv.nextSibling.firstChild);
  6788. return;
  6789. }
  6790. elTmp = elDiv.parentNode.cloneNode(false);
  6791. elDiv.parentNode.insertBefore(elTmp, elDiv);
  6792. elTmp.appendChild(elDiv);
  6793. return;
  6794. }
  6795. nCurMarginLeft = parseInt(elDiv.style.marginLeft, 10);
  6796. if(!nCurMarginLeft){
  6797. nCurMarginLeft = 0;
  6798. }
  6799. nCurMarginLeft += this.nIndentSpacing;
  6800. elDiv.style.marginLeft = nCurMarginLeft+"px";
  6801. },
  6802. _outdentMargin : function(elDiv){
  6803. var elTmp = elDiv,
  6804. elParentNode, elInsertBefore, elNewParent, elInsertParent, oDoc, nCurMarginLeft;
  6805. while(elTmp){
  6806. if(elTmp.tagName && elTmp.tagName === "LI"){
  6807. elDiv = elTmp;
  6808. break;
  6809. }
  6810. elTmp = elTmp.parentNode;
  6811. }
  6812. if(elDiv.tagName === "LI"){
  6813. elParentNode = elDiv.parentNode;
  6814. elInsertBefore = elDiv.parentNode;
  6815. // LI를 적절 위치로 이동.
  6816. // 위에 다른 li/ol/ul가 있는가?
  6817. if(elDiv.previousSibling && elDiv.previousSibling.tagName && elDiv.previousSibling.tagName.match(/LI|UL|OL/)){
  6818. // 위아래로 sibling li/ol/ul가 있다면 ol/ul를 2개로 나누어야됨
  6819. if(elDiv.nextSibling && elDiv.nextSibling.tagName && elDiv.nextSibling.tagName.match(/LI|UL|OL/)){
  6820. elNewParent = elParentNode.cloneNode(false);
  6821. while(elDiv.nextSibling){
  6822. elNewParent.insertBefore(elDiv.nextSibling, null);
  6823. }
  6824. elParentNode.parentNode.insertBefore(elNewParent, elParentNode.nextSibling);
  6825. elInsertBefore = elNewParent;
  6826. // 현재 LI가 마지막 LI라면 부모 OL/UL 하단에 삽입
  6827. }else{
  6828. elInsertBefore = elParentNode.nextSibling;
  6829. }
  6830. }
  6831. elParentNode.parentNode.insertBefore(elDiv, elInsertBefore);
  6832. // 내어쓰기 한 LI 외에 다른 LI가 존재 하지 않을 경우 부모 노드 지워줌
  6833. if(!elParentNode.innerHTML.match(/LI/i)){
  6834. elParentNode.parentNode.removeChild(elParentNode);
  6835. }
  6836. // OL이나 UL 위로까지 내어쓰기가 된 상태라면 LI를 벗겨냄
  6837. if(!elDiv.parentNode.tagName.match(/OL|UL/)){
  6838. elInsertParent = elDiv.parentNode;
  6839. elInsertBefore = elDiv;
  6840. // 내용물을 P로 감싸기
  6841. oDoc = this.oApp.getWYSIWYGDocument();
  6842. elInsertParent = oDoc.createElement("P");
  6843. elInsertBefore = null;
  6844. elDiv.parentNode.insertBefore(elInsertParent, elDiv);
  6845. while(elDiv.firstChild){
  6846. elInsertParent.insertBefore(elDiv.firstChild, elInsertBefore);
  6847. }
  6848. elDiv.parentNode.removeChild(elDiv);
  6849. }
  6850. return;
  6851. }
  6852. nCurMarginLeft = parseInt(elDiv.style.marginLeft, 10);
  6853. if(!nCurMarginLeft){
  6854. nCurMarginLeft = 0;
  6855. }
  6856. nCurMarginLeft -= this.nIndentSpacing;
  6857. if(nCurMarginLeft < 0){
  6858. nCurMarginLeft = 0;
  6859. }
  6860. elDiv.style.marginLeft = nCurMarginLeft+"px";
  6861. },
  6862. // Fix IE's execcommand bug
  6863. // When insertorderedlist/insertunorderedlist is executed on a blockquote, the blockquote will "suck in" directly neighboring OL, UL's if there's any.
  6864. // To prevent this, insert empty P tags right before and after the blockquote and remove them after the execution.
  6865. // [SMARTEDITORSUS-793] Chrome 에서 동일한 이슈 발생, Chrome 은 빈 P 태그로는 처리되지 않으 &nbsp; 추가
  6866. // [SMARTEDITORSUS-1857] 인용구내에 UL/OL이 있고 바깥에서 UL/OL을 실행하는 경우도 동일한 문제가 발생하여 동일한 방식으로 해결하도록 해당 케이스 추가
  6867. _insertBlankLine : function(){
  6868. var oSelection = this.oApp.getSelection();
  6869. var elNode = oSelection.commonAncestorContainer;
  6870. this.elP1 = null;
  6871. this.elP2 = null;
  6872. // [SMARTEDITORSUS-793] 인용구 안에서 글머리기호/번호매기기하는 경우에 대한 처리
  6873. while(elNode){
  6874. if(elNode.tagName == "BLOCKQUOTE"){
  6875. this.elP1 = jindo.$("<p>&nbsp;</p>", this.oApp.getWYSIWYGDocument());
  6876. elNode.parentNode.insertBefore(this.elP1, elNode);
  6877. this.elP2 = jindo.$("<p>&nbsp;</p>", this.oApp.getWYSIWYGDocument());
  6878. elNode.parentNode.insertBefore(this.elP2, elNode.nextSibling);
  6879. break;
  6880. }
  6881. elNode = elNode.parentNode;
  6882. }
  6883. // [SMARTEDITORSUS-1857] 인용구 바깥에서 글머리기호/번호매기기하는 경우에 대한 처리
  6884. if(!this.elP1 && !this.elP2){
  6885. elNode = oSelection.commonAncestorContainer;
  6886. elNode = (elNode.nodeType !== 1) ? elNode.parentNode : elNode;
  6887. var elPrev = elNode.previousSibling,
  6888. elNext = elNode.nextSibling;
  6889. if(elPrev && elPrev.tagName === "BLOCKQUOTE"){
  6890. this.elP1 = jindo.$("<p>&nbsp;</p>", this.oApp.getWYSIWYGDocument());
  6891. elPrev.parentNode.insertBefore(this.elP1, elPrev.nextSibling);
  6892. }
  6893. if(elNext && elNext.tagName === "BLOCKQUOTE"){
  6894. this.elP1 = jindo.$("<p>&nbsp;</p>", this.oApp.getWYSIWYGDocument());
  6895. elNext.parentNode.insertBefore(this.elP1, elNext);
  6896. }
  6897. }
  6898. },
  6899. // Fix IE's execcommand bug
  6900. // When insertorderedlist/insertunorderedlist is executed on a blockquote with all the child nodes selected,
  6901. // eg:<blockquote>[selection starts here]blah...[selection ends here]</blockquote>
  6902. // , IE will change the blockquote with the list tag and create <OL><OL><LI>blah...</LI></OL></OL>.
  6903. // (two OL's or two UL's depending on which command was executed)
  6904. //
  6905. // It can also happen when the cursor is located at bogus positions like
  6906. // * below blockquote when the blockquote is the last element in the document
  6907. //
  6908. // [IE] 인용구 안에서 글머리 기호를 적용했을 때, 인용구 밖에 적용된 번호매기기/글머리 기호가 인용구 안으로 빨려 들어가는 문제 처리
  6909. _fixCorruptedBlockQuote : function(sTagName){
  6910. var aNodes = this.oApp.getWYSIWYGDocument().getElementsByTagName(sTagName),
  6911. elCorruptedBlockQuote, elTmpParent, elNewNode, aLists,
  6912. i, nLen, nPos, el, oSelection;
  6913. for(i=0, nLen=aNodes.length; i<nLen; i++){
  6914. if(aNodes[i].firstChild && aNodes[i].firstChild.tagName == sTagName){
  6915. elCorruptedBlockQuote = aNodes[i];
  6916. break;
  6917. }
  6918. }
  6919. if(!elCorruptedBlockQuote){return;}
  6920. elTmpParent = elCorruptedBlockQuote.parentNode;
  6921. // (1) changing outerHTML will cause loss of the reference to the node, so remember the idx position here
  6922. nPos = this._getPosIdx(elCorruptedBlockQuote);
  6923. el = this.oApp.getWYSIWYGDocument().createElement("DIV");
  6924. el.innerHTML = elCorruptedBlockQuote.outerHTML.replace("<"+sTagName, "<BLOCKQUOTE");
  6925. elCorruptedBlockQuote.parentNode.insertBefore(el.firstChild, elCorruptedBlockQuote);
  6926. elCorruptedBlockQuote.parentNode.removeChild(elCorruptedBlockQuote);
  6927. // (2) and retrieve the new node here
  6928. elNewNode = elTmpParent.childNodes[nPos];
  6929. // garbage <OL></OL> or <UL></UL> will be left over after setting the outerHTML, so remove it here.
  6930. aLists = elNewNode.getElementsByTagName(sTagName);
  6931. for(i=0, nLen=aLists.length; i<nLen; i++){
  6932. if(aLists[i].childNodes.length<1){
  6933. aLists[i].parentNode.removeChild(aLists[i]);
  6934. }
  6935. }
  6936. oSelection = this.oApp.getEmptySelection();
  6937. oSelection.selectNodeContents(elNewNode);
  6938. oSelection.collapseToEnd();
  6939. oSelection.select();
  6940. },
  6941. /**
  6942. * [SMARTEDITORSUS-1795] UL/OL 삽입시 LI 하위에 BLOCKQUOTE 있으면 제거한다.
  6943. * <blockquote><p><ul><li><span class="Apple-style-span"><blockquote><p style="display: inline !important;">선택영역</p></blockquote></span></li></ul></p><blockquote>
  6944. * 삭제될때도 복사됨
  6945. * <blockquote><p><span class="Apple-style-span"><blockquote><p style="display: inline !important;">선택영역</p></blockquote></span></p><blockquote>
  6946. */
  6947. _removeBlockQuote : function(){
  6948. var sVendorSpanClass = "Apple-style-span",
  6949. elVendorSpan,
  6950. aelVendorSpanDummy,
  6951. oSelection = this.oApp.getSelection(),
  6952. elNode = oSelection.commonAncestorContainer,
  6953. elChild = elNode,
  6954. elLi;
  6955. // LI 와 SPAN.Apple-style-span 를 찾는다.
  6956. while(elNode){
  6957. if(elNode.tagName === "LI"){
  6958. elLi = elNode;
  6959. elNode = (elNode.style.cssText === "display: inline !important; ") ? elNode.parentNode : null;
  6960. }else if(elNode.tagName === "SPAN" && elNode.className === sVendorSpanClass){
  6961. elVendorSpan = elNode;
  6962. elNode = (!elLi) ? elNode.parentNode : null;
  6963. }else{
  6964. elNode = elNode.parentNode;
  6965. }
  6966. }
  6967. // SPAN.Apple-style-span 을 selection 된 텍스트로 교체한 후 다시 selection을 준다.
  6968. if(elLi && elVendorSpan){
  6969. elNode = elVendorSpan.parentNode;
  6970. elNode.replaceChild(elChild, elVendorSpan);
  6971. oSelection.selectNodeContents(elNode);
  6972. oSelection.collapseToEnd();
  6973. oSelection.select();
  6974. }
  6975. // BLOCKQUOTE 내에 남아있는 SPAN.Apple-style-span 을 제거한다.(UL과 OL 교체시 남게되는 더미 SPAN 제거용)
  6976. while(elNode){
  6977. if(elNode.tagName === "BLOCKQUOTE"){
  6978. aelVendorSpanDummy = elNode.getElementsByClassName(sVendorSpanClass);
  6979. for(var i = 0;(elVendorSpan = aelVendorSpanDummy[i]); i++){
  6980. elVendorSpan.parentNode.removeChild(elVendorSpan);
  6981. }
  6982. elNode = null;
  6983. }else{
  6984. elNode = elNode.parentNode;
  6985. }
  6986. }
  6987. },
  6988. _getPosIdx : function(refNode){
  6989. var idx = 0;
  6990. for(var node = refNode.previousSibling; node; node = node.previousSibling){idx++;}
  6991. return idx;
  6992. },
  6993. _countClickCr : function(sCommand) {
  6994. if (!sCommand.match(this.rxClickCr)) {
  6995. return;
  6996. }
  6997. this.oApp.exec('MSG_NOTIFY_CLICKCR', [sCommand.replace(/^insert/i, '')]);
  6998. },
  6999. _extendBlock : function(){
  7000. // [SMARTEDITORSUS-663] [FF] block단위로 확장하여 Range를 새로 지정해주는것이 원래 스펙이므로
  7001. // 해결을 위해서는 현재 선택된 부분을 Block으로 extend하여 execCommand API가 처리될 수 있도록 함
  7002. var oSelection = this.oApp.getSelection(),
  7003. oStartContainer = oSelection.startContainer,
  7004. oEndContainer = oSelection.endContainer,
  7005. aChildImg = [],
  7006. aSelectedImg = [],
  7007. oSelectionClone = oSelection.cloneRange();
  7008. // <p><img><br/><img><br/><img></p> 일 때 이미지가 일부만 선택되면 발생
  7009. // - container 노드는 P 이고 container 노드의 자식노드 중 이미지가 여러개인데 선택된 이미지가 그 중 일부인 경우
  7010. if(!(oStartContainer === oEndContainer && oStartContainer.nodeType === 1 && oStartContainer.tagName === "P")){
  7011. return;
  7012. }
  7013. aChildImg = jindo.$A(oStartContainer.childNodes).filter(function(value, index, array){
  7014. return (value.nodeType === 1 && value.tagName === "IMG");
  7015. }).$value();
  7016. aSelectedImg = jindo.$A(oSelection.getNodes()).filter(function(value, index, array){
  7017. return (value.nodeType === 1 && value.tagName === "IMG");
  7018. }).$value();
  7019. if(aChildImg.length <= aSelectedImg.length){
  7020. return;
  7021. }
  7022. oSelection.selectNode(oStartContainer);
  7023. oSelection.select();
  7024. return oSelectionClone;
  7025. }
  7026. });
  7027. //}
  7028. //{
  7029. /**
  7030. * @fileOverview This file contains Husky plugin that takes care of the operations related to styling the font
  7031. * @name hp_SE_WYSIWYGStyler.js
  7032. * @required SE_EditingArea_WYSIWYG, HuskyRangeManager
  7033. */
  7034. nhn.husky.SE_WYSIWYGStyler = jindo.$Class({
  7035. name : "SE_WYSIWYGStyler",
  7036. _sCursorHolder : "\uFEFF",
  7037. $init : function(){
  7038. var htBrowser = jindo.$Agent().navigator();
  7039. if(htBrowser.ie && htBrowser.version > 8){
  7040. // [SMARTEDITORSUS-178] ZWNBSP(\uFEFF) 를 사용하면 IE9 이상의 경우 높이값을 갖지 못해 커서위치가 이상함
  7041. // [SMARTEDITORSUS-1704] ZWSP(\u200B) 를 사용할 경우 줄바꿈이 됨
  7042. // 기본적으로 \uFEFF 를 사용하고 IE9 이상만 \u2060 사용 (\u2060 은 \uFEFF 와 동일한 역할을 하지만 크롬에서는 깨짐)
  7043. // *주의* 작성자가 IE9이상에서 작성하고 독자가 크롬에서 볼 경우 \u2060 가 깨진 문자로 보여질 수 있기 때문에 컨버터를 통해 \u2060 를 \uFEFF 로 변환한다.
  7044. // FIXME: 단, \u2060 를 \uFEFF 변환으로 인해 SPAN태그만 들어있는 상태에서 모드를 변환하면 커서 위치가 다시 이상해질 수 있음
  7045. // 참고:
  7046. // http://en.wikipedia.org/wiki/Universal_Character_Set_characters#Word_joiners_and_separators
  7047. // http://en.wikipedia.org/wiki/Zero-width_no-break_space
  7048. // https://www.cs.tut.fi/~jkorpela/chars/spaces.html
  7049. this._sCursorHolder = "\u2060";
  7050. this.$ON_REGISTER_CONVERTERS = function(){
  7051. var rx2060 = /\u2060/g;
  7052. this.oApp.exec("ADD_CONVERTER", ["WYSIWYG_TO_IR", jindo.$Fn(function(sContents){
  7053. return sContents.replace(rx2060, "\uFEFF");
  7054. }, this).bind()]);
  7055. };
  7056. }
  7057. },
  7058. $PRECONDITION : function(sFullCommand, aArgs){
  7059. return (this.oApp.getEditingMode() == "WYSIWYG");
  7060. },
  7061. $ON_SET_WYSIWYG_STYLE : function(oStyles){
  7062. var oSelection = this.oApp.getSelection();
  7063. var htSelectedTDs = {};
  7064. this.oApp.exec("IS_SELECTED_TD_BLOCK",['bIsSelectedTd',htSelectedTDs]);
  7065. var bSelectedBlock = htSelectedTDs.bIsSelectedTd;
  7066. // style cursor or !(selected block)
  7067. if(oSelection.collapsed && !bSelectedBlock){
  7068. this.oApp.exec("RECORD_UNDO_ACTION", ["FONT STYLE", {bMustBlockElement : true}]);
  7069. var oSpan, bNewSpan = false;
  7070. var elCAC = oSelection.commonAncestorContainer;
  7071. //var elCAC = nhn.CurrentSelection.getCommonAncestorContainer();
  7072. if(elCAC.nodeType == 3){
  7073. elCAC = elCAC.parentNode;
  7074. }
  7075. // [SMARTEDITORSUS-1648] SPAN > 굵게/밑줄/기울림/취소선이 있는 경우, 상위 SPAN을 찾는다.
  7076. if(elCAC && oSelection._rxCursorHolder.test(elCAC.innerHTML)){
  7077. oSpan = oSelection._findParentSingleSpan(elCAC);
  7078. }
  7079. // 스타일을 적용할 SPAN이 없으면 새로 생성
  7080. if(!oSpan){
  7081. oSpan = this.oApp.getWYSIWYGDocument().createElement("SPAN");
  7082. oSpan.innerHTML = this._sCursorHolder;
  7083. bNewSpan = true;
  7084. }else if(oSpan.innerHTML == ""){ // 내용이 아예 없으면 크롬에서 커서가 위치하지 못함
  7085. oSpan.innerHTML = this._sCursorHolder;
  7086. }
  7087. var sValue;
  7088. for(var sName in oStyles){
  7089. sValue = oStyles[sName];
  7090. if(typeof sValue != "string"){
  7091. continue;
  7092. }
  7093. oSpan.style[sName] = sValue;
  7094. }
  7095. if(bNewSpan){
  7096. if(oSelection.startContainer.tagName == "BODY" && oSelection.startOffset === 0){
  7097. var oVeryFirstNode = oSelection._getVeryFirstRealChild(this.oApp.getWYSIWYGDocument().body);
  7098. var bAppendable = true;
  7099. var elTmp = oVeryFirstNode.cloneNode(false);
  7100. // some browsers may throw an exception for trying to set the innerHTML of BR/IMG tags
  7101. try{
  7102. elTmp.innerHTML = "test";
  7103. if(elTmp.innerHTML != "test"){
  7104. bAppendable = false;
  7105. }
  7106. }catch(e){
  7107. bAppendable = false;
  7108. }
  7109. if(bAppendable && elTmp.nodeType == 1 && elTmp.tagName == "BR"){// [SMARTEDITORSUS-311] [FF4] Cursor Holder 인 BR 의 하위노드로 SPAN 을 추가하여 발생하는 문제
  7110. oSelection.selectNode(oVeryFirstNode);
  7111. oSelection.collapseToStart();
  7112. oSelection.insertNode(oSpan);
  7113. }else if(bAppendable && oVeryFirstNode.tagName != "IFRAME" && oVeryFirstNode.appendChild && typeof oVeryFirstNode.innerHTML == "string"){
  7114. oVeryFirstNode.appendChild(oSpan);
  7115. }else{
  7116. oSelection.selectNode(oVeryFirstNode);
  7117. oSelection.collapseToStart();
  7118. oSelection.insertNode(oSpan);
  7119. }
  7120. }else{
  7121. oSelection.collapseToStart();
  7122. oSelection.insertNode(oSpan);
  7123. }
  7124. }else{
  7125. oSelection = this.oApp.getEmptySelection();
  7126. }
  7127. // [SMARTEDITORSUS-229] 새로 생성되는 SPAN 에도 취소선/밑줄 처리 추가
  7128. if(!!oStyles.color){
  7129. oSelection._checkTextDecoration(oSpan);
  7130. }
  7131. // [SMARTEDITORSUS-1648] oSpan이 굵게//밑줄/기울임/취소선태그보다 상위인 경우, IE에서 굵게//밑줄/기울임/취소선태그 밖으로 나가게 된다. 때문에 SPAN을 새로 만든 경우 oSpan을, 그렇지 않은 경우 elCAC를 잡는다.
  7132. oSelection.selectNodeContents(bNewSpan?oSpan:elCAC);
  7133. oSelection.collapseToEnd();
  7134. // TODO: focus 는 왜 있는 것일까? => IE에서 style 적용후 포커스가 날아가서 글작성이 안됨???
  7135. oSelection._window.focus();
  7136. oSelection._window.document.body.focus();
  7137. oSelection.select();
  7138. // 영역으로 스타일이 잡혀 있는 경우(예:현재 커서가 B블럭 안에 존재) 해당 영역이 사라져 버리는 오류 발생해서 제거
  7139. // http://bts.nhncorp.com/nhnbts/browse/COM-912
  7140. /*
  7141. var oCursorStyle = this.oApp.getCurrentStyle();
  7142. if(oCursorStyle.bold == "@^"){
  7143. this.oApp.delayedExec("EXECCOMMAND", ["bold"], 0);
  7144. }
  7145. if(oCursorStyle.underline == "@^"){
  7146. this.oApp.delayedExec("EXECCOMMAND", ["underline"], 0);
  7147. }
  7148. if(oCursorStyle.italic == "@^"){
  7149. this.oApp.delayedExec("EXECCOMMAND", ["italic"], 0);
  7150. }
  7151. if(oCursorStyle.lineThrough == "@^"){
  7152. this.oApp.delayedExec("EXECCOMMAND", ["strikethrough"], 0);
  7153. }
  7154. */
  7155. // FF3 will actually display %uFEFF when it is followed by a number AND certain font-family is used(like Gulim), so remove the character for FF3
  7156. //if(jindo.$Agent().navigator().firefox && jindo.$Agent().navigator().version == 3){
  7157. // FF4+ may have similar problems, so ignore the version number
  7158. // [SMARTEDITORSUS-416] 커서가 올라가지 않도록 BR 을 살려둠
  7159. // if(jindo.$Agent().navigator().firefox){
  7160. // oSpan.innerHTML = "";
  7161. // }
  7162. return;
  7163. }
  7164. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["FONT STYLE", {bMustBlockElement:true}]);
  7165. if(bSelectedBlock){
  7166. var aNodes;
  7167. this.oApp.exec("GET_SELECTED_TD_BLOCK",['aTdCells',htSelectedTDs]);
  7168. aNodes = htSelectedTDs.aTdCells;
  7169. for( var j = 0; j < aNodes.length ; j++){
  7170. oSelection.selectNodeContents(aNodes[j]);
  7171. oSelection.styleRange(oStyles);
  7172. oSelection.select();
  7173. }
  7174. } else {
  7175. var bCheckTextDecoration = !!oStyles.color; // [SMARTEDITORSUS-26] 취소선/밑줄 색상 적용 처리
  7176. var bIncludeLI = oStyles.fontSize || oStyles.fontFamily;
  7177. // [SMARTEDITORSUS-2237] IE11 에서 엑셀을 복사붙여넣기하면 유효하지 않은 위치(tbody, tr, td 사이)에 font 태그가 삽입된다.
  7178. // oSelection.styleRange 을 실행하면 유효하지 않은 위치의 태그들에 스타일지정용 span 이 삽입되어 테이블이 깨지게 된다.
  7179. // 때문에 styleRange 실행전에 잘못된 노드들을 제거해준다.
  7180. for(var i = 0, aNodes = oSelection.getNodes(), oNode;(oNode = aNodes[i]); i++){
  7181. nhn.husky.SE2M_Utils.removeInvalidNodeInTable(oNode);
  7182. }
  7183. oSelection.styleRange(oStyles, null, null, bIncludeLI, bCheckTextDecoration);
  7184. // http://bts.nhncorp.com/nhnbts/browse/COM-964
  7185. //
  7186. // In FF when,
  7187. // 1) Some text was wrapped with a styling SPAN and a bogus BR is followed
  7188. // eg: <span style="XXX">TEST</span><br>
  7189. // 2) And some place outside the span is clicked.
  7190. //
  7191. // The text cursor will be located outside the SPAN like the following,
  7192. // <span style="XXX">TEST</span>[CURSOR]<br>
  7193. //
  7194. // which is not what the user would expect
  7195. // Desired result: <span style="XXX">TEST[CURSOR]</span><br>
  7196. //
  7197. // To make the cursor go inside the styling SPAN, remove the bogus BR when the styling SPAN is created.
  7198. // -> Style TEST<br> as <span style="XXX">TEST</span> (remove unnecessary BR)
  7199. // -> Cannot monitor clicks/cursor position real-time so make the contents error-proof instead.
  7200. if(jindo.$Agent().navigator().firefox){
  7201. var aStyleParents = oSelection.aStyleParents;
  7202. for(var i=0, nLen=aStyleParents.length; i<nLen; i++){
  7203. var elNode = aStyleParents[i];
  7204. if(elNode.nextSibling && elNode.nextSibling.tagName == "BR" && !elNode.nextSibling.nextSibling){
  7205. elNode.parentNode.removeChild(elNode.nextSibling);
  7206. }
  7207. }
  7208. }
  7209. oSelection._window.focus();
  7210. oSelection.select();
  7211. }
  7212. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["FONT STYLE", {bMustBlockElement:true}]);
  7213. }
  7214. });
  7215. //}
  7216. //{
  7217. /**
  7218. * @fileOverview This file contains Husky plugin that takes care of the operations related to detecting the style change
  7219. * @name hp_SE_WYSIWYGStyleGetter.js
  7220. */
  7221. nhn.husky.SE_WYSIWYGStyleGetter = jindo.$Class({
  7222. name : "SE_WYSIWYGStyleGetter",
  7223. hKeyUp : null,
  7224. getStyleInterval : 200,
  7225. oStyleMap : {
  7226. fontFamily : {
  7227. type : "Value",
  7228. css : "fontFamily"
  7229. },
  7230. fontSize : {
  7231. type : "Value",
  7232. css : "fontSize"
  7233. },
  7234. lineHeight : {
  7235. type : "Value",
  7236. css : "lineHeight",
  7237. converter : function(sValue, oStyle){
  7238. if(!sValue.match(/px$/)){
  7239. return sValue;
  7240. }
  7241. return Math.ceil((parseInt(sValue, 10)/parseInt(oStyle.fontSize, 10))*10)/10;
  7242. }
  7243. },
  7244. bold : {
  7245. command : "bold"
  7246. },
  7247. underline : {
  7248. command : "underline"
  7249. },
  7250. italic : {
  7251. command : "italic"
  7252. },
  7253. lineThrough : {
  7254. command : "strikethrough"
  7255. },
  7256. superscript : {
  7257. command : "superscript"
  7258. },
  7259. subscript : {
  7260. command : "subscript"
  7261. },
  7262. justifyleft : {
  7263. command : "justifyleft"
  7264. },
  7265. justifycenter : {
  7266. command : "justifycenter"
  7267. },
  7268. justifyright : {
  7269. command : "justifyright"
  7270. },
  7271. justifyfull : {
  7272. command : "justifyfull"
  7273. },
  7274. orderedlist : {
  7275. command : "insertorderedlist"
  7276. },
  7277. unorderedlist : {
  7278. command : "insertunorderedlist"
  7279. }
  7280. },
  7281. $init : function(){
  7282. this.oStyle = this._getBlankStyle();
  7283. },
  7284. $LOCAL_BEFORE_ALL : function(){
  7285. return (this.oApp.getEditingMode() == "WYSIWYG");
  7286. },
  7287. $ON_MSG_APP_READY : function(){
  7288. this.oDocument = this.oApp.getWYSIWYGDocument();
  7289. this.oApp.exec("ADD_APP_PROPERTY", ["getCurrentStyle", jindo.$Fn(this.getCurrentStyle, this).bind()]);
  7290. if(jindo.$Agent().navigator().safari || jindo.$Agent().navigator().chrome || jindo.$Agent().navigator().ie){
  7291. this.oStyleMap.textAlign = {
  7292. type : "Value",
  7293. css : "textAlign"
  7294. };
  7295. }
  7296. },
  7297. $ON_EVENT_EDITING_AREA_MOUSEUP : function(oEvnet){
  7298. /*
  7299. if(this.hKeyUp){
  7300. clearTimeout(this.hKeyUp);
  7301. }
  7302. this.oApp.delayedExec("CHECK_STYLE_CHANGE", [], 100);
  7303. */
  7304. this.oApp.exec("CHECK_STYLE_CHANGE");
  7305. },
  7306. $ON_EVENT_EDITING_AREA_KEYPRESS : function(oEvent){
  7307. // ctrl+a in FF triggers keypress event with keyCode 97, other browsers don't throw keypress event for ctrl+a
  7308. var oKeyInfo;
  7309. if(this.oApp.oNavigator.firefox){
  7310. oKeyInfo = oEvent.key();
  7311. if(oKeyInfo.ctrl && oKeyInfo.keyCode == 97){
  7312. return;
  7313. }
  7314. }
  7315. if(this.bAllSelected){
  7316. this.bAllSelected = false;
  7317. return;
  7318. }
  7319. /*
  7320. // queryCommandState often fails to return correct result for Korean/Enter. So just ignore them.
  7321. if(this.oApp.oNavigator.firefox && (oKeyInfo.keyCode == 229 || oKeyInfo.keyCode == 13)){
  7322. return;
  7323. }
  7324. */
  7325. this.oApp.exec("CHECK_STYLE_CHANGE");
  7326. //this.oApp.delayedExec("CHECK_STYLE_CHANGE", [], 0);
  7327. },
  7328. $ON_EVENT_EDITING_AREA_KEYDOWN : function(oEvent){
  7329. var oKeyInfo = oEvent.key();
  7330. // ctrl+a
  7331. if((this.oApp.oNavigator.ie || this.oApp.oNavigator.firefox) && oKeyInfo.ctrl && oKeyInfo.keyCode == 65){
  7332. this.oApp.exec("RESET_STYLE_STATUS");
  7333. this.bAllSelected = true;
  7334. return;
  7335. }
  7336. /*
  7337. backspace 8
  7338. enter 13
  7339. page up 33
  7340. page down 34
  7341. end 35
  7342. home 36
  7343. left arrow 37
  7344. up arrow 38
  7345. right arrow 39
  7346. down arrow 40
  7347. insert 45
  7348. delete 46
  7349. */
  7350. // other key strokes are taken care by keypress event
  7351. if(!(oKeyInfo.keyCode == 8 || (oKeyInfo.keyCode >= 33 && oKeyInfo.keyCode <= 40) || oKeyInfo.keyCode == 45 || oKeyInfo.keyCode == 46)) return;
  7352. // [SMARTEDITORSUS-1841] IE11에서 테이블 첫번째 셀에서 shift+end 를 두번 실행하면 오류 발생
  7353. // ctrl+a 를 다루는 방식대로 RESET_STYLE_STATUS 를 수행하고 CHECK_STYLE_CHANGE 는 수행하지 않도록 처리
  7354. if(oKeyInfo.shift && oKeyInfo.keyCode === 35){
  7355. this.oApp.exec("RESET_STYLE_STATUS");
  7356. this.bAllSelected = true;
  7357. return;
  7358. }
  7359. // take care of ctrl+a -> delete/bksp sequence
  7360. if(this.bAllSelected){
  7361. // firefox will throw both keydown and keypress events for those input(keydown first), so let keypress take care of them
  7362. if(this.oApp.oNavigator.firefox){
  7363. return;
  7364. }
  7365. this.bAllSelected = false;
  7366. return;
  7367. }
  7368. this.oApp.exec("CHECK_STYLE_CHANGE");
  7369. },
  7370. $ON_CHECK_STYLE_CHANGE : function(){
  7371. this._getStyle();
  7372. },
  7373. $ON_RESET_STYLE_STATUS : function(){
  7374. this.oStyle = this._getBlankStyle();
  7375. var oBodyStyle = this._getStyleOf(this.oApp.getWYSIWYGDocument().body);
  7376. this.oStyle.fontFamily = oBodyStyle.fontFamily;
  7377. this.oStyle.fontSize = oBodyStyle.fontSize;
  7378. this.oStyle["justifyleft"]="@^";
  7379. for(var sAttributeName in this.oStyle){
  7380. //this.oApp.exec("SET_STYLE_STATUS", [sAttributeName, this.oStyle[sAttributeName]]);
  7381. this.oApp.exec("MSG_STYLE_CHANGED", [sAttributeName, this.oStyle[sAttributeName]]);
  7382. }
  7383. },
  7384. getCurrentStyle : function(){
  7385. return this.oStyle;
  7386. },
  7387. _check_style_change : function(){
  7388. this.oApp.exec("CHECK_STYLE_CHANGE", []);
  7389. },
  7390. _getBlankStyle : function(){
  7391. var oBlankStyle = {};
  7392. for(var attributeName in this.oStyleMap){
  7393. if(this.oStyleMap[attributeName].type == "Value"){
  7394. oBlankStyle[attributeName] = "";
  7395. }else{
  7396. oBlankStyle[attributeName] = 0;
  7397. }
  7398. }
  7399. return oBlankStyle;
  7400. },
  7401. _getStyle : function(){
  7402. var oStyle;
  7403. if(nhn.CurrentSelection.isCollapsed()){
  7404. oStyle = this._getStyleOf(nhn.CurrentSelection.getCommonAncestorContainer());
  7405. }else{
  7406. var oSelection = this.oApp.getSelection();
  7407. var funcFilter = function(oNode){
  7408. if (!oNode.childNodes || oNode.childNodes.length == 0)
  7409. return true;
  7410. else
  7411. return false;
  7412. }
  7413. var aBottomNodes = oSelection.getNodes(false, funcFilter);
  7414. if(aBottomNodes.length == 0){
  7415. oStyle = this._getStyleOf(oSelection.commonAncestorContainer);
  7416. }else{
  7417. oStyle = this._getStyleOf(aBottomNodes[0]);
  7418. }
  7419. }
  7420. for(attributeName in oStyle){
  7421. if(this.oStyleMap[attributeName].converter){
  7422. oStyle[attributeName] = this.oStyleMap[attributeName].converter(oStyle[attributeName], oStyle);
  7423. }
  7424. if(this.oStyle[attributeName] != oStyle[attributeName]){
  7425. /**
  7426. * [SMARTEDITORSUS-1803] 글꼴을 변경할 때는 글자크기 변경사항은 반영되지 않도록 - getComputedStyle() 버그
  7427. *
  7428. * 글꼴이나 글자 크기를 변경할 때마다,
  7429. * this.oApp.exec("CHECK_STYLE_CHANGE") 호출되는데,
  7430. * 대상 스타일 아니라 모든 요소의 변화를 확인하게 된다.
  7431. *
  7432. * 글꼴만 변경하는 경우에도
  7433. * getComputedStyle() 반올림 방식으로 인한 오차로 인해
  7434. * pt 단위의 글자크기가 px로 바뀌게 되는데,
  7435. *
  7436. * 스타일 변화 확인에는 jindo.$Element().css() 사용하는데,
  7437. * el.currentStyle - getComputedStyle(el) 순위로 존재여부를 확인하여 사용한다.
  7438. *
  7439. * getComputedStyle(el) 사용하는 경우,
  7440. * 대상 엘리먼트에 pt 단위의 값이 지정되어 있었다면
  7441. * 다음의 순서를 거친다.
  7442. * - pt 단위를 px 단위로 변환
  7443. * - 소수점 이하 값을 반올림
  7444. *
  7445. * 글자 크기의 경우 영향으로
  7446. * 산술적인 pt-px 변환이 아닌 값으로 변경되어
  7447. * 툴바에 노출되는 계산에 사용될 있다.
  7448. * */
  7449. if((typeof(document.body.currentStyle) != "object") && (typeof(getComputedStyle) == "function")){
  7450. if((attributeName == "fontSize") && (this.oStyle["fontFamily"] != oStyle["fontFamily"])){
  7451. continue;
  7452. }
  7453. }
  7454. // --[SMARTEDITORSUS-1803]
  7455. this.oApp.exec("MSG_STYLE_CHANGED", [attributeName, oStyle[attributeName]]);
  7456. }
  7457. }
  7458. this.oStyle = oStyle;
  7459. },
  7460. _getStyleOf : function(oNode){
  7461. var oStyle = this._getBlankStyle();
  7462. // this must not happen
  7463. if(!oNode){
  7464. return oStyle;
  7465. }
  7466. if( oNode.nodeType == 3 ){
  7467. oNode = oNode.parentNode;
  7468. }else if( oNode.nodeType == 9 ){
  7469. //document에는 css를 적용할 수 없음.
  7470. oNode = oNode.body;
  7471. }
  7472. var welNode = jindo.$Element(oNode);
  7473. var attribute, cssName;
  7474. for(var styleName in this.oStyle){
  7475. attribute = this.oStyleMap[styleName];
  7476. if(attribute.type && attribute.type == "Value"){
  7477. try{
  7478. if(attribute.css){
  7479. var sValue = welNode.css(attribute.css);
  7480. if(styleName == "fontFamily"){
  7481. sValue = sValue.split(/,/)[0];
  7482. }
  7483. oStyle[styleName] = sValue;
  7484. } else if(attribute.command){
  7485. oStyle[styleName] = this.oDocument.queryCommandState(attribute.command);
  7486. } else {
  7487. // todo
  7488. }
  7489. }catch(e){}
  7490. }else{
  7491. if(attribute.command){
  7492. try{
  7493. if(this.oDocument.queryCommandState(attribute.command)){
  7494. oStyle[styleName] = "@^";
  7495. }else{
  7496. oStyle[styleName] = "@-";
  7497. }
  7498. }catch(e){}
  7499. }else{
  7500. // todo
  7501. }
  7502. }
  7503. }
  7504. switch(oStyle["textAlign"]){
  7505. case "left":
  7506. oStyle["justifyleft"]="@^";
  7507. break;
  7508. case "center":
  7509. oStyle["justifycenter"]="@^";
  7510. break;
  7511. case "right":
  7512. oStyle["justifyright"]="@^";
  7513. break;
  7514. case "justify":
  7515. oStyle["justifyfull"]="@^";
  7516. break;
  7517. }
  7518. // IE에서는 기본 정렬이 queryCommandState로 넘어오지 않아서 정렬이 없다면, 왼쪽 정렬로 가정함
  7519. if(oStyle["justifyleft"]=="@-" && oStyle["justifycenter"]=="@-" && oStyle["justifyright"]=="@-" && oStyle["justifyfull"]=="@-"){oStyle["justifyleft"]="@^";}
  7520. return oStyle;
  7521. }
  7522. });
  7523. //}
  7524. //{
  7525. /**
  7526. * @fileOverview This file contains Husky plugin that takes care of the operations related to changing the font size using Select element
  7527. * @name SE2M_FontSizeWithLayerUI.js
  7528. */
  7529. nhn.husky.SE2M_FontSizeWithLayerUI = jindo.$Class({
  7530. name : "SE2M_FontSizeWithLayerUI",
  7531. $init : function(elAppContainer){
  7532. this._assignHTMLElements(elAppContainer);
  7533. },
  7534. _assignHTMLElements : function(elAppContainer){
  7535. //@ec
  7536. this.oDropdownLayer = jindo.$$.getSingle("DIV.husky_se_fontSize_layer", elAppContainer);
  7537. //@ec[
  7538. this.elFontSizeLabel = jindo.$$.getSingle("SPAN.husky_se2m_current_fontSize", elAppContainer);
  7539. this.aLIFontSizes = jindo.$A(jindo.$$("LI", this.oDropdownLayer)).filter(function(v,i,a){return (v.firstChild != null);})._array;
  7540. //@ec]
  7541. this.sDefaultText = this.elFontSizeLabel.innerHTML;
  7542. },
  7543. $ON_MSG_APP_READY : function(){
  7544. this.oApp.exec("REGISTER_UI_EVENT", ["fontSize", "click", "SE2M_TOGGLE_FONTSIZE_LAYER"]);
  7545. this.oApp.exec("SE2_ATTACH_HOVER_EVENTS", [this.aLIFontSizes]);
  7546. for(var i=0; i<this.aLIFontSizes.length; i++){
  7547. this.oApp.registerBrowserEvent(this.aLIFontSizes[i], "click", "SET_FONTSIZE", [this._getFontSizeFromLI(this.aLIFontSizes[i])]);
  7548. }
  7549. },
  7550. $ON_SE2M_TOGGLE_FONTSIZE_LAYER : function(){
  7551. this.oApp.exec("TOGGLE_TOOLBAR_ACTIVE_LAYER", [this.oDropdownLayer, null, "SELECT_UI", ["fontSize"], "DESELECT_UI", ["fontSize"]]);
  7552. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['size']);
  7553. },
  7554. _rxPX : /px$/i,
  7555. _rxPT : /pt$/i,
  7556. $ON_MSG_STYLE_CHANGED : function(sAttributeName, sAttributeValue){
  7557. if(sAttributeName == "fontSize"){
  7558. // [SMARTEDITORSUS-1600]
  7559. if(this._rxPX.test(sAttributeValue)){
  7560. // as-is
  7561. /*
  7562. if(sAttributeValue.match(/px$/)){
  7563. var num = parseFloat(sAttributeValue.replace("px", "")).toFixed(0);
  7564. if(this.mapPX2PT[num]){
  7565. sAttributeValue = this.mapPX2PT[num] + "pt";
  7566. }else{
  7567. if(sAttributeValue > 0){
  7568. sAttributeValue = num + "px";
  7569. }else{
  7570. sAttributeValue = this.sDefaultText;
  7571. }
  7572. }*/
  7573. /**
  7574. * Chrome의 경우,
  7575. * jindo.$Element().css()에서 대상 Element에 구하고자 하는 style 값이 명시되어 있지 않다면,
  7576. * 실제 수행되는 메서드는 window.getComputedStyle()이다.
  7577. *
  7578. * 메서드를 거치면 px 단위로 값을 가져오게 되는데,
  7579. * WYSIWYGDocument.body에 pt 단위로 값이 설정되어 있었다면
  7580. * px : pt = 72 : 96 비례에 의해
  7581. * 변환된 px 값을 획득하게 되며,
  7582. *
  7583. * 아래 parseFloat() 특성
  7584. * 소수점 16자리부터는 버려질 있으며,
  7585. *
  7586. * 경우 발생할 있는 오차는
  7587. * pt 기준으로 3.75E-16 pt이다.
  7588. *
  7589. * 0.5pt 크기로 구간을 설정하였기 때문에
  7590. * 오차는 설정에 지장을 주지 않는다.
  7591. *
  7592. * 위의 기존 방식은 계산을 거치지 않을 아니라,
  7593. * 소수점 첫째 자리부터 무조건 반올림하기 때문에
  7594. * 결과에 따라 0.375 pt의 오차가 발생할 있었다.
  7595. * */
  7596. var num = parseFloat(sAttributeValue.replace(this._rxPX, ""));
  7597. if(num > 0){
  7598. // px : pt = 72 : 96
  7599. sAttributeValue = num * 72 / 96 + "pt";
  7600. }else{
  7601. sAttributeValue = this.sDefaultText;
  7602. }
  7603. // --[SMARTEDITORSUS-1600]
  7604. }
  7605. // [SMARTEDITORSUS-1600]
  7606. // 산술 계산을 통해 일차적으로 pt로 변환된 값을 0.5pt 구간을 적용하여 보정하되, 보다 가까운 쪽으로 설정한다.
  7607. if(this._rxPT.test(sAttributeValue)){
  7608. var num = parseFloat(sAttributeValue.replace(this._rxPT, ""));
  7609. var integerPart = Math.floor(num); // 정수 부분
  7610. var decimalPart = num - integerPart; // 소수 부분
  7611. // 보정 기준은 소수 부분이며, 반올림 단위는 0.25pt
  7612. if(decimalPart >= 0 && decimalPart < 0.25){
  7613. num = integerPart + 0;
  7614. }else if(decimalPart >= 0.25 && decimalPart < 0.75){
  7615. num = integerPart + 0.5;
  7616. }else{
  7617. num = integerPart + 1;
  7618. }
  7619. // 보정된 pt
  7620. sAttributeValue = num + "pt";
  7621. }
  7622. // --[SMARTEDITORSUS-1600]
  7623. if(!sAttributeValue){
  7624. sAttributeValue = this.sDefaultText;
  7625. }
  7626. var elLi = this._getMatchingLI(sAttributeValue);
  7627. this._clearFontSizeSelection();
  7628. if(elLi){
  7629. this.elFontSizeLabel.innerHTML = sAttributeValue;
  7630. jindo.$Element(elLi).addClass("active");
  7631. }else{
  7632. this.elFontSizeLabel.innerHTML = sAttributeValue;
  7633. }
  7634. }
  7635. },
  7636. $ON_SET_FONTSIZE : function(sFontSize){
  7637. if(!sFontSize){return;}
  7638. this.oApp.exec("SET_WYSIWYG_STYLE", [{"fontSize":sFontSize}]);
  7639. this.oApp.exec("HIDE_ACTIVE_LAYER", []);
  7640. this.oApp.exec("CHECK_STYLE_CHANGE", []);
  7641. },
  7642. _getMatchingLI : function(sFontSize){
  7643. var elLi;
  7644. sFontSize = sFontSize.toLowerCase();
  7645. for(var i=0; i<this.aLIFontSizes.length; i++){
  7646. elLi = this.aLIFontSizes[i];
  7647. if(this._getFontSizeFromLI(elLi).toLowerCase() == sFontSize){return elLi;}
  7648. }
  7649. return null;
  7650. },
  7651. _getFontSizeFromLI : function(elLi){
  7652. return elLi.firstChild.firstChild.style.fontSize;
  7653. },
  7654. _clearFontSizeSelection : function(elLi){
  7655. for(var i=0; i<this.aLIFontSizes.length; i++){
  7656. jindo.$Element(this.aLIFontSizes[i]).removeClass("active");
  7657. }
  7658. }
  7659. });
  7660. //{
  7661. /**
  7662. * @fileOverview This file contains Husky plugin that takes care of the operations related to setting/changing the line style
  7663. * @name hp_SE_LineStyler.js
  7664. */
  7665. nhn.husky.SE2M_LineStyler = jindo.$Class({
  7666. name : "SE2M_LineStyler",
  7667. $BEFORE_MSG_APP_READY : function() {
  7668. this.oApp.exec("ADD_APP_PROPERTY", ["getLineStyle", jindo.$Fn(this.getLineStyle, this).bind()]);
  7669. },
  7670. $ON_SET_LINE_STYLE : function(sStyleName, styleValue, htOptions){
  7671. this.oSelection = this.oApp.getSelection();
  7672. var nodes = this._getSelectedNodes(false);
  7673. this.setLineStyle(sStyleName, styleValue, htOptions, nodes);
  7674. this.oApp.exec("CHECK_STYLE_CHANGE", []);
  7675. },
  7676. $ON_SET_LINE_BLOCK_STYLE : function(sStyleName, styleValue, htOptions){
  7677. this.oSelection = this.oApp.getSelection();
  7678. this.setLineBlockStyle(sStyleName, styleValue, htOptions);
  7679. this.oApp.exec("CHECK_STYLE_CHANGE", []);
  7680. },
  7681. /**
  7682. * SE2M_TableEditor 플러그인에 의해 선택된 TD를 SE2M_TableBlockStyler 플러그인을 통해 가져온다.
  7683. * 선택된 TD가 없으면 Empty Array 반환한다.
  7684. * @returns {Array} SE2M_TableEditor 플러그인에 의해 선택된 TD 요소 배열
  7685. */
  7686. _getSelectedTDs : function(){
  7687. var htSelectedTDs = {};
  7688. this.oApp.exec("GET_SELECTED_TD_BLOCK",['aTdCells',htSelectedTDs]);
  7689. return htSelectedTDs.aTdCells || [];
  7690. },
  7691. getLineStyle : function(sStyle){
  7692. var nodes = this._getSelectedNodes(false);
  7693. var curWrapper, prevWrapper;
  7694. var sCurStyle, sStyleValue;
  7695. if(nodes.length === 0){return null;}
  7696. var iLength = nodes.length;
  7697. if(iLength === 0){
  7698. sStyleValue = null;
  7699. }else{
  7700. prevWrapper = this._getLineWrapper(nodes[0]);
  7701. sStyleValue = this._getWrapperLineStyle(sStyle, prevWrapper);
  7702. }
  7703. var firstNode = this.oSelection.getStartNode();
  7704. if(sStyleValue != null){
  7705. for(var i=1; i<iLength; i++){
  7706. if(this._isChildOf(nodes[i], curWrapper)){continue;}
  7707. if(!nodes[i]){continue;}
  7708. curWrapper = this._getLineWrapper(nodes[i]);
  7709. if(curWrapper == prevWrapper){continue;}
  7710. sCurStyle = this._getWrapperLineStyle(sStyle, curWrapper);
  7711. if(sCurStyle != sStyleValue){
  7712. sStyleValue = null;
  7713. break;
  7714. }
  7715. prevWrapper = curWrapper;
  7716. }
  7717. }
  7718. curWrapper = this._getLineWrapper(nodes[iLength-1]);
  7719. var lastNode = this.oSelection.getEndNode();
  7720. setTimeout(jindo.$Fn(function(firstNode, lastNode){
  7721. // [SMARTEDITORSUS-1606] 테이블 셀 일부가 선택되었는지 확인
  7722. var aNodes = this._getSelectedTDs();
  7723. if(aNodes.length > 0){
  7724. // [SMARTEDITORSUS-1822] 테이블 셀이 일부가 선택되었다면
  7725. // 현재 Selection의 fisrtNode 와 lastNode 가 셀 내부에 있는지 확인하고
  7726. // 셀 내부에 있으면 노드를 선택된 테이블 셀 노드로 교체한다.
  7727. var elFirstTD = nhn.husky.SE2M_Utils.findAncestorByTagName("TD", firstNode);
  7728. var elLastTD = nhn.husky.SE2M_Utils.findAncestorByTagName("TD", lastNode);
  7729. firstNode = (elFirstTD || !firstNode) ? aNodes[0].firstChild : firstNode;
  7730. lastNode = (elLastTD || !lastNode) ? aNodes[aNodes.length - 1].lastChild : lastNode;
  7731. }
  7732. this.oSelection.setEndNodes(firstNode, lastNode);
  7733. this.oSelection.select();
  7734. this.oApp.exec("CHECK_STYLE_CHANGE", []);
  7735. }, this).bind(firstNode, lastNode), 0);
  7736. return sStyleValue;
  7737. },
  7738. // height in percentage. For example pass 1 to set the line height to 100% and 1.5 to set it to 150%
  7739. setLineStyle : function(sStyleName, styleValue, htOptions, nodes){
  7740. thisRef = this;
  7741. var bWrapperCreated = false;
  7742. function _setLineStyle(div, sStyleName, styleValue){
  7743. if(!div){
  7744. bWrapperCreated = true;
  7745. // try to wrap with P first
  7746. try{
  7747. div = thisRef.oSelection.surroundContentsWithNewNode("P");
  7748. // if the range contains a block-level tag, wrap it with a DIV
  7749. }catch(e){
  7750. div = thisRef.oSelection.surroundContentsWithNewNode("DIV");
  7751. }
  7752. }
  7753. if(typeof styleValue == "function"){
  7754. styleValue(div);
  7755. }else{
  7756. div.style[sStyleName] = styleValue;
  7757. }
  7758. if(div.childNodes.length === 0){
  7759. div.innerHTML = "&nbsp;";
  7760. }
  7761. return div;
  7762. }
  7763. function isInBody(node){
  7764. while(node && node.tagName != "BODY"){
  7765. node = nhn.DOMFix.parentNode(node);
  7766. }
  7767. if(!node){return false;}
  7768. return true;
  7769. }
  7770. if(nodes.length === 0){
  7771. return;
  7772. }
  7773. var curWrapper, prevWrapper;
  7774. var iLength = nodes.length;
  7775. if((!htOptions || !htOptions["bDontAddUndoHistory"])){
  7776. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["LINE STYLE"]);
  7777. }
  7778. prevWrapper = this._getLineWrapper(nodes[0]);
  7779. prevWrapper = _setLineStyle(prevWrapper, sStyleName, styleValue);
  7780. var startNode = prevWrapper;
  7781. var endNode = prevWrapper;
  7782. for(var i=1; i<iLength; i++){
  7783. // Skip the node if a copy of the node were wrapped and the actual node no longer exists within the document.
  7784. try{
  7785. if(!isInBody(nhn.DOMFix.parentNode(nodes[i]))){continue;}
  7786. }catch(e){continue;}
  7787. if(this._isChildOf(nodes[i], curWrapper)){continue;}
  7788. curWrapper = this._getLineWrapper(nodes[i]);
  7789. if(curWrapper == prevWrapper){continue;}
  7790. curWrapper = _setLineStyle(curWrapper, sStyleName, styleValue);
  7791. prevWrapper = curWrapper;
  7792. }
  7793. endNode = curWrapper || startNode;
  7794. if(bWrapperCreated && (!htOptions || !htOptions.bDoNotSelect)) {
  7795. setTimeout(jindo.$Fn(function(startNode, endNode, htOptions){
  7796. if(startNode == endNode){
  7797. this.oSelection.selectNodeContents(startNode);
  7798. if(startNode.childNodes.length==1 && startNode.firstChild.tagName == "BR"){
  7799. this.oSelection.collapseToStart();
  7800. }
  7801. }else{
  7802. this.oSelection.setEndNodes(startNode, endNode);
  7803. }
  7804. this.oSelection.select();
  7805. if((!htOptions || !htOptions["bDontAddUndoHistory"])){
  7806. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["LINE STYLE"]);
  7807. }
  7808. }, this).bind(startNode, endNode, htOptions), 0);
  7809. }
  7810. },
  7811. /**
  7812. * Block Style 적용
  7813. */
  7814. setLineBlockStyle : function(sStyleName, styleValue, htOptions) {
  7815. //var aTempNodes = aTextnodes = [];
  7816. var aTempNodes = [];
  7817. var aTextnodes = [];
  7818. var aNodes = this._getSelectedTDs();
  7819. for( var j = 0; j < aNodes.length ; j++){
  7820. this.oSelection.selectNode(aNodes[j]);
  7821. aTempNodes = this.oSelection.getNodes();
  7822. for(var k = 0, m = 0; k < aTempNodes.length ; k++){
  7823. if(aTempNodes[k].nodeType == 3 || (aTempNodes[k].tagName == "BR" && k == 0)) {
  7824. aTextnodes[m] = aTempNodes[k];
  7825. m ++;
  7826. }
  7827. }
  7828. this.setLineStyle(sStyleName, styleValue, htOptions, aTextnodes);
  7829. aTempNodes = aTextnodes = [];
  7830. }
  7831. },
  7832. getTextNodes : function(bSplitTextEndNodes, oSelection){
  7833. var txtFilter = function(oNode){
  7834. // 편집 중에 생겨난 빈 LI/P에도 스타일 먹이도록 포함함
  7835. // [SMARTEDITORSUS-1861] 커서홀더용 BOM문자 제외하도록 함
  7836. if((oNode.nodeType == 3 && oNode.nodeValue != "\n" && oNode.nodeValue != "" && oNode.nodeValue != "\uFEFF") || (oNode.tagName == "LI" && oNode.innerHTML == "") || (oNode.tagName == "P" && oNode.innerHTML == "")){
  7837. return true;
  7838. }else{
  7839. return false;
  7840. }
  7841. };
  7842. return oSelection.getNodes(bSplitTextEndNodes, txtFilter);
  7843. },
  7844. _getSelectedNodes : function(bDontUpdate){
  7845. if(!bDontUpdate){
  7846. this.oSelection = this.oApp.getSelection();
  7847. }
  7848. // 페이지 최하단에 빈 LI 있을 경우 해당 LI 포함하도록 expand
  7849. if(this.oSelection.endContainer.tagName == "LI" && this.oSelection.endOffset == 0 && this.oSelection.endContainer.innerHTML == ""){
  7850. this.oSelection.setEndAfter(this.oSelection.endContainer);
  7851. }
  7852. if(this.oSelection.collapsed){
  7853. // [SMARTEDITORSUS-1822] SE2M_TableEditor 플러그인에 의해 선택된 TD가 없는지 확인
  7854. // IE의 경우 SE2M_TableEditor 플러그인에 의해 TD가 선택되면 기존 selection 영역을 리셋해버리기 때문에 TD 내의 노드를 반환한다.
  7855. var aNodes = this._getSelectedTDs();
  7856. if(aNodes.length > 0){
  7857. return [aNodes[0].firstChild, aNodes[aNodes.length - 1].lastChild];
  7858. }
  7859. this.oSelection.selectNode(this.oSelection.commonAncestorContainer);
  7860. }
  7861. //var nodes = this.oSelection.getTextNodes();
  7862. var nodes = this.getTextNodes(false, this.oSelection);
  7863. if(nodes.length === 0){
  7864. var tmp = this.oSelection.getStartNode();
  7865. if(tmp){
  7866. nodes[0] = tmp;
  7867. }else{
  7868. var elTmp = this.oSelection._document.createTextNode("\u00A0");
  7869. this.oSelection.insertNode(elTmp);
  7870. nodes = [elTmp];
  7871. }
  7872. }
  7873. return nodes;
  7874. },
  7875. _getWrapperLineStyle : function(sStyle, div){
  7876. var sStyleValue = null;
  7877. if(div && div.style[sStyle]){
  7878. sStyleValue = div.style[sStyle];
  7879. }else{
  7880. div = this.oSelection.commonAncesterContainer;
  7881. while(div && !this.oSelection.rxLineBreaker.test(div.tagName)){
  7882. if(div && div.style[sStyle]){
  7883. sStyleValue = div.style[sStyle];
  7884. break;
  7885. }
  7886. div = nhn.DOMFix.parentNode(div);
  7887. }
  7888. }
  7889. return sStyleValue;
  7890. },
  7891. _isChildOf : function(node, container){
  7892. while(node && node.tagName != "BODY"){
  7893. if(node == container){return true;}
  7894. node = nhn.DOMFix.parentNode(node);
  7895. }
  7896. return false;
  7897. },
  7898. _getLineWrapper : function(node){
  7899. var oTmpSelection = this.oApp.getEmptySelection();
  7900. oTmpSelection.selectNode(node);
  7901. var oLineInfo = oTmpSelection.getLineInfo();
  7902. var oStart = oLineInfo.oStart;
  7903. var oEnd = oLineInfo.oEnd;
  7904. var a, b;
  7905. var breakerA, breakerB;
  7906. var div = null;
  7907. a = oStart.oNode;
  7908. breakerA = oStart.oLineBreaker;
  7909. b = oEnd.oNode;
  7910. breakerB = oEnd.oLineBreaker;
  7911. this.oSelection.setEndNodes(a, b);
  7912. if(breakerA == breakerB){
  7913. if(breakerA.tagName == "P" || breakerA.tagName == "DIV" || breakerA.tagName == "LI"){
  7914. // if(breakerA.tagName == "P" || breakerA.tagName == "DIV"){
  7915. div = breakerA;
  7916. }else{
  7917. this.oSelection.setEndNodes(breakerA.firstChild, breakerA.lastChild);
  7918. }
  7919. }
  7920. return div;
  7921. }
  7922. });
  7923. //}
  7924. /**
  7925. * @fileOverview This file contains Husky plugin that takes care of the operations related to changing the lineheight using layer
  7926. * @name hp_SE2M_LineHeightWithLayerUI.js
  7927. */
  7928. nhn.husky.SE2M_LineHeightWithLayerUI = jindo.$Class({
  7929. name : "SE2M_LineHeightWithLayerUI",
  7930. MIN_LINE_HEIGHT : 50,
  7931. $ON_MSG_APP_READY : function(){
  7932. this.oApp.exec("REGISTER_UI_EVENT", ["lineHeight", "click", "SE2M_TOGGLE_LINEHEIGHT_LAYER"]);
  7933. this.oApp.registerLazyMessage(["SE2M_TOGGLE_LINEHEIGHT_LAYER"], ["hp_SE2M_LineHeightWithLayerUI$Lazy.js"]);
  7934. }
  7935. });
  7936. //{
  7937. /**
  7938. * @fileOverview This file contains Husky plugin that takes care of the operations directly related to the color palette
  7939. * @name hp_SE2M_ColorPalette.js
  7940. */
  7941. nhn.husky.SE2M_ColorPalette = jindo.$Class({
  7942. name : "SE2M_ColorPalette",
  7943. elAppContainer : null,
  7944. bUseRecentColor : false,
  7945. nLimitRecentColor : 17,
  7946. rxRGBColorPattern : /rgb\((\d+), ?(\d+), ?(\d+)\)/i,
  7947. rxColorPattern : /^#?[0-9a-fA-F]{6}$|^rgb\(\d+, ?\d+, ?\d+\)$/i,
  7948. aRecentColor : [], // 최근 사용한 색 목록, 가장 최근에 등록한 색의 index가 가장 작음
  7949. URL_COLOR_LIST : "",
  7950. URL_COLOR_ADD : "",
  7951. URL_COLOR_UPDATE : "",
  7952. sRecentColorTemp : "<li><button type=\"button\" title=\"{RGB_CODE}\" style=\"background:{RGB_CODE}\"><span><span>{RGB_CODE}</span></span></button></li>",
  7953. $init : function(elAppContainer){
  7954. this.elAppContainer = elAppContainer;
  7955. },
  7956. $ON_MSG_APP_READY : function(){},
  7957. _assignHTMLElements : function(oAppContainer){
  7958. var htConfiguration = nhn.husky.SE2M_Configuration.SE2M_ColorPalette;
  7959. if(htConfiguration){
  7960. this.bUseRecentColor = htConfiguration.bUseRecentColor || false;
  7961. this.URL_COLOR_ADD = htConfiguration.addColorURL || "http://api.se2.naver.com/1/colortable/TextAdd.nhn";
  7962. this.URL_COLOR_UPDATE = htConfiguration.updateColorURL || "http://api.se2.naver.com/1/colortable/TextUpdate.nhn";
  7963. this.URL_COLOR_LIST = htConfiguration.colorListURL || "http://api.se2.naver.com/1/colortable/TextList.nhn";
  7964. }
  7965. this.elColorPaletteLayer = jindo.$$.getSingle("DIV.husky_se2m_color_palette", oAppContainer);
  7966. this.elColorPaletteLayerColorPicker = jindo.$$.getSingle("DIV.husky_se2m_color_palette_colorpicker", this.elColorPaletteLayer);
  7967. this.elRecentColorForm = jindo.$$.getSingle("form", this.elColorPaletteLayerColorPicker);
  7968. this.elBackgroundColor = jindo.$$.getSingle("ul.husky_se2m_bgcolor_list", oAppContainer);
  7969. this.elInputColorCode = jindo.$$.getSingle("INPUT.husky_se2m_cp_colorcode", this.elColorPaletteLayerColorPicker);
  7970. this.elPreview = jindo.$$.getSingle("SPAN.husky_se2m_cp_preview", this.elColorPaletteLayerColorPicker);
  7971. this.elCP_ColPanel = jindo.$$.getSingle("DIV.husky_se2m_cp_colpanel", this.elColorPaletteLayerColorPicker);
  7972. this.elCP_HuePanel = jindo.$$.getSingle("DIV.husky_se2m_cp_huepanel", this.elColorPaletteLayerColorPicker);
  7973. this.elCP_ColPanel.style.position = "relative";
  7974. this.elCP_HuePanel.style.position = "relative";
  7975. this.elColorPaletteLayerColorPicker.style.display = "none";
  7976. this.elMoreBtn = jindo.$$.getSingle("BUTTON.husky_se2m_color_palette_more_btn", this.elColorPaletteLayer);
  7977. this.welMoreBtn = jindo.$Element(this.elMoreBtn);
  7978. this.elOkBtn = jindo.$$.getSingle("BUTTON.husky_se2m_color_palette_ok_btn", this.elColorPaletteLayer);
  7979. if(this.bUseRecentColor){
  7980. this.elColorPaletteLayerRecent = jindo.$$.getSingle("DIV.husky_se2m_color_palette_recent", this.elColorPaletteLayer);
  7981. this.elRecentColor = jindo.$$.getSingle("ul.se2_pick_color", this.elColorPaletteLayerRecent);
  7982. this.elDummyNode = jindo.$$.getSingle("ul.se2_pick_color > li", this.elColorPaletteLayerRecent) || null;
  7983. this.elColorPaletteLayerRecent.style.display = "none";
  7984. }
  7985. },
  7986. $LOCAL_BEFORE_FIRST : function(){
  7987. this._assignHTMLElements(this.elAppContainer);
  7988. if(this.elDummyNode){
  7989. jindo.$Element(jindo.$$.getSingle("ul.se2_pick_color > li", this.elColorPaletteLayerRecent)).leave();
  7990. }
  7991. if( this.bUseRecentColor ){
  7992. this._ajaxRecentColor(this._ajaxRecentColorCallback);
  7993. }
  7994. this.oApp.registerBrowserEvent(this.elColorPaletteLayer, "click", "EVENT_CLICK_COLOR_PALETTE");
  7995. // [SMARTEDITORSUS-1833] 아이패드에서 mouseover 이벤트리스너를 등록하면 후속 click 이벤트가 바로 동작하지 않음
  7996. // 모바일환경에서 hover 처리는 의미가 없으므로 PC 환경에서만 hover 처리하도록 함
  7997. if(!this.oApp.bMobile){
  7998. this.oApp.registerBrowserEvent(this.elBackgroundColor, "mouseover", "EVENT_MOUSEOVER_COLOR_PALETTE");
  7999. this.oApp.registerBrowserEvent(this.elColorPaletteLayer, "mouseover", "EVENT_MOUSEOVER_COLOR_PALETTE");
  8000. this.oApp.registerBrowserEvent(this.elBackgroundColor, "mouseout", "EVENT_MOUSEOUT_COLOR_PALETTE");
  8001. this.oApp.registerBrowserEvent(this.elColorPaletteLayer, "mouseout", "EVENT_MOUSEOUT_COLOR_PALETTE");
  8002. }
  8003. },
  8004. $ON_EVENT_MOUSEOVER_COLOR_PALETTE : function(oEvent){
  8005. var elHovered = oEvent.element;
  8006. while(elHovered && elHovered.tagName && elHovered.tagName.toLowerCase() != "li"){
  8007. elHovered = elHovered.parentNode;
  8008. }
  8009. //조건 추가-by cielo 2010.04.20
  8010. if(!elHovered || !elHovered.nodeType || elHovered.nodeType == 9){return;}
  8011. if(elHovered.className == "" || (!elHovered.className) || typeof(elHovered.className) == 'undefined'){jindo.$Element(elHovered).addClass("hover");}
  8012. },
  8013. $ON_EVENT_MOUSEOUT_COLOR_PALETTE : function(oEvent){
  8014. var elHovered = oEvent.element;
  8015. while(elHovered && elHovered.tagName && elHovered.tagName.toLowerCase() != "li"){
  8016. elHovered = elHovered.parentNode;
  8017. }
  8018. if(!elHovered){return;}
  8019. if(elHovered.className == "hover"){jindo.$Element(elHovered).removeClass("hover");}
  8020. },
  8021. $ON_EVENT_CLICK_COLOR_PALETTE : function(oEvent){
  8022. var elClicked = oEvent.element;
  8023. while(elClicked.tagName == "SPAN"){elClicked = elClicked.parentNode;}
  8024. if(elClicked.tagName && elClicked.tagName == "BUTTON"){
  8025. if(elClicked == this.elMoreBtn){
  8026. this.oApp.exec("TOGGLE_COLOR_PICKER");
  8027. return;
  8028. }
  8029. this.oApp.exec("APPLY_COLOR", [elClicked]);
  8030. }
  8031. },
  8032. $ON_APPLY_COLOR : function(elButton){
  8033. var sColorCode = this.elInputColorCode.value,
  8034. welColorParent = null;
  8035. if(sColorCode.indexOf("#") == -1){
  8036. sColorCode = "#" + sColorCode;
  8037. this.elInputColorCode.value = sColorCode;
  8038. }
  8039. // 입력 버튼인 경우
  8040. if(elButton == this.elOkBtn){
  8041. if(!this._verifyColorCode(sColorCode)){
  8042. this.elInputColorCode.value = "";
  8043. alert(this.oApp.$MSG("SE_Color.invalidColorCode"));
  8044. this.elInputColorCode.focus();
  8045. return;
  8046. }
  8047. this.oApp.exec("COLOR_PALETTE_APPLY_COLOR", [sColorCode,true]);
  8048. return;
  8049. }
  8050. // 색상 버튼인 경우
  8051. welColorParent = jindo.$Element(elButton.parentNode.parentNode.parentNode);
  8052. sColorCode = elButton.title;
  8053. if(welColorParent.hasClass("husky_se2m_color_palette")){ // 템플릿 색상 적용
  8054. /*
  8055. * [SMARTEDITORSUS-1884][SMARTEDITORSUS-2117]
  8056. * 설정값 제거(r12236) 전에도
  8057. * 모든 타입에서
  8058. * nhn.husky.SE2M_Configuration.SE2M_ColorPalette.bAddRecentColorFromDefault 값이
  8059. * undefined인 상태로 동작하고 있었기 때문에
  8060. * false로 처리
  8061. */
  8062. this.oApp.exec("COLOR_PALETTE_APPLY_COLOR", [sColorCode, false]);
  8063. }else if(welColorParent.hasClass("husky_se2m_color_palette_recent")){ // 최근 색상 적용
  8064. this.oApp.exec("COLOR_PALETTE_APPLY_COLOR", [sColorCode,true]);
  8065. }
  8066. },
  8067. $ON_RESET_COLOR_PALETTE : function(){
  8068. this._initColor();
  8069. },
  8070. $ON_TOGGLE_COLOR_PICKER : function(){
  8071. if(this.elColorPaletteLayerColorPicker.style.display == "none"){
  8072. this.oApp.exec("SHOW_COLOR_PICKER");
  8073. }else{
  8074. this.oApp.exec("HIDE_COLOR_PICKER");
  8075. }
  8076. },
  8077. $ON_SHOW_COLOR_PICKER : function(){
  8078. this.elColorPaletteLayerColorPicker.style.display = "";
  8079. this.cpp = new nhn.ColorPicker(this.elCP_ColPanel, {huePanel:this.elCP_HuePanel});
  8080. var fn = jindo.$Fn(function(oEvent) {
  8081. this.elPreview.style.backgroundColor = oEvent.hexColor;
  8082. this.elInputColorCode.value = oEvent.hexColor;
  8083. }, this).bind();
  8084. this.cpp.attach("colorchange", fn);
  8085. this.$ON_SHOW_COLOR_PICKER = this._showColorPickerMain;
  8086. this.$ON_SHOW_COLOR_PICKER();
  8087. },
  8088. $ON_HIDE_COLOR_PICKER : function(){
  8089. this.elColorPaletteLayerColorPicker.style.display = "none";
  8090. this.welMoreBtn.addClass("se2_view_more");
  8091. this.welMoreBtn.removeClass("se2_view_more2");
  8092. },
  8093. $ON_SHOW_COLOR_PALETTE : function(sCallbackCmd, oLayerContainer){
  8094. this.sCallbackCmd = sCallbackCmd;
  8095. this.oLayerContainer = oLayerContainer;
  8096. this.oLayerContainer.insertBefore(this.elColorPaletteLayer, null);
  8097. this.elColorPaletteLayer.style.display = "block";
  8098. this.oApp.delayedExec("POSITION_TOOLBAR_LAYER", [this.elColorPaletteLayer.parentNode.parentNode], 0);
  8099. },
  8100. $ON_HIDE_COLOR_PALETTE : function(){
  8101. this.elColorPaletteLayer.style.display = "none";
  8102. },
  8103. $ON_COLOR_PALETTE_APPLY_COLOR : function(sColorCode , bAddRecentColor){
  8104. bAddRecentColor = (!bAddRecentColor)? false : bAddRecentColor;
  8105. sColorCode = this._getHexColorCode(sColorCode);
  8106. //더보기 레이어에서 적용한 색상만 최근 사용한 색에 추가한다.
  8107. if( this.bUseRecentColor && !!bAddRecentColor ){
  8108. this.oApp.exec("ADD_RECENT_COLOR", [sColorCode]);
  8109. }
  8110. this.oApp.exec(this.sCallbackCmd, [sColorCode]);
  8111. },
  8112. $ON_EVENT_MOUSEUP_COLOR_PALETTE : function(oEvent){
  8113. var elButton = oEvent.element;
  8114. if(! elButton.style.backgroundColor){return;}
  8115. this.oApp.exec("COLOR_PALETTE_APPLY_COLOR", [elButton.style.backgroundColor,false]);
  8116. },
  8117. $ON_ADD_RECENT_COLOR : function(sRGBCode){
  8118. var bAdd = (this.aRecentColor.length === 0);
  8119. this._addRecentColor(sRGBCode);
  8120. if(bAdd){
  8121. this._ajaxAddColor();
  8122. }else{
  8123. this._ajaxUpdateColor();
  8124. }
  8125. this._redrawRecentColorElement();
  8126. },
  8127. _verifyColorCode : function(sColorCode){
  8128. return this.rxColorPattern.test(sColorCode);
  8129. },
  8130. _getHexColorCode : function(sColorCode){
  8131. if(this.rxRGBColorPattern.test(sColorCode)){
  8132. var dec2Hex = function(sDec){
  8133. var sTmp = parseInt(sDec, 10).toString(16);
  8134. if(sTmp.length<2){sTmp = "0"+sTmp;}
  8135. return sTmp.toUpperCase();
  8136. };
  8137. var sR = dec2Hex(RegExp.$1);
  8138. var sG = dec2Hex(RegExp.$2);
  8139. var sB = dec2Hex(RegExp.$3);
  8140. sColorCode = "#"+sR+sG+sB;
  8141. }
  8142. return sColorCode;
  8143. },
  8144. _addRecentColor : function(sRGBCode){
  8145. var waRecentColor = jindo.$A(this.aRecentColor);
  8146. waRecentColor = waRecentColor.refuse(sRGBCode);
  8147. waRecentColor.unshift(sRGBCode);
  8148. if(waRecentColor.length() > this.nLimitRecentColor){
  8149. waRecentColor.length(this.nLimitRecentColor);
  8150. }
  8151. this.aRecentColor = waRecentColor.$value();
  8152. },
  8153. _redrawRecentColorElement : function(){
  8154. var aRecentColorHtml = [],
  8155. nRecentColor = this.aRecentColor.length,
  8156. i;
  8157. if(nRecentColor === 0){
  8158. return;
  8159. }
  8160. for(i=0; i<nRecentColor; i++){
  8161. aRecentColorHtml.push(this.sRecentColorTemp.replace(/\{RGB_CODE\}/gi, this.aRecentColor[i]));
  8162. }
  8163. this.elRecentColor.innerHTML = aRecentColorHtml.join("");
  8164. this.elColorPaletteLayerRecent.style.display = "block";
  8165. },
  8166. _ajaxAddColor : function(){
  8167. jindo.$Ajax(this.URL_COLOR_ADD, {
  8168. type : "jsonp",
  8169. onload: function(){}
  8170. }).request({
  8171. text_key : "colortable",
  8172. text_data : this.aRecentColor.join(",")
  8173. });
  8174. },
  8175. _ajaxUpdateColor : function(){
  8176. jindo.$Ajax(this.URL_COLOR_UPDATE, {
  8177. type : "jsonp",
  8178. onload: function(){}
  8179. }).request({
  8180. text_key : "colortable",
  8181. text_data : this.aRecentColor.join(",")
  8182. });
  8183. },
  8184. _showColorPickerMain : function(){
  8185. this._initColor();
  8186. this.elColorPaletteLayerColorPicker.style.display = "";
  8187. this.welMoreBtn.removeClass("se2_view_more");
  8188. this.welMoreBtn.addClass("se2_view_more2");
  8189. },
  8190. _initColor : function(){
  8191. if(this.cpp){this.cpp.rgb({r:0,g:0,b:0});}
  8192. this.elPreview.style.backgroundColor = '#'+'000000';
  8193. this.elInputColorCode.value = '#'+'000000';
  8194. this.oApp.exec("HIDE_COLOR_PICKER");
  8195. },
  8196. _ajaxRecentColor : function(fCallback){
  8197. jindo.$Ajax(this.URL_COLOR_LIST, {
  8198. type : "jsonp",
  8199. onload : jindo.$Fn(fCallback, this).bind()
  8200. }).request();
  8201. },
  8202. _ajaxRecentColorCallback : function(htResponse){
  8203. var aColorList = htResponse.json()["result"],
  8204. waColorList,
  8205. i, nLen;
  8206. if(!aColorList || !!aColorList.error){
  8207. return;
  8208. }
  8209. waColorList = jindo.$A(aColorList).filter(this._verifyColorCode, this);
  8210. if(waColorList.length() > this.nLimitRecentColor){
  8211. waColorList.length(this.nLimitRecentColor);
  8212. }
  8213. aColorList = waColorList.reverse().$value();
  8214. for(i = 0, nLen = aColorList.length; i < nLen; i++){
  8215. this._addRecentColor(this._getHexColorCode(aColorList[i]));
  8216. }
  8217. this._redrawRecentColorElement();
  8218. }
  8219. }).extend(jindo.Component);
  8220. //}
  8221. /**
  8222. * @fileOverview This file contains Husky plugin that takes care of the operations related to changing the font color
  8223. * @name hp_SE_FontColor.js
  8224. */
  8225. nhn.husky.SE2M_FontColor = jindo.$Class({
  8226. name : "SE2M_FontColor",
  8227. rxColorPattern : /^#?[0-9a-fA-F]{6}$|^rgb\(\d+, ?\d+, ?\d+\)$/i,
  8228. $init : function(elAppContainer){
  8229. this._assignHTMLElements(elAppContainer);
  8230. },
  8231. _assignHTMLElements : function(elAppContainer){
  8232. //@ec[
  8233. this.elLastUsed = jindo.$$.getSingle("SPAN.husky_se2m_fontColor_lastUsed", elAppContainer);
  8234. this.elDropdownLayer = jindo.$$.getSingle("DIV.husky_se2m_fontcolor_layer", elAppContainer);
  8235. this.elPaletteHolder = jindo.$$.getSingle("DIV.husky_se2m_fontcolor_paletteHolder", this.elDropdownLayer);
  8236. //@ec]
  8237. this._setLastUsedFontColor("#000000");
  8238. },
  8239. $BEFORE_MSG_APP_READY : function() {
  8240. this.oApp.exec("ADD_APP_PROPERTY", ["getLastUsedFontColor", jindo.$Fn(this.getLastUsedFontColor, this).bind()]);
  8241. },
  8242. $ON_MSG_APP_READY : function(){
  8243. this.oApp.exec("REGISTER_UI_EVENT", ["fontColorA", "click", "APPLY_LAST_USED_FONTCOLOR"]);
  8244. this.oApp.exec("REGISTER_UI_EVENT", ["fontColorB", "click", "TOGGLE_FONTCOLOR_LAYER"]);
  8245. this.oApp.registerLazyMessage(["APPLY_LAST_USED_FONTCOLOR", "TOGGLE_FONTCOLOR_LAYER"], ["hp_SE2M_FontColor$Lazy.js"]);
  8246. },
  8247. _setLastUsedFontColor : function(sFontColor){
  8248. this.sLastUsedColor = sFontColor;
  8249. this.elLastUsed.style.backgroundColor = this.sLastUsedColor;
  8250. },
  8251. getLastUsedFontColor : function(){
  8252. return (!!this.sLastUsedColor) ? this.sLastUsedColor : '#000000';
  8253. }
  8254. });
  8255. //{
  8256. /**
  8257. * @fileOverview This file contains Husky plugin that takes care of changing the background color
  8258. * @name hp_SE2M_BGColor.js
  8259. */
  8260. nhn.husky.SE2M_BGColor = jindo.$Class({
  8261. name : "SE2M_BGColor",
  8262. rxColorPattern : /^#?[0-9a-fA-F]{6}$|^rgb\(\d+, ?\d+, ?\d+\)$/i,
  8263. $init : function(elAppContainer){
  8264. this._assignHTMLElements(elAppContainer);
  8265. },
  8266. _assignHTMLElements : function(elAppContainer){
  8267. //@ec[
  8268. this.elLastUsed = jindo.$$.getSingle("SPAN.husky_se2m_BGColor_lastUsed", elAppContainer);
  8269. this.elDropdownLayer = jindo.$$.getSingle("DIV.husky_se2m_BGColor_layer", elAppContainer);
  8270. this.elBGColorList = jindo.$$.getSingle("UL.husky_se2m_bgcolor_list", elAppContainer);
  8271. this.elPaletteHolder = jindo.$$.getSingle("DIV.husky_se2m_BGColor_paletteHolder", this.elDropdownLayer);
  8272. //@ec]
  8273. this._setLastUsedBGColor("#777777");
  8274. },
  8275. $BEFORE_MSG_APP_READY : function() {
  8276. this.oApp.exec("ADD_APP_PROPERTY", ["getLastUsedBackgroundColor", jindo.$Fn(this.getLastUsedBGColor, this).bind()]);
  8277. },
  8278. $ON_MSG_APP_READY : function(){
  8279. this.oApp.exec("REGISTER_UI_EVENT", ["BGColorA", "click", "APPLY_LAST_USED_BGCOLOR"]);
  8280. this.oApp.exec("REGISTER_UI_EVENT", ["BGColorB", "click", "TOGGLE_BGCOLOR_LAYER"]);
  8281. this.oApp.registerBrowserEvent(this.elBGColorList, "click", "EVENT_APPLY_BGCOLOR", []);
  8282. this.oApp.registerLazyMessage(["APPLY_LAST_USED_BGCOLOR", "TOGGLE_BGCOLOR_LAYER"], ["hp_SE2M_BGColor$Lazy.js"]);
  8283. },
  8284. _setLastUsedBGColor : function(sBGColor){
  8285. this.sLastUsedColor = sBGColor;
  8286. this.elLastUsed.style.backgroundColor = this.sLastUsedColor;
  8287. },
  8288. getLastUsedBGColor : function(){
  8289. return (!!this.sLastUsedColor) ? this.sLastUsedColor : '#777777';
  8290. }
  8291. });
  8292. //}
  8293. /**
  8294. * @fileOverview This file contains Husky plugin that takes care of the operations related to hyperlink
  8295. * @name hp_SE_Hyperlink.js
  8296. */
  8297. nhn.husky.SE2M_Hyperlink = jindo.$Class({
  8298. name : "SE2M_Hyperlink",
  8299. sATagMarker : "HTTP://HUSKY_TMP.MARKER/",
  8300. _assignHTMLElements : function(elAppContainer){
  8301. this.oHyperlinkButton = jindo.$$.getSingle("li.husky_seditor_ui_hyperlink", elAppContainer);
  8302. this.oHyperlinkLayer = jindo.$$.getSingle("div.se2_layer", this.oHyperlinkButton);
  8303. this.oLinkInput = jindo.$$.getSingle("INPUT[type=text]", this.oHyperlinkLayer);
  8304. this.oBtnConfirm = jindo.$$.getSingle("button.se2_apply", this.oHyperlinkLayer);
  8305. this.oBtnCancel = jindo.$$.getSingle("button.se2_cancel", this.oHyperlinkLayer);
  8306. //this.oCbNewWin = jindo.$$.getSingle("INPUT[type=checkbox]", this.oHyperlinkLayer) || null;
  8307. },
  8308. _generateAutoLink : function(sAll, sBreaker, sURL, sWWWURL, sHTTPURL) {
  8309. sBreaker = sBreaker || "";
  8310. var sResult;
  8311. if (sWWWURL){
  8312. sResult = '<a href="http://'+sWWWURL+'">'+sURL+'</a>';
  8313. } else {
  8314. sResult = '<a href="'+sHTTPURL+'">'+sURL+'</a>';
  8315. }
  8316. return sBreaker+sResult;
  8317. },
  8318. /**
  8319. * [SMARTEDITORSUS-1405] 자동링크 비활성화 옵션을 체크해서 처리한다.
  8320. * $ON_REGISTER_CONVERTERS 메시지가 SE_EditingAreaManager.$ON_MSG_APP_READY 에서 수행되므로 먼저 처리한다.
  8321. */
  8322. $BEFORE_MSG_APP_READY : function(){
  8323. var htOptions = nhn.husky.SE2M_Configuration.SE2M_Hyperlink;
  8324. if(htOptions && htOptions.bAutolink === false){
  8325. // 자동링크 컨버터 비활성화
  8326. this.$ON_REGISTER_CONVERTERS = null;
  8327. // UI enable/disable 처리 제외
  8328. this.$ON_DISABLE_MESSAGE = null;
  8329. this.$ON_ENABLE_MESSAGE = null;
  8330. // 브라우저의 자동링크기능 비활성화
  8331. try{ this.oApp.getWYSIWYGDocument().execCommand("AutoUrlDetect", false, false); } catch(e){}
  8332. }
  8333. },
  8334. $ON_MSG_APP_READY : function(){
  8335. this.bLayerShown = false;
  8336. // [SMARTEDITORSUS-2260] 메일 > Mac에서 ctrl 조합 단축키 모두 meta 조합으로 변경
  8337. if (jindo.$Agent().os().mac) {
  8338. this.oApp.exec("REGISTER_HOTKEY", ["meta+k", "TOGGLE_HYPERLINK_LAYER", []]);
  8339. } else {
  8340. this.oApp.exec("REGISTER_HOTKEY", ["ctrl+k", "TOGGLE_HYPERLINK_LAYER", []]);
  8341. }
  8342. this.oApp.exec("REGISTER_UI_EVENT", ["hyperlink", "click", "TOGGLE_HYPERLINK_LAYER"]);
  8343. this.oApp.registerLazyMessage(["TOGGLE_HYPERLINK_LAYER", "APPLY_HYPERLINK"], ["hp_SE2M_Hyperlink$Lazy.js"]);
  8344. },
  8345. $ON_REGISTER_CONVERTERS : function(){
  8346. this.oApp.exec("ADD_CONVERTER_DOM", ["IR_TO_DB", jindo.$Fn(this.irToDb, this).bind()]);
  8347. },
  8348. $LOCAL_BEFORE_FIRST : function(sMsg){
  8349. if(!!sMsg.match(/(REGISTER_CONVERTERS)/)){
  8350. this.oApp.acceptLocalBeforeFirstAgain(this, true);
  8351. return true;
  8352. }
  8353. this._assignHTMLElements(this.oApp.htOptions.elAppContainer);
  8354. this.sRXATagMarker = this.sATagMarker.replace(/\//g, "\\/").replace(/\./g, "\\.");
  8355. this.oApp.registerBrowserEvent(this.oBtnConfirm, "click", "APPLY_HYPERLINK");
  8356. this.oApp.registerBrowserEvent(this.oBtnCancel, "click", "HIDE_ACTIVE_LAYER");
  8357. this.oApp.registerBrowserEvent(this.oLinkInput, "keydown", "EVENT_HYPERLINK_KEYDOWN");
  8358. },
  8359. $ON_EVENT_HYPERLINK_KEYDOWN : function(oEvent){
  8360. if (oEvent.key().enter){
  8361. this.oApp.exec("APPLY_HYPERLINK");
  8362. oEvent.stop();
  8363. }
  8364. },
  8365. /**
  8366. * [MUG-1265] 버튼이 사용불가 상태이면 자동변환기능을 막는다.
  8367. * @see http://stackoverflow.com/questions/7556007/avoid-transformation-text-to-link-ie-contenteditable-mode
  8368. * IE9 이전 버전은 AutoURlDetect을 사용할 없어 오류 발생되기 때문에, try catch로 블럭 처리(http://msdn.microsoft.com/en-us/library/aa769893%28VS.85%29.aspx)
  8369. */
  8370. $ON_DISABLE_MESSAGE : function(sCmd) {
  8371. if(sCmd !== "TOGGLE_HYPERLINK_LAYER"){
  8372. return;
  8373. }
  8374. try{ this.oApp.getWYSIWYGDocument().execCommand("AutoUrlDetect", false, false); } catch(e){}
  8375. this._bDisabled = true;
  8376. },
  8377. /**
  8378. * [MUG-1265] 버튼이 사용가능 상태이면 자동변환기능을 복원해준다.
  8379. */
  8380. $ON_ENABLE_MESSAGE : function(sCmd) {
  8381. if(sCmd !== "TOGGLE_HYPERLINK_LAYER"){
  8382. return;
  8383. }
  8384. try{ this.oApp.getWYSIWYGDocument().execCommand("AutoUrlDetect", false, true); } catch(e){}
  8385. this._bDisabled = false;
  8386. },
  8387. irToDb : function(oTmpNode){
  8388. if(this._bDisabled){ // [MUG-1265] 버튼이 사용불가 상태이면 자동변환하지 않는다.
  8389. return;
  8390. }
  8391. //저장 시점에 자동 링크를 위한 함수.
  8392. //[SMARTEDITORSUS-1207][IE][메일] object 삽입 후 글을 저장하면 IE 브라우저가 죽어버리는 현상
  8393. //원인 : 확인 불가. IE 저작권 관련 이슈로 추정
  8394. //해결 : contents를 가지고 있는 div 태그를 이 함수 내부에서 복사하여 수정 후 call by reference로 넘어온 변수의 innerHTML을 변경
  8395. var oCopyNode = oTmpNode.cloneNode(true);
  8396. try{
  8397. oCopyNode.innerHTML;
  8398. }catch(e) {
  8399. oCopyNode = jindo.$(oTmpNode.outerHTML);
  8400. }
  8401. var oTmpRange = this.oApp.getEmptySelection();
  8402. var elFirstNode = oTmpRange._getFirstRealChild(oCopyNode);
  8403. var elLastNode = oTmpRange._getLastRealChild(oCopyNode);
  8404. var waAllNodes = jindo.$A(oTmpRange._getNodesBetween(elFirstNode, elLastNode));
  8405. var aAllTextNodes = waAllNodes.filter(function(elNode){return (elNode && elNode.nodeType === 3);}).$value();
  8406. var a = aAllTextNodes;
  8407. /*
  8408. // 텍스트 검색이 용이 하도록 끊어진 텍스트 노드가 있으면 합쳐줌. (화면상으로 ABC라고 보이나 상황에 따라 실제 2개의 텍스트 A, BC로 이루어져 있을 수 있음. 이를 ABC 하나의 노드로 만들어 줌.)
  8409. // 문제 발생 가능성에 비해서 퍼포먼스나 사이드 이펙트 가능성 높아 일단 주석
  8410. var aCleanTextNodes = [];
  8411. for(var i=0, nLen=aAllTextNodes.length; i<nLen; i++){
  8412. if(a[i].nextSibling && a[i].nextSibling.nodeType === 3){
  8413. a[i].nextSibling.nodeValue += a[i].nodeValue;
  8414. a[i].parentNode.removeChild(a[i]);
  8415. }else{
  8416. aCleanTextNodes[aCleanTextNodes.length] = a[i];
  8417. }
  8418. }
  8419. */
  8420. var aCleanTextNodes = aAllTextNodes;
  8421. // IE에서 PRE를 제외한 다른 태그 하위에 있는 텍스트 노드는 줄바꿈 등의 값을 변질시킴
  8422. var elTmpDiv = this.oApp.getWYSIWYGDocument().createElement("DIV");
  8423. var elParent, bAnchorFound;
  8424. var sTmpStr = "@"+(new Date()).getTime()+"@";
  8425. var rxTmpStr = new RegExp(sTmpStr, "g");
  8426. for(var i=0, nLen=aAllTextNodes.length; i<nLen; i++){
  8427. // Anchor가 이미 걸려 있는 텍스트이면 링크를 다시 걸지 않음.
  8428. elParent = a[i].parentNode;
  8429. bAnchorFound = false;
  8430. while(elParent){
  8431. if(elParent.tagName === "A" || elParent.tagName === "PRE"){
  8432. bAnchorFound = true;
  8433. break;
  8434. }
  8435. elParent = elParent.parentNode;
  8436. }
  8437. if(bAnchorFound){
  8438. continue;
  8439. }
  8440. // www.또는 http://으로 시작하는 텍스트에 링크 걸어 줌
  8441. // IE에서 텍스트 노드 앞쪽의 스페이스나 주석등이 사라지는 현상이 있어 sTmpStr을 앞에 붙여줌.
  8442. elTmpDiv.innerHTML = "";
  8443. try {
  8444. elTmpDiv.appendChild(a[i].cloneNode(true));
  8445. // IE에서 innerHTML를 이용 해 직접 텍스트 노드 값을 할당 할 경우 줄바꿈등이 깨질 수 있어, 텍스트 노드로 만들어서 이를 바로 append 시켜줌
  8446. // [SMARTEDITORSUS-1649] https:// URL을 입력한 경우에도 자동링크 지원
  8447. //elTmpDiv.innerHTML = (sTmpStr+elTmpDiv.innerHTML).replace(/(&nbsp|\s)?(((?!http:\/\/)www\.(?:(?!\&nbsp;|\s|"|').)+)|(http:\/\/(?:(?!&nbsp;|\s|"|').)+))/ig, this._generateAutoLink);
  8448. elTmpDiv.innerHTML = (sTmpStr+elTmpDiv.innerHTML).replace(/(&nbsp|\s)?(((?!http[s]?:\/\/)www\.(?:(?!\&nbsp;|\s|"|').)+)|(http[s]?:\/\/(?:(?!&nbsp;|\s|"|').)+))/ig, this._generateAutoLink);
  8449. // --[SMARTEDITORSUS-1649]
  8450. // innerHTML 내에 텍스트가 있을 경우 insert 시에 주변 텍스트 노드와 합쳐지는 현상이 있어 div로 위치를 먼저 잡고 하나씩 삽입
  8451. a[i].parentNode.insertBefore(elTmpDiv, a[i]);
  8452. a[i].parentNode.removeChild(a[i]);
  8453. } catch(e1) {
  8454. }
  8455. while(elTmpDiv.firstChild){
  8456. elTmpDiv.parentNode.insertBefore(elTmpDiv.firstChild, elTmpDiv);
  8457. }
  8458. elTmpDiv.parentNode.removeChild(elTmpDiv);
  8459. // alert(a[i].nodeValue);
  8460. }
  8461. elTmpDiv = oTmpRange = elFirstNode = elLastNode = waAllNodes = aAllTextNodes = a = aCleanTextNodes = elParent = null;
  8462. oCopyNode.innerHTML = oCopyNode.innerHTML.replace(rxTmpStr, "");
  8463. oTmpNode.innerHTML = oCopyNode.innerHTML;
  8464. oCopyNode = null;
  8465. //alert(oTmpNode.innerHTML);
  8466. }
  8467. });
  8468. /**
  8469. * @fileOverview This file contains Husky plugin that takes care of the operations related to changing the font name using Select element
  8470. * @name SE2M_FontNameWithLayerUI.js
  8471. * @trigger MSG_STYLE_CHANGED,SE2M_TOGGLE_FONTNAME_LAYER
  8472. */
  8473. nhn.husky.SE2M_FontNameWithLayerUI = jindo.$Class({
  8474. name : "SE2M_FontNameWithLayerUI",
  8475. FONT_SEPARATOR : "husky_seditor_font_separator",
  8476. _rxQuote : /['"]/g,
  8477. _rxComma : /\s*,\s*/g,
  8478. $init : function(elAppContainer, aAdditionalFontList){
  8479. this.elLastHover = null;
  8480. this._assignHTMLElements(elAppContainer);
  8481. this.htBrowser = jindo.$Agent().navigator();
  8482. this.aAdditionalFontList = aAdditionalFontList || [];
  8483. },
  8484. addAllFonts : function(){
  8485. var aDefaultFontList, aFontList, htMainFont, aFontInUse, i;
  8486. // family name -> display name 매핑 (웹폰트는 두개가 다름)
  8487. this.htFamilyName2DisplayName = {};
  8488. this.htAllFonts = {};
  8489. this.aBaseFontList = [];
  8490. this.aDefaultFontList = [];
  8491. this.aTempSavedFontList = [];
  8492. this.htOptions = this.oApp.htOptions.SE2M_FontName;
  8493. if(this.htOptions){
  8494. aDefaultFontList = this.htOptions.aDefaultFontList || [];
  8495. aFontList = this.htOptions.aFontList;
  8496. htMainFont = this.htOptions.htMainFont;
  8497. aFontInUse = this.htOptions.aFontInUse;
  8498. //add Font
  8499. if(this.htBrowser.ie && aFontList){
  8500. for(i=0; i<aFontList.length; i++){
  8501. this.addFont(aFontList[i].id, aFontList[i].name, aFontList[i].size, aFontList[i].url, aFontList[i].cssUrl);
  8502. }
  8503. }
  8504. for(i=0; i<aDefaultFontList.length; i++){
  8505. this.addFont(aDefaultFontList[i][0], aDefaultFontList[i][1], 0, "", "", 1);
  8506. }
  8507. //set Main Font
  8508. //if(mainFontSelected=='true') {
  8509. if(htMainFont && htMainFont.id) {
  8510. //this.setMainFont(mainFontId, mainFontName, mainFontSize, mainFontUrl, mainFontCssUrl);
  8511. this.setMainFont(htMainFont.id, htMainFont.name, htMainFont.size, htMainFont.url, htMainFont.cssUrl);
  8512. }
  8513. // add font in use
  8514. if(this.htBrowser.ie && aFontInUse){
  8515. for(i=0; i<aFontInUse.length; i++){
  8516. this.addFontInUse(aFontInUse[i].id, aFontInUse[i].name, aFontInUse[i].size, aFontInUse[i].url, aFontInUse[i].cssUrl);
  8517. }
  8518. }
  8519. }
  8520. // [SMARTEDITORSUS-245] 서비스 적용 시 글꼴정보를 넘기지 않으면 기본 글꼴 목록이 보이지 않는 오류
  8521. if(!this.htOptions || !this.htOptions.aDefaultFontList || this.htOptions.aDefaultFontList.length === 0){
  8522. this.addFont("돋움,Dotum", "돋움", 0, "", "", 1, null, true);
  8523. this.addFont("돋움체,DotumChe,AppleGothic", "돋움체", 0, "", "", 1, null, true);
  8524. this.addFont("굴림,Gulim", "굴림", 0, "", "", 1, null, true);
  8525. this.addFont("굴림체,GulimChe", "굴림체", 0, "", "", 1, null, true);
  8526. this.addFont("바탕,Batang,AppleMyungjo", "바탕", 0, "", "", 1, null, true);
  8527. this.addFont("바탕체,BatangChe", "바탕체", 0, "", "", 1, null, true);
  8528. this.addFont("궁서,Gungsuh,GungSeo", "궁서", 0, "", "", 1, null, true);
  8529. this.addFont('Arial', 'Arial', 0, "", "", 1, "abcd", true);
  8530. this.addFont('Tahoma', 'Tahoma', 0, "", "", 1, "abcd", true);
  8531. this.addFont('Times New Roman', 'Times New Roman', 0, "", "", 1, "abcd", true);
  8532. this.addFont('Verdana', 'Verdana', 0, "", "", 1, "abcd", true);
  8533. this.addFont('Courier New', 'Courier New', 0, "", "", 1, "abcd", true);
  8534. }
  8535. // [SMARTEDITORSUS-1436] 글꼴 리스트에 글꼴 종류 추가하기 기능
  8536. if(!!this.aAdditionalFontList && this.aAdditionalFontList.length > 0){
  8537. for(i = 0, nLen = this.aAdditionalFontList.length; i < nLen; i++){
  8538. this.addFont(this.aAdditionalFontList[i][0], this.aAdditionalFontList[i][1], 0, "", "", 1);
  8539. }
  8540. }
  8541. },
  8542. $ON_MSG_APP_READY : function(){
  8543. this.bDoNotRecordUndo = false;
  8544. this.oApp.exec("ADD_APP_PROPERTY", ["addFont", jindo.$Fn(this.addFont, this).bind()]);
  8545. this.oApp.exec("ADD_APP_PROPERTY", ["addFontInUse", jindo.$Fn(this.addFontInUse, this).bind()]);
  8546. // 블로그등 팩토리 폰트 포함 용
  8547. this.oApp.exec("ADD_APP_PROPERTY", ["setMainFont", jindo.$Fn(this.setMainFont, this).bind()]);
  8548. // 메일등 단순 폰트 지정 용
  8549. this.oApp.exec("ADD_APP_PROPERTY", ["setDefaultFont", jindo.$Fn(this.setDefaultFont, this).bind()]);
  8550. this.oApp.exec("REGISTER_UI_EVENT", ["fontName", "click", "SE2M_TOGGLE_FONTNAME_LAYER"]);
  8551. this._initFontName(); // [SMARTEDITORSUS-2111] 메일쪽 요청으로 글꼴목록 초기화시점 변경
  8552. },
  8553. $AFTER_MSG_APP_READY : function(){
  8554. this._attachIEEvent();
  8555. },
  8556. _assignHTMLElements : function(elAppContainer){
  8557. //@ec[
  8558. this.oDropdownLayer = jindo.$$.getSingle("DIV.husky_se_fontName_layer", elAppContainer);
  8559. this.elFontNameLabel = jindo.$$.getSingle("SPAN.husky_se2m_current_fontName", elAppContainer);
  8560. this.elFontNameList = jindo.$$.getSingle("UL", this.oDropdownLayer);
  8561. this.elInnerLayer = this.elFontNameList.parentNode;
  8562. this.aelFontInMarkup = jindo.$$("LI", this.oDropdownLayer); // 마크업에 있는 LI
  8563. this.elFontItemTemplate = this.aelFontInMarkup.shift(); // 맨앞에 있는 LI 는 템플릿
  8564. this.aLIFontNames = jindo.$A(jindo.$$("LI", this.oDropdownLayer)).filter(function(v,i,a){return (v.firstChild !== null);})._array;
  8565. //@ec]
  8566. this.sDefaultText = this.elFontNameLabel.innerHTML;
  8567. },
  8568. //$LOCAL_BEFORE_FIRST : function(){
  8569. _initFontName : function(){
  8570. this._addFontInMarkup();
  8571. this.addAllFonts();
  8572. // [SMARTEDITORSUS-1853] 폰트가 초기화되면 현재 스타일정보를 가져와서 툴바에 반영해준다.
  8573. var oStyle;
  8574. if(this.oApp.getCurrentStyle && (oStyle = this.oApp.getCurrentStyle())){
  8575. this.$ON_MSG_STYLE_CHANGED("fontFamily", oStyle.fontFamily);
  8576. }
  8577. this.oApp.registerBrowserEvent(this.oDropdownLayer, "mouseover", "EVENT_FONTNAME_LAYER_MOUSEOVER", []);
  8578. this.oApp.registerBrowserEvent(this.oDropdownLayer, "click", "EVENT_FONTNAME_LAYER_CLICKED", []);
  8579. },
  8580. /**
  8581. * 해당 글꼴이 존재하면 LI 요소를 보여주고 true 반환한다.
  8582. * @param {Element} el 글꼴리스트의 LI 요소
  8583. * @param {String} sFontName 확인할 글꼴이름
  8584. * @return {Boolean} LI 요소가 있고 글꼴이 OS에 존재하면 true 반환
  8585. */
  8586. _checkFontLI : function(el, sFontName){
  8587. if(!el){
  8588. return false;
  8589. }
  8590. var bInstalled = IsInstalledFont(sFontName);
  8591. el.style.display = bInstalled ? "block" : "none";
  8592. return bInstalled;
  8593. },
  8594. /**
  8595. * 마크업에 있는 글꼴 목록을 추가해준다.
  8596. */
  8597. _addFontInMarkup : function(){
  8598. for(var i = 0, elLi, sFontFamily, elSeparator, bUseSeparator; (elLi = this.aelFontInMarkup[i]); i++){
  8599. if(elLi.firstChild){
  8600. sFontFamily = this._getFontFamilyFromLI(elLi).replace(this._rxQuote, "").replace(this._rxComma, ",");
  8601. // 폰트패밀리값으로 OS에 폰트가 설치되어있는지 확인하여 노출하고 노출되면 구분선노출플래그를 true 로 세팅한다.
  8602. bUseSeparator |= this._checkFontLI(elLi, sFontFamily);
  8603. }else if(elLi.className.indexOf(this.FONT_SEPARATOR) > -1){
  8604. if(elSeparator){ // 이전에 구분선이 있었으면 구분선 노출여부 판단
  8605. elSeparator.style.display = bUseSeparator ? "block" : "none";
  8606. }
  8607. elSeparator = elLi; // 새로운 구분선 저장
  8608. bUseSeparator = false; // 구분선노출플래그 리셋
  8609. }else{
  8610. elLi.style.display = "none";
  8611. }
  8612. }
  8613. // 마지막 구분선 노출여부를 확인한다.
  8614. if(elSeparator){
  8615. elSeparator.style.display = bUseSeparator ? "block" : "none";
  8616. }
  8617. },
  8618. _attachIEEvent : function(){
  8619. if(!this.htBrowser.ie){
  8620. return;
  8621. }
  8622. if(this.htBrowser.nativeVersion < 9){ // [SMARTEDITORSUS-187] [< IE9] 최초 paste 시점에 웹폰트 파일을 로드
  8623. this._wfOnPasteWYSIWYGBody = jindo.$Fn(this._onPasteWYSIWYGBody, this);
  8624. this._wfOnPasteWYSIWYGBody.attach(this.oApp.getWYSIWYGDocument().body, "paste");
  8625. return;
  8626. }
  8627. if(document.documentMode < 9){ // [SMARTEDITORSUS-169] [>= IE9] 최초 포커스 시점에 웹폰트 로드
  8628. this._wfOnFocusWYSIWYGBody = jindo.$Fn(this._onFocusWYSIWYGBody, this);
  8629. this._wfOnFocusWYSIWYGBody.attach(this.oApp.getWYSIWYGDocument().body, "focus");
  8630. return;
  8631. }
  8632. // documentMode === 9
  8633. // http://blogs.msdn.com/b/ie/archive/2010/08/17/ie9-opacity-and-alpha.aspx // opacity:0.0;
  8634. this.welEditingAreaCover = jindo.$Element('<DIV style="width:100%; height:100%; position:absolute; top:0px; left:0px; z-index:1000;"></DIV>');
  8635. this.oApp.welEditingAreaContainer.prepend(this.welEditingAreaCover);
  8636. jindo.$Fn(this._onMouseupCover, this).attach(this.welEditingAreaCover.$value(), "mouseup");
  8637. },
  8638. _onFocusWYSIWYGBody : function(e){
  8639. this._wfOnFocusWYSIWYGBody.detach(this.oApp.getWYSIWYGDocument().body, "focus");
  8640. this._loadAllBaseFont();
  8641. },
  8642. _onPasteWYSIWYGBody : function(e){
  8643. this._wfOnPasteWYSIWYGBody.detach(this.oApp.getWYSIWYGDocument().body, "paste");
  8644. this._loadAllBaseFont();
  8645. },
  8646. _onMouseupCover : function(e){
  8647. e.stop();
  8648. // [SMARTEDITORSUS-1632] 문서 모드가 9 이상일 때, 경우에 따라 this.welEditingAreaContainer가 없을 때 스크립트 오류 발생
  8649. if(this.welEditingAreaCover){
  8650. this.welEditingAreaCover.leave();
  8651. }
  8652. //this.welEditingAreaCover.leave();
  8653. // --[SMARTEDITORSUS-1632]
  8654. var oMouse = e.mouse(),
  8655. elBody = this.oApp.getWYSIWYGDocument().body,
  8656. welBody = jindo.$Element(elBody),
  8657. oSelection = this.oApp.getEmptySelection();
  8658. // [SMARTEDITORSUS-363] 강제로 Selection 을 주도록 처리함
  8659. oSelection.selectNode(elBody);
  8660. oSelection.collapseToStart();
  8661. oSelection.select();
  8662. welBody.fireEvent("mousedown", {left : oMouse.left, middle : oMouse.middle, right : oMouse.right});
  8663. welBody.fireEvent("mouseup", {left : oMouse.left, middle : oMouse.middle, right : oMouse.right});
  8664. /**
  8665. * [SMARTEDITORSUS-1691]
  8666. * [IE 10-] 에디터가 초기화되고 나서 <p></p> innerHTML ,
  8667. * 경우 실제 커서는 <p></p> .
  8668. * 따라서 임시 북마크를 사용해서 <p></p> .
  8669. *
  8670. * [SMARTEDITORSUS-1781]
  8671. * [IE 11] 문서 모드가 Edge인 경우에 한하여
  8672. * <p><br></p> innerHTML ,
  8673. * 실제 커서는 <p><br></p> .
  8674. * 경우에는 임시 북마크를 삽입할 필요 없이 <br> 앞에 커서를 위치시켜 준다.
  8675. * */
  8676. if(this.oApp.oNavigator.ie && document.documentMode < 11 && this.oApp.getEditingMode() === "WYSIWYG"){
  8677. if(this.oApp.getWYSIWYGDocument().body.innerHTML == "<p></p>"){
  8678. this.oApp.getWYSIWYGDocument().body.innerHTML = '<p><span id="husky_bookmark_start_INIT"></span><span id="husky_bookmark_end_INIT"></span></p>';
  8679. var oSelection = this.oApp.getSelection();
  8680. oSelection.moveToStringBookmark("INIT");
  8681. oSelection.select();
  8682. oSelection.removeStringBookmark("INIT");
  8683. }
  8684. }else if(this.oApp.oNavigator.ie && this.oApp.oNavigator.nativeVersion == 11 && document.documentMode == 11 && this.oApp.getEditingMode() === "WYSIWYG"){
  8685. if(this.oApp.getWYSIWYGDocument().body.innerHTML == "<p><br></p>"){
  8686. var elCursorHolder_br = jindo.$$.getSingle("br", elBody);
  8687. oSelection.setStartBefore(elCursorHolder_br);
  8688. oSelection.setEndBefore(elCursorHolder_br);
  8689. oSelection.select();
  8690. }
  8691. }
  8692. // --[SMARTEDITORSUS-1781][SMARTEDITORSUS-1691]
  8693. },
  8694. $ON_EVENT_TOOLBAR_MOUSEDOWN : function(){
  8695. if(this.htBrowser.nativeVersion < 9 || document.documentMode < 9){
  8696. return;
  8697. }
  8698. // [SMARTEDITORSUS-1632] 문서 모드가 9 이상일 때, 경우에 따라 this.welEditingAreaContainer가 없을 때 스크립트 오류 발생
  8699. if(this.welEditingAreaCover){
  8700. this.welEditingAreaCover.leave();
  8701. }
  8702. //this.welEditingAreaCover.leave();
  8703. // --[SMARTEDITORSUS-1632]
  8704. },
  8705. _loadAllBaseFont : function(){
  8706. var i, nFontLen;
  8707. if(!this.htBrowser.ie){
  8708. return;
  8709. }
  8710. if(this.htBrowser.nativeVersion < 9){
  8711. for(i=0, nFontLen=this.aBaseFontList.length; i<nFontLen; i++){
  8712. this.aBaseFontList[i].loadCSS(this.oApp.getWYSIWYGDocument());
  8713. }
  8714. }else if(document.documentMode < 9){
  8715. for(i=0, nFontLen=this.aBaseFontList.length; i<nFontLen; i++){
  8716. this.aBaseFontList[i].loadCSSToMenu();
  8717. }
  8718. }
  8719. this._loadAllBaseFont = function(){};
  8720. },
  8721. _addFontToMenu: function(sDisplayName, sFontFamily, sSampleText){
  8722. var elItem = document.createElement("LI");
  8723. elItem.innerHTML = this.elFontItemTemplate.innerHTML.replace("@DisplayName@", sDisplayName).replace("FontFamily", sFontFamily).replace("@SampleText@", sSampleText);
  8724. this.elFontNameList.insertBefore(elItem, this.elFontItemTemplate);
  8725. this.aLIFontNames[this.aLIFontNames.length] = elItem;
  8726. if(this.aLIFontNames.length > 20){
  8727. this.oDropdownLayer.style.overflowX = 'hidden';
  8728. this.oDropdownLayer.style.overflowY = 'auto';
  8729. this.oDropdownLayer.style.height = '400px';
  8730. this.oDropdownLayer.style.width = '204px'; // [SMARTEDITORSUS-155] 스크롤을 포함하여 206px 이 되도록 처리
  8731. }
  8732. },
  8733. $ON_EVENT_FONTNAME_LAYER_MOUSEOVER : function(wev){
  8734. var elTmp = this._findLI(wev.element);
  8735. if(!elTmp){
  8736. return;
  8737. }
  8738. this._clearLastHover();
  8739. elTmp.className = "hover";
  8740. this.elLastHover = elTmp;
  8741. },
  8742. $ON_EVENT_FONTNAME_LAYER_CLICKED : function(wev){
  8743. var elTmp = this._findLI(wev.element);
  8744. if(!elTmp){
  8745. return;
  8746. }
  8747. var sFontFamily = this._getFontFamilyFromLI(elTmp);
  8748. // [SMARTEDITORSUS-169] 웹폰트의 경우 fontFamily 에 ' 을 붙여주는 처리를 함
  8749. var htFontInfo = this.htAllFonts[sFontFamily.replace(/\"/g, nhn.husky.SE2M_FontNameWithLayerUI.CUSTOM_FONT_MARKS)];
  8750. var nDefaultFontSize;
  8751. if(htFontInfo){
  8752. nDefaultFontSize = htFontInfo.defaultSize+"pt";
  8753. }else{
  8754. nDefaultFontSize = 0;
  8755. }
  8756. this.oApp.exec("SET_FONTFAMILY", [sFontFamily, nDefaultFontSize]);
  8757. },
  8758. _findLI : function(elTmp){
  8759. while(elTmp.tagName != "LI"){
  8760. if(!elTmp || elTmp === this.oDropdownLayer){
  8761. return null;
  8762. }
  8763. elTmp = elTmp.parentNode;
  8764. }
  8765. if(elTmp.className.indexOf(this.FONT_SEPARATOR) > -1){
  8766. return null;
  8767. }
  8768. return elTmp;
  8769. },
  8770. _clearLastHover : function(){
  8771. if(this.elLastHover){
  8772. this.elLastHover.className = "";
  8773. }
  8774. },
  8775. $ON_SE2M_TOGGLE_FONTNAME_LAYER : function(){
  8776. this.oApp.exec("TOGGLE_TOOLBAR_ACTIVE_LAYER", [this.oDropdownLayer, null, "MSG_FONTNAME_LAYER_OPENED", [], "MSG_FONTNAME_LAYER_CLOSED", []]);
  8777. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['font']);
  8778. },
  8779. $ON_MSG_FONTNAME_LAYER_OPENED : function(){
  8780. this.oApp.exec("SELECT_UI", ["fontName"]);
  8781. },
  8782. $ON_MSG_FONTNAME_LAYER_CLOSED : function(){
  8783. this._clearLastHover();
  8784. this.oApp.exec("DESELECT_UI", ["fontName"]);
  8785. },
  8786. $ON_MSG_STYLE_CHANGED : function(sAttributeName, sAttributeValue){
  8787. if(sAttributeName == "fontFamily"){
  8788. sAttributeValue = sAttributeValue.replace(/["']/g, "");
  8789. var elLi = this._getMatchingLI(sAttributeValue);
  8790. this._clearFontNameSelection();
  8791. if(elLi){
  8792. this.elFontNameLabel.innerHTML = this._getFontNameLabelFromLI(elLi);
  8793. jindo.$Element(elLi).addClass("active");
  8794. }else{
  8795. //var sDisplayName = this.htFamilyName2DisplayName[sAttributeValue] || sAttributeValue;
  8796. var sDisplayName = this.sDefaultText;
  8797. this.elFontNameLabel.innerHTML = sDisplayName;
  8798. }
  8799. }
  8800. },
  8801. $BEFORE_RECORD_UNDO_BEFORE_ACTION : function(){
  8802. return !this.bDoNotRecordUndo;
  8803. },
  8804. $BEFORE_RECORD_UNDO_AFTER_ACTION : function(){
  8805. return !this.bDoNotRecordUndo;
  8806. },
  8807. $BEFORE_RECORD_UNDO_ACTION : function(){
  8808. return !this.bDoNotRecordUndo;
  8809. },
  8810. $ON_SET_FONTFAMILY : function(sFontFamily, sDefaultSize){
  8811. if(!sFontFamily){return;}
  8812. // [SMARTEDITORSUS-169] 웹폰트의 경우 fontFamily 에 ' 을 붙여주는 처리를 함
  8813. var oFontInfo = this.htAllFonts[sFontFamily.replace(/\"/g, nhn.husky.SE2M_FontNameWithLayerUI.CUSTOM_FONT_MARKS)];
  8814. if(!!oFontInfo){
  8815. oFontInfo.loadCSS(this.oApp.getWYSIWYGDocument());
  8816. }
  8817. // fontFamily와 fontSize 두개의 액션을 하나로 묶어서 undo history 저장
  8818. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["SET FONTFAMILY", {bMustBlockElement:true}]);
  8819. this.bDoNotRecordUndo = true;
  8820. if(parseInt(sDefaultSize, 10) > 0){
  8821. this.oApp.exec("SET_WYSIWYG_STYLE", [{"fontSize":sDefaultSize}]);
  8822. }
  8823. this.oApp.exec("SET_WYSIWYG_STYLE", [{"fontFamily":sFontFamily}]);
  8824. this.bDoNotRecordUndo = false;
  8825. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["SET FONTFAMILY", {bMustBlockElement:true}]);
  8826. this.oApp.exec("HIDE_ACTIVE_LAYER", []);
  8827. this.oApp.exec("CHECK_STYLE_CHANGE", []);
  8828. },
  8829. _getMatchingLI : function(sFontName){
  8830. sFontName = sFontName.toLowerCase();
  8831. var elLi, aFontFamily;
  8832. for(var i=0; i<this.aLIFontNames.length; i++){
  8833. elLi = this.aLIFontNames[i];
  8834. aFontFamily = this._getFontFamilyFromLI(elLi).toLowerCase().split(",");
  8835. for(var h=0; h < aFontFamily.length;h++){
  8836. if( !!aFontFamily[h] && jindo.$S(aFontFamily[h].replace(/['"]/ig, "")).trim().$value() == sFontName){
  8837. return elLi;
  8838. }
  8839. }
  8840. }
  8841. return null;
  8842. },
  8843. _getFontFamilyFromLI : function(elLi){
  8844. //return elLi.childNodes[1].innerHTML.toLowerCase();
  8845. // <li><button type="button"><span>돋음</span>(</span><em style="font-family:'돋음',Dotum,'굴림',Gulim,Helvetica,Sans-serif;">돋음</em><span>)</span></span></button></li>
  8846. return (elLi.getElementsByTagName("EM")[0]).style.fontFamily;
  8847. },
  8848. _getFontNameLabelFromLI : function(elLi){
  8849. return elLi.firstChild.firstChild.firstChild.nodeValue;
  8850. },
  8851. _clearFontNameSelection : function(elLi){
  8852. for(var i=0; i<this.aLIFontNames.length; i++){
  8853. jindo.$Element(this.aLIFontNames[i]).removeClass("active");
  8854. }
  8855. },
  8856. /**
  8857. * Add the font to the list
  8858. * @param fontId {String} value of font-family in style
  8859. * @param fontName {String} name of font list in editor
  8860. * @param defaultSize
  8861. * @param fontURL
  8862. * @param fontCSSURL
  8863. * @param fontType fontType == null, custom font (sent from the server)
  8864. * fontType == 1, default font
  8865. * fontType == 2, tempSavedFont
  8866. * @param sSampleText {String} sample text of font list in editor
  8867. * @param bCheck {Boolean}
  8868. */
  8869. addFont : function (fontId, fontName, defaultSize, fontURL, fontCSSURL, fontType, sSampleText, bCheck) {
  8870. // custom font feature only available in IE
  8871. if(!this.htBrowser.ie && fontCSSURL){
  8872. return null;
  8873. }
  8874. // OS에 해당 폰트가 존재하는지 여부를 확인한다.
  8875. if(bCheck && !IsInstalledFont(fontId)){
  8876. return null;
  8877. }
  8878. // [SMARTEDITORSUS-2235] 폰트패밀리가 대소문자 구분되어 삽입될 수 있도록 주석처리
  8879. //fontId = fontId.toLowerCase();
  8880. var newFont = new fontProperty(fontId, fontName, defaultSize, fontURL, fontCSSURL);
  8881. var sFontFamily;
  8882. var sDisplayName;
  8883. if(defaultSize>0){
  8884. sFontFamily = fontId+"_"+defaultSize;
  8885. sDisplayName = fontName+"_"+defaultSize;
  8886. }else{
  8887. sFontFamily = fontId;
  8888. sDisplayName = fontName;
  8889. }
  8890. if(!fontType){
  8891. sFontFamily = nhn.husky.SE2M_FontNameWithLayerUI.CUSTOM_FONT_MARKS + sFontFamily + nhn.husky.SE2M_FontNameWithLayerUI.CUSTOM_FONT_MARKS;
  8892. }
  8893. if(this.htAllFonts[sFontFamily]){
  8894. return this.htAllFonts[sFontFamily];
  8895. }
  8896. this.htAllFonts[sFontFamily] = newFont;
  8897. /*
  8898. // do not add again, if the font is already in the list
  8899. for(var i=0; i<this._allFontList.length; i++){
  8900. if(newFont.fontFamily == this._allFontList[i].fontFamily){
  8901. return this._allFontList[i];
  8902. }
  8903. }
  8904. this._allFontList[this._allFontList.length] = newFont;
  8905. */
  8906. // [SMARTEDITORSUS-169] [IE9] 웹폰트A 선택>웹폰트B 선택>웹폰트 A를 다시 선택하면 웹폰트 A가 적용되지 않는 문제가 발생
  8907. //
  8908. // [원인]
  8909. // - IE9의 웹폰트 로드/언로드 시점
  8910. // 웹폰트 로드 시점: StyleSheet 의 @font-face 구문이 해석된 이후, DOM Tree 상에서 해당 웹폰트가 최초로 사용된 시점
  8911. // 웹폰트 언로드 시점: StyleSheet 의 @font-face 구문이 해석된 이후, DOM Tree 상에서 해당 웬폰트가 더이상 사용되지 않는 시점
  8912. // - 메뉴 리스트에 적용되는 스타일은 @font-face 이전에 처리되는 것이어서 언로드에 영향을 미치지 않음
  8913. //
  8914. // 스마트에디터의 경우, 웹폰트를 선택할 때마다 SPAN 이 새로 추가되는 것이 아닌 선택된 SPAN 의 fontFamily 를 변경하여 처리하므로
  8915. // fontFamily 변경 후 DOM Tree 상에서 더이상 사용되지 않는 것으로 브라우저 판단하여 언로드 해버림.
  8916. // [해결]
  8917. // 언로드가 발생하지 않도록 메뉴 리스트에 스타일을 적용하는 것을 @font-face 이후로 하도록 처리하여 DOM Tree 상에 항상 적용될 수 있도록 함
  8918. //
  8919. // [SMARTEDITORSUS-969] [IE10] 웹폰트를 사용하여 글을 등록하고, 수정모드로 들어갔을 때 웹폰트가 적용되지 않는 문제
  8920. // - IE10에서도 웹폰트 언로드가 발생하지 않도록 조건을 수정함
  8921. // -> 기존 : nativeVersion === 9 && documentMode === 9
  8922. // -> 수정 : nativeVersion >= 9 && documentMode >= 9
  8923. if(this.htBrowser.ie && this.htBrowser.nativeVersion >= 9 && document.documentMode >= 9) {
  8924. newFont.loadCSSToMenu();
  8925. }
  8926. this.htFamilyName2DisplayName[sFontFamily] = fontName;
  8927. sSampleText = sSampleText || this.oApp.$MSG('SE2M_FontNameWithLayerUI.sSampleText');
  8928. this._addFontToMenu(sDisplayName, sFontFamily, sSampleText);
  8929. if(!fontType){
  8930. this.aBaseFontList[this.aBaseFontList.length] = newFont;
  8931. }else{
  8932. if(fontType == 1){
  8933. this.aDefaultFontList[this.aDefaultFontList.length] = newFont;
  8934. }else{
  8935. this.aTempSavedFontList[this.aTempSavedFontList.length] = newFont;
  8936. }
  8937. }
  8938. return newFont;
  8939. },
  8940. // Add the font AND load it right away
  8941. addFontInUse : function (fontId, fontName, defaultSize, fontURL, fontCSSURL, fontType) {
  8942. var newFont = this.addFont(fontId, fontName, defaultSize, fontURL, fontCSSURL, fontType);
  8943. if(!newFont){
  8944. return null;
  8945. }
  8946. newFont.loadCSS(this.oApp.getWYSIWYGDocument());
  8947. return newFont;
  8948. },
  8949. // Add the font AND load it right away AND THEN set it as the default font
  8950. setMainFont : function (fontId, fontName, defaultSize, fontURL, fontCSSURL, fontType) {
  8951. var newFont = this.addFontInUse(fontId, fontName, defaultSize, fontURL, fontCSSURL, fontType);
  8952. if(!newFont){
  8953. return null;
  8954. }
  8955. this.setDefaultFont(newFont.fontFamily, defaultSize);
  8956. return newFont;
  8957. },
  8958. setDefaultFont : function(sFontFamily, nFontSize){
  8959. var elBody = this.oApp.getWYSIWYGDocument().body;
  8960. elBody.style.fontFamily = sFontFamily;
  8961. if(nFontSize>0){elBody.style.fontSize = nFontSize + 'pt';}
  8962. }
  8963. });
  8964. nhn.husky.SE2M_FontNameWithLayerUI.CUSTOM_FONT_MARKS = "'"; // [SMARTEDITORSUS-169] 웹폰트의 경우 fontFamily 에 ' 을 붙여주는 처리를 함
  8965. // property function for all fonts - including the default fonts and the custom fonts
  8966. // non-custom fonts will have the defaultSize of 0 and empty string for fontURL/fontCSSURL
  8967. function fontProperty(fontId, fontName, defaultSize, fontURL, fontCSSURL){
  8968. this.fontId = fontId;
  8969. this.fontName = fontName;
  8970. this.defaultSize = defaultSize;
  8971. this.fontURL = fontURL;
  8972. this.fontCSSURL = fontCSSURL;
  8973. this.displayName = fontName;
  8974. this.isLoaded = true;
  8975. this.fontFamily = this.fontId;
  8976. // it is custom font
  8977. if(this.fontCSSURL != ""){
  8978. this.displayName += '' + defaultSize;
  8979. this.fontFamily += '_' + defaultSize;
  8980. // custom fonts requires css loading
  8981. this.isLoaded = false;
  8982. // load the css that loads the custom font
  8983. this.loadCSS = function(doc){
  8984. // if the font is loaded already, return
  8985. if(this.isLoaded){
  8986. return;
  8987. }
  8988. this._importCSS(doc);
  8989. this.isLoaded = true;
  8990. };
  8991. // [SMARTEDITORSUS-169] [IE9]
  8992. // addImport 후에 처음 적용된 DOM-Tree 가 iframe 내부인 경우 (setMainFont || addFontInUse 에서 호출된 경우)
  8993. // 해당 폰트에 대한 언로드 문제가 계속 발생하여 IE9에서 addFont 에서 호출하는 loadCSS 의 경우에는 isLoaded를 true 로 변경하지 않음.
  8994. this.loadCSSToMenu = function(){
  8995. this._importCSS(document);
  8996. };
  8997. this._importCSS = function(doc){
  8998. var nStyleSheet = doc.styleSheets.length;
  8999. var oStyleSheet = doc.styleSheets[nStyleSheet - 1];
  9000. if(nStyleSheet === 0 || oStyleSheet.imports.length > 30){ // imports limit
  9001. // [SMARTEDITORSUS-1828] IE11에서 document.createStyleSheet API가 제거되었음
  9002. // [SMARTEDITORSUS-2181] createStyleSheet 를 사용하면 순서보장이 안되어 createElement("style") 로 삽입하는 방식만 사용
  9003. // 참고1 : http://msdn.microsoft.com/en-us/library/ie/bg182625(v=vs.85).aspx#legacyapis
  9004. // 참고2 : http://msdn.microsoft.com/en-us/library/ie/ms531194(v=vs.85).aspx
  9005. oStyleSheet = doc.createElement("style");
  9006. doc.documentElement.firstChild.appendChild(oStyleSheet);
  9007. // [SMARTEDITORSUS-2189] sheet은 모던브라우저, IE9이상부터 지원 (IE8이하는 styleSheet 으로 가져와야함)
  9008. // 참고 : http://help.dottoro.com/ljpatulu.php
  9009. oStyleSheet = oStyleSheet.sheet || oStyleSheet.styleSheet;
  9010. }
  9011. oStyleSheet.addImport(this.fontCSSURL);
  9012. };
  9013. }else{
  9014. this.loadCSS = function(){};
  9015. this.loadCSSToMenu = function(){};
  9016. }
  9017. this.toStruct = function(){
  9018. return {fontId:this.fontId, fontName:this.fontName, defaultSize:this.defaultSize, fontURL:this.fontURL, fontCSSURL:this.fontCSSURL};
  9019. };
  9020. }
  9021. /**
  9022. * ColorPicker Component
  9023. * @author gony
  9024. */
  9025. nhn.ColorPicker = jindo.$Class({
  9026. elem : null,
  9027. huePanel : null,
  9028. canvasType : "Canvas",
  9029. _hsvColor : null,
  9030. $init : function(oElement, oOptions) {
  9031. this.elem = jindo.$Element(oElement).empty();
  9032. this.huePanel = null;
  9033. this.cursor = jindo.$Element("<div>").css("overflow", "hidden");
  9034. this.canvasType = jindo.$(oElement).filters?"Filter":jindo.$("<canvas>").getContext?"Canvas":null;
  9035. if(!this.canvasType) {
  9036. return false;
  9037. }
  9038. this.option({
  9039. huePanel : null,
  9040. huePanelType : "horizontal"
  9041. });
  9042. this.option(oOptions);
  9043. if (this.option("huePanel")) {
  9044. this.huePanel = jindo.$Element(this.option("huePanel")).empty();
  9045. }
  9046. // rgb
  9047. this._hsvColor = this._hsv(0,100,100); // #FF0000
  9048. // event binding
  9049. for(var name in this) {
  9050. if (/^_on[A-Z][a-z]+[A-Z][a-z]+$/.test(name)) {
  9051. this[name+"Fn"] = jindo.$Fn(this[name], this);
  9052. }
  9053. }
  9054. this._onDownColorFn.attach(this.elem, "mousedown");
  9055. if (this.huePanel) {
  9056. this._onDownHueFn.attach(this.huePanel, "mousedown");
  9057. }
  9058. // paint
  9059. this.paint();
  9060. },
  9061. rgb : function(rgb) {
  9062. this.hsv(this._rgb2hsv(rgb.r, rgb.g, rgb.b));
  9063. },
  9064. hsv : function(hsv) {
  9065. if (typeof hsv == "undefined") {
  9066. return this._hsvColor;
  9067. }
  9068. var rgb = null;
  9069. var w = this.elem.width();
  9070. var h = this.elem.height();
  9071. var cw = this.cursor.width();
  9072. var ch = this.cursor.height();
  9073. var x = 0, y = 0;
  9074. if (this.huePanel) {
  9075. rgb = this._hsv2rgb(hsv.h, 100, 100);
  9076. this.elem.css("background", "#"+this._rgb2hex(rgb.r, rgb.g, rgb.b));
  9077. x = hsv.s/100 * w;
  9078. y = (100-hsv.v)/100 * h;
  9079. } else {
  9080. var hw = w / 2;
  9081. if (hsv.v > hsv.s) {
  9082. hsv.v = 100;
  9083. x = hsv.s/100 * hw;
  9084. } else {
  9085. hsv.s = 100;
  9086. x = (100-hsv.v)/100 * hw + hw;
  9087. }
  9088. y = hsv.h/360 * h;
  9089. }
  9090. x = Math.max(Math.min(x-1,w-cw), 1);
  9091. y = Math.max(Math.min(y-1,h-ch), 1);
  9092. this.cursor.css({left:x+"px",top:y+"px"});
  9093. this._hsvColor = hsv;
  9094. rgb = this._hsv2rgb(hsv.h, hsv.s, hsv.v);
  9095. this.fireEvent("colorchange", {type:"colorchange", element:this, currentElement:this, rgbColor:rgb, hexColor:"#"+this._rgb2hex(rgb.r, rgb.g, rgb.b), hsvColor:hsv} );
  9096. },
  9097. paint : function() {
  9098. if (this.huePanel) {
  9099. // paint color panel
  9100. this["_paintColWith"+this.canvasType]();
  9101. // paint hue panel
  9102. this["_paintHueWith"+this.canvasType]();
  9103. } else {
  9104. // paint color panel
  9105. this["_paintOneWith"+this.canvasType]();
  9106. }
  9107. // draw cursor
  9108. this.cursor.appendTo(this.elem);
  9109. this.cursor.css({position:"absolute",top:"1px",left:"1px",background:"white",border:"1px solid black"}).width(3).height(3);
  9110. this.hsv(this._hsvColor);
  9111. },
  9112. _paintColWithFilter : function() {
  9113. // white : left to right
  9114. jindo.$Element("<div>").css({
  9115. position : "absolute",
  9116. top : 0,
  9117. left : 0,
  9118. width : "100%",
  9119. height : "100%",
  9120. filter : "progid:DXImageTransform.Microsoft.Gradient(GradientType=1,StartColorStr='#FFFFFFFF',EndColorStr='#00FFFFFF')"
  9121. }).appendTo(this.elem);
  9122. // black : down to up
  9123. jindo.$Element("<div>").css({
  9124. position : "absolute",
  9125. top : 0,
  9126. left : 0,
  9127. width : "100%",
  9128. height : "100%",
  9129. filter : "progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#00000000',EndColorStr='#FF000000')"
  9130. }).appendTo(this.elem);
  9131. },
  9132. _paintColWithCanvas : function() {
  9133. var cvs = jindo.$Element("<canvas>").css({width:"100%",height:"100%"});
  9134. cvs.appendTo(this.elem.empty());
  9135. var ctx = cvs.attr("width", cvs.width()).attr("height", cvs.height()).$value().getContext("2d");
  9136. var lin = null;
  9137. var w = cvs.width();
  9138. var h = cvs.height();
  9139. // white : left to right
  9140. lin = ctx.createLinearGradient(0,0,w,0);
  9141. lin.addColorStop(0, "rgba(255,255,255,1)");
  9142. lin.addColorStop(1, "rgba(255,255,255,0)");
  9143. ctx.fillStyle = lin;
  9144. ctx.fillRect(0,0,w,h);
  9145. // black : down to top
  9146. lin = ctx.createLinearGradient(0,0,0,h);
  9147. lin.addColorStop(0, "rgba(0,0,0,0)");
  9148. lin.addColorStop(1, "rgba(0,0,0,1)");
  9149. ctx.fillStyle = lin;
  9150. ctx.fillRect(0,0,w,h);
  9151. },
  9152. _paintOneWithFilter : function() {
  9153. var sp, ep, s_rgb, e_rgb, s_hex, e_hex;
  9154. var h = this.elem.height();
  9155. for(var i=1; i < 7; i++) {
  9156. sp = Math.floor((i-1)/6 * h);
  9157. ep = Math.floor(i/6 * h);
  9158. s_rgb = this._hsv2rgb((i-1)/6*360, 100, 100);
  9159. e_rgb = this._hsv2rgb(i/6*360, 100, 100);
  9160. s_hex = "#FF"+this._rgb2hex(s_rgb.r, s_rgb.g, s_rgb.b);
  9161. e_hex = "#FF"+this._rgb2hex(e_rgb.r, e_rgb.g, e_rgb.b);
  9162. jindo.$Element("<div>").css({
  9163. position : "absolute",
  9164. left : 0,
  9165. width : "100%",
  9166. top : sp + "px",
  9167. height : (ep-sp) + "px",
  9168. filter : "progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='"+s_hex+"',EndColorStr='"+e_hex+"')"
  9169. }).appendTo(this.elem);
  9170. }
  9171. // white : left to right
  9172. jindo.$Element("<div>").css({
  9173. position : "absolute",
  9174. top : 0,
  9175. left : 0,
  9176. width : "50%",
  9177. height : "100%",
  9178. filter : "progid:DXImageTransform.Microsoft.Gradient(GradientType=1,StartColorStr='#FFFFFFFF',EndColorStr='#00FFFFFF')"
  9179. }).appendTo(this.elem);
  9180. // black : down to up
  9181. jindo.$Element("<div>").css({
  9182. position : "absolute",
  9183. top : 0,
  9184. right : 0,
  9185. width : "50%",
  9186. height : "100%",
  9187. filter : "progid:DXImageTransform.Microsoft.Gradient(GradientType=1,StartColorStr='#00000000',EndColorStr='#FF000000')"
  9188. }).appendTo(this.elem);
  9189. },
  9190. _paintOneWithCanvas : function() {
  9191. var rgb = {r:0, g:0, b:0};
  9192. var cvs = jindo.$Element("<canvas>").css({width:"100%",height:"100%"});
  9193. cvs.appendTo(this.elem.empty());
  9194. var ctx = cvs.attr("width", cvs.width()).attr("height", cvs.height()).$value().getContext("2d");
  9195. var w = cvs.width();
  9196. var h = cvs.height();
  9197. var lin = ctx.createLinearGradient(0,0,0,h);
  9198. for(var i=0; i < 7; i++) {
  9199. rgb = this._hsv2rgb(i/6*360, 100, 100);
  9200. lin.addColorStop(i/6, "rgb("+rgb.join(",")+")");
  9201. }
  9202. ctx.fillStyle = lin;
  9203. ctx.fillRect(0,0,w,h);
  9204. lin = ctx.createLinearGradient(0,0,w,0);
  9205. lin.addColorStop(0, "rgba(255,255,255,1)");
  9206. lin.addColorStop(0.5, "rgba(255,255,255,0)");
  9207. lin.addColorStop(0.5, "rgba(0,0,0,0)");
  9208. lin.addColorStop(1, "rgba(0,0,0,1)");
  9209. ctx.fillStyle = lin;
  9210. ctx.fillRect(0,0,w,h);
  9211. },
  9212. _paintHueWithFilter : function() {
  9213. var sp, ep, s_rgb, e_rgb, s_hex, e_hex;
  9214. var vert = (this.option().huePanelType == "vertical");
  9215. var w = this.huePanel.width();
  9216. var h = this.huePanel.height();
  9217. var elDiv = null;
  9218. var nPanelBorderWidth = parseInt(this.huePanel.css('borderWidth'), 10);
  9219. if (!!isNaN(nPanelBorderWidth)) { nPanelBorderWidth = 0; }
  9220. w -= nPanelBorderWidth * 2; // borderWidth를 제외한 내측 폭을 구함
  9221. for(var i=1; i < 7; i++) {
  9222. sp = Math.floor((i-1)/6 * (vert?h:w));
  9223. ep = Math.floor(i/6 * (vert?h:w));
  9224. s_rgb = this._hsv2rgb((i-1)/6*360, 100, 100);
  9225. e_rgb = this._hsv2rgb(i/6*360, 100, 100);
  9226. s_hex = "#FF"+this._rgb2hex(s_rgb.r, s_rgb.g, s_rgb.b);
  9227. e_hex = "#FF"+this._rgb2hex(e_rgb.r, e_rgb.g, e_rgb.b);
  9228. elDiv = jindo.$Element("<div>").css({
  9229. position : "absolute",
  9230. filter : "progid:DXImageTransform.Microsoft.Gradient(GradientType="+(vert?0:1)+",StartColorStr='"+s_hex+"',EndColorStr='"+e_hex+"')"
  9231. });
  9232. var width = (ep - sp) + 1; // IE에서 폭을 넓혀주지 않으면 확대 시 벌어짐, 그래서 1px 보정
  9233. elDiv.appendTo(this.huePanel);
  9234. elDiv.css(vert?"left":"top", 0).css(vert?"width":"height", '100%');
  9235. elDiv.css(vert?"top":"left", sp + "px").css(vert?"height":"width", width + "px");
  9236. }
  9237. },
  9238. _paintHueWithCanvas : function() {
  9239. var opt = this.option(), rgb;
  9240. var vtc = (opt.huePanelType == "vertical");
  9241. var cvs = jindo.$Element("<canvas>").css({width:"100%",height:"100%"});
  9242. cvs.appendTo(this.huePanel.empty());
  9243. var ctx = cvs.attr("width", cvs.width()).attr("height", cvs.height()).$value().getContext("2d");
  9244. var lin = ctx.createLinearGradient(0,0,vtc?0:cvs.width(),vtc?cvs.height():0);
  9245. for(var i=0; i < 7; i++) {
  9246. rgb = this._hsv2rgb(i/6*360, 100, 100);
  9247. lin.addColorStop(i/6, "rgb("+rgb.join(",")+")");
  9248. }
  9249. ctx.fillStyle = lin;
  9250. ctx.fillRect(0,0,cvs.width(),cvs.height());
  9251. },
  9252. _rgb2hsv : function(r,g,b) {
  9253. var h = 0, s = 0, v = Math.max(r,g,b), min = Math.min(r,g,b), delta = v - min;
  9254. s = (v ? delta/v : 0);
  9255. if (s) {
  9256. if (r == v) {
  9257. h = 60 * (g - b) / delta;
  9258. } else if (g == v) {
  9259. h = 120 + 60 * (b - r) / delta;
  9260. } else if (b == v) {
  9261. h = 240 + 60 * (r - g) / delta;
  9262. }
  9263. if (h < 0) {
  9264. h += 360;
  9265. }
  9266. }
  9267. h = Math.floor(h);
  9268. s = Math.floor(s * 100);
  9269. v = Math.floor(v / 255 * 100);
  9270. return this._hsv(h,s,v);
  9271. },
  9272. _hsv2rgb : function(h,s,v) {
  9273. h = (h % 360) / 60; s /= 100; v /= 100;
  9274. var r=0, g=0, b=0;
  9275. var i = Math.floor(h);
  9276. var f = h-i;
  9277. var p = v*(1-s);
  9278. var q = v*(1-s*f);
  9279. var t = v*(1-s*(1-f));
  9280. switch (i) {
  9281. case 0: r=v; g=t; b=p; break;
  9282. case 1: r=q; g=v; b=p; break;
  9283. case 2: r=p; g=v; b=t; break;
  9284. case 3: r=p; g=q; b=v; break;
  9285. case 4: r=t; g=p; b=v; break;
  9286. case 5: r=v; g=p; b=q;break;
  9287. case 6: break;
  9288. }
  9289. r = Math.floor(r*255);
  9290. g = Math.floor(g*255);
  9291. b = Math.floor(b*255);
  9292. return this._rgb(r,g,b);
  9293. },
  9294. _rgb2hex : function(r,g,b) {
  9295. r = r.toString(16);
  9296. if (r.length == 1) {
  9297. r = '0'+r;
  9298. }
  9299. g = g.toString(16);
  9300. if (g.length==1) {
  9301. g = '0'+g;
  9302. }
  9303. b = b.toString(16);
  9304. if (b.length==1) {
  9305. b = '0'+b;
  9306. }
  9307. return r+g+b;
  9308. },
  9309. _hex2rgb : function(hex) {
  9310. var m = hex.match(/#?([0-9a-f]{6}|[0-9a-f]{3})/i);
  9311. if (m[1].length == 3) {
  9312. m = m[1].match(/./g).filter(function(c) {
  9313. return c+c;
  9314. });
  9315. } else {
  9316. m = m[1].match(/../g);
  9317. }
  9318. return {
  9319. r : Number("0x" + m[0]),
  9320. g : Number("0x" + m[1]),
  9321. b : Number("0x" + m[2])
  9322. };
  9323. },
  9324. _rgb : function(r,g,b) {
  9325. var ret = [r,g,b];
  9326. ret.r = r;
  9327. ret.g = g;
  9328. ret.b = b;
  9329. return ret;
  9330. },
  9331. _hsv : function(h,s,v) {
  9332. var ret = [h,s,v];
  9333. ret.h = h;
  9334. ret.s = s;
  9335. ret.v = v;
  9336. return ret;
  9337. },
  9338. _onDownColor : function(e) {
  9339. if (!e.mouse().left) {
  9340. return false;
  9341. }
  9342. var pos = e.pos();
  9343. this._colPagePos = [pos.pageX, pos.pageY];
  9344. this._colLayerPos = [pos.layerX, pos.layerY];
  9345. this._onUpColorFn.attach(document, "mouseup");
  9346. this._onMoveColorFn.attach(document, "mousemove");
  9347. this._onMoveColor(e);
  9348. },
  9349. _onUpColor : function(e) {
  9350. this._onUpColorFn.detach(document, "mouseup");
  9351. this._onMoveColorFn.detach(document, "mousemove");
  9352. },
  9353. _onMoveColor : function(e) {
  9354. var hsv = this._hsvColor;
  9355. var pos = e.pos();
  9356. var x = this._colLayerPos[0] + (pos.pageX - this._colPagePos[0]);
  9357. var y = this._colLayerPos[1] + (pos.pageY - this._colPagePos[1]);
  9358. var w = this.elem.width();
  9359. var h = this.elem.height();
  9360. x = Math.max(Math.min(x, w), 0);
  9361. y = Math.max(Math.min(y, h), 0);
  9362. if (this.huePanel) {
  9363. hsv.s = hsv[1] = x / w * 100;
  9364. hsv.v = hsv[2] = (h - y) / h * 100;
  9365. } else {
  9366. hsv.h = y/h*360;
  9367. var hw = w/2;
  9368. if (x < hw) {
  9369. hsv.s = x/hw * 100;
  9370. hsv.v = 100;
  9371. } else {
  9372. hsv.s = 100;
  9373. hsv.v = (w-x)/hw * 100;
  9374. }
  9375. }
  9376. this.hsv(hsv);
  9377. e.stop();
  9378. },
  9379. _onDownHue : function(e) {
  9380. if (!e.mouse().left) {
  9381. return false;
  9382. }
  9383. var pos = e.pos();
  9384. this._huePagePos = [pos.pageX, pos.pageY];
  9385. this._hueLayerPos = [pos.layerX, pos.layerY];
  9386. this._onUpHueFn.attach(document, "mouseup");
  9387. this._onMoveHueFn.attach(document, "mousemove");
  9388. this._onMoveHue(e);
  9389. },
  9390. _onUpHue : function(e) {
  9391. this._onUpHueFn.detach(document, "mouseup");
  9392. this._onMoveHueFn.detach(document, "mousemove");
  9393. },
  9394. _onMoveHue : function(e) {
  9395. var hsv = this._hsvColor;
  9396. var pos = e.pos();
  9397. var cur = 0, len = 0;
  9398. var x = this._hueLayerPos[0] + (pos.pageX - this._huePagePos[0]);
  9399. var y = this._hueLayerPos[1] + (pos.pageY - this._huePagePos[1]);
  9400. if (this.option().huePanelType == "vertical") {
  9401. cur = y;
  9402. len = this.huePanel.height();
  9403. } else {
  9404. cur = x;
  9405. len = this.huePanel.width();
  9406. }
  9407. hsv.h = hsv[0] = (Math.min(Math.max(cur, 0), len)/len * 360)%360;
  9408. this.hsv(hsv);
  9409. e.stop();
  9410. }
  9411. }).extend(jindo.Component);
  9412. //{
  9413. /**
  9414. * @fileOverview This file contains Husky plugin that takes care of Accessibility about SmartEditor2.
  9415. * @name hp_SE2M_Accessibility.js
  9416. */
  9417. nhn.husky.SE2M_Accessibility = jindo.$Class({
  9418. name : "SE2M_Accessibility",
  9419. /*
  9420. * elAppContainer : mandatory
  9421. * sLocale, sEditorType : optional
  9422. */
  9423. $init: function(elAppContainer, sLocale, sEditorType) {
  9424. this._assignHTMLElements(elAppContainer);
  9425. if(!!sLocale){
  9426. this.sLang = sLocale;
  9427. }
  9428. if(!!sEditorType){
  9429. this.sType = sEditorType;
  9430. }
  9431. },
  9432. _assignHTMLElements : function(elAppContainer){
  9433. this.elHelpPopupLayer = jindo.$$.getSingle("DIV.se2_accessibility", elAppContainer);
  9434. this.welHelpPopupLayer = jindo.$Element(this.elHelpPopupLayer);
  9435. //close buttons
  9436. this.oCloseButton = jindo.$$.getSingle("BUTTON.se2_close", this.elHelpPopupLayer);
  9437. this.oCloseButton2 = jindo.$$.getSingle("BUTTON.se2_close2", this.elHelpPopupLayer);
  9438. this.nDefaultTop = 150;
  9439. // [SMARTEDITORSUS-1594] 포커스 탐색에 사용하기 위해 할당
  9440. this.elAppContainer = elAppContainer;
  9441. // --[SMARTEDITORSUS-1594]
  9442. },
  9443. $ON_MSG_APP_READY : function(){
  9444. this.htAccessOption = nhn.husky.SE2M_Configuration.SE2M_Accessibility || {};
  9445. this.oApp.exec("REGISTER_HOTKEY", ["alt+F10", "FOCUS_TOOLBAR_AREA", []]);
  9446. this.oApp.exec("REGISTER_HOTKEY", ["alt+COMMA", "FOCUS_BEFORE_ELEMENT", []]);
  9447. this.oApp.exec("REGISTER_HOTKEY", ["alt+PERIOD", "FOCUS_NEXT_ELEMENT", []]);
  9448. if (this.sLang && this.sLang !== 'ko_KR') {
  9449. //do nothing
  9450. return;
  9451. } else {
  9452. this.oApp.exec("REGISTER_HOTKEY", ["alt+0", "OPEN_HELP_POPUP", []]);
  9453. //[SMARTEDITORSUS-1327] IE 7/8에서 ALT+0으로 팝업 띄우고 esc클릭시 팝업창 닫히게 하려면 아래 부분 꼭 필요함. (target은 document가 되어야 함!)
  9454. this.oApp.exec("REGISTER_HOTKEY", ["esc", "CLOSE_HELP_POPUP", [], document]);
  9455. }
  9456. //[SMARTEDITORSUS-1353]
  9457. if (this.htAccessOption.sTitleElementId) {
  9458. this.oApp.registerBrowserEvent(document.getElementById(this.htAccessOption.sTitleElementId), "keydown", "MOVE_TO_EDITAREA", []);
  9459. }
  9460. },
  9461. $ON_MOVE_TO_EDITAREA : function(weEvent) {
  9462. var TAB_KEY_CODE = 9;
  9463. if (weEvent.key().keyCode == TAB_KEY_CODE) {
  9464. if(weEvent.key().shift) {return;}
  9465. this.oApp.delayedExec("FOCUS", [], 0);
  9466. }
  9467. },
  9468. $LOCAL_BEFORE_FIRST : function(sMsg){
  9469. jindo.$Fn(jindo.$Fn(this.oApp.exec, this.oApp).bind("CLOSE_HELP_POPUP", [this.oCloseButton]), this).attach(this.oCloseButton, "click");
  9470. jindo.$Fn(jindo.$Fn(this.oApp.exec, this.oApp).bind("CLOSE_HELP_POPUP", [this.oCloseButton2]), this).attach(this.oCloseButton2, "click");
  9471. //레이어의 이동 범위 설정.
  9472. var elIframe = this.oApp.getWYSIWYGWindow().frameElement;
  9473. this.htOffsetPos = jindo.$Element(elIframe).offset();
  9474. this.nEditorWidth = elIframe.offsetWidth;
  9475. this.htInitialPos = this.welHelpPopupLayer.offset();
  9476. var htScrollXY = this.oApp.oUtils.getScrollXY();
  9477. this.nLayerWidth = 590;
  9478. this.nLayerHeight = 480;
  9479. this.htTopLeftCorner = {x:parseInt(this.htOffsetPos.left, 10), y:parseInt(this.htOffsetPos.top, 10)};
  9480. //[css markup] left:11 top:74로 되어 있음
  9481. },
  9482. /**
  9483. * [SMARTEDITORSUS-1594]
  9484. * SE2M_Configuration_General에서 포커스를 이동할 에디터 영역 이후의 엘레먼트를 지정해 두었다면, 설정값을 따른다.
  9485. * 지정하지 않았거나 String이라면, elAppContainer를 기준으로 자동 탐색한다.
  9486. * */
  9487. $ON_FOCUS_NEXT_ELEMENT : function() {
  9488. // 포커스 캐싱
  9489. this._currentNextFocusElement = null; // 새로운 포커스 이동이 발생할 때마다 캐싱 초기화
  9490. if(this.htAccessOption.sNextElementId){
  9491. this._currentNextFocusElement = document.getElementById(this.htAccessOption.sNextElementId);
  9492. }else{
  9493. this._currentNextFocusElement = this._findNextFocusElement(this.elAppContainer);
  9494. }
  9495. if(this._currentNextFocusElement){
  9496. window.focus(); // [SMARTEDITORSUS-1360] IE7에서는 element에 대한 focus를 주기 위해 선행되어야 한다.
  9497. this._currentNextFocusElement.focus();
  9498. }else if(parent && parent.nhn && parent.nhn.husky && parent.nhn.husky.EZCreator && parent.nhn.husky.EZCreator.elIFrame){
  9499. parent.focus();
  9500. if(this._currentNextFocusElement = this._findNextFocusElement(parent.nhn.husky.EZCreator.elIFrame)){
  9501. this._currentNextFocusElement.focus();
  9502. }
  9503. }
  9504. },
  9505. /**
  9506. * [SMARTEDITORSUS-1594] DIV#smart_editor2 다음 요소에서 가장 가까운 포커스용 태그를 탐색
  9507. * */
  9508. _findNextFocusElement : function(targetElement){
  9509. var target = null;
  9510. var el = targetElement.nextSibling;
  9511. while(el){
  9512. if(el.nodeType !== 1){ // Element Node만을 대상으로 한다.
  9513. // 대상 노드 대신 nextSibling을 찾되, 부모를 거슬러 올라갈 수도 있다.
  9514. // document.body까지 거슬러 올라가게 되면 탐색 종료
  9515. el = this._switchToSiblingOrNothing(el);
  9516. if(!el){
  9517. break;
  9518. }else{
  9519. continue;
  9520. }
  9521. }
  9522. // 대상 노드를 기준으로, 전위순회로 조건에 부합하는 노드 탐색
  9523. this._recursivePreorderTraversalFilter(el, this._isFocusTag);
  9524. if(this._nextFocusElement){
  9525. target = this._nextFocusElement;
  9526. // 탐색에 사용했던 변수 초기화
  9527. this._bStopFindingNextElement = false;
  9528. this._nextFocusElement = null;
  9529. break;
  9530. }else{
  9531. // 대상 노드 대신 nextSibling을 찾되, 부모를 거슬러 올라갈 수도 있다.
  9532. // document.body까지 거슬러 올라가게 되면 탐색 종료
  9533. el = this._switchToSiblingOrNothing(el);
  9534. if(!el){
  9535. break;
  9536. }
  9537. }
  9538. }
  9539. // target이 존재하지 않으면 null 반환
  9540. return target;
  9541. },
  9542. /**
  9543. * [SMARTEDITORSUS-1594] 대상 노드를 기준으로 하여, nextSibling 또는 previousSibling을 찾는다.
  9544. * nextSibling 또는 previousSibling이 없다면,
  9545. * 부모를 거슬러 올라가면서 nextSibling 또는 previousSibling을 찾는다.
  9546. * document의 body까지 올라가도 nextSibling 또는 previousSibling이 나타나지 않는다면
  9547. * 탐색 대상으로 null을 반환한다.
  9548. * @param {NodeElement} 대상 노드 (주의:NodeElement에 대한 null 체크 안함)
  9549. * @param {Boolean} 생략하거나 false이면 nextSibling을 찾고, true이면 previousSibling을 찾는다.
  9550. * */
  9551. _switchToSiblingOrNothing : function(targetElement, isPreviousOrdered){
  9552. var el = targetElement;
  9553. if(isPreviousOrdered){
  9554. if(el.previousSibling){
  9555. el = el.previousSibling;
  9556. }else{
  9557. // 형제가 없다면 부모를 거슬러 올라가면서 탐색
  9558. // 이 루프의 종료 조건
  9559. // 1. 부모를 거슬러 올라가다가 el이 document.body가 되는 시점
  9560. // - 더 이상 previousSibling을 탐색할 수 없음
  9561. // 2. el이 부모로 대체된 뒤 previousSibling이 존재하는 경우
  9562. while(el.nodeName.toUpperCase() != "BODY" && !el.previousSibling){
  9563. el = el.parentNode;
  9564. }
  9565. if(el.nodeName.toUpperCase() == "BODY"){
  9566. el = null;
  9567. }else{
  9568. el = el.previousSibling;
  9569. }
  9570. }
  9571. }else{
  9572. if(el.nextSibling){
  9573. el = el.nextSibling;
  9574. }else{
  9575. // 형제가 없다면 부모를 거슬러 올라가면서 탐색
  9576. // 이 루프의 종료 조건
  9577. // 1. 부모를 거슬러 올라가다가 el이 document.body가 되는 시점
  9578. // - 더 이상 nextSibling을 탐색할 수 없음
  9579. // 2. el이 부모로 대체된 뒤 nextSibling이 존재하는 경우
  9580. while(el.nodeName.toUpperCase() != "BODY" && !el.nextSibling){
  9581. el = el.parentNode;
  9582. }
  9583. if(el.nodeName.toUpperCase() == "BODY"){
  9584. el = null;
  9585. }else{
  9586. el = el.nextSibling;
  9587. }
  9588. }
  9589. }
  9590. return el;
  9591. },
  9592. /**
  9593. * [SMARTEDITORSUS-1594] 대상 노드를 기준으로 하는 트리를 전위순회를 거쳐, 필터 조건에 부합하는 노드를 찾는다.
  9594. * @param {NodeElement} 탐색하려는 트리의 루트 노드
  9595. * @param {Function} 필터 조건으로 사용할 함수
  9596. * @param {Boolean} 생략하거나 false이면 순수 전위순회(루트 - 좌측 - 우측 ) 탐색하고, true이면 반대 방향의 전위순회(루트 - 우측 - 좌측) 탐색한다.
  9597. * */
  9598. _recursivePreorderTraversalFilter : function(node, filterFunction, isReversed){
  9599. var self = this;
  9600. // 현재 노드를 기준으로 필터링
  9601. var _bStopFindingNextElement = filterFunction.apply(node);
  9602. if(_bStopFindingNextElement){
  9603. // 최초로 포커스 태그를 찾는다면 탐색 중단용 flag 변경
  9604. self._bStopFindingNextElement = true;
  9605. if(isReversed){
  9606. self._previousFocusElement = node;
  9607. }else{
  9608. self._nextFocusElement = node;
  9609. }
  9610. return;
  9611. }else{
  9612. // 필터링 조건에 부합하지 않는다면, 자식들을 기준으로 반복하게 된다.
  9613. if(isReversed){
  9614. for(var len = node.childNodes.length, i = len - 1; i >= 0; i--){
  9615. self._recursivePreorderTraversalFilter(node.childNodes[i], filterFunction, true);
  9616. if(!!this._bStopFindingNextElement){
  9617. break;
  9618. }
  9619. }
  9620. }else{
  9621. for(var i=0, len = node.childNodes.length; i < len; i++){
  9622. self._recursivePreorderTraversalFilter(node.childNodes[i], filterFunction);
  9623. if(!!this._bStopFindingNextElement){
  9624. break;
  9625. }
  9626. }
  9627. }
  9628. }
  9629. },
  9630. /**
  9631. * [SMARTEDITORSUS-1594] 필터 함수로, 노드가 tab 키로 포커스를 이동하는 태그에 해당하는지 확인한다.
  9632. * */
  9633. _isFocusTag : function(){
  9634. var self = this;
  9635. // tab 키로 포커스를 잡아주는 태그 목록
  9636. var aFocusTagViaTabKey = ["A", "BUTTON", "INPUT", "TEXTAREA"];
  9637. // 포커스 태그가 현재 노드에 존재하는지 확인하기 위한 flag
  9638. var bFocusTagExists = false;
  9639. for(var i = 0, len = aFocusTagViaTabKey.length; i < len; i++){
  9640. if(self.nodeType === 1 && self.nodeName && self.nodeName.toUpperCase() == aFocusTagViaTabKey[i] && !self.disabled && jindo.$Element(self).visible()){
  9641. bFocusTagExists = true;
  9642. break;
  9643. }
  9644. }
  9645. return bFocusTagExists;
  9646. },
  9647. /**
  9648. * [SMARTEDITORSUS-1594]
  9649. * SE2M_Configuration_General에서 포커스를 이동할 에디터 영역 이전의 엘레먼트를 지정해 두었다면, 설정값을 따른다.
  9650. * 지정하지 않았거나 String이라면, elAppContainer를 기준으로 자동 탐색한다.
  9651. * */
  9652. $ON_FOCUS_BEFORE_ELEMENT : function() {
  9653. // 포커스 캐싱
  9654. this._currentPreviousFocusElement = null; // 새로운 포커스 이동이 발생할 때마다 캐싱 초기화
  9655. if(this.htAccessOption.sBeforeElementId){
  9656. this._currentPreviousFocusElement = document.getElementById(this.htAccessOption.sBeforeElementId);
  9657. }else{
  9658. this._currentPreviousFocusElement = this._findPreviousFocusElement(this.elAppContainer); // 삽입될 대상
  9659. }
  9660. if(this._currentPreviousFocusElement){
  9661. window.focus(); // [SMARTEDITORSUS-1360] IE7에서는 element에 대한 focus를 주기 위해 선행되어야 한다.
  9662. this._currentPreviousFocusElement.focus();
  9663. }else if(parent && parent.nhn && parent.nhn.husky && parent.nhn.husky.EZCreator && parent.nhn.husky.EZCreator.elIFrame){
  9664. parent.focus();
  9665. if(this._currentPreviousFocusElement = this._findPreviousFocusElement(parent.nhn.husky.EZCreator.elIFrame)){
  9666. this._currentPreviousFocusElement.focus();
  9667. }
  9668. }
  9669. },
  9670. /**
  9671. * [SMARTEDITORSUS-1594] DIV#smart_editor2 이전 요소에서 가장 가까운 포커스용 태그를 탐색
  9672. * */
  9673. _findPreviousFocusElement : function(targetElement){
  9674. var target = null;
  9675. var el = targetElement.previousSibling;
  9676. while(el){
  9677. if(el.nodeType !== 1){ // Element Node만을 대상으로 한다.
  9678. // 대상 노드 대신 previousSibling을 찾되, 부모를 거슬러 올라갈 수도 있다.
  9679. // document.body까지 거슬러 올라가게 되면 탐색 종료
  9680. el = this._switchToSiblingOrNothing(el, /*isReversed*/true);
  9681. if(!el){
  9682. break;
  9683. }else{
  9684. continue;
  9685. }
  9686. }
  9687. // 대상 노드를 기준으로, 역 전위순회로 조건에 부합하는 노드 탐색
  9688. this._recursivePreorderTraversalFilter(el, this._isFocusTag, true);
  9689. if(this._previousFocusElement){
  9690. target = this._previousFocusElement;
  9691. // 탐색에 사용했던 변수 초기화
  9692. this._bStopFindingNextElement = false;
  9693. this._previousFocusElement = null;
  9694. break;
  9695. }else{
  9696. // 대상 노드 대신 previousSibling을 찾되, 부모를 거슬러 올라갈 수도 있다.
  9697. // document.body까지 거슬러 올라가게 되면 탐색 종료
  9698. el = this._switchToSiblingOrNothing(el, /*isReversed*/true);
  9699. if(!el){
  9700. break;
  9701. }
  9702. }
  9703. }
  9704. // target이 존재하지 않으면 null 반환
  9705. return target;
  9706. },
  9707. $ON_FOCUS_TOOLBAR_AREA : function(){
  9708. this.oButton = jindo.$$.getSingle("BUTTON.se2_font_family", this.elAppContainer);
  9709. if(this.oButton && !this.oButton.disabled){ // [SMARTEDITORSUS-1369] IE9이하에서 disabled 요소에 포커스를 주면 오류 발생
  9710. window.focus();
  9711. this.oButton.focus();
  9712. }
  9713. },
  9714. $ON_OPEN_HELP_POPUP : function() {
  9715. this.oApp.exec("DISABLE_ALL_UI", [{aExceptions: ["se2_accessibility"]}]);
  9716. this.oApp.exec("SHOW_EDITING_AREA_COVER");
  9717. this.oApp.exec("SELECT_UI", ["se2_accessibility"]);
  9718. //아래 코드 없어야 블로그에서도 동일한 위치에 팝업 뜸..
  9719. //this.elHelpPopupLayer.style.top = this.nDefaultTop+"px";
  9720. this.nCalcX = this.htTopLeftCorner.x + this.oApp.getEditingAreaWidth() - this.nLayerWidth;
  9721. this.nCalcY = this.htTopLeftCorner.y - 30; // 블로그버전이 아닌 경우 에디터영역을 벗어나는 문제가 있기 때문에 기본툴바(30px) 크기만큼 올려줌
  9722. this.oApp.exec("SHOW_DIALOG_LAYER", [this.elHelpPopupLayer, {
  9723. elHandle: this.elTitle,
  9724. nMinX : this.htTopLeftCorner.x + 0,
  9725. nMinY : this.nDefaultTop + 77,
  9726. nMaxX : this.nCalcX,
  9727. nMaxY : this.nCalcY
  9728. }]);
  9729. // offset (nTop:Numeric, nLeft:Numeric)
  9730. this.welHelpPopupLayer.offset(this.nCalcY, (this.nCalcX)/2);
  9731. //[SMARTEDITORSUS-1327] IE에서 포커스 이슈로 IE에 대해서만 window.focus실행함.
  9732. if(jindo.$Agent().navigator().ie) {
  9733. window.focus();
  9734. }
  9735. var self = this;
  9736. setTimeout(function(){
  9737. try{
  9738. self.oCloseButton2.focus();
  9739. }catch(e){
  9740. }
  9741. },200);
  9742. },
  9743. $ON_CLOSE_HELP_POPUP : function() {
  9744. this.oApp.exec("ENABLE_ALL_UI"); // 모든 UI 활성화.
  9745. this.oApp.exec("DESELECT_UI", ["helpPopup"]);
  9746. this.oApp.exec("HIDE_ALL_DIALOG_LAYER", []);
  9747. this.oApp.exec("HIDE_EDITING_AREA_COVER"); // 편집 영역 활성화.
  9748. this.oApp.exec("FOCUS");
  9749. }
  9750. });
  9751. //}
  9752. /**
  9753. * @fileOverview This file contains Husky plugin that takes care of the operations related to inserting special characters
  9754. * @name hp_SE2M_SCharacter.js
  9755. * @required HuskyRangeManager
  9756. */
  9757. nhn.husky.SE2M_SCharacter = jindo.$Class({
  9758. name : "SE2M_SCharacter",
  9759. $ON_MSG_APP_READY : function(){
  9760. this.oApp.exec("REGISTER_UI_EVENT", ["sCharacter", "click", "TOGGLE_SCHARACTER_LAYER"]);
  9761. this.oApp.registerLazyMessage(["TOGGLE_SCHARACTER_LAYER"], ["hp_SE2M_SCharacter$Lazy.js"]);
  9762. }
  9763. });
  9764. /**
  9765. * @fileOverview This file contains Husky plugin that takes care of the operations related to Find/Replace
  9766. * @name hp_SE2M_FindReplacePlugin.js
  9767. */
  9768. nhn.husky.SE2M_FindReplacePlugin = jindo.$Class({
  9769. name : "SE2M_FindReplacePlugin",
  9770. oEditingWindow : null,
  9771. oFindReplace : null,
  9772. bFindMode : true,
  9773. bLayerShown : false,
  9774. $init : function(){
  9775. this.nDefaultTop = 20;
  9776. },
  9777. $ON_MSG_APP_READY : function(){
  9778. // the right document will be available only when the src is completely loaded
  9779. this.oEditingWindow = this.oApp.getWYSIWYGWindow();
  9780. // [SMARTEDITORSUS-2260] 메일 > Mac에서 ctrl 조합 단축키 모두 meta 조합으로 변경
  9781. if (jindo.$Agent().os().mac) {
  9782. this.oApp.exec("REGISTER_HOTKEY", ["meta+f", "SHOW_FIND_LAYER", []]);
  9783. this.oApp.exec("REGISTER_HOTKEY", ["meta+h", "SHOW_REPLACE_LAYER", []]);
  9784. } else {
  9785. this.oApp.exec("REGISTER_HOTKEY", ["ctrl+f", "SHOW_FIND_LAYER", []]);
  9786. this.oApp.exec("REGISTER_HOTKEY", ["ctrl+h", "SHOW_REPLACE_LAYER", []]);
  9787. }
  9788. this.oApp.exec("REGISTER_UI_EVENT", ["findAndReplace", "click", "TOGGLE_FIND_REPLACE_LAYER"]);
  9789. this.oApp.registerLazyMessage(["TOGGLE_FIND_REPLACE_LAYER","SHOW_FIND_LAYER","SHOW_REPLACE_LAYER","SHOW_FIND_REPLACE_LAYER"], ["hp_SE2M_FindReplacePlugin$Lazy.js","N_FindReplace.js"]);
  9790. },
  9791. $ON_SHOW_ACTIVE_LAYER : function(){
  9792. this.oApp.exec("HIDE_DIALOG_LAYER", [this.elDropdownLayer]);
  9793. }
  9794. });
  9795. /**
  9796. * @fileOverview This file contains Husky plugin that takes care of the operations related to quote
  9797. * @name hp_SE_Quote.js
  9798. * @required SE_EditingArea_WYSIWYG
  9799. */
  9800. nhn.husky.SE2M_Quote = jindo.$Class({
  9801. name : "SE2M_Quote",
  9802. htQuoteStyles_view : null,
  9803. $init : function(){
  9804. var htConfig = nhn.husky.SE2M_Configuration.Quote || {};
  9805. var sImageBaseURL = htConfig.sImageBaseURL;
  9806. this.nMaxLevel = htConfig.nMaxLevel || 14;
  9807. this.htQuoteStyles_view = {};
  9808. this.htQuoteStyles_view["se2_quote1"] = "_zoom:1;padding:0 8px; margin:0 0 30px 20px; margin-right:15px; border-left:2px solid #cccccc;color:#888888;";
  9809. this.htQuoteStyles_view["se2_quote2"] = "_zoom:1;margin:0 0 30px 13px;padding:0 8px 0 16px;background:url("+sImageBaseURL+"/bg_quote2.gif) 0 3px no-repeat;color:#888888;";
  9810. this.htQuoteStyles_view["se2_quote3"] = "_zoom:1;margin:0 0 30px 0;padding:10px;border:1px dashed #cccccc;color:#888888;";
  9811. this.htQuoteStyles_view["se2_quote4"] = "_zoom:1;margin:0 0 30px 0;padding:10px;border:1px dashed #66b246;color:#888888;";
  9812. this.htQuoteStyles_view["se2_quote5"] = "_zoom:1;margin:0 0 30px 0;padding:10px;border:1px dashed #cccccc;background:url("+sImageBaseURL+"/bg_b1.png) repeat;_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+sImageBaseURL+"/bg_b1.png',sizingMethod='scale');color:#888888;";
  9813. this.htQuoteStyles_view["se2_quote6"] = "_zoom:1;margin:0 0 30px 0;padding:10px;border:1px solid #e5e5e5;color:#888888;";
  9814. this.htQuoteStyles_view["se2_quote7"] = "_zoom:1;margin:0 0 30px 0;padding:10px;border:1px solid #66b246;color:#888888;";
  9815. this.htQuoteStyles_view["se2_quote8"] = "_zoom:1;margin:0 0 30px 0;padding:10px;border:1px solid #e5e5e5;background:url("+sImageBaseURL+"/bg_b1.png) repeat;_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+sImageBaseURL+"/bg_b1.png',sizingMethod='scale');color:#888888;";
  9816. this.htQuoteStyles_view["se2_quote9"] = "_zoom:1;margin:0 0 30px 0;padding:10px;border:2px solid #e5e5e5;color:#888888;";
  9817. this.htQuoteStyles_view["se2_quote10"] = "_zoom:1;margin:0 0 30px 0;padding:10px;border:2px solid #e5e5e5;background:url("+sImageBaseURL+"/bg_b1.png) repeat;_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+sImageBaseURL+"/bg_b1.png',sizingMethod='scale');color:#888888;";
  9818. },
  9819. _assignHTMLElements : function(){
  9820. //@ec
  9821. this.elDropdownLayer = jindo.$$.getSingle("DIV.husky_seditor_blockquote_layer", this.oApp.htOptions.elAppContainer);
  9822. this.aLI = jindo.$$("LI", this.elDropdownLayer);
  9823. },
  9824. $ON_REGISTER_CONVERTERS : function(){
  9825. this.oApp.exec("ADD_CONVERTER", ["DB_TO_IR", jindo.$Fn(function(sContents){
  9826. sContents = sContents.replace(/<(blockquote)[^>]*class=['"]?(se2_quote[0-9]+)['"]?[^>]*>/gi, "<$1 class=$2>");
  9827. return sContents;
  9828. }, this).bind()]);
  9829. this.oApp.exec("ADD_CONVERTER", ["IR_TO_DB", jindo.$Fn(function(sContents){
  9830. var htQuoteStyles_view = this.htQuoteStyles_view;
  9831. sContents = sContents.replace(/<(blockquote)[^>]*class=['"]?(se2_quote[0-9]+)['"]?[^>]*>/gi, function(sAll, sTag, sClassName){
  9832. return '<'+sTag+' class='+sClassName+' style="'+htQuoteStyles_view[sClassName]+'">';
  9833. });
  9834. return sContents;
  9835. }, this).bind()]);
  9836. this.htSE1toSE2Map = {
  9837. "01" : "1",
  9838. "02" : "2",
  9839. "03" : "6",
  9840. "04" : "8",
  9841. "05" : "9",
  9842. "07" : "3",
  9843. "08" : "5"
  9844. };
  9845. // convert SE1's quotes to SE2's
  9846. // -> 블로그 개발 쪽에서 처리 하기로 함.
  9847. /*
  9848. this.oApp.exec("ADD_CONVERTER", ["DB_TO_IR", jindo.$Fn(function(sContents){
  9849. return sContents.replace(/<blockquote[^>]* class="?vview_quote([0-9]+)"?[^>]*>((?:\s|.)*?)<\/blockquote>/ig, jindo.$Fn(function(m0,sQuoteType,sQuoteContents){
  9850. if (/<!--quote_txt-->((?:\s|.)*?)<!--\/quote_txt-->/ig.test(sQuoteContents)){
  9851. if(!this.htSE1toSE2Map[sQuoteType]){
  9852. return m0;
  9853. }
  9854. return '<blockquote class="se2_quote'+this.htSE1toSE2Map[sQuoteType]+'">'+RegExp.$1+'</blockquote>';
  9855. }else{
  9856. return '';
  9857. }
  9858. }, this).bind());
  9859. }, this).bind()]);
  9860. */
  9861. },
  9862. $LOCAL_BEFORE_FIRST : function(){
  9863. this._assignHTMLElements();
  9864. this.oApp.registerBrowserEvent(this.elDropdownLayer, "click", "EVENT_SE2_BLOCKQUOTE_LAYER_CLICK", []);
  9865. this.oApp.delayedExec("SE2_ATTACH_HOVER_EVENTS", [this.aLI], 0);
  9866. },
  9867. $ON_MSG_APP_READY: function(){
  9868. this.oApp.exec("REGISTER_UI_EVENT", ["quote", "click", "TOGGLE_BLOCKQUOTE_LAYER"]);
  9869. this.oApp.registerLazyMessage(["TOGGLE_BLOCKQUOTE_LAYER"], ["hp_SE2M_Quote$Lazy.js"]);
  9870. },
  9871. // [SMARTEDITORSUS-209] 인용구 내에 내용이 없을 때 Backspace 로 인용구가 삭제되도록 처리
  9872. $ON_EVENT_EDITING_AREA_KEYDOWN : function(weEvent) {
  9873. var oSelection,
  9874. elParentQuote;
  9875. if ('WYSIWYG' !== this.oApp.getEditingMode()){
  9876. return;
  9877. }
  9878. if(8 !== weEvent.key().keyCode){
  9879. return;
  9880. }
  9881. oSelection = this.oApp.getSelection();
  9882. oSelection.fixCommonAncestorContainer();
  9883. elParentQuote = this._findParentQuote(oSelection.commonAncestorContainer);
  9884. if(!elParentQuote){
  9885. return;
  9886. }
  9887. if(this._isBlankQuote(elParentQuote)){
  9888. weEvent.stop(jindo.$Event.CANCEL_DEFAULT);
  9889. oSelection.selectNode(elParentQuote);
  9890. oSelection.collapseToStart();
  9891. jindo.$Element(elParentQuote).leave();
  9892. oSelection.select();
  9893. }
  9894. },
  9895. // [SMARTEDITORSUS-215] Delete 로 인용구 뒤의 P 가 제거되지 않도록 처리
  9896. $ON_EVENT_EDITING_AREA_KEYUP : function(weEvent) {
  9897. var oSelection,
  9898. elParentQuote,
  9899. oP;
  9900. if ('WYSIWYG' !== this.oApp.getEditingMode()){
  9901. return;
  9902. }
  9903. if(46 !== weEvent.key().keyCode){
  9904. return;
  9905. }
  9906. oSelection = this.oApp.getSelection();
  9907. oSelection.fixCommonAncestorContainer();
  9908. elParentQuote = this._findParentQuote(oSelection.commonAncestorContainer);
  9909. if(!elParentQuote){
  9910. return false;
  9911. }
  9912. if(!elParentQuote.nextSibling){
  9913. weEvent.stop(jindo.$Event.CANCEL_DEFAULT);
  9914. oP = oSelection._document.createElement("P");
  9915. oP.innerHTML = "&nbsp;";
  9916. jindo.$Element(elParentQuote).after(oP);
  9917. setTimeout(jindo.$Fn(function(oSelection){
  9918. var sBookmarkID = oSelection.placeStringBookmark();
  9919. oSelection.select();
  9920. oSelection.removeStringBookmark(sBookmarkID);
  9921. },this).bind(oSelection), 0);
  9922. }
  9923. },
  9924. _isBlankQuote : function(elParentQuote){
  9925. var elChild,
  9926. aChildNodes,
  9927. i, nLen,
  9928. bChrome = this.oApp.oNavigator.chrome,
  9929. bSafari = this.oApp.oNavigator.safari,
  9930. isBlankText = function(sText){
  9931. sText = sText.replace(/[\r\n]/ig, '').replace(unescape("%uFEFF"), '');
  9932. if(sText === ""){
  9933. return true;
  9934. }
  9935. if(sText === "&nbsp;" || sText === " "){ // [SMARTEDITORSUS-479]
  9936. return true;
  9937. }
  9938. return false;
  9939. },
  9940. isBlank = function(oNode){
  9941. if(oNode.nodeType === 3 && isBlankText(oNode.nodeValue)){
  9942. return true;
  9943. }
  9944. if((oNode.tagName === "P" || oNode.tagName === "SPAN") &&
  9945. (isBlankText(oNode.innerHTML) || oNode.innerHTML === "<br>")){
  9946. return true;
  9947. }
  9948. return false;
  9949. },
  9950. isBlankTable = function(oNode){
  9951. if((jindo.$$("tr", oNode)).length === 0){
  9952. return true;
  9953. }
  9954. return false;
  9955. };
  9956. if(isBlankText(elParentQuote.innerHTML) || elParentQuote.innerHTML === "<br>"){
  9957. return true;
  9958. }
  9959. if(bChrome || bSafari){ // [SMARTEDITORSUS-352], [SMARTEDITORSUS-502]
  9960. var aTable = jindo.$$("TABLE", elParentQuote),
  9961. nTable = aTable.length,
  9962. elTable;
  9963. for(i=0; i<nTable; i++){
  9964. elTable = aTable[i];
  9965. if(isBlankTable(elTable)){
  9966. jindo.$Element(elTable).leave();
  9967. }
  9968. }
  9969. }
  9970. aChildNodes = elParentQuote.childNodes;
  9971. for(i=0, nLen=aChildNodes.length; i<nLen; i++){
  9972. elChild = aChildNodes[i];
  9973. if(!isBlank(elChild)){
  9974. return false;
  9975. }
  9976. }
  9977. return true;
  9978. },
  9979. _findParentQuote : function(el){
  9980. return this._findAncestor(jindo.$Fn(function(elNode){
  9981. if(!elNode){return false;}
  9982. if(elNode.tagName !== "BLOCKQUOTE"){return false;}
  9983. if(!elNode.className){return false;}
  9984. var sClassName = elNode.className;
  9985. if(!this.htQuoteStyles_view[sClassName]){return false;}
  9986. return true;
  9987. }, this).bind(), el);
  9988. },
  9989. _findAncestor : function(fnCondition, elNode){
  9990. while(elNode && !fnCondition(elNode)){elNode = elNode.parentNode;}
  9991. return elNode;
  9992. }
  9993. });
  9994. /**
  9995. * @fileOverview This file contains Husky plugin that takes care of the operations related to table creation
  9996. * @name hp_SE_Table.js
  9997. */
  9998. nhn.husky.SE2M_TableCreator = jindo.$Class({
  9999. name : "SE2M_TableCreator",
  10000. _sSETblClass : "__se_tbl",
  10001. nRows : 3,
  10002. nColumns : 4,
  10003. nBorderSize : 1,
  10004. sBorderColor : "#000000",
  10005. sBGColor: "#000000",
  10006. nBorderStyleIdx : 3,
  10007. nTableStyleIdx : 1,
  10008. nMinRows : 1,
  10009. nMaxRows : 20,
  10010. nMinColumns : 1,
  10011. nMaxColumns : 20,
  10012. nMinBorderWidth : 1,
  10013. nMaxBorderWidth : 10,
  10014. rxLastDigits : null,
  10015. sReEditGuideMsg_table : null,
  10016. // 테두리 스타일 목록
  10017. // 표 스타일 스타일 목록
  10018. oSelection : null,
  10019. $ON_MSG_APP_READY : function(){
  10020. this.sReEditGuideMsg_table = this.oApp.$MSG("SE2M_ReEditAction.reEditGuideMsg.table");
  10021. this.oApp.exec("REGISTER_UI_EVENT", ["table", "click", "TOGGLE_TABLE_LAYER"]);
  10022. this.oApp.registerLazyMessage(["TOGGLE_TABLE_LAYER"], ["hp_SE2M_TableCreator$Lazy.js"]);
  10023. },
  10024. // [SMARTEDITORSUS-365] 테이블퀵에디터 > 속성 직접입력 > 테두리 스타일
  10025. // - 테두리 없음을 선택하는 경우 본문에 삽입하는 표에 가이드 라인을 표시해 줍니다. 보기 시에는 테두리가 보이지 않습니다.
  10026. $ON_REGISTER_CONVERTERS : function(){
  10027. this.oApp.exec("ADD_CONVERTER_DOM", ["IR_TO_DB", jindo.$Fn(this.irToDbDOM, this).bind()]);
  10028. this.oApp.exec("ADD_CONVERTER_DOM", ["DB_TO_IR", jindo.$Fn(this.dbToIrDOM, this).bind()]);
  10029. },
  10030. irToDbDOM : function(oTmpNode){
  10031. /**
  10032. * 저장을 위한 Table Tag 아래와 같이 변경됩니다.
  10033. * (1) <TABLE>
  10034. * <table border="1" cellpadding="0" cellspacing="0" style="border:1px dashed #c7c7c7; border-left:0; border-bottom:0;" attr_no_border_tbl="1" class="__se_tbl">
  10035. * --> <table border="0" cellpadding="1" cellspacing="0" attr_no_border_tbl="1" class="__se_tbl">
  10036. * (2) <TD>
  10037. * <td style="border:1px dashed #c7c7c7; border-top:0; border-right:0; background-color:#ffef00" width="245"><p>&nbsp;</p></td>
  10038. * --> <td style="background-color:#ffef00" width="245">&nbsp;</td>
  10039. */
  10040. var aNoBorderTable = [];
  10041. var aTables = jindo.$$('table[class=__se_tbl]', oTmpNode, {oneTimeOffCache:true});
  10042. // 테두리가 없음 속성의 table (임의로 추가한 attr_no_border_tbl 속성이 있는 table 을 찾음)
  10043. jindo.$A(aTables).forEach(function(oValue, nIdx, oArray) {
  10044. if(jindo.$Element(oValue).attr("attr_no_border_tbl")){
  10045. aNoBorderTable.push(oValue);
  10046. }
  10047. }, this);
  10048. if(aNoBorderTable.length < 1){
  10049. return;
  10050. }
  10051. // [SMARTEDITORSUS-410] 글 저장 시, 테두리 없음 속성을 선택할 때 임의로 표시한 가이드 라인 property 만 style 에서 제거해 준다.
  10052. // <TABLE> 과 <TD> 의 속성값을 변경 및 제거
  10053. var aTDs = [], oTable;
  10054. for(var i = 0, nCount = aNoBorderTable.length; i < nCount; i++){
  10055. oTable = aNoBorderTable[i];
  10056. // <TABLE> 에서 border, cellpadding 속성값 변경, style property 제거
  10057. jindo.$Element(oTable).css({"border": "", "borderLeft": "", "borderBottom": ""});
  10058. jindo.$Element(oTable).attr({"border": 0, "cellpadding": 1});
  10059. // <TD> 에서는 background-color 를 제외한 style 을 모두 제거
  10060. aTDs = jindo.$$('tbody>tr>td', oTable);
  10061. jindo.$A(aTDs).forEach(function(oTD, nIdx, oTDArray) {
  10062. jindo.$Element(oTD).css({"border": "", "borderTop": "", "borderRight": ""});
  10063. });
  10064. }
  10065. },
  10066. dbToIrDOM : function(oTmpNode){
  10067. /**
  10068. * 수정을 위한 Table Tag 아래와 같이 변경됩니다.
  10069. * (1) <TABLE>
  10070. * <table border="0" cellpadding="1" cellspacing="0" attr_no_border_tbl="1" class="__se_tbl">
  10071. * --> <table border="1" cellpadding="0" cellspacing="0" style="border:1px dashed #c7c7c7; border-left:0; border-bottom:0;" attr_no_border_tbl="1" class="__se_tbl">
  10072. * (2) <TD>
  10073. * <td style="background-color:#ffef00" width="245">&nbsp;</td>
  10074. * --> <td style="border:1px dashed #c7c7c7; border-top:0; border-right:0; background-color:#ffef00" width="245"><p>&nbsp;</p></td>
  10075. */
  10076. var aNoBorderTable = [];
  10077. var aTables = jindo.$$('table[class=__se_tbl]', oTmpNode, {oneTimeOffCache:true});
  10078. // 테두리가 없음 속성의 table (임의로 추가한 attr_no_border_tbl 속성이 있는 table 을 찾음)
  10079. jindo.$A(aTables).forEach(function(oValue, nIdx, oArray) {
  10080. if(jindo.$Element(oValue).attr("attr_no_border_tbl")){
  10081. aNoBorderTable.push(oValue);
  10082. }
  10083. }, this);
  10084. if(aNoBorderTable.length < 1){
  10085. return;
  10086. }
  10087. // <TABLE> 과 <TD> 의 속성값을 변경/추가
  10088. var aTDs = [], oTable;
  10089. for(var i = 0, nCount = aNoBorderTable.length; i < nCount; i++){
  10090. oTable = aNoBorderTable[i];
  10091. // <TABLE> 에서 border, cellpadding 속성값 변경/ style 속성 추가
  10092. jindo.$Element(oTable).css({"border": "1px dashed #c7c7c7", "borderLeft": 0, "borderBottom": 0});
  10093. jindo.$Element(oTable).attr({"border": 1, "cellpadding": 0});
  10094. // <TD> 에서 style 속성값 추가
  10095. aTDs = jindo.$$('tbody>tr>td', oTable);
  10096. jindo.$A(aTDs).forEach(function(oTD, nIdx, oTDArray) {
  10097. jindo.$Element(oTD).css({"border": "1px dashed #c7c7c7", "borderTop": 0, "borderRight": 0});
  10098. });
  10099. }
  10100. }
  10101. });
  10102. /**
  10103. * @fileOverview This file contains Husky plugin that takes care of the operations related to changing the font style in the table.
  10104. * @requires SE2M_TableEditor.js
  10105. * @name SE2M_TableBlockManager
  10106. */
  10107. nhn.husky.SE2M_TableBlockStyler = jindo.$Class({
  10108. name : "SE2M_TableBlockStyler",
  10109. nSelectedTD : 0,
  10110. htSelectedTD : {},
  10111. aTdRange : [],
  10112. $init : function(){ },
  10113. $LOCAL_BEFORE_ALL : function(){
  10114. return (this.oApp.getEditingMode() == "WYSIWYG");
  10115. },
  10116. $ON_MSG_APP_READY : function(){
  10117. this.oDocument = this.oApp.getWYSIWYGDocument();
  10118. },
  10119. $ON_EVENT_EDITING_AREA_MOUSEUP : function(wevE){
  10120. if(this.oApp.getEditingMode() != "WYSIWYG") return;
  10121. this.setTdBlock();
  10122. },
  10123. /**
  10124. * selected Area가 td block인지 체크하는 함수.
  10125. */
  10126. $ON_IS_SELECTED_TD_BLOCK : function(sAttr,oReturn) {
  10127. if( this.nSelectedTD > 0){
  10128. oReturn[sAttr] = true;
  10129. return oReturn[sAttr];
  10130. }else{
  10131. oReturn[sAttr] = false;
  10132. return oReturn[sAttr];
  10133. }
  10134. },
  10135. /**
  10136. *
  10137. */
  10138. $ON_GET_SELECTED_TD_BLOCK : function(sAttr,oReturn){
  10139. //use : this.oApp.exec("GET_SELECTED_TD_BLOCK",['aCells',this.htSelectedTD]);
  10140. oReturn[sAttr] = this.htSelectedTD.aTdCells;
  10141. },
  10142. setTdBlock : function() {
  10143. this.oApp.exec("GET_SELECTED_CELLS",['aTdCells',this.htSelectedTD]); //tableEditor로 부터 얻어온다.
  10144. var aNodes = this.htSelectedTD.aTdCells;
  10145. if(aNodes){
  10146. this.nSelectedTD = aNodes.length;
  10147. }
  10148. },
  10149. $ON_DELETE_BLOCK_CONTENTS : function(){
  10150. var self = this, welParent, oBlockNode, oChildNode;
  10151. this.setTdBlock();
  10152. for (var j = 0; j < this.nSelectedTD ; j++){
  10153. jindo.$Element(this.htSelectedTD.aTdCells[j]).child( function(elChild){
  10154. welParent = jindo.$Element(elChild._element.parentNode);
  10155. welParent.remove(elChild);
  10156. oBlockNode = self.oDocument.createElement('P');
  10157. if (jindo.$Agent().navigator().firefox) {
  10158. oChildNode = self.oDocument.createElement('BR');
  10159. } else {
  10160. oChildNode = self.oDocument.createTextNode('\u00A0');
  10161. }
  10162. oBlockNode.appendChild(oChildNode);
  10163. welParent.append(oBlockNode);
  10164. }, 1);
  10165. }
  10166. }
  10167. });
  10168. //{
  10169. /**
  10170. * @fileOverview This file contains Husky plugin with test handlers
  10171. * @name hp_SE2M_StyleRemover.js
  10172. */
  10173. nhn.husky.SE2M_StyleRemover = jindo.$Class({
  10174. name: "SE2M_StyleRemover",
  10175. $ON_MSG_APP_READY : function(){
  10176. this.oApp.exec("REGISTER_UI_EVENT", ["styleRemover", "click", "CHOOSE_REMOVE_STYLE", []]);
  10177. },
  10178. $LOCAL_BEFORE_FIRST : function(){
  10179. // The plugin may be used in view and when it is used there, EditingAreaManager plugin is not loaded.
  10180. // So, get the document from the selection instead of EditingAreaManager.
  10181. this.oHuskyRange = this.oApp.getEmptySelection();
  10182. this._document = this.oHuskyRange._document;
  10183. },
  10184. $ON_CHOOSE_REMOVE_STYLE : function(oSelection){
  10185. var bSelectedBlock = false;
  10186. var htSelectedTDs = {};
  10187. this.oApp.exec("IS_SELECTED_TD_BLOCK",['bIsSelectedTd',htSelectedTDs]);
  10188. bSelectedBlock = htSelectedTDs.bIsSelectedTd;
  10189. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["REMOVE STYLE", {bMustBlockElement:true}]);
  10190. if( bSelectedBlock ){
  10191. this.oApp.exec("REMOVE_STYLE_IN_BLOCK", []);
  10192. }else{
  10193. this.oApp.exec("REMOVE_STYLE", []);
  10194. }
  10195. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["REMOVE STYLE", {bMustBlockElement:true}]);
  10196. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['noeffect']);
  10197. },
  10198. $ON_REMOVE_STYLE_IN_BLOCK : function(oSelection){
  10199. var htSelectedTDs = {};
  10200. this.oSelection = this.oApp.getSelection();
  10201. this.oApp.exec("GET_SELECTED_TD_BLOCK",['aTdCells',htSelectedTDs]);
  10202. var aNodes = htSelectedTDs.aTdCells;
  10203. for( var j = 0; j < aNodes.length ; j++){
  10204. this.oSelection.selectNodeContents(aNodes[j]);
  10205. this.oSelection.select();
  10206. this.oApp.exec("REMOVE_STYLE", []);
  10207. }
  10208. },
  10209. $ON_REMOVE_STYLE : function(oSelection){
  10210. if(!oSelection || !oSelection.commonAncestorContainer){
  10211. oSelection = this.oApp.getSelection();
  10212. }
  10213. if(oSelection.collapsed){return;}
  10214. oSelection.expandBothEnds();
  10215. var sBookmarkID = oSelection.placeStringBookmark();
  10216. var aNodes = oSelection.getNodes(true);
  10217. this._removeStyle(aNodes);
  10218. oSelection.moveToBookmark(sBookmarkID);
  10219. var aNodes = oSelection.getNodes(true);
  10220. for(var i=0; i<aNodes.length; i++){
  10221. var oNode = aNodes[i];
  10222. if(oNode.style && oNode.tagName != "BR" && oNode.tagName != "TD" && oNode.tagName != "TR" && oNode.tagName != "TBODY" && oNode.tagName != "TABLE"){
  10223. oNode.removeAttribute("align");
  10224. oNode.removeAttribute("style");
  10225. if((jindo.$Element(oNode).css("display") == "inline" && oNode.tagName != "IMG" && oNode.tagName != "IFRAME") && (!oNode.firstChild || oSelection._isBlankTextNode(oNode.firstChild))){
  10226. oNode.parentNode.removeChild(oNode);
  10227. }
  10228. }
  10229. }
  10230. oSelection.moveToBookmark(sBookmarkID);
  10231. // [SMARTEDITORSUS-1750] 스타일제거를 위해 selection을 확장(oSelection.expandBothEnds)하면 TR까지 확장되는데 IE10에서만 execCommand 가 제대로 동작하지 않는 문제가 발생하기 때문에 확장전 selection으로 복원하도록 수정
  10232. // [SMARTEDITORSUS-1893] 테이블밖에서는 마지막라인이 풀리는 이슈가 발생하여 commonAncestorContainer가 TBODY 인 경우에만 selection을 복원하도록 제한
  10233. if(oSelection.commonAncestorContainer.tagName === "TBODY"){
  10234. oSelection = this.oApp.getSelection();
  10235. }
  10236. oSelection.select();
  10237. // use a custom removeStringBookmark here as the string bookmark could've been cloned and there are some additional cases that need to be considered
  10238. // remove start marker
  10239. var oMarker = this._document.getElementById(oSelection.HUSKY_BOOMARK_START_ID_PREFIX+sBookmarkID);
  10240. while(oMarker){
  10241. oParent = nhn.DOMFix.parentNode(oMarker);
  10242. oParent.removeChild(oMarker);
  10243. while(oParent && (!oParent.firstChild || (!oParent.firstChild.nextSibling && oSelection._isBlankTextNode(oParent.firstChild)))){
  10244. var oNextParent = oParent.parentNode;
  10245. oParent.parentNode.removeChild(oParent);
  10246. oParent = oNextParent;
  10247. }
  10248. oMarker = this._document.getElementById(oSelection.HUSKY_BOOMARK_START_ID_PREFIX+sBookmarkID);
  10249. }
  10250. // remove end marker
  10251. var oMarker = this._document.getElementById(oSelection.HUSKY_BOOMARK_END_ID_PREFIX+sBookmarkID);
  10252. while(oMarker){
  10253. oParent = nhn.DOMFix.parentNode(oMarker);
  10254. oParent.removeChild(oMarker);
  10255. while(oParent && (!oParent.firstChild || (!oParent.firstChild.nextSibling && oSelection._isBlankTextNode(oParent.firstChild)))){
  10256. var oNextParent = oParent.parentNode;
  10257. oParent.parentNode.removeChild(oParent);
  10258. oParent = oNextParent;
  10259. }
  10260. oMarker = this._document.getElementById(oSelection.HUSKY_BOOMARK_END_ID_PREFIX+sBookmarkID);
  10261. }
  10262. this.oApp.exec("CHECK_STYLE_CHANGE");
  10263. },
  10264. $ON_REMOVE_STYLE2 : function(aNodes){
  10265. this._removeStyle(aNodes);
  10266. },
  10267. $ON_REMOVE_STYLE_AND_PASTE_HTML : function(sHtml, bNoUndo){
  10268. var htBrowser,
  10269. elDivHolder,
  10270. elFirstTD,
  10271. aNodesInSelection,
  10272. oSelection;
  10273. htBrowser = jindo.$Agent().navigator();
  10274. if(!sHtml) {return false;}
  10275. if(this.oApp.getEditingMode() != "WYSIWYG"){
  10276. this.oApp.exec("CHANGE_EDITING_MODE", ["WYSIWYG"]);
  10277. }
  10278. if(!bNoUndo){
  10279. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["REMOVE STYLE AND PASTE HTML"]);
  10280. }
  10281. oSelection = this.oApp.getSelection();
  10282. oSelection.deleteContents(); // remove select node - for dummy image, reedit object
  10283. // If the table were inserted within a styled(strikethough & etc) paragraph, the table may inherit the style in IE.
  10284. elDivHolder = this.oApp.getWYSIWYGDocument().createElement("DIV");
  10285. oSelection.insertNode(elDivHolder);
  10286. if (!!htBrowser.webkit) {
  10287. elDivHolder.innerHTML = "&nbsp;"; // for browser bug! - summary reiteration
  10288. }
  10289. oSelection.selectNode(elDivHolder);
  10290. this.oApp.exec("REMOVE_STYLE", [oSelection]);
  10291. //[SMARTEDITORSUS-181][IE9] 표나 요약글 등의 테이블에서 > 테이블 외부로 커서 이동 불가
  10292. if( htBrowser.ie ){
  10293. sHtml += "<p>&nbsp;</p>";
  10294. }else if(htBrowser.firefox){
  10295. //[SMARTEDITORSUS-477][개별블로그](파폭특정)포스트쓰기>요약글을 삽입 후 요약글 아래 임의의 본문영역에 마우스 클릭 시 커서가 요약안에 노출됩니다.
  10296. // 본문에 table만 있는 경우, 커서가 밖으로 못나오는 현상이 있음.FF버그임.
  10297. sHtml += "<p><br></p>";
  10298. }
  10299. oSelection.selectNode(elDivHolder);
  10300. oSelection.pasteHTML(sHtml);
  10301. //Table인경우, 커서를 테이블 첫 TD에 넣기 위한 작업.
  10302. aNodesInSelection = oSelection.getNodes() || [];
  10303. for(var i = 0; i < aNodesInSelection.length ; i++){
  10304. if(!!aNodesInSelection[i].tagName && aNodesInSelection[i].tagName.toLowerCase() == 'td'){
  10305. elFirstTD = aNodesInSelection[i];
  10306. oSelection.selectNodeContents(elFirstTD.firstChild || elFirstTD);
  10307. oSelection.collapseToStart();
  10308. oSelection.select();
  10309. break;
  10310. }
  10311. }
  10312. oSelection.collapseToEnd(); //파란색 커버 제거.
  10313. oSelection.select();
  10314. this.oApp.exec("FOCUS");
  10315. if (!elDivHolder) {// 임시 div 삭제.
  10316. elDivHolder.parentNode.removeChild(elDivHolder);
  10317. }
  10318. if(!bNoUndo){
  10319. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["REMOVE STYLE AND PASTE HTML"]);
  10320. }
  10321. },
  10322. _removeStyle : function(aNodes){
  10323. var arNodes = jindo.$A(aNodes);
  10324. for(var i=0; i<aNodes.length; i++){
  10325. var oNode = aNodes[i];
  10326. // oNode had been removed from the document already
  10327. if(!oNode || !oNode.parentNode || !oNode.parentNode.tagName){continue;}
  10328. var bDontSplit = false;
  10329. // If oNode is direct child of a block level node, don't do anything. (should not move up the hierarchy anymore)
  10330. if(jindo.$Element(oNode.parentNode).css("display") != "inline"){
  10331. continue;
  10332. }
  10333. var parent = oNode.parentNode;
  10334. // do not proceed if oNode is not completely selected
  10335. if(oNode.firstChild){
  10336. if(arNodes.indexOf(this.oHuskyRange._getVeryLastRealChild(oNode)) == -1){continue;}
  10337. if(arNodes.indexOf(this.oHuskyRange._getVeryFirstRealChild(oNode)) == -1){continue;}
  10338. }
  10339. // Case 1: oNode is the right most node
  10340. //
  10341. // If oNode were C(right most node) from
  10342. // H
  10343. // |
  10344. // P
  10345. // / | \
  10346. // A B C
  10347. //
  10348. // and B and C were selected, bring up all the (selected) left siblings to the right of the parent and and make it
  10349. // H
  10350. // / | \
  10351. // P B C
  10352. // |
  10353. // A
  10354. // ===========================================================
  10355. // If A, B and C were selected from
  10356. // H
  10357. // |
  10358. // P
  10359. // / | \
  10360. // A B C
  10361. //
  10362. // append them to the right of the parent and make it
  10363. // H
  10364. // / | | \
  10365. // P A B C
  10366. //
  10367. // and then remove P as it's got no child and make it
  10368. // H
  10369. // / | \
  10370. // A B C
  10371. if(!oNode.nextSibling){
  10372. i--;
  10373. var tmp = oNode;
  10374. // bring up left siblings
  10375. while(tmp){
  10376. var prevNode = tmp.previousSibling;
  10377. parent.parentNode.insertBefore(tmp, parent.nextSibling);
  10378. if(!prevNode){break;}
  10379. if(arNodes.indexOf(this._getVeryFirst(prevNode)) == -1){break;}
  10380. tmp = prevNode;
  10381. }
  10382. // remove the parent if it's got no child now
  10383. if(parent.childNodes.length === 0){parent.parentNode.removeChild(parent);}
  10384. continue;
  10385. }
  10386. // Case 2: oNode's got a right sibling that is included in the selection
  10387. //
  10388. // if the next sibling is included in the selection, stop current iteration
  10389. // -> current node will be handled in the next iteration
  10390. if(arNodes.indexOf(this._getVeryLast(oNode.nextSibling)) != -1){continue;}
  10391. // Since the case
  10392. // 1. oNode is the right most node
  10393. // 2. oNode's got a right sibling that is included in the selection
  10394. // were all taken care of above, so from here we just need take care of the case when oNode is NOT the right most node and oNode's right sibling is NOT included in the selection
  10395. // Case 3: the rest
  10396. // When all of the left siblings were selected, take all the left siblings and current node and append them to the left of the parent node.
  10397. // H
  10398. // |
  10399. // P
  10400. // / | | \
  10401. // A B C D
  10402. // -> if A, B and C were selected, then make it
  10403. // H
  10404. // / | | \
  10405. // A B C P
  10406. // |
  10407. // D
  10408. i--;
  10409. // bring up selected prev siblings
  10410. if(arNodes.indexOf(this._getVeryFirst(oNode.parentNode)) != -1){
  10411. // move
  10412. var tmp = oNode;
  10413. var lastInserted = parent;
  10414. while(tmp){
  10415. var prevNode = tmp.previousSibling;
  10416. parent.parentNode.insertBefore(tmp, lastInserted);
  10417. lastInserted = tmp;
  10418. if(!prevNode){break;}
  10419. tmp = prevNode;
  10420. }
  10421. if(parent.childNodes.length === 0){parent.parentNode.removeChild(parent);}
  10422. // When NOT all of the left siblings were selected, split the parent node and insert the selected nodes in between.
  10423. // H
  10424. // |
  10425. // P
  10426. // / | | \
  10427. // A B C D
  10428. // -> if B and C were selected, then make it
  10429. // H
  10430. // / | | \
  10431. // P B C P
  10432. // | |
  10433. // A D
  10434. }else{
  10435. //split
  10436. if(bDontSplit){
  10437. i++;
  10438. continue;
  10439. }
  10440. var oContainer = this._document.createElement("SPAN");
  10441. var tmp = oNode;
  10442. parent.insertBefore(oContainer, tmp.nextSibling);
  10443. while(tmp){
  10444. var prevNode = tmp.previousSibling;
  10445. oContainer.insertBefore(tmp, oContainer.firstChild);
  10446. if(!prevNode){break;}
  10447. if(arNodes.indexOf(this._getVeryFirst(prevNode)) == -1){break;}
  10448. tmp = prevNode;
  10449. }
  10450. this._splitAndAppendAtTop(oContainer);
  10451. while(oContainer.firstChild){
  10452. oContainer.parentNode.insertBefore(oContainer.firstChild, oContainer);
  10453. }
  10454. oContainer.parentNode.removeChild(oContainer);
  10455. }
  10456. }
  10457. },
  10458. _splitAndAppendAtTop : function(oSpliter){
  10459. var targetNode = oSpliter;
  10460. var oTmp = targetNode;
  10461. var oCopy = oTmp;
  10462. while(jindo.$Element(oTmp.parentNode).css("display") == "inline"){
  10463. var oNode = oTmp.parentNode.cloneNode(false);
  10464. while(oTmp.nextSibling){
  10465. oNode.appendChild(oTmp.nextSibling);
  10466. }
  10467. oTmp = oTmp.parentNode;
  10468. oNode.insertBefore(oCopy, oNode.firstChild);
  10469. oCopy = oNode;
  10470. }
  10471. oTop = oTmp.parentNode;
  10472. oTop.insertBefore(targetNode, oTmp.nextSibling);
  10473. oTop.insertBefore(oCopy, targetNode.nextSibling);
  10474. },
  10475. _getVeryFirst : function(oNode){
  10476. if(!oNode){return null;}
  10477. if(oNode.firstChild){
  10478. return this.oHuskyRange._getVeryFirstRealChild(oNode);
  10479. }else{
  10480. return oNode;
  10481. }
  10482. },
  10483. _getVeryLast : function(oNode){
  10484. if(!oNode){return null;}
  10485. if(oNode.lastChild){
  10486. return this.oHuskyRange._getVeryLastRealChild(oNode);
  10487. }else{
  10488. return oNode;
  10489. }
  10490. }
  10491. });
  10492. //}
  10493. nhn.husky.SE2M_TableEditor = jindo.$Class({
  10494. name : "SE2M_TableEditor",
  10495. _sSETblClass : "__se_tbl",
  10496. _sSEReviewTblClass : "__se_tbl_review",
  10497. STATUS : {
  10498. S_0 : 1, // neither cell selection nor cell resizing is active
  10499. MOUSEDOWN_CELL : 2, // mouse down on a table cell
  10500. CELL_SELECTING : 3, // cell selection is in progress
  10501. CELL_SELECTED : 4, // cell selection was (completely) made
  10502. MOUSEOVER_BORDER : 5, // mouse is over a table/cell border and the cell resizing grip is shown
  10503. MOUSEDOWN_BORDER : 6 // mouse down on the cell resizing grip (cell resizing is in progress)
  10504. },
  10505. CELL_SELECTION_CLASS : "se2_te_selection",
  10506. MIN_CELL_WIDTH : 5,
  10507. MIN_CELL_HEIGHT : 5,
  10508. TMP_BGC_ATTR : "_se2_tmp_te_bgc",
  10509. TMP_BGIMG_ATTR : "_se2_tmp_te_bg_img",
  10510. ATTR_TBL_TEMPLATE : "_se2_tbl_template",
  10511. nStatus : 1,
  10512. nMouseEventsStatus : 0,
  10513. aSelectedCells : [],
  10514. $ON_REGISTER_CONVERTERS : function(){
  10515. // remove the cell selection class
  10516. this.oApp.exec("ADD_CONVERTER_DOM", ["WYSIWYG_TO_IR", jindo.$Fn(function(elTmpNode){
  10517. if(this.aSelectedCells.length < 1){
  10518. //return sContents;
  10519. return;
  10520. }
  10521. var aCells;
  10522. var aCellType = ["TD", "TH"];
  10523. for(var n = 0; n < aCellType.length; n++){
  10524. aCells = elTmpNode.getElementsByTagName(aCellType[n]);
  10525. for(var i = 0, nLen = aCells.length; i < nLen; i++){
  10526. if(aCells[i].className){
  10527. aCells[i].className = aCells[i].className.replace(this.CELL_SELECTION_CLASS, "");
  10528. if(aCells[i].getAttribute(this.TMP_BGC_ATTR)){
  10529. aCells[i].style.backgroundColor = aCells[i].getAttribute(this.TMP_BGC_ATTR);
  10530. aCells[i].removeAttribute(this.TMP_BGC_ATTR);
  10531. }else if(aCells[i].getAttribute(this.TMP_BGIMG_ATTR)){
  10532. jindo.$Element(this.aCells[i]).css("backgroundImage",aCells[i].getAttribute(this.TMP_BGIMG_ATTR));
  10533. aCells[i].removeAttribute(this.TMP_BGIMG_ATTR);
  10534. }
  10535. }
  10536. }
  10537. }
  10538. // this.wfnMouseDown.attach(this.elResizeCover, "mousedown");
  10539. // return elTmpNode.innerHTML;
  10540. // var rxSelectionColor = new RegExp("<(TH|TD)[^>]*)("+this.TMP_BGC_ATTR+"=[^> ]*)([^>]*>)", "gi");
  10541. }, this).bind()]);
  10542. },
  10543. $ON_MSG_APP_READY : function(){
  10544. this.oApp.registerLazyMessage(["EVENT_EDITING_AREA_MOUSEMOVE","STYLE_TABLE"], ["hp_SE2M_TableEditor$Lazy.js","SE2M_TableTemplate.js"]);
  10545. }
  10546. });
  10547. /**
  10548. * @name SE2M_QuickEditor_Common
  10549. * @class
  10550. * @description Quick Editor Common function Class
  10551. * @author NHN AjaxUI Lab - mixed
  10552. * @version 1.0
  10553. * @since 2009.09.29
  10554. * */
  10555. nhn.husky.SE2M_QuickEditor_Common = jindo.$Class({
  10556. /**
  10557. * class 이름
  10558. * @type {String}
  10559. */
  10560. name : "SE2M_QuickEditor_Common",
  10561. /**
  10562. * 환경 정보.
  10563. * @type {Object}
  10564. */
  10565. _environmentData : "",
  10566. /**
  10567. * 현재 타입 (table|img)
  10568. * @type {String}
  10569. */
  10570. _currentType :"",
  10571. /**
  10572. * 이벤트가 레이어 안에서 호출되었는지 알기 위한 변수
  10573. * @type {Boolean}
  10574. */
  10575. _in_event : false,
  10576. /**
  10577. * Ajax처리를 하지 않음
  10578. * @type {Boolean}
  10579. */
  10580. _bUseConfig : false,
  10581. /**
  10582. * 공통 서버에서 개인 설정 받아오는 AjaxUrl
  10583. * @See SE2M_Configuration.js
  10584. */
  10585. _sBaseAjaxUrl : "",
  10586. _sAddTextAjaxUrl : "",
  10587. /**
  10588. * 초기 인스턴스 생성 실행되는 함수.
  10589. */
  10590. $init : function() {
  10591. this.waHotkeys = new jindo.$A([]);
  10592. this.waHotkeyLayers = new jindo.$A([]);
  10593. },
  10594. $ON_MSG_APP_READY : function() {
  10595. var htConfiguration = nhn.husky.SE2M_Configuration.QuickEditor;
  10596. if(htConfiguration){
  10597. this._bUseConfig = (!!htConfiguration.common && typeof htConfiguration.common.bUseConfig !== "undefined") ? htConfiguration.common.bUseConfig : true;
  10598. }
  10599. if(!this._bUseConfig){
  10600. this.setData("{table:'full',img:'full',review:'full'}");
  10601. } else {
  10602. this._sBaseAjaxUrl = htConfiguration.common.sBaseAjaxUrl;
  10603. this._sAddTextAjaxUrl = htConfiguration.common.sAddTextAjaxUrl;
  10604. this.getData();
  10605. }
  10606. this.oApp.registerLazyMessage(["OPEN_QE_LAYER"], ["hp_SE2M_QuickEditor_Common$Lazy.js"]);
  10607. },
  10608. //삭제 시에 qe layer close
  10609. $ON_EVENT_EDITING_AREA_KEYDOWN : function(oEvent){
  10610. var oKeyInfo = oEvent.key();
  10611. //Backspace : 8, Delete :46
  10612. if (oKeyInfo.keyCode == 8 || oKeyInfo.keyCode == 46 ) {
  10613. // [SMARTEDITORSUS-1213][IE9, 10] 사진 삭제 후 zindex 1000인 div가 잔존하는데, 그 위로 썸네일 drag를 시도하다 보니 drop이 불가능.
  10614. var htBrowser = jindo.$Agent().navigator();
  10615. if(htBrowser.ie && htBrowser.nativeVersion > 8){
  10616. var elFirstChild = jindo.$$.getSingle("DIV.husky_seditor_editing_area_container").childNodes[0];
  10617. if((elFirstChild.tagName == "DIV") && (elFirstChild.style.zIndex == 1000)){
  10618. elFirstChild.parentNode.removeChild(elFirstChild);
  10619. }
  10620. }
  10621. // --[SMARTEDITORSUS-1213]
  10622. this.oApp.exec("CLOSE_QE_LAYER", [oEvent]);
  10623. }
  10624. },
  10625. getData : function() {
  10626. var self = this;
  10627. jindo.$Ajax(self._sBaseAjaxUrl, {
  10628. type : "jsonp",
  10629. timeout : 1,
  10630. onload: function(rp) {
  10631. var result = rp.json().result;
  10632. // [SMARTEDITORSUS-1028][SMARTEDITORSUS-1517] QuickEditor 설정 API 개선
  10633. //if (!!result && !!result.length) {
  10634. if (!!result && !!result.text_data) {
  10635. //self.setData(result[result.length - 1]);
  10636. self.setData(result.text_data);
  10637. } else {
  10638. self.setData("{table:'full',img:'full',review:'full'}");
  10639. }
  10640. // --[SMARTEDITORSUS-1028][SMARTEDITORSUS-1517]
  10641. },
  10642. onerror : function() {
  10643. self.setData("{table:'full',img:'full',review:'full'}");
  10644. },
  10645. ontimeout : function() {
  10646. self.setData("{table:'full',img:'full',review:'full'}");
  10647. }
  10648. }).request({ text_key : "qeditor_fold" });
  10649. },
  10650. setData : function(sResult){
  10651. var oResult = {
  10652. table : "full",
  10653. img : "full",
  10654. review : "full"
  10655. };
  10656. if(sResult){
  10657. oResult = eval("("+sResult+")");
  10658. }
  10659. this._environmentData = {
  10660. table : {
  10661. isOpen : false,
  10662. type : oResult["table"],//full,fold,
  10663. isFixed : false,
  10664. position : []
  10665. },
  10666. img : {
  10667. isOpen : false,
  10668. type : oResult["img"],//full,fold
  10669. isFixed : false
  10670. },
  10671. review : {
  10672. isOpen : false,
  10673. type : oResult["review"],//full,fold
  10674. isFixed : false,
  10675. position : []
  10676. }
  10677. };
  10678. this.waTableTagNames =jindo.$A(["table","tbody","td","tfoot","th","thead","tr"]);
  10679. },
  10680. /**
  10681. * 위지윅 영역에 단축키가 등록될 ,
  10682. * tab shift+tab (들여쓰기 / 내어쓰기 ) 제외한 단축키 리스트를 저장한다.
  10683. */
  10684. $ON_REGISTER_HOTKEY : function(sHotkey, sCMD, aArgs){
  10685. if(sHotkey != "tab" && sHotkey != "shift+tab"){
  10686. this.waHotkeys.push([sHotkey, sCMD, aArgs]);
  10687. }
  10688. }
  10689. });
  10690. /**
  10691. * @classDescription shortcut
  10692. * @author AjaxUI Lab - mixed
  10693. */
  10694. function Shortcut(sKey,sId){
  10695. var sKey = sKey.replace(/\s+/g,"");
  10696. var store = Shortcut.Store;
  10697. var action = Shortcut.Action;
  10698. if(typeof sId === "undefined"&&sKey.constructor == String){
  10699. store.set("document",sKey,document);
  10700. return action.init(store.get("document"),sKey);
  10701. }else if(sId.constructor == String&&sKey.constructor == String){
  10702. store.set(sId,sKey,jindo.$(sId));
  10703. return action.init(store.get(sId),sKey);
  10704. }else if(sId.constructor != String&&sKey.constructor == String){
  10705. var fakeId = "nonID"+new Date().getTime();
  10706. fakeId = Shortcut.Store.searchId(fakeId,sId);
  10707. store.set(fakeId,sKey,sId);
  10708. return action.init(store.get(fakeId),sKey);
  10709. }
  10710. alert(sId+"는 반드시 string이거나 없어야 됩니다.");
  10711. };
  10712. Shortcut.Store = {
  10713. anthorKeyHash:{},
  10714. datas:{},
  10715. currentId:"",
  10716. currentKey:"",
  10717. searchId:function(sId,oElement){
  10718. // [SMARTEDITORSUS-2103]
  10719. var isElementInData = false;
  10720. jindo.$H(this.datas).forEach(function(oValue,sKey){
  10721. if(oElement == oValue.element){
  10722. sId = sKey;
  10723. isElementInData = true;
  10724. jindo.$H.Break();
  10725. }
  10726. });
  10727. /*
  10728. * element context는 서로 다르지만
  10729. * 이미 추가된 Shortcut.Data 객체와 timestamp가 중복되는 경우,
  10730. *
  10731. * 원래 동작해야 element context가 아닌,
  10732. * 이미 추가된 element context에서 잘못 동작할 있다.
  10733. *
  10734. * 경우에는 timestamp 기반 id를 새롭개 생성해서
  10735. * 원래 동작해야 element context에서 동작할 있도록 한다.
  10736. */
  10737. if(!isElementInData && (sId in this.datas)){
  10738. var newFakeId = sId;
  10739. while(newFakeId in this.datas){
  10740. newFakeId = "nonID"+new Date().getTime();
  10741. }
  10742. return newFakeId;
  10743. }
  10744. return sId;
  10745. // --[SMARTEDITORSUS-2103]
  10746. },
  10747. set:function(sId,sKey,oElement){
  10748. this.currentId = sId;
  10749. this.currentKey = sKey;
  10750. var idData = this.get(sId);
  10751. this.datas[sId] = idData?idData.createKey(sKey):new Shortcut.Data(sId,sKey,oElement);
  10752. },
  10753. get:function(sId,sKey){
  10754. if(sKey){
  10755. return this.datas[sId].keys[sKey];
  10756. }else{
  10757. return this.datas[sId];
  10758. }
  10759. },
  10760. reset:function(sId){
  10761. var data = this.datas[sId];
  10762. Shortcut.Helper.bind(data.func,data.element,"detach");
  10763. delete this.datas[sId];
  10764. },
  10765. allReset: function(){
  10766. jindo.$H(this.datas).forEach(jindo.$Fn(function(value,key) {
  10767. this.reset(key);
  10768. },this).bind());
  10769. }
  10770. };
  10771. Shortcut.Data = jindo.$Class({
  10772. $init:function(sId,sKey,oElement){
  10773. this.id = sId;
  10774. this.element = oElement;
  10775. this.func = jindo.$Fn(this.fire,this).bind();
  10776. Shortcut.Helper.bind(this.func,oElement,"attach");
  10777. this.keys = {};
  10778. this.keyStemp = {};
  10779. this.createKey(sKey);
  10780. },
  10781. createKey:function(sKey){
  10782. this.keyStemp[Shortcut.Helper.keyInterpretor(sKey)] = sKey;
  10783. this.keys[sKey] = {};
  10784. var data = this.keys[sKey];
  10785. data.key = sKey;
  10786. data.events = [];
  10787. data.commonExceptions = [];
  10788. // data.keyAnalysis = Shortcut.Helper.keyInterpretor(sKey);
  10789. data.stopDefalutBehavior = true;
  10790. return this;
  10791. },
  10792. getKeyStamp : function(eEvent){
  10793. var sKey = eEvent.keyCode || eEvent.charCode;
  10794. var returnVal = "";
  10795. returnVal += eEvent.altKey?"1":"0";
  10796. returnVal += eEvent.ctrlKey?"1":"0";
  10797. returnVal += eEvent.metaKey?"1":"0";
  10798. returnVal += eEvent.shiftKey?"1":"0";
  10799. returnVal += sKey;
  10800. return returnVal;
  10801. },
  10802. fire:function(eEvent){
  10803. eEvent = eEvent||window.eEvent;
  10804. var oMatchKeyData = this.keyStemp[this.getKeyStamp(eEvent)];
  10805. if(oMatchKeyData){
  10806. this.excute(new jindo.$Event(eEvent),oMatchKeyData);
  10807. }
  10808. },
  10809. excute:function(weEvent,sRawKey){
  10810. var isExcute = true;
  10811. var staticFun = Shortcut.Helper;
  10812. var data = this.keys[sRawKey];
  10813. if(staticFun.notCommonException(weEvent,data.commonExceptions)){
  10814. jindo.$A(data.events).forEach(function(v){
  10815. if(data.stopDefalutBehavior){
  10816. var leng = v.exceptions.length;
  10817. if(leng){
  10818. for(var i=0;i<leng;i++){
  10819. if(!v.exception[i](weEvent)){
  10820. isExcute = false;
  10821. break;
  10822. }
  10823. }
  10824. if(isExcute){
  10825. v.event(weEvent);
  10826. if(jindo.$Agent().navigator().ie){
  10827. var e = weEvent._event;
  10828. e.keyCode = "";
  10829. e.charCode = "";
  10830. }
  10831. weEvent.stop();
  10832. }else{
  10833. jindo.$A.Break();
  10834. }
  10835. }else{
  10836. v.event(weEvent);
  10837. if(jindo.$Agent().navigator().ie){
  10838. var e = weEvent._event;
  10839. e.keyCode = "";
  10840. e.charCode = "";
  10841. }
  10842. weEvent.stop();
  10843. }
  10844. }
  10845. });
  10846. }
  10847. },
  10848. addEvent:function(fpEvent,sRawKey){
  10849. var events = this.keys[sRawKey].events;
  10850. if(!Shortcut.Helper.hasEvent(fpEvent,events)){
  10851. events.push({
  10852. event:fpEvent,
  10853. exceptions:[]
  10854. });
  10855. };
  10856. },
  10857. addException:function(fpException,sRawKey){
  10858. var commonExceptions = this.keys[sRawKey].commonExceptions;
  10859. if(!Shortcut.Helper.hasException(fpException,commonExceptions)){
  10860. commonExceptions.push(fpException);
  10861. };
  10862. },
  10863. removeException:function(fpException,sRawKey){
  10864. var commonExceptions = this.keys[sRawKey].commonExceptions;
  10865. commonExceptions = jindo.$A(commonExceptions).filter(function(exception){
  10866. return exception!=fpException;
  10867. }).$value();
  10868. },
  10869. removeEvent:function(fpEvent,sRawKey){
  10870. var events = this.keys[sRawKey].events;
  10871. events = jindo.$A(events).filter(function(event) {
  10872. return event!=fpEvent;
  10873. }).$value();
  10874. this.unRegister(sRawKey);
  10875. },
  10876. unRegister:function(sRawKey){
  10877. var aEvents = this.keys[sRawKey].events;
  10878. if(aEvents.length)
  10879. delete this.keys[sRawKey];
  10880. var hasNotKey = true;
  10881. for(var i in this.keys){
  10882. hasNotKey =false;
  10883. break;
  10884. }
  10885. if(hasNotKey){
  10886. Shortcut.Helper.bind(this.func,this.element,"detach");
  10887. delete Shortcut.Store.datas[this.id];
  10888. }
  10889. },
  10890. startDefalutBehavior: function(sRawKey){
  10891. this._setDefalutBehavior(sRawKey,false);
  10892. },
  10893. stopDefalutBehavior: function(sRawKey){
  10894. this._setDefalutBehavior(sRawKey,true);
  10895. },
  10896. _setDefalutBehavior: function(sRawKey,bType){
  10897. this.keys[sRawKey].stopDefalutBehavior = bType;
  10898. }
  10899. });
  10900. Shortcut.Helper = {
  10901. keyInterpretor:function(sKey){
  10902. var keyArray = sKey.split("+");
  10903. var wKeyArray = jindo.$A(keyArray);
  10904. var returnVal = "";
  10905. returnVal += wKeyArray.has("alt")?"1":"0";
  10906. returnVal += wKeyArray.has("ctrl")?"1":"0";
  10907. returnVal += wKeyArray.has("meta")?"1":"0";
  10908. returnVal += wKeyArray.has("shift")?"1":"0";
  10909. var wKeyArray = wKeyArray.filter(function(v){
  10910. return !(v=="alt"||v=="ctrl"||v=="meta"||v=="shift")
  10911. });
  10912. var key = wKeyArray.$value()[0];
  10913. if(key){
  10914. var sKey = Shortcut.Store.anthorKeyHash[key.toUpperCase()]||key.toUpperCase().charCodeAt(0);
  10915. returnVal += sKey;
  10916. }
  10917. return returnVal;
  10918. },
  10919. notCommonException:function(e,exceptions){
  10920. var leng = exceptions.length;
  10921. for(var i=0;i<leng ;i++){
  10922. if(!exceptions[i](e))
  10923. return false;
  10924. }
  10925. return true;
  10926. },
  10927. hasEvent:function(fpEvent,aEvents){
  10928. var nLength = aEvents.length;
  10929. for(var i=0; i<nLength; ++i){
  10930. if(aEvents.event==fpEvent){
  10931. return true;
  10932. }
  10933. };
  10934. return false;
  10935. },
  10936. hasException:function(fpException,commonExceptions){
  10937. var nLength = commonExceptions.length;
  10938. for(var i=0; i<nLength; ++i){
  10939. if(commonExceptions[i]==fpException){
  10940. return true;
  10941. }
  10942. };
  10943. return false;
  10944. },
  10945. bind:function(wfFunc,oElement,sType){
  10946. if(sType=="attach"){
  10947. domAttach(oElement,"keydown",wfFunc);
  10948. }else{
  10949. domDetach(oElement,"keydown",wfFunc);
  10950. }
  10951. }
  10952. };
  10953. (function domAttach (){
  10954. if(document.addEventListener){
  10955. window.domAttach = function(dom,ev,fn){
  10956. dom.addEventListener(ev, fn, false);
  10957. }
  10958. }else{
  10959. window.domAttach = function(dom,ev,fn){
  10960. dom.attachEvent("on"+ev, fn);
  10961. }
  10962. }
  10963. })();
  10964. (function domDetach (){
  10965. if(document.removeEventListener){
  10966. window.domDetach = function(dom,ev,fn){
  10967. dom.removeEventListener(ev, fn, false);
  10968. }
  10969. }else{
  10970. window.domDetach = function(dom,ev,fn){
  10971. dom.detachEvent("on"+ev, fn);
  10972. }
  10973. }
  10974. })();
  10975. Shortcut.Action ={
  10976. init:function(oData,sRawKey){
  10977. this.dataInstance = oData;
  10978. this.rawKey = sRawKey;
  10979. return this;
  10980. },
  10981. addEvent:function(fpEvent){
  10982. this.dataInstance.addEvent(fpEvent,this.rawKey);
  10983. return this;
  10984. },
  10985. removeEvent:function(fpEvent){
  10986. this.dataInstance.removeEvent(fpEvent,this.rawKey);
  10987. return this;
  10988. },
  10989. addException : function(fpException){
  10990. this.dataInstance.addException(fpException,this.rawKey);
  10991. return this;
  10992. },
  10993. removeException : function(fpException){
  10994. this.dataInstance.removeException(fpException,this.rawKey);
  10995. return this;
  10996. },
  10997. // addCommonException : function(fpException){
  10998. // return this;
  10999. // },
  11000. // removeCommonEexception : function(fpException){
  11001. // return this;
  11002. // },
  11003. startDefalutBehavior: function(){
  11004. this.dataInstance.startDefalutBehavior(this.rawKey);
  11005. return this;
  11006. },
  11007. stopDefalutBehavior: function(){
  11008. this.dataInstance.stopDefalutBehavior(this.rawKey);
  11009. return this;
  11010. },
  11011. resetElement: function(){
  11012. Shortcut.Store.reset(this.dataInstance.id);
  11013. return this;
  11014. },
  11015. resetAll: function(){
  11016. Shortcut.Store.allReset();
  11017. return this;
  11018. }
  11019. };
  11020. (function (){
  11021. Shortcut.Store.anthorKeyHash = {
  11022. BACKSPACE : 8,
  11023. TAB : 9,
  11024. ENTER : 13,
  11025. ESC : 27,
  11026. SPACE : 32,
  11027. PAGEUP : 33,
  11028. PAGEDOWN : 34,
  11029. END : 35,
  11030. HOME : 36,
  11031. LEFT : 37,
  11032. UP : 38,
  11033. RIGHT : 39,
  11034. DOWN : 40,
  11035. DEL : 46,
  11036. COMMA : 188,//(,)
  11037. PERIOD : 190,//(.)
  11038. SLASH : 191//(/),
  11039. };
  11040. var hash = Shortcut.Store.anthorKeyHash;
  11041. for(var i=1 ; i < 13 ; i++){
  11042. Shortcut.Store.anthorKeyHash["F"+i] = i+111;
  11043. }
  11044. var agent = jindo.$Agent().navigator();
  11045. if(agent.ie||agent.safari||agent.chrome){
  11046. hash.HYPHEN = 189;//(-)
  11047. hash.EQUAL = 187;//(=)
  11048. }else{
  11049. hash.HYPHEN = 109;
  11050. hash.EQUAL = 61;
  11051. }
  11052. })();
  11053. var shortcut = Shortcut;
  11054. //{
  11055. /**
  11056. * @fileOverview This file contains Husky plugin that takes care of the hotkey feature
  11057. * @name hp_Hotkey.js
  11058. */
  11059. nhn.husky.Hotkey = jindo.$Class({
  11060. name : "Hotkey",
  11061. $init : function(){
  11062. this.oShortcut = shortcut;
  11063. },
  11064. $ON_ADD_HOTKEY : function(sHotkey, sCMD, aArgs, elTarget){
  11065. if(!aArgs){aArgs = [];}
  11066. var func = jindo.$Fn(this.oApp.exec, this.oApp).bind(sCMD, aArgs);
  11067. this.oShortcut(sHotkey, elTarget).addEvent(func);
  11068. }
  11069. });
  11070. //}
  11071. /*[
  11072. * UNDO
  11073. *
  11074. * UNDO 히스토리에 저장되어 있는 이전 IR을 복구한다.
  11075. *
  11076. * none
  11077. *
  11078. ---------------------------------------------------------------------------]*/
  11079. /*[
  11080. * REDO
  11081. *
  11082. * UNDO 히스토리에 저장되어 있는 다음 IR을 복구한다.
  11083. *
  11084. * none
  11085. *
  11086. ---------------------------------------------------------------------------]*/
  11087. /*[
  11088. * RECORD_UNDO_ACTION
  11089. *
  11090. * 현재 IR을 UNDO 히스토리에 추가한다.
  11091. *
  11092. * sAction string 실행 액션(어떤 이유로 IR에 변경이 있었는지 참고용)
  11093. * oSaveOption object 저장 옵션(htRecordOption 참고)
  11094. *
  11095. ---------------------------------------------------------------------------]*/
  11096. /*[
  11097. * RECORD_UNDO_BEFORE_ACTION
  11098. *
  11099. * 현재 IR을 UNDO 히스토리에 추가한다. 액션 전후 따로 저장 경우 단계.
  11100. *
  11101. * sAction string 실행 액션(어떤 이유로 IR에 변경이 있었는지 참고용)
  11102. * oSaveOption object 저장 옵션(htRecordOption 참고)
  11103. *
  11104. ---------------------------------------------------------------------------]*/
  11105. /*[
  11106. * RECORD_UNDO_AFTER_ACTION
  11107. *
  11108. * 현재 IR을 UNDO 히스토리에 추가한다. 액션 전후 따로 저장 경우 단계.
  11109. *
  11110. * sAction string 실행 액션(어떤 이유로 IR에 변경이 있었는지 참고용)
  11111. * oSaveOption object 저장 옵션(htRecordOption 참고)
  11112. *
  11113. ---------------------------------------------------------------------------]*/
  11114. /*[
  11115. * RESTORE_UNDO_HISTORY
  11116. *
  11117. * UNDO 히스토리에 저장되어 있는 IR을 복구한다.
  11118. *
  11119. * nUndoIdx number 몇번째 히스토리를 복구할지
  11120. * nUndoStateStep number 히스토리 내에 몇번째 스텝을 복구 할지. (before:0, after:1)
  11121. *
  11122. ---------------------------------------------------------------------------]*/
  11123. /*[
  11124. * DO_RECORD_UNDO_HISTORY
  11125. *
  11126. * 현재 IR을 UNDO 히스토리에 추가한다.
  11127. *
  11128. * sAction string 실행 액션(어떤 이유로 IR에 변경이 있었는지 참고용)
  11129. * htRecordOption object 저장 옵션
  11130. * nStep (number) 0 | 1 액션의 스텝 인덱스 (보통 1단계이나 Selection 저장이 필요한 경우 1, 2단계로 나누어짐)
  11131. * bSkipIfEqual (bool) false | true 변경이 없다면 히스토리에 추가하지 않음 (현재 길이로 판단하여 저장함)
  11132. * bTwoStepAction (bool) false | true 2단계 액션인 경우
  11133. * sSaveTarget (string) [TAG] | null 저장 타겟을 지정하는 경우 사용 (해당 태그를 포함하여 저장)
  11134. * elSaveTarget : [Element] | null 저장 타겟을 지정하는 경우 사용 (해당 엘리먼트의 innerHTML을 저장)
  11135. * bDontSaveSelection : false | true Selection을 추가하지 않는 경우 (, 편집)
  11136. * bMustBlockElement : false | true 반드시 Block 엘리먼트에 대해서만 저장함, 없으면 BODY 영역 (, 글자 스타일 편집)
  11137. * bMustBlockContainer : false | true 반드시 Block 엘리먼트( 컨테이너로 사용되는) 대해서만 저장함, 없으면 BODY 영역 (, 엔터)
  11138. * oUndoCallback : null | [Object] Undo 처리할 호출해야할 콜백 메시지 정보
  11139. * oRedoCallback : null | [Object] Redo 처리할 호출해야할 콜백 메시지 정보
  11140. *
  11141. ---------------------------------------------------------------------------]*/
  11142. /*[
  11143. * DO_RECORD_UNDO_HISTORY_AT
  11144. *
  11145. * 현재 IR을 UNDO 히스토리의 지정된 위치에 추가한다.
  11146. *
  11147. * oInsertionIdx object 삽입할 위치({nIdx:히스토리 번호, nStep: 히스토리 내에 액션 번호})
  11148. * sAction string 실행 액션(어떤 이유로 IR에 변경이 있었는지 참고용)
  11149. * sContent string 저장할 내용
  11150. * oBookmark object oSelection.getXPathBookmark() 통해 얻어진 북마크
  11151. *
  11152. ---------------------------------------------------------------------------]*/
  11153. /**
  11154. * @pluginDesc Husky Framework에서 자주 사용되는 메시지를 처리하는 플러그인
  11155. * @fileOverview This file contains Husky plugin that takes care of the operations related to Undo/Redo
  11156. * @name hp_SE_UndoRedo.js
  11157. * @required SE_EditingAreaManager, HuskyRangeManager
  11158. */
  11159. nhn.husky.SE_UndoRedo = jindo.$Class({
  11160. name : "SE_UndoRedo",
  11161. oCurStateIdx : null,
  11162. iMinimumSizeChange : 1,
  11163. // limit = nMaxUndoCount + nAfterMaxDeleteBuffer. When the limit is reached delete [0...nAfterMaxDeleteBuffer] so only nMaxUndoCount histories will be left
  11164. nMaxUndoCount : 20, // 1000
  11165. nAfterMaxDeleteBuffer : 100,
  11166. sBlankContentsForFF : "<br>",
  11167. sDefaultXPath : "/HTML[0]/BODY[0]",
  11168. $init : function(){
  11169. this.aUndoHistory = [];
  11170. this.oCurStateIdx = {nIdx: 0, nStep: 0};
  11171. this.nHardLimit = this.nMaxUndoCount + this.nAfterMaxDeleteBuffer;
  11172. },
  11173. $LOCAL_BEFORE_ALL : function(sCmd){
  11174. if(sCmd.match(/_DO_RECORD_UNDO_HISTORY_AT$/)){
  11175. return true;
  11176. }
  11177. try{
  11178. if(this.oApp.getEditingMode() != "WYSIWYG"){
  11179. return false;
  11180. }
  11181. }catch(e){
  11182. return false;
  11183. }
  11184. return true;
  11185. },
  11186. $BEFORE_MSG_APP_READY : function(){
  11187. this._historyLength = 0;
  11188. this.oApp.exec("ADD_APP_PROPERTY", ["getUndoHistory", jindo.$Fn(this._getUndoHistory, this).bind()]);
  11189. this.oApp.exec("ADD_APP_PROPERTY", ["getUndoStateIdx", jindo.$Fn(this._getUndoStateIdx, this).bind()]);
  11190. this.oApp.exec("ADD_APP_PROPERTY", ["saveSnapShot", jindo.$Fn(this._saveSnapShot, this).bind()]);
  11191. this.oApp.exec("ADD_APP_PROPERTY", ["getLastKey", jindo.$Fn(this._getLastKey, this).bind()]);
  11192. this.oApp.exec("ADD_APP_PROPERTY", ["setLastKey", jindo.$Fn(this._setLastKey, this).bind()]);
  11193. this._saveSnapShot();
  11194. this.oApp.exec("DO_RECORD_UNDO_HISTORY_AT", [this.oCurStateIdx, "", "", "", null, this.sDefaultXPath]);
  11195. },
  11196. _getLastKey : function(){
  11197. return this.sLastKey;
  11198. },
  11199. _setLastKey : function(sLastKey){
  11200. this.sLastKey = sLastKey;
  11201. },
  11202. $ON_MSG_APP_READY : function(){
  11203. var oNavigator = jindo.$Agent().navigator();
  11204. this.bIE = oNavigator.ie;
  11205. this.bFF = oNavigator.firefox;
  11206. //this.bChrome = oNavigator.chrome;
  11207. //this.bSafari = oNavigator.safari;
  11208. this.oApp.exec("REGISTER_UI_EVENT", ["undo", "click", "UNDO"]);
  11209. this.oApp.exec("REGISTER_UI_EVENT", ["redo", "click", "REDO"]);
  11210. // [SMARTEDITORSUS-2260] 메일 > Mac에서 ctrl 조합 단축키 모두 meta 조합으로 변경
  11211. if (jindo.$Agent().os().mac) {
  11212. this.oApp.exec("REGISTER_HOTKEY", ["meta+z", "UNDO"]);
  11213. this.oApp.exec("REGISTER_HOTKEY", ["meta+y", "REDO"]);
  11214. } else {
  11215. this.oApp.exec("REGISTER_HOTKEY", ["ctrl+z", "UNDO"]);
  11216. this.oApp.exec("REGISTER_HOTKEY", ["ctrl+y", "REDO"]);
  11217. }
  11218. // this.htOptions = this.oApp.htOptions["SE_UndoRedo"] || {};
  11219. },
  11220. $ON_UNDO : function(){
  11221. this._doRecordUndoHistory("UNDO", { nStep : 0, bSkipIfEqual : true, bMustBlockContainer : true });
  11222. if(this.oCurStateIdx.nIdx <= 0){
  11223. return;
  11224. }
  11225. // 현재의 상태에서 Undo 했을 때 처리해야 할 메시지 호출
  11226. var oUndoCallback = this.aUndoHistory[this.oCurStateIdx.nIdx].oUndoCallback[this.oCurStateIdx.nStep];
  11227. var sCurrentPath = this.aUndoHistory[this.oCurStateIdx.nIdx].sParentXPath[this.oCurStateIdx.nStep];
  11228. if(oUndoCallback){
  11229. this.oApp.exec(oUndoCallback.sMsg, oUndoCallback.aParams);
  11230. }
  11231. if(this.oCurStateIdx.nStep > 0){
  11232. this.oCurStateIdx.nStep--;
  11233. }else{
  11234. var oTmpHistory = this.aUndoHistory[this.oCurStateIdx.nIdx];
  11235. this.oCurStateIdx.nIdx--;
  11236. if(oTmpHistory.nTotalSteps>1){
  11237. this.oCurStateIdx.nStep = 0;
  11238. }else{
  11239. oTmpHistory = this.aUndoHistory[this.oCurStateIdx.nIdx];
  11240. this.oCurStateIdx.nStep = oTmpHistory.nTotalSteps-1;
  11241. }
  11242. }
  11243. var sUndoHistoryPath = this.aUndoHistory[this.oCurStateIdx.nIdx].sParentXPath[this.oCurStateIdx.nStep];
  11244. var bUseDefault = false;
  11245. if(sUndoHistoryPath !== sCurrentPath && sUndoHistoryPath.indexOf(sCurrentPath) === 0){ // 현재의 Path가 Undo의 Path보다 범위가 큰 경우
  11246. bUseDefault = true;
  11247. }
  11248. this.oApp.exec("RESTORE_UNDO_HISTORY", [this.oCurStateIdx.nIdx, this.oCurStateIdx.nStep, bUseDefault]);
  11249. this.oApp.exec("CHECK_STYLE_CHANGE", []);
  11250. this.sLastKey = null;
  11251. },
  11252. $ON_REDO : function(){
  11253. if(this.oCurStateIdx.nIdx >= this.aUndoHistory.length){
  11254. return;
  11255. }
  11256. var oCurHistory = this.aUndoHistory[this.oCurStateIdx.nIdx];
  11257. if(this.oCurStateIdx.nIdx == this.aUndoHistory.length-1 && this.oCurStateIdx.nStep >= oCurHistory.nTotalSteps-1){
  11258. return;
  11259. }
  11260. if(this.oCurStateIdx.nStep < oCurHistory.nTotalSteps-1){
  11261. this.oCurStateIdx.nStep++;
  11262. }else{
  11263. this.oCurStateIdx.nIdx++;
  11264. oCurHistory = this.aUndoHistory[this.oCurStateIdx.nIdx];
  11265. this.oCurStateIdx.nStep = oCurHistory.nTotalSteps-1;
  11266. }
  11267. // 원복될 상태에서 Redo 했을 때 처리해야 할 메시지 호출
  11268. var oRedoCallback = this.aUndoHistory[this.oCurStateIdx.nIdx].oRedoCallback[this.oCurStateIdx.nStep];
  11269. if(oRedoCallback){
  11270. this.oApp.exec(oRedoCallback.sMsg, oRedoCallback.aParams);
  11271. }
  11272. this.oApp.exec("RESTORE_UNDO_HISTORY", [this.oCurStateIdx.nIdx, this.oCurStateIdx.nStep]);
  11273. this.oApp.exec("CHECK_STYLE_CHANGE", []);
  11274. this.sLastKey = null;
  11275. },
  11276. $ON_RECORD_UNDO_ACTION : function(sAction, oSaveOption){
  11277. oSaveOption = oSaveOption || { sSaveTarget : null, elSaveTarget : null, bMustBlockElement : false, bMustBlockContainer : false, bDontSaveSelection : false };
  11278. oSaveOption.nStep = 0;
  11279. oSaveOption.bSkipIfEqual = false;
  11280. oSaveOption.bTwoStepAction = false;
  11281. this._doRecordUndoHistory(sAction, oSaveOption);
  11282. },
  11283. $ON_RECORD_UNDO_BEFORE_ACTION : function(sAction, oSaveOption){
  11284. oSaveOption = oSaveOption || { sSaveTarget : null, elSaveTarget : null, bMustBlockElement : false, bMustBlockContainer : false, bDontSaveSelection : false };
  11285. oSaveOption.nStep = 0;
  11286. oSaveOption.bSkipIfEqual = false;
  11287. oSaveOption.bTwoStepAction = true;
  11288. this._doRecordUndoHistory(sAction, oSaveOption);
  11289. },
  11290. $ON_RECORD_UNDO_AFTER_ACTION : function(sAction, oSaveOption){
  11291. oSaveOption = oSaveOption || { sSaveTarget : null, elSaveTarget : null, bMustBlockElement : false, bMustBlockContainer : false, bDontSaveSelection : false };
  11292. oSaveOption.nStep = 1;
  11293. oSaveOption.bSkipIfEqual = false;
  11294. oSaveOption.bTwoStepAction = true;
  11295. this._doRecordUndoHistory(sAction, oSaveOption);
  11296. },
  11297. $ON_RESTORE_UNDO_HISTORY : function(nUndoIdx, nUndoStateStep, bUseDefault){
  11298. this.oApp.exec("HIDE_ACTIVE_LAYER");
  11299. this.oCurStateIdx.nIdx = nUndoIdx;
  11300. this.oCurStateIdx.nStep = nUndoStateStep;
  11301. var oCurHistory = this.aUndoHistory[this.oCurStateIdx.nIdx],
  11302. sContent = oCurHistory.sContent[this.oCurStateIdx.nStep],
  11303. sFullContents = oCurHistory.sFullContents[this.oCurStateIdx.nStep],
  11304. oBookmark = oCurHistory.oBookmark[this.oCurStateIdx.nStep],
  11305. sParentXPath = oCurHistory.sParentXPath[this.oCurStateIdx.nStep],
  11306. oParent = null,
  11307. sCurContent = "",
  11308. oSelection = this.oApp.getEmptySelection();
  11309. this.oApp.exec("RESTORE_IE_SELECTION"); // this is done to null the ie selection
  11310. if(bUseDefault){
  11311. this.oApp.getWYSIWYGDocument().body.innerHTML = sFullContents;
  11312. sFullContents = this.oApp.getWYSIWYGDocument().body.innerHTML;
  11313. sCurContent = sFullContents;
  11314. sParentXPath = this.sDefaultXPath;
  11315. }else{
  11316. oParent = oSelection._evaluateXPath(sParentXPath, oSelection._document);
  11317. try{
  11318. oParent.innerHTML = sContent;
  11319. sCurContent = oParent.innerHTML;
  11320. }catch(e){ // Path 노드를 찾지 못하는 경우
  11321. this.oApp.getWYSIWYGDocument().body.innerHTML = sFullContents;
  11322. sFullContents = this.oApp.getWYSIWYGDocument().body.innerHTML; // setting the innerHTML may change the internal DOM structure, so save the value again.
  11323. sCurContent = sFullContents;
  11324. sParentXPath = this.sDefaultXPath;
  11325. }
  11326. }
  11327. if(this.bFF && sCurContent == this.sBlankContentsForFF){
  11328. sCurContent = "";
  11329. }
  11330. oCurHistory.sFullContents[this.oCurStateIdx.nStep] = sFullContents;
  11331. oCurHistory.sContent[this.oCurStateIdx.nStep] = sCurContent;
  11332. oCurHistory.sParentXPath[this.oCurStateIdx.nStep] = sParentXPath;
  11333. if(oBookmark && oBookmark.sType == "scroll"){
  11334. setTimeout(jindo.$Fn(function(){this.oApp.getWYSIWYGDocument().documentElement.scrollTop = oBookmark.nScrollTop;}, this).bind(), 0);
  11335. }else{
  11336. oSelection = this.oApp.getEmptySelection();
  11337. if(oSelection.selectionLoaded){
  11338. if(oBookmark){
  11339. oSelection.moveToXPathBookmark(oBookmark);
  11340. }else{
  11341. oSelection = this.oApp.getEmptySelection();
  11342. }
  11343. oSelection.select();
  11344. }
  11345. }
  11346. },
  11347. _doRecordUndoHistory : function(sAction, htRecordOption){
  11348. /*
  11349. htRecordOption = {
  11350. nStep : 0 | 1,
  11351. bSkipIfEqual : false | true,
  11352. bTwoStepAction : false | true,
  11353. sSaveTarget : [TAG] | null
  11354. elSaveTarget : [Element] | null
  11355. bDontSaveSelection : false | true
  11356. bMustBlockElement : false | true
  11357. bMustBlockContainer : false | true
  11358. };
  11359. */
  11360. htRecordOption = htRecordOption || {};
  11361. var nStep = htRecordOption.nStep || 0,
  11362. bSkipIfEqual = htRecordOption.bSkipIfEqual || false,
  11363. bTwoStepAction = htRecordOption.bTwoStepAction || false,
  11364. sSaveTarget = htRecordOption.sSaveTarget || null,
  11365. elSaveTarget = htRecordOption.elSaveTarget || null,
  11366. bDontSaveSelection = htRecordOption.bDontSaveSelection || false,
  11367. bMustBlockElement = htRecordOption.bMustBlockElement || false,
  11368. bMustBlockContainer = htRecordOption.bMustBlockContainer || false,
  11369. oUndoCallback = htRecordOption.oUndoCallback,
  11370. oRedoCallback = htRecordOption.oRedoCallback;
  11371. // if we're in the middle of some action history,
  11372. // remove everything after current idx if any "little" change is made
  11373. this._historyLength = this.aUndoHistory.length;
  11374. if(this.oCurStateIdx.nIdx !== this._historyLength-1){
  11375. bSkipIfEqual = true;
  11376. }
  11377. var oCurHistory = this.aUndoHistory[this.oCurStateIdx.nIdx],
  11378. sHistoryFullContents = oCurHistory.sFullContents[this.oCurStateIdx.nStep],
  11379. sCurContent = "",
  11380. sFullContents = "",
  11381. sParentXPath = "",
  11382. oBookmark = null,
  11383. oSelection = null,
  11384. oInsertionIdx = {nIdx:this.oCurStateIdx.nIdx, nStep:this.oCurStateIdx.nStep}; // 히스토리를 저장할 위치
  11385. oSelection = this.oApp.getSelection();
  11386. if(oSelection.selectionLoaded){
  11387. oBookmark = oSelection.getXPathBookmark();
  11388. }
  11389. if(elSaveTarget){
  11390. sParentXPath = oSelection._getXPath(elSaveTarget);
  11391. }else if(sSaveTarget){
  11392. sParentXPath = this._getTargetXPath(oBookmark, sSaveTarget);
  11393. }else{
  11394. sParentXPath = this._getParentXPath(oBookmark, bMustBlockElement, bMustBlockContainer);
  11395. }
  11396. sFullContents = this.oApp.getWYSIWYGDocument().body.innerHTML;
  11397. // sCurContent = this.oApp.getWYSIWYGDocument().body.innerHTML.replace(/ *_cssquery_UID="[^"]+" */g, "");
  11398. if(sParentXPath === this.sDefaultXPath){
  11399. sCurContent = sFullContents;
  11400. }else{
  11401. sCurContent = oSelection._evaluateXPath(sParentXPath, oSelection._document).innerHTML;
  11402. }
  11403. if(this.bFF && sCurContent == this.sBlankContentsForFF){
  11404. sCurContent = "";
  11405. }
  11406. // every TwoStepAction needs to be recorded
  11407. if(!bTwoStepAction && bSkipIfEqual){
  11408. if(sHistoryFullContents.length === sFullContents.length){
  11409. return;
  11410. }
  11411. // 저장된 데이터와 같음에도 다르다고 처리되는 경우에 대한 처리
  11412. // (예, P안에 Block엘리먼트가 추가된 경우 P를 분리)
  11413. //if(this.bChrome || this.bSafari){
  11414. var elCurrentDiv = document.createElement("div");
  11415. var elHistoryDiv = document.createElement("div");
  11416. elCurrentDiv.innerHTML = sFullContents;
  11417. elHistoryDiv.innerHTML = sHistoryFullContents;
  11418. var elDocFragment = document.createDocumentFragment();
  11419. elDocFragment.appendChild(elCurrentDiv);
  11420. elDocFragment.appendChild(elHistoryDiv);
  11421. sFullContents = elCurrentDiv.innerHTML;
  11422. sHistoryFullContents = elHistoryDiv.innerHTML;
  11423. elCurrentDiv = null;
  11424. elHistoryDiv = null;
  11425. elDocFragment = null;
  11426. if(sHistoryFullContents.length === sFullContents.length){
  11427. return;
  11428. }
  11429. //}
  11430. }
  11431. if(bDontSaveSelection){
  11432. oBookmark = { sType : "scroll", nScrollTop : this.oApp.getWYSIWYGDocument().documentElement.scrollTop };
  11433. }
  11434. oInsertionIdx.nStep = nStep;
  11435. if(oInsertionIdx.nStep === 0 && this.oCurStateIdx.nStep === oCurHistory.nTotalSteps-1){
  11436. oInsertionIdx.nIdx = this.oCurStateIdx.nIdx+1;
  11437. }
  11438. this._doRecordUndoHistoryAt(oInsertionIdx, sAction, sCurContent, sFullContents, oBookmark, sParentXPath, oUndoCallback, oRedoCallback);
  11439. },
  11440. $ON_DO_RECORD_UNDO_HISTORY_AT : function(oInsertionIdx, sAction, sContent, sFullContents, oBookmark, sParentXPath){
  11441. this._doRecordUndoHistoryAt(oInsertionIdx, sAction, sContent, sFullContents, oBookmark, sParentXPath);
  11442. },
  11443. _doRecordUndoHistoryAt : function(oInsertionIdx, sAction, sContent, sFullContents, oBookmark, sParentXPath, oUndoCallback, oRedoCallback){
  11444. if(oInsertionIdx.nStep !== 0){
  11445. this.aUndoHistory[oInsertionIdx.nIdx].nTotalSteps = oInsertionIdx.nStep+1;
  11446. this.aUndoHistory[oInsertionIdx.nIdx].sContent[oInsertionIdx.nStep] = sContent;
  11447. this.aUndoHistory[oInsertionIdx.nIdx].sFullContents[oInsertionIdx.nStep] = sFullContents;
  11448. this.aUndoHistory[oInsertionIdx.nIdx].oBookmark[oInsertionIdx.nStep] = oBookmark;
  11449. this.aUndoHistory[oInsertionIdx.nIdx].sParentXPath[oInsertionIdx.nStep] = sParentXPath;
  11450. this.aUndoHistory[oInsertionIdx.nIdx].oUndoCallback[oInsertionIdx.nStep] = oUndoCallback;
  11451. this.aUndoHistory[oInsertionIdx.nIdx].oRedoCallback[oInsertionIdx.nStep] = oRedoCallback;
  11452. }else{
  11453. var oNewHistory = {sAction:sAction, nTotalSteps: 1};
  11454. oNewHistory.sContent = [];
  11455. oNewHistory.sContent[0] = sContent;
  11456. oNewHistory.sFullContents = [];
  11457. oNewHistory.sFullContents[0] = sFullContents;
  11458. oNewHistory.oBookmark = [];
  11459. oNewHistory.oBookmark[0] = oBookmark;
  11460. oNewHistory.sParentXPath = [];
  11461. oNewHistory.sParentXPath[0] = sParentXPath;
  11462. oNewHistory.oUndoCallback = [];
  11463. oNewHistory.oUndoCallback[0] = oUndoCallback;
  11464. oNewHistory.oRedoCallback = [];
  11465. oNewHistory.oRedoCallback[0] = oRedoCallback;
  11466. this.aUndoHistory.splice(oInsertionIdx.nIdx, this._historyLength - oInsertionIdx.nIdx, oNewHistory);
  11467. this._historyLength = this.aUndoHistory.length;
  11468. }
  11469. if(this._historyLength > this.nHardLimit){
  11470. this.aUndoHistory.splice(0, this.nAfterMaxDeleteBuffer);
  11471. oInsertionIdx.nIdx -= this.nAfterMaxDeleteBuffer;
  11472. }
  11473. this.oCurStateIdx.nIdx = oInsertionIdx.nIdx;
  11474. this.oCurStateIdx.nStep = oInsertionIdx.nStep;
  11475. },
  11476. _saveSnapShot : function(){
  11477. this.oSnapShot = {
  11478. oBookmark : this.oApp.getSelection().getXPathBookmark()
  11479. };
  11480. },
  11481. _getTargetXPath : function(oBookmark, sSaveTarget){ // ex. A, TABLE ...
  11482. var sParentXPath = this.sDefaultXPath,
  11483. aStartXPath = oBookmark[0].sXPath.split("/"),
  11484. aEndXPath = oBookmark[1].sXPath.split("/"),
  11485. aParentPath = [],
  11486. nPathLen = aStartXPath.length < aEndXPath.length ? aStartXPath.length : aEndXPath.length,
  11487. nPathIdx = 0, nTargetIdx = -1;
  11488. if(sSaveTarget === "BODY"){
  11489. return sParentXPath;
  11490. }
  11491. for(nPathIdx=0; nPathIdx<nPathLen; nPathIdx++){
  11492. if(aStartXPath[nPathIdx] !== aEndXPath[nPathIdx]){
  11493. break;
  11494. }
  11495. aParentPath.push(aStartXPath[nPathIdx]);
  11496. if(aStartXPath[nPathIdx] === "" || aStartXPath[nPathIdx] === "HTML" || aStartXPath[nPathIdx] === "BODY"){
  11497. continue;
  11498. }
  11499. if(aStartXPath[nPathIdx].indexOf(sSaveTarget) > -1){
  11500. nTargetIdx = nPathIdx;
  11501. }
  11502. }
  11503. if(nTargetIdx > -1){
  11504. aParentPath.length = nTargetIdx; // Target 의 상위 노드까지 지정
  11505. }
  11506. sParentXPath = aParentPath.join("/");
  11507. if(sParentXPath.length < this.sDefaultXPath.length){
  11508. sParentXPath = this.sDefaultXPath;
  11509. }
  11510. return sParentXPath;
  11511. },
  11512. _getParentXPath : function(oBookmark, bMustBlockElement, bMustBlockContainer){
  11513. var sParentXPath = this.sDefaultXPath,
  11514. aStartXPath, aEndXPath,
  11515. aSnapShotStart, aSnapShotEnd,
  11516. nSnapShotLen, nPathLen,
  11517. aParentPath = ["", "HTML[0]", "BODY[0]"],
  11518. nPathIdx = 0, nBlockIdx = -1,
  11519. // rxBlockContainer = /\bUL|OL|TD|TR|TABLE|BLOCKQUOTE\[/i, // DL
  11520. // rxBlockElement = /\bP|LI|DIV|UL|OL|TD|TR|TABLE|BLOCKQUOTE\[/i, // H[1-6]|DD|DT|DL|PRE
  11521. // rxBlock,
  11522. sPath, sTag;
  11523. if(!oBookmark){
  11524. return sParentXPath;
  11525. }
  11526. // 가능한 중복되는 Parent 를 검색
  11527. if(oBookmark[0].sXPath === sParentXPath || oBookmark[1].sXPath === sParentXPath){
  11528. return sParentXPath;
  11529. }
  11530. aStartXPath = oBookmark[0].sXPath.split("/");
  11531. aEndXPath = oBookmark[1].sXPath.split("/");
  11532. aSnapShotStart = this.oSnapShot.oBookmark[0].sXPath.split("/");
  11533. aSnapShotEnd = this.oSnapShot.oBookmark[1].sXPath.split("/");
  11534. nSnapShotLen = aSnapShotStart.length < aSnapShotEnd.length ? aSnapShotStart.length : aSnapShotEnd.length;
  11535. nPathLen = aStartXPath.length < aEndXPath.length ? aStartXPath.length : aEndXPath.length;
  11536. nPathLen = nPathLen < nSnapShotLen ? nPathLen : nSnapShotLen;
  11537. if(nPathLen < 3){ // BODY
  11538. return sParentXPath;
  11539. }
  11540. bMustBlockElement = bMustBlockElement || false;
  11541. bMustBlockContainer = bMustBlockContainer || false;
  11542. // rxBlock = bMustBlockElement ? rxBlockElement : rxBlockContainer;
  11543. for(nPathIdx=3; nPathIdx<nPathLen; nPathIdx++){
  11544. sPath = aStartXPath[nPathIdx];
  11545. if(sPath !== aEndXPath[nPathIdx] ||
  11546. sPath !== aSnapShotStart[nPathIdx] ||
  11547. sPath !== aSnapShotEnd[nPathIdx] ||
  11548. aEndXPath[nPathIdx] !== aSnapShotStart[nPathIdx] ||
  11549. aEndXPath[nPathIdx] !== aSnapShotEnd[nPathIdx] ||
  11550. aSnapShotStart[nPathIdx] !== aSnapShotEnd[nPathIdx]){
  11551. break;
  11552. }
  11553. aParentPath.push(sPath);
  11554. sTag = sPath.substring(0, sPath.indexOf("["));
  11555. if(bMustBlockElement && (sTag === "P" || sTag === "LI" || sTag === "DIV")){
  11556. nBlockIdx = nPathIdx;
  11557. }else if(sTag === "UL" || sTag === "OL" || sTag === "TD" || sTag === "TR" || sTag === "TABLE" || sTag === "BLOCKQUOTE"){
  11558. nBlockIdx = nPathIdx;
  11559. }
  11560. // if(rxBlock.test(sPath)){
  11561. // nBlockIdx = nPathIdx;
  11562. // }
  11563. }
  11564. if(nBlockIdx > -1){
  11565. aParentPath.length = nBlockIdx + 1;
  11566. }else if(bMustBlockElement || bMustBlockContainer){
  11567. return sParentXPath;
  11568. }
  11569. return aParentPath.join("/");
  11570. },
  11571. _getUndoHistory : function(){
  11572. return this.aUndoHistory;
  11573. },
  11574. _getUndoStateIdx : function(){
  11575. return this.oCurStateIdx;
  11576. }
  11577. });
  11578. /*[
  11579. * ATTACH_HOVER_EVENTS
  11580. *
  11581. * 주어진 HTML엘리먼트에 Hover 이벤트 발생시 특정 클래스가 할당 되도록 설정
  11582. *
  11583. * aElms array Hover 이벤트를 HTML Element 목록
  11584. * sHoverClass string Hover 시에 할당 클래스
  11585. *
  11586. ---------------------------------------------------------------------------]*/
  11587. /**
  11588. * @pluginDesc Husky Framework에서 자주 사용되는 유틸성 메시지를 처리하는 플러그인
  11589. */
  11590. nhn.husky.Utils = jindo.$Class({
  11591. name : "Utils",
  11592. $init : function(){
  11593. var oAgentInfo = jindo.$Agent();
  11594. var oNavigatorInfo = oAgentInfo.navigator();
  11595. if(oNavigatorInfo.ie && oNavigatorInfo.version == 6){
  11596. try{
  11597. document.execCommand('BackgroundImageCache', false, true);
  11598. }catch(e){}
  11599. }
  11600. },
  11601. $BEFORE_MSG_APP_READY : function(){
  11602. this.oApp.exec("ADD_APP_PROPERTY", ["htBrowser", jindo.$Agent().navigator()]);
  11603. },
  11604. $ON_ATTACH_HOVER_EVENTS : function(aElms, htOptions){
  11605. htOptions = htOptions || [];
  11606. var sHoverClass = htOptions.sHoverClass || "hover";
  11607. var fnElmToSrc = htOptions.fnElmToSrc || function(el){return el};
  11608. var fnElmToTarget = htOptions.fnElmToTarget || function(el){return el};
  11609. if(!aElms) return;
  11610. var wfAddClass = jindo.$Fn(function(wev){
  11611. jindo.$Element(fnElmToTarget(wev.currentElement)).addClass(sHoverClass);
  11612. }, this);
  11613. var wfRemoveClass = jindo.$Fn(function(wev){
  11614. jindo.$Element(fnElmToTarget(wev.currentElement)).removeClass(sHoverClass);
  11615. }, this);
  11616. for(var i=0, len = aElms.length; i<len; i++){
  11617. var elSource = fnElmToSrc(aElms[i]);
  11618. wfAddClass.attach(elSource, "mouseover");
  11619. wfRemoveClass.attach(elSource, "mouseout");
  11620. wfAddClass.attach(elSource, "focus");
  11621. wfRemoveClass.attach(elSource, "blur");
  11622. }
  11623. }
  11624. });
  11625. /*[
  11626. * SHOW_DIALOG_LAYER
  11627. *
  11628. * 다이얼로그 레이어를 화면에 보여준다.
  11629. *
  11630. * oLayer HTMLElement 다이얼로그 레이어로 사용 HTML 엘리먼트
  11631. *
  11632. ---------------------------------------------------------------------------]*/
  11633. /*[
  11634. * HIDE_DIALOG_LAYER
  11635. *
  11636. * 다이얼로그 레이어를 화면에 숨긴다.
  11637. *
  11638. * oLayer HTMLElement 숨길 다이얼로그 레이어에 해당 하는 HTML 엘리먼트
  11639. *
  11640. ---------------------------------------------------------------------------]*/
  11641. /*[
  11642. * HIDE_LAST_DIALOG_LAYER
  11643. *
  11644. * 마지막으로 화면에 표시한 다이얼로그 레이어를 숨긴다.
  11645. *
  11646. * none
  11647. *
  11648. ---------------------------------------------------------------------------]*/
  11649. /*[
  11650. * HIDE_ALL_DIALOG_LAYER
  11651. *
  11652. * 표시 중인 모든 다이얼로그 레이어를 숨긴다.
  11653. *
  11654. * none
  11655. *
  11656. ---------------------------------------------------------------------------]*/
  11657. /**
  11658. * @pluginDesc 드래그가 가능한 레이어를 컨트롤 하는 플러그인
  11659. */
  11660. nhn.husky.DialogLayerManager = jindo.$Class({
  11661. name : "DialogLayerManager",
  11662. aMadeDraggable : null,
  11663. aOpenedLayers : null,
  11664. $init : function(){
  11665. this.aMadeDraggable = [];
  11666. this.aDraggableLayer = [];
  11667. this.aOpenedLayers = [];
  11668. },
  11669. $ON_MSG_APP_READY : function() {
  11670. this.oApp.registerLazyMessage(["SHOW_DIALOG_LAYER","TOGGLE_DIALOG_LAYER"], ["hp_DialogLayerManager$Lazy.js", "N_DraggableLayer.js"]);
  11671. }
  11672. });
  11673. /*[
  11674. * TOGGLE_ACTIVE_LAYER
  11675. *
  11676. * 액티브 레이어가 화면에 보이는 여부를 토글 한다.
  11677. *
  11678. * oLayer HTMLElement 레이어로 사용할 HTML Element
  11679. * sOnOpenCmd string 화면에 보이는 경우 발생 메시지(옵션)
  11680. * aOnOpenParam array sOnOpenCmd와 함께 넘겨줄 파라미터(옵션)
  11681. * sOnCloseCmd string 해당 레이어가 화면에서 숨겨질 발생 메시지(옵션)
  11682. * aOnCloseParam array sOnCloseCmd와 함께 넘겨줄 파라미터(옵션)
  11683. *
  11684. ---------------------------------------------------------------------------]*/
  11685. /*[
  11686. * SHOW_ACTIVE_LAYER
  11687. *
  11688. * 액티브 레이어가 화면에 보이는 여부를 토글 한다.
  11689. *
  11690. * oLayer HTMLElement 레이어로 사용할 HTML Element
  11691. * sOnCloseCmd string 해당 레이어가 화면에서 숨겨질 발생 메시지(옵션)
  11692. * aOnCloseParam array sOnCloseCmd와 함께 넘겨줄 파라미터(옵션)
  11693. *
  11694. ---------------------------------------------------------------------------]*/
  11695. /*[
  11696. * HIDE_ACTIVE_LAYER
  11697. *
  11698. * 현재 화면에 보이는 액티브 레이어를 화면에서 숨긴다.
  11699. *
  11700. * none
  11701. *
  11702. ---------------------------------------------------------------------------]*/
  11703. /**
  11704. * @pluginDesc 한번에 한개만 화면에 보여야 하는 레이어를 관리하는 플러그인
  11705. */
  11706. nhn.husky.ActiveLayerManager = jindo.$Class({
  11707. name : "ActiveLayerManager",
  11708. oCurrentLayer : null,
  11709. $BEFORE_MSG_APP_READY : function() {
  11710. this.oNavigator = jindo.$Agent().navigator();
  11711. },
  11712. $ON_TOGGLE_ACTIVE_LAYER : function(oLayer, sOnOpenCmd, aOnOpenParam, sOnCloseCmd, aOnCloseParam){
  11713. if(oLayer == this.oCurrentLayer){
  11714. this.oApp.exec("HIDE_ACTIVE_LAYER", []);
  11715. }else{
  11716. this.oApp.exec("SHOW_ACTIVE_LAYER", [oLayer, sOnCloseCmd, aOnCloseParam]);
  11717. if(sOnOpenCmd){this.oApp.exec(sOnOpenCmd, aOnOpenParam);}
  11718. }
  11719. },
  11720. $ON_SHOW_ACTIVE_LAYER : function(oLayer, sOnCloseCmd, aOnCloseParam){
  11721. oLayer = jindo.$(oLayer);
  11722. var oPrevLayer = this.oCurrentLayer;
  11723. if(oLayer == oPrevLayer){return;}
  11724. this.oApp.exec("HIDE_ACTIVE_LAYER", []);
  11725. this.sOnCloseCmd = sOnCloseCmd;
  11726. this.aOnCloseParam = aOnCloseParam;
  11727. oLayer.style.display = "block";
  11728. this.oCurrentLayer = oLayer;
  11729. this.oApp.exec("ADD_APP_PROPERTY", ["oToolBarLayer", this.oCurrentLayer]);
  11730. },
  11731. $ON_HIDE_ACTIVE_LAYER : function(){
  11732. var oLayer = this.oCurrentLayer;
  11733. if(!oLayer){return;}
  11734. oLayer.style.display = "none";
  11735. this.oCurrentLayer = null;
  11736. if(this.sOnCloseCmd){
  11737. this.oApp.exec(this.sOnCloseCmd, this.aOnCloseParam);
  11738. }
  11739. },
  11740. $ON_HIDE_ACTIVE_LAYER_IF_NOT_CHILD : function(el){
  11741. var elTmp = el;
  11742. while(elTmp){
  11743. if(elTmp == this.oCurrentLayer){
  11744. return;
  11745. }
  11746. elTmp = elTmp.parentNode;
  11747. }
  11748. this.oApp.exec("HIDE_ACTIVE_LAYER");
  11749. },
  11750. // for backward compatibility only.
  11751. // use HIDE_ACTIVE_LAYER instead!
  11752. $ON_HIDE_CURRENT_ACTIVE_LAYER : function(){
  11753. this.oApp.exec("HIDE_ACTIVE_LAYER", []);
  11754. }
  11755. });
  11756. //{
  11757. /**
  11758. * @fileOverview This file contains Husky plugin that takes care of the operations related to string conversion. Ususally used to convert the IR value.
  11759. * @name hp_StringConverterManager.js
  11760. */
  11761. nhn.husky.StringConverterManager = jindo.$Class({
  11762. name : "StringConverterManager",
  11763. oConverters : null,
  11764. $init : function(){
  11765. this.oConverters = {};
  11766. this.oConverters_DOM = {};
  11767. this.oAgent = jindo.$Agent().navigator();
  11768. },
  11769. $BEFORE_MSG_APP_READY : function(){
  11770. this.oApp.exec("ADD_APP_PROPERTY", ["applyConverter", jindo.$Fn(this.applyConverter, this).bind()]);
  11771. this.oApp.exec("ADD_APP_PROPERTY", ["addConverter", jindo.$Fn(this.addConverter, this).bind()]);
  11772. this.oApp.exec("ADD_APP_PROPERTY", ["addConverter_DOM", jindo.$Fn(this.addConverter_DOM, this).bind()]);
  11773. },
  11774. applyConverter : function(sRuleName, sContents, oDocument){
  11775. //string을 넣는 이유:IE의 경우,본문 앞에 있는 html 주석이 삭제되는 경우가 있기때문에 임시 string을 추가해준것임.
  11776. var sTmpStr = "@"+(new Date()).getTime()+"@";
  11777. var rxTmpStr = new RegExp(sTmpStr, "g");
  11778. var oRes = {sContents:sTmpStr+sContents};
  11779. oDocument = oDocument || document;
  11780. this.oApp.exec("MSG_STRING_CONVERTER_STARTED", [sRuleName, oRes]);
  11781. // this.oApp.exec("MSG_STRING_CONVERTER_STARTED_"+sRuleName, [oRes]);
  11782. var aConverters;
  11783. sContents = oRes.sContents;
  11784. aConverters = this.oConverters_DOM[sRuleName];
  11785. if(aConverters){
  11786. var elContentsHolder = oDocument.createElement("DIV");
  11787. elContentsHolder.innerHTML = sContents;
  11788. for(var i=0; i<aConverters.length; i++){
  11789. aConverters[i](elContentsHolder);
  11790. }
  11791. sContents = elContentsHolder.innerHTML;
  11792. // 내용물에 EMBED등이 있을 경우 IE에서 페이지 나갈 때 권한 오류 발생 할 수 있어 명시적으로 노드 삭제.
  11793. if(!!elContentsHolder.parentNode){
  11794. elContentsHolder.parentNode.removeChild(elContentsHolder);
  11795. }
  11796. elContentsHolder = null;
  11797. //IE의 경우, sContents를 innerHTML로 넣는 경우 string과 <p>tag 사이에 '\n\'개행문자를 넣어준다.
  11798. if( jindo.$Agent().navigator().ie ){
  11799. sTmpStr = sTmpStr +'(\r\n)?'; //ie+win에서는 개행이 \r\n로 들어감.
  11800. rxTmpStr = new RegExp(sTmpStr , "g");
  11801. }
  11802. }
  11803. aConverters = this.oConverters[sRuleName];
  11804. if(aConverters){
  11805. for(var i=0; i<aConverters.length; i++){
  11806. var sTmpContents = aConverters[i](sContents);
  11807. if(typeof sTmpContents != "undefined"){
  11808. sContents = sTmpContents;
  11809. }
  11810. }
  11811. }
  11812. oRes = {sContents:sContents};
  11813. this.oApp.exec("MSG_STRING_CONVERTER_ENDED", [sRuleName, oRes]);
  11814. oRes.sContents = oRes.sContents.replace(rxTmpStr, "");
  11815. return oRes.sContents;
  11816. },
  11817. $ON_ADD_CONVERTER : function(sRuleName, funcConverter){
  11818. var aCallerStack = this.oApp.aCallerStack;
  11819. funcConverter.sPluginName = aCallerStack[aCallerStack.length-2].name;
  11820. this.addConverter(sRuleName, funcConverter);
  11821. },
  11822. $ON_ADD_CONVERTER_DOM : function(sRuleName, funcConverter){
  11823. var aCallerStack = this.oApp.aCallerStack;
  11824. funcConverter.sPluginName = aCallerStack[aCallerStack.length-2].name;
  11825. this.addConverter_DOM(sRuleName, funcConverter);
  11826. },
  11827. addConverter : function(sRuleName, funcConverter){
  11828. var aConverters = this.oConverters[sRuleName];
  11829. if(!aConverters){
  11830. this.oConverters[sRuleName] = [];
  11831. }
  11832. this.oConverters[sRuleName][this.oConverters[sRuleName].length] = funcConverter;
  11833. },
  11834. addConverter_DOM : function(sRuleName, funcConverter){
  11835. var aConverters = this.oConverters_DOM[sRuleName];
  11836. if(!aConverters){
  11837. this.oConverters_DOM[sRuleName] = [];
  11838. }
  11839. this.oConverters_DOM[sRuleName][this.oConverters_DOM[sRuleName].length] = funcConverter;
  11840. }
  11841. });
  11842. //}
  11843. /**
  11844. * @fileOverview This file contains Husky plugin that maps a message code to the actual message
  11845. * @name hp_MessageManager.js
  11846. */
  11847. nhn.husky.MessageManager = jindo.$Class({
  11848. name : "MessageManager",
  11849. _oMessageMapSet : {},
  11850. _sDefaultLocale : "ko_KR",
  11851. $init : function(oMessageMap, sLocale){
  11852. // 하위호환을 위해 기존 코드 유지
  11853. var oTmpMessageMap;
  11854. switch(sLocale) {
  11855. case "ja_JP" :
  11856. oTmpMessageMap = oMessageMap_ja_JP;
  11857. break;
  11858. case "en_US" :
  11859. oTmpMessageMap = oMessageMap_en_US;
  11860. break;
  11861. case "zh_CN" :
  11862. oTmpMessageMap = oMessageMap_zh_CN;
  11863. break;
  11864. default : // Korean
  11865. oTmpMessageMap = oMessageMap;
  11866. break;
  11867. }
  11868. oTmpMessageMap = oTmpMessageMap || oMessageMap;
  11869. this._sDefaultLocale = sLocale || this._sDefaultLocale;
  11870. this._setMessageMap(oTmpMessageMap, this._sDefaultLocale);
  11871. },
  11872. /**
  11873. * 로케일에 해당하는 메시지맵을 세팅한다.
  11874. * @param {Object} oMessageMap 세팅할 메시지맵 객체
  11875. * @param {String} [sLocale] 메시지맵 객체를 세팅할 로케일 정보
  11876. */
  11877. _setMessageMap : function(oMessageMap, sLocale){
  11878. sLocale = sLocale || this._sDefaultLocale;
  11879. if(oMessageMap){
  11880. this._oMessageMapSet[sLocale] = oMessageMap;
  11881. }
  11882. },
  11883. /**
  11884. * 로케일에 해당하는 메시지맵을 가져온다.
  11885. * @param {String} [sLocale] 가져올 메시지맵 객체의 로케일 정보
  11886. * @returns {Object} 메시지맵
  11887. */
  11888. _getMessageMap : function(sLocale){
  11889. return this._oMessageMapSet[sLocale] || this._oMessageMapSet[this._sDefaultLocale] || {};
  11890. },
  11891. $BEFORE_MSG_APP_READY : function(){
  11892. this.oApp.exec("ADD_APP_PROPERTY", ["$MSG", jindo.$Fn(this.getMessage, this).bind()]);
  11893. },
  11894. /**
  11895. * 메시지문자열을 가져온다.
  11896. * @param {String} sMsg 메시지키
  11897. * @param {String} [sLocale] 가져올 메시지의 로케일 정보
  11898. * @returns {String} 해당로케일의 메시지문자열
  11899. */
  11900. getMessage : function(sMsg, sLocale){
  11901. var oMessageMap = this._getMessageMap(sLocale);
  11902. if(oMessageMap[sMsg]){return unescape(oMessageMap[sMsg]);}
  11903. return sMsg;
  11904. }
  11905. });
  11906. //{
  11907. /**
  11908. * @fileOverview This file contains
  11909. * @name hp_LazyLoader.js
  11910. */
  11911. nhn.husky.LazyLoader = jindo.$Class({
  11912. name : "LazyLoader",
  11913. // sMsg : KEY
  11914. // contains htLoadingInfo : {}
  11915. htMsgInfo : null,
  11916. // contains objects
  11917. // sURL : HTML to be loaded
  11918. // elTarget : where to append the HTML
  11919. // sSuccessCallback : message name
  11920. // sFailureCallback : message name
  11921. // nLoadingStatus :
  11922. // 0 : loading not started
  11923. // 1 : loading started
  11924. // 2 : loading ended
  11925. aLoadingInfo : null,
  11926. // aToDo : [{aMsgs: ["EXECCOMMAND"], sURL: "http://127.0.0.1/html_snippet.txt", elTarget: elPlaceHolder}, ...]
  11927. $init : function(aToDo){
  11928. this.htMsgInfo = {};
  11929. this.aLoadingInfo = [];
  11930. this.aToDo = aToDo;
  11931. },
  11932. $ON_MSG_APP_READY : function(){
  11933. for(var i=0; i<this.aToDo.length; i++){
  11934. var htToDoDetail = this.aToDo[i];
  11935. this._createBeforeHandlersAndSaveURLInfo(htToDoDetail.oMsgs, htToDoDetail.sURL, htToDoDetail.elTarget, htToDoDetail.htOptions);
  11936. }
  11937. },
  11938. $LOCAL_BEFORE_ALL : function(sMsgHandler, aParams){
  11939. var sMsg = sMsgHandler.replace("$BEFORE_", "");
  11940. var htCurMsgInfo = this.htMsgInfo[sMsg];
  11941. // ignore current message
  11942. if(htCurMsgInfo.nLoadingStatus == 1){return true;}
  11943. // the HTML was loaded before(probably by another message), remove the loading handler and re-send the message
  11944. if(htCurMsgInfo.nLoadingStatus == 2){
  11945. this[sMsgHandler] = function(){
  11946. this._removeHandler(sMsgHandler);
  11947. this.oApp.delayedExec(sMsg, aParams, 0);
  11948. return false;
  11949. };
  11950. return true;
  11951. }
  11952. htCurMsgInfo.bLoadingStatus = 1;
  11953. (new jindo.$Ajax(htCurMsgInfo.sURL, {
  11954. onload : jindo.$Fn(this._onload, this).bind(sMsg, aParams)
  11955. })).request();
  11956. return true;
  11957. },
  11958. _onload : function(sMsg, aParams, oResponse){
  11959. if(oResponse._response.readyState == 4) {
  11960. this.htMsgInfo[sMsg].elTarget.innerHTML = oResponse.text();
  11961. this.htMsgInfo[sMsg].nLoadingStatus = 2;
  11962. this._removeHandler("$BEFORE_"+sMsg);
  11963. this.oApp.exec("sMsg", aParams);
  11964. }else{
  11965. this.oApp.exec(this.htMsgInfo[sMsg].sFailureCallback, []);
  11966. }
  11967. },
  11968. _removeHandler : function(sMsgHandler){
  11969. delete this[sMsgHandler];
  11970. this.oApp.createMessageMap(sMsgHandler);
  11971. },
  11972. _createBeforeHandlersAndSaveURLInfo : function(oMsgs, sURL, elTarget, htOptions){
  11973. htOptions = htOptions || {};
  11974. var htNewInfo = {
  11975. sURL : sURL,
  11976. elTarget : elTarget,
  11977. sSuccessCallback : htOptions.sSuccessCallback,
  11978. sFailureCallback : htOptions.sFailureCallback,
  11979. nLoadingStatus : 0
  11980. };
  11981. this.aLoadingInfo[this.aLoadingInfo.legnth] = htNewInfo;
  11982. // extract msgs if plugin is given
  11983. if(!(oMsgs instanceof Array)){
  11984. var oPlugin = oMsgs;
  11985. oMsgs = [];
  11986. var htMsgAdded = {};
  11987. for(var sFunctionName in oPlugin){
  11988. if(sFunctionName.match(/^\$(BEFORE|ON|AFTER)_(.+)$/)){
  11989. var sMsg = RegExp.$2;
  11990. if(sMsg == "MSG_APP_READY"){continue;}
  11991. if(!htMsgAdded[sMsg]){
  11992. oMsgs[oMsgs.length] = RegExp.$2;
  11993. htMsgAdded[sMsg] = true;
  11994. }
  11995. }
  11996. }
  11997. }
  11998. for(var i=0; i<oMsgs.length; i++){
  11999. // create HTML loading handler
  12000. var sTmpMsg = "$BEFORE_"+oMsgs[i];
  12001. this[sTmpMsg] = function(){return false;};
  12002. this.oApp.createMessageMap(sTmpMsg);
  12003. // add loading info
  12004. this.htMsgInfo[oMsgs[i]] = htNewInfo;
  12005. }
  12006. }
  12007. });
  12008. //}
  12009. /**
  12010. * @name nhn.husky.PopUpManager
  12011. * @namespace
  12012. * @description 팝업 매니저 클래스.
  12013. * <dt><strong>Spec Code</strong></dt>
  12014. * <dd><a href="http://ajaxui.nhndesign.com/svnview/SmartEditor2_Official/tags/SE2M_popupManager/0.1/test/spec/hp_popupManager_spec.html" target="_new">Spec</a></dd>
  12015. * <dt><strong>wiki</strong></dt>
  12016. * <dd><a href="http://wikin.nhncorp.com/pages/viewpage.action?pageId=63501152" target="_new">wiki</a></dd>
  12017. * @author NHN AjaxUI Lab - sung jong min
  12018. * @version 0.1
  12019. * @since 2009.07.06
  12020. */
  12021. nhn.husky.PopUpManager = {};
  12022. /** * @ignore */
  12023. nhn.husky.PopUpManager._instance = null;
  12024. /** * @ignore */
  12025. nhn.husky.PopUpManager._pluginKeyCnt = 0;
  12026. /**
  12027. * @description 팝업 매니저 인스턴스 호출 메소드, nhn.husky js framework 기반 코드
  12028. * @public
  12029. * @param {Object} oApp 허스키 코어 객체를 넘겨준다.(this.oApp)
  12030. * @return {Object} nhn.husky.PopUpManager Instance
  12031. * @example 팝업관련 플러그인 제작 예제
  12032. * nhn.husky.NewPlugin = function(){
  12033. * this.$ON_APP_READY = function(){
  12034. * // 팝업 매니저 getInstance 메소드를 호출한다.
  12035. * // 허스키 코어의 참조값을 넘겨준다(this.oApp)
  12036. * this.oPopupMgr = nhn.husky.PopUpMaganer.getInstance(this.oApp);
  12037. * };
  12038. *
  12039. * // 팝업을 요청하는 메시지 메소드는 아래와 같음
  12040. * this.$ON_NEWPLUGIN_OPEN_WINDOW = function(){
  12041. * var oWinOp = {
  12042. * oApp : this.oApp, // oApp this.oApp 허스키 참조값
  12043. * sUrl : "", // sUrl : 페이지 URL
  12044. * sName : "", // sName : 페이지 name
  12045. * nWidth : 400,
  12046. * nHeight : 400,
  12047. * bScroll : true
  12048. * }
  12049. * this.oPopUpMgr.openWindow(oWinOp);
  12050. * };
  12051. *
  12052. * // 팝업페이지 응답데이타 반환 메시지 메소드를 정의함.
  12053. * // 각 플러그인 팝업페이지에서 해당 메시지와 데이타를 넘기게 됨.
  12054. * this.@ON_NEWPLUGIN_WINDOW_CALLBACK = function(){
  12055. * // 팝업페이지별로 정의된 형태의 아규먼트 데이타가 넘어오면 처리한다.
  12056. * }
  12057. * }
  12058. * @example 팝업 페이지와 opener 호출 인터페이스 예제
  12059. * onclick시
  12060. * "nhn.husky.PopUpManager.setCallback(window, "NEWPLUGIN_WINDOW_CALLBACK", oData);"
  12061. * 형태로 호출함.
  12062. *
  12063. *
  12064. */
  12065. nhn.husky.PopUpManager.getInstance = function(oApp) {
  12066. if (this._instance==null) {
  12067. this._instance = new (function(){
  12068. this._whtPluginWin = new jindo.$H();
  12069. this._whtPlugin = new jindo.$H();
  12070. this.addPlugin = function(sKey, vValue){
  12071. this._whtPlugin.add(sKey, vValue);
  12072. };
  12073. this.getPlugin = function() {
  12074. return this._whtPlugin;
  12075. };
  12076. this.getPluginWin = function() {
  12077. return this._whtPluginWin;
  12078. };
  12079. this.openWindow = function(oWinOpt) {
  12080. var op= {
  12081. oApp : null,
  12082. sUrl : "",
  12083. sName : "popup",
  12084. sLeft : null,
  12085. sTop : null,
  12086. nWidth : 400,
  12087. nHeight : 400,
  12088. sProperties : null,
  12089. bScroll : true
  12090. };
  12091. for(var i in oWinOpt) op[i] = oWinOpt[i];
  12092. if(op.oApp == null) {
  12093. alert("팝업 요청시 옵션으로 oApp(허스키 reference) 값을 설정하셔야 합니다.");
  12094. }
  12095. var left = op.sLeft || (screen.availWidth-op.nWidth)/2;
  12096. var top = op.sTop ||(screen.availHeight-op.nHeight)/2;
  12097. var sProperties = op.sProperties != null ? op.sProperties :
  12098. "top="+ top +",left="+ left +",width="+op.nWidth+",height="+op.nHeight+",scrollbars="+(op.bScroll?"yes":"no")+",status=yes";
  12099. var win = window.open(op.sUrl, op.sName,sProperties);
  12100. if (!!win) {
  12101. setTimeout( function(){
  12102. try{win.focus();}catch(e){}
  12103. }, 100);
  12104. }
  12105. this.removePluginWin(win);
  12106. this._whtPluginWin.add(this.getCorrectKey(this._whtPlugin, op.oApp), win);
  12107. return win;
  12108. };
  12109. this.getCorrectKey = function(whtData, oCompare) {
  12110. var key = null;
  12111. whtData.forEach(function(v,k){
  12112. if (v == oCompare) {
  12113. key = k;
  12114. return;
  12115. }
  12116. });
  12117. return key;
  12118. };
  12119. this.removePluginWin = function(vValue) {
  12120. var list = this._whtPluginWin.search(vValue);
  12121. if (list) {
  12122. this._whtPluginWin.remove(list);
  12123. this.removePluginWin(vValue);
  12124. }
  12125. }
  12126. })();
  12127. }
  12128. this._instance.addPlugin("plugin_" + (this._pluginKeyCnt++), oApp);
  12129. return nhn.husky.PopUpManager._instance;
  12130. };
  12131. /**
  12132. * @description opener 연동 interface
  12133. * @public
  12134. * @param {Object} oOpenWin 팝업 페이지의 window 객체
  12135. * @param {Object} sMsg 플러그인 메시지명
  12136. * @param {Object} oData 응답 데이타
  12137. */
  12138. nhn.husky.PopUpManager.setCallback = function(oOpenWin, sMsg, oData) {
  12139. if (this._instance.getPluginWin().hasValue(oOpenWin)) {
  12140. var key = this._instance.getCorrectKey(this._instance.getPluginWin(), oOpenWin);
  12141. if (key) {
  12142. this._instance.getPlugin().$(key).exec(sMsg, oData);
  12143. }
  12144. }
  12145. };
  12146. /**
  12147. * @description opener에 허스키 함수를 실행시키고 데이터 값을 리턴 받음.
  12148. * @param
  12149. */
  12150. nhn.husky.PopUpManager.getFunc = function(oOpenWin, sFunc) {
  12151. if (this._instance.getPluginWin().hasValue(oOpenWin)) {
  12152. var key = this._instance.getCorrectKey(this._instance.getPluginWin(), oOpenWin);
  12153. if (key) {
  12154. return this._instance.getPlugin().$(key)[sFunc]();
  12155. }
  12156. }
  12157. };
  12158. if(typeof window.nhn == 'undefined') { window.nhn = {}; }
  12159. if(!nhn.husky) { nhn.husky = {}; }
  12160. (function(){
  12161. // 구버전 jindo.$Agent polyfill
  12162. var ua = navigator.userAgent,
  12163. oAgent = jindo.$Agent(),
  12164. browser = oAgent.navigator(),
  12165. os = oAgent.os();
  12166. // [SMARTEDITORSUS-1795] 갤럭시노트 기본브라우저 구분을 위해 구분필드 추가
  12167. var aMatch = ua.match(/(SHW-|Chrome|Safari)/gi) || "";
  12168. if(aMatch.length === 2 && aMatch[0] === "SHW-" && aMatch[1] === "Safari"){
  12169. // 갤럭시노트 기본브라우저
  12170. browser.bGalaxyBrowser = true;
  12171. }else if(ua.indexOf("LG-V500") > -1 && ua.indexOf("Version/4.0") > -1){
  12172. // [SMARTEDITORSUS-1802] G패드 기본브라우저
  12173. browser.bGPadBrowser = true;
  12174. }
  12175. // [SMARTEDITORSUS-1860] iOS 버전 확인용
  12176. // os 에서 ios 여부 및 version 정보는 jindo2.3.0 부터 추가되었음
  12177. if(typeof os.ios === 'undefined'){
  12178. os.ios = ua.indexOf("iPad") > -1 || ua.indexOf("iPhone") > -1;
  12179. if(os.ios){
  12180. aMatch = ua.match(/(iPhone )?OS ([\d|_]+)/);
  12181. if(aMatch != null && aMatch[2] != undefined){
  12182. os.version = String(aMatch[2]).split("_").join(".");
  12183. }
  12184. }
  12185. }
  12186. })();
  12187. nhn.husky.SE2M_UtilPlugin = jindo.$Class({
  12188. name : "SE2M_UtilPlugin",
  12189. $BEFORE_MSG_APP_READY : function(){
  12190. this.oApp.exec("ADD_APP_PROPERTY", ["oAgent", jindo.$Agent()]);
  12191. this.oApp.exec("ADD_APP_PROPERTY", ["oNavigator", jindo.$Agent().navigator()]);
  12192. this.oApp.exec("ADD_APP_PROPERTY", ["oUtils", this]);
  12193. },
  12194. $ON_REGISTER_HOTKEY : function(sHotkey, sCMD, aArgs, elTarget) {
  12195. this.oApp.exec("ADD_HOTKEY", [sHotkey, sCMD, aArgs, (elTarget || this.oApp.getWYSIWYGDocument())]);
  12196. },
  12197. $ON_SE2_ATTACH_HOVER_EVENTS : function(aElms){
  12198. this.oApp.exec("ATTACH_HOVER_EVENTS", [aElms, {fnElmToSrc: this._elm2Src, fnElmToTarget: this._elm2Target}]);
  12199. },
  12200. _elm2Src : function(el){
  12201. if(el.tagName == "LI" && el.firstChild && el.firstChild.tagName == "BUTTON"){
  12202. return el.firstChild;
  12203. }else{
  12204. return el;
  12205. }
  12206. },
  12207. _elm2Target : function(el){
  12208. if(el.tagName == "BUTTON" && el.parentNode.tagName == "LI"){
  12209. return el.parentNode;
  12210. }else{
  12211. return el;
  12212. }
  12213. },
  12214. getScrollXY : function(){
  12215. var scrollX,scrollY;
  12216. var oAppWindow = this.oApp.getWYSIWYGWindow();
  12217. if(typeof oAppWindow.scrollX == "undefined"){
  12218. scrollX = oAppWindow.document.documentElement.scrollLeft;
  12219. scrollY = oAppWindow.document.documentElement.scrollTop;
  12220. }else{
  12221. scrollX = oAppWindow.scrollX;
  12222. scrollY = oAppWindow.scrollY;
  12223. }
  12224. return {x:scrollX, y:scrollY};
  12225. }
  12226. });
  12227. nhn.husky.SE2M_Utils = {
  12228. sURLPattern : '(http|https|ftp|mailto):(?:\\/\\/)?((:?\\w|-)+(:?\\.(:?\\w|-)+)+)([^ <>]+)?',
  12229. rxDateFormat : /^(?:\d{4}\.)?\d{1,2}\.\d{1,2}$/,
  12230. _rxTable : /^(?:CAPTION|TBODY|THEAD|TFOOT|TR|TD|TH|COLGROUP|COL)$/i,
  12231. _rxSpaceOnly : /^\s+$/,
  12232. _rxFontStart : /<font(?:\s+[^>]*)?>/i,
  12233. _htFontSize : { // @see http://jerekdain.com/fontconversion.html
  12234. "1" : "7pt",
  12235. "2" : "10pt",
  12236. "3" : "12pt",
  12237. "4" : "13.5pt",
  12238. "5" : "18pt",
  12239. "6" : "24pt"
  12240. },
  12241. /**
  12242. * 유효하지 않은 노드가 TBODY, TR, TD 등등 사이에 있는지 판별한다.
  12243. * @param oNode {Node} 검사할 노드
  12244. * @return {Boolean} TBODY, TR, TD 등등 사이에 있는 유효하지 않은 노드인지 여부
  12245. */
  12246. isInvalidNodeInTable : function(oNode){
  12247. // 해당노드가 table 관련노드들이 아닌데 table 관련노드들 사이에 있는지 검사한다.
  12248. // TODO: 좀 더 정확하게 검사할 필요가 있을까?
  12249. if(oNode && !this._rxTable.test(oNode.nodeName)){
  12250. var oTmpNode;
  12251. if((oTmpNode = oNode.previousSibling) && this._rxTable.test(oTmpNode.nodeName)){
  12252. return true;
  12253. }
  12254. if((oTmpNode = oNode.nextSibling) && this._rxTable.test(oTmpNode.nodeName)){
  12255. return true;
  12256. }
  12257. }
  12258. return false;
  12259. },
  12260. /**
  12261. * [SMARTEDITORSUS-1584][SMARTEDITORSUS-2237]
  12262. * TBODY, TR, TD 사이에 있는 유효하지 않은 노드이면 제거한다.
  12263. * @param oNode {Node} 검사할 노드
  12264. */
  12265. removeInvalidNodeInTable : function(oNode){
  12266. if(this.isInvalidNodeInTable(oNode) && oNode.parentNode){
  12267. oNode.parentNode.removeChild(oNode);
  12268. }
  12269. },
  12270. /**
  12271. * [SMARTEDITORSUS-2315] 유효하지 않은 폰트태그를 제거한다.
  12272. * @param {Element} el 태그정제를 제한할 상위 요소
  12273. */
  12274. removeInvalidFont : function(el){
  12275. if(!el){
  12276. return;
  12277. }
  12278. this._removeInvalidFontInTable(el);
  12279. this._removeEmptyFont(el);
  12280. },
  12281. /**
  12282. * [SMARTEDITORSUS-2237] IE11 에서 엑셀을 복사붙여넣기하면 유효하지 않은 위치(tbody, tr, td 사이) font 태그가 삽입되므로 제거
  12283. * @param {Element} el 태그제거를 제한할 상위 요소
  12284. */
  12285. _removeInvalidFontInTable : function(el){
  12286. var aelFonts = jindo.$$("table font", el);
  12287. for(var i = 0, elFont; (elFont = aelFonts[i]); i++){
  12288. this.removeInvalidNodeInTable(elFont);
  12289. }
  12290. },
  12291. /**
  12292. * 폰트태그를 제거한다.
  12293. * @param {Element} el 태그제거를 제한할 상위 요소
  12294. */
  12295. _removeEmptyFont : function(el){
  12296. var aelFonts = jindo.$$("font", el);
  12297. for(var i = 0, elFont, sInner; (elFont = aelFonts[i]); i++){
  12298. sInner = elFont.innerHTML || "";
  12299. sInner = sInner.replace(this._rxSpaceOnly, "");
  12300. if (!sInner) {
  12301. elFont.parentNode.removeChild(elFont);
  12302. }
  12303. }
  12304. },
  12305. /**
  12306. * [SMARTEDITORSUS-2315] font 태그를 span 으로 변환
  12307. * 포스트이슈[MUG-7757] 처리 로직 참고
  12308. * @param {Element} el 태그변환을 제한할 상위 요소
  12309. */
  12310. convertFontToSpan : function(el){
  12311. if(!el){
  12312. return;
  12313. }
  12314. var oDoc = el.ownerDocument || document;
  12315. var aelTarget = jindo.$$("font", el);
  12316. for(var i = 0, elTarget, elSpan, sAttrValue; (elTarget = aelTarget[i]); i++){
  12317. elSpan = elTarget.parentNode;
  12318. if(elSpan.tagName !== "SPAN" || elSpan.childNodes.length > 1){
  12319. elSpan = oDoc.createElement("SPAN");
  12320. elTarget.parentNode.insertBefore(elSpan, elTarget);
  12321. }
  12322. sAttrValue = elTarget.getAttribute("face");
  12323. if(sAttrValue){
  12324. elSpan.style.fontFamily = sAttrValue;
  12325. }
  12326. sAttrValue = this._htFontSize[elTarget.getAttribute("size")];
  12327. if(sAttrValue){
  12328. elSpan.style.fontSize = sAttrValue;
  12329. }
  12330. sAttrValue = elTarget.getAttribute("color");
  12331. if(sAttrValue){
  12332. elSpan.style.color = sAttrValue;
  12333. }
  12334. // font태그 안쪽 내용을 span에 넣는다.
  12335. this._switchFontInnerToSpan(elTarget, elSpan);
  12336. if(elTarget.parentNode){
  12337. elTarget.parentNode.removeChild(elTarget);
  12338. }
  12339. }
  12340. },
  12341. /**
  12342. * font태그 안쪽 내용을 span에 넣는다.
  12343. * @param {Element} elFont 대상FONT태그
  12344. * @param {Element} elSpan 빈SPAN태그
  12345. */
  12346. _switchFontInnerToSpan : function(elFont, elSpan){
  12347. var sInnerHTML = elFont.innerHTML;
  12348. /**
  12349. * 폰트태그안에 폰트태그가 있을때 innerHTML으로 넣으면 안쪽 폰트태그는 span변환작업에서 누락될 있기 때문에
  12350. * 폰트태그가 중첩해서 있으면 appendChild를 이용하고 그렇지 않으면 innerHTML을 이용
  12351. */
  12352. if(this._rxFontStart.test(sInnerHTML)){
  12353. for(var elChild; (elChild = elFont.firstChild);){
  12354. elSpan.appendChild(elChild);
  12355. }
  12356. }else{
  12357. elSpan.innerHTML = sInnerHTML;
  12358. }
  12359. },
  12360. /**
  12361. * 대상요소의 하위 요소들을 모두 밖으로 빼내고 대상요소를 제거한다.
  12362. * @param {Element} el 제거 대상 요소
  12363. */
  12364. stripTag : function(el){
  12365. for(var elChild; (elChild = el.firstChild);){
  12366. el.parentNode.insertBefore(elChild, el);
  12367. }
  12368. el.parentNode.removeChild(el);
  12369. },
  12370. /**
  12371. * 노드 하위의 특정태그를 모두 제거한다.
  12372. * @param {Element} el 확인 대상 요소
  12373. * @param {String} sTagName 제거 대상 태그명 (대문자)
  12374. */
  12375. stripTags :function(el, sTagName){
  12376. var aelTarget = jindo.$$(sTagName, el);
  12377. for(var i = 0, elTarget; (elTarget = aelTarget[i]); i++){
  12378. this.stripTag(elTarget);
  12379. }
  12380. },
  12381. /**
  12382. * [SMARTEDITORSUS-2203] 날짜표기를 바로 잡는다. ex) 2015.10.13 -> 2015.10.13.
  12383. * @param {String} sDate 확인할 문자열
  12384. * @returns {String} 올바른 표기로 변환한 문자열
  12385. */
  12386. reviseDateFormat : function(sDate){
  12387. if(sDate && sDate.replace){
  12388. sDate = sDate.replace(this.rxDateFormat, "$&.");
  12389. }
  12390. return sDate;
  12391. },
  12392. /**
  12393. * 사용자 클래스 정보를 추출한다.
  12394. * @param {String} sStr 추출 String
  12395. * @param {rx} rxValue rx type 형식의
  12396. * @param {String} sDivision value의 split 형식
  12397. * @return {Array}
  12398. */
  12399. getCustomCSS : function(sStr, rxValue, sDivision) {
  12400. var ret = [];
  12401. if('undefined' == typeof(sStr) || 'undefined' == typeof(rxValue) || !sStr || !rxValue) {
  12402. return ret;
  12403. }
  12404. var aMatch = sStr.match(rxValue);
  12405. if(aMatch && aMatch[0]&&aMatch[1]) {
  12406. if(sDivision) {
  12407. ret = aMatch[1].split(sDivision);
  12408. } else {
  12409. ret[0] = aMatch[1];
  12410. }
  12411. }
  12412. return ret;
  12413. },
  12414. /**
  12415. * HashTable로 구성된 Array의 같은 프로퍼티를 sSeperator 구분된 String 값으로 변환
  12416. * @param {Object} v
  12417. * @param {Object} sKey
  12418. * @author senxation
  12419. * @example
  12420. a = [{ b : "1" }, { b : "2" }]
  12421. toStringSamePropertiesOfArray(a, "b", ", ");
  12422. ==> "1, 2"
  12423. */
  12424. toStringSamePropertiesOfArray : function(v, sKey, sSeperator) {
  12425. if(!v){
  12426. return "";
  12427. }
  12428. if (v instanceof Array) {
  12429. var a = [];
  12430. for (var i = 0; i < v.length; i++) {
  12431. a.push(v[i][sKey]);
  12432. }
  12433. return a.join(",").replace(/,/g, sSeperator);
  12434. }
  12435. else {
  12436. if (typeof v[sKey] == "undefined") {
  12437. return "";
  12438. }
  12439. if (typeof v[sKey] == "string") {
  12440. return v[sKey];
  12441. }
  12442. }
  12443. },
  12444. /**
  12445. * 단일 객체를 배열로 만들어줌
  12446. * @param {Object} v
  12447. * @return {Array}
  12448. * @author senxation
  12449. * @example
  12450. makeArray("test"); ==> ["test"]
  12451. */
  12452. makeArray : function(v) {
  12453. if (v === null || typeof v === "undefined"){
  12454. return [];
  12455. }
  12456. if (v instanceof Array) {
  12457. return v;
  12458. }
  12459. var a = [];
  12460. a.push(v);
  12461. return a;
  12462. },
  12463. /**
  12464. * 말줄임을 할때 줄일 내용과 컨테이너가 다를 경우 처리
  12465. * 컨테이너의 css white-space값이 "normal"이어야한다. (컨테이너보다 텍스트가 길면 여러행으로 표현되는 상태)
  12466. * @param {HTMLElement} elText 말줄임할 엘리먼트
  12467. * @param {HTMLElement} elContainer 말줄임할 엘리먼트를 감싸는 컨테이너
  12468. * @param {String} sStringTail 말줄임을 표현할 문자열 (미지정시 ...)
  12469. * @param {Number} nLine 최대 라인수 (미지정시 1)
  12470. * @author senxation
  12471. * @example
  12472. //div가 2줄 이하가 되도록 strong 내부의 내용을 줄임
  12473. <div>
  12474. <strong id="a">말줄임을적용할내용말줄임을적용할내용말줄임을적용할내용</strong><span></span>
  12475. <div>
  12476. ellipsis(jindo.$("a"), jindo.$("a").parentNode, "...", 2);
  12477. */
  12478. ellipsis : function(elText, elContainer, sStringTail, nLine) {
  12479. sStringTail = sStringTail || "...";
  12480. if (typeof nLine == "undefined") {
  12481. nLine = 1;
  12482. }
  12483. var welText = jindo.$Element(elText);
  12484. var welContainer = jindo.$Element(elContainer);
  12485. var sText = welText.html();
  12486. var nLength = sText.length;
  12487. var nCurrentHeight = welContainer.height();
  12488. var nIndex = 0;
  12489. welText.html('A');
  12490. var nHeight = welContainer.height();
  12491. if (nCurrentHeight < nHeight * (nLine + 0.5)) {
  12492. return welText.html(sText);
  12493. }
  12494. /**
  12495. * 지정된 라인보다 커질때까지 전체 남은 문자열의 절반을 더해나감
  12496. */
  12497. nCurrentHeight = nHeight;
  12498. while(nCurrentHeight < nHeight * (nLine + 0.5)) {
  12499. nIndex += Math.max(Math.ceil((nLength - nIndex)/2), 1);
  12500. welText.html(sText.substring(0, nIndex) + sStringTail);
  12501. nCurrentHeight = welContainer.height();
  12502. }
  12503. /**
  12504. * 지정된 라인이 될때까지 한글자씩 잘라냄
  12505. */
  12506. while(nCurrentHeight > nHeight * (nLine + 0.5)) {
  12507. nIndex--;
  12508. welText.html(sText.substring(0, nIndex) + sStringTail);
  12509. nCurrentHeight = welContainer.height();
  12510. }
  12511. },
  12512. /**
  12513. * 최대 가로사이즈를 지정하여 말줄임한다.
  12514. * elText의 css white-space값이 "nowrap"이어야한다. (컨테이너보다 텍스트가 길면 행변환되지않고 가로로 길게 표현되는 상태)
  12515. * @param {HTMLElement} elText 말줄임할 엘리먼트
  12516. * @param {String} sStringTail 말줄임을 표현할 문자열 (미지정시 ...)
  12517. * @param {Function} fCondition 조건 함수. 내부에서 true를 리턴하는 동안에만 말줄임을 진행한다.
  12518. * @author senxation
  12519. * @example
  12520. //150픽셀 이하가 되도록 strong 내부의 내용을 줄임
  12521. <strong id="a">말줄임을적용할내용말줄임을적용할내용말줄임을적용할내용</strong>>
  12522. ellipsisByPixel(jindo.$("a"), "...", 150);
  12523. */
  12524. ellipsisByPixel : function(elText, sStringTail, nPixel, fCondition) {
  12525. sStringTail = sStringTail || "...";
  12526. var welText = jindo.$Element(elText);
  12527. var nCurrentWidth = welText.width();
  12528. if (nCurrentWidth < nPixel) {
  12529. return;
  12530. }
  12531. var sText = welText.html();
  12532. var nLength = sText.length;
  12533. var nIndex = 0;
  12534. if (typeof fCondition == "undefined") {
  12535. var nWidth = welText.html('A').width();
  12536. nCurrentWidth = nWidth;
  12537. while(nCurrentWidth < nPixel) {
  12538. nIndex += Math.max(Math.ceil((nLength - nIndex)/2), 1);
  12539. welText.html(sText.substring(0, nIndex) + sStringTail);
  12540. nCurrentWidth = welText.width();
  12541. }
  12542. fCondition = function() {
  12543. return true;
  12544. };
  12545. }
  12546. nIndex = welText.html().length - sStringTail.length;
  12547. while(nCurrentWidth > nPixel) {
  12548. if (!fCondition()) {
  12549. break;
  12550. }
  12551. nIndex--;
  12552. welText.html(sText.substring(0, nIndex) + sStringTail);
  12553. nCurrentWidth = welText.width();
  12554. }
  12555. },
  12556. /**
  12557. * 여러개의 엘리먼트를 각각의 지정된 최대너비로 말줄임한다.
  12558. * 말줄임할 엘리먼트의 css white-space값이 "nowrap"이어야한다. (컨테이너보다 텍스트가 길면 행변환되지않고 가로로 길게 표현되는 상태)
  12559. * @param {Array} aElement 말줄임할 엘리먼트의 배열. 지정된 순서대로 말줄임한다.
  12560. * @param {String} sStringTail 말줄임을 표현할 문자열 (미지정시 ...)
  12561. * @param {Array} aMinWidth 말줄임할 너비의 배열.
  12562. * @param {Function} fCondition 조건 함수. 내부에서 true를 리턴하는 동안에만 말줄임을 진행한다.
  12563. * @example
  12564. //#a #b #c의 너비를 각각 100, 50, 50픽셀로 줄임 (div#parent 가 200픽셀 이하이면 중단)
  12565. //#c의 너비를 줄이는 동안 fCondition에서 false를 리턴하면 b, a는 말줄임 되지 않는다.
  12566. <div id="parent">
  12567. <strong id="a">말줄임을적용할내용</strong>
  12568. <strong id="b">말줄임을적용할내용</strong>
  12569. <strong id="c">말줄임을적용할내용</strong>
  12570. <div>
  12571. ellipsisElementsToDesinatedWidth([jindo.$("c"), jindo.$("b"), jindo.$("a")], "...", [100, 50, 50], function(){
  12572. if (jindo.$Element("parent").width() > 200) {
  12573. return true;
  12574. }
  12575. return false;
  12576. });
  12577. */
  12578. ellipsisElementsToDesinatedWidth : function(aElement, sStringTail, aMinWidth, fCondition) {
  12579. jindo.$A(aElement).forEach(function(el, i){
  12580. if (!el) {
  12581. jindo.$A.Continue();
  12582. }
  12583. nhn.husky.SE2M_Utils.ellipsisByPixel(el, sStringTail, aMinWidth[i], fCondition);
  12584. });
  12585. },
  12586. /**
  12587. * 숫자를 입력받아 정해진 길이만큼 앞에 "0" 추가된 문자열을 구한다.
  12588. * @param {Number} nNumber
  12589. * @param {Number} nLength
  12590. * @return {String}
  12591. * @example
  12592. paddingZero(10, 5); ==> "00010" (String)
  12593. */
  12594. paddingZero : function(nNumber, nLength) {
  12595. var sResult = nNumber.toString();
  12596. while (sResult.length < nLength) {
  12597. sResult = ("0" + sResult);
  12598. }
  12599. return sResult;
  12600. },
  12601. /**
  12602. * string을 byte 단위로 짤라서 tail를 붙힌다.
  12603. * @param {String} sString
  12604. * @param {Number} nByte
  12605. * @param {String} sTail
  12606. * @example
  12607. cutStringToByte('일이삼사오육', 6, '...') ==> '일이삼...' (string)
  12608. */
  12609. cutStringToByte : function(sString, nByte, sTail){
  12610. if(sString === null || sString.length === 0) {
  12611. return sString;
  12612. }
  12613. sString = sString.replace(/ +/g, " ");
  12614. if (!sTail && sTail != "") {
  12615. sTail = "...";
  12616. }
  12617. var maxByte = nByte;
  12618. var n=0;
  12619. var nLen = sString.length;
  12620. for(var i=0; i<nLen;i++){
  12621. n += this.getCharByte(sString.charAt(i));
  12622. if(n == maxByte){
  12623. if(i == nLen-1) {
  12624. return sString;
  12625. } else {
  12626. return sString.substring(0,i)+sTail;
  12627. }
  12628. } else if( n > maxByte ) {
  12629. return sString.substring(0, i)+sTail;
  12630. }
  12631. }
  12632. return sString;
  12633. },
  12634. /**
  12635. * 입력받은 문자의 byte 구한다.
  12636. * @param {String} ch
  12637. *
  12638. */
  12639. getCharByte : function(ch){
  12640. if (ch === null || ch.length < 1) {
  12641. return 0;
  12642. }
  12643. var byteSize = 0;
  12644. var str = escape(ch);
  12645. if ( str.length == 1 ) { // when English then 1byte
  12646. byteSize ++;
  12647. } else if ( str.indexOf("%u") != -1 ) { // when Korean then 2byte
  12648. byteSize += 2;
  12649. } else if ( str.indexOf("%") != -1 ) { // else 3byte
  12650. byteSize += str.length/3;
  12651. }
  12652. return byteSize;
  12653. },
  12654. /**
  12655. * Hash Table에서 원하는 키값만을 가지는 필터된 새로운 Hash Table을 구한다.
  12656. * @param {HashTable} htUnfiltered
  12657. * @param {Array} aKey
  12658. * @return {HashTable}
  12659. * @author senxation
  12660. * @example
  12661. getFilteredHashTable({
  12662. a : 1,
  12663. b : 2,
  12664. c : 3,
  12665. d : 4
  12666. }, ["a", "c"]);
  12667. ==> { a : 1, c : 3 }
  12668. */
  12669. getFilteredHashTable : function(htUnfiltered, vKey) {
  12670. if (!(vKey instanceof Array)) {
  12671. return arguments.callee.call(this, htUnfiltered, [ vKey ]);
  12672. }
  12673. var waKey = jindo.$A(vKey);
  12674. return jindo.$H(htUnfiltered).filter(function(vValue, sKey){
  12675. if (waKey.has(sKey) && vValue) {
  12676. return true;
  12677. } else {
  12678. return false;
  12679. }
  12680. }).$value();
  12681. },
  12682. isBlankNode : function(elNode){
  12683. var isBlankTextNode = this.isBlankTextNode;
  12684. var bEmptyContent = function(elNode){
  12685. if(!elNode) {
  12686. return true;
  12687. }
  12688. if(isBlankTextNode(elNode)){
  12689. return true;
  12690. }
  12691. if(elNode.tagName == "BR") {
  12692. return true;
  12693. }
  12694. if(elNode.innerHTML == "&nbsp;" || elNode.innerHTML == "") {
  12695. return true;
  12696. }
  12697. return false;
  12698. };
  12699. var bEmptyP = function(elNode){
  12700. if(elNode.tagName == "IMG" || elNode.tagName == "IFRAME"){
  12701. return false;
  12702. }
  12703. if(bEmptyContent(elNode)){
  12704. return true;
  12705. }
  12706. if(elNode.tagName == "P"){
  12707. for(var i=elNode.childNodes.length-1; i>=0; i--){
  12708. var elTmp = elNode.childNodes[i];
  12709. if(isBlankTextNode(elTmp)){
  12710. elTmp.parentNode.removeChild(elTmp);
  12711. }
  12712. }
  12713. if(elNode.childNodes.length == 1){
  12714. if(elNode.firstChild.tagName == "IMG" || elNode.firstChild.tagName == "IFRAME"){
  12715. return false;
  12716. }
  12717. if(bEmptyContent(elNode.firstChild)){
  12718. return true;
  12719. }
  12720. }
  12721. }
  12722. return false;
  12723. };
  12724. if(bEmptyP(elNode)){
  12725. return true;
  12726. }
  12727. for(var i=0, nLen=elNode.childNodes.length; i<nLen; i++){
  12728. var elTmp = elNode.childNodes[i];
  12729. if(!bEmptyP(elTmp)){
  12730. return false;
  12731. }
  12732. }
  12733. return true;
  12734. },
  12735. isBlankTextNode : function(oNode){
  12736. var sText;
  12737. if(oNode.nodeType == 3){
  12738. sText = oNode.nodeValue;
  12739. sText = sText.replace(unescape("%uFEFF"), '');
  12740. if(sText == "") {
  12741. return true;
  12742. }
  12743. }
  12744. return false;
  12745. },
  12746. isFirstChildOfNode : function(sTagName, sParentTagName, elNode){
  12747. if(!elNode){
  12748. return false;
  12749. }
  12750. if(elNode.tagName == sParentTagName && elNode.firstChild.tagName == sTagName){
  12751. return true;
  12752. }
  12753. return false;
  12754. },
  12755. /**
  12756. * elNode의 상위 노드 태그명이 sTagName과 일치하는 것이 있다면 반환.
  12757. * @param {String} sTagName 검색 태그명(반드시 대문자를 사용할 )
  12758. * @param {HTMLElement} elNode 검색 시작점으로 사용 노드
  12759. * @return {HTMLElement} 부모 노드 태그명이 sTagName과 일치하는 노드. 없을 경우 null 반환
  12760. */
  12761. findAncestorByTagName : function(sTagName, elNode){
  12762. while(elNode && elNode.tagName != sTagName) {
  12763. elNode = elNode.parentNode;
  12764. }
  12765. return elNode;
  12766. },
  12767. /**
  12768. * [SMARTEDITORSUS-1735]
  12769. * elNode의 상위 노드 태그명이 sTagName과 일치하는 것이 있다면
  12770. * 해당 노드와 재귀 탐색 횟수가 담긴 객체를 반환.
  12771. * @param {String} sTagName 검색 태그명(반드시 대문자를 사용할 )
  12772. * @param {HTMLElement} elNode 검색 시작점으로 사용 노드
  12773. * @return {Object}
  12774. * {HTMLElement} Object.elNode 부모 노드 태그명이 sTagName과 일치하는 노드. 없을 경우 null 반환
  12775. * {Number} Object.nRecursiveCount 재귀 탐색 횟수
  12776. */
  12777. findAncestorByTagNameWithCount : function(sTagName, elNode){
  12778. var nRecursiveCount = 0;
  12779. var htResult = {};
  12780. while(elNode && elNode.tagName != sTagName) {
  12781. elNode = elNode.parentNode;
  12782. nRecursiveCount += 1;
  12783. }
  12784. htResult = {
  12785. elNode : elNode,
  12786. nRecursiveCount : nRecursiveCount
  12787. }
  12788. return htResult;
  12789. },
  12790. /**
  12791. * [SMARTEDITORSUS-1672] elNode의 상위 노드 태그명이 aTagName 요소 하나와 일치하는 것이 있다면 반환.
  12792. * @param {String} aTagName 검색 태그명이 담긴 배열
  12793. * @param {HTMLElement} elNode 검색 시작점으로 사용 노드
  12794. * @return {HTMLElement} 부모 노드 태그명이 aTagName의 요소 하나와 일치하는 노드. 없을 경우 null 반환
  12795. */
  12796. findClosestAncestorAmongTagNames : function(aTagName, elNode){
  12797. var rxTagNames = new RegExp("^(" + aTagName.join("|") + ")$", "i");
  12798. while(elNode && !rxTagNames.test(elNode.tagName)){
  12799. elNode = elNode.parentNode;
  12800. }
  12801. return elNode;
  12802. },
  12803. /**
  12804. * [SMARTEDITORSUS-1735]
  12805. * elNode의 상위 노드 태그명이 aTagName 요소 하나와 일치하는 것이 있다면
  12806. * 해당 노드와 재귀 탐색 횟수가 담긴 객체를 반환.
  12807. * @param {String} aTagName 검색 태그명이 담긴 배열
  12808. * @param {HTMLElement} elNode 검색 시작점으로 사용 노드
  12809. * @return {Object}
  12810. * {HTMLElement} Object.elNode 부모 노드 태그명이 aTagName의 요소 하나와 일치하는 노드. 없을 경우 null 반환
  12811. * {Number} Object.nRecursiveCount 재귀 탐색 횟수
  12812. */
  12813. findClosestAncestorAmongTagNamesWithCount : function(aTagName, elNode){
  12814. var nRecursiveCount = 0;
  12815. var htResult = {};
  12816. var rxTagNames = new RegExp("^(" + aTagName.join("|") + ")$", "i");
  12817. while(elNode && !rxTagNames.test(elNode.tagName)){
  12818. elNode = elNode.parentNode;
  12819. nRecursiveCount += 1;
  12820. }
  12821. htResult = {
  12822. elNode : elNode,
  12823. nRecursiveCount : nRecursiveCount
  12824. }
  12825. return htResult;
  12826. },
  12827. /**
  12828. * [SMARTEDITORSUS-2136] 대상이 Number인지 확인한다.
  12829. *
  12830. * @param {Number} n 판별 대상
  12831. * @return {Boolean} 대상이 Number이다.
  12832. * @see http://stackoverflow.com/questions/18082/validate-decimal-numbers-in-javascript-isnumeric/1830844#1830844
  12833. * */
  12834. isNumber : function(n){
  12835. return !isNaN(parseFloat(n)) && isFinite(n);
  12836. },
  12837. /**
  12838. * [SMARTEDITORSUS-2136] 객체의 property를 delete 연산자로 제거하는 polyfill
  12839. *
  12840. * @param {Object} oTarget 대상 객체
  12841. * @param {String} sProp property
  12842. *
  12843. * @example nhn.husky.SE2M_Utils.deleteProperty(elTable, 'propA'); // elTable.propA를 delete
  12844. *
  12845. * @see http://stackoverflow.com/questions/1073414/deleting-a-window-property-in-ie
  12846. * */
  12847. deleteProperty : function(oTarget, sProp){
  12848. if((typeof(oTarget) !== 'object') || (typeof(sProp) !== 'string') || (typeof(oTarget[sProp]) === 'undefined')){
  12849. return;
  12850. }
  12851. oTarget[sProp] = undefined;
  12852. try{
  12853. delete oTarget[sProp];
  12854. }catch(e){
  12855. // [IE 8-]
  12856. }
  12857. },
  12858. loadCSS : function(url, fnCallback){
  12859. var oDoc = document;
  12860. var elHead = oDoc.getElementsByTagName("HEAD")[0];
  12861. var elStyle = oDoc.createElement ("LINK");
  12862. elStyle.setAttribute("type", "text/css");
  12863. elStyle.setAttribute("rel", "stylesheet");
  12864. elStyle.setAttribute("href", url);
  12865. if(fnCallback){
  12866. if ('onload' in elStyle) {
  12867. elStyle.onload = function(){
  12868. fnCallback();
  12869. // [SMARTEDITORSUS-2032] IE10호환성보기(IE7) 에서 onload 이벤트가 2번 발생할 수 있는 가능성이 있기 때문에
  12870. // 콜백실행 후 onload 이벤트 핸들러를 제거
  12871. this.onload = null;
  12872. };
  12873. } else {
  12874. elStyle.onreadystatechange = function(){
  12875. if(elStyle.readyState != "complete"){
  12876. return;
  12877. }
  12878. // [SMARTEDITORSUS-308] [IE9] 응답이 304인 경우
  12879. // onreadystatechage 핸들러에서 readyState 가 complete 인 경우가 두 번 발생
  12880. // LINK 엘리먼트의 속성으로 콜백 실행 여부를 플래그로 남겨놓아 처리함
  12881. if(elStyle.getAttribute("_complete")){
  12882. return;
  12883. }
  12884. elStyle.setAttribute("_complete", true);
  12885. fnCallback();
  12886. };
  12887. }
  12888. }
  12889. elHead.appendChild (elStyle);
  12890. },
  12891. getUniqueId : function(sPrefix) {
  12892. return (sPrefix || '') + jindo.$Date().time() + (Math.random() * 100000).toFixed();
  12893. },
  12894. /**
  12895. * @param {Object} oSrc value copy할 object
  12896. * @return {Object}
  12897. * @example
  12898. * var oSource = [1, 3, 4, { a:1, b:2, c: { a:1 }}];
  12899. var oTarget = oSource; // call by reference
  12900. oTarget = nhn.husky.SE2M_Utils.clone(oSource);
  12901. oTarget[1] = 2;
  12902. oTarget[3].a = 100;
  12903. console.log(oSource); // check for deep copy
  12904. console.log(oTarget, oTarget instanceof Object); // check instance type!
  12905. */
  12906. clone : function(oSrc, oChange) {
  12907. if ('undefined' != typeof(oSrc) && !!oSrc && (oSrc.constructor == Array || oSrc.constructor == Object)) {
  12908. var oCopy = (oSrc.constructor == Array ? [] : {} );
  12909. for (var property in oSrc) {
  12910. if ('undefined' != typeof(oChange) && !!oChange[property]) {
  12911. oCopy[property] = arguments.callee(oChange[property]);
  12912. } else {
  12913. oCopy[property] = arguments.callee(oSrc[property]);
  12914. }
  12915. }
  12916. return oCopy;
  12917. }
  12918. return oSrc;
  12919. },
  12920. getHtmlTagAttr : function(sHtmlTag, sAttr) {
  12921. var rx = new RegExp('\\s' + sAttr + "=('([^']*)'|\"([^\"]*)\"|([^\"' >]*))", 'i');
  12922. var aResult = rx.exec(sHtmlTag);
  12923. if (!aResult) {
  12924. return '';
  12925. }
  12926. var sAttrTmp = (aResult[1] || aResult[2] || aResult[3]); // for chrome 5.x bug!
  12927. if (!!sAttrTmp) {
  12928. sAttrTmp = sAttrTmp.replace(/[\"]/g, '');
  12929. }
  12930. return sAttrTmp;
  12931. },
  12932. /**
  12933. * iframe 영역의 aling 정보를 다시 세팅하는 부분.
  12934. * iframe 형태의 산출물을 에디터에 삽입 이후에 에디터 정렬기능을 추가 하였을때 ir_to_db 이전 시점에서 div태그에 정렬을 넣어주는 로직임.
  12935. * 브라우저 형태에 따라 정렬 태그가 iframe을 감싸는 div 혹은 p 태그에 정렬이 추가된다.
  12936. * @param {HTMLElement} el iframe의 parentNode
  12937. * @param {Document} oDoc document
  12938. */
  12939. // [COM-1151] SE2M_PreStringConverter 에서 수정하도록 변경
  12940. iframeAlignConverter : function(el, oDoc){
  12941. var sTagName = el.tagName.toUpperCase();
  12942. if(sTagName == "DIV" || sTagName == 'P'){
  12943. //irToDbDOM 에서 최상위 노드가 div 엘리먼트 이므로 parentNode가 없으면 최상의 div 노드 이므로 리턴한다.
  12944. if(el.parentNode === null ){
  12945. return;
  12946. }
  12947. var elWYSIWYGDoc = oDoc;
  12948. var wel = jindo.$Element(el);
  12949. var sHtml = wel.html();
  12950. //현재 align을 얻어오기.
  12951. var sAlign = jindo.$Element(el).attr('align') || jindo.$Element(el).css('text-align');
  12952. //if(!sAlign){ // P > DIV의 경우 문제 발생, 수정 화면에 들어 왔을 때 태그 깨짐
  12953. // return;
  12954. //}
  12955. //새로운 div 노드 생성한다.
  12956. var welAfter = jindo.$Element(jindo.$('<div></div>', elWYSIWYGDoc));
  12957. welAfter.html(sHtml).attr('align', sAlign);
  12958. wel.replace(welAfter);
  12959. }
  12960. },
  12961. /**
  12962. * jindo.$JSON.fromXML을 변환한 메서드.
  12963. * 소숫점이 있는 경우의 처리 시에 숫자로 변환하지 않도록 (parseFloat 사용 안하도록 수정)
  12964. * 관련 BTS : [COM-1093]
  12965. * @param {String} sXML XML 형태의 문자열
  12966. * @return {jindo.$JSON}
  12967. */
  12968. getJsonDatafromXML : function(sXML) {
  12969. var o = {};
  12970. var re = /\s*<(\/?[\w:\-]+)((?:\s+[\w:\-]+\s*=\s*(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*'))*)\s*((?:\/>)|(?:><\/\1>|\s*))|\s*<!\[CDATA\[([\w\W]*?)\]\]>\s*|\s*>?([^<]*)/ig;
  12971. var re2= /^[0-9]+(?:\.[0-9]+)?$/;
  12972. var re3= /^\s+$/g;
  12973. var ec = {"&amp;":"&","&nbsp;":" ","&quot;":"\"","&lt;":"<","&gt;":">"};
  12974. var fg = {tags:["/"],stack:[o]};
  12975. var es = function(s){
  12976. if (typeof s == "undefined") {
  12977. return "";
  12978. }
  12979. return s.replace(/&[a-z]+;/g, function(m){ return (typeof ec[m] == "string")?ec[m]:m; });
  12980. };
  12981. var at = function(s,c) {
  12982. s.replace(/([\w\:\-]+)\s*=\s*(?:"((?:\\"|[^"])*)"|'((?:\\'|[^'])*)')/g, function($0,$1,$2,$3) {
  12983. c[$1] = es(($2?$2.replace(/\\"/g,'"'):undefined)||($3?$3.replace(/\\'/g,"'"):undefined));
  12984. });
  12985. };
  12986. var em = function(o) {
  12987. for(var x in o){
  12988. if (o.hasOwnProperty(x)) {
  12989. if(Object.prototype[x]) {
  12990. continue;
  12991. }
  12992. return false;
  12993. }
  12994. }
  12995. return true;
  12996. };
  12997. // $0 : 전체
  12998. // $1 : 태그명
  12999. // $2 : 속성문자열
  13000. // $3 : 닫는태그
  13001. // $4 : CDATA바디값
  13002. // $5 : 그냥 바디값
  13003. var cb = function($0,$1,$2,$3,$4,$5) {
  13004. var cur, cdata = "";
  13005. var idx = fg.stack.length - 1;
  13006. if (typeof $1 == "string" && $1) {
  13007. if ($1.substr(0,1) != "/") {
  13008. var has_attr = (typeof $2 == "string" && $2);
  13009. var closed = (typeof $3 == "string" && $3);
  13010. var newobj = (!has_attr && closed)?"":{};
  13011. cur = fg.stack[idx];
  13012. if (typeof cur[$1] == "undefined") {
  13013. cur[$1] = newobj;
  13014. cur = fg.stack[idx+1] = cur[$1];
  13015. } else if (cur[$1] instanceof Array) {
  13016. var len = cur[$1].length;
  13017. cur[$1][len] = newobj;
  13018. cur = fg.stack[idx+1] = cur[$1][len];
  13019. } else {
  13020. cur[$1] = [cur[$1], newobj];
  13021. cur = fg.stack[idx+1] = cur[$1][1];
  13022. }
  13023. if (has_attr) {
  13024. at($2,cur);
  13025. }
  13026. fg.tags[idx+1] = $1;
  13027. if (closed) {
  13028. fg.tags.length--;
  13029. fg.stack.length--;
  13030. }
  13031. } else {
  13032. fg.tags.length--;
  13033. fg.stack.length--;
  13034. }
  13035. } else if (typeof $4 == "string" && $4) {
  13036. cdata = $4;
  13037. } else if (typeof $5 == "string" && $5.replace(re3, "")) { // [SMARTEDITORSUS-1525] 닫는 태그인데 공백문자가 들어있어 cdata 값을 덮어쓰는 경우 방지
  13038. cdata = es($5);
  13039. }
  13040. if (cdata.length > 0) {
  13041. var par = fg.stack[idx-1];
  13042. var tag = fg.tags[idx];
  13043. if (re2.test(cdata)) {
  13044. //cdata = parseFloat(cdata);
  13045. }else if (cdata == "true" || cdata == "false"){
  13046. cdata = new Boolean(cdata);
  13047. }
  13048. if(typeof par =='undefined') {
  13049. return;
  13050. }
  13051. if (par[tag] instanceof Array) {
  13052. var o = par[tag];
  13053. if (typeof o[o.length-1] == "object" && !em(o[o.length-1])) {
  13054. o[o.length-1].$cdata = cdata;
  13055. o[o.length-1].toString = function(){ return cdata; };
  13056. } else {
  13057. o[o.length-1] = cdata;
  13058. }
  13059. } else {
  13060. if (typeof par[tag] == "object" && !em(par[tag])) {
  13061. par[tag].$cdata = cdata;
  13062. par[tag].toString = function() { return cdata; };
  13063. } else {
  13064. par[tag] = cdata;
  13065. }
  13066. }
  13067. }
  13068. };
  13069. sXML = sXML.replace(/<(\?|\!-)[^>]*>/g, "");
  13070. sXML.replace(re, cb);
  13071. return jindo.$Json(o);
  13072. },
  13073. /**
  13074. * 문자열내 자주 사용되는 특수문자 5 (", ', &, <, >) HTML Entity Code 변경하여 반환
  13075. * @see http://www.w3.org/TR/html4/charset.html#entities
  13076. * @param {String} sString 원본 문자열
  13077. * @returns {String} 변경된 문자열
  13078. * @example
  13079. * replaceSpecialChar() or replaceSpecialChar(123)
  13080. * // 결과: ""
  13081. *
  13082. * replaceSpecialChar("&quot;, ', &, <, >")
  13083. * // 결과: &amp;quot;, &amp;#39;, &amp;amp;, &amp;lt;, &amp;gt;
  13084. */
  13085. replaceSpecialChar : function(sString){
  13086. return (typeof(sString) == "string") ? (sString.replace(/\&/g, "&amp;").replace(/\"/g, "&quot;").replace(/\'/g, "&#39;").replace(/</g, "&lt;").replace(/\>/g, "&gt;")) : "";
  13087. },
  13088. /**
  13089. * 문자열내 자주 사용되는 HTML Entity Code 5개를 원래 문자로 (", ', &, <, >) 변경하여 반환
  13090. * @see http://www.w3.org/TR/html4/charset.html#entities
  13091. * @param {String} sString 원본 문자열
  13092. * @returns {String} 변경된 문자열
  13093. * @example
  13094. * restoreSpecialChar() or restoreSpecialChar(123)
  13095. * // 결과: ""
  13096. *
  13097. * restoreSpecialChar("&amp;quot;, &amp;#39;, &amp;amp;, &amp;lt;, &amp;gt;")
  13098. * // 결과: ", ', &, <, >
  13099. */
  13100. restoreSpecialChar : function(sString){
  13101. return (typeof(sString) == "string") ? (sString.replace(/&quot;/g, "\"").replace(/&#39;/g, "'").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&")) : "";
  13102. }
  13103. };
  13104. /**
  13105. * nhn.husky.AutoResizer
  13106. * HTML모드와 TEXT 모드의 편집 영역인 TEXTAREA에 대한 자동확장 처리
  13107. */
  13108. nhn.husky.AutoResizer = jindo.$Class({
  13109. welHiddenDiv : null,
  13110. welCloneDiv : null,
  13111. elContainer : null,
  13112. $init : function(el, htOption){
  13113. var aCopyStyle = [
  13114. 'lineHeight', 'textDecoration', 'letterSpacing',
  13115. 'fontSize', 'fontFamily', 'fontStyle', 'fontWeight',
  13116. 'textTransform', 'textAlign', 'direction', 'wordSpacing', 'fontSizeAdjust',
  13117. 'paddingTop', 'paddingLeft', 'paddingBottom', 'paddingRight', 'width'
  13118. ],
  13119. i = aCopyStyle.length,
  13120. oCss = {
  13121. "position" : "absolute",
  13122. "top" : -9999,
  13123. "left" : -9999,
  13124. "opacity": 0,
  13125. "overflow": "hidden",
  13126. "wordWrap" : "break-word"
  13127. };
  13128. this.nMinHeight = htOption.nMinHeight;
  13129. this.wfnCallback = htOption.wfnCallback;
  13130. this.elContainer = el.parentNode;
  13131. this.welTextArea = jindo.$Element(el); // autoresize를 적용할 TextArea
  13132. this.welHiddenDiv = jindo.$Element('<div>');
  13133. this.wfnResize = jindo.$Fn(this._resize, this);
  13134. this.sOverflow = this.welTextArea.css("overflow");
  13135. this.welTextArea.css("overflow", "hidden");
  13136. while(i--){
  13137. oCss[aCopyStyle[i]] = this.welTextArea.css(aCopyStyle[i]);
  13138. }
  13139. this.welHiddenDiv.css(oCss);
  13140. this.nLastHeight = this.welTextArea.height();
  13141. },
  13142. bind : function(){
  13143. this.welCloneDiv = jindo.$Element(this.welHiddenDiv.$value().cloneNode(false));
  13144. this.wfnResize.attach(this.welTextArea, "keyup");
  13145. this.welCloneDiv.appendTo(this.elContainer);
  13146. this._resize();
  13147. },
  13148. unbind : function(){
  13149. this.wfnResize.detach(this.welTextArea, "keyup");
  13150. this.welTextArea.css("overflow", this.sOverflow);
  13151. if(this.welCloneDiv){
  13152. this.welCloneDiv.leave();
  13153. }
  13154. },
  13155. _resize : function(){
  13156. var sContents = this.welTextArea.$value().value,
  13157. bExpand = false,
  13158. nHeight;
  13159. if(sContents === this.sContents){
  13160. return;
  13161. }
  13162. this.sContents = sContents.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/ /g, '&nbsp;').replace(/\n/g, '<br>');
  13163. this.sContents += "<br>"; // 마지막 개행 뒤에 <br>을 더 붙여주어야 늘어나는 높이가 동일함
  13164. this.welCloneDiv.html(this.sContents);
  13165. nHeight = this.welCloneDiv.height();
  13166. if(nHeight < this.nMinHeight){
  13167. nHeight = this.nMinHeight;
  13168. }
  13169. this.welTextArea.css("height", nHeight + "px");
  13170. this.elContainer.style.height = nHeight + "px";
  13171. if(this.nLastHeight < nHeight){
  13172. bExpand = true;
  13173. }
  13174. this.wfnCallback(bExpand);
  13175. }
  13176. });
  13177. /**
  13178. * 문자를 연결하는 '+' 대신에 java와 유사하게 처리하도록 문자열 처리하도록 만드는 object
  13179. * @author nox
  13180. * @example
  13181. var sTmp1 = new StringBuffer();
  13182. sTmp1.append('1').append('2').append('3');
  13183. var sTmp2 = new StringBuffer('1');
  13184. sTmp2.append('2').append('3');
  13185. var sTmp3 = new StringBuffer('1').append('2').append('3');
  13186. */
  13187. if ('undefined' != typeof(StringBuffer)) {
  13188. StringBuffer = {};
  13189. }
  13190. StringBuffer = function(str) {
  13191. this._aString = [];
  13192. if ('undefined' != typeof(str)) {
  13193. this.append(str);
  13194. }
  13195. };
  13196. StringBuffer.prototype.append = function(str) {
  13197. this._aString.push(str);
  13198. return this;
  13199. };
  13200. StringBuffer.prototype.toString = function() {
  13201. return this._aString.join('');
  13202. };
  13203. StringBuffer.prototype.setLength = function(nLen) {
  13204. if('undefined' == typeof(nLen) || 0 >= nLen) {
  13205. this._aString.length = 0;
  13206. } else {
  13207. this._aString.length = nLen;
  13208. }
  13209. };
  13210. /**
  13211. * Installed Font Detector
  13212. * @author hooriza
  13213. *
  13214. * @see http://remysharp.com/2008/07/08/how-to-detect-if-a-font-is-installed-only-using-javascript/
  13215. */
  13216. (function() {
  13217. var oDummy = null, rx = /,/gi;
  13218. IsInstalledFont = function(sFont) {
  13219. var sDefFont = sFont == 'Comic Sans MS' ? 'Courier New' : 'Comic Sans MS';
  13220. if (!oDummy) {
  13221. oDummy = document.createElement('div');
  13222. }
  13223. var sStyle = 'position:absolute !important; font-size:200px !important; left:-9999px !important; top:-9999px !important;';
  13224. oDummy.innerHTML = 'mmmmiiiii'+unescape('%uD55C%uAE00');
  13225. oDummy.style.cssText = sStyle + 'font-family:"' + sDefFont + '" !important';
  13226. var elBody = document.body || document.documentElement;
  13227. if(elBody.firstChild){
  13228. elBody.insertBefore(oDummy, elBody.firstChild);
  13229. }else{
  13230. document.body.appendChild(oDummy);
  13231. }
  13232. var sOrg = oDummy.offsetWidth + '-' + oDummy.offsetHeight;
  13233. oDummy.style.cssText = sStyle + 'font-family:"' + sFont.replace(rx, '","') + '", "' + sDefFont + '" !important';
  13234. var bInstalled = sOrg != (oDummy.offsetWidth + '-' + oDummy.offsetHeight);
  13235. document.body.removeChild(oDummy);
  13236. return bInstalled;
  13237. };
  13238. })();
  13239. //{
  13240. /**
  13241. * @fileOverview This file contains Husky plugin that takes care of loading css files dynamically
  13242. * @name hp_SE2B_CSSLoader.js
  13243. */
  13244. nhn.husky.SE2B_CSSLoader = jindo.$Class({
  13245. name : "SE2B_CSSLoader",
  13246. bCssLoaded : false,
  13247. // load & continue with the message right away.
  13248. aInstantLoadTrigger : ["OPEN_QE_LAYER", "SHOW_ACTIVE_LAYER", "SHOW_DIALOG_LAYER", "START_SPELLCHECK"],
  13249. // if a rendering bug occurs in IE, give some delay before continue processing the message.
  13250. aDelayedLoadTrigger : ["MSG_SE_OBJECT_EDIT_REQUESTED", "OBJECT_MODIFY", "MSG_SE_DUMMY_OBJECT_EDIT_REQUESTED", "TOGGLE_TOOLBAR_ACTIVE_LAYER", "SHOW_TOOLBAR_ACTIVE_LAYER"],
  13251. $init : function(){
  13252. this.htOptions = nhn.husky.SE2M_Configuration.SE2B_CSSLoader;
  13253. // only IE's slow
  13254. if(!jindo.$Agent().navigator().ie){
  13255. this.$ON_MSG_APP_READY = jindo.$Fn(function(){
  13256. this.loadSE2CSS();
  13257. }, this).bind()
  13258. }else{
  13259. for(var i=0, nLen = this.aInstantLoadTrigger.length; i<nLen; i++){
  13260. this["$BEFORE_"+this.aInstantLoadTrigger[i]] = jindo.$Fn(function(){
  13261. this.loadSE2CSS();
  13262. }, this).bind();
  13263. }
  13264. for(var i=0, nLen = this.aDelayedLoadTrigger.length; i<nLen; i++){
  13265. var sMsg = this.aDelayedLoadTrigger[i];
  13266. this["$BEFORE_"+this.aDelayedLoadTrigger[i]] = jindo.$Fn(function(sMsg){
  13267. var aArgs = jindo.$A(arguments).$value();
  13268. aArgs = aArgs.splice(1, aArgs.length-1);
  13269. return this.loadSE2CSS(sMsg, aArgs);
  13270. }, this).bind(sMsg);
  13271. }
  13272. }
  13273. },
  13274. /*
  13275. $BEFORE_REEDIT_ITEM_ACTION : function(){
  13276. return this.loadSE2CSS("REEDIT_ITEM_ACTION", arguments);
  13277. },
  13278. $BEFORE_OBJECT_MODIFY : function(){
  13279. return this.loadSE2CSS("OBJECT_MODIFY", arguments);
  13280. },
  13281. $BEFORE_MSG_SE_DUMMY_OBJECT_EDIT_REQUESTED : function(){
  13282. return this.loadSE2CSS("MSG_SE_DUMMY_OBJECT_EDIT_REQUESTED", arguments);
  13283. },
  13284. $BEFORE_TOGGLE_DBATTACHMENT_LAYER : function(){
  13285. return this.loadSE2CSS("TOGGLE_DBATTACHMENT_LAYER", arguments);
  13286. },
  13287. $BEFORE_SHOW_WRITE_REVIEW_DESIGN_SELECT_LAYER : function(){
  13288. this.loadSE2CSS();
  13289. },
  13290. $BEFORE_OPEN_QE_LAYER : function(){
  13291. this.loadSE2CSS();
  13292. },
  13293. $BEFORE_TOGGLE_TOOLBAR_ACTIVE_LAYER : function(){
  13294. return this.loadSE2CSS("TOGGLE_TOOLBAR_ACTIVE_LAYER", arguments);
  13295. },
  13296. $BEFORE_SHOW_TOOLBAR_ACTIVE_LAYER : function(){
  13297. return this.loadSE2CSS("SHOW_TOOLBAR_ACTIVE_LAYER", arguments);
  13298. },
  13299. $BEFORE_SHOW_ACTIVE_LAYER : function(){
  13300. this.loadSE2CSS();
  13301. },
  13302. $BEFORE_SHOW_DIALOG_LAYER : function(){
  13303. this.loadSE2CSS();
  13304. },
  13305. $BEFORE_TOGGLE_ITEM_LAYER : function(){
  13306. return this.loadSE2CSS("TOGGLE_ITEM_LAYER", arguments);
  13307. },
  13308. */
  13309. // if a rendering bug occurs in IE, pass sMsg and oArgs to give some delay before the message is processed.
  13310. loadSE2CSS : function(sMsg, oArgs){
  13311. if(this.bCssLoaded){return true;}
  13312. this.bCssLoaded = true;
  13313. var fnCallback = null;
  13314. if(sMsg){
  13315. fnCallback = jindo.$Fn(this.oApp.exec, this.oApp).bind(sMsg, oArgs);
  13316. }
  13317. //nhn.husky.SE2M_Utils.loadCSS("css/smart_editor2.css");
  13318. var sCssUrl = this.htOptions.sCSSBaseURI;
  13319. var sLocale = this.oApp && this.oApp.htOptions.I18N_LOCALE;
  13320. if(sLocale){
  13321. sCssUrl += "/" + sLocale;
  13322. }
  13323. sCssUrl += "/smart_editor2_items.css";
  13324. nhn.husky.SE2M_Utils.loadCSS(sCssUrl, fnCallback);
  13325. return false;
  13326. }
  13327. });
  13328. //}
  13329. if(typeof window.nhn=='undefined'){window.nhn = {};}
  13330. /**
  13331. * @fileOverview This file contains a message mapping(Korean), which is used to map the message code to the actual message
  13332. * @name husky_SE2B_Lang_ko_KR.js
  13333. * @ unescape
  13334. */
  13335. var oMessageMap = {
  13336. 'SE_EditingAreaManager.onExit' : '내용이 변경되었습니다.',
  13337. 'SE_Color.invalidColorCode' : '색상 코드를 올바르게 입력해 주세요. \n\n 예) #000000, #FF0000, #FFFFFF, #ffffff, ffffff',
  13338. 'SE_Hyperlink.invalidURL' : '입력하신 URL이 올바르지 않습니다.',
  13339. 'SE_FindReplace.keywordMissing' : '찾으실 단어를 입력해 주세요.',
  13340. 'SE_FindReplace.keywordNotFound' : '찾으실 단어가 없습니다.',
  13341. 'SE_FindReplace.replaceAllResultP1' : '일치하는 내용이 총 ',
  13342. 'SE_FindReplace.replaceAllResultP2' : '건 바뀌었습니다.',
  13343. 'SE_FindReplace.notSupportedBrowser' : '현재 사용하고 계신 브라우저에서는 사용하실수 없는 기능입니다.\n\n이용에 불편을 드려 죄송합니다.',
  13344. 'SE_FindReplace.replaceKeywordNotFound' : '바뀔 단어가 없습니다',
  13345. 'SE_LineHeight.invalidLineHeight' : '잘못된 값입니다.',
  13346. 'SE_Footnote.defaultText' : '각주내용을 입력해 주세요',
  13347. 'SE.failedToLoadFlash' : '플래시가 차단되어 있어 해당 기능을 사용할 수 없습니다.',
  13348. 'SE2M_EditingModeChanger.confirmTextMode' : '텍스트 모드로 전환하면 작성된 내용은 유지되나, \n\n글꼴 등의 편집효과와 이미지 등의 첨부내용이 모두 사라지게 됩니다.\n\n전환하시겠습니까?',
  13349. 'SE2M_FontNameWithLayerUI.sSampleText' : '가나다라'
  13350. };
  13351. if(typeof window.nhn=='undefined'){window.nhn = {};}
  13352. /**
  13353. * @fileOverview This file contains a message mapping(Korean), which is used to map the message code to the actual message
  13354. * @name husky_SE2B_Lang_en_US.js
  13355. * @ unescape
  13356. */
  13357. var oMessageMap_en_US = {
  13358. 'SE_EditingAreaManager.onExit' : 'Contents have been changed.',
  13359. 'SE_Color.invalidColorCode' : 'Enter the correct color code. \n\n ex) #000000, #FF0000, #FFFFFF, #ffffff, ffffff',
  13360. 'SE_Hyperlink.invalidURL' : 'You have entered an incorrect URL.',
  13361. 'SE_FindReplace.keywordMissing' : 'Enter the word you wish to find.',
  13362. 'SE_FindReplace.keywordNotFound' : 'The word does not exist.',
  13363. 'SE_FindReplace.replaceAllResultP1' : 'A total of ',
  13364. 'SE_FindReplace.replaceAllResultP2' : ' matching contents have been changed.',
  13365. 'SE_FindReplace.notSupportedBrowser' : 'Function cannot be used in the browser you are currently using. \n\nSorry for the inconvenience.',
  13366. 'SE_FindReplace.replaceKeywordNotFound' : 'No word to change.',
  13367. 'SE_LineHeight.invalidLineHeight' : 'Incorrect value.',
  13368. 'SE_Footnote.defaultText' : 'Enter footnote details.',
  13369. 'SE.failedToLoadFlash' : 'The function cannot be used because flash has been blocked.',
  13370. 'SE2M_EditingModeChanger.confirmTextMode' : 'The contents remain, but editing effects, including fonts, and attachments, \n\nsuch as images, will disappear when changed to text mode. \n\n Make changes?',
  13371. 'SE2M_FontNameWithLayerUI.sSampleText' : 'ABCD'
  13372. };
  13373. if(typeof window.nhn=='undefined'){window.nhn = {};}
  13374. /**
  13375. * @fileOverview This file contains a message mapping(Korean), which is used to map the message code to the actual message
  13376. * @name husky_SE2B_Lang_ja_JP.js
  13377. * @ unescape
  13378. */
  13379. var oMessageMap_ja_JP = {
  13380. 'SE_EditingAreaManager.onExit' : '内容が変更されました。',
  13381. 'SE_Color.invalidColorCode' : 'カラーコードを正しく入力してください。 \n\n 例) #000000, #FF0000, #FFFFFF, #ffffff, ffffff',
  13382. 'SE_Hyperlink.invalidURL' : '入力したURLが正しくありません。',
  13383. 'SE_FindReplace.keywordMissing' : 'お探しの単語を入力してください。',
  13384. 'SE_FindReplace.keywordNotFound' : 'お探しの単語がありません。',
  13385. 'SE_FindReplace.replaceAllResultP1' : '一致する内容が計',
  13386. 'SE_FindReplace.replaceAllResultP2' : '件変わりました。',
  13387. 'SE_FindReplace.notSupportedBrowser' : '現在ご使用中のブラウザーではご利用いただけない機能です。\n\nご不便をおかけしまして申し訳ございません。',
  13388. 'SE_FindReplace.replaceKeywordNotFound' : '変更される単語がありません。',
  13389. 'SE_LineHeight.invalidLineHeight' : '誤った値です。',
  13390. 'SE_Footnote.defaultText' : '脚注内容を入力してください。',
  13391. 'SE.failedToLoadFlash' : 'フラッシュが遮断されているため、この機能は使用できません。',
  13392. 'SE2M_EditingModeChanger.confirmTextMode' : 'テキストモードに切り換えると、作成された内容は維持されますが、\n\nフォント等の編集効果と画像等の添付内容が消えることになります。\n\n切り換えますか?',
  13393. 'SE2M_FontNameWithLayerUI.sSampleText' : 'あいうえお'
  13394. };
  13395. if(typeof window.nhn=='undefined'){window.nhn = {};}
  13396. /**
  13397. * @fileOverview This file contains a message mapping(Korean), which is used to map the message code to the actual message
  13398. * @name husky_SE2B_Lang_zh_CN.js
  13399. * @ unescape
  13400. */
  13401. var oMessageMap_zh_CN = {
  13402. 'SE_EditingAreaManager.onExit' : '内容有了变化。',
  13403. 'SE_Color.invalidColorCode' : '请你输入正确的色相代码。 \n\n 例) #000000, #FF0000, #FFFFFF, #ffffff, ffffff',
  13404. 'SE_Hyperlink.invalidURL' : '你输入的URL不符条件。',
  13405. 'SE_FindReplace.keywordMissing' : '请你输入要找的词汇。',
  13406. 'SE_FindReplace.keywordNotFound' : '没有词汇符合条件。',
  13407. 'SE_FindReplace.replaceAllResultP1' : '符合条件的内容改编为',
  13408. 'SE_FindReplace.replaceAllResultP2' : '件',
  13409. 'SE_FindReplace.notSupportedBrowser' : '这是你现在使用的浏览器不可支持的功能。\n\n麻烦你很道歉。',
  13410. 'SE_FindReplace.replaceKeywordNotFound' : '没有词汇要改变。',
  13411. 'SE_LineHeight.invalidLineHeight' : '这是有问题的值。',
  13412. 'SE_Footnote.defaultText' : '请你输入脚注内容。',
  13413. 'SE.failedToLoadFlash' : 'flash被隔绝,不能使用该功能。',
  13414. 'SE2M_EditingModeChanger.confirmTextMode' : '转换为text模式就能维持制作内容,\n\n但字体等编辑效果和图像等附件内容都会消失。\n\n你还要继续吗?',
  13415. 'SE2M_FontNameWithLayerUI.sSampleText' : 'ABCD'
  13416. };
  13417. if(typeof window.nhn=='undefined'){window.nhn = {};}
  13418. /**
  13419. * @fileOverview This file contains a message mapping(Korean), which is used to map the message code to the actual message
  13420. * @name husky_SE2B_Lang_zh_TW.js
  13421. * @ unescape
  13422. */
  13423. var oMessageMap_zh_TW = {
  13424. 'SE_EditingAreaManager.onExit' : '內容已被更改。',
  13425. 'SE_Color.invalidColorCode' : '請輸入正確的顔色代碼。\n\n例子)#000000, #FF0000, #FFFFFF, #ffffff, ffffff',
  13426. 'SE_Hyperlink.invalidURL' : '輸錯URL',
  13427. 'SE_FindReplace.keywordMissing' : '請輸入要查詢的單詞。',
  13428. 'SE_FindReplace.keywordNotFound' : '要查詢的單詞不存在。',
  13429. 'SE_FindReplace.replaceAllResultP1' : '一致的內容總有',
  13430. 'SE_FindReplace.replaceAllResultP2' : '件已被更改。',
  13431. 'SE_FindReplace.notSupportedBrowser' : '當前的浏覽器上無法使用此功能。\n\n很抱歉給你添麻煩了。',
  13432. 'SE_FindReplace.replaceKeywordNotFound' : '要更改的詞彙不存在。',
  13433. 'SE_LineHeight.invalidLineHeight' : '爲有錯誤的值。',
  13434. 'SE_Footnote.defaultText' : '請輸入注腳內容。',
  13435. 'SE.failedToLoadFlash' : 'Flash被屏蔽,導致無法使用此功能。',
  13436. 'SE2M_EditingModeChanger.confirmTextMode' : '如轉換爲文本模式,雖然維持已寫成的內容,\n\n但字號等編輯效果和圖像等附加內容都會被消失。\n\n是否轉換?',
  13437. 'SE2M_FontNameWithLayerUI.sSampleText' : 'ABCD'
  13438. };
  13439. /*[
  13440. * SE_FIT_IFRAME
  13441. *
  13442. * 스마트에디터 사이즈에 맞게 iframe사이즈를 조절한다.
  13443. *
  13444. * none
  13445. *
  13446. ---------------------------------------------------------------------------]*/
  13447. /**
  13448. * @pluginDesc 에디터를 싸고 있는 iframe 사이즈 조절을 담당하는 플러그인
  13449. */
  13450. nhn.husky.SE_OuterIFrameControl = $Class({
  13451. name : "SE_OuterIFrameControl",
  13452. oResizeGrip : null,
  13453. $init : function(oAppContainer){
  13454. // page up, page down, home, end, left, up, right, down
  13455. this.aHeightChangeKeyMap = [-100, 100, 500, -500, -1, -10, 1, 10];
  13456. this._assignHTMLObjects(oAppContainer);
  13457. //키보드 이벤트
  13458. this.$FnKeyDown = $Fn(this._keydown, this);
  13459. if(this.oResizeGrip){
  13460. this.$FnKeyDown.attach(this.oResizeGrip, "keydown");
  13461. }
  13462. //마우스 이벤트
  13463. if(!!jindo.$Agent().navigator().ie){
  13464. this.$FnMouseDown = $Fn(this._mousedown, this);
  13465. this.$FnMouseMove = $Fn(this._mousemove, this);
  13466. this.$FnMouseMove_Parent = $Fn(this._mousemove_parent, this);
  13467. this.$FnMouseUp = $Fn(this._mouseup, this);
  13468. if(this.oResizeGrip){
  13469. this.$FnMouseDown.attach(this.oResizeGrip, "mousedown");
  13470. }
  13471. }
  13472. },
  13473. _assignHTMLObjects : function(oAppContainer){
  13474. oAppContainer = jindo.$(oAppContainer) || document;
  13475. this.oResizeGrip = cssquery.getSingle(".husky_seditor_editingArea_verticalResizer", oAppContainer);
  13476. this.elIFrame = window.frameElement;
  13477. this.welIFrame = $Element(this.elIFrame);
  13478. },
  13479. $ON_MSG_APP_READY : function(){
  13480. this.oApp.exec("SE_FIT_IFRAME", []);
  13481. },
  13482. $ON_MSG_EDITING_AREA_SIZE_CHANGED : function(){
  13483. this.oApp.exec("SE_FIT_IFRAME", []);
  13484. },
  13485. $ON_SE_FIT_IFRAME : function(){
  13486. this.elIFrame.style.height = document.body.offsetHeight+"px";
  13487. },
  13488. $AFTER_RESIZE_EDITING_AREA_BY : function(ipWidthChange, ipHeightChange){
  13489. this.oApp.exec("SE_FIT_IFRAME", []);
  13490. },
  13491. _keydown : function(oEvent){
  13492. var oKeyInfo = oEvent.key();
  13493. // 33, 34: page up/down, 35,36: end/home, 37,38,39,40: left, up, right, down
  13494. if(oKeyInfo.keyCode >= 33 && oKeyInfo.keyCode <= 40){
  13495. this.oApp.exec("MSG_EDITING_AREA_RESIZE_STARTED", []);
  13496. this.oApp.exec("RESIZE_EDITING_AREA_BY", [0, this.aHeightChangeKeyMap[oKeyInfo.keyCode-33]]);
  13497. this.oApp.exec("MSG_EDITING_AREA_RESIZE_ENDED", []);
  13498. oEvent.stop();
  13499. }
  13500. },
  13501. _mousedown : function(oEvent){
  13502. this.iStartHeight = oEvent.pos().clientY;
  13503. this.iStartHeightOffset = oEvent.pos().layerY;
  13504. this.$FnMouseMove.attach(document, "mousemove");
  13505. this.$FnMouseMove_Parent.attach(parent.document, "mousemove");
  13506. this.$FnMouseUp.attach(document, "mouseup");
  13507. this.$FnMouseUp.attach(parent.document, "mouseup");
  13508. this.iStartHeight = oEvent.pos().clientY;
  13509. this.oApp.exec("MSG_EDITING_AREA_RESIZE_STARTED", [this.$FnMouseDown, this.$FnMouseMove, this.$FnMouseUp]);
  13510. },
  13511. _mousemove : function(oEvent){
  13512. var iHeightChange = oEvent.pos().clientY - this.iStartHeight;
  13513. this.oApp.exec("RESIZE_EDITING_AREA_BY", [0, iHeightChange]);
  13514. },
  13515. _mousemove_parent : function(oEvent){
  13516. var iHeightChange = oEvent.pos().pageY - (this.welIFrame.offset().top + this.iStartHeight);
  13517. this.oApp.exec("RESIZE_EDITING_AREA_BY", [0, iHeightChange]);
  13518. },
  13519. _mouseup : function(oEvent){
  13520. this.$FnMouseMove.detach(document, "mousemove");
  13521. this.$FnMouseMove_Parent.detach(parent.document, "mousemove");
  13522. this.$FnMouseUp.detach(document, "mouseup");
  13523. this.$FnMouseUp.detach(parent.document, "mouseup");
  13524. this.oApp.exec("MSG_EDITING_AREA_RESIZE_ENDED", [this.$FnMouseDown, this.$FnMouseMove, this.$FnMouseUp]);
  13525. }
  13526. });
  13527. // Sample plugin. Use CTRL+T to toggle the toolbar
  13528. nhn.husky.SE_ToolbarToggler = $Class({
  13529. name : "SE_ToolbarToggler",
  13530. bUseToolbar : true,
  13531. $init : function(oAppContainer, bUseToolbar){
  13532. this._assignHTMLObjects(oAppContainer, bUseToolbar);
  13533. },
  13534. _assignHTMLObjects : function(oAppContainer, bUseToolbar){
  13535. oAppContainer = jindo.$(oAppContainer) || document;
  13536. this.toolbarArea = cssquery.getSingle(".se2_tool", oAppContainer);
  13537. //설정이 없거나, 사용하겠다고 표시한 경우 block 처리
  13538. if( typeof(bUseToolbar) == 'undefined' || bUseToolbar === true){
  13539. this.toolbarArea.style.display = "block";
  13540. }else{
  13541. this.toolbarArea.style.display = "none";
  13542. }
  13543. },
  13544. $ON_MSG_APP_READY : function(){
  13545. this.oApp.exec("REGISTER_HOTKEY", ["ctrl+t", "SE_TOGGLE_TOOLBAR", []]);
  13546. },
  13547. $ON_SE_TOGGLE_TOOLBAR : function(){
  13548. this.toolbarArea.style.display = (this.toolbarArea.style.display == "none")?"block":"none";
  13549. this.oApp.exec("MSG_EDITING_AREA_SIZE_CHANGED", []);
  13550. }
  13551. });
  13552. nhn.husky.HuskyCore.addLoadedFile("hp_SE2M_FindReplacePlugin$Lazy.js");
  13553. /**
  13554. * @depends nhn.husky.SE2M_FindReplacePlugin
  13555. * this.oApp.registerLazyMessage(["TOGGLE_FIND_REPLACE_LAYER","SHOW_FIND_LAYER","SHOW_REPLACE_LAYER","SHOW_FIND_REPLACE_LAYER"], ["hp_SE2M_FindReplacePlugin$Lazy.js","N_FindReplace.js"]);
  13556. */
  13557. nhn.husky.HuskyCore.mixin(nhn.husky.SE2M_FindReplacePlugin, {
  13558. //@lazyload_js TOGGLE_FIND_REPLACE_LAYER,SHOW_FIND_LAYER,SHOW_REPLACE_LAYER,SHOW_FIND_REPLACE_LAYER:N_FindReplace.js[
  13559. _assignHTMLElements : function(){
  13560. var oAppContainer = this.oApp.htOptions.elAppContainer;
  13561. this.oApp.exec("LOAD_HTML", ["find_and_replace"]);
  13562. // this.oEditingWindow = jindo.$$.getSingle("IFRAME", oAppContainer);
  13563. this.elDropdownLayer = jindo.$$.getSingle("DIV.husky_se2m_findAndReplace_layer", oAppContainer);
  13564. this.welDropdownLayer = jindo.$Element(this.elDropdownLayer);
  13565. var oTmp = jindo.$$("LI", this.elDropdownLayer);
  13566. this.oFindTab = oTmp[0];
  13567. this.oReplaceTab = oTmp[1];
  13568. oTmp = jindo.$$(".container > .bx", this.elDropdownLayer);
  13569. this.oFindInputSet = jindo.$$.getSingle(".husky_se2m_find_ui", this.elDropdownLayer);
  13570. this.oReplaceInputSet = jindo.$$.getSingle(".husky_se2m_replace_ui", this.elDropdownLayer);
  13571. this.elTitle = jindo.$$.getSingle("H3", this.elDropdownLayer);
  13572. this.oFindInput_Keyword = jindo.$$.getSingle("INPUT", this.oFindInputSet);
  13573. oTmp = jindo.$$("INPUT", this.oReplaceInputSet);
  13574. this.oReplaceInput_Original = oTmp[0];
  13575. this.oReplaceInput_Replacement = oTmp[1];
  13576. this.oFindNextButton = jindo.$$.getSingle("BUTTON.husky_se2m_find_next", this.elDropdownLayer);
  13577. this.oReplaceFindNextButton = jindo.$$.getSingle("BUTTON.husky_se2m_replace_find_next", this.elDropdownLayer);
  13578. this.oReplaceButton = jindo.$$.getSingle("BUTTON.husky_se2m_replace", this.elDropdownLayer);
  13579. this.oReplaceAllButton = jindo.$$.getSingle("BUTTON.husky_se2m_replace_all", this.elDropdownLayer);
  13580. this.aCloseButtons = jindo.$$("BUTTON.husky_se2m_cancel", this.elDropdownLayer);
  13581. },
  13582. $LOCAL_BEFORE_FIRST : function(sMsg){
  13583. this._assignHTMLElements();
  13584. this.oFindReplace = new nhn.FindReplace(this.oEditingWindow);
  13585. for(var i=0; i<this.aCloseButtons.length; i++){
  13586. // var func = jindo.$Fn(this.oApp.exec, this.oApp).bind("HIDE_DIALOG_LAYER", [this.elDropdownLayer]);
  13587. var func = jindo.$Fn(this.oApp.exec, this.oApp).bind("HIDE_FIND_REPLACE_LAYER", [this.elDropdownLayer]);
  13588. jindo.$Fn(func, this).attach(this.aCloseButtons[i], "click");
  13589. }
  13590. jindo.$Fn(jindo.$Fn(this.oApp.exec, this.oApp).bind("SHOW_FIND", []), this).attach(this.oFindTab, "click");
  13591. jindo.$Fn(jindo.$Fn(this.oApp.exec, this.oApp).bind("SHOW_REPLACE", []), this).attach(this.oReplaceTab, "click");
  13592. jindo.$Fn(jindo.$Fn(this.oApp.exec, this.oApp).bind("FIND", []), this).attach(this.oFindNextButton, "click");
  13593. jindo.$Fn(jindo.$Fn(this.oApp.exec, this.oApp).bind("FIND", []), this).attach(this.oReplaceFindNextButton, "click");
  13594. jindo.$Fn(jindo.$Fn(this.oApp.exec, this.oApp).bind("REPLACE", []), this).attach(this.oReplaceButton, "click");
  13595. jindo.$Fn(jindo.$Fn(this.oApp.exec, this.oApp).bind("REPLACE_ALL", []), this).attach(this.oReplaceAllButton, "click");
  13596. this.oFindInput_Keyword.value = "";
  13597. this.oReplaceInput_Original.value = "";
  13598. this.oReplaceInput_Replacement.value = "";
  13599. //레이어의 이동 범위 설정.
  13600. var elIframe = this.oApp.getWYSIWYGWindow().frameElement;
  13601. this.htOffsetPos = jindo.$Element(elIframe).offset();
  13602. this.nEditorWidth = elIframe.offsetWidth;
  13603. this.elDropdownLayer.style.display = "block";
  13604. this.htInitialPos = this.welDropdownLayer.offset();
  13605. var htScrollXY = this.oApp.oUtils.getScrollXY();
  13606. // this.welDropdownLayer.offset(this.htOffsetPos.top-htScrollXY.y, this.htOffsetPos.left-htScrollXY.x);
  13607. this.welDropdownLayer.offset(this.htOffsetPos.top, this.htOffsetPos.left);
  13608. this.htTopLeftCorner = {x:parseInt(this.elDropdownLayer.style.left, 10), y:parseInt(this.elDropdownLayer.style.top, 10)};
  13609. // offset width가 IE에서 css lazy loading 때문에 제대로 잡히지 않아 상수로 설정
  13610. //this.nLayerWidth = this.elDropdownLayer.offsetWidth;
  13611. this.nLayerWidth = 258;
  13612. this.nLayerHeight = 160;
  13613. //this.nLayerWidth = Math.abs(parseInt(this.elDropdownLayer.style.marginLeft))+20;
  13614. this.elDropdownLayer.style.display = "none";
  13615. },
  13616. // [SMARTEDITORSUS-728] 찾기/바꾸기 레이어 오픈 툴바 버튼 active/inactive 처리 추가
  13617. $ON_TOGGLE_FIND_REPLACE_LAYER : function(){
  13618. if(!this.bLayerShown) {
  13619. this.oApp.exec("SHOW_FIND_REPLACE_LAYER");
  13620. } else {
  13621. this.oApp.exec("HIDE_FIND_REPLACE_LAYER");
  13622. }
  13623. },
  13624. $ON_SHOW_FIND_REPLACE_LAYER : function(){
  13625. this.bLayerShown = true;
  13626. this.oApp.exec("DISABLE_ALL_UI", [{aExceptions: ["findAndReplace"]}]);
  13627. this.oApp.exec("SELECT_UI", ["findAndReplace"]);
  13628. this.oApp.exec("HIDE_ALL_DIALOG_LAYER", []);
  13629. this.elDropdownLayer.style.top = this.nDefaultTop+"px";
  13630. this.oApp.exec("SHOW_DIALOG_LAYER", [this.elDropdownLayer, {
  13631. elHandle: this.elTitle,
  13632. fnOnDragStart : jindo.$Fn(this.oApp.exec, this.oApp).bind("SHOW_EDITING_AREA_COVER"),
  13633. fnOnDragEnd : jindo.$Fn(this.oApp.exec, this.oApp).bind("HIDE_EDITING_AREA_COVER"),
  13634. nMinX : this.htTopLeftCorner.x,
  13635. nMinY : this.nDefaultTop,
  13636. nMaxX : this.htTopLeftCorner.x + this.oApp.getEditingAreaWidth() - this.nLayerWidth,
  13637. nMaxY : this.htTopLeftCorner.y + this.oApp.getEditingAreaHeight() - this.nLayerHeight,
  13638. sOnShowMsg : "FIND_REPLACE_LAYER_SHOWN"
  13639. }]);
  13640. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['findreplace']);
  13641. },
  13642. $ON_HIDE_FIND_REPLACE_LAYER : function() {
  13643. this.oApp.exec("ENABLE_ALL_UI");
  13644. this.oApp.exec("DESELECT_UI", ["findAndReplace"]);
  13645. this.oApp.exec("HIDE_ALL_DIALOG_LAYER", []);
  13646. this.bLayerShown = false;
  13647. },
  13648. $ON_FIND_REPLACE_LAYER_SHOWN : function(){
  13649. this.oApp.exec("POSITION_TOOLBAR_LAYER", [this.elDropdownLayer]);
  13650. if(this.bFindMode){
  13651. this.oFindInput_Keyword.value = "_clear_";
  13652. this.oFindInput_Keyword.value = "";
  13653. this.oFindInput_Keyword.focus();
  13654. }else{
  13655. this.oReplaceInput_Original.value = "_clear_";
  13656. this.oReplaceInput_Original.value = "";
  13657. this.oReplaceInput_Replacement.value = "";
  13658. this.oReplaceInput_Original.focus();
  13659. }
  13660. this.oApp.exec("HIDE_CURRENT_ACTIVE_LAYER", []);
  13661. },
  13662. $ON_SHOW_FIND_LAYER : function(){
  13663. this.oApp.exec("SHOW_FIND");
  13664. this.oApp.exec("SHOW_FIND_REPLACE_LAYER");
  13665. },
  13666. $ON_SHOW_REPLACE_LAYER : function(){
  13667. this.oApp.exec("SHOW_REPLACE");
  13668. this.oApp.exec("SHOW_FIND_REPLACE_LAYER");
  13669. },
  13670. $ON_SHOW_FIND : function(){
  13671. this.bFindMode = true;
  13672. this.oFindInput_Keyword.value = this.oReplaceInput_Original.value;
  13673. jindo.$Element(this.oFindTab).addClass("active");
  13674. jindo.$Element(this.oReplaceTab).removeClass("active");
  13675. jindo.$Element(this.oFindNextButton).removeClass("normal");
  13676. jindo.$Element(this.oFindNextButton).addClass("strong");
  13677. this.oFindInputSet.style.display = "block";
  13678. this.oReplaceInputSet.style.display = "none";
  13679. this.oReplaceButton.style.display = "none";
  13680. this.oReplaceAllButton.style.display = "none";
  13681. jindo.$Element(this.elDropdownLayer).removeClass("replace");
  13682. jindo.$Element(this.elDropdownLayer).addClass("find");
  13683. },
  13684. $ON_SHOW_REPLACE : function(){
  13685. this.bFindMode = false;
  13686. this.oReplaceInput_Original.value = this.oFindInput_Keyword.value;
  13687. jindo.$Element(this.oFindTab).removeClass("active");
  13688. jindo.$Element(this.oReplaceTab).addClass("active");
  13689. jindo.$Element(this.oFindNextButton).removeClass("strong");
  13690. jindo.$Element(this.oFindNextButton).addClass("normal");
  13691. this.oFindInputSet.style.display = "none";
  13692. this.oReplaceInputSet.style.display = "block";
  13693. this.oReplaceButton.style.display = "inline";
  13694. this.oReplaceAllButton.style.display = "inline";
  13695. jindo.$Element(this.elDropdownLayer).removeClass("find");
  13696. jindo.$Element(this.elDropdownLayer).addClass("replace");
  13697. },
  13698. $ON_FIND : function(){
  13699. var sKeyword;
  13700. if(this.bFindMode){
  13701. sKeyword = this.oFindInput_Keyword.value;
  13702. }else{
  13703. sKeyword = this.oReplaceInput_Original.value;
  13704. }
  13705. var oSelection = this.oApp.getSelection();
  13706. oSelection.select();
  13707. switch(this.oFindReplace.find(sKeyword, false)){
  13708. case 1:
  13709. alert(this.oApp.$MSG("SE_FindReplace.keywordNotFound"));
  13710. oSelection.select();
  13711. break;
  13712. case 2:
  13713. alert(this.oApp.$MSG("SE_FindReplace.keywordMissing"));
  13714. break;
  13715. }
  13716. },
  13717. $ON_REPLACE : function(){
  13718. var sOriginal = this.oReplaceInput_Original.value;
  13719. var sReplacement = this.oReplaceInput_Replacement.value;
  13720. var oSelection = this.oApp.getSelection();
  13721. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["REPLACE"]);
  13722. var iReplaceResult = this.oFindReplace.replace(sOriginal, sReplacement, false);
  13723. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["REPLACE"]);
  13724. switch(iReplaceResult){
  13725. case 1:
  13726. case 3:
  13727. alert(this.oApp.$MSG("SE_FindReplace.keywordNotFound"));
  13728. oSelection.select();
  13729. break;
  13730. case 4:
  13731. alert(this.oApp.$MSG("SE_FindReplace.keywordMissing"));
  13732. break;
  13733. }
  13734. },
  13735. $ON_REPLACE_ALL : function(){
  13736. var sOriginal = this.oReplaceInput_Original.value;
  13737. var sReplacement = this.oReplaceInput_Replacement.value;
  13738. var oSelection = this.oApp.getSelection();
  13739. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["REPLACE ALL", {sSaveTarget:"BODY"}]);
  13740. var iReplaceAllResult = this.oFindReplace.replaceAll(sOriginal, sReplacement, false);
  13741. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["REPLACE ALL", {sSaveTarget:"BODY"}]);
  13742. if(iReplaceAllResult === 0){
  13743. alert(this.oApp.$MSG("SE_FindReplace.replaceKeywordNotFound"));
  13744. oSelection.select();
  13745. this.oApp.exec("FOCUS");
  13746. }else{
  13747. if(iReplaceAllResult<0){
  13748. alert(this.oApp.$MSG("SE_FindReplace.keywordMissing"));
  13749. oSelection.select();
  13750. }else{
  13751. alert(this.oApp.$MSG("SE_FindReplace.replaceAllResultP1")+iReplaceAllResult+this.oApp.$MSG("SE_FindReplace.replaceAllResultP2"));
  13752. oSelection = this.oApp.getEmptySelection();
  13753. oSelection.select();
  13754. this.oApp.exec("FOCUS");
  13755. }
  13756. }
  13757. }
  13758. //@lazyload_js]
  13759. });
  13760. nhn.husky.HuskyCore.addLoadedFile("hp_SE2M_Quote$Lazy.js");
  13761. /**
  13762. * @depends nhn.husky.SE2M_Quote
  13763. * this.oApp.registerLazyMessage(["TOGGLE_BLOCKQUOTE_LAYER"], ["hp_SE2M_Quote$Lazy.js"]);
  13764. */
  13765. nhn.husky.HuskyCore.mixin(nhn.husky.SE2M_Quote, {
  13766. //@lazyload_js TOGGLE_BLOCKQUOTE_LAYER[
  13767. $ON_TOGGLE_BLOCKQUOTE_LAYER : function(){
  13768. this.oApp.exec("TOGGLE_TOOLBAR_ACTIVE_LAYER", [this.elDropdownLayer, null, "SELECT_UI", ["quote"], "DESELECT_UI", ["quote"]]);
  13769. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['quote']);
  13770. },
  13771. $ON_EVENT_SE2_BLOCKQUOTE_LAYER_CLICK : function(weEvent){
  13772. var elButton = nhn.husky.SE2M_Utils.findAncestorByTagName("BUTTON", weEvent.element);
  13773. if(!elButton || elButton.tagName != "BUTTON"){return;}
  13774. var sClass = elButton.className;
  13775. this.oApp.exec("APPLY_BLOCKQUOTE", [sClass]);
  13776. },
  13777. $ON_APPLY_BLOCKQUOTE : function(sClass){
  13778. if(sClass.match(/(se2_quote[0-9]+)/)){
  13779. this._wrapBlock("BLOCKQUOTE", RegExp.$1);
  13780. }else{
  13781. this._unwrapBlock("BLOCKQUOTE");
  13782. }
  13783. this.oApp.exec("HIDE_ACTIVE_LAYER", []);
  13784. },
  13785. /**
  13786. * 인용구의 중첩 가능한 최대 개수를 넘었는지 확인함
  13787. * 인용구 내부에서 인용구를 적용하면 중첩되지 않으므로 자식노드에 대해서만 확인함
  13788. */
  13789. _isExceedMaxDepth : function(elNode){
  13790. var countChildQuote = function(elNode){
  13791. var elChild = elNode.firstChild;
  13792. var nCount = 0;
  13793. var nMaxCount = 0;
  13794. if(!elChild){
  13795. if(elNode.tagName && elNode.tagName === "BLOCKQUOTE"){
  13796. return 1;
  13797. }else{
  13798. return 0;
  13799. }
  13800. }
  13801. while(elChild){
  13802. if(elChild.nodeType === 1){
  13803. nCount = countChildQuote(elChild);
  13804. if(elChild.tagName === "BLOCKQUOTE"){
  13805. nCount += 1;
  13806. }
  13807. if(nMaxCount < nCount){
  13808. nMaxCount = nCount;
  13809. }
  13810. if(nMaxCount >= this.nMaxLevel){
  13811. return nMaxCount;
  13812. }
  13813. }
  13814. elChild = elChild.nextSibling;
  13815. }
  13816. return nMaxCount;
  13817. };
  13818. return (countChildQuote(elNode) >= this.nMaxLevel);
  13819. },
  13820. _unwrapBlock : function(tag){
  13821. var oSelection = this.oApp.getSelection();
  13822. var elCommonAncestor = oSelection.commonAncestorContainer;
  13823. while(elCommonAncestor && elCommonAncestor.tagName != tag){elCommonAncestor = elCommonAncestor.parentNode;}
  13824. if(!elCommonAncestor){return;}
  13825. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["CANCEL BLOCK QUOTE", {sSaveTarget:"BODY"}]);
  13826. // [SMARTEDITORSUS-1782] 인용구가 제거되기 전에 선택 영역안에 있는 마지막 텍스트노드를 미리 찾아둔다.
  13827. var oLastTextNode = oSelection.commonAncestorContainer;
  13828. if(oLastTextNode.nodeType !== 3){ // 텍스트노드가 아니면
  13829. var aTextNodesInRange = oSelection.getTextNodes() || "",
  13830. nLastIndex = aTextNodesInRange.length - 1;
  13831. oLastTextNode = (nLastIndex > -1) ? aTextNodesInRange[nLastIndex] : null;
  13832. }
  13833. // 인용구내의 요소들을 바깥으로 모두 꺼낸 후 인용구요소를 제거
  13834. while(elCommonAncestor.firstChild){elCommonAncestor.parentNode.insertBefore(elCommonAncestor.firstChild, elCommonAncestor);}
  13835. elCommonAncestor.parentNode.removeChild(elCommonAncestor);
  13836. // [SMARTEDITORSUS-1782] 찾아둔 마지막 텍스트노드 끝으로 커서를 이동시킨다.
  13837. if(oLastTextNode){
  13838. oSelection.selectNodeContents(oLastTextNode);
  13839. oSelection.collapseToEnd();
  13840. oSelection.select();
  13841. }
  13842. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["CANCEL BLOCK QUOTE", {sSaveTarget:"BODY"}]);
  13843. },
  13844. _wrapBlock : function(tag, className){
  13845. var oSelection,
  13846. oLineInfo,
  13847. oStart, oEnd,
  13848. rxDontUseAsWhole = /BODY|TD|LI/i,
  13849. oStartNode, oEndNode, oNode,
  13850. elCommonAncestor,
  13851. elCommonNode,
  13852. elParentQuote,
  13853. elInsertBefore,
  13854. oFormattingNode,
  13855. elNextNode,
  13856. elParentNode,
  13857. aQuoteChild,
  13858. aQuoteCloneChild,
  13859. i, nLen, oP,
  13860. sBookmarkID;
  13861. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["BLOCK QUOTE", {sSaveTarget:"BODY"}]);
  13862. oSelection = this.oApp.getSelection();
  13863. // var sBookmarkID = oSelection.placeStringBookmark();
  13864. // [SMARTEDITORSUS-430] 문자를 입력하고 Enter 후 인용구를 적용할 때 위의 문자들이 인용구 안에 들어가는 문제
  13865. // [SMARTEDITORSUS-1323] 사진 첨부 후 인용구 적용 시 첨부한 사진이 삭제되는 현상
  13866. if(oSelection.startContainer === oSelection.endContainer &&
  13867. oSelection.startContainer.nodeType === 1 &&
  13868. oSelection.startContainer.tagName === "P"){
  13869. if(nhn.husky.SE2M_Utils.isBlankNode(oSelection.startContainer) ||
  13870. nhn.husky.SE2M_Utils.isFirstChildOfNode("IMG", oSelection.startContainer.tagName, oSelection.startContainer) ||
  13871. nhn.husky.SE2M_Utils.isFirstChildOfNode("IFRAME", oSelection.startContainer.tagName, oSelection.startContainer)){
  13872. oLineInfo = oSelection.getLineInfo(true);
  13873. }else{
  13874. oLineInfo = oSelection.getLineInfo(false);
  13875. }
  13876. }else{
  13877. oLineInfo = oSelection.getLineInfo(false);
  13878. }
  13879. oStart = oLineInfo.oStart;
  13880. oEnd = oLineInfo.oEnd;
  13881. if(oStart.bParentBreak && !rxDontUseAsWhole.test(oStart.oLineBreaker.tagName)){
  13882. oStartNode = oStart.oNode.parentNode;
  13883. }else{
  13884. oStartNode = oStart.oNode;
  13885. }
  13886. if(oEnd.bParentBreak && !rxDontUseAsWhole.test(oEnd.oLineBreaker.tagName)){
  13887. oEndNode = oEnd.oNode.parentNode;
  13888. }else{
  13889. oEndNode = oEnd.oNode;
  13890. }
  13891. oSelection.setStartBefore(oStartNode);
  13892. oSelection.setEndAfter(oEndNode);
  13893. oNode = this._expandToTableStart(oSelection, oEndNode);
  13894. if(oNode){
  13895. oEndNode = oNode;
  13896. oSelection.setEndAfter(oNode);
  13897. }
  13898. oNode = this._expandToTableStart(oSelection, oStartNode);
  13899. if(oNode){
  13900. oStartNode = oNode;
  13901. oSelection.setStartBefore(oNode);
  13902. }
  13903. oNode = oStartNode;
  13904. // IE에서는 commonAncestorContainer 자체는 select 가능하지 않고, 하위에 commonAncestorContainer를 대체 하더라도 똑같은 영역이 셀렉트 되어 보이는
  13905. // 노드가 있을 경우 하위 노드가 commonAncestorContainer로 반환됨.
  13906. // 그래서, 스크립트로 commonAncestorContainer 계산 하도록 함.
  13907. // 예)
  13908. // <P><SPAN>TEST</SPAN></p>를 선택 할 경우, <SPAN>TEST</SPAN>가 commonAncestorContainer로 잡힘
  13909. oSelection.fixCommonAncestorContainer();
  13910. elCommonAncestor = oSelection.commonAncestorContainer;
  13911. if(oSelection.startContainer == oSelection.endContainer && oSelection.endOffset-oSelection.startOffset == 1){
  13912. elCommonNode = oSelection.startContainer.childNodes[oSelection.startOffset];
  13913. }else{
  13914. elCommonNode = oSelection.commonAncestorContainer;
  13915. }
  13916. elParentQuote = this._findParentQuote(elCommonNode);
  13917. if(elParentQuote){
  13918. elParentQuote.className = className;
  13919. // [SMARTEDITORSUS-1239] blockquote 태그교체시 style 적용
  13920. this._setStyle(elParentQuote, this.htQuoteStyles_view[className]);
  13921. // --[SMARTEDITORSUS-1239]
  13922. return;
  13923. }
  13924. while(!elCommonAncestor.tagName || (elCommonAncestor.tagName && elCommonAncestor.tagName.match(/UL|OL|LI|IMG|IFRAME/))){
  13925. elCommonAncestor = elCommonAncestor.parentNode;
  13926. }
  13927. // find the insertion position for the formatting tag right beneath the common ancestor container
  13928. while(oNode && oNode != elCommonAncestor && oNode.parentNode != elCommonAncestor){oNode = oNode.parentNode;}
  13929. if(oNode == elCommonAncestor){
  13930. elInsertBefore = elCommonAncestor.firstChild;
  13931. }else{
  13932. elInsertBefore = oNode;
  13933. }
  13934. oFormattingNode = oSelection._document.createElement(tag);
  13935. if(className){
  13936. oFormattingNode.className = className;
  13937. // [SMARTEDITORSUS-1239] 에디터에서 인용구 5개이상 상입 시 에디터를 뚫고 노출되는 현상
  13938. // [SMARTEDITORSUS-1229] 인용구 여러 개 중첩하면 에디터 본문 영역을 벗어나는 현상
  13939. // blockquate style 적용
  13940. this._setStyle(oFormattingNode, this.htQuoteStyles_view[className]);
  13941. }
  13942. elCommonAncestor.insertBefore(oFormattingNode, elInsertBefore);
  13943. oSelection.setStartAfter(oFormattingNode);
  13944. oSelection.setEndAfter(oEndNode);
  13945. oSelection.surroundContents(oFormattingNode);
  13946. if(this._isExceedMaxDepth(oFormattingNode)){
  13947. alert(this.oApp.$MSG("SE2M_Quote.exceedMaxCount").replace("#MaxCount#", (this.nMaxLevel + 1)));
  13948. this.oApp.exec("HIDE_ACTIVE_LAYER", []);
  13949. elNextNode = oFormattingNode.nextSibling;
  13950. elParentNode = oFormattingNode.parentNode;
  13951. aQuoteChild = oFormattingNode.childNodes;
  13952. aQuoteCloneChild = [];
  13953. jindo.$Element(oFormattingNode).leave();
  13954. for(i = 0, nLen = aQuoteChild.length; i < nLen; i++){
  13955. aQuoteCloneChild[i] = aQuoteChild[i];
  13956. }
  13957. for(i = 0, nLen = aQuoteCloneChild.length; i < nLen; i++){
  13958. if(!!elNextNode){
  13959. jindo.$Element(elNextNode).before(aQuoteCloneChild[i]);
  13960. }else{
  13961. jindo.$Element(elParentNode).append(aQuoteCloneChild[i]);
  13962. }
  13963. }
  13964. return;
  13965. }
  13966. oSelection.selectNodeContents(oFormattingNode);
  13967. // insert an empty line below, so the text cursor can move there
  13968. if(oFormattingNode && oFormattingNode.parentNode && oFormattingNode.parentNode.tagName == "BODY" && !oFormattingNode.nextSibling){
  13969. oP = oSelection._document.createElement("P");
  13970. //oP.innerHTML = unescape("<br/>");
  13971. oP.innerHTML = "&nbsp;";
  13972. oFormattingNode.parentNode.insertBefore(oP, oFormattingNode.nextSibling);
  13973. }
  13974. // oSelection.removeStringBookmark(sBookmarkID);
  13975. // Insert an empty line inside the blockquote if it's empty.
  13976. // This is done to position the cursor correctly when the contents of the blockquote is empty in Chrome.
  13977. if(nhn.husky.SE2M_Utils.isBlankNode(oFormattingNode)){
  13978. // [SMARTEDITORSUS-1751] 현재 undo/redo 기능을 사용하지 않고 ie7은 주요브라우저에서 제외되었기 때문에 다른 이슈들 처리시 복잡도를 줄이기 위해 코멘트처리함
  13979. // [SMARTEDITORSUS-645] 편집영역 포커스 없이 인용구 추가했을 때 IE7에서 박스가 늘어나는 문제
  13980. //oFormattingNode.innerHTML = "&nbsp;";
  13981. // [SMARTEDITORSUS-1567] P 태그로 감싸주지 않으면 크롬에서 blockquote 태그에 정렬이 적용되는데 IR_TO_DB 컨버터에서 style을 리셋하고 있기 때문에 저장되는 시점에 정렬이 제거된다.
  13982. // [SMARTEDITORSUS-1229] 인용구 여러 개 중첩하면 에디터 본문 영역을 벗어나는 현상
  13983. oFormattingNode.innerHTML = "&nbsp;";
  13984. // [SMARTEDITORSUS-1741] 커서가 p태그 안으로 들어가도록 세팅
  13985. oSelection.selectNodeContents(oFormattingNode.firstChild);
  13986. oSelection.collapseToStart();
  13987. oSelection.select();
  13988. }
  13989. //oSelection.select();
  13990. setTimeout(jindo.$Fn(function(oSelection){
  13991. sBookmarkID = oSelection.placeStringBookmark();
  13992. oSelection.select();
  13993. oSelection.removeStringBookmark(sBookmarkID);
  13994. this.oApp.exec("FOCUS"); // [SMARTEDITORSUS-469] [SMARTEDITORSUS-434] 에디터 로드 후 최초 삽입한 인용구 안에 포커스가 가지 않는 문제
  13995. },this).bind(oSelection), 0);
  13996. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["BLOCK QUOTE", {sSaveTarget:"BODY"}]);
  13997. return oFormattingNode;
  13998. },
  13999. _expandToTableStart : function(oSelection, oNode){
  14000. var elCommonAncestor = oSelection.commonAncestorContainer;
  14001. var oResultNode = null;
  14002. var bLastIteration = false;
  14003. while(oNode && !bLastIteration){
  14004. if(oNode == elCommonAncestor){bLastIteration = true;}
  14005. if(/TBODY|TFOOT|THEAD|TR/i.test(oNode.tagName)){
  14006. oResultNode = this._getTableRoot(oNode);
  14007. break;
  14008. }
  14009. oNode = oNode.parentNode;
  14010. }
  14011. return oResultNode;
  14012. },
  14013. _getTableRoot : function(oNode){
  14014. while(oNode && oNode.tagName != "TABLE"){oNode = oNode.parentNode;}
  14015. return oNode;
  14016. },
  14017. _setStyle : function(el, sStyle) {
  14018. el.setAttribute("style", sStyle);
  14019. el.style.cssText = sStyle;
  14020. }
  14021. //@lazyload_js]
  14022. });
  14023. nhn.husky.HuskyCore.addLoadedFile("hp_SE2M_SCharacter$Lazy.js");
  14024. /**
  14025. * @depends nhn.husky.SE2M_SCharacter
  14026. * this.oApp.registerLazyMessage(["TOGGLE_SCHARACTER_LAYER"], ["hp_SE2M_SCharacter$Lazy.js"]);
  14027. */
  14028. nhn.husky.HuskyCore.mixin(nhn.husky.SE2M_SCharacter, {
  14029. //@lazyload_js TOGGLE_SCHARACTER_LAYER[
  14030. _assignHTMLObjects : function(oAppContainer){
  14031. oAppContainer = jindo.$(oAppContainer) || document;
  14032. this.elDropdownLayer = jindo.$$.getSingle("DIV.husky_seditor_sCharacter_layer", oAppContainer);
  14033. this.oTextField = jindo.$$.getSingle("INPUT", this.elDropdownLayer);
  14034. this.oInsertButton = jindo.$$.getSingle("BUTTON.se2_confirm", this.elDropdownLayer);
  14035. this.aCloseButton = jindo.$$("BUTTON.husky_se2m_sCharacter_close", this.elDropdownLayer);
  14036. this.aSCharList = jindo.$$("UL.husky_se2m_sCharacter_list", this.elDropdownLayer);
  14037. var oLabelUL = jindo.$$.getSingle("UL.se2_char_tab", this.elDropdownLayer);
  14038. this.aLabel = jindo.$$(">LI", oLabelUL);
  14039. },
  14040. $LOCAL_BEFORE_FIRST : function(sFullMsg){
  14041. this.bIE = jindo.$Agent().navigator().ie;
  14042. this._assignHTMLObjects(this.oApp.htOptions.elAppContainer);
  14043. this.charSet = [];
  14044. this.charSet[0] = unescape('FF5B FF5D 3014 3015 3008 3009 300A 300B 300C 300D 300E 300F 3010 3011 2018 2019 201C 201D 3001 3002 %B7 2025 2026 %A7 203B 2606 2605 25CB 25CF 25CE 25C7 25C6 25A1 25A0 25B3 25B2 25BD 25BC 25C1 25C0 25B7 25B6 2664 2660 2661 2665 2667 2663 2299 25C8 25A3 25D0 25D1 2592 25A4 25A5 25A8 25A7 25A6 25A9 %B1 %D7 %F7 2260 2264 2265 221E 2234 %B0 2032 2033 2220 22A5 2312 2202 2261 2252 226A 226B 221A 223D 221D 2235 222B 222C 2208 220B 2286 2287 2282 2283 222A 2229 2227 2228 FFE2 21D2 21D4 2200 2203 %B4 FF5E 02C7 02D8 02DD 02DA 02D9 %B8 02DB %A1 %BF 02D0 222E 2211 220F 266D 2669 266A 266C 327F 2192 2190 2191 2193 2194 2195 2197 2199 2196 2198 321C 2116 33C7 2122 33C2 33D8 2121 2668 260F 260E 261C 261E %B6 2020 2021 %AE %AA %BA 2642 2640').replace(/(\S{4})/g, function(a){return "%u"+a;}).split(' ');
  14045. this.charSet[1] = unescape('%BD 2153 2154 %BC %BE 215B 215C 215D 215E %B9 %B2 %B3 2074 207F 2081 2082 2083 2084 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 FFE6 %24 FFE5 FFE1 20AC 2103 212B 2109 FFE0 %A4 2030 3395 3396 3397 2113 3398 33C4 33A3 33A4 33A5 33A6 3399 339A 339B 339C 339D 339E 339F 33A0 33A1 33A2 33CA 338D 338E 338F 33CF 3388 3389 33C8 33A7 33A8 33B0 33B1 33B2 33B3 33B4 33B5 33B6 33B7 33B8 33B9 3380 3381 3382 3383 3384 33BA 33BB 33BC 33BD 33BE 33BF 3390 3391 3392 3393 3394 2126 33C0 33C1 338A 338B 338C 33D6 33C5 33AD 33AE 33AF 33DB 33A9 33AA 33AB 33AC 33DD 33D0 33D3 33C3 33C9 33DC 33C6').replace(/(\S{4})/g, function(a){return "%u"+a;}).split(' ');
  14046. this.charSet[2] = unescape('3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 326A 326B 326C 326D 326E 326F 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 327A 327B 24D0 24D1 24D2 24D3 24D4 24D5 24D6 24D7 24D8 24D9 24DA 24DB 24DC 24DD 24DE 24DF 24E0 24E1 24E2 24E3 24E4 24E5 24E6 24E7 24E8 24E9 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 246A 246B 246C 246D 246E 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 320A 320B 320C 320D 320E 320F 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 321A 321B 249C 249D 249E 249F 24A0 24A1 24A2 24A3 24A4 24A5 24A6 24A7 24A8 24A9 24AA 24AB 24AC 24AD 24AE 24AF 24B0 24B1 24B2 24B3 24B4 24B5 2474 2475 2476 2477 2478 2479 247A 247B 247C 247D 247E 247F 2480 2481 2482').replace(/(\S{4})/g, function(a){return "%u"+a;}).split(' ');
  14047. this.charSet[3] = unescape('3131 3132 3133 3134 3135 3136 3137 3138 3139 313A 313B 313C 313D 313E 313F 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 314A 314B 314C 314D 314E 314F 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 315A 315B 315C 315D 315E 315F 3160 3161 3162 3163 3165 3166 3167 3168 3169 316A 316B 316C 316D 316E 316F 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 317A 317B 317C 317D 317E 317F 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 318A 318B 318C 318D 318E').replace(/(\S{4})/g, function(a){return "%u"+a;}).split(' ');
  14048. this.charSet[4] = unescape('0391 0392 0393 0394 0395 0396 0397 0398 0399 039A 039B 039C 039D 039E 039F 03A0 03A1 03A3 03A4 03A5 03A6 03A7 03A8 03A9 03B1 03B2 03B3 03B4 03B5 03B6 03B7 03B8 03B9 03BA 03BB 03BC 03BD 03BE 03BF 03C0 03C1 03C3 03C4 03C5 03C6 03C7 03C8 03C9 %C6 %D0 0126 0132 013F 0141 %D8 0152 %DE 0166 014A %E6 0111 %F0 0127 I 0133 0138 0140 0142 0142 0153 %DF %FE 0167 014B 0149 0411 0413 0414 0401 0416 0417 0418 0419 041B 041F 0426 0427 0428 0429 042A 042B 042C 042D 042E 042F 0431 0432 0433 0434 0451 0436 0437 0438 0439 043B 043F 0444 0446 0447 0448 0449 044A 044B 044C 044D 044E 044F').replace(/(\S{4})/g, function(a){return "%u"+a;}).split(' ');
  14049. this.charSet[5] = unescape('3041 3042 3043 3044 3045 3046 3047 3048 3049 304A 304B 304C 304D 304E 304F 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 305A 305B 305C 305D 305E 305F 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 306A 306B 306C 306D 306E 306F 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 307A 307B 307C 307D 307E 307F 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 308A 308B 308C 308D 308E 308F 3090 3091 3092 3093 30A1 30A2 30A3 30A4 30A5 30A6 30A7 30A8 30A9 30AA 30AB 30AC 30AD 30AE 30AF 30B0 30B1 30B2 30B3 30B4 30B5 30B6 30B7 30B8 30B9 30BA 30BB 30BC 30BD 30BE 30BF 30C0 30C1 30C2 30C3 30C4 30C5 30C6 30C7 30C8 30C9 30CA 30CB 30CC 30CD 30CE 30CF 30D0 30D1 30D2 30D3 30D4 30D5 30D6 30D7 30D8 30D9 30DA 30DB 30DC 30DD 30DE 30DF 30E0 30E1 30E2 30E3 30E4 30E5 30E6 30E7 30E8 30E9 30EA 30EB 30EC 30ED 30EE 30EF 30F0 30F1 30F2 30F3 30F4 30F5 30F6').replace(/(\S{4})/g, function(a){return "%u"+a;}).split(' ');
  14050. var funcInsert = jindo.$Fn(this.oApp.exec, this.oApp).bind("INSERT_SCHARACTERS", [this.oTextField.value]);
  14051. jindo.$Fn(funcInsert, this).attach(this.oInsertButton, "click");
  14052. this.oApp.exec("SET_SCHARACTER_LIST", [this.charSet]);
  14053. for(var i=0; i<this.aLabel.length; i++){
  14054. var func = jindo.$Fn(this.oApp.exec, this.oApp).bind("CHANGE_SCHARACTER_SET", [i]);
  14055. jindo.$Fn(func, this).attach(this.aLabel[i].firstChild, "mousedown");
  14056. }
  14057. for(var i=0; i<this.aCloseButton.length; i++){
  14058. this.oApp.registerBrowserEvent(this.aCloseButton[i], "click", "HIDE_ACTIVE_LAYER", []);
  14059. }
  14060. this.oApp.registerBrowserEvent(this.elDropdownLayer, "click", "EVENT_SCHARACTER_CLICKED", []);
  14061. // [SMARTEDITORSUS-1767]
  14062. this.oApp.registerBrowserEvent(this.oTextField, "keydown", "EVENT_SCHARACTER_KEYDOWN");
  14063. // --[SMARTEDITORSUS-1767]
  14064. },
  14065. // [SMARTEDITORSUS-1767]
  14066. $ON_EVENT_SCHARACTER_KEYDOWN : function(oEvent){
  14067. if (oEvent.key().enter){
  14068. this.oApp.exec("INSERT_SCHARACTERS");
  14069. oEvent.stop();
  14070. }
  14071. },
  14072. // --[SMARTEDITORSUS-1767]
  14073. $ON_TOGGLE_SCHARACTER_LAYER : function(){
  14074. this.oTextField.value = "";
  14075. this.oSelection = this.oApp.getSelection();
  14076. this.oApp.exec("TOGGLE_TOOLBAR_ACTIVE_LAYER", [this.elDropdownLayer, null, "MSG_SCHARACTER_LAYER_SHOWN", [], "MSG_SCHARACTER_LAYER_HIDDEN", [""]]);
  14077. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['symbol']);
  14078. },
  14079. $ON_MSG_SCHARACTER_LAYER_SHOWN : function(){
  14080. this.oTextField.focus();
  14081. this.oApp.exec("SELECT_UI", ["sCharacter"]);
  14082. },
  14083. $ON_MSG_SCHARACTER_LAYER_HIDDEN : function(){
  14084. this.oApp.exec("DESELECT_UI", ["sCharacter"]);
  14085. },
  14086. $ON_EVENT_SCHARACTER_CLICKED : function(weEvent){
  14087. var elButton = nhn.husky.SE2M_Utils.findAncestorByTagName("BUTTON", weEvent.element);
  14088. if(!elButton || elButton.tagName != "BUTTON"){return;}
  14089. if(elButton.parentNode.tagName != "LI"){return;}
  14090. var sChar = elButton.firstChild.innerHTML;
  14091. if(sChar.length > 1){return;}
  14092. this.oApp.exec("SELECT_SCHARACTER", [sChar]);
  14093. weEvent.stop();
  14094. },
  14095. $ON_SELECT_SCHARACTER : function(schar){
  14096. this.oTextField.value += schar;
  14097. if(this.oTextField.createTextRange){
  14098. var oTextRange = this.oTextField.createTextRange();
  14099. oTextRange.collapse(false);
  14100. oTextRange.select();
  14101. }else{
  14102. if(this.oTextField.selectionEnd){
  14103. this.oTextField.selectionEnd = this.oTextField.value.length;
  14104. this.oTextField.focus();
  14105. }
  14106. }
  14107. },
  14108. $ON_INSERT_SCHARACTERS : function(){
  14109. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["INSERT SCHARACTER"]);
  14110. this.oApp.exec("PASTE_HTML", [this.oTextField.value]);
  14111. this.oApp.exec("FOCUS");
  14112. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["INSERT SCHARACTER"]);
  14113. this.oApp.exec("HIDE_ACTIVE_LAYER", []);
  14114. },
  14115. $ON_CHANGE_SCHARACTER_SET : function(nSCharSet){
  14116. for(var i=0; i<this.aSCharList.length; i++){
  14117. if(jindo.$Element(this.aLabel[i]).hasClass("active")){
  14118. if(i == nSCharSet){return;}
  14119. jindo.$Element(this.aLabel[i]).removeClass("active");
  14120. }
  14121. }
  14122. this._drawSCharList(nSCharSet);
  14123. jindo.$Element(this.aLabel[nSCharSet]).addClass("active");
  14124. },
  14125. $ON_SET_SCHARACTER_LIST : function(charSet){
  14126. this.charSet = charSet;
  14127. this.bSCharSetDrawn = new Array(this.charSet.length);
  14128. this._drawSCharList(0);
  14129. },
  14130. _drawSCharList : function(i){
  14131. if(this.bSCharSetDrawn[i]){return;}
  14132. this.bSCharSetDrawn[i] = true;
  14133. var len = this.charSet[i].length;
  14134. var aLI = new Array(len);
  14135. this.aSCharList[i].innerHTML = '';
  14136. var button, span;
  14137. for(var ii=0; ii<len; ii++){
  14138. aLI[ii] = jindo.$("<LI>");
  14139. if(this.bIE){
  14140. button = jindo.$("<BUTTON>");
  14141. button.setAttribute('type', 'button');
  14142. }else{
  14143. button = jindo.$("<BUTTON>");
  14144. button.type = "button";
  14145. }
  14146. span = jindo.$("<SPAN>");
  14147. span.innerHTML = unescape(this.charSet[i][ii]);
  14148. button.appendChild(span);
  14149. aLI[ii].appendChild(button);
  14150. aLI[ii].onmouseover = function(){this.className='hover'};
  14151. aLI[ii].onmouseout = function(){this.className=''};
  14152. this.aSCharList[i].appendChild(aLI[ii]);
  14153. }
  14154. //this.oApp.delayedExec("SE2_ATTACH_HOVER_EVENTS", [jindo.$$(">LI", this.aSCharList[i]), 0]);
  14155. }
  14156. //@lazyload_js]
  14157. });
  14158. nhn.husky.HuskyCore.addLoadedFile("hp_SE2M_TableCreator$Lazy.js");
  14159. /**
  14160. * @depends nhn.husky.SE2M_TableCreator
  14161. * this.oApp.registerLazyMessage(["TOGGLE_TABLE_LAYER"], ["hp_SE2M_TableCreator$Lazy.js"]);
  14162. */
  14163. nhn.husky.HuskyCore.mixin(nhn.husky.SE2M_TableCreator, {
  14164. //@lazyload_js TOGGLE_TABLE_LAYER[
  14165. _assignHTMLObjects : function(oAppContainer){
  14166. this.oApp.exec("LOAD_HTML", ["create_table"]);
  14167. var tmp = null;
  14168. this.elDropdownLayer = jindo.$$.getSingle("DIV.husky_se2m_table_layer", oAppContainer);
  14169. this.welDropdownLayer = jindo.$Element(this.elDropdownLayer);
  14170. tmp = jindo.$$("INPUT", this.elDropdownLayer);
  14171. this.elText_row = tmp[0];
  14172. this.elText_col = tmp[1];
  14173. this.elRadio_manualStyle = tmp[2];
  14174. this.elText_borderSize = tmp[3];
  14175. this.elText_borderColor = tmp[4];
  14176. this.elText_BGColor = tmp[5];
  14177. this.elRadio_templateStyle = tmp[6];
  14178. tmp = jindo.$$("BUTTON", this.elDropdownLayer);
  14179. this.elBtn_rowInc = tmp[0];
  14180. this.elBtn_rowDec = tmp[1];
  14181. this.elBtn_colInc = tmp[2];
  14182. this.elBtn_colDec = tmp[3];
  14183. this.elBtn_borderStyle = tmp[4];
  14184. this.elBtn_incBorderSize = jindo.$$.getSingle("BUTTON.se2m_incBorder", this.elDropdownLayer);
  14185. this.elBtn_decBorderSize = jindo.$$.getSingle("BUTTON.se2m_decBorder", this.elDropdownLayer);
  14186. this.elLayer_Dim1 = jindo.$$.getSingle("DIV.se2_t_dim0", this.elDropdownLayer);
  14187. this.elLayer_Dim2 = jindo.$$.getSingle("DIV.se2_t_dim3", this.elDropdownLayer);
  14188. // border style layer contains btn elm's
  14189. tmp = jindo.$$("SPAN.se2_pre_color>BUTTON", this.elDropdownLayer);
  14190. this.elBtn_borderColor = tmp[0];
  14191. this.elBtn_BGColor = tmp[1];
  14192. this.elBtn_tableStyle = jindo.$$.getSingle("DIV.se2_select_ty2>BUTTON", this.elDropdownLayer);
  14193. tmp = jindo.$$("P.se2_btn_area>BUTTON", this.elDropdownLayer);
  14194. this.elBtn_apply = tmp[0];
  14195. this.elBtn_cancel = tmp[1];
  14196. this.elTable_preview = jindo.$$.getSingle("TABLE.husky_se2m_table_preview", this.elDropdownLayer);
  14197. this.elLayer_borderStyle = jindo.$$.getSingle("DIV.husky_se2m_table_border_style_layer", this.elDropdownLayer);
  14198. this.elPanel_borderStylePreview = jindo.$$.getSingle("SPAN.husky_se2m_table_border_style_preview", this.elDropdownLayer);
  14199. this.elPanel_borderColorPallet = jindo.$$.getSingle("DIV.husky_se2m_table_border_color_pallet", this.elDropdownLayer);
  14200. this.elPanel_bgColorPallet = jindo.$$.getSingle("DIV.husky_se2m_table_bgcolor_pallet", this.elDropdownLayer);
  14201. this.elLayer_tableStyle = jindo.$$.getSingle("DIV.husky_se2m_table_style_layer", this.elDropdownLayer);
  14202. this.elPanel_tableStylePreview = jindo.$$.getSingle("SPAN.husky_se2m_table_style_preview", this.elDropdownLayer);
  14203. this.aElBtn_borderStyle = jindo.$$("BUTTON", this.elLayer_borderStyle);
  14204. this.aElBtn_tableStyle = jindo.$$("BUTTON", this.elLayer_tableStyle);
  14205. this.sNoBorderText = jindo.$$.getSingle("SPAN.se2m_no_border", this.elDropdownLayer).innerHTML;
  14206. this.rxLastDigits = RegExp("([0-9]+)$");
  14207. },
  14208. $LOCAL_BEFORE_FIRST : function(){
  14209. this._assignHTMLObjects(this.oApp.htOptions.elAppContainer);
  14210. this.oApp.registerBrowserEvent(this.elText_row, "change", "TABLE_SET_ROW_NUM", [null, 0]);
  14211. this.oApp.registerBrowserEvent(this.elText_col, "change", "TABLE_SET_COLUMN_NUM", [null, 0]);
  14212. this.oApp.registerBrowserEvent(this.elText_borderSize, "change", "TABLE_SET_BORDER_SIZE", [null, 0]);
  14213. this.oApp.registerBrowserEvent(this.elBtn_rowInc, "click", "TABLE_INC_ROW");
  14214. this.oApp.registerBrowserEvent(this.elBtn_rowDec, "click", "TABLE_DEC_ROW");
  14215. jindo.$Fn(this._numRowKeydown, this).attach(this.elText_row.parentNode, "keydown");
  14216. this.oApp.registerBrowserEvent(this.elBtn_colInc, "click", "TABLE_INC_COLUMN");
  14217. this.oApp.registerBrowserEvent(this.elBtn_colDec, "click", "TABLE_DEC_COLUMN");
  14218. jindo.$Fn(this._numColKeydown, this).attach(this.elText_col.parentNode, "keydown");
  14219. this.oApp.registerBrowserEvent(this.elBtn_incBorderSize, "click", "TABLE_INC_BORDER_SIZE");
  14220. this.oApp.registerBrowserEvent(this.elBtn_decBorderSize, "click", "TABLE_DEC_BORDER_SIZE");
  14221. jindo.$Fn(this._borderSizeKeydown, this).attach(this.elText_borderSize.parentNode, "keydown");
  14222. this.oApp.registerBrowserEvent(this.elBtn_borderStyle, "click", "TABLE_TOGGLE_BORDER_STYLE_LAYER");
  14223. this.oApp.registerBrowserEvent(this.elBtn_tableStyle, "click", "TABLE_TOGGLE_STYLE_LAYER");
  14224. this.oApp.registerBrowserEvent(this.elBtn_borderColor, "click", "TABLE_TOGGLE_BORDER_COLOR_PALLET");
  14225. this.oApp.registerBrowserEvent(this.elBtn_BGColor, "click", "TABLE_TOGGLE_BGCOLOR_PALLET");
  14226. this.oApp.registerBrowserEvent(this.elRadio_manualStyle, "click", "TABLE_ENABLE_MANUAL_STYLE");
  14227. this.oApp.registerBrowserEvent(this.elRadio_templateStyle, "click", "TABLE_ENABLE_TEMPLATE_STYLE");
  14228. //this.oApp.registerBrowserEvent(this.elDropdownLayer, "click", "TABLE_LAYER_CLICKED");
  14229. //this.oApp.registerBrowserEvent(this.elLayer_borderStyle, "click", "TABLE_BORDER_STYLE_LAYER_CLICKED");
  14230. //this.oApp.registerBrowserEvent(this.elLayer_tableStyle, "click", "TABLE_STYLE_LAYER_CLICKED");
  14231. this.oApp.exec("SE2_ATTACH_HOVER_EVENTS", [this.aElBtn_borderStyle]);
  14232. this.oApp.exec("SE2_ATTACH_HOVER_EVENTS", [this.aElBtn_tableStyle]);
  14233. var i;
  14234. for(i=0; i<this.aElBtn_borderStyle.length; i++){
  14235. this.oApp.registerBrowserEvent(this.aElBtn_borderStyle[i], "click", "TABLE_SELECT_BORDER_STYLE");
  14236. }
  14237. for(i=0; i<this.aElBtn_tableStyle.length; i++){
  14238. this.oApp.registerBrowserEvent(this.aElBtn_tableStyle[i], "click", "TABLE_SELECT_STYLE");
  14239. }
  14240. this.oApp.registerBrowserEvent(this.elBtn_apply, "click", "TABLE_INSERT");
  14241. this.oApp.registerBrowserEvent(this.elBtn_cancel, "click", "HIDE_ACTIVE_LAYER");
  14242. this.oApp.exec("TABLE_SET_BORDER_COLOR", [/#[0-9A-Fa-f]{6}/.test(this.elText_borderColor.value) ? this.elText_borderColor.value : "#cccccc"]);
  14243. this.oApp.exec("TABLE_SET_BGCOLOR", [/#[0-9A-Fa-f]{6}/.test(this.elText_BGColor.value) ? this.elText_BGColor.value : "#ffffff"]);
  14244. // 1: manual style
  14245. // 2: template style
  14246. this.nStyleMode = 1;
  14247. // add #BorderSize+x# if needed
  14248. //---
  14249. // [SMARTEDITORSUS-365] 테이블퀵에디터 > 속성 직접입력 > 테두리 스타일
  14250. // - 테두리 없음을 선택하는 경우 본문에 삽입하는 표에 가이드 라인을 표시해 줍니다. 보기 시에는 테두리가 보이지 않습니다.
  14251. this.aTableStyleByBorder = [
  14252. '',
  14253. 'border="1" cellpadding="0" cellspacing="0" style="border:1px dashed #c7c7c7; border-left:0; border-bottom:0;"',
  14254. 'border="1" cellpadding="0" cellspacing="0" style="border:#BorderSize#px dashed #BorderColor#; border-left:0; border-bottom:0;"',
  14255. 'border="0" cellpadding="0" cellspacing="0" style="border:#BorderSize#px solid #BorderColor#; border-left:0; border-bottom:0;"',
  14256. 'border="0" cellpadding="0" cellspacing="1" style="border:#BorderSize#px solid #BorderColor#;"',
  14257. 'border="0" cellpadding="0" cellspacing="1" style="border:#BorderSize#px double #BorderColor#;"',
  14258. 'border="0" cellpadding="0" cellspacing="1" style="border-width:#BorderSize*2#px #BorderSize#px #BorderSize#px #BorderSize*2#px; border-style:solid;border-color:#BorderColor#;"',
  14259. 'border="0" cellpadding="0" cellspacing="1" style="border-width:#BorderSize#px #BorderSize*2#px #BorderSize*2#px #BorderSize#px; border-style:solid;border-color:#BorderColor#;"'
  14260. ];
  14261. this.aTDStyleByBorder = [
  14262. '',
  14263. 'style="border:1px dashed #c7c7c7; border-top:0; border-right:0; background-color:#BGColor#"',
  14264. 'style="border:#BorderSize#px dashed #BorderColor#; border-top:0; border-right:0; background-color:#BGColor#"',
  14265. 'style="border:#BorderSize#px solid #BorderColor#; border-top:0; border-right:0; background-color:#BGColor#"',
  14266. 'style="border:#BorderSize#px solid #BorderColor#; background-color:#BGColor#"',
  14267. 'style="border:#BorderSize+2#px double #BorderColor#; background-color:#BGColor#"',
  14268. 'style="border-width:#BorderSize#px #BorderSize*2#px #BorderSize*2#px #BorderSize#px; border-style:solid;border-color:#BorderColor#; background-color:#BGColor#"',
  14269. 'style="border-width:#BorderSize*2#px #BorderSize#px #BorderSize#px #BorderSize*2#px; border-style:solid;border-color:#BorderColor#; background-color:#BGColor#"'
  14270. ];
  14271. this.oApp.registerBrowserEvent(this.elDropdownLayer, "keydown", "EVENT_TABLE_CREATE_KEYDOWN");
  14272. this._drawTableDropdownLayer();
  14273. },
  14274. $ON_TABLE_SELECT_BORDER_STYLE : function(weEvent){
  14275. var elButton = weEvent.currentElement;
  14276. // var aMatch = this.rxLastDigits.exec(weEvent.element.className);
  14277. var aMatch = this.rxLastDigits.exec(elButton.className);
  14278. this._selectBorderStyle(aMatch[1]);
  14279. },
  14280. $ON_TABLE_SELECT_STYLE : function(weEvent){
  14281. var aMatch = this.rxLastDigits.exec(weEvent.element.className);
  14282. this._selectTableStyle(aMatch[1]);
  14283. },
  14284. $ON_TOGGLE_TABLE_LAYER : function(){
  14285. // this.oSelection = this.oApp.getSelection();
  14286. this._showNewTable();
  14287. this.oApp.exec("TOGGLE_TOOLBAR_ACTIVE_LAYER", [this.elDropdownLayer, null, "SELECT_UI", ["table"], "TABLE_CLOSE", []]);
  14288. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['table']);
  14289. },
  14290. // $ON_TABLE_BORDER_STYLE_LAYER_CLICKED : function(weEvent){
  14291. // top.document.title = weEvent.element.tagName;
  14292. // },
  14293. $ON_TABLE_CLOSE_ALL : function(){
  14294. this.oApp.exec("TABLE_HIDE_BORDER_COLOR_PALLET", []);
  14295. this.oApp.exec("TABLE_HIDE_BGCOLOR_PALLET", []);
  14296. this.oApp.exec("TABLE_HIDE_BORDER_STYLE_LAYER", []);
  14297. this.oApp.exec("TABLE_HIDE_STYLE_LAYER", []);
  14298. },
  14299. $ON_TABLE_INC_ROW : function(){
  14300. this.oApp.exec("TABLE_SET_ROW_NUM", [null, 1]);
  14301. },
  14302. $ON_TABLE_DEC_ROW : function(){
  14303. this.oApp.exec("TABLE_SET_ROW_NUM", [null, -1]);
  14304. },
  14305. $ON_TABLE_INC_COLUMN : function(){
  14306. this.oApp.exec("TABLE_SET_COLUMN_NUM", [null, 1]);
  14307. },
  14308. $ON_TABLE_DEC_COLUMN : function(){
  14309. this.oApp.exec("TABLE_SET_COLUMN_NUM", [null, -1]);
  14310. },
  14311. $ON_TABLE_SET_ROW_NUM : function(nRows, nRowDiff){
  14312. nRows = nRows || parseInt(this.elText_row.value, 10) || 0;
  14313. nRowDiff = nRowDiff || 0;
  14314. nRows += nRowDiff;
  14315. if(nRows < this.nMinRows){nRows = this.nMinRows;}
  14316. if(nRows > this.nMaxRows){nRows = this.nMaxRows;}
  14317. this.elText_row.value = nRows;
  14318. this._showNewTable();
  14319. },
  14320. $ON_TABLE_SET_COLUMN_NUM : function(nColumns, nColumnDiff){
  14321. nColumns = nColumns || parseInt(this.elText_col.value, 10) || 0;
  14322. nColumnDiff = nColumnDiff || 0;
  14323. nColumns += nColumnDiff;
  14324. if(nColumns < this.nMinColumns){nColumns = this.nMinColumns;}
  14325. if(nColumns > this.nMaxColumns){nColumns = this.nMaxColumns;}
  14326. this.elText_col.value = nColumns;
  14327. this._showNewTable();
  14328. },
  14329. _getTableString : function(){
  14330. var sTable;
  14331. if(this.nStyleMode == 1){
  14332. sTable = this._doGetTableString(this.nColumns, this.nRows, this.nBorderSize, this.sBorderColor, this.sBGColor, this.nBorderStyleIdx);
  14333. }else{
  14334. sTable = this._doGetTableString(this.nColumns, this.nRows, this.nBorderSize, this.sBorderColor, this.sBGColor, 0);
  14335. }
  14336. return sTable;
  14337. },
  14338. $ON_TABLE_INSERT : function(){
  14339. this.oApp.exec("IE_FOCUS", []); // [SMARTEDITORSUS-500] IE인 경우 명시적인 focus 추가
  14340. //[SMARTEDITORSUS-596]이벤트 발생이 안되는 경우,
  14341. //max 제한이 적용이 안되기 때문에 테이블 사입 시점에 다시한번 Max 값을 검사한다.
  14342. this.oApp.exec("TABLE_SET_COLUMN_NUM");
  14343. this.oApp.exec("TABLE_SET_ROW_NUM");
  14344. this._loadValuesFromHTML();
  14345. var sTable,
  14346. elLinebreak,
  14347. elBody,
  14348. welBody,
  14349. elTmpDiv,
  14350. elTable,
  14351. elFirstTD,
  14352. oSelection,
  14353. elTableHolder,
  14354. htBrowser;
  14355. elBody = this.oApp.getWYSIWYGDocument().body;
  14356. welBody = jindo.$Element(elBody);
  14357. htBrowser = jindo.$Agent().navigator();
  14358. this.nTableWidth = elBody.offsetWidth;
  14359. sTable = this._getTableString();
  14360. elTmpDiv = this.oApp.getWYSIWYGDocument().createElement("DIV");
  14361. elTmpDiv.innerHTML = sTable;
  14362. elTable = elTmpDiv.firstChild;
  14363. elTable.className = this._sSETblClass;
  14364. oSelection = this.oApp.getSelection();
  14365. oSelection = this._divideParagraph(oSelection); // [SMARTEDITORSUS-306]
  14366. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["INSERT TABLE", {sSaveTarget:"BODY"}]);
  14367. // If the table were inserted within a styled(strikethough & etc) paragraph, the table may inherit the style in IE.
  14368. elTableHolder = this.oApp.getWYSIWYGDocument().createElement("DIV");
  14369. // 영역을 잡았을 경우, 영역 지우고 테이블 삽입
  14370. oSelection.deleteContents();
  14371. oSelection.insertNode(elTableHolder);
  14372. oSelection.selectNode(elTableHolder);
  14373. this.oApp.exec("REMOVE_STYLE", [oSelection]);
  14374. if(htBrowser.ie && this.oApp.getWYSIWYGDocument().body.childNodes.length === 1 && this.oApp.getWYSIWYGDocument().body.firstChild === elTableHolder){
  14375. // IE에서 table이 body에 바로 붙어 있을 경우, 정렬등에서 문제가 발생 함으로 elTableHolder(DIV)를 남겨둠
  14376. elTableHolder.insertBefore(elTable, null);
  14377. }else{
  14378. elTableHolder.parentNode.insertBefore(elTable, elTableHolder);
  14379. elTableHolder.parentNode.removeChild(elTableHolder);
  14380. }
  14381. // FF : 테이블 하단에 BR이 없을 경우, 커서가 테이블 밑으로 이동할 수 없어 BR을 삽입 해 줌.
  14382. //[SMARTEDITORSUS-181][IE9] 표나 요약글 등의 테이블에서 > 테이블 외부로 커서 이동 불가
  14383. if(htBrowser.firefox){
  14384. elLinebreak = this.oApp.getWYSIWYGDocument().createElement("BR");
  14385. elTable.parentNode.insertBefore(elLinebreak, elTable.nextSibling);
  14386. }else if(htBrowser.ie){
  14387. elLinebreak = this.oApp.getWYSIWYGDocument().createElement("p");
  14388. if(document.documentMode == 11){ // [SMARTEDITORSUS-2064] IE11인 경우 빈 P태그 안에 커서가 안들어가기 때문에 br 추가
  14389. elLinebreak.innerHTML = "<br>";
  14390. }
  14391. elTable.parentNode.insertBefore(elLinebreak, elTable.nextSibling);
  14392. }
  14393. if(this.nStyleMode == 2){
  14394. this.oApp.exec("STYLE_TABLE", [elTable, this.nTableStyleIdx]);
  14395. }
  14396. elFirstTD = elTable.getElementsByTagName("TD")[0];
  14397. oSelection.selectNodeContents(elFirstTD.firstChild || elFirstTD);
  14398. oSelection.collapseToEnd();
  14399. oSelection.select();
  14400. this.oApp.exec("FOCUS");
  14401. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["INSERT TABLE", {sSaveTarget:"BODY"}]);
  14402. this.oApp.exec("HIDE_ACTIVE_LAYER", []);
  14403. this.oApp.exec('MSG_DISPLAY_REEDIT_MESSAGE_SHOW', [this.name, this.sReEditGuideMsg_table]);
  14404. },
  14405. /**
  14406. * P 안에 Table 추가되지 않도록 P 태그를 분리함
  14407. *
  14408. * [SMARTEDITORSUS-306]
  14409. * P Table 추가한 경우, DOM 에서 비정상적인 P 생성하여 깨지는 경우가 발생함
  14410. * 테이블이 추가되는 부분에 P 있는 경우, P 분리시켜주는 처리
  14411. */
  14412. _divideParagraph : function(oSelection){
  14413. var oParentP,
  14414. welParentP,
  14415. sNodeVaule,
  14416. sBM, oSWrapper, oEWrapper;
  14417. oSelection.fixCommonAncestorContainer(); // [SMARTEDITORSUS-423] 엔터에 의해 생성된 P 가 아닌 이전 P 가 선택되지 않도록 fix 하도록 처리
  14418. /**
  14419. * [SMARTEDITORSUS-1735]
  14420. * 기존 로직은 selection을 기준으로 위로 거슬러 올라가면서
  14421. * 번째로 만나는 <P> 분리 기준으로 했다.
  14422. *
  14423. * 하지만 selection이 cell 내부에 있는 상태에서
  14424. * cell 내부에는 <P> 없고
  14425. * 해당 table을 <P> 감싸고 있는 경우,
  14426. * selection 기준으로 바깥의 <P> 개로 나뉜
  14427. * 해당 table이 양분되는 현상이 발생한다.
  14428. *
  14429. * 따라서 selection이 cell 내부에 있는 경우에는,
  14430. * cell 내부에 <P> 있는 경우에만 분리를 수행할 있도록 보정한다.
  14431. * */
  14432. //oParentP = oSelection.findAncestorByTagName("P");
  14433. var _elCommonAncestorContainer = oSelection.commonAncestorContainer;
  14434. var _htAncestor_P = nhn.husky.SE2M_Utils.findAncestorByTagNameWithCount("P", _elCommonAncestorContainer);
  14435. var _elAncestor_P = _htAncestor_P.elNode;
  14436. if(_elAncestor_P){
  14437. var _htAncestor_Cell = nhn.husky.SE2M_Utils.findClosestAncestorAmongTagNamesWithCount(["TD", "TH"], _elCommonAncestorContainer);
  14438. var _elAncestor_Cell = _htAncestor_Cell.elNode;
  14439. if(_elAncestor_Cell){
  14440. var _nRecursiveCount_P = _htAncestor_P.nRecursiveCount;
  14441. var _nRecursiveCount_Cell = _htAncestor_Cell.nRecursiveCount;
  14442. // cell 안에 있는 <P>일 때만 분할
  14443. if(_nRecursiveCount_P < _nRecursiveCount_Cell){
  14444. oParentP = _elAncestor_P;
  14445. }
  14446. }else{ // selection을 기준으로 cell이 발견되지 않으면 그대로 진행
  14447. oParentP = _elAncestor_P;
  14448. }
  14449. }
  14450. // --[SMARTEDITORSUS-1735]
  14451. if(!oParentP){
  14452. return oSelection;
  14453. }
  14454. if(!oParentP.firstChild || nhn.husky.SE2M_Utils.isBlankNode(oParentP)){
  14455. oSelection.selectNode(oParentP); // [SMARTEDITORSUS-423] 불필요한 개행이 일어나지 않도록 빈 P 를 선택하여 TABLE 로 대체하도록 처리
  14456. oSelection.select();
  14457. return oSelection;
  14458. }
  14459. sBM = oSelection.placeStringBookmark();
  14460. oSelection.moveToBookmark(sBM);
  14461. oSWrapper = this.oApp.getWYSIWYGDocument().createElement("P");
  14462. oSelection.setStartBefore(oParentP.firstChild);
  14463. oSelection.surroundContents(oSWrapper);
  14464. oSelection.collapseToEnd();
  14465. oEWrapper = this.oApp.getWYSIWYGDocument().createElement("P");
  14466. oSelection.setEndAfter(oParentP.lastChild);
  14467. oSelection.surroundContents(oEWrapper);
  14468. oSelection.collapseToStart();
  14469. oSelection.removeStringBookmark(sBM);
  14470. welParentP = jindo.$Element(oParentP);
  14471. welParentP.after(oEWrapper);
  14472. welParentP.after(oSWrapper);
  14473. welParentP.leave();
  14474. oSelection = this.oApp.getEmptySelection();
  14475. oSelection.setEndAfter(oSWrapper);
  14476. oSelection.setStartBefore(oEWrapper);
  14477. oSelection.select();
  14478. return oSelection;
  14479. },
  14480. $ON_TABLE_CLOSE : function(){
  14481. this.oApp.exec("TABLE_CLOSE_ALL", []);
  14482. this.oApp.exec("DESELECT_UI", ["table"]);
  14483. },
  14484. $ON_TABLE_SET_BORDER_SIZE : function(nBorderWidth, nBorderWidthDiff){
  14485. nBorderWidth = nBorderWidth || parseInt(this.elText_borderSize.value, 10) || 0;
  14486. nBorderWidthDiff = nBorderWidthDiff || 0;
  14487. nBorderWidth += nBorderWidthDiff;
  14488. if(nBorderWidth < this.nMinBorderWidth){nBorderWidth = this.nMinBorderWidth;}
  14489. if(nBorderWidth > this.nMaxBorderWidth){nBorderWidth = this.nMaxBorderWidth;}
  14490. this.elText_borderSize.value = nBorderWidth;
  14491. },
  14492. $ON_TABLE_INC_BORDER_SIZE : function(){
  14493. this.oApp.exec("TABLE_SET_BORDER_SIZE", [null, 1]);
  14494. },
  14495. $ON_TABLE_DEC_BORDER_SIZE : function(){
  14496. this.oApp.exec("TABLE_SET_BORDER_SIZE", [null, -1]);
  14497. },
  14498. $ON_TABLE_TOGGLE_BORDER_STYLE_LAYER : function(){
  14499. if(this.elLayer_borderStyle.style.display == "block"){
  14500. this.oApp.exec("TABLE_HIDE_BORDER_STYLE_LAYER", []);
  14501. }else{
  14502. this.oApp.exec("TABLE_SHOW_BORDER_STYLE_LAYER", []);
  14503. }
  14504. },
  14505. $ON_TABLE_SHOW_BORDER_STYLE_LAYER : function(){
  14506. this.oApp.exec("TABLE_CLOSE_ALL", []);
  14507. this.elBtn_borderStyle.className = "se2_view_more2";
  14508. this.elLayer_borderStyle.style.display = "block";
  14509. this._refresh();
  14510. },
  14511. $ON_TABLE_HIDE_BORDER_STYLE_LAYER : function(){
  14512. this.elBtn_borderStyle.className = "se2_view_more";
  14513. this.elLayer_borderStyle.style.display = "none";
  14514. this._refresh();
  14515. },
  14516. $ON_TABLE_TOGGLE_STYLE_LAYER : function(){
  14517. if(this.elLayer_tableStyle.style.display == "block"){
  14518. this.oApp.exec("TABLE_HIDE_STYLE_LAYER", []);
  14519. }else{
  14520. this.oApp.exec("TABLE_SHOW_STYLE_LAYER", []);
  14521. }
  14522. },
  14523. $ON_TABLE_SHOW_STYLE_LAYER : function(){
  14524. this.oApp.exec("TABLE_CLOSE_ALL", []);
  14525. this.elBtn_tableStyle.className = "se2_view_more2";
  14526. this.elLayer_tableStyle.style.display = "block";
  14527. this._refresh();
  14528. },
  14529. $ON_TABLE_HIDE_STYLE_LAYER : function(){
  14530. this.elBtn_tableStyle.className = "se2_view_more";
  14531. this.elLayer_tableStyle.style.display = "none";
  14532. this._refresh();
  14533. },
  14534. $ON_TABLE_TOGGLE_BORDER_COLOR_PALLET : function(){
  14535. if(this.welDropdownLayer.hasClass("p1")){
  14536. this.oApp.exec("TABLE_HIDE_BORDER_COLOR_PALLET", []);
  14537. }else{
  14538. this.oApp.exec("TABLE_SHOW_BORDER_COLOR_PALLET", []);
  14539. }
  14540. },
  14541. $ON_TABLE_SHOW_BORDER_COLOR_PALLET : function(){
  14542. this.oApp.exec("TABLE_CLOSE_ALL", []);
  14543. this.welDropdownLayer.addClass("p1");
  14544. this.welDropdownLayer.removeClass("p2");
  14545. this.oApp.exec("SHOW_COLOR_PALETTE", ["TABLE_SET_BORDER_COLOR_FROM_PALETTE", this.elPanel_borderColorPallet]);
  14546. this.elPanel_borderColorPallet.parentNode.style.display = "block";
  14547. },
  14548. $ON_TABLE_HIDE_BORDER_COLOR_PALLET : function(){
  14549. this.welDropdownLayer.removeClass("p1");
  14550. this.oApp.exec("HIDE_COLOR_PALETTE", []);
  14551. this.elPanel_borderColorPallet.parentNode.style.display = "none";
  14552. },
  14553. $ON_TABLE_TOGGLE_BGCOLOR_PALLET : function(){
  14554. if(this.welDropdownLayer.hasClass("p2")){
  14555. this.oApp.exec("TABLE_HIDE_BGCOLOR_PALLET", []);
  14556. }else{
  14557. this.oApp.exec("TABLE_SHOW_BGCOLOR_PALLET", []);
  14558. }
  14559. },
  14560. $ON_TABLE_SHOW_BGCOLOR_PALLET : function(){
  14561. this.oApp.exec("TABLE_CLOSE_ALL", []);
  14562. this.welDropdownLayer.removeClass("p1");
  14563. this.welDropdownLayer.addClass("p2");
  14564. this.oApp.exec("SHOW_COLOR_PALETTE", ["TABLE_SET_BGCOLOR_FROM_PALETTE", this.elPanel_bgColorPallet]);
  14565. this.elPanel_bgColorPallet.parentNode.style.display = "block";
  14566. },
  14567. $ON_TABLE_HIDE_BGCOLOR_PALLET : function(){
  14568. this.welDropdownLayer.removeClass("p2");
  14569. this.oApp.exec("HIDE_COLOR_PALETTE", []);
  14570. this.elPanel_bgColorPallet.parentNode.style.display = "none";
  14571. },
  14572. $ON_TABLE_SET_BORDER_COLOR_FROM_PALETTE : function(sColorCode){
  14573. this.oApp.exec("TABLE_SET_BORDER_COLOR", [sColorCode]);
  14574. this.oApp.exec("TABLE_HIDE_BORDER_COLOR_PALLET", []);
  14575. },
  14576. $ON_TABLE_SET_BORDER_COLOR : function(sColorCode){
  14577. this.elText_borderColor.value = sColorCode;
  14578. this.elBtn_borderColor.style.backgroundColor = sColorCode;
  14579. },
  14580. $ON_TABLE_SET_BGCOLOR_FROM_PALETTE : function(sColorCode){
  14581. this.oApp.exec("TABLE_SET_BGCOLOR", [sColorCode]);
  14582. this.oApp.exec("TABLE_HIDE_BGCOLOR_PALLET", []);
  14583. },
  14584. $ON_TABLE_SET_BGCOLOR : function(sColorCode){
  14585. this.elText_BGColor.value = sColorCode;
  14586. this.elBtn_BGColor.style.backgroundColor = sColorCode;
  14587. },
  14588. $ON_TABLE_ENABLE_MANUAL_STYLE : function(){
  14589. this.nStyleMode = 1;
  14590. this._drawTableDropdownLayer();
  14591. },
  14592. $ON_TABLE_ENABLE_TEMPLATE_STYLE : function(){
  14593. this.nStyleMode = 2;
  14594. this._drawTableDropdownLayer();
  14595. },
  14596. $ON_EVENT_TABLE_CREATE_KEYDOWN : function(oEvent){
  14597. if (oEvent.key().enter){
  14598. this.elBtn_apply.focus();
  14599. this.oApp.exec("TABLE_INSERT");
  14600. oEvent.stop();
  14601. }
  14602. },
  14603. _drawTableDropdownLayer : function(){
  14604. if(this.nBorderStyleIdx == 1){
  14605. this.elPanel_borderStylePreview.innerHTML = this.sNoBorderText;
  14606. this.elLayer_Dim1.className = "se2_t_dim2";
  14607. }else{
  14608. this.elPanel_borderStylePreview.innerHTML = "";
  14609. this.elLayer_Dim1.className = "se2_t_dim0";
  14610. }
  14611. if(this.nStyleMode == 1){
  14612. this.elRadio_manualStyle.checked = true;
  14613. this.elLayer_Dim2.className = "se2_t_dim3";
  14614. this.elText_borderSize.disabled = false;
  14615. this.elText_borderColor.disabled = false;
  14616. this.elText_BGColor.disabled = false;
  14617. }else{
  14618. this.elRadio_templateStyle.checked = true;
  14619. this.elLayer_Dim2.className = "se2_t_dim1";
  14620. this.elText_borderSize.disabled = true;
  14621. this.elText_borderColor.disabled = true;
  14622. this.elText_BGColor.disabled = true;
  14623. }
  14624. this.oApp.exec("TABLE_CLOSE_ALL", []);
  14625. },
  14626. _selectBorderStyle : function(nStyleNum){
  14627. this.elPanel_borderStylePreview.className = "se2_b_style"+nStyleNum;
  14628. this.nBorderStyleIdx = nStyleNum;
  14629. this._drawTableDropdownLayer();
  14630. },
  14631. _selectTableStyle : function(nStyleNum){
  14632. this.elPanel_tableStylePreview.className = "se2_t_style"+nStyleNum;
  14633. this.nTableStyleIdx = nStyleNum;
  14634. this._drawTableDropdownLayer();
  14635. },
  14636. _showNewTable : function(){
  14637. var oTmp = document.createElement("DIV");
  14638. this._loadValuesFromHTML();
  14639. oTmp.innerHTML = this._getPreviewTableString(this.nColumns, this.nRows);
  14640. //this.nTableWidth = 0;
  14641. //oTmp.innerHTML = this._getTableString();
  14642. var oNewTable = oTmp.firstChild;
  14643. this.elTable_preview.parentNode.insertBefore(oNewTable, this.elTable_preview);
  14644. this.elTable_preview.parentNode.removeChild(this.elTable_preview);
  14645. this.elTable_preview = oNewTable;
  14646. this._refresh();
  14647. },
  14648. _getPreviewTableString : function(nColumns, nRows){
  14649. var sTable = '<table border="0" cellspacing="1" class="se2_pre_table husky_se2m_table_preview">';
  14650. var sRow = '<tr>';
  14651. for(var i=0; i<nColumns; i++){
  14652. sRow += "<td><p>&nbsp;</p></td>\n";
  14653. }
  14654. sRow += "</tr>\n";
  14655. sTable += "<tbody>";
  14656. for(var i=0; i<nRows; i++){
  14657. sTable += sRow;
  14658. }
  14659. sTable += "</tbody>\n";
  14660. sTable += "</table>\n";
  14661. return sTable;
  14662. },
  14663. _loadValuesFromHTML : function(){
  14664. this.nColumns = parseInt(this.elText_col.value, 10) || 1;
  14665. this.nRows = parseInt(this.elText_row.value, 10) || 1;
  14666. this.nBorderSize = parseInt(this.elText_borderSize.value, 10) || 1;
  14667. this.sBorderColor = this.elText_borderColor.value;
  14668. this.sBGColor = this.elText_BGColor.value;
  14669. },
  14670. _doGetTableString : function(nColumns, nRows, nBorderSize, sBorderColor, sBGColor, nBorderStyleIdx){
  14671. var nTDWidth = parseInt(this.nTableWidth/nColumns, 10);
  14672. var nBorderSize = this.nBorderSize;
  14673. var sTableStyle = this.aTableStyleByBorder[nBorderStyleIdx].replace(/#BorderSize#/g, this.nBorderSize).replace(/#BorderSize\*([0-9]+)#/g, function(sAll, s1){return nBorderSize*parseInt(s1, 10);}).replace(/#BorderSize\+([0-9]+)#/g, function(sAll, s1){return nBorderSize+parseInt(s1, 10);}).replace("#BorderColor#", this.sBorderColor).replace("#BGColor#", this.sBGColor);
  14674. var sTDStyle = this.aTDStyleByBorder[nBorderStyleIdx].replace(/#BorderSize#/g, this.nBorderSize).replace(/#BorderSize\*([0-9]+)#/g, function(sAll, s1){return nBorderSize*parseInt(s1, 10);}).replace(/#BorderSize\+([0-9]+)#/g, function(sAll, s1){return nBorderSize+parseInt(s1, 10);}).replace("#BorderColor#", this.sBorderColor).replace("#BGColor#", this.sBGColor);
  14675. if(nTDWidth){
  14676. sTDStyle += " width="+nTDWidth;
  14677. }else{
  14678. //sTableStyle += " width=100%";
  14679. sTableStyle += "class=se2_pre_table";
  14680. }
  14681. // [SMARTEDITORSUS-365] 테이블퀵에디터 > 속성 직접입력 > 테두리 스타일
  14682. // - 테두리 없음을 선택하는 경우 본문에 삽입하는 표에 가이드 라인을 표시해 줍니다. 보기 시에는 테두리가 보이지 않습니다.
  14683. // - 글 저장 시에는 글 작성 시에 적용하였던 style 을 제거합니다. 이를 위해서 임의의 속성(attr_no_border_tbl)을 추가하였다가 저장 시점에서 제거해 주도록 합니다.
  14684. var sTempNoBorderClass = (nBorderStyleIdx == 1) ? 'attr_no_border_tbl="1"' : '';
  14685. var sTable = "<table "+sTableStyle+" "+sTempNoBorderClass+">";
  14686. var sRow = "<tr>";
  14687. for(var i=0; i<nColumns; i++){
  14688. sRow += "<td "+sTDStyle+"><p>&nbsp;</p></td>\n";
  14689. }
  14690. sRow += "</tr>\n";
  14691. sTable += "<tbody>\n";
  14692. for(var i=0; i<nRows; i++){
  14693. sTable += sRow;
  14694. }
  14695. sTable += "</tbody>\n";
  14696. sTable += "</table>\n<br>";
  14697. return sTable;
  14698. },
  14699. _numRowKeydown : function(weEvent){
  14700. var oKeyInfo = weEvent.key();
  14701. // up
  14702. if(oKeyInfo.keyCode == 38){
  14703. this.oApp.exec("TABLE_INC_ROW", []);
  14704. }
  14705. // down
  14706. if(oKeyInfo.keyCode == 40){
  14707. this.oApp.exec("TABLE_DEC_ROW", []);
  14708. }
  14709. },
  14710. _numColKeydown : function(weEvent){
  14711. var oKeyInfo = weEvent.key();
  14712. // up
  14713. if(oKeyInfo.keyCode == 38){
  14714. this.oApp.exec("TABLE_INC_COLUMN", []);
  14715. }
  14716. // down
  14717. if(oKeyInfo.keyCode == 40){
  14718. this.oApp.exec("TABLE_DEC_COLUMN", []);
  14719. }
  14720. },
  14721. _borderSizeKeydown : function(weEvent){
  14722. var oKeyInfo = weEvent.key();
  14723. // up
  14724. if(oKeyInfo.keyCode == 38){
  14725. this.oApp.exec("TABLE_INC_BORDER_SIZE", []);
  14726. }
  14727. // down
  14728. if(oKeyInfo.keyCode == 40){
  14729. this.oApp.exec("TABLE_DEC_BORDER_SIZE", []);
  14730. }
  14731. },
  14732. _refresh : function(){
  14733. // the dropdown layer breaks without this line in IE 6 when modifying the preview table
  14734. this.elDropdownLayer.style.zoom=0;
  14735. this.elDropdownLayer.style.zoom="";
  14736. }
  14737. //@lazyload_js]
  14738. });
  14739. nhn.husky.HuskyCore.addLoadedFile("hp_SE2M_TableEditor$Lazy.js");
  14740. /**
  14741. * @depends nhn.husky.SE2M_TableEditor
  14742. * this.oApp.registerLazyMessage(["EVENT_EDITING_AREA_MOUSEMOVE", "STYLE_TABLE"], ["hp_SE2M_TableEditor$Lazy.js","SE2M_TableTemplate.js"]);
  14743. */
  14744. nhn.husky.HuskyCore.mixin(nhn.husky.SE2M_TableEditor, {
  14745. // [SMARTEDITORSUS-1672]
  14746. _aCellName : ["TD", "TH"],
  14747. // --[SMARTEDITORSUS-1672]
  14748. //@lazyload_js EVENT_EDITING_AREA_MOUSEMOVE:SE2M_TableTemplate.js[
  14749. _assignHTMLObjects : function(){
  14750. this.oApp.exec("LOAD_HTML", ["qe_table"]);
  14751. this.elQELayer = jindo.$$.getSingle("DIV.q_table_wrap", this.oApp.htOptions.elAppContainer);
  14752. this.elQELayer.style.zIndex = 150;
  14753. this.elBtnAddRowBelow = jindo.$$.getSingle("BUTTON.se2_addrow", this.elQELayer);
  14754. this.elBtnAddColumnRight = jindo.$$.getSingle("BUTTON.se2_addcol", this.elQELayer);
  14755. this.elBtnSplitRow = jindo.$$.getSingle("BUTTON.se2_seprow", this.elQELayer);
  14756. this.elBtnSplitColumn = jindo.$$.getSingle("BUTTON.se2_sepcol", this.elQELayer);
  14757. this.elBtnDeleteRow = jindo.$$.getSingle("BUTTON.se2_delrow", this.elQELayer);
  14758. this.elBtnDeleteColumn = jindo.$$.getSingle("BUTTON.se2_delcol", this.elQELayer);
  14759. this.elBtnMergeCell = jindo.$$.getSingle("BUTTON.se2_merrow", this.elQELayer);
  14760. this.elBtnBGPalette = jindo.$$.getSingle("BUTTON.husky_se2m_table_qe_bgcolor_btn", this.elQELayer);
  14761. this.elBtnBGIMGPalette = jindo.$$.getSingle("BUTTON.husky_se2m_table_qe_bgimage_btn", this.elQELayer);
  14762. this.elPanelBGPaletteHolder = jindo.$$.getSingle("DIV.husky_se2m_tbl_qe_bg_paletteHolder", this.elQELayer);
  14763. this.elPanelBGIMGPaletteHolder = jindo.$$.getSingle("DIV.husky_se2m_tbl_qe_bg_img_paletteHolder", this.elQELayer);
  14764. this.elPanelTableBGArea = jindo.$$.getSingle("DIV.se2_qe2", this.elQELayer);
  14765. this.elPanelTableTemplateArea = jindo.$$.getSingle("DL.se2_qe3", this.elQELayer);
  14766. this.elPanelReviewBGArea = jindo.$$.getSingle("DL.husky_se2m_tbl_qe_review_bg", this.elQELayer);
  14767. this.elPanelBGImg = jindo.$$.getSingle("DD", this.elPanelReviewBGArea);
  14768. this.welPanelTableBGArea = jindo.$Element(this.elPanelTableBGArea);
  14769. this.welPanelTableTemplateArea = jindo.$Element(this.elPanelTableTemplateArea);
  14770. this.welPanelReviewBGArea = jindo.$Element(this.elPanelReviewBGArea);
  14771. // this.elPanelReviewBtnArea = jindo.$$.getSingle("DIV.se2_btn_area", this.elQELayer); //My리뷰 버튼 레이어
  14772. this.elPanelDim1 = jindo.$$.getSingle("DIV.husky_se2m_tbl_qe_dim1", this.elQELayer);
  14773. this.elPanelDim2 = jindo.$$.getSingle("DIV.husky_se2m_tbl_qe_dim2", this.elQELayer);
  14774. this.elPanelDimDelCol = jindo.$$.getSingle("DIV.husky_se2m_tbl_qe_dim_del_col", this.elQELayer);
  14775. this.elPanelDimDelRow = jindo.$$.getSingle("DIV.husky_se2m_tbl_qe_dim_del_row", this.elQELayer);
  14776. this.elInputRadioBGColor = jindo.$$.getSingle("INPUT.husky_se2m_radio_bgc", this.elQELayer);
  14777. this.elInputRadioBGImg = jindo.$$.getSingle("INPUT.husky_se2m_radio_bgimg", this.elQELayer);
  14778. this.elSelectBoxTemplate = jindo.$$.getSingle("DIV.se2_select_ty2", this.elQELayer);
  14779. this.elInputRadioTemplate = jindo.$$.getSingle("INPUT.husky_se2m_radio_template", this.elQELayer);
  14780. this.elPanelQETemplate = jindo.$$.getSingle("DIV.se2_layer_t_style", this.elQELayer);
  14781. this.elBtnQETemplate = jindo.$$.getSingle("BUTTON.husky_se2m_template_more", this.elQELayer);
  14782. this.elPanelQETemplatePreview = jindo.$$.getSingle("SPAN.se2_t_style1", this.elQELayer);
  14783. this.aElBtn_tableStyle = jindo.$$("BUTTON", this.elPanelQETemplate);
  14784. for(i = 0; i < this.aElBtn_tableStyle.length; i++){
  14785. this.oApp.registerBrowserEvent(this.aElBtn_tableStyle[i], "click", "TABLE_QE_SELECT_TEMPLATE");
  14786. }
  14787. },
  14788. _attachEvents : function(){
  14789. var htBrowser = jindo.$Agent().navigator();
  14790. this.oApp.exec("SE2_ATTACH_HOVER_EVENTS", [this.aElBtn_tableStyle]);
  14791. this._wfnOnMouseDownResizeCover = jindo.$Fn(this._fnOnMouseDownResizeCover, this);
  14792. this._wfnOnMouseMoveResizeCover = jindo.$Fn(this._fnOnMouseMoveResizeCover, this);
  14793. this._wfnOnMouseUpResizeCover = jindo.$Fn(this._fnOnMouseUpResizeCover, this);
  14794. this._wfnOnMouseDownResizeCover.attach(this.elResizeCover, "mousedown");
  14795. if((htBrowser.ie) && (htBrowser.version > 8)){
  14796. this._wfnOnResizeEndTable = jindo.$Fn(this._fnOnResizeEndTable, this).bind();
  14797. }
  14798. // this.oApp.registerBrowserEvent(doc, "click", "EVENT_EDITING_AREA_CLICK");
  14799. this.oApp.registerBrowserEvent(this.elBtnMergeCell, "click", "TE_MERGE_CELLS");
  14800. this.oApp.registerBrowserEvent(this.elBtnSplitColumn, "click", "TE_SPLIT_COLUMN");
  14801. this.oApp.registerBrowserEvent(this.elBtnSplitRow, "click", "TE_SPLIT_ROW");
  14802. // this.oApp.registerBrowserEvent(this.elBtnAddColumnLeft, "click", "TE_INSERT_COLUMN_LEFT");
  14803. this.oApp.registerBrowserEvent(this.elBtnAddColumnRight, "click", "TE_INSERT_COLUMN_RIGHT");
  14804. this.oApp.registerBrowserEvent(this.elBtnAddRowBelow, "click", "TE_INSERT_ROW_BELOW");
  14805. // this.oApp.registerBrowserEvent(this.elBtnAddRowAbove, "click", "TE_INSERT_ROW_ABOVE");
  14806. this.oApp.registerBrowserEvent(this.elBtnDeleteColumn, "click", "TE_DELETE_COLUMN");
  14807. this.oApp.registerBrowserEvent(this.elBtnDeleteRow, "click", "TE_DELETE_ROW");
  14808. this.oApp.registerBrowserEvent(this.elInputRadioBGColor, "click", "DRAW_QE_RADIO_OPTION", [2]);
  14809. this.oApp.registerBrowserEvent(this.elInputRadioBGImg, "click", "DRAW_QE_RADIO_OPTION", [3]);
  14810. this.oApp.registerBrowserEvent(this.elInputRadioTemplate, "click", "DRAW_QE_RADIO_OPTION", [4]);
  14811. this.oApp.registerBrowserEvent(this.elBtnBGPalette, "click", "TABLE_QE_TOGGLE_BGC_PALETTE");
  14812. // this.oApp.registerBrowserEvent(this.elPanelReviewBtnArea, "click", "SAVE_QE_MY_REVIEW_ITEM"); //My리뷰 버튼 레이어
  14813. this.oApp.registerBrowserEvent(this.elBtnBGIMGPalette, "click", "TABLE_QE_TOGGLE_IMG_PALETTE");
  14814. this.oApp.registerBrowserEvent(this.elPanelBGIMGPaletteHolder, "click", "TABLE_QE_SET_IMG_FROM_PALETTE");
  14815. //this.elPanelQETemplate
  14816. //this.elBtnQETemplate
  14817. this.oApp.registerBrowserEvent(this.elBtnQETemplate, "click", "TABLE_QE_TOGGLE_TEMPLATE");
  14818. this.oApp.registerBrowserEvent(document.body, "mouseup", "EVENT_OUTER_DOC_MOUSEUP");
  14819. this.oApp.registerBrowserEvent(document.body, "mousemove", "EVENT_OUTER_DOC_MOUSEMOVE");
  14820. },
  14821. $LOCAL_BEFORE_FIRST : function(sMsg){
  14822. if(sMsg.indexOf("REGISTER_CONVERTERS") > -1){
  14823. this.oApp.acceptLocalBeforeFirstAgain(this, true);
  14824. return true;
  14825. }
  14826. this.htResizing = {};
  14827. this.nDraggableCellEdge = 2;
  14828. var elBody = jindo.$Element(document.body);
  14829. this.nPageLeftRightMargin = parseInt(elBody.css("marginLeft"), 10) + parseInt(elBody.css("marginRight"), 10);
  14830. this.nPageTopBottomMargin = parseInt(elBody.css("marginTop"), 10) + parseInt(elBody.css("marginBottom"), 10);
  14831. //this.nPageLeftRightMargin = parseInt(elBody.css("marginLeft"), 10)+parseInt(elBody.css("marginRight"), 10) + parseInt(elBody.css("paddingLeft"), 10)+parseInt(elBody.css("paddingRight"), 10);
  14832. //this.nPageTopBottomMargin = parseInt(elBody.css("marginTop"), 10)+parseInt(elBody.css("marginBottom"), 10) + parseInt(elBody.css("paddingTop"), 10)+parseInt(elBody.css("paddingBottom"), 10);
  14833. this.QE_DIM_MERGE_BTN = 1;
  14834. this.QE_DIM_BG_COLOR = 2;
  14835. this.QE_DIM_REVIEW_BG_IMG = 3;
  14836. this.QE_DIM_TABLE_TEMPLATE = 4;
  14837. this.rxLastDigits = RegExp("([0-9]+)$");
  14838. this._assignHTMLObjects();
  14839. this.addCSSClass(this.CELL_SELECTION_CLASS, "background-color:#B4C9E9;");
  14840. this._createCellResizeGrip();
  14841. this.elIFrame = this.oApp.getWYSIWYGWindow().frameElement;
  14842. //[SMARTEDITORSUS-1625] iframe의 offset을 수행하면 iOS에서 처음 탭시 포커싱이 안되는데 정확한 이유를 모르겠음
  14843. //일단 사용안하기 때문에 코멘트처리해서 회피함
  14844. //TODO: 다른 부분에서 동일한 이슈가 발생할 경우 디버깅이 어렵기 때문에 정확한 원인파악이 필요함
  14845. //this.htFrameOffset = jindo.$Element(this.elIFrame).offset();
  14846. this.sEmptyTDSrc = "";
  14847. if(this.oApp.oNavigator.firefox){
  14848. this.sEmptyTDSrc = "<p><br/></p>";
  14849. }else{
  14850. this.sEmptyTDSrc = "<p>&nbsp;</p>";
  14851. }
  14852. this._changeTableEditorStatus(this.STATUS.S_0);
  14853. this._attachEvents();
  14854. // [SMARTEDITORSUS-1672]
  14855. this._rxCellNames = new RegExp("^(" + this._aCellName.join("|") + ")$", "i");
  14856. // --[SMARTEDITORSUS-1672]
  14857. },
  14858. $ON_EVENT_EDITING_AREA_KEYUP : function(oEvent){
  14859. // for undo/redo and other hotkey functions
  14860. var oKeyInfo = oEvent.key();
  14861. // 229: Korean/Eng, 33, 34: page up/down, 35,36: end/home, 37,38,39,40: left, up, right, down, 16: shift
  14862. if(oKeyInfo.keyCode == 229 || oKeyInfo.alt || oKeyInfo.ctrl || oKeyInfo.keyCode == 16){
  14863. return;
  14864. }else if(oKeyInfo.keyCode == 8 || oKeyInfo.keyCode == 46){
  14865. this.oApp.exec("DELETE_BLOCK_CONTENTS");
  14866. oEvent.stop();
  14867. }
  14868. switch(this.nStatus){
  14869. case this.STATUS.CELL_SELECTED:
  14870. this._changeTableEditorStatus(this.STATUS.S_0);
  14871. break;
  14872. }
  14873. },
  14874. $ON_TABLE_QE_SELECT_TEMPLATE : function(weEvent){
  14875. var aMatch = this.rxLastDigits.exec(weEvent.element.className);
  14876. var elCurrentTable = this.elSelectionStartTable;
  14877. this._changeTableEditorStatus(this.STATUS.S_0);
  14878. this.oApp.exec("STYLE_TABLE", [elCurrentTable, aMatch[1]]);
  14879. //this._selectTableStyle(aMatch[1]);
  14880. var elSaveTarget = !!elCurrentTable && elCurrentTable.parentNode ? elCurrentTable.parentNode : null;
  14881. var sSaveTarget = !elCurrentTable ? "BODY" : null;
  14882. this.oApp.exec("RECORD_UNDO_ACTION", ["CHANGE_TABLE_STYLE", {elSaveTarget:elSaveTarget, sSaveTarget : sSaveTarget, bDontSaveSelection:true}]);
  14883. },
  14884. $BEFORE_CHANGE_EDITING_MODE : function(sMode, bNoFocus){
  14885. if(sMode !== "WYSIWYG" && this.nStatus !== this.STATUS.S_0){
  14886. this._changeTableEditorStatus(this.STATUS.S_0);
  14887. }
  14888. },
  14889. // [Undo/Redo] Table Selection 처리와 관련된 부분 주석 처리
  14890. // $AFTER_DO_RECORD_UNDO_HISTORY : function(){
  14891. // if(this.nStatus != this.STATUS.CELL_SELECTED){
  14892. // return;
  14893. // }
  14894. //
  14895. // if(this.aSelectedCells.length < 1){
  14896. // return;
  14897. // }
  14898. //
  14899. // var aTables = this.oApp.getWYSIWYGDocument().getElementsByTagName("TABLE");
  14900. // for(var nTableIdx = 0, nLen = aTables.length; nTableIdx < nLen; nTableIdx++){
  14901. // if(aTables[nTableIdx] === this.elSelectionStartTable){
  14902. // break;
  14903. // }
  14904. // }
  14905. //
  14906. // var aUndoHistory = this.oApp.getUndoHistory();
  14907. // var oUndoStateIdx = this.oApp.getUndoStateIdx();
  14908. // if(!aUndoHistory[oUndoStateIdx.nIdx].htTableSelection){
  14909. // aUndoHistory[oUndoStateIdx.nIdx].htTableSelection = [];
  14910. // }
  14911. // aUndoHistory[oUndoStateIdx.nIdx].htTableSelection[oUndoStateIdx.nStep] = {
  14912. // nTableIdx : nTableIdx,
  14913. // nSX : this.htSelectionSPos.x,
  14914. // nSY : this.htSelectionSPos.y,
  14915. // nEX : this.htSelectionEPos.x,
  14916. // nEY : this.htSelectionEPos.y
  14917. // };
  14918. // },
  14919. //
  14920. // $BEFORE_RESTORE_UNDO_HISTORY : function(){
  14921. // if(this.nStatus == this.STATUS.CELL_SELECTED){
  14922. // var oSelection = this.oApp.getEmptySelection();
  14923. // oSelection.selectNode(this.elSelectionStartTable);
  14924. // oSelection.collapseToEnd();
  14925. // oSelection.select();
  14926. // }
  14927. // },
  14928. //
  14929. // $AFTER_RESTORE_UNDO_HISTORY : function(){
  14930. // var aUndoHistory = this.oApp.getUndoHistory();
  14931. // var oUndoStateIdx = this.oApp.getUndoStateIdx();
  14932. //
  14933. // if(aUndoHistory[oUndoStateIdx.nIdx].htTableSelection && aUndoHistory[oUndoStateIdx.nIdx].htTableSelection[oUndoStateIdx.nStep]){
  14934. // var htTableSelection = aUndoHistory[oUndoStateIdx.nIdx].htTableSelection[oUndoStateIdx.nStep];
  14935. // this.elSelectionStartTable = this.oApp.getWYSIWYGDocument().getElementsByTagName("TABLE")[htTableSelection.nTableIdx];
  14936. // this.htMap = this._getCellMapping(this.elSelectionStartTable);
  14937. //
  14938. // this.htSelectionSPos.x = htTableSelection.nSX;
  14939. // this.htSelectionSPos.y = htTableSelection.nSY;
  14940. // this.htSelectionEPos.x = htTableSelection.nEX;
  14941. // this.htSelectionEPos.y = htTableSelection.nEY;
  14942. // this._selectCells(this.htSelectionSPos, this.htSelectionEPos);
  14943. //
  14944. // this._startCellSelection();
  14945. // this._changeTableEditorStatus(this.STATUS.CELL_SELECTED);
  14946. // }else{
  14947. // this._changeTableEditorStatus(this.STATUS.S_0);
  14948. // }
  14949. // },
  14950. /**
  14951. * 테이블 배경색 셋팅
  14952. */
  14953. $ON_TABLE_QE_TOGGLE_BGC_PALETTE : function(){
  14954. if(this.elPanelBGPaletteHolder.parentNode.style.display == "block"){
  14955. this.oApp.exec("HIDE_TABLE_QE_BGC_PALETTE", []);
  14956. }else{
  14957. this.oApp.exec("SHOW_TABLE_QE_BGC_PALETTE", []);
  14958. }
  14959. },
  14960. $ON_SHOW_TABLE_QE_BGC_PALETTE : function(){
  14961. this.elPanelBGPaletteHolder.parentNode.style.display = "block";
  14962. this.oApp.exec("SHOW_COLOR_PALETTE", ["TABLE_QE_SET_BGC_FROM_PALETTE", this.elPanelBGPaletteHolder]);
  14963. },
  14964. $ON_HIDE_TABLE_QE_BGC_PALETTE : function(){
  14965. this.elPanelBGPaletteHolder.parentNode.style.display = "none";
  14966. this.oApp.exec("HIDE_COLOR_PALETTE", []);
  14967. },
  14968. $ON_TABLE_QE_SET_BGC_FROM_PALETTE : function(sColorCode){
  14969. this.oApp.exec("TABLE_QE_SET_BGC", [sColorCode]);
  14970. if(this.oSelection){
  14971. this.oSelection.select();
  14972. }
  14973. this._changeTableEditorStatus(this.STATUS.S_0);
  14974. },
  14975. $ON_TABLE_QE_SET_BGC : function(sColorCode){
  14976. this.elBtnBGPalette.style.backgroundColor = sColorCode;
  14977. for(var i = 0, nLen = this.aSelectedCells.length; i < nLen; i++){
  14978. this.aSelectedCells[i].setAttribute(this.TMP_BGC_ATTR, sColorCode);
  14979. this.aSelectedCells[i].removeAttribute(this.TMP_BGIMG_ATTR);
  14980. }
  14981. this.sQEAction = "TABLE_SET_BGCOLOR";
  14982. },
  14983. /**
  14984. * 테이블 리뷰 테이블 배경 이미지 셋팅
  14985. */
  14986. $ON_TABLE_QE_TOGGLE_IMG_PALETTE : function(){
  14987. if(this.elPanelBGIMGPaletteHolder.parentNode.style.display == "block"){
  14988. this.oApp.exec("HIDE_TABLE_QE_IMG_PALETTE", []);
  14989. }else{
  14990. this.oApp.exec("SHOW_TABLE_QE_IMG_PALETTE", []);
  14991. }
  14992. },
  14993. $ON_SHOW_TABLE_QE_IMG_PALETTE : function(){
  14994. this.elPanelBGIMGPaletteHolder.parentNode.style.display = "block";
  14995. },
  14996. $ON_HIDE_TABLE_QE_IMG_PALETTE : function(){
  14997. this.elPanelBGIMGPaletteHolder.parentNode.style.display = "none";
  14998. },
  14999. $ON_TABLE_QE_SET_IMG_FROM_PALETTE : function(elEvt){
  15000. this.oApp.exec("TABLE_QE_SET_IMG", [elEvt.element]);
  15001. if(this.oSelection){
  15002. this.oSelection.select();
  15003. }
  15004. this._changeTableEditorStatus(this.STATUS.S_0);
  15005. },
  15006. $ON_TABLE_QE_SET_IMG : function(elSelected){
  15007. var sClassName = jindo.$Element(elSelected).className();
  15008. var welBtnBGIMGPalette = jindo.$Element(this.elBtnBGIMGPalette);
  15009. var aBtnClassNames = welBtnBGIMGPalette.className().split(" ");
  15010. for(var i = 0, nLen = aBtnClassNames.length; i < nLen; i++){
  15011. if(aBtnClassNames[i].indexOf("cellimg") > 0){
  15012. welBtnBGIMGPalette.removeClass(aBtnClassNames[i]);
  15013. }
  15014. }
  15015. jindo.$Element(this.elBtnBGIMGPalette).addClass(sClassName);
  15016. var n = sClassName.substring(11, sClassName.length); //se2_cellimg11
  15017. var sImageName = "pattern_";
  15018. if(n === "0"){
  15019. for(var i = 0, nLen = this.aSelectedCells.length; i < nLen; i++){
  15020. jindo.$Element(this.aSelectedCells[i]).css("backgroundImage", "");
  15021. this.aSelectedCells[i].removeAttribute(this.TMP_BGC_ATTR);
  15022. this.aSelectedCells[i].removeAttribute(this.TMP_BGIMG_ATTR);
  15023. }
  15024. }else{
  15025. if(n == 19 || n == 20 || n == 21 || n == 22 || n == 25 || n == 26){ //파일 사이즈때문에 jpg
  15026. sImageName = sImageName + n + ".jpg";
  15027. }else{
  15028. sImageName = sImageName + n + ".gif";
  15029. }
  15030. for(var j = 0, nLen = this.aSelectedCells.length; j < nLen ; j++){
  15031. jindo.$Element(this.aSelectedCells[j]).css("backgroundImage", "url("+"http://static.se2.naver.com/static/img/"+sImageName+")");
  15032. this.aSelectedCells[j].removeAttribute(this.TMP_BGC_ATTR);
  15033. this.aSelectedCells[j].setAttribute(this.TMP_BGIMG_ATTR, "url("+"http://static.se2.naver.com/static/img/"+sImageName+")");
  15034. }
  15035. }
  15036. this.sQEAction = "TABLE_SET_BGIMAGE";
  15037. },
  15038. $ON_SAVE_QE_MY_REVIEW_ITEM : function(){
  15039. this.oApp.exec("SAVE_MY_REVIEW_ITEM");
  15040. this.oApp.exec("CLOSE_QE_LAYER");
  15041. },
  15042. /**
  15043. * 테이블 에디터 Show
  15044. */
  15045. $ON_SHOW_COMMON_QE : function(){
  15046. if(jindo.$Element(this.elSelectionStartTable).hasClass(this._sSETblClass)){
  15047. this.oApp.exec("SHOW_TABLE_QE");
  15048. }else{
  15049. if(jindo.$Element(this.elSelectionStartTable).hasClass(this._sSEReviewTblClass)){
  15050. this.oApp.exec("SHOW_REVIEW_QE");
  15051. }
  15052. }
  15053. },
  15054. $ON_SHOW_TABLE_QE : function(){
  15055. this.oApp.exec("HIDE_TABLE_QE_BGC_PALETTE", []);
  15056. this.oApp.exec("TABLE_QE_HIDE_TEMPLATE", []);
  15057. this.oApp.exec("SETUP_TABLE_QE_MODE", [0]);
  15058. this.oApp.exec("OPEN_QE_LAYER", [this.htMap[this.htSelectionEPos.x][this.htSelectionEPos.y], this.elQELayer, "table"]);
  15059. //this.oApp.exec("FOCUS");
  15060. },
  15061. $ON_SHOW_REVIEW_QE : function(){
  15062. this.oApp.exec("SETUP_TABLE_QE_MODE", [1]);
  15063. this.oApp.exec("OPEN_QE_LAYER", [this.htMap[this.htSelectionEPos.x][this.htSelectionEPos.y], this.elQELayer, "review"]);
  15064. },
  15065. $ON_CLOSE_SUB_LAYER_QE : function(){
  15066. if(typeof this.elPanelBGPaletteHolder != 'undefined'){
  15067. this.elPanelBGPaletteHolder.parentNode.style.display = "none";
  15068. }
  15069. if(typeof this.elPanelBGIMGPaletteHolder != 'undefined'){
  15070. this.elPanelBGIMGPaletteHolder.parentNode.style.display = "none";
  15071. }
  15072. },
  15073. // 0: table
  15074. // 1: review
  15075. $ON_SETUP_TABLE_QE_MODE : function(nMode){
  15076. var bEnableMerge = true;
  15077. if(typeof nMode == "number"){
  15078. this.nQEMode = nMode;
  15079. }
  15080. if(this.aSelectedCells.length < 2){
  15081. bEnableMerge = false;
  15082. }
  15083. this.oApp.exec("TABLE_QE_DIM", [this.QE_DIM_MERGE_BTN, bEnableMerge]);
  15084. //null인경우를 대비해서 default값을 지정해준다.
  15085. var sBackgroundColor = this.aSelectedCells[0].getAttribute(this.TMP_BGC_ATTR) || "rgb(255,255,255)";
  15086. var bAllMatched = true;
  15087. for(var i = 1, nLen = this.aSelectedCells.length; i < nLen; i++){
  15088. // [SMARTEDITORSUS-1552] 드래그로 셀을 선택하는 중 elCell이 없는 경우 오류 발생
  15089. if(this.aSelectedCells[i]){
  15090. if(sBackgroundColor != this.aSelectedCells[i].getAttribute(this.TMP_BGC_ATTR)){
  15091. bAllMatched = false;
  15092. break;
  15093. }
  15094. }
  15095. // --[SMARTEDITORSUS-1552]
  15096. }
  15097. if(bAllMatched){
  15098. this.elBtnBGPalette.style.backgroundColor = sBackgroundColor;
  15099. }else{
  15100. this.elBtnBGPalette.style.backgroundColor = "#FFFFFF";
  15101. }
  15102. var sBackgroundImage = this.aSelectedCells[0].getAttribute(this.TMP_BGIMG_ATTR) || "";
  15103. var bAllMatchedImage = true;
  15104. var sPatternInfo, nPatternImage = 0;
  15105. var welBtnBGIMGPalette = jindo.$Element(this.elBtnBGIMGPalette);
  15106. if(!!sBackgroundImage){
  15107. var aPattern = sBackgroundImage.match(/\_[0-9]*/);
  15108. sPatternInfo = (!!aPattern)?aPattern[0] : "_0";
  15109. nPatternImage = sPatternInfo.substring(1, sPatternInfo.length);
  15110. for(var i = 1, nLen = this.aSelectedCells.length; i < nLen; i++){
  15111. if(sBackgroundImage != this.aSelectedCells[i].getAttribute(this.TMP_BGIMG_ATTR)){
  15112. bAllMatchedImage = false;
  15113. break;
  15114. }
  15115. }
  15116. }
  15117. var aBtnClassNames = welBtnBGIMGPalette.className().split(/\s/);
  15118. for(var j = 0, nLen = aBtnClassNames.length; j < nLen; j++){
  15119. if(aBtnClassNames[j].indexOf("cellimg") > 0){
  15120. welBtnBGIMGPalette.removeClass(aBtnClassNames[j]);
  15121. }
  15122. }
  15123. if(bAllMatchedImage && nPatternImage > 0){
  15124. welBtnBGIMGPalette.addClass("se2_cellimg" + nPatternImage);
  15125. }else{
  15126. welBtnBGIMGPalette.addClass("se2_cellimg0");
  15127. }
  15128. if(this.nQEMode === 0){ //table
  15129. this.elPanelTableTemplateArea.style.display = "block";
  15130. // this.elSelectBoxTemplate.style.display = "block";
  15131. this.elPanelReviewBGArea.style.display = "none";
  15132. // this.elSelectBoxTemplate.style.position = "";
  15133. //this.elPanelReviewBtnArea.style.display = "none"; //My리뷰 버튼 레이어
  15134. // 배경Area에서 css를 제거해야함
  15135. jindo.$Element(this.elPanelTableBGArea).className("se2_qe2");
  15136. var nTpl = this.parseIntOr0(this.elSelectionStartTable.getAttribute(this.ATTR_TBL_TEMPLATE));
  15137. if(nTpl){
  15138. //this.elInputRadioTemplate.checked = "true";
  15139. }else{
  15140. this.elInputRadioBGColor.checked = "true";
  15141. nTpl = 1;
  15142. }
  15143. this.elPanelQETemplatePreview.className = "se2_t_style" + nTpl;
  15144. this.elPanelBGImg.style.position = "";
  15145. }else if(this.nQEMode == 1){ //review
  15146. this.elPanelTableTemplateArea.style.display = "none";
  15147. // this.elSelectBoxTemplate.style.display = "none";
  15148. this.elPanelReviewBGArea.style.display = "block";
  15149. // this.elSelectBoxTemplate.style.position = "static";
  15150. // this.elPanelReviewBtnArea.style.display = "block"; //My리뷰 버튼 레이어
  15151. var nTpl = this.parseIntOr0(this.elSelectionStartTable.getAttribute(this.ATTR_REVIEW_TEMPLATE));
  15152. this.elPanelBGImg.style.position = "relative";
  15153. }else{
  15154. this.elPanelTableTemplateArea.style.display = "none";
  15155. this.elPanelReviewBGArea.style.display = "none";
  15156. // this.elPanelReviewBtnArea.style.display = "none"; //My리뷰 버튼 레이어
  15157. }
  15158. this.oApp.exec("DRAW_QE_RADIO_OPTION", [0]);
  15159. },
  15160. // nClickedIdx
  15161. // 0: none
  15162. // 2: bg color
  15163. // 3: bg img
  15164. // 4: template
  15165. $ON_DRAW_QE_RADIO_OPTION : function(nClickedIdx){
  15166. if(nClickedIdx !== 0 && nClickedIdx != 2){
  15167. this.oApp.exec("HIDE_TABLE_QE_BGC_PALETTE", []);
  15168. }
  15169. if(nClickedIdx !== 0 && nClickedIdx != 3){
  15170. this.oApp.exec("HIDE_TABLE_QE_IMG_PALETTE", []);
  15171. }
  15172. if(nClickedIdx !== 0 && nClickedIdx != 4){
  15173. this.oApp.exec("TABLE_QE_HIDE_TEMPLATE", []);
  15174. }
  15175. if(this.nQEMode === 0){
  15176. // bg image option does not exist in table mode. so select the bgcolor option
  15177. if(this.elInputRadioBGImg.checked){
  15178. this.elInputRadioBGColor.checked = "true";
  15179. }
  15180. if(this.elInputRadioBGColor.checked){
  15181. // one dimming layer is being shared so only need to dim once and the rest will be undimmed automatically
  15182. //this.oApp.exec("TABLE_QE_DIM", [this.QE_DIM_BG_COLOR, true]);
  15183. this.oApp.exec("TABLE_QE_DIM", [this.QE_DIM_TABLE_TEMPLATE, false]);
  15184. }else{
  15185. this.oApp.exec("TABLE_QE_DIM", [this.QE_DIM_BG_COLOR, false]);
  15186. //this.oApp.exec("TABLE_QE_DIM", [this.QE_DIM_TABLE_TEMPLATE, true]);
  15187. }
  15188. }else{
  15189. // template option does not exist in review mode. so select the bgcolor optio
  15190. if(this.elInputRadioTemplate.checked){
  15191. this.elInputRadioBGColor.checked = "true";
  15192. }
  15193. if(this.elInputRadioBGColor.checked){
  15194. //this.oApp.exec("TABLE_QE_DIM", [this.QE_DIM_BG_COLOR, true]);
  15195. this.oApp.exec("TABLE_QE_DIM", [this.QE_DIM_REVIEW_BG_IMG, false]);
  15196. }else{
  15197. this.oApp.exec("TABLE_QE_DIM", [this.QE_DIM_BG_COLOR, false]);
  15198. //this.oApp.exec("TABLE_QE_DIM", [this.QE_DIM_REVIEW_BG_IMG, true]);
  15199. }
  15200. }
  15201. },
  15202. // nPart
  15203. // 1: Merge cell btn
  15204. // 2: Cell bg color
  15205. // 3: Review - bg image
  15206. // 4: Table - Template
  15207. //
  15208. // bUndim
  15209. // true: Undim
  15210. // false(default): Dim
  15211. $ON_TABLE_QE_DIM : function(nPart, bUndim){
  15212. var elPanelDim;
  15213. var sDimClassPrefix = "se2_qdim";
  15214. if(nPart == 1){
  15215. elPanelDim = this.elPanelDim1;
  15216. }else{
  15217. elPanelDim = this.elPanelDim2;
  15218. }
  15219. if(bUndim){
  15220. nPart = 0;
  15221. }
  15222. elPanelDim.className = sDimClassPrefix + nPart;
  15223. },
  15224. $ON_TE_SELECT_TABLE : function(elTable){
  15225. this.elSelectionStartTable = elTable;
  15226. this.htMap = this._getCellMapping(this.elSelectionStartTable);
  15227. },
  15228. $ON_TE_SELECT_CELLS : function(htSPos, htEPos){
  15229. this._selectCells(htSPos, htEPos);
  15230. },
  15231. $ON_TE_MERGE_CELLS : function(){
  15232. if(this.aSelectedCells.length === 0 || this.aSelectedCells.length == 1){
  15233. return;
  15234. }
  15235. this._removeClassFromSelection();
  15236. var i, elFirstTD, elTD;
  15237. elFirstTD = this.aSelectedCells[0];
  15238. var elTable = nhn.husky.SE2M_Utils.findAncestorByTagName("TABLE", elFirstTD);
  15239. var nHeight, nWidth;
  15240. var elCurTD, elLastTD = this.aSelectedCells[0];
  15241. nHeight = parseInt(elLastTD.style.height || elLastTD.getAttribute("height"), 10);
  15242. nWidth = parseInt(elLastTD.style.width || elLastTD.getAttribute("width"), 10);
  15243. //nHeight = elLastTD.offsetHeight;
  15244. //nWidth = elLastTD.offsetWidth;
  15245. for(i = this.htSelectionSPos.x + 1; i < this.htSelectionEPos.x + 1; i++){
  15246. curTD = this.htMap[i][this.htSelectionSPos.y];
  15247. if(curTD == elLastTD){
  15248. continue;
  15249. }
  15250. elLastTD = curTD;
  15251. nWidth += parseInt(curTD.style.width || curTD.getAttribute("width"), 10);
  15252. //nWidth += curTD.offsetWidth;
  15253. }
  15254. elLastTD = this.aSelectedCells[0];
  15255. for(i = this.htSelectionSPos.y + 1; i < this.htSelectionEPos.y + 1; i++){
  15256. curTD = this.htMap[this.htSelectionSPos.x][i];
  15257. if(curTD == elLastTD){
  15258. continue;
  15259. }
  15260. elLastTD = curTD;
  15261. nHeight += parseInt(curTD.style.height || curTD.getAttribute("height"), 10);
  15262. //nHeight += curTD.offsetHeight;
  15263. }
  15264. if(nWidth){
  15265. elFirstTD.style.width = nWidth + "px";
  15266. }
  15267. if(nHeight){
  15268. elFirstTD.style.height = nHeight + "px";
  15269. }
  15270. elFirstTD.setAttribute("colSpan", this.htSelectionEPos.x - this.htSelectionSPos.x + 1);
  15271. elFirstTD.setAttribute("rowSpan", this.htSelectionEPos.y - this.htSelectionSPos.y + 1);
  15272. for(i = 1; i < this.aSelectedCells.length; i++){
  15273. elTD = this.aSelectedCells[i];
  15274. if(elTD.parentNode){
  15275. if(!nhn.husky.SE2M_Utils.isBlankNode(elTD)){
  15276. elFirstTD.innerHTML += elTD.innerHTML;
  15277. }
  15278. // [SMARTEDITORSUS-1533] 병합되는 셀 바로 뒤에 포함된 빈 텍스트 노드도 함께 제거하여 DOM 트리 일관성 유지
  15279. var htBrowser = jindo.$Agent().navigator();
  15280. if(htBrowser.ie && (htBrowser.nativeVersion == 9 || htBrowser.nativeVersion == 10) && (htBrowser.version == 9 || htBrowser.version == 10)){
  15281. this._removeEmptyTextNode_IE(elTD);
  15282. }
  15283. // --[SMARTEDITORSUS-1533]
  15284. elTD.parentNode.removeChild(elTD);
  15285. }
  15286. }
  15287. // this._updateSelection();
  15288. this.htMap = this._getCellMapping(this.elSelectionStartTable);
  15289. this._selectCells(this.htSelectionSPos, this.htSelectionEPos);
  15290. this._showTableTemplate(this.elSelectionStartTable);
  15291. this._addClassToSelection();
  15292. this.sQEAction = "TABLE_CELL_MERGE";
  15293. this.oApp.exec("SHOW_COMMON_QE");
  15294. },
  15295. $ON_TABLE_QE_TOGGLE_TEMPLATE : function(){
  15296. if(this.elPanelQETemplate.style.display == "block"){
  15297. this.oApp.exec("TABLE_QE_HIDE_TEMPLATE");
  15298. }else{
  15299. this.oApp.exec("TABLE_QE_SHOW_TEMPLATE");
  15300. }
  15301. },
  15302. $ON_TABLE_QE_SHOW_TEMPLATE : function(){
  15303. this.elPanelQETemplate.style.display = "block";
  15304. this.oApp.exec("POSITION_TOOLBAR_LAYER", [this.elPanelQETemplate]);
  15305. },
  15306. $ON_TABLE_QE_HIDE_TEMPLATE : function(){
  15307. this.elPanelQETemplate.style.display = "none";
  15308. },
  15309. $ON_STYLE_TABLE : function(elTable, nTableStyleIdx){
  15310. if(!elTable){
  15311. if(!this._t){
  15312. this._t = 1;
  15313. }
  15314. elTable = this.elSelectionStartTable;
  15315. nTableStyleIdx = (this._t++) % 20 + 1;
  15316. }
  15317. if(this.oSelection){
  15318. this.oSelection.select();
  15319. }
  15320. this._applyTableTemplate(elTable, nTableStyleIdx);
  15321. },
  15322. $ON_TE_DELETE_COLUMN : function(){
  15323. // [SMARTEDITORSUS-1784] [SMARTEDITORSUS-555] 처리 후 발생한 사이트이펙트
  15324. if(this.aSelectedCells.length === 0) {
  15325. return;
  15326. }
  15327. /*if(this.aSelectedCells.length === 0 || this.aSelectedCells.length == 1) {
  15328. return;
  15329. }*/
  15330. // --[SMARTEDITORSUS-1784]
  15331. this._selectAll_Column();
  15332. this._deleteSelectedCells();
  15333. this.sQEAction = "DELETE_TABLE_COLUMN";
  15334. this._changeTableEditorStatus(this.STATUS.S_0);
  15335. },
  15336. $ON_TE_DELETE_ROW : function(){
  15337. // [SMARTEDITORSUS-1784] [SMARTEDITORSUS-555] 처리 후 발생한 사이트이펙트
  15338. if(this.aSelectedCells.length === 0) {
  15339. return;
  15340. }
  15341. /*if(this.aSelectedCells.length === 0 || this.aSelectedCells.length == 1) {
  15342. return;
  15343. }*/
  15344. // --[SMARTEDITORSUS-1784]
  15345. this._selectAll_Row();
  15346. this._deleteSelectedCells();
  15347. this.sQEAction = "DELETE_TABLE_ROW";
  15348. this._changeTableEditorStatus(this.STATUS.S_0);
  15349. },
  15350. $ON_TE_INSERT_COLUMN_RIGHT : function(){
  15351. if(this.aSelectedCells.length === 0) {
  15352. return;
  15353. }
  15354. this._selectAll_Column();
  15355. this._insertColumnAfter(this.htSelectionEPos.x);
  15356. },
  15357. $ON_TE_INSERT_COLUMN_LEFT : function(){
  15358. this._selectAll_Column();
  15359. this._insertColumnAfter(this.htSelectionSPos.x - 1);
  15360. },
  15361. $ON_TE_INSERT_ROW_BELOW : function(){
  15362. if(this.aSelectedCells.length === 0) {
  15363. return;
  15364. }
  15365. this._insertRowBelow(this.htSelectionEPos.y);
  15366. },
  15367. $ON_TE_INSERT_ROW_ABOVE : function(){
  15368. this._insertRowBelow(this.htSelectionSPos.y - 1);
  15369. },
  15370. $ON_TE_SPLIT_COLUMN : function(){
  15371. var nSpan, nNewSpan, nWidth, nNewWidth;
  15372. var elCurCell, elNewTD;
  15373. if(this.aSelectedCells.length === 0) {
  15374. return;
  15375. }
  15376. this._removeClassFromSelection();
  15377. var elLastCell = this.aSelectedCells[0];
  15378. // Assign colSpan>1 to all selected cells.
  15379. // If current colSpan == 1 then increase the colSpan of the cell and all the vertically adjacent cells.
  15380. for(var i = 0, nLen = this.aSelectedCells.length; i < nLen; i++){
  15381. elCurCell = this.aSelectedCells[i];
  15382. nSpan = parseInt(elCurCell.getAttribute("colSpan"), 10) || 1;
  15383. if(nSpan > 1){
  15384. continue;
  15385. }
  15386. var htPos = this._getBasisCellPosition(elCurCell);
  15387. for(var y = 0; y < this.htMap[0].length;){
  15388. elCurCell = this.htMap[htPos.x][y];
  15389. nSpan = parseInt(elCurCell.getAttribute("colSpan"), 10) || 1;
  15390. elCurCell.setAttribute("colSpan", nSpan+1);
  15391. y += parseInt(elCurCell.getAttribute("rowSpan"), 10) || 1;
  15392. }
  15393. }
  15394. for(var i = 0, nLen = this.aSelectedCells.length; i < nLen; i++){
  15395. elCurCell = this.aSelectedCells[i];
  15396. nSpan = parseInt(elCurCell.getAttribute("colSpan"), 10) || 1;
  15397. nNewSpan = (nSpan/2).toFixed(0);
  15398. elCurCell.setAttribute("colSpan", nNewSpan);
  15399. elNewTD = this._shallowCloneTD(elCurCell);
  15400. elNewTD.setAttribute("colSpan", nSpan-nNewSpan);
  15401. elLastCell = elNewTD;
  15402. nSpan = parseInt(elCurCell.getAttribute("rowSpan"), 10) || 1;
  15403. elNewTD.setAttribute("rowSpan", nSpan);
  15404. elNewTD.innerHTML = "&nbsp;";
  15405. nWidth = elCurCell.width || elCurCell.style.width;
  15406. if(nWidth){
  15407. nWidth = this.parseIntOr0(nWidth);
  15408. elCurCell.removeAttribute("width");
  15409. nNewWidth = (nWidth/2).toFixed();
  15410. elCurCell.style.width = nNewWidth + "px";
  15411. elNewTD.style.width = (nWidth - nNewWidth) + "px";
  15412. }
  15413. elCurCell.parentNode.insertBefore(elNewTD, elCurCell.nextSibling);
  15414. // [SMARTEDITORSUS-1745][SMARTEDITORSUS-1842] 배경색이 바로 반영되지 않는 버그로 인해 명시
  15415. // [SMARTEDITORSUS-2155] Win10 Spartan
  15416. var htBrowser = jindo.$Agent().navigator();
  15417. if((htBrowser.edge && (Math.floor(htBrowser.version) === 12)) || (htBrowser.ie && (htBrowser.nativeVersion >= 9 || htBrowser.nativeVersion <= 11) && (htBrowser.version >= 9 || htBrowser.version <= 11))){
  15418. elNewTD.style.cssText = elCurCell.style.cssText;
  15419. }
  15420. // --[SMARTEDITORSUS-1745][SMARTEDITORSUS-1842][SMARTEDITORSUS-2155]
  15421. }
  15422. this._reassignCellSizes(this.elSelectionStartTable);
  15423. this.htMap = this._getCellMapping(this.elSelectionStartTable);
  15424. var htPos = this._getBasisCellPosition(elLastCell);
  15425. this.htSelectionEPos.x = htPos.x;
  15426. this._selectCells(this.htSelectionSPos, this.htSelectionEPos);
  15427. this.sQEAction = "SPLIT_TABLE_COLUMN";
  15428. this.oApp.exec("SHOW_COMMON_QE");
  15429. },
  15430. $ON_TE_SPLIT_ROW : function(){
  15431. var nSpan, nNewSpan, nHeight, nHeight;
  15432. var elCurCell, elNewTD, htPos, elNewTR;
  15433. if(this.aSelectedCells.length === 0) {
  15434. return;
  15435. }
  15436. var aTR = jindo.$$(">TBODY>TR", this.elSelectionStartTable, {oneTimeOffCache:true});
  15437. this._removeClassFromSelection();
  15438. //top.document.title = this.htSelectionSPos.x+","+this.htSelectionSPos.y+"::"+this.htSelectionEPos.x+","+this.htSelectionEPos.y;
  15439. var nNewRows = 0;
  15440. // Assign rowSpan>1 to all selected cells.
  15441. // If current rowSpan == 1 then increase the rowSpan of the cell and all the horizontally adjacent cells.
  15442. var elNextTRInsertionPoint;
  15443. for(var i = 0, nLen = this.aSelectedCells.length; i < nLen; i++){
  15444. elCurCell = this.aSelectedCells[i];
  15445. nSpan = parseInt(elCurCell.getAttribute("rowSpan"), 10) || 1;
  15446. if(nSpan > 1){
  15447. continue;
  15448. }
  15449. htPos = this._getBasisCellPosition(elCurCell);
  15450. elNextTRInsertionPoint = aTR[htPos.y];
  15451. // a new TR has to be inserted when there's an increase in rowSpan
  15452. elNewTR = this.oApp.getWYSIWYGDocument().createElement("TR");
  15453. elNextTRInsertionPoint.parentNode.insertBefore(elNewTR, elNextTRInsertionPoint.nextSibling);
  15454. nNewRows++;
  15455. // loop through horizontally adjacent cells and increase their rowSpan
  15456. for(var x = 0; x < this.htMap.length;){
  15457. elCurCell = this.htMap[x][htPos.y];
  15458. nSpan = parseInt(elCurCell.getAttribute("rowSpan"), 10) || 1;
  15459. elCurCell.setAttribute("rowSpan", nSpan + 1);
  15460. x += parseInt(elCurCell.getAttribute("colSpan"), 10) || 1;
  15461. }
  15462. }
  15463. aTR = jindo.$$(">TBODY>TR", this.elSelectionStartTable, {oneTimeOffCache:true});
  15464. var htPos1, htPos2;
  15465. for(var i = 0, nLen = this.aSelectedCells.length; i < nLen; i++){
  15466. elCurCell = this.aSelectedCells[i];
  15467. nSpan = parseInt(elCurCell.getAttribute("rowSpan"), 10) || 1;
  15468. nNewSpan = (nSpan/2).toFixed(0);
  15469. elCurCell.setAttribute("rowSpan", nNewSpan);
  15470. elNewTD = this._shallowCloneTD(elCurCell);
  15471. elNewTD.setAttribute("rowSpan", nSpan - nNewSpan);
  15472. nSpan = parseInt(elCurCell.getAttribute("colSpan"), 10) || 1;
  15473. elNewTD.setAttribute("colSpan", nSpan);
  15474. elNewTD.innerHTML = "&nbsp;";
  15475. nHeight = elCurCell.height || elCurCell.style.height;
  15476. if(nHeight){
  15477. nHeight = this.parseIntOr0(nHeight);
  15478. elCurCell.removeAttribute("height");
  15479. nNewHeight = (nHeight/2).toFixed();
  15480. elCurCell.style.height = nNewHeight + "px";
  15481. elNewTD.style.height = (nHeight - nNewHeight) + "px";
  15482. }
  15483. //var elTRInsertTo = elCurCell.parentNode;
  15484. //for(var ii=0; ii<nNewSpan; ii++) elTRInsertTo = elTRInsertTo.nextSibling;
  15485. var nTRIdx = jindo.$A(aTR).indexOf(elCurCell.parentNode);
  15486. var nNextTRIdx = parseInt(nTRIdx, 10)+parseInt(nNewSpan, 10);
  15487. var elTRInsertTo = aTR[nNextTRIdx];
  15488. var oSiblingTDs = elTRInsertTo.childNodes;
  15489. var elInsertionPt = null;
  15490. var tmp;
  15491. htPos1 = this._getBasisCellPosition(elCurCell);
  15492. for(var ii = 0, nNumTDs = oSiblingTDs.length; ii < nNumTDs; ii++){
  15493. tmp = oSiblingTDs[ii];
  15494. // [SMARTEDITORSUS-1672]
  15495. //if(!tmp.tagName || tmp.tagName != "TD"){
  15496. if(!tmp.tagName || !this._rxCellNames.test(tmp.tagName)){
  15497. // --[SMARTEDITORSUS-1672]
  15498. continue;
  15499. }
  15500. htPos2 = this._getBasisCellPosition(tmp);
  15501. if(htPos1.x < htPos2.x){
  15502. elInsertionPt = tmp;
  15503. break;
  15504. }
  15505. }
  15506. elTRInsertTo.insertBefore(elNewTD, elInsertionPt);
  15507. // [SMARTEDITORSUS-1745][SMARTEDITORSUS-1842] 배경색이 바로 반영되지 않는 버그로 인해 명시
  15508. // [SMARTEDITORSUS-2155] Win10 Spartan
  15509. var htBrowser = jindo.$Agent().navigator();
  15510. if((htBrowser.edge && (Math.floor(htBrowser.version) === 12)) || (htBrowser.ie && (htBrowser.nativeVersion >= 9 || htBrowser.nativeVersion <= 11) && (htBrowser.version >= 9 || htBrowser.version <= 11))){
  15511. elNewTD.style.cssText = elNewTD.style.cssText;
  15512. }
  15513. // --[SMARTEDITORSUS-1745][SMARTEDITORSUS-1842][SMARTEDITORSUS-2155]
  15514. }
  15515. this._reassignCellSizes(this.elSelectionStartTable);
  15516. this.htMap = this._getCellMapping(this.elSelectionStartTable);
  15517. this.htSelectionEPos.y += nNewRows;
  15518. this._selectCells(this.htSelectionSPos, this.htSelectionEPos);
  15519. this.sQEAction = "SPLIT_TABLE_ROW";
  15520. this.oApp.exec("SHOW_COMMON_QE");
  15521. },
  15522. $ON_MSG_CELL_SELECTED : function(){
  15523. // disable row/col delete btn
  15524. this.elPanelDimDelCol.className = "se2_qdim6r";
  15525. this.elPanelDimDelRow.className = "se2_qdim6c";
  15526. if(this.htSelectionSPos.x === 0 && this.htSelectionEPos.x === this.htMap.length - 1){
  15527. this.oApp.exec("MSG_ROW_SELECTED");
  15528. }
  15529. if(this.htSelectionSPos.y === 0 && this.htSelectionEPos.y === this.htMap[0].length - 1){
  15530. this.oApp.exec("MSG_COL_SELECTED");
  15531. }
  15532. this.oApp.exec("SHOW_COMMON_QE");
  15533. },
  15534. $ON_MSG_ROW_SELECTED : function(){
  15535. this.elPanelDimDelRow.className = "";
  15536. },
  15537. $ON_MSG_COL_SELECTED : function(){
  15538. this.elPanelDimDelCol.className = "";
  15539. },
  15540. $ON_EVENT_EDITING_AREA_MOUSEDOWN : function(wevE){
  15541. if(!this.oApp.isWYSIWYGEnabled()){
  15542. return;
  15543. }
  15544. switch(this.nStatus){
  15545. case this.STATUS.S_0:
  15546. // the user may just want to resize the image
  15547. if(!wevE.element){return;}
  15548. if(wevE.element.tagName == "IMG"){return;}
  15549. if(this.oApp.getEditingMode() !== "WYSIWYG"){return;}
  15550. // change the status to MOUSEDOWN_CELL if the mouse is over a table cell
  15551. // [SMARTEDITORSUS-1672]
  15552. /*var elTD = nhn.husky.SE2M_Utils.findAncestorByTagName("TD", wevE.element);
  15553. if(elTD && elTD.tagName == "TD"){*/
  15554. var elTD = nhn.husky.SE2M_Utils.findClosestAncestorAmongTagNames(this._aCellName, wevE.element);
  15555. if(elTD && this._rxCellNames.test(elTD.tagName)){
  15556. // --[SMARTEDITORSUS-1672]
  15557. var elTBL = nhn.husky.SE2M_Utils.findAncestorByTagName("TABLE", elTD);
  15558. if(!jindo.$Element(elTBL).hasClass(this._sSETblClass) && !jindo.$Element(elTBL).hasClass(this._sSEReviewTblClass)){return;}
  15559. if(!this._isValidTable(elTBL)){
  15560. jindo.$Element(elTBL).removeClass(this._sSETblClass);
  15561. jindo.$Element(elTBL).removeClass(this._sSEReviewTblClass);
  15562. return;
  15563. }
  15564. if(elTBL){
  15565. this.elSelectionStartTD = elTD;
  15566. this.elSelectionStartTable = elTBL;
  15567. this._changeTableEditorStatus(this.STATUS.MOUSEDOWN_CELL);
  15568. }
  15569. }
  15570. break;
  15571. case this.STATUS.MOUSEDOWN_CELL:
  15572. break;
  15573. case this.STATUS.CELL_SELECTING:
  15574. break;
  15575. case this.STATUS.CELL_SELECTED:
  15576. this._changeTableEditorStatus(this.STATUS.S_0);
  15577. break;
  15578. }
  15579. },
  15580. $ON_EVENT_EDITING_AREA_MOUSEMOVE : function(wevE){
  15581. if(this.oApp.getEditingMode() != "WYSIWYG"){return;}
  15582. // [SMARTEDITORSUS-2136] [IE] <table>에 resizeend 핸들러 부여
  15583. var elTable = wevE.element,
  15584. htBrowser = jindo.$Agent().navigator(),
  15585. sPointerUpEvent = 'onpointerup',
  15586. sResizeEndEvent = 'onresizeend';
  15587. if(htBrowser.ie && elTable && elTable.tagName && (elTable.tagName.toUpperCase() === 'TABLE')){ // [IE]
  15588. if(sPointerUpEvent in elTable){ // [IE 11] resizeend 이벤트 deprecated
  15589. elTable[sPointerUpEvent] = this._wfnOnResizeEndTable;
  15590. }else if(sResizeEndEvent in elTable){
  15591. if(htBrowser.version > 8){
  15592. elTable[sResizeEndEvent] = this._wfnOnResizeEndTable;
  15593. }else{
  15594. // [IE 8-] event 객체가 handler로 전달되지 않는 문제가 있어서 별도의 handler 사용
  15595. elTable[sResizeEndEvent] = this._getTableResizeEndHandler(elTable);
  15596. }
  15597. }
  15598. }
  15599. // --[SMARTEDITORSUS-2136]
  15600. switch(this.nStatus){
  15601. case this.STATUS.S_0:
  15602. if(this._isOnBorder(wevE)){
  15603. //this._changeTableEditorStatus(this.MOUSEOVER_BORDER);
  15604. this._showCellResizeGrip(wevE);
  15605. }else{
  15606. this._hideResizer();
  15607. }
  15608. break;
  15609. case this.STATUS.MOUSEDOWN_CELL:
  15610. // change the status to CELL_SELECTING if the mouse moved out of the inital TD
  15611. // [SMARTEDITORSUS-1672]
  15612. //var elTD = nhn.husky.SE2M_Utils.findAncestorByTagName("TD", wevE.element);
  15613. var elTD = nhn.husky.SE2M_Utils.findClosestAncestorAmongTagNames(this._aCellName, wevE.element);
  15614. // --[SMARTEDITORSUS-1672]
  15615. if((elTD && elTD !== this.elSelectionStartTD) || !elTD){
  15616. if(!elTD){elTD = this.elSelectionStartTD;}
  15617. this._reassignCellSizes(this.elSelectionStartTable);
  15618. this._startCellSelection();
  15619. this._selectBetweenCells(this.elSelectionStartTD, elTD);
  15620. }
  15621. break;
  15622. case this.STATUS.CELL_SELECTING:
  15623. // show selection
  15624. // [SMARTEDITORSUS-1672]
  15625. //var elTD = nhn.husky.SE2M_Utils.findAncestorByTagName("TD", wevE.element);
  15626. var elTD = nhn.husky.SE2M_Utils.findClosestAncestorAmongTagNames(this._aCellName, wevE.element);
  15627. // --[SMARTEDITORSUS-1672]
  15628. if(!elTD || elTD === this.elLastSelectedTD){return;}
  15629. var elTBL = nhn.husky.SE2M_Utils.findAncestorByTagName("TABLE", elTD);
  15630. if(elTBL !== this.elSelectionStartTable){return;}
  15631. this.elLastSelectedTD = elTD;
  15632. this._selectBetweenCells(this.elSelectionStartTD, elTD);
  15633. break;
  15634. case this.STATUS.CELL_SELECTED:
  15635. break;
  15636. }
  15637. },
  15638. // 셀 선택 상태에서 문서영역을 상/하로 벗어날 경우, 벗어난 방향으로 선택 셀을 늘려가며 문서의 스크롤을 해줌
  15639. $ON_EVENT_OUTER_DOC_MOUSEMOVE : function(wevE){
  15640. switch(this.nStatus){
  15641. case this.STATUS.CELL_SELECTING:
  15642. var htPos = wevE.pos();
  15643. var nYPos = htPos.pageY;
  15644. var nXPos = htPos.pageX;
  15645. if(nYPos < this.htEditingAreaPos.top){
  15646. var y = this.htSelectionSPos.y;
  15647. if(y > 0){
  15648. this.htSelectionSPos.y--;
  15649. this._selectCells(this.htSelectionSPos, this.htSelectionEPos);
  15650. var oSelection = this.oApp.getSelection();
  15651. oSelection.selectNodeContents(this.aSelectedCells[0]);
  15652. oSelection.select();
  15653. oSelection.oBrowserSelection.selectNone();
  15654. }
  15655. }else{
  15656. if(nYPos > this.htEditingAreaPos.bottom){
  15657. var y = this.htSelectionEPos.y;
  15658. if(y < this.htMap[0].length - 1){
  15659. this.htSelectionEPos.y++;
  15660. this._selectCells(this.htSelectionSPos, this.htSelectionEPos);
  15661. var oSelection = this.oApp.getSelection();
  15662. oSelection.selectNodeContents(this.htMap[this.htSelectionEPos.x][this.htSelectionEPos.y]);
  15663. oSelection.select();
  15664. oSelection.oBrowserSelection.selectNone();
  15665. }
  15666. }
  15667. }
  15668. if(nXPos < this.htEditingAreaPos.left){
  15669. var x = this.htSelectionSPos.x;
  15670. if(x > 0){
  15671. this.htSelectionSPos.x--;
  15672. this._selectCells(this.htSelectionSPos, this.htSelectionEPos);
  15673. var oSelection = this.oApp.getSelection();
  15674. oSelection.selectNodeContents(this.aSelectedCells[0]);
  15675. oSelection.select();
  15676. oSelection.oBrowserSelection.selectNone();
  15677. }
  15678. }else{
  15679. if(nXPos > this.htEditingAreaPos.right){
  15680. var x = this.htSelectionEPos.x;
  15681. if(x < this.htMap.length - 1){
  15682. this.htSelectionEPos.x++;
  15683. this._selectCells(this.htSelectionSPos, this.htSelectionEPos);
  15684. var oSelection = this.oApp.getSelection();
  15685. oSelection.selectNodeContents(this.htMap[this.htSelectionEPos.x][this.htSelectionEPos.y]);
  15686. oSelection.select();
  15687. oSelection.oBrowserSelection.selectNone();
  15688. }
  15689. }
  15690. }
  15691. break;
  15692. }
  15693. },
  15694. $ON_EVENT_OUTER_DOC_MOUSEUP : function(wevE){
  15695. this._eventEditingAreaMouseup(wevE);
  15696. },
  15697. $ON_EVENT_EDITING_AREA_MOUSEUP : function(wevE){
  15698. this._eventEditingAreaMouseup(wevE);
  15699. },
  15700. _eventEditingAreaMouseup : function(wevE){
  15701. if(this.oApp.getEditingMode() != "WYSIWYG"){return;}
  15702. switch(this.nStatus){
  15703. case this.STATUS.S_0:
  15704. break;
  15705. case this.STATUS.MOUSEDOWN_CELL:
  15706. this._changeTableEditorStatus(this.STATUS.S_0);
  15707. break;
  15708. case this.STATUS.CELL_SELECTING:
  15709. this._changeTableEditorStatus(this.STATUS.CELL_SELECTED);
  15710. break;
  15711. case this.STATUS.CELL_SELECTED:
  15712. break;
  15713. }
  15714. },
  15715. /**
  15716. * Table의 block으로 잡힌 영역을 넘겨준다.
  15717. * @see hp_SE2M_TableBlockStyler.js
  15718. */
  15719. $ON_GET_SELECTED_CELLS : function(sAttr,oReturn){
  15720. if(!!this.aSelectedCells){
  15721. oReturn[sAttr] = this.aSelectedCells;
  15722. }
  15723. },
  15724. _coverResizeLayer : function(){
  15725. // [SMARTEDITORSUS-1504] 에디터 전체 크기보다 창이 작아졌을 때 elResizeGrid가 최대화된 elResizeCover으로부터 벗어나는 이슈가 있음
  15726. //this.elResizeCover.style.position = "absolute";
  15727. this.elResizeCover.style.position = "fixed";
  15728. // --[SMARTEDITORSUS-1504]
  15729. var size = jindo.$Document().clientSize();
  15730. this.elResizeCover.style.width = size.width - this.nPageLeftRightMargin + "px";
  15731. this.elResizeCover.style.height = size.height - this.nPageTopBottomMargin + "px";
  15732. //this.elResizeCover.style.width = size.width + "px";
  15733. //this.elResizeCover.style.height = size.height + "px";
  15734. //document.body.insertBefore(this.elResizeCover, document.body.firstChild);
  15735. document.body.appendChild(this.elResizeCover);
  15736. },
  15737. _uncoverResizeLayer : function(){
  15738. this.elResizeGrid.appendChild(this.elResizeCover);
  15739. this.elResizeCover.style.position = "";
  15740. this.elResizeCover.style.width = "100%";
  15741. this.elResizeCover.style.height = "100%";
  15742. },
  15743. _reassignCellSizes : function(elTable){
  15744. var allCells = new Array(2);
  15745. allCells[0] = jindo.$$(">TBODY>TR>TD", elTable, {oneTimeOffCache:true});
  15746. allCells[1] = jindo.$$(">TBODY>TR>TH", elTable, {oneTimeOffCache:true});
  15747. var aAllCellsWithSizeInfo = new Array(allCells[0].length + allCells[1].length);
  15748. var numCells = 0;
  15749. var nTblBorderPadding = this.parseIntOr0(elTable.border);
  15750. var nTblCellPadding = this.parseIntOr0(elTable.cellPadding);
  15751. // remember all the dimensions first and then assign later.
  15752. // this is done this way because if the table/cell size were set in %, setting one cell size would change size of other cells, which are still yet in %.
  15753. // 1 for TD and 1 for TH
  15754. for(var n = 0; n < 2; n++){
  15755. for(var i = 0; i < allCells[n].length; i++){
  15756. var elCell = allCells[n][i];
  15757. var welCell = jindo.$Element(elCell);
  15758. var htBrowser = jindo.$Agent().navigator();
  15759. // [SMARTEDITORSUS-1427][SMARTEDITORSUS-1431][SMARTEDITORSUS-1491][SMARTEDITORSUS-1504] IE9, 10에서 Jindo.$Element#css 가 빈 속성값을 1px로 가져오는 문제점이 있어 대체
  15760. /*var nPaddingLeft = this.parseIntOr0(welCell.css("paddingLeft"));
  15761. var nPaddingRight = this.parseIntOr0(welCell.css("paddingRight"));
  15762. var nPaddingTop = this.parseIntOr0(welCell.css("paddingTop"));
  15763. var nPaddingBottom = this.parseIntOr0(welCell.css("paddingBottom"));
  15764. var nBorderLeft = this.parseBorder(welCell.css("borderLeftWidth"), welCell.css("borderLeftStyle"));
  15765. var nBorderRight = this.parseBorder(welCell.css("borderRightWidth"), welCell.css("borderRightStyle"));
  15766. var nBorderTop = this.parseBorder(welCell.css("borderTopWidth"), welCell.css("borderTopStyle"));
  15767. var nBorderBottom = this.parseBorder(welCell.css("borderBottomWidth"), welCell.css("borderBottomStyle"));*/
  15768. var nPaddingLeft, nPaddingRight, nPaddingTop, nPaddingBottom;
  15769. var nBorderLeft, nBorderRight, nBorderTop, nBorderBottom;
  15770. // --[SMARTEDITORSUS-1427][SMARTEDITORSUS-1431][SMARTEDITORSUS-1491][SMARTEDITORSUS-1504]
  15771. var nOffsetWidth, nOffsetHeight;
  15772. // [SMARTEDITORSUS-1571] IE 10 이상임에도 불구하고, 문서 모드가 8 이하로 설정되어 있는 경우가 있어 메서드 기반 분기로 변경
  15773. if(elCell.getComputedStyle){
  15774. // --[SMARTEDITORSUS-1571]
  15775. // getComputedStyle()로 inherit된 스타일을 획득. IE 8 이하에서는 지원되지 않는다.
  15776. nPaddingLeft = parseFloat(getComputedStyle(elCell).paddingLeft, 10);
  15777. nPaddingRight = parseFloat(getComputedStyle(elCell).paddingRight, 10);
  15778. nPaddingTop = parseFloat(getComputedStyle(elCell).paddingTop, 10);
  15779. nPaddingBottom = parseFloat(getComputedStyle(elCell).paddingBottom, 10);
  15780. // 최초 리사이징 직전 width attribute에서 style의 width로 이행하는 과정에서 미세보정이 있기 때문에 크기가 조금 변한다.
  15781. nBorderLeft = parseFloat(getComputedStyle(elCell).borderLeftWidth, 10);
  15782. nBorderRight = parseFloat(getComputedStyle(elCell).borderRightWidth, 10);
  15783. nBorderTop = parseFloat(getComputedStyle(elCell).borderTopWidth, 10);
  15784. nBorderBottom = parseFloat(getComputedStyle(elCell).borderBottomWidth, 10);
  15785. }else{ // 이 방식은 inherit된 스타일을 가져오지 못하는 문제와 함께, 일부 브라우저의 소수점 값을 버림하는 문제가 있다.
  15786. // [SMARTEDITORSUS-1427][SMARTEDITORSUS-1431][SMARTEDITORSUS-1491]
  15787. nPaddingLeft = this.parseIntOr0(elCell.style.paddingLeft);
  15788. nPaddingRight = this.parseIntOr0(elCell.style.paddingRight);
  15789. nPaddingTop = this.parseIntOr0(elCell.style.paddingTop);
  15790. nPaddingBottom = this.parseIntOr0(elCell.style.paddingBottom);
  15791. // --[SMARTEDITORSUS-1427][SMARTEDITORSUS-1431][SMARTEDITORSUS-1491]
  15792. // 기존 로직을 사용. IE의 경우 bug로 분류하여 1px를 획득하도록 설정되어 있다.
  15793. nBorderLeft = this.parseBorder(welCell.css("borderLeftWidth"), welCell.css("borderLeftStyle"));
  15794. nBorderRight = this.parseBorder(welCell.css("borderRightWidth"), welCell.css("borderRightStyle"));
  15795. nBorderTop = this.parseBorder(welCell.css("borderTopWidth"), welCell.css("borderTopStyle"));
  15796. nBorderBottom = this.parseBorder(welCell.css("borderBottomWidth"), welCell.css("borderBottomStyle"));
  15797. }
  15798. /**
  15799. * 매번 발생하는 리사이징 오차를 최소하기 위하여, 2회차부터는 1회차에 적용되는 style 값을 가져온다.
  15800. *
  15801. * width와 height attribute는 최초 1회에 제거된다.
  15802. * 2회차부터는, 동적으로 변하는 style의 width, height 값을 그대로 사용한다.
  15803. * */
  15804. /*nOffsetWidth = elCell.offsetWidth - (nPaddingLeft + nPaddingRight + nBorderLeft + nBorderRight) + "px";
  15805. nOffsetHeight = elCell.offsetHeight - (nPaddingTop + nPaddingBottom + nBorderTop + nBorderBottom) + "px";*/
  15806. var nWidth = jindo.$Element(elCell).attr("width");
  15807. var nHeight = jindo.$Element(elCell).attr("height");
  15808. if(!nWidth && !nHeight){
  15809. nOffsetWidth = elCell.style.width;
  15810. nOffsetHeight = elCell.style.height;
  15811. }else{
  15812. nOffsetWidth = elCell.offsetWidth - (nPaddingLeft + nPaddingRight + nBorderLeft + nBorderRight) + "px";
  15813. nOffsetHeight = elCell.offsetHeight - (nPaddingTop + nPaddingBottom + nBorderTop + nBorderBottom) + "px";
  15814. }
  15815. /*if(htBrowser.ie && (htBrowser.nativeVersion >= 9 && htBrowser.nativeVersion <= 10)){
  15816. // IE9, IE10
  15817. // [SMARTEDITORSUS-1427][SMARTEDITORSUS-1431][SMARTEDITORSUS-1491] IE9, 10에서 Jindo.$Element#css 관련 문제에 대응하면 다른 브라우저와 동일한 수식 적용 가능
  15818. //nOffsetWidth = elCell.offsetWidth + "px";
  15819. //nOffsetHeight = elCell.offsetHeight - (nPaddingTop + nPaddingBottom + nBorderTop + nBorderBottom) + "px";
  15820. nOffsetWidth = elCell.offsetWidth - (nPaddingLeft + nPaddingRight + nBorderLeft + nBorderRight) + "px";
  15821. nOffsetHeight = elCell.offsetHeight - (nPaddingTop + nPaddingBottom + nBorderTop + nBorderBottom) + "px";
  15822. // --[SMARTEDITORSUS-1427][SMARTEDITORSUS-1431][SMARTEDITORSUS-1491]
  15823. }else{
  15824. // Firefox, Chrome, IE7, IE8
  15825. nOffsetWidth = elCell.offsetWidth - (nPaddingLeft + nPaddingRight + nBorderLeft + nBorderRight) + "px";
  15826. nOffsetHeight = elCell.offsetHeight - (nPaddingTop + nPaddingBottom + nBorderTop + nBorderBottom) + "px";
  15827. }*/
  15828. // --[SMARTEDITORSUS-1504]
  15829. aAllCellsWithSizeInfo[numCells++] = [elCell, nOffsetWidth, nOffsetHeight];
  15830. }
  15831. }
  15832. // [SMARTEDITORSUS-2136]
  15833. var nTableWidth = elTable._nWidth, nTableHeight = elTable._nHeight,
  15834. nResizedTableWidth = elTable._nResizedWidth, nResizedTableHeight = elTable._nResizedHeight, // [IE] resizeend 이벤트가 발생했다면 존재
  15835. nTableWidthAdjustRatio = 1, nTableHeightAdjustRatio = 1; // 셀 크기 변경 시 사용되는 보정계수
  15836. if(nhn.husky.SE2M_Utils.isNumber(nTableWidth) && nhn.husky.SE2M_Utils.isNumber(nTableHeight)
  15837. && nhn.husky.SE2M_Utils.isNumber(nResizedTableWidth) && nhn.husky.SE2M_Utils.isNumber(nResizedTableHeight)){
  15838. // [IE] resizeend 정보가 기록되어 있다면, 셀 크기 변경 시 보정계수 조정
  15839. nTableWidthAdjustRatio = nResizedTableWidth / nTableWidth,
  15840. nTableHeightAdjustRatio = nResizedTableHeight / nTableHeight;
  15841. }
  15842. // [IE] 기록해 둔 resizeend 크기는 일회성으로 사용한다.
  15843. if(elTable._nResizedWidth){
  15844. nhn.husky.SE2M_Utils.deleteProperty(elTable, '_nResizedWidth');
  15845. }
  15846. if(elTable._nResizedHeight){
  15847. nhn.husky.SE2M_Utils.deleteProperty(elTable, '_nResizedHeight');
  15848. }
  15849. // --[SMARTEDITORSUS-2136]
  15850. for(var i = 0; i < numCells; i++){
  15851. var aCellInfo = aAllCellsWithSizeInfo[i];
  15852. aCellInfo[0].removeAttribute("width");
  15853. aCellInfo[0].removeAttribute("height");
  15854. // [SMARTEDITORSUS-2136] 보정계수를 적용하여 셀의 크기 변경
  15855. aCellInfo[0].style.width = (parseFloat(aCellInfo[1], 10) * nTableWidthAdjustRatio) + 'px';
  15856. aCellInfo[0].style.height = (parseFloat(aCellInfo[2], 10) * nTableHeightAdjustRatio) + 'px';
  15857. // --[SMARTEDITORSUS-2136]
  15858. // jindo.$Element(aCellInfo[0]).css("width", aCellInfo[1]);
  15859. // jindo.$Element(aCellInfo[0]).css("height", aCellInfo[2]);
  15860. }
  15861. // [SMARTEDITORSUS-2136] HTMLElement의 속성으로 <table>의 크기 기록
  15862. var welTable = jindo.$Element(elTable);
  15863. elTable._nWidth = welTable.width(),
  15864. elTable._nHeight = welTable.height();
  15865. // --[SMARTEDITORSUS-2136]
  15866. elTable.removeAttribute("width");
  15867. elTable.removeAttribute("height");
  15868. elTable.style.width = "";
  15869. elTable.style.height = "";
  15870. },
  15871. _fnOnMouseDownResizeCover : function(oEvent){
  15872. this.bResizing = true;
  15873. this.nStartHeight = oEvent.pos().clientY;
  15874. // [SMARTEDITORSUS-1504] 표 테두리를 누를 때마다 글양식이 2px씩 세로로 길어지는 문제가 있는데, 이를 위한 flag
  15875. this.bResizingCover = true;
  15876. // --[SMARTEDITORSUS-1504]
  15877. this._wfnOnMouseMoveResizeCover.attach(this.elResizeCover, "mousemove");
  15878. this._wfnOnMouseUpResizeCover.attach(document, "mouseup");
  15879. this._coverResizeLayer();
  15880. this.elResizeGrid.style.border = "1px dotted black";
  15881. this.nStartHeight = oEvent.pos().clientY;
  15882. this.nStartWidth = oEvent.pos().clientX;
  15883. // [SMARTEDITORSUS-1504] 표 리사이즈용 gripper의 배치를 WYSIWYG 편집 영역 위치 기반으로 개선
  15884. this.nClientXDiff = this.nStartWidth - this.htResizing.htEPos.clientX;
  15885. this.nClientYDiff = this.nStartHeight - this.htResizing.htEPos.clientY;
  15886. // --[SMARTEDITORSUS-1504]
  15887. this._reassignCellSizes(this.htResizing.elTable);
  15888. this.htMap = this._getCellMapping(this.htResizing.elTable);
  15889. var htPosition = this._getBasisCellPosition(this.htResizing.elCell);
  15890. var nOffsetX = (parseInt(this.htResizing.elCell.getAttribute("colspan")) || 1) - 1;
  15891. var nOffsetY = (parseInt(this.htResizing.elCell.getAttribute("rowspan")) || 1) - 1;
  15892. var x = htPosition.x + nOffsetX + this.htResizing.nHA;
  15893. var y = htPosition.y + nOffsetY + this.htResizing.nVA;
  15894. if(x < 0 || y < 0){return;}
  15895. this.htAllAffectedCells = this._getAllAffectedCells(x, y, this.htResizing.nResizeMode, this.htResizing.elTable);
  15896. },
  15897. _fnOnMouseMoveResizeCover : function(oEvent){
  15898. // [SMARTEDITORSUS-1504] 표 모서리 Drag 사용성 개선
  15899. // - 최초 리사이징 후 해당 위치에서 바로 마우스를 눌러 Drag 가능
  15900. if(jindo.$Agent().navigator().chrome || jindo.$Agent().navigator().safari){
  15901. if(this.htResizing.nPreviousResizeMode != undefined && this.htResizing.nPreviousResizeMode != 0){
  15902. if(this.htResizing.nResizeMode != this.htResizing.nPreviousResizeMode){
  15903. this.htResizing.nResizeMode = this.htResizing.nPreviousResizeMode;
  15904. this._showResizer();
  15905. }
  15906. }
  15907. }
  15908. // --[SMARTEDITORSUS-1504]
  15909. var nHeightChange = oEvent.pos().clientY - this.nStartHeight;
  15910. var nWidthChange = oEvent.pos().clientX - this.nStartWidth;
  15911. var oEventPos = oEvent.pos();
  15912. // [SMARTEDITORSUS-1504] 표 리사이즈용 gripper의 배치를 WYSIWYG 편집 영역 위치 기반으로 개선
  15913. /*if(this.htResizing.nResizeMode == 1){
  15914. this.elResizeGrid.style.left = oEventPos.pageX - this.parseIntOr0(this.elResizeGrid.style.width)/2 + "px";
  15915. }else{
  15916. this.elResizeGrid.style.top = oEventPos.pageY - this.parseIntOr0(this.elResizeGrid.style.height)/2 + "px";
  15917. }*/
  15918. if(this.htResizing.nResizeMode == 1){
  15919. this.elResizeGrid.style.left = oEvent.pos().clientX - this.nClientXDiff - this.parseIntOr0(this.elResizeGrid.style.width)/2 + "px";
  15920. }else{
  15921. this.elResizeGrid.style.top = oEvent.pos().clientY - this.nClientYDiff - this.parseIntOr0(this.elResizeGrid.style.height)/2 + "px";
  15922. }
  15923. // --[SMARTEDITORSUS-1504]
  15924. },
  15925. _fnOnMouseUpResizeCover : function(oEvent){
  15926. this.bResizing = false;
  15927. this._hideResizer();
  15928. this._uncoverResizeLayer();
  15929. this.elResizeGrid.style.border = "";
  15930. this._wfnOnMouseMoveResizeCover.detach(this.elResizeCover, "mousemove");
  15931. this._wfnOnMouseUpResizeCover.detach(document, "mouseup");
  15932. var nHeightChange = 0;
  15933. var nWidthChange = 0;
  15934. if(this.htResizing.nResizeMode == 2){
  15935. nHeightChange = oEvent.pos().clientY - this.nStartHeight;
  15936. }
  15937. if(this.htResizing.nResizeMode == 1){
  15938. nWidthChange = oEvent.pos().clientX - this.nStartWidth;
  15939. if(this.htAllAffectedCells.nMinBefore != -1 && nWidthChange < -1*this.htAllAffectedCells.nMinBefore){
  15940. nWidthChange = -1 * this.htAllAffectedCells.nMinBefore + this.MIN_CELL_WIDTH;
  15941. }
  15942. if(this.htAllAffectedCells.nMinAfter != -1 && nWidthChange > this.htAllAffectedCells.nMinAfter){
  15943. nWidthChange = this.htAllAffectedCells.nMinAfter - this.MIN_CELL_WIDTH;
  15944. }
  15945. }
  15946. // [SMARTEDITORSUS-1504] FireFox는 소수점으로 size가 나오는데, parseInt는 소수점 이하를 버림
  15947. // [SMARTEDITORSUS-1655] 메서드, 프로퍼티 기반 리팩토링
  15948. var width, height;
  15949. // --[SMARTEDITORSUS-1655]
  15950. var aCellsBefore = this.htAllAffectedCells.aCellsBefore;
  15951. for(var i = 0; i < aCellsBefore.length; i++){
  15952. var elCell = aCellsBefore[i];
  15953. // [SMARTEDITORSUS-1655]
  15954. width = 0, height = 0;
  15955. width = elCell.style.width;
  15956. if(isNaN(parseFloat(width, 10))){ // 값이 없거나 "auto"인 경우
  15957. width = 0;
  15958. }else{
  15959. width = parseFloat(width, 10);
  15960. }
  15961. width += nWidthChange;
  15962. height = elCell.style.height;
  15963. if(isNaN(parseFloat(height, 10))){ // 값이 없거나 "auto"인 경우
  15964. height = 0;
  15965. }else{
  15966. height = parseFloat(height, 10);
  15967. }
  15968. height += nHeightChange;
  15969. // --[SMARTEDITORSUS-1655]
  15970. //var width = this.parseIntOr0(elCell.style.width) + nWidthChange;
  15971. elCell.style.width = Math.max(width, this.MIN_CELL_WIDTH) + "px";
  15972. //var height = this.parseIntOr0(elCell.style.height) + nHeightChange;
  15973. elCell.style.height = Math.max(height, this.MIN_CELL_HEIGHT) + "px";
  15974. }
  15975. var aCellsAfter = this.htAllAffectedCells.aCellsAfter;
  15976. for(var i = 0; i < aCellsAfter.length; i++){
  15977. var elCell = aCellsAfter[i];
  15978. // [SMARTEDITORSUS-1655]
  15979. width = 0, height = 0;
  15980. width = elCell.style.width;
  15981. if(isNaN(parseFloat(width, 10))){ // 값이 없거나 "auto"인 경우
  15982. width = 0;
  15983. }else{
  15984. width = parseFloat(width, 10);
  15985. }
  15986. width -= nWidthChange;
  15987. height = elCell.style.height;
  15988. if(isNaN(parseFloat(height, 10))){ // 값이 없거나 "auto"인 경우
  15989. height = 0;
  15990. }else{
  15991. height = parseFloat(height, 10);
  15992. }
  15993. height -= nHeightChange;
  15994. // --[SMARTEDITORSUS-1655]
  15995. //var width = this.parseIntOr0(elCell.style.width) - nWidthChange;
  15996. elCell.style.width = Math.max(width, this.MIN_CELL_WIDTH) + "px";
  15997. //var height = this.parseIntOr0(elCell.style.height) - nHeightChange;
  15998. elCell.style.height = Math.max(height, this.MIN_CELL_HEIGHT) + "px";
  15999. }
  16000. // --[SMARTEDITORSUS-1504]
  16001. // [SMARTEDITORSUS-1504] 표 테두리를 누를 때마다 글양식이 2px씩 세로로 길어지는 문제가 있는데, 이를 위한 flag
  16002. this.bResizingCover = false;
  16003. // --[SMARTEDITORSUS-1504]
  16004. },
  16005. /**
  16006. * [SMARTEDITORSUS-2136] [IE 9, 10] resizeend 이벤트 handler
  16007. * [IE 11] resizeend 이벤트 deprecated : pointerup 이벤트로 갈음한다.
  16008. * */
  16009. _fnOnResizeEndTable : function(oEvent){
  16010. var wev = jindo.$Event(oEvent);
  16011. var elTable = wev.element;
  16012. this._markResizedMetric(elTable);
  16013. },
  16014. /**
  16015. * [SMARTEDITORSUS-2136] [IE 8-] resizeend 이벤트 handler
  16016. * */
  16017. _getTableResizeEndHandler : function(elTable){
  16018. return jindo.$Fn(this._markResizedMetric, this).bind(elTable);
  16019. },
  16020. /**
  16021. * [SMARTEDITORSUS-2136] [IE] resizeend 이벤트 발생
  16022. * 경우에 변화하는 표의 크기를 기록해 두고
  16023. * 크기 변경 보정에 사용한다.
  16024. * */
  16025. _markResizedMetric : function(elTable){
  16026. if(!elTable || (elTable.tagName.toUpperCase() !== 'TABLE')){
  16027. return;
  16028. }
  16029. // HTMLElement의 속성으로 resize된 <table>의 크기 기록
  16030. var welCurrentTable = jindo.$Element(elTable);
  16031. elTable._nResizedWidth = welCurrentTable.width(),
  16032. elTable._nResizedHeight = welCurrentTable.height();
  16033. },
  16034. $ON_CLOSE_QE_LAYER : function(oEvent){
  16035. // [SMARTEDITORSUS-2137] 퀵에디터의 접기/펼치기 클릭 시에는, cell의 상태를 변경하지 않는다.
  16036. var elTarget = oEvent ? oEvent.element : null,
  16037. welTarget = elTarget ? jindo.$Element(elTarget) : null,
  16038. aQEToggleClassName = ['q_open_table_fold', 'q_open_table_full'], sQEToggleClassName,
  16039. i, len = aQEToggleClassName.length,
  16040. isFromQEToggle = false;
  16041. if(welTarget){
  16042. for(i = len; i--;){
  16043. sQEToggleClassName = aQEToggleClassName[i];
  16044. if(welTarget.hasClass(sQEToggleClassName)){
  16045. isFromQEToggle = true;
  16046. break;
  16047. }
  16048. }
  16049. }
  16050. if(isFromQEToggle){
  16051. return;
  16052. }
  16053. // --[SMARTEDITORSUS-2137]
  16054. this._changeTableEditorStatus(this.STATUS.S_0);
  16055. },
  16056. _changeTableEditorStatus : function(nNewStatus){
  16057. if(this.nStatus == nNewStatus){return;}
  16058. this.nStatus = nNewStatus;
  16059. switch(nNewStatus){
  16060. case this.STATUS.S_0:
  16061. if(this.nStatus == this.STATUS.MOUSEDOWN_CELL){
  16062. break;
  16063. }
  16064. this._deselectCells();
  16065. // 히스토리 저장 (선택 위치는 저장하지 않음)
  16066. if(!!this.sQEAction){
  16067. this.oApp.exec("RECORD_UNDO_ACTION", [this.sQEAction, {elSaveTarget:this.elSelectionStartTable, bDontSaveSelection:true}]);
  16068. this.sQEAction = "";
  16069. }
  16070. if(this.oApp.oNavigator["safari"] || this.oApp.oNavigator["chrome"]){
  16071. this.oApp.getWYSIWYGDocument().onselectstart = null;
  16072. }
  16073. this.oApp.exec("ENABLE_WYSIWYG", []);
  16074. this.oApp.exec("CLOSE_QE_LAYER");
  16075. this.elSelectionStartTable = null;
  16076. break;
  16077. case this.STATUS.CELL_SELECTING:
  16078. // [SMARTEDITORSUS-2155] Legacy Event Methods (https://msdn.microsoft.com/en-us/library/ms536742(v=vs.85).aspx)
  16079. if(this.oApp.oNavigator.ie && (typeof(document.body.setCapture) === 'function')){
  16080. document.body.setCapture(false);
  16081. }
  16082. break;
  16083. case this.STATUS.CELL_SELECTED:
  16084. this.oApp.delayedExec("MSG_CELL_SELECTED", [], 0);
  16085. // [SMARTEDITORSUS-2155] Legacy Event Methods (https://msdn.microsoft.com/en-us/library/ms536742(v=vs.85).aspx)
  16086. if(this.oApp.oNavigator.ie && (typeof(document.body.releaseCapture) === 'function')){
  16087. document.body.releaseCapture();
  16088. }
  16089. break;
  16090. }
  16091. this.oApp.exec("TABLE_EDITOR_STATUS_CHANGED", [this.nStatus]);
  16092. },
  16093. _isOnBorder : function(wevE){
  16094. // ===========================[Start: Set/init global resizing info]===========================
  16095. // 0: not resizing
  16096. // 1: horizontal resizing
  16097. // 2: vertical resizing
  16098. this.htResizing.nResizeMode = 0;
  16099. this.htResizing.elCell = wevE.element;
  16100. // [SMARTEDITORSUS-1672]
  16101. //if(wevE.element.tagName != "TD" && wevE.element.tagName != "TH"){return false;}
  16102. if(!this._rxCellNames.test(wevE.element.tagName)){return false;}
  16103. // --[SMARTEDITORSUS-1672]
  16104. this.htResizing.elTable = nhn.husky.SE2M_Utils.findAncestorByTagName("TABLE", this.htResizing.elCell);
  16105. if(!this.htResizing.elTable){return;}
  16106. if(!jindo.$Element(this.htResizing.elTable).hasClass(this._sSETblClass) && !jindo.$Element(this.htResizing.elTable).hasClass(this._sSEReviewTblClass)){return;}
  16107. // Adjustment variables: to be used to map the x, y position of the resizing point relative to elCell
  16108. // eg) When left border of a cell at 2,2 is selected, the actual cell that has to be resized is the one at 1,2. So, set the horizontal adjustment to -1.
  16109. // Vertical Adjustment
  16110. this.htResizing.nVA = 0;
  16111. // Horizontal Adjustment
  16112. this.htResizing.nHA = 0;
  16113. this.htResizing.nBorderLeftPos = 0;
  16114. this.htResizing.nBorderTopPos = -1;
  16115. this.htResizing.htEPos = wevE.pos(true);
  16116. this.htResizing.nBorderSize = this.parseIntOr0(this.htResizing.elTable.border);
  16117. // ===========================[E N D: Set/init global resizing info]===========================
  16118. // Separate info is required as the offsetX/Y are different in IE and FF
  16119. // For IE, (0, 0) is top left corner of the cell including the border.
  16120. // For FF, (0, 0) is top left corner of the cell excluding the border.
  16121. var nAdjustedDraggableCellEdge1;
  16122. var nAdjustedDraggableCellEdge2;
  16123. if(jindo.$Agent().navigator().ie || jindo.$Agent().navigator().safari){
  16124. nAdjustedDraggableCellEdge1 = this.htResizing.nBorderSize + this.nDraggableCellEdge;
  16125. nAdjustedDraggableCellEdge2 = this.nDraggableCellEdge;
  16126. }else{
  16127. nAdjustedDraggableCellEdge1 = this.nDraggableCellEdge;
  16128. nAdjustedDraggableCellEdge2 = this.htResizing.nBorderSize + this.nDraggableCellEdge;
  16129. }
  16130. // [SMARTEDITORSUS-1504] 경계선 판별에 사용
  16131. var elCellWidth = this.htResizing.elCell.clientWidth,
  16132. elCellHeight = this.htResizing.elCell.clientHeight;
  16133. nRightBorderCriteria = elCellWidth - this.htResizing.htEPos.offsetX,
  16134. nBottomBorderCriteria = elCellHeight - this.htResizing.htEPos.offsetY;
  16135. // --[SMARTEDITORSUS-1504]
  16136. // top border of the cell is selected
  16137. if(this.htResizing.htEPos.offsetY <= nAdjustedDraggableCellEdge1){
  16138. // [SMARTEDITORSUS-2136] resizeend 이후 표의 상단 테두리에 resize grip이 생성되면 스크립트 오류를 발생시킨다.
  16139. var _isFirstRow = false,
  16140. _elRow = this.htResizing.elCell.parentNode;
  16141. var _elTbody = _elRow.parentNode;
  16142. var _aRow = jindo.$$('tr', _elTbody, {oneTimeOffCache : true});
  16143. if(_aRow[0] == _elRow){
  16144. _isFirstRow = true;
  16145. }
  16146. // --[SMARTEDITORSUS-2136]
  16147. // top border of the first cell can't be dragged
  16148. if(_isFirstRow){
  16149. this.htResizing.nVA = -1;
  16150. // [SMARTEDITORSUS-1504] 표 리사이즈용 gripper 배치 개선
  16151. //this.htResizing.nResizeMode = 2;
  16152. this.htResizing.nResizeMode = 4;
  16153. // --[SMARTEDITORSUS-1504]
  16154. }
  16155. }
  16156. // bottom border of the cell is selected
  16157. // [SMARTEDITORSUS-1504] 표 모서리 Drag 사용성 개선
  16158. //if(this.htResizing.elCell.offsetHeight-nAdjustedDraggableCellEdge2 <= this.htResizing.htEPos.offsetY){
  16159. if(nBottomBorderCriteria <= nAdjustedDraggableCellEdge2){
  16160. this.htResizing.nBorderTopPos = this.htResizing.elCell.offsetHeight + nAdjustedDraggableCellEdge1 - 1;
  16161. this.htResizing.nResizeMode = 2;
  16162. }
  16163. // --[SMARTEDITORSUS-1504]
  16164. // left border of the cell is selected
  16165. if(this.htResizing.htEPos.offsetX <= nAdjustedDraggableCellEdge1){
  16166. // left border of the first cell can't be dragged
  16167. // [SMARTEDITORSUS-1504] 표 리사이즈용 gripper 배치 개선
  16168. // 일반 표는 아래 if문을 거치지 않지만, 글양식의 경우 가장 좌측 cell의 previousSibling이 textNode이기 때문에 if문에 부합하는 문제가 있었다.
  16169. /*if(this.htResizing.elCell.previousSibling){
  16170. this.htResizing.nHA = -1;
  16171. this.htResizing.nResizeMode = 0;
  16172. }*/
  16173. // 가장 좌측의 cell은 그 offsetLeft가 table의 scrollLeft와 같다.
  16174. if(this.htResizing.elTable.scrollLeft != this.htResizing.elCell.offsetLeft){
  16175. this.htResizing.nHA = -1;
  16176. this.htResizing.nResizeMode = 3;
  16177. }
  16178. // --[SMARTEDITORSUS-1504]
  16179. }
  16180. // right border of the cell is selected
  16181. // [SMARTEDITORSUS-1504] 표 모서리 Drag 사용성 개선
  16182. //if(this.htResizing.elCell.offsetWidth - nAdjustedDraggableCellEdge2 <= this.htResizing.htEPos.offsetX){
  16183. if(nRightBorderCriteria <= nAdjustedDraggableCellEdge1){
  16184. this.htResizing.nBorderLeftPos = this.htResizing.elCell.offsetWidth + nAdjustedDraggableCellEdge1 - 1;
  16185. this.htResizing.nResizeMode = 1;
  16186. }
  16187. // --[SMARTEDITORSUS-1504]
  16188. // [SMARTEDITORSUS-1504] 표 모서리 Drag 사용성 개선
  16189. if(jindo.$Agent().navigator().chrome || jindo.$Agent().navigator().safari){
  16190. if(!this.htResizing.elPreviousCell){
  16191. this.htResizing.elPreviousCell = this.htResizing.elCell;
  16192. }else{
  16193. if(this.htResizing.elCell != this.htResizing.elPreviousCell){
  16194. this.htResizing.elPreviousCell = this.htResizing.elCell;
  16195. }
  16196. }
  16197. }
  16198. // --[SMARTEDITORSUS-1504]
  16199. if(this.htResizing.nResizeMode === 0){return false;}
  16200. return true;
  16201. },
  16202. _showCellResizeGrip : function(){
  16203. // [SMARTEDITORSUS-2136] 표 상단 테두리에는 resize grip을 표시하지 않는다.
  16204. if(this.htResizing.nResizeMode == 4){
  16205. return;
  16206. }
  16207. // --[SMARTEDITORSUS-2136]
  16208. // [SMARTEDITORSUS-1504] gripper가 WYSIWYG 편집영역 위치정보에 기반하여 배치되도록 변경
  16209. // 만약 iframe 내부에 gripper를 생성한다면, 커서 위치를 기반으로 생성해 주면 됨
  16210. if(this.htResizing.nResizeMode == 1 || this.htResizing.nResizeMode == 3){
  16211. this.elResizeCover.style.cursor = "col-resize";
  16212. }else if(this.htResizing.nResizeMode == 2){
  16213. this.elResizeCover.style.cursor = "row-resize";
  16214. }
  16215. this._showResizer();
  16216. // gripper는 대상 셀에서 어느 경계 위에 커서가 위치했느냐에 기반하여 배치
  16217. if(this.htResizing.nResizeMode == 1){ // 오른쪽 경계
  16218. this._setResizerSize((this.htResizing.nBorderSize + this.nDraggableCellEdge) * 2, this.parseIntOr0(jindo.$Element(this.elIFrame).css("height")));
  16219. this.elResizeGrid.style.top = "0px";
  16220. this.elResizeGrid.style.left = this.htResizing.elCell.clientWidth + this.htResizing.htEPos.clientX - this.htResizing.htEPos.offsetX - this.parseIntOr0(this.elResizeGrid.style.width)/2 + "px";
  16221. }else if(this.htResizing.nResizeMode == 2){ // 아래쪽 경계
  16222. //가변폭을 지원하기 때문에 매번 현재 Container의 크기를 구해와서 Grip을 생성해야 한다.
  16223. var elIFrameWidth = this.oApp.elEditingAreaContainer.offsetWidth + "px";
  16224. this._setResizerSize(this.parseIntOr0(elIFrameWidth), (this.htResizing.nBorderSize + this.nDraggableCellEdge) * 2);
  16225. this.elResizeGrid.style.top = this.htResizing.elCell.clientHeight + this.htResizing.htEPos.clientY - this.htResizing.htEPos.offsetY - this.parseIntOr0(this.elResizeGrid.style.height)/2 + "px";
  16226. this.elResizeGrid.style.left = "0px";
  16227. }else if(this.htResizing.nResizeMode == 3){ // 왼쪽 경계
  16228. this._setResizerSize((this.htResizing.nBorderSize + this.nDraggableCellEdge) * 2, this.parseIntOr0(jindo.$Element(this.elIFrame).css("height")));
  16229. this.elResizeGrid.style.top = "0px";
  16230. this.elResizeGrid.style.left = + this.htResizing.htEPos.clientX - this.htResizing.htEPos.offsetX - this.parseIntOr0(this.elResizeGrid.style.width)/2 + "px";
  16231. // 이후 작업들은 오른쪽 경계를 기준으로 일괄처리
  16232. this.htResizing.nResizeMode = 1;
  16233. }
  16234. // --[SMARTEDITORSUS-1504]
  16235. },
  16236. _getAllAffectedCells : function(basis_x, basis_y, iResizeMode, oTable){
  16237. if(!oTable){return [];}
  16238. var oTbl = this._getCellMapping(oTable);
  16239. var iTblX = oTbl.length;
  16240. var iTblY = oTbl[0].length;
  16241. // 선택 테두리의 앞쪽 셀
  16242. var aCellsBefore = [];
  16243. // 선택 테두리의 뒤쪽 셀
  16244. var aCellsAfter = [];
  16245. var htResult;
  16246. var nMinBefore = -1, nMinAfter = -1;
  16247. // horizontal resizing -> need to get vertical rows
  16248. if(iResizeMode == 1){
  16249. for(var y = 0; y < iTblY; y++){
  16250. if(aCellsBefore.length>0 && aCellsBefore[aCellsBefore.length-1] == oTbl[basis_x][y]){continue;}
  16251. aCellsBefore[aCellsBefore.length] = oTbl[basis_x][y];
  16252. var nWidth = parseInt(oTbl[basis_x][y].style.width);
  16253. if(nMinBefore == -1 || nMinBefore > nWidth){
  16254. nMinBefore = nWidth;
  16255. }
  16256. }
  16257. if(oTbl.length > basis_x+1){
  16258. for(var y = 0; y < iTblY; y++){
  16259. if(aCellsAfter.length>0 && aCellsAfter[aCellsAfter.length-1] == oTbl[basis_x+1][y]){continue;}
  16260. aCellsAfter[aCellsAfter.length] = oTbl[basis_x+1][y];
  16261. var nWidth = parseInt(oTbl[basis_x + 1][y].style.width);
  16262. if(nMinAfter == -1 || nMinAfter > nWidth){
  16263. nMinAfter = nWidth;
  16264. }
  16265. }
  16266. }
  16267. htResult = {aCellsBefore: aCellsBefore, aCellsAfter: aCellsAfter, nMinBefore: nMinBefore, nMinAfter: nMinAfter};
  16268. }else{
  16269. for(var x = 0; x < iTblX; x++){
  16270. if(aCellsBefore.length>0 && aCellsBefore[aCellsBefore.length - 1] == oTbl[x][basis_y]){continue;}
  16271. aCellsBefore[aCellsBefore.length] = oTbl[x][basis_y];
  16272. if(nMinBefore == -1 || nMinBefore > oTbl[x][basis_y].style.height){
  16273. nMinBefore = oTbl[x][basis_y].style.height;
  16274. }
  16275. }
  16276. // 높이 리사이징 시에는 선택 테두리 앞쪽 셀만 조절 함으로 아래쪽 셀은 생성 할 필요 없음
  16277. htResult = {aCellsBefore: aCellsBefore, aCellsAfter: aCellsAfter, nMinBefore: nMinBefore, nMinAfter: nMinAfter};
  16278. }
  16279. return htResult;
  16280. },
  16281. _createCellResizeGrip : function(){
  16282. this.elTmp = document.createElement("DIV");
  16283. try{
  16284. this.elTmp.innerHTML = '<div style="position:absolute; overflow:hidden; z-index: 99; "><div onmousedown="return false" style="background-color:#000000;filter:alpha(opacity=0);opacity:0.0;-moz-opacity:0.0;-khtml-opacity:0.0;cursor: col-resize; left: 0px; top: 0px; width: 100%; height: 100%;font-size:1px;z-index: 999; "></div></div>';
  16285. this.elResizeGrid = this.elTmp.firstChild;
  16286. this.elResizeCover = this.elResizeGrid.firstChild;
  16287. }catch(e){}
  16288. // [SMARTEDITORSUS-1504] gripper를 WYSIWYG 편집 영역 위치 정보에 기반하여 배치하도록 개선
  16289. //document.body.appendChild(this.elResizeGrid);
  16290. // document.body 대신 WYSIWYG 편집 영역을 둘러싼 container div에 추가
  16291. var oContainer = jindo.$$.getSingle(".husky_seditor_editing_area_container");
  16292. oContainer.appendChild(this.elResizeGrid);
  16293. // --[SMARTEDITORSUS-1504]
  16294. },
  16295. _selectAll_Row : function(){
  16296. this.htSelectionSPos.x = 0;
  16297. this.htSelectionEPos.x = this.htMap.length - 1;
  16298. this._selectCells(this.htSelectionSPos, this.htSelectionEPos);
  16299. },
  16300. _selectAll_Column : function(){
  16301. this.htSelectionSPos.y = 0;
  16302. this.htSelectionEPos.y = this.htMap[0].length - 1;
  16303. this._selectCells(this.htSelectionSPos, this.htSelectionEPos);
  16304. },
  16305. _deleteSelectedCells : function(){
  16306. var elTmp;
  16307. for(var i = 0, nLen = this.aSelectedCells.length; i < nLen; i++){
  16308. elTmp = this.aSelectedCells[i];
  16309. // [SMARTEDITORSUS-1533] 삭제되는 열 바로 뒤에 인접한 빈 텍스트 노드도 함께 삭제하여 DOM 트리 일관성 유지
  16310. var htBrowser = jindo.$Agent().navigator();
  16311. if(htBrowser.ie && (htBrowser.nativeVersion == 9 || htBrowser.nativeVersion == 10) && (htBrowser.version == 9 || htBrowser.version == 10)){
  16312. this._removeEmptyTextNode_IE(elTmp);
  16313. }
  16314. // --[SMARTEDITORSUS-1533]
  16315. elTmp.parentNode.removeChild(elTmp);
  16316. }
  16317. var aTR = jindo.$$(">TBODY>TR", this.elSelectionStartTable, {oneTimeOffCache:true});
  16318. var nSelectionWidth = this.htSelectionEPos.x - this.htSelectionSPos.x + 1;
  16319. var nWidth = this.htMap.length;
  16320. if(nSelectionWidth == nWidth){
  16321. for(var i = 0, nLen = aTR.length; i < nLen; i++){
  16322. elTmp = aTR[i];
  16323. // There can be empty but necessary TR's because of Rowspan
  16324. if(!this.htMap[0][i] || !this.htMap[0][i].parentNode || this.htMap[0][i].parentNode.tagName !== "TR"){
  16325. // [SMARTEDITORSUS-1533] 삭제되는 행 바로 뒤에 인접한 빈 텍스트 노드도 함께 삭제하여 DOM 트리 일관성 유지
  16326. var htBrowser = jindo.$Agent().navigator();
  16327. if(htBrowser.ie && (htBrowser.nativeVersion == 9 || htBrowser.nativeVersion == 10) && (htBrowser.version == 9 || htBrowser.version == 10)){
  16328. this._removeEmptyTextNode_IE(elTmp);
  16329. }
  16330. // --[SMARTEDITORSUS-1533]
  16331. elTmp.parentNode.removeChild(elTmp);
  16332. }
  16333. }
  16334. aTR = jindo.$$(">TBODY>TR", this.elSelectionStartTable, {oneTimeOffCache:true});
  16335. }
  16336. if(aTR.length < 1){
  16337. this.elSelectionStartTable.parentNode.removeChild(this.elSelectionStartTable);
  16338. }
  16339. this._updateSelection();
  16340. },
  16341. _insertColumnAfter : function(){
  16342. this._removeClassFromSelection();
  16343. this._hideTableTemplate(this.elSelectionStartTable);
  16344. var aTR = jindo.$$(">TBODY>TR", this.elSelectionStartTable, {oneTimeOffCache:true});
  16345. var sInserted;
  16346. var sTmpAttr_Inserted = "_tmp_inserted";
  16347. var elCell, elCellClone, elCurTR, elInsertionPt;
  16348. // copy each cells in the following order: top->down, right->left
  16349. // +---+---+---+---+
  16350. // |...|.2.|.1.|...|
  16351. // |---+---+.1.|...|
  16352. // |...|.3.|.1.|...|
  16353. // |...|.3.+---+...|
  16354. // |...|.3.|.4.+...|
  16355. // |...+---+---+...|
  16356. // |...|.6.|.5.|...|
  16357. // +---+---+---+---+
  16358. // [SMARTEDITORSUS-991] IE는 insertionPt의 previousSibling에도 배경색을 적용해줘야 할 필요가 있음.
  16359. var htBrowser = jindo.$Agent().navigator();
  16360. // --[SMARTEDITORSUS-991]
  16361. for(var y = 0, nYLen = this.htMap[0].length; y < nYLen; y++){
  16362. elCurTR = aTR[y];
  16363. for(var x = this.htSelectionEPos.x; x >= this.htSelectionSPos.x; x--){
  16364. elCell = this.htMap[x][y];
  16365. //sInserted = elCell.getAttribute(sTmpAttr_Inserted);
  16366. //if(sInserted){continue;}
  16367. //elCell.setAttribute(sTmpAttr_Inserted, "o");
  16368. elCellClone = this._shallowCloneTD(elCell);
  16369. // elCellClone의 outerHTML에 정상적인 rowSpan이 있더라도 IE에서는 이 위치에서 항상 1을 반환. (elCellClone.rowSpan & elCellClone.getAttribute("rowSpan")).
  16370. //var nSpan = parseInt(elCellClone.getAttribute("rowSpan"));
  16371. var nSpan = parseInt(elCell.getAttribute("rowSpan"));
  16372. if(nSpan > 1){
  16373. elCellClone.setAttribute("rowSpan", 1);
  16374. elCellClone.style.height = "";
  16375. }
  16376. nSpan = parseInt(elCell.getAttribute("colSpan"));
  16377. if(nSpan > 1){
  16378. elCellClone.setAttribute("colSpan", 1);
  16379. elCellClone.style.width = "";
  16380. }
  16381. // 현재 줄(TR)에 속한 셀(TD)을 찾아서 그 앞에 append 한다.
  16382. elInsertionPt = null;
  16383. for(var xx = this.htSelectionEPos.x; xx >= this.htSelectionSPos.x; xx--){
  16384. if(this.htMap[xx][y].parentNode == elCurTR){
  16385. elInsertionPt = this.htMap[xx][y].nextSibling;
  16386. break;
  16387. }
  16388. }
  16389. elCurTR.insertBefore(elCellClone, elInsertionPt);
  16390. // [SMARTEDITORSUS-1742][SMARTEDITORSUS-1842] 배경색이 바로 반영되지 않는 버그로 인해 명시
  16391. // [SMARTEDITORSUS-2155] Win10 Spartan
  16392. if((htBrowser.edge && (Math.floor(htBrowser.version) === 12)) || (htBrowser.ie && (htBrowser.nativeVersion >= 9 || htBrowser.nativeVersion <= 11) && (htBrowser.version >= 9 || htBrowser.version <= 11))){
  16393. elCellClone.style.cssText = elCellClone.style.cssText;
  16394. }
  16395. // --[SMARTEDITORSUS-1742][SMARTEDITORSUS-1842][SMARTEDITORSUS-2155]
  16396. }
  16397. }
  16398. // remove the insertion marker from the original cells
  16399. for(var i = 0, nLen = this.aSelectedCells.length; i < nLen; i++){
  16400. this.aSelectedCells[i].removeAttribute(sTmpAttr_Inserted);
  16401. }
  16402. var nSelectionWidth = this.htSelectionEPos.x - this.htSelectionSPos.x + 1;
  16403. var nSelectionHeight = this.htSelectionEPos.y - this.htSelectionSPos.y + 1;
  16404. this.htSelectionSPos.x += nSelectionWidth;
  16405. this.htSelectionEPos.x += nSelectionWidth;
  16406. this.htMap = this._getCellMapping(this.elSelectionStartTable);
  16407. this._selectCells(this.htSelectionSPos, this.htSelectionEPos);
  16408. this._showTableTemplate(this.elSelectionStartTable);
  16409. this._addClassToSelection();
  16410. this.sQEAction = "INSERT_TABLE_COLUMN";
  16411. this.oApp.exec("SHOW_COMMON_QE");
  16412. },
  16413. _insertRowBelow : function(){
  16414. this._selectAll_Row();
  16415. this._removeClassFromSelection();
  16416. this._hideTableTemplate(this.elSelectionStartTable);
  16417. var elRowClone;
  16418. var elTBody = this.htMap[0][0].parentNode.parentNode;
  16419. var aTRs = jindo.$$(">TR", elTBody, {oneTimeOffCache:true});
  16420. var elInsertionPt = aTRs[this.htSelectionEPos.y + 1] || null;
  16421. // [SMARTEDITORSUS-991] IE는 insertionPt의 previousSibling에도 배경색을 적용해줘야 할 필요가 있음.
  16422. var htBrowser = jindo.$Agent().navigator();
  16423. // --[SMARTEDITORSUS-991]
  16424. for(var y = this.htSelectionSPos.y; y <= this.htSelectionEPos.y; y++){
  16425. elRowClone = this._getTRCloneWithAllTD(y);
  16426. elTBody.insertBefore(elRowClone, elInsertionPt);
  16427. // [SMARTEDITORSUS-991] IE는 insertionPt의 previousSibling에도 추가로 배경색을 적용해줘야 할 필요가 있음.
  16428. //if(htBrowser.ie && htBrowser.nativeVersion >= 9){
  16429. // [SMARTEDITORSUS-1533] 문서모드가 9~10인 IE 9~10에서 빈 텍스트 노드가 인식된다.
  16430. // [SMARTEDITORSUS-1842]
  16431. // [SMARTEDITORSUS-2155] Win10 Spartan
  16432. if((htBrowser.edge && (Math.floor(htBrowser.version) === 12)) || (htBrowser.ie && (htBrowser.nativeVersion >= 9 || htBrowser.nativeVersion <= 11) && (htBrowser.version >= 9 || htBrowser.version <= 11))){
  16433. // --[SMARTEDITORSUS-1842][SMARTEDITORSUS-2155]
  16434. // 스타일을 적용시켜 줄 대상 tr
  16435. var elPreviousSiblingParent = this.htMap[0][y].parentNode;
  16436. var aOriginalPreviousSibling = elPreviousSiblingParent.childNodes;
  16437. var aPreviousSibling = [];
  16438. for(var i = 0, len = aOriginalPreviousSibling.length; i < len; i++){
  16439. // [SMARTEDITORSUS-1742]
  16440. //aPreviousSibling.push(aOriginalPreviousSibling[i]);
  16441. if(this._rxCellNames.test(aOriginalPreviousSibling[i].nodeName)){
  16442. aPreviousSibling.push(aOriginalPreviousSibling[i].cloneNode());
  16443. }
  16444. // --[SMARTEDITORSUS-1742]
  16445. }
  16446. // 배경색을 복사하기 위해 준비
  16447. var aCellClone = elRowClone.childNodes;
  16448. for(var i = 0, len = aCellClone.length; i < len; i++){
  16449. var elCloneTD = aCellClone[i];
  16450. var elPreviousTD = aPreviousSibling[i];
  16451. // [SMARTEDITORSUS-1639] 병합 후 추가시 JS 오류가 발생하는 문제가 있어 nodeName 확인
  16452. // [SMARTEDITORSUS-1672]
  16453. //if(elCloneTD.nodeName == "TD" && elPreviousTD && elPreviousTD.nodeName == "TD"){
  16454. if(this._rxCellNames.test(elCloneTD.nodeName) && elPreviousTD && this._rxCellNames.test(elPreviousTD.nodeName)){
  16455. // --[SMARTEDITORSUS-1672]
  16456. // [SMARTEDITORSUS-1742]
  16457. //elPreviousTD.style.backgroundColor = elCloneTD.style.backgroundColor;
  16458. elCloneTD.style.cssText = elPreviousTD.style.cssText;
  16459. // --[SMARTEDITORSUS-1742]
  16460. }
  16461. }
  16462. }
  16463. // --[SMARTEDITORSUS-991]
  16464. }
  16465. var nSelectionWidth = this.htSelectionEPos.x - this.htSelectionSPos.x + 1;
  16466. var nSelectionHeight = this.htSelectionEPos.y - this.htSelectionSPos.y + 1;
  16467. this.htSelectionSPos.y += nSelectionHeight;
  16468. this.htSelectionEPos.y += nSelectionHeight;
  16469. this.htMap = this._getCellMapping(this.elSelectionStartTable);
  16470. this._selectCells(this.htSelectionSPos, this.htSelectionEPos);
  16471. this._showTableTemplate(this.elSelectionStartTable);
  16472. this._addClassToSelection();
  16473. this.sQEAction = "INSERT_TABLE_ROW";
  16474. this.oApp.exec("SHOW_COMMON_QE");
  16475. },
  16476. _updateSelection : function(){
  16477. this.aSelectedCells = jindo.$A(this.aSelectedCells).filter(function(v){return (v.parentNode!==null && v.parentNode.parentNode!==null);}).$value();
  16478. },
  16479. _startCellSelection : function(){
  16480. this.htMap = this._getCellMapping(this.elSelectionStartTable);
  16481. // De-select the default selection
  16482. this.oApp.getEmptySelection().oBrowserSelection.selectNone();
  16483. if(this.oApp.oNavigator["safari"] || this.oApp.oNavigator["chrome"]){
  16484. this.oApp.getWYSIWYGDocument().onselectstart = function(){return false;};
  16485. }
  16486. var elIFrame = this.oApp.getWYSIWYGWindow().frameElement;
  16487. this.htEditingAreaPos = jindo.$Element(elIFrame).offset();
  16488. this.htEditingAreaPos.height = elIFrame.offsetHeight;
  16489. this.htEditingAreaPos.bottom = this.htEditingAreaPos.top + this.htEditingAreaPos.height;
  16490. this.htEditingAreaPos.width = elIFrame.offsetWidth;
  16491. this.htEditingAreaPos.right = this.htEditingAreaPos.left + this.htEditingAreaPos.width;
  16492. /*
  16493. if(!this.oNavigatorInfo["firefox"]){
  16494. this.oApp.exec("DISABLE_WYSIWYG", []);
  16495. }
  16496. */
  16497. this._changeTableEditorStatus(this.STATUS.CELL_SELECTING);
  16498. },
  16499. _selectBetweenCells : function(elCell1, elCell2){
  16500. this._deselectCells();
  16501. var oP1 = this._getBasisCellPosition(elCell1);
  16502. var oP2 = this._getBasisCellPosition(elCell2);
  16503. this._setEndPos(oP1);
  16504. this._setEndPos(oP2);
  16505. var oStartPos = {}, oEndPos = {};
  16506. oStartPos.x = Math.min(oP1.x, oP1.ex, oP2.x, oP2.ex);
  16507. oStartPos.y = Math.min(oP1.y, oP1.ey, oP2.y, oP2.ey);
  16508. oEndPos.x = Math.max(oP1.x, oP1.ex, oP2.x, oP2.ex);
  16509. oEndPos.y = Math.max(oP1.y, oP1.ey, oP2.y, oP2.ey);
  16510. this._selectCells(oStartPos, oEndPos);
  16511. },
  16512. _getNextCell : function(elCell){
  16513. while(elCell){
  16514. elCell = elCell.nextSibling;
  16515. if(elCell && elCell.tagName && elCell.tagName.match(/^TD|TH$/)){return elCell;}
  16516. }
  16517. return null;
  16518. },
  16519. _getCellMapping : function(elTable){
  16520. var aTR = jindo.$$(">TBODY>TR", elTable, {oneTimeOffCache:true});
  16521. var nTD = 0;
  16522. var aTD_FirstRow = aTR[0].childNodes;
  16523. /*
  16524. // remove empty TR's from the bottom of the table
  16525. for(var i=aTR.length-1; i>0; i--){
  16526. if(!aTR[i].childNodes || aTR[i].childNodes.length === 0){
  16527. aTR[i].parentNode.removeChild(aTR[i]);
  16528. aTR = aTR.slice(0, i);
  16529. if(this.htSelectionSPos.y>=i) this.htSelectionSPos.y--;
  16530. if(this.htSelectionEPos.y>=i) this.htSelectionEPos.y--;
  16531. }else{
  16532. break;
  16533. }
  16534. }
  16535. */
  16536. // count the number of columns
  16537. for(var i = 0; i < aTD_FirstRow.length; i++){
  16538. var elTmp = aTD_FirstRow[i];
  16539. if(!elTmp.tagName || !elTmp.tagName.match(/^TD|TH$/)){continue;}
  16540. if(elTmp.getAttribute("colSpan")){
  16541. nTD += this.parseIntOr0(elTmp.getAttribute("colSpan"));
  16542. }else{
  16543. nTD ++;
  16544. }
  16545. }
  16546. var nTblX = nTD;
  16547. var nTblY = aTR.length;
  16548. var aCellMapping = new Array(nTblX);
  16549. for(var x = 0; x < nTblX; x++){
  16550. aCellMapping[x] = new Array(nTblY);
  16551. }
  16552. for(var y = 0; y < nTblY; y++){
  16553. var elCell = aTR[y].childNodes[0];
  16554. if(!elCell){continue;}
  16555. if(!elCell.tagName || !elCell.tagName.match(/^TD|TH$/)){elCell = this._getNextCell(elCell);}
  16556. var x = -1;
  16557. while(elCell){
  16558. x++;
  16559. if(!aCellMapping[x]){aCellMapping[x] = [];}
  16560. if(aCellMapping[x][y]){continue;}
  16561. var colSpan = parseInt(elCell.getAttribute("colSpan"), 10) || 1;
  16562. var rowSpan = parseInt(elCell.getAttribute("rowSpan"), 10) || 1;
  16563. /*
  16564. if(y+rowSpan >= nTblY){
  16565. rowSpan = nTblY-y;
  16566. elCell.setAttribute("rowSpan", rowSpan);
  16567. }
  16568. */
  16569. for(var yy = 0; yy < rowSpan; yy++){
  16570. for(var xx = 0; xx < colSpan; xx++){
  16571. if(!aCellMapping[x+xx]){
  16572. aCellMapping[x+xx] = [];
  16573. }
  16574. aCellMapping[x+xx][y+yy] = elCell;
  16575. }
  16576. }
  16577. elCell = this._getNextCell(elCell);
  16578. }
  16579. }
  16580. // remove empty TR's
  16581. // (상단 TD의 rowspan만으로 지탱되는) 빈 TR이 있을 경우 IE7 이하에서 랜더링 오류가 발생 할 수 있어 빈 TR을 지워 줌
  16582. var bRowRemoved = false;
  16583. var elLastCell = null;
  16584. for(var y = 0, nRealY = 0, nYLen = aCellMapping[0].length; y < nYLen; y++, nRealY++){
  16585. elLastCell = null;
  16586. if(!aTR[y].innerHTML.match(/TD|TH/i)){
  16587. for(var x = 0, nXLen = aCellMapping.length; x < nXLen; x++){
  16588. elCell = aCellMapping[x][y];
  16589. if(!elCell || elCell === elLastCell){
  16590. continue;
  16591. }
  16592. elLastCell = elCell;
  16593. var rowSpan = parseInt(elCell.getAttribute("rowSpan"), 10) || 1;
  16594. if(rowSpan > 1){
  16595. elCell.setAttribute("rowSpan", rowSpan - 1);
  16596. }
  16597. }
  16598. // [SMARTEDITORSUS-1533]
  16599. var htBrowser = jindo.$Agent().navigator();
  16600. if(htBrowser.ie && (htBrowser.nativeVersion == 9 || htBrowser.nativeVersion == 10) && (htBrowser.version == 9 || htBrowser.version == 10)){
  16601. this._removeEmptyTextNode_IE(aTR[y]);
  16602. }
  16603. // --[SMARTEDITORSUS-1533]
  16604. aTR[y].parentNode.removeChild(aTR[y]);
  16605. if(this.htSelectionEPos.y >= nRealY){
  16606. nRealY--;
  16607. this.htSelectionEPos.y--;
  16608. }
  16609. bRowRemoved = true;
  16610. }
  16611. }
  16612. if(bRowRemoved){
  16613. return this._getCellMapping(elTable);
  16614. }
  16615. return aCellMapping;
  16616. },
  16617. _selectCells : function(htSPos, htEPos){
  16618. this.aSelectedCells = this._getSelectedCells(htSPos, htEPos);
  16619. this._addClassToSelection();
  16620. },
  16621. _deselectCells : function(){
  16622. this._removeClassFromSelection();
  16623. this.aSelectedCells = [];
  16624. this.htSelectionSPos = {x:-1, y:-1};
  16625. this.htSelectionEPos = {x:-1, y:-1};
  16626. },
  16627. _addClassToSelection : function(){
  16628. var welCell, elCell;
  16629. for(var i = 0; i < this.aSelectedCells.length; i++){
  16630. elCell = this.aSelectedCells[i];
  16631. // [SMARTEDITORSUS-1552] 드래그로 셀을 선택하는 중 elCell이 없는 경우 오류 발생
  16632. if(elCell){
  16633. // [SMARTEDITORSUS-1498][SMARTEDITORSUS-1549] 선택된 모든 셀에서 드래그가 발생하지 못하게 방지(FF, Chrome)
  16634. if(elCell.ondragstart == null){
  16635. elCell.ondragstart = function(){
  16636. return false;
  16637. };
  16638. }
  16639. // --[SMARTEDITORSUS-1498][SMARTEDITORSUS-1549]
  16640. welCell = jindo.$Element(elCell);
  16641. welCell.addClass(this.CELL_SELECTION_CLASS);
  16642. // [SMARTEDITORSUS-1498][SMARTEDITORSUS-1549] 선택된 모든 셀에서 드래그가 발생하지 못하게 방지(FF, Chrome)
  16643. welCell.addClass("undraggable");
  16644. // --[SMARTEDITORSUS-1498][SMARTEDITORSUS-1549]
  16645. if(elCell.style.backgroundColor){
  16646. elCell.setAttribute(this.TMP_BGC_ATTR, elCell.style.backgroundColor);
  16647. welCell.css("backgroundColor", "");
  16648. }
  16649. if(elCell.style.backgroundImage) {
  16650. elCell.setAttribute(this.TMP_BGIMG_ATTR, elCell.style.backgroundImage);
  16651. welCell.css("backgroundImage", "");
  16652. }
  16653. }
  16654. // --[SMARTEDITORSUS-1552]
  16655. }
  16656. },
  16657. _removeClassFromSelection : function(){
  16658. var welCell, elCell;
  16659. for(var i = 0; i < this.aSelectedCells.length; i++){
  16660. elCell = this.aSelectedCells[i];
  16661. // [SMARTEDITORSUS-1552] 드래그로 셀을 선택하는 중 elCell이 없는 경우 오류 발생
  16662. if(elCell){
  16663. welCell = jindo.$Element(elCell);
  16664. welCell.removeClass(this.CELL_SELECTION_CLASS);
  16665. // [SMARTEDITORSUS-1498][SMARTEDITORSUS-1549] 선택된 모든 셀에서 드래그가 발생하지 못하게 방지(FF, Chrome)
  16666. welCell.removeClass("undraggable");
  16667. // --[SMARTEDITORSUS-1498][SMARTEDITORSUS-1549]
  16668. //배경색
  16669. if(elCell.getAttribute(this.TMP_BGC_ATTR)){
  16670. elCell.style.backgroundColor = elCell.getAttribute(this.TMP_BGC_ATTR);
  16671. elCell.removeAttribute(this.TMP_BGC_ATTR);
  16672. }
  16673. //배경이미지
  16674. if(elCell.getAttribute(this.TMP_BGIMG_ATTR)) {
  16675. welCell.css("backgroundImage",elCell.getAttribute(this.TMP_BGIMG_ATTR));
  16676. elCell.removeAttribute(this.TMP_BGIMG_ATTR);
  16677. }
  16678. }
  16679. // --[SMARTEDITORSUS-1552]
  16680. }
  16681. },
  16682. _expandAndSelect : function(htPos1, htPos2){
  16683. var x, y, elTD, nTmp, i;
  16684. // expand top
  16685. if(htPos1.y > 0){
  16686. for(x = htPos1.x; x <= htPos2.x; x++){
  16687. elTD = this.htMap[x][htPos1.y];
  16688. if(this.htMap[x][htPos1.y - 1] == elTD){
  16689. nTmp = htPos1.y - 2;
  16690. while(nTmp >= 0 && this.htMap[x][nTmp] == elTD){
  16691. nTmp--;
  16692. }
  16693. htPos1.y = nTmp + 1;
  16694. this._expandAndSelect(htPos1, htPos2);
  16695. return;
  16696. }
  16697. }
  16698. }
  16699. // expand left
  16700. if(htPos1.x > 0){
  16701. for(y = htPos1.y; y <= htPos2.y; y++){
  16702. elTD = this.htMap[htPos1.x][y];
  16703. if(this.htMap[htPos1.x - 1][y] == elTD){
  16704. nTmp = htPos1.x - 2;
  16705. while(nTmp >= 0 && this.htMap[nTmp][y] == elTD){
  16706. nTmp--;
  16707. }
  16708. htPos1.x = nTmp + 1;
  16709. this._expandAndSelect(htPos1, htPos2);
  16710. return;
  16711. }
  16712. }
  16713. }
  16714. // expand bottom
  16715. if(htPos2.y < this.htMap[0].length - 1){
  16716. for(x = htPos1.x; x <= htPos2.x; x++){
  16717. elTD = this.htMap[x][htPos2.y];
  16718. if(this.htMap[x][htPos2.y + 1] == elTD){
  16719. nTmp = htPos2.y + 2;
  16720. while(nTmp < this.htMap[0].length && this.htMap[x][nTmp] == elTD){
  16721. nTmp++;
  16722. }
  16723. htPos2.y = nTmp - 1;
  16724. this._expandAndSelect(htPos1, htPos2);
  16725. return;
  16726. }
  16727. }
  16728. }
  16729. // expand right
  16730. if(htPos2.x < this.htMap.length - 1){
  16731. for(y = htPos1.y; y <= htPos2.y; y++){
  16732. elTD = this.htMap[htPos2.x][y];
  16733. if(this.htMap[htPos2.x + 1][y] == elTD){
  16734. nTmp = htPos2.x + 2;
  16735. while(nTmp < this.htMap.length && this.htMap[nTmp][y] == elTD){
  16736. nTmp++;
  16737. }
  16738. htPos2.x = nTmp - 1;
  16739. this._expandAndSelect(htPos1, htPos2);
  16740. return;
  16741. }
  16742. }
  16743. }
  16744. },
  16745. _getSelectedCells : function(htPos1, htPos2){
  16746. this._expandAndSelect(htPos1, htPos2);
  16747. var x1 = htPos1.x;
  16748. var y1 = htPos1.y;
  16749. var x2 = htPos2.x;
  16750. var y2 = htPos2.y;
  16751. this.htSelectionSPos = htPos1;
  16752. this.htSelectionEPos = htPos2;
  16753. var aResult = [];
  16754. for(var y = y1; y <= y2; y++){
  16755. for(var x = x1; x <= x2; x++){
  16756. if(jindo.$A(aResult).has(this.htMap[x][y])){
  16757. continue;
  16758. }
  16759. aResult[aResult.length] = this.htMap[x][y];
  16760. }
  16761. }
  16762. return aResult;
  16763. },
  16764. _setEndPos : function(htPos){
  16765. var nColspan, nRowspan;
  16766. nColspan = parseInt(htPos.elCell.getAttribute("colSpan"), 10) || 1;
  16767. nRowspan = parseInt(htPos.elCell.getAttribute("rowSpan"), 10) || 1;
  16768. htPos.ex = htPos.x + nColspan - 1;
  16769. htPos.ey = htPos.y + nRowspan - 1;
  16770. },
  16771. _getBasisCellPosition : function(elCell){
  16772. var x = 0, y = 0;
  16773. for(x = 0; x < this.htMap.length; x++){
  16774. for(y = 0; y < this.htMap[x].length; y++){
  16775. if(this.htMap[x][y] == elCell){
  16776. return {'x': x, 'y': y, elCell: elCell};
  16777. }
  16778. }
  16779. }
  16780. return {'x': 0, 'y': 0, elCell: elCell};
  16781. },
  16782. _applyTableTemplate : function(elTable, nTemplateIdx){
  16783. // clear style first if already exists
  16784. /*
  16785. if(elTable.getAttribute(this.ATTR_TBL_TEMPLATE)){
  16786. this._doApplyTableTemplate(elTable, nhn.husky.SE2M_TableTemplate[this.parseIntOr0(elTable.getAttribute(this.ATTR_TBL_TEMPLATE))], true);
  16787. }else{
  16788. this._clearAllTableStyles(elTable);
  16789. }
  16790. */
  16791. if (!elTable) {
  16792. return;
  16793. }
  16794. // 사용자가 지정한 스타일 무시하고 새 템플릿 적용
  16795. // http://bts.nhncorp.com/nhnbts/browse/COM-871
  16796. this._clearAllTableStyles(elTable);
  16797. this._doApplyTableTemplate(elTable, nhn.husky.SE2M_TableTemplate[nTemplateIdx], false);
  16798. elTable.setAttribute(this.ATTR_TBL_TEMPLATE, nTemplateIdx);
  16799. },
  16800. _clearAllTableStyles : function(elTable){
  16801. elTable.removeAttribute("border");
  16802. elTable.removeAttribute("cellPadding");
  16803. elTable.removeAttribute("cellSpacing");
  16804. elTable.style.padding = "";
  16805. elTable.style.border = "";
  16806. elTable.style.backgroundColor = "";
  16807. elTable.style.color = "";
  16808. var aTD = jindo.$$(">TBODY>TR>TD", elTable, {oneTimeOffCache:true});
  16809. for(var i = 0, nLen = aTD.length; i < nLen; i++){
  16810. aTD[i].style.padding = "";
  16811. aTD[i].style.border = "";
  16812. aTD[i].style.backgroundColor = "";
  16813. aTD[i].style.color = "";
  16814. }
  16815. // [SMARTEDITORSUS-1672]
  16816. var aTH = jindo.$$(">TBODY>TR>TH", elTable, {oneTimeOffCache:true});
  16817. for(var i = 0, nLen = aTH.length; i < nLen; i++){
  16818. aTH[i].style.padding = "";
  16819. aTH[i].style.border = "";
  16820. aTH[i].style.backgroundColor = "";
  16821. aTH[i].style.color = "";
  16822. }
  16823. // --[SMARTEDITORSUS-1672]
  16824. },
  16825. _hideTableTemplate : function(elTable){
  16826. if(elTable.getAttribute(this.ATTR_TBL_TEMPLATE)){
  16827. this._doApplyTableTemplate(elTable, nhn.husky.SE2M_TableTemplate[this.parseIntOr0(elTable.getAttribute(this.ATTR_TBL_TEMPLATE))], true);
  16828. }
  16829. },
  16830. _showTableTemplate : function(elTable){
  16831. if(elTable.getAttribute(this.ATTR_TBL_TEMPLATE)){
  16832. this._doApplyTableTemplate(elTable, nhn.husky.SE2M_TableTemplate[this.parseIntOr0(elTable.getAttribute(this.ATTR_TBL_TEMPLATE))], false);
  16833. }
  16834. },
  16835. _doApplyTableTemplate : function(elTable, htTableTemplate, bClearStyle){
  16836. var htTableProperty = htTableTemplate.htTableProperty;
  16837. var htTableStyle = htTableTemplate.htTableStyle;
  16838. var ht1stRowStyle = htTableTemplate.ht1stRowStyle;
  16839. var ht1stColumnStyle = htTableTemplate.ht1stColumnStyle;
  16840. var aRowStyle = htTableTemplate.aRowStyle;
  16841. var elTmp;
  16842. // replace all TH's with TD's
  16843. if(htTableProperty){
  16844. this._copyAttributesTo(elTable, htTableProperty, bClearStyle);
  16845. }
  16846. if(htTableStyle){
  16847. this._copyStylesTo(elTable, htTableStyle, bClearStyle);
  16848. }
  16849. var aTR = jindo.$$(">TBODY>TR", elTable, {oneTimeOffCache:true});
  16850. var nStartRowNum = 0;
  16851. if(ht1stRowStyle){
  16852. var nStartRowNum = 1;
  16853. for(var ii = 0, nNumCells = aTR[0].childNodes.length; ii < nNumCells; ii++){
  16854. elTmp = aTR[0].childNodes[ii];
  16855. if(!elTmp.tagName || !elTmp.tagName.match(/^TD|TH$/)){continue;}
  16856. this._copyStylesTo(elTmp, ht1stRowStyle, bClearStyle);
  16857. }
  16858. }
  16859. var nRowSpan;
  16860. var elFirstEl;
  16861. if(ht1stColumnStyle){
  16862. // if the style's got a row heading, skip the 1st row. (it was taken care above)
  16863. var nRowStart = ht1stRowStyle ? 1 : 0;
  16864. for(var i = nRowStart, nLen = aTR.length; i < nLen;){
  16865. elFirstEl = aTR[i].firstChild;
  16866. nRowSpan = 1;
  16867. if(elFirstEl && elFirstEl.tagName.match(/^TD|TH$/)){
  16868. nRowSpan = parseInt(elFirstEl.getAttribute("rowSpan"), 10) || 1;
  16869. this._copyStylesTo(elFirstEl, ht1stColumnStyle, bClearStyle);
  16870. }
  16871. i += nRowSpan;
  16872. }
  16873. }
  16874. if(aRowStyle){
  16875. var nNumStyles = aRowStyle.length;
  16876. for(var i = nStartRowNum, nLen = aTR.length; i < nLen; i++){
  16877. for(var ii = 0, nNumCells = aTR[i].childNodes.length; ii < nNumCells; ii++){
  16878. var elTmp = aTR[i].childNodes[ii];
  16879. if(!elTmp.tagName || !elTmp.tagName.match(/^TD|TH$/)){continue;}
  16880. this._copyStylesTo(elTmp, aRowStyle[(i+nStartRowNum)%nNumStyles], bClearStyle);
  16881. }
  16882. }
  16883. }
  16884. },
  16885. _copyAttributesTo : function(oTarget, htProperties, bClearStyle){
  16886. var elTmp;
  16887. for(var x in htProperties){
  16888. if(htProperties.hasOwnProperty(x)){
  16889. if(bClearStyle){
  16890. if(oTarget[x]){
  16891. elTmp = document.createElement(oTarget.tagName);
  16892. elTmp[x] = htProperties[x];
  16893. if(elTmp[x] == oTarget[x]){
  16894. oTarget.removeAttribute(x);
  16895. }
  16896. }
  16897. }else{
  16898. elTmp = document.createElement(oTarget.tagName);
  16899. elTmp.style[x] = "";
  16900. if(!oTarget[x] || oTarget.style[x] == elTmp.style[x]){oTarget.setAttribute(x, htProperties[x]);}
  16901. }
  16902. }
  16903. }
  16904. },
  16905. _copyStylesTo : function(oTarget, htProperties, bClearStyle){
  16906. var elTmp;
  16907. for(var x in htProperties){
  16908. if(htProperties.hasOwnProperty(x)){
  16909. if(bClearStyle){
  16910. if(oTarget.style[x]){
  16911. elTmp = document.createElement(oTarget.tagName);
  16912. elTmp.style[x] = htProperties[x];
  16913. if(elTmp.style[x] == oTarget.style[x]){
  16914. oTarget.style[x] = "";
  16915. }
  16916. }
  16917. }else{
  16918. elTmp = document.createElement(oTarget.tagName);
  16919. elTmp.style[x] = "";
  16920. if(!oTarget.style[x] || oTarget.style[x] == elTmp.style[x] || x.match(/^border/)){oTarget.style[x] = htProperties[x];}
  16921. }
  16922. }
  16923. }
  16924. },
  16925. _hideResizer : function(){
  16926. this.elResizeGrid.style.display = "none";
  16927. },
  16928. _showResizer : function(){
  16929. this.elResizeGrid.style.display = "block";
  16930. },
  16931. _setResizerSize : function(width, height){
  16932. this.elResizeGrid.style.width = width + "px";
  16933. this.elResizeGrid.style.height = height + "px";
  16934. },
  16935. parseBorder : function(vBorder, sBorderStyle){
  16936. if(sBorderStyle == "none"){return 0;}
  16937. var num = parseInt(vBorder, 10);
  16938. if(isNaN(num)){
  16939. if(typeof(vBorder) == "string"){
  16940. // IE Bug
  16941. return 1;
  16942. /*
  16943. switch(vBorder){
  16944. case "thin":
  16945. return 1;
  16946. case "medium":
  16947. return 3;
  16948. case "thick":
  16949. return 5;
  16950. }
  16951. */
  16952. }
  16953. }
  16954. return num;
  16955. },
  16956. parseIntOr0 : function(num){
  16957. num = parseInt(num, 10);
  16958. if(isNaN(num)){return 0;}
  16959. return num;
  16960. },
  16961. _getTRCloneWithAllTD : function(nRow){
  16962. var elResult = this.htMap[0][nRow].parentNode.cloneNode(false);
  16963. var elCurTD, elCurTDClone;
  16964. for(var i = 0, nLen = this.htMap.length; i < nLen; i++){
  16965. elCurTD = this.htMap[i][nRow];
  16966. // [SMARTEDITORSUS-1672]
  16967. //if(elCurTD.tagName == "TD"){
  16968. if(this._rxCellNames.test(elCurTD.tagName)){
  16969. // --[SMARTEDITORSUS-1672]
  16970. elCurTDClone = this._shallowCloneTD(elCurTD);
  16971. elCurTDClone.setAttribute("rowSpan", 1);
  16972. elCurTDClone.setAttribute("colSpan", 1);
  16973. elCurTDClone.style.width = "";
  16974. elCurTDClone.style.height = "";
  16975. elResult.insertBefore(elCurTDClone, null);
  16976. }
  16977. }
  16978. return elResult;
  16979. },
  16980. _shallowCloneTD : function(elTD){
  16981. var elResult = elTD.cloneNode(false);
  16982. elResult.innerHTML = this.sEmptyTDSrc;
  16983. return elResult;
  16984. },
  16985. // elTbl이 꽉 찬 직사각형 형태의 테이블인지 확인
  16986. _isValidTable : function(elTbl){
  16987. if(!elTbl || !elTbl.tagName || elTbl.tagName != "TABLE"){
  16988. return false;
  16989. }
  16990. this.htMap = this._getCellMapping(elTbl);
  16991. var nXSize = this.htMap.length;
  16992. if(nXSize < 1){return false;}
  16993. var nYSize = this.htMap[0].length;
  16994. if(nYSize < 1){return false;}
  16995. for(var i = 1; i < nXSize; i++){
  16996. // 첫번째 열과 길이가 다른 열이 하나라도 있다면 직사각형이 아님
  16997. if(this.htMap[i].length != nYSize || !this.htMap[i][nYSize - 1]){
  16998. return false;
  16999. }
  17000. // 빈칸이 하나라도 있다면 꽉 찬 직사각형이 아님
  17001. for(var j = 0; j < nYSize; j++){
  17002. if(!this.htMap[i] || !this.htMap[i][j]){
  17003. return false;
  17004. }
  17005. }
  17006. }
  17007. return true;
  17008. },
  17009. addCSSClass : function(sClassName, sClassRule){
  17010. var oDoc = this.oApp.getWYSIWYGDocument();
  17011. if(oDoc.styleSheets[0] && oDoc.styleSheets[0].addRule){
  17012. // IE
  17013. oDoc.styleSheets[0].addRule("." + sClassName, sClassRule);
  17014. }else{
  17015. // FF
  17016. var elHead = oDoc.getElementsByTagName("HEAD")[0];
  17017. var elStyle = oDoc.createElement ("STYLE");
  17018. //styleElement.type = "text / css";
  17019. elHead.appendChild (elStyle);
  17020. elStyle.sheet.insertRule("." + sClassName + " { "+sClassRule+" }", 0);
  17021. }
  17022. },
  17023. // [SMARTEDITORSUS-1533]
  17024. _removeEmptyTextNode_IE : function(elPair){
  17025. var elEmptyTextNode = elPair.nextSibling;
  17026. if(elEmptyTextNode && elEmptyTextNode.nodeType == 3 && !/\S/.test(elEmptyTextNode.nodeValue)){
  17027. elPair.parentNode.removeChild(elEmptyTextNode);
  17028. }
  17029. }
  17030. // --[SMARTEDITORSUS-1533]
  17031. //@lazyload_js]
  17032. });
  17033. nhn.husky.HuskyCore.addLoadedFile("hp_SE2M_BGColor$Lazy.js");
  17034. /**
  17035. * @depends nhn.husky.SE2M_BGColor
  17036. * this.oApp.registerLazyMessage(["APPLY_LAST_USED_BGCOLOR", "TOGGLE_BGCOLOR_LAYER"], ["hp_SE2M_BGColor$Lazy.js"]);
  17037. */
  17038. nhn.husky.HuskyCore.mixin(nhn.husky.SE2M_BGColor, {
  17039. //@lazyload_js APPLY_LAST_USED_BGCOLOR,TOGGLE_BGCOLOR_LAYER[
  17040. $ON_TOGGLE_BGCOLOR_LAYER : function(){
  17041. this.oApp.exec("TOGGLE_TOOLBAR_ACTIVE_LAYER", [this.elDropdownLayer, null, "BGCOLOR_LAYER_SHOWN", [], "BGCOLOR_LAYER_HIDDEN", []]);
  17042. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['bgcolor']);
  17043. },
  17044. $ON_BGCOLOR_LAYER_SHOWN : function(){
  17045. this.oApp.exec("SELECT_UI", ["BGColorB"]);
  17046. this.oApp.exec("SHOW_COLOR_PALETTE", ["APPLY_BGCOLOR", this.elPaletteHolder]);
  17047. },
  17048. $ON_BGCOLOR_LAYER_HIDDEN : function(){
  17049. this.oApp.exec("DESELECT_UI", ["BGColorB"]);
  17050. this.oApp.exec("RESET_COLOR_PALETTE", []);
  17051. },
  17052. $ON_EVENT_APPLY_BGCOLOR : function(weEvent){
  17053. var elButton = weEvent.element;
  17054. // Safari/Chrome/Opera may capture the event on Span
  17055. while(elButton.tagName == "SPAN"){elButton = elButton.parentNode;}
  17056. if(elButton.tagName != "BUTTON"){return;}
  17057. var sBGColor, sFontColor;
  17058. sBGColor = elButton.style.backgroundColor;
  17059. sFontColor = elButton.style.color;
  17060. this.oApp.exec("APPLY_BGCOLOR", [sBGColor, sFontColor]);
  17061. },
  17062. $ON_APPLY_LAST_USED_BGCOLOR : function(){
  17063. this.oApp.exec("APPLY_BGCOLOR", [this.sLastUsedColor]);
  17064. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['bgcolor']);
  17065. },
  17066. $ON_APPLY_BGCOLOR : function(sBGColor, sFontColor){
  17067. if(!this.rxColorPattern.test(sBGColor)){
  17068. alert(this.oApp.$MSG("SE_Color.invalidColorCode"));
  17069. return;
  17070. }
  17071. this._setLastUsedBGColor(sBGColor);
  17072. var oStyle = {"backgroundColor": sBGColor};
  17073. if(sFontColor){oStyle.color = sFontColor;}
  17074. this.oApp.exec("SET_WYSIWYG_STYLE", [oStyle]);
  17075. this.oApp.exec("HIDE_ACTIVE_LAYER");
  17076. }
  17077. //@lazyload_js]
  17078. });
  17079. nhn.husky.HuskyCore.addLoadedFile("hp_SE2M_FontColor$Lazy.js");
  17080. /**
  17081. * @depends nhn.husky.SE2M_FontColor
  17082. * this.oApp.registerLazyMessage(["APPLY_LAST_USED_FONTCOLOR", "TOGGLE_FONTCOLOR_LAYER"], ["hp_SE2M_FontColor$Lazy.js"]);
  17083. */
  17084. nhn.husky.HuskyCore.mixin(nhn.husky.SE2M_FontColor, {
  17085. //@lazyload_js APPLY_LAST_USED_FONTCOLOR,TOGGLE_FONTCOLOR_LAYER[
  17086. $ON_TOGGLE_FONTCOLOR_LAYER : function(){
  17087. this.oApp.exec("TOGGLE_TOOLBAR_ACTIVE_LAYER", [this.elDropdownLayer, null, "FONTCOLOR_LAYER_SHOWN", [], "FONTCOLOR_LAYER_HIDDEN", []]);
  17088. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['fontcolor']);
  17089. },
  17090. $ON_FONTCOLOR_LAYER_SHOWN : function(){
  17091. this.oApp.exec("SELECT_UI", ["fontColorB"]);
  17092. this.oApp.exec("SHOW_COLOR_PALETTE", ["APPLY_FONTCOLOR", this.elPaletteHolder]);
  17093. },
  17094. $ON_FONTCOLOR_LAYER_HIDDEN : function(){
  17095. this.oApp.exec("DESELECT_UI", ["fontColorB"]);
  17096. this.oApp.exec("RESET_COLOR_PALETTE", []);
  17097. },
  17098. $ON_APPLY_LAST_USED_FONTCOLOR : function(){
  17099. this.oApp.exec("APPLY_FONTCOLOR", [this.sLastUsedColor]);
  17100. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['fontcolor']);
  17101. },
  17102. $ON_APPLY_FONTCOLOR : function(sFontColor){
  17103. if(!this.rxColorPattern.test(sFontColor)){
  17104. alert(this.oApp.$MSG("SE_FontColor.invalidColorCode"));
  17105. return;
  17106. }
  17107. this._setLastUsedFontColor(sFontColor);
  17108. this.oApp.exec("SET_WYSIWYG_STYLE", [{"color":sFontColor}]);
  17109. // [SMARTEDITORSUS-907] 모든 브라우저에서 SET_WYSIWYG_STYLE로 색상을 설정하도록 변경
  17110. // var oAgent = jindo.$Agent().navigator();
  17111. // if( oAgent.ie || oAgent.firefox ){ // [SMARTEDITORSUS-658] Firefox 추가
  17112. // this.oApp.exec("SET_WYSIWYG_STYLE", [{"color":sFontColor}]);
  17113. // } else {
  17114. // var bDontAddUndoHistory = false;
  17115. // if(this.oApp.getSelection().collapsed){
  17116. // bDontAddUndoHistory = true;
  17117. // }
  17118. // this.oApp.exec("EXECCOMMAND", ["ForeColor", false, sFontColor, { "bDontAddUndoHistory" : bDontAddUndoHistory }]);
  17119. // if(bDontAddUndoHistory){
  17120. // this.oApp.exec("RECORD_UNDO_ACTION", ["FONT COLOR", {bMustBlockElement : true}]);
  17121. // }
  17122. // }
  17123. this.oApp.exec("HIDE_ACTIVE_LAYER");
  17124. }
  17125. //@lazyload_js]
  17126. });
  17127. nhn.husky.HuskyCore.addLoadedFile("hp_SE2M_Hyperlink$Lazy.js");
  17128. /**
  17129. * @depends nhn.husky.SE2M_Hyperlink
  17130. * this.oApp.registerLazyMessage(["TOGGLE_HYPERLINK_LAYER", "APPLY_HYPERLINK"], ["hp_SE2M_Hyperlink$Lazy.js"]);
  17131. */
  17132. nhn.husky.HuskyCore.mixin(nhn.husky.SE2M_Hyperlink, {
  17133. //@lazyload_js TOGGLE_HYPERLINK_LAYER,APPLY_HYPERLINK[
  17134. $ON_TOGGLE_HYPERLINK_LAYER : function(){
  17135. if(!this.bLayerShown){
  17136. this.oApp.exec("IE_FOCUS", []);
  17137. this.oSelection = this.oApp.getSelection();
  17138. }
  17139. // hotkey may close the layer right away so delay here
  17140. this.oApp.delayedExec("TOGGLE_TOOLBAR_ACTIVE_LAYER", [this.oHyperlinkLayer, null, "MSG_HYPERLINK_LAYER_SHOWN", [], "MSG_HYPERLINK_LAYER_HIDDEN", [""]], 0);
  17141. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['hyperlink']);
  17142. },
  17143. $ON_MSG_HYPERLINK_LAYER_SHOWN : function(){
  17144. this.bLayerShown = true;
  17145. var oAnchor = this.oSelection.findAncestorByTagName("A");
  17146. if (!oAnchor) {
  17147. oAnchor = this._getSelectedNode();
  17148. }
  17149. //this.oCbNewWin.checked = false;
  17150. if(oAnchor && !this.oSelection.collapsed){
  17151. this.oSelection.selectNode(oAnchor);
  17152. this.oSelection.select();
  17153. var sTarget = oAnchor.target;
  17154. //if(sTarget && sTarget == "_blank"){this.oCbNewWin.checked = true;}
  17155. // href속성에 문제가 있을 경우, 예: href="http://na&nbsp;&nbsp; ver.com", IE에서 oAnchor.href 접근 시에 알수 없는 오류를 발생시킴
  17156. try{
  17157. var sHref = oAnchor.getAttribute("href");
  17158. this.oLinkInput.value = sHref && sHref.indexOf("#") == -1 ? sHref : "http://";
  17159. }catch(e){
  17160. this.oLinkInput.value = "http://";
  17161. }
  17162. this.bModify = true;
  17163. }else{
  17164. this.oLinkInput.value = "http://";
  17165. this.bModify = false;
  17166. }
  17167. this.oApp.delayedExec("SELECT_UI", ["hyperlink"], 0);
  17168. this.oLinkInput.focus();
  17169. this.oLinkInput.value = this.oLinkInput.value;
  17170. this.oLinkInput.select();
  17171. },
  17172. $ON_MSG_HYPERLINK_LAYER_HIDDEN : function(){
  17173. this.bLayerShown = false;
  17174. this.oApp.exec("DESELECT_UI", ["hyperlink"]);
  17175. },
  17176. _validateTarget : function() {
  17177. var oNavigator = jindo.$Agent().navigator(),
  17178. bReturn = true;
  17179. if(oNavigator.ie) {
  17180. jindo.$A(this.oSelection.getNodes(true)).forEach(function(elNode, index, array){
  17181. if(!!elNode && elNode.nodeType == 1 && elNode.tagName.toLowerCase() == "iframe" && elNode.getAttribute('s_type').toLowerCase() == "db") {
  17182. bReturn = false;
  17183. jindo.$A.Break();
  17184. }
  17185. jindo.$A.Continue();
  17186. }, this);
  17187. }
  17188. return bReturn;
  17189. },
  17190. $ON_APPLY_HYPERLINK : function(){
  17191. // [SMARTEDITORSUS-1451] 글감에 링크를 적용하지 않도록 처리
  17192. if(!this._validateTarget()){
  17193. alert(this.oApp.$MSG("SE_Hyperlink.invalidTarget"));
  17194. return;
  17195. }
  17196. var sURL = this.oLinkInput.value;
  17197. if(!/^((http|https|ftp|mailto):(?:\/\/)?)/.test(sURL)){
  17198. sURL = "http://"+sURL;
  17199. }
  17200. sURL = sURL.replace(/\s+$/, "");
  17201. var oAgent = jindo.$Agent().navigator();
  17202. var sBlank = "";
  17203. this.oApp.exec("IE_FOCUS", []);
  17204. if(oAgent.ie){sBlank = "<span style=\"text-decoration:none;\">&nbsp;</span>";}
  17205. if(this._validateURL(sURL)){
  17206. //if(this.oCbNewWin.checked){
  17207. // if(false){
  17208. // sTarget = "_blank";
  17209. // }else{
  17210. sTarget = "_self";
  17211. //}
  17212. this.oApp.exec("RECORD_UNDO_BEFORE_ACTION", ["HYPERLINK", {sSaveTarget:(this.bModify ? "A" : null)}]);
  17213. var sBM;
  17214. if(this.oSelection.collapsed){
  17215. var str = "<a href='" + sURL + "' target="+sTarget+">" + sURL + "</a>" + sBlank;
  17216. this.oSelection.pasteHTML(str);
  17217. sBM = this.oSelection.placeStringBookmark();
  17218. }else{
  17219. // 브라우저에서 제공하는 execcommand에 createLink로는 타겟을 지정할 수가 없다.
  17220. // 그렇기 때문에, 더미 URL을 createLink에 넘겨서 링크를 먼저 걸고, 이후에 loop을 돌면서 더미 URL을 가진 A태그를 찾아서 정상 URL 및 타겟을 세팅 해 준다.
  17221. sBM = this.oSelection.placeStringBookmark();
  17222. this.oSelection.select();
  17223. // [SMARTEDITORSUS-61] TD 안에 있는 텍스트를 전체 선택하여 URL 변경하면 수정되지 않음 (only IE8)
  17224. // SE_EditingArea_WYSIWYG 에서는 IE인 경우, beforedeactivate 이벤트가 발생하면 현재의 Range를 저장하고, RESTORE_IE_SELECTION 메시지가 발생하면 저장된 Range를 적용한다.
  17225. // IE8 또는 IE7 호환모드이고 TD 안의 텍스트 전체를 선택한 경우 Bookmark 생성 후의 select()를 처리할 때
  17226. // HuskyRange 에서 호출되는 this._oSelection.empty(); 에서 beforedeactivate 가 발생하여 empty 처리된 selection 이 저장되는 문제가 있어 링크가 적용되지 않음.
  17227. // 올바른 selection 이 저장되어 EXECCOMMAND에서 링크가 적용될 수 있도록 함
  17228. if(oAgent.ie && (oAgent.version === 8 || oAgent.nativeVersion === 8)){ // nativeVersion 으로 IE7 호환모드인 경우 확인
  17229. this.oApp.exec("IE_FOCUS", []);
  17230. this.oSelection.moveToBookmark(sBM);
  17231. this.oSelection.select();
  17232. }
  17233. // createLink 이후에 이번에 생성된 A 태그를 찾을 수 있도록 nSession을 포함하는 더미 링크를 만든다.
  17234. var nSession = Math.ceil(Math.random()*10000);
  17235. if(sURL == ""){ // unlink
  17236. this.oApp.exec("EXECCOMMAND", ["unlink"]);
  17237. }else{ // createLink
  17238. if(this._isExceptional()){
  17239. this.oApp.exec("EXECCOMMAND", ["unlink", false, "", {bDontAddUndoHistory: true}]);
  17240. var sTempUrl = "<a href='" + sURL + "' target="+sTarget+">";
  17241. jindo.$A(this.oSelection.getNodes(true)).forEach(function(value, index, array){
  17242. var oEmptySelection = this.oApp.getEmptySelection();
  17243. if(value.nodeType === 3){
  17244. oEmptySelection.selectNode(value);
  17245. oEmptySelection.pasteHTML(sTempUrl + value.nodeValue + "</a>");
  17246. }else if(value.nodeType === 1 && value.tagName === "IMG"){
  17247. oEmptySelection.selectNode(value);
  17248. oEmptySelection.pasteHTML(sTempUrl + jindo.$Element(value).outerHTML() + "</a>");
  17249. }
  17250. }, this);
  17251. }else{
  17252. this.oApp.exec("EXECCOMMAND", ["createLink", false, this.sATagMarker+nSession+encodeURIComponent(sURL), {bDontAddUndoHistory: true}]);
  17253. }
  17254. }
  17255. var oDoc = this.oApp.getWYSIWYGDocument();
  17256. var aATags = oDoc.body.getElementsByTagName("A");
  17257. var nLen = aATags.length;
  17258. var rxMarker = new RegExp(this.sRXATagMarker+nSession, "gi");
  17259. var elATag;
  17260. for(var i=0; i<nLen; i++){
  17261. elATag = aATags[i];
  17262. var sHref = "";
  17263. try{
  17264. sHref = elATag.getAttribute("href");
  17265. }catch(e){}
  17266. if (sHref && sHref.match(rxMarker)) {
  17267. var sNewHref = sHref.replace(rxMarker, "");
  17268. var sDecodeHref = decodeURIComponent(sNewHref);
  17269. if(oAgent.ie){
  17270. jindo.$Element(elATag).attr({
  17271. "href" : sDecodeHref,
  17272. "target" : sTarget
  17273. });
  17274. //}else if(oAgent.firefox){
  17275. }else{
  17276. var sAContent = jindo.$Element(elATag).html();
  17277. jindo.$Element(elATag).attr({
  17278. "href" : sDecodeHref,
  17279. "target" : sTarget
  17280. });
  17281. if(this._validateURL(sAContent)){
  17282. jindo.$Element(elATag).html(jindo.$Element(elATag).attr("href"));
  17283. }
  17284. }
  17285. /*else{
  17286. elATag.href = sDecodeHref;
  17287. }
  17288. */
  17289. }
  17290. }
  17291. }
  17292. this.oApp.exec("HIDE_ACTIVE_LAYER");
  17293. setTimeout(jindo.$Fn(function(){
  17294. var oSelection = this.oApp.getEmptySelection();
  17295. oSelection.moveToBookmark(sBM);
  17296. oSelection.collapseToEnd();
  17297. oSelection.select();
  17298. oSelection.removeStringBookmark(sBM);
  17299. this.oApp.exec("FOCUS");
  17300. this.oApp.exec("RECORD_UNDO_AFTER_ACTION", ["HYPERLINK", {sSaveTarget:(this.bModify ? "A" : null)}]);
  17301. }, this).bind(), 17);
  17302. }else{
  17303. alert(this.oApp.$MSG("SE_Hyperlink.invalidURL"));
  17304. this.oLinkInput.focus();
  17305. }
  17306. },
  17307. _isExceptional : function(){
  17308. var oNavigator = jindo.$Agent().navigator(),
  17309. bImg = false, bEmail = false;
  17310. if(!oNavigator.ie){
  17311. return false;
  17312. }
  17313. // [SMARTEDITORSUS-612] 이미지 선택 후 링크 추가했을 때 링크가 걸리지 않는 문제
  17314. if(this.oApp.getWYSIWYGDocument().selection && this.oApp.getWYSIWYGDocument().selection.type === "None"){
  17315. bImg = jindo.$A(this.oSelection.getNodes()).some(function(value, index, array){
  17316. if(value.nodeType === 1 && value.tagName === "IMG"){
  17317. return true;
  17318. }
  17319. }, this);
  17320. if(bImg){
  17321. return true;
  17322. }
  17323. }
  17324. if(oNavigator.nativeVersion > 8){ // version? nativeVersion?
  17325. return false;
  17326. }
  17327. // [SMARTEDITORSUS-579] IE8 이하에서 E-mail 패턴 문자열에 URL 링크 못거는 이슈
  17328. bEmail = jindo.$A(this.oSelection.getTextNodes()).some(function(value, index, array){
  17329. if(value.nodeValue.indexOf("@") >= 1){
  17330. return true;
  17331. }
  17332. }, this);
  17333. if(bEmail){
  17334. return true;
  17335. }
  17336. return false;
  17337. },
  17338. _getSelectedNode : function(){
  17339. var aNodes = this.oSelection.getNodes();
  17340. for (var i = 0; i < aNodes.length; i++) {
  17341. if (aNodes[i].tagName && aNodes[i].tagName == "A") {
  17342. return aNodes[i];
  17343. }
  17344. }
  17345. },
  17346. _validateURL : function(sURL){
  17347. if(!sURL){return false;}
  17348. // escape 불가능한 %가 들어있나 확인
  17349. try{
  17350. var aURLParts = sURL.split("?");
  17351. aURLParts[0] = aURLParts[0].replace(/%[a-z0-9]{2}/gi, "U");
  17352. decodeURIComponent(aURLParts[0]);
  17353. }catch(e){
  17354. return false;
  17355. }
  17356. return /^(http|https|ftp|mailto):(\/\/)?(([-가-힣]|\w)+(?:[\/\.:@]([-가-힣]|\w)+)+)\/?(.*)?\s*$/i.test(sURL);
  17357. }
  17358. //@lazyload_js]
  17359. });
  17360. nhn.husky.HuskyCore.addLoadedFile("hp_SE2M_LineHeightWithLayerUI$Lazy.js");
  17361. /**
  17362. * @depends nhn.husky.SE2M_LineHeightWithLayerUI
  17363. * this.oApp.registerLazyMessage(["SE2M_TOGGLE_LINEHEIGHT_LAYER"], ["hp_SE2M_LineHeightWithLayerUI$Lazy.js"]);
  17364. */
  17365. nhn.husky.HuskyCore.mixin(nhn.husky.SE2M_LineHeightWithLayerUI, {
  17366. //@lazyload_js SE2M_TOGGLE_LINEHEIGHT_LAYER[
  17367. _assignHTMLObjects : function(elAppContainer) {
  17368. //this.elLineHeightSelect = jindo.$$.getSingle("SELECT.husky_seditor_ui_lineHeight_select", elAppContainer);
  17369. this.oDropdownLayer = jindo.$$.getSingle("DIV.husky_se2m_lineHeight_layer", elAppContainer);
  17370. this.aLIOptions = jindo.$A(jindo.$$("LI", this.oDropdownLayer)).filter(function(v,i,a){return (v.firstChild !== null);})._array;
  17371. this.oInput = jindo.$$.getSingle("INPUT", this.oDropdownLayer);
  17372. var tmp = jindo.$$.getSingle(".husky_se2m_lineHeight_direct_input", this.oDropdownLayer);
  17373. tmp = jindo.$$("BUTTON", tmp);
  17374. this.oBtn_up = tmp[0];
  17375. this.oBtn_down = tmp[1];
  17376. this.oBtn_ok = tmp[2];
  17377. this.oBtn_cancel = tmp[3];
  17378. },
  17379. $LOCAL_BEFORE_FIRST : function(){
  17380. this._assignHTMLObjects(this.oApp.htOptions.elAppContainer);
  17381. this.oApp.exec("SE2_ATTACH_HOVER_EVENTS", [this.aLIOptions]);
  17382. for(var i=0; i<this.aLIOptions.length; i++){
  17383. this.oApp.registerBrowserEvent(this.aLIOptions[i], "click", "SET_LINEHEIGHT_FROM_LAYER_UI", [this._getLineHeightFromLI(this.aLIOptions[i])]);
  17384. }
  17385. this.oApp.registerBrowserEvent(this.oBtn_up, "click", "SE2M_INC_LINEHEIGHT", []);
  17386. this.oApp.registerBrowserEvent(this.oBtn_down, "click", "SE2M_DEC_LINEHEIGHT", []);
  17387. this.oApp.registerBrowserEvent(this.oBtn_ok, "click", "SE2M_SET_LINEHEIGHT_FROM_DIRECT_INPUT", []);
  17388. this.oApp.registerBrowserEvent(this.oBtn_cancel, "click", "SE2M_CANCEL_LINEHEIGHT", []);
  17389. this.oApp.registerBrowserEvent(this.oInput, "keydown", "EVENT_SE2M_LINEHEIGHT_KEYDOWN");
  17390. },
  17391. $ON_EVENT_SE2M_LINEHEIGHT_KEYDOWN : function(oEvent){
  17392. if (oEvent.key().enter){
  17393. this.oApp.exec("SE2M_SET_LINEHEIGHT_FROM_DIRECT_INPUT");
  17394. oEvent.stop();
  17395. }
  17396. },
  17397. $ON_SE2M_TOGGLE_LINEHEIGHT_LAYER : function(){
  17398. this.oApp.exec("TOGGLE_TOOLBAR_ACTIVE_LAYER", [this.oDropdownLayer, null, "LINEHEIGHT_LAYER_SHOWN", [], "LINEHEIGHT_LAYER_HIDDEN", []]);
  17399. this.oApp.exec('MSG_NOTIFY_CLICKCR', ['lineheight']);
  17400. },
  17401. $ON_SE2M_INC_LINEHEIGHT : function(){
  17402. this.oInput.value = parseInt(this.oInput.value, 10) || this.MIN_LINE_HEIGHT;
  17403. this.oInput.value++;
  17404. },
  17405. $ON_SE2M_DEC_LINEHEIGHT : function(){
  17406. this.oInput.value = parseInt(this.oInput.value, 10) || this.MIN_LINE_HEIGHT;
  17407. if(this.oInput.value > this.MIN_LINE_HEIGHT){this.oInput.value--;}
  17408. },
  17409. $ON_LINEHEIGHT_LAYER_SHOWN : function(){
  17410. this.oApp.exec("SELECT_UI", ["lineHeight"]);
  17411. this.oInitialSelection = this.oApp.getSelection();
  17412. var nLineHeight = this.oApp.getLineStyle("lineHeight");
  17413. if(nLineHeight != null && nLineHeight !== 0){
  17414. this.oInput.value = (nLineHeight*100).toFixed(0);
  17415. var elLi = this._getMatchingLI(this.oInput.value+"%");
  17416. if(elLi){jindo.$Element(elLi.firstChild).addClass("active");}
  17417. }else{
  17418. this.oInput.value = "";
  17419. }
  17420. },
  17421. $ON_LINEHEIGHT_LAYER_HIDDEN : function(){
  17422. this.oApp.exec("DESELECT_UI", ["lineHeight"]);
  17423. this._clearOptionSelection();
  17424. },
  17425. $ON_SE2M_SET_LINEHEIGHT_FROM_DIRECT_INPUT : function(){
  17426. var nInputValue = parseInt(this.oInput.value, 10);
  17427. var sValue = (nInputValue < this.MIN_LINE_HEIGHT) ? this.MIN_LINE_HEIGHT : nInputValue;
  17428. this._setLineHeightAndCloseLayer(sValue);
  17429. },
  17430. $ON_SET_LINEHEIGHT_FROM_LAYER_UI : function(sValue){
  17431. this._setLineHeightAndCloseLayer(sValue);
  17432. },
  17433. $ON_SE2M_CANCEL_LINEHEIGHT : function(){
  17434. this.oInitialSelection.select();
  17435. this.oApp.exec("HIDE_ACTIVE_LAYER");
  17436. },
  17437. _setLineHeightAndCloseLayer : function(sValue){
  17438. var nLineHeight = parseInt(sValue, 10)/100;
  17439. if(nLineHeight>0){
  17440. this.oApp.exec("SET_LINE_STYLE", ["lineHeight", nLineHeight]);
  17441. }else{
  17442. alert(this.oApp.$MSG("SE_LineHeight.invalidLineHeight"));
  17443. }
  17444. this.oApp.exec("SE2M_TOGGLE_LINEHEIGHT_LAYER", []);
  17445. var oNavigator = jindo.$Agent().navigator();
  17446. if(oNavigator.chrome || oNavigator.safari){
  17447. this.oApp.exec("FOCUS"); // [SMARTEDITORSUS-654]
  17448. }
  17449. },
  17450. _getMatchingLI : function(sValue){
  17451. var elLi;
  17452. sValue = sValue.toLowerCase();
  17453. for(var i=0; i<this.aLIOptions.length; i++){
  17454. elLi = this.aLIOptions[i];
  17455. if(this._getLineHeightFromLI(elLi).toLowerCase() == sValue){return elLi;}
  17456. }
  17457. return null;
  17458. },
  17459. _getLineHeightFromLI : function(elLi){
  17460. return elLi.firstChild.firstChild.innerHTML;
  17461. },
  17462. _clearOptionSelection : function(elLi){
  17463. for(var i=0; i<this.aLIOptions.length; i++){
  17464. jindo.$Element(this.aLIOptions[i].firstChild).removeClass("active");
  17465. }
  17466. }
  17467. //@lazyload_js]
  17468. });
  17469. nhn.husky.HuskyCore.addLoadedFile("hp_SE2M_QuickEditor_Common$Lazy.js");
  17470. /**
  17471. * @depends nhn.husky.SE2M_QuickEditor_Common
  17472. * this.oApp.registerLazyMessage(["OPEN_QE_LAYER"], ["hp_SE2M_QuickEditor_Common$Lazy.js"]);
  17473. */
  17474. nhn.husky.HuskyCore.mixin(nhn.husky.SE2M_QuickEditor_Common, {
  17475. //@lazyload_js OPEN_QE_LAYER[
  17476. /**
  17477. * openType을 저장하는 함수.
  17478. * @param {String} sType
  17479. * @param {Boolean} bBol
  17480. */
  17481. setOpenType : function(sType,bBol){
  17482. // [SMARTEDITORSUS-1213] 작성된 컨텐츠 수정 화면에서 사진이 로드되자마자 바로 사진을 클릭하면 QuickEditor를 띄우는 데 문제가 있음
  17483. if(typeof(this._environmentData) == "undefined" || this._environmentData == null){
  17484. this._environmentData = {};
  17485. }
  17486. if(typeof(this._environmentData[sType]) == "undefined" || this._environmentData[sType] == null){
  17487. this._environmentData[sType] = {};
  17488. }
  17489. if(typeof(this._environmentData[sType].isOpen) == "undefined" || this._environmentData[sType].isOpen == null){
  17490. this._environmentData[sType].isOpen = true;
  17491. }
  17492. // --[SMARTEDITORSUS-1213]
  17493. this._environmentData[sType].isOpen = bBol;
  17494. },
  17495. /**
  17496. * 레이어가 오픈 실행되는 이벤트.
  17497. * 레이어가 처음 ,
  17498. * 저장된 단축키 리스트를 레이어에 등록하고 (레이어가 있을때도 단축키가 먹도록 하기 위해)
  17499. * 레이어에 대한 키보드/마우스 이벤트를 등록한다.
  17500. * @param {Element} oEle
  17501. * @param {Element} oLayer
  17502. * @param {String} sType(img|table|review)
  17503. */
  17504. $ON_OPEN_QE_LAYER : function(oEle,oLayer,sType){
  17505. if(this.waHotkeys.length() > 0 && !this.waHotkeyLayers.has(oLayer)){
  17506. this.waHotkeyLayers.push(oLayer);
  17507. var aParam;
  17508. for(var i=0, nLen=this.waHotkeys.length(); i<nLen; i++){
  17509. aParam = this.waHotkeys.get(i);
  17510. this.oApp.exec("ADD_HOTKEY", [aParam[0], aParam[1], aParam[2], oLayer]);
  17511. }
  17512. }
  17513. var type = sType;//?sType:"table";//this.get_type(oEle);
  17514. if(type){
  17515. this.targetEle = oEle;
  17516. this.currentEle = oLayer;
  17517. this.layer_show(type,oEle);
  17518. }
  17519. },
  17520. /**
  17521. * 레이어가 닫혔을때 실행되는 이벤트.
  17522. * @param {jindo.$Event} weEvent
  17523. */
  17524. $ON_CLOSE_QE_LAYER : function(weEvent){
  17525. if(!this.currentEle){return;}
  17526. // this.oApp.exec("HIDE_EDITING_AREA_COVER");
  17527. // this.oApp.exec("ENABLE_ALL_UI");
  17528. this.oApp.exec("CLOSE_SUB_LAYER_QE");
  17529. this.layer_hide(weEvent);
  17530. },
  17531. /**
  17532. * 어플리케이션이 준비단계일때 실행되는 이벤트
  17533. */
  17534. $LOCAL_BEFORE_FIRST : function(sMsg) {
  17535. if (!sMsg.match(/OPEN_QE_LAYER/)) { // (sMsg == "$ON_CLOSE_QE_LAYER" && !this.currentEle)
  17536. this.oApp.acceptLocalBeforeFirstAgain(this, true);
  17537. if(sMsg.match(/REGISTER_HOTKEY/)){
  17538. return true;
  17539. }
  17540. return false;
  17541. }
  17542. this.woEditor = jindo.$Element(this.oApp.elEditingAreaContainer);
  17543. this.woStandard = jindo.$Element(this.oApp.htOptions.elAppContainer).offset();
  17544. this._qe_wrap = jindo.$$.getSingle("DIV.quick_wrap", this.oApp.htOptions.elAppContainer);
  17545. var that = this;
  17546. new jindo.DragArea(this._qe_wrap, {
  17547. sClassName : 'q_dragable',
  17548. bFlowOut : false,
  17549. nThreshold : 1
  17550. }).attach({
  17551. beforeDrag : function(oCustomEvent) {
  17552. oCustomEvent.elFlowOut = oCustomEvent.elArea.parentNode;
  17553. },
  17554. dragStart: function(oCustomEvent){
  17555. if(!jindo.$Element(oCustomEvent.elDrag).hasClass('se2_qmax')){
  17556. oCustomEvent.elDrag = oCustomEvent.elDrag.parentNode;
  17557. }
  17558. that.oApp.exec("SHOW_EDITING_AREA_COVER");
  17559. },
  17560. dragEnd : function(oCustomEvent){
  17561. that.changeFixedMode();
  17562. that._in_event = false;
  17563. //if(that._currentType=="review"||that._currentType=="table"){ // [SMARTEDITORSUS-153] 이미지 퀵 에디터도 같은 로직으로 처리하도록 수정
  17564. var richEle = jindo.$Element(oCustomEvent.elDrag);
  17565. that._environmentData[that._currentType].position = [richEle.css("top"),richEle.css("left")];
  17566. //}
  17567. that.oApp.exec("HIDE_EDITING_AREA_COVER");
  17568. }
  17569. });
  17570. var imgFn = jindo.$Fn(this.toggle,this).bind("img");
  17571. var tableFn = jindo.$Fn(this.toggle,this).bind("table");
  17572. jindo.$Fn(imgFn,this).attach(jindo.$$.getSingle(".q_open_img_fold", this.oApp.htOptions.elAppContainer),"click");
  17573. jindo.$Fn(imgFn,this).attach(jindo.$$.getSingle(".q_open_img_full", this.oApp.htOptions.elAppContainer),"click");
  17574. jindo.$Fn(tableFn,this).attach(jindo.$$.getSingle(".q_open_table_fold", this.oApp.htOptions.elAppContainer),"click");
  17575. jindo.$Fn(tableFn,this).attach(jindo.$$.getSingle(".q_open_table_full", this.oApp.htOptions.elAppContainer),"click");
  17576. },
  17577. /**
  17578. * 레이어의 최대화/최소화를 토글링 하는 함수.
  17579. * @param {String} sType(table|img)
  17580. * @param {jindo.$Event} weEvent
  17581. */
  17582. toggle : function(sType,weEvent){
  17583. sType = this._currentType;
  17584. // var oBefore = jindo.$Element(jindo.$$.getSingle("._"+this._environmentData[sType].type,this.currentEle));
  17585. // var beforeX = oBefore.css("left");
  17586. // var beforeY = oBefore.css("top");
  17587. this.oApp.exec("CLOSE_QE_LAYER", [weEvent]);
  17588. if(this._environmentData[sType].type=="full"){
  17589. this._environmentData[sType].type = "fold";
  17590. }else{
  17591. this._environmentData[sType].type = "full";
  17592. }
  17593. // [SMARTEDITORSUS-1028][SMARTEDITORSUS-1517] QuickEditor 설정 API 개선으로, submit 이후 발생하게 되는 beforeunload 이벤트 대신 호출 시점 변경
  17594. // QuickEditor를 접고 펼칠 때마다 API 통신을 거치기 때문에 submit이나 beforeunload에 구애받지 않고 안정적인 데이터 저장 가능
  17595. if (this._environmentData && this._bUseConfig) {
  17596. // [SMARTEDITORSUS-1970] 사용 설정값이 있는 경우에만 Ajax를 호출하도록 한다.
  17597. jindo.$Ajax(this._sAddTextAjaxUrl,{
  17598. type : "jsonp",
  17599. onload: function(){}
  17600. }).request({
  17601. text_key :"qeditor_fold",
  17602. text_data : "{table:'"+this._environmentData["table"]["type"]+"',img:'"+this._environmentData["img"]["type"]+"',review:'"+this._environmentData["review"]["type"]+"'}"
  17603. });
  17604. }
  17605. // --[SMARTEDITORSUS-1028][SMARTEDITORSUS-1517]
  17606. // this.positionCopy(beforeX,beforeY,this._environmentData[sType].type);
  17607. this.oApp.exec("OPEN_QE_LAYER", [this.targetEle,this.currentEle,sType]);
  17608. this._in_event = false;
  17609. weEvent.stop(jindo.$Event.CANCEL_DEFAULT);
  17610. },
  17611. /**
  17612. * 토글링시 전에 엘리먼트에 위치를 카피하는 함수.
  17613. * @param {Number} beforeX
  17614. * @param {Number} beforeY
  17615. * @param {Element} sAfterEle
  17616. */
  17617. positionCopy:function(beforeX, beforeY, sAfterEle){
  17618. jindo.$Element(jindo.$$.getSingle("._"+sAfterEle,this.currentEle)).css({
  17619. top : beforeY,
  17620. left : beforeX
  17621. });
  17622. },
  17623. /**
  17624. * 레이어를 고정으로 할때 실행되는 함수.
  17625. */
  17626. changeFixedMode : function(){
  17627. this._environmentData[this._currentType].isFixed = true;
  17628. },
  17629. /**
  17630. * 에디팅 영역에서 keyup할때 실행되는 함수.
  17631. * @param {jindo.$Event} weEvent
  17632. */
  17633. /*
  17634. $ON_EVENT_EDITING_AREA_KEYUP:function(weEvent){
  17635. if(this._currentType&&(!this._in_event)&&this._environmentData[this._currentType].isOpen){
  17636. this.oApp.exec("CLOSE_QE_LAYER", [weEvent]);
  17637. }
  17638. this._in_event = false;
  17639. },
  17640. */
  17641. $ON_HIDE_ACTIVE_LAYER : function(){
  17642. this.oApp.exec("CLOSE_QE_LAYER");
  17643. },
  17644. /**
  17645. * 에디팅 영역에서 mousedown할때 실행되는 함수.
  17646. * @param {jindo.$Event} weEvent
  17647. */
  17648. $ON_EVENT_EDITING_AREA_MOUSEDOWN:function(weEvent){
  17649. if(this._currentType&&(!this._in_event)&&this._environmentData[this._currentType].isOpen){
  17650. this.oApp.exec("CLOSE_QE_LAYER", [weEvent]);
  17651. }
  17652. this._in_event = false;
  17653. },
  17654. /**
  17655. * 에디팅 영역에서 mousewheel할때 실행되는 함수.
  17656. * @param {jindo.$Event} weEvent
  17657. */
  17658. $ON_EVENT_EDITING_AREA_MOUSEWHEEL:function(weEvent){
  17659. if(this._currentType&&(!this._in_event)&&this._environmentData[this._currentType].isOpen){
  17660. this.oApp.exec("CLOSE_QE_LAYER", [weEvent]);
  17661. }
  17662. this._in_event = false;
  17663. },
  17664. /**
  17665. * 레이어를 띄우는데 레이어가 table(템플릿),img인지를 확인하여 id를 반환하는 함수.
  17666. * @param {Element} oEle
  17667. * @return {String} layer id
  17668. */
  17669. get_type : function(oEle){
  17670. var tagName = oEle.tagName.toLowerCase();
  17671. if(this.waTableTagNames.has(tagName)){
  17672. return "table";
  17673. }else if(tagName=="img"){
  17674. return "img";
  17675. }
  17676. },
  17677. /**
  17678. * 퀵에디터에서 keyup시 실행되는 이벤트
  17679. */
  17680. $ON_QE_IN_KEYUP : function(){
  17681. this._in_event = true;
  17682. },
  17683. /**
  17684. * 퀵에디터에서 mousedown시 실행되는 이벤트
  17685. */
  17686. $ON_QE_IN_MOUSEDOWN : function(){
  17687. this._in_event = true;
  17688. },
  17689. /**
  17690. * 퀵에디터에서 mousewheel시 실행되는 이벤트
  17691. */
  17692. $ON_QE_IN_MOUSEWHEEL : function(){
  17693. this._in_event = true;
  17694. },
  17695. /**
  17696. * 레이어를 숨기는 함수.
  17697. * @param {jindo.$Event} weEvent
  17698. */
  17699. layer_hide : function(weEvent){
  17700. this.setOpenType(this._currentType,false);
  17701. jindo.$Element(jindo.$$.getSingle("._"+this._environmentData[this._currentType].type,this.currentEle)).hide();
  17702. },
  17703. /**
  17704. * 늦게 이벤트 바인딩 하는 함수.
  17705. * 레이어가 처음 이벤트를 등록한다.
  17706. */
  17707. lazy_common : function(){
  17708. this.oApp.registerBrowserEvent(jindo.$(this._qe_wrap), "keyup", "QE_IN_KEYUP");
  17709. this.oApp.registerBrowserEvent(jindo.$(this._qe_wrap), "mousedown", "QE_IN_MOUSEDOWN");
  17710. this.oApp.registerBrowserEvent(jindo.$(this._qe_wrap), "mousewheel", "QE_IN_MOUSEWHEEL");
  17711. this.lazy_common = function(){};
  17712. },
  17713. /**
  17714. * 레이어를 보여주는 함수.
  17715. * @param {String} sType
  17716. * @param {Element} oEle
  17717. */
  17718. layer_show : function(sType,oEle){
  17719. this._currentType = sType;
  17720. this.setOpenType(this._currentType,true);
  17721. var layer = jindo.$$.getSingle("._"+this._environmentData[this._currentType].type,this.currentEle);
  17722. jindo.$Element(layer)
  17723. .show()
  17724. .css( this.get_position_layer(oEle , layer) );
  17725. this.lazy_common();
  17726. },
  17727. /**
  17728. * 레이어의 위치를 반환 하는 함수
  17729. * 고정 상태가 아니거나 최소화 상태이면 엘리먼트 위치에 퀵에디터를 띄우고
  17730. * 고정 상태이고 최대화 상태이면 표나 양식은 저장된 위치에 띄워주고, 이미지는...?
  17731. * @param {Element} oEle
  17732. * @param {Element} oLayer
  17733. */
  17734. get_position_layer : function(oEle , oLayer){
  17735. if(!this.isCurrentFixed() || this._environmentData[this._currentType].type == "fold"){
  17736. return this.calculateLayer(oEle , oLayer);
  17737. }
  17738. //if(this._currentType == "review" || this._currentType == "table"){ // [SMARTEDITORSUS-153] 이미지 퀵 에디터도 같은 로직으로 처리하도록 수정
  17739. var position = this._environmentData[this._currentType].position;
  17740. var nTop = parseInt(position[0], 10);
  17741. var nAppHeight = this.getAppPosition().h;
  17742. var nLayerHeight = jindo.$Element(oLayer).height();
  17743. // [SMARTEDITORSUS-129] 편집 영역 높이를 줄였을 때 퀵에디터가 영역을 벗어나지 않도록 처리
  17744. if((nTop + nLayerHeight + this.nYGap) > nAppHeight){
  17745. nTop = nAppHeight - nLayerHeight;
  17746. this._environmentData[this._currentType].position[0] = nTop;
  17747. }
  17748. return {
  17749. top : nTop + "px",
  17750. left :position[1]
  17751. };
  17752. //}
  17753. //return this.calculateLayer(null , oLayer);
  17754. },
  17755. /**
  17756. * 현재 레이어가 고정형태인지 반환하는 함수.
  17757. */
  17758. isCurrentFixed : function(){
  17759. return this._environmentData[this._currentType].isFixed;
  17760. },
  17761. /**
  17762. * 레이어를 띄울 위치를 계산하는 함수.
  17763. * @param {Element} oEle
  17764. * @param {Element} oLayer
  17765. */
  17766. calculateLayer : function(oEle, oLayer){
  17767. /*
  17768. * 기준을 한군데로 만들어야 .
  17769. * 1. 에디터는 페이지
  17770. * 2. 엘리먼트는 안에 에디팅 영역
  17771. * 3. 레이어는 에디팅 영역
  17772. *
  17773. * 기준은 페이지로 .
  17774. */
  17775. var positionInfo = this.getPositionInfo(oEle, oLayer);
  17776. return {
  17777. top : positionInfo.y + "px",
  17778. left : positionInfo.x + "px"
  17779. };
  17780. },
  17781. /**
  17782. * 위치를 반환 하는 함수.
  17783. * @param {Element} oEle
  17784. * @param {Element} oLayer
  17785. */
  17786. getPositionInfo : function(oEle, oLayer){
  17787. this.nYGap = jindo.$Agent().navigator().ie? -16 : -18;
  17788. this.nXGap = 1;
  17789. var oRevisePosition = {};
  17790. var eleInfo = this.getElementPosition(oEle, oLayer);
  17791. var appInfo = this.getAppPosition();
  17792. var layerInfo = {
  17793. w : jindo.$Element(oLayer).width(),
  17794. h : jindo.$Element(oLayer).height()
  17795. };
  17796. if((eleInfo.x + layerInfo.w + this.nXGap) > appInfo.w){
  17797. oRevisePosition.x = appInfo.w - layerInfo.w ;
  17798. }else{
  17799. oRevisePosition.x = eleInfo.x + this.nXGap;
  17800. }
  17801. if((eleInfo.y + layerInfo.h + this.nYGap) > appInfo.h){
  17802. oRevisePosition.y = appInfo.h - layerInfo.h - 2;
  17803. }else{
  17804. oRevisePosition.y = eleInfo.y + this.nYGap;
  17805. }
  17806. return {
  17807. x : oRevisePosition.x ,
  17808. y : oRevisePosition.y
  17809. };
  17810. },
  17811. /**
  17812. * 기준 엘리먼트의 위치를 반환하는 함수
  17813. * 엘리먼트가 있는 경우
  17814. * @param {Element} eEle
  17815. */
  17816. getElementPosition : function(eEle, oLayer){
  17817. var wEle, oOffset, nEleWidth, nEleHeight, nScrollX, nScrollY;
  17818. if(eEle){
  17819. wEle = jindo.$Element(eEle);
  17820. oOffset = wEle.offset();
  17821. nEleWidth = wEle.width();
  17822. nEleHeight = wEle.height();
  17823. }else{
  17824. oOffset = {
  17825. top : parseInt(oLayer.style.top, 10) - this.nYGap,
  17826. left : parseInt(oLayer.style.left, 10) - this.nXGap
  17827. };
  17828. nEleWidth = 0;
  17829. nEleHeight = 0;
  17830. }
  17831. var oAppWindow = this.oApp.getWYSIWYGWindow();
  17832. if(typeof oAppWindow.scrollX == "undefined"){
  17833. nScrollX = oAppWindow.document.documentElement.scrollLeft;
  17834. nScrollY = oAppWindow.document.documentElement.scrollTop;
  17835. }else{
  17836. nScrollX = oAppWindow.scrollX;
  17837. nScrollY = oAppWindow.scrollY;
  17838. }
  17839. var oEditotOffset = this.woEditor.offset();
  17840. return {
  17841. x : oOffset.left - nScrollX + nEleWidth,
  17842. y : oOffset.top - nScrollY + nEleHeight
  17843. };
  17844. },
  17845. /**
  17846. * 에디터의 크기 계산하는 함수.
  17847. */
  17848. getAppPosition : function(){
  17849. return {
  17850. w : this.woEditor.width(),
  17851. h : this.woEditor.height()
  17852. };
  17853. }
  17854. //@lazyload_js]
  17855. });
  17856. nhn.husky.HuskyCore.addLoadedFile("hp_DialogLayerManager$Lazy.js");
  17857. /**
  17858. * @depends nhn.husky.DialogLayerManager
  17859. * this.oApp.registerLazyMessage(["SHOW_DIALOG_LAYER","TOGGLE_DIALOG_LAYER"], ["hp_DialogLayerManager$Lazy.js", "N_DraggableLayer.js"]);
  17860. */
  17861. nhn.husky.HuskyCore.mixin(nhn.husky.DialogLayerManager, {
  17862. //@lazyload_js SHOW_DIALOG_LAYER,TOGGLE_DIALOG_LAYER:N_DraggableLayer.js[
  17863. $ON_SHOW_DIALOG_LAYER : function(elLayer, htOptions){
  17864. elLayer = jindo.$(elLayer);
  17865. htOptions = htOptions || {};
  17866. if(!elLayer){return;}
  17867. if(jindo.$A(this.aOpenedLayers).has(elLayer)){return;}
  17868. this.oApp.exec("POSITION_DIALOG_LAYER", [elLayer]);
  17869. this.aOpenedLayers[this.aOpenedLayers.length] = elLayer;
  17870. var oDraggableLayer;
  17871. var nIdx = jindo.$A(this.aMadeDraggable).indexOf(elLayer);
  17872. if(nIdx == -1){
  17873. oDraggableLayer = new nhn.DraggableLayer(elLayer, htOptions);
  17874. this.aMadeDraggable[this.aMadeDraggable.length] = elLayer;
  17875. this.aDraggableLayer[this.aDraggableLayer.length] = oDraggableLayer;
  17876. }else{
  17877. if(htOptions){
  17878. oDraggableLayer = this.aDraggableLayer[nIdx];
  17879. oDraggableLayer.setOptions(htOptions);
  17880. }
  17881. elLayer.style.display = "block";
  17882. }
  17883. if(htOptions.sOnShowMsg){
  17884. this.oApp.exec(htOptions.sOnShowMsg, htOptions.sOnShowParam);
  17885. }
  17886. },
  17887. $ON_HIDE_LAST_DIALOG_LAYER : function(){
  17888. this.oApp.exec("HIDE_DIALOG_LAYER", [this.aOpenedLayers[this.aOpenedLayers.length-1]]);
  17889. },
  17890. $ON_HIDE_ALL_DIALOG_LAYER : function(){
  17891. for(var i=this.aOpenedLayers.length-1; i>=0; i--){
  17892. this.oApp.exec("HIDE_DIALOG_LAYER", [this.aOpenedLayers[i]]);
  17893. }
  17894. },
  17895. $ON_HIDE_DIALOG_LAYER : function(elLayer){
  17896. elLayer = jindo.$(elLayer);
  17897. if(elLayer){elLayer.style.display = "none";}
  17898. this.aOpenedLayers = jindo.$A(this.aOpenedLayers).refuse(elLayer).$value();
  17899. },
  17900. $ON_TOGGLE_DIALOG_LAYER : function(elLayer, htOptions){
  17901. if(jindo.$A(this.aOpenedLayers).indexOf(elLayer)){
  17902. this.oApp.exec("SHOW_DIALOG_LAYER", [elLayer, htOptions]);
  17903. }else{
  17904. this.oApp.exec("HIDE_DIALOG_LAYER", [elLayer]);
  17905. }
  17906. },
  17907. $ON_SET_DIALOG_LAYER_POSITION : function(elLayer, nTop, nLeft){
  17908. elLayer.style.top = nTop;
  17909. elLayer.style.left = nLeft;
  17910. }
  17911. //@lazyload_js]
  17912. });
  17913. nhn.husky.HuskyCore.addLoadedFile("N_FindReplace.js");
  17914. /**
  17915. * @fileOverview This file contains a function that takes care of various operations related to find and replace
  17916. * @name N_FindReplace.js
  17917. */
  17918. nhn.FindReplace = jindo.$Class({
  17919. sKeyword : "",
  17920. window : null,
  17921. document : null,
  17922. bBrowserSupported : false,
  17923. _bLGDevice : false,
  17924. // true if End Of Contents is reached during last execution of find
  17925. bEOC : false,
  17926. $init : function(win){
  17927. this.sInlineContainer = "SPAN|B|U|I|S|STRIKE";
  17928. this.rxInlineContainer = new RegExp("^("+this.sInlineContainer+")$");
  17929. this.window = win;
  17930. this.document = this.window.document;
  17931. if(this.document.domain != this.document.location.hostname){
  17932. var oAgentInfo = jindo.$Agent();
  17933. var oNavigatorInfo = oAgentInfo.navigator();
  17934. if(oNavigatorInfo.firefox && oNavigatorInfo.version < 3){
  17935. this.bBrowserSupported = false;
  17936. this.find = function(){return 3;};
  17937. return;
  17938. }
  17939. }
  17940. this._bLGDevice = (navigator.userAgent.indexOf("LG-") > -1); // [SMARTEDITORSUS-1814] LG기기 여부 판단
  17941. this.bBrowserSupported = true;
  17942. },
  17943. // 0: found
  17944. // 1: not found
  17945. // 2: keyword required
  17946. // 3: browser not supported
  17947. find : function(sKeyword, bCaseMatch, bBackwards, bWholeWord){
  17948. var bSearchResult, bFreshSearch;
  17949. // [SMARTEDITORSUS-1814] LG브라우저의 경우 focus를 주면 선택영역이 풀리는 문제가 있어서 LG기기가 아닌 경우만 focus를 실행하도록 수정
  17950. // TODO: this.window.focus() 가 꼭 필요한지 전체적으로 점검해 볼 필요가 있음
  17951. if(!this._bLGDevice){
  17952. this.window.focus();
  17953. }
  17954. if(!sKeyword) return 2;
  17955. // try find starting from current cursor position
  17956. this.bEOC = false;
  17957. bSearchResult = this.findNext(sKeyword, bCaseMatch, bBackwards, bWholeWord);
  17958. if(bSearchResult) return 0;
  17959. // end of the contents could have been reached so search again from the beginning
  17960. this.bEOC = true;
  17961. bSearchResult = this.findNew(sKeyword, bCaseMatch, bBackwards, bWholeWord);
  17962. if(bSearchResult) return 0;
  17963. return 1;
  17964. },
  17965. findNew : function (sKeyword, bCaseMatch, bBackwards, bWholeWord){
  17966. this.findReset();
  17967. return this.findNext(sKeyword, bCaseMatch, bBackwards, bWholeWord);
  17968. },
  17969. findNext : function(sKeyword, bCaseMatch, bBackwards, bWholeWord){
  17970. var bSearchResult;
  17971. bCaseMatch = bCaseMatch || false;
  17972. bWholeWord = bWholeWord || false;
  17973. bBackwards = bBackwards || false;
  17974. if(this.window.find){
  17975. var bWrapAround = false;
  17976. if(this.document.body.contentEditable === "false"){ // [SMARTEDITORSUS-2086] 크롬에서 맞춤법검사후 단어 선택시 스크롤이 튀는 문제에 대한 workaround
  17977. return window.find(sKeyword, bCaseMatch, bBackwards, bWrapAround, bWholeWord);
  17978. }else{
  17979. return this.window.find(sKeyword, bCaseMatch, bBackwards, bWrapAround, bWholeWord);
  17980. }
  17981. }
  17982. // IE solution
  17983. if(this.document.body.createTextRange){
  17984. try{
  17985. var iOption = 0;
  17986. if(bBackwards) iOption += 1;
  17987. if(bWholeWord) iOption += 2;
  17988. if(bCaseMatch) iOption += 4;
  17989. this.window.focus();
  17990. if(this.document.selection){ // document.selection 이 있으면 selection 에서 TextRange 생성
  17991. this._range = this.document.selection.createRangeCollection().item(0);
  17992. this._range.collapse(false);
  17993. }else if(!this._range){ // [SMARTEDITORSUS-1528] IE11인 경우 createTextRange 로 TextRange 생성
  17994. this._range = this.document.body.createTextRange();
  17995. }else{ // [SMARTEDITORSUS-1837] 이미 생성되어 있는 TextRange를 이용해 collapseEnd 하면 다음 문자를 찾을 수 있다.
  17996. this._range.collapse(false);
  17997. }
  17998. bSearchResult = this._range.findText(sKeyword, 1, iOption);
  17999. this._range.select();
  18000. return bSearchResult;
  18001. }catch(e){
  18002. return false;
  18003. }
  18004. }
  18005. return false;
  18006. },
  18007. findReset : function() {
  18008. if (this.window.find){
  18009. this.window.getSelection().removeAllRanges();
  18010. return;
  18011. }
  18012. // IE solution
  18013. if(this.document.body.createTextRange){
  18014. this._range = this.document.body.createTextRange();
  18015. this._range.collapse(true);
  18016. this._range.select();
  18017. }
  18018. },
  18019. // 0: replaced & next word found
  18020. // 1: replaced & next word not found
  18021. // 2: not replaced & next word found
  18022. // 3: not replaced & next word not found
  18023. // 4: sOriginalWord required
  18024. replace : function(sOriginalWord, Replacement, bCaseMatch, bBackwards, bWholeWord){
  18025. return this._replace(sOriginalWord, Replacement, bCaseMatch, bBackwards, bWholeWord);
  18026. },
  18027. /**
  18028. * [SMARTEDITORSUS-1591] 크롬에서 replaceAll selection 새로 만들면 첫번째 단어가 삭제되지 않고 남는 문제가 있어서
  18029. * selection 객체를 받아서 사용할 있도록 private 메서드 추가
  18030. * TODO: 근본적으로 HuskyRange 리팩토링할 필요가 있음
  18031. */
  18032. _replace : function(sOriginalWord, Replacement, bCaseMatch, bBackwards, bWholeWord, oSelection){
  18033. if(!sOriginalWord) return 4;
  18034. oSelection = oSelection || new nhn.HuskyRange(this.window);
  18035. oSelection.setFromSelection();
  18036. bCaseMatch = bCaseMatch || false;
  18037. var bMatch, selectedText = oSelection.toString();
  18038. if(bCaseMatch)
  18039. bMatch = (selectedText == sOriginalWord);
  18040. else
  18041. bMatch = (selectedText.toLowerCase() == sOriginalWord.toLowerCase());
  18042. if(!bMatch)
  18043. return this.find(sOriginalWord, bCaseMatch, bBackwards, bWholeWord)+2;
  18044. if(typeof Replacement == "function"){
  18045. // the returned oSelection must contain the replacement
  18046. oSelection = Replacement(oSelection);
  18047. }else{
  18048. oSelection.pasteText(Replacement);
  18049. }
  18050. // force it to find the NEXT occurance of sOriginalWord
  18051. oSelection.select();
  18052. return this.find(sOriginalWord, bCaseMatch, bBackwards, bWholeWord);
  18053. },
  18054. // returns number of replaced words
  18055. // -1 : if original word is not given
  18056. replaceAll : function(sOriginalWord, Replacement, bCaseMatch, bWholeWord){
  18057. if(!sOriginalWord) return -1;
  18058. var bBackwards = false;
  18059. var iReplaceResult;
  18060. var iResult = 0;
  18061. var win = this.window;
  18062. if(this.find(sOriginalWord, bCaseMatch, bBackwards, bWholeWord) !== 0){
  18063. return iResult;
  18064. }
  18065. var oSelection = new nhn.HuskyRange(this.window);
  18066. oSelection.setFromSelection();
  18067. // 시작점의 북마크가 지워지면서 시작점을 지나서 replace가 되는 현상 방지용
  18068. // 첫 단어 앞쪽에 특수 문자 삽입 해서, replace와 함께 북마크가 사라지는 것 방지
  18069. oSelection.collapseToStart();
  18070. var oTmpNode = this.window.document.createElement("SPAN");
  18071. oTmpNode.innerHTML = unescape("%uFEFF");
  18072. oSelection.insertNode(oTmpNode);
  18073. oSelection.select();
  18074. var sBookmark = oSelection.placeStringBookmark();
  18075. this.bEOC = false;
  18076. while(!this.bEOC){
  18077. iReplaceResult = this._replace(sOriginalWord, Replacement, bCaseMatch, bBackwards, bWholeWord, oSelection);
  18078. if(iReplaceResult == 0 || iReplaceResult == 1){
  18079. iResult++;
  18080. }
  18081. }
  18082. var startingPointReached = function(){
  18083. var oCurSelection = new nhn.HuskyRange(win);
  18084. oCurSelection.setFromSelection();
  18085. oSelection.moveToBookmark(sBookmark);
  18086. var pos = oSelection.compareBoundaryPoints(nhn.W3CDOMRange.START_TO_END, oCurSelection);
  18087. if(pos == 1) return false;
  18088. return true;
  18089. };
  18090. iReplaceResult = 0;
  18091. this.bEOC = false;
  18092. while(!startingPointReached() && iReplaceResult == 0 && !this.bEOC){
  18093. iReplaceResult = this._replace(sOriginalWord, Replacement, bCaseMatch, bBackwards, bWholeWord, oSelection);
  18094. if(iReplaceResult == 0 || iReplaceResult == 1){
  18095. iResult++;
  18096. }
  18097. }
  18098. oSelection.moveToBookmark(sBookmark);
  18099. oSelection.deleteContents(); // [SMARTEDITORSUS-1591] 크롬에서 첫번째 단어가 삭제되지 않는 경우가 있으므로 select()메서드대신 deleteContents() 메서드를 호출한다.
  18100. oSelection.removeStringBookmark(sBookmark);
  18101. // setTimeout 없이 바로 지우면 IE8 브라우저가 빈번하게 죽어버림
  18102. setTimeout(function(){
  18103. if(oTmpNode && oTmpNode.parentNode){
  18104. oTmpNode.parentNode.removeChild(oTmpNode);
  18105. }
  18106. }, 0);
  18107. return iResult;
  18108. },
  18109. _isBlankTextNode : function(oNode){
  18110. if(oNode.nodeType == 3 && oNode.nodeValue == ""){return true;}
  18111. return false;
  18112. },
  18113. _getNextNode : function(elNode, bDisconnected){
  18114. if(!elNode || elNode.tagName == "BODY"){
  18115. return {elNextNode: null, bDisconnected: false};
  18116. }
  18117. if(elNode.nextSibling){
  18118. elNode = elNode.nextSibling;
  18119. while(elNode.firstChild){
  18120. if(elNode.tagName && !this.rxInlineContainer.test(elNode.tagName)){
  18121. bDisconnected = true;
  18122. }
  18123. elNode = elNode.firstChild;
  18124. }
  18125. return {elNextNode: elNode, bDisconnected: bDisconnected};
  18126. }
  18127. return this._getNextNode(nhn.DOMFix.parentNode(elNode), bDisconnected);
  18128. },
  18129. _getNextTextNode : function(elNode, bDisconnected){
  18130. var htNextNode, elNode;
  18131. while(true){
  18132. htNextNode = this._getNextNode(elNode, bDisconnected);
  18133. elNode = htNextNode.elNextNode;
  18134. bDisconnected = htNextNode.bDisconnected;
  18135. if(elNode && elNode.nodeType != 3 && !this.rxInlineContainer.test(elNode.tagName)){
  18136. bDisconnected = true;
  18137. }
  18138. if(!elNode || (elNode.nodeType==3 && !this._isBlankTextNode(elNode))){
  18139. break;
  18140. }
  18141. }
  18142. return {elNextText: elNode, bDisconnected: bDisconnected};
  18143. },
  18144. _getFirstTextNode : function(){
  18145. // 문서에서 제일 앞쪽에 위치한 아무 노드 찾기
  18146. var elFirstNode = this.document.body.firstChild;
  18147. while(!!elFirstNode && elFirstNode.firstChild){
  18148. elFirstNode = elFirstNode.firstChild;
  18149. }
  18150. // 문서에 아무 노드도 없음
  18151. if(!elFirstNode){
  18152. return null;
  18153. }
  18154. // 처음 노드가 텍스트 노드가 아니거나 bogus 노드라면 다음 텍스트 노드를 찾음
  18155. if(elFirstNode.nodeType != 3 || this._isBlankTextNode(elFirstNode)){
  18156. var htTmp = this._getNextTextNode(elFirstNode, false);
  18157. elFirstNode = htTmp.elNextText;
  18158. }
  18159. return elFirstNode;
  18160. },
  18161. _addToTextMap : function(elNode, aTexts, aElTexts, nLen){
  18162. var nStartPos = aTexts[nLen].length;
  18163. for(var i=0, nTo=elNode.nodeValue.length; i<nTo; i++){
  18164. aElTexts[nLen][nStartPos+i] = [elNode, i];
  18165. }
  18166. aTexts[nLen] += elNode.nodeValue;
  18167. },
  18168. _createTextMap : function(){
  18169. var aTexts = [];
  18170. var aElTexts = [];
  18171. var nLen=-1;
  18172. var elNode = this._getFirstTextNode();
  18173. var htNextNode = {elNextText: elNode, bDisconnected: true};
  18174. while(elNode){
  18175. if(htNextNode.bDisconnected){
  18176. nLen++;
  18177. aTexts[nLen] = "";
  18178. aElTexts[nLen] = [];
  18179. }
  18180. this._addToTextMap(htNextNode.elNextText, aTexts, aElTexts, nLen);
  18181. htNextNode = this._getNextTextNode(elNode, false);
  18182. elNode = htNextNode.elNextText;
  18183. }
  18184. return {aTexts: aTexts, aElTexts: aElTexts};
  18185. },
  18186. replaceAll_js : function(sOriginalWord, Replacement, bCaseMatch, bWholeWord){
  18187. try{
  18188. var t0 = new Date();
  18189. var htTmp = this._createTextMap();
  18190. var t1 = new Date();
  18191. var aTexts = htTmp.aTexts;
  18192. var aElTexts = htTmp.aElTexts;
  18193. // console.log(sOriginalWord);
  18194. // console.log(aTexts);
  18195. // console.log(aElTexts);
  18196. var nMatchCnt = 0;
  18197. var nOriginLen = sOriginalWord.length;
  18198. // 단어 한개씩 비교
  18199. for(var i=0, niLen=aTexts.length; i<niLen; i++){
  18200. var sText = aTexts[i];
  18201. // 단어 안에 한글자씩 비교
  18202. //for(var j=0, njLen=sText.length - nOriginLen; j<njLen; j++){
  18203. for(var j=sText.length-nOriginLen; j>=0; j--){
  18204. var sTmp = sText.substring(j, j+nOriginLen);
  18205. if(bWholeWord &&
  18206. (j > 0 && sText.charAt(j-1).match(/[a-zA-Z가-힣]/))
  18207. ){
  18208. continue;
  18209. }
  18210. if(sTmp == sOriginalWord){
  18211. nMatchCnt++;
  18212. var oSelection = new nhn.HuskyRange(this.window);
  18213. // 마지막 글자의 뒷부분 처리
  18214. var elContainer, nOffset;
  18215. if(j+nOriginLen < aElTexts[i].length){
  18216. elContainer = aElTexts[i][j+nOriginLen][0];
  18217. nOffset = aElTexts[i][j+nOriginLen][1];
  18218. }else{
  18219. elContainer = aElTexts[i][j+nOriginLen-1][0];
  18220. nOffset = aElTexts[i][j+nOriginLen-1][1]+1;
  18221. }
  18222. oSelection.setEnd(elContainer, nOffset, true, true);
  18223. oSelection.setStart(aElTexts[i][j][0], aElTexts[i][j][1], true);
  18224. if(typeof Replacement == "function"){
  18225. // the returned oSelection must contain the replacement
  18226. oSelection = Replacement(oSelection);
  18227. }else{
  18228. oSelection.pasteText(Replacement);
  18229. }
  18230. j -= nOriginLen;
  18231. }
  18232. continue;
  18233. }
  18234. }
  18235. /*
  18236. var t2 = new Date();
  18237. console.log("OK");
  18238. console.log(sOriginalWord);
  18239. console.log("MC:"+(t1-t0));
  18240. console.log("RP:"+(t2-t1));
  18241. */
  18242. return nMatchCnt;
  18243. }catch(e){
  18244. /*
  18245. console.log("ERROR");
  18246. console.log(sOriginalWord);
  18247. console.log(new Date()-t0);
  18248. */
  18249. return nMatchCnt;
  18250. }
  18251. }
  18252. });
  18253. nhn.husky.HuskyCore.addLoadedFile("SE2M_TableTemplate.js");
  18254. // "padding", "backgroundcolor", "border", "borderTop", "borderRight", "borderBottom", "borderLeft", "color", "textAlign", "fontWeight"
  18255. nhn.husky.SE2M_TableTemplate = [
  18256. {},
  18257. /*
  18258. // 0
  18259. {
  18260. htTableProperty : {
  18261. border : "0",
  18262. cellPadding : "0",
  18263. cellSpacing : "0"
  18264. },
  18265. htTableStyle : {
  18266. border : "1px dashed #666666",
  18267. borderRight : "0",
  18268. borderBottom : "0"
  18269. },
  18270. aRowStyle : [
  18271. {
  18272. padding : "3px 0 2px 0",
  18273. border : "1px dashed #666666",
  18274. borderTop : "0",
  18275. borderLeft : "0"
  18276. }
  18277. ]
  18278. },
  18279. // 1
  18280. {
  18281. htTableProperty : {
  18282. border : "0",
  18283. cellPadding : "0",
  18284. cellSpacing : "0"
  18285. },
  18286. htTableStyle : {
  18287. border : "1px solid #c7c7c7",
  18288. borderRight : "0",
  18289. borderBottom : "0"
  18290. },
  18291. aRowStyle : [
  18292. {
  18293. padding : "3px 0 2px 0",
  18294. border : "1px solid #c7c7c7",
  18295. borderTop : "0",
  18296. borderLeft : "0"
  18297. }
  18298. ]
  18299. },
  18300. // 2
  18301. {
  18302. htTableProperty : {
  18303. border : "0",
  18304. cellPadding : "0",
  18305. cellSpacing : "1"
  18306. },
  18307. htTableStyle : {
  18308. border : "1px solid #c7c7c7"
  18309. },
  18310. aRowStyle : [
  18311. {
  18312. padding : "2px 0 1px 0",
  18313. border : "1px solid #c7c7c7"
  18314. }
  18315. ]
  18316. },
  18317. // 3
  18318. {
  18319. htTableProperty : {
  18320. border : "0",
  18321. cellPadding : "0",
  18322. cellSpacing : "1"
  18323. },
  18324. htTableStyle : {
  18325. border : "1px double #c7c7c7"
  18326. },
  18327. aRowStyle : [
  18328. {
  18329. padding : "1px 0 0",
  18330. border : "3px double #c7c7c7"
  18331. }
  18332. ]
  18333. },
  18334. // 4
  18335. {
  18336. htTableProperty : {
  18337. border : "0",
  18338. cellPadding : "0",
  18339. cellSpacing : "1"
  18340. },
  18341. htTableStyle : {
  18342. borderWidth : "2px 1px 1px 2px",
  18343. borderStyle : "solid",
  18344. borderColor : "#c7c7c7"
  18345. },
  18346. aRowStyle : [
  18347. {
  18348. padding : "2px 0 0",
  18349. borderWidth : "1px 2px 2px 1px",
  18350. borderStyle : "solid",
  18351. borderColor : "#c7c7c7"
  18352. }
  18353. ]
  18354. },
  18355. // 5
  18356. {
  18357. htTableProperty : {
  18358. border : "0",
  18359. cellPadding : "0",
  18360. cellSpacing : "1"
  18361. },
  18362. htTableStyle : {
  18363. borderWidth : "1px 2px 2px 1px",
  18364. borderStyle : "solid",
  18365. borderColor : "#c7c7c7"
  18366. },
  18367. aRowStyle : [
  18368. {
  18369. padding : "1px 0 0",
  18370. borderWidth : "2px 1px 1px 2px",
  18371. borderStyle : "solid",
  18372. borderColor : "#c7c7c7"
  18373. }
  18374. ]
  18375. },
  18376. */
  18377. // Black theme ======================================================
  18378. // 6
  18379. {
  18380. htTableProperty : {
  18381. border : "0",
  18382. cellPadding : "0",
  18383. cellSpacing : "1"
  18384. },
  18385. htTableStyle : {
  18386. backgroundColor : "#c7c7c7"
  18387. },
  18388. aRowStyle : [
  18389. {
  18390. padding : "3px 4px 2px",
  18391. backgroundColor : "#ffffff",
  18392. color : "#666666"
  18393. }
  18394. ]
  18395. },
  18396. // 7
  18397. {
  18398. htTableProperty : {
  18399. border : "0",
  18400. cellPadding : "0",
  18401. cellSpacing : "1"
  18402. },
  18403. htTableStyle : {
  18404. backgroundColor : "#c7c7c7"
  18405. },
  18406. aRowStyle : [
  18407. {
  18408. padding : "3px 4px 2px",
  18409. backgroundColor : "#ffffff",
  18410. color : "#666666"
  18411. },
  18412. {
  18413. padding : "3px 4px 2px",
  18414. backgroundColor : "#f3f3f3",
  18415. color : "#666666"
  18416. }
  18417. ]
  18418. },
  18419. // 8
  18420. {
  18421. htTableProperty : {
  18422. border : "0",
  18423. cellPadding : "0",
  18424. cellSpacing : "0"
  18425. },
  18426. htTableStyle : {
  18427. backgroundColor : "#ffffff",
  18428. borderTop : "1px solid #c7c7c7"
  18429. },
  18430. aRowStyle : [
  18431. {
  18432. padding : "3px 4px 2px",
  18433. borderBottom : "1px solid #c7c7c7",
  18434. backgroundColor : "#ffffff",
  18435. color : "#666666"
  18436. },
  18437. {
  18438. padding : "3px 4px 2px",
  18439. borderBottom : "1px solid #c7c7c7",
  18440. backgroundColor : "#f3f3f3",
  18441. color : "#666666"
  18442. }
  18443. ]
  18444. },
  18445. // 9
  18446. {
  18447. htTableProperty : {
  18448. border : "0",
  18449. cellPadding : "0",
  18450. cellSpacing : "0"
  18451. },
  18452. htTableStyle : {
  18453. border : "1px solid #c7c7c7"
  18454. },
  18455. ht1stRowStyle : {
  18456. padding : "3px 4px 2px",
  18457. backgroundColor : "#f3f3f3",
  18458. color : "#666666",
  18459. borderRight : "1px solid #e7e7e7",
  18460. textAlign : "left",
  18461. fontWeight : "normal"
  18462. },
  18463. aRowStyle : [
  18464. {
  18465. padding : "3px 4px 2px",
  18466. backgroundColor : "#ffffff",
  18467. borderTop : "1px solid #e7e7e7",
  18468. borderRight : "1px solid #e7e7e7",
  18469. color : "#666666"
  18470. }
  18471. ]
  18472. },
  18473. // 10
  18474. {
  18475. htTableProperty : {
  18476. border : "0",
  18477. cellPadding : "0",
  18478. cellSpacing : "1"
  18479. },
  18480. htTableStyle : {
  18481. backgroundColor : "#c7c7c7"
  18482. },
  18483. aRowStyle : [
  18484. {
  18485. padding : "3px 4px 2px",
  18486. backgroundColor : "#f8f8f8",
  18487. color : "#666666"
  18488. },
  18489. {
  18490. padding : "3px 4px 2px",
  18491. backgroundColor : "#ebebeb",
  18492. color : "#666666"
  18493. }
  18494. ]
  18495. },
  18496. // 11
  18497. {
  18498. htTableProperty : {
  18499. border : "0",
  18500. cellPadding : "0",
  18501. cellSpacing : "0"
  18502. },
  18503. ht1stRowStyle : {
  18504. padding : "3px 4px 2px",
  18505. borderTop : "1px solid #000000",
  18506. borderBottom : "1px solid #000000",
  18507. backgroundColor : "#333333",
  18508. color : "#ffffff",
  18509. textAlign : "left",
  18510. fontWeight : "normal"
  18511. },
  18512. aRowStyle : [
  18513. {
  18514. padding : "3px 4px 2px",
  18515. borderBottom : "1px solid #ebebeb",
  18516. backgroundColor : "#ffffff",
  18517. color : "#666666"
  18518. },
  18519. {
  18520. padding : "3px 4px 2px",
  18521. borderBottom : "1px solid #ebebeb",
  18522. backgroundColor : "#f8f8f8",
  18523. color : "#666666"
  18524. }
  18525. ]
  18526. },
  18527. // 12
  18528. {
  18529. htTableProperty : {
  18530. border : "0",
  18531. cellPadding : "0",
  18532. cellSpacing : "1"
  18533. },
  18534. htTableStyle : {
  18535. backgroundColor : "#c7c7c7"
  18536. },
  18537. ht1stRowStyle : {
  18538. padding : "3px 4px 2px",
  18539. backgroundColor : "#333333",
  18540. color : "#ffffff",
  18541. textAlign : "left",
  18542. fontWeight : "normal"
  18543. },
  18544. ht1stColumnStyle : {
  18545. padding : "3px 4px 2px",
  18546. backgroundColor : "#f8f8f8",
  18547. color : "#666666",
  18548. textAlign : "left",
  18549. fontWeight : "normal"
  18550. },
  18551. aRowStyle : [
  18552. {
  18553. padding : "3px 4px 2px",
  18554. backgroundColor : "#ffffff",
  18555. color : "#666666"
  18556. }
  18557. ]
  18558. },
  18559. // 13
  18560. {
  18561. htTableProperty : {
  18562. border : "0",
  18563. cellPadding : "0",
  18564. cellSpacing : "1"
  18565. },
  18566. htTableStyle : {
  18567. backgroundColor : "#c7c7c7"
  18568. },
  18569. ht1stColumnStyle : {
  18570. padding : "3px 4px 2px",
  18571. backgroundColor : "#333333",
  18572. color : "#ffffff",
  18573. textAlign : "left",
  18574. fontWeight : "normal"
  18575. },
  18576. aRowStyle : [
  18577. {
  18578. padding : "3px 4px 2px",
  18579. backgroundColor : "#ffffff",
  18580. color : "#666666"
  18581. }
  18582. ]
  18583. },
  18584. // Blue theme ======================================================
  18585. // 14
  18586. {
  18587. htTableProperty : {
  18588. border : "0",
  18589. cellPadding : "0",
  18590. cellSpacing : "1"
  18591. },
  18592. htTableStyle : {
  18593. backgroundColor : "#a6bcd1"
  18594. },
  18595. aRowStyle : [
  18596. {
  18597. padding : "3px 4px 2px",
  18598. backgroundColor : "#ffffff",
  18599. color : "#3d76ab"
  18600. }
  18601. ]
  18602. },
  18603. // 15
  18604. {
  18605. htTableProperty : {
  18606. border : "0",
  18607. cellPadding : "0",
  18608. cellSpacing : "1"
  18609. },
  18610. htTableStyle : {
  18611. backgroundColor : "#a6bcd1"
  18612. },
  18613. aRowStyle : [
  18614. {
  18615. padding : "3px 4px 2px",
  18616. backgroundColor : "#ffffff",
  18617. color : "#3d76ab"
  18618. },
  18619. {
  18620. padding : "3px 4px 2px",
  18621. backgroundColor : "#f6f8fa",
  18622. color : "#3d76ab"
  18623. }
  18624. ]
  18625. },
  18626. // 16
  18627. {
  18628. htTableProperty : {
  18629. border : "0",
  18630. cellPadding : "0",
  18631. cellSpacing : "0"
  18632. },
  18633. htTableStyle : {
  18634. backgroundColor : "#ffffff",
  18635. borderTop : "1px solid #a6bcd1"
  18636. },
  18637. aRowStyle : [
  18638. {
  18639. padding : "3px 4px 2px",
  18640. borderBottom : "1px solid #a6bcd1",
  18641. backgroundColor : "#ffffff",
  18642. color : "#3d76ab"
  18643. },
  18644. {
  18645. padding : "3px 4px 2px",
  18646. borderBottom : "1px solid #a6bcd1",
  18647. backgroundColor : "#f6f8fa",
  18648. color : "#3d76ab"
  18649. }
  18650. ]
  18651. },
  18652. // 17
  18653. {
  18654. htTableProperty : {
  18655. border : "0",
  18656. cellPadding : "0",
  18657. cellSpacing : "0"
  18658. },
  18659. htTableStyle : {
  18660. border : "1px solid #a6bcd1"
  18661. },
  18662. ht1stRowStyle : {
  18663. padding : "3px 4px 2px",
  18664. backgroundColor : "#f6f8fa",
  18665. color : "#3d76ab",
  18666. borderRight : "1px solid #e1eef7",
  18667. textAlign : "left",
  18668. fontWeight : "normal"
  18669. },
  18670. aRowStyle : [
  18671. {
  18672. padding : "3px 4px 2px",
  18673. backgroundColor : "#ffffff",
  18674. borderTop : "1px solid #e1eef7",
  18675. borderRight : "1px solid #e1eef7",
  18676. color : "#3d76ab"
  18677. }
  18678. ]
  18679. },
  18680. // 18
  18681. {
  18682. htTableProperty : {
  18683. border : "0",
  18684. cellPadding : "0",
  18685. cellSpacing : "1"
  18686. },
  18687. htTableStyle : {
  18688. backgroundColor : "#a6bcd1"
  18689. },
  18690. aRowStyle : [
  18691. {
  18692. padding : "3px 4px 2px",
  18693. backgroundColor : "#fafbfc",
  18694. color : "#3d76ab"
  18695. },
  18696. {
  18697. padding : "3px 4px 2px",
  18698. backgroundColor : "#e6ecf2",
  18699. color : "#3d76ab"
  18700. }
  18701. ]
  18702. },
  18703. // 19
  18704. {
  18705. htTableProperty : {
  18706. border : "0",
  18707. cellPadding : "0",
  18708. cellSpacing : "0"
  18709. },
  18710. ht1stRowStyle : {
  18711. padding : "3px 4px 2px",
  18712. borderTop : "1px solid #466997",
  18713. borderBottom : "1px solid #466997",
  18714. backgroundColor : "#6284ab",
  18715. color : "#ffffff",
  18716. textAlign : "left",
  18717. fontWeight : "normal"
  18718. },
  18719. aRowStyle : [
  18720. {
  18721. padding : "3px 4px 2px",
  18722. borderBottom : "1px solid #ebebeb",
  18723. backgroundColor : "#ffffff",
  18724. color : "#3d76ab"
  18725. },
  18726. {
  18727. padding : "3px 4px 2px",
  18728. borderBottom : "1px solid #ebebeb",
  18729. backgroundColor : "#f6f8fa",
  18730. color : "#3d76ab"
  18731. }
  18732. ]
  18733. },
  18734. // 20
  18735. {
  18736. htTableProperty : {
  18737. border : "0",
  18738. cellPadding : "0",
  18739. cellSpacing : "1"
  18740. },
  18741. htTableStyle : {
  18742. backgroundColor : "#a6bcd1"
  18743. },
  18744. ht1stRowStyle : {
  18745. padding : "3px 4px 2px",
  18746. backgroundColor : "#6284ab",
  18747. color : "#ffffff",
  18748. textAlign : "left",
  18749. fontWeight : "normal"
  18750. },
  18751. ht1stColumnStyle : {
  18752. padding : "3px 4px 2px",
  18753. backgroundColor : "#f6f8fa",
  18754. color : "#3d76ab",
  18755. textAlign : "left",
  18756. fontWeight : "normal"
  18757. },
  18758. aRowStyle : [
  18759. {
  18760. padding : "3px 4px 2px",
  18761. backgroundColor : "#ffffff",
  18762. color : "#3d76ab"
  18763. }
  18764. ]
  18765. },
  18766. // 21
  18767. {
  18768. htTableProperty : {
  18769. border : "0",
  18770. cellPadding : "0",
  18771. cellSpacing : "1"
  18772. },
  18773. htTableStyle : {
  18774. backgroundColor : "#a6bcd1"
  18775. },
  18776. ht1stColumnStyle : {
  18777. padding : "3px 4px 2px",
  18778. backgroundColor : "#6284ab",
  18779. color : "#ffffff",
  18780. textAlign : "left",
  18781. fontWeight : "normal"
  18782. },
  18783. aRowStyle : [
  18784. {
  18785. padding : "3px 4px 2px",
  18786. backgroundColor : "#ffffff",
  18787. color : "#3d76ab"
  18788. }
  18789. ]
  18790. }
  18791. ];
  18792. nhn.husky.HuskyCore.addLoadedFile("N_DraggableLayer.js");
  18793. /**
  18794. * @fileOverview This file contains a function that takes care of the draggable layers
  18795. * @name N_DraggableLayer.js
  18796. */
  18797. nhn.DraggableLayer = jindo.$Class({
  18798. $init : function(elLayer, oOptions){
  18799. this.elLayer = elLayer;
  18800. this.setOptions(oOptions);
  18801. this.elHandle = this.oOptions.elHandle;
  18802. elLayer.style.display = "block";
  18803. elLayer.style.position = "absolute";
  18804. elLayer.style.zIndex = "9999";
  18805. this.aBasePosition = this.getBaseOffset(elLayer);
  18806. // "number-ize" the position and set it as inline style. (the position could've been set as "auto" or set by css, not inline style)
  18807. var nTop = (this.toInt(jindo.$Element(elLayer).offset().top) - this.aBasePosition.top);
  18808. var nLeft = (this.toInt(jindo.$Element(elLayer).offset().left) - this.aBasePosition.left);
  18809. var htXY = this._correctXY({x:nLeft, y:nTop});
  18810. elLayer.style.top = htXY.y+"px";
  18811. elLayer.style.left = htXY.x+"px";
  18812. this.$FnMouseDown = jindo.$Fn(jindo.$Fn(this._mousedown, this).bind(elLayer), this);
  18813. this.$FnMouseMove = jindo.$Fn(jindo.$Fn(this._mousemove, this).bind(elLayer), this);
  18814. this.$FnMouseUp = jindo.$Fn(jindo.$Fn(this._mouseup, this).bind(elLayer), this);
  18815. this.$FnMouseDown.attach(this.elHandle, "mousedown");
  18816. this.elHandle.ondragstart = new Function('return false');
  18817. this.elHandle.onselectstart = new Function('return false');
  18818. },
  18819. _mousedown : function(elLayer, oEvent){
  18820. if(oEvent.element.tagName == "INPUT") return;
  18821. this.oOptions.fnOnDragStart();
  18822. this.MouseOffsetY = (oEvent.pos().clientY-this.toInt(elLayer.style.top)-this.aBasePosition['top']);
  18823. this.MouseOffsetX = (oEvent.pos().clientX-this.toInt(elLayer.style.left)-this.aBasePosition['left']);
  18824. this.$FnMouseMove.attach(elLayer.ownerDocument, "mousemove");
  18825. this.$FnMouseUp.attach(elLayer.ownerDocument, "mouseup");
  18826. this.elHandle.style.cursor = "move";
  18827. },
  18828. _mousemove : function(elLayer, oEvent){
  18829. var nTop = (oEvent.pos().clientY-this.MouseOffsetY-this.aBasePosition['top']);
  18830. var nLeft = (oEvent.pos().clientX-this.MouseOffsetX-this.aBasePosition['left']);
  18831. var htXY = this._correctXY({x:nLeft, y:nTop});
  18832. elLayer.style.top = htXY.y + "px";
  18833. elLayer.style.left = htXY.x + "px";
  18834. },
  18835. _mouseup : function(elLayer, oEvent){
  18836. this.oOptions.fnOnDragEnd();
  18837. this.$FnMouseMove.detach(elLayer.ownerDocument, "mousemove");
  18838. this.$FnMouseUp.detach(elLayer.ownerDocument, "mouseup");
  18839. this.elHandle.style.cursor = "";
  18840. },
  18841. _correctXY : function(htXY){
  18842. var nLeft = htXY.x;
  18843. var nTop = htXY.y;
  18844. if(nTop<this.oOptions.nMinY) nTop = this.oOptions.nMinY;
  18845. if(nTop>this.oOptions.nMaxY) nTop = this.oOptions.nMaxY;
  18846. if(nLeft<this.oOptions.nMinX) nLeft = this.oOptions.nMinX;
  18847. if(nLeft>this.oOptions.nMaxX) nLeft = this.oOptions.nMaxX;
  18848. return {x:nLeft, y:nTop};
  18849. },
  18850. toInt : function(num){
  18851. var result = parseInt(num);
  18852. return result || 0;
  18853. },
  18854. findNonStatic : function(oEl){
  18855. if(!oEl) return null;
  18856. if(oEl.tagName == "BODY") return oEl;
  18857. if(jindo.$Element(oEl).css("position").match(/absolute|relative/i)) return oEl;
  18858. return this.findNonStatic(oEl.offsetParent);
  18859. },
  18860. getBaseOffset : function(oEl){
  18861. var oBase = this.findNonStatic(oEl.offsetParent) || oEl.ownerDocument.body;
  18862. var tmp = jindo.$Element(oBase).offset();
  18863. return {top: tmp.top, left: tmp.left};
  18864. },
  18865. setOptions : function(htOptions){
  18866. this.oOptions = htOptions || {};
  18867. this.oOptions.bModal = this.oOptions.bModal || false;
  18868. this.oOptions.elHandle = this.oOptions.elHandle || this.elLayer;
  18869. this.oOptions.nMinX = this.oOptions.nMinX || -999999;
  18870. this.oOptions.nMinY = this.oOptions.nMinY || -999999;
  18871. this.oOptions.nMaxX = this.oOptions.nMaxX || 999999;
  18872. this.oOptions.nMaxY = this.oOptions.nMaxY || 999999;
  18873. this.oOptions.fnOnDragStart = this.oOptions.fnOnDragStart || function(){};
  18874. this.oOptions.fnOnDragEnd = this.oOptions.fnOnDragEnd || function(){};
  18875. }
  18876. });