Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
leizi929
Sortable
提交
548460af
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 搜索 >>
提交
548460af
编写于
2月 20, 2016
作者:
R
RubaXa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
* qunit
上级
652098ad
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
180 addition
and
54 deletion
+180
-54
Gruntfile.js
Gruntfile.js
+26
-3
tests/index.html
tests/index.html
+15
-20
tests/sortable.tests.js
tests/sortable.tests.js
+92
-11
tests/src/polyfills.js
tests/src/polyfills.js
+28
-0
tests/src/qunit.ext.js
tests/src/qunit.ext.js
+0
-13
tests/src/simulate.js
tests/src/simulate.js
+19
-7
未找到文件。
Gruntfile.js
浏览文件 @
548460af
...
...
@@ -18,7 +18,11 @@ module.exports = function (grunt) {
},
jshint
:
{
all
:
[
'
*.js
'
,
'
!*.min.js
'
],
all
:
[
'
*.js
'
,
'
!*.min.js
'
,
'
tests/**/*.js
'
],
options
:
{
jshintrc
:
true
...
...
@@ -48,7 +52,25 @@ module.exports = function (grunt) {
}
},
jquery
:
{}
jquery
:
{},
qunit
:
{
all
:
[
'
tests/index.html
'
],
options
:
{
'
--web-security
'
:
'
no
'
,
coverage
:
{
src
:
[
'
Sortable.js
'
],
instrumentedFiles
:
'
temp/
'
,
htmlReport
:
'
report/coverage/
'
,
coberturaReport
:
'
report/
'
,
baseUrl
:
"
./coverage
"
,
linesThresholdPct
:
99
,
functionsThresholdPct
:
100
,
branchesThresholdPct
:
90
,
statementsThresholdPct
:
90
}
}
}
});
...
...
@@ -91,6 +113,7 @@ module.exports = function (grunt) {
grunt
.
loadNpmTasks
(
'
grunt-version
'
);
grunt
.
loadNpmTasks
(
'
grunt-contrib-jshint
'
);
grunt
.
loadNpmTasks
(
'
grunt-contrib-uglify
'
);
grunt
.
loadNpmTasks
(
'
grunt-qunit-istanbul
'
);
grunt
.
loadNpmTasks
(
'
grunt-exec
'
);
// Meteor tasks
...
...
@@ -98,6 +121,6 @@ module.exports = function (grunt) {
grunt
.
registerTask
(
'
meteor-publish
'
,
'
exec:meteor-publish
'
);
grunt
.
registerTask
(
'
meteor
'
,
[
'
meteor-test
'
,
'
meteor-publish
'
]);
grunt
.
registerTask
(
'
tests
'
,
[
'
jshint
'
]);
grunt
.
registerTask
(
'
tests
'
,
[
'
jshint
'
,
'
qunit
'
]);
grunt
.
registerTask
(
'
default
'
,
[
'
tests
'
,
'
version
'
,
'
uglify:dist
'
]);
};
tests/index.html
浏览文件 @
548460af
...
...
@@ -8,32 +8,27 @@
<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>
<style>
.styled
{
margin
:
0
;
padding
:
0
;
list-style
:
none
;
}
.styled
>
*
{
padding
:
5px
10px
;
}
</style>
<div
id=
"fixture"
></div>
<div
id=
"qunit"
></div>
<div
id=
"qunit-fixture"
></div>
<link
rel=
"stylesheet"
href=
"//code.jquery.com/qunit/qunit-1.21.0.css
"
/>
<script
src=
"//code.jquery.com/qunit/qunit-1.21.0.js"
></script>
<link
href=
"http://code.jquery.com/qunit/qunit-1.21.0.css"
rel=
"stylesheet
"
/>
<script
src=
"
http:
//code.jquery.com/qunit/qunit-1.21.0.js"
></script>
<script
src=
"./src/
raf
.js"
></script>
<script
src=
"./src/
polyfills
.js"
></script>
<script
src=
"./src/simulate.js"
></script>
<script
src=
"./src/qunit.ext.js"
></script>
<script
src=
"../Sortable.js"
></script>
<script>
Sortable
.
create
(
simple
);
</script>
<script
src=
"./sortable.tests.js"
></script>
</body>
</html>
tests/sortable.tests.js
浏览文件 @
548460af
/* global QUnit, fixture, Sortable, simulateDrag */
'
use strict
'
;
QUnit
.
module
(
'
Sortable
'
);
QUnit
.
sortableTest
(
'
simple
'
,
{
from
:
{
el
:
'
#simple
'
,
index
:
0
},
function
createSortableList
(
options
)
{
var
listEl
=
document
.
createElement
(
'
div
'
);
var
length
=
options
.
length
;
var
withHandle
=
options
.
withHandle
;
if
(
withHandle
)
{
options
.
handle
=
withHandle
;
}
listEl
.
className
=
'
js-list
'
;
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
var
el
=
document
.
createElement
(
'
div
'
);
to
:
{
el
:
'
#simple
'
,
index
:
'
last
'
el
.
appendChild
(
document
.
createTextNode
(
'
Item
'
+
(
i
+
1
)));
el
.
className
=
'
js-list-item
'
;
listEl
.
appendChild
(
el
);
}
},
function
(
assert
,
scope
)
{
assert
.
ok
(
scope
.
toList
.
contains
(
scope
.
target
),
'
container
'
);
assert
.
equal
(
scope
.
target
,
scope
.
toList
.
lastElementChild
,
'
position
'
);
fixture
.
appendChild
(
listEl
);
return
{
el
:
listEl
,
sortable
:
Sortable
.
create
(
listEl
,
options
),
destroy
:
function
()
{
this
.
sortable
.
destroy
();
fixture
.
removeChild
(
this
.
el
);
this
.
el
=
null
;
this
.
sortable
=
null
;
}
};
}
QUnit
.
test
(
'
core
'
,
function
(
assert
)
{
var
done
=
assert
.
async
();
var
events
=
{};
var
logEvent
=
function
(
evt
)
{
events
[
this
+
evt
.
type
]
=
true
;
};
var
list
=
createSortableList
({
length
:
3
,
onStart
:
logEvent
.
bind
(
'
on
'
),
onMove
:
logEvent
.
bind
(
'
on
'
),
onUpdate
:
logEvent
.
bind
(
'
on
'
),
onEnd
:
logEvent
.
bind
(
'
on
'
)
});
list
.
el
.
addEventListener
(
'
start
'
,
logEvent
.
bind
(
''
));
list
.
el
.
addEventListener
(
'
move
'
,
logEvent
.
bind
(
''
));
list
.
el
.
addEventListener
(
'
update
'
,
logEvent
.
bind
(
''
));
list
.
el
.
addEventListener
(
'
end
'
,
logEvent
.
bind
(
''
));
simulateDrag
({
from
:
{
el
:
list
.
el
,
index
:
0
},
to
:
{
index
:
'
last
'
},
ontap
:
function
()
{
assert
.
ok
(
list
.
el
.
firstChild
.
className
.
indexOf
(
'
sortable-chosen
'
)
>
-
1
,
'
sortable-choose
'
);
},
ondragstart
:
function
()
{
setTimeout
(
function
()
{
assert
.
ok
(
list
.
el
.
firstChild
.
className
.
indexOf
(
'
sortable-ghost
'
)
>
-
1
,
'
sortable-ghost
'
);
},
0
);
}
},
function
()
{
assert
.
deepEqual
(
Object
.
keys
(
events
),
[
'
start
'
,
'
onstart
'
,
'
move
'
,
'
onmove
'
,
'
update
'
,
'
onupdate
'
,
'
end
'
,
'
onend
'
]);
list
.
destroy
();
done
();
});
});
//QUnit.test('handle', function (assert) {
// var done = assert.async();
// var list = createSortableList({
// length: 3,
// withHandle: true,
// onStart: function () { assert.ok(false, 'start'); },
// onEnd: function () { assert.ok(false, 'end'); }
// });
//});
tests/src/
raf
.js
→
tests/src/
polyfills
.js
浏览文件 @
548460af
...
...
@@ -36,3 +36,31 @@
};
}
}());
if
(
!
Function
.
prototype
.
bind
)
{
Function
.
prototype
.
bind
=
function
(
oThis
)
{
'
use strict
'
;
if
(
typeof
this
!==
'
function
'
)
{
// ближайший аналог внутренней функции
// IsCallable в ECMAScript 5
throw
new
TypeError
(
'
Function.prototype.bind - what is trying to be bound is not callable
'
);
}
var
aArgs
=
Array
.
prototype
.
slice
.
call
(
arguments
,
1
),
fToBind
=
this
,
fNOP
=
function
()
{},
fBound
=
function
()
{
return
fToBind
.
apply
(
this
instanceof
fNOP
&&
oThis
?
this
:
oThis
,
aArgs
.
concat
(
Array
.
prototype
.
slice
.
call
(
arguments
)));
};
fNOP
.
prototype
=
this
.
prototype
;
fBound
.
prototype
=
new
fNOP
();
return
fBound
;
};
}
tests/src/qunit.ext.js
已删除
100644 → 0
浏览文件 @
652098ad
(
function
()
{
'
use strict
'
;
QUnit
.
sortableTest
=
function
sortableTest
(
name
,
options
,
fn
)
{
QUnit
.
test
(
name
,
function
(
assert
)
{
var
done
=
assert
.
async
();
var
data
=
simulateDrag
(
options
,
function
()
{
fn
(
assert
,
data
,
options
);
done
();
});
});
};
})();
tests/src/simulate.js
浏览文件 @
548460af
...
...
@@ -42,7 +42,9 @@
}
function
getTraget
(
target
)
{
var
children
=
document
.
getElementById
(
target
.
el
.
substr
(
1
)).
children
;
var
el
=
typeof
target
.
el
===
'
string
'
?
document
.
getElementById
(
target
.
el
.
substr
(
1
))
:
target
.
el
;
var
children
=
el
.
children
;
return
(
children
[
target
.
index
]
||
children
[
target
.
index
===
'
first
'
?
0
:
-
1
]
||
...
...
@@ -58,16 +60,18 @@
return
{
x
:
rect
.
left
,
y
:
rect
.
top
,
cx
:
rect
.
left
+
width
/
2
,
cy
:
rect
.
top
+
height
/
2
,
cx
:
rect
.
left
+
width
/
2
,
cy
:
rect
.
top
+
height
/
2
,
w
:
width
,
h
:
height
,
hw
:
width
/
2
,
wh
:
height
/
2
}
hw
:
width
/
2
,
wh
:
height
/
2
}
;
}
function
simulateDrag
(
options
,
callback
)
{
options
.
to
.
el
=
options
.
to
.
el
||
options
.
from
.
el
;
var
fromEl
=
getTraget
(
options
.
from
);
var
toEl
=
getTraget
(
options
.
to
);
...
...
@@ -83,10 +87,16 @@
var
duration
=
options
.
duration
||
1000
;
simulateEvent
(
fromEl
,
'
mousedown
'
,
{
button
:
0
});
options
.
ontap
&&
options
.
ontap
();
simulateEvent
(
toEl
,
'
dragstart
'
);
requestAnimationFrame
(
function
()
{
options
.
ondragstart
&&
options
.
ondragstart
();
});
requestAnimationFrame
(
function
loop
()
{
var
progress
=
(
new
Date
().
getTime
()
-
startTime
)
/
duration
;
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
);
...
...
@@ -95,6 +105,7 @@
dotEl
.
style
.
left
=
x
+
'
px
'
;
dotEl
.
style
.
top
=
y
+
'
px
'
;
//console.log(overEl.parentNode.parentNode.parentNode.id, overEl.className, x, y);
overEl
&&
simulateEvent
(
overEl
,
'
dragover
'
,
{
clientX
:
x
,
clientY
:
y
...
...
@@ -104,6 +115,7 @@
dotEl
.
style
.
display
=
''
;
requestAnimationFrame
(
loop
);
}
else
{
options
.
ondragend
&&
options
.
ondragend
();
simulateEvent
(
toEl
,
'
drop
'
);
callback
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录