coffeescript-ui
Version:
Coffeescript User Interface System
139 lines (108 loc) • 3.27 kB
text/coffeescript
###
* coffeescript-ui - Coffeescript User Interface System (CUI)
* Copyright (c) 2013 - 2016 Programmfabrik GmbH
* MIT Licence
* https://github.com/programmfabrik/coffeescript-ui, http://www.coffeescript-ui.org
###
class CUI.Sortable extends CUI.Draggable
= "sortable"
initOpts: ->
super()
allowSort:
mandatory: true
default: (ev, from_idx, to_idx) ->
return true
check: Function
sorted:
mandatory: true
default: (ev, from_idx, to_idx) ->
alert("You sorted item #{from_idx} to #{to_idx}.")
check: Function
getSortTarget: (target, node) ->
els = CUI.dom.elementsUntil(target, null, node)
if els.length > 1
els[els.length-2]
else
return null
getClass: ->
if
"cui-drag-drop-select"
else
super()
readOpts: ->
super()
=
get_child_number: (child) ->
for c, idx in .children
if c == child
return idx
null
move_element: (source_idx, dest_idx) ->
$source = .children[source_idx]
$dest = .children[dest_idx]
if source_idx == dest_idx
return
if source_idx < dest_idx
CUI.globalDrag.noClickKill = true
CUI.dom.insertAfter($dest, $source)
else if source_idx > dest_idx
CUI.globalDrag.noClickKill = true
CUI.dom.insertBefore($dest, $source)
CUI.dom.syncAnimatedClone()
@
start_drag: (ev, $target, diff) ->
CUI.globalDrag.sort_source =
CUI.globalDrag.sort_source.classList.add("cui-sortable-placeholder")
CUI.globalDrag.start_idx =
CUI.dom.addClass(, 'cui-sorting')
CUI.dom.initAnimatedClone()
getCloneSourceForHelper: ->
__findClosestSon: ($target) ->
# find the closest child of the target
parents = CUI.dom.parentsUntil($target, null, )
if parents[parents.length-1] == window
return null
switch parents.length
when 0
return null
when 1
return $target
else
return parents[parents.length - 2]
do_drag: (ev, $target, diff) ->
target_child =
if not target_child
return
source_idx =
dest_idx =
if
@
init_drag: (ev, $target) ->
# we need to move the target to the element undernith the cursor
super(ev, )
stop_drag: (ev) ->
super(ev)
end_drag: (ev) ->
super(ev)
cleanup_drag: (ev) ->
super(ev)
CUI.dom.removeClass(, 'cui-sorting')
CUI.globalDrag.sort_source.classList.remove("cui-sortable-placeholder")
CUI.dom.removeAnimatedClone()
__end_drag: (ev, stopped) ->
# move dragged object into position
curr_idx =
if CUI.globalDrag.start_idx == curr_idx
return
if stopped
else
return