-
Notifications
You must be signed in to change notification settings - Fork 96
/
paste.js
executable file
·167 lines (149 loc) · 4.85 KB
/
paste.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
CKEDITOR.dialog.add( 'paste', function( editor )
{
var isCustomDomain = CKEDITOR.env.isCustomDomain();
return {
title : editor.lang.clipboard.title,
minWidth : CKEDITOR.env.ie && CKEDITOR.env.quirks ? 370 : 350,
minHeight : CKEDITOR.env.quirks ? 250 : 245,
htmlToLoad : '<!doctype html><script type="text/javascript">'
+ 'window.onload = function()'
+ '{'
+ 'if ( ' + CKEDITOR.env.ie + ' ) '
+ 'document.body.contentEditable = "true";'
+ 'else '
+ 'document.designMode = "on";'
+ 'var iframe = new window.parent.CKEDITOR.dom.element( frameElement );'
+ 'var dialog = iframe.getCustomData( "dialog" );'
+ ''
+ 'iframe.getFrameDocument().on( "keydown", function( e )\
{\
if ( e.data.getKeystroke() == 27 )\
dialog.hide();\
});'
+ '};'
+ '</script><style>body { margin: 3px; height: 95%; } </style><body></body>',
onShow : function()
{
if ( CKEDITOR.env.ie )
this.getParentEditor().document.getBody().$.contentEditable = 'false';
// FIREFOX BUG: Force the browser to render the dialog to make the to-be-
// inserted iframe editable. (#3366)
this.parts.dialog.$.offsetHeight;
var container = this.getContentElement( 'general', 'editing_area' ).getElement(),
iframe = CKEDITOR.dom.element.createFromHtml( '<iframe src="javascript:void(0)" frameborder="0" allowtransparency="1"></iframe>' );
var lang = this.getParentEditor().lang;
iframe.setStyles(
{
width : '346px',
height : '130px',
'background-color' : 'white',
border : '1px solid black'
} );
iframe.setCustomData( 'dialog', this );
var accTitle = lang.editorTitle.replace( '%1', lang.clipboard.title );
if ( CKEDITOR.env.ie )
container.setHtml( '<legend style="position:absolute;top:-1000000px;left:-1000000px;">'
+ CKEDITOR.tools.htmlEncode( accTitle )
+ '</legend>' );
else
{
container.setHtml( '' );
container.setAttributes(
{
role : 'region',
title : accTitle
} );
iframe.setAttributes(
{
role : 'region',
title : ' '
} );
}
container.append( iframe );
if ( CKEDITOR.env.ie )
container.setStyle( 'height', ( iframe.$.offsetHeight + 2 ) + 'px' );
if ( isCustomDomain )
{
CKEDITOR._cke_htmlToLoad = this.definition.htmlToLoad;
iframe.setAttribute( 'src',
'javascript:void( (function(){' +
'document.open();' +
'document.domain="' + document.domain + '";' +
'document.write( window.parent.CKEDITOR._cke_htmlToLoad );' +
'delete window.parent.CKEDITOR._cke_htmlToLoad;' +
'document.close();' +
'})() )' );
}
else
{
var doc = iframe.$.contentWindow.document;
doc.open();
doc.write( this.definition.htmlToLoad );
doc.close();
}
},
onHide : function()
{
if ( CKEDITOR.env.ie )
this.getParentEditor().document.getBody().$.contentEditable = 'true';
},
onLoad : function()
{
if ( ( CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat ) && editor.lang.dir == 'rtl' )
this.parts.contents.setStyle( 'overflow', 'hidden' );
},
onOk : function()
{
var container = this.getContentElement( 'general', 'editing_area' ).getElement(),
iframe = container.getElementsByTag( 'iframe' ).getItem( 0 ),
editor = this.getParentEditor(),
html = iframe.$.contentWindow.document.body.innerHTML;
setTimeout( function(){
editor.fire( 'paste', { 'html' : html } );
}, 0 );
},
contents : [
{
id : 'general',
label : editor.lang.common.generalTab,
elements : [
{
type : 'html',
id : 'securityMsg',
html : '<div style="white-space:normal;width:340px;">' + editor.lang.clipboard.securityMsg + '</div>'
},
{
type : 'html',
id : 'pasteMsg',
html : '<div style="white-space:normal;width:340px;">'+editor.lang.clipboard.pasteMsg +'</div>'
},
{
type : 'html',
id : 'editing_area',
style : 'width: 100%; height: 100%;',
html : '<fieldset></fieldset>',
focus : function()
{
var div = this.getElement();
var iframe = div.getElementsByTag( 'iframe' );
if ( iframe.count() < 1 )
return;
iframe = iframe.getItem( 0 );
// #3291 : JAWS needs the 500ms delay to detect that the editor iframe
// iframe is no longer editable. So that it will put the focus into the
// Paste from Word dialog's editable area instead.
setTimeout( function()
{
iframe.$.contentWindow.focus();
}, 500 );
}
}
]
}
]
};
});