1

我正在使用拼音字符在ckeditor中将英语转换为我的本地语言,但它在google chrome和safari中无法正常工作这是我的代码

( function() {

   var codes= new Array();
   codes['a']=0x0627;
   ..................
   codes['z']=0x0632;

   codes['A']=0x0622;
   ..................
   codes['Z']=0x0630;

   codes['>']=0x0650;
   ..................
   codes[':']=58;

   codes['[']=0x201C;
   ..................
   codes['´']=0x0657;

   codes['0']=0x30;
   ..................
   codes['9']=0x39;

   isUrdu=true;
   var urdueditor_lang = 1;        // 1: Urdu, 0: English
   //var isiri2901_nativelang = 0;  // 1: Urdu, 0: English


    function DenIE_OnKeyDown( e )
    {
        var charCode = e.keyCode;
        if (e.ctrlKey && (charCode==32))
        {
            if (urdueditor_lang == 0)
              urdueditor_lang = 1;
            else
              urdueditor_lang = 0;
            try {
              e.preventDefault();
            } catch (err) {
            }
            return false;
        }
    }

    function DenIE_OnKeyPress( e )
    {
        if(urdueditor_lang!=1) return true;
        var charCode = e.keyCode;
        var whichASC = charCode ;
        var whichChar = String.fromCharCode(whichASC); // key's character
        e.keyCode= codes[whichChar];
    }

    var DenGecko_OnKeyDown = function(e) {
        var charCode = (e.charCode) ? e.charCode :
                            ((e.keyCode) ? e.keyCode :
                           ((e.which) ? e.which : 0));
        if (e.ctrlKey && (charCode==32))
        {
            if (urdueditor_lang == 0)
              urdueditor_lang = 1;
            else
              urdueditor_lang = 0;
            try {

              e.preventDefault();
            } catch (err) {
            }
            return false;
        }
    };

    var DenGecko_OnKeyPress = function(e) {
        if(urdueditor_lang!=1) return true;
        var charCode = e.charCode;
        var whichASC = charCode ;
        var whichChar = String.fromCharCode(whichASC); // key's character
        if((charCode==13) || (charCode==8)|| (charCode==37) || (charCode==39) ||  (charCode==38)|| (charCode==40)|| (charCode==33) || (charCode==34) || (charCode==50)  ) return;
        if (e.bubbles==false)
        return true;

        console.log("whichASC", whichASC);
        if (whichASC >= 0x00FF) {
            isUrdu=true;
        }
        else
        {
            isUrdu=false;
        }

        if (whichASC < 0x0020 || whichASC >= 0x007F || e.ctrlKey || e.altKey || e.metaKey)
            return true;
        var newkey;
        newkey = codes[whichChar];
        if (newkey == whichASC)
            return true;
        txt=String.fromCharCode(codes[whichChar]);
          e.preventDefault();
          var editor = CKEDITOR.instances.urduContent;

          editor.insertText(txt);
        }


   CKEDITOR.plugins.add( 'urdu',
   {
      init : function( editor )
      {
         editor.on( 'contentDom', function( e ) {
            var doc = this.document.$;
            if ( CKEDITOR.env.ie ) {        // If Internet Explorer.
               doc.attachEvent("onkeydown", DenIE_OnKeyDown ) ;
               doc.attachEvent("onkeypress", DenIE_OnKeyPress ) ;
            } else {                // If Gecko.
               doc.addEventListener( 'keydown', DenGecko_OnKeyDown, true ) ;
               doc.addEventListener( 'keypress', DenGecko_OnKeyPress, true ) ;
            }
         });

      } //Init
   } );

})();

但它在 Firefox 中工作,我可以在 chrome 中阅读所有浏览器中的文本,safari 字符不会绑定到单词。

4

0 回答 0