var put_to_editor = ''; function editor_append( data ) { put_to_editor = data; $( '#' + mTool.dialog_block ).find( 'iframe' ).each( editor_add ); } function editor_add( data ) { var d = $.browser.msie ? this.document : this.contentDocument; ; d.body.innerHTML = d.body.innerHTML + put_to_editor ; } function editor_on() { $('table.rte iframe').each(function() { var i = this; i.modified = 0; i.limg = ''; i.getDoc = function(){ return d.body.innerHTML; }; i.setDoc = function( x ) { d.body.innerHTML=x; }; i.appDoc = function( x ) { d.body.innerHTML = d.body.innerHTML + x; }; i.kb = function( e ){ if ( e.ctrlKey ){ var k = String.fromCharCode( e.charCode ).toLowerCase(); var c = ''; if ( k==ctrlb ) c = 'bold'; else if ( k == ctrli ) c = 'italic'; else if ( k == ctrlu ) c = 'underline'; if ( c ) { f.focus(); d.execCommand( c, false, null ); f.focus(); e.preventDefault(); e.stopPropagation(); } } }; i.hidepanels = function() { $( $(i).parents('table')[0] ).find( '.panel' ).hide(); }; var f = $.browser.msie ? frames[i.id] : i.contentWindow; var d = $.browser.msie ? f.document : i.contentDocument; d.designMode = 'on'; try { d.execCommand( 'useCSS', false, true ); } catch ( e ) {}; d.open(); d.write( $( '#' + i.id + '-ta' ).text() ); d.close(); if ( !$.browser.msie ) d.addEventListener( 'keypress', i.kb , true ); else d.onmouseup = function() { if ( d.selection != null ) i.rng = d.selection.createRange(); }; $(d).keypress( function() { i.modified = 1; } ); $( 'head' , d ).append('<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><link rel="stylesheet" href="http://mamarama.ru/mamarama/body.css" style="text/css" />'); $( "#" + i.id + "-cmd .cmd" ).each( function() { var t = $( this ); var a = t.attr( 'args' ); var s = $( '#' + i.id + '-' + a ); if ( typeof( a ) == 'string' ) { if ( a == 'image' ) { } if ( a == 'emoticons' ) $(i).parents('table').find('.emot').each( function() { $(this).click( function(){ f.focus(); if ( i.limg != $( this ).children()[0].src ) d.execCommand( 'insertimage' , false , $( this ).children()[0].src ); i.limg = $( this ).children()[0].src; f.focus(); $( ".ediv" ).attr( "display" , "none" ); return false }); }); $('#' + a + '-ok').click( function() { f.focus(); if ( $( '#' + a ).val() == '' || !d.queryCommandEnabled( t.attr('cmd') ) ) { $( '#' + a ).val(''); s.hide(); $(".ediv").attr("display","none"); return; }; if ( t.attr('cmd') == 'insertimage' ) { } else { if ( $.browser.msie ) i.rng.select(); if ( a == 'html' ) i.rng.pasteHTML( $( '#' + a ).val() ); else d.execCommand( t.attr('cmd') , false , $( '#' + a ).val() ); }; f.focus(); $( '#' + a ).val(''); s.hide(); $(".ediv").attr("display","none"); }); }; t.click( function() { i.hidepanels(); if ( typeof( a ) == 'string' ) { s.show(); if ( t.attr( 'args') == 'text' ) { t.attr( 'args', 'wysiwyg' ); if ( $.browser.msie ) { d.body.innerText = d.body.innerHTML; } else { var src = d.createTextNode( d.body.innerHTML ); d.body.innerHTML = ""; d.body.appendChild( src ); } } else if ( t.attr( 'args') == 'wysiwyg' ) { t.attr( 'args', 'text' ); if ( $.browser.msie ) { var o = escape( d.body.innerText ); o = o.replace( "%3CP%3E%0D%0A%3CHR%3E", "%3CHR%3E" ); o = o.replace( "%3CHR%3E%0D%0A%3C/P%3E", "%3CHR%3E" ); d.body.innerHTML = unescape( o ); } else { var src = d.body.ownerDocument.createRange(); src.selectNodeContents( d.body ); d.body.innerHTML = src.toString(); } } } else { var comm = t.attr('cmd'); if ( comm == 'justifyleft' || comm == 'justifycenter' || comm == 'justifyright' ) { } d.execCommand( comm , false , '' ); f.focus(); } i.modified = 1; return false; }) }); }); };
