// ================================================================ // CHEditor 5.1.9.4 // ---------------------------------------------------------------- // Homepage: http://www.chcode.com // EMail: support@chcode.com // Copyright (c) 1997-2019 CHSOFT // ================================================================ var GB = { colors: ['#000000', '#313131', '#434343', '#535353', '#666666', '#999999', '#a0a0a0', '#b5b5b5', '#c0c0c0', '#dcdcdc', '#eeeeee', '#ffffff', '#ff0000', '#ff8000', '#ffff00', '#80ff00', '#00ff00', '#00ff99', '#00ffff', '#0080ff', '#0000ff', '#7f00ff', '#ff00ff', '#ff007f', '#ffcccc', '#ffe5cc', '#ffffcc', '#e5ffcc', '#ccffcc', '#ccffe5', '#ccffff', '#cce5ff', '#ccccff', '#e5ccff', '#ffccff', '#ffcce5', '#ff9999', '#ffcc99', '#ffff99', '#ccff99', '#99ff99', '#99ffcc', '#99ffff', '#99ccff', '#9999ff', '#cc99ff', '#ff99ff', '#ff99cc', '#ff6666', '#ffb266', '#ffff66', '#b2ff66', '#66ff66', '#66ffb2', '#66ffff', '#66b2ff', '#6666ff', '#b266ff', '#ff66ff', '#ff66b2', '#ff3333', '#ff9933', '#ffff33', '#99ff33', '#33ff33', '#33ff99', '#33ffff', '#3399ff', '#3333ff', '#9933ff', '#ff33ff', '#ff3399', '#cc0000', '#cc6600', '#cccc00', '#66cc00', '#00cc00', '#00cc66', '#00cccc', '#0066cc', '#0000cc', '#6600cc', '#cc00cc', '#cc0066', '#990000', '#994c00', '#999900', '#4c9900', '#009900', '#00994c', '#009999', '#004c99', '#000099', '#4c0099', '#990099', '#99004c', '#660000', '#663300', '#666600', '#336600', '#006600', '#006633', '#006666', '#003366', '#000066', '#330066', '#660066', '#660033'], offElementTags: { button: 1, embed: 1, fieldset: 1, form: 1, hr: 1, img: 1, input: 1, object: 1, select: 1, table: 1, textarea: 1 }, selfClosingTags: { area: 1, base: 1, br: 1, col: 1, command: 1, embed: 1, hr: 1, img: 1, input: 1, keygen: 1, link: 1, meta: 1, param: 1, source: 1, track: 1, wbr: 1 }, textFormatTags: { a: 1, addr: 1, acronym: 1, b: 1, bdo: 1, big: 1, cite: 1, code: 1, del: 1, dfn: 1, em: 1, font: 1, i: 1, ins: 1, kbd: 1, q: 1, samp: 1, small: 1, strike: 1, strong: 1, sub: 1, sup: 1, time: 1, tt: 1, u: 1, 'var': 1, span: 1 }, textFormatBlockTags: { address: 1, div: 1, h1: 1, h2: 1, h3: 1, h4: 1, h5: 1, h6: 1, p: 1, pre: 1, code: 1, section: 1, aside: 1, article: 1, figcaption: 1 }, newLineBeforeTags: { address: 1, article: 1, aside: 1, audio: 1, blockquote: 1, body: 1, canvas: 1, code: 1, comment: 1, dd: 1, div: 1, dl: 1, fieldset: 1, figcaption: 1, figure: 1, footer: 1, form: 1, h1: 1, h2: 1, h3: 1, h4: 1, h5: 1, h6: 1, head: 1, header: 1, hggroup: 1, hr: 1, li: 1, noscript: 1, ol: 1, output: 1, p: 1, pre: 1, script: 1, section: 1, table: 1, tbody: 1, td: 1, tfoot: 1, th: 1, thead: 1, title: 1, tr: 1, ul: 1, video: 1 }, lineHeightBlockTags: { address: 1, article: 1, aside: 1, blockquote: 1, code: 1, dd: 1, div: 1, dt: 1, figcaption: 1, figure: 1, h1: 1, h2: 1, h3: 1, h4: 1, h5: 1, h6: 1, li: 1, p: 1, pre: 1, section: 1, td: 1, th: 1 }, listTags: { dd: 1, dt: 1, li: 1 }, lineBreakTags: { address: 1, article: 1, aside: 1, dd: 1, div: 1, dt: 1, figcaption: 1, li: 1, p: 1, section: 1 }, doctype: '', popupWindow: { ColorPicker: { tmpl: 'color_picker.html', width: 420, title: '색상 선택' }, Embed: { tmpl: 'media.html', width: 430, title: '미디어' }, EmotionIcon: { tmpl: 'icon.html', width: 300, title: '표정 아이콘' }, FlashMovie: { tmpl: 'flash.html', width: 584, title: '플래쉬 동영상' }, GoogleMap: { tmpl: 'google_map.html', width: 538, title: '구글 지도' }, ImageUpload: { tmpl: 'image.html', width: 700, title: '내 PC 사진 넣기' }, ImageUrl: { tmpl: 'image_url.html', width: 350, title: '웹 사진 넣기' }, Layout: { tmpl: 'layout.html', width: 430, title: '레이아웃' }, Link: { tmpl: 'link.html', width: 350, title: '하이퍼링크' }, ModifyTable: { tmpl: 'table_modify.html', width: 430, title: '표 고치기' }, Symbol: { tmpl: 'symbol.html', width: 450, title: '특수 문자' }, Table: { tmpl: 'table.html', width: 430, title: '표 만들기' } }, fontName: { kr: ['맑은 고딕', '돋움', '굴림', '바탕', '궁서'], en: ['Arial', 'Comic Sans MS', 'Courier New', 'Georgia', 'HeadLineA', 'Impact', 'Tahoma', 'Times New Roman', 'Verdana'] }, fontStyle: { FontSize: 'font-size', FontName: 'font-family', ForeColor: 'color', BackColor: 'background-color' }, textAlign: { JustifyLeft: '', JustifyCenter: 'center', JustifyRight: 'right', JustifyFull: 'justify' }, listStyle: { ordered: { decimal: '숫자', 'lower-alpha': '영문 소문자', 'upper-alpha': '영문 대문자', 'lower-roman': '로마 소문자', 'upper-roman': '로마 대문자' }, unOrdered: { desc: '동그라미', circle: '빈 원', square: '사각형' } }, fontSize: { pt: [7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36], px: [9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72] }, formatBlock: { P: '일반 텍스트', H1: '제목 1', H2: '제목 2', H3: '제목 3', H4: '제목 4', H5: '제목 5', H6: '제목 6', ADDRESS: 'Address', DIV: 'DIV', PRE: 'Preformatted (PRE)' }, lineHeight: { '한 줄 간격': 1, '1.15': 1.15, '1.5': 1.5, '1.7': 1.7, '1.8': 1.8, '두 줄 간격': 2 }, textBlock: [ ['1px #dedfdf solid', '#f7f7f7'], ['1px #aee8e8 solid', '#bfffff'], ['1px #d3bceb solid', '#e6ccff'], ['1px #e8e88b solid', '#ffff99'], ['1px #c3e89e solid', '#d6ffad'], ['1px #e8c8b7 solid', '#ffdcc9'], ['1px #666666 dashed', '#ffffff'], ['1px #d4d4d4 solid', '#ffffff'], ['1px #cccccc inset', '#f7f7f7'] ], node: { element: 1, attribute: 2, text: 3, cdata_section: 4, entity_reference: 5, entity: 6, processing_instruction: 7, comment: 8, document: 9, document_type: 10, document_fragment: 11, notation: 12 }, selection: { none: 1, text: 2, element: 3 }, readyState: { 0: 'uninitialized', 1: 'loading', 2: 'loaded', 3: 'interactive', 4: 'complete' }, dragWindow: null, colorDropper: null, readyEditor: 0, browser: {} }; function isUndefined(obj) { return obj === void (0); // obj === undefined; } function detechBrowser() { function detect(ua) { var iosdevice = getFirstMatch(/(ipod|iphone|ipad)/i).toLowerCase(), likeAndroid = /like android/i.test(ua), android = !likeAndroid && /android/i.test(ua), versionIdentifier = getFirstMatch(/version\/(\d+(\.\d+)?)/i), tablet = /tablet/i.test(ua), mobile = !tablet && /[^\-]mobi/i.test(ua), result, osVersion = '', osMajorVersion, osname, app; function getFirstMatch(regex) { var match = ua.match(regex); return (match && match.length > 1 && match[1]) || ''; } if (/opera|opr/i.test(ua)) { result = { name: 'Opera', opera: true, version: versionIdentifier || getFirstMatch(/(?:opera|opr)[\s\/](\d+(\.\d+)?)/i) }; } else if (/windows phone/i.test(ua)) { result = { name: 'Windows Phone', windowsphone: true, msie: true, version: getFirstMatch(/iemobile\/(\d+(\.\d+)?)/i) }; } else if (/msie|trident/i.test(ua)) { result = { name: 'Internet Explorer', msie: true, version: getFirstMatch(/(?:msie |rv:)(\d+(\.\d+)?)/i) }; } else if (/edge/i.test(ua)) { result = { name: 'edge', edge: true, version: getFirstMatch(/(?:edge)\/(\d+(\.\d+)?)/i) }; } else if (/chrome|crios|crmo/i.test(ua)) { result = { name: 'Chrome', chrome: true, version: getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.\d+)?)/i) }; } else if (iosdevice) { result = { name: iosdevice === 'iphone' ? 'iPhone' : iosdevice === 'ipad' ? 'iPad' : 'iPod' }; if (versionIdentifier) { result.version = versionIdentifier; } } else if (/firefox|iceweasel/i.test(ua)) { result = { name: 'Firefox', firefox: true, version: getFirstMatch(/(?:firefox|iceweasel)[ \/](\d+(\.\d+)?)/i) }; if (/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(ua)) { result.firefoxos = true; } } else if (/silk/i.test(ua)) { result = { name: 'Amazon Silk', silk: true, version: getFirstMatch(/silk\/(\d+(\.\d+)?)/i) }; } else if (android) { result = { name: 'Android', version: versionIdentifier }; } else if (/phantom/i.test(ua)) { result = { name: 'PhantomJS', phantom: true, version: getFirstMatch(/phantomjs\/(\d+(\.\d+)?)/i) }; } else if (/blackberry|\bbb\d+/i.test(ua) || /rim\stablet/i.test(ua)) { result = { name: 'BlackBerry', blackberry: true, version: versionIdentifier || getFirstMatch(/blackberry[\d]+\/(\d+(\.\d+)?)/i) }; } else if (/(web|hpw)os/i.test(ua)) { result = { name: 'WebOS', webos: true, version: versionIdentifier || getFirstMatch(/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i) }; if (/touchpad\//i.test(ua)) { result.touchpad = true; } } else if (/safari/i.test(ua)) { result = { name: 'Safari', safari: true, version: versionIdentifier }; } else { result = {}; } if (/(apple)?webkit/i.test(ua)) { result.name = result.name || 'Webkit'; result.webkit = true; if (!result.version && versionIdentifier) { result.version = versionIdentifier; } } else if (!result.opera && /gecko\//i.test(ua)) { result.gecko = true; result.version = result.version || getFirstMatch(/gecko\/(\d+(\.\d+)?)/i); result.name = result.name || 'Gecko'; } if (android || result.silk) { result.android = true; } else if (iosdevice) { result[iosdevice] = true; result.ios = true; } if (iosdevice) { osVersion = getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i); osVersion = osVersion.replace(/[_\s]/g, '.'); } else if (android) { osVersion = getFirstMatch(/android[ \/\-](\d+(\.\d+)*)/i); } else if (result.windowsphone) { osVersion = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i); } else if (result.webos) { osVersion = getFirstMatch(/(?:web|hpw)os\/(\d+(\.\d+)*)/i); } else if (result.blackberry) { osVersion = getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i); } if (osVersion) { result.osversion = osVersion; } osMajorVersion = osVersion.split('.')[0]; if (tablet || iosdevice === 'ipad' || (android && (osMajorVersion === 3 || (osMajorVersion === 4 && !mobile))) || result.silk) { result.tablet = true; } else if (mobile || iosdevice === 'iphone' || iosdevice === 'ipod' || android || result.blackberry || result.webos) { result.mobile = true; } if (result.edge || (result.msie && result.version >= 10) || (result.chrome && result.version >= 20) || (result.firefox && result.version >= 20.0) || (result.safari && result.version >= 6) || (result.opera && result.version >= 10.0) || (result.ios && result.osversion && result.osversion.split('.')[0] >= 6) || (result.blackberry && result.version >= 10.1)) { result.a = true; } else if ((result.msie && result.version < 10) || (result.chrome && result.version < 20) || (result.firefox && result.version < 20.0) || (result.safari && result.version < 6) || (result.opera && result.version < 10.0) || (result.ios && result.osversion && result.osversion.split('.')[0] < 6)) { result.c = true; } else { result.x = true; } osname = ''; if (/windows/i.test(ua)) { osname = 'Windows'; } else if (/mac/i.test(ua)) { osname = 'MacOS'; } else if (/x11/i.test(ua)) { osname = 'UNIX'; } else if (/linux/i.test(ua)) { osname = 'Linux'; } else if (/sunos/i.test(ua)) { osname = 'Solaris'; } else { osname = 'Unknown OS'; } result.osname = osname; if (osname === 'Windows') { app = getFirstMatch(/(Windows NT\s(\d+)\.(\d+))/i); switch (app) { case 'Windows NT 5.1': result.os = 'Windows XP'; break; case 'Windows NT 5.2': result.os = 'Windows 2003'; break; case 'Windows NT 6.0': result.os = 'Windows Vista'; break; case 'Windows NT 6.1': result.os = 'Windows 7'; break; case 'Windows NT 6.2': result.os = 'Windows 8'; break; case 'Windows NT 6.3': result.os = 'Windows 8.1'; break; case 'Windows NT 10.0': result.os = 'Windows 10'; break; default: result.os = app; } } if (result.msie) { if (result.version > 10) { result.msie_a = true; result.msie_bogus = true; } else if (result.version > 8) { result.msie_b = true; result.msie_bogus = false; } else { result.msie_c = true; result.msie_bogus = (result.os === 'Windows XP'); } } return result; } return detect(!isUndefined(navigator) ? navigator.userAgent : null); } function URI(uri) { this.scheme = null; this.authority = null; this.path = ''; this.query = null; this.fragment = null; this.parseUri = function (uri) { var m = uri.match(/^(([A-Za-z][0-9A-Za-z+.\-]*)(:))?((\/\/)([^\/?#]*))?([^?#]*)((\?)([^#]*))?((#)(.*))?/); this.scheme = m[3] ? m[2] : null; this.authority = m[5] ? m[6] : null; this.path = m[7]; this.query = m[9] ? m[10] : null; this.fragment = m[12] ? m[13] : null; return this; }; this.azToString = function () { var result = ''; if (this.scheme !== null) { result = result + this.scheme + ':'; } if (this.authority !== null) { result = result + '//' + this.authority; } if (this.path !== null) { result = result + this.path; } if (this.query !== null) { result = result + '?' + this.query; } if (this.fragment !== null) { result = result + '#' + this.fragment; } return result; }; this.toAbsolute = function (location) { var baseUri = new URI(location), URIAbs = this, target = new URI(), removeDotSegments = function (path) { var result = '', rm; while (path) { if (path.substr(0, 3) === '../' || path.substr(0, 2) === './') { path = path.replace(/^\.+/, '').substr(1); } else if (path.substr(0, 3) === '/./' || path === '/.') { path = '/' + path.substr(3); } else if (path.substr(0, 4) === '/../' || path === '/..') { path = '/' + path.substr(4); result = result.replace(/\/?[^\/]*$/, ''); } else if (path === '.' || path === '..') { path = ''; } else { rm = path.match(/^\/?[^\/]*/)[0]; path = path.substr(rm.length); result = result + rm; } } return result; }; if (baseUri.scheme === null) { return false; } if (URIAbs.scheme !== null && URIAbs.scheme.toLowerCase() === baseUri.scheme.toLowerCase()) { URIAbs.scheme = null; } if (URIAbs.scheme !== null) { target.scheme = URIAbs.scheme; target.authority = URIAbs.authority; target.path = removeDotSegments(URIAbs.path); target.query = URIAbs.query; } else { if (URIAbs.authority !== null) { target.authority = URIAbs.authority; target.path = removeDotSegments(URIAbs.path); target.query = URIAbs.query; } else { if (URIAbs.path === '') { target.path = baseUri.path; target.query = URIAbs.query || baseUri.query; } else { if (URIAbs.path.substr(0, 1) === '/') { target.path = removeDotSegments(URIAbs.path); } else { if (baseUri.authority !== null && baseUri.path === '') { target.path = '/' + URIAbs.path; } else { target.path = baseUri.path.replace(/[^\/]+$/, '') + URIAbs.path; } target.path = removeDotSegments(target.path); } target.query = URIAbs.query; } target.authority = baseUri.authority; } target.scheme = baseUri.scheme; } target.fragment = URIAbs.fragment; return target; }; if (uri) { this.parseUri(uri); } } function setConfig() { var config = { allowedOnEvent: true, colorToHex: true, docTitle: '내 문서', editAreaMargin: '5px 10px', editorBgColor: '#fff', editorFontColor: '#000', editorFontName: '"맑은 고딕", "Malgun Gothic", gulim', editorFontSize: '12px', editorHeight: '300px', editorPath: null, editorWidth: '100%', exceptedElements: { script: true, style: true, iframe: false }, fontSizeValue: 'px', // [pt, px] fullHTMLSource: false, imgBlockMargin: '5px 0px', imgCaptionFigure: 'border: 1px #ccc solid; background-color: #f0f0f0; margin: 0', imgCaptionText: 'margin: 5px 5px; text-align: left; line-height: 17px', imgCaptionWrapper: '', imgDefaultAlign: 'left', // [left, center, right] imgJpegQuality: 0.92, // JPEG 사진의 퀄리티 값, 최대값 1 imgMaxWidth: 800, // 사진 최대 가로 크기, 이 크기 보다 크면 리사이징 처리 imgResizeMinLimit: 32, // 사진 리사이징의 사용자 직접 입력 값이 이 값 보다 작으면, 이 값으로 설정 imgResizeSelected: 800, // 사진 리사이징의 선택 입력 폼의 기본 선택 값 imgResizeValue: [120, 240, 320, 640, 800, -1], // -1 = 사용자 직접 입력 imgSetAttrAlt: true, imgSetAttrWidth: 1, // -1 = (width="100%"; height="auto"), 0 = 설정 안함, 1 = 기본값 imgUploadNumber: 12, imgUploadSortName: false, imgWaterMarkAlpha: 1, // 워터마크 불투명도 (최대값 1) imgWaterMarkUrl: '', // 워터마크 이미지 URL (예: 'http://udomain.com/cheditor/icons/watermark.png') includeHostname: true, lineHeight: 1.7, linkTarget: '_blank', makeThumbnail: false, // 사진의 썸네일 이미지 생성, 가로 크기는 thumbnailWidth 값, 세로는 자동 계산 paragraphCss: false, // true =
, false = removeIndent: false, showTagPath: false, tabIndent: 3, tabIndex: 0, thumbnailWidth: 120, // 버튼 사용 유무 useSource: true, usePreview: true, usePrint: true, useNewDocument: true, useUndo: true, useRedo: true, useCopy: true, useCut: true, usePaste: true, usePasteFromWord: true, useSelectAll: true, useStrikethrough: true, useUnderline: true, useItalic: true, useSuperscript: false, useSubscript: false, useJustifyLeft: true, useJustifyCenter: true, useJustifyRight: true, useJustifyFull: true, useBold: true, useOrderedList: true, useUnOrderedList: true, useOutdent: true, useIndent: true, useFontName: true, useFormatBlock: true, useFontSize: true, useLineHeight: true, useBackColor: true, useForeColor: true, useRemoveFormat: true, useClearTag: true, useSymbol: true, useLink: true, useUnLink: true, useFlash: true, useMedia: false, useImage: true, useImageUrl: false, useSmileyIcon: true, useHR: true, useTable: true, useModifyTable: true, useMap: true, useTextBlock: true, useFullScreen: true, usePageBreak: false }, base, elem, i, editorUri, locationAbs; if (config.editorPath === null) { base = location.href; elem = document.getElementsByTagName('base'); for (i = 0; i < elem.length; i++) { if (elem[i].href) { base = elem[i].href; } } elem = document.getElementsByTagName('script'); for (i = 0; i < elem.length; i++) { if (elem[i].src) { editorUri = new URI(elem[i].src); if (/\/cheditor\.js$/.test(editorUri.path)) { locationAbs = editorUri.toAbsolute(base).azToString(); delete locationAbs.query; delete locationAbs.fragment; config.editorPath = locationAbs.replace(/[^\/]+$/, ''); } } } if (config.editorPath === null) { throw 'CHEditor 경로가 바르지 않습니다.\nmyeditor.config.editorPath를 설정하여 주십시오.'; } } this.storedSelections = []; this.keyPressStoredSelections = []; this.images = []; this.editImages = {}; this.cheditor = {}; this.toolbar = {}; this.pulldown = {}; this.currentRS = {}; this.resizeEditor = {}; this.setFullScreenMode = false; this.modalElementZIndex = 1001; this.config = config; this.templateFile = 'template.xml'; this.templatePath = config.editorPath + this.templateFile; this.W3CRange = !(this.undefined(window.getSelection)); this.inputForm = 'textAreaId'; this.range = null; this.tempTimer = null; this.cheditor.tabSpaces = ''; this.cheditor.modifyState = false; this.cheditor.tabSpaces = new Array(this.config.tabIndent + 1).join(' '); } function cheditor() { this.toType = (function (global) { var toString = cheditor.prototype.toString, re = /^.*\s(\w+).*$/; return function (obj) { if (obj === global) { return 'global'; } return toString.call(obj).replace(re, '$1').toLowerCase(); }; }(this)); this.undefined = isUndefined; GB.browser = this.browser = detechBrowser(); if (this.undefined(document.execCommand)) { alert('현재 브라우저에서 CHEditor를 실행할 수 없습니다.'); return null; } if (this.browser.msie && this.browser.version < 7) { alert('CHEditor는 Internet Explorer 7 이하 버전은 지원하지 않습니다.'); return null; } try { setConfig.call(this); this.cheditor.id = (this.undefined(GB.readyEditor)) ? 1 : GB.readyEditor++; } catch (e) { alert(e.toString()); return null; } return this; } cheditor.prototype = { //---------------------------------------------------------------- resetData: function () { if (GB.browser.msie) { if (this.undefined(this.cheditor.editArea.onreadystatechange)) { GB.browser.version = 11; } GB.browser.msie_bogus = (GB.browser.version < 8 || GB.browser.version > 10); document.execCommand('BackgroundImageCache', false, true); } this.resetEditArea(); }, appendContents: function (contents) { var div = this.doc.createElement('div'); this.editAreaFocus(); div.innerHTML = String(this.trimSpace(contents)); while (div.hasChildNodes()) { this.doc.body.appendChild(div.firstChild); } this.editAreaFocus(); }, insertContents: function (contents) { this.editAreaFocus(); this.doCmdPaste(String(this.trimSpace(contents))); }, replaceContents: function (contents) { this.editAreaFocus(); this.doc.body.innerHTML = ''; this.loadContents(contents); this.editAreaFocus(); }, loadContents: function (contents) { if (typeof contents === 'string') { contents = this.trimSpace(contents); if (contents) { this.cheditor.editArea.style.visibility = 'hidden'; this.doc.body.innerHTML = contents; this.cheditor.editArea.style.visibility = 'visible'; } } }, setFolderPath: function () { if (this.config.editorPath.charAt(this.config.editorPath.length - 1) !== '/') { this.config.editorPath += '/'; } this.config.iconPath = this.config.editorPath + 'icons/'; this.config.cssPath = this.config.editorPath + 'css/'; this.config.popupPath = this.config.editorPath + 'popup/'; }, checkInputForm: function () { var textarea = document.getElementById(this.inputForm); if (!textarea) { throw 'ID가 "' + this.inputForm + '"인 textarea 개체를 찾을 수 없습니다.'; } textarea.style.display = 'none'; this.cheditor.textarea = textarea; }, setDesignMode: function (designMode, doc) { var mode = designMode ? 'on' : 'off'; doc = doc || this.doc; if (GB.browser.msie) { if (doc.body.contentEditable !== designMode) { doc.body.contentEditable = designMode; } return; } if (doc.designMode !== mode) { doc.designMode = mode; } }, openDoc: function (doc, contents) { var html = '' + ''; }, resetStatusBar: function () { if (this.config.showTagPath) { this.cheditor.tagPath.innerHTML = '<html> <body> '; } }, previewMode: function () { var content, oSheet, pos = this.getTextContentSelectionPos(false); if (this.cheditor.mode === 'code' && typeof this.resizeTextContent !== 'undefined') { this.cheditor.textContent.setAttribute('start-pos', pos.startPos.toString()); this.cheditor.textContent.setAttribute('end-pos', pos.endPos.toString()); content = this.makeHtmlContent(); this.cheditor.textContent.blur(); this.cheditor.textContent.style.display = 'none'; this.removeEvent(window, 'resize', this.resizeTextContent); this.putContents(content); } this.clearSelection(); this.cheditor.editBlock.style.display = 'none'; this.cheditor.toolbarWrapper.className = 'cheditor-tb-wrapper-preview'; if (!this.setFullScreenMode) { this.cheditor.editArea.style.height = this.config.editorHeight; } this.cheditor.editArea.style.display = 'block'; if (GB.browser.msie && parseInt(GB.browser.version, 10) === 8) { try { oSheet = this.doc.styleSheets[0]; oSheet.addRule('p:before', 'content:"\u200b"'); } catch (ignore) { // ignore } } this.setImageEvent(false); this.setDesignMode(false); }, convertContentsSpacer: function (content) { var self = this, bogusBr = true, excepted = '<\/span><\/span>', reSpacer = new RegExp('<([^>]+)>(' + excepted + ')?(?: |\s+?|\u00a0)(' + excepted + ')?<\/([^>]+)>', 'g'); if (GB.browser.msie && GB.browser.msie_bogus === false) { bogusBr = false; } content = content.replace(/\s{2,}|[\r\n\t]+?/gm, ''); content = content.replace(reSpacer, function (all, open, excepted_a, excepted_b, close) { var tagName = self.trimSpace(open.split(' ')[0]).toLowerCase(), rdata = null; if (GB.lineHeightBlockTags[tagName] || GB.textFormatTags[tagName]) { rdata = '<' + open + '>' + (excepted_a || ''); rdata += bogusBr ? '
]*/ig, '
]*<\/span>/ig, '');
return doc;
},
printPageBreak: function () {
var hr = document.createElement('hr'),
div = this.doc.createElement('div');
hr.style.pageBreakAfter = 'always';
hr.style.border = '1px #999 dotted';
this.insertHTML(hr);
div.appendChild(this.doc.createTextNode('\u00a0'));
this.insertHTML(div);
},
doCmdPaste: function (html) {
var range = null;
this.editAreaFocus();
if (!this.W3CRange) {
if (this.range.item) {
range = this.doc.body.createTextRange();
if (range) {
range.moveToElementText(this.range.item(0));
range.select();
this.range.item(0).outerHTML = html;
}
this.toolbarUpdate();
} else {
this.range.pasteHTML(html);
this.range.select();
}
} else {
this.insertNodeAtSelection(html);
}
},
getPreviousLeaf: function (node) {
var leaf;
while (!node.previousSibling) {
node = node.parentNode;
if (!node) {
return node;
}
}
leaf = node.previousSibling;
while (leaf.lastChild) {
leaf = leaf.lastChild;
}
return leaf;
},
getNextLeaf: function (node, breakNode) {
var leaf;
while (!node.nextSibling) {
node = node.parentNode;
if ((breakNode && breakNode === node) || !node) {
return node;
}
}
leaf = node.nextSibling;
if (breakNode && leaf === breakNode) {
return node;
}
while (leaf.firstChild) {
leaf = leaf.firstChild;
}
return leaf;
},
isTextVisible: function (text) {
var i, found = false, len = text.length;
for (i = 0; i < len; i++) {
if (text.charAt(i) !== ' ' && text.charAt(i) !== '\t' && text.charAt(i) !== '\r' && text.charAt(i) !== '\n') {
found = true;
break;
}
}
return found;
},
checkCssValue: function (elem, prop) {
var css = this.getCssValue(elem), i;
if (!css) {
return null;
}
for (i = 0; i < css.length; i++) {
if (css[i].name === prop) {
return css[i];
}
}
return null;
},
getCssValue: function (elem) {
var i, q, style = [], len, css;
css = elem.getAttribute('style');
if (!css) {
return null;
}
if (typeof css === 'object') {
css = css.cssText;
}
if (this.trimSpace(css) === '') {
return null;
}
css = css.replace(/;$/, '').split(';');
len = css.length;
for (i = 0; i < len; i++) {
q = css[i].split(':');
style.push({ 'name': this.trimSpace(q[0]).toLowerCase(), 'value': this.trimSpace(q[1]).toLowerCase() });
}
return style;
},
makeFontCss: function (cmd, opt, elem) {
switch (cmd) {
case 'font-size': elem.style.fontSize = opt; break;
case 'font-family': elem.style.fontFamily = opt; break;
case 'color': elem.style.color = opt; break;
case 'background-color': elem.style.backgroundColor = opt; break;
}
},
insertStartEndNode: function (range) {
var startNode = this.doc.createElement('span'),
startRange, endRange, endNode, collapsed, node = null;
startNode.id = 'startNode';
if (!this.W3CRange) {
startNode.appendChild(this.doc.createTextNode('\u200b'));
try {
endRange = range.duplicate();
startRange = range.duplicate();
endRange.collapse(false);
startRange.collapse(true);
} catch (e) {
node = this.getRangeElement(range);
if (node.nodeType === GB.node.element) {
} else {
return null;
}
}
endNode = startNode.cloneNode(true);
endNode.id = 'endNode';
if (node) {
node.parentNode.insertBefore(startNode, node);
node.parentNode.insertBefore(endNode, node.nextSibling);
collapsed = false;
} else {
collapsed = startRange.isEqual(endRange);
endRange.pasteHTML(endNode.outerHTML);
endRange.moveStart('character', -1);
endNode = endRange.parentElement();
if (collapsed || range.text.length === 0) {
endNode.parentNode.insertBefore(startNode, endNode);
} else {
startNode = endNode.cloneNode(true);
startNode.id = 'startNode';
startRange.pasteHTML(startNode.outerHTML);
startRange.moveStart('character', -1);
startNode = startRange.parentElement();
}
}
endRange = null;
startRange = null;
} else {
endRange = range.cloneRange();
startRange = range.cloneRange();
startRange.collapse(true);
endRange.collapse(false);
endNode = startNode.cloneNode(false);
endNode.id = 'endNode';
collapsed = range.collapsed;
if (collapsed) {
endRange.insertNode(endNode);
endNode.parentNode.insertBefore(startNode, endNode);
} else {
endRange.insertNode(endNode);
startRange.insertNode(startNode);
}
if (startNode.previousSibling && startNode.previousSibling.nodeType === GB.node.text &&
startNode.previousSibling.nodeValue === '') {
startNode.previousSibling.parentNode.removeChild(startNode.previousSibling);
}
if (endNode.nextSibling && endNode.nextSibling.nodeType === GB.node.text &&
endNode.nextSibling.nodeValue === '') {
endNode.nextSibling.parentNode.removeChild(endNode.nextSibling);
}
startRange.detach(); endRange.detach();
endRange = null; startRange = null;
}
return { startNode: startNode, endNode: endNode, collapsed: collapsed };
},
removeStartEndNode: function (nodes) {
if (nodes.startNode) {
nodes.startNode.parentNode.removeChild(nodes.startNode);
}
if (nodes.endNode) {
nodes.endNode.parentNode.removeChild(nodes.endNode);
}
},
clearCss: function (node, name) {
var i, css, styles = [];
if (!node || node.nodeType !== GB.node.element) {
return null;
}
css = this.getCssValue(node);
if (!css) {
return null;
}
node.removeAttribute('style');
for (i = 0; i < css.length; i++) {
if (css[i].name !== name) {
node.style[css[i].name] = css[i].value;
styles.push(css[i]);
}
}
return styles.length ? styles : null;
},
doCmdPopup: function (cmd, opt, checked) {
var self = this,
range, cursor, selectionType, pNode, node, found, isEmpty, span, endNode, startNode, i, endNodeAncestorRange,
startNodeRange, endNodeRange, compare, tNode, len, selection, child, css, tempNodes, endNodeAncestor,
backupRange, removeNodes = [], spanNodes = [], applyTextNodes = [], tailNodes = [], headNodes = [], rootNode = null,
zeroWidth = this.doc.createTextNode('\u200b'), inRange,
makeSpanText = function (elem, ancestor) {
if (self.undefined(ancestor)) {
ancestor = elem.parentNode;
}
span = self.doc.createElement('span');
self.makeFontCss(cmd, opt, span);
ancestor.insertBefore(span, elem);
span.appendChild(elem);
spanNodes.push(span);
return span;
},
searchTextNode = function (node, match) {
var i = 0, len = node.childNodes.length;
for (; i < len; i++) {
child = node.childNodes[i];
match = searchTextNode(child, match);
if (child === startNode) {
break;
}
if (child.nodeType === GB.node.text) {
match = true;
break;
}
if (child.nodeType === GB.node.element && child.hasChildNodes() === false &&
GB.textFormatTags[child.nodeName.toLowerCase()]) {
removeNodes.push(child);
}
}
return match;
},
compareBoundaryPoints = function (range, type, source) {
var values = {
'StartToStart': 0, //Range.START_TO_START,
'StartToEnd': 1, //Range.START_TO_END,
'EndToEnd': 2, //Range.END_TO_END,
'EndToStart': 3 //Range.END_TO_START
};
if (self.W3CRange) {
return range.compareBoundaryPoints(values[type], source);
}
type = type === 'StartToEnd' ? 'EndToStart' : (type === 'EndToStart' ? 'StartToEnd' : type);
return range.compareEndPoints(type, source);
},
rangeSelectNode = function (range, node) {
if (self.W3CRange) {
range.selectNode(node);
} else {
if (node.nodeType === GB.node.text) {
node = node.parentNode;
}
range.moveToElementText(node);
}
},
clearPreviousLeaf = function (node) {
var leaf, css = [];
while (!node.previousSibling) {
node = node.parentNode;
if (!node || node.nodeName.toLowerCase() === 'body') {
return null;
}
}
leaf = node.previousSibling;
while (leaf.lastChild && leaf.nodeType === GB.node.element && leaf !== startNode) {
rangeSelectNode(cursor, leaf);
compare = compareBoundaryPoints(cursor, 'StartToStart', startNodeRange);
if (compare === 1) {
css = self.clearCss(leaf, cmd);
if (!css && (leaf.nodeName.toLowerCase() === 'span' || leaf.nodeName.toLowerCase() === 'font')) {
while (leaf.firstChild) {
leaf.parentNode.insertBefore(leaf.firstChild, leaf);
}
removeNodes.push(leaf);
break;
}
} else if (compare === 0) {
self.clearCss(leaf, cmd);
if (!rootNode && leaf.nodeName.toLowerCase() === 'span') {
rootNode = leaf;
}
} else { // -1
node = startNode;
found = false;
while (node) {
if (node.nodeType === GB.node.text) {
found = true;
break;
}
node = checkPreviousLeaf(node, leaf);
}
if (!found) {
self.clearCss(leaf, cmd);
if (!rootNode && leaf.nodeName.toLowerCase() === 'span') {
rootNode = leaf;
}
}
}
leaf = leaf.lastChild;
}
if (leaf.nodeType === GB.node.text && self.isTextVisible(leaf.nodeValue)) {
applyTextNodes.push(leaf);
}
return leaf;
},
checkPreviousLeaf = function (node, breakNode) {
var leaf;
while (!node.previousSibling) {
node = node.parentNode;
if (node === breakNode || node.nodeName.toLowerCase() === 'body') {
return null;
}
}
leaf = node.previousSibling;
while (leaf.lastChild) {
leaf = leaf.lastChild;
}
return leaf;
},
checkInRange = function (range, source) {
return (typeof range.inRange !== 'undefined') ? range.inRange(source) :
(compareBoundaryPoints(range, 'StartToStart', source) < 1
&& compareBoundaryPoints(range, 'EndToEnd', source) > -1);
},
checkNextLeaf = function (node) {
var leaf, inRange;
while (!node.nextSibling) {
node = node.parentNode;
if (!node || node.nodeName.toLowerCase() === 'body') {
return null;
}
rangeSelectNode(cursor, node);
inRange = checkInRange(cursor, endNodeRange);
if (inRange) {
inRange = checkInRange(cursor, startNodeRange);
if (!inRange) {
tailNodes.push(node);
} else {
headNodes.push(node);
}
}
if (node === endNodeAncestor) {
return null;
}
}
leaf = node.nextSibling;
if (leaf.nodeType === GB.node.text || !endNodeAncestor) {
return null;
}
rangeSelectNode(cursor, leaf);
inRange = checkInRange(endNodeAncestorRange, cursor);
if (!inRange) {
return null;
}
while (leaf.firstChild) {
leaf = leaf.firstChild;
}
if (leaf.nodeType === GB.node.text) {
tailNodes = [];
return null;
}
return leaf;
},
checkParentSpan = function (node) {
var len = spanNodes.length, i = 0;
for (; i < len; i++) {
if (spanNodes[i] === node) {
return true;
}
}
return false;
};
this.editAreaFocus();
backupRange = this.restoreRange();
selectionType = this.getSelectionType();
if (this.W3CRange) {
range = this.doc;
} else {
range = (selectionType === GB.selection.none) ? this.doc : backupRange;
}
try {
if (cmd === 'LineHeight') {
this.applyLineHeight(opt);
} else {
if (cmd === 'InsertOrderedList' || cmd === 'InsertUnOrderedList') {
if (checked !== true) {
range.execCommand(cmd, false, opt);
if (!GB.browser.msie) {
range = this.getRange();
node = range.commonAncestorContainer;
found = isEmpty = false;
if (node.nodeType === GB.node.element && node.lastChild &&
node.lastChild.nodeName.toLowerCase() === 'br') {
node.lastChild.className = this.cheditor.bogusSpacerName;
isEmpty = true;
}
while (node) {
if (node.nodeName.toLowerCase() === 'ul' || node.nodeName.toLowerCase() === 'ol') {
found = true;
break;
}
node = node.parentNode;
}
if (found) {
if (node.parentNode.nodeName.toLowerCase() === 'p' ||
node.parentNode.nodeName.toLowerCase() === 'div') {
pNode = node.parentNode;
if (pNode.lastChild && pNode.lastChild.nodeName.toLowerCase() === 'br') {
pNode.removeChild(pNode.lastChild);
}
if (pNode.firstChild === node && pNode.lastChild === node) {
pNode.parentNode.insertBefore(node, pNode);
pNode.parentNode.removeChild(pNode);
this.placeCaretAt(node.lastChild, isEmpty);
}
}
}
}
}
cursor = this.getRange();
pNode = this.W3CRange ? cursor.commonAncestorContainer : cursor.parentElement();
if (pNode.nodeType === GB.node.text) {
pNode = pNode.parentNode;
}
while (pNode) {
if (pNode.nodeName.toLowerCase() === 'ol' || pNode.nodeName.toLowerCase() === 'ul') {
if (opt === 'desc' || opt === 'decimal') {
opt = '';
}
pNode.style.listStyleType = opt;
break;
}
pNode = pNode.parentNode;
}
} else if (cmd === 'FontSize' || cmd === 'FontName' || cmd === 'ForeColor' || cmd === 'BackColor') {
if (cmd === 'ForeColor' || cmd === 'BackColor') {
opt = this.colorConvert(opt, 'hex');
} else if (cmd === 'FontName' && opt === '맑은 고딕') {
opt += ', "Malgun Gothic"';
}
cmd = GB.fontStyle[cmd];
range = this.getRange();
tempNodes = this.insertStartEndNode(range);
startNode = tempNodes.startNode;
endNode = tempNodes.endNode;
cursor = this.createRange();
startNodeRange = this.createRange();
rangeSelectNode(startNodeRange, startNode);
endNodeRange = this.createRange();
endNodeAncestorRange = this.createRange();
if (!tempNodes.collapsed) {
tailNodes = [];
endNodeAncestor = null;
rangeSelectNode(endNodeRange, endNode);
node = endNode.parentNode;
while (node && node.nodeName.toLowerCase() !== 'body') {
endNodeAncestor = node;
node = node.parentNode;
}
if (endNodeAncestor) {
rangeSelectNode(endNodeAncestorRange, endNodeAncestor);
}
node = endNode;
while (node) {
node = checkNextLeaf(node);
}
for (i = 0; i < tailNodes.length; i++) {
this.clearCss(tailNodes[i], cmd);
}
node = endNode;
while (node && node !== startNode) {
node = clearPreviousLeaf(node);
}
if (headNodes.length) {
found = false;
node = startNode;
while (node) {
if (node.nodeType === GB.node.text) {
found = true;
break;
}
node = checkPreviousLeaf(node, endNodeAncestor);
}
if (!found) {
for (i = 0; i < headNodes.length; i++) {
self.clearCss(headNodes[i], cmd);
css = self.getCssValue(headNodes[i]);
if (!css && headNodes[i].nodeName.toLowerCase() === 'span') {
child = headNodes[i];
while (child.firstChild) {
child.parentNode.insertBefore(child.firstChild, child);
}
child.parentNode.removeChild(child);
headNodes.splice(i);
}
}
}
}
for (i = 0; i < removeNodes.length; i++) {
removeNodes[i].parentNode.removeChild(removeNodes[i]);
}
removeNodes = [];
len = applyTextNodes.length;
if (rootNode) {
rangeSelectNode(startNodeRange, rootNode);
}
for (i = 0; i < len; i++) {
tNode = applyTextNodes[i];
if (tNode.previousSibling && tNode.previousSibling.nodeType === GB.node.text) {
if (applyTextNodes[i + 1] && tNode.previousSibling === applyTextNodes[i + 1]) {
applyTextNodes[i + 1].nodeValue += tNode.nodeValue;
tNode.parentNode.removeChild(tNode);
} else {
tNode.nodeValue = tNode.previousSibling.nodeValue + tNode.nodeValue;
tNode.previousSibling.parentNode.removeChild(tNode.previousSibling);
i--;
}
continue;
}
pNode = tNode.parentNode;
if (rootNode) {
rangeSelectNode(cursor, pNode);
inRange = checkInRange(startNodeRange, cursor);
if (inRange) {
self.makeFontCss(cmd, '', pNode);
self.makeFontCss(cmd, opt, rootNode);
continue;
}
}
if (pNode.nodeName.toLowerCase() === 'span'
&& (pNode.firstChild === tNode || pNode.firstChild === startNode)
&& (pNode.lastChild === tNode || pNode.lastChild === endNode)) {
self.makeFontCss(cmd, opt, pNode);
spanNodes.push(pNode);
continue;
}
makeSpanText(tNode);
}
len = spanNodes.length;
for (i = 0; i < len; i++) {
child = spanNodes[i];
pNode = child.parentNode;
if (pNode.nodeName.toLowerCase() === 'span') {
if (checkParentSpan(pNode)) {
self.makeFontCss(cmd, '', child);
css = self.getCssValue(child);
if (!css) {
while (child.firstChild) {
pNode.insertBefore(child.firstChild, child);
}
pNode.removeChild(child);
continue;
}
}
while (pNode && pNode.nodeName.toLowerCase() === 'span') {
if (pNode.firstChild === child && pNode.lastChild === child) {
css = self.getCssValue(pNode);
if (css) {
self.makeFontCss(cmd, '', pNode);
css = self.getCssValue(pNode);
if (!css) {
pNode.parentNode.insertBefore(child, pNode);
pNode.parentNode.removeChild(pNode);
pNode = child;
continue;
}
}
}
pNode = pNode.parentNode;
}
}
}
if (this.W3CRange) {
selection = this.getSelection();
if (selection.rangeCount > 0) {
selection.removeAllRanges();
}
range = this.createRange();
range.setStartAfter(startNode);
range.setEndBefore(endNode);
selection.addRange(range);
} else {
startNodeRange = this.createRange();
endNodeRange = startNodeRange.duplicate();
startNodeRange.moveToElementText(startNode);
endNodeRange.moveToElementText(endNode);
startNodeRange.setEndPoint('StartToEnd', startNodeRange);
startNodeRange.setEndPoint('EndToStart', endNodeRange);
startNodeRange.select();
}
} else {
pNode = startNode.parentNode;
found = false;
while (pNode && pNode.nodeName.toLowerCase() === 'span' && !found) {
css = self.getCssValue(pNode);
if (css) {
len = css.length;
for (i = 0; i < len; i++) {
if (css[i].name === cmd && css[i].value === opt) {
found = true;
break;
}
}
}
pNode = pNode.parentNode;
}
if (!found) {
span = this.doc.createElement('span');
this.makeFontCss(cmd, opt, span);
span.appendChild(zeroWidth);
endNode.parentNode.insertBefore(span, endNode);
if (this.W3CRange) {
selection = this.getSelection();
selection.collapse(zeroWidth, 1);
} else {
range = this.getRange();
range.moveToElementText(span);
range.collapse(false);
range.select();
}
}
}
this.removeStartEndNode(tempNodes);
} else {
range.execCommand(cmd, false, opt);
}
}
} catch (e) {
alert(e.toString());
}
this.toolbarUpdate();
this.boxHideAll();
},
modifyImage: function (img) {
var self = this,
idx, div, ico, inputCaption, wrapTextSpan, wrapTextCheckBox, wrapTextIcon, wrapTextChecked,
width = 0, height = 0, wrapElem, currentCaption = '', caption = null, inputAlt, inputTitle, cssFloat,
wrapperClassName = 'cheditor-caption-wrapper',
figureClassName = 'cheditor-caption',
figCaptionClassName = 'cheditor-caption-text',
imageWidthOpt = {
orig: { size: 'normal', desc: '원본 크기' },
fitpage: { size: '100%', desc: '페이지 크기에 맞춤' },
px160: { size: 160, desc: '썸네일, 160 픽셀' },
px320: { size: 320, desc: '작은 크기, 320 픽셀' },
px640: { size: 640, desc: '중간 크기, 640 픽셀' },
px1024: { size: 1024, desc: '크게, 1024 픽셀' },
px1600: { size: 1600, desc: '아주 크게, 1600 픽셀' }
},
captionAlignOpt = { left: '왼쪽', center: '가운데', right: '오른쪽' },
imageFloatOpt = {
left: {
value: '왼쪽',
input: null
},
right: {
value: '오른쪽',
input: null
}
},
fmSelectWidth = document.createElement('select'),
fmSelectCaptionAlign = document.createElement('select'),
onChangeEventHandler = function () {
if (self.editImages[img.src] && self.editImages[img.src].width) {
width = self.editImages[img.src].width;
if (self.editImages[img.src] && self.editImages[img.src].height) {
height = self.editImages[img.src].height;
} else {
height = img.height;
}
} else if (img.width) {
width = img.width;
} else {
return;
}
switch (this.value) {
case 'orig':
width = width + 'px';
height = (height || img.height) + 'px';
break;
case 'fitpage':
width = '100%';
height = 'auto';
break;
default:
width = imageWidthOpt[this.value].size;
if (img.height) {
height = Math.round((img.height * width) / img.width) + 'px';
}
width += 'px';
}
if (width) {
img.style.width = width;
if (caption && caption.figure) {
caption.figure.style.width = width;
}
}
if (height) {
img.style.height = height;
}
},
setCssFloat = function (elem, css) {
if (typeof elem.style.styleFloat === 'undefined') {
elem.style.cssFloat = css;
} else {
elem.style.styleFloat = css;
}
},
getCssFloat = function (elem) {
return (typeof elem.style.styleFloat === 'undefined') ? elem.style.cssFloat : elem.style.styleFloat;
},
clearCssFloat = function (elem) {
setCssFloat(elem, '');
elem.style.marginLeft = '';
elem.style.marginRight = '';
},
createInputForm = function (type, name, value, classname) {
var input = document.createElement('input');
input.setAttribute('type', type);
input.setAttribute('name', name);
input.setAttribute('value', value);
input.className = classname;
return input;
},
applyWrapText = function (elem) {
if (!elem) {
return;
}
wrapElem = (caption && caption.wrapper) ? caption.wrapper : img;
if (elem.checked) {
imageFloatOpt[(elem.name === 'left' ? 'right' : 'left')].input.checked = false;
setCssFloat(wrapElem, elem.name);
if (elem.name === 'left') {
wrapElem.style.marginRight = '1em';
wrapElem.style.marginLeft = '';
} else {
wrapElem.style.marginLeft = '1em';
wrapElem.style.marginRight = '';
}
if (caption && caption.wrapper) {
clearCssFloat(img);
}
} else {
clearCssFloat(wrapElem);
}
},
getCaptionNodes = function (img) {
var nodes = { figure: null, figCaption: [], captionText: '', img: null, wrapper: null },
pNode, node;
pNode = img.parentNode;
if (!pNode || pNode.nodeName.toLowerCase() !== 'figure') {
return null;
}
nodes.figure = pNode;
nodes.figCaption = pNode.getElementsByTagName('figcaption');
for (idx = 0; idx < nodes.figCaption.length; idx++) {
node = nodes.figCaption[idx].firstChild;
while (node) {
if (node.nodeType === GB.node.text) {
nodes.captionText += self.trimSpace(node.nodeValue);
}
node = node.nextSibling;
}
}
if (pNode.parentNode.nodeName.toLowerCase() === 'div' && pNode.parentNode.className === wrapperClassName) {
nodes.wrapper = pNode.parentNode;
}
nodes.img = img;
return nodes;
},
applyAlt = function () {
var alt = self.trimSpace(inputAlt.value);
if (alt !== '') {
img.setAttribute('alt', alt);
}
self.removeEvent(inputAlt, 'blur', applyAlt);
self.cheditor.modifyState = false;
},
applyTitle = function () {
var title = self.trimSpace(inputTitle.value);
if (title !== '') {
img.setAttribute('title', title);
}
self.removeEvent(inputTitle, 'blur', applyTitle);
self.cheditor.modifyState = false;
},
applyCaption = function () {
var figure = self.doc.createElement('figure'),
figCaption = self.doc.createElement('figcaption'),
wrapper = self.doc.createElement('div'),
pNode = img.parentNode, i, para = self.doc.createElement('p');
self.removeEvent(inputCaption, 'blur', applyCaption);
wrapper.className = wrapperClassName;
figure.className = figureClassName;
figCaption.className = figCaptionClassName;
this.value = self.trimSpace(inputCaption.value);
if (!self.isTextVisible(this.value) && caption) {
caption.wrapper.parentNode.insertBefore(para, caption.wrapper);
para.appendChild(caption.img);
cssFloat = getCssFloat(caption.wrapper);
caption.wrapper.parentNode.removeChild(caption.wrapper);
caption = getCaptionNodes(img);
if (cssFloat && (cssFloat === 'left' || cssFloat === 'right')) {
applyWrapText(imageFloatOpt[cssFloat].input);
}
self.cheditor.modifyState = false;
return;
}
if (currentCaption === this.value) {
self.cheditor.modifyState = false;
return;
}
if (caption && caption.figure) {
for (i = 0; i < caption.figCaption.length; i++) {
caption.figure.removeChild(caption.figCaption[i]);
}
figure = caption.figure;
} else {
if (pNode.nodeName.toLowerCase() !== 'body') {
pNode.parentNode.insertBefore(wrapper, pNode.nextSibling);
} else {
pNode.insertBefore(wrapper, img);
}
if (self.config.imgCaptionWrapper !== '') {
wrapper.setAttribute('style', self.config.imgCaptionWrapper);
}
wrapper.appendChild(figure);
figure.setAttribute('style', self.config.imgCaptionFigure);
figure.style.display = 'inline-block';
figure.style.width = img.width;
figure.appendChild(img);
para.appendChild(self.createNbspTextNode());
wrapper.parentNode.insertBefore(para, wrapper.nextSibling);
}
figure.appendChild(figCaption);
figCaption.setAttribute('style', self.config.imgCaptionText);
figCaption.appendChild(self.doc.createTextNode(this.value));
if (!pNode.hasChildNodes()) {
pNode.parentNode.removeChild(pNode);
}
caption = getCaptionNodes(img);
cssFloat = getCssFloat(img);
if (cssFloat && (cssFloat === 'left' || cssFloat === 'right')) {
applyWrapText(imageFloatOpt[cssFloat].input);
}
self.cheditor.modifyState = false;
};
for (idx in imageWidthOpt) {
if (imageWidthOpt.hasOwnProperty(idx)) {
fmSelectWidth.options[fmSelectWidth.options.length] = new Option(imageWidthOpt[idx].desc, idx);
}
}
fmSelectWidth.onchange = onChangeEventHandler;
caption = getCaptionNodes(img);
div = document.createElement('div');
div.style.textAlign = 'left';
ico = new Image();
ico.src = this.config.iconPath + 'image_resize.png';
ico.className = 'cheditor-ico';
div.appendChild(ico);
div.appendChild(fmSelectWidth);
wrapTextChecked = getCssFloat((caption && caption.wrapper) ? caption.wrapper : img);
for (idx in imageFloatOpt) {
if (imageFloatOpt.hasOwnProperty(idx)) {
wrapTextCheckBox = createInputForm('checkbox', idx, '1', 'wrap-checked');
wrapTextCheckBox.setAttribute('id', 'idWrapText-' + idx);
wrapTextCheckBox.onclick = function () {
applyWrapText(this);
};
imageFloatOpt[idx].input = wrapTextCheckBox;
wrapTextSpan = document.createElement('span');
wrapTextIcon = new Image();
wrapTextSpan.className = 'wrap-text-desc';
if (idx === 'left') {
wrapTextSpan.style.marginLeft = '20px';
}
if (wrapTextChecked === idx) {
wrapTextCheckBox.checked = 'checked';
}
wrapTextSpan.appendChild(wrapTextCheckBox);
wrapTextIcon.className = 'cheditor-ico';
wrapTextIcon.src = this.config.iconPath + 'image_align_' + idx + '_wt.png';
wrapTextSpan.appendChild(wrapTextIcon);
div.appendChild(wrapTextSpan);
}
}
if (self.undefined(self.editImages[img.src])) {
self.editImages[img.src] = { width: img.width, height: img.height };
}
div.appendChild(document.createTextNode('\u00a0\u00a0Alt:'));
inputAlt = createInputForm('text', 'inputAlt', '', 'user-input-alt');
inputAlt.onfocus = function () {
self.cheditor.modifyState = true;
self.addEvent(inputAlt, 'blur', applyAlt);
};
div.appendChild(inputAlt);
if (img.getAttribute('alt')) {
inputAlt.value = img.getAttribute('alt');
}
div.appendChild(document.createTextNode('타이틀:'));
inputTitle = createInputForm('text', 'inputTitle', '', 'user-input-alt');
inputTitle.onfocus = function () {
self.cheditor.modifyState = true;
self.addEvent(inputTitle, 'blur', applyTitle);
};
div.appendChild(inputTitle);
if (img.getAttribute('title')) {
inputTitle.value = img.getAttribute('title');
}
div.appendChild(document.createElement('br'));
div.appendChild(document.createTextNode('사진 캡션:'));
inputCaption = createInputForm('text', 'inputCaption', '', 'user-input-caption');
inputCaption.onfocus = function () {
caption = getCaptionNodes(img);
self.cheditor.modifyState = true;
self.addEvent(inputCaption, 'blur', applyCaption);
};
div.appendChild(inputCaption);
div.appendChild(document.createTextNode('캡션 텍스트 정렬:'));
for (idx in captionAlignOpt) {
if (captionAlignOpt.hasOwnProperty(idx)) {
fmSelectCaptionAlign.options[fmSelectCaptionAlign.options.length] = new Option(captionAlignOpt[idx], idx);
if (caption && caption.figCaption[0] && caption.figCaption[0].style.textAlign) {
if (idx === caption.figCaption[0].style.textAlign) {
fmSelectCaptionAlign.options[fmSelectCaptionAlign.options.length - 1].selected = true;
}
}
}
}
fmSelectCaptionAlign.className = 'caption-align';
fmSelectCaptionAlign.onchange = function () {
caption = getCaptionNodes(img);
if (!caption) {
return;
}
for (idx = 0; idx < caption.figCaption.length; idx++) {
caption.figCaption[idx].style.textAlign = this.value;
}
};
div.appendChild(fmSelectCaptionAlign);
if (caption && caption.captionText) {
currentCaption = self.trimSpace(caption.captionText);
inputCaption.value = currentCaption;
}
while (self.cheditor.editBlock.firstChild) {
self.cheditor.editBlock.removeChild(self.cheditor.editBlock.firstChild);
}
self.cheditor.editBlock.appendChild(div);
},
modifyCell: function (ctd) {
var self = this,
ctb = ctd,
ctr = ctb,
tm = [], i, jr, j, jh, jv, rowIndex = 0, realIndex = 0, newc, newr, nc, tempr, rows, span, icon,
div = document.createElement('div'),
getCellMatrix = function () {
rows = (ctb.rows && ctb.rows.length > 0) ? ctb.rows : ctb.getElementsByTagName('tr');
for (i = 0; i < rows.length; i++) {
tm[i] = [];
}
for (i = 0; i < rows.length; i++) {
jr = 0;
for (j = 0; j < rows[i].cells.length; j++) {
while (!(self.undefined(tm[i][jr]))) {
jr++;
}
for (jh = jr; jh < jr + (rows[i].cells[j].colSpan || 1) ; jh++) {
for (jv = i; jv < i + (rows[i].cells[j].rowSpan || 1) ; jv++) {
tm[jv][jh] = (jv === i) ? rows[i].cells[j].cellIndex : -1;
}
}
}
}
return tm;
},
insertColumn = function () {
tm = getCellMatrix();
rows = (ctb.rows && ctb.rows.length > 0) ? ctb.rows : ctb.getElementsByTagName('tr');
if (ctr.rowIndex >= 0) {
rowIndex = ctr.rowIndex;
} else {
for (i = 0; i < rows.length; i++) {
if (rows[i] === ctr) {
rowIndex = i;
break;
}
}
}
for (j = 0; j < tm[rowIndex].length; j++) {
if (tm[rowIndex][j] === ctd.cellIndex) {
realIndex = j;
break;
}
}
for (i = 0; i < rows.length; i++) {
if (tm[i][realIndex] !== -1) {
if (rows[i].cells[tm[i][realIndex]].colSpan > 1) {
rows[i].cells[tm[i][realIndex]].colSpan++;
} else {
newc = rows[i].insertCell(tm[i][realIndex] + 1);
nc = rows[i].cells[tm[i][realIndex]].cloneNode(false);
nc.innerHTML = ' ';
rows[i].replaceChild(nc, newc);
}
}
}
},
insertRow = function (idx) {
newr = ctb.insertRow(ctr.rowIndex + 1);
for (i = 0; i < ctr.cells.length; i++) {
if (ctr.cells[i].rowSpan > 1) {
ctr.cells[i].rowSpan++;
} else {
newc = ctr.cells[i].cloneNode(false);
newc.innerHTML = ' ';
newr.appendChild(newc);
}
}
for (i = 0; i < ctr.rowIndex; i++) {
if (ctb.rows && ctb.rows.length > 0) {
tempr = ctb.rows[i];
} else {
tempr = ctb.getElementsByTagName('tr')[i];
}
for (j = 0; j < tempr.cells.length; j++) {
if (tempr.cells[j].rowSpan > (ctr.rowIndex - i)) {
tempr.cells[j].rowSpan++;
}
}
}
},
deleteColumn = function () {
tm = getCellMatrix(ctb);
rows = (ctb.rows && ctb.rows.length > 0) ? ctb.rows : ctb.getElementsByTagName('tr');
rowIndex = 0; realIndex = 0;
if (ctr.rowIndex >= 0) {
rowIndex = ctr.rowIndex;
} else {
for (i = 0; i < rows.length; i++) {
if (rows[i] === ctr) {
rowIndex = i;
break;
}
}
}
if (tm[0].length <= 1) {
ctb.parentNode.removeChild(ctb);
} else {
for (j = 0; j < tm[rowIndex].length; j++) {
if (tm[rowIndex][j] === ctd.cellIndex) {
realIndex = j;
break;
}
}
for (i = 0; i < rows.length; i++) {
if (tm[i][realIndex] !== -1) {
if (rows[i].cells[tm[i][realIndex]].colSpan > 1) {
rows[i].cells[tm[i][realIndex]].colSpan--;
} else {
rows[i].deleteCell(tm[i][realIndex]);
}
}
}
}
},
deleteRow = function () {
var curCI = -1, prevCI, ni, nrCI, cs, nj;
tm = getCellMatrix(ctb);
rows = (ctb.rows && ctb.rows.length > 0) ? ctb.rows : ctb.getElementsByTagName('TR');
rowIndex = 0;
if (ctr.rowIndex >= 0) {
rowIndex = ctr.rowIndex;
} else {
for (i = 0; i < rows.length; i++) {
if (rows[i] === ctr) {
rowIndex = i;
break;
}
}
}
if (rows.length <= 1) {
ctb.parentNode.removeChild(ctb);
} else {
for (i = 0; i < rowIndex; i++) {
tempr = rows[i];
for (j = 0; j < tempr.cells.length; j++) {
if (tempr.cells[j].rowSpan > (rowIndex - i)) {
tempr.cells[j].rowSpan--;
}
}
}
for (i = 0; i < tm[rowIndex].length; i++) {
prevCI = curCI;
curCI = tm[rowIndex][i];
if (curCI !== -1 && curCI !== prevCI && ctr.cells[curCI].rowSpan > 1 && (rowIndex + 1) < rows.length) {
ni = i;
nrCI = tm[rowIndex + 1][ni];
while (nrCI === -1) {
ni++;
nrCI = (ni < rows[rowIndex + 1].cells.length) ? tm[rowIndex + 1][ni] : rows[rowIndex + 1].cells.length;
}
newc = rows[rowIndex + 1].insertCell(nrCI);
rows[rowIndex].cells[curCI].rowSpan--;
nc = rows[rowIndex].cells[curCI].cloneNode(false);
rows[rowIndex + 1].replaceChild(nc, newc);
cs = (ctr.cells[curCI].colSpan > 1) ? ctr.cells[curCI].colSpan : 1;
nj = 0;
for (j = i; j < (i + cs) ; j++) {
tm[rowIndex + 1][j] = nrCI;
nj = j;
}
for (j = nj; j < tm[rowIndex + 1].length; j++) {
if (tm[rowIndex + 1][j] !== -1) {
tm[rowIndex + 1][j]++;
}
}
}
}
if (ctb.rows && ctb.rows.length > 0) {
ctb.deleteRow(rowIndex);
} else {
ctb.removeChild(rows[rowIndex]);
}
}
},
mergeCellRight = function () {
tm = getCellMatrix(ctb);
rows = (ctb.rows && ctb.rows.length > 0) ? ctb.rows : ctb.getElementsByTagName('tr');
rowIndex = 0; realIndex = 0;
if (ctr.rowIndex >= 0) {
rowIndex = ctr.rowIndex;
} else {
for (i = 0; i < rows.length; i++) {
if (rows[i] === ctr) {
rowIndex = i;
break;
}
}
}
for (j = 0; j < tm[rowIndex].length; j++) {
if (tm[rowIndex][j] === ctd.cellIndex) {
realIndex = j;
break;
}
}
if (ctd.cellIndex + 1 < ctr.cells.length) {
var ccrs = ctd.rowSpan || 1,
cccs = ctd.colSpan || 1,
ncrs = ctr.cells[ctd.cellIndex + 1].rowSpan || 1,
nccs = ctr.cells[ctd.cellIndex + 1].colSpan || 1,
html;
j = realIndex;
while (tm[rowIndex][j] === ctd.cellIndex) {
j++;
}
if (tm[rowIndex][j] === ctd.cellIndex + 1) {
if (ccrs === ncrs) {
if (rows.length > 1) {
ctd.colSpan = cccs + nccs;
}
html = self.trimSpace(ctr.cells[ctd.cellIndex + 1].innerHTML);
html = html.replace(/^ /, '');
ctd.innerHTML += html;
ctr.deleteCell(ctd.cellIndex + 1);
}
}
}
},
mergeCellDown = function () {
var crealIndex = 0,
ccrs = ctd.rowSpan || 1,
cccs = ctd.colSpan || 1,
ncellIndex, html, ncrs, nccs;
tm = getCellMatrix(ctb);
rows = (ctb.rows && ctb.rows.length > 0) ? ctb.rows : ctb.getElementsByTagName('tr');
rowIndex = 0;
if (ctr.rowIndex >= 0) {
rowIndex = ctr.rowIndex;
} else {
for (i = 0; i < rows.length; i++) {
if (rows[i] === ctr) {
rowIndex = i;
break;
}
}
}
for (i = 0; i < tm[rowIndex].length; i++) {
if (tm[rowIndex][i] === ctd.cellIndex) {
crealIndex = i;
break;
}
}
if (rowIndex + ccrs < rows.length) {
ncellIndex = tm[rowIndex + ccrs][crealIndex];
if (ncellIndex !== -1 &&
(crealIndex === 0 || (crealIndex > 0 &&
(tm[rowIndex + ccrs][crealIndex - 1] !== tm[rowIndex + ccrs][crealIndex])))) {
ncrs = rows[rowIndex + ccrs].cells[ncellIndex].rowSpan || 1;
nccs = rows[rowIndex + ccrs].cells[ncellIndex].colSpan || 1;
if (cccs === nccs) {
html = self.trimSpace(rows[rowIndex + ccrs].cells[ncellIndex].innerHTML);
html = html.replace(/^ /, '');
ctd.innerHTML += html;
rows[rowIndex + ccrs].deleteCell(ncellIndex);
ctd.rowSpan = ccrs + ncrs;
}
}
}
},
splitCellVertical = function () {
var ri, cs;
tm = getCellMatrix();
rowIndex = 0; realIndex = 0;
rows = (ctb.rows && ctb.rows.length > 0) ? ctb.rows : ctb.getElementsByTagName('TR');
if (ctr.rowIndex >= 0) {
rowIndex = ctr.rowIndex;
} else {
for (ri = 0; ri < rows.length; ri++) {
if (rows[ri] === ctr) {
rowIndex = ri;
break;
}
}
}
for (j = 0; j < tm[rowIndex].length; j++) {
if (tm[rowIndex][j] === ctd.cellIndex) {
realIndex = j;
break;
}
}
if (ctd.colSpan > 1) {
newc = rows[rowIndex].insertCell(ctd.cellIndex + 1);
ctd.colSpan--;
nc = ctd.cloneNode(false);
nc.innerHTML = ' ';
rows[rowIndex].replaceChild(nc, newc);
ctd.colSpan = 1;
ctd.removeAttribute('colSpan');
} else {
newc = rows[rowIndex].insertCell(ctd.cellIndex + 1);
nc = ctd.cloneNode(false);
nc.innerHTML = ' ';
rows[rowIndex].replaceChild(nc, newc);
for (i = 0; i < tm.length; i++) {
if (i !== rowIndex && tm[i][realIndex] !== -1) {
cs = (rows[i].cells[tm[i][realIndex]].colSpan > 1) ? rows[i].cells[tm[i][realIndex]].colSpan : 1;
rows[i].cells[tm[i][realIndex]].colSpan = cs + 1;
}
}
}
},
splitCellHorizontal = function () {
var ni, rs;
tm = getCellMatrix();
rowIndex = 0; realIndex = 0;
rows = (ctb.rows && ctb.rows.length > 0) ? ctb.rows : ctb.getElementsByTagName('TR');
if (ctr.rowIndex >= 0) {
rowIndex = ctr.rowIndex;
} else {
for (i = 0; i < rows.length; i++) {
if (rows[i] === ctr) {
rowIndex = i;
break;
}
}
}
for (j = 0; j < tm[rowIndex].length; j++) {
if (tm[rowIndex][j] === ctd.cellIndex) {
realIndex = j;
break;
}
}
if (ctd.rowSpan > 1) {
i = realIndex;
while (tm[rowIndex + 1][i] === -1) {
i++;
}
ni = (i === tm[rowIndex + 1].length) ? rows[rowIndex + 1].cells.length : tm[rowIndex + 1][i];
newc = rows[rowIndex + 1].insertCell(ni);
ctd.rowSpan--;
nc = ctd.cloneNode(false);
nc.innerHTML = ' ';
rows[rowIndex + 1].replaceChild(nc, newc);
ctd.rowSpan = 1;
} else {
if (ctb.rows && ctb.rows.length > 0) {
ctb.insertRow(rowIndex + 1);
} else {
if (rowIndex < (rows.length - 1)) {
ctb.insertBefore(document.createElement('TR'), rows[rowIndex + 1]);
} else {
ctb.appendChild(document.createElement('TR'));
}
}
for (i = 0; i < ctr.cells.length; i++) {
if (i !== ctd.cellIndex) {
rs = ctr.cells[i].rowSpan > 1 ? ctr.cells[i].rowSpan : 1;
ctr.cells[i].rowSpan = rs + 1;
}
}
for (i = 0; i < rowIndex; i++) {
tempr = rows[i];
for (j = 0; j < tempr.cells.length; j++) {
if (tempr.cells[j].rowSpan > (rowIndex - i)) {
tempr.cells[j].rowSpan++;
}
}
}
newc = rows[rowIndex + 1].insertCell(0);
nc = ctd.cloneNode(false);
nc.innerHTML = ' ';
rows[rowIndex + 1].replaceChild(nc, newc);
}
},
tblReflash = function () {
self.editAreaFocus(); self.doEditorEvent();
},
colorPickerEventHandler = function () {
GB.popupWindow.ColorPicker.argv = {
func: function (color) {
ctd.setAttribute('bgColor', color);
document.getElementById('fm_cell_bgcolor').value = color;
},
selectedCell: ctd
};
self.windowOpen('ColorPicker');
},
editSubmitEventHandler = function () {
var width = self.trimSpace(document.getElementById('fm_cell_width').value),
height = self.trimSpace(document.getElementById('fm_cell_height').value),
bgcolor = self.trimSpace(document.getElementById('fm_cell_bgcolor').value);
if (width) {
ctd.setAttribute('width', width);
}
if (height) {
ctd.setAttribute('height', height);
}
if (bgcolor) {
ctd.setAttribute('bgcolor', bgcolor);
}
},
deleteSubmitEventHandler = function () {
ctb.parentNode.removeChild(ctb);
self.doEditorEvent();
},
funcs = {
add_cols_after: {
icon: 'table_insert_column.png', title: '열 삽입',
func: function () {
insertColumn(ctd.cellIndex); tblReflash();
}
},
add_rows_after: {
icon: 'table_insert_row.png', title: '행 삽입',
func: function () {
insertRow(ctr.rowIndex); tblReflash();
}
},
remove_cols: {
icon: 'table_delete_column.png', title: '열 삭제',
func: function () {
deleteColumn(ctd.cellIndex); tblReflash();
}
},
remove_rows: {
icon: 'table_delete_row.png', title: '행 삭제',
func: function () {
deleteRow(); tblReflash();
}
},
sp1: { icon: 'dot.gif' },
merge_cell_right: {
icon: 'table_join_row.png', title: '오른쪽 셀과 병합',
func: function () {
mergeCellRight(); tblReflash();
}
},
merge_cell_down: {
icon: 'table_join_column.png', title: '아래 셀과 병합',
func: function () {
mergeCellDown(); tblReflash();
}
},
split_cell_v: {
icon: 'table_split_row.png', title: '셀 열로 나누기',
func: function () {
splitCellVertical(); tblReflash();
}
},
split_cell_h: {
icon: 'table_split_column.png', title: '셀 행으로 나누기',
func: function () {
splitCellHorizontal(); tblReflash();
}
}
},
attrFuncs = {
setWidth: {
txt: '가로폭',
id: 'fm_cell_width',
marginRight: '10px',
value: ctd.getAttribute('width')
},
setHeight: {
txt: '세로폭',
id: 'fm_cell_height',
marginRight: '10px',
value: ctd.getAttribute('height')
},
setBgcolor: {
txt: '배경색',
id: 'fm_cell_bgcolor',
marginRight: '2px',
value: ctd.getAttribute('bgcolor')
}
},
deleteSubmit = new Image(),
spliter = document.createElement('div'), txt, input,
colorPicker = new Image(),
editSubmit = new Image();
while (ctb && ctb.tagName.toLowerCase() !== 'table') {
ctb = ctb.parentNode;
}
while (ctr && ctr.tagName.toLowerCase() !== 'tr') {
ctr = ctr.parentNode;
}
self.cheditor.editBlock.innerHTML = '';
div.style.padding = '6px';
for (i in funcs) {
if (!funcs.hasOwnProperty(i)) {
continue;
}
span = document.createElement('span');
icon = document.createElement('img');
icon.src = self.config.iconPath + funcs[i].icon;
if (i === 'sp1' || i === 'sp2') {
icon.className = 'edit-table-ico';
} else {
icon.setAttribute('title', funcs[i].title);
icon.className = 'edit-table-ico';
icon.setAttribute('alt', '');
icon.onclick = funcs[i].func;
}
div.appendChild(span.appendChild(icon));
}
deleteSubmit.src = this.config.iconPath + 'delete_table.png';
deleteSubmit.style.marginLeft = '22px';
deleteSubmit.className = 'edit-table-ico';
deleteSubmit.setAttribute('title', '테이블 삭제');
deleteSubmit.onclick = deleteSubmitEventHandler;
div.appendChild(deleteSubmit);
spliter.style.padding = '10px 0px 0px 0px';
spliter.style.marginTop = '5px';
spliter.style.borderTop = '1px solid #ccc';
spliter.style.textAlign = 'center';
for (i in attrFuncs) {
if (!attrFuncs.hasOwnProperty(i)) {
continue;
}
txt = document.createTextNode(attrFuncs[i].txt + ' ');
spliter.appendChild(txt);
input = document.createElement('input');
input.style.marginRight = attrFuncs[i].marginRight;
input.setAttribute('type', 'text');
input.setAttribute('name', i);
input.setAttribute('id', attrFuncs[i].id);
input.setAttribute('size', 7);
input.setAttribute('value', attrFuncs[i].value || '');
spliter.appendChild(input);
}
colorPicker.src = this.config.iconPath + 'button/color_picker.gif';
colorPicker.className = 'color-picker';
colorPicker.onclick = colorPickerEventHandler;
spliter.appendChild(colorPicker);
editSubmit.src = this.config.iconPath + 'button/edit_cell.gif';
editSubmit.className = 'input-submit';
editSubmit.style.verticalAlign = 'top';
editSubmit.onclick = editSubmitEventHandler;
spliter.appendChild(editSubmit);
div.appendChild(spliter);
self.cheditor.editBlock.appendChild(div);
},
doEditorEvent: function (evt) {
var self = this,
cmd = null, ancestors = [], node, el, pNode, range, sType, links, span, tag, remove, bText,
srcElement = evt.target || evt.srcElement,
block = self.cheditor.editBlock,
status = self.cheditor.tagPath,
linkOnClickEventHandler = function () {
if (bText) {
document.getElementById('removeSelected').style.display = 'inline';
self.tagSelector(this.el);
}
},
removeOnClickEventHandler = function () {
self.doc.execCommand('RemoveFormat', false, null);
remove.style.display = 'none';
self.editAreaFocus();
self.doEditorEvent();
};
if (!this.undefined(srcElement) && srcElement.nodeType === GB.node.element) {
pNode = srcElement;
} else {
range = self.getRange();
sType = self.getSelectionType();
bText = sType === GB.selection.text;
if (!self.W3CRange) {
switch (sType) {
case GB.selection.none:
case GB.selection.text:
pNode = range.parentElement();
break;
case GB.selection.element:
pNode = range.item(0);
break;
default:
pNode = self.editArea.document.body;
}
} else {
pNode = range.commonAncestorContainer;
if (!range.collapsed &&
range.startContainer === range.endContainer &&
range.startOffset - range.endOffset < 2 &&
range.startContainer.hasChildNodes()) {
pNode = range.startContainer.childNodes[range.startOffset];
}
while (pNode.nodeType === GB.node.text) {
pNode = pNode.parentNode;
}
}
}
node = pNode;
while (pNode && pNode.nodeType === GB.node.element) {
if (pNode.tagName.toLowerCase() === 'body') {
break;
}
if (pNode.tagName.toLowerCase() === 'img') {
cmd = 'img'; break;
}
if (pNode.tagName.toLowerCase() === 'td' || pNode.tagName.toLowerCase() === 'th') {
cmd = 'cell'; break;
}
pNode = pNode.parentNode;
}
if (!cmd) {
block.style.display = 'none';
block.innerHTML = '';
} else {
if (cmd === 'cell') {
block.style.display = 'block';
self.modifyCell(pNode);
}
}
if (self.config.showTagPath) {
while (node && node.nodeType === GB.node.element) {
ancestors.push(node);
if (node.tagName.toLowerCase() === 'body') {
break;
}
node = node.parentNode;
}
status.innerHTML = '';
status.appendChild(document.createTextNode(' '));
el = ancestors.pop();
while (el) {
status.appendChild(document.createTextNode('<'));
tag = el.nodeName.toLowerCase();
links = document.createElement('a');
links.el = el;
links.href = 'javascript:void%200';
links.className = 'cheditor-tag-path-elem';
links.title = el.style.cssText;
(function () {
links.onclick = linkOnClickEventHandler;
})();
links.appendChild(document.createTextNode(tag));
status.appendChild(links);
status.appendChild(document.createTextNode('> '));
el = ancestors.pop();
}
if (bText) {
remove = document.createElement('a');
remove.href = 'javascript:void%200';
remove.id = 'removeSelected';
remove.style.display = 'none';
remove.className = 'cheditor-tag-path-elem';
remove.style.color = '#cc3300';
remove.appendChild(document.createTextNode('