col_resizable-rails 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 54990f2e156466fb5efe98db2b9e94a48c9433fc
4
+ data.tar.gz: 330936a3b2361e0486a20e5fc29828fb5cef594f
5
+ SHA512:
6
+ metadata.gz: 54ce4404e6e2ed103ae5e7be92300ef775c56de574948abada4e400b88a8feac5c2b8c73cc114ee441ab64c58ff1690a6a1cd4ae4cbab77f826d085fca6bb200
7
+ data.tar.gz: b53ca5a7bcb34aee4067dfa8a86eaedd728fc72be6027955ac98fe4979de3a3808b2dfc81fb247118be3624b89997751a33b1c76d56d9441f8afbaca9794edbd
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in col_resizable-rails.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Abinoam P. Marques Jr.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # col_resizable-rails
2
+
3
+ colResizable.js for Rails.
4
+
5
+ colResizable.js was created by Alvaro Prieto Lauroba (@alvaro-prieto).
6
+
7
+ This gem package was made by Abinoam Praxedes Marques Jr. (@abinoam).
8
+
9
+ This gem provides: colResizable 1.6.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'col_resizable-rails'
17
+ ```
18
+
19
+ Then add it to your asset pipeline (at ```app/assets/javascripts/application.js```):
20
+
21
+ ```js
22
+ //= require colResizable.min
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install col_resizable-rails
32
+
33
+ ## Usage
34
+
35
+ Check official colResizable website for usage information.
36
+ * http://www.bacubacu.com/colresizable/
37
+ * https://github.com/alvaro-prieto/colResizable
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Abinoam P. Marques Jr./col_resizable-rails.
48
+
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
53
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "col_resizable/rails"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'col_resizable/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "col_resizable-rails"
8
+ spec.version = ColResizable::Rails::VERSION
9
+ spec.authors = ["Abinoam P. Marques Jr."]
10
+ spec.email = ["abinoam@gmail.com"]
11
+
12
+ spec.summary = %q{colResizable js library gem package}
13
+ spec.description = %q{colResizable is a free jQuery plugin designed to enhance any kind of HTML table object adding column resizing features by dragging column anchors manually.}
14
+ spec.homepage = "https://github.com/abinoam/col_resizable-rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
@@ -0,0 +1,7 @@
1
+ require "col_resizable/rails/version"
2
+ require "col_resizable/rails/engine"
3
+
4
+ module ColResizable
5
+ module Rails
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module ColResizable
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module ColResizable
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,415 @@
1
+ /**
2
+ _ _____ _ _ _
3
+ | | __ \ (_) | | | |
4
+ ___ ___ | | |__) |___ ___ _ ______ _| |__ | | ___
5
+ / __/ _ \| | _ // _ \/ __| |_ / _` | '_ \| |/ _ \
6
+ | (_| (_) | | | \ \ __/\__ \ |/ / (_| | |_) | | __/
7
+ \___\___/|_|_| \_\___||___/_/___\__,_|_.__/|_|\___|
8
+
9
+ v1.7 - jQuery plugin created by Alvaro Prieto Lauroba
10
+
11
+ Licences: MIT & GPL
12
+ Feel free to use or modify this plugin as far as my full name is kept
13
+ */
14
+
15
+ (function($){
16
+
17
+ var d = $(document); //window object
18
+ var h = $("head"); //head object
19
+ var drag = null; //reference to the current grip that is being dragged
20
+ var tables = {}; //object of the already processed tables (table.id as key)
21
+ var count = 0; //internal count to create unique IDs when needed.
22
+
23
+ //common strings for packing
24
+ var ID = "id";
25
+ var PX = "px";
26
+ var SIGNATURE ="JColResizer";
27
+ var FLEX = "JCLRFlex";
28
+
29
+ //short-cuts
30
+ var I = parseInt;
31
+ var M = Math;
32
+ var ie = navigator.userAgent.indexOf('Trident/4.0')>0;
33
+ var S;
34
+ var pad = ""
35
+ try{S = sessionStorage;}catch(e){} //Firefox crashes when executed as local file system
36
+
37
+
38
+ //append required CSS rules
39
+ h.append("<style type='text/css'> .JColResizer{table-layout:fixed;} .JColResizer > tbody > tr > td, .JColResizer > tbody > tr > th{overflow:hidden} .JPadding > tbody > tr > td, .JPadding > tbody > tr > th{padding-left:0!important; padding-right:0!important;} .JCLRgrips{ height:0px; position:relative;} .JCLRgrip{margin-left:-5px; position:absolute; z-index:5; } .JCLRgrip .JColResizer{position:absolute;background-color:red;filter:alpha(opacity=1);opacity:0;width:10px;height:100%;cursor: col-resize;top:0px} .JCLRLastGrip{position:absolute; width:1px; } .JCLRgripDrag{ border-left:1px dotted black; } .JCLRFlex{width:auto!important;} .JCLRgrip.JCLRdisabledGrip .JColResizer{cursor:default; display:none;}</style>");
40
+
41
+
42
+ /**
43
+ * Function to allow column resizing for table objects. It is the starting point to apply the plugin.
44
+ * @param {DOM node} tb - reference to the DOM table object to be enhanced
45
+ * @param {Object} options - some customization values
46
+ */
47
+ var init = function( tb, options){
48
+ var t = $(tb); //the table object is wrapped
49
+ t.opt = options; //each table has its own options available at anytime
50
+ t.mode = options.resizeMode; //shortcuts
51
+ t.dc = t.opt.disabledColumns;
52
+ if(t.opt.removePadding) t.addClass("JPadding");
53
+ if(t.opt.disable) return destroy(t); //the user is asking to destroy a previously colResized table
54
+ var id = t.id = t.attr(ID) || SIGNATURE+count++; //its id is obtained, if null new one is generated
55
+ t.p = t.opt.postbackSafe; //short-cut to detect postback safe
56
+ if(!t.is("table") || tables[id] && !t.opt.partialRefresh) return; //if the object is not a table or if it was already processed then it is ignored.
57
+ if (t.opt.hoverCursor !== 'col-resize') h.append("<style type='text/css'>.JCLRgrip .JColResizer:hover{cursor:"+ t.opt.hoverCursor +"!important}</style>"); //if hoverCursor has been set, append the style
58
+ t.addClass(SIGNATURE).attr(ID, id).before('<div class="JCLRgrips"/>'); //the grips container object is added. Signature class forces table rendering in fixed-layout mode to prevent column's min-width
59
+ t.g = []; t.c = []; t.w = t.width(); t.gc = t.prev(); t.f=t.opt.fixed; //t.c and t.g are arrays of columns and grips respectively
60
+ if(options.marginLeft) t.gc.css("marginLeft", options.marginLeft); //if the table contains margins, it must be specified
61
+ if(options.marginRight) t.gc.css("marginRight", options.marginRight); //since there is no (direct) way to obtain margin values in its original units (%, em, ...)
62
+ t.cs = I(ie? tb.cellSpacing || tb.currentStyle.borderSpacing :t.css('border-spacing'))||2; //table cellspacing (not even jQuery is fully cross-browser)
63
+ t.b = I(ie? tb.border || tb.currentStyle.borderLeftWidth :t.css('border-left-width'))||1; //outer border width (again cross-browser issues)
64
+ // if(!(tb.style.width || tb.width)) t.width(t.width()); //I am not an IE fan at all, but it is a pity that only IE has the currentStyle attribute working as expected. For this reason I can not check easily if the table has an explicit width or if it is rendered as "auto"
65
+ tables[id] = t; //the table object is stored using its id as key
66
+ createGrips(t); //grips are created
67
+
68
+ };
69
+
70
+
71
+ /**
72
+ * This function allows to remove any enhancements performed by this plugin on a previously processed table.
73
+ * @param {jQuery ref} t - table object
74
+ */
75
+ var destroy = function(t){
76
+ var id=t.attr(ID), t=tables[id]; //its table object is found
77
+ if(!t||!t.is("table")) return; //if none, then it wasn't processed
78
+ t.removeClass(SIGNATURE+" "+FLEX).gc.remove(); //class and grips are removed
79
+ delete tables[id]; //clean up data
80
+ };
81
+
82
+
83
+ /**
84
+ * Function to create all the grips associated with the table given by parameters
85
+ * @param {jQuery ref} t - table object
86
+ */
87
+ var createGrips = function(t){
88
+
89
+ var th = t.find(">thead>tr:first>th,>thead>tr:first>td"); //table headers are obtained
90
+ if(!th.length) th = t.find(">tbody>tr:first>th,>tr:first>th,>tbody>tr:first>td, >tr:first>td"); //but headers can also be included in different ways
91
+ th = th.filter(":visible"); //filter invisible columns
92
+ t.cg = t.find("col"); //a table can also contain a colgroup with col elements
93
+ t.ln = th.length; //table length is stored
94
+ if(t.p && S && S[t.id])memento(t,th); //if 'postbackSafe' is enabled and there is data for the current table, its coloumn layout is restored
95
+ th.each(function(i){ //iterate through the table column headers
96
+ var c = $(this); //jquery wrap for the current column
97
+ var dc = t.dc.indexOf(i)!=-1; //is this a disabled column?
98
+ var g = $(t.gc.append('<div class="JCLRgrip"></div>')[0].lastChild); //add the visual node to be used as grip
99
+ g.append(dc ? "": t.opt.gripInnerHtml).append('<div class="'+SIGNATURE+'"></div>');
100
+ if(i == t.ln-1){ //if the current grip is the las one
101
+ g.addClass("JCLRLastGrip"); //add a different css class to stlye it in a different way if needed
102
+ if(t.f) g.html(""); //if the table resizing mode is set to fixed, the last grip is removed since table with can not change
103
+ }
104
+ g.bind('touchstart mousedown', onGripMouseDown); //bind the mousedown event to start dragging
105
+
106
+ if (!dc){
107
+ //if normal column bind the mousedown event to start dragging, if disabled then apply its css class
108
+ g.removeClass('JCLRdisabledGrip').bind('touchstart mousedown', onGripMouseDown);
109
+ }else{
110
+ g.addClass('JCLRdisabledGrip');
111
+ }
112
+
113
+ g.t = t; g.i = i; g.c = c; c.w =c.width(); //some values are stored in the grip's node data as shortcut
114
+ t.g.push(g); t.c.push(c); //the current grip and column are added to its table object
115
+ c.width(c.w).removeAttr("width"); //the width of the column is converted into pixel-based measurements
116
+ g.data(SIGNATURE, {i:i, t:t.attr(ID), last: i == t.ln-1}); //grip index and its table name are stored in the HTML
117
+ });
118
+ t.cg.removeAttr("width"); //remove the width attribute from elements in the colgroup
119
+
120
+ t.find('td, th').not(th).not('table th, table td').each(function(){
121
+ $(this).removeAttr('width'); //the width attribute is removed from all table cells which are not nested in other tables and dont belong to the header
122
+ });
123
+ if(!t.f){
124
+ t.removeAttr('width').addClass(FLEX); //if not fixed, let the table grow as needed
125
+ }
126
+ syncGrips(t); //the grips are positioned according to the current table layout
127
+ //there is a small problem, some cells in the table could contain dimension values interfering with the
128
+ //width value set by this plugin. Those values are removed
129
+
130
+ };
131
+
132
+
133
+ /**
134
+ * Function to allow the persistence of columns dimensions after a browser postback. It is based in
135
+ * the HTML5 sessionStorage object, which can be emulated for older browsers using sessionstorage.js
136
+ * @param {jQuery ref} t - table object
137
+ * @param {jQuery ref} th - reference to the first row elements (only set in deserialization)
138
+ */
139
+ var memento = function(t, th){
140
+ var w,m=0,i=0,aux =[],tw;
141
+ if(th){ //in deserialization mode (after a postback)
142
+ t.cg.removeAttr("width");
143
+ if(t.opt.flush){ S[t.id] =""; return;} //if flush is activated, stored data is removed
144
+ w = S[t.id].split(";"); //column widths is obtained
145
+ tw = w[t.ln+1];
146
+ if(!t.f && tw){ //if not fixed and table width data available its size is restored
147
+ t.width(tw*=1);
148
+ if(t.opt.overflow) { //if overfolw flag is set, restore table width also as table min-width
149
+ t.css('min-width', tw + PX);
150
+ t.w = tw;
151
+ }
152
+ }
153
+ for(;i<t.ln;i++){ //for each column
154
+ aux.push(100*w[i]/w[t.ln]+"%"); //width is stored in an array since it will be required again a couple of lines ahead
155
+ th.eq(i).css("width", aux[i] ); //each column width in % is restored
156
+ }
157
+ for(i=0;i<t.ln;i++)
158
+ t.cg.eq(i).css("width", aux[i]); //this code is required in order to create an inline CSS rule with higher precedence than an existing CSS class in the "col" elements
159
+ }else{ //in serialization mode (after resizing a column)
160
+ S[t.id] =""; //clean up previous data
161
+ for(;i < t.c.length; i++){ //iterate through columns
162
+ w = t.c[i].width(); //width is obtained
163
+ S[t.id] += w+";"; //width is appended to the sessionStorage object using ID as key
164
+ m+=w; //carriage is updated to obtain the full size used by columns
165
+ }
166
+ S[t.id]+=m; //the last item of the serialized string is the table's active area (width),
167
+ //to be able to obtain % width value of each columns while deserializing
168
+ if(!t.f) S[t.id] += ";"+t.width(); //if not fixed, table width is stored
169
+ }
170
+ };
171
+
172
+
173
+ /**
174
+ * Function that places each grip in the correct position according to the current table layout
175
+ * @param {jQuery ref} t - table object
176
+ */
177
+ var syncGrips = function (t){
178
+ t.gc.width(t.w); //the grip's container width is updated
179
+ for(var i=0; i<t.ln; i++){ //for each column
180
+ var c = t.c[i];
181
+ t.g[i].css({ //height and position of the grip is updated according to the table layout
182
+ left: c.offset().left - t.offset().left + c.outerWidth(false) + t.cs / 2 + PX,
183
+ height: t.opt.headerOnly? t.c[0].outerHeight(false) : t.outerHeight(false)
184
+ });
185
+ }
186
+ };
187
+
188
+
189
+
190
+ /**
191
+ * This function updates column's width according to the horizontal position increment of the grip being
192
+ * dragged. The function can be called while dragging if liveDragging is enabled and also from the onGripDragOver
193
+ * event handler to synchronize grip's position with their related columns.
194
+ * @param {jQuery ref} t - table object
195
+ * @param {number} i - index of the grip being dragged
196
+ * @param {bool} isOver - to identify when the function is being called from the onGripDragOver event
197
+ */
198
+ var syncCols = function(t,i,isOver){
199
+ var inc = drag.x-drag.l, c = t.c[i], c2 = t.c[i+1];
200
+ var w = c.w + inc; var w2= c2.w- inc; //their new width is obtained
201
+ c.width( w + PX);
202
+ t.cg.eq(i).width( w + PX);
203
+ if(t.f){ //if fixed mode
204
+ c2.width(w2 + PX);
205
+ t.cg.eq(i+1).width( w2 + PX);
206
+ }else if(t.opt.overflow) { //if overflow is set, incriment min-width to force overflow
207
+ t.css('min-width', t.w + inc);
208
+ }
209
+ if(isOver){
210
+ c.w=w;
211
+ c2.w= t.f ? w2 : c2.w;
212
+ }
213
+ };
214
+
215
+
216
+ /**
217
+ * This function updates all columns width according to its real width. It must be taken into account that the
218
+ * sum of all columns can exceed the table width in some cases (if fixed is set to false and table has some kind
219
+ * of max-width).
220
+ * @param {jQuery ref} t - table object
221
+ */
222
+ var applyBounds = function(t){
223
+ var w = $.map(t.c, function(c){ //obtain real widths
224
+ return c.width();
225
+ });
226
+ t.width(t.w = t.width()).removeClass(FLEX); //prevent table width changes
227
+ $.each(t.c, function(i,c){
228
+ c.width(w[i]).w = w[i]; //set column widths applying bounds (table's max-width)
229
+ });
230
+ t.addClass(FLEX); //allow table width changes
231
+ };
232
+
233
+
234
+ /**
235
+ * Event handler used while dragging a grip. It checks if the next grip's position is valid and updates it.
236
+ * @param {event} e - mousemove event binded to the window object
237
+ */
238
+ var onGripDrag = function(e){
239
+ if(!drag) return;
240
+ var t = drag.t; //table object reference
241
+ var oe = e.originalEvent.touches;
242
+ var ox = oe ? oe[0].pageX : e.pageX; //original position (touch or mouse)
243
+ var x = ox - drag.ox + drag.l; //next position according to horizontal mouse position increment
244
+ var mw = t.opt.minWidth, i = drag.i ; //cell's min width
245
+ var l = t.cs*1.5 + mw + t.b;
246
+ var last = i == t.ln-1; //check if it is the last column's grip (usually hidden)
247
+ var min = i? t.g[i-1].position().left+t.cs+mw: l; //min position according to the contiguous cells
248
+ var max = t.f ? //fixed mode?
249
+ i == t.ln-1?
250
+ t.w-l:
251
+ t.g[i+1].position().left-t.cs-mw:
252
+ Infinity; //max position according to the contiguous cells
253
+ x = M.max(min, M.min(max, x)); //apply bounding
254
+ drag.x = x; drag.css("left", x + PX); //apply position increment
255
+ if(last){ //if it is the last grip
256
+ var c = t.c[drag.i]; //width of the last column is obtained
257
+ drag.w = c.w + x- drag.l;
258
+ }
259
+ if(t.opt.liveDrag){ //if liveDrag is enabled
260
+ if(last){
261
+ c.width(drag.w);
262
+ if(!t.f && t.opt.overflow){ //if overflow is set, incriment min-width to force overflow
263
+ t.css('min-width', t.w + x - drag.l);
264
+ }else {
265
+ t.w = t.width();
266
+ }
267
+ }else{
268
+ syncCols(t,i); //columns are synchronized
269
+ }
270
+ syncGrips(t);
271
+ var cb = t.opt.onDrag; //check if there is an onDrag callback
272
+ if (cb) { e.currentTarget = t[0]; cb(e); } //if any, it is fired
273
+ }
274
+ return false; //prevent text selection while dragging
275
+ };
276
+
277
+
278
+ /**
279
+ * Event handler fired when the dragging is over, updating table layout
280
+ * @param {event} e - grip's drag over event
281
+ */
282
+ var onGripDragOver = function(e){
283
+
284
+ d.unbind('touchend.'+SIGNATURE+' mouseup.'+SIGNATURE).unbind('touchmove.'+SIGNATURE+' mousemove.'+SIGNATURE);
285
+ $("head :last-child").remove(); //remove the dragging cursor style
286
+ if(!drag) return;
287
+ drag.removeClass(drag.t.opt.draggingClass); //remove the grip's dragging css-class
288
+ if (!(drag.x - drag.l == 0)) {
289
+ var t = drag.t;
290
+ var cb = t.opt.onResize; //get some values
291
+ var i = drag.i; //column index
292
+ var last = i == t.ln-1; //check if it is the last column's grip (usually hidden)
293
+ var c = t.g[i].c; //the column being dragged
294
+ if(last){
295
+ c.width(drag.w);
296
+ c.w = drag.w;
297
+ }else{
298
+ syncCols(t, i, true); //the columns are updated
299
+ }
300
+ if(!t.f) applyBounds(t); //if not fixed mode, then apply bounds to obtain real width values
301
+ syncGrips(t); //the grips are updated
302
+ if (cb) { e.currentTarget = t[0]; cb(e); } //if there is a callback function, it is fired
303
+ if(t.p && S) memento(t); //if postbackSafe is enabled and there is sessionStorage support, the new layout is serialized and stored
304
+ }
305
+ drag = null; //since the grip's dragging is over
306
+ };
307
+
308
+
309
+ /**
310
+ * Event handler fired when the grip's dragging is about to start. Its main goal is to set up events
311
+ * and store some values used while dragging.
312
+ * @param {event} e - grip's mousedown event
313
+ */
314
+ var onGripMouseDown = function(e){
315
+ var o = $(this).data(SIGNATURE); //retrieve grip's data
316
+ var t = tables[o.t], g = t.g[o.i]; //shortcuts for the table and grip objects
317
+ var oe = e.originalEvent.touches; //touch or mouse event?
318
+ g.ox = oe? oe[0].pageX: e.pageX; //the initial position is kept
319
+ g.l = g.position().left;
320
+ g.x = g.l;
321
+
322
+ d.bind('touchmove.'+SIGNATURE+' mousemove.'+SIGNATURE, onGripDrag ).bind('touchend.'+SIGNATURE+' mouseup.'+SIGNATURE, onGripDragOver); //mousemove and mouseup events are bound
323
+ h.append("<style type='text/css'>*{cursor:"+ t.opt.dragCursor +"!important}</style>"); //change the mouse cursor
324
+ g.addClass(t.opt.draggingClass); //add the dragging class (to allow some visual feedback)
325
+ drag = g; //the current grip is stored as the current dragging object
326
+ if(t.c[o.i].l) for(var i=0,c; i<t.ln; i++){ c=t.c[i]; c.l = false; c.w= c.width(); } //if the colum is locked (after browser resize), then c.w must be updated
327
+ return false; //prevent text selection
328
+ };
329
+
330
+
331
+ /**
332
+ * Event handler fired when the browser is resized. The main purpose of this function is to update
333
+ * table layout according to the browser's size synchronizing related grips
334
+ */
335
+ var onResize = function(){
336
+ for(var t in tables){
337
+ if( tables.hasOwnProperty( t ) ) {
338
+ t = tables[t];
339
+ var i, mw=0;
340
+ t.removeClass(SIGNATURE); //firefox doesn't like layout-fixed in some cases
341
+ if (t.f) { //in fixed mode
342
+ t.w = t.width(); //its new width is kept
343
+ for(i=0; i<t.ln; i++) mw+= t.c[i].w;
344
+ //cell rendering is not as trivial as it might seem, and it is slightly different for
345
+ //each browser. In the beginning i had a big switch for each browser, but since the code
346
+ //was extremely ugly now I use a different approach with several re-flows. This works
347
+ //pretty well but it's a bit slower. For now, lets keep things simple...
348
+ for(i=0; i<t.ln; i++) t.c[i].css("width", M.round(1000*t.c[i].w/mw)/10 + "%").l=true;
349
+ //c.l locks the column, telling us that its c.w is outdated
350
+ }else{ //in non fixed-sized tables
351
+ applyBounds(t); //apply the new bounds
352
+ if(t.mode == 'flex' && t.p && S){ //if postbackSafe is enabled and there is sessionStorage support,
353
+ memento(t); //the new layout is serialized and stored for 'flex' tables
354
+ }
355
+ }
356
+ syncGrips(t.addClass(SIGNATURE));
357
+ }
358
+ }
359
+
360
+ };
361
+
362
+
363
+ //bind resize event, to update grips position
364
+ $(window).bind('resize.'+SIGNATURE, onResize);
365
+
366
+
367
+ /**
368
+ * The plugin is added to the jQuery library
369
+ * @param {Object} options - an object that holds some basic customization values
370
+ */
371
+ $.fn.extend({
372
+ colResizable: function(options) {
373
+ var defaults = {
374
+
375
+ //attributes:
376
+
377
+ resizeMode: 'fit', //mode can be 'fit', 'flex' or 'overflow'
378
+ draggingClass: 'JCLRgripDrag', //css-class used when a grip is being dragged (for visual feedback purposes)
379
+ gripInnerHtml: '', //if it is required to use a custom grip it can be done using some custom HTML
380
+ liveDrag: false, //enables table-layout updating while dragging
381
+ minWidth: 15, //minimum width value in pixels allowed for a column
382
+ headerOnly: false, //specifies that the size of the the column resizing anchors will be bounded to the size of the first row
383
+ hoverCursor: "col-resize", //cursor to be used on grip hover
384
+ dragCursor: "col-resize", //cursor to be used while dragging
385
+ postbackSafe: false, //when it is enabled, table layout can persist after postback or page refresh. It requires browsers with sessionStorage support (it can be emulated with sessionStorage.js).
386
+ flush: false, //when postbakSafe is enabled, and it is required to prevent layout restoration after postback, 'flush' will remove its associated layout data
387
+ marginLeft: null, //in case the table contains any margins, colResizable needs to know the values used, e.g. "10%", "15em", "5px" ...
388
+ marginRight: null, //in case the table contains any margins, colResizable needs to know the values used, e.g. "10%", "15em", "5px" ...
389
+ disable: false, //disables all the enhancements performed in a previously colResized table
390
+ partialRefresh: false, //can be used in combination with postbackSafe when the table is inside of an updatePanel,
391
+ disabledColumns: [], //column indexes to be excluded
392
+ removePadding: true, //for some uses (such as multiple range slider), it is advised to set this modifier to true, it will remove padding from the header cells.
393
+
394
+ //events:
395
+ onDrag: null, //callback function to be fired during the column resizing process if liveDrag is enabled
396
+ onResize: null //callback function fired when the dragging process is over
397
+ }
398
+ var options = $.extend(defaults, options);
399
+
400
+ //since now there are 3 different ways of resizing columns, I changed the external interface to make it clear
401
+ //calling it 'resizeMode' but also to remove the "fixed" attribute which was confusing for many people
402
+ options.fixed = true;
403
+ options.overflow = false;
404
+ switch(options.resizeMode){
405
+ case 'flex': options.fixed = false; break;
406
+ case 'overflow': options.fixed = false; options.overflow = true; break;
407
+ }
408
+
409
+ return this.each(function() {
410
+ init( this, options);
411
+ });
412
+ }
413
+ });
414
+ })(jQuery);
415
+
@@ -0,0 +1,3 @@
1
+ // colResizable 1.6 - a jQuery plugin by Alvaro Prieto Lauroba http://www.bacubacu.com/colresizable/
2
+
3
+ !function(t){var e,i=t(document),r=t("head"),o=null,s={},d=0,n="id",a="px",l="JColResizer",c="JCLRFlex",f=parseInt,h=Math,p=navigator.userAgent.indexOf("Trident/4.0")>0;try{e=sessionStorage}catch(g){}r.append("<style type='text/css'> .JColResizer{table-layout:fixed;} .JColResizer > tbody > tr > td, .JColResizer > tbody > tr > th{overflow:hidden} .JCLRgrips{ height:0px; position:relative;} .JCLRgrip{margin-left:-5px; position:absolute; z-index:5; } .JCLRgrip .JColResizer{position:absolute;background-color:red;filter:alpha(opacity=1);opacity:0;width:10px;height:100%;cursor: col-resize;top:0px} .JCLRLastGrip{position:absolute; width:1px; } .JCLRgripDrag{ border-left:1px dotted black; } .JCLRFlex{width:auto!important;} .JCLRgrip.JCLRdisabledGrip .JColResizer{cursor:default; display:none;}</style>");var u=function(e,i){var o=t(e);if(o.opt=i,o.mode=i.resizeMode,o.dc=o.opt.disabledColumns,o.opt.disable)return w(o);var a=o.id=o.attr(n)||l+d++;o.p=o.opt.postbackSafe,!o.is("table")||s[a]&&!o.opt.partialRefresh||("col-resize"!==o.opt.hoverCursor&&r.append("<style type='text/css'>.JCLRgrip .JColResizer:hover{cursor:"+o.opt.hoverCursor+"!important}</style>"),o.addClass(l).attr(n,a).before('<div class="JCLRgrips"/>'),o.g=[],o.c=[],o.w=o.width(),o.gc=o.prev(),o.f=o.opt.fixed,i.marginLeft&&o.gc.css("marginLeft",i.marginLeft),i.marginRight&&o.gc.css("marginRight",i.marginRight),o.cs=f(p?e.cellSpacing||e.currentStyle.borderSpacing:o.css("border-spacing"))||2,o.b=f(p?e.border||e.currentStyle.borderLeftWidth:o.css("border-left-width"))||1,s[a]=o,v(o))},w=function(t){var e=t.attr(n),t=s[e];t&&t.is("table")&&(t.removeClass(l+" "+c).gc.remove(),delete s[e])},v=function(i){var r=i.find(">thead>tr:first>th,>thead>tr:first>td");r.length||(r=i.find(">tbody>tr:first>th,>tr:first>th,>tbody>tr:first>td, >tr:first>td")),r=r.filter(":visible"),i.cg=i.find("col"),i.ln=r.length,i.p&&e&&e[i.id]&&m(i,r),r.each(function(e){var r=t(this),o=-1!=i.dc.indexOf(e),s=t(i.gc.append('<div class="JCLRgrip"></div>')[0].lastChild);s.append(o?"":i.opt.gripInnerHtml).append('<div class="'+l+'"></div>'),e==i.ln-1&&(s.addClass("JCLRLastGrip"),i.f&&s.html("")),s.bind("touchstart mousedown",J),o?s.addClass("JCLRdisabledGrip"):s.removeClass("JCLRdisabledGrip").bind("touchstart mousedown",J),s.t=i,s.i=e,s.c=r,r.w=r.width(),i.g.push(s),i.c.push(r),r.width(r.w).removeAttr("width"),s.data(l,{i:e,t:i.attr(n),last:e==i.ln-1})}),i.cg.removeAttr("width"),i.find("td, th").not(r).not("table th, table td").each(function(){t(this).removeAttr("width")}),i.f||i.removeAttr("width").addClass(c),C(i)},m=function(t,i){var r,o,s=0,d=0,n=[];if(i){if(t.cg.removeAttr("width"),t.opt.flush)return void(e[t.id]="");for(r=e[t.id].split(";"),o=r[t.ln+1],!t.f&&o&&(t.width(o*=1),t.opt.overflow&&(t.css("min-width",o+a),t.w=o));d<t.ln;d++)n.push(100*r[d]/r[t.ln]+"%"),i.eq(d).css("width",n[d]);for(d=0;d<t.ln;d++)t.cg.eq(d).css("width",n[d])}else{for(e[t.id]="";d<t.c.length;d++)r=t.c[d].width(),e[t.id]+=r+";",s+=r;e[t.id]+=s,t.f||(e[t.id]+=";"+t.width())}},C=function(t){t.gc.width(t.w);for(var e=0;e<t.ln;e++){var i=t.c[e];t.g[e].css({left:i.offset().left-t.offset().left+i.outerWidth(!1)+t.cs/2+a,height:t.opt.headerOnly?t.c[0].outerHeight(!1):t.outerHeight(!1)})}},b=function(t,e,i){var r=o.x-o.l,s=t.c[e],d=t.c[e+1],n=s.w+r,l=d.w-r;s.width(n+a),t.cg.eq(e).width(n+a),t.f?(d.width(l+a),t.cg.eq(e+1).width(l+a)):t.opt.overflow&&t.css("min-width",t.w+r),i&&(s.w=n,d.w=t.f?l:d.w)},R=function(e){var i=t.map(e.c,function(t){return t.width()});e.width(e.w=e.width()).removeClass(c),t.each(e.c,function(t,e){e.width(i[t]).w=i[t]}),e.addClass(c)},x=function(t){if(o){var e=o.t,i=t.originalEvent.touches,r=i?i[0].pageX:t.pageX,s=r-o.ox+o.l,d=e.opt.minWidth,n=o.i,l=1.5*e.cs+d+e.b,c=n==e.ln-1,f=n?e.g[n-1].position().left+e.cs+d:l,p=e.f?n==e.ln-1?e.w-l:e.g[n+1].position().left-e.cs-d:1/0;if(s=h.max(f,h.min(p,s)),o.x=s,o.css("left",s+a),c){var g=e.c[o.i];o.w=g.w+s-o.l}if(e.opt.liveDrag){c?(g.width(o.w),!e.f&&e.opt.overflow?e.css("min-width",e.w+s-o.l):e.w=e.width()):b(e,n),C(e);var u=e.opt.onDrag;u&&(t.currentTarget=e[0],u(t))}return!1}},y=function(r){if(i.unbind("touchend."+l+" mouseup."+l).unbind("touchmove."+l+" mousemove."+l),t("head :last-child").remove(),o){if(o.removeClass(o.t.opt.draggingClass),o.x-o.l!=0){var s=o.t,d=s.opt.onResize,n=o.i,a=n==s.ln-1,c=s.g[n].c;a?(c.width(o.w),c.w=o.w):b(s,n,!0),s.f||R(s),C(s),d&&(r.currentTarget=s[0],d(r)),s.p&&e&&m(s)}o=null}},J=function(e){var d=t(this).data(l),n=s[d.t],a=n.g[d.i],c=e.originalEvent.touches;if(a.ox=c?c[0].pageX:e.pageX,a.l=a.position().left,a.x=a.l,i.bind("touchmove."+l+" mousemove."+l,x).bind("touchend."+l+" mouseup."+l,y),r.append("<style type='text/css'>*{cursor:"+n.opt.dragCursor+"!important}</style>"),a.addClass(n.opt.draggingClass),o=a,n.c[d.i].l)for(var f,h=0;h<n.ln;h++)f=n.c[h],f.l=!1,f.w=f.width();return!1},L=function(){for(var t in s)if(s.hasOwnProperty(t)){t=s[t];var i,r=0;if(t.removeClass(l),t.f){for(t.w=t.width(),i=0;i<t.ln;i++)r+=t.c[i].w;for(i=0;i<t.ln;i++)t.c[i].css("width",h.round(1e3*t.c[i].w/r)/10+"%").l=!0}else R(t),"flex"==t.mode&&t.p&&e&&m(t);C(t.addClass(l))}};t(window).bind("resize."+l,L),t.fn.extend({colResizable:function(e){var i={resizeMode:"fit",draggingClass:"JCLRgripDrag",gripInnerHtml:"",liveDrag:!1,minWidth:15,headerOnly:!1,hoverCursor:"col-resize",dragCursor:"col-resize",postbackSafe:!1,flush:!1,marginLeft:null,marginRight:null,disable:!1,partialRefresh:!1,disabledColumns:[],onDrag:null,onResize:null},e=t.extend(i,e);switch(e.fixed=!0,e.overflow=!1,e.resizeMode){case"flex":e.fixed=!1;break;case"overflow":e.fixed=!1,e.overflow=!0}return this.each(function(){u(this,e)})}})}(jQuery);
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: col_resizable-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Abinoam P. Marques Jr.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: colResizable is a free jQuery plugin designed to enhance any kind of
56
+ HTML table object adding column resizing features by dragging column anchors manually.
57
+ email:
58
+ - abinoam@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - col_resizable-rails.gemspec
73
+ - lib/col_resizable/rails.rb
74
+ - lib/col_resizable/rails/engine.rb
75
+ - lib/col_resizable/rails/version.rb
76
+ - vendor/assets/javascripts/colResizable.js
77
+ - vendor/assets/javascripts/colResizable.min.js
78
+ homepage: https://github.com/abinoam/col_resizable-rails
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.6.9
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: colResizable js library gem package
102
+ test_files: []