Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
leizi929
Sortable
提交
54ec83bb
S
Sortable
项目概览
leizi929
/
Sortable
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Sortable
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
54ec83bb
编写于
2月 17, 2016
作者:
R
RubaXa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
+ initial
上级
2876924a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
199 addition
and
0 deletion
+199
-0
tests/index.html
tests/index.html
+27
-0
tests/sortable.tests.js
tests/sortable.tests.js
+17
-0
tests/src/raf.js
tests/src/raf.js
+38
-0
tests/src/simulate.js
tests/src/simulate.js
+117
-0
未找到文件。
tests/index.html
0 → 100644
浏览文件 @
54ec83bb
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
/>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
/>
<meta
property=
"og:image"
content=
"/st/og-image.png"
/>
<title>
Sortable :: Tests
</title>
</head>
<body>
<div
id=
"canvas"
>
<ul
id=
"simple"
>
<li>
item 1
</li>
<li>
item 2
</li>
<li>
item 3
</li>
</ul>
</div>
<script
src=
"./src/raf.js"
></script>
<script
src=
"./src/simulate.js"
></script>
<script
src=
"../Sortable.js"
></script>
<script
src=
"./sortable.tests.js"
></script>
</body>
</html>
tests/sortable.tests.js
0 → 100644
浏览文件 @
54ec83bb
'
use strict
'
;
Sortable
.
create
(
simple
);
simulateDrag
({
from
:
{
el
:
'
#simple
'
,
index
:
0
},
to
:
{
el
:
'
#simple
'
,
index
:
'
last
'
}
},
function
()
{
});
tests/src/raf.js
0 → 100644
浏览文件 @
54ec83bb
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(
function
requestAnimationFramePolyfill
()
{
'
use strict
'
;
var
lastTime
=
0
;
var
vendors
=
[
'
ms
'
,
'
moz
'
,
'
webkit
'
,
'
o
'
];
for
(
var
x
=
0
;
x
<
vendors
.
length
&&
!
window
.
requestAnimationFrame
;
++
x
)
{
window
.
requestAnimationFrame
=
window
[
vendors
[
x
]
+
'
RequestAnimationFrame
'
];
window
.
cancelAnimationFrame
=
window
[
vendors
[
x
]
+
'
CancelAnimationFrame
'
]
||
window
[
vendors
[
x
]
+
'
CancelRequestAnimationFrame
'
];
}
if
(
!
window
.
requestAnimationFrame
)
{
window
.
requestAnimationFrame
=
function
(
callback
,
element
)
{
var
currTime
=
new
Date
().
getTime
();
var
timeToCall
=
Math
.
max
(
0
,
16
-
(
currTime
-
lastTime
));
var
id
=
window
.
setTimeout
(
function
()
{
callback
(
currTime
+
timeToCall
);
},
timeToCall
);
lastTime
=
currTime
+
timeToCall
;
return
id
;
};
}
if
(
!
window
.
cancelAnimationFrame
)
{
window
.
cancelAnimationFrame
=
function
(
id
)
{
clearTimeout
(
id
);
};
}
}());
tests/src/simulate.js
0 → 100644
浏览文件 @
54ec83bb
(
function
()
{
'
use strict
'
;
function
simulateEvent
(
el
,
type
,
options
)
{
var
event
;
var
ownerDocument
=
el
.
ownerDocument
;
options
=
options
||
{};
if
(
/^mouse/
.
test
(
type
))
{
event
=
ownerDocument
.
createEvent
(
'
MouseEvents
'
);
event
.
initMouseEvent
(
type
,
true
,
true
,
ownerDocument
.
defaultView
,
options
.
button
,
options
.
screenX
,
options
.
screenY
,
options
.
clientX
,
options
.
clientY
,
options
.
ctrlKey
,
options
.
altKey
,
options
.
shiftKey
,
options
.
metaKey
,
options
.
button
,
el
);
}
else
{
event
=
ownerDocument
.
createEvent
(
'
CustomEvent
'
);
event
.
initCustomEvent
(
type
,
true
,
true
,
ownerDocument
.
defaultView
,
options
.
button
,
options
.
screenX
,
options
.
screenY
,
options
.
clientX
,
options
.
clientY
,
options
.
ctrlKey
,
options
.
altKey
,
options
.
shiftKey
,
options
.
metaKey
,
options
.
button
,
el
);
event
.
dataTransfer
=
{
data
:
{},
setData
:
function
(
type
,
val
)
{
this
.
data
[
type
]
=
val
;
},
getData
:
function
(
type
)
{
return
this
.
data
[
type
];
}
};
}
if
(
el
.
dispatchEvent
)
{
el
.
dispatchEvent
(
event
);
}
else
if
(
el
.
fireEvent
)
{
el
.
fireEvent
(
'
on
'
+
type
,
event
);
}
return
event
;
}
function
getTraget
(
target
)
{
var
children
=
document
.
getElementById
(
target
.
el
.
substr
(
1
)).
children
;
return
(
children
[
target
.
index
]
||
children
[
target
.
index
===
'
first
'
?
0
:
-
1
]
||
children
[
target
.
index
===
'
last
'
?
children
.
length
-
1
:
-
1
]
);
}
function
getRect
(
el
)
{
var
rect
=
el
.
getBoundingClientRect
();
var
width
=
rect
.
right
-
rect
.
left
;
var
height
=
rect
.
bottom
-
rect
.
top
;
return
{
x
:
rect
.
left
,
y
:
rect
.
top
,
cx
:
rect
.
left
+
width
/
2
,
cy
:
rect
.
top
+
height
/
2
,
w
:
width
,
h
:
height
,
hw
:
width
/
2
,
wh
:
height
/
2
}
}
function
simulateDrag
(
options
,
callback
)
{
var
fromEl
=
getTraget
(
options
.
from
);
var
toEl
=
getTraget
(
options
.
to
);
var
fromRect
=
getRect
(
fromEl
);
var
toRect
=
getRect
(
toEl
);
var
dotEl
=
document
.
createElement
(
'
div
'
);
dotEl
.
style
.
cssText
=
'
position: fixed; background: red; width: 10px; height: 10px; opacity: .4; margin: -5px 0 0 -5px; transition: all .3s; border-radius: 100%;
'
;
document
.
body
.
appendChild
(
dotEl
);
var
startTime
=
new
Date
().
getTime
();
var
duration
=
options
.
duration
||
1000
;
simulateEvent
(
fromEl
,
'
mousedown
'
,
{
button
:
0
});
simulateEvent
(
toEl
,
'
dragstart
'
);
requestAnimationFrame
(
function
loop
()
{
var
progress
=
(
new
Date
().
getTime
()
-
startTime
)
/
duration
;
var
x
=
fromRect
.
cx
+
(
toRect
.
cx
-
fromRect
.
cx
)
*
progress
;
var
y
=
fromRect
.
cy
+
(
toRect
.
cy
-
fromRect
.
cy
)
*
progress
;
var
overEl
=
fromEl
.
ownerDocument
.
elementFromPoint
(
x
,
y
);
dotEl
.
style
.
display
=
'
none
'
;
dotEl
.
style
.
left
=
x
+
'
px
'
;
dotEl
.
style
.
top
=
y
+
'
px
'
;
overEl
&&
simulateEvent
(
overEl
,
'
dragover
'
,
{
clientX
:
x
,
clientY
:
y
});
if
(
progress
<
1
)
{
dotEl
.
style
.
display
=
''
;
requestAnimationFrame
(
loop
);
}
else
{
simulateEvent
(
toEl
,
'
drop
'
);
callback
();
}
});
}
// Export
window
.
simulateEvent
=
simulateEvent
;
window
.
simulateDrag
=
simulateDrag
;
})();
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录