// jQuery finderSelect: a jQuery plugin that activates selecting elements // within a parent with Ctrl+Click, Command+Click and Shift+Click. // // Copyright 2013 Mike Angell // // Please see: // // https://github.com/evulse/finderselect // // For complete documentation. (function( $ ) { var d = $(document); var b = $('body'); var commands = { highlight: highlight, unHighlight: unHighlight, highlightAll: highlightAll, unHighlightAll: unHighlightAll, selected: selected, children: children, update: update, addHook: addHook }; var hooks = {}; var o = {}; var f = $.fn.finderSelect = function() { if (typeof arguments[0] === 'string') { var args = Array.prototype.slice.call(arguments); args.splice(0, 1); return commands[arguments[0]].apply(this, args); } else { finderSelect.apply(this, arguments); return this; } }; function finderSelect(opt) { var p = $(this); var options = { selectClass: "selected", unSelectClass: "un-selected", currentClass: "selected-current", lastClass: "selected-last", shiftClass: "selected-shift", ctrlClass: "selected-ctrl", triggerUpdate: "finderSelectUpdate", children: false, event: "mousedown", cursor: "pointer", dragEvent: "mouseenter", enableClickDrag: true, enableShiftClick: true, enableCtrlClick: true, enableSingleClick: true, enableSelectAll: true, enableDisableSelection: true, enableTouchCtrlDefault: true, enableDesktopCtrlDefault: false, totalSelector: false, menuSelector: false, menuXOffset: 0, menuYOffset: 0 }; $.extend(options, opt); o = options; if(!o.children) { o.children = f.detect.children(p); } f.h.off(f.get.siblings(p,o), o); if(o.cursor) { f.set.cursor(p,o); } if(o.enableDisableSelection) { f.core.disableSelection(p,o); } if(o.enableClickDrag) { f.core.clickDrag(p,o); } if(o.enableSelectAll) { f.core.selectAll(p,o); } if(o.enableShiftClick || o.enableCtrlClick || o.enableSingleClick) { f.core.click(p,o); } if(o.totalSelector) { f.core.totalUpdate(p,o); } if(o.menuSelector) { f.core.loadMenu(p,o); } }; function highlight(el) { f.h.on(el, o); return this; } function unHighlight(el) { f.h.off(el, o); return this; } function highlightAll() { var p = $(this); f.h.on(p.find(o.children), o); return this; } function unHighlightAll() { var p = $(this); f.h.off(p.find(o.children), o); return this; } function selected() { var p = $(this); return p.find(o.children+'.'+o.selectClass); } function children() { var p = $(this); return p.find(o.children); } function update() { var p = $(this); f.t.update(p, o); return this; } function addHook(hookName, fn) { if(typeof hookName == "object"){ var i; for(i=0; i 0) { c.hard.v = $(start[0]); f.set.click(p, c.hard.v, o.lastClass); } else { var start = f.get.elem(z < x, c.hard.v, o.selectClass); if(start.length > 0) { start = (z > x ) ? $(start[0]) : $(start[start.length-1]); c.hard.v = start; f.set.click(p, c.hard.v, o.lastClass); } else { c.hard.v = s.first(); f.set.click(p, c.hard.v, o.lastClass); f.t.singleClick(s,{current:{v:s.first()}},o); } } } var x = s.index(c.hard.v); var y = s.index(c.shift.v); var z = s.index(c.current.v); if(c.hard.v.length == 0){ f.t.singleClick(s,{current:{v:s.first()}},o); } if(c.shift.v.length != 0) { if((x < y && x < z && z < y) || (x > y && x > z && z > y)) { f.h.off(f.get.between(s, c.shift, c.current), o); } if((x < y && x > z && z < y) || (x > y && x < z && z > y)) { f.h.off(f.get.between(s, c.shift, c.hard), o); f.h.on(f.get.between(s, c.current, c.hard), o); } if((x > y && x > z && z < y) || (x < y && x < z && z > y) || (x == y)) { f.h.on(f.get.between(s, c.shift, c.current), o); } else { f.h.off(c.shift.v, o); f.t.unHExist(z>y, c.shift.v,o); } } else { f.t.unHExist(z>x,c.hard.v,o); f.h.on(f.get.between(s, c.current, c.hard), o); } f.h.on(c.current.v, o); f.set.clicks(c.hard.v, c.current.v, null, p, o); }, unHAll: function(p,o) { f.h.off(p.find(o.children), o); f.t.update(p, o); }, hAll: function(p,o) { f.h.on(p.find(o.children), o); f.t.update(p, o); }, unHExist: function(bool,el,o) { if(bool) { f.h.off(f.get.elem(false, el, false, o.unSelectClass), o); } else { f.h.off(f.get.elem(true, el, false, o.unSelectClass), o); } } }; })(window.jQuery || window.Zepto);