var output;
var editor_root;
var editor_popup;
var editor;
var dragging=false;
function update_ui_state(){
parent.update_ui_state();
}
function keycode_name(_1){
var _2=null;
if(_1==37){
_2="left";
}else{
if(_1==39){
_2="right";
}else{
if(_1==38){
_2="up";
}else{
if(_1==40){
_2="down";
}else{
if(_1==36){
_2="home";
}else{
if(_1==35){
_2="end";
}else{
if(_1==33){
_2="pageup";
}else{
if(_1==34){
_2="pagedown";
}else{
if(_1==46){
_2="delete";
}else{
if(_1==8){
_2="backspace";
}else{
if(_1==13){
_2="enter";
}else{
if(_1==9){
_2="tab";
}else{
if(_1==119){
_2="toggle";
}
}
}
}
}
}
}
}
}
}
}
}
}
return _2;
}
function handle_key_code(_3,_4,_5,_6,_7){
if(_5||_6||_7){
return false;
}
var _8=keycode_name(_3);
if(_8==null){
return false;
}
switch(_8){
case "left":
this.editor.move_left(_4);
break;
case "right":
this.editor.move_right(_4);
break;
case "home":
this.editor.move_home(_4);
break;
case "end":
this.editor.move_end(_4);
break;
case "up":
this.editor.move_up(_4);
break;
case "down":
this.editor.move_down(_4);
break;
case "pageup":
for(var i=0;i<10;++i){
this.editor.move_up(_4);
}
break;
case "pagedown":
for(var i=0;i<10;++i){
this.editor.move_down(_4);
}
break;
case "delete":
this.editor.key_delete();
break;
case "backspace":
this.editor.key_backspace();
break;
case "enter":
this.editor.key_enter();
break;
case "tab":
this.editor.key_tab();
break;
case "toggle":
this.editor.toggle_lang();
break;
default:
assert(false);
}
return true;
}
function handle_key_char(_a,_b,_c,_d,_e){
var _f=this;
var _10={"z":this.editor.undo,"y":this.editor.redo,"v":this.editor.paste,"x":this.editor.internal_cut,"c":this.editor.internal_copy,"a":this.editor.select_all,"b":function(){
var a=_f.editor.get_selection_item_attributes();
if(a==null){
a=_f.editor.get_new_item_attributes();
}
_f.editor.set_bold(!a.bold);
_f.editor.grab_focus();
},"i":function(){
var a=_f.editor.get_selection_item_attributes();
if(a==null){
a=_f.editor.get_new_item_attributes();
}
_f.editor.set_italic(!a.italic);
_f.editor.grab_focus();
},"u":function(){
var a=_f.editor.get_selection_item_attributes();
if(a==null){
a=_f.editor.get_new_item_attributes();
}
_f.editor.set_underline(!a.underline);
_f.editor.grab_focus();
}};
var ch=String.fromCharCode(_a);
var lch=ch.toLowerCase();
var _16=_10[lch];
if((_c||_e)&&(!_d)&&(_16)){
_16.call(this.editor);
if((lch=="z")||(lch=="y")||(lch=="a")||(lch=="b")||(lch=="i")||(lch=="u")){
return true;
}
}
if(_c||_d||_e){
return false;
}
if(_a==32){
this.editor.key_space(ch);
}else{
if((_a>=65)&&(_a<65+26)){
this.editor.key_xlit_char(ch);
}else{
if((_a>=97)&&(_a<97+26)){
this.editor.key_xlit_char(ch);
}else{
if((_a>=48)&&(_a<48+10)){
this.editor.key_num_char(ch);
}else{
this.editor.key_simple_char(ch);
}
}
}
}
return true;
}
function on_popup_choice(){
editor.grab_focus();
editor.move_right();
}
function do_init(_17,_18,_19,_1a,_1b){
output=parent.output;
var _1c=_19?parent.document:document;
this.editor_popup=new QuillPopup(_1c,on_popup_choice);
if(_19){
this.editor_popup.set_offset(_1a,_1b);
}
this.editor_root=document.getElementById(_17);
this.editor=new QuillEditor(document,this.editor_root,this.editor_popup,_18);
var _1d=this;
this.dragging=false;
window.setInterval(function(){
_1d.editor.toggle_caret_blink();
},500);
this.focus_listener=this.editor_root;
if($.browser.safari){
$(this.focus_listener).click(function(e){
_1d.editor.set_has_focus(true);
});
}else{
$(this.focus_listener).focus(function(e){
_1d.editor.set_has_focus(true);
});
}
$(this.focus_listener).blur(function(e){
_1d.editor.set_has_focus(false);
});
$(window).resize(function(e){
_1d.editor.update_on_resize();
});
$(this.editor_root).mousedown(function(e){
_1d.editor.grab_focus();
if(_1d.dragging){
return;
}
_1d.dragging=true;
var _23=_1d;
$(_1d.editor_root).mousemove(function(e){
_23.editor.move_caret_to_xy(e.pageX,e.pageY,true);
update_ui_state();
});
_1d.editor.move_caret_to_xy(e.pageX,e.pageY,false);
update_ui_state();
});
$(_1d.editor_root).mouseup(function(e){
_1d.dragging=false;
$(_1d.editor_root).unbind("mousemove");
});
function print_key(_26,e){
}
$(this.focus_listener).keypress(function(e){
print_key("keypress",e);
var _29=false;
if(e.which>=32){
if((!window.event)||(!e.ctrlKey)){
_29=handle_key_char.call(_1d,e.which,e.shiftKey,e.ctrlKey,e.altKey,e.metaKey);
}
}else{
if((!window.event)&&((e.which==0)||(e.which==8)||(e.which==13))){
_29=handle_key_code.call(_1d,e.keyCode,e.shiftKey,e.ctrlKey,e.altKey,e.metaKey);
}
}
if(_29){
e.preventDefault();
update_ui_state();
}
});
$(this.focus_listener).keydown(function(e){
print_key("keydown",e);
var _2b;
if(!window.event){
return;
}
_2b=handle_key_code.call(_1d,e.keyCode,e.shiftKey,e.ctrlKey,e.altKey,e.metaKey);
if((!_2b)&&e.ctrlKey&&(e.keyCode>=32)){
_2b=handle_key_char.call(_1d,e.keyCode,e.shiftKey,e.ctrlKey,e.altKey,e.metaKey);
}
if(_2b){
e.preventDefault();
update_ui_state();
}
});
if($.browser.msie){
$().bind("selectstart",function(e){
var src=e.target.id;
if(src!=="paste"){
e.preventDefault();
}
});
}else{
$().mousedown(function(e){
e.preventDefault();
});
}
}

