Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document and fix cleanHtml #146

Open
yonjah opened this issue Aug 28, 2018 · 0 comments
Open

Document and fix cleanHtml #146

yonjah opened this issue Aug 28, 2018 · 0 comments
Labels

Comments

@yonjah
Copy link

yonjah commented Aug 28, 2018

cleanHtml logic is not clear and it seem like it has a lot of unrelated logic.
I couldn't find any documentation for it (probably because the original function was very simple)

Original method just returned a string removing some redundant html tags and white spaces -

$.fn.cleanHtml = function () {
    var html = $(this).html();
    return html && html.replace(/(<br>|\s|<div><br><\/div>|&nbsp;)*$/, '');
};

Now it seem like it has a lot of extra logic was added in

Wysiwyg.prototype.cleanHtml = function( o ) {
        var self = this;
        if ( $( self ).data( "wysiwyg-html-mode" ) === true ) {
            $( self ).html( $( self ).text() );
            $( self ).attr( "contenteditable", true );
            $( self ).data( "wysiwyg-html-mode", false );
        }
        ...

If I understand correctly #4 the code should remove the pre element from the content (not sure why it's needed but it does not seem to revert the instance back once it's done)

And after it we have this code which is used to inject image data in as new form inputs

        // Strip the images with src="data:image/.." out;
        if ( o === true && $( self ).parent().is( "form" ) ) {
            var gGal = $( self ).html;
            if ( $( gGal ).has( "img" ).length ) {
                var gImages = $( "img", $( gGal ) );
                var gResults = [];
                var gEditor = $( self ).parent();
                $.each( gImages, function( i, v ) {
                    if ( $( v ).attr( "src" ).match( /^data:image\/.*$/ ) ) {
                        gResults.push( gImages[ i ] );
                        $( gEditor ).prepend( "<input value='" + $( v ).attr( "src" ) + "' type='hidden' name='postedimage/" + i + "' />" );
                        $( v ).attr( "src", "postedimage/" + i );
                    }
                } );
            }
        }

(I think implementation is a bit buggy since it never actually call the $( self ).html method but I haven't really ran the code to check).
But even if it works correctly it doesn't seem like it has anything to do with the actual clean functionality and it's probably should be included in a unique method (maybe even with a complementary logic which will allow to also remove the inputs that were created).

currently on v2 it also not being exposed at all and it seem to still assume this refers to the wysiwyg instance ( there is a pull request which exposes it but doesn't address any of the other issues)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants