MCPcopy Create free account
hub / github.com/TruthHun/BookStack / bindDragEvent

Function bindDragEvent

static/wangEditor/js/wangEditor.js:7928–7997  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7926
7927 // 绑定drag事件
7928 function bindDragEvent() {
7929 var _x, _y;
7930 var dragMarginLeft, dragMarginTop;
7931 var imgWidth, imgHeight;
7932
7933 function mousemove (e) {
7934 var diffX, diffY;
7935
7936 // 计算差额
7937 diffX = e.pageX - _x;
7938 diffY = e.pageY - _y;
7939
7940 // --------- 计算拖拽点的位置 ---------
7941 var currentDragMarginLeft = dragMarginLeft + diffX;
7942 var currentDragMarginTop = dragMarginTop + diffY;
7943 $dragPoint.css({
7944 'margin-left': currentDragMarginLeft,
7945 'margin-top': currentDragMarginTop
7946 });
7947
7948 // --------- 计算图片的大小 ---------
7949 var currentImgWidth = imgWidth + diffX;
7950 var currentImggHeight = imgHeight + diffY;
7951 $currentImg && $currentImg.css({
7952 width: currentImgWidth,
7953 height: currentImggHeight
7954 });
7955 }
7956
7957 $dragPoint.on('mousedown', function(e){
7958 if (!$currentImg) {
7959 return;
7960 }
7961 // 当前鼠标位置
7962 _x = e.pageX;
7963 _y = e.pageY;
7964
7965 // 当前拖拽点的位置
7966 dragMarginLeft = parseFloat($dragPoint.css('margin-left'), 10);
7967 dragMarginTop = parseFloat($dragPoint.css('margin-top'), 10);
7968
7969 // 当前图片的大小
7970 imgWidth = $currentImg.width();
7971 imgHeight = $currentImg.height();
7972
7973 // 隐藏 $toolbar
7974 $toolbar.hide();
7975
7976 // 绑定计算事件
7977 E.$document.on('mousemove._dragResizeImg', mousemove);
7978 E.$document.on('mouseup._dragResizeImg', function (e) {
7979 // 取消绑定
7980 E.$document.off('mousemove._dragResizeImg');
7981 E.$document.off('mouseup._dragResizeImg');
7982
7983 // 隐藏,并还原拖拽点的位置
7984 hide();
7985 $dragPoint.css({

Callers 1

renderFunction · 0.85

Calls 1

hideFunction · 0.70

Tested by

no test coverage detected