Skip to content

@ericf /gist:266915
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
/**
* 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.