diff options
author | Richard Beales <[email protected]> | 2013-03-18 07:32:01 +0000 |
---|---|---|
committer | Richard Beales <[email protected]> | 2013-03-18 07:32:01 +0000 |
commit | 7c97d17aaf373339a8bcd917ad59ca6018148f0d (patch) | |
tree | 5a3c04f0f9529be392c1263d3feb75806eb43797 /lib/dijit/form/_ListBase.js.uncompressed.js | |
parent | 70db7424e7068701e60cc5bcdfe8f858be508179 (diff) | |
parent | c670a80ddd9b03bd4ea6d940a9ed682fd26248d7 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'lib/dijit/form/_ListBase.js.uncompressed.js')
-rw-r--r-- | lib/dijit/form/_ListBase.js.uncompressed.js | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/lib/dijit/form/_ListBase.js.uncompressed.js b/lib/dijit/form/_ListBase.js.uncompressed.js new file mode 100644 index 000000000..ea32c3ceb --- /dev/null +++ b/lib/dijit/form/_ListBase.js.uncompressed.js @@ -0,0 +1,135 @@ +define("dijit/form/_ListBase", [ + "dojo/_base/declare", // declare + "dojo/on", + "dojo/window" // winUtils.scrollIntoView +], function(declare, on, winUtils){ + +// module: +// dijit/form/_ListBase + +return declare( "dijit.form._ListBase", null, { + // summary: + // Focus-less menu to handle UI events consistently + // Abstract methods that must be defined externally: + // + // - onSelect: item is active (mousedown but not yet mouseup, or keyboard arrow selected but no Enter) + // - onDeselect: cancels onSelect + // tags: + // private + + // selected: DOMNode + // currently selected node + selected: null, + + _listConnect: function(/*String|Function*/ eventType, /*String*/ callbackFuncName){ + // summary: + // Connects 'containerNode' to specified method of this object + // and automatically registers for 'disconnect' on widget destroy. + // description: + // Provide widget-specific analog to 'connect'. + // The callback function is called with the normal event object, + // but also a second parameter is passed that indicates which list item + // actually received the event. + // returns: + // A handle that can be passed to `disconnect` in order to disconnect + // before the widget is destroyed. + // tags: + // private + + var self = this; + return self.own(on(self.containerNode, + on.selector( + function(eventTarget, selector, target){ + return eventTarget.parentNode == target; + }, + eventType + ), + function(evt){ + evt.preventDefault(); + self[callbackFuncName](evt, this); + } + )); + }, + + selectFirstNode: function(){ + // summary: + // Select the first displayed item in the list. + var first = this.containerNode.firstChild; + while(first && first.style.display == "none"){ + first = first.nextSibling; + } + this._setSelectedAttr(first); + }, + + selectLastNode: function(){ + // summary: + // Select the last displayed item in the list + var last = this.containerNode.lastChild; + while(last && last.style.display == "none"){ + last = last.previousSibling; + } + this._setSelectedAttr(last); + }, + + selectNextNode: function(){ + // summary: + // Select the item just below the current selection. + // If nothing selected, select first node. + var selectedNode = this.selected; + if(!selectedNode){ + this.selectFirstNode(); + }else{ + var next = selectedNode.nextSibling; + while(next && next.style.display == "none"){ + next = next.nextSibling; + } + if(!next){ + this.selectFirstNode(); + }else{ + this._setSelectedAttr(next); + } + } + }, + + selectPreviousNode: function(){ + // summary: + // Select the item just above the current selection. + // If nothing selected, select last node (if + // you select Previous and try to keep scrolling up the list). + var selectedNode = this.selected; + if(!selectedNode){ + this.selectLastNode(); + }else{ + var prev = selectedNode.previousSibling; + while(prev && prev.style.display == "none"){ + prev = prev.previousSibling; + } + if(!prev){ + this.selectLastNode(); + }else{ + this._setSelectedAttr(prev); + } + } + }, + + _setSelectedAttr: function(/*DomNode*/ node){ + // summary: + // Does the actual select. + if(this.selected != node){ + var selectedNode = this.selected; + if(selectedNode){ + this.onDeselect(selectedNode); + this.selected = null; + } + if(node){ + this.selected = node; + winUtils.scrollIntoView(node); + this.onSelect(node); + } + }else if(node){ + this.onSelect(node); + } + } +}); + +}); |