Skip to content

Commit

Permalink
Fixed visibiliti for tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
xdan committed Mar 12, 2018
1 parent ff91810 commit 6d4dff3
Show file tree
Hide file tree
Showing 10 changed files with 218 additions and 47 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"newversiongit": "git add --all && git commit -m \"New version %npm_package_version%. Read more https://github.com/xdan/jodit/releases/tag/%npm_package_version% \" && git tag %npm_package_version% && git push --tags origin HEAD:master",
"start": "node server.js",
"build": "rm -f build/* && cross-env NODE_ENV=production webpack --progress",
"test": "karma start --browsers Firefox karma.conf.js --single-run"
"test": "karma start --browsers Firefox karma.conf.js --single-run",
"jodit": "cd ../jodit-angular/ && npm run newversion && cd ../jodit-joomla && npm run newversion"
},
"repository": {
"type": "git",
Expand All @@ -29,7 +30,7 @@
"devDependencies": {
"@types/ace": "^0.0.35",
"@types/es6-promise": "^3.3.0",
"@types/node": "^7.0.55",
"@types/node": "^7.0.56",
"autoprefixer": "^6.7.7",
"awesome-typescript-loader": "^3.4.1",
"chai": "^3.5.0",
Expand All @@ -51,7 +52,7 @@
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.9",
"less": "^2.7.3",
"less-loader": "^4.0.5",
"less-loader": "^4.1.0",
"mocha": "^3.4.2",
"optimize-css-assets-webpack-plugin": "^3.2.0",
"postcss-loader": "^2.1.0",
Expand All @@ -63,7 +64,7 @@
"webpack": "^3.11.0",
"webpack-dev-middleware": "^1.12.2",
"webpack-dev-server": "^2.11.1",
"webpack-hot-middleware": "^2.21.0"
"webpack-hot-middleware": "^2.21.2"
},
"dependencies": {}
}
8 changes: 6 additions & 2 deletions src/modules/Selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ export class Select extends Component{
* parent.selection.insertHTML('<img src="image.png"/>');
* ```
*/
insertHTML(html: number|string|Node) {
insertHTML(html: number | string | Node) {
if (html === '') {
return;
}
Expand All @@ -439,7 +439,7 @@ export class Select extends Component{
lastChild: Node|null,
lastEditorElement: Node|null;

if (!this.isFocused()) {
if (!this.isFocused() && this.jodit.isEditorMode()) {
this.focus();
}

Expand All @@ -449,6 +449,10 @@ export class Select extends Component{
node.appendChild(<Node>html);
}

if (!this.jodit.isEditorMode() && this.jodit.events.fire('insertHTML', node.innerHTML) === false) {
return;
}

lastChild = node.lastChild;

while (node.firstChild) {
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/formatBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {Dom} from "../modules/Dom";
import * as consts from '../constants';
import {Config} from "../Config";
import {ToolbarButton, ControlType} from "../modules/ToolbarCollection";
import {markerInfo} from "../modules/Selection";


Config.prototype.controls.paragraph = <ControlType>{
Expand Down Expand Up @@ -89,8 +90,8 @@ export function formatBlock(editor: Jodit) {
let work: boolean = false;

editor.selection.eachSelection((current: Node): false | void => {
const selectionInfo = editor.selection.save();
let currentBox: HTMLElement|false = current ? <HTMLElement>Dom.up(current, Dom.isBlock, editor.editor) : false;
const selectionInfo: markerInfo[] = editor.selection.save();
let currentBox: HTMLElement | false = current ? <HTMLElement>Dom.up(current, Dom.isBlock, editor.editor) : false;

if (!currentBox && current) {
currentBox = Dom.wrap(current, editor.options.enter, editor);
Expand Down
29 changes: 29 additions & 0 deletions src/plugins/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@ export class source extends Component {
}
};

private insertHTML = (html: string) => {
if (this.mirror.selectionStart || this.mirror.selectionStart === 0) {
let startPos: number = this.mirror.selectionStart,
endPos: number = this.mirror.selectionEnd;

this.mirror.value = this.mirror.value.substring(0, startPos)
+ html
+ this.mirror.value.substring(endPos, this.mirror.value.length);
} else {
this.mirror.value += this.mirror;
}

this.toWYSIWYG();
};

private __lock = false;

private toWYSIWYG = () => {
Expand Down Expand Up @@ -190,6 +205,12 @@ export class source extends Component {
});

editor.events
.on('insertHTML', (html: string): void | false => {
if (!editor.options.readonly && !this.jodit.isEditorMode()) {
this.insertHTML(html);
return false;
}
})
.on('aceInited', () => {
if (editor.options.readonly) {
if (this.aceEditor) {
Expand Down Expand Up @@ -505,6 +526,14 @@ export class source extends Component {
this.selectAll = () => {
aceEditor.selection.selectAll();
};
this.insertHTML = (html: string) => {
let start: AceAjax.Position = aceEditor.selection.getCursor(),
end: AceAjax.Position = aceEditor.session.insert(start, html);

aceEditor.selection.setRange(<AceAjax.Range>{
start, end
}, false);
};

this.setMirrorSelectionRange = (start: number, end: number) => {
setSelectionRangeIndices(start, end);
Expand Down
2 changes: 1 addition & 1 deletion src/styles/modules/dropdownlist.less
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
z-index:@z-index-dropdownlist;
left: 0;
top: 100%;

overflow: visible;
h5,h4,h3,h2,h1,p,blockquote, pre {
font-family: @font-default;
margin: 0;
Expand Down
4 changes: 2 additions & 2 deletions test/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
chai.config.includeStack = true;
(typeof chai !== 'undefined') && (chai.config.includeStack = true);

Jodit.defaultOptions.observer.timeout = 0;
Jodit.defaultOptions.useAceEditor = false;
Expand Down Expand Up @@ -36,7 +36,7 @@ if (String.prototype.repeat === undefined) {

})(Element.prototype);

var expect = chai.expect;
var expect = typeof chai !== 'undefined' ? chai.expect : function () {};
var stuff = [];
var removeStuff = function () {
stuff.forEach(function (elm) {
Expand Down
97 changes: 80 additions & 17 deletions test/tests/commandsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,67 @@ describe('Commands Jodit Editor Tests', function() {

expect(editor.getEditorValue()).to.equal('<h1>test</h1>');
});
describe('For UL>li elements', function () {
it('Should replace all LI elements to P and unwrap it from UL', function () {
var editor = new Jodit(appendTestArea());
editor.value = '<ul>' +
'<li>1</li>' +
'<li>2</li>' +
'<li>3</li>' +
'</ul>';

var range = editor.editorDocument.createRange();
range.selectNodeContents(editor.editor.firstChild);
editor.selection.selectRange(range);

editor.execCommand('formatBlock', false, 'p');
except(editor.value).to.be.equal('<p>1</p>' +
'<p>2</p>' +
'<p>3</p>'
)
describe('For UL>li elements', function () {
describe('Select only LI', function () {
it('Should replace all LI elements to P and unwrap it from UL', function () {
var editor = new Jodit(appendTestArea());
editor.value = '<ul>' +
'<li>1</li>' +
'<li>2</li>' +
'<li>3</li>' +
'</ul>';

var range = editor.editorDocument.createRange();
range.setStart(editor.editor.firstChild.firstChild.firstChild, 0);
range.setEnd(editor.editor.firstChild.lastChild.firstChild, 1);
editor.selection.selectRange(range);

editor.execCommand('formatBlock', false, 'h1');
expect(editor.value).to.be.equal('<ul>' +
'<li><h1>1</h1></li>' +
'<li><h1>2</h1></li>' +
'<li><h1>3</h1></li>' +
'</ul>'
)

editor.execCommand('formatBlock', false, 'p');
expect(editor.value).to.be.equal('<ul>' +
'<li>1</li>' +
'<li>2</li>' +
'<li>3</li>' +
'</ul>'
)
});
});
describe('Select UL', function () {
it('Should replace all LI elements to P and unwrap it from UL', function () {
var editor = new Jodit(appendTestArea());
editor.value = '<ul>' +
'<li>1</li>' +
'<li>2</li>' +
'<li>3</li>' +
'</ul>';

var range = editor.editorDocument.createRange();
range.selectNode(editor.editor.firstChild);
editor.selection.selectRange(range);

editor.execCommand('formatBlock', false, 'h1');
expect(editor.value).to.be.equal('<ul>' +
'<li><h1>1</h1></li>' +
'<li><h1>2</h1></li>' +
'<li><h1>3</h1></li>' +
'</ul>');

editor.execCommand('formatBlock', false, 'p');
expect(editor.value).to.be.equal('<ul>' +
'<li>1</li>' +
'<li>2</li>' +
'<li>3</li>' +
'</ul>'
)
});
});
});
});
Expand Down Expand Up @@ -340,6 +383,26 @@ describe('Commands Jodit Editor Tests', function() {
expect(editor.getEditorValue()).to.equal('test');
});
});
describe('Exec bold for collapsed range and move cursor in another place', function () {
it('Should remove stron element', function () {
var editor = new Jodit(appendTestArea());
editor.value = 'testtest';
var range = editor.editorDocument.createRange();
range.setStart(editor.editor.firstChild, 4);
range.collapse(true)
editor.selection.selectRange(range);

editor.execCommand('bold')
expect(editor.value).to.be.equal('test<strong></strong>test');

range.setStart(editor.editor.lastChild, 2);
range.collapse(true)
editor.selection.selectRange(range);
simulateEvent('mousedown', 0, editor.editor)
expect(editor.value).to.be.equal('testtest');

});
});
});

describe('After exec some command', function() {
Expand Down
41 changes: 41 additions & 0 deletions test/tests/imageTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,47 @@ describe('Test image', function() {
expect(Math.abs(positionResizer.left - positionImg.left) < 2).to.be.true;
expect(Math.abs(positionResizer.top - positionImg.top) < 2).to.be.true;

editor.destruct();
document.body.removeChild(div);
});
});
describe('After resize - popup', function () {
it('should be hidden and after this should be shown', function () {
var div = document.createElement('div');
div.innerHTML = '<div style="width:800px; margin:auto; border:1px solid red;">\n' +
' wrong image selection\n' +
' <div style="position:relative;text-align: left">\n' +
' <textarea id="text_area1"> <img src="https://xdsoft.net/jodit/build/images/artio.jpg" style="border:1px solid red;width:100px;height:100px;"/></textarea>\n' +
' </div>\n' +
' </div>';

document.body.appendChild(div);
var editor = new Jodit('#text_area1');
simulateEvent('mousedown', 0, editor.editor.querySelector('img'));

var popup = document.querySelector('.jodit_toolbar_popup-inline[data-editor_id=text_area1]');

expect(popup.parentNode.parentNode !== null).to.equal(true);

var resizer = document.querySelector('.jodit_resizer[data-editor_id=text_area1]');
expect(resizer.style.display === 'block').to.equal(true);

var positionResizer = offset(resizer);
var positionImg = offset(editor.editor.querySelector('img'));

simulateEvent('mousedown', 0, resizer.getElementsByTagName('i')[0]);
simulateEvent('mousemove', 0, editor.ownerWindow, function (data) {
data.clientX = positionResizer.left - 10;
data.clientY = positionResizer.top - 10;
});

expect(popup.parentNode.parentNode).to.be.equal(null);
simulateEvent('mouseup', 0, editor.ownerWindow, function (data) {
data.clientX = positionResizer.left - 10;
data.clientY = positionResizer.top - 10;
});
expect(popup.parentNode.parentNode).to.be.not.equal(null);

editor.destruct();
document.body.removeChild(div);
});
Expand Down
Loading

0 comments on commit 6d4dff3

Please sign in to comment.