1/* jQuery Resizable Columns v0.1.0 | http://dobtco.github.io/jquery-resizable-columns/ | Licensed MIT | Built Wed Apr 30 2014 14:24:25 */ 2var __bind = function(fn, me) { 3 return function() { 4 return fn.apply(me, arguments); 5 }; 6}, 7 __slice = [].slice; 8 9(function($, window) { 10 var ResizableColumns, parseWidth, pointerX, setWidth; 11 parseWidth = function(node) { 12 return parseFloat(node.style.width.replace('%', '')); 13 }; 14 setWidth = function(node, width) { 15 width = width.toFixed(2); 16 return node.style.width = "" + width + "%"; 17 }; 18 pointerX = function(e) { 19 if (e.type.indexOf('touch') === 0) { 20 return (e.originalEvent.touches[0] || e.originalEvent.changedTouches[0]).pageX; 21 } 22 return e.pageX; 23 }; 24 ResizableColumns = (function() { 25 ResizableColumns.prototype.defaults = { 26 selector: 'tr th:visible', 27 store: window.store, 28 syncHandlers: true, 29 resizeFromBody: true, 30 maxWidth: null, 31 minWidth: null 32 }; 33 34 function ResizableColumns($table, options) { 35 this.pointerdown = __bind(this.pointerdown, this); 36 this.constrainWidth = __bind(this.constrainWidth, this); 37 this.options = $.extend({}, this.defaults, options); 38 this.$table = $table; 39 this.setHeaders(); 40 this.restoreColumnWidths(); 41 this.syncHandleWidths(); 42 $(window).on('resize.rc', ((function(_this) { 43 return function() { 44 return _this.syncHandleWidths(); 45 }; 46 })(this))); 47 if (this.options.start) { 48 this.$table.bind('column:resize:start.rc', this.options.start); 49 } 50 if (this.options.resize) { 51 this.$table.bind('column:resize.rc', this.options.resize); 52 } 53 if (this.options.stop) { 54 this.$table.bind('column:resize:stop.rc', this.options.stop); 55 } 56 } 57 58 ResizableColumns.prototype.triggerEvent = function(type, args, original) { 59 var event; 60 event = $.Event(type); 61 event.originalEvent = $.extend({}, original); 62 return this.$table.trigger(event, [this].concat(args || [])); 63 }; 64 65 ResizableColumns.prototype.getColumnId = function($el) { 66 return this.$table.data('resizable-columns-id') + '-' + $el.data('resizable-column-id'); 67 }; 68 69 ResizableColumns.prototype.setHeaders = function() { 70 this.$tableHeaders = this.$table.find(this.options.selector); 71 this.assignPercentageWidths(); 72 return this.createHandles(); 73 }; 74 75 ResizableColumns.prototype.destroy = function() { 76 this.$handleContainer.remove(); 77 this.$table.removeData('resizableColumns'); 78 return this.$table.add(window).off('.rc'); 79 }; 80 81 ResizableColumns.prototype.assignPercentageWidths = function() { 82 return this.$tableHeaders.each((function(_this) { 83 return function(_, el) { 84 var $el; 85 $el = $(el); 86 return setWidth($el[0], $el.outerWidth() / _this.$table.width() * 100); 87 }; 88 })(this)); 89 }; 90 91 ResizableColumns.prototype.createHandles = function() { 92 var _ref; 93 if ((_ref = this.$handleContainer) != null) { 94 _ref.remove(); 95 } 96 this.$table.before((this.$handleContainer = $("<div class='rc-handle-container' />"))); 97 this.$tableHeaders.each((function(_this) { 98 return function(i, el) { 99 var $handle; 100 if (_this.$tableHeaders.eq(i + 1).length === 0 || (_this.$tableHeaders.eq(i).attr('data-noresize') != null) || (_this.$tableHeaders.eq(i + 1).attr('data-noresize') != null)) { 101 return; 102 } 103 $handle = $("<div class='rc-handle' />"); 104 $handle.data('th', $(el)); 105 return $handle.appendTo(_this.$handleContainer); 106 }; 107 })(this)); 108 return this.$handleContainer.on('mousedown touchstart', '.rc-handle', this.pointerdown); 109 }; 110 111 ResizableColumns.prototype.syncHandleWidths = function() { 112 return this.$handleContainer.width(this.$table.width()).find('.rc-handle').each((function(_this) { 113 return function(_, el) { 114 var $el; 115 $el = $(el); 116 return $el.css({ 117 left: $el.data('th').outerWidth() + ($el.data('th').offset().left - _this.$handleContainer.offset().left), 118 height: _this.options.resizeFromBody ? _this.$table.height() : _this.$table.find('thead').height() 119 }); 120 }; 121 })(this)); 122 }; 123 124 ResizableColumns.prototype.saveColumnWidths = function() { 125 return this.$tableHeaders.each((function(_this) { 126 return function(_, el) { 127 var $el; 128 $el = $(el); 129 if ($el.attr('data-noresize') == null) { 130 if (_this.options.store != null) { 131 return _this.options.store.set(_this.getColumnId($el), parseWidth($el[0])); 132 } 133 } 134 }; 135 })(this)); 136 }; 137 138 ResizableColumns.prototype.restoreColumnWidths = function() { 139 return this.$tableHeaders.each((function(_this) { 140 return function(_, el) { 141 var $el, width; 142 $el = $(el); 143 if ((_this.options.store != null) && (width = _this.options.store.get(_this.getColumnId($el)))) { 144 return setWidth($el[0], width); 145 } 146 }; 147 })(this)); 148 }; 149 150 ResizableColumns.prototype.totalColumnWidths = function() { 151 var total; 152 total = 0; 153 this.$tableHeaders.each((function(_this) { 154 return function(_, el) { 155 return total += parseFloat($(el)[0].style.width.replace('%', '')); 156 }; 157 })(this)); 158 return total; 159 }; 160 161 ResizableColumns.prototype.constrainWidth = function(width) { 162 if (this.options.minWidth != null) { 163 width = Math.max(this.options.minWidth, width); 164 } 165 if (this.options.maxWidth != null) { 166 width = Math.min(this.options.maxWidth, width); 167 } 168 return width; 169 }; 170 171 ResizableColumns.prototype.pointerdown = function(e) { 172 var $currentGrip, $leftColumn, $ownerDocument, $rightColumn, newWidths, startPosition, widths; 173 e.preventDefault(); 174 $ownerDocument = $(e.currentTarget.ownerDocument); 175 startPosition = pointerX(e); 176 $currentGrip = $(e.currentTarget); 177 $leftColumn = $currentGrip.data('th'); 178 $rightColumn = this.$tableHeaders.eq(this.$tableHeaders.index($leftColumn) + 1); 179 widths = { 180 left: parseWidth($leftColumn[0]), 181 right: parseWidth($rightColumn[0]) 182 }; 183 newWidths = { 184 left: widths.left, 185 right: widths.right 186 }; 187 this.$handleContainer.add(this.$table).addClass('rc-table-resizing'); 188 $leftColumn.add($rightColumn).add($currentGrip).addClass('rc-column-resizing'); 189 this.triggerEvent('column:resize:start', [$leftColumn, $rightColumn, newWidths.left, newWidths.right], e); 190 $ownerDocument.on('mousemove.rc touchmove.rc', (function(_this) { 191 return function(e) { 192 var difference; 193 difference = (pointerX(e) - startPosition) / _this.$table.width() * 100; 194 setWidth($leftColumn[0], newWidths.left = _this.constrainWidth(widths.left + difference)); 195 setWidth($rightColumn[0], newWidths.right = _this.constrainWidth(widths.right - difference)); 196 if (_this.options.syncHandlers != null) { 197 _this.syncHandleWidths(); 198 } 199 return _this.triggerEvent('column:resize', [$leftColumn, $rightColumn, newWidths.left, newWidths.right], e); 200 }; 201 })(this)); 202 return $ownerDocument.one('mouseup touchend', (function(_this) { 203 return function() { 204 $ownerDocument.off('mousemove.rc touchmove.rc'); 205 _this.$handleContainer.add(_this.$table).removeClass('rc-table-resizing'); 206 $leftColumn.add($rightColumn).add($currentGrip).removeClass('rc-column-resizing'); 207 _this.syncHandleWidths(); 208 _this.saveColumnWidths(); 209 return _this.triggerEvent('column:resize:stop', [$leftColumn, $rightColumn, newWidths.left, newWidths.right], e); 210 }; 211 })(this)); 212 }; 213 214 return ResizableColumns; 215 216 })(); 217 return $.fn.extend({ 218 resizableColumns: function() { 219 var args, option; 220 option = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; 221 return this.each(function() { 222 var $table, data; 223 $table = $(this); 224 data = $table.data('resizableColumns'); 225 if (!data) { 226 $table.data('resizableColumns', (data = new ResizableColumns($table, option))); 227 } 228 if (typeof option === 'string') { 229 return data[option].apply(data, args); 230 } 231 }); 232 } 233 }); 234})(window.jQuery, window);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.