IconContainer.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. define("dojox/mobile/IconContainer", [
  2. "dojo/_base/array",
  3. "dojo/_base/declare",
  4. "dojo/_base/window",
  5. "dojo/dom-construct",
  6. "dojo/dom-style",
  7. "dijit/registry", // registry.byNode
  8. "dijit/_Contained",
  9. "dijit/_Container",
  10. "dijit/_WidgetBase",
  11. "./IconItem",
  12. "./Heading",
  13. "./View"
  14. ], function(array, declare, win, domConstruct, domStyle, registry, Contained, Container, WidgetBase, IconItem, Heading, View){
  15. /*=====
  16. var Contained = dijit._Contained;
  17. var Container = dijit._Container;
  18. var WidgetBase = dijit._WidgetBase;
  19. =====*/
  20. // module:
  21. // dojox/mobile/IconContainer
  22. // summary:
  23. // A container widget that holds multiple icons.
  24. return declare("dojox.mobile.IconContainer", [WidgetBase, Container, Contained],{
  25. // summary:
  26. // A container widget that holds multiple icons.
  27. // description:
  28. // IconContainer is a container widget that holds multiple icons
  29. // each of which represents application component.
  30. // defaultIcon: String
  31. // The default fall-back icon, which is displayed only when the
  32. // specified icon has failed to load.
  33. defaultIcon: "",
  34. // transition: String
  35. // A type of animated transition effect. You can choose from the
  36. // standard transition types, "slide", "fade", "flip", or from the
  37. // extended transition types, "cover", "coverv", "dissolve",
  38. // "reveal", "revealv", "scaleIn", "scaleOut", "slidev",
  39. // "swirl", "zoomIn", "zoomOut". If "none" is specified, transition
  40. // occurs immediately without animation. If "below" is specified,
  41. // the application contents are displayed below the icons.
  42. transition: "below",
  43. // pressedIconOpacity: Number
  44. // The opacity of the pressed icon image.
  45. pressedIconOpacity: 0.4,
  46. // iconBase: String
  47. // The default icon path for child items.
  48. iconBase: "",
  49. // iconPos: String
  50. // The default icon position for child items.
  51. iconPos: "",
  52. // back: String
  53. // A label for the navigational control.
  54. back: "Home",
  55. // label: String
  56. // A title text of the heading.
  57. label: "My Application",
  58. // single: Boolean
  59. // If true, only one icon content can be opened at a time.
  60. single: false,
  61. buildRendering: function(){
  62. this.domNode = this.containerNode = this.srcNodeRef || win.doc.createElement("UL");
  63. this.domNode.className = "mblIconContainer";
  64. var t = this._terminator = domConstruct.create("LI");
  65. t.className = "mblIconItemTerminator";
  66. t.innerHTML = " ";
  67. this.domNode.appendChild(t);
  68. },
  69. _setupSubNodes: function(ul){
  70. array.forEach(this.getChildren(), function(w){
  71. ul.appendChild(w.subNode);
  72. });
  73. },
  74. startup: function(){
  75. if(this._started){ return; }
  76. if(this.transition === "below"){
  77. this._setupSubNodes(this.domNode);
  78. }else{
  79. var view = this.appView = new View({id:this.id+"_mblApplView"});
  80. var _this = this;
  81. view.onAfterTransitionIn = function(moveTo, dir, transition, context, method){
  82. _this._opening._open_1();
  83. };
  84. view.domNode.style.visibility = "hidden";
  85. var heading = view._heading
  86. = new Heading({back: this._cv ? this._cv(this.back) : this.back,
  87. label: this._cv ? this._cv(this.label) : this.label,
  88. moveTo: this.domNode.parentNode.id,
  89. transition: this.transition});
  90. view.addChild(heading);
  91. var ul = view._ul = win.doc.createElement("UL");
  92. ul.className = "mblIconContainer";
  93. ul.style.marginTop = "0px";
  94. this._setupSubNodes(ul);
  95. view.domNode.appendChild(ul);
  96. var target;
  97. for(var w = this.getParent(); w; w = w.getParent()){
  98. if(w instanceof View){
  99. target = w.domNode.parentNode;
  100. break;
  101. }
  102. }
  103. if(!target){ target = win.body(); }
  104. target.appendChild(view.domNode);
  105. view.startup();
  106. }
  107. this.inherited(arguments);
  108. },
  109. closeAll: function(){
  110. // summary:
  111. // Closes all the icon items.
  112. var len = this.domNode.childNodes.length, child, w;
  113. for(var i = 0; i < len; i++){
  114. var child = this.domNode.childNodes[i];
  115. if(child.nodeType !== 1){ continue; }
  116. if(child === this._terminator){ break; }
  117. var w = registry.byNode(child);
  118. w.containerNode.parentNode.style.display = "none";
  119. domStyle.set(w.iconNode, "opacity", 1);
  120. }
  121. },
  122. addChild: function(widget, /*Number?*/insertIndex){
  123. var children = this.getChildren();
  124. if(typeof insertIndex !== "number" || insertIndex > children.length){
  125. insertIndex = children.length;
  126. }
  127. var idx = insertIndex;
  128. var refNode = this.containerNode;
  129. if(idx > 0){
  130. refNode = children[idx - 1].domNode;
  131. idx = "after";
  132. }
  133. domConstruct.place(widget.domNode, refNode, idx);
  134. widget.transition = this.transition;
  135. if(this.transition === "below"){
  136. for(var i = 0, refNode = this._terminator; i < insertIndex; i++){
  137. refNode = refNode.nextSibling;
  138. }
  139. domConstruct.place(widget.subNode, refNode, "after");
  140. }else{
  141. domConstruct.place(widget.subNode, this.appView._ul, insertIndex);
  142. }
  143. widget.inheritParams();
  144. widget._setIconAttr(widget.icon);
  145. if(this._started && !widget._started){
  146. widget.startup();
  147. }
  148. },
  149. removeChild: function(/*Widget|Number*/widget){
  150. if(typeof widget === "number"){
  151. widget = this.getChildren()[widget];
  152. }
  153. if(widget){
  154. this.inherited(arguments);
  155. if(this.transition === "below"){
  156. this.containerNode.removeChild(widget.subNode);
  157. }else{
  158. this.appView._ul.removeChild(widget.subNode);
  159. }
  160. }
  161. }
  162. });
  163. });