YUI 3.x Home -

YUI Library Examples: Drag & Drop: Using the Drag Shim

Drag & Drop: Using the Drag Shim

This example shows the use of the drag shim when dragging nodes over other troublesome nodes.

Try dragging the proxy element over the iframe below, in most browsers this will not happen. Now click the Shim off button and drag again. Now you can drag over the iframe.

You can see the shim by clicking the Debug Off button.

Drag Me

Using the shim

Here is the code for this example.

  1. YUI().use('dd-ddm', 'dd-drag', 'dd-proxy', function(Y) {
  2.  
  3. //Toggling the buttons
  4. Y.Node.get('#shim').on('click', function(e) {
  5. var value = e.target.get('value');
  6. if (value == 'off' || value == 'Shim Off') {
  7. dd.set('useShim', true);
  8. e.target.set('value', 'on');
  9. e.target.set('innerHTML', 'Shim On');
  10. Y.Node.get('#debugShim').set('disabled', false);
  11. } else {
  12. dd.set('useShim', false);
  13. e.target.set('value', 'off');
  14. e.target.set('innerHTML', 'Shim Off');
  15. Y.Node.get('#debugShim').set('disabled', true);
  16. }
  17. });
  18.  
  19. Y.Node.get('#debugShim').on('click', function(e) {
  20. var value = e.target.get('value');
  21. if (value == 'off' || value == 'Debug Off') {
  22. Y.DD.DDM._debugShim = true;
  23. e.target.set('value', 'on');
  24. e.target.set('innerHTML', 'Debug On');
  25. } else {
  26. Y.DD.DDM._debugShim = false;
  27. e.target.set('value', 'off');
  28. e.target.set('innerHTML', 'Debug Off');
  29. }
  30. });
  31.  
  32.  
  33. var dd = new Y.DD.Drag({
  34. //Selector of the node to make draggable
  35. node: '#demo',
  36. useShim: false
  37. }).plug(Y.Plugin.DDProxy, {
  38. offsetNode: false,
  39. resizeFrame: false
  40. });
  41. dd.on('drag:start', function() {
  42. this.get('dragNode').setStyles({
  43. height: '20px',
  44. width: '100px',
  45. backgroundColor: 'blue',
  46. color: '#fff'
  47. });
  48. this.get('dragNode').set('innerHTML', 'Custom Proxy');
  49. this.deltaXY = [this.deltaXY[0] - 20, this.deltaXY[1] - 20];
  50. });
  51. });
YUI().use('dd-ddm', 'dd-drag', 'dd-proxy', function(Y) {
 
    //Toggling the buttons
    Y.Node.get('#shim').on('click', function(e) {
        var value = e.target.get('value');
        if (value == 'off' || value == 'Shim Off') {
            dd.set('useShim', true);
            e.target.set('value', 'on');
            e.target.set('innerHTML', 'Shim On');
            Y.Node.get('#debugShim').set('disabled', false);
        } else {
            dd.set('useShim', false);
            e.target.set('value', 'off');
            e.target.set('innerHTML', 'Shim Off');
            Y.Node.get('#debugShim').set('disabled', true);
        }
    });
 
    Y.Node.get('#debugShim').on('click', function(e) {
        var value = e.target.get('value');
        if (value == 'off' || value == 'Debug Off') {
            Y.DD.DDM._debugShim = true;
            e.target.set('value', 'on');
            e.target.set('innerHTML', 'Debug On');
        } else {
            Y.DD.DDM._debugShim = false;
            e.target.set('value', 'off');
            e.target.set('innerHTML', 'Debug Off');
        }
    });
 
 
    var dd = new Y.DD.Drag({
        //Selector of the node to make draggable
        node: '#demo',
        useShim: false
    }).plug(Y.Plugin.DDProxy, {
        offsetNode: false,
        resizeFrame: false
    });
    dd.on('drag:start', function() {
        this.get('dragNode').setStyles({
            height: '20px',
            width: '100px',
            backgroundColor: 'blue',
            color: '#fff'
        });
        this.get('dragNode').set('innerHTML', 'Custom Proxy');
        this.deltaXY = [this.deltaXY[0] - 20, this.deltaXY[1] - 20];
    });
});

Copyright © 2009 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings