Last active
August 29, 2015 14:12
-
-
Save kawabataryo/79635ffde8a5f3ababf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* [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