123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
-
- (function()
- {
-
- CKEDITOR.config.jqueryOverrideVal = typeof CKEDITOR.config.jqueryOverrideVal == 'undefined'
- ? true : CKEDITOR.config.jqueryOverrideVal;
- var jQuery = window.jQuery;
- if ( typeof jQuery == 'undefined' )
- return;
-
- jQuery.extend( jQuery.fn,
-
- {
-
- ckeditorGet: function()
- {
- var instance = this.eq( 0 ).data( 'ckeditorInstance' );
- if ( !instance )
- throw "CKEditor not yet initialized, use ckeditor() with callback.";
- return instance;
- },
-
- ckeditor: function( callback, config )
- {
- if ( !CKEDITOR.env.isCompatible )
- return this;
- if ( !jQuery.isFunction( callback ))
- {
- var tmp = config;
- config = callback;
- callback = tmp;
- }
- config = config || {};
- this.filter( 'textarea, div, p' ).each( function()
- {
- var $element = jQuery( this ),
- editor = $element.data( 'ckeditorInstance' ),
- instanceLock = $element.data( '_ckeditorInstanceLock' ),
- element = this;
- if ( editor && !instanceLock )
- {
- if ( callback )
- callback.apply( editor, [ this ] );
- }
- else if ( !instanceLock )
- {
-
-
- if ( config.autoUpdateElement
- || ( typeof config.autoUpdateElement == 'undefined' && CKEDITOR.config.autoUpdateElement ) )
- {
- config.autoUpdateElementJquery = true;
- }
-
- config.autoUpdateElement = false;
- $element.data( '_ckeditorInstanceLock', true );
-
- editor = CKEDITOR.replace( element, config );
- $element.data( 'ckeditorInstance', editor );
-
- editor.on( 'instanceReady', function( event )
- {
- var editor = event.editor;
- setTimeout( function()
- {
-
- if ( !editor.element )
- {
- setTimeout( arguments.callee, 100 );
- return;
- }
-
- event.removeListener( 'instanceReady', this.callee );
-
- editor.on( 'dataReady', function()
- {
- $element.trigger( 'setData' + '.ckeditor', [ editor ] );
- });
-
- editor.on( 'getData', function( event ) {
- $element.trigger( 'getData' + '.ckeditor', [ editor, event.data ] );
- }, 999 );
-
- editor.on( 'destroy', function()
- {
- $element.trigger( 'destroy.ckeditor', [ editor ] );
- });
-
- if ( editor.config.autoUpdateElementJquery && $element.is( 'textarea' ) && $element.parents( 'form' ).length )
- {
- var onSubmit = function()
- {
- $element.ckeditor( function()
- {
- editor.updateElement();
- });
- };
-
- $element.parents( 'form' ).submit( onSubmit );
-
- $element.parents( 'form' ).bind( 'form-pre-serialize', onSubmit );
-
- $element.bind( 'destroy.ckeditor', function()
- {
- $element.parents( 'form' ).unbind( 'submit', onSubmit );
- $element.parents( 'form' ).unbind( 'form-pre-serialize', onSubmit );
- });
- }
-
- editor.on( 'destroy', function()
- {
- $element.data( 'ckeditorInstance', null );
- });
-
- $element.data( '_ckeditorInstanceLock', null );
-
- $element.trigger( 'instanceReady.ckeditor', [ editor ] );
-
- if ( callback )
- callback.apply( editor, [ element ] );
- }, 0 );
- }, null, null, 9999);
- }
- else
- {
-
- CKEDITOR.on( 'instanceReady', function( event )
- {
- var editor = event.editor;
- setTimeout( function()
- {
-
- if ( !editor.element )
- {
- setTimeout( arguments.callee, 100 );
- return;
- }
- if ( editor.element.$ == element )
- {
-
- if ( callback )
- callback.apply( editor, [ element ] );
- }
- }, 0 );
- }, null, null, 9999);
- }
- });
- return this;
- }
- });
-
- if ( CKEDITOR.config.jqueryOverrideVal )
- {
- jQuery.fn.val = CKEDITOR.tools.override( jQuery.fn.val, function( oldValMethod )
- {
-
- return function( newValue, forceNative )
- {
- var isSetter = typeof newValue != 'undefined',
- result;
- this.each( function()
- {
- var $this = jQuery( this ),
- editor = $this.data( 'ckeditorInstance' );
- if ( !forceNative && $this.is( 'textarea' ) && editor )
- {
- if ( isSetter )
- editor.setData( newValue );
- else
- {
- result = editor.getData();
-
- return null;
- }
- }
- else
- {
- if ( isSetter )
- oldValMethod.call( $this, newValue );
- else
- {
- result = oldValMethod.call( $this );
-
- return null;
- }
- }
- return true;
- });
- return isSetter ? this : result;
- };
- });
- }
- })();
|