1 | define([ |
---|
2 | "dojo/_base/declare", |
---|
3 | "dojo/_base/lang", |
---|
4 | "dojo/dom-class", |
---|
5 | "dojo/dom-construct", |
---|
6 | "./iconUtils", |
---|
7 | "dojo/has", |
---|
8 | "dojo/has!dojo-bidi?dojox/mobile/bidi/Badge" |
---|
9 | ], function(declare, lang, domClass, domConstruct, iconUtils, has, BidiBadge){ |
---|
10 | // module: |
---|
11 | // dojox/mobile/Badge |
---|
12 | |
---|
13 | var Badge = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiBadge" : "dojox.mobile.Badge", null, { |
---|
14 | // summary: |
---|
15 | // A utility class to create and update a badge node. |
---|
16 | // description: |
---|
17 | // Badge is not a widget, but a simple utility class for creating and |
---|
18 | // updating a badge node. A badge consists of a simple DOM button. |
---|
19 | // It is intended to be used from other widgets such as dojox/mobile/IconItem |
---|
20 | // or dojox/mobile/TabBarButton. |
---|
21 | |
---|
22 | // value: [const] String |
---|
23 | // A text to show in a badge. |
---|
24 | // Note that changing the value of the property after the badge |
---|
25 | // creation has no effect. |
---|
26 | value: "0", |
---|
27 | |
---|
28 | // className: [const] String |
---|
29 | // A CSS class name of a DOM button. |
---|
30 | className: "mblDomButtonRedBadge", |
---|
31 | |
---|
32 | // fontSize: [const] Number |
---|
33 | // Font size in pixel. The other style attributes are determined by the DOM |
---|
34 | // button itself. |
---|
35 | // Note that changing the value of the property after the badge |
---|
36 | // creation has no effect. |
---|
37 | fontSize: 16, // [px] |
---|
38 | |
---|
39 | constructor: function(/*Object?*/params, /*DomNode?*/node){ |
---|
40 | // summary: |
---|
41 | // Creates a new instance of the class. |
---|
42 | // params: |
---|
43 | // Contains properties to be set. |
---|
44 | // node: |
---|
45 | // The DOM node. If none is specified, it is automatically created. |
---|
46 | if (params){ |
---|
47 | lang.mixin(this, params); |
---|
48 | } |
---|
49 | this.domNode = node ? node : domConstruct.create("div"); |
---|
50 | domClass.add(this.domNode, "mblBadge"); |
---|
51 | if(this.domNode.className.indexOf("mblDomButton") === -1){ |
---|
52 | domClass.add(this.domNode, this.className); |
---|
53 | } |
---|
54 | if(this.fontSize !== 16){ |
---|
55 | this.domNode.style.fontSize = this.fontSize + "px"; |
---|
56 | } |
---|
57 | iconUtils.createDomButton(this.domNode); |
---|
58 | this.setValue(this.value); |
---|
59 | }, |
---|
60 | |
---|
61 | getValue: function(){ |
---|
62 | // summary: |
---|
63 | // Returns the text shown in the badge. |
---|
64 | return this.domNode.firstChild.innerHTML || ""; |
---|
65 | }, |
---|
66 | |
---|
67 | setValue: function(/*String*/value){ |
---|
68 | // summary: |
---|
69 | // Set a label text to the badge. |
---|
70 | this.domNode.firstChild.innerHTML = value; |
---|
71 | } |
---|
72 | }); |
---|
73 | |
---|
74 | return has("dojo-bidi") ? declare("dojox.mobile.Badge", [Badge, BidiBadge]) : Badge; |
---|
75 | }); |
---|