Permalink
Browse files

Fixed FireFox tab bug

  • Loading branch information...
1 parent fb6c7ce commit 9dabd204dd0fc5e128e3a7a0fe846fdeb0b111c8 @nCrafts committed Aug 30, 2016
Showing with 6 additions and 2 deletions.
  1. +2 −0 dist/js/tabular-input.js
  2. +1 −1 dist/js/tabular-input.min.js
  3. +1 −1 package.json
  4. +2 −0 src/js/tabular-input.js
@@ -66,6 +66,7 @@
this.config = config;
element.on('keydown', 'input', function (e) {
if (_this.config.newRowOnTab === true && e.which === 9 && $(e.target).closest('tr').is(':last-child') && $(e.target).parent('td').is(':last-child')) {
+ e.preventDefault();
_this.addRow(element);
}
});
@@ -107,6 +108,7 @@
var newRowHTML = '<tr class=\'' + (this.config.animate === true ? 'animate-add' : '') + '\'><td>' + newRowInputs.join('</td><td>') + '</td></tr>';
element.find('tr:last').after(newRowHTML);
this.setName(element);
+ element.find('tr:last td:first input').focus();
setTimeout(function () {
element.find('.animate-add').removeClass('animate-add');
}, 250);
@@ -1 +1 @@
-!function(t){function n(i){if(e[i])return e[i].exports;var o=e[i]={exports:{},id:i,loaded:!1};return t[i].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var e={};return n.m=t,n.c=e,n.p="",n(0)}([function(t,n){"use strict";function e(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},o=function(){function t(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(n,e,i){return e&&t(n.prototype,e),i&&t(n,i),n}}(),a=function(t){var n=function(){function n(i,o){var a=this;e(this,n),this.config=o,i.on("keydown","input",function(n){a.config.newRowOnTab===!0&&9===n.which&&t(n.target).closest("tr").is(":last-child")&&t(n.target).parent("td").is(":last-child")&&a.addRow(i)})}return o(n,[{key:"addColumn",value:function(n){n.find("tbody tr").each(function(n,e){t(e).find("td:last").after('<td><input type="text"/></td>')}),this.config.columns++,this.setColumnHeads(n,this.config.columnHeads),this.setName(n),this.setWidth(n)}},{key:"deleteColumn",value:function(t,n){if(0!==this.config.columns){var e="number"!=typeof n?this.config.columns:n+1;t.find("tr td:nth-child("+e+")").remove(),this.config.columns--,this.setName(t),this.setWidth(t)}}},{key:"addRow",value:function(t){if(!(this.config.maxRows!==!1&&t.find("tbody tr").length>=this.config.maxRows)){for(var n=[],e=0;e<this.config.columns;e++)n.push('<input type="text"/>');var i="<tr class='"+(this.config.animate===!0?"animate-add":"")+"'><td>"+n.join("</td><td>")+"</td></tr>";t.find("tr:last").after(i),this.setName(t),setTimeout(function(){t.find(".animate-add").removeClass("animate-add")},250)}}},{key:"deleteRow",value:function(t,n){var e=n||t.find("tr").length-1;t.find("tr").eq(e).addClass("animate-remove"),this.config.animate===!1?t.find("tr.animate-remove").remove():setTimeout(function(){t.find("tr.animate-remove").remove()},250)}},{key:"maxRows",value:function(t,n){"number"==typeof n&&(this.config.maxRows=n)}},{key:"setColumnHeads",value:function(t,n){if("object"===("undefined"==typeof n?"undefined":i(n))){for(this.config.columnHeads=!0;n.length<this.config.columns;)n.push("");var e=n.map(function(t){return"<th>"+t+"</th>"}).slice(0,this.config.columns).join();t.find("thead").html("<tr>"+e+"</tr>")}}},{key:"setName",value:function(n){var e=this;this.config.name!==!1&&n.find("tr").each(function(n,i){t(i).find("td").each(function(i,o){t(o).find("input").attr("name",e.config.name+"["+i+"]["+n+"]")})})}},{key:"setWidth",value:function(t){var n=(100/this.config.columns).toFixed(2)+"%";t.find("td").css("width",n),t.find("th").length>0&&t.find("th").css("width",n)}},{key:"destroy",value:function(t){t.find(".tabularInput-table").remove()}}],[{key:"jQueryInterface",value:function(e,i){var o=this;return this.each(function(){if("string"==typeof e&&"function"==typeof o.data().tabularObject[e])return void o.data().tabularObject[e](o,i);for(var a=t.extend({rows:2,columns:4,name:!1,newRowOnTab:!1,columnHeads:!1,animate:!1,maxRows:!1},e),r=0,u=[];r<a.rows;){for(var s=[],f=0;f<a.columns;f++)s.push('<input type="text"/>');u.push("<tr row-index='"+r+"'><td>"+s.join("</td><td>")+"</td></tr>"),r++}o.html(t('<table width="100%" cellspacing="0" cellpadding="0" class="tabularInput-table '+(a.animate?"animate":"")+'"></table>').html("<thead></thead><tbody>"+u.join()+"</tbody>"));var c=new n(o,a);c.setColumnHeads(o,a.columnHeads),c.setName(o),c.setWidth(o),o.data("tabularObject",c)})}}]),n}();t.fn.tabularInput=n.jQueryInterface,t.fn.tabularInput.Constructor=n}(jQuery);n["default"]=a}]);
+!function(t){function n(i){if(e[i])return e[i].exports;var o=e[i]={exports:{},id:i,loaded:!1};return t[i].call(o.exports,o,o.exports,n),o.loaded=!0,o.exports}var e={};return n.m=t,n.c=e,n.p="",n(0)}([function(t,n){"use strict";function e(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},o=function(){function t(t,n){for(var e=0;e<n.length;e++){var i=n[e];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(n,e,i){return e&&t(n.prototype,e),i&&t(n,i),n}}(),a=function(t){var n=function(){function n(i,o){var a=this;e(this,n),this.config=o,i.on("keydown","input",function(n){a.config.newRowOnTab===!0&&9===n.which&&t(n.target).closest("tr").is(":last-child")&&t(n.target).parent("td").is(":last-child")&&(n.preventDefault(),a.addRow(i))})}return o(n,[{key:"addColumn",value:function(n){n.find("tbody tr").each(function(n,e){t(e).find("td:last").after('<td><input type="text"/></td>')}),this.config.columns++,this.setColumnHeads(n,this.config.columnHeads),this.setName(n),this.setWidth(n)}},{key:"deleteColumn",value:function(t,n){if(0!==this.config.columns){var e="number"!=typeof n?this.config.columns:n+1;t.find("tr td:nth-child("+e+")").remove(),this.config.columns--,this.setName(t),this.setWidth(t)}}},{key:"addRow",value:function(t){if(!(this.config.maxRows!==!1&&t.find("tbody tr").length>=this.config.maxRows)){for(var n=[],e=0;e<this.config.columns;e++)n.push('<input type="text"/>');var i="<tr class='"+(this.config.animate===!0?"animate-add":"")+"'><td>"+n.join("</td><td>")+"</td></tr>";t.find("tr:last").after(i),this.setName(t),t.find("tr:last td:first input").focus(),setTimeout(function(){t.find(".animate-add").removeClass("animate-add")},250)}}},{key:"deleteRow",value:function(t,n){var e=n||t.find("tr").length-1;t.find("tr").eq(e).addClass("animate-remove"),this.config.animate===!1?t.find("tr.animate-remove").remove():setTimeout(function(){t.find("tr.animate-remove").remove()},250)}},{key:"maxRows",value:function(t,n){"number"==typeof n&&(this.config.maxRows=n)}},{key:"setColumnHeads",value:function(t,n){if("object"===("undefined"==typeof n?"undefined":i(n))){for(this.config.columnHeads=!0;n.length<this.config.columns;)n.push("");var e=n.map(function(t){return"<th>"+t+"</th>"}).slice(0,this.config.columns).join();t.find("thead").html("<tr>"+e+"</tr>")}}},{key:"setName",value:function(n){var e=this;this.config.name!==!1&&n.find("tr").each(function(n,i){t(i).find("td").each(function(i,o){t(o).find("input").attr("name",e.config.name+"["+i+"]["+n+"]")})})}},{key:"setWidth",value:function(t){var n=(100/this.config.columns).toFixed(2)+"%";t.find("td").css("width",n),t.find("th").length>0&&t.find("th").css("width",n)}},{key:"destroy",value:function(t){t.find(".tabularInput-table").remove()}}],[{key:"jQueryInterface",value:function(e,i){var o=this;return this.each(function(){if("string"==typeof e&&"function"==typeof o.data().tabularObject[e])return void o.data().tabularObject[e](o,i);for(var a=t.extend({rows:2,columns:4,name:!1,newRowOnTab:!1,columnHeads:!1,animate:!1,maxRows:!1},e),r=0,u=[];r<a.rows;){for(var s=[],f=0;f<a.columns;f++)s.push('<input type="text"/>');u.push("<tr row-index='"+r+"'><td>"+s.join("</td><td>")+"</td></tr>"),r++}o.html(t('<table width="100%" cellspacing="0" cellpadding="0" class="tabularInput-table '+(a.animate?"animate":"")+'"></table>').html("<thead></thead><tbody>"+u.join()+"</tbody>"));var c=new n(o,a);c.setColumnHeads(o,a.columnHeads),c.setName(o),c.setWidth(o),o.data("tabularObject",c)})}}]),n}();t.fn.tabularInput=n.jQueryInterface,t.fn.tabularInput.Constructor=n}(jQuery);n["default"]=a}]);
View
@@ -19,7 +19,7 @@
],
"license": "MIT",
"main": "dist/js/tabular.js",
- "version": "0.0.1",
+ "version": "0.0.2",
"devDependencies": {
"babel-core": "^6.7.6",
"babel-loader": "^6.2.4",
@@ -6,6 +6,7 @@ const tabularInput = (($) => {
this.config = config
element.on('keydown', 'input', (e) => {
if (this.config.newRowOnTab === true && e.which === 9 && $(e.target).closest('tr').is(':last-child') && $(e.target).parent('td').is(':last-child')) {
+ e.preventDefault()
this.addRow(element)
}
})
@@ -43,6 +44,7 @@ const tabularInput = (($) => {
let newRowHTML = `<tr class='${this.config.animate === true ? 'animate-add' : ''}'><td>${newRowInputs.join('</td><td>')}</td></tr>`
element.find('tr:last').after(newRowHTML)
this.setName(element)
+ element.find('tr:last td:first input').focus()
setTimeout(() => {
element.find('.animate-add').removeClass('animate-add')
}, 250)

0 comments on commit 9dabd20

Please sign in to comment.