Imported Ami into own repository.
This commit is contained in:
commit
af337ab2cf
88 changed files with 10827 additions and 0 deletions
66
src/ami.js/submitbox.js
Normal file
66
src/ami.js/submitbox.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include utility.js
|
||||
#include watcher.js
|
||||
|
||||
var AmiSubmitBox = function(parent) {
|
||||
var pub = {},
|
||||
watcher = new AmiWatcher,
|
||||
maxLengthValue = 0,
|
||||
click = function(ev) {
|
||||
watcher.call(pub, [ev]);
|
||||
};
|
||||
|
||||
var button = $e({
|
||||
tag: 'input',
|
||||
attrs: {
|
||||
type: 'button',
|
||||
value: 'Send',
|
||||
id: 'sendmsg',
|
||||
onclick: function(ev) { click(ev); },
|
||||
},
|
||||
}),
|
||||
curLength = $e({
|
||||
tag: 'span',
|
||||
child: '0',
|
||||
}),
|
||||
maxLength = $e({
|
||||
tag: 'span',
|
||||
child: maxLengthValue.toString(),
|
||||
}),
|
||||
container = $e({
|
||||
attrs: { id: 'submitButtonContainer' },
|
||||
child: [
|
||||
{
|
||||
tag: 'span',
|
||||
attrs: { id: 'messageLengthCounter' },
|
||||
child: [curLength, '/', maxLength],
|
||||
},
|
||||
' ',
|
||||
button,
|
||||
],
|
||||
});
|
||||
|
||||
parent.appendChild(container);
|
||||
|
||||
pub.click = click;
|
||||
pub.watch = function(callback) {
|
||||
watcher.watch(callback);
|
||||
};
|
||||
pub.unwatch = function(watcher) {
|
||||
watcher.unwatch(callback);
|
||||
};
|
||||
|
||||
pub.setCurrentLength = function(num) {
|
||||
num = parseInt(num);
|
||||
curLength.textContent = num.toLocaleString();
|
||||
if(num >= maxLengthValue && !curLength.style.color)
|
||||
curLength.style.color = '#c00';
|
||||
else if(num < maxLengthValue && curLength.style.color)
|
||||
curLength.style.color = null;
|
||||
};
|
||||
pub.setMaxLength = function(num) {
|
||||
maxLengthValue = parseInt(num);
|
||||
maxLength.textContent = maxLengthValue.toLocaleString();
|
||||
};
|
||||
|
||||
return pub;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue