How do I deactivate Bootstrap-wysihtml5 jquery editor instance?

陌路散爱 提交于 2019-12-10 21:07:59

问题


I'm using the Bootstrap-wysihtml5 jquery plugin (https://github.com/jhollingworth/bootstrap-wysihtml5/) to convert textareas to WYSIWYG. I would like to be able to activate and deactivate the editor by clicking on 2 buttons, so far i can show the editor, please will you let me know how i can deactivate the editor and leave just the textarea and its value. My code is as follows:-

HTML

<textarea name="textarea" id="textarea" cols="45" rows="5"></textarea>

<input type="button" id="button1" value="Show Editor"> 
<input type="button" id="button2" value="Hide Editor">

Script

$("#button1").click(function(){
$('textarea').wysihtml5();
});

$("#button2").click(function(){
// this is where i'm stuck
});

Thank you


回答1:


I had the same problem trying to disable/hide the toolbar and editor and had luck with the following commands (to disable the editor). I'm using version wysihtml5-0.3.0_rc2.js)

$('#editorId').data('wysihtml5').editor.composer.disable();
$('#editorId').data('wysihtml5').editor.composer.enable();

or (to hide the editor)

$('#editorId').data('wysihtml5').editor.composer.hide();
$('#editorId').data('wysihtml5').editor.composer.show();

To do the same to the toolbar you do the following to hide/show (can't find a wat to disable the toolbar):

$('#editorId').data('wysihtml5').editor.toolbar.hide();
$('#editorId').data('wysihtml5').editor.toolbar.show();



回答2:


A few lines of custom JS code. I think they can help you.

var content = $('#content');
var contentPar = content.parent()
contentPar.find('.wysihtml5-toolbar').remove()
contentPar.find('iframe').remove()
contentPar.find('input[name*="wysihtml5"]').remove()
content.show()


来源:https://stackoverflow.com/questions/15712214/how-do-i-deactivate-bootstrap-wysihtml5-jquery-editor-instance

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!