Skip to content
This repository was archived by the owner on May 12, 2023. It is now read-only.

Commit 9811da8

Browse files
authored
feat(): resizable dialogs (#77)
1 parent 1213b08 commit 9811da8

File tree

4 files changed

+97
-9
lines changed

4 files changed

+97
-9
lines changed

editormd.js

+48-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
* Editor.md
33
*
44
* @file editormd.js
5-
* @version v1.7.13
5+
* @version v1.7.14
66
* @description Open source online markdown editor.
77
* @license MIT License
88
* @author Pandao
99
* {@link https://github.com/pandao/editor.md}
10-
* @updateTime 2023-04-25
10+
* @updateTime 2023-05-03
1111
*/
1212

1313
;(function(factory) {
@@ -59,7 +59,7 @@
5959
};
6060

6161
editormd.title = editormd.$name = "Editor.md";
62-
editormd.version = "1.7.13";
62+
editormd.version = "1.7.14";
6363
editormd.homePage = "https://pandao.github.io/editor.md/";
6464
editormd.classPrefix = "editormd-";
6565

@@ -1259,6 +1259,11 @@
12591259

12601260
return this;
12611261
},
1262+
positionDialog : function(dialog, position) {
1263+
$.proxy(editormd.positionDialog, this)(dialog, position);
1264+
1265+
return this;
1266+
},
12621267

12631268
getToolbarHandles : function(name) {
12641269
var toolbarHandlers = this.toolbarHandlers = editormd.toolbarHandlers;
@@ -2762,6 +2767,32 @@
27622767
}
27632768
};
27642769

2770+
2771+
editormd.positionDialog = function(dialog, position="center") {
2772+
var left, top;
2773+
2774+
switch (position) {
2775+
case "center":
2776+
left = ($(window).width() - dialog.width()) / 2 + "px";
2777+
top = ($(window).height() - dialog.height()) / 2 + "px";
2778+
break;
2779+
case "center-left":
2780+
left = ($(window).width() / 4 - dialog.width() / 2) + "px";
2781+
top = ($(window).height() - dialog.height()) / 2 + "px";
2782+
break;
2783+
case "center-right":
2784+
left = ($(window).width() * 3 / 4 - dialog.width() / 2) + "px";
2785+
top = ($(window).height() - dialog.height()) / 2 + "px";
2786+
break;
2787+
default:
2788+
console.warn(`Unsupported dialog position: ${position}`);
2789+
left = ($(window).width() - dialog.width()) / 2 + "px";
2790+
top = ($(window).height() - dialog.height()) / 2 + "px";
2791+
}
2792+
2793+
dialog.css({ top, left });
2794+
};
2795+
27652796
/**
27662797
* 显示透明背景层
27672798
* Display mask layer when dialog opening
@@ -4123,6 +4154,12 @@
41234154
opacity : 0.1
41244155
},
41254156
removeDialogOnClose: false,
4157+
resizeableX: false,
4158+
resizeableY: false,
4159+
minWidth: 0,
4160+
minHeight: 0,
4161+
maxWidth: "none",
4162+
maxHeight: "none",
41264163
lockScreen : true,
41274164
footer : true,
41284165
buttons : false
@@ -4207,7 +4244,14 @@
42074244
zIndex : editormd.dialogZindex,
42084245
border : (editormd.isIE8) ? "1px solid #ddd" : "",
42094246
width : (typeof options.width === "number") ? options.width + "px" : options.width,
4210-
height : (typeof options.height === "number") ? options.height + "px" : options.height
4247+
height : (typeof options.height === "number") ? options.height + "px" : options.height,
4248+
"min-width": (typeof options.minWidth === "number") ? options.minWidth + "px" : options.minWidth,
4249+
"min-height": (typeof options.minHeight === "number") ? options.minHeight + "px" : options.minHeight,
4250+
"max-width": (typeof options.maxWidth === "number") ? options.maxWidth + "px" : options.maxWidth,
4251+
"max-height": (typeof options.maxHeight === "number") ? options.maxHeight + "px" : options.maxHeight,
4252+
...((options.resizeableX || options.resizeableY) ? { overflow: 'hidden',
4253+
resize: (options.resizeableX && options.resizeableY) ? "both" : ((options.resizeableX) ? "horizontal" : "vertical")
4254+
} : {})
42114255
});
42124256

42134257
var dialogPosition = function(){

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ibm-skills-network/editor.md",
3-
"version": "1.7.13",
3+
"version": "1.7.14",
44
"description": "Open source online markdown editor.",
55
"directories": {
66
"doc": "docs",

src/editormd.js

+46-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
};
4848

4949
editormd.title = editormd.$name = "Editor.md";
50-
editormd.version = "1.7.13";
50+
editormd.version = "1.7.14";
5151
editormd.homePage = "https://pandao.github.io/editor.md/";
5252
editormd.classPrefix = "editormd-";
5353

@@ -1247,6 +1247,11 @@
12471247

12481248
return this;
12491249
},
1250+
positionDialog : function(dialog, position) {
1251+
$.proxy(editormd.positionDialog, this)(dialog, position);
1252+
1253+
return this;
1254+
},
12501255

12511256
getToolbarHandles : function(name) {
12521257
var toolbarHandlers = this.toolbarHandlers = editormd.toolbarHandlers;
@@ -2750,6 +2755,32 @@
27502755
}
27512756
};
27522757

2758+
2759+
editormd.positionDialog = function(dialog, position="center") {
2760+
var left, top;
2761+
2762+
switch (position) {
2763+
case "center":
2764+
left = ($(window).width() - dialog.width()) / 2 + "px";
2765+
top = ($(window).height() - dialog.height()) / 2 + "px";
2766+
break;
2767+
case "center-left":
2768+
left = ($(window).width() / 4 - dialog.width() / 2) + "px";
2769+
top = ($(window).height() - dialog.height()) / 2 + "px";
2770+
break;
2771+
case "center-right":
2772+
left = ($(window).width() * 3 / 4 - dialog.width() / 2) + "px";
2773+
top = ($(window).height() - dialog.height()) / 2 + "px";
2774+
break;
2775+
default:
2776+
console.warn(`Unsupported dialog position: ${position}`);
2777+
left = ($(window).width() - dialog.width()) / 2 + "px";
2778+
top = ($(window).height() - dialog.height()) / 2 + "px";
2779+
}
2780+
2781+
dialog.css({ top, left });
2782+
};
2783+
27532784
/**
27542785
* 显示透明背景层
27552786
* Display mask layer when dialog opening
@@ -4111,6 +4142,12 @@
41114142
opacity : 0.1
41124143
},
41134144
removeDialogOnClose: false,
4145+
resizeableX: false,
4146+
resizeableY: false,
4147+
minWidth: 0,
4148+
minHeight: 0,
4149+
maxWidth: "none",
4150+
maxHeight: "none",
41144151
lockScreen : true,
41154152
footer : true,
41164153
buttons : false
@@ -4195,7 +4232,14 @@
41954232
zIndex : editormd.dialogZindex,
41964233
border : (editormd.isIE8) ? "1px solid #ddd" : "",
41974234
width : (typeof options.width === "number") ? options.width + "px" : options.width,
4198-
height : (typeof options.height === "number") ? options.height + "px" : options.height
4235+
height : (typeof options.height === "number") ? options.height + "px" : options.height,
4236+
"min-width": (typeof options.minWidth === "number") ? options.minWidth + "px" : options.minWidth,
4237+
"min-height": (typeof options.minHeight === "number") ? options.minHeight + "px" : options.minHeight,
4238+
"max-width": (typeof options.maxWidth === "number") ? options.maxWidth + "px" : options.maxWidth,
4239+
"max-height": (typeof options.maxHeight === "number") ? options.maxHeight + "px" : options.maxHeight,
4240+
...((options.resizeableX || options.resizeableY) ? { overflow: 'hidden',
4241+
resize: (options.resizeableX && options.resizeableY) ? "both" : ((options.resizeableX) ? "horizontal" : "vertical")
4242+
} : {})
41994243
});
42004244

42014245
var dialogPosition = function(){

0 commit comments

Comments
 (0)