2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
8 var eventNameList = [ 'click', 'keydown', 'mousedown', 'keypress', 'mouseover', 'mouseout' ];
\r
10 // Inline event callbacks assigned via innerHTML/outerHTML, such as
\r
11 // onclick/onmouseover, are ignored in AIR.
\r
12 // Use DOM2 event listeners to substitue inline handlers instead.
\r
13 function convertInlineHandlers( container )
\r
15 // TODO: document.querySelectorAll is not supported in AIR.
\r
16 var children = container.getElementsByTag( '*' ),
\r
17 count = children.count(),
\r
20 for ( var i = 0; i < count; i++ )
\r
22 child = children.getItem( i );
\r
26 for ( var j = 0; j < eventNameList.length; j++ )
\r
28 (function( eventName )
\r
30 var inlineEventHandler = node.getAttribute( 'on' + eventName );
\r
31 if ( node.hasAttribute( 'on' + eventName ) )
\r
33 node.removeAttribute( 'on' + eventName );
\r
34 node.on( eventName, function( evt )
\r
36 var callFunc = /(return\s*)?CKEDITOR\.tools\.callFunction\(([^)]+)\)/.exec( inlineEventHandler ),
\r
37 hasReturn = callFunc && callFunc[ 1 ],
\r
38 callFuncArgs = callFunc && callFunc[ 2 ].split( ',' ),
\r
39 preventDefault = /return false;/.test( inlineEventHandler );
\r
43 var nums = callFuncArgs.length,
\r
46 for ( var i = 0; i < nums; i++ )
\r
48 // Trim spaces around param.
\r
49 callFuncArgs[ i ] = argName = CKEDITOR.tools.trim( callFuncArgs[ i ] );
\r
51 // String form param.
\r
52 var strPattern = argName.match( /^(["'])([^"']*?)\1$/ );
\r
55 callFuncArgs[ i ] = strPattern[ 2 ];
\r
59 // Integer form param.
\r
60 if ( argName.match( /\d+/ ) )
\r
62 callFuncArgs[ i ] = parseInt( argName, 10 );
\r
66 // Speical variables.
\r
70 callFuncArgs[ i ] = node.$;
\r
73 callFuncArgs[ i ] = evt.data.$;
\r
76 callFuncArgs [ i ] = null;
\r
81 var retval = CKEDITOR.tools.callFunction.apply( window, callFuncArgs );
\r
82 if ( hasReturn && retval === false )
\r
86 if ( preventDefault )
\r
87 evt.data.preventDefault();
\r
90 })( eventNameList[ j ] );
\r
96 CKEDITOR.plugins.add( 'adobeair',
\r
98 init : function( editor )
\r
100 if ( !CKEDITOR.env.air )
\r
103 // Body doesn't get default margin on AIR.
\r
104 editor.addCss( 'body { padding: 8px }' );
\r
106 editor.on( 'uiReady', function()
\r
108 convertInlineHandlers( editor.container );
\r
110 if ( editor.sharedSpaces )
\r
112 for ( var space in editor.sharedSpaces )
\r
113 convertInlineHandlers( editor.sharedSpaces[ space ] );
\r
116 editor.on( 'elementsPathUpdate', function( evt ) { convertInlineHandlers( evt.data.space ); } );
\r
119 editor.on( 'contentDom', function()
\r
121 // Hyperlinks are enabled in editable documents in Adobe
\r
122 // AIR. Prevent their click behavior.
\r
123 editor.document.on( 'click', function( ev )
\r
125 ev.data.preventDefault( true );
\r
131 CKEDITOR.ui.on( 'ready', function( evt )
\r
134 // richcombo, panelbutton and menu
\r
137 var panel = ui._.panel._.panel,
\r
142 // Adding dom event listeners off-line are not supported in AIR,
\r
143 // waiting for panel iframe loaded.
\r
144 if ( !panel.isLoaded )
\r
146 setTimeout( arguments.callee, 30 );
\r
149 holder = panel._.holder;
\r
150 convertInlineHandlers( holder );
\r
153 else if ( ui instanceof CKEDITOR.dialog )
\r
154 convertInlineHandlers( ui._.element );
\r
158 CKEDITOR.dom.document.prototype.write = CKEDITOR.tools.override( CKEDITOR.dom.document.prototype.write,
\r
159 function( original_write )
\r
161 function appendElement( parent, tagName, fullTag, text )
\r
163 var node = parent.append( tagName ),
\r
164 attrs = CKEDITOR.htmlParser.fragment.fromHtml( fullTag ).children[ 0 ].attributes;
\r
165 attrs && node.setAttributes( attrs );
\r
166 text && node.append( parent.getDocument().createText( text ) );
\r
169 return function( html, mode )
\r
171 // document.write() or document.writeln() fail silently after
\r
172 // the page load event in Adobe AIR.
\r
173 // DOM manipulation could be used instead.
\r
174 if ( this.getBody() )
\r
176 // We're taking the below extra work only because innerHTML
\r
177 // on <html> element doesn't work as expected.
\r
179 head = this.getHead();
\r
181 // Create style nodes for inline css. ( <style> content doesn't applied when setting via innerHTML )
\r
182 html = html.replace( /(<style[^>]*>)([\s\S]*?)<\/style>/gi,
\r
183 function ( match, startTag, styleText )
\r
185 appendElement( head, 'style', startTag, styleText );
\r
189 html = html.replace( /<base\b[^>]*\/>/i,
\r
192 appendElement( head, 'base', match );
\r
196 html = html.replace( /<title>([\s\S]*)<\/title>/i,
\r
197 function( match, title )
\r
199 doc.$.title = title;
\r
203 // Move the rest of head stuff.
\r
204 html = html.replace( /<head>([\s\S]*)<\/head>/i,
\r
205 function( headHtml )
\r
207 // Inject the <head> HTML inside a <div>.
\r
208 // Do that before getDocumentHead because WebKit moves
\r
209 // <link css> elements to the <head> at this point.
\r
210 var div = new CKEDITOR.dom.element( 'div', doc );
\r
211 div.setHtml( headHtml );
\r
212 // Move the <div> nodes to <head>.
\r
213 div.moveChildren( head );
\r
217 html.replace( /(<body[^>]*>)([\s\S]*)(?=$|<\/body>)/i,
\r
218 function( match, startTag, innerHTML )
\r
220 doc.getBody().setHtml( innerHTML );
\r
221 var attrs = CKEDITOR.htmlParser.fragment.fromHtml( startTag ).children[ 0 ].attributes;
\r
222 attrs && doc.getBody().setAttributes( attrs );
\r
226 original_write.apply( this, arguments );
\r