Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
nCrafts committed Apr 11, 2016
1 parent 7f866c4 commit bed13f5
Show file tree
Hide file tree
Showing 8 changed files with 499 additions and 23 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Nishant Agrawal

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
7 changes: 5 additions & 2 deletions README.md
@@ -1,2 +1,5 @@
## Test
# Test2
## Tabular Input
# Intro
One-line text fields in a tabular format, with support for dynamically adding rows.
# License
MIT License
170 changes: 170 additions & 0 deletions dist/js/tabular-input.js
@@ -0,0 +1,170 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};

/******/ // The require function
/******/ function __webpack_require__(moduleId) {

/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;

/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };

/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ // Flag the module as loaded
/******/ module.loaded = true;

/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }


/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;

/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;

/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";

/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports) {

'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var tabularInput = function ($) {
var tabularInput = function () {
function tabularInput(element, config) {
var _this = this;

_classCallCheck(this, tabularInput);

this.config = config;
this.rowCounter = config.rows;
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')) {
_this.addRow(element);
}
});
}

_createClass(tabularInput, [{
key: 'addRow',
value: function addRow(element) {
var newRowInputs = [];
for (var a = 0; a < this.config.columns; a++) {
if (this.config.name === false) {
newRowInputs.push('<input type="text"/>');
} else {
newRowInputs.push('<input type="text" name="' + this.config.name + '[' + a + '][' + this.rowCounter + ']"/>');
}
}
var newRowHTML = '<tr class=\'' + (this.config.animate === true ? 'animate-add' : '') + '\'><td style=\'width: ' + this.config.cellWidth + '%\'>' + newRowInputs.join('</td><td>') + '</td></tr>';
element.find('tr:last').after(newRowHTML);
this.rowCounter++;
setTimeout(function () {
element.find('.animate-add').removeClass('animate-add');
}, 500);
}
}, {
key: 'deleteRow',
value: function deleteRow(element, _whichRow) {
var whichRow = typeof _whichRow === 'undefined' ? element.find('tr').length - 1 : _whichRow;
element.find('tr').eq(whichRow).addClass('animate-remove');
if (this.config.animate === false) {
element.find('tr.animate-remove').remove();
} else {
setTimeout(function () {
element.find('tr.animate-remove').remove();
}, 300);
}
}
}, {
key: 'setColumnHeads',
value: function setColumnHeads(element, heads) {
var headsHTML = heads.map(function (x) {
return '<th>' + x + '</th>';
}).join();
element.find('thead').html('<tr>' + headsHTML + '</tr>');
}
}], [{
key: 'jQueryInterface',
value: function jQueryInterface(_config, extraArgument) {

if (typeof _config === 'string' && typeof this.data().tabularObject[_config] === 'function') {
this.data().tabularObject[_config](this, extraArgument);
return;
}

var config = $.extend({
rows: 2,
columns: 4,
name: false,
newRowOnTab: false,
columnHeads: false,
animate: false
}, _config);

config.cellWidth = 100 / config.columns;

var currentRow = 0;
var allRowsArray = [];

while (currentRow < config.rows) {
var currentRowInputs = [];
for (var a = 0; a < config.columns; a++) {
if (config.name === false) {
currentRowInputs.push('<input type="text"/>');
} else {
currentRowInputs.push('<input type="text" name="' + config.name + '[' + a + '][' + currentRow + ']"/>');
}
}
allRowsArray.push('<tr><td style=\'width: ' + config.cellWidth + '%\'>' + currentRowInputs.join('</td><td>') + '</td></tr>');
currentRow++;
}

this.html($('<table width="100%" cellspacing="0" cellpadding="0" class="tabularInput-table ' + (config.animate ? 'animate' : '') + '"></table>').html('<thead></thead><tbody>' + allRowsArray.join() + '</tbody>'));
var tabularObject = new tabularInput(this, config);

if (config.columnHeads !== false) {
config.columnHeads = typeof config.columnHeads === 'undefined' ? ' column'.repeat(config.columns).split(' ').splice(1) : config.columnHeads;
tabularObject.setColumnHeads(this, config.columnHeads);
}

this.data('tabularObject', tabularObject);
}
}]);

return tabularInput;
}();

$.fn.tabularInput = tabularInput.jQueryInterface;
$.fn.tabularInput.Constructor = tabularInput;
}(jQuery);

exports.default = tabularInput;

/***/ }
/******/ ]);
75 changes: 61 additions & 14 deletions docs/index.html
Expand Up @@ -3,17 +3,18 @@

<body>

<link type='text/css' rel='stylesheet' href='../src/css/tabular_input.css'/>
<link type='text/css' rel='stylesheet' href='../src/css/tabular-input.css'/>
<link type='text/css' rel='stylesheet' href='style.css'/>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/styles/default.min.css">

<div style="width: 600px; margin: 75px auto auto auto">
<div style="width: 720px; margin: 75px auto auto auto">

<h1>Tabular Input Fields</h1>

<div class='example'>
<h2>Simple Usage</h2>
<div id='tabular1'></div>
<pre>
<pre class='javascript'>
jQuery('#tabular').tabularInput({
'rows': 3,
'columns': 5
Expand All @@ -26,39 +27,85 @@ <h2>Add / Delete Row Button</h2>
<div id='tabular2'></div>
<button type='button' onClick='javascript:$("#tabular2").tabularInput("addRow")'>Add New Row</button>
<button type='button' onClick='javascript:$("#tabular2").tabularInput("deleteRow")'>Delete Last Row</button>
<pre>
<pre class='javascript'>
jQuery('#tabular').tabularInput({
'rows': 3,
'columns': 5
'columns': 5,
'animate': true
});
$("#tabular").tabularInput("addRow");
$("#tabular").tabularInput("deleteRow");

$("#tabular").tabularInput("addRow"); // Add a row at the end
$("#tabular").tabularInput("deleteRow"); // Delete the last row
$("#tabular").tabularInput("deleteRow", 2); // Delete row at index 2
</pre>
</div>

<div class='example'>
<h2>Auto Add Row on Tab</h2>
<h2>Add Row on Tab</h2>
<p>Move to the last cell and press Tab</p>
<div id='tabular3'></div>
<pre>
<pre class='javascript'>
jQuery('#tabular').tabularInput({
'rows': 3,
'columns': 5,
'newRowOnTab': true
'newRowOnTab': true,
'animate': true
});
</pre>
</div>

<div class='example'>
<h2>Column Heads</h2>
<div id='tabular4'></div>
<pre class='javascript'>
// Set them on initialisation
jQuery('#tabular').tabularInput({
'rows': 3,
'columns': 3,
'columnHeads': ['Name', 'Age', 'Sex', 'Occupation']
});

// Or later
jQuery('#tabular').tabularInput('setColumnHeads', ['Name', 'Age', 'Sex', 'Occupation']);
</pre>
</div>

<div class='example'>
<h2>Fetching and Setting Field Values</h2>
<div id='tabular5'></div>
<pre class='javascript'>
// Set them on initialisation
jQuery('#tabular').tabularInput({
'rows': 3,
'columns': 3,
'name': 'myField'
});

// Fetch value of first column, in the third row
jQuery('[name="myField[0][2]"]').val();

// Set value of second column, in the third row
jQuery('[name="myField[1][2]"]').val('JavaScript');
</pre>
<button type='button' onClick='javascript:$("#tabular").tabularInput("addRow")'>Add New Row</button>
</div>

</div>

</body>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src='../dist/js/tabular_input.js'></script>
<script src='../dist/js/tabular-input.js'></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.3.0/highlight.min.js"></script>
<script>
jQuery(document).ready(function(){
jQuery('#tabular1, #tabular2').tabularInput({'rows': 3, 'columns': 5});
jQuery('#tabular3').tabularInput({'rows': 3, 'columns': 5, 'newRowOnTab': true});
jQuery('pre').each(function(i, block) {
hljs.highlightBlock(block);
});
jQuery('#tabular1').tabularInput({'rows': 3, 'columns': 5});
jQuery('#tabular2').tabularInput({'rows': 3, 'columns': 5, 'animate': true});
jQuery('#tabular3').tabularInput({'rows': 3, 'columns': 5, 'newRowOnTab': true, 'animate': true});
jQuery('#tabular4').tabularInput({'rows': 3, 'columns': 4, 'columnHeads': ['Name', 'Age', 'Sex', 'Occupation']});
jQuery('#tabular5').tabularInput({'rows': 3, 'columns': 5, 'name': 'myField'});
});
</script>

Expand Down
50 changes: 45 additions & 5 deletions docs/style.css
Expand Up @@ -2,25 +2,65 @@ body
{
font-family: 'Helvetica', Arial;
content: #555;
font-size: .95em;
}

.example
{
margin: 75px auto;
margin: 5em auto;
}

h1, h2, h3
{
font-weight: normal;
content: #555;
color: #444;
}

button
{
font-family: 'Helvetica', Arial;
box-shadow: none;
color: #555;
font-weight: 600;
font-size: .75em;
letter-spacing: .2px;
border: 1px solid #ccc;
padding: .9em 1.5em;
background-color: #fafafa;
border-radius: 2px;
cursor: pointer;
margin-right: 7px;
display: inline-block;
opacity: .95;
}

button:focus
{
outline: none;
}

button:hover
{
box-shadow: 0px 0px 4px #c9c9c9;
opacity: 1;
}

pre
pre,
pre.hljs
{
font-size: 1.05em;
border-bottom: 1px solid #ddd;
border-right: 1px solid #ddd;
border-radius: 3px;
border-radius: 2px;
padding: 14px 16px;
background-color: #fafafa;
background-color: #f3f3f3;
box-shadow: 1px 1px 1px #aaa inset;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
}

.tabularInput-table
{
margin: 12px 0px;
}

0 comments on commit bed13f5

Please sign in to comment.