If you've been keeping up with activity in the F# world, you have no doubt seen great strides in a number of areas such as expansion of support for F# on different platforms and an ever increasing number of libraries and frameworks. One of these libraries that I've been playing with of late is named FunScript.
What is FunScript?
provides a nice definition.
jQuery UI Drag/Drop Example
In this example, we create a simple TODO type of application using jQuery UI, FunScript, and the TypeScript type provider that FunScript provides. You can find the full example with detailed comments on the
FunScript GitHub site
type ts = FunScript.TypeScript.Api<
let addTasksToElement (elementSelector:string) tasks =
let tasks = tasks
|> Array.mapi (fun index task ->
"<div class='ui-widget-content draggable'>" +
task + "</div>" |> box)
ts.jQuery.Invoke(elementSelector).append tasks |> ignore
let populateTasks () =
let tasksToDo =
[| "Persist the tasks to a data store."
"Add new tasks."
"Remove a task." |]
let tasksDone =
[| "Allow tasks to be moved to done."
"Add dynamic population of tasks." |]
addTasksToElement ".tasksNotStarted" tasksToDo
addTasksToElement ".tasksDone" tasksDone
let initDragAndDrop () =
let dragSettings = ts.Draggable(revert = "invalid", cursor = "move",
helper = "clone" )
ts.jQuery.Invoke(".draggable").draggable(dragSettings) |> ignore
let dropSettings = ts.Droppable(hoverClass = "ui-state-active",
accept = ".draggable")
dropSettings.drop <- immediateFn
<| TupledDelegate<ts.Event, ts.DroppableEventUIParam,
ts.JQuery>(fun e ui ->
ts.jQuery.Invoke(".droppable").droppable(dropSettings) |> ignore
let main() =