Skip to content

Commit

Permalink
feadt(ons-switch): Moved isChecked() and setCheked() and getCheckboxE…
Browse files Browse the repository at this point in the history
…lement() to ons-switch custom elements from angular switch view.
  • Loading branch information
anatoo committed Oct 1, 2015
1 parent 8531911 commit 2362851
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
21 changes: 21 additions & 0 deletions core/elements/ons-switch.es6
Expand Up @@ -74,6 +74,27 @@ limitations under the License.
}
}

/**
* @return {Boolean}
*/
isChecked() {
return this.checked;
}

/**
* @param {Boolean}
*/
setChecked(isChecked) {
return this.checked = !!isChecked;
}

/**
* @return {HTMLElement}
*/
getCheckboxElement() {
return this._getCheckbox();
}

createdCallback() {
this._compile();
ModifierUtil.initModifier(this, scheme);
Expand Down
35 changes: 16 additions & 19 deletions framework/views/switch.js
Expand Up @@ -36,6 +36,18 @@ limitations under the License.
this.emit('change', {'switch': this, value: this._checkbox[0].checked, isInteractive: true});
}.bind(this));

this._prepareNgModel(element, scope, attrs);

this._scope.$on('$destroy', this._destroy.bind(this));

this._clearDerivingMethods = $onsen.deriveMethods(this, element[0], [
'isChecked',
'setChecked',
'getCheckboxElement'
]);
},

_prepareNgModel: function(element, scope, attrs) {
if (attrs.ngModel) {
var set = $parse(attrs.ngModel).assign;

Expand All @@ -55,25 +67,10 @@ limitations under the License.
}
},

/**
* @return {Boolean}
*/
isChecked: function() {
return this._element[0]._isChecked();
},

/**
* @param {Boolean}
*/
setChecked: function(isChecked) {
return this._element[0]._setChecked(isChecked);
},

/**
* @return {HTMLElement}
*/
getCheckboxElement: function() {
return this._checkbox[0];
_destroy: function() {
this.emit('destroy');
this._clearDerivingMethods();
this._element = this._checkbox = this._scope = null;
}
});
MicroEvent.mixin(SwitchView);
Expand Down

0 comments on commit 2362851

Please sign in to comment.