Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
yairEO committed Sep 5, 2020
1 parent 42684bc commit 1494ad6
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/dragsort.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/dragsort.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 80 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yaireo/dragsort",
"version": "1.0.7",
"version": "1.0.8",
"homepage": "https://github.com/yairEO/dragsort",
"description": "Simple lisghtweight HTML5 drag-&-drop sorting ",
"license": "MIT",
Expand All @@ -9,10 +9,10 @@
"clean": "rm -rf dist",
"makedir": "mkdirp dist",
"js": "terser --compress --mangle --output dist/dragsort.js -- src/dragsort.js",
"js:watch": "onchange \"src/dragsort.js\" -- npm run js",
"css": "cleancss --level=2 --output dist/dragsort.css src/dragsort.css",
"css:watch": "onchange \"src/dragsort.css\" -- npm run css",
"start": "npm run build && npm run js:watch & npm run css:watch"
"watch:js": "onchange \"src/dragsort.js\" -- npm run js",
"watch:css": "onchange \"src/dragsort.css\" -- npm run css",
"start": "npm run build && concurrently \"npm:watch:*\""
},
"_npmUser": {
"name": "vsync",
Expand All @@ -33,6 +33,7 @@
"devDependencies": {
"autoprefixer": "^9.8.6",
"clean-css-cli": "^4.3.0",
"concurrently": "^5.3.0",
"mkdirp": "^1.0.4",
"node-sass": "^4.14.1",
"onchange": "^7.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/dragsort.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
.dragsort--dragStart .dragsort--hide {
width: 0 !important;
height: 0 !important;
padding: 0;
/* padding: 0;
margin: 0;
border-width: 0;
border-width: 0; */
}

.dragsort--dragStart > *{
Expand Down
20 changes: 14 additions & 6 deletions src/dragsort.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,26 @@ var DragSort = (function (elm) {
},

dragstart(e, elm) {
_current = this;
var draggableElm = this.getDraggableElm(elm);
_current = this

var draggableElm = this.getDraggableElm(elm),
clientRect;

if (!draggableElm) {
_current = {};
_current = {}
return
}

this.source = this.getInitialState()
this.target = this.getInitialState()

clientRect = draggableElm.getBoundingClientRect() // more accurate than offsetWidth/offsetHeight (not rounded)

this.source.elm = draggableElm
this.source.idx = this.getNodeIndex(draggableElm)
this.source.size.width = draggableElm.offsetWidth //elm.getBoundingClientRect();
this.source.size.height = draggableElm.offsetHeight
this.source.size.width = clientRect.width
this.source.size.height = clientRect.height

// https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/effectAllowed
e.dataTransfer.effectAllowed = 'move'

Expand All @@ -104,10 +110,12 @@ var DragSort = (function (elm) {
},

afterDragStart() {
var prop = this.settings.mode == 'vertical' ? 'height' : 'width'

this.parentElm.classList.add(`${this.namespace}--dragStart`)

// hiding the source element with transition, the initial "width" is set to occupy the same space
this.source.elm.style.width = this.source.elm.clientWidth + 'px'
this.source.elm.style[prop] = this.source.size[prop] + 'px'

this.source.elm.classList.add(`${this.namespace}--dragElem`)
},
Expand Down

0 comments on commit 1494ad6

Please sign in to comment.