Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

medium-editor-tables

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

medium-editor-tables - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

CONTRIBUTING.md

7

bower.json
{
"name": "medium-editor-tables",
"version": "0.2.1",
"homepage": "http://daviferreira.github.io/medium-editor/",
"homepage": "http://yabwe.github.io/medium-editor/",
"authors": [

@@ -38,5 +37,5 @@ "Davi Ferreira <hi@daviferreira.com>"

"dependencies": {
"medium-editor": "^4.6.0",
"normalize.css": "~3.0.2"
"medium-editor": "5.0.0",
"normalize.css": "3.0.3"
}
}

@@ -0,1 +1,7 @@

0.3.0 / 2015-06-18
==================
* Upgrade to MediumEditor 5.0
0.2.1 / 2015-04-26

@@ -2,0 +8,0 @@ ==================

@@ -36,4 +36,4 @@ (function (root, factory) {

function getSelectionStart(doc) {
var node = doc.getSelection().anchorNode,
startNode = (node && node.nodeType === 3 ? node.parentNode : node);
var node = doc.getSelection().anchorNode;
var startNode = (node && node.nodeType === 3 ? node.parentNode : node);
return startNode;

@@ -65,4 +65,4 @@ }

var parentNode = node.parentNode,
tagName = parentNode.tagName.toLowerCase();
var parentNode = node.parentNode;
var tagName = parentNode.tagName.toLowerCase();

@@ -99,3 +99,3 @@ while (tagName !== 'body') {

function Grid (el, callback, rows, columns) {
function Grid(el, callback, rows, columns) {
return this.init(el, callback, rows, columns);

@@ -118,3 +118,3 @@ }

markCells: function () {
[].forEach.call(this._cellsElements, function(el) {
[].forEach.call(this._cellsElements, function (el) {
var cell = {

@@ -125,3 +125,3 @@ column: parseInt(el.dataset.column, 10),

var active = this._currentCell &&
cell.row <= this._currentCell.row &&
cell.row <= this._currentCell.row &&
cell.column <= this._currentCell.column;

@@ -161,3 +161,3 @@ if (active === true) {

this._generateCells();
this._cells.map(function(cell) {
this._cells.map(function (cell) {
html += '<a href="#" class="medium-editor-table-builder-cell' +

@@ -179,3 +179,3 @@ (cell.active === true ? ' active' : '') +

_bindEvents: function () {
[].forEach.call(this._cellsElements, function(el) {
[].forEach.call(this._cellsElements, function (el) {
this._onMouseEnter(el);

@@ -283,3 +283,4 @@ this._onClick(el);

var html = '';
var x, y;
var x;
var y;
var text = getSelectionText(this._doc);

@@ -307,4 +308,4 @@

_onKeyDown: function (e) {
var el = getSelectionStart(this._doc),
table;
var el = getSelectionStart(this._doc);
var table;

@@ -340,5 +341,6 @@ if (e.which === TAB_KEY_CODE && isInsideElementOfTag(el, 'table')) {

_insertRow: function (tbody, cols) {
var tr = document.createElement('tr'),
html = '',
i;
var tr = document.createElement('tr');
var html = '';
var i;
for (i = 0; i < cols; i += 1) {

@@ -366,3 +368,3 @@ html += '<td><br /></td>';

function MediumEditorTable (options) {
function MediumEditorTable(options) {
this.options = extend(options, {

@@ -388,3 +390,3 @@ columns: 10,

getForm: function() {
getForm: function () {
if (!this.builder) {

@@ -396,3 +398,3 @@ this.builder = new Builder({

}.bind(this),
ownerDocument: this.base.options.ownerDocument,
ownerDocument: this.document,
rows: this.options.rows,

@@ -399,0 +401,0 @@ columns: this.options.columns

@@ -1,1 +0,1 @@

!function(a,b){"use strict";"object"==typeof module?module.exports=b:"function"==typeof define&&define.amd?define(b):a.MediumEditorTable=b}(this,function(){"use strict";function a(a,b){var c;a=a||{};for(c in b)b.hasOwnProperty(c)&&!a.hasOwnProperty(c)&&(a[c]=b[c]);return a}function b(a){return a.getSelection?a.getSelection().toString():a.selection&&"Control"!==a.selection.type?a.selection.createRange().text:""}function c(a){var b=a.getSelection().anchorNode,c=b&&3===b.nodeType?b.parentNode:b;return c}function d(a,b,c){if(void 0!==a.getSelection&&b){var d=a.createRange(),e=a.getSelection();c?d.setStartBefore(b):d.setStartAfter(b),d.collapse(!0),e.removeAllRanges(),e.addRange(d)}}function e(a,b){if(!a)return!1;for(var c=a.parentNode,d=c.tagName.toLowerCase();"body"!==d;){if(d===b)return!0;if(c=c.parentNode,!c||!c.tagName)return!1;d=c.tagName.toLowerCase()}return!1}function f(a,b){var c=a&&a.tagName?a.tagName.toLowerCase():!1;if(!c)return!1;for(;c&&"body"!==c;){if(c===b)return a;a=a.parentNode,c=a&&a.tagName?a.tagName.toLowerCase():!1}}function g(a,b,c,d){return this.init(a,b,c,d)}function h(a){return this.init(a)}function i(a){return this.init(a)}function j(b){this.options=a(b,{columns:10,rows:10}),this.parent=!0,this.hasForm=!0,this.isFormVisible=!1,this.createButton()}g.prototype={init:function(a,b,c,d){return this._root=a,this._callback=b,this.rows=c,this.columns=d,this._render()},setCurrentCell:function(a){this._currentCell=a},markCells:function(){[].forEach.call(this._cellsElements,function(a){var b={column:parseInt(a.dataset.column,10),row:parseInt(a.dataset.row,10)},c=this._currentCell&&b.row<=this._currentCell.row&&b.column<=this._currentCell.column;c===!0?a.classList.add("active"):a.classList.remove("active")}.bind(this))},_generateCells:function(){this._cells=[];for(var a=0;a<this.rows*this.columns;a++){var b=a%this.columns,c=Math.floor(a/this.rows);this._cells.push({column:b,row:c,active:!1})}},_html:function(){var a='<div class="medium-editor-table-builder-grid clearfix">';return a+=this._cellsHTML(),a+="</div>"},_cellsHTML:function(){var a="";return this._generateCells(),this._cells.map(function(b){a+='<a href="#" class="medium-editor-table-builder-cell'+(b.active===!0?" active":"")+'" data-row="'+b.row+'" data-column="'+b.column+'">',a+="</a>"}),a},_render:function(){this._root.innerHTML=this._html(),this._cellsElements=this._root.querySelectorAll("a"),this._bindEvents()},_bindEvents:function(){[].forEach.call(this._cellsElements,function(a){this._onMouseEnter(a),this._onClick(a)}.bind(this))},_onMouseEnter:function(a){var b,c=this;a.addEventListener("mouseenter",function(){clearTimeout(b);var a=this.dataset;b=setTimeout(function(){c._currentCell={column:parseInt(a.column,10),row:parseInt(a.row,10)},c.markCells()},50)})},_onClick:function(a){var b=this;a.addEventListener("click",function(a){a.preventDefault(),b._callback(this.dataset.row,this.dataset.column)})}},h.prototype={init:function(a){this.options=a,this._doc=a.ownerDocument||document,this._root=this._doc.createElement("div"),this._root.className="medium-editor-table-builder",this.grid=new g(this._root,this.options.onClick,this.options.rows,this.options.columns)},getElement:function(){return this._root},hide:function(){this._root.style.display="",this.grid.setCurrentCell({column:-1,row:-1}),this.grid.markCells()},show:function(a){this._root.style.display="block",this._root.style.left=a+"px"}};var k=9;return i.prototype={init:function(a){this._editor=a,this._doc=this._editor.options.ownerDocument,this._bindTabBehavior()},insert:function(a,b){var c=this._html(a,b);this._editor.insertHTML('<table class="medium-editor-table" id="medium-editor-table" width="100%"><tbody>'+c+"</tbody></table>");var e=this._doc.getElementById("medium-editor-table");e.removeAttribute("id"),d(this._doc,e.querySelector("td"),!0)},_html:function(a,c){var d,e,f="",g=b(this._doc);for(d=0;a>=d;d++){for(f+="<tr>",e=0;c>=e;e++)f+="<td>"+(0===d&&0===e?g:"<br />")+"</td>";f+="</tr>"}return f},_bindTabBehavior:function(){var a=this;[].forEach.call(this._editor.elements,function(b){b.addEventListener("keydown",function(b){a._onKeyDown(b)})})},_onKeyDown:function(a){var b,g=c(this._doc);a.which===k&&e(g,"table")&&(a.preventDefault(),a.stopPropagation(),b=this._getTableElements(g),a.shiftKey?this._tabBackwards(g.previousSibling,b.row):(this._isLastCell(g,b.row,b.root)&&this._insertRow(f(g,"tbody"),b.row.cells.length),d(this._doc,g)))},_getTableElements:function(a){return{cell:f(a,"td"),row:f(a,"tr"),root:f(a,"table")}},_tabBackwards:function(a,b){a=a||this._getPreviousRowLastCell(b),d(this._doc,a,!0)},_insertRow:function(a,b){var c,d=document.createElement("tr"),e="";for(c=0;b>c;c+=1)e+="<td><br /></td>";d.innerHTML=e,a.appendChild(d)},_isLastCell:function(a,b,c){return--b.cells.length==a.cellIndex&&--c.rows.length==b.rowIndex},_getPreviousRowLastCell:function(a){return a=a.previousSibling,a?a.cells[a.cells.length-1]:void 0}},j.prototype={createButton:function(){this._createButtonElement(),this._bindButtonClick()},getForm:function(){return this.builder||(this.builder=new h({onClick:function(a,b){this.table.insert(a,b),this.hide()}.bind(this),ownerDocument:this.base.options.ownerDocument,rows:this.options.rows,columns:this.options.columns}),this.table=new i(this.base)),this.builder.getElement()},getButton:function(){return"fontawesome"===this.base.options.buttonLabels&&(this.button.innerHTML='<i class="fa fa-table"></i>'),this.button},onHide:function(){this.hide()},hide:function(){this.isFormVisible=!1,this.builder.hide(),this.button.classList.remove("medium-editor-button-active")},show:function(){this.isFormVisible=!0,this.builder.show(this.button.offsetLeft),this.button.classList.add("medium-editor-button-active");for(var a=document.getElementsByClassName("medium-editor-table-builder-grid"),b=0;b<a.length;b++)a[b].style.height=16*this.options.rows+2+"px",a[b].style.width=16*this.options.columns+2+"px"},_createButtonElement:function(){this.button=document.createElement("button"),this.button.className="medium-editor-action",this.button.innerHTML="tbl"},_bindButtonClick:function(){this.button.addEventListener("click",function(a){a.preventDefault(),this[this.isFormVisible===!0?"hide":"show"]()}.bind(this))}},j}());
!function(a,b){"use strict";"object"==typeof module?module.exports=b:"function"==typeof define&&define.amd?define(b):a.MediumEditorTable=b}(this,function(){"use strict";function a(a,b){var c;a=a||{};for(c in b)b.hasOwnProperty(c)&&!a.hasOwnProperty(c)&&(a[c]=b[c]);return a}function b(a){return a.getSelection?a.getSelection().toString():a.selection&&"Control"!==a.selection.type?a.selection.createRange().text:""}function c(a){var b=a.getSelection().anchorNode,c=b&&3===b.nodeType?b.parentNode:b;return c}function d(a,b,c){if(void 0!==a.getSelection&&b){var d=a.createRange(),e=a.getSelection();c?d.setStartBefore(b):d.setStartAfter(b),d.collapse(!0),e.removeAllRanges(),e.addRange(d)}}function e(a,b){if(!a)return!1;for(var c=a.parentNode,d=c.tagName.toLowerCase();"body"!==d;){if(d===b)return!0;if(c=c.parentNode,!c||!c.tagName)return!1;d=c.tagName.toLowerCase()}return!1}function f(a,b){var c=a&&a.tagName?a.tagName.toLowerCase():!1;if(!c)return!1;for(;c&&"body"!==c;){if(c===b)return a;a=a.parentNode,c=a&&a.tagName?a.tagName.toLowerCase():!1}}function g(a,b,c,d){return this.init(a,b,c,d)}function h(a){return this.init(a)}function i(a){return this.init(a)}function j(b){this.options=a(b,{columns:10,rows:10}),this.parent=!0,this.hasForm=!0,this.isFormVisible=!1,this.createButton()}g.prototype={init:function(a,b,c,d){return this._root=a,this._callback=b,this.rows=c,this.columns=d,this._render()},setCurrentCell:function(a){this._currentCell=a},markCells:function(){[].forEach.call(this._cellsElements,function(a){var b={column:parseInt(a.dataset.column,10),row:parseInt(a.dataset.row,10)},c=this._currentCell&&b.row<=this._currentCell.row&&b.column<=this._currentCell.column;c===!0?a.classList.add("active"):a.classList.remove("active")}.bind(this))},_generateCells:function(){this._cells=[];for(var a=0;a<this.rows*this.columns;a++){var b=a%this.columns,c=Math.floor(a/this.rows);this._cells.push({column:b,row:c,active:!1})}},_html:function(){var a='<div class="medium-editor-table-builder-grid clearfix">';return a+=this._cellsHTML(),a+="</div>"},_cellsHTML:function(){var a="";return this._generateCells(),this._cells.map(function(b){a+='<a href="#" class="medium-editor-table-builder-cell'+(b.active===!0?" active":"")+'" data-row="'+b.row+'" data-column="'+b.column+'">',a+="</a>"}),a},_render:function(){this._root.innerHTML=this._html(),this._cellsElements=this._root.querySelectorAll("a"),this._bindEvents()},_bindEvents:function(){[].forEach.call(this._cellsElements,function(a){this._onMouseEnter(a),this._onClick(a)}.bind(this))},_onMouseEnter:function(a){var b,c=this;a.addEventListener("mouseenter",function(){clearTimeout(b);var a=this.dataset;b=setTimeout(function(){c._currentCell={column:parseInt(a.column,10),row:parseInt(a.row,10)},c.markCells()},50)})},_onClick:function(a){var b=this;a.addEventListener("click",function(a){a.preventDefault(),b._callback(this.dataset.row,this.dataset.column)})}},h.prototype={init:function(a){this.options=a,this._doc=a.ownerDocument||document,this._root=this._doc.createElement("div"),this._root.className="medium-editor-table-builder",this.grid=new g(this._root,this.options.onClick,this.options.rows,this.options.columns)},getElement:function(){return this._root},hide:function(){this._root.style.display="",this.grid.setCurrentCell({column:-1,row:-1}),this.grid.markCells()},show:function(a){this._root.style.display="block",this._root.style.left=a+"px"}};var k=9;return i.prototype={init:function(a){this._editor=a,this._doc=this._editor.options.ownerDocument,this._bindTabBehavior()},insert:function(a,b){var c=this._html(a,b);this._editor.pasteHTML('<table class="medium-editor-table" id="medium-editor-table" width="100%"><tbody>'+c+"</tbody></table>",{cleanAttrs:[],cleanTags:[]});var e=this._doc.getElementById("medium-editor-table");e.removeAttribute("id"),d(this._doc,e.querySelector("td"),!0)},_html:function(a,c){var d,e,f="",g=b(this._doc);for(d=0;a>=d;d++){for(f+="<tr>",e=0;c>=e;e++)f+="<td>"+(0===d&&0===e?g:"<br />")+"</td>";f+="</tr>"}return f},_bindTabBehavior:function(){var a=this;[].forEach.call(this._editor.elements,function(b){b.addEventListener("keydown",function(b){a._onKeyDown(b)})})},_onKeyDown:function(a){var b,g=c(this._doc);a.which===k&&e(g,"table")&&(a.preventDefault(),a.stopPropagation(),b=this._getTableElements(g),a.shiftKey?this._tabBackwards(g.previousSibling,b.row):(this._isLastCell(g,b.row,b.root)&&this._insertRow(f(g,"tbody"),b.row.cells.length),d(this._doc,g)))},_getTableElements:function(a){return{cell:f(a,"td"),row:f(a,"tr"),root:f(a,"table")}},_tabBackwards:function(a,b){a=a||this._getPreviousRowLastCell(b),d(this._doc,a,!0)},_insertRow:function(a,b){var c,d=document.createElement("tr"),e="";for(c=0;b>c;c+=1)e+="<td><br /></td>";d.innerHTML=e,a.appendChild(d)},_isLastCell:function(a,b,c){return--b.cells.length==a.cellIndex&&--c.rows.length==b.rowIndex},_getPreviousRowLastCell:function(a){return a=a.previousSibling,a?a.cells[a.cells.length-1]:void 0}},j.prototype={createButton:function(){this._createButtonElement(),this._bindButtonClick()},isDisplayed:function(){return this.isFormVisible},getForm:function(){return this.builder||(this.builder=new h({onClick:function(a,b){this.table.insert(a,b),this.hideForm()}.bind(this),ownerDocument:this.document,rows:this.options.rows,columns:this.options.columns}),this.table=new i(this.base)),this.builder.getElement()},getButton:function(){return"fontawesome"===this.base.options.buttonLabels&&(this.button.innerHTML='<i class="fa fa-table"></i>'),this.button},onHide:function(){this.hideForm()},hideForm:function(){this.isFormVisible=!1,this.builder.hide(),this.button.classList.remove("medium-editor-button-active")},show:function(){this.isFormVisible=!0,this.builder.show(this.button.offsetLeft),this.button.classList.add("medium-editor-button-active");for(var a=document.getElementsByClassName("medium-editor-table-builder-grid"),b=0;b<a.length;b++)a[b].style.height=16*this.options.rows+2+"px",a[b].style.width=16*this.options.columns+2+"px"},_createButtonElement:function(){this.button=document.createElement("button"),this.button.className="medium-editor-action",this.button.innerHTML="tbl"},_bindButtonClick:function(){this.button.addEventListener("click",function(a){a.preventDefault(),this[this.isFormVisible===!0?"hideForm":"show"]()}.bind(this))}},j}());
{
"name": "medium-editor-tables",
"version": "0.2.1",
"version": "0.3.0",
"author": "Davi Ferreira <hi@daviferreira.com>",

@@ -9,9 +9,8 @@ "description": "MediumEditor extension to allow tables.",

"type": "git",
"url": "https://github.com/daviferreira/medium-editor-tables"
"url": "https://github.com/yabwe/medium-editor-tables"
},
"bugs": {
"url": "https://github.com/daviferreira/medium-editor-tables/issues",
"email": "hi@daviferreira.com"
"url": "https://github.com/yabwe/medium-editor-tables/issues"
},
"homepage": "http://daviferreira.github.io/medium-editor/",
"homepage": "http://yabwe.github.io/medium-editor/",
"keywords": [

@@ -31,6 +30,6 @@ "editor",

"grunt": "0.4.5",
"grunt-autoprefixer": "3.0.0",
"grunt-autoprefixer": "3.0.1",
"grunt-bump": "0.3.1",
"grunt-contrib-concat": "0.5.1",
"grunt-contrib-cssmin": "0.12.2",
"grunt-contrib-cssmin": "0.12.3",
"grunt-contrib-jasmine": "0.8.2",

@@ -41,15 +40,16 @@ "grunt-contrib-jshint": "0.11.2",

"grunt-coveralls": "1.0.0",
"grunt-jscs": "1.6.0",
"grunt-sass": "0.18.1",
"grunt-jscs": "1.8.0",
"grunt-sass": "1.0.0",
"grunt-template-jasmine-istanbul": "0.3.3",
"load-grunt-config": "^0.17.1",
"time-grunt": "1.1.1"
"load-grunt-config": "0.17.1",
"time-grunt": "1.2.1"
},
"scripts": {
"test": "grunt test --verbose",
"test:ci": "grunt travis --verbose",
"start": "open ./demo/index.html"
},
"dependencies": {
"medium-editor": "^4.6.0"
"peerDependencies": {
"medium-editor": "5.0.0"
}
}

@@ -5,9 +5,11 @@ # MediumEditor Tables

[![Travis build status](https://travis-ci.org/daviferreira/medium-editor-tables.png?branch=master)](https://travis-ci.org/daviferreira/medium-editor-tables)
[![dependencies](https://david-dm.org/daviferreira/medium-editor-tables.png)](https://david-dm.org/daviferreira/medium-editor-tables)
[![devDependency Status](https://david-dm.org/daviferreira/medium-editor-tables/dev-status.png)](https://david-dm.org/daviferreira/medium-editor-tables#info=devDependencies)
[![Coverage Status](https://coveralls.io/repos/daviferreira/medium-editor-tables/badge.svg)](https://coveralls.io/r/daviferreira/medium-editor-tables)
[![Travis build status](https://travis-ci.org/yabwe/medium-editor-tables.png?branch=master)](https://travis-ci.org/yabwe/medium-editor-tables)
[![dependencies](https://david-dm.org/yabwe/medium-editor-tables.png)](https://david-dm.org/yabwe/medium-editor-tables)
[![devDependency Status](https://david-dm.org/yabwe/medium-editor-tables/dev-status.png)](https://david-dm.org/yabwe/medium-editor-tables#info=devDependencies)
[![Coverage Status](https://coveralls.io/repos/yabwe/medium-editor-tables/badge.svg)](https://coveralls.io/r/yabwe/medium-editor-tables)
MediumEditor Tables is an extension to add a table button/behavior to [MediumEditor](https://github.com/daviferreira/medium-editor).
MediumEditor Tables is an extension to add a table button/behavior to [MediumEditor](https://github.com/yabwe/medium-editor).
Demo: [http://yabwe.github.io/medium-editor-tables/](http://yabwe.github.io/medium-editor-tables/)
--

@@ -86,26 +88,2 @@

## Development
Clone the repository and:
```
npm install
grunt
```
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Test your changes to the best of your ability
4. Update the documentation to reflect your changes if they add or changes current functionality
5. Commit your changes (`git commit -am 'Added some feature'`)
6. Push to the branch (`git push origin my-new-feature`)
7. Create new Pull Request
or
1. Just pull request all the things the way you want!
## Demo

@@ -122,2 +100,2 @@

MIT: https://github.com/daviferreira/medium-editor-tables/blob/master/LICENSE
MIT: https://github.com/yabwe/medium-editor-tables/blob/master/LICENSE

@@ -25,3 +25,27 @@ describe('Util TestCase', function () {

});
describe('#isInsideElementOfTag', function () {
it('should return false when node is invalid', function () {
expect(isInsideElementOfTag(undefined, 'p')).toBe(false);
});
it('should return true when parent element has specified tag', function () {
var parentEl = document.createElement('div');
var childEl = document.createElement('p');
parentEl.appendChild(childEl);
document.body.appendChild(parentEl);
expect(isInsideElementOfTag(childEl, 'div')).toBe(true);
document.body.removeChild(parentEl);
});
it('should return true when parent element does not have specified tag', function () {
var parentEl = document.createElement('div');
var childEl = document.createElement('p');
parentEl.appendChild(childEl);
document.body.appendChild(parentEl);
expect(isInsideElementOfTag(childEl, 'span')).toBe(false);
document.body.removeChild(parentEl);
});
});
});
});

@@ -29,3 +29,3 @@ function MediumEditorTable(options) {

}.bind(this),
ownerDocument: this.base.options.ownerDocument,
ownerDocument: this.document,
rows: this.options.rows,

@@ -32,0 +32,0 @@ columns: this.options.columns

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc