2015-05-08 8 views
6

चयन के आधार पर एक ckeditor प्लगइन मेनू बटन की स्थिति टॉगल करने का सही तरीका क्या है?एक CKEditor प्लगइन बटन

उदाहरण के लिए, एक लिंक/अनलिंक प्लगइन में, अगर कर्सर एक लिंक में है तो मैं केवल अनलिंक सक्षम करना चाहता हूं।

editor.addCommand("unlink", { 
    exec: function (editor) { 
     //do something here 
    }, 
    refresh: function (editor, path) { 
     // never seems to get fired. Is this even the right hook? 
    } 
}); 

editor.ui.addButton("Unlink", { 
    label: "Unlink", 
    command: "unlink" 
}); 

सहायता के लिए धन्यवाद!

उत्तर

2

CKEDITOR.commandDefinition#contextSensitive संपत्ति है जो किसी विशेष संदर्भ में कमांड की स्थिति को नियंत्रित करने के लिए संभव बनाता है।

उदाहरण के लिए, अनलिंक करें बटन का actual implementation लगता है:

CKEDITOR.unlinkCommand.prototype = { 
    exec: function(editor) { 
     ... 
    }, 

    refresh: function(editor, path) {  
     var element = path.lastElement && path.lastElement.getAscendant('a', true); 

     if (element && element.getName() == 'a' && element.getAttribute('href') && element.getChildCount()) 
      this.setState(CKEDITOR.TRISTATE_OFF); 
     else 
      this.setState(CKEDITOR.TRISTATE_DISABLED); 
    }, 

    contextSensitive: 1, 
    ... 
}; 
संबंधित मुद्दे