Skip to content

Commit

Permalink
Resize title column to fit text.
Browse files Browse the repository at this point in the history
  • Loading branch information
dteviot committed Sep 28, 2016
1 parent c7bf110 commit f9c16af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 13 additions & 1 deletion plugin/js/ChapterUrlsUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ChapterUrlsUI {
ChapterUrlsUI.getApplyChangesButton().onclick = this.setTableMode.bind(this);
}

populateChapterUrlsTable(chapters) {
populateChapterUrlsTable(chapters, userPreferences) {
ChapterUrlsUI.clearChapterUrlsTable();
let linksTable = ChapterUrlsUI.getChapterUrlsTable();
chapters.forEach(function (chapter) {
Expand All @@ -24,6 +24,7 @@ class ChapterUrlsUI {
ChapterUrlsUI.appendColumnDataToRow(row, chapter.sourceUrl);
linksTable.appendChild(row);
});
ChapterUrlsUI.resizeTitleColumnToFit(linksTable, userPreferences.alwaysOpenAsTab);
}

static clearChapterUrlsTable() {
Expand Down Expand Up @@ -117,6 +118,17 @@ class ChapterUrlsUI {
row.appendChild(col);
}

/** @private */
static resizeTitleColumnToFit(linksTable, openAsTab) {
let inputs = util.getElements(linksTable, "input", i => i.type === "text");
let width = inputs.reduce((acc, element) => Math.max(acc, element.value.length), 0);
if (!openAsTab) {
// if open as popup, don't allow column to be more than 1/2 window width
width = Math.min(width, 40);
}
inputs.forEach(i => i.size = width);
}

/**
* @private
*/
Expand Down
4 changes: 3 additions & 1 deletion plugin/js/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class Parser {
constructor(imageCollector) {
this.chapters = [];
this.imageCollector = imageCollector || new ImageCollector();
this.userPreferences = null;
}

onUserPreferencesUpdate(userPreferences) {
this.userPreferences = userPreferences;
this.imageCollector.onUserPreferencesUpdate(userPreferences);
}

Expand Down Expand Up @@ -191,7 +193,7 @@ Parser.prototype.onLoadFirstPage = function (url, firstPageDom) {
// returns promise, because may need to fetch additional pages to find list of chapters
that.getChapterUrls(firstPageDom).then(function(chapters) {
let chapterUrlsUI = new ChapterUrlsUI(that);
chapterUrlsUI.populateChapterUrlsTable(chapters);
chapterUrlsUI.populateChapterUrlsTable(chapters, that.userPreferences);
if (0 < chapters.length) {
if (chapters[0].sourceUrl === url) {
chapters[0].rawDom = firstPageDom;
Expand Down

0 comments on commit f9c16af

Please sign in to comment.