Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 4120de8

Browse files
committed
Internal: Initial commit.
0 parents  commit 4120de8

18 files changed

+635
-0
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Configurations to normalize the IDE behavior.
2+
# http://editorconfig.org/
3+
4+
root = true
5+
6+
[*]
7+
indent_style = tab
8+
tab_width = 4
9+
charset = utf-8
10+
end_of_line = lf
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true

.eslintrc.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
/* eslint-env node */
7+
8+
'use strict';
9+
10+
module.exports = {
11+
extends: 'ckeditor5'
12+
};

.gitattributes

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
* text=auto
2+
3+
*.htaccess eol=lf
4+
*.cgi eol=lf
5+
*.sh eol=lf
6+
7+
*.css text
8+
*.htm text
9+
*.html text
10+
*.js text
11+
*.json text
12+
*.php text
13+
*.txt text
14+
*.md text
15+
16+
*.png -text
17+
*.gif -text
18+
*.jpg -text

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# These files will be ignored by Git and by our linting tools:
2+
# gulp lint
3+
# gulp lint-staged
4+
5+
node_modules/

.travis.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
sudo: required
2+
dist: trusty
3+
addons:
4+
apt:
5+
sources:
6+
- google-chrome
7+
packages:
8+
- google-chrome-stable
9+
language: node_js
10+
node_js:
11+
- "6"
12+
cache:
13+
- node_modules
14+
before_install:
15+
- export DISPLAY=:99.0
16+
- sh -e /etc/init.d/xvfb start
17+
install:
18+
- npm install @ckeditor/ckeditor5-dev-tests
19+
- ckeditor5-dev-tests-install-dependencies
20+
script:
21+
- ckeditor5-dev-tests-travis
22+
after_success:
23+
- codeclimate-test-reporter < coverage/lcov.info
24+
- ckeditor5-dev-tests-save-revision

CONTRIBUTING.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Contributing
2+
========================================
3+
4+
Information about contributing can be found on the following page: <https://github.com/ckeditor/ckeditor5/blob/master/CONTRIBUTING.md>.

LICENSE.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Software License Agreement
2+
==========================
3+
4+
**CKEditor 5 Easy Image**https://github.com/ckeditor/ckeditor5-easy-image <br>
5+
Copyright (c) 2003-2017, [CKSource](http://cksource.com) Frederico Knabben. All rights reserved.
6+
7+
Licensed under the terms of any of the following licenses at your choice:
8+
9+
* [GNU General Public License Version 2 or later (the "GPL")](http://www.gnu.org/licenses/gpl.html)
10+
* [GNU Lesser General Public License Version 2.1 or later (the "LGPL")](http://www.gnu.org/licenses/lgpl.html)
11+
* [Mozilla Public License Version 1.1 or later (the "MPL")](http://www.mozilla.org/MPL/MPL-1.1.html)
12+
13+
You are not required to, but if you want to explicitly declare the license you have chosen to be bound to when using, reproducing, modifying and distributing this software, just include a text file titled "legal.txt" in your version of this software, indicating your license choice. In any case, your choice will not restrict any recipient of your version of this software to use, reproduce, modify and distribute this software under any of the above licenses.
14+
15+
Sources of Intellectual Property Included in CKEditor
16+
-----------------------------------------------------
17+
18+
Where not otherwise indicated, all CKEditor content is authored by CKSource engineers and consists of CKSource-owned intellectual property. In some specific instances, CKEditor will incorporate work done by developers outside of CKSource with their express permission.
19+
20+
Trademarks
21+
----------
22+
23+
**CKEditor** is a trademark of [CKSource](http://cksource.com) Frederico Knabben. All other brand and product names are trademarks, registered trademarks or service marks of their respective holders.

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CKEditor 5 Easy Image with Cloud Services
2+
=========================================
3+
4+
[![Join the chat at https://gitter.im/ckeditor/ckeditor5](https://badges.gitter.im/ckeditor/ckeditor5.svg)](https://gitter.im/ckeditor/ckeditor5?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5+
[![npm version](https://badge.fury.io/js/%40ckeditor%2Fckeditor5-easy-image.svg)](https://www.npmjs.com/package/@ckeditor/ckeditor5-easy-image)
6+
[![Build Status](https://travis-ci.org/ckeditor/ckeditor5-easy-image.svg?branch=master)](https://travis-ci.org/ckeditor/ckeditor5-easy-image)
7+
[![Test Coverage](https://codeclimate.com/github/ckeditor/ckeditor5-easy-image/badges/coverage.svg)](https://codeclimate.com/github/ckeditor/ckeditor5-easy-image/coverage)
8+
[![Dependency Status](https://david-dm.org/ckeditor/ckeditor5-easy-image/status.svg)](https://david-dm.org/ckeditor/ckeditor5-easy-image)
9+
[![devDependency Status](https://david-dm.org/ckeditor/ckeditor5-easy-image/dev-status.svg)](https://david-dm.org/ckeditor/ckeditor5-easy-image?type=dev)
10+
11+
Easy Image feature for CKEditor 5. Plugin which lets you easily insert images into the editor and integrates automatically with CKEditor Cloud Services. More information about the project can be found at the following URL: <https://github.com/ckeditor/ckeditor5-easy-image>.
12+
13+
## License
14+
15+
Licensed under the GPL, LGPL and MPL licenses, at your choice. For full details about the license, please check the `LICENSE.md` file.

gulpfile.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
/* eslint-env node */
7+
8+
'use strict';
9+
10+
const gulp = require( 'gulp' );
11+
const ckeditor5Lint = require( '@ckeditor/ckeditor5-dev-lint' );
12+
const options = {
13+
// Files ignored by `gulp lint` task.
14+
// Files from .gitignore will be added automatically during task execution.
15+
ignoredFiles: [
16+
'src/lib/**'
17+
]
18+
};
19+
20+
gulp.task( 'lint', () => ckeditor5Lint.lint( options ) );
21+
gulp.task( 'lint-staged', () => ckeditor5Lint.lintStaged( options ) );
22+
gulp.task( 'pre-commit', [ 'lint-staged' ] );

package.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "@ckeditor/ckeditor5-easy-image",
3+
"version": "0.0.1",
4+
"description": "Easy Image feature for CKEditor 5.",
5+
"keywords": [
6+
"ckeditor5",
7+
"ckeditor5-feature"
8+
],
9+
"dependencies": {
10+
"@ckeditor/ckeditor-cloudservices-core": "^0.1.0",
11+
"@ckeditor/ckeditor5-core": "^0.9.0",
12+
"@ckeditor/ckeditor5-image": "^0.7.0",
13+
"@ckeditor/ckeditor5-upload": "^0.2.0"
14+
},
15+
"devDependencies": {
16+
"@ckeditor/ckeditor5-dev-lint": "^3.1.0",
17+
"@ckeditor/ckeditor5-editor-classic": "^0.8.0",
18+
"@ckeditor/ckeditor5-paragraph": "^0.9.0",
19+
"@ckeditor/ckeditor5-utils": "^0.10.0",
20+
"eslint-config-ckeditor5": "^1.0.6",
21+
"gulp": "^3.9.1",
22+
"guppy-pre-commit": "^0.4.0"
23+
},
24+
"engines": {
25+
"node": ">=6.0.0",
26+
"npm": ">=3.0.0"
27+
},
28+
"author": "CKSource (http://cksource.com/)",
29+
"license": "(GPL-2.0 OR LGPL-2.1 OR MPL-1.1)",
30+
"homepage": "https://ckeditor5.github.io",
31+
"bugs": "https://github.com/ckeditor/ckeditor5-easy-image/issues",
32+
"repository": {
33+
"type": "git",
34+
"url": "https://github.com/ckeditor/ckeditor5-easy-image.git"
35+
},
36+
"files": [
37+
"lang",
38+
"src",
39+
"theme"
40+
]
41+
}

src/cloudservicesuploadadapter.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
/**
7+
* @module easy-image/cloudservicesuploadadapter
8+
*/
9+
10+
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
11+
import FileRepository from '@ckeditor/ckeditor5-upload/src/filerepository';
12+
import UploadGateway from '@ckeditor/ckeditor-cloudservices-core/src/uploadgateway/uploadgateway';
13+
14+
export default class CloudServicesUploadAdapter extends Plugin {
15+
static get requires() {
16+
return [ FileRepository ];
17+
}
18+
19+
init() {
20+
const editor = this.editor;
21+
const config = editor.config;
22+
23+
const token = config.get( 'cloudServices.token' );
24+
const uploadUrl = config.get( 'cloudServices.uploadUrl' );
25+
26+
// Application is in offline mode.
27+
if ( !token || !uploadUrl ) {
28+
return;
29+
}
30+
31+
this._uploadGateway = new CloudServicesUploadAdapter._UploadGateway( token, uploadUrl );
32+
33+
editor.plugins.get( FileRepository ).createAdapter = loader => {
34+
return new Adapter( this._uploadGateway, loader );
35+
};
36+
}
37+
}
38+
39+
class Adapter {
40+
constructor( uploadGateway, loader ) {
41+
this.uploadGateway = uploadGateway;
42+
43+
this.loader = loader;
44+
}
45+
46+
upload() {
47+
this.fileUploader = this.uploadGateway.upload( this.loader.file );
48+
49+
this.fileUploader.on( 'progress', ( evt, data ) => {
50+
this.loader.uploadTotal = data.total;
51+
this.loader.uploaded = data.uploaded;
52+
} );
53+
54+
return this.fileUploader.send();
55+
}
56+
57+
abort() {
58+
this.fileUploader.abort();
59+
}
60+
}
61+
62+
// Store the API in static property to easily overwrite it in tests.
63+
// Too bad dependency injection does not work in Webpack + ES 6 (const) + Babel.
64+
CloudServicesUploadAdapter._UploadGateway = UploadGateway;

src/easyimage.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
/**
7+
* @module easy-image/easyimage
8+
*/
9+
10+
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
11+
import CloudServicesUploadAdapter from './cloudservicesuploadadapter';
12+
import Image from '@ckeditor/ckeditor5-image/src/image';
13+
import ImageUpload from '@ckeditor/ckeditor5-upload/src/imageupload';
14+
15+
export default class EasyImage extends Plugin {
16+
/**
17+
* @inheritDoc
18+
*/
19+
static get requires() {
20+
return [
21+
CloudServicesUploadAdapter,
22+
Image,
23+
ImageUpload
24+
];
25+
}
26+
27+
/**
28+
* @inheritDoc
29+
*/
30+
static get pluginName() {
31+
return 'EasyImage';
32+
}
33+
}

tests/_utils/uploadgatewaymock.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3+
* For licensing, see LICENSE.md.
4+
*/
5+
6+
import mix from '@ckeditor/ckeditor5-utils/src/mix';
7+
import EmitterMixin from '@ckeditor/ckeditor5-utils/src/emittermixin';
8+
9+
export default class UploadGatewayMock {
10+
constructor( token, uploadUrl ) {
11+
UploadGatewayMock.lastToken = token;
12+
UploadGatewayMock.lastUploadUrl = uploadUrl;
13+
}
14+
15+
upload() {
16+
this.lastFileUploader = new FileUploader();
17+
18+
return this.lastFileUploader;
19+
}
20+
21+
resolveLastUpload() {
22+
this.lastFileUploader._resolve( { default: 'http://image.mock.url/' } );
23+
}
24+
}
25+
26+
class FileUploader {
27+
onProgress( callback ) {
28+
this.on( 'progress', ( event, data ) => callback( data ) );
29+
30+
return this;
31+
}
32+
33+
onError( callback ) {
34+
this.once( 'error', ( event, data ) => callback( data ) );
35+
36+
return this;
37+
}
38+
39+
send() {
40+
return new Promise( resolve => {
41+
this._resolve = resolve;
42+
} );
43+
}
44+
45+
abort() {
46+
this.aborted = true;
47+
}
48+
}
49+
50+
mix( FileUploader, EmitterMixin );

0 commit comments

Comments
 (0)