draggable.lzx
<library>
<include href="utils/states/dragstate.lzx"/>
<include href="dragmanager.lzx"/>
<include href="droppable.lzx"/>
<mixin name="draggable">
<doc>
<tag name="shortdesc"><text>A mixin that adds easy drag and drop support to view.</text></tag>
<text>
<p>The <tagname>draggable</tagname> mixin adds easy drag and drop support to <sgmltag class="element" role="LzView"><view></sgmltag></p>
<example title="Example of Using Drag and Drop" query-parameters="lzr=swf10"><programlisting>
<canvas width="100%" height="450">
<!-- can be dragged onto any droppable view -->
<view with="draggable" width="100" height="100" bgcolor="${this.dragover ? 'red' : 'green'}" opacity="${this.dragging ? .5 : 1}">
<handler name="ondragging" args="view:lz.view">
Debug.info('ondragging draggable', view);
</handler>
<handler name="ondragover" args="view:lz.view">
Debug.info('ondragover draggable', view);
</handler>
<handler name="ondrop" args="view:lz.view">
Debug.info('ondrop draggable', view);
</handler>
</view>
<!-- can only be dragged only onto droppable text -->
<view with="draggable" destinationtypes="text" y="200" width="100" height="100" bgcolor="${this.dragover ? 'red' : 'green'}" opacity="${this.dragging ? .5 : 1}">
<handler name="ondragging" args="view:lz.view">
Debug.info('ondragging draggable', view);
</handler>
<handler name="ondragover" args="view:lz.view">
Debug.info('ondragover draggable', view);
</handler>
<handler name="ondrop" args="view:lz.view">
Debug.info('ondrop draggable', view);
</handler>
</view>
<!-- can be dragged onto any droppable view -->
<text with="draggable" y="400" bgcolor="${this.dragover ? 'red' : 'green'}" opacity="${this.dragging ? .5 : 1}">Drag anywhere
<handler name="ondragging" args="view:lz.view">
Debug.info('ondragging draggable', view);
</handler>
<handler name="ondragover" args="view:lz.view">
Debug.info('ondragover draggable', view);
</handler>
<handler name="ondrop" args="view:lz.view">
Debug.info('ondrop draggable', view);
</handler>
</text>
<!-- accepts any draggable view-->
<view with="droppable" x="200" width="100" height="100" bgcolor="${this.dragging ? 'yellow' : 'orange'}" opacity="${this.dragover ? .5 : 1}">
<handler name="ondragging" args="view:lz.view">
Debug.info('ondragging droppable', view);
</handler>
<handler name="ondragover" args="view:lz.view">
Debug.info('ondragover droppable', view);
</handler>
<handler name="ondrop" args="view:lz.view">
Debug.info('ondrop droppable', view);
</handler>
</view>
<!-- accepts any draggable view-->
<text with="droppable" x="200" y="200" bgcolor="${this.dragging ? 'yellow' : 'orange'}" opacity="${this.dragover ? .5 : 1}">Drop here
<handler name="ondragging" args="view:lz.view">
Debug.info('ondragging droppable', view);
</handler>
<handler name="ondragover" args="view:lz.view">
Debug.info('ondragover droppable', view);
</handler>
<handler name="ondrop" args="view:lz.view">
Debug.info('ondrop droppable', view);
</handler>
</text>
<!-- only accepts draggable text -->
<text with="droppable" sourcetypes="text" x="200" y="400" bgcolor="${this.dragging ? 'yellow' : 'orange'}" opacity="${this.dragover ? .5 : 1}">Drop text here
<handler name="ondragging" args="view:lz.view">
Debug.info('ondragging droppable', view);
</handler>
<handler name="ondragover" args="view:lz.view">
Debug.info('ondragover droppable', view);
</handler>
<handler name="ondrop" args="view:lz.view">
Debug.info('ondrop droppable', view);
</handler>
</text>
</canvas>
</programlisting></example>
<p><classname>draggable</classname> is a mixin intended for use with <sgmltag class="element" role="LzView"><view></sgmltag> and its subclasses.
</p>
</text>
</doc>
<attribute name="draggable" type="boolean" value="true
"/>
<attribute name="destinationtypes" type="string" value="droppable
"/>
<attribute name="__splitre" value="new RegExp('\\s*,\\s*')
"/>
<setter name="destinationtypes" args="destinationtypes">
var out = [],
classes = destinationtypes.split(this.__splitre);
this.destinationtypes = destinationtypes;
for (var i = 0, l = classes.length; i < l; i++) {
var newclass = lz[classes[i]];
if (! newclass) {
//Debug.warn('no class %w found for %w', classes[i], this);
continue
}
out.push(newclass);
}
this.__classes = out;
</setter>
<attribute name="dragging" type="expression" value="null
"/>
<attribute name="dragover" type="expression" value="null
"/>
<event name="ondrop"/>
<method name="validDestination" args="view:lz.droppable" returns="Boolean">
if (! this.draggable) return false;
var classes = this.__classes;
for (var i = 0, l = classes.length; i < l; i++) {
if (view is classes[i]) {
return true;
}
}
return false;
</method>
<dragstate applied="${parent.dragging}"/>
<handler name="onmousedown">
if (this.draggable) {
dragmanager.setAttribute('dragging', this);
}
</handler>
<handler name="onmouseup">
if (this.dragging) {
dragmanager.setAttribute('dragging', null);
}
</handler>
</mixin>
</library>
Cross References
Includes
Named Instances