Change CKEditor toolbar dynamically

后端 未结 10 1736
猫巷女王i
猫巷女王i 2020-12-09 04:30

How do you change the CKEditor toolbar dynamically (without using a pre-defined toolbar)?

The CKEditor Developer\'s Guide only tells you how to set the toolbar durin

10条回答
  •  长情又很酷
    2020-12-09 05:17

    According to [CKEditor documentation][1] they have given up the concept of 'theme' and thus the 'loadToolbar()' method mentioned above have to be modified a bit to work with the newest version of CKEditor.

    This worked for me (CKEditor 4.4.4):

    CKEDITOR.editor.prototype.setToolbar = function(tbName) {
    		if (!this._.events.themeSpace) {
    		  CKEDITOR.plugins.registered.toolbar.init(this);
    		// causes themeSpace event to be listened to.
    		}
    		// If a different toolbar was specified use it, otherwise just reload
    		if (tbName){
    			this.config.toolbar = tbName;
    		}
    		//According to CKEditor documentation
    		var obj = this.fire( 'uiSpace', { space: 'top', html: '' } ).html;
    		console.log("Received from themespace:");
    		console.log(obj);
    		// Replace the toolbar HTML 
    		var tbEleId = this.id +"_" + this.config.toolbarLocation;
    		console.log("Editor element id: " + tbEleId);
    		var tbEle = document.getElementById(tbEleId);
    		//tbEle.innerHTML = obj.html;
    		$(tbEle).html(obj);
          }
    [1]: http://docs.ckeditor.com/#!/guide/dev_api_changes

提交回复
热议问题