droppable.lzx
<library>
<include href="dragmanager.lzx"/>
<mixin name="droppable">
<doc>
<tag name="shortdesc"><text>A mixin that adds easy drag and drop support to view.</text></tag>
<text>
<p>The <tagname>droppable</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>droppable</classname> is a mixin intended for use with <sgmltag class="element" role="LzView"><view></sgmltag> and its subclasses.
</p>
</text>
</doc>
<attribute name="droppable" type="boolean" value="true
"/>
<attribute name="sourcetypes" type="string" value="draggable
"/>
<attribute name="__splitre" value="new RegExp('\\s*,\\s*')
"/>
<setter name="sourcetypes" args="sourcetypes">
var out = [],
classes = sourcetypes.split(this.__splitre);
this.sourcetypes = sourcetypes;
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="validSource" args="view:lz.draggable" returns="Boolean">
if (! this.droppable) 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>
<handler name="oninit">
dragmanager.__add(this);
</handler>
<handler name="onmousetrackover">
dragmanager.setAttribute('dragover', this);
</handler>
<handler name="onmousetrackout">
dragmanager.setAttribute('dragover', null);
</handler>
<handler name="onmousetrackup">
dragmanager.__dropEvent(this);
</handler>
</mixin>
</library>
Cross References
Includes
Named Instances