2011-08-02 05:34:47 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2011, Google Inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions of source code must retain the above copyright
|
2011-08-02 05:34:47 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions in binary form must reproduce the above
|
2011-08-02 05:34:47 +02:00
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Neither the name of Google Inc. nor the names of its
|
2011-08-02 05:34:47 +02:00
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
*/
|
2011-08-02 05:34:47 +02:00
|
|
|
|
|
|
|
Refine.FixedWidthParserUI = function(controller, jobID, job, format, config,
|
|
|
|
dataContainerElmt, progressContainerElmt, optionContainerElmt) {
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
this._controller = controller;
|
|
|
|
this._jobID = jobID;
|
|
|
|
this._job = job;
|
|
|
|
this._format = format;
|
|
|
|
this._config = config;
|
|
|
|
|
|
|
|
this._dataContainer = dataContainerElmt;
|
|
|
|
this._progressContainer = progressContainerElmt;
|
|
|
|
this._optionContainer = optionContainerElmt;
|
|
|
|
|
|
|
|
this._timerID = null;
|
|
|
|
this._initialize();
|
|
|
|
this.updatePreview();
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
Refine.DefaultImportingController.parserUIs["FixedWidthParserUI"] = Refine.FixedWidthParserUI;
|
|
|
|
|
|
|
|
Refine.FixedWidthParserUI.encodeSeparator = function(s) {
|
2011-08-04 22:37:14 +02:00
|
|
|
return s.replace("\\", "\\\\")
|
|
|
|
.replace("\n", "\\n")
|
|
|
|
.replace("\t", "\\t");
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.FixedWidthParserUI.decodeSeparator = function(s) {
|
2011-08-04 22:37:14 +02:00
|
|
|
return s.replace("\\n", "\n")
|
|
|
|
.replace("\\t", "\t")
|
|
|
|
.replace("\\\\", "\\");
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.FixedWidthParserUI.prototype.dispose = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
if (this._timerID != null) {
|
|
|
|
window.clearTimeout(this._timerID);
|
|
|
|
this._timerID = null;
|
|
|
|
}
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.FixedWidthParserUI.prototype.confirmReadyToCreateProject = function() {
|
|
|
|
return true; // always ready
|
|
|
|
};
|
|
|
|
|
|
|
|
Refine.FixedWidthParserUI.prototype.getOptions = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var options = {
|
2011-08-14 04:05:18 +02:00
|
|
|
columnWidths: this._getColumnWidths()
|
2011-08-04 22:37:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var columnNames = $.trim(this._optionContainerElmts.columnNamesInput[0].value).replace(/,\s+/g, ',').split(',');
|
|
|
|
if (columnNames.length > 0 && columnNames[0].length > 0) {
|
|
|
|
options.columnNames = columnNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (this._optionContainer.find("input[name='row-separator']:checked")[0].value) {
|
|
|
|
case 'new-line':
|
|
|
|
options.lineSeparator = "\n";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
options.lineSeparator = Refine.FixedWidthParserUI.decodeSeparator(
|
|
|
|
this._optionContainerElmts.rowSeparatorInput[0].value);
|
|
|
|
}
|
|
|
|
|
|
|
|
var parseIntDefault = function(s, def) {
|
|
|
|
try {
|
|
|
|
var n = parseInt(s);
|
|
|
|
if (!isNaN(n)) {
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore
|
2011-08-02 05:34:47 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
return def;
|
|
|
|
};
|
|
|
|
if (this._optionContainerElmts.ignoreCheckbox[0].checked) {
|
|
|
|
options.ignoreLines = parseIntDefault(this._optionContainerElmts.ignoreInput[0].value, -1);
|
|
|
|
} else {
|
|
|
|
options.ignoreLines = -1;
|
|
|
|
}
|
|
|
|
if (this._optionContainerElmts.headerLinesCheckbox[0].checked) {
|
|
|
|
options.headerLines = parseIntDefault(this._optionContainerElmts.headerLinesInput[0].value, 0);
|
|
|
|
} else {
|
|
|
|
options.headerLines = 0;
|
|
|
|
}
|
|
|
|
if (this._optionContainerElmts.skipCheckbox[0].checked) {
|
|
|
|
options.skipDataLines = parseIntDefault(this._optionContainerElmts.skipInput[0].value, 0);
|
|
|
|
} else {
|
|
|
|
options.skipDataLines = 0;
|
|
|
|
}
|
|
|
|
if (this._optionContainerElmts.limitCheckbox[0].checked) {
|
|
|
|
options.limit = parseIntDefault(this._optionContainerElmts.limitInput[0].value, -1);
|
|
|
|
} else {
|
|
|
|
options.limit = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
options.guessCellValueTypes = this._optionContainerElmts.guessCellValueTypesCheckbox[0].checked;
|
|
|
|
|
|
|
|
options.storeBlankRows = this._optionContainerElmts.storeBlankRowsCheckbox[0].checked;
|
|
|
|
options.storeBlankCellsAsNulls = this._optionContainerElmts.storeBlankCellsAsNullsCheckbox[0].checked;
|
|
|
|
options.includeFileSources = this._optionContainerElmts.includeFileSourcesCheckbox[0].checked;
|
|
|
|
|
|
|
|
return options;
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.FixedWidthParserUI.prototype._initialize = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._optionContainer.unbind().empty().html(
|
|
|
|
DOM.loadHTML("core", "scripts/index/parser-interfaces/fixed-width-parser-ui.html"));
|
|
|
|
this._optionContainerElmts = DOM.bind(this._optionContainer);
|
|
|
|
this._optionContainerElmts.previewButton.click(function() { self._updatePreview(); });
|
|
|
|
|
|
|
|
this._optionContainerElmts.columnWidthsInput[0].value = this._config.columnWidths.join(',');
|
|
|
|
if ('columnNames' in this._config) {
|
|
|
|
this._optionContainerElmts.columnNamesInput[0].value = this._config.columnNames.join(',');
|
|
|
|
}
|
|
|
|
|
|
|
|
var rowSeparatorValue = (this._config.lineSeparator == "\n") ? 'new-line' : 'custom';
|
|
|
|
this._optionContainer.find(
|
|
|
|
"input[name='row-separator'][value='" + rowSeparatorValue + "']").attr("checked", "checked");
|
|
|
|
this._optionContainerElmts.rowSeparatorInput[0].value =
|
|
|
|
Refine.FixedWidthParserUI.encodeSeparator(this._config.lineSeparator);
|
|
|
|
|
|
|
|
if (this._config.ignoreLines > 0) {
|
|
|
|
this._optionContainerElmts.ignoreCheckbox.attr("checked", "checked");
|
|
|
|
this._optionContainerElmts.ignoreInput[0].value = this._config.ignoreLines.toString();
|
|
|
|
}
|
|
|
|
if (this._config.headerLines > 0) {
|
|
|
|
this._optionContainerElmts.headerLinesCheckbox.attr("checked", "checked");
|
|
|
|
this._optionContainerElmts.headerLinesInput[0].value = this._config.headerLines.toString();
|
|
|
|
}
|
|
|
|
if (this._config.limit > 0) {
|
|
|
|
this._optionContainerElmts.limitCheckbox.attr("checked", "checked");
|
|
|
|
this._optionContainerElmts.limitInput[0].value = this._config.limit.toString();
|
|
|
|
}
|
|
|
|
if (this._config.skipDataLines > 0) {
|
|
|
|
this._optionContainerElmts.skipCheckbox.attr("checked", "checked");
|
|
|
|
this._optionContainerElmts.skipInput.value[0].value = this._config.skipDataLines.toString();
|
|
|
|
}
|
|
|
|
if (this._config.storeBlankRows) {
|
|
|
|
this._optionContainerElmts.storeBlankRowsCheckbox.attr("checked", "checked");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._config.guessCellValueTypes) {
|
|
|
|
this._optionContainerElmts.guessCellValueTypesCheckbox.attr("checked", "checked");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._config.storeBlankCellsAsNulls) {
|
|
|
|
this._optionContainerElmts.storeBlankCellsAsNullsCheckbox.attr("checked", "checked");
|
|
|
|
}
|
|
|
|
if (this._config.includeFileSources) {
|
|
|
|
this._optionContainerElmts.includeFileSourcesCheckbox.attr("checked", "checked");
|
|
|
|
}
|
|
|
|
|
|
|
|
var onChange = function() {
|
|
|
|
self._scheduleUpdatePreview();
|
|
|
|
};
|
|
|
|
this._optionContainer.find("input").bind("change", onChange);
|
|
|
|
this._optionContainer.find("select").bind("change", onChange);
|
2011-08-14 04:05:18 +02:00
|
|
|
};
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2011-08-14 04:05:18 +02:00
|
|
|
Refine.FixedWidthParserUI.prototype._getColumnWidths = function() {
|
|
|
|
var newColumnWidths = [];
|
|
|
|
var a = $.trim(this._optionContainerElmts.columnWidthsInput[0].value).replace(/,\s+/g, ',').split(',');
|
|
|
|
for (var i = 0; i < a.length; i++) {
|
|
|
|
var n = parseInt(a[i]);
|
|
|
|
if (!isNaN(n)) {
|
2011-08-04 22:37:14 +02:00
|
|
|
newColumnWidths.push(n);
|
2011-08-02 05:34:47 +02:00
|
|
|
}
|
2011-08-14 04:05:18 +02:00
|
|
|
}
|
|
|
|
return newColumnWidths;
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.FixedWidthParserUI.prototype._scheduleUpdatePreview = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
if (this._timerID != null) {
|
|
|
|
window.clearTimeout(this._timerID);
|
|
|
|
this._timerID = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
this._timerID = window.setTimeout(function() {
|
|
|
|
self._timerID = null;
|
|
|
|
self.updatePreview();
|
|
|
|
}, 500); // 0.5 second
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.FixedWidthParserUI.prototype.updatePreview = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._progressContainer.show();
|
|
|
|
|
|
|
|
var options = this.getOptions();
|
|
|
|
// for preview, we need exact text, so it's easier to show where the columns are split
|
|
|
|
options.guessCellValueTypes = false;
|
|
|
|
|
|
|
|
this._controller.updateFormatAndOptions(options, function(result) {
|
|
|
|
if (result.status == "ok") {
|
|
|
|
self._controller.getPreviewData(function(projectData) {
|
|
|
|
new Refine.FixedWidthPreviewTable(
|
|
|
|
self,
|
2011-08-14 04:05:18 +02:00
|
|
|
options,
|
2011-08-04 22:37:14 +02:00
|
|
|
projectData,
|
|
|
|
self._dataContainer
|
|
|
|
);
|
|
|
|
self._progressContainer.hide();
|
|
|
|
}, 20);
|
|
|
|
}
|
|
|
|
});
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.FixedWidthPreviewTable = function(parserUI, config, projectData, elmt) {
|
2011-08-04 22:37:14 +02:00
|
|
|
this._parserUI = parserUI;
|
|
|
|
this._config = config;
|
|
|
|
this._projectData = projectData;
|
|
|
|
this._elmt = elmt;
|
|
|
|
this._render();
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Refine.FixedWidthPreviewTable.prototype._render = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var scrollTop = this._elmt[0].scrollTop;
|
|
|
|
var scrollLeft = this._elmt[0].scrollLeft;
|
|
|
|
|
|
|
|
this._elmt.unbind().empty();
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
var container = $('<div>')
|
|
|
|
.addClass('fixed-width-preview-container')
|
|
|
|
.appendTo(this._elmt);
|
|
|
|
var table = $('<table>')
|
|
|
|
.addClass("data-table")
|
|
|
|
.addClass("fixed-width-preview-data-table")
|
|
|
|
.appendTo(container)[0];
|
|
|
|
|
|
|
|
var columns = this._projectData.columnModel.columns;
|
|
|
|
var columnWidths = [].concat(this._config.columnWidths);
|
2011-08-14 04:05:18 +02:00
|
|
|
var includeFileSources = this._config.includeFileSources;
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
var addCell = function(tr) {
|
|
|
|
var index = tr.cells.length;
|
|
|
|
var td = tr.insertCell(index);
|
|
|
|
td.className = (index % 2 == 0) ? 'even' : 'odd';
|
|
|
|
return td;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*------------------------------------------------------------
|
|
|
|
* Column Headers
|
|
|
|
*------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
var trHead = table.insertRow(table.rows.length);
|
|
|
|
$(addCell(trHead)).addClass("column-header").html(' '); // index
|
|
|
|
|
|
|
|
var createColumnHeader = function(column, index) {
|
|
|
|
var name = column.name;
|
2011-08-14 04:05:18 +02:00
|
|
|
var index2 = index - (includeFileSources ? 1 : 0);
|
|
|
|
if (index2 >= 0 && index2 < columnWidths.length) {
|
|
|
|
name = name.slice(0, columnWidths[index2]);
|
2011-08-02 05:34:47 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
$(addCell(trHead))
|
|
|
|
.addClass("column-header")
|
|
|
|
.text(name)
|
|
|
|
.attr('title', column.name);
|
|
|
|
};
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
createColumnHeader(columns[i], i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------
|
2011-08-14 04:05:18 +02:00
|
|
|
* Data Rows of Cells
|
2011-08-04 22:37:14 +02:00
|
|
|
*------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
var rows = this._projectData.rowModel.rows;
|
|
|
|
var renderRow = function(tr, r, row) {
|
|
|
|
var tdIndex = addCell(tr);
|
|
|
|
$('<div></div>').html((row.i + 1) + ".").appendTo(tdIndex);
|
|
|
|
|
|
|
|
var cells = row.cells;
|
|
|
|
for (var i = 0; i < columns.length; i++) {
|
|
|
|
var column = columns[i];
|
|
|
|
var td = addCell(tr);
|
|
|
|
var divContent = $('<div/>').addClass("data-table-cell-content").appendTo(td);
|
|
|
|
|
|
|
|
var cell = (column.cellIndex < cells.length) ? cells[column.cellIndex] : null;
|
|
|
|
if (!cell || ("v" in cell && cell.v === null)) {
|
|
|
|
$('<span>').html(" ").appendTo(divContent);
|
|
|
|
} else if ("e" in cell) {
|
|
|
|
$('<span>').addClass("data-table-error").text(cell.e).appendTo(divContent);
|
|
|
|
} else if (!("r" in cell) || !cell.r) {
|
|
|
|
if (typeof cell.v !== "string") {
|
|
|
|
if (typeof cell.v == "number") {
|
|
|
|
divContent.addClass("data-table-cell-content-numeric");
|
|
|
|
}
|
|
|
|
$('<span>')
|
|
|
|
.addClass("data-table-value-nonstring")
|
|
|
|
.text(cell.v)
|
|
|
|
.appendTo(divContent);
|
|
|
|
} else if (URL.looksLikeUrl(cell.v)) {
|
|
|
|
$('<a>')
|
|
|
|
.text(cell.v)
|
|
|
|
.attr("href", cell.v)
|
|
|
|
.attr("target", "_blank")
|
|
|
|
.appendTo(divContent);
|
|
|
|
} else {
|
|
|
|
$('<span>').text(cell.v).appendTo(divContent);
|
2011-08-02 05:34:47 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2011-08-02 05:34:47 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
for (var r = 0; r < rows.length; r++) {
|
|
|
|
var row = rows[r];
|
|
|
|
renderRow(table.insertRow(table.rows.length), r, row);
|
|
|
|
}
|
|
|
|
|
2011-08-14 04:05:18 +02:00
|
|
|
/*
|
|
|
|
* Measure font metrics.
|
|
|
|
*/
|
|
|
|
var pixelOffset = $(trHead.cells[includeFileSources ? 2 : 1]).position().left;
|
2011-08-04 22:37:14 +02:00
|
|
|
var testString = '01234567890123456789012345678901234567890123456789';
|
|
|
|
var testDiv = $('<div>')
|
|
|
|
.css('position', 'absolute')
|
|
|
|
.css('top', '-100px')
|
|
|
|
.text(testString)
|
|
|
|
.appendTo(container);
|
|
|
|
var pixelsPerChar = testDiv.width() / testString.length;
|
|
|
|
testDiv.remove();
|
|
|
|
|
2011-08-14 04:05:18 +02:00
|
|
|
/*
|
|
|
|
* Render column separators
|
|
|
|
*/
|
2011-08-04 22:37:14 +02:00
|
|
|
var columnSeparators = [];
|
|
|
|
var columnCharIndexes = [];
|
|
|
|
var positionColumnSeparator = function(outer, charIndex) {
|
|
|
|
outer.css('left',
|
|
|
|
Math.round(pixelOffset + charIndex * pixelsPerChar - DOM.getHPaddings(outer) / 2) + 'px');
|
|
|
|
};
|
|
|
|
var computeCharIndex = function(evt) {
|
|
|
|
var offset = evt.pageX - container.offset().left;
|
|
|
|
return Math.round((offset - pixelOffset) / pixelsPerChar);
|
|
|
|
};
|
|
|
|
var updatePreview = function() {
|
|
|
|
columnCharIndexes.sort(function(a, b) { return a - b; });
|
|
|
|
|
|
|
|
var newColumnWidths = [];
|
|
|
|
for (var i = 0; i < columnCharIndexes.length; i++) {
|
|
|
|
var charIndex = columnCharIndexes[i];
|
|
|
|
var columnWidth = (i == 0) ? charIndex : (charIndex - columnCharIndexes[i - 1]);
|
|
|
|
if (columnWidth > 0) {
|
|
|
|
newColumnWidths.push(columnWidth);
|
|
|
|
}
|
2011-08-02 05:34:47 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
self._parserUI._optionContainerElmts.columnWidthsInput[0].value = newColumnWidths.join(',');
|
|
|
|
self._parserUI.updatePreview();
|
|
|
|
};
|
|
|
|
|
|
|
|
var newSeparator = $('<div>')
|
|
|
|
.addClass('fixed-width-preview-column-separator-outer')
|
|
|
|
.append($('<div>').addClass('fixed-width-preview-column-separator-inner'))
|
|
|
|
.appendTo(container);
|
|
|
|
|
|
|
|
var createColumnSeparator = function(charIndex, index) {
|
|
|
|
columnCharIndexes[index] = charIndex;
|
|
|
|
|
|
|
|
var outer = $('<div>')
|
|
|
|
.addClass('fixed-width-preview-column-separator-outer')
|
|
|
|
.appendTo(container);
|
|
|
|
var inner = $('<div>')
|
|
|
|
.addClass('fixed-width-preview-column-separator-inner')
|
|
|
|
.appendTo(outer);
|
|
|
|
var close = $('<div>').appendTo(inner);
|
|
|
|
|
|
|
|
positionColumnSeparator(outer, charIndex);
|
|
|
|
|
|
|
|
outer.mouseover(function() {
|
|
|
|
newSeparator.hide();
|
|
|
|
})
|
|
|
|
.mouseout(function() {
|
|
|
|
newSeparator.show();
|
|
|
|
})
|
|
|
|
.mousedown(function() {
|
|
|
|
var mouseMove = function(evt) {
|
2011-08-02 05:34:47 +02:00
|
|
|
var newCharIndex = computeCharIndex(evt);
|
2011-08-04 22:37:14 +02:00
|
|
|
positionColumnSeparator(outer, newCharIndex);
|
|
|
|
|
|
|
|
evt.preventDefault();
|
|
|
|
evt.stopPropagation();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
var mouseUp = function(evt) {
|
|
|
|
container.unbind('mousemove', mouseMove);
|
|
|
|
container.unbind('mouseup', mouseUp);
|
|
|
|
|
|
|
|
var newCharIndex = computeCharIndex(evt);
|
|
|
|
positionColumnSeparator(outer, newCharIndex);
|
|
|
|
|
|
|
|
columnCharIndexes[index] = newCharIndex;
|
2011-08-02 05:34:47 +02:00
|
|
|
updatePreview();
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2011-08-02 05:34:47 +02:00
|
|
|
evt.preventDefault();
|
|
|
|
evt.stopPropagation();
|
|
|
|
return false;
|
2011-08-04 22:37:14 +02:00
|
|
|
};
|
|
|
|
container.bind('mousemove', mouseMove);
|
|
|
|
container.bind('mouseup', mouseUp);
|
|
|
|
});
|
|
|
|
|
|
|
|
close.click(function() {
|
|
|
|
columnCharIndexes[index] = index > 0 ? columnCharIndexes[index - 1] : 0;
|
|
|
|
updatePreview();
|
2011-08-02 05:34:47 +02:00
|
|
|
});
|
2011-08-04 22:37:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var charOffset = 0;
|
|
|
|
for (var i = 0; i < columnWidths.length; i++) {
|
|
|
|
var columnWidth = columnWidths[i];
|
|
|
|
createColumnSeparator(charOffset + columnWidth, i);
|
|
|
|
charOffset += columnWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
container
|
|
|
|
.mouseout(function(evt) {
|
|
|
|
newSeparator.hide();
|
|
|
|
})
|
|
|
|
.mousemove(function(evt) {
|
|
|
|
var offset = evt.pageX - container.offset().left;
|
|
|
|
var newCharIndex = Math.round((offset - pixelOffset) / pixelsPerChar);
|
|
|
|
positionColumnSeparator(newSeparator.show(), newCharIndex);
|
|
|
|
});
|
|
|
|
newSeparator.mousedown(function(evt) {
|
|
|
|
var newCharIndex = computeCharIndex(evt);
|
|
|
|
columnCharIndexes.push(newCharIndex);
|
|
|
|
updatePreview();
|
|
|
|
|
|
|
|
evt.preventDefault();
|
|
|
|
evt.stopPropagation();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
this._elmt[0].scrollTop = scrollTop;
|
|
|
|
this._elmt[0].scrollLeft = scrollLeft;
|
2011-08-02 05:34:47 +02:00
|
|
|
};
|