// $Id: functions.js,v 1.1 2006/01/17 03:01:18 mclark Exp $
// Copyright ©2006 Matthew Clark. All Rights Reserved.
Scriptio.prototype.Absolute = function() {
if (arguments.length == 1)
return Math.abs((typeof(arguments[0]) != 'number') ? parseFloat(arguments[0]) : arguments[0]);
else
this.author('Invalid number of arguments for "Absolute" function');
}
Scriptio.prototype.Cos = function() {
if (arguments.length == 1)
return Math.cos((typeof(arguments[0]) != 'number') ? parseFloat(arguments[0]) : arguments[0]);
else
this.author('Invalid number of arguments for "Cos" function');
}
Scriptio.prototype.Random = function() {
if (arguments.length == 1)
return Math.random((typeof(arguments[0]) != 'number') ? parseFloat(arguments[0]) : arguments[0]);
else
this.author('Invalid number of arguments for "Random" function');
}
Scriptio.prototype.Round = function() {
if (arguments.length == 1)
return Math.round((typeof(arguments[0]) != 'number') ? parseFloat(arguments[0]) : arguments[0]);
else
this.author('Invalid number of arguments for "Sqrt" function');
}
Scriptio.prototype.Sin = function() {
if (arguments.length == 1)
return Math.sin((typeof(arguments[0]) != 'number') ? parseFloat(arguments[0]) : arguments[0]);
else
this.author('Invalid number of arguments for "Sin" function');
}
Scriptio.prototype.Sqrt = function() {
if (arguments.length == 1)
return Math.sqrt((typeof(arguments[0]) != 'number') ? parseFloat(arguments[0]) : arguments[0]);
else
this.author('Invalid number of arguments for "Sqrt" function');
}
Scriptio.prototype.Length = function() {
if (arguments.length == 1)
return ((typeof(arguments[0]) != 'string') ? '' + arguments[0] : arguments[0]).length;
else
this.author('Invalid number of arguments for "Length" function');
}
Scriptio.prototype.Answer = function() {
var result = false;
if (arguments.length == 1) {
var objs = this.get(arguments[0]);
for (var i = 0; i < objs.length; i++) {
var obj = objs[i],
type = obj.getAttribute('xtype');
if (type == 'entry') {
// TODO:
} else if (type == 'checkbox') {
if (obj.childNodes && obj.childNodes.length && obj.childNodes[0].checked)
result = obj.childNodes[0].checked;
} else if (type == 'radio') {
// TODO:
}
}
} else if (arguments.length == 0)
result = this.global.button_selected;
else
this.author('Invalid number of arguments for "Answer" function');
return result;
}
Scriptio.prototype.StringWidth = function() {
if (arguments.length == 1) {
var text = scriptio_clean_text(arguments[0]);
var obj = document.createElement('span');
obj.style.position = 'absolute';
obj.style.visibility = 'hidden';
obj.style.fontFamily = this.last_face;
obj.style.fontSize = '' + this.last_size + 'px';
/*
if (text.indexOf('
') >= 0) {
var lines = text.split('
');
for (var i = 0; i < lines.length; i++) {
if (i > 0)
obj.appendChild(document.createElement('br'));
obj.appendChild(document.createTextNode(lines[i]));
}
} else
*/
obj.appendChild(document.createTextNode(text));
this.expo.appendChild(obj);
var result = obj.offsetWidth;
this.expo.removeChild(obj);
return result;
} else
this.author('Invalid number of arugments for "StringWidth" function');
}
Scriptio.prototype.object_extent = function(arg) {
var result = new Object();
var any = false;
var objs = this.get(arg);
for (var i = 0; i < objs.length; i++) {
var obj = objs[i];
if (obj.getAttribute('xtype') != 'group') {
var slide = obj.getAttribute('slide'),
grow = obj.getAttribute('grow'),
left = slide ? parseInt(obj.getAttribute('end_left')) : (obj.offsetLeft - (obj.style.marginLeft ? parseInt(obj.style.marginLeft) : 0)),
top = slide ? parseInt(obj.getAttribute('end_top')) : (obj.offsetTop - (obj.style.marginTop ? parseInt(obj.style.marginTop) : 0)),
right = left + (grow ? parseInt(obj.getAttribute('orig_width')) : obj.offsetWidth),
bottom = top + (grow ? parseInt(obj.getAttribute('orig_height')) : obj.offsetHeight);
if (any) {
if (result.left > left)
result.left = left;
if (result.right < right)
result.right = right;
if (result.top > top)
result.top = top;
if (result.bottom < bottom)
result.bottom = bottom;
} else {
result.left = left;
result.top = top;
result.right = right;
result.bottom = bottom;
any = true;
}
}
}
if (!any)
result.left = result.top = result.right = result.bottom = 0;
return result;
}
Scriptio.prototype.Left = function() {
if (arguments.length == 1) {
var extent = this.object_extent(arguments[0]);
return extent.left;
} else
this.author('Invalid number of arguments for "Left" function');
}
Scriptio.prototype.Top = function() {
if (arguments.length == 1) {
var extent = this.object_extent(arguments[0]);
return extent.top;
} else
this.author('Invalid number of arguments for "Top" function');
}
Scriptio.prototype.Right = function() {
if (arguments.length == 1) {
var extent = this.object_extent(arguments[0]);
return extent.right;
} else
this.author('Invalid number of arguments for "Right" function');
}
Scriptio.prototype.Bottom = function() {
if (arguments.length == 1) {
var extent = this.object_extent(arguments[0]);
return extent.bottom;
} else
this.author('Invalid number of arguments for "Bottom" function');
}
Scriptio.prototype.Width = function() {
if (arguments.length == 1) {
var extent = this.object_extent(arguments[0]);
return extent.right - extent.left;
} else
this.author('Invalid number of arguments for "Width" function');
}
Scriptio.prototype.Height = function() {
if (arguments.length == 1) {
var extent = this.object_extent(arguments[0]);
return extent.bottom - extent.top;
} else
this.author('Invalid number of arguments for "Height" function');
}