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