Added: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.js
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.js?rev=1178141&view=auto ============================================================================== --- ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.js (added) +++ ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.js Sun Oct 2 08:06:49 2011 @@ -0,0 +1,460 @@ +/* + * elRTE - WSWING editor for web + * + * Usage: + * var opts = { + * .... // see elRTE.options.js + * } + * var editor = new elRTE($('#my-id').get(0), opts) + * or + * $('#my-id').elrte(opts) + * + * $('#my-id) may be textarea or any DOM Element with text + * + * @author: Dmitry Levashov (dio) [hidden email] + * Copyright: Studio 42, http://www.std42.ru + */ +(function($) { + +elRTE = function(target, opts) { + if (!target || !target.nodeName) { + return alert('elRTE: argument "target" is not DOM Element'); + } + var self = this, html; + this.version = '1.3'; + this.build = '2011-06-23'; + this.options = $.extend(true, {}, this.options, opts); + this.browser = $.browser; + this.target = $(target); + + this.lang = (''+this.options.lang); + this._i18n = new eli18n({textdomain : 'rte', messages : { rte : this.i18Messages[this.lang] || {}} }); + this.rtl = !!(/^(ar|fa|he)$/.test(this.lang) && this.i18Messages[this.lang]); + + if (this.rtl) { + this.options.cssClass += ' el-rte-rtl'; + } + this.toolbar = $('<div class="toolbar"/>'); + this.iframe = document.createElement('iframe'); + this.iframe.setAttribute('frameborder', 0); // fixes IE border + + // this.source = $('<textarea />').hide(); + this.workzone = $('<div class="workzone"/>').append(this.iframe).append(this.source); + this.statusbar = $('<div class="statusbar"/>'); + this.tabsbar = $('<div class="tabsbar"/>'); + this.editor = $('<div class="'+this.options.cssClass+'" />').append(this.toolbar).append(this.workzone).append(this.statusbar).append(this.tabsbar); + + this.doc = null; + this.$doc = null; + this.window = null; + + this.utils = new this.utils(this); + this.dom = new this.dom(this); + this.filter = new this.filter(this) + + /** + * Sync iframes/textareas height with workzone height + * + * @return void + */ + this.updateHeight = function() { + self.workzone.add(self.iframe).add(self.source).height(self.workzone.height()); + } + + /** + * Turn editor resizable on/off if allowed + * + * @param Boolean + * @return void + **/ + this.resizable = function(r) { + var self = this; + if (this.options.resizable && $.fn.resizable) { + if (r) { + this.editor.resizable({handles : 'se', alsoResize : this.workzone, minWidth :300, minHeight : 200 }).bind('resize', self.updateHeight); + } else { + this.editor.resizable('destroy').unbind('resize', self.updateHeight); + } + } + } + + /* attach editor to document */ + this.editor.insertAfter(target); + /* init editor textarea */ + var content = ''; + if (target.nodeName == 'TEXTAREA') { + this.source = this.target; + this.source.insertAfter(this.iframe).hide(); + content = this.target.val(); + } else { + this.source = $('<textarea />').insertAfter(this.iframe).hide(); + content = this.target.hide().html(); + } + this.source.attr('name', this.target.attr('name')||this.target.attr('id')); + content = $.trim(content); + if (!content) { + content = ' '; + } + + /* add tabs */ + if (this.options.allowSource) { + this.tabsbar.append('<div class="tab editor rounded-bottom-7 active">'+self.i18n('Editor')+'</div><div class="tab source rounded-bottom-7">'+self.i18n('Source')+'</div><div class="clearfix" style="clear:both"/>') + .children('.tab').click(function(e) { + if (!$(this).hasClass('active')) { + self.tabsbar.children('.tab').toggleClass('active'); + self.workzone.children().toggle(); + + if ($(this).hasClass('editor')) { + self.updateEditor(); + self.window.focus(); + self.ui.update(true); + } else { + self.updateSource(); + self.source.focus(); + if ($.browser.msie) { + // @todo + } else { + self.source[0].setSelectionRange(0, 0); + } + self.ui.disable(); + self.statusbar.empty(); + + } + } + + }); + } + + this.window = this.iframe.contentWindow; + this.doc = this.iframe.contentWindow.document; + this.$doc = $(this.doc); + + /* put content into iframe */ + html = '<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'; + $.each(self.options.cssfiles, function() { + html += '<link rel="stylesheet" type="text/css" href="'+this+'" />'; + }); + this.doc.open(); + var s = this.filter.wysiwyg(content), + cl = this.rtl ? ' class="el-rte-rtl"' : ''; + this.doc.write(self.options.doctype+html+'</head><body'+cl+'>'+(s)+'</body></html>'); + this.doc.close(); + + /* make iframe editable */ + if ($.browser.msie) { + this.doc.body.contentEditable = true; + } else { + try { this.doc.designMode = "on"; } + catch(e) { } + this.doc.execCommand('styleWithCSS', false, this.options.styleWithCSS); + } + + if (this.options.height>0) { + this.workzone.height(this.options.height); + } + if (this.options.width>0) { + this.editor.width(this.options.width); + } + + this.updateHeight(); + this.resizable(true); + this.window.focus(); + + this.history = new this.history(this); + + /* init selection object */ + this.selection = new this.selection(this); + /* init buttons */ + this.ui = new this.ui(this); + + + /* bind updateSource to parent form submit */ + this.target.parents('form').bind('submit.elfinder', function(e) { + self.source.parents('form').find('[name="el-select"]').remove() + self.beforeSave(); + }); + + // on tab press - insert \t and prevent move focus + this.source.bind('keydown', function(e) { + if (e.keyCode == 9) { + e.preventDefault(); + + if ($.browser.msie) { + var r = document.selection.createRange(); + r.text = "\t"+r.text; + this.focus(); + } else { + var before = this.value.substr(0, this.selectionStart), + after = this.value.substr(this.selectionEnd); + this.value = before+"\t"+after; + this.setSelectionRange(before.length+1, before.length+1); + } + } + }); + + $(this.doc.body).bind('dragend', function(e) { + setTimeout(function() { + try { + self.window.focus(); + var bm = self.selection.getBookmark(); + self.selection.moveToBookmark(bm); + self.ui.update(); + } catch(e) { } + + + }, 200); + + }); + + this.typing = false; + this.lastKey = null; + /* update buttons on click and keyup */ + this.$doc.bind('mouseup', function() { + self.typing = false; + self.lastKey = null; + self.ui.update(); + }) + .bind('keyup', function(e) { + if ((e.keyCode >= 8 && e.keyCode <= 13) || (e.keyCode>=32 && e.keyCode<= 40) || e.keyCode == 46 || (e.keyCode >=96 && e.keyCode <= 111)) { + self.ui.update(); + } + }) + .bind('keydown', function(e) { + if ((e.metaKey || e.ctrlKey) && e.keyCode == 65) { + self.ui.update(); + } else if (e.keyCode == 13) { + var n = self.selection.getNode(); + // self.log(n) + if (self.dom.selfOrParent(n, /^PRE$/)) { + self.selection.insertNode(self.doc.createTextNode("\r\n")); + return false; + } else if ($.browser.safari && e.shiftKey) { + self.selection.insertNode(self.doc.createElement('br')) + return false; + } + } + + if ((e.keyCode>=48 && e.keyCode <=57) || e.keyCode==61 || e.keyCode == 109 || (e.keyCode>=65 && e.keyCode<=90) || e.keyCode==188 ||e.keyCode==190 || e.keyCode==191 || (e.keyCode>=219 && e.keyCode<=222)) { + if (!self.typing) { + self.history.add(true); + } + self.typing = true; + self.lastKey = null; + } else if (e.keyCode == 8 || e.keyCode == 46 || e.keyCode == 32 || e.keyCode == 13) { + if (e.keyCode != self.lastKey) { + self.history.add(true); + } + self.lastKey = e.keyCode; + self.typing = false; + } + + if (e.keyCode == 32 && $.browser.opera) { + self.selection.insertNode(self.doc.createTextNode(" ")); + return false + } + }) + .bind('paste', function(e) { + if (!self.options.allowPaste) { + // paste denied + e.stopPropagation(); + e.preventDefault(); + } else { + var n = $(self.dom.create('div'))[0], + r = self.doc.createTextNode('_'); + self.history.add(true); + self.typing = true; + self.lastKey = null; + n.appendChild(r); + self.selection.deleteContents().insertNode(n); + self.selection.select(r); + setTimeout(function() { + if (n.parentNode) { + // clean sandbox content + $(n).html(self.filter.proccess('paste', $(n).html())); + r = n.lastChild; + self.dom.unwrap(n); + if (r) { + self.selection.select(r); + self.selection.collapse(false); + } + } else { + // smth wrong - clean all doc + n.parentNode && n.parentNode.removeChild(n); + self.val(self.filter.proccess('paste', self.filter.wysiwyg2wysiwyg($(self.doc.body).html()))); + self.selection.select(self.doc.body.firstChild); + self.selection.collapse(true); + } + $(self.doc.body).mouseup(); // to activate history buutons + }, 15); + } + }); + + if ($.browser.msie) { + this.$doc.bind('keyup', function(e) { + if (e.keyCode == 86 && (e.metaKey||e.ctrlKey)) { + self.history.add(true); + self.typing = true; + self.lastKey = null; + self.selection.saveIERange(); + self.val(self.filter.proccess('paste', self.filter.wysiwyg2wysiwyg($(self.doc.body).html()))); + self.selection.restoreIERange(); + $(self.doc.body).mouseup(); + this.ui.update(); + } + }); + } + + if ($.browser.safari) { + this.$doc.bind('click', function(e) { + $(self.doc.body).find('.elrte-webkit-hl').removeClass('elrte-webkit-hl'); + if (e.target.nodeName == 'IMG') { + $(e.target).addClass('elrte-webkit-hl'); + } + }).bind('keyup', function(e) { + $(self.doc.body).find('.elrte-webkit-hl').removeClass('elrte-webkit-hl'); + }) + } + + this.window.focus(); + + this.destroy = function() { + this.updateSource(); + this.target.is('textarea') + ? this.target.val($.trim(this.source.val())) + : this.target.html($.trim(this.source.val())); + this.editor.remove(); + this.target.show().parents('form').unbind('submit.elfinder'); + } + +} + +/** + * Return message translated to selected language + * + * @param string msg message text in english + * @return string + **/ +elRTE.prototype.i18n = function(msg) { + return this._i18n.translate(msg); +} + + + +/** + * Display editor + * + * @return void + **/ +elRTE.prototype.open = function() { + this.editor.show(); +} + +/** + * Hide editor and display elements on wich editor was created + * + * @return void + **/ +elRTE.prototype.close = function() { + this.editor.hide(); +} + +elRTE.prototype.updateEditor = function() { + this.val(this.source.val()); +} + +elRTE.prototype.updateSource = function() { + this.source.val(this.filter.source($(this.doc.body).html())); +} + +/** + * Return edited text + * + * @return String + **/ +elRTE.prototype.val = function(v) { + if (typeof(v) == 'string') { + v = ''+v; + if (this.source.is(':visible')) { + this.source.val(this.filter.source2source(v)); + } else { + if ($.browser.msie) { + this.doc.body.innerHTML = '<br />'+this.filter.wysiwyg(v); + this.doc.body.removeChild(this.doc.body.firstChild); + } else { + this.doc.body.innerHTML = this.filter.wysiwyg(v); + } + + } + } else { + if (this.source.is(':visible')) { + return this.filter.source2source(this.source.val()).trim(); + } else { + return this.filter.source($(this.doc.body).html()).trim(); + } + } +} + +elRTE.prototype.beforeSave = function() { + this.source.val($.trim(this.val())||''); +} + +/** + * Submit form + * + * @return void + **/ +elRTE.prototype.save = function() { + this.beforeSave(); + this.editor.parents('form').submit(); +} + +elRTE.prototype.log = function(msg) { + if (window.console && window.console.log) { + window.console.log(msg); + } + +} + +elRTE.prototype.i18Messages = {}; + +$.fn.elrte = function(o, v) { + var cmd = typeof(o) == 'string' ? o : '', ret; + + this.each(function() { + if (!this.elrte) { + this.elrte = new elRTE(this, typeof(o) == 'object' ? o : {}); + } + switch (cmd) { + case 'open': + case 'show': + this.elrte.open(); + break; + case 'close': + case 'hide': + this.elrte.close(); + break; + case 'updateSource': + this.elrte.updateSource(); + break; + case 'destroy': + this.elrte.destroy(); + } + }); + + if (cmd == 'val') { + if (!this.length) { + return ''; + } else if (this.length == 1) { + return v ? this[0].elrte.val(v) : this[0].elrte.val(); + } else { + ret = {} + this.each(function() { + ret[this.elrte.source.attr('name')] = this.elrte.val(); + }); + return ret; + } + } + return this; +} + +})(jQuery); Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.options.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.options.js?rev=1178141&view=auto ============================================================================== --- ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.options.js (added) +++ ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.options.js Sun Oct 2 08:06:49 2011 @@ -0,0 +1,168 @@ +/* + * elRTE configuration + * + * @param doctype - doctype for editor iframe + * @param cssClass - css class for editor + * @param cssFiles - array of css files, witch will inlude in iframe + * @param height - not used now (may be deleted in future) + * @param lang - interface language (requires file in i18n dir) + * @param toolbar - name of toolbar to load + * @param absoluteURLs - convert files and images urls to absolute or not + * @param allowSource - is source editing allowing + * @param stripWhiteSpace - strip лиÑние whitespaces/tabs or not + * @param styleWithCSS - use style=... instead of strong etc. + * @param fmAllow - allow using file manger (elFinder) + * @param fmOpen - callback for open file manager + * @param buttons - object with pairs of buttons classes names and titles (when create new button, you have to add iys name here) + * @param panels - named groups of buttons + * @param panelNames - title of panels (required for one planned feature) + * @param toolbars - named redy to use toolbals (you may combine your own toolbar) + * + * @author: Dmitry Levashov (dio) [hidden email] + * Copyright: Studio 42, http://www.std42.ru + */ +(function($) { +elRTE.prototype.options = { + doctype : '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">', + cssClass : 'el-rte', + cssfiles : [], + height : null, + resizable : true, + lang : 'en', + toolbar : 'normal', + absoluteURLs : true, + allowSource : true, + stripWhiteSpace : true, + styleWithCSS : false, + fmAllow : true, + fmOpen : null, + /* if set all other tag will be removed */ + allowTags : [], + /* if set this tags will be removed */ + denyTags : ['applet', 'base', 'basefont', 'bgsound', 'blink', 'body', 'col', 'colgroup', 'isindex', 'frameset', 'html', 'head', 'meta', 'marquee', 'noframes', 'noembed', 'o:p', 'title', 'xml'], + denyAttr : [], + /* on paste event this attributes will removed from pasted html */ + pasteDenyAttr : ['id', 'name', 'class', 'style', 'language', 'onclick', 'ondblclick', 'onhover', 'onkeup', 'onkeydown', 'onkeypress'], + /* If false - all text nodes will be wrapped by paragraph tag */ + allowTextNodes : true, + /* allow browser specific styles like -moz|-webkit|-o */ + allowBrowsersSpecStyles : false, + /* allow paste content into editor */ + allowPaste : true, + /* if true - only text will be pasted (not in ie) */ + pasteOnlyText : false, + /* user replacement rules */ + replace : [], + /* user restore rules */ + restore : [], + pagebreak : '<div style="page-break-after: always;"></div>', //'<!-- pagebreak -->', + buttons : { + 'save' : 'Save', + 'copy' : 'Copy', + 'cut' : 'Cut', + 'css' : 'Css style and class', + 'paste' : 'Paste', + 'pastetext' : 'Paste only text', + 'pasteformattext' : 'Paste formatted text', + 'removeformat' : 'Clean format', + 'undo' : 'Undo last action', + 'redo' : 'Redo previous action', + 'bold' : 'Bold', + 'italic' : 'Italic', + 'underline' : 'Underline', + 'strikethrough' : 'Strikethrough', + 'superscript' : 'Superscript', + 'subscript' : 'Subscript', + 'justifyleft' : 'Align left', + 'justifyright' : 'Ailgn right', + 'justifycenter' : 'Align center', + 'justifyfull' : 'Align full', + 'indent' : 'Indent', + 'outdent' : 'Outdent', + 'rtl' : 'Right to left', + 'ltr' : 'Left to right', + 'forecolor' : 'Font color', + 'hilitecolor' : 'Background color', + 'formatblock' : 'Format', + 'fontsize' : 'Font size', + 'fontname' : 'Font', + 'insertorderedlist' : 'Ordered list', + 'insertunorderedlist' : 'Unordered list', + 'horizontalrule' : 'Horizontal rule', + 'blockquote' : 'Blockquote', + 'div' : 'Block element (DIV)', + 'link' : 'Link', + 'unlink' : 'Delete link', + 'anchor' : 'Bookmark', + 'image' : 'Image', + 'pagebreak' : 'Page break', + 'smiley' : 'Smiley', + 'flash' : 'Flash', + 'table' : 'Table', + 'tablerm' : 'Delete table', + 'tableprops' : 'Table properties', + 'tbcellprops' : 'Table cell properties', + 'tbrowbefore' : 'Insert row before', + 'tbrowafter' : 'Insert row after', + 'tbrowrm' : 'Delete row', + 'tbcolbefore' : 'Insert column before', + 'tbcolafter' : 'Insert column after', + 'tbcolrm' : 'Delete column', + 'tbcellsmerge' : 'Merge table cells', + 'tbcellsplit' : 'Split table cell', + 'docstructure' : 'Toggle display document structure', + 'elfinder' : 'Open file manager', + 'fullscreen' : 'Toggle full screen mode', + 'nbsp' : 'Non breakable space', + 'stopfloat' : 'Stop element floating', + 'about' : 'About this software' + }, + panels : { + eol : [], // special panel, insert's a new line in toolbar + save : ['save'], + copypaste : ['copy', 'cut', 'paste', 'pastetext', 'pasteformattext', 'removeformat', 'docstructure'], + undoredo : ['undo', 'redo'], + style : ['bold', 'italic', 'underline', 'strikethrough', 'subscript', 'superscript'], + colors : ['forecolor', 'hilitecolor'], + alignment : ['justifyleft', 'justifycenter', 'justifyright', 'justifyfull'], + indent : ['outdent', 'indent'], + format : ['formatblock', 'fontsize', 'fontname'], + lists : ['insertorderedlist', 'insertunorderedlist'], + elements : ['horizontalrule', 'blockquote', 'div', 'stopfloat', 'css', 'nbsp', 'smiley', 'pagebreak'], + direction : ['ltr', 'rtl'], + links : ['link', 'unlink', 'anchor'], + images : ['image'], + media : ['image', 'flash'], + tables : ['table', 'tableprops', 'tablerm', 'tbrowbefore', 'tbrowafter', 'tbrowrm', 'tbcolbefore', 'tbcolafter', 'tbcolrm', 'tbcellprops', 'tbcellsmerge', 'tbcellsplit'], + elfinder : ['elfinder'], + fullscreen : ['fullscreen', 'about'] + }, + toolbars : { + tiny : ['style'], + compact : ['save', 'undoredo', 'style', 'alignment', 'lists', 'links', 'fullscreen'], + normal : ['save', 'copypaste', 'undoredo', 'style', 'alignment', 'colors', 'indent', 'lists', 'links', 'elements', 'images', 'fullscreen'], + complete : ['save', 'copypaste', 'undoredo', 'style', 'alignment', 'colors', 'format', 'indent', 'lists', 'links', 'elements', 'media', 'fullscreen'], + maxi : ['save', 'copypaste', 'undoredo', 'elfinder', 'style', 'alignment', 'direction', 'colors', 'format', 'indent', 'lists', 'links', 'elements', 'media', 'tables', 'fullscreen'], + eldorado : ['save', 'copypaste', 'elfinder', 'undoredo', 'style', 'alignment', 'colors', 'format', 'indent', 'lists', 'links', 'elements', 'media', 'tables', 'fullscreen'] + + }, + panelNames : { + save : 'Save', + copypaste : 'Copy/Pase', + undoredo : 'Undo/Redo', + style : 'Text styles', + colors : 'Colors', + alignment : 'Alignment', + indent : 'Indent/Outdent', + format : 'Text format', + lists : 'Lists', + elements : 'Misc elements', + direction : 'Script direction', + links : 'Links', + images : 'Images', + media : 'Media', + tables : 'Tables', + elfinder : 'File manager (elFinder)' + } +}; +})(jQuery); Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.options.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.options.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.options.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.selection.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.selection.js?rev=1178141&view=auto ============================================================================== --- ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.selection.js (added) +++ ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.selection.js Sun Oct 2 08:06:49 2011 @@ -0,0 +1,777 @@ +/** + * @class selection - elRTE utils for working with text selection + * + * @param elRTE rte обÑекÑ-ÑедакÑÐ¾Ñ + * + * @author: Dmitry Levashov (dio) [hidden email] + **/ +(function($) { +elRTE.prototype.selection = function(rte) { + this.rte = rte; + var self = this; + this.w3cRange = null; + var start, end, node, bm; + + $(this.rte.doc) + .keyup(function(e) { + if (e.ctrlKey || e.metaKey || (e.keyCode >= 8 && e.keyCode <= 13) || (e.keyCode>=32 && e.keyCode<= 40) || e.keyCode == 46 || (e.keyCode >=96 && e.keyCode <= 111)) { + self.cleanCache(); + } + }) + .mousedown(function(e) { + // self.rte.log(e) + if (e.target.nodeName == 'HTML') { + start = self.rte.doc.body; + } else { + start = e.target; + } + end = node = null; + }) + .mouseup(function(e) { + if (e.target.nodeName == 'HTML') { + end = self.rte.doc.body; + } else { + end = e.target; + } + end = e.target; + node = null; + }).click(); + + /** + * возвÑаÑÐ°ÐµÑ selection + * + * @return Selection + **/ + function selection() { + return self.rte.window.getSelection ? self.rte.window.getSelection() : self.rte.window.document.selection; + } + + /** + * ÐÑпомогаÑелÑÐ½Ð°Ñ ÑÑнкÑÐ¸Ñ + * ÐозвÑаÑÐ°ÐµÑ Ñамого веÑÑ Ð½ÐµÐ³Ð¾ ÑодиÑелÑ, оÑвеÑаÑÑего ÑÑÐ»Ð¾Ð²Ð¸Ñ - ÑекÑÑÐ°Ñ Ð½Ð¾Ð´Ð° - его единÑÑÐ²ÐµÐ½Ð½Ð°Ñ Ð½ÐµÐ¿ÑÑÑÐ°Ñ Ð´Ð¾ÑеÑнÑÑ Ð½Ð¾Ð´Ð° + * + * @param DOMElement n нода, Ð´Ð»Ñ ÐºÐ¾ÑоÑой иÑем ÑодиÑÐµÐ»Ñ + * @param DOMElement p еÑли задана - нода, вÑÑе коÑоÑой не поднимаемÑÑ + * @param String s ÑÑÑона поиÑка (left||right||null) + * @return DOMElement + **/ + function realSelected(n, p, s) { + while (n.nodeName != 'BODY' && n.parentNode && n.parentNode.nodeName != 'BODY' && (p ? n!== p && n.parentNode != p : 1) && ((s=='left' && self.rte.dom.isFirstNotEmpty(n)) || (s=='right' && self.rte.dom.isLastNotEmpty(n)) || (self.rte.dom.isFirstNotEmpty(n) && self.rte.dom.isLastNotEmpty(n))) ) { + n = n.parentNode; + } + return n; + } + + /** + * ÐозвÑаÑÐ°ÐµÑ TRUE, еÑли вÑделение "ÑÑ Ð»Ð¾Ð¿Ð½ÑÑо" + * + * @return bool + **/ + this.collapsed = function() { + return this.getRangeAt().isCollapsed(); + } + + /** + * "Ð¡Ñ Ð»Ð¾Ð¿ÑваеÑ" вÑделение + * + * @param bool toStart ÑÑ Ð»Ð¾Ð¿Ð½ÑÑÑ Ðº наÑалÑной ÑоÑке + * @return void + **/ + this.collapse = function(st) { + var s = selection(), + r = this.getRangeAt(); + r.collapse(st?true:false); + if (!$.browser.msie) { + s.removeAllRanges(); + s.addRange(r); + + } + return this; + } + + /** + * ÐозвÑаÑÐ°ÐµÑ TextRange + * ÐÐ»Ñ Ð½Ð¾ÑмалÑнÑÑ Ð±ÑаÑзеÑов - наÑивнÑй range + * Ð´Ð»Ñ "ÑамизнаеÑеÑего" - ÑмÑлÑÑÐ¸Ñ w3c range + * + * @return range|w3cRange + **/ + this.getRangeAt = function(updateW3cRange) { + if (this.rte.browser.msie) { + if (!this.w3cRange) { + this.w3cRange = new this.rte.w3cRange(this.rte); + } + updateW3cRange && this.w3cRange.update(); + return this.w3cRange; + } + + var s = selection(); + var r = s.rangeCount > 0 ? s.getRangeAt(0) : this.rte.doc.createRange(); + r.getStart = function() { + return this.startContainer.nodeType==1 + ? this.startContainer.childNodes[Math.min(this.startOffset, this.startContainer.childNodes.length-1)] + : this.startContainer; + } + + r.getEnd = function() { + return this.endContainer.nodeType==1 + ? this.endContainer.childNodes[ Math.min(this.startOffset == this.endOffset ? this.endOffset : this.endOffset-1, this.endContainer.childNodes.length-1)] + : this.endContainer; + } + r.isCollapsed = function() { + return this.collapsed; + } + return r; + } + + this.saveIERange = function() { + if ($.browser.msie) { + bm = this.getRangeAt().getBookmark(); + } + } + + this.restoreIERange = function() { + $.browser.msie && bm && this.getRangeAt().moveToBookmark(bm); + } + + this.cloneContents = function() { + var n = this.rte.dom.create('div'), r, c, i; + if ($.browser.msie) { + try { + r = this.rte.window.document.selection.createRange(); + } catch(e) { + r = this.rte.doc.body.createTextRange(); + } + $(n).html(r.htmlText); + } else { + c = this.getRangeAt().cloneContents(); + for (i=0; i<c.childNodes.length; i++) { + n.appendChild(c.childNodes[i].cloneNode(true)); + } + } + return n; + } + + /** + * ÐÑделÑÐµÑ Ð½Ð¾Ð´Ñ + * + * @param DOMNode s нода наÑала вÑÐ´ÐµÐ»ÐµÐ½Ð¸Ñ + * @param DOMNode e нода конÑа вÑÐ´ÐµÐ»ÐµÐ½Ð¸Ñ + * @return selection + **/ + this.select = function(s, e) { + e = e||s; + + if (this.rte.browser.msie) { + var r = this.rte.doc.body.createTextRange(), + r1 = r.duplicate(), + r2 = r.duplicate(); + + r1.moveToElementText(s); + r2.moveToElementText(e); + r.setEndPoint('StartToStart', r1); + r.setEndPoint('EndToEnd', r2); + r.select(); + } else { + + var sel = selection(), + r = this.getRangeAt(); + r.setStartBefore(s); + r.setEndAfter(e); + sel.removeAllRanges(); + sel.addRange(r); + } + return this.cleanCache(); + } + + /** + * ÐÑделÑÐµÑ ÑодеÑжимое Ð½Ð¾Ð´Ñ + * + * @param Element n нода + * @return selection + **/ + this.selectContents = function(n) { + var r = this.getRangeAt(); + if (n && n.nodeType == 1) { + if (this.rte.browser.msie) { + r.range(); + r.r.moveToElementText(n.parentNode); + r.r.select(); + } else { + try { + r.selectNodeContents(n); + } catch (e) { + return this.rte.log('unable select node contents '+n); + } + var s = selection(); + s.removeAllRanges(); + s.addRange(r); + } + } + return this; + } + + this.deleteContents = function() { + if (!$.browser.msie) { + this.getRangeAt().deleteContents(); + } + return this; + } + + /** + * ÐÑÑавлÑÐµÑ Ð½Ð¾Ð´Ñ Ð² ÑекÑÑее вÑделение + * + * @param Element n нода + * @return selection + **/ + this.insertNode = function(n, collapse) { + if (collapse && !this.collapsed()) { + this.collapse(); + } + + if (this.rte.browser.msie) { + var html = n.nodeType == 3 ? n.nodeValue : $(this.rte.dom.create('span')).append($(n)).html(); + var r = this.getRangeAt(); + r.insertNode(html); + } else { + var r = this.getRangeAt(); + r.insertNode(n); + r.setStartAfter(n); + r.setEndAfter(n); + var s = selection(); + s.removeAllRanges(); + s.addRange(r); + } + return this.cleanCache(); + } + + /** + * ÐÑÑавлÑÐµÑ html в ÑекÑÑее вÑделение + * + * @param Element n нода + * @return selection + **/ + this.insertHtml = function(html, collapse) { + if (collapse && !this.collapsed()) { + this.collapse(); + } + + if (this.rte.browser.msie) { + this.getRangeAt().range().pasteHTML(html); + } else { + var n = $(this.rte.dom.create('span')).html(html||'').get(0); + this.insertNode(n); + $(n).replaceWith($(n).html()); + } + return this.cleanCache(); + } + + /** + * ÐÑÑавлÑÐµÑ Ð½Ð¾Ð´Ñ Ð² ÑекÑÑее вÑделение + * + * @param Element n нода + * @return selection + **/ + this.insertText = function(text, collapse) { + var n = this.rte.doc.createTextNode(text); + return this.insertHtml(n.nodeValue); + } + + this.getBookmark = function() { + this.rte.window.focus(); + var r, r1, r2, _s, _e, + s = this.rte.dom.createBookmark(), + e = this.rte.dom.createBookmark(); + + + + if ($.browser.msie) { + try { + r = this.rte.window.document.selection.createRange(); + } catch(e) { + r = this.rte.doc.body.createTextRange(); + } + + if (r.item) { + var n = r.item(0); + r = this.rte.doc.body.createTextRange(); + r.moveToElementText(n); + } + + r1 = r.duplicate(); + r2 = r.duplicate(); + _s = this.rte.dom.create('span'); + _e = this.rte.dom.create('span'); + + _s.appendChild(s); + _e.appendChild(e); + + r1.collapse(true); + r1.pasteHTML(_s.innerHTML); + r2.collapse(false); + r2.pasteHTML(_e.innerHTML); + } else { + var sel = selection(); + var r = sel.rangeCount > 0 ? sel.getRangeAt(0) : this.rte.doc.createRange(); + + // r = this.getRangeAt(); + r1 = r.cloneRange(); + r2 = r.cloneRange(); + + // this.insertNode(this.rte.dom.create('hr')) + // return + r2.collapse(false); + r2.insertNode(e); + r1.collapse(true); + r1.insertNode(s); + this.select(s, e); + } + + return [s.id, e.id]; + } + + this.moveToBookmark = function(b) { + this.rte.window.focus(); + + if (b && b.length==2) { + var s = this.rte.doc.getElementById(b[0]), + e = this.rte.doc.getElementById(b[1]), + sel, r; + if (s && e) { + this.select(s, e); + if (this.rte.dom.next(s) == e) { + this.collapse(true); + } + if (!$.browser.msie) { + sel = selection(); + r = sel.rangeCount > 0 ? sel.getRangeAt(0) : this.rte.doc.createRange(); + sel.removeAllRanges(); + sel.addRange(r); + } + + s.parentNode.removeChild(s); + e.parentNode.removeChild(e); + } + } + return this; + } + + this.removeBookmark = function(b) { + this.rte.window.focus(); + if (b.length==2) { + var s = this.rte.doc.getElementById(b[0]), + e = this.rte.doc.getElementById(b[1]); + if (s && e) { + s.parentNode.removeChild(s); + e.parentNode.removeChild(e); + } + } + } + + /** + * ÐÑиÑÐ°ÐµÑ ÐºÑÑ + * + * @return selection + **/ + this.cleanCache = function() { + start = end = node = null; + return this; + } + + + /** + * ÐозвÑаÑÐ°ÐµÑ Ð½Ð¾Ð´Ñ Ð½Ð°Ñала вÑÐ´ÐµÐ»ÐµÐ½Ð¸Ñ + * + * @return DOMElement + **/ + this.getStart = function() { + if (!start) { + var r = this.getRangeAt(); + start = r.getStart(); + } + return start; + } + + /** + * ÐозвÑаÑÐ°ÐµÑ Ð½Ð¾Ð´Ñ ÐºÐ¾Ð½Ñа вÑÐ´ÐµÐ»ÐµÐ½Ð¸Ñ + * + * @return DOMElement + **/ + this.getEnd = function() { + if (!end) { + var r = this.getRangeAt(); + end = r.getEnd(); + } + return end; + } + + /** + * ÐозвÑаÑÐ°ÐµÑ Ð²ÑбÑанÑÑ Ð½Ð¾Ð´Ñ (обÑий конÑÐµÐ¹Ð½ÐµÑ Ð²ÑÐµÑ Ð²ÑбÑаннÑÑ Ð½Ð¾Ð´) + * + * @return Element + **/ + this.getNode = function() { + if (!node) { + node = this.rte.dom.findCommonAncestor(this.getStart(), this.getEnd()); + } + return node; + } + + + /** + * ÐозвÑаÑÐ°ÐµÑ Ð¼Ð°ÑÑив вÑбÑаннÑÑ Ð½Ð¾Ð´ + * + * @param Object o паÑамеÑÑÑ Ð¿Ð¾Ð»ÑÑÐµÐ½Ð¸Ñ Ð¸ обÑабоÑки вÑбÑанÑÑ Ð½Ð¾Ð´ + * @return Array + **/ + this.selected = function(o) { + var opts = { + collapsed : false, // веÑнÑÑÑ Ð²Ñделение, даже еÑли оно ÑÑ Ð»Ð¾Ð¿Ð½ÑÑо + blocks : false, // блоÑное вÑделение + filter : false, // ÑилÑÑÑ ÑезÑлÑÑаÑов + wrap : 'text', // ÑÑо обоÑаÑиваем + tag : 'span' // во ÑÑо обоÑаÑиваем + } + opts = $.extend({}, opts, o); + + // блоÑное вÑделение - иÑем блоÑнÑÑ Ð½Ð¾Ð´Ñ, но не ÑаблиÑÑ + if (opts.blocks) { + var n = this.getNode(), _n = null; + if (_n = this.rte.dom.selfOrParent(n, 'selectionBlock') ) { + return [_n]; + } + } + + var sel = this.selectedRaw(opts.collapsed, opts.blocks); + var ret = []; + var buffer = []; + var ndx = null; + + // обоÑаÑиваем Ð½Ð¾Ð´Ñ Ð² бÑÑÑеÑе + function wrap() { + + function allowParagraph() { + for (var i=0; i < buffer.length; i++) { + if (buffer[i].nodeType == 1 && (self.rte.dom.selfOrParent(buffer[i], /^P$/) || $(buffer[i]).find('p').length>0)) { + return false; + } + }; + return true; + } + + if (buffer.length>0) { + var tag = opts.tag == 'p' && !allowParagraph() ? 'div' : opts.tag; + var n = self.rte.dom.wrap(buffer, tag); + ret[ndx] = n; + ndx = null; + buffer = []; + } + } + + // добавлÑем Ð½Ð¾Ð´Ñ Ð² бÑÑÑÐµÑ + function addToBuffer(n) { + if (n.nodeType == 1) { + if (/^(THEAD|TFOOT|TBODY|COL|COLGROUP|TR)$/.test(n.nodeName)) { + $(n).find('td,th').each(function() { + var tag = opts.tag == 'p' && $(this).find('p').length>0 ? 'div' : opts.tag; + var n = self.rte.dom.wrapContents(this, tag); + return ret.push(n); + }) + } else if (/^(CAPTION|TD|TH|LI|DT|DD)$/.test(n.nodeName)) { + var tag = opts.tag == 'p' && $(n).find('p').length>0 ? 'div' : opts.tag; + var n = self.rte.dom.wrapContents(n, tag); + return ret.push(n); + } + } + var prev = buffer.length>0 ? buffer[buffer.length-1] : null; + if (prev && prev != self.rte.dom.prev(n)) { + wrap(); + } + buffer.push(n); + if (ndx === null) { + ndx = ret.length; + ret.push('dummy'); // заглÑÑка Ð´Ð»Ñ Ð¾Ð±Ð¾ÑаÑиваемÑÑ ÑлеменÑов + } + } + + if (sel.nodes.length>0) { + + for (var i=0; i < sel.nodes.length; i++) { + var n = sel.nodes[i]; + // пеÑвÑÑ Ð¸ поÑл ÑекÑÑовÑе Ð½Ð¾Ð´Ñ ÑазÑезаем, еÑли Ð½ÐµÐ¾Ð±Ñ Ð¾Ð´Ð¸Ð¼Ð¾ + if (n.nodeType == 3 && (i==0 || i == sel.nodes.length-1) && $.trim(n.nodeValue).length>0) { + if (i==0 && sel.so>0) { + n = n.splitText(sel.so); + } + if (i == sel.nodes.length-1 && sel.eo>0) { + n.splitText(i==0 && sel.so>0 ? sel.eo - sel.so : sel.eo); + } + } + + switch (opts.wrap) { + // обоÑаÑиваем ÑолÑко ÑекÑÑовÑе Ð½Ð¾Ð´Ñ Ñ br + case 'text': + if ((n.nodeType == 1 && n.nodeName == 'BR') || (n.nodeType == 3 && $.trim(n.nodeValue).length>0)) { + addToBuffer(n); + } else if (n.nodeType == 1) { + ret.push(n); + } + break; + // обоÑаÑиваем вÑе инлайн ÑлеменÑÑ + case 'inline': + if (this.rte.dom.isInline(n)) { + addToBuffer(n); + } else if (n.nodeType == 1) { + + ret.push(n); + } + break; + // обоÑаÑиваем вÑе + case 'all': + if (n.nodeType == 1 || !this.rte.dom.isEmpty(n)) { + addToBuffer(n); + } + break; + // ниÑего не обоÑаÑиваем + default: + if (n.nodeType == 1 || !this.rte.dom.isEmpty(n)) { + ret.push(n); + } + } + }; + wrap(); + } + + if (ret.length) { + this.rte.window.focus(); + + this.select(ret[0], ret[ret.length-1]); + } + return opts.filter ? this.rte.dom.filter(ret, opts.filter) : ret; + } + + this.dump = function(ca, s, e, so, eo) { + var r = this.getRangeAt(); + this.rte.log('commonAncestorContainer'); + this.rte.log(ca || r.commonAncestorContainer); + // this.rte.log('commonAncestorContainer childs num') + // this/rte.log((ca||r.commonAncestorContainer).childNodes.length) + this.rte.log('startContainer'); + this.rte.log(s || r.startContainer); + this.rte.log('startOffset: '+(so>=0 ? so : r.startOffset)); + this.rte.log('endContainer'); + this.rte.log(e||r.endContainer); + this.rte.log('endOffset: '+(eo>=0 ? eo : r.endOffset)); + } + + /** + * ÐозвÑаÑÐ°ÐµÑ Ð¼Ð°ÑÑив вÑбÑаннÑÑ Ð½Ð¾Ð´, как еÑÑÑ + * + * @param bool возвÑаÑаÑÑ ÐµÑли вÑделение ÑÑ Ð»Ð¾Ð¿Ð½ÑÑо + * @param bool "блоÑное" вÑделение (ÑекÑÑовÑе Ð½Ð¾Ð´Ñ Ð²ÐºÐ»ÑÑаÑÑÑÑ Ð¿Ð¾Ð»Ð½Ð¾ÑÑÑÑ, не завиÑимо Ð¾Ñ offset) + * @return Array + **/ + this.selectedRaw = function(collapsed, blocks) { + var res = {so : null, eo : null, nodes : []}; + var r = this.getRangeAt(true); + var ca = r.commonAncestorContainer; + var s, e; // start & end nodes + var sf = false; // start node fully selected + var ef = false; // end node fully selected + + // возвÑаÑÐ°ÐµÑ true, еÑли нода не ÑекÑÑÐ¾Ð²Ð°Ñ Ð¸Ð»Ð¸ вÑделена полноÑÑÑÑ + function isFullySelected(n, s, e) { + if (n.nodeType == 3) { + e = e>=0 ? e : n.nodeValue.length; + return (s==0 && e==n.nodeValue.length) || $.trim(n.nodeValue).length == $.trim(n.nodeValue.substring(s, e)).length; + } + return true; + } + + // возвÑаÑÐ°ÐµÑ true, еÑли нода пÑÑÑÐ°Ñ Ð¸Ð»Ð¸ в ней не вÑделено ни одного непÑобелÑного Ñимвола + function isEmptySelected(n, s, e) { + if (n.nodeType == 1) { + return self.rte.dom.isEmpty(n); + } else if (n.nodeType == 3) { + return $.trim(n.nodeValue.substring(s||0, e>=0 ? e : n.nodeValue.length)).length == 0; + } + return true; + } + + + //this.dump() + // наÑалÑÐ½Ð°Ñ Ð½Ð¾Ð´Ð° + if (r.startContainer.nodeType == 1) { + if (r.startOffset<r.startContainer.childNodes.length) { + s = r.startContainer.childNodes[r.startOffset]; + res.so = s.nodeType == 1 ? null : 0; + } else { + s = r.startContainer.childNodes[r.startOffset-1]; + res.so = s.nodeType == 1 ? null : s.nodeValue.length; + } + } else { + s = r.startContainer; + res.so = r.startOffset; + } + + // вÑделение ÑÑ Ð»Ð¾Ð¿Ð½ÑÑо + if (r.collapsed) { + if (collapsed) { + // блоÑное вÑделение + if (blocks) { + s = realSelected(s); + if (!this.rte.dom.isEmpty(s) || (s = this.rte.dom.next(s))) { + res.nodes = [s]; + } + + // добавлÑем инлайн ÑоÑедей + if (this.rte.dom.isInline(s)) { + res.nodes = this.rte.dom.toLineStart(s).concat(res.nodes, this.rte.dom.toLineEnd(s)); + } + + // offset Ð´Ð»Ñ ÑекÑÑовÑÑ Ð½Ð¾Ð´ + if (res.nodes.length>0) { + res.so = res.nodes[0].nodeType == 1 ? null : 0; + res.eo = res.nodes[res.nodes.length-1].nodeType == 1 ? null : res.nodes[res.nodes.length-1].nodeValue.length; + } + + } else if (!this.rte.dom.isEmpty(s)) { + res.nodes = [s]; + } + + } + return res; + } + + // конеÑÐ½Ð°Ñ Ð½Ð¾Ð´Ð° + if (r.endContainer.nodeType == 1) { + e = r.endContainer.childNodes[r.endOffset-1]; + res.eo = e.nodeType == 1 ? null : e.nodeValue.length; + } else { + e = r.endContainer; + res.eo = r.endOffset; + } + // this.rte.log('select 1') + //this.dump(ca, s, e, res.so, res.eo) + + // наÑалÑÐ½Ð°Ñ Ð½Ð¾Ð´Ð° вÑделена полноÑÑÑÑ - поднимаемÑÑ Ð½Ð°Ð²ÐµÑÑ Ð¿Ð¾ левой ÑÑоÑоне + if (s.nodeType == 1 || blocks || isFullySelected(s, res.so, s.nodeValue.length)) { +// this.rte.log('start text node is fully selected') + s = realSelected(s, ca, 'left'); + sf = true; + res.so = s.nodeType == 1 ? null : 0; + } + // конеÑÐ½Ð°Ñ Ð½Ð¾Ð´Ð° вÑделена полноÑÑÑÑ - поднимаемÑÑ Ð½Ð°Ð²ÐµÑÑ Ð¿Ð¾ пÑавой ÑÑоÑоне + if (e.nodeType == 1 || blocks || isFullySelected(e, 0, res.eo)) { +// this.rte.log('end text node is fully selected') + e = realSelected(e, ca, 'right'); + ef = true; + res.eo = e.nodeType == 1 ? null : e.nodeValue.length; + } + + // блоÑное вÑделение - еÑли Ð½Ð¾Ð´Ñ Ð½Ðµ ÑлеменÑÑ - поднимаемÑÑ Ðº ÑодиÑелÑ, но ниже конÑейнеÑа + if (blocks) { + if (s.nodeType != 1 && s.parentNode != ca && s.parentNode.nodeName != 'BODY') { + s = s.parentNode; + res.so = null; + } + if (e.nodeType != 1 && e.parentNode != ca && e.parentNode.nodeName != 'BODY') { + e = e.parentNode; + res.eo = null; + } + } + + // еÑли конÑÐµÐ½ÐµÑ Ð²Ñделен полноÑÑÑÑ, поднимаемÑÑ Ð½Ð°Ð²ÐµÑÑ Ð½Ð°ÑколÑко можно + if (s.parentNode == e.parentNode && s.parentNode.nodeName != 'BODY' && (sf && this.rte.dom.isFirstNotEmpty(s)) && (ef && this.rte.dom.isLastNotEmpty(e))) { +// this.rte.log('common parent') + s = e = s.parentNode; + res.so = s.nodeType == 1 ? null : 0; + res.eo = e.nodeType == 1 ? null : e.nodeValue.length; + } + // наÑалÑÐ½Ð°Ñ Ð½Ð¾Ð´Ð° == конеÑной ноде + if (s == e) { +// this.rte.log('start is end') + if (!this.rte.dom.isEmpty(s)) { + res.nodes.push(s); + } + return res; + } + // this.rte.log('start 2') + //this.dump(ca, s, e, res.so, res.eo) + + // Ð½Ð°Ñ Ð¾Ð´Ð¸Ð¼ наÑалÑнÑÑ Ð¸ конеÑнÑÑ ÑоÑки - Ð½Ð¾Ð´Ñ Ð¸Ð· иеÑаÑÑ Ð¸Ð¸ ÑодиÑелей наÑалÑной и конеÑно нодÑ, Ñ ÐºÐ¾ÑоÑÑÑ ÑодиÑÐµÐ»Ñ - конÑÐµÐ¹Ð½ÐµÑ + var sp = s; + while (sp.nodeName != 'BODY' && sp.parentNode !== ca && sp.parentNode.nodeName != 'BODY') { + sp = sp.parentNode; + } + //this.rte.log(s.nodeName) + // this.rte.log('start point') + // this.rte.log(sp) + + var ep = e; +// this.rte.log(ep) + while (ep.nodeName != 'BODY' && ep.parentNode !== ca && ep.parentNode.nodeName != 'BODY') { + // this.rte.log(ep) + ep = ep.parentNode; + } + // this.rte.log('end point') + // this.rte.log(ep) + + + // еÑли наÑалÑÐ½Ð°Ñ Ð½Ð¾Ð´Ð° не пÑÑÑÐ°Ñ - добавлÑем ее + if (!isEmptySelected(s, res.so, s.nodeType==3 ? s.nodeValue.length : null)) { + res.nodes.push(s); + } + // поднимаемÑÑ Ð¾Ñ Ð½Ð°ÑалÑной Ð½Ð¾Ð´Ñ Ð´Ð¾ наÑалÑной ÑоÑки + var n = s; + while (n !== sp) { + var _n = n; + while ((_n = this.rte.dom.next(_n))) { + res.nodes.push(_n); + } + n = n.parentNode; + } + // Ð¾Ñ Ð½Ð°ÑалÑной ÑоÑки до конеÑной ÑоÑки + n = sp; + while ((n = this.rte.dom.next(n)) && n!= ep ) { +// this.rte.log(n) + res.nodes.push(n); + } + // поднимаемÑÑ Ð¾Ñ ÐºÐ¾Ð½ÐµÑной Ð½Ð¾Ð´Ñ Ð´Ð¾ конеÑной ÑоÑки, ÑезÑлÑÑÐ°Ñ Ð¿ÐµÑевоÑаÑиваем + var tmp = []; + n = e; + while (n !== ep) { + var _n = n; + while ((_n = this.rte.dom.prev(_n))) { + tmp.push(_n); + } + n = n.parentNode; + } + if (tmp.length) { + res.nodes = res.nodes.concat(tmp.reverse()); + } + // еÑли конеÑÐ½Ð°Ñ Ð½Ð¾Ð´Ð° не пÑÑÑÐ°Ñ Ð¸ != наÑалÑной - добавлÑем ее + if (!isEmptySelected(e, 0, e.nodeType==3 ? res.eo : null)) { + res.nodes.push(e); + } + + if (blocks) { + // добавлÑем инлайн ÑоÑедей Ñлева + if (this.rte.dom.isInline(s)) { + res.nodes = this.rte.dom.toLineStart(s).concat(res.nodes); + res.so = res.nodes[0].nodeType == 1 ? null : 0; + } + // добавлÑем инлайн ÑоÑедей ÑпÑава + if (this.rte.dom.isInline(e)) { + res.nodes = res.nodes.concat(this.rte.dom.toLineEnd(e)); + res.eo = res.nodes[res.nodes.length-1].nodeType == 1 ? null : res.nodes[res.nodes.length-1].nodeValue.length; + } + } + + // вÑе ÑадÑÑÑÑÑ! :) + return res; + } + +} + +})(jQuery); \ No newline at end of file Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.selection.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.selection.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.selection.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.ui.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.ui.js?rev=1178141&view=auto ============================================================================== --- ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.ui.js (added) +++ ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.ui.js Sun Oct 2 08:06:49 2011 @@ -0,0 +1,190 @@ +/** + * @class elRTE User interface controller + * + * @param elRTE rte обÑекÑ-ÑедакÑÐ¾Ñ + * + * @author: Dmitry Levashov (dio) [hidden email] + * @todo: this.domElem.removeClass('disabled') - move to ui.update; + * @todo: add dom and selection as button members + * Copyright: Studio 42, http://www.std42.ru + **/ +(function($) { +elRTE.prototype.ui = function(rte) { + this.rte = rte; + this._buttons = []; + var self = this, + tb = this.rte.options.toolbars[rte.options.toolbar && rte.options.toolbars[rte.options.toolbar] ? rte.options.toolbar : 'normal'], + tbl = tb.length, + p, pname, pl, n, c, b, i; + + // add prototype to all buttons + for (i in this.buttons) { + if (this.buttons.hasOwnProperty(i) && i != 'button') { + this.buttons[i].prototype = this.buttons.button.prototype; + } + } + + // create buttons and put on toolbar + while (tbl--) { + first = (tbl == 0 ? true : false); + if (tb[tbl - 1] == 'eol') { first = true; } + + pname = tb[tbl]; + + // special 'end of line' panel, starts next panel on a new line + if (pname == 'eol') { + $(this.rte.doc.createElement('br')).prependTo(this.rte.toolbar); + continue; + } + + p = $('<ul class="panel-'+pname+(first ? ' first' : '')+'" />').prependTo(this.rte.toolbar); + p.bind('mousedown', function(e) { + e.preventDefault(); + }) + pl = this.rte.options.panels[pname].length; + while (pl--) { + n = this.rte.options.panels[pname][pl]; + c = this.buttons[n] || this.buttons.button; + this._buttons.push((b = new c(this.rte, n))); + p.prepend(b.domElem); + } + } + + this.update(); + + this.disable = function() { + $.each(self._buttons, function() { + !this.active && this.domElem.addClass('disabled'); + }); + } + +} + +/** + * ÐбновлÑÐµÑ ÐºÐ½Ð¾Ð¿ÐºÐ¸ - вÑзÑÐ²Ð°ÐµÑ Ð¼ÐµÑод update() Ð´Ð»Ñ ÐºÐ°Ð¶Ð´Ð¾Ð¹ кнопки + * + * @return void + **/ +elRTE.prototype.ui.prototype.update = function(cleanCache) { + cleanCache && this.rte.selection.cleanCache(); + var n = this.rte.selection.getNode(), + p = this.rte.dom.parents(n, '*'), + rtl = this.rte.rtl, + sep = rtl ? ' « ' : ' » ', + path = '', name, i; + + function _name(n) { + var name = n.nodeName.toLowerCase(); + n = $(n) + if (name == 'img') { + if (n.hasClass('elrte-media')) { + name = 'media'; + } else if (n.hasClass('elrte-google-maps')) { + name = 'google map'; + } else if (n.hasClass('elrte-yandex-maps')) { + name = 'yandex map'; + } else if (n.hasClass('elrte-pagebreak')) { + name = 'pagebreak'; + } + } + return name; + } + + if (n && n.nodeType == 1 && n.nodeName != 'BODY') { + p.unshift(n); + } + + if (!rtl) { + p = p.reverse(); + } + + for (i=0; i < p.length; i++) { + path += (i>0 ? sep : '')+_name(p[i]); + } + + this.rte.statusbar.html(path); + $.each(this._buttons, function() { + this.update(); + }); + this.rte.window.focus(); +} + + + +elRTE.prototype.ui.prototype.buttons = { + + /** + * @class кнопка на toolbar ÑедакÑоÑа + * ÑеализÑÐµÑ Ð¿Ð¾Ð²ÐµÐ´ÐµÐ½Ð¸Ðµ по ÑмолÑÐ°Ð½Ð¸Ñ Ð¸ ÑвлÑеÑÑÑ ÑодиÑелем Ð´Ð»Ñ Ð´ÑÑÐ³Ð¸Ñ ÐºÐ½Ð¾Ð¿Ð¾Ðº + * + * @param elRTE rte обÑекÑ-ÑедакÑÐ¾Ñ + * @param String name название кнопки (команда иÑполнÑÐµÐ¼Ð°Ñ document.execCommand()) + **/ + button : function(rte, name) { + var self = this; + this.rte = rte; + this.active = false; + this.name = name; + this.val = null; + this.domElem = $('<li style="-moz-user-select:-moz-none" class="'+name+' rounded-3" name="'+name+'" title="'+this.rte.i18n(this.rte.options.buttons[name] || name)+'" unselectable="on" />') + .hover( + function() { $(this).addClass('hover'); }, + function() { $(this).removeClass('hover'); } + ) + .click( function(e) { + e.stopPropagation(); + e.preventDefault(); + if (!$(this).hasClass('disabled')) { + // try{ + self.command(); + // } catch(e) { + // self.rte.log(e) + // } + + } + self.rte.window.focus(); + }); + } +} + +/** + * ÐбÑабоÑÑик нажаÑÐ¸Ñ Ð½Ð° ÐºÐ½Ð¾Ð¿ÐºÑ Ð½Ð° ÑÑлбаÑе. ÐÑполнение ÐºÐ¾Ð¼Ð°Ð½Ð´Ñ Ð¸Ð»Ð¸ оÑкÑÑÑие окна|Ð¼ÐµÐ½Ñ Ð¸ Ñд + * + * @return void + **/ +elRTE.prototype.ui.prototype.buttons.button.prototype.command = function() { + this.rte.history.add(); + try { + this.rte.doc.execCommand(this.name, false, this.val); + } catch(e) { + return this.rte.log('commands failed: '+this.name); + } + + this.rte.ui.update(true); +} + +/** + * ÐбновлÑÐµÑ ÑоÑÑоÑние кнопки + * + * @return void + **/ +elRTE.prototype.ui.prototype.buttons.button.prototype.update = function() { + try { + if (!this.rte.doc.queryCommandEnabled(this.name)) { + return this.domElem.addClass('disabled'); + } else { + this.domElem.removeClass('disabled'); + } + } catch (e) { + return; + } + try { + if (this.rte.doc.queryCommandState(this.name)) { + this.domElem.addClass('active'); + } else { + this.domElem.removeClass('active'); + } + } catch (e) { } +} + +})(jQuery); Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.ui.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.ui.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.ui.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.utils.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.utils.js?rev=1178141&view=auto ============================================================================== --- ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.utils.js (added) +++ ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.utils.js Sun Oct 2 08:06:49 2011 @@ -0,0 +1,396 @@ +/* + * Misc utils for elRTE + * + * @param Object rte - editor + * @todo ÐодÑмаÑÑ, ÑÑо из ÑÑого ÑеалÑно нÑжно и навеÑÑи поÑÑдок. Ðозможно ÑаÑÑÑ Ð¿ÐµÑенеÑÑи в ellib + * + * @author: Dmitry Levashov (dio) [hidden email] + * Copyright: Studio 42, http://www.std42.ru + */ +(function($) { +elRTE.prototype.utils = function(rte) { + this.rte = rte; + this.url = null; + // domo arigato, Steave, http://blog.stevenlevithan.com/archives/parseuri + this.reg = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/; + this.baseURL = ''; + this.path = ''; + /** + * entities map + **/ + this.entities = {'&' : '&', '"' : '"', '<' : '<', '>' : '>'}; + /** + * entities regexp + **/ + this.entitiesRegExp = /[<>&\"]/g; + /** + * media info + **/ + this.media = [{ + type : 'application/x-shockwave-flash', + classid : ['clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'], + codebase : 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' + }, { + type : 'application/x-director', + classid : ['clsid:166b1bca-3f9c-11cf-8075-444553540000'], + codebase : 'http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=8,5,1,0' + }, { + type : 'application/x-mplayer2', + classid : ['clsid:6bf52a52-394a-11d3-b153-00c04f79faa6', 'clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95', 'clsid:05589fa1-c356-11ce-bf01-00aa0055595a'], + codebase : 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701' + }, { + type : 'video/quicktime', + classid : ['clsid:02bf25d5-8c17-4b23-bc80-d3488abddc6b'], + codebase : 'http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0' + }, { + type : 'audio/x-pn-realaudio-plugin', + classid : ['clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa'], + codebase : 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0' + }]; + + // rgb color regexp + this.rgbRegExp = /\s*rgb\s*?\(\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?,\s*?([0-9]+)\s*?\)\s*/i; + // regexp to detect color in border/background properties + this.colorsRegExp = /aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|rgb\s*\([^\)]+\)/i; + // web safe colors + this.colors = { + aqua : '#00ffff', + black : '#000000', + blue : '#0000ff', + fuchsia : '#ff00ff', + gray : '#808080', + green : '#008000', + lime : '#00ff00', + maroon : '#800000', + navy : '#000080', + olive : '#808000', + orange : '#ffa500', + purple : '#800080', + red : '#ff0000', + silver : '#c0c0c0', + teal : '#008080', + white : '#fffffff', + yellow : '#ffff00' + } + + var self = this; + + this.rgb2hex = function(str) { + return this.color2Hex(''+str) + } + + this.toPixels = function(num) { + var m = num.match(/([0-9]+\.?[0-9]*)\s*(px|pt|em|%)/); + if (m) { + num = m[1]; + unit = m[2]; + } + if (num[0] == '.') { + num = '0'+num; + } + num = parseFloat(num); + + if (isNaN(num)) { + return ''; + } + var base = parseInt($(document.body).css('font-size')) || 16; + switch (unit) { + case 'em': return parseInt(num*base); + case 'pt': return parseInt(num*base/12); + case '%' : return parseInt(num*base/100); + } + return num; + } + + // TODO: add parse rel path ../../etc + this.absoluteURL = function(url) { + !this.url && this._url(); + url = $.trim(url); + if (!url) { + return ''; + } + // ÑÑÑлки на ÑкоÑÑ Ð½Ðµ пеÑеводим в Ð°Ð±Ñ + if (url[0] == '#') { + return url; + } + var u = this.parseURL(url); + + if (!u.host && !u.path && !u.anchor) { + //this.rte.log('Invalid URL: '+url) + return ''; + } + if (!this.rte.options.absoluteURLs) { + return url; + } + if (u.protocol) { + //this.rte.log('url already absolute: '+url); + return url; + } + if (u.host && (u.host.indexOf('.')!=-1 || u.host == 'localhost')) { + //this.rte.log('no protocol'); + return this.url.protocol+'://'+url; + } + if (url[0] == '/') { + url = this.baseURL+url; + } else { + if (url.indexOf('./') == 0) { + url = url.substring(2); + } + url = this.baseURL+this.path+url; + } + return url; + } + + this.parseURL = function(url) { + var u = url.match(this.reg); + var ret = {}; + $.each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(i) { + ret[this] = u[i]; + }); + if (!ret.host.match(/[a-z0-9]/i)) { + ret.host = ''; + } + return ret; + } + + this.trimEventCallback = function(c) { + c = c ? c.toString() : ''; + return $.trim(c.replace(/\r*\n/mg, '').replace(/^function\s*on[a-z]+\s*\(\s*event\s*\)\s*\{(.+)\}$/igm, '$1')); + } + + this._url = function() { + this.url = this.parseURL(window.location.href); + this.baseURL = this.url.protocol+'://'+(this.url.userInfo ? parts.userInfo+'@' : '')+this.url.host+(this.url.port ? ':'+this.url.port : ''); + this.path = !this.url.file ? this.url.path : this.url.path.substring(0, this.url.path.length - this.url.file.length); + } + + + /** + * Create object (map) from array + * + * @param Array + * @return Object + **/ + this.makeObject = function(o) { + var m = {}; + $.each(o, function(i, e) { + m[e] = e; + }); + return m; + } + + /** + * Encode entities in string + * + * @param String + * @return String + **/ + this.encode = function(s) { + var e = this.entities; + return (''+s).replace(this.entitiesRegExp, function(c) { + return e[c]; + }); + } + + /** + * Decode entities in string + * + * @param String + * @return String + **/ + this.decode = function(s) { + return $('<div/>').html(s||'').text(); + } + + /** + * Parse style string into object + * + * @param String + * @return Object + **/ + this.parseStyle = function(s) { + var st = {}, a = this.rte.options.allowBrowsersSpecStyles, t, n, v, p; + + if (typeof(s) == 'string' && s.length) { + + $.each(s.replace(/"/gi, "'").split(';'), function(i, str) { + if ((p = str.indexOf(':')) !== -1) { + n = $.trim(str.substr(0, p)); + v = $.trim(str.substr(p+1)) + if (n == 'color' || n == 'background-color') { + v = v.toLowerCase(); + } + if (n && v && (a || n.substring(0, 1) != '-')) { + st[n] = v; + } + } + }); + } + return st; + } + + + /** + * Compact some style properties and convert colors in hex + * + * @param Object + * @return Object + **/ + this.compactStyle = function(s) { + var self = this; + + if (s.border == 'medium none') { + delete s.border; + } + + $.each(s, function(n, v) { + if (/color$/i.test(n)) { + s[n] = self.color2Hex(v); + } else if (/^(border|background)$/i.test(n)) { + s[n] = v.replace(self.colorsRegExp, function(m) { + return self.color2Hex(m); + }); + } + }); + + if (s['border-width']) { + s.border = s['border-width']+' '+(s['border-style']||'solid')+' '+(s['border-color']||'#000'); + delete s['border-width']; + delete s['border-style']; + delete s['border-color']; + } + + if (s['background-image']) { + s.background = (s['background-color']+' ')||''+s['background-image']+' '+s['background-position']||'0 0'+' '+s['background-repeat']||'repeat'; + delete s['background-image']; + delete['background-image']; + delete['background-position']; + delete['background-repeat']; + } + + if (s['margin-top'] && s['margin-right'] && s['margin-bottom'] && s['margin-left']) { + s.margin = s['margin-top']+' '+s['margin-right']+' '+s['margin-bottom']+' '+s['margin-left']; + delete s['margin-top']; + delete s['margin-right']; + delete s['margin-bottom']; + delete s['margin-left']; + } + + if (s['padding-top'] && s['padding-right'] && s['padding-bottom'] && s['padding-left']) { + s.padding = s['padding-top']+' '+s['padding-right']+' '+s['padding-bottom']+' '+s['padding-left']; + delete s['padding-top']; + delete s['padding-right']; + delete s['padding-bottom']; + delete s['padding-left']; + } + + if (s['list-style-type'] || s['list-style-position'] || s['list-style-image']) { + s['list-style'] = $.trim(s['list-style-type']||' '+s['list-style-position']||''+s['list-style-image']||''); + delete s['list-style-type']; + delete s['list-style-position']; + delete s['list-style-image']; + } + + return s; + } + + /** + * Serialize style object into string + * + * @param Object style map + * @param Boolean flag - compact style? + * @return String + **/ + this.serializeStyle = function(o, c) { + var s = []; + // c=true + $.each(c ? this.compactStyle(o) : o, function(n, v) { + v && s.push(n+':'+v); + }); + return s.join(';'); + } + + /** + * Parse class string into object + * + * @param String + * @return Object + **/ + this.parseClass = function(c) { + c = $.trim(c); + // this.rte.log(c) + return c.length ? this.makeObject(c.split(/\s+/)) : {}; + return c.length ? c.split(/\s+/) : []; + } + + /** + * Serialize class object into string + * + * @param Object + * @return String + **/ + this.serializeClass = function(c) { + // return c.join(' ') + var s = []; + // this.rte.log(c) + var rte = this.rte + $.each(c, function(n) { + s.push(n); + // rte.log(typeof(n)) + }); + return s.join(' '); + } + + /** + * Return required media type info + * + * @param String mimetype + * @param String classid + * @return Object + **/ + this.mediaInfo = function(t, c) { + var l = this.media.length; + + while (l--) { + if (t === this.media[l].type || (c && $.inArray(c, this.media[l].classid) != -1)) { + return this.media[l]; + } + } + } + + /** + * Return color hex value + * + * @param String color name or rgb + * @return String + **/ + this.color2Hex = function(c) { + var m; + + c = c||''; + + if (c.indexOf('#') === 0) { + return c; + } + + + function hex(s) { + s = parseInt(s).toString(16); + return s.length > 1 ? s : '0' + s; + }; + + if (this.colors[c]) { + return this.colors[c]; + } + if ((m = c.match(this.rgbRegExp))) { + return '#'+hex(m[1])+hex(m[2])+hex(m[3]); + } + return ''; + } + + + + +} + +})(jQuery); \ No newline at end of file Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.utils.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.utils.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.utils.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.w3cRange.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.w3cRange.js?rev=1178141&view=auto ============================================================================== --- ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.w3cRange.js (added) +++ ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.w3cRange.js Sun Oct 2 08:06:49 2011 @@ -0,0 +1,330 @@ +/** + * @class w3cRange - w3c text range emulation for "strange" browsers + * + * @param elRTE rte обÑекÑ-ÑедакÑÐ¾Ñ + * + * @author: Dmitry Levashov (dio) [hidden email] + * Copyright: Studio 42, http://www.std42.ru + **/ +(function($) { +elRTE.prototype.w3cRange = function(rte) { + var self = this; + this.rte = rte; + this.r = null; + this.collapsed = true; + this.startContainer = null; + this.endContainer = null; + this.startOffset = 0; + this.endOffset = 0; + this.commonAncestorContainer = null; + + this.range = function() { + try { + this.r = this.rte.window.document.selection.createRange(); + } catch(e) { + this.r = this.rte.doc.body.createTextRange(); + } + return this.r; + } + + this.insertNode = function(html) { + this.range(); + self.r.collapse(false) + var r = self.r.duplicate(); + r.pasteHTML(html); + } + + this.getBookmark = function() { + this.range(); + if (this.r.item) { + var n = this.r.item(0); + this.r = this.rte.doc.body.createTextRange(); + this.r.moveToElementText(n); + } + return this.r.getBookmark(); + } + + this.moveToBookmark = function(bm) { + this.rte.window.focus(); + this.range().moveToBookmark(bm); + this.r.select(); + } + + /** + * ÐбновлÑÐµÑ Ð´Ð°Ð½Ð½Ñе о вÑделеннÑÑ Ð½Ð¾Ð´Ð°Ñ + * + * @return void + **/ + this.update = function() { + + function _findPos(start) { + var marker = '\uFEFF'; + var ndx = offset = 0; + var r = self.r.duplicate(); + r.collapse(start); + var p = r.parentElement(); + if (!p || p.nodeName == 'HTML') { + return {parent : self.rte.doc.body, ndx : ndx, offset : offset}; + } + + r.pasteHTML(marker); + + childs = p.childNodes; + for (var i=0; i < childs.length; i++) { + var n = childs[i]; + if (i>0 && (n.nodeType!==3 || childs[i-1].nodeType !==3)) { + ndx++; + } + if (n.nodeType !== 3) { + offset = 0; + } else { + var pos = n.nodeValue.indexOf(marker); + if (pos !== -1) { + offset += pos; + break; + } + offset += n.nodeValue.length; + } + }; + r.moveStart('character', -1); + r.text = ''; + return {parent : p, ndx : Math.min(ndx, p.childNodes.length-1), offset : offset}; + } + + this.range(); + this.startContainer = this.endContainer = null; + + if (this.r.item) { + this.collapsed = false; + var i = this.r.item(0); + this.setStart(i.parentNode, this.rte.dom.indexOf(i)); + this.setEnd(i.parentNode, this.startOffset+1); + } else { + this.collapsed = this.r.boundingWidth == 0; + var start = _findPos(true); + var end = _findPos(false); + + start.parent.normalize(); + end.parent.normalize(); + start.ndx = Math.min(start.ndx, start.parent.childNodes.length-1); + end.ndx = Math.min(end.ndx, end.parent.childNodes.length-1); + if (start.parent.childNodes[start.ndx].nodeType && start.parent.childNodes[start.ndx].nodeType == 1) { + this.setStart(start.parent, start.ndx); + } else { + this.setStart(start.parent.childNodes[start.ndx], start.offset); + } + if (end.parent.childNodes[end.ndx].nodeType && end.parent.childNodes[end.ndx].nodeType == 1) { + this.setEnd(end.parent, end.ndx); + } else { + this.setEnd(end.parent.childNodes[end.ndx], end.offset); + } + // this.dump(); + this.select(); + } + return this; + } + + this.isCollapsed = function() { + this.range(); + this.collapsed = this.r.item ? false : this.r.boundingWidth == 0; + return this.collapsed; + } + + /** + * "Ð¡Ñ Ð»Ð¾Ð¿ÑваеÑ" вÑделение + * + * @param bool toStart - ÑÑ Ð»Ð¾Ð¿ÑваÑÑ Ð²Ñделение к наÑÐ°Ð»Ñ Ð¸Ð»Ð¸ к конÑÑ + * @return void + **/ + this.collapse = function(toStart) { + this.range(); + if (this.r.item) { + var n = this.r.item(0); + this.r = this.rte.doc.body.createTextRange(); + this.r.moveToElementText(n); + } + this.r.collapse(toStart); + this.r.select(); + this.collapsed = true; + } + + this.getStart = function() { + this.range(); + if (this.r.item) { + return this.r.item(0); + } + var r = this.r.duplicate(); + r.collapse(true); + var s = r.parentElement(); + return s && s.nodeName == 'BODY' ? s.firstChild : s; + } + + + this.getEnd = function() { + this.range(); + if (this.r.item) { + return this.r.item(0); + } + var r = this.r.duplicate(); + r.collapse(false); + var e = r.parentElement(); + return e && e.nodeName == 'BODY' ? e.lastChild : e; + } + + + /** + * УÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ð½Ð°Ñaло вÑÐ´ÐµÐ»ÐµÐ½Ð¸Ñ Ð½Ð° ÑказанÑÑ Ð½Ð¾Ð´Ñ + * + * @param Element node нода + * @param Number offset оÑÑÑÑп Ð¾Ñ Ð½Ð°Ñала Ð½Ð¾Ð´Ñ + * @return void + **/ + this.setStart = function(node, offset) { + this.startContainer = node; + this.startOffset = offset; + if (this.endContainer) { + this.commonAncestorContainer = this.rte.dom.findCommonAncestor(this.startContainer, this.endContainer); + } + } + + /** + * УÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ ÐºÐ¾Ð½ÐµÑ Ð²ÑÐ´ÐµÐ»ÐµÐ½Ð¸Ñ Ð½Ð° ÑказанÑÑ Ð½Ð¾Ð´Ñ + * + * @param Element node нода + * @param Number offset оÑÑÑÑп Ð¾Ñ ÐºÐ¾Ð½Ñа Ð½Ð¾Ð´Ñ + * @return void + **/ + this.setEnd = function(node, offset) { + this.endContainer = node; + this.endOffset = offset; + if (this.startContainer) { + this.commonAncestorContainer = this.rte.dom.findCommonAncestor(this.startContainer, this.endContainer); + } + } + + /** + * УÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ð½Ð°Ñaло вÑÐ´ÐµÐ»ÐµÐ½Ð¸Ñ Ð¿ÐµÑед Ñказаной нодой + * + * @param Element node нода + * @return void + **/ + this.setStartBefore = function(n) { + if (n.parentNode) { + this.setStart(n.parentNode, this.rte.dom.indexOf(n)); + } + } + + /** + * УÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ð½Ð°Ñaло вÑÐ´ÐµÐ»ÐµÐ½Ð¸Ñ Ð¿Ð¾Ñле Ñказаной Ð½Ð¾Ð´Ñ + * + * @param Element node нода + * @return void + **/ + this.setStartAfter = function(n) { + if (n.parentNode) { + this.setStart(n.parentNode, this.rte.dom.indexOf(n)+1); + } + } + + /** + * УÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ ÐºÐ¾Ð½ÐµÑ Ð²ÑÐ´ÐµÐ»ÐµÐ½Ð¸Ñ Ð¿ÐµÑед Ñказаной нодой + * + * @param Element node нода + * @return void + **/ + this.setEndBefore = function(n) { + if (n.parentNode) { + this.setEnd(n.parentNode, this.rte.dom.indexOf(n)); + } + } + + /** + * УÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ ÐºÐ¾Ð½ÐµÑ Ð²ÑÐ´ÐµÐ»ÐµÐ½Ð¸Ñ Ð¿Ð¾Ñле Ñказаной Ð½Ð¾Ð´Ñ + * + * @param Element node нода + * @return void + **/ + this.setEndAfter = function(n) { + if (n.parentNode) { + this.setEnd(n.parentNode, this.rte.dom.indexOf(n)+1); + } + } + + /** + * УÑÑÐ°Ð½Ð°Ð²Ð»Ð¸Ð²Ð°ÐµÑ Ð½Ð¾Ð²Ð¾Ðµ вÑделение поÑле изменений + * + * @return void + **/ + this.select = function() { + // thanks tinymice authors + function getPos(n, o) { + if (n.nodeType != 3) { + return -1; + } + var c ='\uFEFF'; + var val = n.nodeValue; + var r = self.rte.doc.body.createTextRange(); + n.nodeValue = val.substring(0, o) + c + val.substring(o); + r.moveToElementText(n.parentNode); + r.findText(c); + var p = Math.abs(r.moveStart('character', -0xFFFFF)); + n.nodeValue = val; + return p; + }; + + this.r = this.rte.doc.body.createTextRange(); + var so = this.startOffset; + var eo = this.endOffset; + var s = this.startContainer.nodeType == 1 + ? this.startContainer.childNodes[Math.min(so, this.startContainer.childNodes.length - 1)] + : this.startContainer; + var e = this.endContainer.nodeType == 1 + ? this.endContainer.childNodes[Math.min(so == eo ? eo : eo - 1, this.endContainer.childNodes.length - 1)] + : this.endContainer; + + if (this.collapsed) { + if (s.nodeType == 3) { + var p = getPos(s, so); + this.r.move('character', p); + } else { + this.r.moveToElementText(s); + this.r.collapse(true); + } + } else { + var r = this.rte.doc.body.createTextRange(); + var sp = getPos(s, so); + var ep = getPos(e, eo); + if (s.nodeType == 3) { + this.r.move('character', sp); + } else { + this.r.moveToElementText(s); + } + if (e.nodeType == 3) { + r.move('character', ep); + } else { + r.moveToElementText(e); + } + this.r.setEndPoint('EndToEnd', r); + } + + try { + this.r.select(); + } catch(e) { + + } + if (r) { + r = null; + } + } + + this.dump = function() { + this.rte.log('collapsed: '+this.collapsed); + //this.rte.log('commonAncestorContainer: '+this.commonAncestorContainer.nodeName||'#text') + this.rte.log('startContainer: '+(this.startContainer ? this.startContainer.nodeName : 'non')); + this.rte.log('startOffset: '+this.startOffset); + this.rte.log('endContainer: '+(this.endContainer ? this.endContainer.nodeName : 'none')); + this.rte.log('endOffset: '+this.endOffset); + } + +} +})(jQuery); Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.w3cRange.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.w3cRange.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/elRTE.w3cRange.js ------------------------------------------------------------------------------ svn:mime-type = text/plain Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/i18n/ ------------------------------------------------------------------------------ bugtraq:number = true Added: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/i18n/elrte.YOUR_LANG.js URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/i18n/elrte.YOUR_LANG.js?rev=1178141&view=auto ============================================================================== --- ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/i18n/elrte.YOUR_LANG.js (added) +++ ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/i18n/elrte.YOUR_LANG.js Sun Oct 2 08:06:49 2011 @@ -0,0 +1,216 @@ +/* + * WARNING! Use this file only if you want to make translation + * Please submit your translation to the project by creating new issue at: + * http://elrte.org/redmine/projects/elrte/issues/new + */ +/* + * YOUR_LANGUAGE_TRANSLATION translation + * @author NAME <EMAIL> + * @version 201x-xx-xx + */ +(function($) { +// LANG_CODE can be 2-letter "en", "fr" or 5-letter "pt_BR", "zh_CN" +elRTE.prototype.i18Messages.LANG_CODE = { + '_translator' : 'YOUR_NAME <YOUR_EMAIL>', + '_translation' : 'YOUR_TRANSLATION NAME', // will be seen in about dialog + 'Editor' : '', + 'Source' : '', + // panels names + 'Copy/Pase' : '', + 'Undo/Redo' : '', + 'Text styles' : '', + 'Colors' : '', + 'Alignment' : '', + 'Indent/Outdent' : '', + 'Text format' : '', + 'Lists' : '', + 'Misc elements' : '', + 'Links' : '', + 'Images' : '', + 'Media' : '', + 'Tables' : '', + 'File manager (elFinder)' : '', + // buttons names + 'About this software' : '', + 'Save' : '', + 'Copy' : '', + 'Cut' : '', + 'Paste' : '', + 'Paste only text' : '', + 'Paste formatted text' : '', + 'Clean format' : '', + 'Undo last action' : '', + 'Redo previous action' : '', + 'Bold' : '', + 'Italic' : '', + 'Underline' : '', + 'Strikethrough' : '', + 'Superscript' : '', + 'Subscript' : '', + 'Align left' : '', + 'Ailgn right' : '', + 'Align center' : '', + 'Align full' : '', + 'Font color' : '', + 'Background color' : '', + 'Indent' : '', + 'Outdent' : '', + 'Format' : '', + 'Font size' : '', + 'Font' : '', + 'Ordered list' : '', + 'Unordered list' : '', + 'Horizontal rule' : '', + 'Blockquote' : '', + 'Block element (DIV)' : '', + 'Link' : '', + 'Delete link' : '', + 'Bookmark' : '', + 'Image' : '', + 'Table' : '', + 'Delete table' : '', + 'Insert row before' : '', + 'Insert row after' : '', + 'Delete row' : '', + 'Insert column before' : '', + 'Insert column after' : '', + 'Delete column' : '', + 'Merge table cells' : '', + 'Split table cell' : '', + 'Toggle display document structure' : '', + 'Table cell properties' : '', + 'Table properties' : '', + 'Toggle full screen mode' : '', + 'Open file manager' : '', + 'Non breakable space' : '', + 'Stop element floating' : '', + // dialogs + 'Warning' : '', + 'Properies' : '', + 'Popup' : '', + 'Advanced' : '', + 'Events' : '', + 'Width' : '', + 'Height' : '', + 'Left' : '', + 'Center' : '', + 'Right' : '', + 'Border' : '', + 'Background' : '', + 'Css class' : '', + 'Css style' : '', + 'No' : '', + 'Title' : '', + 'Script direction' : '', + 'Language' : '', + 'Charset' : '', + 'Not set' : '', + 'Left to right' : '', + 'Right to left' : '', + 'In this window' : '', + 'In new window (_blank)' : '', + 'In new parent window (_parent)' : '', + 'In top frame (_top)' : '', + 'URL' : '', + 'Open in' : '', + 'Open file manger' : '', + // copy + 'This operation is disabled in your browser on security reason. Use shortcut instead.' : '', + // format + 'Heading 1' : '', + 'Heading 2' : '', + 'Heading 3' : '', + 'Heading 4' : '', + 'Heading 5' : '', + 'Heading 6' : '', + 'Paragraph' : '', + 'Address' : '', + 'Preformatted' : '', + // font size + 'Small (8pt)' : '', + 'Small (10px)' : '', + 'Small (12pt)' : '', + 'Normal (14pt)' : '', + 'Large (18pt)' : '', + 'Large (24pt)' : '', + 'Large (36pt)' : '', + // bookmark + 'Bookmark name' : '', + // link + 'Link URL' : '', + 'Target' : '', + 'Select bookmark' : '', + 'Open link in popup window' : '', + 'Window name' : '', + 'Window size' : '', + 'Window position' : '', + 'Location bar' : '', + 'Menu bar' : '', + 'Toolbar' : '', + 'Scrollbars' : '', + 'Status bar' : '', + 'Resizable' : '', + 'Depedent' : '', + 'Add return false' : '', + 'Target MIME type' : '', + 'Relationship page to target (rel)' : '', + 'Relationship target to page (rev)' : '', + 'Tab index' : '', + 'Access key' : '', + // image + 'Size' : '', + 'Preview' : '', + 'Margins' : '', + 'Alt text' : '', + 'Image URL' : '', + // table + 'Spacing' : '', + 'Padding' : '', + 'Rows' : '', + 'Columns' : '', + 'Groups' : '', + 'Cells' : '', + 'Caption' : '', + 'Inner borders' : '', + // table cell + 'Table cell type' : '', + 'Data' : '', + 'Header' : '', + 'Justify' : '', + 'Paddings' : '', + 'Apply to' : '', + 'Current cell' : '', + 'All cells in row' : '', + 'All cells in column' : '', + 'All cells in table' : '', + // about + 'About elRTE' : '', + 'Version' : '', + 'Licence' : '', + 'elRTE is an open-source JavaScript based WYSIWYG HTML-editor.' : '', + 'Main goal of the editor - simplify work with text and formating (HTML) on sites, blogs, forums and other online services.' : '', + 'You can use it in any commercial or non-commercial projects.' : '', + 'Authors' : '', + 'Chief developer' : '', + 'Developer, tech support' : '', + 'Developer' : '', + 'Interface designer' : '', + 'Spanish localization' : '', + 'Czech localization' : '', + 'Japanese localization' : '', + 'Latvian localization' : '', + 'German localization' : '', + 'Ukranian localization' : '', + 'Persian (farsi) localization' : '', + 'Arabic localization' : '', + 'RTL support' : '', + 'French localization' : '', + 'Dutch localization' : '', + 'Hungarian localization' : '', + 'Polish localization' : '', + 'Italian localization' : '', + 'Traditional Chinese localization' : '', + 'For more information about this software visit the' : '', + 'elRTE website' : 'на ÑайÑе elRTE' +} +})(jQuery); Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/i18n/elrte.YOUR_LANG.js ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/i18n/elrte.YOUR_LANG.js ------------------------------------------------------------------------------ svn:keywords = Date Rev Author URL Id Propchange: ofbiz/trunk/framework/images/webapp/images/jquery/plugins/elrte-1.3/src/elrte/js/i18n/elrte.YOUR_LANG.js ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |