/* * Copyright (c) 2004-2007, The Dojo Foundation All Rights Reserved. * * Licensed under the Academic Free License version 2.1 or above OR the modified * BSD license. For more information on Dojo licensing, see: * * http://dojotoolkit.org/book/dojo-book-0-9/introduction/licensing */ /* * This is a compiled version of Dojo, built for deployment and not for * development. To get an editable version, please visit: * * http://dojotoolkit.org * * for documentation and information on getting the source. */ if (!dojo._hasResource["dijit._base.focus"]) { // _hasResource checks added by // build. Do not use // _hasResource directly in your // code. dojo._hasResource["dijit._base.focus"] = true; dojo.provide("dijit._base.focus"); // summary: // These functions are used to query or set the focus and selection. // // Also, they trace when widgets become actived/deactivated, // so that the widget can fire _onFocus/_onBlur events. // "Active" here means something similar to "focused", but // "focus" isn't quite the right word because we keep track of // a whole stack of "active" widgets. Example: Combobutton --> Menu --> // MenuItem. The onBlur event for Combobutton doesn't fire due to focusing // on the Menu or a MenuItem, since they are considered part of the // Combobutton widget. It only happens when focus is shifted // somewhere completely different. dojo.mixin(dijit, { // _curFocus: DomNode // Currently focused item on screen _curFocus : null, // _prevFocus: DomNode // Previously focused item on screen _prevFocus : null, isCollapsed : function() { // summary: tests whether the current selection is empty var _window = dojo.global; var _document = dojo.doc; if (_document.selection) { // IE return !_document.selection.createRange().text; // Boolean } else if (_window.getSelection) { var selection = _window.getSelection(); if (dojo.isString(selection)) { // Safari return !selection; // Boolean } else { // Mozilla/W3 return selection.isCollapsed || !selection.toString(); // Boolean } } }, getBookmark : function() { // summary: Retrieves a bookmark that can be used with // moveToBookmark to return to the same range var bookmark, selection = dojo.doc.selection; if (selection) { // IE var range = selection.createRange(); if (selection.type.toUpperCase() == 'CONTROL') { bookmark = range.length ? dojo._toArray(range) : null; } else { bookmark = range.getBookmark(); } } else { if (dojo.global.getSelection) { selection = dojo.global.getSelection(); if (selection) { var range = selection.getRangeAt(0); bookmark = range.cloneRange(); } } else { console .debug("No idea how to store the current selection for this browser!"); } } return bookmark; // Array }, moveToBookmark : function(/* Object */bookmark) { // summary: Moves current selection to a bookmark // bookmark: this should be a returned object from // dojo.html.selection.getBookmark() var _document = dojo.doc; if (_document.selection) { // IE var range; if (dojo.isArray(bookmark)) { range = _document.body.createControlRange(); dojo.forEach(bookmark, range.addElement); } else { range = _document.selection.createRange(); range.moveToBookmark(bookmark); } range.select(); } else { // Moz/W3C var selection = dojo.global.getSelection && dojo.global.getSelection(); if (selection && selection.removeAllRanges) { selection.removeAllRanges(); selection.addRange(bookmark); } else { console .debug("No idea how to restore selection for this browser!"); } } }, getFocus : function(/* Widget */menu, /* Window */openedForWindow) { // summary: // Returns the current focus and selection. // Called when a popup appears (either a top level menu or a // dialog), // or when a toolbar/menubar receives focus // // menu: // the menu that's being opened // // openedForWindow: // iframe in which menu was opened // // returns: // a handle to restore focus/selection return { // Node to return focus to node : menu && dojo.isDescendant(dijit._curFocus, menu.domNode) ? dijit._prevFocus : dijit._curFocus, // Previously selected text bookmark : !dojo.withGlobal(openedForWindow || dojo.global, dijit.isCollapsed) ? dojo.withGlobal(openedForWindow || dojo.global, dijit.getBookmark) : null, openedForWindow : openedForWindow }; // Object }, focus : function(/* Object || DomNode */handle) { // summary: // Sets the focused node and the selection according to argument. // To set focus to an iframe's content, pass in the iframe itself. // handle: // object returned by get(), or a DomNode if (!handle) { return; } var node = "node" in handle ? handle.node : handle, // because // handle is // either // DomNode or a // composite // object bookmark = handle.bookmark, openedForWindow = handle.openedForWindow; // Set the focus // Note that for iframe's we need to use the