Standby.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.widget.Standby"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.widget.Standby"] = true;
  8. dojo.provide("dojox.widget.Standby");
  9. dojo.require("dojo.window");
  10. dojo.require("dojo.fx");
  11. dojo.require("dijit._Widget");
  12. dojo.require("dijit._Templated");
  13. dojo.experimental("dojox.widget.Standby");
  14. dojo.declare("dojox.widget.Standby",[dijit._Widget, dijit._Templated],{
  15. // summary:
  16. // A widget designed to act as a Standby/Busy/Disable/Blocking widget to indicate a
  17. // particular DOM node is processing and cannot be clicked on at this time.
  18. // This widget uses absolute positioning to apply the overlay and image.
  19. //
  20. // image:
  21. // A URL to an image to center within the blocking overlay.
  22. // The default is a basic spinner.
  23. //
  24. // imageText:
  25. // Text to set on the ALT tag of the image.
  26. // The default is 'Please wait...'
  27. //
  28. // text:
  29. // Text to display in the center instead of an image.
  30. // Defaults to 'Please Wait...'
  31. //
  32. // centerIndicator:
  33. // Which to use as the center info, the text or the image.
  34. // Defaults to image.
  35. //
  36. // color:
  37. // The color to use for the translucent overlay.
  38. // Text string such as: darkblue, #FE02FD, etc.
  39. //
  40. // duration:
  41. // How long the fade in and out effects should run in milliseconds.
  42. // Default is 500ms
  43. //
  44. // zIndex:
  45. // Control that lets you specify if the zIndex for the overlay
  46. // should be auto-computed based off parent zIndex, or should be set
  47. // to a particular value. This is useful when you want to overlay
  48. // things in digit.Dialogs, you can specify a base zIndex to append from.
  49. // Default is 'auto'.
  50. // templateString: [protected] String
  51. // The template string defining out the basics of the widget. No need for an external
  52. // file.
  53. templateString:
  54. "<div>" +
  55. "<div style=\"display: none; opacity: 0; z-index: 9999; " +
  56. "position: absolute; cursor:wait;\" dojoAttachPoint=\"_underlayNode\"></div>" +
  57. "<img src=\"${image}\" style=\"opacity: 0; display: none; z-index: -10000; " +
  58. "position: absolute; top: 0px; left: 0px; cursor:wait;\" "+
  59. "dojoAttachPoint=\"_imageNode\">" +
  60. "<div style=\"opacity: 0; display: none; z-index: -10000; position: absolute; " +
  61. "top: 0px;\" dojoAttachPoint=\"_textNode\"></div>" +
  62. "</div>",
  63. // _underlayNode: [private] DOMNode
  64. // The node that is the translucent underlay for the
  65. // image that blocks access to the target.
  66. _underlayNode: null,
  67. // _imageNode: [private] DOMNode
  68. // The image node where we attach and define the image to display.
  69. _imageNode: null,
  70. // _textNode: [private] DOMNode
  71. // The div to attach text/HTML in the overlay center item.
  72. _textNode: null,
  73. // _centerNode: [private] DOMNode
  74. // Which node to use as the center node, the image or the text node.
  75. _centerNode: null,
  76. // image: String
  77. // The URL to the image to center in the overlay.
  78. image: dojo.moduleUrl("dojox", "widget/Standby/images/loading.gif").toString(),
  79. // imageText: String
  80. // Text for the ALT tag.
  81. imageText: "Please Wait...",
  82. // text: String
  83. // Text/HTML to display in the center of the overlay
  84. // This is used if image center is disabled.
  85. text: "Please wait...",
  86. // centerIndicator: String
  87. // Property to define if the image and its alt text should be used, or
  88. // a simple Text/HTML node should be used. Allowable values are 'image'
  89. // and 'text'.
  90. // Default is 'image'.
  91. centerIndicator: "image",
  92. // _displayed: [private] Boolean
  93. // Flag to indicate if the overlay is displayed or not.
  94. _displayed: false,
  95. // _resizeCheck: [private] Object
  96. // Handle to interval function that checks the target for changes.
  97. _resizeCheck: null,
  98. // target: DOMNode||DOMID(String)||WidgetID(String)
  99. // The target to overlay when active. Can be a widget id, a
  100. // dom id, or a direct node reference.
  101. target: "",
  102. // color: String
  103. // The color to set the overlay. Should be in #XXXXXX form.
  104. // Default color for the translucent overlay is light gray.
  105. color: "#C0C0C0",
  106. // duration: integer
  107. // Integer defining how long the show and hide effects should take.
  108. duration: 500,
  109. // _started: [private] Boolean
  110. // Trap flag to ensure startup only processes once.
  111. _started: false,
  112. // _parent: [private] DOMNode
  113. // Wrapping div for the widget, also used for IE 7 in dealing with the
  114. // zoom issue.
  115. _parent: null,
  116. // zIndex: String
  117. // Control that lets you specify if the zIndex for the overlay
  118. // should be auto-computed based off parent zIndex, or should be set
  119. // to a particular value. This is useful when you want to overlay
  120. // things in digit.Dialogs, you can specify a base zIndex to append from.
  121. zIndex: "auto",
  122. startup: function(args){
  123. // summary:
  124. // Over-ride of the basic widget startup function.
  125. // Configures the target node and sets the image to use.
  126. if(!this._started){
  127. if(typeof this.target === "string"){
  128. var w = dijit.byId(this.target);
  129. if(w){
  130. this.target = w.domNode;
  131. }else{
  132. this.target = dojo.byId(this.target);
  133. }
  134. }
  135. if(this.text){
  136. this._textNode.innerHTML = this.text;
  137. }
  138. if(this.centerIndicator === "image"){
  139. this._centerNode = this._imageNode;
  140. dojo.attr(this._imageNode, "src", this.image);
  141. dojo.attr(this._imageNode, "alt", this.imageText);
  142. }else{
  143. this._centerNode = this._textNode;
  144. }
  145. dojo.style(this._underlayNode, {
  146. display: "none",
  147. backgroundColor: this.color
  148. });
  149. dojo.style(this._centerNode, "display", "none");
  150. this.connect(this._underlayNode, "onclick", "_ignore");
  151. //Last thing to do is move the widgets parent, if any, to the current document body.
  152. //Avoids having to deal with parent relative/absolute mess. Otherwise positioning
  153. //tends to go goofy.
  154. if(this.domNode.parentNode && this.domNode.parentNode != dojo.body()){
  155. dojo.body().appendChild(this.domNode);
  156. }
  157. //IE 7 has a horrible bug with zoom, so we have to create this node
  158. //to cross-check later. Sigh.
  159. if(dojo.isIE == 7){
  160. this._ieFixNode = dojo.doc.createElement("div");
  161. dojo.style(this._ieFixNode, {
  162. opacity: "0",
  163. zIndex: "-1000",
  164. position: "absolute",
  165. top: "-1000px"
  166. });
  167. dojo.body().appendChild(this._ieFixNode);
  168. }
  169. }
  170. },
  171. show: function(){
  172. // summary:
  173. // Function to display the blocking overlay and busy/status icon or text.
  174. if(!this._displayed){
  175. if(this._anim){
  176. this._anim.stop();
  177. delete this._anim;
  178. }
  179. this._displayed = true;
  180. this._size();
  181. this._disableOverflow();
  182. this._fadeIn();
  183. }
  184. },
  185. hide: function(){
  186. // summary:
  187. // Function to hide the blocking overlay and status icon or text.
  188. if(this._displayed){
  189. if(this._anim){
  190. this._anim.stop();
  191. delete this._anim;
  192. }
  193. this._size();
  194. this._fadeOut();
  195. this._displayed = false;
  196. if(this._resizeCheck !== null){
  197. clearInterval(this._resizeCheck);
  198. this._resizeCheck = null;
  199. }
  200. }
  201. },
  202. isVisible: function(){
  203. // summary:
  204. // Helper function so you can test if the widget is already visible or not.
  205. // returns:
  206. // boolean indicating if the widget is in 'show' state or not.
  207. return this._displayed; // boolean
  208. },
  209. onShow: function(){
  210. // summary:
  211. // Event that fires when the display of the Standby completes.
  212. },
  213. onHide: function(){
  214. // summary:
  215. // Event that fires when the display of the Standby completes.
  216. },
  217. uninitialize: function(){
  218. // summary:
  219. // Over-ride to hide the widget, which clears intervals, before cleanup.
  220. this._displayed = false;
  221. if(this._resizeCheck){
  222. clearInterval(this._resizeCheck);
  223. }
  224. dojo.style(this._centerNode, "display", "none");
  225. dojo.style(this._underlayNode, "display", "none");
  226. if(dojo.isIE == 7){
  227. dojo.body().removeChild(this._ieFixNode);
  228. delete this._ieFixNode;
  229. }
  230. if(this._anim){
  231. this._anim.stop();
  232. delete this._anim;
  233. }
  234. this.target = null;
  235. this._imageNode = null;
  236. this._textNode = null;
  237. this._centerNode = null;
  238. this.inherited(arguments);
  239. },
  240. _size: function(){
  241. // summary:
  242. // Internal function that handles resizing the overlay and
  243. // centering of the image on window resizing.
  244. // tags:
  245. // private
  246. if(this._displayed){
  247. var dir = dojo.attr(dojo.body(), "dir");
  248. if(dir){dir = dir.toLowerCase();}
  249. var _ie7zoom;
  250. var scrollers = this._scrollerWidths();
  251. var target = this.target;
  252. //Show the image and make sure the zIndex is set high.
  253. var curStyle = dojo.style(this._centerNode, "display");
  254. dojo.style(this._centerNode, "display", "block");
  255. var box = dojo.position(target, true);
  256. if(target === dojo.body() || target === dojo.doc){
  257. // Target is the whole doc, so scale to viewport.
  258. box = dojo.window.getBox();
  259. box.x = box.l;
  260. box.y = box.t;
  261. }
  262. var cntrIndicator = dojo.marginBox(this._centerNode);
  263. dojo.style(this._centerNode, "display", curStyle);
  264. //IE has a horrible zoom bug. So, we have to try and account for
  265. //it and fix up the scaling.
  266. if(this._ieFixNode){
  267. _ie7zoom = -this._ieFixNode.offsetTop / 1000;
  268. box.x = Math.floor((box.x + 0.9) / _ie7zoom);
  269. box.y = Math.floor((box.y + 0.9) / _ie7zoom);
  270. box.w = Math.floor((box.w + 0.9) / _ie7zoom);
  271. box.h = Math.floor((box.h + 0.9) / _ie7zoom);
  272. }
  273. //Figure out how to zIndex this thing over the target.
  274. var zi = dojo.style(target, "zIndex");
  275. var ziUl = zi;
  276. var ziIn = zi;
  277. if(this.zIndex === "auto"){
  278. if(zi != "auto"){
  279. ziUl = parseInt(ziUl, 10) + 1;
  280. ziIn = parseInt(ziIn, 10) + 2;
  281. }else{
  282. //We need to search up the chain to see if there
  283. //are any parent zIndexs to overlay.
  284. var cNode = target.parentNode;
  285. var oldZi = -100000;
  286. while(cNode && cNode !== dojo.body()){
  287. zi = dojo.style(cNode, "zIndex");
  288. if(!zi || zi === "auto"){
  289. cNode = cNode.parentNode;
  290. }else{
  291. var newZi = parseInt(zi, 10);
  292. if(oldZi < newZi){
  293. oldZi = newZi;
  294. ziUl = newZi + 1;
  295. ziIn = newZi + 2;
  296. }
  297. // Keep looking until we run out, we want the highest zIndex.
  298. cNode = cNode.parentNode;
  299. }
  300. }
  301. }
  302. }else{
  303. ziUl = parseInt(this.zIndex, 10) + 1;
  304. ziIn = parseInt(this.zIndex, 10) + 2;
  305. }
  306. dojo.style(this._centerNode, "zIndex", ziIn);
  307. dojo.style(this._underlayNode, "zIndex", ziUl);
  308. var pn = target.parentNode;
  309. if(pn && pn !== dojo.body() &&
  310. target !== dojo.body() &&
  311. target !== dojo.doc){
  312. // If the parent is the body tag itself,
  313. // we can avoid all this, the body takes
  314. // care of overflow for me. Besides, browser
  315. // weirdness with height and width on body causes
  316. // problems with this sort of intersect testing
  317. // anyway.
  318. var obh = box.h;
  319. var obw = box.w;
  320. var pnBox = dojo.position(pn, true);
  321. //More IE zoom corrections. Grr.
  322. if(this._ieFixNode){
  323. _ie7zoom = -this._ieFixNode.offsetTop / 1000;
  324. pnBox.x = Math.floor((pnBox.x + 0.9) / _ie7zoom);
  325. pnBox.y = Math.floor((pnBox.y + 0.9) / _ie7zoom);
  326. pnBox.w = Math.floor((pnBox.w + 0.9) / _ie7zoom);
  327. pnBox.h = Math.floor((pnBox.h + 0.9) / _ie7zoom);
  328. }
  329. //Shift the parent width/height a bit if scollers are present.
  330. pnBox.w -= pn.scrollHeight > pn.clientHeight &&
  331. pn.clientHeight > 0 ? scrollers.v: 0;
  332. pnBox.h -= pn.scrollWidth > pn.clientWidth &&
  333. pn.clientWidth > 0 ? scrollers.h: 0;
  334. //RTL requires a bit of massaging in some cases
  335. //(and differently depending on browser, ugh!)
  336. //WebKit and others still need work.
  337. if(dir === "rtl"){
  338. if(dojo.isOpera){
  339. box.x += pn.scrollHeight > pn.clientHeight &&
  340. pn.clientHeight > 0 ? scrollers.v: 0;
  341. pnBox.x += pn.scrollHeight > pn.clientHeight &&
  342. pn.clientHeight > 0 ? scrollers.v: 0;
  343. }else if(dojo.isIE){
  344. pnBox.x += pn.scrollHeight > pn.clientHeight &&
  345. pn.clientHeight > 0 ? scrollers.v: 0;
  346. }else if(dojo.isWebKit){
  347. //TODO: FIX THIS!
  348. }
  349. }
  350. //Figure out if we need to adjust the overlay to fit a viewable
  351. //area, then resize it, we saved the original height/width above.
  352. //This is causing issues on IE. Argh!
  353. if(pnBox.w < box.w){
  354. //Scale down the width if necessary.
  355. box.w = box.w - pnBox.w;
  356. }
  357. if(pnBox.h < box.h){
  358. //Scale down the width if necessary.
  359. box.h = box.h - pnBox.h;
  360. }
  361. //Look at the y positions and see if we intersect with the
  362. //viewport borders. Will have to do computations off it.
  363. var vpTop = pnBox.y;
  364. var vpBottom = pnBox.y + pnBox.h;
  365. var bTop = box.y;
  366. var bBottom = box.y + obh;
  367. var vpLeft = pnBox.x;
  368. var vpRight = pnBox.x + pnBox.w;
  369. var bLeft = box.x;
  370. var bRight = box.x + obw;
  371. var delta;
  372. //Adjust the height now
  373. if(bBottom > vpTop &&
  374. bTop < vpTop){
  375. box.y = pnBox.y;
  376. //intersecting top, need to do some shifting.
  377. delta = vpTop - bTop;
  378. var visHeight = obh - delta;
  379. //If the visible height < viewport height,
  380. //We need to shift it.
  381. if(visHeight < pnBox.h){
  382. box.h = visHeight;
  383. }else{
  384. //Deal with horizontal scrollbars if necessary.
  385. box.h -= 2*(pn.scrollWidth > pn.clientWidth &&
  386. pn.clientWidth > 0? scrollers.h: 0);
  387. }
  388. }else if(bTop < vpBottom && bBottom > vpBottom){
  389. //Intersecting bottom, just figure out how much
  390. //overlay to show.
  391. box.h = vpBottom - bTop;
  392. }else if(bBottom <= vpTop || bTop >= vpBottom){
  393. //Outside view, hide it.
  394. box.h = 0;
  395. }
  396. //adjust width
  397. if(bRight > vpLeft && bLeft < vpLeft){
  398. box.x = pnBox.x;
  399. //intersecting left, need to do some shifting.
  400. delta = vpLeft - bLeft;
  401. var visWidth = obw - delta;
  402. //If the visible width < viewport width,
  403. //We need to shift it.
  404. if(visWidth < pnBox.w){
  405. box.w = visWidth;
  406. }else{
  407. //Deal with horizontal scrollbars if necessary.
  408. box.w -= 2*(pn.scrollHeight > pn.clientHeight &&
  409. pn.clientHeight > 0? scrollers.w:0);
  410. }
  411. }else if(bLeft < vpRight && bRight > vpRight){
  412. //Intersecting right, just figure out how much
  413. //overlay to show.
  414. box.w = vpRight - bLeft;
  415. }else if(bRight <= vpLeft || bLeft >= vpRight){
  416. //Outside view, hide it.
  417. box.w = 0;
  418. }
  419. }
  420. if(box.h > 0 && box.w > 0){
  421. //Set position and size of the blocking div overlay.
  422. dojo.style(this._underlayNode, {
  423. display: "block",
  424. width: box.w + "px",
  425. height: box.h + "px",
  426. top: box.y + "px",
  427. left: box.x + "px"
  428. });
  429. var styles = ["borderRadius", "borderTopLeftRadius",
  430. "borderTopRightRadius","borderBottomLeftRadius",
  431. "borderBottomRightRadius"];
  432. this._cloneStyles(styles);
  433. if(!dojo.isIE){
  434. //Browser specific styles to try and clone if non-IE.
  435. styles = ["MozBorderRadius", "MozBorderRadiusTopleft",
  436. "MozBorderRadiusTopright","MozBorderRadiusBottomleft",
  437. "MozBorderRadiusBottomright","WebkitBorderRadius",
  438. "WebkitBorderTopLeftRadius", "WebkitBorderTopRightRadius",
  439. "WebkitBorderBottomLeftRadius","WebkitBorderBottomRightRadius"
  440. ];
  441. this._cloneStyles(styles, this);
  442. }
  443. var cntrIndicatorTop = (box.h/2) - (cntrIndicator.h/2);
  444. var cntrIndicatorLeft = (box.w/2) - (cntrIndicator.w/2);
  445. //Only show the image if there is height and width room.
  446. if(box.h >= cntrIndicator.h && box.w >= cntrIndicator.w){
  447. dojo.style(this._centerNode, {
  448. top: (cntrIndicatorTop + box.y) + "px",
  449. left: (cntrIndicatorLeft + box.x) + "px",
  450. display: "block"
  451. });
  452. }else{
  453. dojo.style(this._centerNode, "display", "none");
  454. }
  455. }else{
  456. //Target has no size, display nothing on it!
  457. dojo.style(this._underlayNode, "display", "none");
  458. dojo.style(this._centerNode, "display", "none");
  459. }
  460. if(this._resizeCheck === null){
  461. //Set an interval timer that checks the target size and scales as needed.
  462. //Checking every 10th of a second seems to generate a fairly smooth update.
  463. var self = this;
  464. this._resizeCheck = setInterval(function(){self._size();}, 100);
  465. }
  466. }
  467. },
  468. _cloneStyles: function(list){
  469. // summary:
  470. // Internal function to clone a set of styles from the target to
  471. // the underlay.
  472. // list: Array
  473. // An array of style names to clone.
  474. //
  475. // tags:
  476. // private
  477. dojo.forEach(list, function(style){
  478. dojo.style(this._underlayNode,style,dojo.style(this.target,style));
  479. }, this);
  480. },
  481. _fadeIn: function(){
  482. // summary:
  483. // Internal function that does the opacity style fade in animation.
  484. // tags:
  485. // private
  486. var self = this;
  487. var underlayNodeAnim = dojo.animateProperty({
  488. duration: self.duration,
  489. node: self._underlayNode,
  490. properties: {opacity: {start: 0, end: 0.75}}
  491. });
  492. var imageAnim = dojo.animateProperty({
  493. duration: self.duration,
  494. node: self._centerNode,
  495. properties: {opacity: {start: 0, end: 1}},
  496. onEnd: function(){
  497. self.onShow();
  498. delete self._anim;
  499. }
  500. });
  501. this._anim = dojo.fx.combine([underlayNodeAnim,imageAnim]);
  502. this._anim.play();
  503. },
  504. _fadeOut: function(){
  505. // summary:
  506. // Internal function that does the opacity style fade out animation.
  507. // tags:
  508. // private
  509. var self = this;
  510. var underlayNodeAnim = dojo.animateProperty({
  511. duration: self.duration,
  512. node: self._underlayNode,
  513. properties: {opacity: {start: 0.75, end: 0}},
  514. onEnd: function(){
  515. dojo.style(this.node,{"display":"none", "zIndex": "-1000"});
  516. }
  517. });
  518. var imageAnim = dojo.animateProperty({
  519. duration: self.duration,
  520. node: self._centerNode,
  521. properties: {opacity: {start: 1, end: 0}},
  522. onEnd: function(){
  523. dojo.style(this.node,{"display":"none", "zIndex": "-1000"});
  524. self.onHide();
  525. self._enableOverflow();
  526. delete self._anim;
  527. }
  528. });
  529. this._anim = dojo.fx.combine([underlayNodeAnim,imageAnim]);
  530. this._anim.play();
  531. },
  532. _ignore: function(event){
  533. // summary:
  534. // Function to ignore events that occur on the overlay.
  535. // event: Event
  536. // The event to halt
  537. // tags:
  538. // private
  539. if(event){
  540. dojo.stopEvent(event);
  541. }
  542. },
  543. _scrollerWidths: function(){
  544. // summary:
  545. // This function will calculate the size of the vertical and
  546. // horizontaol scrollbars.
  547. // returns:
  548. // Object of form: {v: Number, h: Number} where v is vertical scrollbar width
  549. // and h is horizontal scrollbar width.
  550. // tags:
  551. // private
  552. var div = dojo.doc.createElement("div");
  553. dojo.style(div, {
  554. position: "absolute",
  555. opacity: 0,
  556. overflow: "hidden",
  557. width: "50px",
  558. height: "50px",
  559. zIndex: "-100",
  560. top: "-200px",
  561. left: "-200px",
  562. padding: "0px",
  563. margin: "0px"
  564. });
  565. var iDiv = dojo.doc.createElement("div");
  566. dojo.style(iDiv, {
  567. width: "200px",
  568. height: "10px"
  569. });
  570. div.appendChild(iDiv);
  571. dojo.body().appendChild(div);
  572. //Figure out content size before and after
  573. //scrollbars are there, then just subtract to
  574. //get width.
  575. var b = dojo.contentBox(div);
  576. dojo.style(div, "overflow", "scroll");
  577. var a = dojo.contentBox(div);
  578. dojo.body().removeChild(div);
  579. return { v: b.w - a.w, h: b.h - a.h };
  580. },
  581. /* The following are functions that tie into _Widget.attr() */
  582. _setTextAttr: function(text){
  583. // summary:
  584. // Function to allow widget.attr to set the text displayed in center
  585. // if using text display.
  586. // text: String
  587. // The text to set.
  588. this._textNode.innerHTML = text;
  589. this.text = text;
  590. },
  591. _setColorAttr: function(c){
  592. // summary:
  593. // Function to allow widget.attr to set the color used for the translucent
  594. // div overlay.
  595. // c: String
  596. // The color to set the background underlay to in #XXXXXX format..
  597. dojo.style(this._underlayNode, "backgroundColor", c);
  598. this.color = c;
  599. },
  600. _setImageTextAttr: function(text){
  601. // summary:
  602. // Function to allow widget.attr to set the ALT text text displayed for
  603. // the image (if using image center display).
  604. // text: String
  605. // The text to set.
  606. dojo.attr(this._imageNode, "alt", text);
  607. this.imageText = text;
  608. },
  609. _setImageAttr: function(url){
  610. // summary:
  611. // Function to allow widget.attr to set the url source for the center image
  612. // text: String
  613. // The url to set for the image.
  614. dojo.attr(this._imageNode, "src", url);
  615. this.image = url;
  616. },
  617. _setCenterIndicatorAttr: function(indicator){
  618. // summary:
  619. // Function to allow widget.attr to set the node used for the center indicator,
  620. // either the image or the text.
  621. // indicator: String
  622. // The indicator to use, either 'image' or 'text'.
  623. this.centerIndicator = indicator;
  624. if(indicator === "image"){
  625. this._centerNode = this._imageNode;
  626. dojo.style(this._textNode, "display", "none");
  627. }else{
  628. this._centerNode = this._textNode;
  629. dojo.style(this._imageNode, "display", "none");
  630. }
  631. },
  632. _disableOverflow: function(){
  633. // summary:
  634. // Function to disable scrollbars on the body. Only used if the overlay
  635. // targets the body or the document.
  636. if(this.target === dojo.body() || this.target === dojo.doc){
  637. // Store the overflow state we have to restore later.
  638. // IE had issues, so have to check that it's defined. Ugh.
  639. this._overflowDisabled = true;
  640. var body = dojo.body();
  641. if(body.style && body.style.overflow){
  642. this._oldOverflow = dojo.style(body, "overflow");
  643. }else{
  644. this._oldOverflow = "";
  645. }
  646. if(dojo.isIE && !dojo.isQuirks){
  647. // IE will put scrollbars in anyway, html (parent of body)
  648. // also controls them in standards mode, so we have to
  649. // remove them, argh.
  650. if(body.parentNode &&
  651. body.parentNode.style &&
  652. body.parentNode.style.overflow){
  653. this._oldBodyParentOverflow = body.parentNode.style.overflow;
  654. }else{
  655. try{
  656. this._oldBodyParentOverflow = dojo.style(body.parentNode, "overflow");
  657. }catch(e){
  658. this._oldBodyParentOverflow = "scroll";
  659. }
  660. }
  661. dojo.style(body.parentNode, "overflow", "hidden");
  662. }
  663. dojo.style(body, "overflow", "hidden");
  664. }
  665. },
  666. _enableOverflow: function(){
  667. // summary:
  668. // Function to restore scrollbars on the body. Only used if the overlay
  669. // targets the body or the document.
  670. if(this._overflowDisabled){
  671. delete this._overflowDisabled;
  672. var body = dojo.body();
  673. // Restore all the overflow.
  674. if(dojo.isIE && !dojo.isQuirks){
  675. body.parentNode.style.overflow = this._oldBodyParentOverflow;
  676. delete this._oldBodyParentOverflow;
  677. }
  678. dojo.style(body, "overflow", this._oldOverflow);
  679. if(dojo.isWebKit){
  680. //Gotta poke WebKit, or scrollers don't come back. :-(
  681. var div = dojo.create("div", { style: {
  682. height: "2px"
  683. }
  684. });
  685. body.appendChild(div);
  686. setTimeout(function(){
  687. body.removeChild(div);
  688. }, 0);
  689. }
  690. delete this._oldOverflow;
  691. }
  692. }
  693. });
  694. }