Drag and drop in uki
As of 0.1 ukijs gets support for drag and drop events based on w3c d&d specification (dragstart, drag, dragstop, dragover, dragenter, dragleave, drop). So in new browsers (FF3.5+, latest webkits) uki will use native events thus allowing to drag items within and outside of the browser window. For the rest of the browser crowd (IE, Opera, previous FF) uki will emulate exactly the same behavior within browser.
Screencast: drag and drop with uki from Volodya Kolesnikov on Vimeo.
Events
To make view draggable you have to mark it with draggable attribute. All uki views support it:
uki({ view: 'List', draggable: true ... })
Then add the dragstart event:
uki('List').draggstart(function(e) {
// set the data that will be dragged
e.dataTransfer.setData('text/plain', this.selectedRows().join('\n'));
// set the drag feedback image (both uki views
// and simple dom nodes are allowed)
e.dataTransfer.setDragImage(uki(
{ view: 'Label', rect: '100 20', anchors: 'left top', inset: '0 5',
background: 'cssBox(border: 1px solid #CCC;background:#EEF)',
text: this.selectedRows().length + ' rows' }
), 10, 10);
// set allowed affect to 'copy', 'move' etc
e.dataTransfer.effectAllowed = 'copy';
});
For the drop targets you need to add dragover and drop events:
uki('[name=target]')
.dragover(function(e) { // required
e.preventDefault();
e.dataTransfer.dropEffect = 'copy'; // same as effectAllowed
})
.dragenter(function(e) { // optional
this.text('enter');
})
.dragleave(function(e) { // optional
this.text('leave');
})
.drop(function(e) {
alert(e.dataTransfer.getData('text/plain'))
});
See the demo
[...] ondragstart or drop. And it supports them in all browsers. See the screencast, demo and read the blog post to get more info on this [...]
0.1.0 release « ukijs blog
March 19, 2010 at 2:38 pm
[...] Drag and Drop With Simple UI Kit [...]
HTML5 Unleashed: Tips, Tricks and Techniques | MyInfoNetHome.Info
May 19, 2010 at 6:08 am
[...] Drag and Drop With Simple UI Kit [...]
彼岸(Into the wild) » Blog Archive » HTML5 Unleashed: Tips, Tricks and Techniques
May 24, 2010 at 10:00 am
[...] 基于 Simple UI Kit 的拖放 [...]
解读 HTML5:建议、技巧和技术 - 幸福收藏夹
July 20, 2010 at 1:45 pm
[...] 基于 Simple UI Kit 的拖放 [...]
给HTML5的建议、HTML5的技巧和技术 | 实时信息(shtion.com)
July 20, 2010 at 5:15 pm
[...] 基于 Simple UI Kit 的拖放 [...]
解读 HTML5:建议、技巧和技术 | FEDEV
July 23, 2010 at 8:30 am
[...] 基于 Simple UI Kit 的拖放 [...]
解读 HTML5:建议、技巧和技术 | 田园牧歌
July 31, 2010 at 4:23 am
[...] 基于 Simple UI Kit 的拖放 [...]
Soun's Blog » Blog Archive » 解读 HTML5:建议、技巧和技术。
August 17, 2010 at 3:22 am
[...] 基于 Simple UI Kit 的拖放 [...]
Html5从入门到精通 – 王魏博客-关注前端,记录生活,记录互联网
December 6, 2010 at 2:07 am
[...] 基于 Simple UI Kit 的拖放 [...]
解读 HTML5:建议、技巧和技术 | 飞翔代码
March 2, 2011 at 5:50 am
[...] Drag and Drop With Simple UI Kit [...]
HTML5 Unleashed: Tips, Tricks and Techniques - Leebay's Blog
March 6, 2011 at 9:07 am