function DesignText(strName)
{
this.name = strName;
function $(id)
{
return document.getElementById(id);
}
function string()
{
var list = new Array();
for(var i=0; i<arguments.length; i++)
list.push(arguments[i])
return list.join("");
}
this.MaxFontSize = 100;
this.ActiveObj = null;
this.ActiveType = null;
this.ActiveOver = null;
this.IsSet = true;
this.StyleName = "";
this.Index = 101;
this.sx = 0;
this.sy = 0;
this.px = 0;
this.py = 0;
this.IsDown = 0;
var _this = this;
DesignText.prototype.Init = function()
{
this.DivPage = $("divPage");
this.ChooseFontName = $("droChooseFont");
this.FontSizeTextBox = $("txt_fontsize");
this.ControlBox = $("divControlBox");
this.DesignBox = $("divDesignBox");
this.ComFrame = $("sysdiv_com_frame");
this.InputBox = $("txt_input");
this.DesignInfo = $("hidd_design_info");
this.ImageList = $("hidd_images_ids");
if (this.ImageList.value != "") {
var list = this.ImageList.value.split(';');
this.DesignBox.style.backgroundImage = string('url(', string("../AttachFiles/UserPhoto/temp/thumb/", list[0], "_2.jpg"), ')');
}
this.DesignBox.style.width = "180px";
this.DesignBox.style.height = "186px";
this.FontSize = 12;
this.FontSizeTextBox.value = this.FontSize;
this.dn_parseDesignInfo();
this.dn_setControlState(false);
this.ChooseFontName.onchange = function(e) {
e = window.event || e;
_this.dn_chooseFontName(e);
}
for(var i=1; i<= 10; i++) {
var obj = $(string("imgColor_", i));
obj.onclick = function(e) {
e = window.event || e;
_this.dn_setFontColor(e);
}
}
$("imgAlignLeft").onclick = function(e) {
e = window.event || e;
_this.dn_setAlign(e, "left");
}
$("imgAlignCenter").onclick = function(e) {
e = window.event || e;
_this.dn_setAlign(e, "center");
}
$("imgAlignRight").onclick = function(e) {
e = window.event || e;
_this.dn_setAlign(e, "right");
}
$("imgFontBold").onclick = function(e) {
e = window.event || e;
_this.dn_setFontBold(e);
}
$("imgFontItalic").onclick = function(e) {
e = window.event || e;
_this.dn_setFontItalic(e);
}
$("imgFontUnderline").onclick = function(e) {
e = window.event || e;
_this.dn_setFontUnderline(e);
}
$("imgFontSizePlus").onclick = function(e) {
e = window.event || e;
_this.dn_setFontSizePlus(e);
}
$("imgFontSizeMinus").onclick = function(e) {
e = window.event || e;
_this.dn_setFontSizeMinus(e);
}
this.FontSizeTextBox.onfocus = function(e) {
e = window.event || e;
_this.dn_txt_fontsize_onfocus(e);
}
this.FontSizeTextBox.onchange = function(e) {
e = window.event || e;
_this.dn_txt_fontsize_onchange(e);
}
this.FontSizeTextBox.onblur = function(e) {
e = window.event || e;
_this.dn_txt_fontsize_onblur(e);
}
this.ControlBox.onmousedown = function(e) {
e = window.event || e;
_this.dn_cbox_onmousedown(e);
}
this.ControlBox.onmouseover = function(e) {
e = window.event || e;
_this.dn_cbox_onmouseover(e);
}
this.ControlBox.onmouseout = function(e) {
e = window.event || e;
_this.dn_cbox_onmouseout(e);
}
this.ControlBox.onmouseup = function(e) {
e = window.event || e;
_this.dn_cbox_onmouseup(e);
}
this.DesignBox.onmousedown = function(e) {
e = window.event || e;
_this.dn_dbox_onmousedown(e);
}
this.DesignBox.onmousemove = function(e) {
e = window.event || e;
_this.dn_dbox_onmousemove(e);
}
this.DesignBox.onmouseup = function(e) {
e = window.event || e;
_this.dn_dbox_onmouseup(e);
}
this.InputBox.onblur = function(e) {
e = window.event || e;
_this.dn_inputbox_onblur(e);
}
this.InputBox.onpaste = function(e) {
e = window.event || e;
_this.dn_inputbox_onpaste(e);
}
this.InputBox.onkeyup = function(e) {
e = window.event || e;
_this.dn_inputbox_onkeyup(e);
}
loadColorControl();
}
DesignText.prototype.dn_parseDesignInfo = function()
{
if (this.DesignInfo.value != "") {
var o = eval(this.DesignInfo.value);
if (o.length > 0) {
for(var i=0; i<o.length; i++)
this.dn_createLabel(o[i]);
}
}
}
DesignText.prototype.dn_getActiveFrame = function(obj)
{
if (obj == null) {return null;}
if (obj.id != "")
return obj;
else
return this.dn_getActiveFrame(obj.parentElement);
}
DesignText.prototype.dn_cbox_onmousedown = function(e)
{
var o = e.srcElement || e.target;
var obj = this.dn_getActiveFrame(o);
if (obj != this.ControlBox) {
this.ActiveType = obj;
this.dn_setDownStyle(obj);
if (obj.id == "divLabel")
this.dn_Label();
else if (obj.id == "divDelete") {
if (this.ActiveObj != null) {
if (window.confirm("Are you sure you want to delete the selected Label?"))
this.dn_deleteControl(this.ActiveObj);
else {
this.dn_setNoneStyle(this.ActiveOver);
this.ActiveType = null;
this.ActiveOver = null;
}
}
else {
alert("Please select the Label you want to delete!");
this.dn_setNoneStyle(this.ActiveOver);
this.ActiveType = null;
this.ActiveOver = null;
}
}
}
}
DesignText.prototype.dn_cbox_onmouseover = function(e)
{
var o = e.srcElement || e.target;
var obj = this.dn_getActiveFrame(o);
if (obj != this.ControlBox) {
if (this.ActiveType != obj) {
this.ActiveOver = obj;
this.dn_setOverStyle(obj);
}
}
}
DesignText.prototype.dn_cbox_onmouseout = function(e)
{
if (this.ActiveOver != null && this.ActiveOver != this.ActiveType) {
this.dn_setNoneStyle(this.ActiveOver);
this.ActiveOver = null;
}
}
DesignText.prototype.dn_cbox_onmouseup = function(e)
{
if (this.ActiveType != null) {
this.dn_setNoneStyle(this.ActiveType);
this.ActiveType = null;
}
}
DesignText.prototype.dn_dbox_onmousemove = function(e)
{
if(e.pageX) {
var x = e.pageX + window.pageXOffset;
var y = e.pageY + window.pageYOffset;
}
else if(e.clientX) {
var x = e.clientX + document.body.scrollLeft;
var y = e.clientY + document.body.scrollTop;
}
var obj = e.srcElement || e.target;
if (this.IsDown == 1) {
if (this.ActiveFrame != null)
this.dn_setControlResize(this.ActiveFrame, this.ActiveObj, x - this.sx, y - this.sy);
else if (this.ActiveObj != null)
this.dn_setControlPos(this.ActiveObj, x - this.sx, y - this.sy);
}
}
DesignText.prototype.dn_dbox_onmousedown = function(e)
{
if(e.pageX) {
var x = e.pageX + window.pageXOffset;
var y = e.pageY + window.pageYOffset;
}
else if(e.clientX) {
var x = e.clientX + document.body.scrollLeft;
var y = e.clientY + document.body.scrollTop;
}
this.sx = x;
this.sy = y;
var obj = e.srcElement || e.target;
this.IsDown = 1;
var objStand = this.dn_getStandardControl(obj);
if (objStand != null) {
if (objStand != this.ActiveObj && this.ActiveObj != null)
this.dn_deleteFrame(this.ActiveObj);
this.ActiveObj = objStand;
if (obj.ensort != "visibleframe") {
this.dn_createFrame(this.ActiveObj);
this.dn_setControlState(true, this.ActiveObj.innerHTML);
this.dn_parseStyle(this.ActiveObj);
this.ActiveObj.setCapture();
}
else {
this.ActiveObj = objStand;
this.ActiveFrame = obj;
this.ActiveFrame.setCapture();
}
if (this.ActiveObj != null) {
this.px = this.ActiveObj.offsetLeft;
this.py = this.ActiveObj.offsetTop;
this.ActiveObj.initWidth = this.ActiveObj.offsetWidth;
this.ActiveObj.initHeight = this.ActiveObj.offsetHeight;
}
}
else if (this.ActiveObj != null) {
if (!this.IsSet && this.StyleName != "") {
if (this.StyleName == "fontSize")
this.dn_setStyle(this.StyleName, this.FontSizeTextBox.value);
}
this.dn_setControlState(false, "");
this.dn_deleteFrame(this.ActiveObj);
}
}
DesignText.prototype.dn_dbox_onmouseup = function()
{
if (this.ActiveObj != null) {
this.ActiveObj.releaseCapture();
}
if (this.ActiveFrame != null) {
this.ActiveFrame.releaseCapture();
this.ActiveFrame = null;
}
this.IsDown = 0;
}
DesignText.prototype.dn_inputbox_onblur = function(e)
{
var obj = e.srcElement || e.target;
if (this.ActiveObj != null && obj.value == "")
this.dn_deleteControl(this.ActiveObj);
}
DesignText.prototype.dn_inputbox_onpaste = function(e)
{
if (this.ActiveObj != null) {
this.ActiveObj.innerHTML = clipboardData.getData('text');
this.dn_setFramePanelSize(this.dn_getFramePanel(this.ActiveObj.id), this.ActiveObj.offsetWidth, this.ActiveObj.offsetHeight);
}
}
DesignText.prototype.dn_inputbox_onkeyup = function(e)
{
var obj = e.srcElement || e.target;
if (this.ActiveObj != null) {
this.ActiveObj.innerHTML = obj.value;
this.dn_setFramePanelSize(this.dn_getFramePanel(this.ActiveObj.id), this.ActiveObj.offsetWidth, this.ActiveObj.offsetHeight);
}
}
DesignText.prototype.dn_setControlState = function(bSta, value)
{
this.InputBox.readOnly = !bSta;
this.FontSizeTextBox.readOnly = !bSta;
this.ChooseFontName.disabled = !bSta;
if (value != null)
this.InputBox.value = value;
if (bSta) {
this.InputBox.style.backgroundColor = "#FFFFFF";
this.FontSizeTextBox.style.backgroundColor = "#FFFFFF";
this.ChooseFontName.style.backgroundColor = "#FFFFFF";
}
else {
this.InputBox.style.backgroundColor = "#e0e0e0";
this.FontSizeTextBox.style.backgroundColor = "#e0e0e0";
this.ChooseFontName.style.backgroundColor = "#e0e0e0";
}
}
DesignText.prototype.dn_parseStyle = function(obj)
{
this.ChooseFontName.value = obj.style.fontFamily;
this.FontSizeTextBox.value = obj.style.fontSize.replace(/[^\d]/gi, "");
}
DesignText.prototype.dn_setOverStyle = function(obj)
{
obj.style.borderLeft = "solid 1px #ffffff";
obj.style.borderTop = "solid 1px #ffffff";
obj.style.borderRight = "solid 1px #808080";
obj.style.borderBottom = "solid 1px #808080";
}
DesignText.prototype.dn_setDownStyle = function(obj)
{
obj.style.borderLeft = "solid 1px #808080";
obj.style.borderTop = "solid 1px #808080";
obj.style.borderRight = "solid 1px #ffffff";
obj.style.borderBottom = "solid 1px #ffffff";
}
DesignText.prototype.dn_setNoneStyle = function(obj)
{
obj.style.borderLeft = "none";
obj.style.borderTop = "none";
obj.style.borderRight = "none";
obj.style.borderBottom = "none";
}
DesignText.prototype.dn_Label = function()
{
var o = new Object();
if (this.ActiveObj != null)
this.dn_deleteFrame(this.ActiveObj);
var L = 0;
var T = 0;
var r = parseInt(Math.random()*1000000);
o.ID = string("lab_", r);
o.Style = string("z-index: ", this.Index, "; position: absolute; display: inline; cursor: pointer; font-size: ", this.FontSizeTextBox.value, "pt; font-family: ", this.ChooseFontName.value, "; border-left: none; border-top: none; border-right: none; border-bottom: none; left: ", L, "px; top: ", T, "px");
o.Text = "Label";
this.ActiveObj = this.dn_createLabel(o);
this.dn_createFrame(this.ActiveObj);
this.dn_setControlState(true, "Label");
this.Index++;
}
DesignText.prototype.dn_createLabel = function(o)
{
var obj = document.createElement("DIV");
obj.id = o.ID;
obj.style.cssText = o.Style;
obj.ms_positioning = "FlowLayout";
obj.innerHTML = o.Text;
obj.ensort = "label";
this.DesignBox.appendChild(obj);
this.Index = obj.style.zIndex + 1;
return obj;
}
DesignText.prototype.dn_deleteControl = function(obj)
{
this.dn_setControlState(false);
this.dn_deleteFrame(obj);
obj.parentElement.removeChild(obj);
}
DesignText.prototype.dn_getStandardControl = function(obj)
{
if (obj.ensort == "hiddentd") {
var objPanel = obj.parentElement.parentElement.parentElement.parentElement;
return $(objPanel.id.toString().substring(3, objPanel.id.length - 6));
}
else if(obj.ensort == "visibleframe") {
var objPanel = obj.parentElement.parentElement.parentElement.parentElement.parentElement;
return $(objPanel.id.toString().substring(3, objPanel.id.length - 6));
}
else {
if (obj.standard != null)
return $(obj.standard);
else if (obj.id != "" && obj != this.DesignBox)
return obj;
else
return null;
}
}
DesignText.prototype.dn_createFrame = function(obj)
{
var strId = string("sys", obj.id, "_panel");
var _obj = $(strId);
if (_obj != null)
this.DesignBox.removeChild(_obj);
var objPanel = this.ComFrame.cloneNode(true);
objPanel.id = strId;
objPanel.standard = obj.id;
objPanel.style.zIndex = 90000;
this.dn_setFramePanelPos(objPanel, obj.offsetLeft - 7, obj.offsetTop - 7);
this.dn_setFramePanelSize(objPanel, obj.offsetWidth, obj.offsetHeight);
this.DesignBox.appendChild(objPanel);
obj.oldIndex = obj.style.zIndex;
obj.style.zIndex = 900001;
}
DesignText.prototype.dn_deleteFrame = function(obj)
{
var objPanel = this.dn_getFramePanel(obj.id);
if (objPanel != null)
objPanel.parentElement.removeChild(objPanel);
if (obj.oldIndex != null)
obj.style.zIndex = obj.oldIndex;
else
obj.style.zIndex = 101;
this.ActiveObj = null;
}
DesignText.prototype.dn_setControlPos = function(obj, x_diff, y_diff)
{
var x = this.px + x_diff;
var y = this.py + y_diff;
if (x >= 0 && x <= this.DesignBox.offsetWidth - obj.offsetWidth)
obj.style.left = string(x, "px");
if (y >= 0 && y <= this.DesignBox.offsetHeight - obj.offsetHeight)
obj.style.top = string(y, "px");
this.dn_setFramePanelPos(this.dn_getFramePanel(obj.id), obj.offsetLeft - 7, obj.offsetTop - 7);
}
DesignText.prototype.dn_getFramePanel = function(id)
{
return $(string("sys", id, "_panel"));
}
DesignText.prototype.dn_setFramePanelPos = function(obj, left, top)
{
try {
obj.style.left = string(left, "px");
obj.style.top = string(top, "px");
}
catch(e){}
}
DesignText.prototype.dn_setFramePanelSize = function(obj, width, height)
{
try {
obj.style.width = string(width + 14, "px");
obj.style.height = string(height + 14, "px");
obj.childNodes[0].childNodes[0].childNodes[1].childNodes[1].style.width = string(width, "px");
obj.childNodes[0].childNodes[0].childNodes[1].childNodes[1].style.height = string(height, "px");
}
catch(e){}
}
DesignText.prototype.dn_setBatchResize = function(isLeft, isTop, x_diff, y_diff)
{
var obj = this.ActiveObj;
if(isLeft)
obj.style.left = string(this.px - x_diff, "px");
if(isTop)
obj.style.top = string(this.py - y_diff, "px");
obj.style.width = string(obj.initWidth + x_diff, "px");
obj.style.height = string(obj.initHeight + y_diff, "px");
var objPanel = this.dn_getFramePanel(obj.id);
this.dn_setFramePanelPos(objPanel, obj.offsetLeft - 7, obj.offsetTop - 7);
this.dn_setFramePanelSize(objPanel, obj.offsetWidth, obj.offsetHeight);
}
DesignText.prototype.dn_setControlResize = function(objFrame, objStand, x_diff, y_diff)
{
if(objStand == null){return;}
var w_init = objStand.initWidth;
var h_init = objStand.initHeight;
switch (objFrame.frametype) {
case "se": {//左上
if (w_init + (-x_diff) >= 2 && h_init + (-y_diff) >= 2)
this.dn_setBatchResize(true, true, -x_diff, -y_diff);
break;
}
case "ss": {//中上
if(h_init + (-y_diff) >= 2)
this.dn_setBatchResize(false, true, -1, -y_diff);
break;
}
case "sw": {//右上
if (w_init + x_diff >= 2 && h_init + (-y_diff) >= 2)
this.dn_setBatchResize(false, true, x_diff, -y_diff);
break;
}
case "ww": {//右中
if (w_init + x_diff >= 2)
this.dn_setBatchResize(false, false, x_diff, -1);
break;
}
case "nw": {//右下
if (w_init + x_diff >= 2 && h_init + y_diff >= 2)
this.dn_setBatchResize(false, false, x_diff, y_diff);
break;
}
case "nn": {//中下
if (h_init + y_diff >= 2)
this.dn_setBatchResize(false, false, -1, y_diff);
break;
}
case "ne": {//左下
if (w_init + (-x_diff) >= 2 && h_init + y_diff >= 2)
this.dn_setBatchResize(true, false, -x_diff, y_diff);
break;
}
case "ee": {//左中
if (w_init + (-x_diff) >= 2)
this.dn_setBatchResize(true, false, -x_diff, -1);
break;
}
}
}
DesignText.prototype.dn_getCursorPos = function(obj)
{
var s = "@#%#^&#*$";
obj.focus();
rng = document.selection.createRange();
rng.text = s;
var n = obj.value.indexOf(s);
rng.moveStart("character", -s.length);
rng.text = "";
return n;
}
DesignText.prototype.dn_chooseFontName = function(e)
{
var obj = e.srcElement || e.target;
if (this.ActiveObj != null) {
this.dn_setStyle("fontFamily", obj.value, true);
}
}
DesignText.prototype.dn_changeFontMoreColor = function()
{
if (this.ActiveObj != null) {
var o = callColorDialog(this.ActiveObj.style.color);
this.dn_setStyle("color", convertColorToHex(o));
}
else
callColorDialog();
}
DesignText.prototype.dn_setFontColor = function(e)
{
var obj = e.srcElement || e.target;
this.dn_setStyle("color", obj.currentStyle.backgroundColor);
}
DesignText.prototype.dn_setAlign = function(e, value)
{
this.dn_setStyle("textAlign", value, true);
}
DesignText.prototype.dn_setFontBold = function(e)
{
if (this.ActiveObj != null) {
var bold = (this.ActiveObj.style.fontWeight != "bold"? "bold" : "");
this.dn_setStyle("fontWeight", bold, true);
}
}
DesignText.prototype.dn_setFontItalic = function(e)
{
if (this.ActiveObj != null) {
var italic = (this.ActiveObj.style.fontStyle != "italic"? "italic" : "");
this.dn_setStyle("fontStyle", italic, true);
}
}
DesignText.prototype.dn_setFontUnderline = function(e)
{
if (this.ActiveObj != null) {
this.ActiveObj.style.textDecorationUnderline = (!this.ActiveObj.style.textDecorationUnderline? true : false);
}
}
DesignText.prototype.dn_setFontSizePlus = function(e)
{
var obj = e.srcElement || e.target;
if (this.ActiveObj != null) {
var fontSize = parseInt(this.FontSizeTextBox.value);
if (fontSize < this.MaxFontSize) {
this.FontSize = fontSize + 1;
this.FontSizeTextBox.value = this.FontSize;
this.dn_setStyle("fontSize", string(this.FontSize, "pt"), true);
}
}
}
DesignText.prototype.dn_setFontSizeMinus = function(e)
{
var obj = e.srcElement || e.target;
if (this.ActiveObj != null) {
var fontSize = parseInt(this.FontSizeTextBox.value);
if (fontSize > 1) {
this.FontSize = fontSize - 1;
this.FontSizeTextBox.value = this.FontSize;
this.dn_setStyle("fontSize", string(this.FontSize, "pt"), true);
}
}
}
DesignText.prototype.dn_txt_fontsize_onfocus = function()
{
this.IsSet = false;
this.StyleName = "fontSize";
}
DesignText.prototype.dn_txt_fontsize_onchange = function()
{
if (this.FontSizeTextBox.value != "") {
var s = this.FontSizeTextBox.value.replace(/[^\d\.]/gi, "");
if (s != "") {
var size = Round(Number(s), 0);
if (size >= 1 && size <= this.MaxFontSize) {
this.FontSize = size;
this.FontSizeTextBox.value = size;
this.dn_setStyle("fontSize", string(size, "pt"), true);
}
else
this.FontSizeTextBox.value = this.FontSize;
}
else
this.FontSizeTextBox.value = this.FontSize;
}
else
this.FontSizeTextBox.value = this.FontSize;
}
DesignText.prototype.dn_txt_fontsize_onblur = function()
{
if (this.FontSizeTextBox.value == "")
this.FontSizeTextBox.value = this.FontSize;
}
DesignText.prototype.dn_setStyle = function(name, value, bSta)
{
if (this.ActiveObj != null) {
eval(string('_this.ActiveObj.style.', name, ' = "', value, '";'));
if (bSta)
this.dn_setFramePanelSize(this.dn_getFramePanel(this.ActiveObj.id), this.ActiveObj.offsetWidth, this.ActiveObj.offsetHeight);
this.IsSet = true;
this.StyleName = "";
}
}
DesignText.prototype.dn_getDesignLabel = function()
{
if (this.DesignBox.childNodes.length > 0) {
var list = new Array();
for(var i=0; i<this.DesignBox.childNodes.length; i++) {
var obj = this.DesignBox.childNodes[i];
if (obj.ensort == "label") {
list.push('{');
list.push(string('ID:"', obj.id, '",'));
list.push(string('Text:"', obj.innerHTML, '",'));
list.push(string('Style:"', obj.style.cssText, '"'));
list.push('},');
}
}
var s = list.join("");
if (s != "") {
s = s.substring(0, s.length - 1);
return string("[", s, "]");
}
}
return "";
}
DesignText.prototype.dn_setNextStep = function()
{
this.DesignInfo.value = this.dn_getDesignLabel();
$('btn_next_step').onclick();
}
}