差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
| study:javascript:start [2012/12/31 13:50] – [demo page] banana | study:javascript:start [2015/02/19 07:07] (現在) – [Add Comma] banana | ||
|---|---|---|---|
| 行 78: | 行 78: | ||
| ====== Merge Rowspan ====== | ====== Merge Rowspan ====== | ||
| <code javascript> | <code javascript> | ||
| - | function | + | (function ($) { |
| - | { | + | $.extend($.fn, { |
| - | var rowsCn = tableObj.rows.length; | + | |
| - | + | | |
| - | if(rowsCn-1 > rowIndex) | + | |
| - | cellMergeProcess(tableObj, rowIndex, cellIndex); | + | } |
| - | } | + | }); |
| - | + | ||
| - | function cellMergeProcess(tableObj, | + | |
| - | { | + | |
| - | var rowsCn = tableObj.rows.length; | + | |
| - | var compareCellsLen = tableObj.rows[rowIndex].cells.length; | + | |
| - | + | ||
| - | // | + | |
| - | var compareObj = tableObj.rows[rowIndex].cells[cellIndex]; | + | |
| - | var compareValue = compareObj.innerHTML; | + | |
| - | var cn = 1; | + | |
| - | var delCells = new Array(); | + | |
| - | var arrCellIndex = new Array(); | + | |
| - | for(i=rowIndex+1; | + | |
| - | { | + | |
| - | var cellsLen = tableObj.rows[i].cells.length; | + | |
| - | var bufCellIndex = cellIndex | + | |
| - | //get collIndex of row | + | |
| - | if(compareCellsLen != cellsLen) | + | |
| - | { | + | // merge options |
| - | bufCellIndex | + | this.o = $.extend(true, {}, $.impl.defaults, |
| - | } | + | |
| - | cellObj = tableObj.rows[i].cells[bufCellIndex]; | + | this.init(); |
| - | + | }; | |
| - | if(compareValue == cellObj.innerHTML) | + | |
| - | { | + | |
| - | //save the number of cell to delete. | + | |
| - | delCells[cn-1] = tableObj.rows[i]; | + | |
| - | //save the index of row cell. | + | |
| - | arrCellIndex[cn - 1] = bufCellIndex; | + | |
| - | cn++; | + | |
| - | } | + | |
| - | else | + | |
| - | { | + | |
| - | // | + | |
| - | compareObj.rowSpan = cn; | + | |
| - | + | ||
| - | // | + | |
| - | for(j=0; j < delCells.length; | + | |
| - | { | + | |
| - | delCells[j].deleteCell(arrCellIndex[j]); | + | |
| - | } | + | |
| - | + | ||
| - | // | + | |
| - | compareObj | + | |
| - | compareValue = cellObj.innerHTML; | + | |
| - | cn = 1; | + | |
| - | delCells = new Array(); | + | |
| - | arrCellIndex = new Array(); | + | |
| - | } | + | |
| - | } | + | |
| - | //merge | + | |
| - | compareObj.rowSpan = cn; | + | $.extend($.impl, |
| - | //delete | + | |
| - | for(j=0; j < delCells.length; j++) | + | rowIndex: 1, |
| - | { | + | cellIndex: [1] |
| - | delCells[j].deleteCell(arrCellIndex[j]); | + | }, |
| - | } | + | prototype: { |
| - | }// | + | init: function() { |
| + | // cell length before merging | ||
| + | | ||
| + | this.delArrays | ||
| + | this._scan(); | ||
| + | }, | ||
| + | _scan: function() { | ||
| + | var self = this, | ||
| + | indexArray = self.o.cellIndex; | ||
| + | $.each(indexArray, | ||
| + | self._cellMergeChk(o); | ||
| + | }); | ||
| + | }, | ||
| + | _cellMergeChk: | ||
| + | var self = this, | ||
| + | $target = $(self.target), | ||
| + | options = self.o, | ||
| + | cnt = 1, | ||
| + | compareObj = $target.find(' | ||
| - | </code> | + | |
| + | $target.find(' | ||
| + | // compare cell's length | ||
| + | compareIndex = cellIndex; | ||
| + | cellsLen = $(this).find(' | ||
| + | if (self.tdLen != cellsLen) { | ||
| + | compareIndex = compareIndex - (self.tdLen - cellsLen); | ||
| + | } | ||
| + | cellObj = $(this).find(' | ||
| + | if (compareObj.html() == cellObj.html()) { | ||
| + | self.delArrays[cnt - 1] = cellObj; | ||
| + | cnt++; | ||
| + | } else { | ||
| + | // merge | ||
| + | self._merge(compareObj); | ||
| + | // initialize | ||
| + | compareObj = cellObj; | ||
| + | self.delArrays = []; | ||
| + | cnt = 1; | ||
| + | }//if~else | ||
| + | }); | ||
| + | }, | ||
| + | _merge: function(mergedCell) { | ||
| + | $.each(this.delArrays, | ||
| + | $(this).remove(); | ||
| + | }); | ||
| + | mergedCell.attr(' | ||
| + | } | ||
| + | }// | ||
| + | }); | ||
| + | })(jQuery); | ||
| + | </ | ||
| - | ===== Usage ===== | ||
| - | #merge first <td> \\ | ||
| - | cellMergeChk(document.getElementById(" | ||
| - | #merge second <td> \\ | ||
| - | cellMergeChk(document.getElementById(" | ||
| - | ===== reference | + | |
| - | http://blog.naver.com/bacchusl? | + | |
| + | |||
| + | ===== Demo ===== | ||
| + | link to [[http://jsfiddle.net/loliqoop/ | ||
| 行 166: | 行 170: | ||
| ====== Add Comma ====== | ====== Add Comma ====== | ||
| <code javascript> | <code javascript> | ||
| - | function | + | function |
| - | | + | return ("" |
| - | if (number.length > 3) { | + | |
| - | var mod = number.length % 3; | + | |
| - | var output = (mod > 0 ? (number.substring(0, | + | |
| - | for (i=0 ; i < Math.floor(number.length / 3); i++) { | + | |
| - | if ((mod == 0) && (i == 0)){ | + | |
| - | output += number.substring(mod+ 3 * i, mod + 3 * i + 3); | + | |
| - | } else{ | + | |
| - | output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3); | + | |
| - | } | + | |
| - | }//end for | + | |
| - | return (output); | + | |
| - | | + | |
| - | return number; | + | |
| - | | + | |
| } | } | ||
| </ | </ | ||
| ちなみにカンマを除去するのは次のとおり | ちなみにカンマを除去するのは次のとおり | ||
| <code javascript> | <code javascript> | ||
| - | function | + | function |
| - | var str = '' | + | return number.replace(/ |
| - | var output=str.replace(/ | + | |
| - | return output; | + | |
| } | } | ||
| - | |||
| </ | </ | ||
| 行 337: | 行 324: | ||
| < | < | ||
| \\b(^_A-Za-z0-9-(\\._A-Za-z0-9-)*@(A-Za-z0-9-)+((\\.com)|(\\.net)|(\\.org)|(\\.info)|(\\.edu)|(\\.mil)|(\\.gov) | \\b(^_A-Za-z0-9-(\\._A-Za-z0-9-)*@(A-Za-z0-9-)+((\\.com)|(\\.net)|(\\.org)|(\\.info)|(\\.edu)|(\\.mil)|(\\.gov) | ||
| - | |(\\.biz)|(\\.ws)|(\\.us)|(\\.tv)|(\\.cc)|(\\.aero)|(\\.arpa)|(\\.coop)|(\\.int)|(\\.jobs)|(\\.museum)|(\\.name)|(\\.pro)|(\\.travel)|(\\.nato)|(\\..{2, | + | |(\\.biz)|(\\.ws)|(\\.us)|(\\.tv)|(\\.cc)|(\\.aero)|(\\.arpa)|(\\.coop)|(\\.int)|(\\.jobs)|(\\.museum)|(\\.name) |
| + | |(\\.pro)|(\\.travel)|(\\.nato)|(\\..{2, | ||
| </ | </ | ||
| ~~DISCUSSION~~ | ~~DISCUSSION~~ | ||