Improved richtext behaviours in FF.

This commit is contained in:
Martin Edenhofer 2015-01-07 15:30:13 +01:00
parent b864dd2c45
commit 80877854af
4 changed files with 190 additions and 15 deletions

View file

@ -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) ->

View file

@ -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 <br> 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

View file

@ -165,7 +165,6 @@ test( "htmlRemoveTags", function() {
var source = "<div>test</div>"
var should = "test"
var result = App.Utils.htmlRemoveTags( $(source) )
console.log('RRRR', result);
equal( result.html(), should, source )
source = "<a href=\"some_link\">some link to somewhere</a>"
@ -178,11 +177,26 @@ test( "htmlRemoveTags", function() {
result = App.Utils.htmlRemoveTags( $(source) )
equal( result.html(), should, source )
source = "<div><a href=\"some_link\">some link to somewhere</a><input value=\"should not be shown\"></div>"
should = "some link to somewhere"
result = App.Utils.htmlRemoveTags( $(source) )
equal( result.html(), should, source )
source = "<div><a href=\"some_link\">some link to somewhere</a> <div><hr></div> <span>123</span> <img src=\"some_image\"/></div>"
should = "some link to somewhere 123 "
result = App.Utils.htmlRemoveTags( $(source) )
equal( result.html(), should, source )
source = "<div><form class=\"xxx\">test 123</form></div>"
should = "test 123"
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
source = "<div><textarea class=\"xxx\">test 123</textarea></div>"
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 = "<div><div><b></b> test <input value=\"should not be shown\"></div></div>"
should = "<div> test </div>"
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
source = "<div><div><b></b> test </div><span>123</span></div>"
should = "<div> test </div><span>123</span>"
result = App.Utils.htmlRemoveRichtext( $(source) )
@ -223,9 +242,15 @@ test( "htmlRemoveRichtext", function() {
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
source = "<div><textarea class=\"xxx\"> test </textarea></div>"
//should = "<div> test </div>"
should = " test "
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
source = "<div><br></div>"
should = "<br>"
result = App.Utils.htmlClanup( $(source) )
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
source = "<div><div class=\"xxx\"><br></div></div>"
@ -233,6 +258,12 @@ test( "htmlRemoveRichtext", function() {
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
source = "<div><form class=\"xxx\">test 123</form></div>"
//should = "<div>test 123</div>"
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 = "<div><form class=\"xxx\">test 123</form></div>"
//should = "<div>test 123<br></div>"
should = "test 123"
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
source = "<div><form class=\"xxx\">test 123</form> some other value</div>"
//should = "<div>ttest 123 some other value</div>"
should = "test 123 some other value"
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
source = "<div><form class=\"xxx\">test 123</form> some other value<input value=\"should not be shown\"></div>"
//should = "<div>test 123 some other value</div>"
should = "test 123 some other value"
result = App.Utils.htmlRemoveRichtext( $(source) )
equal( result.html(), should, source )
});
// wrap

View file

@ -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