2011-11-14 2 views
0

ckeditor의 키 바인딩에 h1, h2, h3 태그를 추가해야하는데이 작업을 수행하는 간단한 기능이 있습니다.
이 함수는 정상적으로 작동하고 예상대로 작동하지만 한 번만 사용할 수 있습니다. 동일한 함수를 다른 디렉토리에 복사하고 포함 시키려고하면 작동하지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?ckeditor에서 여러 개의 플러그인을 사용하려면 어떻게해야합니까?

위치 : 플러그인/버튼-H1/plugin.js

var a= { 
    exec:function(editor){ 
    var format = { 
    element : "h1" 
    }; 
    var style = new CKEDITOR.style(format); 
     style.apply(editor.document); 
    } 
}, 

// Add the plugin 
b="button-h1"; 
CKEDITOR.plugins.add(b,{ 
    init:function(editor){ 
    editor.addCommand(b,a); 
    editor.ui.addButton("button-h1",{ 
    label:"Button H1", 
    icon: this.path + "button-h1.png", 
    command:b 
    }); 
} 
}); 

하지만라는 다른 폴더 안에 또 다른 플러그인을 만들 때 '버튼을-H2'같은 코드 만 다른 이름 및 태그와 함께, 그것은 작동하지 않습니다.

위치 : 플러그인/버튼-H2/plugin.js

// Exactly the same as above, but with "h2" tags. 
var a= { 
    exec:function(editor){ 
    var format = { 
    element : "h2" 
    }; 
    var style = new CKEDITOR.style(format); 
     style.apply(editor.document); 
    } 
}, 

// Add the plugin 
b="button-h2"; 
CKEDITOR.plugins.add(b,{ 
    init:function(editor){ 
    editor.addCommand(b,a); 
    editor.ui.addButton("button-h2",{ 
    label:"Button H2", 
    icon: this.path + "button-h2.png", 
    command:b 
    }); 
} 
}); 

는 기본적으로, 선택한 텍스트 주위에 제목 태그를 추가 "CTRL + 1"을 사용할 수 있도록 사용자가 필요합니다.
이 방법은 H1 또는 H2 중 하나만 사용할 수 있다는 점을 제외하고는 모두 작동하지 않습니다.

내 config.js에는 다음을 모두 설정해야합니다.

config.extraPlugins = "button-h1,button-h2"; 
config.keystrokes = 
[ 
    [ CKEDITOR.CTRL + 49 /*1*/, 'button-h1' ], 
    [ CKEDITOR.CTRL + 50 /*2*/, 'button-h2' ] 

]; 

그래서,
- 플러그인 작품,하지만 난 단지 H1 또는 H2에서 사용할 수 있으며, 둘, 왜?

동시에 하나 이상의 함수를 실행할 수 있도록이 함수를 함수에 넣어야합니까?

답변

0

답변을 찾았습니다. 나는 이것을 익명의 함수로 감쌀 필요가 있었다.

(function(){ 
var a= 
{ 
    exec:function(editor){ 
     var format = { 
     element : "h1" 
     }; 
    var style = new CKEDITOR.style(format); 
    style.apply(editor.document); 
    } 
}, 

b="tags-h1"; 
CKEDITOR.plugins.add(b,{ 
    init:function(editor){ 
    editor.addCommand(b,a); 
    editor.ui.addButton(b,{ 
    label:"Heading 1", 
    icon: this.path + "heading-1.png", 
    command:b 
    }); 
    } 
}); 
})(); 
관련 문제