initGs.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. $(function(){
  2. enableGsEditor();
  3. });
  4. function enableGsEditor(){
  5. var tag = "button";
  6. if($.browser.msie && parseInt($.browser.version)<8){
  7. tag = "div";
  8. }
  9. window.gseditor = com.wiris.jsEditor.JsEditor.newInstance({
  10. 'language': 'zh'
  11. });
  12. gseditor.insertInto(document.getElementById('editorContainer'));
  13. gseditor.onIsReady(function(){
  14. $(tag+".wrs_button").each(function(i,n){$(this).attr("num",i)});
  15. setTimeout(function(){
  16. $("#gsedit_loading").hide();
  17. $("#editorContainer").removeAttr("style");
  18. gseditor.focus()
  19. },180);
  20. });
  21. js.Lib.isIE = $.browser.msie;
  22. var cmdstr = "";
  23. $("#editorContainer").keydown(function(e){
  24. if(e.keyCode==33){
  25. $(tag+".wrs_selected").prev().click();
  26. return false;
  27. }else if(e.keyCode==34){
  28. $(tag+".wrs_selected").next().click();
  29. return false;
  30. }if(e.keyCode==36){
  31. $(tag+"[role]").first().click();
  32. return false;
  33. }else if(e.keyCode==35){
  34. $(tag+"[role]").last().click();
  35. return false;
  36. }
  37. if(e.keyCode==27 || e.keyCode==112){
  38. var btnList = $("div.wrs_selected "+tag+".wrs_button");
  39. if(btnList.eq(0).find(".numposition").length==0){
  40. btnList.each(function(){
  41. $(this).append('<i class="numposition" style="font-size:10px">'+$(this).attr("num")+'</i>');
  42. });
  43. }
  44. btnList.addClass("position");
  45. return false;
  46. }
  47. if(e.altKey && e.ctrlKey){
  48. if(/48|49|5[0-7]/.test(e.keyCode)){
  49. cmdstr+=e.keyCode-48;
  50. }else if(/9[6-9]|10[0-5]/.test(e.keyCode)){
  51. cmdstr+=e.keyCode-96;
  52. }
  53. }
  54. }).keyup(function(e){
  55. if(e.keyCode==27 || e.keyCode==112){
  56. var btnList = $(tag+".position");
  57. btnList.removeClass("position");
  58. }
  59. if(e.keyCode==18){
  60. $(tag+"[num='"+$.trim(cmdstr)+"']").click();
  61. cmdstr = "";
  62. e.preventDefault();
  63. return false;
  64. }
  65. });
  66. }
  67. if(!window.editGs){
  68. window.editGs = function(obj){
  69. var mathML = $.gs[obj.id];
  70. $("#gseditor").ui("dialog",{
  71. close : ".pup_close"
  72. });
  73. $("#gsinsert").data("element",obj);
  74. if($.browser.msie){
  75. gseditor.setMathML(mathML);
  76. }else{
  77. gseditor.editorModel.reset();
  78. gseditor.editorModel.insertMathML(mathML);
  79. }
  80. gs.focus();
  81. setTimeout(function(){
  82. $("button[num=34]").focus();
  83. },100);
  84. return false;
  85. }
  86. }