Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kawabataryo
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kawabataryo/79635ffde8a5f3ababf0 to your computer and use it in GitHub Desktop.
Save kawabataryo/79635ffde8a5f3ababf0 to your computer and use it in GitHub Desktop.
/**
* [namespace]
*/
var App = App || {};
/**
* [Model]
*/
App.Model = function(text){
this.text = text;
this.initView();
}
App.Model.prototype = {
initView: function(){
new App.ViewResult(this.setData());
},
setData: function(){
var obj = {};
obj['strlength'] = this.getStrLength();
return obj;
},
getStrLength: function(){
return this.text.length;
}
}
/**
* [ViewForm]
*/
App.ViewForm = function(){
this.arg = arguments[0];
this.form = document.getElementById(this.arg['formID']);
this.textArea = document.getElementById(this.arg['textAreaID']);
this.init();
}
App.ViewForm.prototype = {
init: function(){
var that = this;
that.form.addEventListener('submit', function(e){
e.preventDefault();
new App.Model(that.getText());
});
},
getText: function(){
return this.textArea.value;
}
}
/**
* [ViewResult]
*/
App.ViewResult = function(result){
this.result = result;
this.textCount = document.getElementById('textCount');
this.lenderTextLength();
}
App.ViewResult.prototype = {
lenderTextLength: function(){
this.textCount.innerHTML = '';
for(var key in this.result){
this.textCount.innerHTML += '<li>' + this.result[key] + '</li>';
}
}
}
window.onload = function(){
new App.ViewForm({
formID: 'form',
textAreaID: 'textArea'
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment