8

クライアントの情報をその場で編集するために best_in_place gem を使用しています。

私の質問は、このコンテンツを HTML として編集するために WYSIWYG エディターを統合するにはどうすればよいですか? 現在、このエディターを使用しています: https://github.com/Nerian/bootstrap-wysihtml5-rails/

私はjavascriptとcofeescriptが苦手なので、おそらく何か間違ったことをしています。

ビュー内の私のコード:

<%= best_in_place @client, :info, :type => :textarea, :nil => "Click here to add content!", :html_attrs => { class: "wysihtml5" }, :sanitize => false %>

そしてclients.js.cofee

$(document).ready ->

# Activating Best In Place
jQuery(".best_in_place").best_in_place()

# Loading editor
$(".wysihtml5").each (i, elem) ->
$(elem).wysihtml5()

誰かがそれについて何をすべきか知っていますか?

ありがとう

4

5 に答える 5

0

コーヒースクリプトの単純なインデントの問題である可能性があります。$(document).ready -> の下の行をタブでインデントするだけです。

$(document).ready ->
  # Activating Best In Place
  jQuery(".best_in_place").best_in_place()

  # Loading editor
  $(".wysihtml5").each (i, elem) ->
  $(elem).wysihtml5()

さらに検証するには、コードを coffeescript フレーム @ http://js2coffee.org/にコピーします。結果の JavaScript は次のようになります。

$(document).ready(function() {
  jQuery(".best_in_place").best_in_place();
  $(".wysihtml5").each(function(i, elem) {});
  return $(elem).wysihtml5();
});

つまり、DOM がロードされた後にプラグインを呼び出す必要があります。

于 2014-06-02T04:10:02.767 に答える
0

私はこれを自分で遊んでいますが、控えめに言っても明らかではありませんでした。

これは私が最終的にそれを機能させた方法です:

イベントwysihtml5()にバインドされた textarea 要素を呼び出す必要があります。best_in_place:activateこれは私のapplication.js.coffeeです:

$(".best_in_place").each (index, element) ->
  $element  = $(element)

  $element
  .best_in_place()
  .on 'best_in_place:activate', () ->
    $element.find(".wysihtml5").each ->
      $this = $(this)
      $this.wysihtml5()

ヘルパーのオプションを wysihtml5使用して css クラスを追加しました。inner_class

<%= best_in_place @client, :info, type: :textarea, nil: "Click here to add content!", inner_class: 'wysihtml5' }, sanitize: false, display_as: :info_html %>

を使用していることに注意してください。これはdisplay_as: :info_html、モデルに処理済みの html を格納するフィールドがあるためですが、display_with: lambda { |v| v.html_safe }そうでない場合は使用できます。

そして今、トリッキーな部分が来ます: の現在のバージョン (3.0.3) は、テキストエリアがぼやけて に置き換えられたため、best_in_placeうまく機能しません。これにより、編集可能な操作がキャンセルされました。私は自分でgemにいくつかの変更を加える必要がありましたが、それがマージされることを願っています(完全な議論を見ることができます here)が、その間は私の forkを使用できます。その場合、ビューヘルパーにこの追加オプションを提供する必要があります: .wysihtml5contenteditable iframeskip_blur: true

于 2015-02-23T15:57:22.080 に答える