2017-09-24 51 views
0

我使用gem 'ckeditor', github: 'galetahub/ckeditor'與rails admin。 我想要當我發佈在主頁上的文章,與文章的描述相關的圖像應該是自動響應。我在如何使ckeditor圖像響應導軌

資產/使用Javascript/CKEditor的

一個文件夾,我在此文件夾中粘貼此piece of code,但似乎不工作too.please幫助我。在此先感謝

回答

0

如果你想在CKEditor中插入圖像作出響應,你可以使用下面的代碼。它爲 圖像標記創建htmlfilter,它用 替換內聯「寬度」和「樣式」定義的相應屬性和添加(在本示例中) Bootstrap「img-responsive」類

我相信CKEDITOR不會將img-responsive類添加到這些圖像。你可以通過添加一個圖片CKEDITOR來檢查,然後檢查頁面上的html是否添加了img-responsive類。

功能CKEDITOR.on()事件'instanceReady'將執行代碼的'img-responsive'類添加到圖像元素el

事實是,我認爲你應該把一個斷點代碼和測試中,如果實際執行

CKEDITOR.on('instanceReady', function (ev) { // etc.. etc.. }); 

因爲this are the instruction on how to adapt ckeditor with turbolinks

創建文件app /資產/ JA vascripts/init_ckeditor.coffee

var ready = function() { 
    CKEDITOR.on('instanceReady', function (ev) { // code }); 
} 

$(document).ready(ready) 
$(document).on('page:load', ready) 

確保文件是從您的應用程序/資產/ JavaScript的加載/ application.js中

CKEDITOR is the API entry point. The entire CKEditor code runs under this object.

The documentation of the .on() jquery method可以幫助你更好地理解爲什麼這個調用沒有執行,基本上.on()方法在觸發該事件時觸發function(){}中的js代碼。

事件是instanceReady這是info from the API

instanceReady(EVT) 觸發的事件創建CKEDITOR實例時,完全初始化並準備互動。

Parameters 
evt : CKEDITOR.eventInfo 
editor : CKEDITOR.editor 
The editor instance that has been created.