Skip to content

Commit

Permalink
Added Promise polyfill
Browse files Browse the repository at this point in the history
In `tsconfig.json`
* noImplicitAny
* strictNullChecks
* strictFunctionTypes
* noImplicitReturns
* noImplicitThis
were enabled
  • Loading branch information
xdan committed Jan 13, 2018
1 parent 2e375e8 commit cbf2535
Show file tree
Hide file tree
Showing 56 changed files with 469 additions and 691 deletions.
2 changes: 1 addition & 1 deletion build/jodit.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ type Permissions = {
allowFolderRename: boolean,
allowImageResize: boolean,
allowImageCrop: boolean,
[key: string]: boolean;
};
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"devDependencies": {
"@types/ace": "^0.0.35",
"@types/node": "^7.0.51",
"@types/es6-promise": "^3.3.0",
"autoprefixer": "^6.7.7",
"awesome-typescript-loader": "^3.4.1",
"chai": "^3.5.0",
"classlist-polyfill": "^1.2.0",
"clean-css-loader": "0.0.4",
"compression": "^1.7.1",
"cross-env": "^3.2.4",
Expand Down Expand Up @@ -60,6 +60,11 @@
"webpack": "^3.10.0",
"webpack-dev-middleware": "^1.12.2",
"webpack-dev-server": "^2.9.7",
"webpack-hot-middleware": "^2.21.0"
"webpack-hot-middleware": "^2.21.0",
"classlist-polyfill": "^1.2.0",
"es6-promise": "^4.2.2"
},
"dependencies": {

}
}
11 changes: 5 additions & 6 deletions src/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {Widget} from "./modules/Widget";
import TabsWidget = Widget.TabsWidget;
import ImageSelectorWidget = Widget.ImageSelectorWidget;


/**
* Default Editor's Configuration
**/
Expand Down Expand Up @@ -231,7 +230,7 @@ export class Config {
* console.log(editor.i18n('Type something')) //Начните что-либо вводить
* ```
*/
i18n: object|string = 'en';
i18n: {[key: string] : any} | string = 'en';

/**
* The tabindex global attribute is an integer indicating if the element can take input focus (is focusable), if it should participate to sequential keyboard navigation, and if so, at what position. It can take several values
Expand Down Expand Up @@ -516,9 +515,9 @@ export class Config {
textIcons: boolean = false;
}
Config.prototype.controls = {
about: {
about: <ControlType>{
exec: (editor: Jodit) => {
const dialog = new (require('./modules/Dialog').Dialog)(editor);
const dialog: any = editor.getInstance('Dialog');
dialog.setTitle(editor.i18n('About Jodit'));
dialog.setContent(
'<div class="jodit_about">\
Expand Down Expand Up @@ -551,12 +550,12 @@ Config.prototype.controls = {
tooltip: 'About Jodit',
mode: consts.MODE_SOURCE + consts.MODE_WYSIWYG
},
hr : {
hr : <ControlType>{
command: 'insertHorizontalRule',
tags: ["hr"],
tooltip: "Insert Horizontal Line"
},
image : {
image : <ControlType> {
popup: (editor: Jodit, current: HTMLImageElement|false, self: ControlType, close) => {
const insertImage = (url: string) => {
editor.selection.insertNode(dom('<img src="' + url + '"/>', editor.editorDocument));
Expand Down
47 changes: 24 additions & 23 deletions src/Jodit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
* Copyright 2013-2018 Valeriy Chupurnov xdsoft.net
*/

import {Component}from './modules/Component';
import {Select}from './modules/Selection';
import {Component} from './modules/Component';
import {Select} from './modules/Selection';
import {Toolbar} from './modules/Toolbar';
import {Cookie} from './modules/Cookie';
import {FileBrowser} from './modules/FileBrowser';
import {Uploader} from './modules/Uploader';
import {Dom} from './modules/Dom';
import {EventsNative} from './modules/EventsNative';
import * as consts from './constants';
import {extend, inArray, dom, each, sprintf, defaultLanguage, debounce} from './modules/Helpers';
import * as helper from './modules/Helpers';
import {FileBrowser} from "./modules/FileBrowser";
import {Uploader} from "./modules/Uploader";
import {Config} from "./Config";
import {Dom} from "./modules/Dom";
import {EventsNative} from "./modules/EventsNative";


declare let appVersion: string;

Expand All @@ -39,7 +40,7 @@ export class Jodit extends Component{
static defaultOptions: Config;
static plugins: any = {};
static modules: any = {};
static instances = {};
static instances: {[key: string]: Jodit} = {};
static lang: any = {};

/**
Expand Down Expand Up @@ -128,9 +129,9 @@ export class Jodit extends Component{

toolbar: Toolbar;

private __modulesInstances = {};
private __modulesInstances: {[key: string]: Component} = {};

getInstance(moduleName, options?: object) {
getInstance(moduleName: string, options?: object): Component {
if (Jodit.modules[moduleName] === undefined) {
throw new Error('Need real module name')
}
Expand All @@ -153,17 +154,17 @@ export class Jodit extends Component{

this.events = new EventsNative();

const OptionsDefault = function () {};
const OptionsDefault: any = function () {};
OptionsDefault.prototype = Jodit.defaultOptions;

this.options = <Config>(new OptionsDefault());

if (options !== undefined && typeof options === 'object') {
Object.keys(options).forEach((key) => {
if (typeof Jodit.defaultOptions[key] === 'object' && !Array.isArray(Jodit.defaultOptions[key])) {
this.options[key] = extend(true, {}, Jodit.defaultOptions[key], options[key]);
Object.keys(options).forEach((key: string) => {
if (typeof (<any>Jodit.defaultOptions)[key] === 'object' && !Array.isArray((<any>Jodit.defaultOptions)[key])) {
(<any>this.options)[key] = extend(true, {}, (<any>Jodit.defaultOptions)[key], (<any>options)[key]);
} else {
this.options[key] = options[key];
(<any>this.options)[key] = (<any>options)[key];
}
})
}
Expand All @@ -190,8 +191,8 @@ export class Jodit extends Component{
}


this.selection = this.getInstance('Select');
this.uploader = this.getInstance('Uploader');
this.selection = new Select(this);
this.uploader = new Uploader(this);

this.container = <HTMLDivElement>dom('<div class="jodit_container" />', this.ownerDocument);
this.container.classList.add('jodit_' + (this.options.theme || 'default') + '_theme');
Expand Down Expand Up @@ -296,7 +297,7 @@ export class Jodit extends Component{
}

// proxy events
this.events.on(this.editor, 'keydown keyup keypress mousedown mouseup mousepress paste resize touchstart touchend focus blur', (e: Event) => {
this.events.on(this.editor, 'keydown keyup keypress mousedown mouseup mousepress paste resize touchstart touchend focus blur', (e: Event): false | void => {
if (this.events) {
if (this.events.fire(e.type, e) === false) {
e.preventDefault();
Expand Down Expand Up @@ -374,7 +375,7 @@ export class Jodit extends Component{
delete this.__plugins[pluginName];
});

this.components.forEach((component) => {
this.components.forEach((component: Component) => {
if (component.destruct !== undefined && typeof component.destruct === 'function') {
component.destruct();
}
Expand Down Expand Up @@ -529,8 +530,8 @@ export class Jodit extends Component{
* this.execCommand('formatBlock', 'p'); // will be inserted paragraph
* ```
*/
execCommand(command, second = false, third: null|any = null) {
let result;
execCommand(command: string, second = false, third: null|any = null) {
let result: any;
command = command.toLowerCase();
/**
* Called before any command
Expand Down Expand Up @@ -731,7 +732,7 @@ export class Jodit extends Component{
}

let store,
parse = value => sprintf.apply(this, [value].concat(params));
parse = (value: string): string => sprintf.apply(this, [value].concat(<string[]>params));

if (this.options !== undefined && Jodit.lang[defaultLanguage(this.options.language)] !== undefined) {
store = Jodit.lang[defaultLanguage(this.options.language)];
Expand All @@ -743,8 +744,8 @@ export class Jodit extends Component{
}
}

if (this.options !== undefined && this.options.i18n[defaultLanguage(this.options.language)] !== undefined && this.options.i18n[defaultLanguage(this.options.language)][key]) {
return parse(this.options.i18n[defaultLanguage(this.options.language)][key]);
if (this.options !== undefined && (<any>this.options.i18n)[defaultLanguage(this.options.language)] !== undefined && (<any>this.options.i18n)[defaultLanguage(this.options.language)][key]) {
return parse((<any>this.options.i18n)[defaultLanguage(this.options.language)][key]);
}

if (typeof store[key] === 'string' && store[key]) {
Expand Down
22 changes: 11 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@
import "./styles/bundle.less";
import './polyfills';

import {Toolbar} from './modules/Toolbar';
import {Jodit} from './Jodit';
import {Toolbar} from './modules/Toolbar';


import * as consts from './constants';
import * as Plugins from "./plugins/";
import * as Modules from "./modules/";
import * as Languages from "./langs/";
import * as Icons from "./styles/icons/";
import * as Plugins from "./plugins/index";
import * as Modules from "./modules/index";
import * as Languages from "./langs/index";
import * as Icons from "./styles/icons/index";

import {Config} from "./Config";

// copy constants in Jodit
Object.keys(consts).forEach((key) => {
Jodit[key] = consts[key];
Object.keys(consts).forEach((key: string) => {
(<any>Jodit)[key] = (<any>consts)[key];
});

const esFilter = (key: string): boolean => key !== '__esModule';

// Icons
Object.keys(Icons).filter(esFilter).forEach((key: string) => {
Toolbar.icons[key.replace('_', '-')] = Icons[key];
Toolbar.icons[key.replace('_', '-')] = (<any>Icons)[key];
});
// Modules
Object.keys(Modules).filter(esFilter).forEach((key: string) => {
Jodit.modules[key] = Modules[key];
Jodit.modules[key] = (<any>Modules)[key];
});

//Plugins
Object.keys(Plugins).filter(esFilter).forEach((key: string) => {
Jodit.plugins[key] = Plugins[key];
Jodit.plugins[key] = (<any>Plugins)[key];
});

// Languages
Object.keys(Languages).filter(esFilter).forEach((key: string) => {
Jodit.lang[key] = Languages[key];
Jodit.lang[key] = (<any>Languages)[key];
});

Jodit.defaultOptions = new Config();
Expand Down
17 changes: 8 additions & 9 deletions src/modules/Ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import {Jodit} from "../Jodit"
import {Config} from '../Config'
import {each, extend} from "./Helpers";
import {PseudoPromise} from "./PseudoPromise";
import {Component} from "./Component";

/**
Expand Down Expand Up @@ -72,21 +71,21 @@ Config.prototype.defaultAjaxOptions = <AjaxOptions>{
};

export class Ajax extends Component{
private __buildParams (obj, prefix?: string): string {
if (typeof obj === 'string' || (this.jodit.ownerWindow['FormData'] && obj instanceof this.jodit.ownerWindow['FormData'])) {
return obj;
private __buildParams (obj: string | {[key: string] : string | object} | FormData, prefix?: string): string | FormData{
if (typeof obj === 'string' || ((<any>this.jodit.ownerWindow)['FormData'] && obj instanceof (<any>this.jodit.ownerWindow)['FormData'])) {
return <string | FormData>obj;
}

let str: string[] = [],
p: string,
k: string,
v: string;
v: any;

for (p in obj) {
if (obj.hasOwnProperty(p)) {
k = prefix ? prefix + "[" + p + "]" : p;
v = obj[p];
str.push(typeof v === "object" ? this.__buildParams(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(v));
v = (<{[key: string] : string}>obj)[p];
str.push(typeof v === "object" ? <string>this.__buildParams(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(<string>v));
}
}

Expand Down Expand Up @@ -114,8 +113,8 @@ export class Ajax extends Component{
}
}

send(): PseudoPromise {
return new PseudoPromise((resolve: (this: XMLHttpRequest, resp: object) => any, reject: (error: Error) => any) => {
send(): Promise<any> {
return new Promise((resolve: (this: XMLHttpRequest, resp: object) => any, reject: (error: Error) => any) => {
const __parse = (resp: string) => {
switch (this.options.dataType) {
case 'json':
Expand Down
17 changes: 9 additions & 8 deletions src/modules/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@
*/

import {Jodit} from "../Jodit";
import {EventsNative} from "./EventsNative";

export class Component {
handlers: {};
//handlers: {};

/**
* @property{Jodit} parent
* @property{Jodit} jodit
*/
jodit: Jodit;


constructor(jodit?: Jodit) {
// @ts-ignore: Object is possibly 'undefined'
this.jodit = jodit;

if (jodit && jodit.components) {
jodit.components.push(this);
if (jodit && jodit instanceof Jodit) {
this.jodit = jodit;
if (jodit.components) {
jodit.components.push(this);
}
}
}
destruct() {}
/*
private __scope: any[] = [];
private __scopeNamespace: any = {};
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Cookie extends Component {
if (days) {
date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = '; expires=' + date.toGMTString();
expires = '; expires=' + date.toUTCString();
} else {
expires = '';
}
Expand Down
Loading

0 comments on commit cbf2535

Please sign in to comment.