masonry-rails 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d441d9484feb77daf92b8c94197d293eedb2aa00
4
- data.tar.gz: 3331c5fd8c1f908908e74b6312451c8b7a73b1c1
3
+ metadata.gz: 317395b5bfdcd827ae69571c5ef820a1a4735134
4
+ data.tar.gz: be9571efd07411c357b868c7e731c5ad3f57b7ee
5
5
  SHA512:
6
- metadata.gz: 16f44417be573df8aff7e589384232ae997693d1037158bbe2a971a19c4907e74d57d4f4328b5301bc09c54542be243242ff9876cf51e999414eb671f70b6c67
7
- data.tar.gz: b2b016b66bccc398915fb973b92547dae8bbbbac552630279673f404bba595140c0c610682062fb7cc66d333bc3fef05924c098159fd0640a790dba2329f2d07
6
+ metadata.gz: 9caeec75e0d3b4a93dc70fb5f5c9b10556589b612169bb22407ddc4161846a0dba9fe643be73170dd02c7b31c63e626565342970d98c1c7665286206d04cb7bc
7
+ data.tar.gz: b9469caf405466325dea5b54caf904646736787540008479798cefbb74717e61a6d92eb6c9d0f2bcdde3cf6414db7479b9157b0459bdced6ab879efdd8817724
data/Gemfile CHANGED
@@ -1,11 +1,9 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'rails'
4
-
5
3
  group :development do
6
- gem "rspec", "> 2.10.0"
7
- gem "rdoc", "> 3.12"
8
- gem "bundler", "> 1.2.0"
9
- gem "jeweler", "> 1.8.4"
10
- gem "simplecov",">= 0.5"
4
+ gem "rspec", '~> 2.10', '> 2.10.0'
5
+ gem "rdoc", '~> 4.0', '> 4.0.0'
6
+ gem "bundler", '~> 1.2', '> 1.2.0'
7
+ gem "jeweler", '~> 1.8', '> 1.8.4'
8
+ gem "simplecov",'~> 0.5'
11
9
  end
@@ -1,39 +1,9 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- abstract (1.0.0)
5
- actionmailer (3.0.8)
6
- actionpack (= 3.0.8)
7
- mail (~> 2.2.19)
8
- actionpack (3.0.8)
9
- activemodel (= 3.0.8)
10
- activesupport (= 3.0.8)
11
- builder (~> 2.1.2)
12
- erubis (~> 2.6.6)
13
- i18n (~> 0.5.0)
14
- rack (~> 1.2.1)
15
- rack-mount (~> 0.6.14)
16
- rack-test (~> 0.5.7)
17
- tzinfo (~> 0.3.23)
18
- activemodel (3.0.8)
19
- activesupport (= 3.0.8)
20
- builder (~> 2.1.2)
21
- i18n (~> 0.5.0)
22
- activerecord (3.0.8)
23
- activemodel (= 3.0.8)
24
- activesupport (= 3.0.8)
25
- arel (~> 2.0.10)
26
- tzinfo (~> 0.3.23)
27
- activeresource (3.0.8)
28
- activemodel (= 3.0.8)
29
- activesupport (= 3.0.8)
30
- activesupport (3.0.8)
31
4
  addressable (2.3.5)
32
- arel (2.0.10)
33
5
  builder (2.1.2)
34
6
  diff-lcs (1.2.1)
35
- erubis (2.6.6)
36
- abstract (>= 1.0.0)
37
7
  faraday (0.8.7)
38
8
  multipart-post (~> 1.1)
39
9
  git (1.2.5)
@@ -47,7 +17,6 @@ GEM
47
17
  hashie (2.0.5)
48
18
  highline (1.6.19)
49
19
  httpauth (0.2.0)
50
- i18n (0.5.0)
51
20
  jeweler (1.8.6)
52
21
  builder
53
22
  bundler (~> 1.0)
@@ -57,14 +26,9 @@ GEM
57
26
  nokogiri (= 1.5.10)
58
27
  rake
59
28
  rdoc
29
+ json (1.8.1)
60
30
  jwt (0.1.8)
61
31
  multi_json (>= 1.5)
62
- mail (2.2.19)
63
- activesupport (>= 2.3.6)
64
- i18n (>= 0.4.0)
65
- mime-types (~> 1.16)
66
- treetop (~> 1.4.8)
67
- mime-types (1.21)
68
32
  multi_json (1.7.1)
69
33
  multi_xml (0.5.4)
70
34
  multipart-post (1.2.0)
@@ -76,27 +40,10 @@ GEM
76
40
  multi_json (~> 1.0)
77
41
  multi_xml (~> 0.5)
78
42
  rack (~> 1.2)
79
- polyglot (0.3.3)
80
43
  rack (1.2.8)
81
- rack-mount (0.6.14)
82
- rack (>= 1.0.0)
83
- rack-test (0.5.7)
84
- rack (>= 1.0)
85
- rails (3.0.8)
86
- actionmailer (= 3.0.8)
87
- actionpack (= 3.0.8)
88
- activerecord (= 3.0.8)
89
- activeresource (= 3.0.8)
90
- activesupport (= 3.0.8)
91
- bundler (~> 1.0)
92
- railties (= 3.0.8)
93
- railties (3.0.8)
94
- actionpack (= 3.0.8)
95
- activesupport (= 3.0.8)
96
- rake (>= 0.8.7)
97
- thor (~> 0.14.4)
98
44
  rake (10.0.3)
99
- rdoc (4.0.0)
45
+ rdoc (4.1.2)
46
+ json (~> 1.4)
100
47
  rspec (2.13.0)
101
48
  rspec-core (~> 2.13.0)
102
49
  rspec-expectations (~> 2.13.0)
@@ -109,19 +56,13 @@ GEM
109
56
  multi_json (~> 1.0)
110
57
  simplecov-html (~> 0.7.1)
111
58
  simplecov-html (0.7.1)
112
- thor (0.14.6)
113
- treetop (1.4.12)
114
- polyglot
115
- polyglot (>= 0.3.1)
116
- tzinfo (0.3.37)
117
59
 
118
60
  PLATFORMS
119
61
  ruby
120
62
 
121
63
  DEPENDENCIES
122
- bundler (> 1.2.0)
123
- jeweler (> 1.8.4)
124
- rails
125
- rdoc (> 3.12)
126
- rspec (> 2.10.0)
127
- simplecov (>= 0.5)
64
+ bundler (~> 1.2, > 1.2.0)
65
+ jeweler (~> 1.8, > 1.8.4)
66
+ rdoc (~> 4.0, > 4.0.0)
67
+ rspec (~> 2.10, > 2.10.0)
68
+ simplecov (~> 0.5)
data/README.md CHANGED
@@ -26,12 +26,22 @@ For random content generation
26
26
  * box maker
27
27
  * loremimages
28
28
 
29
+ Latest masonry 3.1.5
30
+
31
+ * masonry.min
32
+
33
+ layouts (in `masonry/layouts` folder)
34
+
35
+ * layout/horizontal
36
+
29
37
  ## Isotope
30
38
 
31
39
  [Isotope](http://isotope.metafizzy.co/index.html) is also included. Isotope is very similar to Masonry and might be a nice alternative for some use cases. Why it is included ;)
32
40
 
33
41
  ### Isotope assets
34
42
 
43
+ all found in the `isotope` folder
44
+
35
45
  Javascript
36
46
 
37
47
  * jquery.isotope.js
@@ -42,6 +52,21 @@ Extras:
42
52
  * jquery.debounced_resize.min.js
43
53
  * jquery.throttled_resize.min.js
44
54
 
55
+ For latest isotope 2.0
56
+
57
+ * isotope
58
+ * layout-mode
59
+ * item
60
+
61
+ layouts (in `isotope/layouts` folder)
62
+
63
+ * layout/cells-by-column
64
+ * layout/cells-by-row
65
+ * layout/fit-columns
66
+ * layout/horizontal
67
+ * layout/packery
68
+
69
+
45
70
  Stylesheets
46
71
 
47
72
  * isotope.css
@@ -50,7 +75,7 @@ More isotope related stylesheets in `isotope` folder in `vendor/assets. Use as i
50
75
 
51
76
  Please see Isotope [License](http://isotope.metafizzy.co/docs/license.html) for commercial use.
52
77
 
53
- Usage: See [Getting started](http://isotope.metafizzy.co/docs/introduction.html#getting_started)
78
+ Usage: See [Getting started](http://isotope.metafizzy.co/#getting-started)
54
79
 
55
80
  ## Usage
56
81
 
@@ -78,10 +103,18 @@ Use these stylesheets as a base in order to play around with different effects..
78
103
 
79
104
  ### Javascript
80
105
 
106
+ *masonry*
107
+
81
108
  ```javascript
82
109
  //= require masonry/jquery.masonry
83
110
  ```
84
111
 
112
+ To use latest *masonry 3.1.5* without jQuery
113
+
114
+ ```javascript
115
+ //= require masonry/masonry
116
+ ```
117
+
85
118
  Optional
86
119
 
87
120
  ```javascript
@@ -100,9 +133,17 @@ Content generation helpers:
100
133
 
101
134
  See examples on [masonry](http://masonry.desandro.com/docs/intro.html) or [github](https://github.com/desandro/masonry)
102
135
 
136
+ *isotope*
137
+
138
+ All isotope scripts are in the `isotope` folder
139
+
140
+ ```javascript
141
+ //= require isotope/jquery.isotope
142
+ ```
143
+
103
144
  ### Setup
104
145
 
105
- We will use the _infinite scroll_ example for a full walkthrough of how to setup and use Masonry. We add the classes `transitions-enabled`and `infinite-scroll` to the container in order to enable these two effects simultaneously. Look further down in this guide to see configurations of other effects that canbe combined ;)
146
+ We will use the _infinite scroll_ example for a full walkthrough of how to setup and use Masonry. We add the classes `transitions-enabled`and `infinite-scroll` to the container in order to enable these two effects simultaneously. Look further down in this guide to see configurations of other effects that can be combined ;)
106
147
 
107
148
  *Main container*
108
149
 
@@ -110,6 +151,8 @@ We will use the _infinite scroll_ example for a full walkthrough of how to setup
110
151
  <div id="masonry-container" class="transitions-enabled infinite-scroll clearfix">
111
152
 
112
153
  <div class="box col3">
154
+ ...
155
+ </div>
113
156
 
114
157
  <div class="box col1">
115
158
  <p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. </p>
@@ -124,7 +167,7 @@ We will use the _infinite scroll_ example for a full walkthrough of how to setup
124
167
  </div>
125
168
  ```
126
169
 
127
- Note: We use the ID `masonry-container` in order to ensure against conflicts with other "plugins". Twitter Bootstrap, f.ex reserves the class names `container` and `container-fluid` for particular (container) layouts.
170
+ Note: We use the ID `masonry-container` in order to ensure against conflicts with other "plugins". Twitter Bootstrap, for example, reserves the class names `container` and `container-fluid` for particular (container) layouts.
128
171
 
129
172
  ```css
130
173
  #masonry-container {
@@ -181,7 +224,7 @@ Add class `has-gutters` to container for this effect.
181
224
 
182
225
  ## Right to left
183
226
 
184
- Enable right-to-layout by setting the `isRTL` option to true.
227
+ Enable right-to-left layout by setting the `isRTL` option to true.
185
228
 
186
229
  See `masonry/right-to-left.css`
187
230
 
@@ -250,7 +293,7 @@ Transitions used in examples
250
293
 
251
294
  Note: use `masonry/transitions.css` for a head start!
252
295
 
253
- Noice the class names: `.transitions-enabled`, `masonry` and `.masonry-brick`.
296
+ Notice the class names: `.transitions-enabled`, `masonry` and `.masonry-brick`.
254
297
 
255
298
  ```css
256
299
  .transitions-enabled.masonry,
@@ -388,7 +431,7 @@ $(function(){
388
431
  });
389
432
  ```
390
433
 
391
- The loader should be "on top". Here the loader iscon is configured in the `loading` object as `http://i.imgur.com/6RMhx.gif`. This loader is included as an image asset at `assets/images/masonry/loader.gif`. So instead simply use:
434
+ The loader should be "on top". Here the loader is configured in the `loading` object as `http://i.imgur.com/6RMhx.gif`. This loader is included as an image asset at `assets/images/masonry/loader.gif`. So instead simply use:
392
435
 
393
436
  `img: '/assets/masonry/loader.gif'`
394
437
 
@@ -510,7 +553,7 @@ When the ajax-request is sent to the ArticlesController we need to append the ne
510
553
  $("#masonry-container").append("<div class='page'><%= escape_javascript(render(@articles)) %></div>");
511
554
  ```
512
555
 
513
- Note: You need to configure Jquery UI to use sausage.
556
+ Note: You need to configure jQuery UI to use sausage.
514
557
 
515
558
  See: [railscast-endless-page](http://railscasts.com/episodes/114-endless-page-revised) for how to use endless pages with Rails using *will_paginate* gem.
516
559
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.3
@@ -2,14 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: masonry-rails 0.2.3 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
8
  s.name = "masonry-rails"
8
- s.version = "0.2.1"
9
+ s.version = "0.2.3"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["Kristian Mandrup"]
12
- s.date = "2013-12-02"
14
+ s.date = "2014-11-20"
13
15
  s.description = "Masonry will rock your world!"
14
16
  s.email = "kmandrup@gmail.com"
15
17
  s.extra_rdoc_files = [
@@ -64,11 +66,19 @@ Gem::Specification.new do |s|
64
66
  "spec/index.html",
65
67
  "spec/spec_helper.rb",
66
68
  "vendor/assets/images/masonry/loader.gif",
67
- "vendor/assets/javascripts/debounce.js",
68
- "vendor/assets/javascripts/jquery.debounced_resize.js",
69
- "vendor/assets/javascripts/jquery.isotope.js",
70
- "vendor/assets/javascripts/jquery.isotope.min.js",
71
- "vendor/assets/javascripts/jquery.throttled_resize.js",
69
+ "vendor/assets/javascripts/isotope/debounce.js",
70
+ "vendor/assets/javascripts/isotope/isotope.js",
71
+ "vendor/assets/javascripts/isotope/item.js",
72
+ "vendor/assets/javascripts/isotope/jquery.debounced_resize.js",
73
+ "vendor/assets/javascripts/isotope/jquery.isotope.js",
74
+ "vendor/assets/javascripts/isotope/jquery.isotope.min.js",
75
+ "vendor/assets/javascripts/isotope/jquery.throttled_resize.js",
76
+ "vendor/assets/javascripts/isotope/layout-mode.js",
77
+ "vendor/assets/javascripts/isotope/layout/cells-by-column.js",
78
+ "vendor/assets/javascripts/isotope/layout/cells-by-row.js",
79
+ "vendor/assets/javascripts/isotope/layout/fit-columns.js",
80
+ "vendor/assets/javascripts/isotope/layout/horizontal.js",
81
+ "vendor/assets/javascripts/isotope/layout/packery.js",
72
82
  "vendor/assets/javascripts/masonry/box-maker.js",
73
83
  "vendor/assets/javascripts/masonry/jquery.event-drag.js",
74
84
  "vendor/assets/javascripts/masonry/jquery.imagesloaded.js",
@@ -82,6 +92,8 @@ Gem::Specification.new do |s|
82
92
  "vendor/assets/javascripts/masonry/jquery.pageless.min.js",
83
93
  "vendor/assets/javascripts/masonry/jquery.sausage.js",
84
94
  "vendor/assets/javascripts/masonry/jquery.sausage.min.js",
95
+ "vendor/assets/javascripts/masonry/layout/horizontal.js",
96
+ "vendor/assets/javascripts/masonry/masonry.min.js",
85
97
  "vendor/assets/javascripts/masonry/modernizr-transitions.js",
86
98
  "vendor/assets/stylesheets/isotope.css",
87
99
  "vendor/assets/stylesheets/isotope/base.css",
@@ -100,35 +112,31 @@ Gem::Specification.new do |s|
100
112
  ]
101
113
  s.homepage = "http://github.com/kristianmandrup/masonry-rails"
102
114
  s.licenses = ["MIT"]
103
- s.require_paths = ["lib"]
104
- s.rubygems_version = "2.0.0"
115
+ s.rubygems_version = "2.2.2"
105
116
  s.summary = "Use JQuery Masonry with Rails asset pipeline"
106
117
 
107
118
  if s.respond_to? :specification_version then
108
119
  s.specification_version = 4
109
120
 
110
121
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
111
- s.add_runtime_dependency(%q<rails>, [">= 0"])
112
- s.add_development_dependency(%q<rspec>, ["> 2.10.0"])
113
- s.add_development_dependency(%q<rdoc>, ["> 3.12"])
114
- s.add_development_dependency(%q<bundler>, ["> 1.2.0"])
115
- s.add_development_dependency(%q<jeweler>, ["> 1.8.4"])
116
- s.add_development_dependency(%q<simplecov>, [">= 0.5"])
122
+ s.add_development_dependency(%q<rspec>, ["> 2.10.0", "~> 2.10"])
123
+ s.add_development_dependency(%q<rdoc>, ["> 4.0.0", "~> 4.0"])
124
+ s.add_development_dependency(%q<bundler>, ["> 1.2.0", "~> 1.2"])
125
+ s.add_development_dependency(%q<jeweler>, ["> 1.8.4", "~> 1.8"])
126
+ s.add_development_dependency(%q<simplecov>, ["~> 0.5"])
117
127
  else
118
- s.add_dependency(%q<rails>, [">= 0"])
119
- s.add_dependency(%q<rspec>, ["> 2.10.0"])
120
- s.add_dependency(%q<rdoc>, ["> 3.12"])
121
- s.add_dependency(%q<bundler>, ["> 1.2.0"])
122
- s.add_dependency(%q<jeweler>, ["> 1.8.4"])
123
- s.add_dependency(%q<simplecov>, [">= 0.5"])
128
+ s.add_dependency(%q<rspec>, ["> 2.10.0", "~> 2.10"])
129
+ s.add_dependency(%q<rdoc>, ["> 4.0.0", "~> 4.0"])
130
+ s.add_dependency(%q<bundler>, ["> 1.2.0", "~> 1.2"])
131
+ s.add_dependency(%q<jeweler>, ["> 1.8.4", "~> 1.8"])
132
+ s.add_dependency(%q<simplecov>, ["~> 0.5"])
124
133
  end
125
134
  else
126
- s.add_dependency(%q<rails>, [">= 0"])
127
- s.add_dependency(%q<rspec>, ["> 2.10.0"])
128
- s.add_dependency(%q<rdoc>, ["> 3.12"])
129
- s.add_dependency(%q<bundler>, ["> 1.2.0"])
130
- s.add_dependency(%q<jeweler>, ["> 1.8.4"])
131
- s.add_dependency(%q<simplecov>, [">= 0.5"])
135
+ s.add_dependency(%q<rspec>, ["> 2.10.0", "~> 2.10"])
136
+ s.add_dependency(%q<rdoc>, ["> 4.0.0", "~> 4.0"])
137
+ s.add_dependency(%q<bundler>, ["> 1.2.0", "~> 1.2"])
138
+ s.add_dependency(%q<jeweler>, ["> 1.8.4", "~> 1.8"])
139
+ s.add_dependency(%q<simplecov>, ["~> 0.5"])
132
140
  end
133
141
  end
134
142
 
@@ -0,0 +1,628 @@
1
+ /*!
2
+ * Isotope v2.0.1
3
+ * Filter & sort magical layouts
4
+ * http://isotope.metafizzy.co
5
+ */
6
+
7
+ ( function( window ) {
8
+
9
+ 'use strict';
10
+
11
+ // -------------------------- vars -------------------------- //
12
+
13
+ var jQuery = window.jQuery;
14
+
15
+ // -------------------------- helpers -------------------------- //
16
+
17
+ // extend objects
18
+ function extend( a, b ) {
19
+ for ( var prop in b ) {
20
+ a[ prop ] = b[ prop ];
21
+ }
22
+ return a;
23
+ }
24
+
25
+ var trim = String.prototype.trim ?
26
+ function( str ) {
27
+ return str.trim();
28
+ } :
29
+ function( str ) {
30
+ return str.replace( /^\s+|\s+$/g, '' );
31
+ };
32
+
33
+ var docElem = document.documentElement;
34
+
35
+ var getText = docElem.textContent ?
36
+ function( elem ) {
37
+ return elem.textContent;
38
+ } :
39
+ function( elem ) {
40
+ return elem.innerText;
41
+ };
42
+
43
+ var objToString = Object.prototype.toString;
44
+ function isArray( obj ) {
45
+ return objToString.call( obj ) === '[object Array]';
46
+ }
47
+
48
+ // index of helper cause IE8
49
+ var indexOf = Array.prototype.indexOf ? function( ary, obj ) {
50
+ return ary.indexOf( obj );
51
+ } : function( ary, obj ) {
52
+ for ( var i=0, len = ary.length; i < len; i++ ) {
53
+ if ( ary[i] === obj ) {
54
+ return i;
55
+ }
56
+ }
57
+ return -1;
58
+ };
59
+
60
+ // turn element or nodeList into an array
61
+ function makeArray( obj ) {
62
+ var ary = [];
63
+ if ( isArray( obj ) ) {
64
+ // use object if already an array
65
+ ary = obj;
66
+ } else if ( obj && typeof obj.length === 'number' ) {
67
+ // convert nodeList to array
68
+ for ( var i=0, len = obj.length; i < len; i++ ) {
69
+ ary.push( obj[i] );
70
+ }
71
+ } else {
72
+ // array of single index
73
+ ary.push( obj );
74
+ }
75
+ return ary;
76
+ }
77
+
78
+ function removeFrom( obj, ary ) {
79
+ var index = indexOf( ary, obj );
80
+ if ( index !== -1 ) {
81
+ ary.splice( index, 1 );
82
+ }
83
+ }
84
+
85
+ // -------------------------- isotopeDefinition -------------------------- //
86
+
87
+ // used for AMD definition and requires
88
+ function isotopeDefinition( Outlayer, getSize, matchesSelector, Item, LayoutMode ) {
89
+ // create an Outlayer layout class
90
+ var Isotope = Outlayer.create( 'isotope', {
91
+ layoutMode: "masonry",
92
+ isJQueryFiltering: true,
93
+ sortAscending: true
94
+ });
95
+
96
+ Isotope.Item = Item;
97
+ Isotope.LayoutMode = LayoutMode;
98
+
99
+ Isotope.prototype._create = function() {
100
+ this.itemGUID = 0;
101
+ // functions that sort items
102
+ this._sorters = {};
103
+ this._getSorters();
104
+ // call super
105
+ Outlayer.prototype._create.call( this );
106
+
107
+ // create layout modes
108
+ this.modes = {};
109
+ // start filteredItems with all items
110
+ this.filteredItems = this.items;
111
+ // keep of track of sortBys
112
+ this.sortHistory = [ 'original-order' ];
113
+ // create from registered layout modes
114
+ for ( var name in LayoutMode.modes ) {
115
+ this._initLayoutMode( name );
116
+ }
117
+ };
118
+
119
+ Isotope.prototype.reloadItems = function() {
120
+ // reset item ID counter
121
+ this.itemGUID = 0;
122
+ // call super
123
+ Outlayer.prototype.reloadItems.call( this );
124
+ };
125
+
126
+ Isotope.prototype._itemize = function() {
127
+ var items = Outlayer.prototype._itemize.apply( this, arguments );
128
+ // assign ID for original-order
129
+ for ( var i=0, len = items.length; i < len; i++ ) {
130
+ var item = items[i];
131
+ item.id = this.itemGUID++;
132
+ }
133
+ this._updateItemsSortData( items );
134
+ return items;
135
+ };
136
+
137
+
138
+ // -------------------------- layout -------------------------- //
139
+
140
+ Isotope.prototype._initLayoutMode = function( name ) {
141
+ var Mode = LayoutMode.modes[ name ];
142
+ // set mode options
143
+ // HACK extend initial options, back-fill in default options
144
+ var initialOpts = this.options[ name ] || {};
145
+ this.options[ name ] = Mode.options ?
146
+ extend( Mode.options, initialOpts ) : initialOpts;
147
+ // init layout mode instance
148
+ this.modes[ name ] = new Mode( this );
149
+ };
150
+
151
+
152
+ Isotope.prototype.layout = function() {
153
+ // if first time doing layout, do all magic
154
+ if ( !this._isLayoutInited && this.options.isInitLayout ) {
155
+ this.arrange();
156
+ return;
157
+ }
158
+ this._layout();
159
+ };
160
+
161
+ // private method to be used in layout() & magic()
162
+ Isotope.prototype._layout = function() {
163
+ // don't animate first layout
164
+ var isInstant = this._getIsInstant();
165
+ // layout flow
166
+ this._resetLayout();
167
+ this._manageStamps();
168
+ this.layoutItems( this.filteredItems, isInstant );
169
+
170
+ // flag for initalized
171
+ this._isLayoutInited = true;
172
+ };
173
+
174
+ // filter + sort + layout
175
+ Isotope.prototype.arrange = function( opts ) {
176
+ // set any options pass
177
+ this.option( opts );
178
+ this._getIsInstant();
179
+ // filter, sort, and layout
180
+ this.filteredItems = this._filter( this.items );
181
+ this._sort();
182
+ this._layout();
183
+ };
184
+ // alias to _init for main plugin method
185
+ Isotope.prototype._init = Isotope.prototype.arrange;
186
+
187
+ // HACK
188
+ // Don't animate/transition first layout
189
+ // Or don't animate/transition other layouts
190
+ Isotope.prototype._getIsInstant = function() {
191
+ var isInstant = this.options.isLayoutInstant !== undefined ?
192
+ this.options.isLayoutInstant : !this._isLayoutInited;
193
+ this._isInstant = isInstant;
194
+ return isInstant;
195
+ };
196
+
197
+ // -------------------------- filter -------------------------- //
198
+
199
+ Isotope.prototype._filter = function( items ) {
200
+ var filter = this.options.filter;
201
+ filter = filter || '*';
202
+ var matches = [];
203
+ var hiddenMatched = [];
204
+ var visibleUnmatched = [];
205
+
206
+ var test = this._getFilterTest( filter );
207
+
208
+ // test each item
209
+ for ( var i=0, len = items.length; i < len; i++ ) {
210
+ var item = items[i];
211
+ if ( item.isIgnored ) {
212
+ continue;
213
+ }
214
+ // add item to either matched or unmatched group
215
+ var isMatched = test( item );
216
+ // item.isFilterMatched = isMatched;
217
+ // add to matches if its a match
218
+ if ( isMatched ) {
219
+ matches.push( item );
220
+ }
221
+ // add to additional group if item needs to be hidden or revealed
222
+ if ( isMatched && item.isHidden ) {
223
+ hiddenMatched.push( item );
224
+ } else if ( !isMatched && !item.isHidden ) {
225
+ visibleUnmatched.push( item );
226
+ }
227
+ }
228
+
229
+ var _this = this;
230
+ function hideReveal() {
231
+ _this.reveal( hiddenMatched );
232
+ _this.hide( visibleUnmatched );
233
+ }
234
+
235
+ if ( this._isInstant ) {
236
+ this._noTransition( hideReveal );
237
+ } else {
238
+ hideReveal();
239
+ }
240
+
241
+ return matches;
242
+ };
243
+
244
+ // get a jQuery, function, or a matchesSelector test given the filter
245
+ Isotope.prototype._getFilterTest = function( filter ) {
246
+ if ( jQuery && this.options.isJQueryFiltering ) {
247
+ // use jQuery
248
+ return function( item ) {
249
+ return jQuery( item.element ).is( filter );
250
+ };
251
+ }
252
+ if ( typeof filter === 'function' ) {
253
+ // use filter as function
254
+ return function( item ) {
255
+ return filter( item.element );
256
+ };
257
+ }
258
+ // default, use filter as selector string
259
+ return function( item ) {
260
+ return matchesSelector( item.element, filter );
261
+ };
262
+ };
263
+
264
+ // -------------------------- sorting -------------------------- //
265
+
266
+ /**
267
+ * @params {Array} elems
268
+ * @public
269
+ */
270
+ Isotope.prototype.updateSortData = function( elems ) {
271
+ this._getSorters();
272
+ // update item sort data
273
+ // default to all items if none are passed in
274
+ elems = makeArray( elems );
275
+ var items = this.getItems( elems );
276
+ // if no items found, update all items
277
+ items = items.length ? items : this.items;
278
+ this._updateItemsSortData( items );
279
+ };
280
+
281
+ Isotope.prototype._getSorters = function() {
282
+ var getSortData = this.options.getSortData;
283
+ for ( var key in getSortData ) {
284
+ var sorter = getSortData[ key ];
285
+ this._sorters[ key ] = mungeSorter( sorter );
286
+ }
287
+ };
288
+
289
+ /**
290
+ * @params {Array} items - of Isotope.Items
291
+ * @private
292
+ */
293
+ Isotope.prototype._updateItemsSortData = function( items ) {
294
+ for ( var i=0, len = items.length; i < len; i++ ) {
295
+ var item = items[i];
296
+ item.updateSortData();
297
+ }
298
+ };
299
+
300
+ // ----- munge sorter ----- //
301
+
302
+ // encapsulate this, as we just need mungeSorter
303
+ // other functions in here are just for munging
304
+ var mungeSorter = ( function() {
305
+ // add a magic layer to sorters for convienent shorthands
306
+ // `.foo-bar` will use the text of .foo-bar querySelector
307
+ // `[foo-bar]` will use attribute
308
+ // you can also add parser
309
+ // `.foo-bar parseInt` will parse that as a number
310
+ function mungeSorter( sorter ) {
311
+ // if not a string, return function or whatever it is
312
+ if ( typeof sorter !== 'string' ) {
313
+ return sorter;
314
+ }
315
+ // parse the sorter string
316
+ var args = trim( sorter ).split(' ');
317
+ var query = args[0];
318
+ // check if query looks like [an-attribute]
319
+ var attrMatch = query.match( /^\[(.+)\]$/ );
320
+ var attr = attrMatch && attrMatch[1];
321
+ var getValue = getValueGetter( attr, query );
322
+ // use second argument as a parser
323
+ var parser = Isotope.sortDataParsers[ args[1] ];
324
+ // parse the value, if there was a parser
325
+ sorter = parser ? function( elem ) {
326
+ return elem && parser( getValue( elem ) );
327
+ } :
328
+ // otherwise just return value
329
+ function( elem ) {
330
+ return elem && getValue( elem );
331
+ };
332
+
333
+ return sorter;
334
+ }
335
+
336
+ // get an attribute getter, or get text of the querySelector
337
+ function getValueGetter( attr, query ) {
338
+ var getValue;
339
+ // if query looks like [foo-bar], get attribute
340
+ if ( attr ) {
341
+ getValue = function( elem ) {
342
+ return elem.getAttribute( attr );
343
+ };
344
+ } else {
345
+ // otherwise, assume its a querySelector, and get its text
346
+ getValue = function( elem ) {
347
+ var child = elem.querySelector( query );
348
+ return child && getText( child );
349
+ };
350
+ }
351
+ return getValue;
352
+ }
353
+
354
+ return mungeSorter;
355
+ })();
356
+
357
+ // parsers used in getSortData shortcut strings
358
+ Isotope.sortDataParsers = {
359
+ 'parseInt': function( val ) {
360
+ return parseInt( val, 10 );
361
+ },
362
+ 'parseFloat': function( val ) {
363
+ return parseFloat( val );
364
+ }
365
+ };
366
+
367
+ // ----- sort method ----- //
368
+
369
+ // sort filteredItem order
370
+ Isotope.prototype._sort = function() {
371
+ var sortByOpt = this.options.sortBy;
372
+ if ( !sortByOpt ) {
373
+ return;
374
+ }
375
+ // concat all sortBy and sortHistory
376
+ var sortBys = [].concat.apply( sortByOpt, this.sortHistory );
377
+ // sort magic
378
+ var itemSorter = getItemSorter( sortBys, this.options.sortAscending );
379
+ this.filteredItems.sort( itemSorter );
380
+ // keep track of sortBy History
381
+ if ( sortByOpt !== this.sortHistory[0] ) {
382
+ // add to front, oldest goes in last
383
+ this.sortHistory.unshift( sortByOpt );
384
+ }
385
+ };
386
+
387
+ // returns a function used for sorting
388
+ function getItemSorter( sortBys, sortAsc ) {
389
+ return function sorter( itemA, itemB ) {
390
+ // cycle through all sortKeys
391
+ for ( var i = 0, len = sortBys.length; i < len; i++ ) {
392
+ var sortBy = sortBys[i];
393
+ var a = itemA.sortData[ sortBy ];
394
+ var b = itemB.sortData[ sortBy ];
395
+ if ( a > b || a < b ) {
396
+ // if sortAsc is an object, use the value given the sortBy key
397
+ var isAscending = sortAsc[ sortBy ] !== undefined ? sortAsc[ sortBy ] : sortAsc;
398
+ var direction = isAscending ? 1 : -1;
399
+ return ( a > b ? 1 : -1 ) * direction;
400
+ }
401
+ }
402
+ return 0;
403
+ };
404
+ }
405
+
406
+ // -------------------------- methods -------------------------- //
407
+
408
+ // get layout mode
409
+ Isotope.prototype._mode = function() {
410
+ var layoutMode = this.options.layoutMode;
411
+ var mode = this.modes[ layoutMode ];
412
+ if ( !mode ) {
413
+ // TODO console.error
414
+ throw new Error( 'No layout mode: ' + layoutMode );
415
+ }
416
+ // HACK sync mode's options
417
+ // any options set after init for layout mode need to be synced
418
+ mode.options = this.options[ layoutMode ];
419
+ return mode;
420
+ };
421
+
422
+ Isotope.prototype._resetLayout = function() {
423
+ // trigger original reset layout
424
+ Outlayer.prototype._resetLayout.call( this );
425
+ this._mode()._resetLayout();
426
+ };
427
+
428
+ Isotope.prototype._getItemLayoutPosition = function( item ) {
429
+ return this._mode()._getItemLayoutPosition( item );
430
+ };
431
+
432
+ Isotope.prototype._manageStamp = function( stamp ) {
433
+ this._mode()._manageStamp( stamp );
434
+ };
435
+
436
+ Isotope.prototype._getContainerSize = function() {
437
+ return this._mode()._getContainerSize();
438
+ };
439
+
440
+ Isotope.prototype.needsResizeLayout = function() {
441
+ return this._mode().needsResizeLayout();
442
+ };
443
+
444
+ // -------------------------- adding & removing -------------------------- //
445
+
446
+ // HEADS UP overwrites default Outlayer appended
447
+ Isotope.prototype.appended = function( elems ) {
448
+ var items = this.addItems( elems );
449
+ if ( !items.length ) {
450
+ return;
451
+ }
452
+ var filteredItems = this._filterRevealAdded( items );
453
+ // add to filteredItems
454
+ this.filteredItems = this.filteredItems.concat( filteredItems );
455
+ };
456
+
457
+ // HEADS UP overwrites default Outlayer prepended
458
+ Isotope.prototype.prepended = function( elems ) {
459
+ var items = this._itemize( elems );
460
+ if ( !items.length ) {
461
+ return;
462
+ }
463
+ // add items to beginning of collection
464
+ var previousItems = this.items.slice(0);
465
+ this.items = items.concat( previousItems );
466
+ // start new layout
467
+ this._resetLayout();
468
+ this._manageStamps();
469
+ // layout new stuff without transition
470
+ var filteredItems = this._filterRevealAdded( items );
471
+ // layout previous items
472
+ this.layoutItems( previousItems );
473
+ // add to filteredItems
474
+ this.filteredItems = filteredItems.concat( this.filteredItems );
475
+ };
476
+
477
+ Isotope.prototype._filterRevealAdded = function( items ) {
478
+ var filteredItems = this._noTransition( function() {
479
+ return this._filter( items );
480
+ });
481
+ // layout and reveal just the new items
482
+ this.layoutItems( filteredItems, true );
483
+ this.reveal( filteredItems );
484
+ return items;
485
+ };
486
+
487
+ /**
488
+ * Filter, sort, and layout newly-appended item elements
489
+ * @param {Array or NodeList or Element} elems
490
+ */
491
+ Isotope.prototype.insert = function( elems ) {
492
+ var items = this.addItems( elems );
493
+ if ( !items.length ) {
494
+ return;
495
+ }
496
+ // append item elements
497
+ var i, item;
498
+ var len = items.length;
499
+ for ( i=0; i < len; i++ ) {
500
+ item = items[i];
501
+ this.element.appendChild( item.element );
502
+ }
503
+ // filter new stuff
504
+ /*
505
+ // this way adds hides new filtered items with NO transition
506
+ // so user can't see if new hidden items have been inserted
507
+ var filteredInsertItems;
508
+ this._noTransition( function() {
509
+ filteredInsertItems = this._filter( items );
510
+ // hide all new items
511
+ this.hide( filteredInsertItems );
512
+ });
513
+ // */
514
+ // this way hides new filtered items with transition
515
+ // so user at least sees that something has been added
516
+ var filteredInsertItems = this._filter( items );
517
+ // hide all newitems
518
+ this._noTransition( function() {
519
+ this.hide( filteredInsertItems );
520
+ });
521
+ // */
522
+ // set flag
523
+ for ( i=0; i < len; i++ ) {
524
+ items[i].isLayoutInstant = true;
525
+ }
526
+ this.arrange();
527
+ // reset flag
528
+ for ( i=0; i < len; i++ ) {
529
+ delete items[i].isLayoutInstant;
530
+ }
531
+ this.reveal( filteredInsertItems );
532
+ };
533
+
534
+ var _remove = Isotope.prototype.remove;
535
+ Isotope.prototype.remove = function( elems ) {
536
+ elems = makeArray( elems );
537
+ var removeItems = this.getItems( elems );
538
+ // do regular thing
539
+ _remove.call( this, elems );
540
+ // bail if no items to remove
541
+ if ( !removeItems || !removeItems.length ) {
542
+ return;
543
+ }
544
+ // remove elems from filteredItems
545
+ for ( var i=0, len = removeItems.length; i < len; i++ ) {
546
+ var item = removeItems[i];
547
+ // remove item from collection
548
+ removeFrom( item, this.filteredItems );
549
+ }
550
+ };
551
+
552
+ Isotope.prototype.shuffle = function() {
553
+ // update random sortData
554
+ for ( var i=0, len = this.items.length; i < len; i++ ) {
555
+ var item = this.items[i];
556
+ item.sortData.random = Math.random();
557
+ }
558
+ this.options.sortBy = 'random';
559
+ this._sort();
560
+ this._layout();
561
+ };
562
+
563
+ /**
564
+ * trigger fn without transition
565
+ * kind of hacky to have this in the first place
566
+ * @param {Function} fn
567
+ * @returns ret
568
+ * @private
569
+ */
570
+ Isotope.prototype._noTransition = function( fn ) {
571
+ // save transitionDuration before disabling
572
+ var transitionDuration = this.options.transitionDuration;
573
+ // disable transition
574
+ this.options.transitionDuration = 0;
575
+ // do it
576
+ var returnValue = fn.call( this );
577
+ // re-enable transition for reveal
578
+ this.options.transitionDuration = transitionDuration;
579
+ return returnValue;
580
+ };
581
+
582
+ // ----- helper methods ----- //
583
+
584
+ /**
585
+ * getter method for getting filtered item elements
586
+ * @returns {Array} elems - collection of item elements
587
+ */
588
+ Isotope.prototype.getFilteredItemElements = function() {
589
+ var elems = [];
590
+ for ( var i=0, len = this.filteredItems.length; i < len; i++ ) {
591
+ elems.push( this.filteredItems[i].element );
592
+ }
593
+ return elems;
594
+ };
595
+
596
+ // ----- ----- //
597
+
598
+ return Isotope;
599
+ }
600
+
601
+ // -------------------------- transport -------------------------- //
602
+
603
+ if ( typeof define === 'function' && define.amd ) {
604
+ // AMD
605
+ define( [
606
+ 'outlayer/outlayer',
607
+ 'get-size/get-size',
608
+ 'matches-selector/matches-selector',
609
+ './item',
610
+ './layout-mode',
611
+ // include default layout modes
612
+ './layout-modes/masonry',
613
+ './layout-modes/fit-rows',
614
+ './layout-modes/vertical'
615
+ ],
616
+ isotopeDefinition );
617
+ } else {
618
+ // browser global
619
+ window.Isotope = isotopeDefinition(
620
+ window.Outlayer,
621
+ window.getSize,
622
+ window.matchesSelector,
623
+ window.Isotope.Item,
624
+ window.Isotope.LayoutMode
625
+ );
626
+ }
627
+
628
+ })( window );