aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage/ui/token-field/token.reel/token.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage/ui/token-field/token.reel/token.js')
-rw-r--r--node_modules/montage/ui/token-field/token.reel/token.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/node_modules/montage/ui/token-field/token.reel/token.js b/node_modules/montage/ui/token-field/token.reel/token.js
new file mode 100644
index 00000000..15216c3f
--- /dev/null
+++ b/node_modules/montage/ui/token-field/token.reel/token.js
@@ -0,0 +1,91 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6var Montage = require("montage").Montage,
7 Component = require("ui/component").Component;
8
9exports.Token = Montage.create(Component, {
10
11 text: {value: null},
12
13 allowAdHocValues: {value: null},
14
15 value: {
16 get: function() {
17 return this._value;
18 },
19 set: function(aValue) {
20 this._adHoc = false;
21 if(aValue) {
22 this._value = aValue;
23 if(this.textPropertyPath) {
24 if(typeof aValue[this.textPropertyPath] == 'undefined' && this.allowAdHocValues) {
25 this.text = aValue;
26 this._adHoc = true;
27 } else {
28 this.text = this.value[this.textPropertyPath];
29 }
30 } else {
31 this.text = this.value;
32 }
33 }
34 }
35 },
36
37 textPropertyPath: {value: null},
38
39 tokensController: {value: null},
40
41 // private
42
43 __adHoc: {value: null},
44 _adHoc: {
45 get: function() {
46 return this.__adHoc;
47 },
48 set: function(value) {
49 this.__adHoc = value;
50 this.needsDraw = true;
51 }
52 },
53
54 _deleteEl: {value: null},
55
56 prepareForDraw: {
57 value: function() {
58 if(window.Touch) {
59 this._deleteEl.addEventListener('touchend', this);
60 } else {
61 this._deleteEl.addEventListener('click', this);
62 }
63 }
64 },
65
66 draw: {
67 value: function() {
68 this.element.classList[this._adHoc ? 'add' : 'remove']('montage-token-adhoc');
69 }
70 },
71
72 // Event handling
73
74 removeSelf: {
75 value: function() {
76 this.tokensController.removeObjects(this.value);
77 }
78 },
79
80 handleClick: {
81 value: function(event) {
82 this.removeSelf();
83 }
84 },
85 handleTouchend: {
86 value: function(event) {
87 this.removeSelf();
88 }
89 }
90
91});