mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-29 11:30:28 +00:00
8b9723f6c7
* initial POC * clean up the code * Add documentation changes * Improve docs
81 lines
5.2 KiB
Plaintext
81 lines
5.2 KiB
Plaintext
caption: droppable
|
|
created: 20170406082820317
|
|
modified: 20240612125454153
|
|
tags: Widgets TriggeringWidgets
|
|
title: DroppableWidget
|
|
type: text/vnd.tiddlywiki
|
|
|
|
\procedure drop-on-tags-actions()
|
|
<$action-log actionTiddlerList=<<actionTiddlerList>>/>
|
|
<$action-setfield $tiddler="$:/temp/drop/TitleList" $field="text" text=<<actionTiddlerList>> type="text/plain"/>
|
|
\end
|
|
|
|
\procedure droppable-image-actions()
|
|
<$action-setfield $tiddler=<<actionTiddler>> $field="icon" $value=<<currentTiddler>>/>
|
|
\end
|
|
|
|
\procedure colour-demo-body()
|
|
<$droppable actions=<<droppable-colour-actions>>>
|
|
<span style=`display: inline-block; width: 1em; height: 1em;background-color: $(currentTiddler)$;`>
|
|
</span>
|
|
</$droppable>
|
|
\end
|
|
|
|
\procedure droppable-colour-actions()
|
|
<$action-setfield $tiddler=<<actionTiddler>> $field="color" $value=<<currentTiddler>>/>
|
|
\end
|
|
|
|
The `droppable` widget creates a DOM element onto which dragged items can be dropped by the user, triggering the specified actions. It only works on browsers that support drag and drop, which typically means desktop browsers, but [[there are workarounds|Mobile Drag And Drop Shim Plugin]].
|
|
|
|
See DragAndDropMechanism for an overview.
|
|
|
|
! Content and Attributes
|
|
|
|
|! Attribute |! Description |
|
|
|actions |Actions to be performed when items are dropped. It activates ''1 action per item'' |
|
|
|listActions |<<.from-version "5.3.4">> Actions to be performed when items are dropped. It activates ''1 action for'' a the whole ''list of items'' |
|
|
|class |Optional CSS classes to assign to the draggable element. The class `tc-droppable` is added automatically, and the class `tc-dragover` is applied while an item is being dragged over the droppable element |
|
|
|tag |Optional tag to override the default of a "div" element when the widget is rendered in block mode, or a "span" element when it is rendered in inline mode |
|
|
|enable |<<.from-version "5.1.22">> Optional value "no" to disable the droppable functionality (defaults to "yes") |
|
|
|data-* |<<.from-version "5.3.2">> Optional [[data attributes|https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes]] to be assigned to the HTML element |
|
|
|style.* |<<.from-version "5.3.2">> Optional [[CSS properties|https://developer.mozilla.org/en-US/docs/Web/CSS/Reference]] to be assigned to the HTML element |
|
|
|
|
''Within the action string'', the following variables are generated by the DroppableWidget:
|
|
|
|
|!Variables |!Description |
|
|
|`actionTiddler` |For parameter <<.param actions>>, the [[actionTiddler Variable]] contains the title of the item being dropped |
|
|
|`actionTiddlerList` |For parameter <<.param listActions>> the [[actionTiddlerList Variable]] contains a [[Title List]] of all the items being dropped |
|
|
|`modifier` |The [[modifier Variable]] contains the modifier key held while dragging (can be normal, ctrl, shift or ctrl-shift) |
|
|
|
|
<<.note """Note that the <<.var actionTiddler>> variable holds a single, unquoted title. This is unlike the DraggableWidget which uses the same variable to pass a quoted [[Title List]].""">>
|
|
|
|
! Examples
|
|
|
|
This example displays a palette of icons. Dragging a tiddler onto one of the icons assigns that icon to the tiddler.
|
|
|
|
<$list filter="[all[tiddlers+shadows]tag[$:/tags/Image]sort[title]]">
|
|
<$droppable actions=<<droppable-image-actions>>>
|
|
<$transclude/>
|
|
</$droppable>
|
|
</$list>
|
|
|
|
---
|
|
|
|
Similarly, this example shows a palette of colours. Dragging a tiddler onto one of the colours assigns that colour to be used for rendering the icon of the tiddler.
|
|
|
|
<$list filter="LightPink Pink Crimson LavenderBlush PaleVioletRed HotPink DeepPink MediumVioletRed Orchid Thistle Plum Violet Magenta Fuchsia DarkMagenta Purple MediumOrchid DarkViolet DarkOrchid Indigo BlueViolet MediumPurple MediumSlateBlue SlateBlue DarkSlateBlue Lavender GhostWhite Blue MediumBlue MidnightBlue DarkBlue Navy RoyalBlue CornflowerBlue LightSteelBlue LightSlateGrey SlateGrey DodgerBlue AliceBlue SteelBlue LightSkyBlue SkyBlue DeepSkyBlue LightBlue PowderBlue CadetBlue Azure LightCyan PaleTurquoise Cyan Aqua DarkTurquoise DarkSlateGrey DarkCyan Teal MediumTurquoise LightSeaGreen Turquoise Aquamarine MediumAquamarine MediumSpringGreen MintCream SpringGreen MediumSeaGreen SeaGreen Honeydew LightGreen PaleGreen DarkSeaGreen LimeGreen Lime ForestGreen Green DarkGreen Chartreuse LawnGreen GreenYellow DarkOliveGreen YellowGreen OliveDrab Beige LightGoldenrodYellow Ivory LightYellow Yellow Olive DarkKhaki LemonChiffon PaleGoldenrod Khaki Gold Cornsilk Goldenrod DarkGoldenrod FloralWhite OldLace Wheat Moccasin Orange PapayaWhip BlanchedAlmond NavajoWhite AntiqueWhite Tan BurlyWood Bisque DarkOrange Linen Peru PeachPuff SandyBrown Chocolate SaddleBrown Seashell Sienna LightSalmon Coral OrangeRed DarkSalmon Tomato MistyRose Salmon Snow LightCoral RosyBrown IndianRed Red Brown FireBrick DarkRed Maroon White WhiteSmoke Gainsboro LightGrey Silver DarkGrey Grey DimGrey Black">
|
|
<<colour-demo-body>>
|
|
</$list>
|
|
|
|
---
|
|
|
|
Drag the tag pill <<tag HelloThere>> or a single tiddler link [[HelloThere]] into the "Drop Area" below. It will show the "Title List" stored in $:/temp/drop/TitleList
|
|
|
|
<<.note title:""
|
|
_:"""<$droppable listActions=<<drop-on-tags-actions>> >
|
|
''Drop'' the tagpill or a link into this ''area''.<br>
|
|
~TitleList: <$transclude $tiddler="$:/temp/drop/TitleList"/>
|
|
</$droppable>""">>
|
|
|
|
|