jquery-nested-rails-cis 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ pkg/*
2
+ tmp
3
+ spec/support/*/Gemfile.lock
4
+ spec/support/*/public/javascripts
5
+ .ruby-version
6
+ .bundle
7
+ imports/*
8
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2013 Cyber Infrastructure Private Limited
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,244 @@
1
+ # Jquery Nested Rails
2
+
3
+ jQuery Nested for a complete gap free, multi column grid layout experience.
4
+
5
+ <br>Demo: [http://suprb.com/apps/nested/](http://suprb.com/apps/nested/)
6
+
7
+ This gem provides:
8
+
9
+ * Jquery Nested 1.03 - [Jquery Nested](https://github.com/suprb/Nested)
10
+
11
+ #### Compare the result
12
+
13
+ Nested to the left and Grid-A-Licious/Masonry to the right.
14
+
15
+ !["compare"](https://dl.dropbox.com/u/35476/compare.jpg)
16
+
17
+ ## What is Nested?
18
+
19
+ Nested is a jQuery plugin which allows you to create multi-column, dynamic grid layouts. How is this done? Nested does three things. It creates a matrix of all elements and creates a multi column grid, similar to other libraries and scripts out there. Then it scans the maxtric for gaps and tries to fill them by reordering the elements. This is exactly how I’ve seen other newer libraries, scripts and modifications behave but if you stop here, the result will sometime leave unwanted gaps as well. That is why I added the last step, an option to resize any element at the bottom of the grid that is bigger (or smaller if you prefer) than the gap to make the grid completely gap-free.
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ For Rails 3+ apps, add the jquery-nested-rails gem to your Gemfile.
26
+
27
+ gem 'jquery-nested-rails'
28
+
29
+ And then execute:
30
+
31
+ $ bundle install
32
+
33
+ Or install it yourself via:
34
+
35
+ $ bundle exec rake build
36
+ $ gem install --local pkg/jquery-nested-rails-0.0.1.gem
37
+
38
+
39
+ ## Usage
40
+
41
+ ### Generator
42
+ Run the generator by following command
43
+ ```
44
+ rails g jquery_nested_rails:install
45
+ ```
46
+ This generator will add the Jquery Nested in your javascript manifiest of asset pipeline.
47
+
48
+ If you are using the Rails 3.1 or greater and if you are using the less than rails 3.1 then this generator will add the javascript into your public javascript flder.
49
+
50
+ ### Rails 3.1 or greater
51
+
52
+ The Jquery Nested files and all dependencies will be added to the asset pipeline and be
53
+ available for you to use. If they're not already in app/assets/javascripts/application.js,
54
+ add these lines:
55
+
56
+ //= require jquery.nested
57
+
58
+
59
+ ### Rails 3.0 or lesser
60
+ ```
61
+ <%= javascript_include_tag "jquery.nested" %>
62
+ ```
63
+ Jquery Nested has a dependency on the `jQuery-rails` gem.
64
+
65
+
66
+ ## Markup
67
+
68
+ Use a container element with a group of child items that use the chosen option selector setting (default: `.box`).
69
+
70
+ ```html
71
+ <div id="container">
72
+ <div class="box size11"></div>
73
+ <div class="box size12"></div>
74
+ <div class="box size21"></div>
75
+ <div class="box size22"></div>
76
+ ...
77
+ </div>
78
+ ```
79
+
80
+ Sizing of items are handled by adding `sizeWH` where ` W ` is the number of columns the box shall use and ` H ` is the number of rows the box shall use. E.g ` size15 ` equals ` width: 1 column ` and ` height: 5 rows `
81
+
82
+ The base column and row size is set by the `minWidth` option.
83
+
84
+ ## Options
85
+
86
+ ### selector
87
+
88
+ Default : `.box`
89
+
90
+ ```javascript
91
+ $("#container").nested({selector: '.box'});
92
+ ```
93
+
94
+ ### minWidth
95
+
96
+ Default : `50`
97
+
98
+ ```javascript
99
+ $("#container").nested({minWidth: 100});
100
+ ```
101
+
102
+ ### minColumn
103
+ Default : `1`
104
+
105
+ ```javascript
106
+ $("#container").nested({minColumn: 1});
107
+ ```
108
+
109
+ ### gutter
110
+ Default : `1`
111
+
112
+ ```javascript
113
+ $("#container").nested({gutter: 1});
114
+ ```
115
+
116
+ ###resizeToFit
117
+
118
+ Default : `true`
119
+
120
+ If true, any box bigger than the gap will be resized to fill the gap.
121
+
122
+ ```javascript
123
+ $("#container").nested({resizeToFit: true});
124
+ ```
125
+ ### resizeToFitOptions
126
+
127
+ Default option below
128
+
129
+ #### resizeAny
130
+
131
+ If true, any box bigger or smaller than the gap will be resized to fill the gap.
132
+
133
+ Default : `true`
134
+
135
+ ```javascript
136
+ $("#container").nested({
137
+ resizeToFit: true,
138
+ resizeToFitOptions: {
139
+ resizeAny: true
140
+ }
141
+ });
142
+ ```
143
+
144
+ ### animate
145
+ Default : `false`
146
+
147
+ ```javascript
148
+ $("#container").nested({animate: false});
149
+ ```
150
+
151
+ ###animationOptions
152
+
153
+ Default options below
154
+
155
+ #### speed
156
+ A number of milliseconds to render each object (e.g. 200).
157
+
158
+ Default : `20`
159
+
160
+ #### duration
161
+ A number of milliseconds to run the animation (e.g. 300).
162
+
163
+ Default : `100`
164
+
165
+ #### queue
166
+ Queued objects or not.
167
+
168
+ Default : `true`
169
+
170
+ #### complete
171
+ A function to be executed whenever the animation completes.
172
+
173
+ Default : `function()`
174
+
175
+ ```javascript
176
+ $("#container").nested({
177
+ animate: true,
178
+ animationOptions: {
179
+ speed: 100,
180
+ duration: 200,
181
+ queue: true,
182
+ complete: onComplete
183
+ }
184
+ });
185
+ ```
186
+ ###Some examples
187
+
188
+ ####Example 01
189
+ This example uses a custom width and the default gutter `20px`
190
+
191
+ ```javascript
192
+ $("#example1").nested({
193
+ minWidth: 20
194
+ });
195
+ ```
196
+
197
+ ####Example 02
198
+ This example uses custom width and gutter
199
+
200
+ ```javascript
201
+ $("#example2").nested({
202
+ minWidth: 100,
203
+ gutter: 10
204
+ });
205
+ ```
206
+
207
+ ####Example 03
208
+ Prepending and appending items
209
+
210
+ ```javascript
211
+ $("#example3").nested({
212
+ minWidth: 25,
213
+ gutter: 1,
214
+ animate: true,
215
+ animationOptions: {
216
+ speed: 10,
217
+ duration: 20,
218
+ complete: onComplete
219
+ }
220
+ });
221
+ ```
222
+
223
+ Prepend and Append buttons
224
+ ```javascript
225
+ $('#prepend').click(function(){
226
+ var boxes = makeBoxes();
227
+ $("#example3").prepend(boxes).nested('prepend', boxes);
228
+ });
229
+
230
+ $('#append').click(function(){
231
+ var boxes = makeBoxes();
232
+ $("#example3").append(boxes).nested('append', boxes);
233
+ });
234
+ ```
235
+
236
+ ## Acknowledgement
237
+
238
+ To [Jonas Blomdin](http://github.com/jonasblomdin/) for creating Jquery Nested Plugin.
239
+
240
+ ## Licence
241
+
242
+ The MIT License
243
+
244
+ Copyright (c) 2013 Cyber Infrastructure Private Limited See LICENSE for further details.
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/jquery-nested-rails/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "jquery-nested-rails-cis"
6
+ s.date = '2013-10-30'
7
+ s.version = JqueryNestedRails::Rails::VERSION
8
+ s.authors = ["Anup Pareek, CISROR Team"]
9
+ s.homepage = "http://rubygems.org/gems/jquery-nested-rails"
10
+ s.summary = %q{For a complete gap free, multi column grid layout experience on rails application.}
11
+ s.description = %q{Nested is a jQuery plugin which allows you to create multi-column, dynamic grid layouts. }
12
+ s.license = "MIT"
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "jquery-rails"
16
+
17
+ s.add_dependency "railties", ">= 3.0"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,41 @@
1
+ require 'rails'
2
+
3
+ # Supply generator for Rails 3.0.x or if asset pipeline is not enabled
4
+ if ::Rails.version < "3.1" || !::Rails.application.config.assets.enabled
5
+ module JqueryNestedRails
6
+ module Generators
7
+ class InstallGenerator < ::Rails::Generators::Base
8
+
9
+ desc "This generator installs Jquery Nested #{JqueryNestedRails::Rails::JQUERY_NESTED_VERSION}"
10
+ source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
11
+
12
+ def copy_jquery_nested
13
+ say_status("copying", "Jquery Nested (#{JqueryNestedRails::Rails::JQUERY_NESTED_VERSION})", :green)
14
+ copy_file "jquery.nested.min.js", "public/javascripts/jquery.nested.min.js"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ else
20
+ module JqueryNestedRails
21
+ module Generators
22
+ class InstallGenerator < ::Rails::Generators::Base
23
+ desc "This generator add Jquery Nested #{JqueryNestedRails::Rails::JQUERY_NESTED_VERSION} to application.js or application.js.coffee"
24
+ source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
25
+ def add_assets
26
+ if detect_js_format.nil?
27
+ say_status("copying", "Jquery Nested (#{JqueryNestedRails::Rails::JQUERY_NESTED_VERSION})", :green)
28
+ copy_file "jquery.nested.min.js", "app/assets/javascripts/jquery.nested.min.js"
29
+ else
30
+ insert_into_file "app/assets/javascripts/application#{detect_js_format[0]}", "#{detect_js_format[1]} require jquery.nested\n", :after => "jquery_ujs\n"
31
+ end
32
+ end
33
+
34
+ def detect_js_format
35
+ return ['.js.coffee', '#='] if File.exist?('app/assets/javascripts/application.js.coffee')
36
+ return ['.js', '//='] if File.exist?('app/assets/javascripts/application.js')
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1 @@
1
+ require 'jquery-nested-rails/rails'
@@ -0,0 +1,25 @@
1
+ module ActionDispatch
2
+ module Assertions
3
+ module SelectorAssertions
4
+
5
+ PATTERN_HTML = %Q{"((\\\\\"|[^\"])*)"}
6
+ PATTERN_UNICODE_ESCAPED_CHAR = /\\u([0-9a-zA-Z]{4})/
7
+
8
+ private
9
+
10
+ # Unescapes a JS string.
11
+ def unescape_js(js_string)
12
+ # js encodes double quotes and line breaks.
13
+ unescaped= js_string.gsub('\"', '"')
14
+ unescaped.gsub!('\\\'', "'")
15
+ unescaped.gsub!(/\\\//, '/')
16
+ unescaped.gsub!('\n', "\n")
17
+ unescaped.gsub!('\076', '>')
18
+ unescaped.gsub!('\074', '<')
19
+ # js encodes non-ascii characters.
20
+ unescaped.gsub!(PATTERN_UNICODE_ESCAPED_CHAR) {|u| [$1.hex].pack('U*')}
21
+ unescaped
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails'
2
+ require 'jquery-nested-rails/rails/assert_select' if ::Rails.env.test?
3
+ require 'jquery-nested-rails/rails/engine' if ::Rails.version >= '3.1'
4
+ require 'jquery-nested-rails/rails/railtie'
5
+ require 'jquery-nested-rails/rails/version'
6
+
7
+ module JqueryNestedRails
8
+ module Rails
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ module JqueryNestedRails
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ # Used to ensure that Rails 3.0.x, as well as Rails >= 3.1 with asset pipeline disabled
2
+ # get the minified version of the scripts included into the layout in production.
3
+ module JqueryNestedRails
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie
6
+ config.before_configuration do
7
+ if config.action_view.javascript_expansions
8
+ jquery_nested_rails_defaults = ::Rails.env.production? || ::Rails.env.test? ? %w(jquery.nested.min) : %w(jquery.nested)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ module JqueryNestedRails
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ JQUERY_NESTED_VERSION = "1.03"
5
+ end
6
+ end
@@ -0,0 +1,527 @@
1
+ /**
2
+ * jQuery Nested v1.03
3
+ *
4
+ * For a (total) gap free, multi column, grid layout experience.
5
+ * http://suprb.com/apps/nested/
6
+ * By Andreas Pihlström and additional brain activity by Jonas Blomdin
7
+ *
8
+ * Licensed under the MIT license.
9
+ */
10
+
11
+ // Debouncing function from John Hann
12
+ // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
13
+ // Copy pasted from http://paulirish.com/2009/throttled-smartresize-jquery-event-handler/
14
+
15
+ (function ($, sr) {
16
+ var debounce = function (func, threshold, execAsap) {
17
+ var timeout;
18
+ return function debounced() {
19
+ var obj = this,
20
+ args = arguments;
21
+
22
+ function delayed() {
23
+ if (!execAsap) func.apply(obj, args);
24
+ timeout = null;
25
+ };
26
+ if (timeout) clearTimeout(timeout);
27
+ else if (execAsap) func.apply(obj, args);
28
+
29
+ timeout = setTimeout(delayed, threshold || 150);
30
+ };
31
+ };
32
+ jQuery.fn[sr] = function (fn) {
33
+ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr);
34
+ };
35
+
36
+ })(jQuery, 'smartresize');
37
+
38
+ // Simple count object properties
39
+
40
+ if (!Object.keys) {
41
+ Object.keys = function (obj) {
42
+ var keys = [],
43
+ k;
44
+ for (k in obj) {
45
+ if (Object.prototype.hasOwnProperty.call(obj, k)) {
46
+ keys.push(k);
47
+ }
48
+ }
49
+ return keys;
50
+ };
51
+ }
52
+
53
+ // The Nested magic
54
+
55
+ (function ($) {
56
+
57
+ $.Nested = function (options, element) {
58
+ this.element = $(element);
59
+ this._init(options);
60
+ };
61
+
62
+ $.Nested.settings = {
63
+ selector: '.box',
64
+ minWidth: 50,
65
+ minColumns: 1,
66
+ gutter: 1,
67
+ centered: false,
68
+ resizeToFit: true, // will resize block bigger than the gap
69
+ resizeToFitOptions: {
70
+ resizeAny: true // will resize any block to fit the gap
71
+ },
72
+ animate: true,
73
+ animationOptions: {
74
+ speed: 20,
75
+ duration: 100,
76
+ queue: true,
77
+ complete: function () {}
78
+ }
79
+ };
80
+
81
+ $.Nested.prototype = {
82
+
83
+ _init: function (options) {
84
+ var container = this;
85
+ this.box = this.element;
86
+ $(this.box).css('position', 'relative');
87
+ this.options = $.extend(true, {}, $.Nested.settings, options);
88
+ this.elements = [];
89
+ this._isResizing = false;
90
+ this._update = true;
91
+ this.maxy = new Array();
92
+
93
+ // add smartresize
94
+ $(window).smartresize(function () {
95
+ container.resize();
96
+ });
97
+
98
+ // build box dimensions
99
+ this._setBoxes();
100
+ },
101
+
102
+ _setBoxes: function ($els, method) {
103
+ var self = this;
104
+ this.idCounter = 0;
105
+ this.counter = 0;
106
+ this.t = 0;
107
+ this.maxHeight = 0;
108
+ this.currWidth = 0;
109
+ this.total = this.box.find(this.options.selector);
110
+ this.matrix = {};
111
+ this.gridrow = new Object;
112
+
113
+ var calcWidth = !this.options.centered ? this.box.innerWidth() : $(window).width();
114
+
115
+ //console.log(calcWidth)
116
+
117
+ this.columns = Math.max(this.options.minColumns, parseInt(calcWidth / (this.options.minWidth + this.options.gutter)) + 1);
118
+
119
+ // build columns
120
+ var minWidth = this.options.minWidth;
121
+ var gutter = this.options.gutter;
122
+ var display = "block";
123
+
124
+ $els = this.box.find(this.options.selector);
125
+
126
+ $.each($els, function () {
127
+
128
+ var dim = parseInt($(this).attr('class').replace(/^.*size([0-9]+).*$/, '$1')).toString().split('');
129
+ var x = (dim[0] == "N") ? 1 : parseFloat(dim[0]);
130
+ var y = (dim[1] == "a") ? 1 : parseFloat(dim[1]);
131
+
132
+ var currWidth = minWidth * x + gutter * (x - 1);
133
+ var currHeight = minWidth * y + gutter * (y - 1);
134
+
135
+ $(this).css({
136
+ 'display': display,
137
+ 'position': 'absolute',
138
+ 'width': currWidth,
139
+ 'height': currHeight,
140
+ 'top': $(this).position().top,
141
+ 'left': $(this).position().left
142
+ }).removeClass('nested-moved').attr('data-box', self.idCounter).attr('data-width', currWidth);
143
+
144
+ self.idCounter++;
145
+
146
+ // render grid
147
+ self._renderGrid($(this), method);
148
+
149
+ });
150
+
151
+ // position grid
152
+ if (self.counter == self.total.length) {
153
+
154
+ // if option resizeToFit is true
155
+ if (self.options.resizeToFit) {
156
+ self.elements = self._fillGaps();
157
+ }
158
+ self._renderItems(self.elements);
159
+ // reset elements
160
+ self.elements = [];
161
+ }
162
+ },
163
+
164
+ _addMatrixRow: function (y) {
165
+ if (this.matrix[y]) {
166
+ return false;
167
+ } else this.matrix[y] = {};
168
+
169
+ for (var c = 0; c < (this.columns - 1); c++) {
170
+ var x = c * (this.options.minWidth + this.options.gutter);
171
+ this.matrix[y][x] = 'false';
172
+ }
173
+ },
174
+
175
+ _updateMatrix: function (el) {
176
+ var height = 0;
177
+ var t = parseInt(el['y']);
178
+ var l = parseInt(el['x']);
179
+ for (var h = 0; h < el['height']; h += (this.options.minWidth + this.options.gutter)) {
180
+ for (var w = 0; w < el['width']; w += (this.options.minWidth + this.options.gutter)) {
181
+ var x = l + w;
182
+ var y = t + h;
183
+ if (!this.matrix[y]) {
184
+ this._addMatrixRow(y);
185
+ }
186
+ this.matrix[y][x] = 'true';
187
+ }
188
+ }
189
+ },
190
+
191
+ _getObjectSize: function (obj) { // Helper to get size of object, should probably be moved
192
+ var size = 0;
193
+ $.each(obj, function (p, v) {
194
+ size++;
195
+ });
196
+ return size;
197
+ },
198
+
199
+
200
+ _fillGaps: function () {
201
+ var self = this;
202
+ var box = {};
203
+
204
+ $.each(this.elements, function (index, el) {
205
+ self._updateMatrix(el);
206
+ });
207
+
208
+ var arr = this.elements;
209
+ arr.sort(function (a, b) {
210
+ return a.y - b.y;
211
+ });
212
+ arr.reverse();
213
+
214
+ // Used to keep the highest y value for a box in memory
215
+ var topY = arr[0]['y'];
216
+
217
+ // Used for current y with added offset
218
+ var actualY = 0;
219
+
220
+ // Current number of rows in matrix
221
+ var rowsLeft = this._getObjectSize(this.matrix);
222
+
223
+ $.each(this.matrix, function (y, row) {
224
+ rowsLeft--;
225
+ actualY = parseInt(y); // + parseInt(self.box.offset().top);
226
+ $.each(row, function (x, col) {
227
+
228
+ if (col === 'false' && actualY < topY) {
229
+ if (!box.y) box.y = y;
230
+ if (!box.x) box.x = x;
231
+ if (!box.w) box.w = 0;
232
+ if (!box.h) box.h = self.options.minWidth;
233
+ box.w += (box.w) ? (self.options.minWidth + self.options.gutter) : self.options.minWidth;
234
+
235
+ var addonHeight = 0;
236
+ for (var row = 1; row < rowsLeft; row++) {
237
+ var z = parseInt(y) + parseInt(row * (self.options.minWidth + self.options.gutter));
238
+ if (self.matrix[z] && self.matrix[z][x] == 'false') {
239
+ addonHeight += (self.options.minWidth + self.options.gutter);
240
+ self.matrix[z][x] = 'true';
241
+ } else break;
242
+ }
243
+
244
+ box.h + (parseInt(addonHeight) / (self.options.minWidth + self.options.gutter) == rowsLeft) ? 0 : parseInt(addonHeight);
245
+ box.ready = true;
246
+
247
+ } else if (box.ready) {
248
+
249
+ $.each(arr, function (i, el) {
250
+ if (box.y <= arr[i]['y'] && (self.options.resizeToFitOptions.resizeAny || box.w <= arr[i]['width'] && box.h <= arr[i]['height'])) {
251
+ arr.splice(i, 1);
252
+ $(el['$el']).addClass('nested-moved');
253
+ self.elements.push({
254
+ $el: $(el['$el']),
255
+ x: parseInt(box.x),
256
+ y: parseInt(box.y),
257
+ col: i,
258
+ width: parseInt(box.w),
259
+ height: parseInt(box.h)
260
+ });
261
+
262
+ return false;
263
+ }
264
+ });
265
+ box = {};
266
+ }
267
+ });
268
+
269
+ });
270
+
271
+ self.elements = arr;
272
+ return self.elements;
273
+
274
+ },
275
+
276
+ _renderGrid: function ($box, method) {
277
+
278
+ this.counter++;
279
+ var ypos, gridy = ypos = 0;
280
+ var tot = 0;
281
+ var direction = !method ? "append" : "prepend";
282
+
283
+ // Width & height
284
+ var width = $box.width();
285
+ var height = $box.height();
286
+
287
+ // Calculate row and col
288
+ var col = Math.ceil(width / (this.options.minWidth + this.options.gutter));
289
+ var row = Math.ceil(height / (this.options.minWidth + this.options.gutter));
290
+
291
+ // lock widest box to match minColumns
292
+ if (col > this.options.minColumns) {
293
+ this.options.minColumns = col;
294
+ }
295
+
296
+ while (true) {
297
+
298
+ for (var y = col; y >= 0; y--) {
299
+ if (this.gridrow[gridy + y]) break;
300
+ this.gridrow[gridy + y] = new Object;
301
+ for (var x = 0; x < this.columns; x++) {
302
+ this.gridrow[gridy + y][x] = false;
303
+ }
304
+ }
305
+
306
+ for (var column = 0; column < (this.columns - col); column++) {
307
+
308
+ // Add default empty matrix, used to calculate and update matrix for each box
309
+ matrixY = gridy * (this.options.minWidth + this.options.gutter);
310
+ this._addMatrixRow(matrixY);
311
+
312
+ var fits = true;
313
+
314
+ for (var y = 0; y < row; y++) {
315
+ for (var x = 0; x < col; x++) {
316
+
317
+ if (!this.gridrow[gridy + y]) {
318
+ break;
319
+ }
320
+
321
+ if (this.gridrow[gridy + y][column + x]) {
322
+ fits = false;
323
+ break;
324
+ }
325
+ }
326
+ if (!fits) {
327
+ break;
328
+ }
329
+ }
330
+ if (fits) {
331
+ // Set as taken
332
+ for (var y = 0; y < row; y++) {
333
+ for (var x = 0; x < col; x++) {
334
+
335
+ if (!this.gridrow[gridy + y]) {
336
+ break;
337
+ }
338
+ this.gridrow[gridy + y][column + x] = true;
339
+ }
340
+ }
341
+
342
+ // Push to elements array
343
+ this._pushItem($box, column * (this.options.minWidth + this.options.gutter), gridy * (this.options.minWidth + this.options.gutter), width, height, col, row, direction);
344
+ return;
345
+ }
346
+ }
347
+ gridy++;
348
+ }
349
+ },
350
+
351
+ _pushItem: function ($el, x, y, w, h, cols, rows, method) {
352
+
353
+ if (method == "prepend") {
354
+ this.elements.unshift({
355
+ $el: $el,
356
+ x: x,
357
+ y: y,
358
+ width: w,
359
+ height: h,
360
+ cols: cols,
361
+ rows: rows
362
+ });
363
+ } else {
364
+ //console.log(this.box.position().top)
365
+ this.elements.push({
366
+ $el: $el,
367
+ x: x,
368
+ y: y,
369
+ width: w,
370
+ height: h,
371
+ cols: cols,
372
+ rows: rows
373
+ });
374
+ }
375
+ },
376
+
377
+ _setHeight: function ($els) {
378
+ var self = this;
379
+ $.each($els, function (index, value) {
380
+ // set maxHeight
381
+ var colY = (value['y'] + value['height']);
382
+ if (colY > self.maxHeight) {
383
+ self.maxHeight = colY;
384
+ }
385
+ });
386
+ return self.maxHeight;
387
+ },
388
+
389
+ _setWidth: function ($els) {
390
+ var self = this;
391
+ $.each($els, function (index, value) {
392
+ // set maxWidth
393
+ var colX = (value['x'] + value['width']);
394
+ if (colX > self.currWidth) {
395
+ self.currWidth = colX;
396
+ }
397
+ });
398
+ return self.currWidth;
399
+ },
400
+
401
+ _renderItems: function ($els) {
402
+ var self = this;
403
+
404
+ // set container height and width
405
+ this.box.css('height', this._setHeight($els));
406
+ if (this.options.centered) {
407
+ this.box.css({
408
+ 'width' : this._setWidth($els),
409
+ 'margin-left' : 'auto',
410
+ 'margin-right' : 'auto'
411
+ });
412
+ }
413
+
414
+ $els.reverse();
415
+ var speed = this.options.animationOptions.speed;
416
+ var effect = this.options.animationOptions.effect;
417
+ var duration = this.options.animationOptions.duration;
418
+ var queue = this.options.animationOptions.queue;
419
+ var animate = this.options.animate;
420
+ var complete = this.options.animationOptions.complete;
421
+ var item = this;
422
+ var i = 0;
423
+ var t = 0;
424
+
425
+ $.each($els, function (index, value) {
426
+
427
+ $currLeft = $(value['$el']).position().left;
428
+ $currTop = $(value['$el']).position().top;
429
+ $currWidth = $(value['$el']).width();
430
+ $currHeight = $(value['$el']).width();
431
+
432
+ value['$el'].attr('data-y', $currTop).attr('data-x', $currLeft);
433
+
434
+ //if animate and queue
435
+ if (animate && queue && ($currLeft != value['x'] || $currTop != value['y'])) {
436
+ setTimeout(function () {
437
+ value['$el'].css({
438
+ 'display': 'block',
439
+ 'width': value['width'],
440
+ 'height': value['height']
441
+ }).animate({
442
+ 'left': value['x'],
443
+ 'top': value['y']
444
+ }, duration);
445
+ t++;
446
+ if (t == i) {
447
+ complete.call(undefined, $els)
448
+ }
449
+ }, i * speed);
450
+ i++;
451
+ }
452
+
453
+ //if animate and no queue
454
+ if (animate && !queue && ($currLeft != value['x'] || $currTop != value['y'])) {
455
+ setTimeout(function () {
456
+ value['$el'].css({
457
+ 'display': 'block',
458
+ 'width': value['width'],
459
+ 'height': value['height']
460
+ }).animate({
461
+ 'left': value['x'],
462
+ 'top': value['y']
463
+ }, duration);
464
+ t++;
465
+ if (t == i) {
466
+ complete.call(undefined, $els)
467
+ }
468
+ }, i);
469
+ i++;
470
+ }
471
+
472
+ //if no animation and no queue
473
+ if (!animate && ($currLeft != value['x'] || $currTop != value['y'])) {
474
+ value['$el'].css({
475
+ 'display': 'block',
476
+ 'width': value['width'],
477
+ 'height': value['height'],
478
+ 'left': value['x'],
479
+ 'top': value['y']
480
+ });
481
+ t++;
482
+ if (t == i) {
483
+ complete.call(undefined, $els)
484
+ }
485
+ }
486
+ });
487
+ if (i == 0) {
488
+ complete.call(undefined, $els)
489
+ }
490
+ },
491
+
492
+ append: function ($els) {
493
+ this._isResizing = true;
494
+ this._setBoxes($els, 'append');
495
+ this._isResizing = false;
496
+ },
497
+
498
+ prepend: function ($els) {
499
+ this._isResizing = true;
500
+ this._setBoxes($els, 'prepend');
501
+ this._isResizing = false;
502
+ },
503
+
504
+ resize: function ($els) {
505
+ if (Object.keys(this.matrix[0]).length % Math.floor(this.element.width() / (this.options.minWidth + this.options.gutter)) > 0) {
506
+ this._isResizing = true;
507
+ this._setBoxes(this.box.find(this.options.selector));
508
+ this._isResizing = false;
509
+ }
510
+ }
511
+ }
512
+
513
+ $.fn.nested = function (options, e) {
514
+ if (typeof options === 'string') {
515
+ this.each(function () {
516
+ var container = $.data(this, 'nested');
517
+ container[options].apply(container, [e]);
518
+ });
519
+ } else {
520
+ this.each(function () {
521
+ $.data(this, 'nested', new $.Nested(options, this));
522
+ });
523
+ }
524
+ return this;
525
+ }
526
+
527
+ })(jQuery);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * jQuery Nested v1.03
3
+ *
4
+ * For a (total) gap free, multi column, grid layout experience.
5
+ * http://suprb.com/apps/nested/
6
+ * By Andreas Pihlström and additional brain activity by Jonas Blomdin
7
+ *
8
+ * Licensed under the MIT license.
9
+ */
10
+
11
+ // Debouncing function from John Hann
12
+ // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
13
+ // Copy pasted from http://paulirish.com/2009/throttled-smartresize-jquery-event-handler/
14
+ (function($,sr){var debounce=function(func,threshold,execAsap){var timeout;return function debounced(){var obj=this,args=arguments;function delayed(){if(!execAsap)func.apply(obj,args);timeout=null};if(timeout)clearTimeout(timeout);else if(execAsap)func.apply(obj,args);timeout=setTimeout(delayed,threshold||150)}};jQuery.fn[sr]=function(fn){return fn?this.bind('resize',debounce(fn)):this.trigger(sr)}})(jQuery,'smartresize');if(!Object.keys){Object.keys=function(obj){var keys=[],k;for(k in obj){if(Object.prototype.hasOwnProperty.call(obj,k)){keys.push(k)}}return keys}}(function($){$.Nested=function(options,element){this.element=$(element);this._init(options)};$.Nested.settings={selector:'.box',minWidth:50,minColumns:1,gutter:1,centered:false,resizeToFit:true,resizeToFitOptions:{resizeAny:true},animate:true,animationOptions:{speed:20,duration:100,queue:true,complete:function(){}}};$.Nested.prototype={_init:function(options){var container=this;this.box=this.element;$(this.box).css('position','relative');this.options=$.extend(true,{},$.Nested.settings,options);this.elements=[];this._isResizing=false;this._update=true;this.maxy=new Array();$(window).smartresize(function(){container.resize()});this._setBoxes()},_setBoxes:function($els,method){var self=this;this.idCounter=0;this.counter=0;this.t=0;this.maxHeight=0;this.currWidth=0;this.total=this.box.find(this.options.selector);this.matrix={};this.gridrow=new Object;var calcWidth=!this.options.centered?this.box.innerWidth():$(window).width();this.columns=Math.max(this.options.minColumns,parseInt(calcWidth/(this.options.minWidth+this.options.gutter))+1);var minWidth=this.options.minWidth;var gutter=this.options.gutter;var display="block";$els=this.box.find(this.options.selector);$.each($els,function(){var dim=parseInt($(this).attr('class').replace(/^.*size([0-9]+).*$/,'$1')).toString().split('');var x=(dim[0]=="N")?1:parseFloat(dim[0]);var y=(dim[1]=="a")?1:parseFloat(dim[1]);var currWidth=minWidth*x+gutter*(x-1);var currHeight=minWidth*y+gutter*(y-1);$(this).css({'display':display,'position':'absolute','width':currWidth,'height':currHeight,'top':$(this).position().top,'left':$(this).position().left}).removeClass('nested-moved').attr('data-box',self.idCounter).attr('data-width',currWidth);self.idCounter++;self._renderGrid($(this),method)});if(self.counter==self.total.length){if(self.options.resizeToFit){self.elements=self._fillGaps()}self._renderItems(self.elements);self.elements=[]}},_addMatrixRow:function(y){if(this.matrix[y]){return false}else this.matrix[y]={};for(var c=0;c<(this.columns-1);c++){var x=c*(this.options.minWidth+this.options.gutter);this.matrix[y][x]='false'}},_updateMatrix:function(el){var height=0;var t=parseInt(el['y']);var l=parseInt(el['x']);for(var h=0;h<el['height'];h+=(this.options.minWidth+this.options.gutter)){for(var w=0;w<el['width'];w+=(this.options.minWidth+this.options.gutter)){var x=l+w;var y=t+h;if(!this.matrix[y]){this._addMatrixRow(y)}this.matrix[y][x]='true'}}},_getObjectSize:function(obj){var size=0;$.each(obj,function(p,v){size++});return size},_fillGaps:function(){var self=this;var box={};$.each(this.elements,function(index,el){self._updateMatrix(el)});var arr=this.elements;arr.sort(function(a,b){return a.y-b.y});arr.reverse();var topY=arr[0]['y'];var actualY=0;var rowsLeft=this._getObjectSize(this.matrix);$.each(this.matrix,function(y,row){rowsLeft--;actualY=parseInt(y);$.each(row,function(x,col){if(col==='false'&&actualY<topY){if(!box.y)box.y=y;if(!box.x)box.x=x;if(!box.w)box.w=0;if(!box.h)box.h=self.options.minWidth;box.w+=(box.w)?(self.options.minWidth+self.options.gutter):self.options.minWidth;var addonHeight=0;for(var row=1;row<rowsLeft;row++){var z=parseInt(y)+parseInt(row*(self.options.minWidth+self.options.gutter));if(self.matrix[z]&&self.matrix[z][x]=='false'){addonHeight+=(self.options.minWidth+self.options.gutter);self.matrix[z][x]='true'}else break}box.h+(parseInt(addonHeight)/(self.options.minWidth+self.options.gutter)==rowsLeft)?0:parseInt(addonHeight);box.ready=true}else if(box.ready){$.each(arr,function(i,el){if(box.y<=arr[i]['y']&&(self.options.resizeToFitOptions.resizeAny||box.w<=arr[i]['width']&&box.h<=arr[i]['height'])){arr.splice(i,1);$(el['$el']).addClass('nested-moved');self.elements.push({$el:$(el['$el']),x:parseInt(box.x),y:parseInt(box.y),col:i,width:parseInt(box.w),height:parseInt(box.h)});return false}});box={}}})});self.elements=arr;return self.elements},_renderGrid:function($box,method){this.counter++;var ypos,gridy=ypos=0;var tot=0;var direction=!method?"append":"prepend";var width=$box.width();var height=$box.height();var col=Math.ceil(width/(this.options.minWidth+this.options.gutter));var row=Math.ceil(height/(this.options.minWidth+this.options.gutter));if(col>this.options.minColumns){this.options.minColumns=col}while(true){for(var y=col;y>=0;y--){if(this.gridrow[gridy+y])break;this.gridrow[gridy+y]=new Object;for(var x=0;x<this.columns;x++){this.gridrow[gridy+y][x]=false}}for(var column=0;column<(this.columns-col);column++){matrixY=gridy*(this.options.minWidth+this.options.gutter);this._addMatrixRow(matrixY);var fits=true;for(var y=0;y<row;y++){for(var x=0;x<col;x++){if(!this.gridrow[gridy+y]){break}if(this.gridrow[gridy+y][column+x]){fits=false;break}}if(!fits){break}}if(fits){for(var y=0;y<row;y++){for(var x=0;x<col;x++){if(!this.gridrow[gridy+y]){break}this.gridrow[gridy+y][column+x]=true}}this._pushItem($box,column*(this.options.minWidth+this.options.gutter),gridy*(this.options.minWidth+this.options.gutter),width,height,col,row,direction);return}}gridy++}},_pushItem:function($el,x,y,w,h,cols,rows,method){if(method=="prepend"){this.elements.unshift({$el:$el,x:x,y:y,width:w,height:h,cols:cols,rows:rows})}else{this.elements.push({$el:$el,x:x,y:y,width:w,height:h,cols:cols,rows:rows})}},_setHeight:function($els){var self=this;$.each($els,function(index,value){var colY=(value['y']+value['height']);if(colY>self.maxHeight){self.maxHeight=colY}});return self.maxHeight},_setWidth:function($els){var self=this;$.each($els,function(index,value){var colX=(value['x']+value['width']);if(colX>self.currWidth){self.currWidth=colX}});return self.currWidth},_renderItems:function($els){var self=this;this.box.css('height',this._setHeight($els));if(this.options.centered){this.box.css({'width':this._setWidth($els),'margin-left':'auto','margin-right':'auto'})}$els.reverse();var speed=this.options.animationOptions.speed;var effect=this.options.animationOptions.effect;var duration=this.options.animationOptions.duration;var queue=this.options.animationOptions.queue;var animate=this.options.animate;var complete=this.options.animationOptions.complete;var item=this;var i=0;var t=0;$.each($els,function(index,value){$currLeft=$(value['$el']).position().left;$currTop=$(value['$el']).position().top;$currWidth=$(value['$el']).width();$currHeight=$(value['$el']).width();value['$el'].attr('data-y',$currTop).attr('data-x',$currLeft);if(animate&&queue&&($currLeft!=value['x']||$currTop!=value['y'])){setTimeout(function(){value['$el'].css({'display':'block','width':value['width'],'height':value['height']}).animate({'left':value['x'],'top':value['y']},duration);t++;if(t==i){complete.call(undefined,$els)}},i*speed);i++}if(animate&&!queue&&($currLeft!=value['x']||$currTop!=value['y'])){setTimeout(function(){value['$el'].css({'display':'block','width':value['width'],'height':value['height']}).animate({'left':value['x'],'top':value['y']},duration);t++;if(t==i){complete.call(undefined,$els)}},i);i++}if(!animate&&($currLeft!=value['x']||$currTop!=value['y'])){value['$el'].css({'display':'block','width':value['width'],'height':value['height'],'left':value['x'],'top':value['y']});t++;if(t==i){complete.call(undefined,$els)}}});if(i==0){complete.call(undefined,$els)}},append:function($els){this._isResizing=true;this._setBoxes($els,'append');this._isResizing=false},prepend:function($els){this._isResizing=true;this._setBoxes($els,'prepend');this._isResizing=false},resize:function($els){if(Object.keys(this.matrix[0]).length%Math.floor(this.element.width()/(this.options.minWidth+this.options.gutter))>0){this._isResizing=true;this._setBoxes(this.box.find(this.options.selector));this._isResizing=false}}}$.fn.nested=function(options,e){if(typeof options==='string'){this.each(function(){var container=$.data(this,'nested');container[options].apply(container,[e])})}else{this.each(function(){$.data(this,'nested',new $.Nested(options,this))})}return this}})(jQuery);
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery-nested-rails-cis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anup Pareek, CISROR Team
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: &18317320 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *18317320
25
+ description: ! 'Nested is a jQuery plugin which allows you to create multi-column,
26
+ dynamic grid layouts. '
27
+ email:
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - jquery-nested-rails-cis.gemspec
38
+ - lib/generators/jquery_nested_rails/install/install_generator.rb
39
+ - lib/jquery-nested-rails.rb
40
+ - lib/jquery-nested-rails/assert_select.rb
41
+ - lib/jquery-nested-rails/rails.rb
42
+ - lib/jquery-nested-rails/rails/engine.rb
43
+ - lib/jquery-nested-rails/rails/railtie.rb
44
+ - lib/jquery-nested-rails/rails/version.rb
45
+ - vendor/assets/javascripts/jquery.nested.js
46
+ - vendor/assets/javascripts/jquery.nested.min.js
47
+ homepage: http://rubygems.org/gems/jquery-nested-rails
48
+ licenses:
49
+ - MIT
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: 1.3.6
66
+ requirements: []
67
+ rubyforge_project: jquery-rails
68
+ rubygems_version: 1.8.11
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: For a complete gap free, multi column grid layout experience on rails application.
72
+ test_files: []