mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
Fix some JavaScript lint. Still a lot left.
This commit is contained in:
parent
a25193cc5d
commit
5d0bbb6a45
@ -7,90 +7,96 @@ var span_count_out = [];
|
||||
var current_depth = -1;
|
||||
|
||||
function alignIn( sentence, word, depth ) {
|
||||
if (current_depth < depth) {
|
||||
current_depth = depth;
|
||||
}
|
||||
else { return; }
|
||||
|
||||
var id = 0;
|
||||
for(var i=1;i<nodeIn[sentence].size();i++ ) {
|
||||
if (nodeIn[sentence][i].start <= word && word <= nodeIn[sentence][i].end && nodeIn[sentence][i].depth <= depth) {
|
||||
id = i;
|
||||
}
|
||||
}
|
||||
var id, i;
|
||||
if (current_depth < depth) {
|
||||
current_depth = depth;
|
||||
}
|
||||
else { return; }
|
||||
|
||||
highlightNode( sentence, id );
|
||||
id = 0;
|
||||
for(i=1;i<nodeIn[sentence].size();i++ ) {
|
||||
if (nodeIn[sentence][i].start <= word && word <= nodeIn[sentence][i].end && nodeIn[sentence][i].depth <= depth) {
|
||||
id = i;
|
||||
}
|
||||
}
|
||||
|
||||
highlightNode( sentence, id );
|
||||
}
|
||||
|
||||
function alignOut( sentence, word, depth ) {
|
||||
if (current_depth < depth) {
|
||||
current_depth = depth;
|
||||
}
|
||||
else { return; }
|
||||
var id = 0;
|
||||
for(var i=1;i<nodeOut[sentence].size();i++ ) {
|
||||
if (nodeOut[sentence][i].start <= word && word <= nodeOut[sentence][i].end && nodeOut[sentence][i].depth <= depth) {
|
||||
id = i;
|
||||
}
|
||||
}
|
||||
var id, i;
|
||||
if (current_depth < depth) {
|
||||
current_depth = depth;
|
||||
}
|
||||
else { return; }
|
||||
id = 0;
|
||||
for(i=1;i<nodeOut[sentence].size();i++ ) {
|
||||
if (nodeOut[sentence][i].start <= word && word <= nodeOut[sentence][i].end && nodeOut[sentence][i].depth <= depth) {
|
||||
id = i;
|
||||
}
|
||||
}
|
||||
|
||||
highlightNode( sentence, id );
|
||||
highlightNode( sentence, id );
|
||||
}
|
||||
|
||||
function unAlign( sentence ) {
|
||||
if (current_depth == -1) { return; }
|
||||
current_depth = -1;
|
||||
lowlightAllNodes( sentence );
|
||||
if (current_depth == -1) { return; }
|
||||
current_depth = -1;
|
||||
lowlightAllNodes( sentence );
|
||||
}
|
||||
|
||||
function highlightNode( sentence, id ) {
|
||||
lowlightAllNodes( sentence );
|
||||
highlightSingleNode( sentence, id, 'yellow' );
|
||||
for(var i=0; i<nodeChildren[sentence][id].size(); i++) {
|
||||
var childId = nodeChildren[sentence][id][i];
|
||||
highlightSingleNode( sentence, childId, '#ffffa0');
|
||||
for(var j=0; j<nodeChildren[sentence][childId].size(); j++) {
|
||||
highlightSingleNode( sentence, nodeChildren[sentence][childId][j], '#ffffe0');
|
||||
}
|
||||
}
|
||||
var i;
|
||||
lowlightAllNodes( sentence );
|
||||
highlightSingleNode( sentence, id, 'yellow' );
|
||||
for(i=0; i<nodeChildren[sentence][id].size(); i++) {
|
||||
var childId = nodeChildren[sentence][id][i];
|
||||
var j;
|
||||
highlightSingleNode( sentence, childId, '#ffffa0');
|
||||
for(j=0; j<nodeChildren[sentence][childId].size(); j++) {
|
||||
highlightSingleNode( sentence, nodeChildren[sentence][childId][j], '#ffffe0');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function highlightSingleNode( sentence, id, color ) {
|
||||
for(var i=nodeIn[sentence][id].start;i<=nodeIn[sentence][id].end;i++) {
|
||||
for(var j=nodeIn[sentence][id].depth;j<=max_depth[sentence];j++) {
|
||||
var item = "in-" + sentence + "-" + i + "-" + j;
|
||||
if ($(item) != null) {
|
||||
$(item).setStyle({ backgroundColor: color, borderColor: 'red' });
|
||||
}
|
||||
}
|
||||
}
|
||||
//$("debug").innerHTML = "highlight: "+id+", of "+nodeOut[sentence].size()+"<br>";
|
||||
for(var i=nodeOut[sentence][id].start;i<=nodeOut[sentence][id].end;i++) {
|
||||
for(var j=nodeOut[sentence][id].depth;j<=max_depth[sentence];j++) {
|
||||
var item = "out-" + sentence + "-" + i + "-" + j;
|
||||
//$("debug").innerHTML += item;
|
||||
if ($(item) != null) {
|
||||
$(item).setStyle({ backgroundColor: color, borderColor: 'red' });
|
||||
}
|
||||
}
|
||||
}
|
||||
var i, j;
|
||||
for(i=nodeIn[sentence][id].start;i<=nodeIn[sentence][id].end;i++) {
|
||||
for(j=nodeIn[sentence][id].depth;j<=max_depth[sentence];j++) {
|
||||
var item = "in-" + sentence + "-" + i + "-" + j;
|
||||
if ($(item) != null) {
|
||||
$(item).setStyle({ backgroundColor: color, borderColor: 'red' });
|
||||
}
|
||||
}
|
||||
}
|
||||
//$("debug").innerHTML = "highlight: "+id+", of "+nodeOut[sentence].size()+"<br>";
|
||||
for(i=nodeOut[sentence][id].start;i<=nodeOut[sentence][id].end;i++) {
|
||||
for(j=nodeOut[sentence][id].depth;j<=max_depth[sentence];j++) {
|
||||
var item = "out-" + sentence + "-" + i + "-" + j;
|
||||
//$("debug").innerHTML += item;
|
||||
if ($(item) != null) {
|
||||
$(item).setStyle({ backgroundColor: color, borderColor: 'red' });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lowlightAllNodes( sentence ) {
|
||||
for(var i=0;i<span_count_in[sentence];i++) {
|
||||
for(var j=0;j<=max_depth[sentence];j++) {
|
||||
var item = "in-" + sentence + "-" + i + "-" + j;
|
||||
if ($(item) != null) {
|
||||
$(item).setStyle({ backgroundColor: 'white', borderColor: 'black' });
|
||||
}
|
||||
}
|
||||
}
|
||||
for(var i=0;i<span_count_out[sentence];i++) {
|
||||
for(var j=0;j<=max_depth[sentence];j++) {
|
||||
var item = "out-" + sentence + "-" + i + "-" + j;
|
||||
if ($(item) != null) {
|
||||
$(item).setStyle({ backgroundColor: 'white', borderColor: 'black' });
|
||||
}
|
||||
}
|
||||
}
|
||||
var i, j;
|
||||
for(i=0;i<span_count_in[sentence];i++) {
|
||||
for(j=0;j<=max_depth[sentence];j++) {
|
||||
var item = "in-" + sentence + "-" + i + "-" + j;
|
||||
if ($(item) != null) {
|
||||
$(item).setStyle({ backgroundColor: 'white', borderColor: 'black' });
|
||||
}
|
||||
}
|
||||
}
|
||||
for(i=0;i<span_count_out[sentence];i++) {
|
||||
for(j=0;j<=max_depth[sentence];j++) {
|
||||
var item = "out-" + sentence + "-" + i + "-" + j;
|
||||
if ($(item) != null) {
|
||||
$(item).setStyle({ backgroundColor: 'white', borderColor: 'black' });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
230
scripts/ems/web/javascripts/effects.js
vendored
230
scripts/ems/web/javascripts/effects.js
vendored
@ -13,13 +13,23 @@
|
||||
// returns self (or first argument) if not convertable
|
||||
String.prototype.parseColor = function() {
|
||||
var color = '#';
|
||||
var i;
|
||||
if (this.slice(0,4) == 'rgb(') {
|
||||
var cols = this.slice(4,this.length-1).split(',');
|
||||
var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);
|
||||
i=0;
|
||||
do {
|
||||
color += parseInt(cols[i]).toColorPart();
|
||||
} while (++i<3);
|
||||
} else {
|
||||
if (this.slice(0,1) == '#') {
|
||||
if (this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();
|
||||
if (this.length==7) color = this.toLowerCase();
|
||||
if (this.length==4) {
|
||||
for(i=1;i<4;i++) {
|
||||
color += (this.charAt(i) + this.charAt(i)).toLowerCase();
|
||||
}
|
||||
}
|
||||
if (this.length==7) {
|
||||
color = this.toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
return (color.length==7 ? color : (arguments[0] || this));
|
||||
@ -45,7 +55,9 @@ Element.collectTextNodesIgnoreClass = function(element, className) {
|
||||
Element.setContentZoom = function(element, percent) {
|
||||
element = $(element);
|
||||
element.setStyle({fontSize: (percent/100) + 'em'});
|
||||
if (Prototype.Browser.WebKit) window.scrollBy(0,0);
|
||||
if (Prototype.Browser.WebKit) {
|
||||
window.scrollBy(0,0);
|
||||
}
|
||||
return element;
|
||||
};
|
||||
|
||||
@ -78,7 +90,7 @@ var Effect = {
|
||||
return 1-pos;
|
||||
},
|
||||
flicker: function(pos) {
|
||||
var pos = ((-Math.cos(pos*Math.PI)/4) + .75) + Math.random()/4;
|
||||
pos = ((-Math.cos(pos*Math.PI)/4) + .75) + Math.random()/4;
|
||||
return pos > 1 ? 1 : pos;
|
||||
},
|
||||
wobble: function(pos) {
|
||||
@ -108,7 +120,9 @@ var Effect = {
|
||||
},
|
||||
tagifyText: function(element) {
|
||||
var tagifyStyle = 'position:relative';
|
||||
if (Prototype.Browser.IE) tagifyStyle += ';zoom:1';
|
||||
if (Prototype.Browser.IE) {
|
||||
tagifyStyle += ';zoom:1';
|
||||
}
|
||||
|
||||
element = $(element);
|
||||
$A(element.childNodes).each( function(child) {
|
||||
@ -127,10 +141,11 @@ var Effect = {
|
||||
var elements;
|
||||
if (((typeof element == 'object') ||
|
||||
Object.isFunction(element)) &&
|
||||
(element.length))
|
||||
(element.length)) {
|
||||
elements = element;
|
||||
else
|
||||
} else {
|
||||
elements = $(element).childNodes;
|
||||
}
|
||||
|
||||
var options = Object.extend({
|
||||
speed: 0.1,
|
||||
@ -150,7 +165,7 @@ var Effect = {
|
||||
toggle: function(element, effect, options) {
|
||||
element = $(element);
|
||||
effect = (effect || 'appear').toLowerCase();
|
||||
|
||||
|
||||
return Effect[ Effect.PAIRS[ effect ][ element.visible() ? 1 : 0 ] ](element, Object.extend({
|
||||
queue: { position:'end', scope:(element.id || 'global'), limit: 1 }
|
||||
}, options || {}));
|
||||
@ -178,7 +193,7 @@ Effect.ScopedQueue = Class.create(Enumerable, {
|
||||
switch(position) {
|
||||
case 'front':
|
||||
// move unstarted effects after this effect
|
||||
this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) {
|
||||
this.effects.findAll(function(e){ return e.state=='idle'; }).each( function(e) {
|
||||
e.startOn += effect.finishOn;
|
||||
e.finishOn += effect.finishOn;
|
||||
});
|
||||
@ -195,14 +210,16 @@ Effect.ScopedQueue = Class.create(Enumerable, {
|
||||
effect.startOn += timestamp;
|
||||
effect.finishOn += timestamp;
|
||||
|
||||
if (!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit))
|
||||
if (!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit)) {
|
||||
this.effects.push(effect);
|
||||
}
|
||||
|
||||
if (!this.interval)
|
||||
if (!this.interval) {
|
||||
this.interval = setInterval(this.loop.bind(this), 15);
|
||||
}
|
||||
},
|
||||
remove: function(effect) {
|
||||
this.effects = this.effects.reject(function(e) { return e==effect });
|
||||
this.effects = this.effects.reject(function(e) { return e==effect; });
|
||||
if (this.effects.length == 0) {
|
||||
clearInterval(this.interval);
|
||||
this.interval = null;
|
||||
@ -210,15 +227,19 @@ Effect.ScopedQueue = Class.create(Enumerable, {
|
||||
},
|
||||
loop: function() {
|
||||
var timePos = new Date().getTime();
|
||||
for(var i=0, len=this.effects.length;i<len;i++)
|
||||
var i;
|
||||
for(i=0, len=this.effects.length;i<len;i++) {
|
||||
this.effects[i] && this.effects[i].loop(timePos);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Effect.Queues = {
|
||||
instances: $H(),
|
||||
get: function(queueName) {
|
||||
if (!Object.isString(queueName)) return queueName;
|
||||
if (!Object.isString(queueName)) {
|
||||
return queueName;
|
||||
}
|
||||
|
||||
return this.instances.get(queueName) ||
|
||||
this.instances.set(queueName, new Effect.ScopedQueue());
|
||||
@ -229,7 +250,9 @@ Effect.Queue = Effect.Queues.get('global');
|
||||
Effect.Base = Class.create({
|
||||
position: null,
|
||||
start: function(options) {
|
||||
if (options && options.transition === false) options.transition = Effect.Transitions.linear;
|
||||
if (options && options.transition === false) {
|
||||
options.transition = Effect.Transitions.linear;
|
||||
}
|
||||
this.options = Object.extend(Object.extend({ },Effect.DefaultOptions), options || { });
|
||||
this.currentFrame = 0;
|
||||
this.state = 'idle';
|
||||
@ -241,33 +264,40 @@ Effect.Base = Class.create({
|
||||
|
||||
this.render = (function() {
|
||||
function dispatch(effect, eventName) {
|
||||
if (effect.options[eventName + 'Internal'])
|
||||
if (effect.options[eventName + 'Internal']) {
|
||||
effect.options[eventName + 'Internal'](effect);
|
||||
if (effect.options[eventName])
|
||||
}
|
||||
if (effect.options[eventName]) {
|
||||
effect.options[eventName](effect);
|
||||
}
|
||||
}
|
||||
|
||||
return function(pos) {
|
||||
if (this.state === "idle") {
|
||||
this.state = "running";
|
||||
dispatch(this, 'beforeSetup');
|
||||
if (this.setup) this.setup();
|
||||
if (this.setup) {
|
||||
this.setup();
|
||||
}
|
||||
dispatch(this, 'afterSetup');
|
||||
}
|
||||
if (this.state === "running") {
|
||||
pos = (this.options.transition(pos) * this.fromToDelta) + this.options.from;
|
||||
this.position = pos;
|
||||
dispatch(this, 'beforeUpdate');
|
||||
if (this.update) this.update(pos);
|
||||
if (this.update) {
|
||||
this.update(pos);
|
||||
}
|
||||
dispatch(this, 'afterUpdate');
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
this.event('beforeStart');
|
||||
if (!this.options.sync)
|
||||
if (!this.options.sync) {
|
||||
Effect.Queues.get(Object.isString(this.options.queue) ?
|
||||
'global' : this.options.queue.scope).add(this);
|
||||
}
|
||||
},
|
||||
loop: function(timePos) {
|
||||
if (timePos >= this.startOn) {
|
||||
@ -275,7 +305,9 @@ Effect.Base = Class.create({
|
||||
this.render(1.0);
|
||||
this.cancel();
|
||||
this.event('beforeFinish');
|
||||
if (this.finish) this.finish();
|
||||
if (this.finish) {
|
||||
this.finish();
|
||||
}
|
||||
this.event('afterFinish');
|
||||
return;
|
||||
}
|
||||
@ -288,19 +320,27 @@ Effect.Base = Class.create({
|
||||
}
|
||||
},
|
||||
cancel: function() {
|
||||
if (!this.options.sync)
|
||||
if (!this.options.sync) {
|
||||
Effect.Queues.get(Object.isString(this.options.queue) ?
|
||||
'global' : this.options.queue.scope).remove(this);
|
||||
}
|
||||
this.state = 'finished';
|
||||
},
|
||||
event: function(eventName) {
|
||||
if (this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this);
|
||||
if (this.options[eventName]) this.options[eventName](this);
|
||||
if (this.options[eventName + 'Internal']) {
|
||||
this.options[eventName + 'Internal'](this);
|
||||
}
|
||||
if (this.options[eventName]) {
|
||||
this.options[eventName](this);
|
||||
}
|
||||
},
|
||||
inspect: function() {
|
||||
var data = $H();
|
||||
for(property in this)
|
||||
if (!Object.isFunction(this[property])) data.set(property, this[property]);
|
||||
for(property in this) {
|
||||
if (!Object.isFunction(this[property])) {
|
||||
data.set(property, this[property]);
|
||||
}
|
||||
}
|
||||
return '#<Effect:' + data.inspect() + ',options:' + $H(this.options).inspect() + '>';
|
||||
}
|
||||
});
|
||||
@ -318,7 +358,9 @@ Effect.Parallel = Class.create(Effect.Base, {
|
||||
effect.render(1.0);
|
||||
effect.cancel();
|
||||
effect.event('beforeFinish');
|
||||
if (effect.finish) effect.finish(position);
|
||||
if (effect.finish) {
|
||||
effect.finish(position);
|
||||
}
|
||||
effect.event('afterFinish');
|
||||
});
|
||||
}
|
||||
@ -331,7 +373,7 @@ Effect.Tween = Class.create(Effect.Base, {
|
||||
options = args.length == 5 ? args[3] : null;
|
||||
this.method = Object.isFunction(method) ? method.bind(object) :
|
||||
Object.isFunction(object[method]) ? object[method].bind(object) :
|
||||
function(value) { object[method] = value };
|
||||
function(value) { object[method] = value; };
|
||||
this.start(Object.extend({ from: from, to: to }, options || { }));
|
||||
},
|
||||
update: function(position) {
|
||||
@ -348,12 +390,16 @@ Effect.Event = Class.create(Effect.Base, {
|
||||
|
||||
Effect.Opacity = Class.create(Effect.Base, {
|
||||
initialize: function(element) {
|
||||
var options;
|
||||
this.element = $(element);
|
||||
if (!this.element) throw(Effect._elementDoesNotExistError);
|
||||
if (!this.element) {
|
||||
throw(Effect._elementDoesNotExistError);
|
||||
}
|
||||
// make this work on IE on elements without 'layout'
|
||||
if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout))
|
||||
if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout)) {
|
||||
this.element.setStyle({zoom: 1});
|
||||
var options = Object.extend({
|
||||
}
|
||||
options = Object.extend({
|
||||
from: this.element.getOpacity() || 0.0,
|
||||
to: 1.0
|
||||
}, arguments[1] || { });
|
||||
@ -366,9 +412,12 @@ Effect.Opacity = Class.create(Effect.Base, {
|
||||
|
||||
Effect.Move = Class.create(Effect.Base, {
|
||||
initialize: function(element) {
|
||||
var options;
|
||||
this.element = $(element);
|
||||
if (!this.element) throw(Effect._elementDoesNotExistError);
|
||||
var options = Object.extend({
|
||||
if (!this.element) {
|
||||
throw(Effect._elementDoesNotExistError);
|
||||
}
|
||||
options = Object.extend({
|
||||
x: 0,
|
||||
y: 0,
|
||||
mode: 'relative'
|
||||
@ -400,9 +449,12 @@ Effect.MoveBy = function(element, toTop, toLeft) {
|
||||
|
||||
Effect.Scale = Class.create(Effect.Base, {
|
||||
initialize: function(element, percent) {
|
||||
var options;
|
||||
this.element = $(element);
|
||||
if (!this.element) throw(Effect._elementDoesNotExistError);
|
||||
var options = Object.extend({
|
||||
if (!this.element) {
|
||||
throw(Effect._elementDoesNotExistError);
|
||||
}
|
||||
options = Object.extend({
|
||||
scaleX: true,
|
||||
scaleY: true,
|
||||
scaleContent: true,
|
||||
@ -436,36 +488,54 @@ Effect.Scale = Class.create(Effect.Base, {
|
||||
this.factor = (this.options.scaleTo - this.options.scaleFrom)/100;
|
||||
|
||||
this.dims = null;
|
||||
if (this.options.scaleMode=='box')
|
||||
if (this.options.scaleMode=='box') {
|
||||
this.dims = [this.element.offsetHeight, this.element.offsetWidth];
|
||||
if (/^content/.test(this.options.scaleMode))
|
||||
}
|
||||
if (/^content/.test(this.options.scaleMode)) {
|
||||
this.dims = [this.element.scrollHeight, this.element.scrollWidth];
|
||||
if (!this.dims)
|
||||
}
|
||||
if (!this.dims) {
|
||||
this.dims = [this.options.scaleMode.originalHeight,
|
||||
this.options.scaleMode.originalWidth];
|
||||
}
|
||||
},
|
||||
update: function(position) {
|
||||
var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position);
|
||||
if (this.options.scaleContent && this.fontSize)
|
||||
if (this.options.scaleContent && this.fontSize) {
|
||||
this.element.setStyle({fontSize: this.fontSize * currentScale + this.fontSizeType });
|
||||
}
|
||||
this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale);
|
||||
},
|
||||
finish: function(position) {
|
||||
if (this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
|
||||
if (this.restoreAfterFinish) {
|
||||
this.element.setStyle(this.originalStyle);
|
||||
}
|
||||
},
|
||||
setDimensions: function(height, width) {
|
||||
var d = { };
|
||||
if (this.options.scaleX) d.width = width.round() + 'px';
|
||||
if (this.options.scaleY) d.height = height.round() + 'px';
|
||||
if (this.options.scaleX) {
|
||||
d.width = width.round() + 'px';
|
||||
}
|
||||
if (this.options.scaleY) {
|
||||
d.height = height.round() + 'px';
|
||||
}
|
||||
if (this.options.scaleFromCenter) {
|
||||
var topd = (height - this.dims[0])/2;
|
||||
var leftd = (width - this.dims[1])/2;
|
||||
if (this.elementPositioning == 'absolute') {
|
||||
if (this.options.scaleY) d.top = this.originalTop-topd + 'px';
|
||||
if (this.options.scaleX) d.left = this.originalLeft-leftd + 'px';
|
||||
if (this.options.scaleY) {
|
||||
d.top = this.originalTop-topd + 'px';
|
||||
}
|
||||
if (this.options.scaleX) {
|
||||
d.left = this.originalLeft-leftd + 'px';
|
||||
}
|
||||
} else {
|
||||
if (this.options.scaleY) d.top = -topd + 'px';
|
||||
if (this.options.scaleX) d.left = -leftd + 'px';
|
||||
if (this.options.scaleY) {
|
||||
d.top = -topd + 'px';
|
||||
}
|
||||
if (this.options.scaleX) {
|
||||
d.left = -leftd + 'px';
|
||||
}
|
||||
}
|
||||
}
|
||||
this.element.setStyle(d);
|
||||
@ -474,27 +544,35 @@ Effect.Scale = Class.create(Effect.Base, {
|
||||
|
||||
Effect.Highlight = Class.create(Effect.Base, {
|
||||
initialize: function(element) {
|
||||
var options;
|
||||
this.element = $(element);
|
||||
if (!this.element) throw(Effect._elementDoesNotExistError);
|
||||
var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || { });
|
||||
if (!this.element) {
|
||||
throw(Effect._elementDoesNotExistError);
|
||||
}
|
||||
options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || { });
|
||||
this.start(options);
|
||||
},
|
||||
setup: function() {
|
||||
// Prevent executing on elements not in the layout flow
|
||||
if (this.element.getStyle('display')=='none') { this.cancel(); return; }
|
||||
if (this.element.getStyle('display')=='none') {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
// Disable background image during the effect
|
||||
this.oldStyle = { };
|
||||
if (!this.options.keepBackgroundImage) {
|
||||
this.oldStyle.backgroundImage = this.element.getStyle('background-image');
|
||||
this.element.setStyle({backgroundImage: 'none'});
|
||||
}
|
||||
if (!this.options.endcolor)
|
||||
if (!this.options.endcolor) {
|
||||
this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff');
|
||||
if (!this.options.restorecolor)
|
||||
}
|
||||
if (!this.options.restorecolor) {
|
||||
this.options.restorecolor = this.element.getStyle('background-color');
|
||||
}
|
||||
// init color calculations
|
||||
this._base = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this));
|
||||
this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this));
|
||||
this._base = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16); }.bind(this));
|
||||
this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i]; }.bind(this));
|
||||
},
|
||||
update: function(position) {
|
||||
this.element.setStyle({backgroundColor: $R(0,2).inject('#',function(m,v,i){
|
||||
@ -512,7 +590,9 @@ Effect.ScrollTo = function(element) {
|
||||
scrollOffsets = document.viewport.getScrollOffsets(),
|
||||
elementOffsets = $(element).cumulativeOffset();
|
||||
|
||||
if (options.offset) elementOffsets[1] += options.offset;
|
||||
if (options.offset) {
|
||||
elementOffsets[1] += options.offset;
|
||||
}
|
||||
|
||||
return new Effect.Tween(null,
|
||||
scrollOffsets.top,
|
||||
@ -531,7 +611,9 @@ Effect.Fade = function(element) {
|
||||
from: element.getOpacity() || 1.0,
|
||||
to: 0.0,
|
||||
afterFinishInternal: function(effect) {
|
||||
if (effect.options.to!=0) return;
|
||||
if (effect.options.to!=0) {
|
||||
return;
|
||||
}
|
||||
effect.element.hide().setStyle({opacity: oldOpacity});
|
||||
}
|
||||
}, arguments[1] || { });
|
||||
@ -692,7 +774,9 @@ Effect.SlideDown = function(element) {
|
||||
afterSetup: function(effect) {
|
||||
effect.element.makePositioned();
|
||||
effect.element.down().makePositioned();
|
||||
if (window.opera) effect.element.setStyle({top: ''});
|
||||
if (window.opera) {
|
||||
effect.element.setStyle({top: ''});
|
||||
}
|
||||
effect.element.makeClipping().setStyle({height: '0px'}).show();
|
||||
},
|
||||
afterUpdateInternal: function(effect) {
|
||||
@ -720,7 +804,9 @@ Effect.SlideUp = function(element) {
|
||||
afterSetup: function(effect) {
|
||||
effect.element.makePositioned();
|
||||
effect.element.down().makePositioned();
|
||||
if (window.opera) effect.element.setStyle({top: ''});
|
||||
if (window.opera) {
|
||||
effect.element.setStyle({top: ''});
|
||||
}
|
||||
effect.element.makeClipping().show();
|
||||
},
|
||||
afterUpdateInternal: function(effect) {
|
||||
@ -914,17 +1000,21 @@ Effect.Fold = function(element) {
|
||||
|
||||
Effect.Morph = Class.create(Effect.Base, {
|
||||
initialize: function(element) {
|
||||
var options;
|
||||
this.element = $(element);
|
||||
if (!this.element) throw(Effect._elementDoesNotExistError);
|
||||
var options = Object.extend({
|
||||
if (!this.element) {
|
||||
throw(Effect._elementDoesNotExistError);
|
||||
}
|
||||
options = Object.extend({
|
||||
style: { }
|
||||
}, arguments[1] || { });
|
||||
|
||||
if (!Object.isString(options.style)) this.style = $H(options.style);
|
||||
else {
|
||||
if (options.style.include(':'))
|
||||
if (!Object.isString(options.style)) {
|
||||
this.style = $H(options.style);
|
||||
} else {
|
||||
if (options.style.include(':')) {
|
||||
this.style = options.style.parseStyle();
|
||||
else {
|
||||
} else {
|
||||
this.element.addClassName(options.style);
|
||||
this.style = $H(this.element.getStyles());
|
||||
this.element.removeClassName(options.style);
|
||||
@ -945,7 +1035,9 @@ Effect.Morph = Class.create(Effect.Base, {
|
||||
|
||||
setup: function(){
|
||||
function parseColor(color){
|
||||
if (!color || ['rgba(0, 0, 0, 0)','transparent'].include(color)) color = '#ffffff';
|
||||
if (!color || ['rgba(0, 0, 0, 0)','transparent'].include(color)) {
|
||||
color = '#ffffff';
|
||||
}
|
||||
color = color.parseColor();
|
||||
return $R(0,2).map(function(i){
|
||||
return parseInt( color.slice(i*2+1,i*2+3), 16 );
|
||||
@ -959,8 +1051,9 @@ Effect.Morph = Class.create(Effect.Base, {
|
||||
unit = 'color';
|
||||
} else if (property == 'opacity') {
|
||||
value = parseFloat(value);
|
||||
if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout))
|
||||
if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout)) {
|
||||
this.element.setStyle({zoom: 1});
|
||||
}
|
||||
} else if (Element.CSS_LENGTH.test(value)) {
|
||||
var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/);
|
||||
value = parseFloat(components[1]);
|
||||
@ -986,7 +1079,7 @@ Effect.Morph = Class.create(Effect.Base, {
|
||||
},
|
||||
update: function(position) {
|
||||
var style = { }, transform, i = this.transforms.length;
|
||||
while(i--)
|
||||
while(i--) {
|
||||
style[(transform = this.transforms[i]).style] =
|
||||
transform.unit=='color' ? '#'+
|
||||
(Math.round(transform.originalValue[0]+
|
||||
@ -998,6 +1091,7 @@ Effect.Morph = Class.create(Effect.Base, {
|
||||
(transform.originalValue +
|
||||
(transform.targetValue - transform.originalValue) * position).toFixed(3) +
|
||||
(transform.unit === null ? '' : transform.unit);
|
||||
}
|
||||
this.element.setStyle(style, true);
|
||||
}
|
||||
});
|
||||
@ -1120,4 +1214,4 @@ $w('getInlineOpacity forceRerendering setContentZoom collectTextNodes collectTex
|
||||
function(f) { Effect.Methods[f] = Element[f]; }
|
||||
);
|
||||
|
||||
Element.addMethods(Effect.Methods);
|
||||
Element.addMethods(Effect.Methods);
|
||||
|
@ -13,13 +13,23 @@
|
||||
// returns self (or first argument) if not convertable
|
||||
String.prototype.parseColor = function() {
|
||||
var color = '#';
|
||||
var i;
|
||||
if (this.slice(0,4) == 'rgb(') {
|
||||
var cols = this.slice(4,this.length-1).split(',');
|
||||
var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);
|
||||
i=0;
|
||||
do {
|
||||
color += parseInt(cols[i]).toColorPart();
|
||||
} while (++i<3);
|
||||
} else {
|
||||
if (this.slice(0,1) == '#') {
|
||||
if (this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();
|
||||
if (this.length==7) color = this.toLowerCase();
|
||||
if (this.length==4) {
|
||||
for(i=1;i<4;i++) {
|
||||
color += (this.charAt(i) + this.charAt(i)).toLowerCase();
|
||||
}
|
||||
}
|
||||
if (this.length==7) {
|
||||
color = this.toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
return (color.length==7 ? color : (arguments[0] || this));
|
||||
@ -45,7 +55,9 @@ Element.collectTextNodesIgnoreClass = function(element, className) {
|
||||
Element.setContentZoom = function(element, percent) {
|
||||
element = $(element);
|
||||
element.setStyle({fontSize: (percent/100) + 'em'});
|
||||
if (Prototype.Browser.WebKit) window.scrollBy(0,0);
|
||||
if (Prototype.Browser.WebKit) {
|
||||
window.scrollBy(0,0);
|
||||
}
|
||||
return element;
|
||||
};
|
||||
|
||||
@ -78,7 +90,7 @@ var Effect = {
|
||||
return 1-pos;
|
||||
},
|
||||
flicker: function(pos) {
|
||||
var pos = ((-Math.cos(pos*Math.PI)/4) + .75) + Math.random()/4;
|
||||
pos = ((-Math.cos(pos*Math.PI)/4) + .75) + Math.random()/4;
|
||||
return pos > 1 ? 1 : pos;
|
||||
},
|
||||
wobble: function(pos) {
|
||||
@ -108,7 +120,9 @@ var Effect = {
|
||||
},
|
||||
tagifyText: function(element) {
|
||||
var tagifyStyle = 'position:relative';
|
||||
if (Prototype.Browser.IE) tagifyStyle += ';zoom:1';
|
||||
if (Prototype.Browser.IE) {
|
||||
tagifyStyle += ';zoom:1';
|
||||
}
|
||||
|
||||
element = $(element);
|
||||
$A(element.childNodes).each( function(child) {
|
||||
@ -127,10 +141,11 @@ var Effect = {
|
||||
var elements;
|
||||
if (((typeof element == 'object') ||
|
||||
Object.isFunction(element)) &&
|
||||
(element.length))
|
||||
(element.length)) {
|
||||
elements = element;
|
||||
else
|
||||
} else {
|
||||
elements = $(element).childNodes;
|
||||
}
|
||||
|
||||
var options = Object.extend({
|
||||
speed: 0.1,
|
||||
@ -150,7 +165,7 @@ var Effect = {
|
||||
toggle: function(element, effect, options) {
|
||||
element = $(element);
|
||||
effect = (effect || 'appear').toLowerCase();
|
||||
|
||||
|
||||
return Effect[ Effect.PAIRS[ effect ][ element.visible() ? 1 : 0 ] ](element, Object.extend({
|
||||
queue: { position:'end', scope:(element.id || 'global'), limit: 1 }
|
||||
}, options || {}));
|
||||
@ -178,7 +193,7 @@ Effect.ScopedQueue = Class.create(Enumerable, {
|
||||
switch(position) {
|
||||
case 'front':
|
||||
// move unstarted effects after this effect
|
||||
this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) {
|
||||
this.effects.findAll(function(e){ return e.state=='idle'; }).each( function(e) {
|
||||
e.startOn += effect.finishOn;
|
||||
e.finishOn += effect.finishOn;
|
||||
});
|
||||
@ -195,14 +210,16 @@ Effect.ScopedQueue = Class.create(Enumerable, {
|
||||
effect.startOn += timestamp;
|
||||
effect.finishOn += timestamp;
|
||||
|
||||
if (!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit))
|
||||
if (!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit)) {
|
||||
this.effects.push(effect);
|
||||
}
|
||||
|
||||
if (!this.interval)
|
||||
if (!this.interval) {
|
||||
this.interval = setInterval(this.loop.bind(this), 15);
|
||||
}
|
||||
},
|
||||
remove: function(effect) {
|
||||
this.effects = this.effects.reject(function(e) { return e==effect });
|
||||
this.effects = this.effects.reject(function(e) { return e==effect; });
|
||||
if (this.effects.length == 0) {
|
||||
clearInterval(this.interval);
|
||||
this.interval = null;
|
||||
@ -210,15 +227,19 @@ Effect.ScopedQueue = Class.create(Enumerable, {
|
||||
},
|
||||
loop: function() {
|
||||
var timePos = new Date().getTime();
|
||||
for(var i=0, len=this.effects.length;i<len;i++)
|
||||
var i;
|
||||
for(i=0, len=this.effects.length;i<len;i++) {
|
||||
this.effects[i] && this.effects[i].loop(timePos);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Effect.Queues = {
|
||||
instances: $H(),
|
||||
get: function(queueName) {
|
||||
if (!Object.isString(queueName)) return queueName;
|
||||
if (!Object.isString(queueName)) {
|
||||
return queueName;
|
||||
}
|
||||
|
||||
return this.instances.get(queueName) ||
|
||||
this.instances.set(queueName, new Effect.ScopedQueue());
|
||||
@ -229,7 +250,9 @@ Effect.Queue = Effect.Queues.get('global');
|
||||
Effect.Base = Class.create({
|
||||
position: null,
|
||||
start: function(options) {
|
||||
if (options && options.transition === false) options.transition = Effect.Transitions.linear;
|
||||
if (options && options.transition === false) {
|
||||
options.transition = Effect.Transitions.linear;
|
||||
}
|
||||
this.options = Object.extend(Object.extend({ },Effect.DefaultOptions), options || { });
|
||||
this.currentFrame = 0;
|
||||
this.state = 'idle';
|
||||
@ -241,33 +264,40 @@ Effect.Base = Class.create({
|
||||
|
||||
this.render = (function() {
|
||||
function dispatch(effect, eventName) {
|
||||
if (effect.options[eventName + 'Internal'])
|
||||
if (effect.options[eventName + 'Internal']) {
|
||||
effect.options[eventName + 'Internal'](effect);
|
||||
if (effect.options[eventName])
|
||||
}
|
||||
if (effect.options[eventName]) {
|
||||
effect.options[eventName](effect);
|
||||
}
|
||||
}
|
||||
|
||||
return function(pos) {
|
||||
if (this.state === "idle") {
|
||||
this.state = "running";
|
||||
dispatch(this, 'beforeSetup');
|
||||
if (this.setup) this.setup();
|
||||
if (this.setup) {
|
||||
this.setup();
|
||||
}
|
||||
dispatch(this, 'afterSetup');
|
||||
}
|
||||
if (this.state === "running") {
|
||||
pos = (this.options.transition(pos) * this.fromToDelta) + this.options.from;
|
||||
this.position = pos;
|
||||
dispatch(this, 'beforeUpdate');
|
||||
if (this.update) this.update(pos);
|
||||
if (this.update) {
|
||||
this.update(pos);
|
||||
}
|
||||
dispatch(this, 'afterUpdate');
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
this.event('beforeStart');
|
||||
if (!this.options.sync)
|
||||
if (!this.options.sync) {
|
||||
Effect.Queues.get(Object.isString(this.options.queue) ?
|
||||
'global' : this.options.queue.scope).add(this);
|
||||
}
|
||||
},
|
||||
loop: function(timePos) {
|
||||
if (timePos >= this.startOn) {
|
||||
@ -275,7 +305,9 @@ Effect.Base = Class.create({
|
||||
this.render(1.0);
|
||||
this.cancel();
|
||||
this.event('beforeFinish');
|
||||
if (this.finish) this.finish();
|
||||
if (this.finish) {
|
||||
this.finish();
|
||||
}
|
||||
this.event('afterFinish');
|
||||
return;
|
||||
}
|
||||
@ -288,19 +320,27 @@ Effect.Base = Class.create({
|
||||
}
|
||||
},
|
||||
cancel: function() {
|
||||
if (!this.options.sync)
|
||||
if (!this.options.sync) {
|
||||
Effect.Queues.get(Object.isString(this.options.queue) ?
|
||||
'global' : this.options.queue.scope).remove(this);
|
||||
}
|
||||
this.state = 'finished';
|
||||
},
|
||||
event: function(eventName) {
|
||||
if (this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this);
|
||||
if (this.options[eventName]) this.options[eventName](this);
|
||||
if (this.options[eventName + 'Internal']) {
|
||||
this.options[eventName + 'Internal'](this);
|
||||
}
|
||||
if (this.options[eventName]) {
|
||||
this.options[eventName](this);
|
||||
}
|
||||
},
|
||||
inspect: function() {
|
||||
var data = $H();
|
||||
for(property in this)
|
||||
if (!Object.isFunction(this[property])) data.set(property, this[property]);
|
||||
for(property in this) {
|
||||
if (!Object.isFunction(this[property])) {
|
||||
data.set(property, this[property]);
|
||||
}
|
||||
}
|
||||
return '#<Effect:' + data.inspect() + ',options:' + $H(this.options).inspect() + '>';
|
||||
}
|
||||
});
|
||||
@ -318,7 +358,9 @@ Effect.Parallel = Class.create(Effect.Base, {
|
||||
effect.render(1.0);
|
||||
effect.cancel();
|
||||
effect.event('beforeFinish');
|
||||
if (effect.finish) effect.finish(position);
|
||||
if (effect.finish) {
|
||||
effect.finish(position);
|
||||
}
|
||||
effect.event('afterFinish');
|
||||
});
|
||||
}
|
||||
@ -331,7 +373,7 @@ Effect.Tween = Class.create(Effect.Base, {
|
||||
options = args.length == 5 ? args[3] : null;
|
||||
this.method = Object.isFunction(method) ? method.bind(object) :
|
||||
Object.isFunction(object[method]) ? object[method].bind(object) :
|
||||
function(value) { object[method] = value };
|
||||
function(value) { object[method] = value; };
|
||||
this.start(Object.extend({ from: from, to: to }, options || { }));
|
||||
},
|
||||
update: function(position) {
|
||||
@ -348,12 +390,16 @@ Effect.Event = Class.create(Effect.Base, {
|
||||
|
||||
Effect.Opacity = Class.create(Effect.Base, {
|
||||
initialize: function(element) {
|
||||
var options;
|
||||
this.element = $(element);
|
||||
if (!this.element) throw(Effect._elementDoesNotExistError);
|
||||
if (!this.element) {
|
||||
throw(Effect._elementDoesNotExistError);
|
||||
}
|
||||
// make this work on IE on elements without 'layout'
|
||||
if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout))
|
||||
if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout)) {
|
||||
this.element.setStyle({zoom: 1});
|
||||
var options = Object.extend({
|
||||
}
|
||||
options = Object.extend({
|
||||
from: this.element.getOpacity() || 0.0,
|
||||
to: 1.0
|
||||
}, arguments[1] || { });
|
||||
@ -366,9 +412,12 @@ Effect.Opacity = Class.create(Effect.Base, {
|
||||
|
||||
Effect.Move = Class.create(Effect.Base, {
|
||||
initialize: function(element) {
|
||||
var options;
|
||||
this.element = $(element);
|
||||
if (!this.element) throw(Effect._elementDoesNotExistError);
|
||||
var options = Object.extend({
|
||||
if (!this.element) {
|
||||
throw(Effect._elementDoesNotExistError);
|
||||
}
|
||||
options = Object.extend({
|
||||
x: 0,
|
||||
y: 0,
|
||||
mode: 'relative'
|
||||
@ -400,9 +449,12 @@ Effect.MoveBy = function(element, toTop, toLeft) {
|
||||
|
||||
Effect.Scale = Class.create(Effect.Base, {
|
||||
initialize: function(element, percent) {
|
||||
var options;
|
||||
this.element = $(element);
|
||||
if (!this.element) throw(Effect._elementDoesNotExistError);
|
||||
var options = Object.extend({
|
||||
if (!this.element) {
|
||||
throw(Effect._elementDoesNotExistError);
|
||||
}
|
||||
options = Object.extend({
|
||||
scaleX: true,
|
||||
scaleY: true,
|
||||
scaleContent: true,
|
||||
@ -436,36 +488,54 @@ Effect.Scale = Class.create(Effect.Base, {
|
||||
this.factor = (this.options.scaleTo - this.options.scaleFrom)/100;
|
||||
|
||||
this.dims = null;
|
||||
if (this.options.scaleMode=='box')
|
||||
if (this.options.scaleMode=='box') {
|
||||
this.dims = [this.element.offsetHeight, this.element.offsetWidth];
|
||||
if (/^content/.test(this.options.scaleMode))
|
||||
}
|
||||
if (/^content/.test(this.options.scaleMode)) {
|
||||
this.dims = [this.element.scrollHeight, this.element.scrollWidth];
|
||||
if (!this.dims)
|
||||
}
|
||||
if (!this.dims) {
|
||||
this.dims = [this.options.scaleMode.originalHeight,
|
||||
this.options.scaleMode.originalWidth];
|
||||
}
|
||||
},
|
||||
update: function(position) {
|
||||
var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position);
|
||||
if (this.options.scaleContent && this.fontSize)
|
||||
if (this.options.scaleContent && this.fontSize) {
|
||||
this.element.setStyle({fontSize: this.fontSize * currentScale + this.fontSizeType });
|
||||
}
|
||||
this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale);
|
||||
},
|
||||
finish: function(position) {
|
||||
if (this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
|
||||
if (this.restoreAfterFinish) {
|
||||
this.element.setStyle(this.originalStyle);
|
||||
}
|
||||
},
|
||||
setDimensions: function(height, width) {
|
||||
var d = { };
|
||||
if (this.options.scaleX) d.width = width.round() + 'px';
|
||||
if (this.options.scaleY) d.height = height.round() + 'px';
|
||||
if (this.options.scaleX) {
|
||||
d.width = width.round() + 'px';
|
||||
}
|
||||
if (this.options.scaleY) {
|
||||
d.height = height.round() + 'px';
|
||||
}
|
||||
if (this.options.scaleFromCenter) {
|
||||
var topd = (height - this.dims[0])/2;
|
||||
var leftd = (width - this.dims[1])/2;
|
||||
if (this.elementPositioning == 'absolute') {
|
||||
if (this.options.scaleY) d.top = this.originalTop-topd + 'px';
|
||||
if (this.options.scaleX) d.left = this.originalLeft-leftd + 'px';
|
||||
if (this.options.scaleY) {
|
||||
d.top = this.originalTop-topd + 'px';
|
||||
}
|
||||
if (this.options.scaleX) {
|
||||
d.left = this.originalLeft-leftd + 'px';
|
||||
}
|
||||
} else {
|
||||
if (this.options.scaleY) d.top = -topd + 'px';
|
||||
if (this.options.scaleX) d.left = -leftd + 'px';
|
||||
if (this.options.scaleY) {
|
||||
d.top = -topd + 'px';
|
||||
}
|
||||
if (this.options.scaleX) {
|
||||
d.left = -leftd + 'px';
|
||||
}
|
||||
}
|
||||
}
|
||||
this.element.setStyle(d);
|
||||
@ -474,27 +544,35 @@ Effect.Scale = Class.create(Effect.Base, {
|
||||
|
||||
Effect.Highlight = Class.create(Effect.Base, {
|
||||
initialize: function(element) {
|
||||
var options;
|
||||
this.element = $(element);
|
||||
if (!this.element) throw(Effect._elementDoesNotExistError);
|
||||
var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || { });
|
||||
if (!this.element) {
|
||||
throw(Effect._elementDoesNotExistError);
|
||||
}
|
||||
options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || { });
|
||||
this.start(options);
|
||||
},
|
||||
setup: function() {
|
||||
// Prevent executing on elements not in the layout flow
|
||||
if (this.element.getStyle('display')=='none') { this.cancel(); return; }
|
||||
if (this.element.getStyle('display')=='none') {
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
// Disable background image during the effect
|
||||
this.oldStyle = { };
|
||||
if (!this.options.keepBackgroundImage) {
|
||||
this.oldStyle.backgroundImage = this.element.getStyle('background-image');
|
||||
this.element.setStyle({backgroundImage: 'none'});
|
||||
}
|
||||
if (!this.options.endcolor)
|
||||
if (!this.options.endcolor) {
|
||||
this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff');
|
||||
if (!this.options.restorecolor)
|
||||
}
|
||||
if (!this.options.restorecolor) {
|
||||
this.options.restorecolor = this.element.getStyle('background-color');
|
||||
}
|
||||
// init color calculations
|
||||
this._base = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this));
|
||||
this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this));
|
||||
this._base = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16); }.bind(this));
|
||||
this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i]; }.bind(this));
|
||||
},
|
||||
update: function(position) {
|
||||
this.element.setStyle({backgroundColor: $R(0,2).inject('#',function(m,v,i){
|
||||
@ -512,7 +590,9 @@ Effect.ScrollTo = function(element) {
|
||||
scrollOffsets = document.viewport.getScrollOffsets(),
|
||||
elementOffsets = $(element).cumulativeOffset();
|
||||
|
||||
if (options.offset) elementOffsets[1] += options.offset;
|
||||
if (options.offset) {
|
||||
elementOffsets[1] += options.offset;
|
||||
}
|
||||
|
||||
return new Effect.Tween(null,
|
||||
scrollOffsets.top,
|
||||
@ -531,7 +611,9 @@ Effect.Fade = function(element) {
|
||||
from: element.getOpacity() || 1.0,
|
||||
to: 0.0,
|
||||
afterFinishInternal: function(effect) {
|
||||
if (effect.options.to!=0) return;
|
||||
if (effect.options.to!=0) {
|
||||
return;
|
||||
}
|
||||
effect.element.hide().setStyle({opacity: oldOpacity});
|
||||
}
|
||||
}, arguments[1] || { });
|
||||
@ -692,7 +774,9 @@ Effect.SlideDown = function(element) {
|
||||
afterSetup: function(effect) {
|
||||
effect.element.makePositioned();
|
||||
effect.element.down().makePositioned();
|
||||
if (window.opera) effect.element.setStyle({top: ''});
|
||||
if (window.opera) {
|
||||
effect.element.setStyle({top: ''});
|
||||
}
|
||||
effect.element.makeClipping().setStyle({height: '0px'}).show();
|
||||
},
|
||||
afterUpdateInternal: function(effect) {
|
||||
@ -720,7 +804,9 @@ Effect.SlideUp = function(element) {
|
||||
afterSetup: function(effect) {
|
||||
effect.element.makePositioned();
|
||||
effect.element.down().makePositioned();
|
||||
if (window.opera) effect.element.setStyle({top: ''});
|
||||
if (window.opera) {
|
||||
effect.element.setStyle({top: ''});
|
||||
}
|
||||
effect.element.makeClipping().show();
|
||||
},
|
||||
afterUpdateInternal: function(effect) {
|
||||
@ -914,17 +1000,21 @@ Effect.Fold = function(element) {
|
||||
|
||||
Effect.Morph = Class.create(Effect.Base, {
|
||||
initialize: function(element) {
|
||||
var options;
|
||||
this.element = $(element);
|
||||
if (!this.element) throw(Effect._elementDoesNotExistError);
|
||||
var options = Object.extend({
|
||||
if (!this.element) {
|
||||
throw(Effect._elementDoesNotExistError);
|
||||
}
|
||||
options = Object.extend({
|
||||
style: { }
|
||||
}, arguments[1] || { });
|
||||
|
||||
if (!Object.isString(options.style)) this.style = $H(options.style);
|
||||
else {
|
||||
if (options.style.include(':'))
|
||||
if (!Object.isString(options.style)) {
|
||||
this.style = $H(options.style);
|
||||
} else {
|
||||
if (options.style.include(':')) {
|
||||
this.style = options.style.parseStyle();
|
||||
else {
|
||||
} else {
|
||||
this.element.addClassName(options.style);
|
||||
this.style = $H(this.element.getStyles());
|
||||
this.element.removeClassName(options.style);
|
||||
@ -945,7 +1035,9 @@ Effect.Morph = Class.create(Effect.Base, {
|
||||
|
||||
setup: function(){
|
||||
function parseColor(color){
|
||||
if (!color || ['rgba(0, 0, 0, 0)','transparent'].include(color)) color = '#ffffff';
|
||||
if (!color || ['rgba(0, 0, 0, 0)','transparent'].include(color)) {
|
||||
color = '#ffffff';
|
||||
}
|
||||
color = color.parseColor();
|
||||
return $R(0,2).map(function(i){
|
||||
return parseInt( color.slice(i*2+1,i*2+3), 16 );
|
||||
@ -959,8 +1051,9 @@ Effect.Morph = Class.create(Effect.Base, {
|
||||
unit = 'color';
|
||||
} else if (property == 'opacity') {
|
||||
value = parseFloat(value);
|
||||
if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout))
|
||||
if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout)) {
|
||||
this.element.setStyle({zoom: 1});
|
||||
}
|
||||
} else if (Element.CSS_LENGTH.test(value)) {
|
||||
var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/);
|
||||
value = parseFloat(components[1]);
|
||||
@ -986,7 +1079,7 @@ Effect.Morph = Class.create(Effect.Base, {
|
||||
},
|
||||
update: function(position) {
|
||||
var style = { }, transform, i = this.transforms.length;
|
||||
while(i--)
|
||||
while(i--) {
|
||||
style[(transform = this.transforms[i]).style] =
|
||||
transform.unit=='color' ? '#'+
|
||||
(Math.round(transform.originalValue[0]+
|
||||
@ -998,6 +1091,7 @@ Effect.Morph = Class.create(Effect.Base, {
|
||||
(transform.originalValue +
|
||||
(transform.targetValue - transform.originalValue) * position).toFixed(3) +
|
||||
(transform.unit === null ? '' : transform.unit);
|
||||
}
|
||||
this.element.setStyle(style, true);
|
||||
}
|
||||
});
|
||||
@ -1120,4 +1214,4 @@ $w('getInlineOpacity forceRerendering setContentZoom collectTextNodes collectTex
|
||||
function(f) { Effect.Methods[f] = Element[f]; }
|
||||
);
|
||||
|
||||
Element.addMethods(Effect.Methods);
|
||||
Element.addMethods(Effect.Methods);
|
||||
|
@ -49,9 +49,10 @@ var Scriptaculous = {
|
||||
(typeof Element == 'undefined') ||
|
||||
(typeof Element.Methods=='undefined') ||
|
||||
(convertVersionString(Prototype.Version) <
|
||||
convertVersionString(Scriptaculous.REQUIRED_PROTOTYPE)))
|
||||
convertVersionString(Scriptaculous.REQUIRED_PROTOTYPE))) {
|
||||
throw("script.aculo.us requires the Prototype JavaScript framework >= " +
|
||||
Scriptaculous.REQUIRED_PROTOTYPE);
|
||||
}
|
||||
|
||||
var js = /scriptaculous\.js(\?.*)?$/;
|
||||
$$('head script[src]').findAll(function(s) {
|
||||
@ -60,9 +61,9 @@ var Scriptaculous = {
|
||||
var path = s.src.replace(js, ''),
|
||||
includes = s.src.match(/\?.*load=([a-z,]*)/);
|
||||
(includes ? includes[1] : 'builder,effects,dragdrop,controls,slider,sound').split(',').each(
|
||||
function(include) { Scriptaculous.require(path+include+'.js') });
|
||||
function(include) { Scriptaculous.require(path+include+'.js'); });
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Scriptaculous.load();
|
||||
Scriptaculous.load();
|
||||
|
@ -5,7 +5,9 @@
|
||||
// script.aculo.us is freely distributable under the terms of an MIT-style license.
|
||||
// For details, see the script.aculo.us web site: http://script.aculo.us/
|
||||
|
||||
if (!Control) var Control = { };
|
||||
if (!Control) {
|
||||
var Control = { };
|
||||
}
|
||||
|
||||
// options:
|
||||
// axis: 'vertical', or 'horizontal' (default)
|
||||
@ -18,7 +20,7 @@ Control.Slider = Class.create({
|
||||
var slider = this;
|
||||
|
||||
if (Object.isArray(handle)) {
|
||||
this.handles = handle.collect( function(e) { return $(e) });
|
||||
this.handles = handle.collect( function(e) { return $(e); });
|
||||
} else {
|
||||
this.handles = [$(handle)];
|
||||
}
|
||||
@ -32,8 +34,8 @@ Control.Slider = Class.create({
|
||||
this.range = this.options.range || $R(0,1);
|
||||
|
||||
this.value = 0; // assure backwards compat
|
||||
this.values = this.handles.map( function() { return 0 });
|
||||
this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false;
|
||||
this.values = this.handles.map( function() { return 0; });
|
||||
this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s); }) : false;
|
||||
this.options.startSpan = $(this.options.startSpan || null);
|
||||
this.options.endSpan = $(this.options.endSpan || null);
|
||||
|
||||
@ -58,7 +60,9 @@ Control.Slider = Class.create({
|
||||
this.dragging = false;
|
||||
this.disabled = false;
|
||||
|
||||
if (this.options.disabled) this.setDisabled();
|
||||
if (this.options.disabled) {
|
||||
this.setDisabled();
|
||||
}
|
||||
|
||||
// Allowed values array
|
||||
this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
|
||||
@ -104,8 +108,12 @@ Control.Slider = Class.create({
|
||||
},
|
||||
getNearestValue: function(value){
|
||||
if (this.allowedValues){
|
||||
if (value >= this.allowedValues.max()) return(this.allowedValues.max());
|
||||
if (value <= this.allowedValues.min()) return(this.allowedValues.min());
|
||||
if (value >= this.allowedValues.max()) {
|
||||
return(this.allowedValues.max());
|
||||
}
|
||||
if (value <= this.allowedValues.min()) {
|
||||
return(this.allowedValues.min());
|
||||
}
|
||||
|
||||
var offset = Math.abs(this.allowedValues[0] - value);
|
||||
var newValue = this.allowedValues[0];
|
||||
@ -118,8 +126,12 @@ Control.Slider = Class.create({
|
||||
});
|
||||
return newValue;
|
||||
}
|
||||
if (value > this.range.end) return this.range.end;
|
||||
if (value < this.range.start) return this.range.start;
|
||||
if (value > this.range.end) {
|
||||
return this.range.end;
|
||||
}
|
||||
if (value < this.range.start) {
|
||||
return this.range.start;
|
||||
}
|
||||
return value;
|
||||
},
|
||||
setValue: function(sliderValue, handleIdx){
|
||||
@ -130,10 +142,12 @@ Control.Slider = Class.create({
|
||||
}
|
||||
handleIdx = handleIdx || this.activeHandleIdx || 0;
|
||||
if (this.initialized && this.restricted) {
|
||||
if ((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
|
||||
if ((handleIdx>0) && (sliderValue<this.values[handleIdx-1])) {
|
||||
sliderValue = this.values[handleIdx-1];
|
||||
if ((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
|
||||
}
|
||||
if ((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1])) {
|
||||
sliderValue = this.values[handleIdx+1];
|
||||
}
|
||||
}
|
||||
sliderValue = this.getNearestValue(sliderValue);
|
||||
this.values[handleIdx] = sliderValue;
|
||||
@ -143,7 +157,9 @@ Control.Slider = Class.create({
|
||||
this.translateToPx(sliderValue);
|
||||
|
||||
this.drawSpans();
|
||||
if (!this.dragging || !this.event) this.updateFinished();
|
||||
if (!this.dragging || !this.event) {
|
||||
this.updateFinished();
|
||||
}
|
||||
},
|
||||
setValueBy: function(delta, handleIdx) {
|
||||
this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta,
|
||||
@ -178,14 +194,17 @@ Control.Slider = Class.create({
|
||||
},
|
||||
drawSpans: function() {
|
||||
var slider = this;
|
||||
if (this.spans)
|
||||
$R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
|
||||
if (this.options.startSpan)
|
||||
if (this.spans) {
|
||||
$R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)); });
|
||||
}
|
||||
if (this.options.startSpan) {
|
||||
this.setSpan(this.options.startSpan,
|
||||
$R(0, this.values.length>1 ? this.getRange(0).min() : this.value ));
|
||||
if (this.options.endSpan)
|
||||
}
|
||||
if (this.options.endSpan) {
|
||||
this.setSpan(this.options.endSpan,
|
||||
$R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum));
|
||||
}
|
||||
},
|
||||
setSpan: function(span, range) {
|
||||
if (this.isVertical()) {
|
||||
@ -197,7 +216,7 @@ Control.Slider = Class.create({
|
||||
}
|
||||
},
|
||||
updateStyles: function() {
|
||||
this.handles.each( function(h){ Element.removeClassName(h, 'selected') });
|
||||
this.handles.each( function(h){ Element.removeClassName(h, 'selected'); });
|
||||
Element.addClassName(this.activeHandle, 'selected');
|
||||
},
|
||||
startDrag: function(event) {
|
||||
@ -219,8 +238,9 @@ Control.Slider = Class.create({
|
||||
this.offsetY = (pointer[1] - offsets[1]);
|
||||
} else {
|
||||
// find the handle (prevents issues with Safari)
|
||||
while((this.handles.indexOf(handle) == -1) && handle.parentNode)
|
||||
while((this.handles.indexOf(handle) == -1) && handle.parentNode) {
|
||||
handle = handle.parentNode;
|
||||
}
|
||||
|
||||
if (this.handles.indexOf(handle)!=-1) {
|
||||
this.activeHandle = handle;
|
||||
@ -238,9 +258,13 @@ Control.Slider = Class.create({
|
||||
},
|
||||
update: function(event) {
|
||||
if (this.active) {
|
||||
if (!this.dragging) this.dragging = true;
|
||||
if (!this.dragging) {
|
||||
this.dragging = true;
|
||||
}
|
||||
this.draw(event);
|
||||
if (Prototype.Browser.WebKit) window.scrollBy(0,0);
|
||||
if (Prototype.Browser.WebKit) {
|
||||
window.scrollBy(0,0);
|
||||
}
|
||||
Event.stop(event);
|
||||
}
|
||||
},
|
||||
@ -251,8 +275,9 @@ Control.Slider = Class.create({
|
||||
pointer[1] -= this.offsetY + offsets[1];
|
||||
this.event = event;
|
||||
this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] ));
|
||||
if (this.initialized && this.options.onSlide)
|
||||
if (this.initialized && this.options.onSlide) {
|
||||
this.options.onSlide(this.values.length>1 ? this.values : this.value, this);
|
||||
}
|
||||
},
|
||||
endDrag: function(event) {
|
||||
if (this.active && this.dragging) {
|
||||
@ -268,8 +293,9 @@ Control.Slider = Class.create({
|
||||
this.updateFinished();
|
||||
},
|
||||
updateFinished: function() {
|
||||
if (this.initialized && this.options.onChange)
|
||||
if (this.initialized && this.options.onChange) {
|
||||
this.options.onChange(this.values.length>1 ? this.values : this.value, this);
|
||||
}
|
||||
this.event = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -19,7 +19,9 @@ Sound = {
|
||||
Sound._enabled = false;
|
||||
},
|
||||
play: function(url){
|
||||
if(!Sound._enabled) return;
|
||||
if(!Sound._enabled) {
|
||||
return;
|
||||
}
|
||||
var options = Object.extend({
|
||||
track: 'global', url: url, replace: false
|
||||
}, arguments[1] || {});
|
||||
@ -33,10 +35,11 @@ Sound = {
|
||||
this.tracks[options.track] = null;
|
||||
}
|
||||
|
||||
if(!this.tracks[options.track])
|
||||
if(!this.tracks[options.track]) {
|
||||
this.tracks[options.track] = { id: 0 };
|
||||
else
|
||||
} else {
|
||||
this.tracks[options.track].id++;
|
||||
}
|
||||
|
||||
options.id = this.tracks[options.track].id;
|
||||
$$('body')[0].insert(
|
||||
@ -48,12 +51,13 @@ Sound = {
|
||||
};
|
||||
|
||||
if(Prototype.Browser.Gecko && navigator.userAgent.indexOf("Win") > 0){
|
||||
if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('QuickTime') != -1 }))
|
||||
if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('QuickTime') != -1; })) {
|
||||
Sound.template = new Template('<object id="sound_#{track}_#{id}" width="0" height="0" type="audio/mpeg" data="#{url}"/>');
|
||||
else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('Windows Media') != -1 }))
|
||||
} else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('Windows Media') != -1; })) {
|
||||
Sound.template = new Template('<object id="sound_#{track}_#{id}" type="application/x-mplayer2" data="#{url}"></object>');
|
||||
else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('RealPlayer') != -1 }))
|
||||
} else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('RealPlayer') != -1; })) {
|
||||
Sound.template = new Template('<embed type="audio/x-pn-realaudio-plugin" style="height:0" id="sound_#{track}_#{id}" src="#{url}" loop="false" autostart="true" hidden="true"/>');
|
||||
else
|
||||
} else {
|
||||
Sound.play = function(){};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,9 @@ Event.simulateMouse = function(element, eventName) {
|
||||
options.buttons, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
|
||||
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, 0, $(element));
|
||||
|
||||
if(this.mark) Element.remove(this.mark);
|
||||
if(this.mark) {
|
||||
Element.remove(this.mark);
|
||||
}
|
||||
this.mark = document.createElement('div');
|
||||
this.mark.appendChild(document.createTextNode(" "));
|
||||
document.body.appendChild(this.mark);
|
||||
@ -35,8 +37,9 @@ Event.simulateMouse = function(element, eventName) {
|
||||
this.mark.style.borderTop = "1px solid red;";
|
||||
this.mark.style.borderLeft = "1px solid red;";
|
||||
|
||||
if(this.step)
|
||||
if(this.step) {
|
||||
alert('['+new Date().getTime().toString()+'] '+eventName+'/'+Test.Unit.inspect(options));
|
||||
}
|
||||
|
||||
$(element).dispatchEvent(oEvent);
|
||||
};
|
||||
@ -62,7 +65,8 @@ Event.simulateKey = function(element, eventName) {
|
||||
};
|
||||
|
||||
Event.simulateKeys = function(element, command) {
|
||||
for(var i=0; i<command.length; i++) {
|
||||
var i;
|
||||
for(i=0; i<command.length; i++) {
|
||||
Event.simulateKey(element,'keypress',{charCode:command.charCodeAt(i)});
|
||||
}
|
||||
};
|
||||
@ -82,7 +86,9 @@ Test.Unit.Logger.prototype = {
|
||||
}
|
||||
},
|
||||
start: function(testName) {
|
||||
if (!this.log) return;
|
||||
if (!this.log) {
|
||||
return;
|
||||
}
|
||||
this.testName = testName;
|
||||
this.lastLogLine = document.createElement('tr');
|
||||
this.statusCell = document.createElement('td');
|
||||
@ -96,18 +102,24 @@ Test.Unit.Logger.prototype = {
|
||||
this.loglines.appendChild(this.lastLogLine);
|
||||
},
|
||||
finish: function(status, summary) {
|
||||
if (!this.log) return;
|
||||
if (!this.log) {
|
||||
return;
|
||||
}
|
||||
this.lastLogLine.className = status;
|
||||
this.statusCell.innerHTML = status;
|
||||
this.messageCell.innerHTML = this._toHTML(summary);
|
||||
this.addLinksToResults();
|
||||
},
|
||||
message: function(message) {
|
||||
if (!this.log) return;
|
||||
if (!this.log) {
|
||||
return;
|
||||
}
|
||||
this.messageCell.innerHTML = this._toHTML(message);
|
||||
},
|
||||
summary: function(summary) {
|
||||
if (!this.log) return;
|
||||
if (!this.log) {
|
||||
return;
|
||||
}
|
||||
this.logsummary.innerHTML = this._toHTML(summary);
|
||||
},
|
||||
_createLogTable: function() {
|
||||
@ -138,6 +150,7 @@ Test.Unit.Logger.prototype = {
|
||||
Test.Unit.Runner = Class.create();
|
||||
Test.Unit.Runner.prototype = {
|
||||
initialize: function(testcases) {
|
||||
var i, testcase;
|
||||
this.options = Object.extend({
|
||||
testLog: 'testlog'
|
||||
}, arguments[1] || {});
|
||||
@ -148,7 +161,7 @@ Test.Unit.Runner.prototype = {
|
||||
}
|
||||
if(this.options.tests) {
|
||||
this.tests = [];
|
||||
for(var i = 0; i < this.options.tests.length; i++) {
|
||||
for(i = 0; i < this.options.tests.length; i++) {
|
||||
if(/^test/.test(this.options.tests[i])) {
|
||||
this.tests.push(new Test.Unit.Testcase(this.options.tests[i], testcases[this.options.tests[i]], testcases["setup"], testcases["teardown"]));
|
||||
}
|
||||
@ -158,7 +171,7 @@ Test.Unit.Runner.prototype = {
|
||||
this.tests = [new Test.Unit.Testcase(this.options.test, testcases[this.options.test], testcases["setup"], testcases["teardown"])];
|
||||
} else {
|
||||
this.tests = [];
|
||||
for(var testcase in testcases) {
|
||||
for(testcase in testcases) {
|
||||
if(/^test/.test(testcase)) {
|
||||
this.tests.push(
|
||||
new Test.Unit.Testcase(
|
||||
@ -179,15 +192,15 @@ Test.Unit.Runner.prototype = {
|
||||
parseTestsQueryParameter: function(){
|
||||
if (window.location.search.parseQuery()["tests"]){
|
||||
return window.location.search.parseQuery()["tests"].split(',');
|
||||
};
|
||||
}
|
||||
},
|
||||
// Returns:
|
||||
// "ERROR" if there was an error,
|
||||
// "FAILURE" if there was a failure, or
|
||||
// "SUCCESS" if there was neither
|
||||
getResult: function() {
|
||||
var hasFailure = false;
|
||||
for(var i=0;i<this.tests.length;i++) {
|
||||
var hasFailure = false, i;
|
||||
for(i=0;i<this.tests.length;i++) {
|
||||
if (this.tests[i].errors > 0) {
|
||||
return "ERROR";
|
||||
}
|
||||
@ -234,7 +247,8 @@ Test.Unit.Runner.prototype = {
|
||||
var failures = 0;
|
||||
var errors = 0;
|
||||
var messages = [];
|
||||
for(var i=0;i<this.tests.length;i++) {
|
||||
var i;
|
||||
for(i=0;i<this.tests.length;i++) {
|
||||
assertions += this.tests[i].assertions;
|
||||
failures += this.tests[i].failures;
|
||||
errors += this.tests[i].errors;
|
||||
@ -278,8 +292,12 @@ Test.Unit.Assertions.prototype = {
|
||||
this.messages.push(error.name + ": "+ error.message + "(" + Test.Unit.inspect(error) +")");
|
||||
},
|
||||
status: function() {
|
||||
if (this.failures > 0) return 'failed';
|
||||
if (this.errors > 0) return 'error';
|
||||
if (this.failures > 0) {
|
||||
return 'failed';
|
||||
}
|
||||
if (this.errors > 0) {
|
||||
return 'error';
|
||||
}
|
||||
return 'passed';
|
||||
},
|
||||
assert: function(expression) {
|
||||
@ -305,7 +323,7 @@ Test.Unit.Assertions.prototype = {
|
||||
assertEnumEqual: function(expected, actual) {
|
||||
var message = arguments[2] || "assertEnumEqual";
|
||||
try { $A(expected).length == $A(actual).length &&
|
||||
expected.zip(actual).all(function(pair) { return pair[0] == pair[1] }) ?
|
||||
expected.zip(actual).all(function(pair) { return pair[0] == pair[1]; }) ?
|
||||
this.pass() : this.fail(message + ': expected ' + Test.Unit.inspect(expected) +
|
||||
', actual ' + Test.Unit.inspect(actual)); }
|
||||
catch(e) { this.error(e); }
|
||||
@ -392,7 +410,9 @@ Test.Unit.Assertions.prototype = {
|
||||
var message = arguments[2] || 'assertReturnsTrue';
|
||||
try {
|
||||
var m = obj[method];
|
||||
if(!m) m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)];
|
||||
if(!m) {
|
||||
m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)];
|
||||
}
|
||||
m() ? this.pass() :
|
||||
this.fail(message + ": method returned false"); }
|
||||
catch(e) { this.error(e); }
|
||||
@ -401,7 +421,9 @@ Test.Unit.Assertions.prototype = {
|
||||
var message = arguments[2] || 'assertReturnsFalse';
|
||||
try {
|
||||
var m = obj[method];
|
||||
if(!m) m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)];
|
||||
if(!m) {
|
||||
m = obj['is'+method.charAt(0).toUpperCase()+method.slice(1)];
|
||||
}
|
||||
!m() ? this.pass() :
|
||||
this.fail(message + ": method returned true"); }
|
||||
catch(e) { this.error(e); }
|
||||
@ -423,7 +445,9 @@ Test.Unit.Assertions.prototype = {
|
||||
}
|
||||
elements.zip(expressions).all(function(pair, index) {
|
||||
var element = $(pair.first()), expression = pair.last();
|
||||
if (element.match(expression)) return true;
|
||||
if (element.match(expression)) {
|
||||
return true;
|
||||
}
|
||||
this.fail('assertElementsMatch: (in index ' + index + ') expected ' + expression.inspect() + ' but got ' + element.inspect());
|
||||
}.bind(this)) && this.pass();
|
||||
},
|
||||
@ -440,10 +464,13 @@ Test.Unit.Assertions.prototype = {
|
||||
},
|
||||
_isVisible: function(element) {
|
||||
element = $(element);
|
||||
if(!element.parentNode) return true;
|
||||
if(!element.parentNode) {
|
||||
return true;
|
||||
}
|
||||
this.assertNotNull(element);
|
||||
if(element.style && Element.getStyle(element, 'display') == 'none')
|
||||
if(element.style && Element.getStyle(element, 'display') == 'none') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return this._isVisible(element.parentNode);
|
||||
},
|
||||
@ -525,7 +552,7 @@ Test.setupBDDExtensionMethods = function(){
|
||||
shouldRespondTo: 'assertRespondsTo'
|
||||
};
|
||||
var makeAssertion = function(assertion, args, object) {
|
||||
this[assertion].apply(this,(args || []).concat([object]));
|
||||
this[assertion].apply(this,(args || []).concat([object]));
|
||||
};
|
||||
|
||||
Test.BDDMethods = {};
|
||||
@ -565,4 +592,4 @@ Test.context = function(name, spec, log){
|
||||
}
|
||||
}
|
||||
new Test.Unit.Runner(compiledSpec, { titles: titles, testLog: log || 'testlog', context: name });
|
||||
};
|
||||
};
|
||||
|
@ -49,9 +49,10 @@ var Scriptaculous = {
|
||||
(typeof Element == 'undefined') ||
|
||||
(typeof Element.Methods=='undefined') ||
|
||||
(convertVersionString(Prototype.Version) <
|
||||
convertVersionString(Scriptaculous.REQUIRED_PROTOTYPE)))
|
||||
convertVersionString(Scriptaculous.REQUIRED_PROTOTYPE))) {
|
||||
throw("script.aculo.us requires the Prototype JavaScript framework >= " +
|
||||
Scriptaculous.REQUIRED_PROTOTYPE);
|
||||
}
|
||||
|
||||
var js = /scriptaculous\.js(\?.*)?$/;
|
||||
$$('head script[src]').findAll(function(s) {
|
||||
@ -60,9 +61,9 @@ var Scriptaculous = {
|
||||
var path = s.src.replace(js, ''),
|
||||
includes = s.src.match(/\?.*load=([a-z,]*)/);
|
||||
(includes ? includes[1] : 'builder,effects,dragdrop,controls,slider,sound').split(',').each(
|
||||
function(include) { Scriptaculous.require(path+include+'.js') });
|
||||
function(include) { Scriptaculous.require(path+include+'.js'); });
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Scriptaculous.load();
|
||||
Scriptaculous.load();
|
||||
|
@ -5,7 +5,9 @@
|
||||
// script.aculo.us is freely distributable under the terms of an MIT-style license.
|
||||
// For details, see the script.aculo.us web site: http://script.aculo.us/
|
||||
|
||||
if (!Control) var Control = { };
|
||||
if (!Control) {
|
||||
var Control = { };
|
||||
}
|
||||
|
||||
// options:
|
||||
// axis: 'vertical', or 'horizontal' (default)
|
||||
@ -18,7 +20,7 @@ Control.Slider = Class.create({
|
||||
var slider = this;
|
||||
|
||||
if (Object.isArray(handle)) {
|
||||
this.handles = handle.collect( function(e) { return $(e) });
|
||||
this.handles = handle.collect( function(e) { return $(e); });
|
||||
} else {
|
||||
this.handles = [$(handle)];
|
||||
}
|
||||
@ -32,8 +34,8 @@ Control.Slider = Class.create({
|
||||
this.range = this.options.range || $R(0,1);
|
||||
|
||||
this.value = 0; // assure backwards compat
|
||||
this.values = this.handles.map( function() { return 0 });
|
||||
this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s) }) : false;
|
||||
this.values = this.handles.map( function() { return 0; });
|
||||
this.spans = this.options.spans ? this.options.spans.map(function(s){ return $(s); }) : false;
|
||||
this.options.startSpan = $(this.options.startSpan || null);
|
||||
this.options.endSpan = $(this.options.endSpan || null);
|
||||
|
||||
@ -58,7 +60,9 @@ Control.Slider = Class.create({
|
||||
this.dragging = false;
|
||||
this.disabled = false;
|
||||
|
||||
if (this.options.disabled) this.setDisabled();
|
||||
if (this.options.disabled) {
|
||||
this.setDisabled();
|
||||
}
|
||||
|
||||
// Allowed values array
|
||||
this.allowedValues = this.options.values ? this.options.values.sortBy(Prototype.K) : false;
|
||||
@ -104,8 +108,12 @@ Control.Slider = Class.create({
|
||||
},
|
||||
getNearestValue: function(value){
|
||||
if (this.allowedValues){
|
||||
if (value >= this.allowedValues.max()) return(this.allowedValues.max());
|
||||
if (value <= this.allowedValues.min()) return(this.allowedValues.min());
|
||||
if (value >= this.allowedValues.max()) {
|
||||
return(this.allowedValues.max());
|
||||
}
|
||||
if (value <= this.allowedValues.min()) {
|
||||
return(this.allowedValues.min());
|
||||
}
|
||||
|
||||
var offset = Math.abs(this.allowedValues[0] - value);
|
||||
var newValue = this.allowedValues[0];
|
||||
@ -118,8 +126,12 @@ Control.Slider = Class.create({
|
||||
});
|
||||
return newValue;
|
||||
}
|
||||
if (value > this.range.end) return this.range.end;
|
||||
if (value < this.range.start) return this.range.start;
|
||||
if (value > this.range.end) {
|
||||
return this.range.end;
|
||||
}
|
||||
if (value < this.range.start) {
|
||||
return this.range.start;
|
||||
}
|
||||
return value;
|
||||
},
|
||||
setValue: function(sliderValue, handleIdx){
|
||||
@ -130,10 +142,12 @@ Control.Slider = Class.create({
|
||||
}
|
||||
handleIdx = handleIdx || this.activeHandleIdx || 0;
|
||||
if (this.initialized && this.restricted) {
|
||||
if ((handleIdx>0) && (sliderValue<this.values[handleIdx-1]))
|
||||
if ((handleIdx>0) && (sliderValue<this.values[handleIdx-1])) {
|
||||
sliderValue = this.values[handleIdx-1];
|
||||
if ((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1]))
|
||||
}
|
||||
if ((handleIdx < (this.handles.length-1)) && (sliderValue>this.values[handleIdx+1])) {
|
||||
sliderValue = this.values[handleIdx+1];
|
||||
}
|
||||
}
|
||||
sliderValue = this.getNearestValue(sliderValue);
|
||||
this.values[handleIdx] = sliderValue;
|
||||
@ -143,7 +157,9 @@ Control.Slider = Class.create({
|
||||
this.translateToPx(sliderValue);
|
||||
|
||||
this.drawSpans();
|
||||
if (!this.dragging || !this.event) this.updateFinished();
|
||||
if (!this.dragging || !this.event) {
|
||||
this.updateFinished();
|
||||
}
|
||||
},
|
||||
setValueBy: function(delta, handleIdx) {
|
||||
this.setValue(this.values[handleIdx || this.activeHandleIdx || 0] + delta,
|
||||
@ -178,14 +194,17 @@ Control.Slider = Class.create({
|
||||
},
|
||||
drawSpans: function() {
|
||||
var slider = this;
|
||||
if (this.spans)
|
||||
$R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)) });
|
||||
if (this.options.startSpan)
|
||||
if (this.spans) {
|
||||
$R(0, this.spans.length-1).each(function(r) { slider.setSpan(slider.spans[r], slider.getRange(r)); });
|
||||
}
|
||||
if (this.options.startSpan) {
|
||||
this.setSpan(this.options.startSpan,
|
||||
$R(0, this.values.length>1 ? this.getRange(0).min() : this.value ));
|
||||
if (this.options.endSpan)
|
||||
}
|
||||
if (this.options.endSpan) {
|
||||
this.setSpan(this.options.endSpan,
|
||||
$R(this.values.length>1 ? this.getRange(this.spans.length-1).max() : this.value, this.maximum));
|
||||
}
|
||||
},
|
||||
setSpan: function(span, range) {
|
||||
if (this.isVertical()) {
|
||||
@ -197,7 +216,7 @@ Control.Slider = Class.create({
|
||||
}
|
||||
},
|
||||
updateStyles: function() {
|
||||
this.handles.each( function(h){ Element.removeClassName(h, 'selected') });
|
||||
this.handles.each( function(h){ Element.removeClassName(h, 'selected'); });
|
||||
Element.addClassName(this.activeHandle, 'selected');
|
||||
},
|
||||
startDrag: function(event) {
|
||||
@ -219,8 +238,9 @@ Control.Slider = Class.create({
|
||||
this.offsetY = (pointer[1] - offsets[1]);
|
||||
} else {
|
||||
// find the handle (prevents issues with Safari)
|
||||
while((this.handles.indexOf(handle) == -1) && handle.parentNode)
|
||||
while((this.handles.indexOf(handle) == -1) && handle.parentNode) {
|
||||
handle = handle.parentNode;
|
||||
}
|
||||
|
||||
if (this.handles.indexOf(handle)!=-1) {
|
||||
this.activeHandle = handle;
|
||||
@ -238,9 +258,13 @@ Control.Slider = Class.create({
|
||||
},
|
||||
update: function(event) {
|
||||
if (this.active) {
|
||||
if (!this.dragging) this.dragging = true;
|
||||
if (!this.dragging) {
|
||||
this.dragging = true;
|
||||
}
|
||||
this.draw(event);
|
||||
if (Prototype.Browser.WebKit) window.scrollBy(0,0);
|
||||
if (Prototype.Browser.WebKit) {
|
||||
window.scrollBy(0,0);
|
||||
}
|
||||
Event.stop(event);
|
||||
}
|
||||
},
|
||||
@ -251,8 +275,9 @@ Control.Slider = Class.create({
|
||||
pointer[1] -= this.offsetY + offsets[1];
|
||||
this.event = event;
|
||||
this.setValue(this.translateToValue( this.isVertical() ? pointer[1] : pointer[0] ));
|
||||
if (this.initialized && this.options.onSlide)
|
||||
if (this.initialized && this.options.onSlide) {
|
||||
this.options.onSlide(this.values.length>1 ? this.values : this.value, this);
|
||||
}
|
||||
},
|
||||
endDrag: function(event) {
|
||||
if (this.active && this.dragging) {
|
||||
@ -268,8 +293,9 @@ Control.Slider = Class.create({
|
||||
this.updateFinished();
|
||||
},
|
||||
updateFinished: function() {
|
||||
if (this.initialized && this.options.onChange)
|
||||
if (this.initialized && this.options.onChange) {
|
||||
this.options.onChange(this.values.length>1 ? this.values : this.value, this);
|
||||
}
|
||||
this.event = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -19,7 +19,9 @@ Sound = {
|
||||
Sound._enabled = false;
|
||||
},
|
||||
play: function(url){
|
||||
if(!Sound._enabled) return;
|
||||
if(!Sound._enabled) {
|
||||
return;
|
||||
}
|
||||
var options = Object.extend({
|
||||
track: 'global', url: url, replace: false
|
||||
}, arguments[1] || {});
|
||||
@ -33,10 +35,11 @@ Sound = {
|
||||
this.tracks[options.track] = null;
|
||||
}
|
||||
|
||||
if(!this.tracks[options.track])
|
||||
if(!this.tracks[options.track]) {
|
||||
this.tracks[options.track] = { id: 0 };
|
||||
else
|
||||
} else {
|
||||
this.tracks[options.track].id++;
|
||||
}
|
||||
|
||||
options.id = this.tracks[options.track].id;
|
||||
$$('body')[0].insert(
|
||||
@ -48,12 +51,13 @@ Sound = {
|
||||
};
|
||||
|
||||
if(Prototype.Browser.Gecko && navigator.userAgent.indexOf("Win") > 0){
|
||||
if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('QuickTime') != -1 }))
|
||||
if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('QuickTime') != -1; })) {
|
||||
Sound.template = new Template('<object id="sound_#{track}_#{id}" width="0" height="0" type="audio/mpeg" data="#{url}"/>');
|
||||
else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('Windows Media') != -1 }))
|
||||
} else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('Windows Media') != -1; })) {
|
||||
Sound.template = new Template('<object id="sound_#{track}_#{id}" type="application/x-mplayer2" data="#{url}"></object>');
|
||||
else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('RealPlayer') != -1 }))
|
||||
} else if(navigator.plugins && $A(navigator.plugins).detect(function(p){ return p.name.indexOf('RealPlayer') != -1; })) {
|
||||
Sound.template = new Template('<embed type="audio/x-pn-realaudio-plugin" style="height:0" id="sound_#{track}_#{id}" src="#{url}" loop="false" autostart="true" hidden="true"/>');
|
||||
else
|
||||
} else {
|
||||
Sound.play = function(){};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,9 @@ Event.simulateMouse = function(element, eventName) {
|
||||
options.buttons, options.pointerX, options.pointerY, options.pointerX, options.pointerY,
|
||||
options.ctrlKey, options.altKey, options.shiftKey, options.metaKey, 0, $(element));
|
||||
|
||||
if(this.mark) Element.remove(this.mark);
|
||||
if(this.mark) {
|
||||
Element.remove(this.mark);
|
||||
}
|
||||
this.mark = document.createElement('div');
|
||||
this.mark.appendChild(document.createTextNode(" "));
|
||||
document.body.appendChild(this.mark);
|
||||
@ -35,8 +37,9 @@ Event.simulateMouse = function(element, eventName) {
|
||||
this.mark.style.borderTop = "1px solid red;";
|
||||
this.mark.style.borderLeft = "1px solid red;";
|
||||
|
||||
if(this.step)
|
||||
if(this.step) {
|
||||
alert('['+new Date().getTime().toString()+'] '+eventName+'/'+Test.Unit.inspect(options));
|
||||
}
|
||||
|
||||
$(element).dispatchEvent(oEvent);
|
||||
};
|
||||
@ -62,7 +65,8 @@ Event.simulateKey = function(element, eventName) {
|
||||
};
|
||||
|
||||
Event.simulateKeys = function(element, command) {
|
||||
for(var i=0; i<command.length; i++) {
|
||||
var i;
|
||||
for(i=0; i<command.length; i++) {
|
||||
Event.simulateKey(element,'keypress',{charCode:command.charCodeAt(i)});
|
||||
}
|
||||
};
|
||||
@ -565,4 +569,4 @@ Test.context = function(name, spec, log){
|
||||
}
|
||||
}
|
||||
new Test.Unit.Runner(compiledSpec, { titles: titles, testLog: log || 'testlog', context: name });
|
||||
};
|
||||
};
|
||||
|
@ -58,16 +58,17 @@ function process_hypotheses() {
|
||||
|
||||
function index_hypotheses_by_cell() {
|
||||
// init edge_lists
|
||||
for(var from=0; from<length; from++) {
|
||||
var from, to, id;
|
||||
for(from=0; from<length; from++) {
|
||||
cell_hyps[from] = new Array(length);
|
||||
for(var to=0; to<length; to++) {
|
||||
cell_hyps[from][to] = new Array();
|
||||
for(to=0; to<length; to++) {
|
||||
cell_hyps[from][to] = new Array();
|
||||
}
|
||||
}
|
||||
// populate
|
||||
for (var id in edge) {
|
||||
var from = edge[id][FROM];
|
||||
var to = edge[id][TO];
|
||||
for (id in edge) {
|
||||
from = edge[id][FROM];
|
||||
to = edge[id][TO];
|
||||
edge[id][FROM] = parseInt(from);
|
||||
edge[id][TO] = parseInt(to);
|
||||
edge[id][RULE_SCORE] = parseFloat(edge[id][RULE_SCORE]);
|
||||
@ -79,37 +80,40 @@ function index_hypotheses_by_cell() {
|
||||
}
|
||||
|
||||
function find_reachable_hypotheses() {
|
||||
for (var i=0;i<cell_hyps[0][length-1].length;i++) {
|
||||
var i;
|
||||
for (i=0;i<cell_hyps[0][length-1].length;i++) {
|
||||
id = cell_hyps[0][length-1][i];
|
||||
find_reachable_hypotheses_recursive( id );
|
||||
}
|
||||
}
|
||||
|
||||
function find_reachable_hypotheses_recursive( id ) {
|
||||
var children, c;
|
||||
if (!(reachable[id] === undefined)) { return; }
|
||||
reachable[id] = 1;
|
||||
var children = get_children( id );
|
||||
for(var c=0;c<children.length;c++) {
|
||||
children = get_children( id );
|
||||
for(c=0;c<children.length;c++) {
|
||||
find_reachable_hypotheses_recursive( children[c] );
|
||||
}
|
||||
}
|
||||
|
||||
function compute_best_derivation_scores() {
|
||||
for(var from=0; from<length; from++ ) {
|
||||
var from, to, width, cell_max_score, i, id, c;
|
||||
for(from=0; from<length; from++ ) {
|
||||
cell_derivation_score[from] = Array();
|
||||
}
|
||||
for(var width=length-1; width>=0; width-- ) {
|
||||
for(var from=0; from<length-width; from++ ) {
|
||||
var to = from+width;
|
||||
var cell_max_score = -9.9e9;
|
||||
for (var i=0;i<cell_hyps[from][to].length;i++) {
|
||||
var id = cell_hyps[from][to][i];
|
||||
for(width=length-1; width>=0; width-- ) {
|
||||
for(from=0; from<length-width; from++ ) {
|
||||
to = from+width;
|
||||
cell_max_score = -9.9e9;
|
||||
for (i=0;i<cell_hyps[from][to].length;i++) {
|
||||
id = cell_hyps[from][to][i];
|
||||
if (width == length-1) {
|
||||
edge[id][DERIVATION_SCORE] = edge[id][HYP_SCORE];
|
||||
}
|
||||
if (edge[id][DERIVATION_SCORE] != null) {
|
||||
var children = get_children(id);
|
||||
for(var c=0;c<children.length;c++) {
|
||||
for(c=0;c<children.length;c++) {
|
||||
if (edge[children[c]][DERIVATION_SCORE] == null ||
|
||||
edge[children[c]][DERIVATION_SCORE] < edge[id][DERIVATION_SCORE]) {
|
||||
edge[children[c]][DERIVATION_SCORE] = edge[id][DERIVATION_SCORE];
|
||||
@ -135,8 +139,8 @@ function draw_menu() {
|
||||
draw_menu_button(2,"Number of Hypotheses");
|
||||
draw_menu_button(3,"Number of Rule Cubes");
|
||||
draw_menu_button(4,"Derivation Score");
|
||||
draw_menu_button(5,"Non-Terminals")
|
||||
draw_menu_button(6,"Hypotheses")
|
||||
draw_menu_button(5,"Non-Terminals");
|
||||
draw_menu_button(6,"Hypotheses");
|
||||
}
|
||||
var MENU_POSITION_HYPOTHESES = 6; // where is "Hypotheses" in the menu?
|
||||
|
||||
@ -184,7 +188,7 @@ function draw_menu_button( id, label ) {
|
||||
button.setAttribute("fill", "#c0c0ff");
|
||||
button.setAttribute("stroke", "black");
|
||||
button.setAttribute("stroke-width", "1");
|
||||
button.setAttribute("onclick","click_menu(" + id + ",0);")
|
||||
button.setAttribute("onclick","click_menu(" + id + ",0);");
|
||||
chart.appendChild( button );
|
||||
|
||||
var button_label = document.createElementNS(xmlns,"text");
|
||||
@ -195,7 +199,7 @@ function draw_menu_button( id, label ) {
|
||||
button_label.setAttribute("pointer-events", "none");
|
||||
var content = document.createTextNode( label );
|
||||
button_label.appendChild( content );
|
||||
button_label.setAttribute("onclick","click_menu(" + id + ",0);")
|
||||
button_label.setAttribute("onclick","click_menu(" + id + ",0);");
|
||||
|
||||
chart.appendChild( button_label );
|
||||
}
|
||||
@ -238,7 +242,7 @@ function draw_option_button( rule_option, id, label ) {
|
||||
button.setAttribute("fill", "#fdd017");
|
||||
button.setAttribute("stroke", "black");
|
||||
button.setAttribute("stroke-width", "1");
|
||||
button.setAttribute("onclick","click_"+(rule_option?"rule_":"")+"option(" + id + ");")
|
||||
button.setAttribute("onclick","click_"+(rule_option?"rule_":"")+"option(" + id + ");");
|
||||
chart.appendChild( button );
|
||||
|
||||
var button_label = document.createElementNS(xmlns,"text");
|
||||
@ -279,7 +283,7 @@ function draw_sort_button( id, label ) {
|
||||
else {
|
||||
button.setAttribute("fill", "#a0c0ff");
|
||||
}
|
||||
button.setAttribute("onclick","click_sort(" + id + ");")
|
||||
button.setAttribute("onclick","click_sort(" + id + ");");
|
||||
button.setAttribute("stroke", "black");
|
||||
button.setAttribute("stroke-width", "1");
|
||||
}
|
||||
@ -300,7 +304,7 @@ function draw_sort_button( id, label ) {
|
||||
|
||||
function click_sort( id ) {
|
||||
if (SORT_OPTION == 3) {
|
||||
remove_non_terminal_treemap(1)
|
||||
remove_non_terminal_treemap(1);
|
||||
}
|
||||
remove_hypothesis_overview();
|
||||
|
||||
@ -387,21 +391,21 @@ function draw_chart() {
|
||||
container.appendChild( transform );
|
||||
|
||||
// yellow box for the cell
|
||||
var cell = document.createElementNS(xmlns,"rect");
|
||||
cell.setAttribute("id", "cellbox-" + from + "-" + to);
|
||||
cell.setAttribute("x", CELL_MARGIN);
|
||||
cell.setAttribute("y", CELL_MARGIN);
|
||||
cell.setAttribute("rx", CELL_BORDER);
|
||||
cell.setAttribute("ry", CELL_BORDER);
|
||||
cell.setAttribute("width", CELL_WIDTH-2*CELL_MARGIN);
|
||||
cell.setAttribute("height", CELL_HEIGHT-2*CELL_MARGIN);
|
||||
cell.setAttribute("opacity", .75);
|
||||
cell.setAttribute("fill", get_cell_color(from,to));
|
||||
cell.setAttribute("stroke", "black");
|
||||
cell.setAttribute("stroke-width", "1");
|
||||
cell.setAttribute("onmouseover","hover_cell(" + from + "," + to + ");")
|
||||
cell.setAttribute("onclick","click_cell(" + from + "," + to + ");")
|
||||
transform.appendChild( cell );
|
||||
var cell = document.createElementNS(xmlns,"rect");
|
||||
cell.setAttribute("id", "cellbox-" + from + "-" + to);
|
||||
cell.setAttribute("x", CELL_MARGIN);
|
||||
cell.setAttribute("y", CELL_MARGIN);
|
||||
cell.setAttribute("rx", CELL_BORDER);
|
||||
cell.setAttribute("ry", CELL_BORDER);
|
||||
cell.setAttribute("width", CELL_WIDTH-2*CELL_MARGIN);
|
||||
cell.setAttribute("height", CELL_HEIGHT-2*CELL_MARGIN);
|
||||
cell.setAttribute("opacity", .75);
|
||||
cell.setAttribute("fill", get_cell_color(from,to));
|
||||
cell.setAttribute("stroke", "black");
|
||||
cell.setAttribute("stroke-width", "1");
|
||||
cell.setAttribute("onmouseover","hover_cell(" + from + "," + to + ");")
|
||||
cell.setAttribute("onclick","click_cell(" + from + "," + to + ");")
|
||||
transform.appendChild( cell );
|
||||
}
|
||||
|
||||
// box for the input word
|
||||
@ -409,12 +413,12 @@ function draw_chart() {
|
||||
input_box.setAttribute("id", "inputbox-" + from);
|
||||
input_box.setAttribute("x", CELL_MARGIN+from*CELL_WIDTH);
|
||||
input_box.setAttribute("y", CELL_MARGIN+(length)*CELL_HEIGHT);
|
||||
input_box.setAttribute("rx", 3);
|
||||
input_box.setAttribute("ry", 3);
|
||||
input_box.setAttribute("width", CELL_WIDTH-2*CELL_MARGIN);
|
||||
input_box.setAttribute("height", CELL_HEIGHT/2);
|
||||
//cell.setAttribute("opacity", .75);
|
||||
input_box.setAttribute("fill", INPUT_REGULAR_COLOR);
|
||||
input_box.setAttribute("rx", 3);
|
||||
input_box.setAttribute("ry", 3);
|
||||
input_box.setAttribute("width", CELL_WIDTH-2*CELL_MARGIN);
|
||||
input_box.setAttribute("height", CELL_HEIGHT/2);
|
||||
//cell.setAttribute("opacity", .75);
|
||||
input_box.setAttribute("fill", INPUT_REGULAR_COLOR);
|
||||
chart.appendChild( input_box );
|
||||
|
||||
// input word
|
||||
@ -427,7 +431,7 @@ function draw_chart() {
|
||||
var content = document.createTextNode( input[from] );
|
||||
input_word.appendChild( content );
|
||||
chart.appendChild( input_word );
|
||||
}
|
||||
}
|
||||
assign_chart_coordinates();
|
||||
}
|
||||
|
||||
@ -436,7 +440,7 @@ function assign_chart_coordinates() {
|
||||
for(var width=1; width<=length-from; width++) {
|
||||
var to = from + width - 1;
|
||||
|
||||
var x = from*CELL_WIDTH + (width-1)*CELL_WIDTH/2;
|
||||
var x = from*CELL_WIDTH + (width-1)*CELL_WIDTH/2;
|
||||
var y = (length-width)*CELL_HEIGHT*(1-ZOOM);
|
||||
//alert("(x,y) = (" + length + "," + width + "), width = " + ZOOM + ", height = " + (1-ZOOM));
|
||||
var cell_width = CELL_WIDTH;
|
||||
@ -478,11 +482,11 @@ function assign_chart_coordinates() {
|
||||
|
||||
var container = document.getElementById("cell-container-" + from + "-" + to);
|
||||
container.setAttribute("x", x);
|
||||
container.setAttribute("y", y);
|
||||
container.setAttribute("y", y);
|
||||
var transform = document.getElementById("cell-" + from + "-" + to);
|
||||
transform.setAttribute("transform", "scale(" + (cell_width/CELL_WIDTH) + "," + (cell_height/CELL_HEIGHT) + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function remove_chart() {
|
||||
@ -530,7 +534,7 @@ function click_cell( from, to ) {
|
||||
function highlight_input( from, to, on_off ) {
|
||||
for(var i=from; i<=to; i++) {
|
||||
var input_box = document.getElementById("inputbox-" + i);
|
||||
input_box.setAttribute("fill", on_off ? INPUT_HIGHLIGHT_COLOR : INPUT_REGULAR_COLOR);
|
||||
input_box.setAttribute("fill", on_off ? INPUT_HIGHLIGHT_COLOR : INPUT_REGULAR_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -546,7 +550,7 @@ function annotate_cells_with_hypcount() {
|
||||
var to = from + width - 1;
|
||||
annotate_cell( from, to, cell_hyps[from][to].length, 20 )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function annotate_cells_with_rulecount() {
|
||||
@ -564,7 +568,7 @@ function annotate_cells_with_rulecount() {
|
||||
}
|
||||
annotate_cell( from, to, rule_count, 20 )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function annotate_cells_with_derivation_score() {
|
||||
@ -575,7 +579,7 @@ function annotate_cells_with_derivation_score() {
|
||||
if (score < -9e9) { score = "dead end"; }
|
||||
annotate_cell( from, to, score, 15 )
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function annotate_cell( from, to, label, font_size ) {
|
||||
@ -610,7 +614,7 @@ function unannotate_cells() {
|
||||
var to = from + width - 1;
|
||||
unannotate_cell( from, to );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function unannotate_cell( from, to ) {
|
||||
@ -953,7 +957,7 @@ function color_cells() {
|
||||
var to = from+width-1;
|
||||
highlight_cell(from,to,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function get_cell_color( from, to ) {
|
||||
@ -997,7 +1001,7 @@ var SORT_BUTTON_COUNT = 4; // how many in total (incl. "sort by")?
|
||||
function hypothesis_overview_cell( from, to ) {
|
||||
var width = CELL_WIDTH-2*(CELL_BORDER+CELL_MARGIN+CELL_PADDING);
|
||||
var height = CELL_HEIGHT-2*(CELL_BORDER+CELL_MARGIN+CELL_PADDING);
|
||||
var cell = document.getElementById("cell-" + from + "-" + to);
|
||||
var cell = document.getElementById("cell-" + from + "-" + to);
|
||||
hypothesis_in_rect( width, height, CELL_BORDER+CELL_MARGIN+CELL_PADDING, CELL_BORDER+CELL_MARGIN+CELL_PADDING, cell, cell_hyps[from][to] );
|
||||
}
|
||||
|
||||
@ -1041,12 +1045,12 @@ function hypothesis_in_rect( width, height, offset_x, offset_y, parent_element,
|
||||
hyp.setAttribute("cx", x + diameter/2 + offset_x);
|
||||
hyp.setAttribute("cy", y + diameter/2 + offset_y);
|
||||
hyp.setAttribute("r", diameter/2);
|
||||
hyp.setAttribute("fill", hyp_color(id, 0));
|
||||
hyp.setAttribute("onmouseover","hover_hyp(" + id + ");")
|
||||
hyp.setAttribute("onmouseout","unhover_hyp(" + id + ");")
|
||||
parent_element.appendChild( hyp );
|
||||
hyp.setAttribute("fill", hyp_color(id, 0));
|
||||
hyp.setAttribute("onmouseover","hover_hyp(" + id + ");")
|
||||
hyp.setAttribute("onmouseout","unhover_hyp(" + id + ");")
|
||||
parent_element.appendChild( hyp );
|
||||
|
||||
x += diameter;
|
||||
x += diameter;
|
||||
if (++column >= row_size) {
|
||||
column = 0;
|
||||
y += diameter;
|
||||
@ -1057,8 +1061,8 @@ function hypothesis_in_rect( width, height, offset_x, offset_y, parent_element,
|
||||
|
||||
function remove_hypothesis_overview() {
|
||||
for (var id in edge) {
|
||||
var cell = document.getElementById("cell-" + edge[id][FROM] + "-" + edge[id][TO]);
|
||||
var hyp = document.getElementById("hyp-" + id);
|
||||
var cell = document.getElementById("cell-" + edge[id][FROM] + "-" + edge[id][TO]);
|
||||
var hyp = document.getElementById("hyp-" + id);
|
||||
cell.removeChild(hyp);
|
||||
}
|
||||
// remove sort buttons
|
||||
|
Loading…
Reference in New Issue
Block a user