Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added in tinymce support #1231

Closed
wants to merge 1 commit into from

3 participants

@rovermicrover

Added in TinyMCE support. Tested with the tinymce-rails gem.

The set up is very simliar to how code-mirror works.

The only major difference is the defaults have to be set like bellow.

window.tinyMCEPreInit = {
  base: options['base'],
  theme: options['theme'],
  suffix: '',
  mode: "specific_textareas"
}

Also because the jquery version is loaded, two different scripts must be loaded, with the second as a call back, and then the load events as yet another call back for the second script load.

$.getScript options['jspath'], (script, textStatus, jqXHR) =>
  $.getScript options['jqpath'], (script, textStatus, jqXHR) =>
    gotinyMCE(@arraytmc)

The options are as follows

register_instance_option(:tinymce) do
  false
end

register_instance_option(:tinymce_js_location) do
  "/assets/tinymce/tiny_mce_jquery_src.js"
end

register_instance_option(:tinymce_jquery_location) do
  "/assets/tinymce/jquery.tinymce.js"
end

register_instance_option(:tinymce_theme_options) do
  "advanced"
end

register_instance_option(:tinymce_options) do
  {}
end

register_instance_option(:tinymce_base_location) do
  '/assets/tinymce'
end

The theme option is really just the default theme option, and once again because the jquery version is being used two scripts must be loaded, so there are two options for script location.

From what I have been able to test everything seems to work fine, but about every 10th load or so TinyMCE will just refuse to load. I tried forcing a wait to make sure it wasn't an issue with TinyMCE getting called before all the corresponding files where loaded, even with the nested callbacks. But I wasn't able to find the root cause of the issue.

I hope this helps, and let me know if anything is explained poorly or you have any questions.

PS: I also changed the array variable name for each of the editor setups in the coffee script, just to make things clearer.

@travisbot

This pull request fails (merged 5a34643 into e08adbe).

@mshibuya
Collaborator

I've tested this using Chrome, but TinyMCE doesn't appear in 1 out of 3 forced reloads, every normal reloads and every pjax navigations. Looks like the loading problem still persists.
Can you please fix it?

@rovermicrover

I will have sometime this weekend to look at it again. When you say "1 out of 3 forced reloads, every normal reloads and every pjax navigations" Do you mean it doesn't works 1/3rd of the time on forced reloads, and none at all on the other two. OR Do you mean that it doesn't works 1/3 of the time no matter how you try to load it?

@mshibuya
Collaborator

Sorry I didn't make it clear.
After a little further investigation,

  • not shows up in 1 out of 3 forced reloads
  • never shows up with normal reloads
  • with pjax navigations(i.e. clicking the 'edit' link in other pages)
    • when first page load was made by forced reload, works fine until non-pjax page transition occurs
    • when first page load was made by normal reload, never shows up

Is this really working for you?

@rovermicrover

It was, but I was testing it on my old computer while it was stilling having the issue that lead to this stupid pull request.
#1229

What ever was going on caused the above, issue, made it so I couldn't get ember.js to run at all when I tried it out this weekend, and clearly didn't help with this pull request either. And generally made me waste a lot of time that would have other wise been productive.

This weekend or next when I get sometime I am just going to scrap everything and try again from scratch on a new computer, sorry about this I should have noticed quicker that it was a bug on my OS.

@rovermicrover

Got stuck under a pile of work, still planning on doing this atm, just not right away.

@mshibuya
Collaborator

Closing this for now.
Please open another one if you come up with a solution!

@mshibuya mshibuya closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 30, 2012
  1. @rovermicrover

    added in tinymce support

    rovermicrover authored
This page is out of date. Refresh to see the latest.
View
53 app/assets/javascripts/rails_admin/ra.widgets.coffee
@@ -134,16 +134,45 @@ $(document).live 'rails_admin.dom_ready', ->
window.CKEDITOR.replace(this, options['options'])
$(this).addClass('ckeditored')
- array = $('form [data-richtext=ckeditor]').not('.ckeditored')
- if array.length
- @array = array
+ arrayck = $('form [data-richtext=ckeditor]').not('.ckeditored')
+ if arrayck.length
+ @arrayck = arrayck
if not window.CKEDITOR
- options = $(array[0]).data('options')
+ options = $(arrayck[0]).data('options')
window.CKEDITOR_BASEPATH = options['base_location']
$.getScript options['jspath'], (script, textStatus, jqXHR) =>
- goCkeditors(@array)
+ goCkeditors(@arrayck)
else
- goCkeditors(@array)
+ goCkeditors(@arrayck)
+
+ #tinymce
+
+ gotinyMCE = (array) =>
+ array.each (index, domEle) ->
+ options = $(this).data('options')
+ tinyMCE.init(jQuery.extend({
+ mode : "exact",
+ elements : $(this).attr("id")
+ }, options))
+ $(this).addClass('tinymced')
+
+
+ arraytmc = $('form [data-richtext=tinymce]').not('.tinymced')
+ if arraytmc.length
+ @arraytmc = arraytmc
+ if not window.tinyMCE
+ options = $(arraytmc[0]).data('options')
+ window.tinyMCEPreInit = {
+ base: options['base'],
+ theme: options['theme'],
+ suffix: '',
+ mode: "specific_textareas"
+ }
+ $.getScript options['jspath'], (script, textStatus, jqXHR) =>
+ $.getScript options['jqpath'], (script, textStatus, jqXHR) =>
+ gotinyMCE(@arraytmc)
+ else
+ gotinyMCE(@arraytmc)
#codemirror
@@ -156,14 +185,14 @@ $(document).live 'rails_admin.dom_ready', ->
CodeMirror.fromTextArea(textarea,{mode:options['options']['mode'],theme:options['options']['theme']})
$(textarea).addClass('codemirrored')
- array = $('form [data-richtext=codemirror]').not('.codemirrored')
- if array.length
- @array = array
+ arraycm = $('form [data-richtext=codemirror]').not('.codemirrored')
+ if arraycm.length
+ @arraycm = arraycm
if not window.CodeMirror
- options = $(array[0]).data('options')
+ options = $(arraycm[0]).data('options')
$('head').append('<link href="' + options['csspath'] + '" rel="stylesheet" media="all" type="text\/css">')
$.getScript options['jspath'], (script, textStatus, jqXHR) =>
- goCodeMirrors(@array)
+ goCodeMirrors(@arraycm)
else
- goCodeMirrors(@array)
+ goCodeMirrors(@arraycm)
View
9 app/views/rails_admin/main/_form_text.html.haml
@@ -16,6 +16,15 @@
:options => field.codemirror_config,
:locations => field.codemirror_assets
}
+ elsif field.tinymce
+ richtext = 'tinymce'
+ js_data = {
+ :jspath => field.tinymce_js_location,
+ :jqpath => field.tinymce_jquery_location,
+ :theme => field.tinymce_theme_options,
+ :base => field.tinymce_base_location,
+ :options => field.tinymce_options
+ }
else
richtext = false
js_data = {}
View
25 lib/rails_admin/config/fields/types/text.rb
@@ -67,6 +67,31 @@ class Text < RailsAdmin::Config::Fields::Base
}
end
+ # TinyMCE is disabled by default
+ register_instance_option(:tinymce) do
+ false
+ end
+
+ register_instance_option(:tinymce_js_location) do
+ "/assets/tinymce/tiny_mce_jquery_src.js"
+ end
+
+ register_instance_option(:tinymce_jquery_location) do
+ "/assets/tinymce/jquery.tinymce.js"
+ end
+
+ register_instance_option(:tinymce_theme_options) do
+ "advanced"
+ end
+
+ register_instance_option(:tinymce_options) do
+ {}
+ end
+
+ register_instance_option(:tinymce_base_location) do
+ '/assets/tinymce'
+ end
+
register_instance_option(:partial) do
:form_text
end
Something went wrong with that request. Please try again.