Ignore:
Timestamp:
2013-03-05T16:36:03+13:00 (11 years ago)
Author:
sjm84
Message:

Implemented a "drag to trash" feature

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js

    r27009 r27010  
    1818    var _selectedElement;
    1919
     20    var _overTrash = false;
     21   
    2022    var _validDropSpot = false;
    2123    var _validDropType;
     
    156158       
    157159        return true;
     160    }
     161   
     162    var placeTrashBin = function()
     163    {
     164        var bin = $("<div id=\"veTrash\">Trash</div>");
     165        bin.addClass("ui-state-default");
     166        bin.addClass("ui-corner-all");
     167        bin.droppable(
     168        {
     169            "over":function()
     170            {
     171                _overTrash = true;
     172            },
     173            "out":function()
     174            {
     175                _overTrash = false;
     176            }
     177        });
     178        _editorContainer.append(bin);
    158179    }
    159180   
     
    445466
    446467        populateToolbar();
     468        placeTrashBin();
    447469
    448470        _editorContainer.append(_editorDiv);
     
    451473        _mainDiv.append($("<div>", {"id":"veSpacerDiv"}));
    452474        _mainDiv.append(_infoDiv);
    453         _mainDiv.append($("<div>", {"style":"clear:both;"}));
     475        _mainDiv.append($("<div>", {"style":"clear:both;"}));       
    454476    }
    455477
     
    638660                "start":function(event, ui)
    639661                {
     662                    _overTrash = false;
    640663                    _origDDParent = _div.parent();
    641664                    _origDDPosition = _div.index();
     
    746769                    _div.css("border", "1px dashed black");
    747770                    _div.css("background", _div.data("prevBackground"));
    748 
     771                   
    749772                    //If the element was not dropped in a valid place then put it back
    750773                    if(!_validDropSpot)
     
    762785                        {
    763786                            _origDDParent.children(".veElement").eq(_origDDPosition).before(_div);
     787                        }
     788                       
     789                        if(_overTrash)
     790                        {
     791                            _div.data("parentVEElement").remove();
     792                            return;
    764793                        }
    765794
     
    916945            removeButton.click(function()
    917946            {
    918                 var divParent = _div.parents(".veElement");
    919                 _transactions.push({type:"remMvElem", vElemParent:_div.parent(), vElemPos:_div.index(), vElem:_div});
    920                 _div.data("expanded", "normal");
    921                 $(_xmlNode).remove();
    922                 _div.detach();
    923                 _infoDiv.empty();
    924                
    925                 if(divParent.length)
    926                 {
    927                     divParent.first().trigger("click");
    928                 }
     947                _div.data("parentVEElement").remove();
    929948            });
     949        }
     950       
     951        this.remove = function()
     952        {
     953            var divParent = _div.parents(".veElement");
     954            _transactions.push({type:"remMvElem", vElemParent:_div.parent(), vElemPos:_div.index(), vElem:_div});
     955            _div.data("expanded", "normal");
     956            $(_xmlNode).remove();
     957            _div.detach();
     958            _infoDiv.empty();
     959           
     960            if(divParent.length)
     961            {
     962                divParent.first().trigger("click");
     963            }
    930964        }
    931965
Note: See TracChangeset for help on using the changeset viewer.