2017-08-01 72 views
1

我試圖添加證明插件,以便能夠對齊文本的右,左或中心。但在按照文檔(http://apostrophecms.org/docs/tutorials/howtos/ckeditor.html)中的說明操作後,我不知道該插件是否應該位於特定文件夾中(我的位置是public/modules /撇號/ areas/js/ckeditorPlugins/justify /),因爲它在站點中消失被加載,但如果我將其包含在其他文件夾(如public/plugins/justify)中仍然不起作用。Ckeditor插件配置不工作

這是我的代碼,以防萬一:(位於lib/modules目錄/撇號區/公/ JS/user.js的)

apos.define('apostrophe-areas', { 
    construct: function(self, options) { 
    // Use the super pattern - don't forget to call the original method 
    var superEnableCkeditor = self.enableCkeditor; 
    self.enableCkeditor = function() { 
     superEnableCkeditor(); 
     // Now do as we please 
     CKEDITOR.plugins.addExternal('justify', '/modules/apostrophe-areas/js/ckeditorPlugins/justify/', 'plugin.js'); 
    }; 
    } 
}); 

而且,這將是很好知道插件如何應在可編輯小部件的工具欄設置中調用。 謝謝!

回答

1

事實證明,僅僅撥打apostophe-areas內的CKEDITOR.plugins.addExternal是不夠的。您還需要覆蓋apostrophe-rich-text-widgets-editor模塊的self.beforeCkeditorInline,並明確地調用self.config.extraPlugins = 'your_plugin_name';

這裏是我結束了:

lib/modules/apostrophe-areas/public/js/user.js

apos.define('apostrophe-areas', { 
    construct: function(self, options) { 
    // Use the super pattern - don't forget to call the original method 
    var superEnableCkeditor = self.enableCkeditor; 
    self.enableCkeditor = function() { 
     superEnableCkeditor(); 
     // Now do as we please 
     CKEDITOR.plugins.addExternal('justify', '/modules/my-apostrophe-areas/js/ckeditorPlugins/justify/', 'plugin.js'); 
    }; 
    } 
}); 

然後在in lib/modules/apostrophe-rich-text-widgets/public/js/editor.js

apos.define('apostrophe-rich-text-widgets-editor', { 
    construct: function(self, options) { 
    self.beforeCkeditorInline = function() { 
     self.config.extraPlugins = 'justify'; 
    }; 
    } 
}); 

出於某種原因做CKEDITOR.config.extraPlugins = 'justify'apostrophe-areas不起作用,可能是由於CKEDITOR初始化的方式;

還有一件事:這個特殊的插件(證明,這是)似乎並不遵循按鈕定義邏輯。它將按鈕圖標定義爲圖像,而在撇號CMS 2.3中使用的CKEditor 4.6使用font-awesome來顯示圖標。這意味着與justify模塊一起提供的圖標將不會顯示,您將不得不爲每個按鈕分別編寫自己的CSS。

還有另一個問題,你可能會遇到當你最終啓用justify按鈕。內置的html消毒工具將剝離樣式證明添加到對齊內容的樣式。

撇號CMS似乎在使用sanitize-html來消毒輸入,所以更改CKEditor設置不會產生任何影響。要解決此問題,請將以下內容添加到您的app.js中:

'apostrophe-rich-text-widgets': { 
    // The standard list copied from the module, plus sup and sub 
    sanitizeHtml: { 
    allowedAttributes: { 
     a: ['href', 'name', 'target'], 
     img: ['src'], 
     '*': ['style'] //this will make sure the style attribute is not stripped off 
    } 
    } 
} 
2

您需要的網址是:

/modules/my-apostrophe-areas/js/ckeditorPlugins/justify/

my-前綴自動預先考慮,這樣無論是原apostrophe-areas模塊和它的項目級擴展的public文件夾可以有不同的URL。否則,例如,將無法訪問他們的user.js

我會將這個註釋添加到問題的HOWTO中,該問題目前通過在構成的URL中存根來交叉處理問題。

至於應該如何調用插件,請使用該插件導出的工具欄控件名稱 - 該部分是ckeditor問題,而不是真正的撇號問題。但看看該插件的源代碼,他們可能是JustifyLeft,JustifyCenter,JustifyRightJustifyBlock

0

謝謝你們的幫助。在遵循以下兩種方法之後:找到my-apostrophe-areas文件夾中的插件以及在apostrophe-rich-text小部件上編輯editor.jssanitize.html文件已經使用該配置)後,我使插件工作。但是,我仍然遇到與圖標有關的問題。

我固定,添加對應於align-justify, align-right, align-leftalign-centerpublic/modules/apostrophe-areas/js/vendor/ckeditor/skins/apostrophe/editor.less

末端的字體真棒圖標