diff --git a/app/assets/javascripts/app/lib/app_post/utils.js.coffee b/app/assets/javascripts/app/lib/app_post/utils.js.coffee index 945ece4dd..cbf3c12ca 100644 --- a/app/assets/javascripts/app/lib/app_post/utils.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/utils.js.coffee @@ -82,12 +82,12 @@ class App.Utils @htmlRemoveTags: (html) -> # remove tags, keep content - html.find('div, span, p, li, ul, ol, a, b, u, i, strong, blockquote, h1, h2, h3, h4, h5, h6').replaceWith( -> + html.find('div, span, p, li, ul, ol, a, b, u, i, form, strong, blockquote, textarea, h1, h2, h3, h4, h5, h6').replaceWith( -> $(@).contents() ) # remove tags & content - html.find('div, span, p, li, ul, ol, a, b, u, i, strong, blockquote, h1, h2, h3, h4, h5, h6, br, hr, img').remove() + html.find('div, span, p, li, ul, ol, a, b, u, i, form, strong, blockquote, textarea, h1, h2, h3, h4, h5, h6, br, hr, img, input').remove() html @@ -98,12 +98,12 @@ class App.Utils @_removeAttributes( html ) # remove tags, keep content - html.find('li, ul, ol, a, b, u, i, strong, blockquote, h1, h2, h3, h4, h5, h6').replaceWith( -> + html.find('li, ul, ol, a, b, u, i, strong, form, blockquote, textarea, h1, h2, h3, h4, h5, h6').replaceWith( -> $(@).contents() ) # remove tags & content - html.find('li, ul, ol, a, b, u, i, strong, blockquote, h1, h2, h3, h4, h5, h6, hr, img').remove() + html.find('li, ul, ol, a, b, u, i, strong, form, blockquote, textarea, h1, h2, h3, h4, h5, h6, hr, img, input').remove() html @@ -113,9 +113,6 @@ class App.Utils # remove style and class @_removeAttributes( html ) - # remove tags & content - html.find('hr, img').remove() - # remove tags, keep content html.find('a').replaceWith( -> $(@).contents() @@ -126,7 +123,7 @@ class App.Utils replacementTag = 'div'; # Replace all a tags with the type of replacementTag - html.find('h1, h2, h3, h4, h5, h6').each( -> + html.find('h1, h2, h3, h4, h5, h6, textarea').each( -> outer = this.outerHTML; # Replace opening tag @@ -139,6 +136,10 @@ class App.Utils $(@).replaceWith(newTag); ) + + # remove tags & content + html.find('hr, img, form, input').remove() + html @_removeAttributes: (html) -> diff --git a/app/assets/javascripts/app/lib/base/jquery.contenteditable.js b/app/assets/javascripts/app/lib/base/jquery.contenteditable.js index 8c9d89dc3..f47e1ac43 100644 --- a/app/assets/javascripts/app/lib/base/jquery.contenteditable.js +++ b/app/assets/javascripts/app/lib/base/jquery.contenteditable.js @@ -48,6 +48,7 @@ this._defaults = defaults; this._name = pluginName; + this._setTimeOutReformat = false; // take placeholder from markup if ( !this.options.placeholder && this.$element.data('placeholder') ) { @@ -92,11 +93,22 @@ }) this.$element.on('keyup', function (e) { - console.log('KU') + console.log('KU', e.ctrlKey) + // do not remove tags on space, enter or backspace key, it's needed for FF if ( _this.options.mode === 'textonly' ) { - console.log('REMOVE TAGS') if ( !_this.options.multiline ) { - App.Utils.htmlRemoveTags(_this.$element) + + // do tricky this for FF + if ( e.keyCode !== 32 && e.keyCode !== 13 && e.keyCode !== 8 ) { + + // start request to remove tags + _this.htmlRemoveTags() + } + else { + + // clear request to delete tags, in FF we need
anytime at the end + _this.htmlRemoveTagsClearClearTimeout() + } } else { App.Utils.htmlRemoveRichtext(_this.$element) @@ -112,9 +124,8 @@ this.$element.on('paste', function (e) { console.log('paste') if ( _this.options.mode === 'textonly' ) { - console.log('REMOVE TAGS') if ( !_this.options.multiline ) { - App.Utils.htmlRemoveTags(_this.$element) + _this.htmlRemoveTags() } else { App.Utils.htmlRemoveRichtext(_this.$element) @@ -175,8 +186,25 @@ } }) } + } + // check if rich text key is pressed + Plugin.prototype.htmlRemoveTags = function() { + // clear old clear request + this.htmlRemoveTagsClearClearTimeout() + + // set new clear request + this._setTimeOutReformat = setTimeout($.proxy(function(){ + App.Utils.htmlRemoveTags(this.$element) + }, this), 100) + console.log('htmlRemoveTagsClearSetTimeout', this._setTimeOutReformat) + } + Plugin.prototype.htmlRemoveTagsClearClearTimeout = function() { + if (this._setTimeOutReformat) { + console.log('htmlRemoveTagsClearClearTimeout', this._setTimeOutReformat) + clearTimeout(this._setTimeOutReformat) + } } // check if rich text key is pressed diff --git a/public/assets/tests/html-utils.js b/public/assets/tests/html-utils.js index 3e9a92f71..fe7884b58 100644 --- a/public/assets/tests/html-utils.js +++ b/public/assets/tests/html-utils.js @@ -165,7 +165,6 @@ test( "htmlRemoveTags", function() { var source = "
test
" var should = "test" var result = App.Utils.htmlRemoveTags( $(source) ) - console.log('RRRR', result); equal( result.html(), should, source ) source = "some link to somewhere" @@ -178,11 +177,26 @@ test( "htmlRemoveTags", function() { result = App.Utils.htmlRemoveTags( $(source) ) equal( result.html(), should, source ) + source = "
some link to somewhere
" + should = "some link to somewhere" + result = App.Utils.htmlRemoveTags( $(source) ) + equal( result.html(), should, source ) + source = "
some link to somewhere

123
" should = "some link to somewhere 123 " result = App.Utils.htmlRemoveTags( $(source) ) equal( result.html(), should, source ) + source = "
test 123
" + should = "test 123" + result = App.Utils.htmlRemoveRichtext( $(source) ) + equal( result.html(), should, source ) + + source = "
" + should = "test 123" + result = App.Utils.htmlRemoveRichtext( $(source) ) + equal( result.html(), should, source ) + }); // htmlRemoveRichtext @@ -213,6 +227,11 @@ test( "htmlRemoveRichtext", function() { result = App.Utils.htmlRemoveRichtext( $(source) ) equal( result.html(), should, source ) + source = "
test
" + should = "
test
" + result = App.Utils.htmlRemoveRichtext( $(source) ) + equal( result.html(), should, source ) + source = "
test
123
" should = "
test
123" result = App.Utils.htmlRemoveRichtext( $(source) ) @@ -223,9 +242,15 @@ test( "htmlRemoveRichtext", function() { result = App.Utils.htmlRemoveRichtext( $(source) ) equal( result.html(), should, source ) + source = "
" + //should = "
test
" + should = " test " + result = App.Utils.htmlRemoveRichtext( $(source) ) + equal( result.html(), should, source ) + source = "

" should = "
" - result = App.Utils.htmlClanup( $(source) ) + result = App.Utils.htmlRemoveRichtext( $(source) ) equal( result.html(), should, source ) source = "

" @@ -233,6 +258,12 @@ test( "htmlRemoveRichtext", function() { result = App.Utils.htmlRemoveRichtext( $(source) ) equal( result.html(), should, source ) + source = "
test 123
" + //should = "
test 123
" + should = "test 123" + result = App.Utils.htmlRemoveRichtext( $(source) ) + equal( result.html(), should, source ) + }); // htmlClanup @@ -268,6 +299,25 @@ test( "htmlClanup", function() { result = App.Utils.htmlRemoveRichtext( $(source) ) equal( result.html(), should, source ) + source = "
test 123
" + //should = "
test 123
" + should = "test 123" + result = App.Utils.htmlRemoveRichtext( $(source) ) + equal( result.html(), should, source ) + + source = "
test 123
some other value
" + //should = "
ttest 123 some other value
" + should = "test 123 some other value" + result = App.Utils.htmlRemoveRichtext( $(source) ) + equal( result.html(), should, source ) + + source = "
test 123
some other value
" + //should = "
test 123 some other value
" + should = "test 123 some other value" + result = App.Utils.htmlRemoveRichtext( $(source) ) + equal( result.html(), should, source ) + + }); // wrap diff --git a/test/browser/aac_basic_richtext_test.rb b/test/browser/aac_basic_richtext_test.rb new file mode 100644 index 000000000..b7683efd7 --- /dev/null +++ b/test/browser/aac_basic_richtext_test.rb @@ -0,0 +1,96 @@ +# encoding: utf-8 +require 'browser_test_helper' + +class AACBasicRichtextTest < TestCase + def test_preferences + tests = [ + { + :name => 'richtext single line', + :action => [ + { + :execute => 'click', + :css => 'a[href="#current_user"]', + }, + { + :execute => 'click', + :css => 'a[href="#layout_ref"]', + }, + { + :execute => 'click', + :css => 'a[href="#layout_ref/richtext"]', + }, + { + :execute => 'set', + :css => '#content .text-1', + :value => 'some test for browser ', + :slow => true, + }, + { + :execute => 'wait', + :value => 4, + }, + { + :execute => 'sendkey', + :value => :enter, + }, + { + :execute => 'wait', + :value => 1, + }, + { + :execute => 'sendkey', + :value => 'and some other for browser', + }, + { + :execute => 'wait', + :value => 2, + }, + { + :execute => 'match', + :css => '#content .text-1', + :value => 'some test for browser and some other for browser', + :match_result => true, + }, + ], + }, + { + :name => 'richtext multi line', + :action => [ + { + :execute => 'set', + :css => '#content .text-3', + :value => 'some test for browser ', + :slow => true, + }, + { + :execute => 'wait', + :value => 4, + }, + { + :execute => 'sendkey', + :value => :enter, + }, + { + :execute => 'wait', + :value => 1, + }, + { + :execute => 'sendkey', + :value => 'and some other for browser', + }, + { + :execute => 'wait', + :value => 2, + }, + { + :execute => 'match', + :css => '#content .text-3', + :value => "some test for browser\nand some other for browser", + :match_result => true, + }, + ], + }, + ] + browser_signle_test_with_login(tests, { :username => 'master@example.com' }) + end +end \ No newline at end of file