/*
 * DEXTUploadX5 - Application
 * http://www.dextsolution.com
 *
 * Copyright ⓒ DEXTSolution Inc.
 */
function initVariables() { var manager = window.parent.dx5; gbrowser = manager.browser;;   genvironment = manager.environment;   loadParameters(gdx5Parameter); if (!gdx5Parameter.lang || gdx5Parameter.lang == "auto") { gvector.lang = navigator.language || navigator.browserLanguage || navigator.systemLanguage; gvector.lang = gvector.lang ? gvector.lang.split("-")[0] : ""; } else { gvector.lang = gdx5Parameter.lang; }   gvector.elementId = gdx5Parameter.elementId; gvector.headerHeight = gDEF_HEADER_HEIGHT; gvector.fileItemHeight = gDEF_LSTITEM_HEIGHT;
gvector.uitype = "GRID"; gui = new ApplicationForm(); } function initUI() { svgh.replaceText(svgh.get("UIC-HEADER-TXT-FILE"), gRB.get("RB-LIST-MAIN-0001", "_파일"));       gui.createCustomColumn({ key: "size", display: gRB.get("RB-LIST-MAIN-0002", "_크기"), width: gDEF_SIZECOL_WIDTH, type: "text", headerAlign: "right", itemAlign: "right" });   gui.updateFilterInfo(); gui.updateCurrentFilesInfo(); gui.updateUI();   document.addEventListener("keydown", onFileItemKeyDownHandler, false);   svgh.get("XHTML-INPUT-FILES").addEventListener("change", function () { var success = registerLocalFiles(this.files);
  if (!success) { resetHtmlFiles(); } }, false); if (gbrowser.isChrome) {   svgh.get("XHTML-INPUT-FOLDER").addEventListener("change", function () {   var success = registerLocalFiles(this.files); if (!success) { resetHtmlFiles(); } }, false); }   var checker = svgh.get("UIC-HEADER-CHECKER"); if (checker) { svgh.get("UIC-HEADER-CHECKER-NOT").addEventListener("click", onFileCheckHandler, false); svgh.get("UIC-HEADER-CHECKER-CHK").addEventListener("click", onFileCheckHandler, false); }   var headerName = svgh.get("UIC-HEADER-NAME"); headerName.addEventListener("click", function (evt) {
if (!gvector.enableColumnSorting) return; if (evt.stopPropagation) evt.stopPropagation(); if (evt.preventDefault) evt.preventDefault(); if (gfileEngine.acting) {     errorOut("ESVG-00024", gRB.get("ESVG-00024", "_파일을 전송하고 있는 상태입니다.")); return; } else { sortByName(); } }, false);   var scroller = svgh.get("UIC-FILE-SCROLL-SECTION"); if (scroller) { svgh.get("UIC-FILE-SCROLL-UP").addEventListener("click", function (evt) { evt.stopPropagation(); evt.preventDefault(); if (gfileEngine.acting) {     errorOut("ESVG-00024", gRB.get("ESVG-00024", "_파일을 전송하고 있는 상태입니다.")); return;
} gui.scrollRegion("up"); }, false); svgh.get("UIC-FILE-SCROLL-DOWN").addEventListener("click", function (evt) { evt.stopPropagation(); evt.preventDefault(); if (gfileEngine.acting) {     errorOut("ESVG-00024", gRB.get("ESVG-00024", "_파일을 전송하고 있는 상태입니다.")); return; } gui.scrollRegion("down"); }, false); }   var scrollFrame = svgh.get("UIC-FILE-AREA"); if (gbrowser.isEdge) { window.addEventListener("wheel", onFileAreaWheelHandler, false); } else if (gbrowser.isFirefox) { scrollFrame.addEventListener("DOMMouseScroll", onFileAreaWheelHandler, false); } else {
scrollFrame.addEventListener("mousewheel", onFileAreaWheelHandler, false); } } function moveUpAndDown(index, isUp) {   if (index === (isUp ? 0 : gsortedList.length - 1)) return; var dindex = index + (isUp ? -1 : 1); var sid = gsortedList[index]; var did = gsortedList[dindex]; var parent = svgh.getAsUnit("UIC-FILE-AREA"); var sitem = parent.query(getIdSharp(sid, true)); var ditem = parent.query(getIdSharp(did, true));         if (isUp) parent.appendBefore(ditem, sitem.getNextSibling()); else parent.appendBefore(ditem, sitem);  
var tempY = sitem.att("y"); sitem.att("y", ditem.att("y")); ditem.att("y", tempY);   var tempA = gsortedList[index]; gsortedList[index] = gsortedList[dindex]; gsortedList[dindex] = tempA; } function preview(index, method) { var item = gfileEngine.ufiles.getItem(gsortedList[index]); var bgstr = hexColorToRgba(gvector.previewBgColor, 0.75); if (isImageFile(item.ofile) == false) { errorOut("ESVG-00073", gRB.get("ESVG-00073", "_미리보기에 유효하지 않은 형식입니다.")); return; } if (["image/jpeg", "image/pjpeg", "image/gif", "image/bmp", "image/x-windows-bmp", "image/png", "image/svg+xml"].indexOf(item.ofile.type.toLowerCase()) < 0) { errorOut("ESVG-00073", gRB.get("ESVG-00073", "_미리보기에 유효하지 않은 형식입니다."));
return; } var reader = new FileReader(); reader.onerror = function (evt) { errorOut("ESVG-00073", gRB.get("ESVG-00073", "_미리보기에 유효하지 않은 형식입니다.")); }; reader.onload = (function (t, i, m) { return function (evt) { dispatchDEXTX5Event("preview", createDEXTX5Event("preview", { id: gvector.elementId, itemIndex: i, itemId: t.id, method: m, itemSource: evt.target.result, backColor: bgstr })); }; })(item, index, method);   reader.readAsDataURL(item.ofile); } function getSelectedFirstSVGUnit(useDefault) { var target = null, uitems = null;
    if (gselectedList.length > 0) { target = svgh.getAsUnit(gselectedList[0]); } else if (useDefault === true) { uitems = svgh.queryAll("#UIC-FILE-AREA .css-item"); target = uitems.length > 0 ? new SVGUnit(uitems.item(0)) : null; } return target; } function getSelectedLastSVGUnit(useDefault) { var target = null, uitems = null;     if (gselectedList.length > 0) { target = svgh.getAsUnit(gselectedList[gselectedList.length - 1]); } else if (useDefault === true) { uitems = svgh.queryAll("#UIC-FILE-AREA .css-item"); target = uitems.length > 0 ? new SVGUnit(uitems.item(0)) : null;
} return target; } function getRelativeSVGUnit(basis, keyboard) { var target = null; var area = svgh.getAsUnit("UIC-FILE-AREA"); var ch = parseInt(area.att("height")); var step = Math.floor(ch / gvector.fileItemHeight) + 1;   if (keyboard == 40) { target = basis.element.nextSibling; }   else if (keyboard == 38) { target = basis.element.previousSibling; }   else if (keyboard == 35) { target = svgh.get(gsortedList[gsortedList.length - 1]); }   else if (keyboard == 36) { target = svgh.get(gsortedList[0]); }
  else if (keyboard == 34) { target = basis.element; for (var ncount = step; ncount > 0 && target; ncount--) { if (target.nextSibling && target.nextSibling.localName === "svg") { target = target.nextSibling; } else break; } }   else if (keyboard == 33) { target = basis.element; for (var ncount = step; ncount > 0 && target; ncount--) { if (target.previousSibling && target.previousSibling.localName === "svg") { target = target.previousSibling; } else break; } } return target != null ? new SVGUnit(target) : null; }
var CustomColumn = function () { this.key = ""; this.display = ""; this.width = 50; this.owidth = 50; this.type = "text"; this.items = {}; this.headerAlign = "center"; this.itemAlign = "center"; }; CustomColumn.prototype.getDisplayStringFromItem = function (f) { var v = this.key == "size" ? (f.size < 0 ? "" : getFriendlySize(f.size)) : f.meta[this.key]; if (!v) return "";   else return (this.type == "list") ? (this.items[v] || "") : (v || ""); }; CustomColumn.prototype.getDisplayStringFromValue = function (v) {  
return (this.type == "list") ? (this.items[v] || "") : (v || ""); }; var ApplicationForm = function () { this.uitype = "GRID"; this.helper = new SVGHelper(); this.uRoot = this.helper.getAsUnit("UIC-DEXTUPLOADX5-MAIN"); this.uMain = this.helper.getAsUnit("UIC-MAIN-AREA"); this.uFArea = this.helper.getAsUnit("UIC-FILE-AREA"); this.uJobTxt = this.helper.getAsUnit("UIC-JOB-WORKING-TXT"); this.uJobBk = this.helper.getAsUnit("UIC-JOB-WORKING-BK"); this.columns = {}; this.sortedColumnKeys = []; }; ApplicationForm.prototype.updateUI = function (basis) {  
if (!basis) basis = this.uRoot;   var size = basis.getComputedSize();   var area = this.uFArea, ch = area.att("height"), unit = gvector.fileItemHeight, uitems = svgh.queryAll("#UIC-FILE-AREA .css-item"), th = uitems.length * unit; if (ch < th) { gvector.vscrollbarWidth = 15; } else { gvector.vscrollbarWidth = 0; } this.uMain.updateLayout(size.w, size.h, gvector); }; ApplicationForm.prototype.displayJobWorking = function (msg) { this.uJobTxt.replaceText(msg); }; ApplicationForm.prototype.toggleJobWorking = function (show) { var enableFilterFx = (gbrowser.isFirefox || gbrowser.isSafari || gbrowser.isOpera);
if (enableFilterFx) { this.uFArea.att("filter", show ? "url(#UIS-BLURING-JOB)" : ""); } else { this.uJobBk.css("display", show ? "block" : "none"); } this.uJobTxt.replaceText("").css("display", show ? "block" : "none").att("fill", enableFilterFx ? "#000" : "#fff"); }; ApplicationForm.prototype.createUIItem = function (item) { var uitem = svgh.createUnit("svg", item.id, { "class": "css-item", x: 0, y: (gsortedList.length * gvector.fileItemHeight), width: "100%", "layout-dx5": "height:{fileItemHeight};" }); var ugroup = svgh.createUnit("g").into(uitem);
var utooltip = svgh.createUnit("title").append(svgh.mkTextNode(item.name)).into(ugroup); var uback = svgh.createUnit("rect").attp({ "class": "css-item-back", x: 0, y: 0, width: "100%", height: "100%" }).into(ugroup);   var uchkgroup = svgh.createUnit("g", item.id + "-CHECKER", { "class": "css-item-checker" }).into(ugroup); var uchknot = svgh.createUnit("use", item.id + "-CHECKER-NOT", { "style": "display:" + (item.checked ? "none" : "block"), "xlink:href": "#UIS-CHECKER", x: 7, width: 16, height: 16, "layout-dx5": "y:50%-8.5px;" }).into(uchkgroup); var uchkchk = svgh.createUnit("use", item.id + "-CHECKER-CHK", { "style": "display:" + (item.checked ? "block" : "none"), "xlink:href": "#UIS-CHECKER-CHKED", x: 7, width: 16, height: 16, "layout-dx5": "y:50%-8.5px;" }).into(uchkgroup);
if (gvector.checkerWidth === 0) uchkgroup.att("class", "hide", true); var uicon = svgh.createUnit("image").attp({ width: 18, height: 19, "layout-dx5": "x:8px+{checkerWidth}; y:50%-10px", "xlink:href": "../assets/icons/" + getIconFilename(item.name) }).into(ugroup);   var nameWidthFormat = "100%-32px-{opWidth}-{checkerWidth}-{columnTotWidth}", btnRunDisplay = false, btnDownDisplay = false; if (item.type == "VIRTUAL" && item.openUrl && gvector.openButtonVisible) { nameWidthFormat += "-20px"; btnRunDisplay = true; }
if (item.type == "VIRTUAL" && item.downUrl && gvector.downloadButtonVisible) { nameWidthFormat += "-20px"; btnDownDisplay = true; } var unamearea = svgh.createUnit("svg").attp({ "class": "css-item-name-svg", y: 0, height: "100%", "layout-dx5": "x:28px+{checkerWidth};width:" + nameWidthFormat + ";" }).into(ugroup); var ufname = svgh.createUnit("text").attp({ "class": "css-item-font-name css-item-font-color", x: 0, "layout-dx5": "y:{itemTextBaseline};" }).append(svgh.mkTextNode(item.name)).into(unamearea); var ubtnrun = svgh.createUnit("use", item.id + "-OPRUN", { "class": "css-item-op-run", style: "cursor:pointer;display:" + (btnRunDisplay ? "block" : "none"), "xlink:href": "#UIS-RUN", width: 16, height: 16, "layout-dx5": "x:100%-{opWidth}-{columnTotWidth}-40px; y:50%-8px;" }).into(ugroup);
var ubtndown = svgh.createUnit("use", item.id + "-OPDOWN", { "class": "css-item-op-down", style: "cursor:pointer;display:" + (btnDownDisplay ? "block" : "none"), "xlink:href": "#UIS-DOWNLOAD", width: 16, height: 16, "layout-dx5": "x:100%-{opWidth}-{columnTotWidth}-20px; y:50%-8px;" }).into(ugroup); var columns = svgh.createUnit("g", item.id + "-columns", { "class": "css-item-font-name css-item-font-color css-item-custom-columns" }).into(ugroup); var columnTotWidth = 0; for (var i = this.sortedColumnKeys.length - 1, column = null; i >= 0; i--) {  column = this.columns[this.sortedColumnKeys[i]];
columnTotWidth += column.width; this.addUIItemColumn(item, column, columnTotWidth, columns); } var ustatus = svgh.createUnit("use", item.id + "-STATUS", { width: 16, height: 16, "layout-dx5": "x:100%-{opWidth}+7px; y:50%-8px;" }).into(ugroup); if (item.lock === true) ustatus.att("xlink:href", "#UIS-LOCK"); else if (item.status == "DONE") ustatus.att("xlink:href", "#UIS-UPDONE"); else if (item.type == "FILE" && item.status == "WAIT") ustatus.att("xlink:href", "#UIS-UPWAIT"); else ustatus.att("xlink:href", "#UIS-VFWAIT");  
  svgh.createUnit("line", item.id + "-LN-OP").attp({ "class": "css-item-grid css-item-grid-color", y1: 0, y2: "100%", "shape-rendering": "crispEdges", "stroke-width": 1, "layout-dx5": "x1:100%-{opWidth}; x2:100%-{opWidth};" }).into(ugroup);   svgh.createUnit("line").attp({ "class": "css-item-grid css-item-grid-color", x1: 0, y1: "100%", x2: "100%", y2: "100%", "shape-rendering": "crispEdges", "stroke-width": 1.5 }).into(ugroup); ugroup.atto("dataItem", item).bind("click", onItemClickHandler, false);  
uchknot.atto("dataItem", item).bind("click", onFileCheckHandler, false); uchkchk.atto("dataItem", item).bind("click", onFileCheckHandler, false); ubtnrun.atto("dataItem", item).bind("click", onRunFileHandler, false); ubtndown.atto("dataItem", item).bind("click", onDownloadFileHandler, false); return uitem.element; }; ApplicationForm.prototype.updateUIItem = function (item) { var op = svgh.getAsUnit(item.id + "-STATUS");   if (op.element.correspondingUseElement) op = new SVGUnit(op.element.correspondingUseElement); if (item.lock === true) op.att("xlink:href", "#UIS-LOCK");
else if (item.status == "DONE") op.att("xlink:href", "#UIS-UPDONE"); else if (item.type == "FILE" && item.status == "WAIT") op.att("xlink:href", "#UIS-UPWAIT"); else op.att("xlink:href", "#UIS-VFWAIT");   var nameWidthFormat = "100%-32px-{opWidth}-{checkerWidth}", btnRunDisplay = false, btnDownDisplay = false; if (item.type == "VIRTUAL" && item.openUrl && gvector.openButtonVisible) { nameWidthFormat += "-20px"; btnRunDisplay = true; } if (item.type == "VIRTUAL" && item.downUrl && gvector.downloadButtonVisible) { nameWidthFormat += "-20px";
btnDownDisplay = true; } var uitem = svgh.getAsUnit(item.id);   svgh.getAsUnit(item.id).query(".css-item-name-svg").att("layout-dx5", "x:28px+{checkerWidth};width:" + nameWidthFormat + ";").updateLayout(uitem.getSVGWLen(), uitem.getSVGHLen(), gvector); svgh.getAsUnit(item.id + "-OPRUN").css("display", (item.type == "VIRTUAL" && item.openUrl) ? "block" : "none"); svgh.getAsUnit(item.id + "-OPDOWN").css("display", (item.type == "VIRTUAL" && item.downUrl) ? "block" : "none"); svgh.getAsUnit(item.id + "-LN-OP").css("display", (gvector.opWidth > 0 ? "block" : "none"));  
for (var i = this.sortedColumnKeys.length - 1, col = null, rtw = 0; i >= 0; i--) { col = this.columns[this.sortedColumnKeys[i]]; rtw += col.width; this.updateUIItemColumn(item, col, rtw);  } }; ApplicationForm.prototype.deleteUIItem = function (item) { var uitem = svgh.get(item.id); if (!uitem) return; var current = uitem, sibling = null, evtarget = null, cx = current.x.baseVal.value, cy = current.y.baseVal.value, sx = 0, sy = 0; while (current.nextSibling) { sibling = current.nextSibling; sx = sibling.x.baseVal.value; sy = sibling.y.baseVal.value;
sibling.x.baseVal.value = cx; sibling.y.baseVal.value = cy; cx = sx; cy = sy; current = sibling; } uitem.parentNode.removeChild(uitem); evtarget = uitem; if (evtarget) { evtarget.dataItem = null; evtarget.removeEventListener("click", onItemClickHandler); } evtarget = uitem.querySelector("#" + item.id + "-CHECKER"); if (evtarget) { evtarget.dataItem = null; evtarget.removeEventListener("click", onFileCheckHandler); } evtarget = uitem.querySelector("#" + item.id + "-OPRUN"); if (evtarget) { evtarget.dataItem = null; evtarget.removeEventListener("click", onRunFileHandler);
} evtarget = uitem.querySelector("#" + item.id + "-OPDOWN"); if (evtarget) { evtarget.dataItem = null; evtarget.removeEventListener("click", onDownloadFileHandler); } }; ApplicationForm.prototype.updateCurrentFilesInfo = function () { var cnt = gfileEngine.ufiles.length; var size = gfileEngine.ufiles.getTotalSize(false); var strCount = cnt == 0 ? "0 File" : cnt + " Files"; var strSize = size == 0 ? "0 Byte" : getFriendlySize(size); this.helper.getAsUnit("UIC-FOOTER-CURINFO").replaceText(strSize + " / " + strCount); };
ApplicationForm.prototype.updateFilterInfo = function () { var tokens = [], fsize = ""; if (gvector.maxFileCount >= 0) tokens.push(gvector.maxFileCount + (gvector.maxFileCount == 0 ? " File" : " Files")); if (gvector.minFileSize >= 0) fsize = getFriendlySize(gvector.minFileSize) + "~"; if (gvector.maxFileSize >= 0) tokens.push(fsize + getFriendlySize(gvector.maxFileSize)); else if (fsize) tokens.push(fsize); if (gvector.maxTotalSize >= 0) tokens.push(getFriendlySize(gvector.maxTotalSize) + "(A)"); this.helper.getAsUnit("UIC-FILTER-TXT").replaceText(tokens.length > 0 ? tokens.join(" / ") : gRB.get("RB-LIST-MAIN-0003", "_필터없음"));
}; ApplicationForm.prototype.updateHeaderChecker = function () { var fcount = 0, len = gfileEngine.ufiles.length; for (var i = 0, item = null; i < len; i++) { item = gfileEngine.ufiles[i]; fcount += (item.checked ? 1 : 0); } this.helper.getAsUnit("UIC-HEADER-CHECKER-NOT").css("display", (len > 0 && fcount == len) ? "none" : "block"); this.helper.getAsUnit("UIC-HEADER-CHECKER-CHK").css("display", (len > 0 && fcount == len) ? "block" : "none"); }; ApplicationForm.prototype.scrollRegion = function (action) {  
                  var area = this.uFArea, cw = area.att("width"), ch = area.att("height"), th = gsortedList.length * gvector.fileItemHeight, from = area.getYinViewbox(0), to = 0, temp = 0, frameId, isBelow; if (ch > th && from == 0) { return; } else if (ch > th && from != 0) { to = 0; isBelow = true; } else if (action == "up") {   temp = from - Math.floor(ch); to = temp < 0 ? 0 : temp; isBelow = false; } else if (action == "down") {   temp = from + Math.floor(ch); to = temp > (th - ch) ? th - ch : temp; isBelow = true;
} else return; if (from == to) return; function doScrollAnimation() { if ((isBelow && from > to) || (!isBelow && from < to)) { from = to; area.att("viewBox", "0 " + from + " " + cw + " " + ch); cancelAnimationFrame(frameId); } else { area.att("viewBox", "0 " + from + " " + cw + " " + ch);     from += (isBelow ? 1 : -1) * parseInt(ch * 0.20); frameId = requestAnimationFrame(doScrollAnimation); } } frameId = requestAnimationFrame(doScrollAnimation); }; ApplicationForm.prototype.scrollTo = function (elementIndex) {  
var area = this.uFArea, cw = area.att("width"), ch = area.att("height"), th = gsortedList.length * gvector.fileItemHeight, from = area.getYinViewbox(0), to = 0, unit = gvector.fileItemHeight,     dist = elementIndex, frameId, isBelow; if (ch > th && from == 0) { return; } else if (ch > th && from != 0) { to = 0; isBelow = true; } else { to = (dist * unit); to = to > (th - ch) ? th - ch : to; isBelow = from < to; } if (from === to) return;     if (Math.abs(from - to) <= 1000) { function doScrollAnimation() { if ((isBelow && from > to) || (!isBelow && from < to)) {
from = to; area.att("viewBox", "0 " + from + " " + cw + " " + ch); cancelAnimationFrame(frameId); } else { area.att("viewBox", "0 " + from + " " + cw + " " + ch); from += (isBelow ? 1 : -1) * parseInt(ch * 0.20); frameId = requestAnimationFrame(doScrollAnimation); } } frameId = requestAnimationFrame(doScrollAnimation); } else { area.att("viewBox", "0 " + to + " " + cw + " " + ch); } }; ApplicationForm.prototype.updateTotalCustomColumnWidth = function (width) { gvector.columnTotWidth = width; }; ApplicationForm.prototype.addUIColumn = function (column, rightWidth) {  
                    var encodedkey = column.key.replace(/\s/, "_"); var container = this.helper.getAsUnit("UIC-HEADER-COLUMNS");   var headerSVG = this.helper.createUnit("svg", "UIC-COLS-HEADER-SVG-" + encodedkey, { y: 0, width: column.width, height: "100%", "layout-dx5": "x:100%-{opWidth}-{vscrollbarWidth}-" + rightWidth, "data-column-key": column.key }).bind("click", onSortHeaderColumnHandler, false).into(container);   var headerRect = this.helper.createUnit("rect", "UIC-COLS-HEADER-BK-" + encodedkey).attp({ x: 0, y: 0, width: "100%", height: "100%" }).into(headerSVG); var headerText = this.helper.createUnit("text").into(headerSVG);
var btnArrowAsc = this.helper.createUnit("use", "UIC-COLS-SORT-BUTTON-ASC-" + encodedkey, { "class": "css-header-sort-button", "xlink:href": "#UIS-ARRANGE-ASC", width: 8, height: 8, "layout-dx5": "x:100%-10px;y:100%-10px;" }).hide().into(headerSVG); var btnArrowDsc = this.helper.createUnit("use", "UIC-COLS-SORT-BUTTON-DSC-" + encodedkey, { "class": "css-header-sort-button", "xlink:href": "#UIS-ARRANGE-DSC", width: 8, height: 8, "layout-dx5": "x:100%-10px;y:100%-10px;" }).hide().into(headerSVG);    
  var align = null, xlayout = null; if (column.headerAlign == "left") { align = "start"; xlayout = "x:4px"; } else if (column.headerAlign == "center") { align = "middle"; xlayout = "x:50%"; } else { align = "end"; xlayout = "x:100%-4px"; }  headerText.attp({ "class": "css-header-font-name css-header-font-color", "font-size": "12px", "font-weight": "bold", "text-anchor": align, "layout-dx5": xlayout + ";y:{headerTextBaseline}" }).append(svgh.mkTextNode(column.display)); var headerLine = this.helper.createUnit("line").attp({ x1: 0.5, x2: 0.5, y1: 0, y2: "100%", "shape-rendering": "crispEdges", "stroke": "#d8d8d8", "stroke-width": 1 }).into(headerSVG);  
for (var i = 0, len = gsortedList.length, item = null; i < len; i++) { item = gfileEngine.ufiles.getItem(gsortedList[i]); this.addUIItemColumn(item, column, rightWidth); } }; ApplicationForm.prototype.addUIItemColumn = function (item, column, rightWidth, container) {                  var encodedkey = column.key.replace(/\s/, "_");   var container = container || this.helper.getAsUnit(item.id + "-columns"); if (!container) return;   var evret = dispatchDEXTX5Event("columnDataBinding", createDEXTX5Event("columnDataBinding", { id: gvector.elementId, itemId: item.id, columnKey: column.key, columnValue: (item.meta.hasOwnProperty(column.key) ? item.meta[column.key] : null) }));  
if (evret.go) item.meta[column.key] = evret.value;   var itemString = column.getDisplayStringFromItem(item); var align = column.itemAlign == "left" ? "align_l" : (column.itemAlign == "center" ? "align_c" : "align_r"); var xlayout = column.itemAlign == "left" ? "x:4px" : (column.itemAlign == "center" ? "x:50%" : "x:100%-4px");   area = this.helper.createUnit("svg", item.id + "-columns-" + encodedkey, { y: 0, width: column.width, height: "100%", "layout-dx5": "x:100%-{opWidth}-" + rightWidth }).into(container); if (gbrowser.isIE) {
this.helper.createUnit("text").attp({ "class": align, "layout-dx5": xlayout + ";y:{itemTextBaseline}" }).into(area).append(svgh.mkTextNode(itemString)); } else { foreign = this.helper.createUnit("foreignObject").attp({ x: 0, y: 0, width: "100%", "layout-dx5": "height:{fileItemHeight}" }).into(area); div = this.helper.createNSUnit("http://www.w3.org/1999/xhtml", "div").att("class", align).into(foreign); div.element.innerHTML = itemString; }   this.helper.createUnit("line").attp({ "class": "css-item-grid css-item-grid-color", x1: 0.5, x2: 0.5, y1: 0, y2: "100%", "shape-rendering": "crispEdges", "stroke-width": 1 }).into(area); };
ApplicationForm.prototype.updateUIColumn = function (column, rightWidth) {    var hcolumn = this.helper.getAsUnit("UIC-COLS-HEADER-SVG-" + column.key.replace(/\s/, "_")).attp({ width: column.width, "layout-dx5": "x:100%-{opWidth}-{vscrollbarWidth}-" + rightWidth });       var align = null, xlayout = null; if (column.headerAlign == "left") { align = "start"; xlayout = "x:4px"; } else if (column.headerAlign == "center") { align = "middle"; xlayout = "x:50%"; } else { align = "end"; xlayout = "x:100%-4px"; }
hcolumn.query("text").attp({ "text-anchor": align, "layout-dx5": xlayout + ";y:{headerTextBaseline}" }).replaceText(column.display); for (var i = 0, len = gsortedList.length, item = null; i < len; i++) { item = gfileEngine.ufiles.getItem(gsortedList[i]); this.updateUIItemColumn(item, column, rightWidth); } }; ApplicationForm.prototype.updateUIItemColumn = function (item, column, rightWidth) { var encodedkey = column.key.replace(/\s/, "_"); var area = this.helper.getAsUnit(item.id + "-columns-" + encodedkey); if (!area) return;
  var evret = dispatchDEXTX5Event("columnDataBinding", createDEXTX5Event("columnDataBinding", { id: gvector.elementId, itemId: item.id, columnKey: column.key, columnValue: (item.meta.hasOwnProperty(column.key) ? item.meta[column.key] : null) }));   if (evret.go) item.meta[column.key] = evret.value;   var itemString = column.getDisplayStringFromItem(item); area.att("width", column.width).att("layout-dx5", "x:100%-{opWidth}-" + rightWidth); var align = column.itemAlign == "left" ? "align_l" : (column.itemAlign == "center" ? "align_c" : "align_r"); var xlayout = column.itemAlign == "left" ? "x:4px" : (column.itemAlign == "center" ? "x:50%" : "x:100%-4px");
if (gbrowser.isIE) { area.query("text").att("class", align).att("layout-dx5", xlayout + ";y:{itemTextBaseline}").replaceText(itemString); } else { area.query("foreignObject > div").att("class", align).element.innerHTML = itemString; } }; ApplicationForm.prototype.deleteUIColumn = function (column) { var hcolumn = this.helper.getAsUnit("UIC-COLS-HEADER-SVG-" + column.key.replace(/\s/, "_")); hcolumn.detach(); for (var i = 0, len = gsortedList.length, item = null; i < len; i++) { item = gfileEngine.ufiles.getItem(gsortedList[i]); this.deleteUIItemColumn(item, column);
} }; ApplicationForm.prototype.deleteUIItemColumn = function (item, column) { var encodedkey = column.key.replace(/\s/, "_"); var area = this.helper.getAsUnit(item.id + "-columns-" + encodedkey); area.detach(); }; ApplicationForm.prototype.createCustomColumn = function (format) {   var column = new CustomColumn(); column.key = format.key; column.display = format.display; column.owidth = column.width = !isDefined(format.width) ? 0 : format.width; if (isDefined(format.type)) column.type = format.type.toLowerCase(); if (column.type === "list" && format.items) {
for (var i = 0, len = format.items.length, c = null; i < len; i++) { c = format.items[i];   if (isDefined(c.display) && isDefined(c.value)) column.items[c.value.toString()] = c.display.toString(); } } if (isDefined(format.headerAlign)) column.headerAlign = format.headerAlign.toLowerCase(); if (isDefined(format.itemAlign)) column.itemAlign = format.itemAlign.toLowerCase();   this.columns[column.key] = column;   var fdx = this.sortedColumnKeys.indexOf(column.key);   var pos = !isDefined(format.position) ? 0 : format.position - 2;  
if (pos < 0) pos = 0;   else if (this.sortedColumnKeys.length <= pos) pos = fdx >= 0 ? this.sortedColumnKeys.length - 1 : this.sortedColumnKeys.length;   var tempKey = null;   var rightWidth = 0; if (fdx >= 0 && fdx == pos) { for (var i = this.sortedColumnKeys.length - 1; i >= 0; i--) { column = this.columns[this.sortedColumnKeys[i]]; rightWidth += column.width;   if (i <= pos) this.updateUIColumn(column, rightWidth); } } else if (fdx >= 0 && fdx < pos) {   for (var i = fdx; i < pos; i++) { tempKey = this.sortedColumnKeys[i + 1]; this.sortedColumnKeys[i] = tempKey;
}   this.sortedColumnKeys[pos] = column.key;  for (var i = this.sortedColumnKeys.length - 1; i >= 0; i--) { column = this.columns[this.sortedColumnKeys[i]]; rightWidth += column.width;   if (i <= pos) this.updateUIColumn(column, rightWidth); } } else if (fdx >= 0 && fdx > pos) {   for (var i = fdx; i > pos; i--) { tempKey = this.sortedColumnKeys[i - 1]; this.sortedColumnKeys[i] = tempKey; }   this.sortedColumnKeys[pos] = column.key; for (var i = this.sortedColumnKeys.length - 1; i >= 0; i--) { column = this.columns[this.sortedColumnKeys[i]]; rightWidth += column.width;
  if (i <= fdx) this.updateUIColumn(column, rightWidth); } } else {   this.sortedColumnKeys.splice(pos, 0, column.key); for (var i = this.sortedColumnKeys.length - 1; i >= 0; i--) { column = this.columns[this.sortedColumnKeys[i]]; rightWidth += column.width; if (i == pos) this.addUIColumn(column, rightWidth); else if (i < pos) this.updateUIColumn(column, rightWidth); } }   this.updateTotalCustomColumnWidth(rightWidth);   this.updateUI(); }; ApplicationForm.prototype.deleteCustomColumn = function (key) { if (!this.columns[key]) return;
    var fdx = this.sortedColumnKeys.indexOf(key); var rightWidth = 0; for (var i = this.sortedColumnKeys.length - 1, column = null; i >= 0; i--) {   column = this.columns[this.sortedColumnKeys[i]];   if (i == fdx) this.deleteUIColumn(column); else {   rightWidth += column.width; if (i < fdx) this.updateUIColumn(column, rightWidth); } }   this.columns[key] = null; this.sortedColumnKeys.splice(fdx, 1);   this.updateTotalCustomColumnWidth(rightWidth);   this.updateUI(); }; ApplicationForm.prototype.getAllItems = function () { return Array.from(this.uFArea.element.querySelectorAll(".css-item"));
}; ApplicationForm.prototype.clearAllItems = function () { var parent = this.uFArea.element;   while (parent.childNodes.length > 1 && parent.lastChild.nodeName == "svg") { parent.removeChild(parent.lastChild); } }; ApplicationForm.prototype.attachItem = function (item, index) { new SVGUnit(item).att("y", index * gvector.fileItemHeight).into(this.uFArea); }; ApplicationForm.prototype.toggleColumnVisible = function (key, visible) { if (key == "op") { var nwidth = visible ? gDEF_OPCOL_WIDTH : 0;   if (nwidth != gvector.opWidth) { gvector.opWidth = nwidth;
for (var i = 0, len = gsortedList.length, item = null; i < len; i++) { item = gfileEngine.ufiles.getItem(gsortedList[i]); this.updateUIItem(item); } this.updateUI(); } } else if (this.sortedColumnKeys.indexOf(key) >= 0) { var rightWidth = 0; for (var i = this.sortedColumnKeys.length - 1, pos = -1; i >= 0; i--) { column = this.columns[this.sortedColumnKeys[i]]; if (column.key == key) { pos = i; column.width = visible ? column.owidth : 0; } rightWidth += column.width;   if (i <= pos) this.updateUIColumn(column, rightWidth); }
this.updateTotalCustomColumnWidth(rightWidth); this.updateUI(); } }; 