Skip to content

Commit ace0b5a

Browse files
authored
Merge pull request #8 from BOTOOM/develop
Develop
2 parents 047355e + 7640752 commit ace0b5a

File tree

7 files changed

+251
-84
lines changed

7 files changed

+251
-84
lines changed

README.md

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ a module that enables resize for image/iframe/video.
99

1010
## Demo
1111

12+
### Playground
13+
14+
[rezise module playground](https://botoom.github.io/quill-resize-module/)
15+
1216
![image](https://raw.githubusercontent.com/BOTOOM/quill-resize-module/master/demo/demo.gif)
1317

18+
19+
1420
## Usage
1521

1622
### Webpack/ES6
@@ -39,9 +45,21 @@ const quill = new Quill(editor, {
3945
});
4046
```
4147

48+
#### Default configuration
49+
50+
```javascript
51+
const quill = new Quill(editor, {
52+
modules: {
53+
resize: {
54+
locale: {},
55+
},
56+
},
57+
});
58+
```
59+
4260
### Latest versions of Quill
4361

44-
Recent versions of Quill do not support the use of the style attribute, to fix this, make your configuration similar to the following
62+
Recent versions of Quill do not support the use of the `style` attribute, so element alignment methods are not allowed, to work around this, make your configuration similar to the following
4563

4664
```javascript
4765
import Quill from "quill";
@@ -52,8 +70,9 @@ Quill.register("modules/resize", ResizeModule);
5270
const quill = new Quill(editor, {
5371
modules: {
5472
resize: {
55-
hiddenToobar: true,
56-
noUseStyle: true,
73+
toolbar: {
74+
alingTools: false,
75+
},
5776
locale: {
5877
// ...
5978
},
@@ -116,3 +135,80 @@ const quill = new Quill(editor, {
116135
</script>
117136
</html>
118137
```
138+
139+
<table>
140+
<thead>
141+
<tr>
142+
<th>Property</th>
143+
<th>Description</th>
144+
<th>Example</th>
145+
</tr>
146+
</thead>
147+
<tbody>
148+
<tr>
149+
<td>locale</td>
150+
<td>Change the language of the toolbar buttons. you can change one or more names, if any attribute is not entered the default language (english) will be taken.</td>
151+
<td> <pre><code>const quill = new Quill(editor, {
152+
modules: {
153+
resize: {
154+
locale: {
155+
altTip: "Hold down the alt key to zoom",
156+
floatLeft: "Left",
157+
floatRight: "Right",
158+
center: "Center",
159+
restore: "Restore",
160+
},
161+
},
162+
},
163+
});</code></pre> </td>
164+
</tr>
165+
<tr>
166+
<td>showToolbar</td>
167+
<td>Default is <code>true</code>, changing it to <code>false</code> will hide the toolbar.</td>
168+
<td><pre><code>const quill = new Quill(editor, {
169+
modules: {
170+
resize: {
171+
showToolbar: false,
172+
},
173+
},
174+
});</code></pre></td>
175+
</tr>
176+
<tr>
177+
<td>showSize</td>
178+
<td>Default is <code>false</code>, if changed to <code>true</code> the size of the image or video will be displayed.</td>
179+
<td><pre><code>const quill = new Quill(editor, {
180+
modules: {
181+
resize: {
182+
showSize: true,
183+
},
184+
},
185+
});</code></pre></td>
186+
</tr>
187+
<tr>
188+
<td>alingTools</td>
189+
<td>Default is <code>true</code>, changing it to <code>false</code> will hide the alignment toolbar.</td>
190+
<td><pre><code>const quill = new Quill(editor, {
191+
modules: {
192+
resize: {
193+
toolbar: {
194+
alingTools: false
195+
},
196+
},
197+
},
198+
});</code></pre></td>
199+
</tr>
200+
<tr>
201+
<td>sizeTools</td>
202+
<td>Default is <code>true</code>, changing it to <code>false</code> will hide the resizing toolbar.</td>
203+
<td><pre><code>const quill = new Quill(editor, {
204+
modules: {
205+
resize: {
206+
toolbar: {
207+
sizeTools: false
208+
},
209+
},
210+
},
211+
});</code></pre></td>
212+
</tr>
213+
</tbody>
214+
</table>

demo/index.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@
4040
modules: {
4141
toolbar: toolbarOptions,
4242
resize: {
43-
// hiddenToobar: false,
44-
// noUseStyle: true,
43+
showSize: true,
44+
// showToolbar: false,
45+
toolbar: {
46+
// alingTools: false
47+
},
4548
locale: {}
4649
}
4750
}

dist/quill-resize-module.js

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
return __assign.apply(this, arguments);
5757
};
5858

59-
__$styleInject("#editor-resizer {\n position: absolute;\n border: 1px dashed #fff;\n background-color: rgba(0, 0, 0, 0.5);\n}\n#editor-resizer .handler {\n position: absolute;\n right: -5px;\n bottom: -5px;\n width: 10px;\n height: 10px;\n border: 1px solid #333;\n background-color: rgba(255, 255, 255, 0.8);\n cursor: nwse-resize;\n user-select: none;\n}\n#editor-resizer .toolbar {\n position: absolute;\n top: -5em;\n left: 50%;\n padding: 0.5em;\n border: 1px solid #fff;\n border-radius: 3px;\n background-color: #fff;\n box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);\n transform: translateX(-50%);\n}\n#editor-resizer .toolbar .group {\n display: flex;\n border: 1px solid #aaa;\n border-radius: 6px;\n overflow: hidden;\n white-space: nowrap;\n text-align: center;\n}\n#editor-resizer .toolbar .group:not(:first-child) {\n margin-top: 0.5em;\n}\n#editor-resizer .toolbar .group .btn {\n flex: 1 0 0;\n text-align: center;\n width: 25%;\n padding: 0 0.5rem;\n display: inline-block;\n color: rgba(0, 0, 0, 0.65);\n vertical-align: top;\n line-height: 2;\n user-select: none;\n}\n#editor-resizer .toolbar .group .btn.btn-group {\n padding: 0;\n display: inline-flex;\n line-height: 2em;\n}\n#editor-resizer .toolbar .group .btn.btn-group .inner-btn {\n flex: 1 0 0;\n font-size: 2em;\n width: 50%;\n cursor: pointer;\n}\n#editor-resizer .toolbar .group .btn.btn-group .inner-btn:first-child {\n border-right: 1px solid #ddd;\n}\n#editor-resizer .toolbar .group .btn.btn-group .inner-btn:active {\n transform: scale(0.8);\n}\n#editor-resizer .toolbar .group .btn:not(:last-child) {\n border-right: 1px solid #bbb;\n}\n#editor-resizer .toolbar .group .btn:not(.btn-group):active {\n background-color: rgba(0, 0, 0, 0.1);\n}\n");
59+
__$styleInject("#editor-resizer {\n position: absolute;\n border: 1px dashed #fff;\n background-color: rgba(0, 0, 0, 0.5);\n}\n#editor-resizer .handler {\n position: absolute;\n right: -5px;\n bottom: -5px;\n width: 10px;\n height: 10px;\n border: 1px solid #333;\n background-color: rgba(255, 255, 255, 0.8);\n cursor: nwse-resize;\n user-select: none;\n}\n#editor-resizer .toolbar {\n position: absolute;\n top: -3em;\n left: 50%;\n padding: 0.5em;\n border: 1px solid #fff;\n border-radius: 3px;\n background-color: #fff;\n box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);\n transform: translateX(-50%);\n}\n#editor-resizer .toolbar .group {\n display: flex;\n border: 1px solid #aaa;\n border-radius: 6px;\n overflow: hidden;\n white-space: nowrap;\n text-align: center;\n}\n#editor-resizer .toolbar .group:not(:first-child) {\n margin-top: 0.5em;\n}\n#editor-resizer .toolbar .group .btn {\n flex: 1 0 0;\n text-align: center;\n width: 25%;\n padding: 0 0.5rem;\n display: inline-block;\n color: rgba(0, 0, 0, 0.65);\n vertical-align: top;\n line-height: 2;\n user-select: none;\n}\n#editor-resizer .toolbar .group .btn.btn-group {\n padding: 0;\n display: inline-flex;\n line-height: 2em;\n}\n#editor-resizer .toolbar .group .btn.btn-group .inner-btn {\n flex: 1 0 0;\n font-size: 2em;\n width: 50%;\n cursor: pointer;\n}\n#editor-resizer .toolbar .group .btn.btn-group .inner-btn:first-child {\n border-right: 1px solid #ddd;\n}\n#editor-resizer .toolbar .group .btn.btn-group .inner-btn:active {\n transform: scale(0.8);\n}\n#editor-resizer .toolbar .group .btn:not(:last-child) {\n border-right: 1px solid #bbb;\n}\n#editor-resizer .toolbar .group .btn:not(.btn-group):active {\n background-color: rgba(0, 0, 0, 0.1);\n}\n#editor-resizer .last-item {\n margin-right: 5px;\n}\n#editor-resizer .showSize {\n position: absolute;\n top: 50%;\n left: 50%;\n padding: 0.1em;\n border: 1px solid rgba(255, 255, 255, 0.8);\n border-radius: 2px;\n background-color: rgba(255, 255, 255, 0.8);\n box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);\n transform: translateX(-50%);\n}\n");
6060

6161
var I18n = /** @class */ (function () {
6262
function I18n(config) {
@@ -102,25 +102,22 @@
102102
}
103103
return ResizeElement;
104104
}(HTMLElement));
105-
var templateWithoutToolbar = "\n<div class=\"handler\" title=\"{0}\"></div>\n";
106-
var template = "\n<div class=\"handler\" title=\"{0}\"></div>\n<div class=\"toolbar\">\n <div class=\"group\">\n <a class=\"btn\" data-width=\"100%\">100%</a>\n <a class=\"btn\" data-width=\"50%\">50%</a>\n <a class=\"btn btn-group\">\n <span data-width=\"-5\" class=\"inner-btn\">\uFE63</span>\n <span data-width=\"5\" class=\"inner-btn\">\uFE62</span>\n </a>\n <a data-width=\"auto\" class=\"btn\">{4}</a>\n </div>\n <div class=\"group\">\n <a class=\"btn\" data-float=\"left\">{1}</a>\n <a class=\"btn\" data-float=\"center\">{2}</a>\n <a class=\"btn\" data-float=\"right\">{3}</a>\n <a data-float=\"none\" class=\"btn\">{4}</a>\n </div>\n</div>\n";
107-
var hiddenToobar = false;
108-
var noUseStyle = false;
105+
var templateUsed;
106+
var pluginOptions;
109107
var ResizePlugin = /** @class */ (function () {
110108
function ResizePlugin(resizeTarget, container, options) {
111109
this.resizer = null;
112110
this.startResizePosition = null;
113111
this.i18n = new I18n((options === null || options === void 0 ? void 0 : options.locale) || defaultLocale);
114-
// options?.toolbar ? showToolbar = true: showToolbar = false
115-
hiddenToobar = (options === null || options === void 0 ? void 0 : options.hiddenToobar) || false;
116-
noUseStyle = (options === null || options === void 0 ? void 0 : options.noUseStyle) || false;
112+
templateUsed = this.createToobar(options);
117113
this.resizeTarget = resizeTarget;
118114
if (!resizeTarget.originSize) {
119115
resizeTarget.originSize = {
120116
width: resizeTarget.clientWidth,
121-
height: resizeTarget.clientHeight
117+
height: resizeTarget.clientHeight,
122118
};
123119
}
120+
pluginOptions = options;
124121
this.container = container;
125122
this.initResizer();
126123
this.positionResizerToTarget(resizeTarget);
@@ -135,17 +132,32 @@
135132
if (!resizer) {
136133
resizer = document.createElement("div");
137134
resizer.setAttribute("id", "editor-resizer");
138-
resizer.innerHTML = format(hiddenToobar ? templateWithoutToolbar : template, this.i18n.findLabel("altTip"), this.i18n.findLabel("floatLeft"), this.i18n.findLabel("center"), this.i18n.findLabel("floatRight"), this.i18n.findLabel("restore"));
135+
resizer.innerHTML = format(templateUsed, this.i18n.findLabel("altTip"), this.i18n.findLabel("floatLeft"), this.i18n.findLabel("center"), this.i18n.findLabel("floatRight"), this.i18n.findLabel("restore"));
139136
this.container.appendChild(resizer);
140137
}
141138
this.resizer = resizer;
142139
};
140+
ResizePlugin.prototype.createToobar = function (options) {
141+
var _a, _b;
142+
var templateBasicToolbar = "<div class=\"handler\" title=\"{0}\"></div>";
143+
var size = "<div class=\"showSize\" name=\"ql-size\" title=\"{0}\">{size}</div>";
144+
var sizeTools = "<div class=\"group\">\n <a class=\"btn\" data-width=\"100%\">100%</a>\n <a class=\"btn\" data-width=\"50%\">50%</a>\n <a class=\"btn btn-group\">\n <span data-width=\"-5\" class=\"inner-btn\">\uFE63</span>\n <span data-width=\"5\" class=\"inner-btn\">\uFE62</span>\n </a>\n <a data-width=\"auto\" class=\"btn last-item\">{4}</a>\n </div>";
145+
var alingTools = "<div class=\"group\">\n <a class=\"btn\" data-float=\"left\">{1}</a>\n <a class=\"btn\" data-float=\"center\">{2}</a>\n <a class=\"btn\" data-float=\"right\">{3}</a>\n <a data-float=\"none\" class=\"btn last-item\">{4}</a>\n </div>";
146+
var toolBarTemplate = "<div class=\"toolbar\">\n " + (((_a = options === null || options === void 0 ? void 0 : options.toolbar) === null || _a === void 0 ? void 0 : _a.sizeTools) !== false ? sizeTools : "") + "\n " + (((_b = options === null || options === void 0 ? void 0 : options.toolbar) === null || _b === void 0 ? void 0 : _b.alingTools) !== false ? alingTools : "") + "\n </div>";
147+
return "" + templateBasicToolbar + ((options === null || options === void 0 ? void 0 : options.showSize) === true ? size : "") + ((options === null || options === void 0 ? void 0 : options.showToolbar) !== false ? toolBarTemplate : "");
148+
};
143149
ResizePlugin.prototype.positionResizerToTarget = function (el) {
144150
if (this.resizer !== null) {
145151
this.resizer.style.setProperty("left", el.offsetLeft + "px");
146152
this.resizer.style.setProperty("top", el.offsetTop + "px");
147153
this.resizer.style.setProperty("width", el.clientWidth + "px");
148154
this.resizer.style.setProperty("height", el.clientHeight + "px");
155+
// this.resizer.getElementsByTagName("ql-size").item(0)?.innerHTML = `450px, 500px`
156+
(pluginOptions === null || pluginOptions === void 0 ? void 0 : pluginOptions.showSize) &&
157+
(document.getElementsByName("ql-size").item(0).innerHTML = (el.getAttribute("width") ? el.getAttribute("width") : el.clientWidth) + ", " + (el.getAttribute("height")
158+
? el.getAttribute("height")
159+
: el.clientHeight));
160+
// this.resizer.innerHTML = formatSize (templateUsed, "450px, 500px")
149161
}
150162
};
151163
ResizePlugin.prototype.bindEvents = function () {
@@ -165,16 +177,20 @@
165177
var style = this.resizeTarget.style;
166178
if (width) {
167179
if (this.resizeTarget.tagName.toLowerCase() !== "iframe") {
168-
style.removeProperty("height");
180+
// style.removeProperty("height");
181+
this.resizeTarget.removeAttribute("height");
169182
}
170183
if (width === "auto") {
171-
style.removeProperty("width");
184+
// style.removeProperty("width");
185+
this.resizeTarget.removeAttribute("width");
172186
}
173187
else if (width.includes("%")) {
174-
style.setProperty("width", width);
188+
this.resizeTarget.setAttribute("width", width);
189+
// style.setProperty("width", width);
175190
}
176191
else {
177-
var styleWidth = style.getPropertyValue("width");
192+
var styleWidth = this.resizeTarget.getAttribute("width") || "";
193+
// let styleWidth = style.getPropertyValue("width");
178194
width = parseInt(width);
179195
if (styleWidth.includes("%")) {
180196
styleWidth =
@@ -184,7 +200,8 @@
184200
styleWidth =
185201
Math.max(this.resizeTarget.clientWidth + width, 10) + "px";
186202
}
187-
style.setProperty("width", styleWidth);
203+
this.resizeTarget.setAttribute("width", styleWidth);
204+
// style.setProperty("width", styleWidth);
188205
}
189206
}
190207
else {
@@ -209,7 +226,7 @@
209226
left: e.clientX,
210227
top: e.clientY,
211228
width: this.resizeTarget.clientWidth,
212-
height: this.resizeTarget.clientHeight
229+
height: this.resizeTarget.clientHeight,
213230
};
214231
}
215232
};
@@ -230,14 +247,8 @@
230247
var rate = originSize.height / originSize.width;
231248
height = rate * width;
232249
}
233-
if (noUseStyle) {
234-
this.resizeTarget.setAttribute("width", Math.max(width, 30) + "");
235-
this.resizeTarget.setAttribute("height", Math.max(height, 30) + "");
236-
}
237-
else {
238-
this.resizeTarget.style.setProperty("width", Math.max(width, 30) + "px");
239-
this.resizeTarget.style.setProperty("height", Math.max(height, 30) + "px");
240-
}
250+
this.resizeTarget.setAttribute("width", Math.max(width, 30) + "");
251+
this.resizeTarget.setAttribute("height", Math.max(height, 30) + "");
241252
this.positionResizerToTarget(this.resizeTarget);
242253
};
243254
ResizePlugin.prototype.destory = function () {

0 commit comments

Comments
 (0)