Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It fixed cloning of rows and columns if a table had been inserted manually #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,30 @@ reports/
coverage/
._*
bower_components/

### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

.idea

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

15 changes: 9 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "medium-editor-tables",
"homepage": "http://yabwe.github.io/medium-editor/",
"name": "medium-editor-tables-fork",
"homepage": "https://github.com/lexgorbunov/medium-editor-tables-fork",
"authors": [
"Davi Ferreira <hi@daviferreira.com>"
"Alexanger Gorbunov <lexgorbunov@gmail.com>"
],
"description": "MediumEditor extension to allow tables.",
"description": "MediumEditor extension to allow tables (fork).",
"main": [
"dist/js/medium-editor-tables.js",
"dist/css/medium-editor-tables.css"
Expand All @@ -31,10 +31,13 @@
"package.json",
"src/js",
"README.md",
"CHANGES.md"
"CHANGES.md",
"test",
"tests"
],
"dependencies": {
"medium-editor": "^5.5.1",
"normalize.css": "^3.0.3"
}
},
"version": "0.5.3"
}
39 changes: 22 additions & 17 deletions dist/js/medium-editor-tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,20 @@ Builder.prototype = {
addRow: function (before, e) {
e.preventDefault();
e.stopPropagation();
var tbody = this._range.parentNode.parentNode,
var currentTr = this._range.parentNode,
tbody = currentTr.parentNode,
tr = this._doc.createElement('tr'),
td;
for (var i = 0; i < this._range.parentNode.childNodes.length; i++) {

for (var i = 0; i < currentTr.querySelectorAll('td').length; i++) {
td = this._doc.createElement('td');
td.appendChild(this._doc.createElement('br'));
tr.appendChild(td);
}
if (before !== true && this._range.parentNode.nextSibling) {
tbody.insertBefore(tr, this._range.parentNode.nextSibling);
if (before !== true && currentTr.nextSibling) {
tbody.insertBefore(tr, currentTr.nextSibling);
} else if (before === true) {
tbody.insertBefore(tr, this._range.parentNode);
tbody.insertBefore(tr, currentTr);
} else {
tbody.appendChild(tr);
}
Expand All @@ -351,19 +353,21 @@ Builder.prototype = {
addColumn: function (before, e) {
e.preventDefault();
e.stopPropagation();
var cell = Array.prototype.indexOf.call(this._range.parentNode.childNodes, this._range),
tbody = this._range.parentNode.parentNode,
td;
var currentTr = this._range.parentNode,
cell = Array.prototype.indexOf.call(currentTr.querySelectorAll('td'), this._range),
tbody = currentTr.parentNode,
td,
tableTrs = tbody.querySelectorAll('tr');

for (var i = 0; i < tbody.childNodes.length; i++) {
for (var i = 0; i < tableTrs.length; i++) {
td = this._doc.createElement('td');
td.appendChild(this._doc.createElement('br'));
if (before === true) {
tbody.childNodes[i].insertBefore(td, tbody.childNodes[i].childNodes[cell]);
} else if (this._range.parentNode.parentNode.childNodes[i].childNodes[cell].nextSibling) {
tbody.childNodes[i].insertBefore(td, tbody.childNodes[i].childNodes[cell].nextSibling);
tableTrs[i].insertBefore(td, tableTrs[i].querySelectorAll('td')[cell]);
} else if (currentTr.parentNode.querySelectorAll('tr')[i].querySelectorAll('td')[cell].nextSibling) {
tableTrs[i].insertBefore(td, tableTrs[i].querySelectorAll('td')[cell].nextSibling);
} else {
tbody.childNodes[i].appendChild(td);
tableTrs[i].appendChild(td);
}
}

Expand All @@ -373,20 +377,21 @@ Builder.prototype = {
removeColumn: function (e) {
e.preventDefault();
e.stopPropagation();
var cell = Array.prototype.indexOf.call(this._range.parentNode.childNodes, this._range),
var cell = Array.prototype.indexOf.call(this._range.parentNode.querySelectorAll('td'), this._range),
tbody = this._range.parentNode.parentNode,
rows = tbody.childNodes.length;
currentTrs = tbody.querySelectorAll('tr'),
rows = currentTrs.length;

for (var i = 0; i < rows; i++) {
tbody.childNodes[i].removeChild(tbody.childNodes[i].childNodes[cell]);
currentTrs[i].removeChild(currentTrs[i].querySelectorAll('td')[cell]);
}
this.options.onClick(0, 0);
},

removeTable: function (e) {
e.preventDefault();
e.stopPropagation();
var cell = Array.prototype.indexOf.call(this._range.parentNode.childNodes, this._range),
var cell = Array.prototype.indexOf.call(this._range.parentNode.querySelectorAll('td'), this._range),
table = this._range.parentNode.parentNode.parentNode;

table.parentNode.removeChild(table);
Expand Down
Loading