简体   繁体   English

一个禁用tinymce可视编辑器的书签?

[英]A bookmarklet to disable the tinymce visual editor?

I'm looking for a bookmarklet to disable the tinymce visual editor. 我正在寻找一个书签来禁用tinymce可视编辑器。 This is to say, some code that could be pasted into the address bar to disable the editor (and also bookmarked). 这就是说,有些代码可以粘贴到地址栏中以禁用编辑器(并带有书签)。

Anyone have any ideas? 有人有想法么?

The page I want to use it on is using an older version of TinyMce, I think the same version that is used on this page: http://www.imathas.com/editordemo/demo.html 我要在其上使用的页面使用的是TinyMce的旧版本,我认为此页面上使用的是同一版本: http : //www.imathas.com/editordemo/demo.html

Just to reiterate, I want to remove the TinyMce editor and leave the textarea. 重申一下,我想删除TinyMce编辑器,然后离开文本区域。

If you would like to see the functionality I am talking about, you could also visit this example page: http://www.matracas.org/sentido/tinymce/examples/full.html and click on the enable / disable buttons below the editor. 如果您想查看我正在谈论的功能,也可以访问以下示例页面: http : //www.matracas.org/sentido/tinymce/examples/full.html并单击“启用/禁用”按钮下面的编辑。

The problem here is that the syntax relies on knowing what editor id to put into the .get() function. 这里的问题是语法依赖于知道将哪个编辑器ID放入.get()函数中。

tinyMCE.get('elm1').hide();
tinyMCE.get('elm1').show();

The bookmarklet would ideally just use tinMCE's show / hide functionality, but it would work for all editors on a page. 理想情况下,小书签将仅使用tinMCE的显示/隐藏功能,但它将适用于页面上的所有编辑器。

Here you go! 干得好!

javascript:(function(){var arr=Object.keys(tinyMCE.editors);for(var i=0;i<arr.length;i++){try{tinyMCE.editors[arr[i]].remove();}catch(e){}}})()

More visibly pleasing, but same code: 更加令人愉悦,但代码相同:

javascript:
(function(){
  var arr=Object.keys(tinyMCE.editors);
  for(var i=0;i<arr.length;i++){
    try{
      tinyMCE.editors[arr[i]].remove();
    }
    catch(e){
    }
  }
}
)()

I have added a TinyMCE remover to my bookmarklet collection: http://richardbronosky.github.com/Perfect-Bookmarklets/tinymce.html 我已将TinyMCE卸妆剂添加到我的收藏夹集合中: http : //richardbronosky.github.com/Perfect-Bookmarklets/tinymce.html

It has one major advantage over the others I have seen. 与我见过的其他优点相比,它具有一个主要优点。 It restores the content of the textarea back to what was in the source. 它将文本区域的内容还原回源中的内容。 I don't know if others have experienced this, but we have a web admin to our CMS and TinyMCE, when removed leaves the code altered. 我不知道其他人是否经历过,但是我们有一个CMS和TinyMCE的网络管理员,将其删除后会使代码更改。 I have resolved this. 我已经解决了。

Here is the code: 这是代码:

  for(var i=0;i<tinymce.editors.length;i++){
    var tmpId=tinymce.editors[i].id;
    var tmpVal=document.getElementById(tmpId).value;
    tinyMCE.execCommand("mceRemoveControl",true,tmpId);
    document.getElementById(tmpId).value=tmpVal
  }

Also on github: https://github.com/RichardBronosky/Perfect-Bookmarklets/blob/master/tinymce.html 也在github上: https : //github.com/RichardBronosky/Perfect-Bookmarklets/blob/master/tinymce.html

I start all my bookmarklets with jQuery, although this may work better as a greasemonkey script depending on what you're trying to do. 我的所有小书签都以jQuery开始,尽管根据您要执行的操作,这可能会更好地用作工作簿脚本。

javascript:
function loadScript(url, callback){
        var head = document.getElementsByTagName("head")[0];
        var script = document.createElement("script");
        script.src = url;

        var done = false;
        script.onload = script.onreadystatechange = function()        {
                if( !done && ( !this.readyState 
                                        || this.readyState == "loaded" 
                                        || this.readyState == "complete") )
                {
                        done = true;

                        callback();

                        script.onload = script.onreadystatechange = null;
                        head.removeChild( script );
                }
        };

        head.appendChild(script);
}

loadScript("http://code.jquery.com/jquery-latest.js", function(){
    jQuery('.mceEditor').remove(); }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM