Skip to content

Commit ae32d4c

Browse files
committed
Merge branch 't/11480b' into major
2 parents fe3f0e2 + a43dafc commit ae32d4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+7350
-69
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ New Features:
2626
* [#11341](http://dev.ckeditor.com/ticket/11341): [Enhanced Image](http://ckeditor.com/addon/image2) plugin: it's now possible to link any kind of an image.
2727
* [#10202](http://dev.ckeditor.com/ticket/10202): Introduced wildcards support in the [Allowed Content Rules](http://docs.ckeditor.com/#!/guide/dev_allowed_content_rules) format.
2828
* [#10276](http://dev.ckeditor.com/ticket/10276): Introduced blacklisting in the [Allowed Content Filter](http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter).
29+
* [#10480](http://dev.ckeditor.com/ticket/10480): Introduced code snippets with code higlihghting. There are two versions available so far – the default [Code snippet](http://ckeditor.com/addon/codesnippet) which uses the [highlight.js](highlightjs.org) library and the [Code snippet GeSHi](http://ckeditor.com/addon/codesnippetgeshi) which uses the [GeSHi](http://qbnz.com/highlighter/) library.
2930
* [#11737](http://dev.ckeditor.com/ticket/11737): Introduced an option to prevent [filtering](http://docs.ckeditor.com/#!/guide/dev_advanced_content_filter) of element which matches custom criteria (see [`filter.addElementCallback`](http://docs.ckeditor.com/#!/api/CKEDITOR.filter-method-addElementCallback)).
3031
* [#11532](http://dev.ckeditor.com/ticket/11532): Introduced the [`editor.addContentsCss()`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-addContentsCss) method that can be used for adding custom CSS files.
3132
* [#11536](http://dev.ckeditor.com/ticket/11536): Added the [`CKEDITOR.tools.htmlDecode`](http://docs.ckeditor.com/#!/api/CKEDITOR.tools-method-htmlDecode) method for decoding HTML entities.

plugins/ajax/plugin.js

Lines changed: 94 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,73 +20,93 @@
2020
* @singleton
2121
*/
2222
CKEDITOR.ajax = ( function() {
23-
var createXMLHttpRequest = function() {
24-
// In IE, using the native XMLHttpRequest for local files may throw
25-
// "Access is Denied" errors.
26-
if ( !CKEDITOR.env.ie || location.protocol != 'file:' )
27-
try {
28-
return new XMLHttpRequest();
29-
} catch ( e ) {}
30-
31-
try {
32-
return new ActiveXObject( 'Msxml2.XMLHTTP' );
33-
} catch ( e ) {}
23+
function createXMLHttpRequest() {
24+
// In IE, using the native XMLHttpRequest for local files may throw
25+
// "Access is Denied" errors.
26+
if ( !CKEDITOR.env.ie || location.protocol != 'file:' )
3427
try {
35-
return new ActiveXObject( 'Microsoft.XMLHTTP' );
36-
} catch ( e ) {}
28+
return new XMLHttpRequest();
29+
} catch ( e ) {}
30+
31+
try {
32+
return new ActiveXObject( 'Msxml2.XMLHTTP' );
33+
} catch ( e ) {}
34+
try {
35+
return new ActiveXObject( 'Microsoft.XMLHTTP' );
36+
} catch ( e ) {}
37+
38+
return null;
39+
}
40+
41+
function checkStatus( xhr ) {
42+
// HTTP Status Codes:
43+
// 2xx : Success
44+
// 304 : Not Modified
45+
// 0 : Returned when running locally (file://)
46+
// 1223 : IE may change 204 to 1223 (see http://dev.jquery.com/ticket/1450)
47+
48+
return ( xhr.readyState == 4 && ( ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status === 0 || xhr.status == 1223 ) );
49+
}
50+
51+
function getResponseText( xhr ) {
52+
if ( checkStatus( xhr ) )
53+
return xhr.responseText;
54+
return null;
55+
}
3756

38-
return null;
39-
};
57+
var getResponseXml = function( xhr ) {
58+
if ( checkStatus( xhr ) ) {
59+
var xml = xhr.responseXML;
60+
return new CKEDITOR.xml( xml && xml.firstChild ? xml : xhr.responseText );
61+
}
62+
return null;
63+
}
4064

41-
var checkStatus = function( xhr ) {
42-
// HTTP Status Codes:
43-
// 2xx : Success
44-
// 304 : Not Modified
45-
// 0 : Returned when running locally (file://)
46-
// 1223 : IE may change 204 to 1223 (see http://dev.jquery.com/ticket/1450)
65+
function load( url, callback, getResponseFn ) {
66+
var async = !!callback;
4767

48-
return ( xhr.readyState == 4 && ( ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status === 0 || xhr.status == 1223 ) );
49-
};
68+
var xhr = createXMLHttpRequest();
5069

51-
var getResponseText = function( xhr ) {
52-
if ( checkStatus( xhr ) )
53-
return xhr.responseText;
70+
if ( !xhr )
5471
return null;
55-
};
5672

57-
var getResponseXml = function( xhr ) {
58-
if ( checkStatus( xhr ) ) {
59-
var xml = xhr.responseXML;
60-
return new CKEDITOR.xml( xml && xml.firstChild ? xml : xhr.responseText );
61-
}
62-
return null;
63-
};
73+
xhr.open( 'GET', url, async );
6474

65-
var load = function( url, callback, getResponseFn ) {
66-
var async = !!callback;
75+
if ( async ) {
76+
// TODO: perform leak checks on this closure.
77+
xhr.onreadystatechange = function() {
78+
if ( xhr.readyState == 4 ) {
79+
callback( getResponseFn( xhr ) );
80+
xhr = null;
81+
}
82+
};
83+
}
6784

68-
var xhr = createXMLHttpRequest();
85+
xhr.send( null );
6986

70-
if ( !xhr )
71-
return null;
87+
return async ? '' : getResponseFn( xhr );
88+
}
7289

73-
xhr.open( 'GET', url, async );
90+
function post( url, data, contentType, callback, getResponseFn ) {
91+
var xhr = createXMLHttpRequest();
7492

75-
if ( async ) {
76-
// TODO: perform leak checks on this closure.
77-
xhr.onreadystatechange = function() {
78-
if ( xhr.readyState == 4 ) {
79-
callback( getResponseFn( xhr ) );
80-
xhr = null;
81-
}
82-
};
83-
}
93+
if ( !xhr )
94+
return null;
8495

85-
xhr.send( null );
96+
xhr.open( 'POST', url, true );
8697

87-
return async ? '' : getResponseFn( xhr );
98+
xhr.onreadystatechange = function() {
99+
if ( xhr.readyState == 4 ) {
100+
callback( getResponseFn( xhr ) );
101+
xhr = null;
102+
}
88103
};
89104

105+
xhr.setRequestHeader( 'Content-type', contentType || 'application/x-www-form-urlencoded; charset=UTF-8' );
106+
107+
xhr.send( data );
108+
}
109+
90110
return {
91111
/**
92112
* Loads data from an URL as plain text.
@@ -111,6 +131,29 @@
111131
return load( url, callback, getResponseText );
112132
},
113133

134+
/**
135+
* Creates asynchronous POST `XMLHttpRequest` of given `url`, `data` and optional `contentType`.
136+
* Once the request is done, regardless if successful or not, `callback` is called
137+
* with `XMLHttpRequest#responseText` or `null` as an argument.
138+
*
139+
* CKEDITOR.ajax.post( 'url/post.php', 'foo=bar', null, function( data ) {
140+
* console.log( data );
141+
* } );
142+
*
143+
* CKEDITOR.ajax.post( 'url/post.php', JSON.stringify( { foo: 'bar' } ), 'application/json', function( data ) {
144+
* console.log( data );
145+
* } );
146+
*
147+
* @param {String} url URL of the request.
148+
* @param {String/Object/Array} data Data passed to `XMLHttpRequest#send`.
149+
* @param {String} [contentType='application/x-www-form-urlencoded; charset=UTF-8'] A value of `Content-type` header.
150+
* @param {Function} callback A callback executed asynchronously with `XMLHttpRequest#responseText` or `null` as an argument,
151+
* depending on `status` of the request.
152+
*/
153+
post: function( url, data, contentType, callback ) {
154+
return post( url, data, contentType, callback, getResponseText );
155+
},
156+
114157
/**
115158
* Loads data from an URL as XML.
116159
*
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* @license Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md or http://ckeditor.com/license
4+
*/
5+
6+
'use strict';
7+
8+
( function() {
9+
CKEDITOR.dialog.add( 'codeSnippet', function( editor ) {
10+
var snippetLangs = editor._.codesnippet.langs,
11+
lang = editor.lang.codesnippet,
12+
clientHeight = document.documentElement.clientHeight,
13+
tabulationString = editor.config.codesnippet_tabulation || ' ',
14+
langSelectItems = [],
15+
langSelectDefaultValue,
16+
snippetLangId;
17+
18+
for ( snippetLangId in snippetLangs )
19+
langSelectItems.push( [ snippetLangs[ snippetLangId ], snippetLangId ] );
20+
21+
if ( langSelectItems.length )
22+
langSelectDefaultValue = langSelectItems[ 0 ][ 1 ];
23+
24+
// Size adjustments.
25+
var size = CKEDITOR.document.getWindow().getViewPaneSize(),
26+
// Make it maximum 800px wide, but still fully visible in the viewport.
27+
width = Math.min( size.width - 70, 800 ),
28+
// Make it use 2/3 of the viewport height.
29+
height = size.height / 1.5;
30+
// Low resolution settings.
31+
if ( clientHeight < 650 )
32+
height = clientHeight - 220;
33+
34+
return {
35+
title: lang.title,
36+
minHeight: 200,
37+
resizable: CKEDITOR.DIALOG_RESIZE_NONE,
38+
contents: [
39+
{
40+
id: 'info',
41+
elements: [
42+
{
43+
id: 'lang',
44+
type: 'select',
45+
label: lang.language,
46+
items: langSelectItems,
47+
'default': langSelectDefaultValue,
48+
setup: function( widget ) {
49+
this.setValue( widget.ready ? widget.data.lang : '' );
50+
51+
// The only way to have an empty select value in Firefox is
52+
// to set a negative selectedIndex.
53+
if ( CKEDITOR.env.gecko && ( !widget.data.lang || !widget.ready ) )
54+
this.getInputElement().$.selectedIndex = -1;
55+
},
56+
commit: function( widget ) {
57+
widget.setData( 'lang', this.getValue() );
58+
}
59+
},
60+
{
61+
id: 'code',
62+
type: 'textarea',
63+
label: lang.codeContents,
64+
setup: function( widget ) {
65+
this.setValue( widget.data.code );
66+
},
67+
commit: function( widget ) {
68+
widget.setData( 'code', this.getValue() );
69+
},
70+
required: true,
71+
validate: CKEDITOR.dialog.validate.notEmpty( lang.emptySnippetError ),
72+
inputStyle: 'cursor:auto;' +
73+
'width:' + width + 'px;' +
74+
'height:' + height + 'px;' +
75+
'tab-size:4;' +
76+
'text-align:left;',
77+
'class': 'cke_source'
78+
}
79+
]
80+
}
81+
]
82+
};
83+
} );
84+
}() );
597 Bytes
Loading
1.84 KB
Loading

plugins/codesnippet/lang/en.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @license Copyright (c) 2003-2014, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md or http://ckeditor.com/license
4+
*/
5+
6+
CKEDITOR.plugins.setLang( 'codesnippet', 'en', {
7+
button: 'Insert code snippet',
8+
codeContents: 'Code contents',
9+
emptySnippetError: 'Snippet can\'t be empty.',
10+
language: 'Language',
11+
title: 'Code snippet'
12+
} );

0 commit comments

Comments
 (0)