From a184543714508174c8ebac164fce2f93233c8026 Mon Sep 17 00:00:00 2001 From: taggon Date: Fri, 3 Dec 2010 07:25:34 +0000 Subject: [PATCH] =?UTF-8?q?1.=20=ED=85=8D=EC=8A=A4=ED=8A=B8=EB=A5=BC=20?= =?UTF-8?q?=EC=84=A0=ED=83=9D=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9D=84=20?= =?UTF-8?q?=EB=95=8C=20indent,=20outdent=EA=B0=80=20=EB=90=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8D=98=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?2.=20=EC=9D=BC=EB=B6=80=20=ED=99=98=EA=B2=BD=EC=97=90=EC=84=9C?= =?UTF-8?q?=20Enter,=20Shift-Enter=EC=9E=85=EB=A0=A5=EC=8B=9C=20p=20?= =?UTF-8?q?=ED=83=9C=EA=B7=B8=EA=B0=80=20=EB=A7=8E=EC=9D=B4=20=EC=83=9D?= =?UTF-8?q?=EA=B8=B0=EB=8D=98=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95(#1?= =?UTF-8?q?9241534)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7951 201d5d3c-b55e-5fd7-737f-ddc643e51545 --- modules/editor/skins/xeed/js/xeed.js | 243 ++++++++++++++++----------- 1 file changed, 142 insertions(+), 101 deletions(-) diff --git a/modules/editor/skins/xeed/js/xeed.js b/modules/editor/skins/xeed/js/xeed.js index e0498c11f..918c810a0 100644 --- a/modules/editor/skins/xeed/js/xeed.js +++ b/modules/editor/skins/xeed/js/xeed.js @@ -47,7 +47,7 @@ Xeed = xe.createApp('Xeed', { minHeight : 400 }, options); this._options = opts; - + // min height if (opts.minHeight > opts.height) opts.minHeight = opts.height; @@ -61,6 +61,7 @@ Xeed = xe.createApp('Xeed', { } // Convert to wysiwyg editor + this.$textarea = $text; this.$root = $text.parent(); this.$richedit = this.$root.find('div.edit>div.xdcs:first'); @@ -129,7 +130,7 @@ Xeed = xe.createApp('Xeed', { var v = this._options[key]; if (is_def(v)) return v; }, - + /** * @brief Set option * @param key String option key @@ -208,7 +209,7 @@ Xeed = xe.createApp('Xeed', { */ getFrame : function(seq) { var self = this; - + return { editor_sequence : seq, getSelectedHTML : function(){}, @@ -345,7 +346,7 @@ Xeed = xe.createApp('Xeed', { // unregister ui event if (selector) { - ($btn = is_str(selector)?this.$toolbar.find(selector):$(selector)).unbind('click'); + ($btn = is_str(selector)?this.$toolbar.find(selector):$(selector)).unbind('click'); } }, @@ -377,7 +378,7 @@ Xeed = xe.createApp('Xeed', { this.$richedit.focus(); }, - + /** * @brief Fire event on keydown * @param event object @@ -476,7 +477,7 @@ Simple = xe.createPlugin('SimpleCommand', { // empty button list self.$btns = {}; }, - + API_ON_CHANGE_NODE : function(sender, params) { var self = this, node = params[0]; @@ -532,7 +533,7 @@ Block = xe.createPlugin('BlockCommand', { .each(function(){ var $this = $(this), num; if (!/(?:^|\s)h([1-7])(?:\s|$)/i.test($this.parent().attr('class'))) return true; - + num = RegExp.$1; if (np && !np.indexOf('Mac')) $this.attr('title', 'Ctrl+Command+'+num); else $this.attr('title', 'Ctrl+'+num); @@ -593,15 +594,15 @@ Block = xe.createPlugin('BlockCommand', { if (!sel) return ret; - nodes = sel.collapsed?[sel.getStartNode()]:sel.getNodes(); + nodes = sel.collapsed?[sel[_sc_]]:sel.getNodes(); $(nodes).each(function(i,node){ var name; - while(node[_pn_]) { + while(node && node[_pn_]) { name = node[_nn_].toLowerCase(); - if (/^t(able|body|foot|head|r)$/i.test(name)) { + if (/^t(able|body|foot|head|r)$/.test(name)) { node = node[_pn_]; continue; } @@ -613,12 +614,29 @@ Block = xe.createPlugin('BlockCommand', { } if (rx_root.test(node[_pn_].className || '')) { - if (name != 'br') { - if (node[_nt_] == 3) node = $(node).wrap('

')[0][_pn_]; - if (node[_nt_] == 1) node.className += ' '+_xs_; + var nodes = [], n=node, $p; - ret.push(node); + // get all non-block previous siblings + while(n[_ps_]){ + if (is_block(n[_ps_])) break; + nodes.push(n[_ps_]); + n = n[_ps_]; } + nodes.reverse(); + + // current node + nodes.push(n=node); + + // get all non-block next siblings + while(n[_ns_]) { + if (is_block(n[_ns_])) break; + nodes.push(n[_ns_]); + n = n[_ns_]; + } + + $p = $('

').addClass(_xs_); + node[_pn_].insertBefore($p[0], nodes[0]); + ret.push($p.append(nodes).get(0)); break; } @@ -632,9 +650,11 @@ Block = xe.createPlugin('BlockCommand', { var $this = $(this); return !$this.is('.'+_xr_) && !$this.parentsUntil('.'+_xr_).filter('.'+_xs_).length; }); - + $ret.removeClass(_xs_).each(function(){ if (!this.className) $(this).removeAttr('class') }); + sel.select(); + return $.makeArray($.unique(ret)); }, match : function(node, selector) { @@ -697,7 +717,9 @@ Block = xe.createPlugin('BlockCommand', { fireChangeNode : function(sel) { var self = this, _sel = sel || this.oApp.getSelection(); - setTimeout(function(){ self.cast('ON_CHANGE_NODE', [_sel[_sc_]]) }, 0); + setTimeout(function(){ + if (_sel && _sel[_sc_]) self.cast('ON_CHANGE_NODE', [_sel[_sc_]]) + }, 0); }, /** * @brief Quotes selection @@ -743,7 +765,7 @@ Block = xe.createPlugin('BlockCommand', { this.fireChangeNode(sel); }, /** - * @brief + * @brief */ API_EXEC_BOX : function(sender, params) { var self = this, sel = this.oApp.getSelection(), start, end, ancestor, match, $bx, _bx_ = 'div.bx'; @@ -784,7 +806,7 @@ Block = xe.createPlugin('BlockCommand', { this.fireChangeNode(sel); }, API_EXEC_INDENT : function(sender, params) { - var parents = this.getBlockParents(); + var sel = this.oApp.getSelection(), parents = this.getBlockParents(); $(parents).each(function(){ var $this = $(this), left = parseInt($this.css('margin-left'), 10); @@ -798,9 +820,10 @@ Block = xe.createPlugin('BlockCommand', { this.cast('SAVE_UNDO_POINT'); this.fireChangeNode(); + try { sel.select() } catch(e){}; }, API_EXEC_OUTDENT : function(sender, params) { - var parents = this.getBlockParents(); + var sel = this.oApp.getSelection(), parents = this.getBlockParents(); $(parents).each(function(){ var $this = $(this), left = parseInt($this.css('margin-left'), 10); @@ -817,6 +840,7 @@ Block = xe.createPlugin('BlockCommand', { this.cast('SAVE_UNDO_POINT'); this.fireChangeNode(); + try { sel.select() } catch(e){}; }, /** * @brief @@ -1037,21 +1061,21 @@ Font = xe.createPlugin('Font', { $tb.find('li.cr') .find('ul.ct,ul.cx') .each(function(){ - + var $this = $(this), $li = $this.find('>li').remove(), $clone_li, $span, $btn, colors,i,c,types; - + colors = $li.text().split(';'); for(i=0,c=colors.length; i < c; i++) { types = $.trim(colors[i]).split(':'); $clone_li = $li.clone(true); $btn = $clone_li.find('>button'); $span = $btn.find('>span'); - + (($span.length)?$span:$btn).text('#'+types[0]); $btn.css('backgroundColor', '#'+types[0]); if (types[1]) $btn.css('color', '#'+types[1]); - + $this.append($clone_li); } }) @@ -1291,9 +1315,9 @@ LineBreak = xe.createPlugin('LineBreak', { }, activate : function() { this.oApp.$richedit.keydown(this._fn); - + // If you pres Enter key,
will be inserted by default. - this.oApp.setDefault('force_br', true); + this.oApp.setDefault('force_br', true); }, deactivate : function() { this.oApp.$richedit.unbind('keydown', this._fn); @@ -1317,14 +1341,14 @@ LineBreak = xe.createPlugin('LineBreak', { return false; }, wrapBlock : function(sel) { - var self = this, sc, so, eo, $node, $clone, $bookmark, last, _xb_ = '_xeed_tmp_bookmark'; + var self = this, sc, so, eo, nodes, $node, $clone, $bookmark, last, _xb_ = '_xeed_tmp_bookmark'; // collect all sibling function sibling(node, prev) { var s, ret = []; while(s=node[prev?_ps_:_ns_]) { - if (s[_nt_] == 3 || (s[_nt_] == 1 && !rx_block.test(s[_nn_]))) ret.push(s); + if (s[_nt_] == 3 || (s[_nt_] == 1 && !is_block(s))) ret.push(s); node = s; } @@ -1350,7 +1374,13 @@ LineBreak = xe.createPlugin('LineBreak', { // find block parent $node = $node.parentsUntil('.'+_xr_).filter(function(){ return rx_block.test(this[_nn_]) }); - $node = $node.length?$node.eq(0):$($.merge(sibling(sc,1), [sc], sibling(sc))).wrap('

').parent(); + if ($node.length) { + $node = $node.eq(0); + } else { + nodes = $.merge(sibling(sc,1), [sc], sibling(sc)); + nodes[0][_pn_].insertBefore(($node=$('

')).get(0), nodes[0]); + $node.append(nodes); + } // wrap with '

' in a table cell if ($node.is('td,th')) $node = $node.wrapInner('

').children(0); @@ -1410,7 +1440,7 @@ LineBreak = xe.createPlugin('LineBreak', { if (!$.browser.msie) { if (!$br[0][_ns_]) $br.after(d.createTextNode(invisibleCh)); if ($.browser.safari) { - // TODO : remove broken character which is displayed only in Safari. + // TODO : remove broken character which is displayed only in Safari. } } @@ -1617,7 +1647,7 @@ Filter = xe.createPlugin('ContentFilter', { _r2t : [], // rich2text filters _t2r : [], // text2rich filters _types : [], // valid types - + init : function() { this._in = []; this._out = []; @@ -1657,11 +1687,11 @@ Filter = xe.createPlugin('ContentFilter', { */ API_BEFORE_SET_CONTENT : function(sender, params) { var i,c; - + for(i=0,c=this._in.length; i < c; i++) params[0] = this._in[i](params[0]); for(i=0,c=this._t2r.length; i < c; i++) params[0] = this._t2r[i](params[0]); }, - + API_BEFORE_SET_CONTENT_HTML : function(sender, params) { for(i=0,c=this._r2t.length; i < c; i++) params[0] = this._r2t[i](params[0]); }, @@ -1826,7 +1856,7 @@ Resize = xe.createPlugin('Resize', { }, activate : function() { var $root = this.oApp.$root, chk; - + if (!this.prev_height) this.prev_height = this.oApp.getOption('height'); this.$container = this.oApp.$richedit.parent(); @@ -1948,7 +1978,7 @@ UndoRedo = xe.createPlugin('UndoRedo', { if ($undo && $undo[0]) { fn = (index > 0 && len)?'removeClass':'addClass'; $undo.parent()[fn]('disable'); - } + } if ($redo && $redo[0]) { fn = (index+1 < len)?'removeClass':'addClass'; @@ -2075,14 +2105,20 @@ SChar = xe.createPlugin('SChar', { this.$btn = $tb.find('button.sc').mousedown(function(){ self.cast('TOGGLE_SCHAR_LAYER'); return false; }); this.$layer = this.$btn.next('div.lr') .mousedown(function(event){ event.stopPropagation(); }) - .find('li.li').each(function(){ - var $this = $(this), $ul = $this.find('>ul'), $li = $ul.find('li').remove(), i, c, chars; - - chars = $li.text(); - - for(i=0, c=chars.length; i < c; i++) { - $ul.append( $li.clone(true).find('>button').text(chars.substr(i,1)).end() ); - } + .find('li.li').each(function(i){ + var $this = $(this), $ul = $this.find('>ul'), $li = $ul.find('li').remove(), chars, format; + + chars = $li.text(); + format = $('