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

Commit 2c26e73

Browse files
RifRaf44linkesch
authored andcommitted
add empty paragraph after image (#306)
1 parent 038c038 commit 2c26e73

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/js/images.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*global MediumEditor*/
22

3-
;(function ($, window, document, Util, undefined) {
3+
; (function ($, window, document, Util, undefined) {
44

55
'use strict';
66

@@ -87,12 +87,12 @@
8787
* @return {void}
8888
*/
8989

90-
function Images (el, options) {
90+
function Images(el, options) {
9191
this.el = el;
9292
this.$el = $(el);
9393
this.$currentImage = null;
9494
this.templates = window.MediumInsert.Templates;
95-
this.core = this.$el.data('plugin_'+ pluginName);
95+
this.core = this.$el.data('plugin_' + pluginName);
9696

9797
this.options = $.extend(true, {}, defaults, options);
9898

@@ -253,9 +253,15 @@
253253

254254
// Replace paragraph with div, because figure elements can't be inside paragraph
255255
if ($place.is('p')) {
256-
$place.replaceWith('<div class="medium-insert-active">'+ $place.html() +'</div>');
256+
$place.replaceWith('<div class="medium-insert-active">' + $place.html() + '</div>');
257257
$place = this.$el.find('.medium-insert-active');
258-
this.core.moveCaret($place);
258+
if ($place.next().is('p')) {
259+
this.core.moveCaret($place.next());
260+
}
261+
else {
262+
$place.after('<p><br></p>'); // add empty paragraph so we can move the caret to the next line.
263+
this.core.moveCaret($place.next());
264+
}
259265
}
260266

261267
$place.addClass('medium-insert-images');
@@ -324,7 +330,7 @@
324330
progress = 100 - parseInt(data.loaded / data.total * 100, 10);
325331
$progressbar = data.context.find('.medium-insert-images-progress');
326332

327-
$progressbar.css('width', progress +'%');
333+
$progressbar.css('width', progress + '%');
328334

329335
if (progress === 0) {
330336
$progressbar.remove();
@@ -388,7 +394,7 @@
388394

389395
if (this.options.autoGrid && $place.find('figure').length >= this.options.autoGrid) {
390396
$.each(this.options.styles, function (style, options) {
391-
var className = 'medium-insert-images-'+ style;
397+
var className = 'medium-insert-images-' + style;
392398

393399
$place.removeClass(className);
394400

@@ -428,7 +434,7 @@
428434
*/
429435

430436
Images.prototype.selectImage = function (e) {
431-
if(this.core.options.enabled) {
437+
if (this.core.options.enabled) {
432438
var $image = $(e.target),
433439
that = this;
434440

@@ -584,7 +590,7 @@
584590
.show();
585591

586592
$toolbar.find('button').each(function () {
587-
if ($p.hasClass('medium-insert-images-'+ $(this).data('action'))) {
593+
if ($p.hasClass('medium-insert-images-' + $(this).data('action'))) {
588594
$(this).addClass('medium-editor-button-active');
589595
active = true;
590596
}
@@ -615,7 +621,7 @@
615621
$li.siblings().find('.medium-editor-button-active').removeClass('medium-editor-button-active');
616622

617623
$lis.find('button').each(function () {
618-
var className = 'medium-insert-images-'+ $(this).data('action');
624+
var className = 'medium-insert-images-' + $(this).data('action');
619625

620626
if ($(this).hasClass('medium-editor-button-active')) {
621627
$p.addClass(className);

0 commit comments

Comments
 (0)