Skip to content

Plugins (e.g. SCEditor) config support #8

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

Closed
sashasochka opened this issue Nov 24, 2014 · 9 comments
Closed

Plugins (e.g. SCEditor) config support #8

sashasochka opened this issue Nov 24, 2014 · 9 comments

Comments

@sashasochka
Copy link
Contributor

Hi, how do I set plugin (e.g. SCEditor) options?

JsonEditorConfig.plugins.sceditor.style = /* url */ doesn't work because json-editor takes these properties from JSONEditor global object and in this lib JsonEditorConfig is manually merged into each instance config. The only (very hacky) solution I found is doing:

        window.JSONEditor.plugins = { // todo: add support for plugin properties in angular-json-editor
            sceditor: {
       //         style: '/components/SCEditor/minified/jquery.sceditor.default.min.css'
            }
        };

in angular.module(...).config. Not even $window because I can't use services in my config..

@rodikh
Copy link
Owner

rodikh commented Nov 24, 2014

Hey sochka,

I'm still trying to figure out how to work with sceditor, but i came across a solution that might be slightly more elegant for you.
I noticed that JsonEditor merges the properties of the schema config with the options config.

so something like this will work:

$scope.mySchema = {
    type: 'object',
    properties: {
        content: {
            type: 'string',
            required: true,
            format: "html",
            options: {
                wysiwyg: true,
                sceditor_options: {
                    style: 'path/to/jquery.sceditor.default.min.css'
                }
            }
        }
    }
};

While it's still not the best idea to mix configuration with schema, It'll surely work better for you than configuring global variables.

What do you think?

@sashasochka
Copy link
Contributor Author

It might be a good idea but not with my use case. It's actually other devs - users of my API who'll need to create schemas. I can't quite force them to set this property.

@rodikh
Copy link
Owner

rodikh commented Nov 25, 2014

There doesn't seem to be a smart way to configure JSONEditor without accessing globals,
So I thought perhaps just to wrap the JSONEditor in a constant and let the user configure it during his config phase.
i.e.
.constant('JSONEditor', window.JSONEditor)
and then

angular.module('demoApp', ['angular-json-editor']).config(function (JSONEditor) {
    JSONEditor.plugins = {
        sceditor: {
            style: 'sce/development/jquery.sceditor.default.css'
        }
    };
});

It's still not ideal, as it's just accessing the global, but at least this will work until json-editor is updated with an easier functionality.

Will this be acceptable?

@sashasochka
Copy link
Contributor Author

Maybe we should use providers, so we're able to use $window instead of window? Something like this (not tested):

.provider('JSONEditor', function () {
  var self = this;
  this.$get = function ($window) {
    // merge all the properties from `self` except those starting with `$` onto $window.JSONProvider
   return $window.JSONEditor;
 }
});

Is it better from design point? For my personal use-case it's probably quite the same as what you suggest but later-on it might be easier to mock $window.

@rodikh
Copy link
Owner

rodikh commented Nov 25, 2014

You can now inject JSONEditorProvider to your config, and configure JSONEditor using the JSONEditorProvider.configure() method.
(as demonstrated in the README.md)

@rodikh rodikh closed this as completed Nov 25, 2014
@sashasochka
Copy link
Contributor Author

Thanks! Do you think it makes sense to have JsonEditorConfig now? If I set my iconlib in JSONEditorProvider and won't touch JsonEditorConfig it won't work because JsonEditorConfig will shadow JSONEditorProvider.

rodikh added a commit that referenced this issue Nov 25, 2014
Added deep merge to JSONEditorProvider.configure
#8
@rodikh
Copy link
Owner

rodikh commented Nov 25, 2014

Since there is no use setting a different theme for every instance of JSONEditor on the page, I removed it, and now the configuration should be done through the JSONEditorProvider.configure method.
See readme and example.

@sashasochka
Copy link
Contributor Author

Thanks, that's good. FYI, it's better to release this kind of breaking changes using major version updates. If somebody specified their dependency as "angular-json-editor": "~0.1.3", they'd automatically receive angular-json-editor v0.1.5 but not if major version was bumped.

@rodikh
Copy link
Owner

rodikh commented Nov 25, 2014

Good call.
As you can see I'm new to this, and still learning the ropes.
I'll make sure to note this next time.
Thanks

@sashasochka sashasochka changed the title SCeditor Plugins (e.g. SCEditor) config support Nov 25, 2014
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