public
Last active

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
/**
* MyWidget
*/
 
var MyWidget,
MY_WIDGET = 'myWidget',
SUBJECT = 'subject',
MESSAGE = 'message',
SUBJECT_NODE = 'subjectNode',
MESSAGE_NODE = 'messageNode',
UI_SRC = Y.Widget.UI_SRC,
isNull = Y.Lang.isNull,
isString = Y.Lang.isString;
 
// *** Constructor *** //
 
MyWidget = function () {
MyWidget.superclass.constructor.apply(this, arguments);
};
 
// *** Static *** //
 
Y.mix(MyWidget, {
NAME : MY_WIDGET,
ATTRS : {
subject : {
value : null,
setter : '_setNewSubject'
},
message : {
value : null,
setter : '_setNewMessage'
},
subjectNode : {
writeOnce : true
},
messageNode : {
writeOnce : true
},
}
});
 
// *** Prototype *** //
 
Y.extend(MyWidget, Y.Widget, {
// *** Instance Members *** //
// *** Lifecycle Methods *** //
initializer : function (config) {},
destructor : function () {},
renderUI : function () {},
bindUI : function () {
var subjectNode = this.get(SUBJECT_NODE),
messageNode = this.get(MESSAGE_NODE);
this._bindAttrUI([SUBJECT, MESSAGE]);
if (subjectNode) {
subjectNode.on('change', Y.bind(function(e){
this.set(SUBJECT, e.target.get('value'), { src: UI_SRC });
}, this));
}
if (messageNode) {
messageNode.on('change', Y.bind(function(e){
this.set(MESSAGE, e.target.get('value'), { src: UI_SRC });
}, this));
}
},
syncUI : function () {
this._syncAttrUI([SUBJECT, MESSAGE]);
},
// *** Public Methods *** //
syncAttrs : function () {
var subjectNode = this.get(SUBJECT_NODE),
messageNode = this.get(MESSAGE_NODE);
if (subjectNode) {
this.set(SUBJECT, subjectNode.get('value'), { src: UI_SRC });
}
if (messageNode) {
this.set(MESSAGE, messageNode.get('value'), { src: UI_SRC });
}
},
resetData : function () {
this.reset(SUBJECT);
this.reset(MESSAGE);
},
// *** Private Methods *** //
_setNewSubject : function (v) {
if (isNull(v)) {
return v;
}
if (isString(v)) {
return ( v.length > 0 ? v : null );
}
return Y.Attribute.INVALID_VALUE;
},
_setNewMessage : function (v) {
if (isNull(v)) {
return v;
}
if (isString(v)) {
return ( v.length > 0 ? v : null );
}
return Y.Attribute.INVALID_VALUE;
}
_uiSetSubject : function (v, src) {
if (src === UI_SRC) {
return;
}
var subjectNode = this.get(SUBJECT_NODE);
if (subjectNode) {
subjectNode.set(VALUE, v || '');
}
},
_uiSetMessage : function (v, src) {
if (src === UI_SRC) {
return;
}
var messageNode = this.get(MESSAGE_NODE);
if (messageNode) {
messageNode.set(VALUE, v || '');
}
}
});
 
Y.MyWidget = MyWidget;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.