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

Custom command example does not work as expected #1441

Open
sntran opened this issue Jul 17, 2015 · 1 comment
Open

Custom command example does not work as expected #1441

sntran opened this issue Jul 17, 2015 · 1 comment

Comments

@sntran
Copy link

sntran commented Jul 17, 2015

I tried to recreate the example of custom command on the Docs page. Here is the fiddle (http://jsfiddle.net/noe7dm62/)

As you can see, the button does not output the selected text.

@shalanah
Copy link

shalanah commented Feb 6, 2016

I had problems with this too. I'm brand new to Aloha so I'm not sure if there is another way to do this.

I took a look at the source code on the "Getting Started Page". Aloha seems to wrap the selection with these weird looking chars: ▓ and a combo of these { } [ ] .

Aloha's code is this:

var command = {
    crazyCoolProperty: 'You selected:',
    action: function (boundaries, selection, command, events) {
        var source = aloha.markers.hint(boundaries, true)
            .replace(/[\n\r]/g, '')
            .replace(/^.*?▓([^▓]+)▓.*$/, '$1')
            .replace(/</g, '&lt;').replace(/>/g, '&gt;')
            .replace(/^[\{\[]|[\}\]]$/g, '');
        $('#demo5 .console')
            .html('<b>' + command.crazyCoolProperty + '</b> "' + source + '"');
    }
};
$('#crazy-cool-custom-command').on(
    'click',
    aloha.ui.command(aloha($('#demo5 .editable')[0]), command)
);

And while trying to figure it out I think this would work for your jsfiddle:

var command = {
        crazyCoolProperty: 'You selected: ',
        action: function (boundaries, selection, command, events) {
            var source = aloha.markers.hint(boundaries, true)
               .replace(/[\n\r]/g, '')
               .replace(/^.*?▓([^▓]+)▓.*$/, '$1')
               .replace(/^[\{\[]|[\}\]]$/g, '');
        alert(command.crazyCoolProperty + ' ' + source);
        }
};

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

No branches or pull requests

2 participants