2016-08-22 44 views

回答

0

我建议使用事件来捕获工具应用时,然后应用你以后的具体行为。

目前没有很好的方式来访问这些事件(我将在未来的版本中看到),但同时这里有一个解决方法,它给你你以后的行为,并且应用到任何工具都应该相对简单:

// Override the behaviour of the `ToolboxUI.tools` method so that we can 
// bind to the applied event for the tools of interest. 
var superTools = ContentTools.ToolboxUI.prototype.tools; 
ContentTools.ToolboxUI.prototype.tools = function (tools) { 
    superTools.call(this, tools); 

    function _followWithP(ev) { 
    var element = ev.detail().element; 

    // Find the top level element 
    if (element.parent().type() !== 'Region') { 
     element = element.closest(function(node) { 
     return node.parent().type() === 'Region'; 
     }); 
    } 

    // Find the newely insert element 
    var newElement = element.nextSibling(); 

    // Check if this is the last item in the region 
    var siblings = newElement.parent().children; 
    if (newElement === siblings[siblings.length - 1]) { 
     // This is the last child so apply add a paragraph 
     var p = new ContentEdit.Text('p', {}, ''); 
     newElement.parent().attach(p); 
     p.focus(); 
    } 
    } 

    // Modify the applied behaviour of the image, table and video tools to use 
    // `_followWithP`. 
    this._toolUIs['image'].addEventListener('applied', _followWithP); 
    this._toolUIs['table'].addEventListener('applied', _followWithP); 
    this._toolUIs['video'].addEventListener('applied', _followWithP); 
}