Skip to content

Fix wrong styles when using multiple instances of CodeMirror#3107

Merged
mshibuya merged 1 commit into
railsadminteam:masterfrom
sigra:codemirror_multiple_instances
Feb 9, 2019
Merged

Fix wrong styles when using multiple instances of CodeMirror#3107
mshibuya merged 1 commit into
railsadminteam:masterfrom
sigra:codemirror_multiple_instances

Conversation

@sigra

@sigra sigra commented Feb 1, 2019

Copy link
Copy Markdown
Contributor

Hi!

I faced with a problem when I have multiple CodeMirror instances on a single page. The problem is that the only last style will be applied to all CodeMirror instances.

For example, I have two fields and I wish to write ruby code in the first and javascript in the second:

      field :code, :code_mirror do
        config({
                 mode: 'ruby',
                 theme: 'monokai'
               })
        assets({
                 mode: ::ActionController::Base.helpers.asset_path('codemirror/modes/ruby.js'),
                 theme: ::ActionController::Base.helpers.asset_path('codemirror/themes/monokai.css')
               })
      end
      field :callback, :code_mirror do
        config({
                 mode: 'javascript',
                 theme: 'material'
               })
        assets({
                 mode: ::ActionController::Base.helpers.asset_path('codemirror/modes/javascript.js'),
                 theme: ::ActionController::Base.helpers.asset_path('codemirror/themes/material.css')
               })
      end

But as a result for both fields were applied javascript mode + material theme.

I guess that it's a typical javascript async error when variable was redefined before success callback was executed. This is why my short fix gets options directly from dom element in the callback.

@@ -240,6 +240,7 @@ $(document).on 'rails_admin.dom_ready', (e, content) ->
options = $(this).data('options')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seems to be no longer necessary, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah forget it, it is passed to $.getScript

@mshibuya mshibuya merged commit 8638981 into railsadminteam:master Feb 9, 2019
@mshibuya

mshibuya commented Feb 9, 2019

Copy link
Copy Markdown
Member

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants