//>>built
define("dijit/_base/focus","dojo/_base/array,dojo/dom,dojo/_base/lang,dojo/topic,dojo/_base/window,../focus,../main".split(","),function(k,l,i,h,f,e,g){e.focus=function(a){if(a){var b="node"in a?a.node:a,c=a.bookmark,a=a.openedForWindow,d=c?c.isCollapsed:!1;if(b){var j="iframe"==b.tagName.toLowerCase()?b.contentWindow:b;if(j&&j.focus)try{j.focus()}catch(h){}e._onFocusNode(b)}if(c&&f.withGlobal(a||f.global,g.isCollapsed)&&!d){a&&a.focus();try{f.withGlobal(a||f.global,g.moveToBookmark,null,[c])}catch(i){}}}};
e.watch("curNode",function(a,b,c){g._curFocus=c;g._prevFocus=b;c&&h.publish("focusNode",c)});e.watch("activeStack",function(a,b,c){g._activeStack=c});e.on("widget-blur",function(a,b){h.publish("widgetBlur",a,b)});e.on("widget-focus",function(a,b){h.publish("widgetFocus",a,b)});i.mixin(g,{_curFocus:null,_prevFocus:null,isCollapsed:function(){return g.getBookmark().isCollapsed},getBookmark:function(){var a,b,c=f.doc.selection,d=e.curNode;if(f.global.getSelection){if(c=f.global.getSelection())if(c.isCollapsed){if(a=
d?d.tagName:"")if(a=a.toLowerCase(),"textarea"==a||"input"==a&&(!d.type||"text"==d.type.toLowerCase()))return c={start:d.selectionStart,end:d.selectionEnd,node:d,pRange:!0},{isCollapsed:c.end<=c.start,mark:c};a={isCollapsed:!0};if(c.rangeCount)a.mark=c.getRangeAt(0).cloneRange()}else b=c.getRangeAt(0),a={isCollapsed:!1,mark:b.cloneRange()}}else if(c){a=d?d.tagName:"";a=a.toLowerCase();if(d&&a&&("button"==a||"textarea"==a||"input"==a)){if(c.type&&"none"==c.type.toLowerCase())return{isCollapsed:!0,
mark:null};b=c.createRange();return{isCollapsed:b.text&&b.text.length?!1:!0,mark:{range:b,pRange:!0}}}a={};try{b=c.createRange(),a.isCollapsed=!("Text"==c.type?b.htmlText.length:b.length)}catch(g){return a.isCollapsed=!0,a}if("CONTROL"==c.type.toUpperCase())if(b.length){a.mark=[];c=0;for(d=b.length;c<d;)a.mark.push(b.item(c++))}else a.isCollapsed=!0,a.mark=null;else a.mark=b.getBookmark()}return a},moveToBookmark:function(a){var b=f.doc;if(a=a.mark)if(f.global.getSelection){if((b=f.global.getSelection())&&
b.removeAllRanges)a.pRange?(b=a.node,b.selectionStart=a.start,b.selectionEnd=a.end):(b.removeAllRanges(),b.addRange(a))}else if(b.selection&&a){var c;a.pRange?c=a.range:i.isArray(a)?(c=b.body.createControlRange(),k.forEach(a,function(a){c.addElement(a)})):(c=b.body.createTextRange(),c.moveToBookmark(a));c.select()}},getFocus:function(a,b){var c=!e.curNode||a&&l.isDescendant(e.curNode,a.domNode)?g._prevFocus:e.curNode;return{node:c,bookmark:c&&c==e.curNode&&f.withGlobal(b||f.global,g.getBookmark),
openedForWindow:b}},_activeStack:[],registerIframe:function(a){return e.registerIframe(a)},unregisterIframe:function(a){a&&a.remove()},registerWin:function(a,b){return e.registerWin(a,b)},unregisterWin:function(a){a&&a.remove()}});return g});