@jx3box/jx3box-editor 1.9.9 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ /**
2
+ * 拖拽移动
3
+ * @param  {elementObjct} bar 鼠标点击控制拖拽的元素
4
+ * @param {elementObjct}  target 移动的元素
5
+ * @param {function}  callback 移动后的回调
6
+ */
7
+ const startDrag = (bar, target, callback) => {
8
+ var params = {
9
+ top: 0,
10
+ left: 0,
11
+ currentX: 0,
12
+ currentY: 0,
13
+ flag: false,
14
+ cWidth: 0,
15
+ cHeight: 0,
16
+ tWidth: 0,
17
+ tHeight: 0
18
+ };
19
+
20
+ // 给拖动块添加样式
21
+ bar.style.cursor = 'move';
22
+
23
+ // 获取相关CSS属性
24
+ // o是移动对象
25
+ // var getCss = function (o, key) {
26
+ //   return o.currentStyle ? o.currentStyle[key] : document.defaultView.getComputedStyle(o, false)[key];
27
+ // };
28
+
29
+ bar.onmousedown = function (event) {
30
+ // 按下时初始化params
31
+ var e = event ? event : window.event;
32
+ params = {
33
+ top: target.offsetTop,
34
+ left: target.offsetLeft,
35
+ currentX: e.clientX,
36
+ currentY: e.clientY,
37
+ flag: true,
38
+ cWidth: document.body.clientWidth,
39
+ cHeight: document.body.clientHeight,
40
+ tWidth: target.offsetWidth,
41
+ tHeight: target.offsetHeight
42
+ };
43
+
44
+ // 给被拖动块初始化样式
45
+ target.style.margin = 0;
46
+ target.style.top = params.top + 'px';
47
+ target.style.left = params.left + 'px';
48
+
49
+ if (!event) {
50
+ // 防止IE文字选中
51
+ bar.onselectstart = function () {
52
+ return false;
53
+ }
54
+ }
55
+
56
+ document.onmousemove = function (event) {
57
+ // 防止文字选中
58
+ window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
59
+
60
+ var e = event ? event : window.event;
61
+ if (params.flag) {
62
+ var nowX = e.clientX;
63
+ var nowY = e.clientY;
64
+ // 差异距离
65
+ var disX = nowX - params.currentX;
66
+ var disY = nowY - params.currentY;
67
+ // 最终移动位置
68
+ var zLeft = 0;
69
+ var zTop = 0;
70
+
71
+ zLeft = parseInt(params.left) + disX;
72
+ // 限制X轴范围
73
+ if (zLeft <= -parseInt(params.tWidth / 2)) {
74
+ zLeft = -parseInt(params.tWidth / 2);
75
+ }
76
+ if (zLeft >= params.cWidth - parseInt(params.tWidth * 0.5)) {
77
+ zLeft = params.cWidth - parseInt(params.tWidth * 0.5);
78
+ }
79
+
80
+ zTop = parseInt(params.top) + disY;
81
+ // 限制Y轴范围
82
+ if (zTop <= 0) {
83
+ zTop = 0;
84
+ }
85
+ if (zTop >= params.cHeight - parseInt(params.tHeight * 0.5)) {
86
+ zTop = params.cHeight - parseInt(params.tHeight * 0.5);
87
+ }
88
+
89
+ // 执行移动
90
+ target.style.left = zLeft + 'px';
91
+ target.style.top = zTop + 'px';
92
+ }
93
+
94
+ if (typeof callback == "function") {
95
+ callback(zLeft, zTop);
96
+ }
97
+ }
98
+
99
+ document.onmouseup = function () {
100
+ params.flag = false;
101
+ document.onmousemove = null;
102
+ document.onmouseup = null;
103
+ };
104
+ };
105
+ }
106
+
107
+ /**
108
+ * 为el-dialog弹框增加拖拽功能
109
+ * @param {*} el 指定dom
110
+ * @param {*} binding 绑定对象
111
+ * desc 只要用到了el-dialog的组件,都可以通过增加v-draggable属性变为可拖拽的弹框
112
+ */
113
+ export const draggable = (el, binding) => {
114
+ // 绑定拖拽事件 [绑定拖拽触发元素为弹框头部、拖拽移动元素为整个弹框]
115
+ startDrag(el.querySelector('.el-dialog__header'), el.querySelector('.el-dialog'), binding.value);
116
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jx3box/jx3box-editor",
3
- "version": "1.9.9",
3
+ "version": "2.0.0",
4
4
  "description": "JX3BOX Article & Editor",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,6 +12,7 @@
12
12
 
13
13
  <!-- 弹出界面 -->
14
14
  <el-dialog
15
+ v-draggable
15
16
  class="c-large-dialog"
16
17
  title="魔盒资源库"
17
18
  :visible.sync="dialogVisible"
package/src/Resource.vue CHANGED
@@ -4,7 +4,7 @@
4
4
  <el-button class="u-switch" type="primary" @click="openDialog" :disabled="!enable"> <img class="u-icon" svg-inline src="../assets/img/jx3.svg" />剑三资源 </el-button>
5
5
 
6
6
  <!-- 弹出界面 -->
7
- <el-dialog class="c-large-dialog" title="剑三数据库" :visible.sync="dialogVisible">
7
+ <el-dialog class="c-large-dialog" title="剑三数据库" :visible.sync="dialogVisible" v-draggable>
8
8
  <div class="c-resource-content" v-loading="loading">
9
9
  <div class="m-database-search">
10
10
  <el-radio-group class="u-client" v-model="client" @change="search">
package/src/Tinymce.vue CHANGED
@@ -34,6 +34,7 @@
34
34
  </template>
35
35
 
36
36
  <script>
37
+ import Vue from "vue";
37
38
  import Editor from "@tinymce/tinymce-vue";
38
39
  import Upload from "./Upload";
39
40
  import Resource from "./Resource";
@@ -45,6 +46,10 @@ import hljs_languages from "../assets/js/item/hljs_languages.js"
45
46
  const API_Root = process.env.NODE_ENV === "production" ? __cms : "/";
46
47
  const API = API_Root + "api/cms/upload/tinymce";
47
48
 
49
+ // directive
50
+ import { draggable } from "../assets/js/drag";
51
+ Vue.directive('draggable', draggable);
52
+
48
53
  export default {
49
54
  name: "Tinymce",
50
55
  props: ["content", "height", "attachmentEnable", "resourceEnable"],