January 28, 2014♦
☀
E
F
F
L
U
E
N
C
E
☀
EVR.Pop_Up.Veil = function(container)
{
EVR.Graphic.call(this, container);
this.set_attributes();
this.append();
}
EVR.Pop_Up.Veil.prototype = new EVR.Graphic;
EVR.Pop_Up.Veil.prototype.set_attributes = function()
{
this.set_proportions(1, 1);
this.set_z(POP_UP_VEIL_Z_INDEX);
this.set_color(POP_UP_VEIL_COLOR);
this.set_opacity(POP_UP_VEIL_OPACITY);
}
EVR.Pop_Up.Veil.prototype.toString = function()
{
return "[object EVR.Pop_Up.Veil]";
}
EVR.include("element/pop_up/Veil.js");
EVR.Pop_Up = function(container, width, height)
{
EVR.Graphic.call(this, container, null, null, ALIGN_CENTER);
this.width = width;
this.height = height;
this.set_attributes();
this.add_focus_receiver();
}
EVR.Pop_Up.prototype = new EVR.Graphic;
EVR.Pop_Up.prototype.set_attributes = function()
{
this.set_proportions(this.width, this.height);
this.set_z(POP_UP_WINDOW_Z_INDEX);
var css = this.css;
css.overflow = "auto";
css.border = POP_UP_BORDER;
}
EVR.Pop_Up.prototype.add_focus_receiver = function()
{
var link = document.createElement("a");
link.href = "javascript: void(0)";
this.element.appendChild(link);
this.focus_receiver = link;
}
EVR.Pop_Up.prototype.draw = function()
{
!!this.veil && this.veil.draw();
EVR.Graphic.prototype.draw.call(this);
}
EVR.Pop_Up.prototype.append = function()
{
EVR.Graphic.prototype.append.call(this);
var link = this.focus_receiver;
setTimeout(function() { link.focus() }, 50);
this.veil = new EVR.Pop_Up.Veil(this.container);
}
EVR.Pop_Up.prototype.remove = function()
{
EVR.Graphic.prototype.remove.call(this);
this.veil.remove();
this.veil = null;
}
EVR.Pop_Up.prototype.toString = function()
{
return "[object EVR.Pop_Up]";
}
EVR.include("time/Translator.js");
EVR.Time = function(time)
{
this.translator = new EVR.Time.Translator(time);
}
EVR.Time.prototype.add = function(time)
{
this.translator.add(time);
}
EVR.Time.prototype.get = function()
{
return this.translator.get();
}
EVR.Time.prototype.get_formatted = function(precision, padding)
{
if (precision == null)
{
precision = CLOCK_PRECISION;
}
if (padding == null)
{
padding = CLOCK_PADDING;
}
var m = this.pad(this.get_minutes(), padding);
var s = this.pad(this.get_seconds() % 60, 2);
var string = m + ":" + s;
if (precision > 0)
{
var ms = this.pad(this.get_milliseconds(precision), precision);
string += "." + ms;
}
return string;
}
EVR.Time.prototype.get_milliseconds = function(precision)
{
if (precision == null)
{
precision = 3;
}
return parseInt(this.get() % 1000 / (1000 / Math.pow(10, precision)));
}
EVR.Time.prototype.get_seconds = function()
{
return parseInt(this.get() / 1000);
}
EVR.Time.prototype.get_minutes = function()
{
return parseInt(this.get_seconds() / 60);
}
EVR.Time.prototype.pad = function(number, length)
{
length -= number.toString().length;
return new Array(length + 1).join("0") + number;
}
EVR.Time.prototype.toString = function(precision, padding)
{
return this.get_formatted(precision, padding);
}
EVR.Time.Translator = function(time)
{
this.time = this.convert(time) || 0;
}
EVR.Time.Translator.prototype.convert = function(time)
{
if (!this.is_timestamp(time))
{
time = this.extract_timestamp(time);
}
return time;
}
EVR.Time.Translator.prototype.is_timestamp = function(time)
{
return !/\./.test(time);
}
EVR.Time.Translator.prototype.extract_timestamp = function(time)
{
var fields = time.match(/(.{1,2})\.(.{3})/);
var timestamp = parseInt(fields[2], 10) + parseInt(fields[1], 10) * 1000;
if (fields = time.match(/(.*):/))
{
timestamp += fields[1] * 60 * 1000;
}
return timestamp;
}
EVR.Time.Translator.prototype.get = function()
{
return parseInt(this.time);
}
EVR.Time.Translator.prototype.add = function(time)
{
this.time += this.convert(time);
}
EVR.Time.Translator.prototype.toString = function()
{
return "[EVR.Time.Translator]";
}
EVR.Instructions = function(container)
{
EVR.Pop_Up.call(this, container, INSTRUCTIONS_WIDTH, INSTRUCTIONS_HEIGHT);
this.set_attributes();
this.add_focus_receiver();
this.include_document();
}
EVR.Instructions.prototype = new EVR.Pop_Up;
EVR.Instructions.prototype.set_attributes = function()
{
EVR.Pop_Up.prototype.set_attributes.call(this);
this.set_color(INSTRUCTIONS_BACKGROUND);
var css = this.css;
css.fontSize = INSTRUCTIONS_FONT_SIZE;
css.fontFamily = INSTRUCTIONS_FONT_FAMILY;
css.color = INSTRUCTIONS_FONT_COLOR;
css.letterSpacing = INSTRUCTIONS_LETTER_SPACING;
css.lineHeight = INSTRUCTIONS_LINE_HEIGHT;
css.padding = INSTRUCTIONS_PADDING;
}
EVR.Instructions.prototype.include_document = function()
{
var path = SOURCE_PATH + "instructions/instructions";
var document = new EVR.Requester(path, null, true).execute().split("\n\n");
this.translate_document(document);
}
EVR.Instructions.prototype.translate_document = function(document)
{
var line;
for (var ii = 0; ii < document.length; ii++)
{
line = document[ii];
if (/^img\//.test(line))
{
this.add_image(line);
continue;
}
this.add_paragraph(line);
}
}
EVR.Instructions.prototype.add_image = function(src)
{
var element = document.createElement("img");
element.src = src;
element.style.display = "block";
element.style.margin = INSTRUCTIONS_IMAGE_MARGIN + " auto";
this.element.appendChild(element);
}
EVR.Instructions.prototype.add_paragraph = function(text)
{
var element = document.createElement("p");
var style = element.style;
element.innerHTML = text;
style.textAlign = INSTRUCTIONS_PARAGRAPH_TEXT_ALIGN;
style.background = INSTRUCTIONS_PARAGRAPH_BACKGROUND;
style.padding = INSTRUCTIONS_PARAGRAPH_PADDING;
this.element.appendChild(element);
}
EVR.Instructions.prototype.toString = function()
{
return "[object EVR.Instructions]";
}