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

Selection Range Bug #529

Open
iam1me opened this issue Aug 5, 2016 · 4 comments
Open

Selection Range Bug #529

iam1me opened this issue Aug 5, 2016 · 4 comments

Comments

@iam1me
Copy link
Contributor

iam1me commented Aug 5, 2016

I've created a custom data-field bbcode that translates to an HTML Canvas in the WYSIWYG Editor. I created a data-field-plugin that handles rendering, updating, etc. these canvas elements. That's all working well.

Currently I am using the style attribute to control things like the canvas font-family, font-size, and color. However, I'd prefer if I could just use the standard BBCodes to handle these things. Example: "[b][data-field field-name="TotalAmount"][/data-field][/b]". This would tell me the field name to draw on the canvas, and I would determine that it is bold due to the parent bold tag.

The editor seems like it should be able to support this, except for what appears to be a bug with the range selection. If I have a some text before and after a field, and I highlight all of it and click the Bold button (or use another formatting command) the text before and after the canvas element are bolded, but there is no bold tag around the data-field. Example:

[b]b[/b][data-field data-source="DS" field-name="F"][/data-field][b]a[/b]

The data-field BBCode is marked as Inline, so it seems like it should be bolded as well. Perhaps someone knows of a config setting I maybe missing? Otherwise this is a bug. Hopefully Sam will return to take a look.

@brunoais
Copy link
Collaborator

brunoais commented Aug 6, 2016

What are your definitions for the data-field BBCode? (for both the WYSIWYG editor and for the BBCode editor)

@iam1me
Copy link
Contributor Author

iam1me commented Aug 10, 2016

Hi brunoais,

Sorry for the delay in getting back to you, I've been out sick for a few days. Below is my current code for registering the BBCode specifically. I also have a 'data-field-plugin' that handles the rendering/event handling for the WYSIWYG side of things. Let me know if you'd like to see that.

//// BEGIN "data-field" BBCode
    $.sceditor.plugins.bbcode.bbcode.set('data-field', {
        tags: {
            'canvas': {
                'class': ['data-field']
            }
        },
        isHtmlInline: true,
        //allowedChildren: [],
        allowsEmpty: true,
        excludeClosing: false,
        skipLastLineBreak: false,

        breakBefore: false,
        breakStart: false,
        breakEnd: false,
        breakAfter: false,

        format: function(element, content) {
            var result = '[data-field';

            var attr = null;
            if((attr = element.attr('data-source')))
                result += ' data-source="' + attr + '"';

            if((attr = element.attr('field-name')))
                result += ' field-name="' + attr + '"';

            if((attr = element.attr('numerical-format')))
                result += ' numerical-format="' + attr + '"';

            result += ']';

            if(content)
            {
                if(content.trim) content = content.trim();
                result += content;
            }

            result += '[/data-field]';
            return result;
        },

        html: function(token, attrs, content) {
            var result = '<canvas class="data-field" draggable="true"';

            var attr = null;
            if(attrs['data-source'])
                result += ' data-source="' + attrs['data-source'] + '"';

            if(attrs['field-name'])
                result += ' field-name="' + attrs['field-name'] + '"';

            if(attrs['numerical-format'])
                result += ' numerical-format="' + attrs['numerical-format'] + '"';

            result += '>';

            if(content)
            {   
                if(content.trim) content = content.trim();
                result += content;
            }

            result += '</canvas>';

            return result;
        },       
        quoteType: $.sceditor.BBCodeParser.QuoteType.always
    }); //// END "data-field" BBCode 

@brunoais
Copy link
Collaborator

Where's the definition for the WYSIWYG editor? That's the definition for the BBCode editor (transforming from and to BBCode). For this, I believe I need both.

@iam1me
Copy link
Contributor Author

iam1me commented Aug 11, 2016

Here is my current setup code for the WYSIWYG Editor itself:


        // Replace all textarea's
        // with SCEditor
        $("textarea").sceditor({
            plugins: "bbcode,data-field-plugin",
            toolbar: "bold,italic,underline,strike|font,size,color|link,insert-data-field|removeformat|maximize,source",
            fixInvalidNesting: false,
            style: "styles/sceditor.custom.css" //"scripts/sceditor/minified/jquery.sceditor.default.min.css"
        });

I tried setting fixInvalidNesting to false, but that doesn't seem to have helped.

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

No branches or pull requests

2 participants