English 中文(简体)
TinyMCE - 添加一项关键文书 CNRTL-S COMMAND-S,称AJAX节省职能
原标题:TinyMCE - Adding a Key Binding CNRTL-S COMMAND-S to call an AJAX save Function

我很想知道,如何约束一个CNRTL-S或COMMAND-S,要求我在我的网页上履行一个职能,而AJAX可以节省文字内容。

我如何约束这两个指挥部? 当我只是一个文本领域时,我就使用了以下文字,但是由于增加了锡里卡中心,它不再奏效。 建议

// Keybind the Control-Save
jQuery( #text_area_content ).bind( keydown ,  ctrl+s ,function (evt){
saveTextArea();
    return false;
});
 // Keybind the Meta-Save Mac
jQuery( #text_area_content ).bind( keydown ,  meta+s ,function (evt){
saveTextArea();
    return false;
});

增 编

最佳回答

采用习惯方法进行储蓄,即宣布我在锡业的储蓄功能。 惯用法

tinyMCE.init({
        // General options
        mode: "none",
        /* some standard init params, plugins, ui, custom styles, etc */            


        save_onsavecallback: saveActiveEditor,
        save_oncancelcallback: cancelActiveEditor
    });

然后界定职能本身。

function saveActiveEditor() {
     var activeEditor = tinyMCE.activeEditor;
     var saveUrl = "http://my.ajax.path/saveStuff";
     var idEditor = activeEditor.id;
     var contentEditor = activeEditor.getContent();
     /* the next line is for a custom language listbox to edit different locales */
     var localeEditor = activeEditor.controlManager.get( lbLanguages ).selectedValue;

     $.post(saveUrl ,
            { id: idEditor, content: contentEditor, locale: localeEditor },
            function(results) {
                if (results.Success) {
                    // switch back to display instead of edit
                    return false;
                }
                else {
                    activeEditor.windowManager.alert( Error saving data );
                    return false;
                }
            },
             json 
        );
        return false;
 }

Don tabes to return不实 to overe theail Save action that post reisa data to the Service.


添加的意思是,只允许用户在某个时候改变一个小小小的情况。 您不妨将目前的情况改为:


编辑 #2: TinyMce已经捕获了用于处理数据的Ctrl+s。 由于这种办法还清理了html,并能够处理它在储蓄时提出的具体规则,因此,我提议的解决办法是简化你的储蓄方式。 避免完全推翻具有约束力的Ctrl+s

问题回答

这里的问题是,锡石板不把事件交给母窗。 您可以界定习俗——在锡恩采行和(或)使用以下yn:

// to delegate it to the parent window i use
var create_keydown_event = function(combo){
    var e = { type :  keydown  }, m = combo.split(/+/);
    for (var i=0, l=m.length; i<l; i++){
        switch(m[i]){
            case  ctrl : e.metaKey = true;
            case  alt : case  shift : e[m[i] +  Key ] = true; break;
            default : e.charCode = e.keyCode = e.which = m[i].toUpperCase().charCodeAt(0);
        }
    }
    return e;
}

var handler = function(){

  setTimeout(function(){
    var e = create_keydown_event(combo);
    window.parent.receiveShortCutEvent(e);
  }, 1);
}

//ed.addShortcut(combo, description, handler);
ed.addShortcut( ctrl+s ,  save_shortcut , handler);

在父母的窗口中,需要一项功能 短期通风,将说明与它做什么。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签