Last active
August 29, 2015 14:05
-
-
Save mr21/770a88fd0d994cd593c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// `yourElement` can be a NodeElement or a jQuery object as you want. | |
var selection = $.plugin_selection(yourElement) | |
// `.applyThis` is useful if you want to specify the `this` for all your callbacks. | |
// By default it's `window`. | |
.applyThis(object) | |
.onElementsAdded(function(jq_elems) { | |
// This callback is called when some elements are selected. | |
// Here, `jq_elems` is a jQuery object who contain the new elements selected. | |
// This object doesn't contain only one element if the user use the shift key. | |
// In this callback the `this` pointer is `window` by default | |
// or it's the object you specify with `.applyThis`. | |
}) | |
.onElementsRemoved(function(jq_elems) { | |
// Same behaviour here. | |
// If the user unselect all his items in the same time | |
// `jq_elems` will be a jQuery list. | |
}); | |
// Here you have an access to the list of the elements actually selected. | |
// This array is automatically updated (it's not a copy). | |
var elSelected = selection.getArraySelection(); | |
// By calling `lockCtrlKey` you lock the Ctrl key. | |
// The user can't unselect all the items by clicking around. | |
// There is also a `.unlockCtrlKey` method. | |
selection.lockCtrlKey(); | |
// You can disable the shift key if you want. | |
// There is also a `.enableShiftKey` method. | |
selection.disableShiftKey(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment