Almost there...
This commit is contained in:
parent
0e4a97feb1
commit
aad4a54b8b
20 changed files with 2505 additions and 58 deletions
93
deploy/root/javascripts/application.js
Normal file
93
deploy/root/javascripts/application.js
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
var count = 0;
|
||||
var app = {
|
||||
url: 'http://localhost:9998/chat',
|
||||
initialize: function() {
|
||||
$('login-name').focus();
|
||||
app.listen();
|
||||
},
|
||||
listen: function() {
|
||||
$('comet-frame').src = app.url + '?' + count;
|
||||
count ++;
|
||||
},
|
||||
login: function() {
|
||||
var name = $F('login-name');
|
||||
if(! name.length > 0) {
|
||||
$('system-message').style.color = 'red';
|
||||
$('login-name').focus();
|
||||
return;
|
||||
}
|
||||
$('system-message').style.color = '#2d2b3d';
|
||||
$('system-message').innerHTML = name + ':';
|
||||
|
||||
$('login-button').disabled = true;
|
||||
$('login-form').style.display = 'none';
|
||||
$('message-form').style.display = '';
|
||||
|
||||
var query =
|
||||
'action=login' +
|
||||
'&name=' + encodeURI($F('login-name'));
|
||||
new Ajax.Request(app.url, {
|
||||
postBody: query,
|
||||
onSuccess: function() {
|
||||
$('message').focus();
|
||||
}
|
||||
});
|
||||
},
|
||||
post: function() {
|
||||
var message = $F('message');
|
||||
if(!message > 0) {
|
||||
return;
|
||||
}
|
||||
$('message').disabled = true;
|
||||
$('post-button').disabled = true;
|
||||
|
||||
var query =
|
||||
'action=post' +
|
||||
'&name=' + encodeURI($F('login-name')) +
|
||||
'&message=' + encodeURI(message);
|
||||
new Ajax.Request(app.url, {
|
||||
postBody: query,
|
||||
method : 'post',
|
||||
//requestHeaders: ['Content-Type',
|
||||
// 'application/x-www-form-urlencoded; charset=UTF-8'],
|
||||
onComplete: function() {
|
||||
$('message').disabled = false;
|
||||
$('post-button').disabled = false;
|
||||
$('message').focus();
|
||||
$('message').value = '';
|
||||
}
|
||||
});
|
||||
},
|
||||
update: function(data) {
|
||||
var p = document.createElement('p');
|
||||
p.innerHTML = data.name + ':<br/>' + data.message;
|
||||
|
||||
$('display').appendChild(p);
|
||||
|
||||
new Fx.Scroll('display').down();
|
||||
}
|
||||
};
|
||||
var rules = {
|
||||
'#login-name': function(elem) {
|
||||
Event.observe(elem, 'keydown', function(e) {
|
||||
if(e.keyCode == 13) {
|
||||
$('login-button').focus();
|
||||
}
|
||||
});
|
||||
},
|
||||
'#login-button': function(elem) {
|
||||
elem.onclick = app.login;
|
||||
},
|
||||
'#message': function(elem) {
|
||||
Event.observe(elem, 'keydown', function(e) {
|
||||
if(e.shiftKey && e.keyCode == 13) {
|
||||
$('post-button').focus();
|
||||
}
|
||||
});
|
||||
},
|
||||
'#post-button': function(elem) {
|
||||
elem.onclick = app.post;
|
||||
}
|
||||
};
|
||||
Behaviour.addLoadEvent(app.initialize);
|
||||
Behaviour.register(rules);
|
||||
254
deploy/root/javascripts/behaviour.js
Normal file
254
deploy/root/javascripts/behaviour.js
Normal file
|
|
@ -0,0 +1,254 @@
|
|||
/*
|
||||
Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work
|
||||
of Simon Willison (see comments by Simon below).
|
||||
|
||||
Description:
|
||||
|
||||
Uses css selectors to apply javascript behaviours to enable
|
||||
unobtrusive javascript in html documents.
|
||||
|
||||
Usage:
|
||||
|
||||
var myrules = {
|
||||
'b.someclass' : function(element){
|
||||
element.onclick = function(){
|
||||
alert(this.innerHTML);
|
||||
}
|
||||
},
|
||||
'#someid u' : function(element){
|
||||
element.onmouseover = function(){
|
||||
this.innerHTML = "BLAH!";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Behaviour.register(myrules);
|
||||
|
||||
// Call Behaviour.apply() to re-apply the rules (if you
|
||||
// update the dom, etc).
|
||||
|
||||
License:
|
||||
|
||||
This file is entirely BSD licensed.
|
||||
|
||||
More information:
|
||||
|
||||
http://ripcord.co.nz/behaviour/
|
||||
|
||||
*/
|
||||
|
||||
var Behaviour = {
|
||||
list : new Array,
|
||||
|
||||
register : function(sheet){
|
||||
Behaviour.list.push(sheet);
|
||||
},
|
||||
|
||||
start : function(){
|
||||
Behaviour.addLoadEvent(function(){
|
||||
Behaviour.apply();
|
||||
});
|
||||
},
|
||||
|
||||
apply : function(){
|
||||
for (h=0;sheet=Behaviour.list[h];h++){
|
||||
for (selector in sheet){
|
||||
list = document.getElementsBySelector(selector);
|
||||
|
||||
if (!list){
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i=0;element=list[i];i++){
|
||||
sheet[selector](element);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
addLoadEvent : function(func){
|
||||
var oldonload = window.onload;
|
||||
|
||||
if (typeof window.onload != 'function') {
|
||||
window.onload = func;
|
||||
} else {
|
||||
window.onload = function() {
|
||||
oldonload();
|
||||
func();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Behaviour.start();
|
||||
|
||||
/*
|
||||
The following code is Copyright (C) Simon Willison 2004.
|
||||
|
||||
document.getElementsBySelector(selector)
|
||||
- returns an array of element objects from the current document
|
||||
matching the CSS selector. Selectors can contain element names,
|
||||
class names and ids and can be nested. For example:
|
||||
|
||||
elements = document.getElementsBySelect('div#main p a.external')
|
||||
|
||||
Will return an array of all 'a' elements with 'external' in their
|
||||
class attribute that are contained inside 'p' elements that are
|
||||
contained inside the 'div' element which has id="main"
|
||||
|
||||
New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
|
||||
See http://www.w3.org/TR/css3-selectors/#attribute-selectors
|
||||
|
||||
Version 0.4 - Simon Willison, March 25th 2003
|
||||
-- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
|
||||
-- Opera 7 fails
|
||||
*/
|
||||
|
||||
function getAllChildren(e) {
|
||||
// Returns all children of element. Workaround required for IE5/Windows. Ugh.
|
||||
return e.all ? e.all : e.getElementsByTagName('*');
|
||||
}
|
||||
|
||||
document.getElementsBySelector = function(selector) {
|
||||
// Attempt to fail gracefully in lesser browsers
|
||||
if (!document.getElementsByTagName) {
|
||||
return new Array();
|
||||
}
|
||||
// Split selector in to tokens
|
||||
var tokens = selector.split(' ');
|
||||
var currentContext = new Array(document);
|
||||
for (var i = 0; i < tokens.length; i++) {
|
||||
token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
|
||||
if (token.indexOf('#') > -1) {
|
||||
// Token is an ID selector
|
||||
var bits = token.split('#');
|
||||
var tagName = bits[0];
|
||||
var id = bits[1];
|
||||
var element = document.getElementById(id);
|
||||
if (tagName && element.nodeName.toLowerCase() != tagName) {
|
||||
// tag with that ID not found, return false
|
||||
return new Array();
|
||||
}
|
||||
// Set currentContext to contain just this element
|
||||
currentContext = new Array(element);
|
||||
continue; // Skip to next token
|
||||
}
|
||||
if (token.indexOf('.') > -1) {
|
||||
// Token contains a class selector
|
||||
var bits = token.split('.');
|
||||
var tagName = bits[0];
|
||||
var className = bits[1];
|
||||
if (!tagName) {
|
||||
tagName = '*';
|
||||
}
|
||||
// Get elements matching tag, filter them for class selector
|
||||
var found = new Array;
|
||||
var foundCount = 0;
|
||||
for (var h = 0; h < currentContext.length; h++) {
|
||||
var elements;
|
||||
if (tagName == '*') {
|
||||
elements = getAllChildren(currentContext[h]);
|
||||
} else {
|
||||
elements = currentContext[h].getElementsByTagName(tagName);
|
||||
}
|
||||
for (var j = 0; j < elements.length; j++) {
|
||||
found[foundCount++] = elements[j];
|
||||
}
|
||||
}
|
||||
currentContext = new Array;
|
||||
var currentContextIndex = 0;
|
||||
for (var k = 0; k < found.length; k++) {
|
||||
if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
|
||||
currentContext[currentContextIndex++] = found[k];
|
||||
}
|
||||
}
|
||||
continue; // Skip to next token
|
||||
}
|
||||
// Code to deal with attribute selectors
|
||||
if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
|
||||
var tagName = RegExp.$1;
|
||||
var attrName = RegExp.$2;
|
||||
var attrOperator = RegExp.$3;
|
||||
var attrValue = RegExp.$4;
|
||||
if (!tagName) {
|
||||
tagName = '*';
|
||||
}
|
||||
// Grab all of the tagName elements within current context
|
||||
var found = new Array;
|
||||
var foundCount = 0;
|
||||
for (var h = 0; h < currentContext.length; h++) {
|
||||
var elements;
|
||||
if (tagName == '*') {
|
||||
elements = getAllChildren(currentContext[h]);
|
||||
} else {
|
||||
elements = currentContext[h].getElementsByTagName(tagName);
|
||||
}
|
||||
for (var j = 0; j < elements.length; j++) {
|
||||
found[foundCount++] = elements[j];
|
||||
}
|
||||
}
|
||||
currentContext = new Array;
|
||||
var currentContextIndex = 0;
|
||||
var checkFunction; // This function will be used to filter the elements
|
||||
switch (attrOperator) {
|
||||
case '=': // Equality
|
||||
checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
|
||||
break;
|
||||
case '~': // Match one of space seperated words
|
||||
checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
|
||||
break;
|
||||
case '|': // Match start with value followed by optional hyphen
|
||||
checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
|
||||
break;
|
||||
case '^': // Match starts with value
|
||||
checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
|
||||
break;
|
||||
case '$': // Match ends with value - fails with "Warning" in Opera 7
|
||||
checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
|
||||
break;
|
||||
case '*': // Match ends with value
|
||||
checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
|
||||
break;
|
||||
default :
|
||||
// Just test for existence of attribute
|
||||
checkFunction = function(e) { return e.getAttribute(attrName); };
|
||||
}
|
||||
currentContext = new Array;
|
||||
var currentContextIndex = 0;
|
||||
for (var k = 0; k < found.length; k++) {
|
||||
if (checkFunction(found[k])) {
|
||||
currentContext[currentContextIndex++] = found[k];
|
||||
}
|
||||
}
|
||||
// alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
|
||||
continue; // Skip to next token
|
||||
}
|
||||
|
||||
if (!currentContext[0]){
|
||||
return;
|
||||
}
|
||||
|
||||
// If we get here, token is JUST an element (not a class or ID selector)
|
||||
tagName = token;
|
||||
var found = new Array;
|
||||
var foundCount = 0;
|
||||
for (var h = 0; h < currentContext.length; h++) {
|
||||
var elements = currentContext[h].getElementsByTagName(tagName);
|
||||
for (var j = 0; j < elements.length; j++) {
|
||||
found[foundCount++] = elements[j];
|
||||
}
|
||||
}
|
||||
currentContext = found;
|
||||
}
|
||||
return currentContext;
|
||||
}
|
||||
|
||||
/* That revolting regular expression explained
|
||||
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
|
||||
\---/ \---/\-------------/ \-------/
|
||||
| | | |
|
||||
| | | The value
|
||||
| | ~,|,^,$,* or =
|
||||
| Attribute
|
||||
Tag
|
||||
*/
|
||||
136
deploy/root/javascripts/moo.fx.js
Normal file
136
deploy/root/javascripts/moo.fx.js
Normal file
|
|
@ -0,0 +1,136 @@
|
|||
//(c) 2006 Valerio Proietti (http://mad4milk.net). MIT-style license.
|
||||
//moo.fx.js - depends on prototype.js OR prototype.lite.js
|
||||
//version 2.0
|
||||
|
||||
var Fx = fx = {};
|
||||
|
||||
Fx.Base = function(){};
|
||||
Fx.Base.prototype = {
|
||||
|
||||
setOptions: function(options){
|
||||
this.options = Object.extend({
|
||||
onStart: function(){},
|
||||
onComplete: function(){},
|
||||
transition: Fx.Transitions.sineInOut,
|
||||
duration: 500,
|
||||
unit: 'px',
|
||||
wait: true,
|
||||
fps: 50
|
||||
}, options || {});
|
||||
},
|
||||
|
||||
step: function(){
|
||||
var time = new Date().getTime();
|
||||
if (time < this.time + this.options.duration){
|
||||
this.cTime = time - this.time;
|
||||
this.setNow();
|
||||
} else {
|
||||
setTimeout(this.options.onComplete.bind(this, this.element), 10);
|
||||
this.clearTimer();
|
||||
this.now = this.to;
|
||||
}
|
||||
this.increase();
|
||||
},
|
||||
|
||||
setNow: function(){
|
||||
this.now = this.compute(this.from, this.to);
|
||||
},
|
||||
|
||||
compute: function(from, to){
|
||||
var change = to - from;
|
||||
return this.options.transition(this.cTime, from, change, this.options.duration);
|
||||
},
|
||||
|
||||
clearTimer: function(){
|
||||
clearInterval(this.timer);
|
||||
this.timer = null;
|
||||
return this;
|
||||
},
|
||||
|
||||
_start: function(from, to){
|
||||
if (!this.options.wait) this.clearTimer();
|
||||
if (this.timer) return;
|
||||
setTimeout(this.options.onStart.bind(this, this.element), 10);
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.time = new Date().getTime();
|
||||
this.timer = setInterval(this.step.bind(this), Math.round(1000/this.options.fps));
|
||||
return this;
|
||||
},
|
||||
|
||||
custom: function(from, to){
|
||||
return this._start(from, to);
|
||||
},
|
||||
|
||||
set: function(to){
|
||||
this.now = to;
|
||||
this.increase();
|
||||
return this;
|
||||
},
|
||||
|
||||
hide: function(){
|
||||
return this.set(0);
|
||||
},
|
||||
|
||||
setStyle: function(e, p, v){
|
||||
if (p == 'opacity'){
|
||||
if (v == 0 && e.style.visibility != "hidden") e.style.visibility = "hidden";
|
||||
else if (e.style.visibility != "visible") e.style.visibility = "visible";
|
||||
if (window.ActiveXObject) e.style.filter = "alpha(opacity=" + v*100 + ")";
|
||||
e.style.opacity = v;
|
||||
} else e.style[p] = v+this.options.unit;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Fx.Style = Class.create();
|
||||
Fx.Style.prototype = Object.extend(new Fx.Base(), {
|
||||
|
||||
initialize: function(el, property, options){
|
||||
this.element = $(el);
|
||||
this.setOptions(options);
|
||||
this.property = property.camelize();
|
||||
},
|
||||
|
||||
increase: function(){
|
||||
this.setStyle(this.element, this.property, this.now);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Fx.Styles = Class.create();
|
||||
Fx.Styles.prototype = Object.extend(new Fx.Base(), {
|
||||
|
||||
initialize: function(el, options){
|
||||
this.element = $(el);
|
||||
this.setOptions(options);
|
||||
this.now = {};
|
||||
},
|
||||
|
||||
setNow: function(){
|
||||
for (p in this.from) this.now[p] = this.compute(this.from[p], this.to[p]);
|
||||
},
|
||||
|
||||
custom: function(obj){
|
||||
if (this.timer && this.options.wait) return;
|
||||
var from = {};
|
||||
var to = {};
|
||||
for (p in obj){
|
||||
from[p] = obj[p][0];
|
||||
to[p] = obj[p][1];
|
||||
}
|
||||
return this._start(from, to);
|
||||
},
|
||||
|
||||
increase: function(){
|
||||
for (var p in this.now) this.setStyle(this.element, p, this.now[p]);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//Transitions (c) 2003 Robert Penner (http://www.robertpenner.com/easing/), BSD License.
|
||||
|
||||
Fx.Transitions = {
|
||||
linear: function(t, b, c, d) { return c*t/d + b; },
|
||||
sineInOut: function(t, b, c, d) { return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; }
|
||||
};
|
||||
83
deploy/root/javascripts/moo.fx.pack.js
Normal file
83
deploy/root/javascripts/moo.fx.pack.js
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
//by Valerio Proietti (http://mad4milk.net). MIT-style license.
|
||||
//moo.fx.pack.js - depends on prototype.js or prototype.lite.js + moo.fx.js
|
||||
//version 2.0
|
||||
|
||||
Fx.Scroll = Class.create();
|
||||
Fx.Scroll.prototype = Object.extend(new Fx.Base(), {
|
||||
|
||||
initialize: function(el, options) {
|
||||
this.element = $(el);
|
||||
this.setOptions(options);
|
||||
this.element.style.overflow = 'hidden';
|
||||
},
|
||||
|
||||
down: function(){
|
||||
return this.custom(this.element.scrollTop, this.element.scrollHeight-this.element.offsetHeight);
|
||||
},
|
||||
|
||||
up: function(){
|
||||
return this.custom(this.element.scrollTop, 0);
|
||||
},
|
||||
|
||||
increase: function(){
|
||||
this.element.scrollTop = this.now;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
//fx.Color, originally by Tom Jensen (http://neuemusic.com) MIT-style LICENSE.
|
||||
|
||||
Fx.Color = Class.create();
|
||||
Fx.Color.prototype = Object.extend(new Fx.Base(), {
|
||||
|
||||
initialize: function(el, property, options){
|
||||
this.element = $(el);
|
||||
this.setOptions(options);
|
||||
this.property = property.camelize();
|
||||
this.now = [];
|
||||
},
|
||||
|
||||
custom: function(from, to){
|
||||
return this._start(from.hexToRgb(true), to.hexToRgb(true));
|
||||
},
|
||||
|
||||
setNow: function(){
|
||||
[0,1,2].each(function(i){
|
||||
this.now[i] = Math.round(this.compute(this.from[i], this.to[i]));
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
increase: function(){
|
||||
this.element.style[this.property] = "rgb("+this.now[0]+","+this.now[1]+","+this.now[2]+")";
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.extend(String.prototype, {
|
||||
|
||||
rgbToHex: function(array){
|
||||
var rgb = this.match(new RegExp('([\\d]{1,3})', 'g'));
|
||||
if (rgb[3] == 0) return 'transparent';
|
||||
var hex = [];
|
||||
for (var i = 0; i < 3; i++){
|
||||
var bit = (rgb[i]-0).toString(16);
|
||||
hex.push(bit.length == 1 ? '0'+bit : bit);
|
||||
}
|
||||
var hexText = '#'+hex.join('');
|
||||
if (array) return hex;
|
||||
else return hexText;
|
||||
},
|
||||
|
||||
hexToRgb: function(array){
|
||||
var hex = this.match(new RegExp('^[#]{0,1}([\\w]{1,2})([\\w]{1,2})([\\w]{1,2})$'));
|
||||
var rgb = [];
|
||||
for (var i = 1; i < hex.length; i++){
|
||||
if (hex[i].length == 1) hex[i] += hex[i];
|
||||
rgb.push(parseInt(hex[i], 16));
|
||||
}
|
||||
var rgbText = 'rgb('+rgb.join(',')+')';
|
||||
if (array) return rgb;
|
||||
else return rgbText;
|
||||
}
|
||||
|
||||
});
|
||||
1781
deploy/root/javascripts/prototype.js
vendored
Normal file
1781
deploy/root/javascripts/prototype.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue