Here is a simple example using my answer to your previous question: http://www.jsfiddle.net/yijiang/83W7X/2/embedded/result
var selected = []; function drawSelection(){ if(selected.length){ selected.sort(function(a, b){ if(a.sourceIndex){ return a.sourceIndex - b.sourceIndex; } else if(a.compareDocumentPosition){ if(a.compareDocumentPosition(b) == Node.DOCUMENT_POSITION_PRECEDING){ return 1; } else { return -1; } } }); var range = rangy.createRange(), sel = rangy.getSelection(); range.setStart(selected[0].children[0], 0); range.setEnd(selected[selected.length - 1].children[0], 1); sel.setSingleRange(range); } } $('ul').selectable({ delay: 100, selecting: function(event, ui) { if(ui.selecting.getAttribute('class').indexOf('wrapper') !== -1 && $.inArray(ui.selecting, selected) === -1) { selected.push(ui.selecting); drawSelection(); } }, unselecting: function(event, ui){ if(ui.unselecting.getAttribute('class').indexOf('wrapper') !== -1 && $.inArray(ui.unselecting, selected) > -1){ selected.splice($.inArray(ui.unselecting, selected), 1); drawSelection(); } } });
It mixes the jQuery Selectable user interface with the excellent Rangy Tim Down library to create something similar to what you requested. I think. What you asked for was not entirely clear.
The code stores an array of selected li elements. The second part of the code is added to the corresponding event handlers and parameters. The drawSelection function drawSelection called each time an element is selected or canceled. The function first sorts all the elements by their position in the DOM, then proceeds to draw the selection from the first selected li to the last.
Code like theazureshadow is just proof of concept, as I am abstracting what really should be the simple task of choosing li to the rather heavy Rangy library. It also doesn't work very well and can work with some refactoring.
Yi jiang
source share