jquery-wookmark-rails 0.0.1
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.
- data/.gitignore +16 -0
- data/LICENSE +20 -0
- data/README.md +4 -0
- data/jquery-wookmark-rails.gemspec +16 -0
- data/lib/jquery-wookmark-rails.rb +9 -0
- data/vendor/assets/javascripts/jquery.wookmark.js +450 -0
- data/vendor/assets/javascripts/jquery.wookmark.min.js +12 -0
- metadata +53 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Road Tang
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'jquery-wookmark-rails'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2013-09-21'
|
5
|
+
s.summary = "Jquery wookmakr for Rails"
|
6
|
+
s.description = "integrate jquery wookmark plugin into rails asset pipline"
|
7
|
+
s.authors = ["Road Tang"]
|
8
|
+
s.email = 'roadtang@gmail.com'
|
9
|
+
|
10
|
+
s.files = `git ls-files`.split("\n")
|
11
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
12
|
+
s.require_path = 'lib'
|
13
|
+
|
14
|
+
s.homepage = 'http://github.com/roadt/jquery-wookmark-rails'
|
15
|
+
s.license = 'MIT'
|
16
|
+
end
|
@@ -0,0 +1,450 @@
|
|
1
|
+
/*!
|
2
|
+
jQuery Wookmark plugin
|
3
|
+
@name jquery.wookmark.js
|
4
|
+
@author Christoph Ono (chri@sto.ph or @gbks)
|
5
|
+
@author Sebastian Helzle (sebastian@helzle.net or @sebobo)
|
6
|
+
@version 1.4.3
|
7
|
+
@date 8/25/2013
|
8
|
+
@category jQuery plugin
|
9
|
+
@copyright (c) 2009-2013 Christoph Ono (www.wookmark.com)
|
10
|
+
@license Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
|
11
|
+
*/
|
12
|
+
(function (factory) {
|
13
|
+
if (typeof define === 'function' && define.amd)
|
14
|
+
define(['jquery'], factory);
|
15
|
+
else
|
16
|
+
factory(jQuery);
|
17
|
+
}(function ($) {
|
18
|
+
|
19
|
+
var Wookmark, defaultOptions, __bind;
|
20
|
+
|
21
|
+
__bind = function(fn, me) {
|
22
|
+
return function() {
|
23
|
+
return fn.apply(me, arguments);
|
24
|
+
};
|
25
|
+
};
|
26
|
+
|
27
|
+
// Wookmark default options
|
28
|
+
defaultOptions = {
|
29
|
+
align: 'center',
|
30
|
+
autoResize: false,
|
31
|
+
comparator: null,
|
32
|
+
container: $('body'),
|
33
|
+
ignoreInactiveItems: true,
|
34
|
+
itemWidth: 0,
|
35
|
+
fillEmptySpace: false,
|
36
|
+
flexibleWidth: 0,
|
37
|
+
direction: undefined,
|
38
|
+
offset: 2,
|
39
|
+
onLayoutChanged: undefined,
|
40
|
+
outerOffset: 0,
|
41
|
+
resizeDelay: 50
|
42
|
+
};
|
43
|
+
|
44
|
+
Wookmark = (function() {
|
45
|
+
|
46
|
+
function Wookmark(handler, options) {
|
47
|
+
// Instance variables.
|
48
|
+
this.handler = handler;
|
49
|
+
this.columns = this.containerWidth = this.resizeTimer = null;
|
50
|
+
this.activeItemCount = 0;
|
51
|
+
this.itemHeightsDirty = true;
|
52
|
+
this.placeholders = [];
|
53
|
+
|
54
|
+
$.extend(true, this, defaultOptions, options);
|
55
|
+
|
56
|
+
// Bind instance methods
|
57
|
+
this.update = __bind(this.update, this);
|
58
|
+
this.onResize = __bind(this.onResize, this);
|
59
|
+
this.onRefresh = __bind(this.onRefresh, this);
|
60
|
+
this.getItemWidth = __bind(this.getItemWidth, this);
|
61
|
+
this.layout = __bind(this.layout, this);
|
62
|
+
this.layoutFull = __bind(this.layoutFull, this);
|
63
|
+
this.layoutColumns = __bind(this.layoutColumns, this);
|
64
|
+
this.filter = __bind(this.filter, this);
|
65
|
+
this.clear = __bind(this.clear, this);
|
66
|
+
this.getActiveItems = __bind(this.getActiveItems, this);
|
67
|
+
this.refreshPlaceholders = __bind(this.refreshPlaceholders, this);
|
68
|
+
this.sortElements = __bind(this.sortElements, this);
|
69
|
+
|
70
|
+
// Collect filter data
|
71
|
+
var i = 0, j = 0, filterClasses = {}, itemFilterClasses, $item, filterClass;
|
72
|
+
|
73
|
+
for (; i < handler.length; i++) {
|
74
|
+
$item = handler.eq(i);
|
75
|
+
|
76
|
+
// Read filter classes
|
77
|
+
itemFilterClasses = $item.data('filterClass');
|
78
|
+
|
79
|
+
// Globally store each filter class as object and the fitting items in the array
|
80
|
+
if (typeof itemFilterClasses == 'object' && itemFilterClasses.length > 0) {
|
81
|
+
for (j = 0; j < itemFilterClasses.length; j++) {
|
82
|
+
filterClass = $.trim(itemFilterClasses[j]).toLowerCase();
|
83
|
+
|
84
|
+
if (!(filterClass in filterClasses)) {
|
85
|
+
filterClasses[filterClass] = [];
|
86
|
+
}
|
87
|
+
filterClasses[filterClass].push($item[0]);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}
|
91
|
+
this.filterClasses = filterClasses;
|
92
|
+
|
93
|
+
// Listen to resize event if requested.
|
94
|
+
if (this.autoResize)
|
95
|
+
$(window).bind('resize.wookmark', this.onResize);
|
96
|
+
|
97
|
+
this.container.bind('refreshWookmark', this.onRefresh);
|
98
|
+
}
|
99
|
+
|
100
|
+
// Method for updating the plugins options
|
101
|
+
Wookmark.prototype.update = function(options) {
|
102
|
+
this.itemHeightsDirty = true;
|
103
|
+
$.extend(true, this, options);
|
104
|
+
};
|
105
|
+
|
106
|
+
// This timer ensures that layout is not continuously called as window is being dragged.
|
107
|
+
Wookmark.prototype.onResize = function() {
|
108
|
+
clearTimeout(this.resizeTimer);
|
109
|
+
this.itemHeightsDirty = this.flexibleWidth !== 0;
|
110
|
+
this.resizeTimer = setTimeout(this.layout, this.resizeDelay);
|
111
|
+
};
|
112
|
+
|
113
|
+
// Marks the items heights as dirty and does a relayout
|
114
|
+
Wookmark.prototype.onRefresh = function() {
|
115
|
+
this.itemHeightsDirty = true;
|
116
|
+
this.layout();
|
117
|
+
};
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Filters the active items with the given string filters.
|
121
|
+
* @param filters array of string
|
122
|
+
* @param mode 'or' or 'and'
|
123
|
+
*/
|
124
|
+
Wookmark.prototype.filter = function(filters, mode) {
|
125
|
+
var activeFilters = [], activeFiltersLength, activeItems = $(),
|
126
|
+
i, j, k, filter;
|
127
|
+
|
128
|
+
filters = filters || [];
|
129
|
+
mode = mode || 'or';
|
130
|
+
|
131
|
+
if (filters.length) {
|
132
|
+
// Collect active filters
|
133
|
+
for (i = 0; i < filters.length; i++) {
|
134
|
+
filter = $.trim(filters[i].toLowerCase());
|
135
|
+
if (filter in this.filterClasses) {
|
136
|
+
activeFilters.push(this.filterClasses[filter]);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
// Get items for active filters with the selected mode
|
141
|
+
activeFiltersLength = activeFilters.length;
|
142
|
+
if (mode == 'or' || activeFiltersLength == 1) {
|
143
|
+
// Set all items in all active filters active
|
144
|
+
for (i = 0; i < activeFiltersLength; i++) {
|
145
|
+
activeItems = activeItems.add(activeFilters[i]);
|
146
|
+
}
|
147
|
+
} else if (mode == 'and') {
|
148
|
+
var shortestFilter = activeFilters[0],
|
149
|
+
itemValid = true, foundInFilter,
|
150
|
+
currentItem, currentFilter;
|
151
|
+
|
152
|
+
// Find shortest filter class
|
153
|
+
for (i = 1; i < activeFiltersLength; i++) {
|
154
|
+
if (activeFilters[i].length < shortestFilter.length) {
|
155
|
+
shortestFilter = activeFilters[i];
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
// Iterate over shortest filter and find elements in other filter classes
|
160
|
+
for (i = 0; i < shortestFilter.length; i++) {
|
161
|
+
currentItem = shortestFilter[i];
|
162
|
+
itemValid = true;
|
163
|
+
|
164
|
+
for (j = 0; j < activeFilters.length && itemValid; j++) {
|
165
|
+
currentFilter = activeFilters[j];
|
166
|
+
if (shortestFilter == currentFilter) continue;
|
167
|
+
|
168
|
+
// Search for current item in each active filter class
|
169
|
+
for (k = 0, foundInFilter = false; k < currentFilter.length && !foundInFilter; k++) {
|
170
|
+
foundInFilter = currentFilter[k] == currentItem;
|
171
|
+
}
|
172
|
+
itemValid &= foundInFilter;
|
173
|
+
}
|
174
|
+
if (itemValid)
|
175
|
+
activeItems.push(shortestFilter[i]);
|
176
|
+
}
|
177
|
+
}
|
178
|
+
// Hide inactive items
|
179
|
+
this.handler.not(activeItems).addClass('inactive');
|
180
|
+
} else {
|
181
|
+
// Show all items if no filter is selected
|
182
|
+
activeItems = this.handler;
|
183
|
+
}
|
184
|
+
|
185
|
+
// Show active items
|
186
|
+
activeItems.removeClass('inactive');
|
187
|
+
|
188
|
+
// Unset columns and refresh grid for a full layout
|
189
|
+
this.columns = null;
|
190
|
+
this.layout();
|
191
|
+
};
|
192
|
+
|
193
|
+
/**
|
194
|
+
* Creates or updates existing placeholders to create columns of even height
|
195
|
+
*/
|
196
|
+
Wookmark.prototype.refreshPlaceholders = function(columnWidth, sideOffset) {
|
197
|
+
var i = this.placeholders.length,
|
198
|
+
$placeholder, $lastColumnItem,
|
199
|
+
columnsLength = this.columns.length, column,
|
200
|
+
height, top, innerOffset,
|
201
|
+
containerHeight = this.container.innerHeight();
|
202
|
+
|
203
|
+
for (; i < columnsLength; i++) {
|
204
|
+
$placeholder = $('<div class="wookmark-placeholder"/>').appendTo(this.container);
|
205
|
+
this.placeholders.push($placeholder);
|
206
|
+
}
|
207
|
+
|
208
|
+
innerOffset = this.offset + parseInt(this.placeholders[0].css('borderWidth'), 10) * 2;
|
209
|
+
|
210
|
+
for (i = 0; i < this.placeholders.length; i++) {
|
211
|
+
$placeholder = this.placeholders[i];
|
212
|
+
column = this.columns[i];
|
213
|
+
|
214
|
+
if (i >= columnsLength || !column[column.length - 1]) {
|
215
|
+
$placeholder.css('display', 'none');
|
216
|
+
} else {
|
217
|
+
$lastColumnItem = column[column.length - 1];
|
218
|
+
if (!$lastColumnItem) continue;
|
219
|
+
top = $lastColumnItem.data('wookmark-top') + $lastColumnItem.data('wookmark-height') + this.offset;
|
220
|
+
height = containerHeight - top - innerOffset;
|
221
|
+
|
222
|
+
$placeholder.css({
|
223
|
+
position: 'absolute',
|
224
|
+
display: height > 0 ? 'block' : 'none',
|
225
|
+
left: i * columnWidth + sideOffset,
|
226
|
+
top: top,
|
227
|
+
width: columnWidth - innerOffset,
|
228
|
+
height: height
|
229
|
+
});
|
230
|
+
}
|
231
|
+
}
|
232
|
+
};
|
233
|
+
|
234
|
+
// Method the get active items which are not disabled and visible
|
235
|
+
Wookmark.prototype.getActiveItems = function() {
|
236
|
+
return this.ignoreInactiveItems ? this.handler.not('.inactive') : this.handler;
|
237
|
+
};
|
238
|
+
|
239
|
+
// Method to get the standard item width
|
240
|
+
Wookmark.prototype.getItemWidth = function() {
|
241
|
+
var itemWidth = this.itemWidth,
|
242
|
+
innerWidth = this.container.width() - 2 * this.outerOffset,
|
243
|
+
firstElement = this.handler.eq(0),
|
244
|
+
flexibleWidth = this.flexibleWidth;
|
245
|
+
|
246
|
+
if (this.itemWidth === undefined || this.itemWidth === 0 && !this.flexibleWidth) {
|
247
|
+
itemWidth = firstElement.outerWidth();
|
248
|
+
}
|
249
|
+
else if (typeof this.itemWidth == 'string' && this.itemWidth.indexOf('%') >= 0) {
|
250
|
+
itemWidth = parseFloat(this.itemWidth) / 100 * innerWidth;
|
251
|
+
}
|
252
|
+
|
253
|
+
// Calculate flexible item width if option is set
|
254
|
+
if (flexibleWidth) {
|
255
|
+
if (typeof flexibleWidth == 'string' && flexibleWidth.indexOf('%') >= 0) {
|
256
|
+
flexibleWidth = parseFloat(flexibleWidth) / 100 * innerWidth;
|
257
|
+
}
|
258
|
+
|
259
|
+
var columns = ~~(0.5 + (innerWidth + this.offset) / (flexibleWidth + this.offset)),
|
260
|
+
columnWidth = Math.min(flexibleWidth, ~~((innerWidth - (columns - 1) * this.offset) / columns));
|
261
|
+
|
262
|
+
itemWidth = Math.max(itemWidth, columnWidth);
|
263
|
+
|
264
|
+
// Stretch items to fill calculated width
|
265
|
+
this.handler.css('width', itemWidth);
|
266
|
+
}
|
267
|
+
|
268
|
+
return itemWidth;
|
269
|
+
};
|
270
|
+
|
271
|
+
// Main layout method.
|
272
|
+
Wookmark.prototype.layout = function(force) {
|
273
|
+
// Do nothing if container isn't visible
|
274
|
+
if (!this.container.is(':visible')) return;
|
275
|
+
|
276
|
+
// Calculate basic layout parameters.
|
277
|
+
var columnWidth = this.getItemWidth() + this.offset,
|
278
|
+
containerWidth = this.container.width(),
|
279
|
+
innerWidth = containerWidth - 2 * this.outerOffset,
|
280
|
+
columns = ~~((innerWidth + this.offset) / columnWidth),
|
281
|
+
offset = 0, maxHeight = 0, i = 0,
|
282
|
+
activeItems = this.getActiveItems(),
|
283
|
+
activeItemsLength = activeItems.length,
|
284
|
+
$item;
|
285
|
+
|
286
|
+
// Cache item height
|
287
|
+
if (this.itemHeightsDirty) {
|
288
|
+
for (; i < activeItemsLength; i++) {
|
289
|
+
$item = activeItems.eq(i);
|
290
|
+
$item.data('wookmark-height', $item.outerHeight());
|
291
|
+
}
|
292
|
+
this.itemHeightsDirty = false;
|
293
|
+
}
|
294
|
+
|
295
|
+
// Use less columns if there are to few items
|
296
|
+
columns = Math.max(1, Math.min(columns, activeItemsLength));
|
297
|
+
|
298
|
+
// Calculate the offset based on the alignment of columns to the parent container
|
299
|
+
offset = this.outerOffset;
|
300
|
+
if (this.align == 'center') {
|
301
|
+
offset += ~~(0.5 + (innerWidth - (columns * columnWidth - this.offset)) >> 1);
|
302
|
+
}
|
303
|
+
|
304
|
+
// Get direction for positioning
|
305
|
+
this.direction = this.direction || (this.align == 'right' ? 'right' : 'left');
|
306
|
+
|
307
|
+
// If container and column count hasn't changed, we can only update the columns.
|
308
|
+
if (!force && this.columns !== null && this.columns.length == columns && this.activeItemCount == activeItemsLength) {
|
309
|
+
maxHeight = this.layoutColumns(columnWidth, offset);
|
310
|
+
} else {
|
311
|
+
maxHeight = this.layoutFull(columnWidth, columns, offset);
|
312
|
+
}
|
313
|
+
this.activeItemCount = activeItemsLength;
|
314
|
+
|
315
|
+
// Set container height to height of the grid.
|
316
|
+
this.container.css('height', maxHeight);
|
317
|
+
|
318
|
+
// Update placeholders
|
319
|
+
if (this.fillEmptySpace) {
|
320
|
+
this.refreshPlaceholders(columnWidth, offset);
|
321
|
+
}
|
322
|
+
|
323
|
+
if (this.onLayoutChanged !== undefined && typeof this.onLayoutChanged === 'function') {
|
324
|
+
this.onLayoutChanged();
|
325
|
+
}
|
326
|
+
};
|
327
|
+
|
328
|
+
/**
|
329
|
+
* Sort elements with configurable comparator
|
330
|
+
*/
|
331
|
+
Wookmark.prototype.sortElements = function(elements) {
|
332
|
+
return typeof(this.comparator) === 'function' ? elements.sort(this.comparator) : elements;
|
333
|
+
};
|
334
|
+
|
335
|
+
/**
|
336
|
+
* Perform a full layout update.
|
337
|
+
*/
|
338
|
+
Wookmark.prototype.layoutFull = function(columnWidth, columns, offset) {
|
339
|
+
var $item, i = 0, k = 0,
|
340
|
+
activeItems = $.makeArray(this.getActiveItems()),
|
341
|
+
length = activeItems.length,
|
342
|
+
shortest = null, shortestIndex = null,
|
343
|
+
itemCSS = {position: 'absolute'},
|
344
|
+
sideOffset, heights = [],
|
345
|
+
leftAligned = this.align == 'left' ? true : false;
|
346
|
+
|
347
|
+
this.columns = [];
|
348
|
+
|
349
|
+
// Sort elements before layouting
|
350
|
+
activeItems = this.sortElements(activeItems);
|
351
|
+
|
352
|
+
// Prepare arrays to store height of columns and items.
|
353
|
+
while (heights.length < columns) {
|
354
|
+
heights.push(this.outerOffset);
|
355
|
+
this.columns.push([]);
|
356
|
+
}
|
357
|
+
|
358
|
+
// Loop over items.
|
359
|
+
for (; i < length; i++ ) {
|
360
|
+
$item = $(activeItems[i]);
|
361
|
+
|
362
|
+
// Find the shortest column.
|
363
|
+
shortest = heights[0];
|
364
|
+
shortestIndex = 0;
|
365
|
+
for (k = 0; k < columns; k++) {
|
366
|
+
if (heights[k] < shortest) {
|
367
|
+
shortest = heights[k];
|
368
|
+
shortestIndex = k;
|
369
|
+
}
|
370
|
+
}
|
371
|
+
|
372
|
+
// stick to left side if alignment is left and this is the first column
|
373
|
+
sideOffset = offset;
|
374
|
+
if (shortestIndex > 0 || !leftAligned)
|
375
|
+
sideOffset += shortestIndex * columnWidth;
|
376
|
+
|
377
|
+
// Position the item.
|
378
|
+
itemCSS[this.direction] = sideOffset;
|
379
|
+
itemCSS.top = shortest;
|
380
|
+
$item.css(itemCSS).data('wookmark-top', shortest);
|
381
|
+
|
382
|
+
// Update column height and store item in shortest column
|
383
|
+
heights[shortestIndex] += $item.data('wookmark-height') + this.offset;
|
384
|
+
this.columns[shortestIndex].push($item);
|
385
|
+
}
|
386
|
+
|
387
|
+
// Return longest column
|
388
|
+
return Math.max.apply(Math, heights);
|
389
|
+
};
|
390
|
+
|
391
|
+
/**
|
392
|
+
* This layout method only updates the vertical position of the
|
393
|
+
* existing column assignments.
|
394
|
+
*/
|
395
|
+
Wookmark.prototype.layoutColumns = function(columnWidth, offset) {
|
396
|
+
var heights = [],
|
397
|
+
i = 0, k = 0, currentHeight,
|
398
|
+
column, $item, itemCSS, sideOffset;
|
399
|
+
|
400
|
+
for (; i < this.columns.length; i++) {
|
401
|
+
heights.push(this.outerOffset);
|
402
|
+
column = this.columns[i];
|
403
|
+
sideOffset = i * columnWidth + offset;
|
404
|
+
currentHeight = heights[i];
|
405
|
+
|
406
|
+
for (k = 0; k < column.length; k++) {
|
407
|
+
$item = column[k];
|
408
|
+
itemCSS = {
|
409
|
+
top: currentHeight
|
410
|
+
};
|
411
|
+
itemCSS[this.direction] = sideOffset;
|
412
|
+
|
413
|
+
$item.css(itemCSS).data('wookmark-top', currentHeight);
|
414
|
+
|
415
|
+
currentHeight += $item.data('wookmark-height') + this.offset;
|
416
|
+
}
|
417
|
+
heights[i] = currentHeight;
|
418
|
+
}
|
419
|
+
|
420
|
+
// Return longest column
|
421
|
+
return Math.max.apply(Math, heights);
|
422
|
+
};
|
423
|
+
|
424
|
+
/**
|
425
|
+
* Clear event listeners and time outs.
|
426
|
+
*/
|
427
|
+
Wookmark.prototype.clear = function() {
|
428
|
+
clearTimeout(this.resizeTimer);
|
429
|
+
$(window).unbind('resize.wookmark', this.onResize);
|
430
|
+
this.container.unbind('refreshWookmark', this.onRefresh);
|
431
|
+
};
|
432
|
+
|
433
|
+
return Wookmark;
|
434
|
+
})();
|
435
|
+
|
436
|
+
$.fn.wookmark = function(options) {
|
437
|
+
// Create a wookmark instance if not available
|
438
|
+
if (!this.wookmarkInstance) {
|
439
|
+
this.wookmarkInstance = new Wookmark(this, options || {});
|
440
|
+
} else {
|
441
|
+
this.wookmarkInstance.update(options || {});
|
442
|
+
}
|
443
|
+
|
444
|
+
// Apply layout
|
445
|
+
this.wookmarkInstance.layout(true);
|
446
|
+
|
447
|
+
// Display items (if hidden) and return jQuery object to maintain chainability
|
448
|
+
return this.show();
|
449
|
+
};
|
450
|
+
}));
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/*!
|
2
|
+
jQuery wookmark plugin
|
3
|
+
@name jquery.wookmark.js
|
4
|
+
@author Christoph Ono (chri@sto.ph or @gbks)
|
5
|
+
@author Sebastian Helzle (sebastian@helzle.net or @sebobo)
|
6
|
+
@version 1.4.3
|
7
|
+
@date 08/25/2013
|
8
|
+
@category jQuery plugin
|
9
|
+
@copyright (c) 2009-2013 Christoph Ono (www.wookmark.com)
|
10
|
+
@license Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
|
11
|
+
*/
|
12
|
+
(function(t){"function"==typeof define&&define.amd?define(["jquery"],t):t(jQuery)})(function(t){var i,e,s;s=function(t,i){return function(){return t.apply(i,arguments)}},e={align:"center",autoResize:!1,comparator:null,container:t("body"),ignoreInactiveItems:!0,itemWidth:0,fillEmptySpace:!1,flexibleWidth:0,direction:void 0,offset:2,onLayoutChanged:void 0,outerOffset:0,resizeDelay:50},i=function(){function i(i,h){this.handler=i,this.columns=this.containerWidth=this.resizeTimer=null,this.activeItemCount=0,this.itemHeightsDirty=!0,this.placeholders=[],t.extend(!0,this,e,h),this.update=s(this.update,this),this.onResize=s(this.onResize,this),this.onRefresh=s(this.onRefresh,this),this.getItemWidth=s(this.getItemWidth,this),this.layout=s(this.layout,this),this.layoutFull=s(this.layoutFull,this),this.layoutColumns=s(this.layoutColumns,this),this.filter=s(this.filter,this),this.clear=s(this.clear,this),this.getActiveItems=s(this.getActiveItems,this),this.refreshPlaceholders=s(this.refreshPlaceholders,this),this.sortElements=s(this.sortElements,this);for(var o,n,r,a=0,l=0,f={};i.length>a;a++)if(n=i.eq(a),o=n.data("filterClass"),"object"==typeof o&&o.length>0)for(l=0;o.length>l;l++)r=t.trim(o[l]).toLowerCase(),r in f||(f[r]=[]),f[r].push(n[0]);this.filterClasses=f,this.autoResize&&t(window).bind("resize.wookmark",this.onResize),this.container.bind("refreshWookmark",this.onRefresh)}return i.prototype.update=function(i){this.itemHeightsDirty=!0,t.extend(!0,this,i)},i.prototype.onResize=function(){clearTimeout(this.resizeTimer),this.itemHeightsDirty=0!==this.flexibleWidth,this.resizeTimer=setTimeout(this.layout,this.resizeDelay)},i.prototype.onRefresh=function(){this.itemHeightsDirty=!0,this.layout()},i.prototype.filter=function(i,e){var s,h,o,n,r,a=[],l=t();if(i=i||[],e=e||"or",i.length){for(h=0;i.length>h;h++)r=t.trim(i[h].toLowerCase()),r in this.filterClasses&&a.push(this.filterClasses[r]);if(s=a.length,"or"==e||1==s)for(h=0;s>h;h++)l=l.add(a[h]);else if("and"==e){var f,u,c,d=a[0],m=!0;for(h=1;s>h;h++)a[h].length<d.length&&(d=a[h]);for(h=0;d.length>h;h++){for(u=d[h],m=!0,o=0;a.length>o&&m;o++)if(c=a[o],d!=c){for(n=0,f=!1;c.length>n&&!f;n++)f=c[n]==u;m&=f}m&&l.push(d[h])}}this.handler.not(l).addClass("inactive")}else l=this.handler;l.removeClass("inactive"),this.columns=null,this.layout()},i.prototype.refreshPlaceholders=function(i,e){for(var s,h,o,n,r,a,l=this.placeholders.length,f=this.columns.length,u=this.container.innerHeight();f>l;l++)s=t('<div class="wookmark-placeholder"/>').appendTo(this.container),this.placeholders.push(s);for(a=this.offset+2*parseInt(this.placeholders[0].css("borderWidth"),10),l=0;this.placeholders.length>l;l++)if(s=this.placeholders[l],o=this.columns[l],l>=f||!o[o.length-1])s.css("display","none");else{if(h=o[o.length-1],!h)continue;r=h.data("wookmark-top")+h.data("wookmark-height")+this.offset,n=u-r-a,s.css({position:"absolute",display:n>0?"block":"none",left:l*i+e,top:r,width:i-a,height:n})}},i.prototype.getActiveItems=function(){return this.ignoreInactiveItems?this.handler.not(".inactive"):this.handler},i.prototype.getItemWidth=function(){var t=this.itemWidth,i=this.container.width()-2*this.outerOffset,e=this.handler.eq(0),s=this.flexibleWidth;if(void 0===this.itemWidth||0===this.itemWidth&&!this.flexibleWidth?t=e.outerWidth():"string"==typeof this.itemWidth&&this.itemWidth.indexOf("%")>=0&&(t=parseFloat(this.itemWidth)/100*i),s){"string"==typeof s&&s.indexOf("%")>=0&&(s=parseFloat(s)/100*i);var h=~~(.5+(i+this.offset)/(s+this.offset)),o=Math.min(s,~~((i-(h-1)*this.offset)/h));t=Math.max(t,o),this.handler.css("width",t)}return t},i.prototype.layout=function(t){if(this.container.is(":visible")){var i,e=this.getItemWidth()+this.offset,s=this.container.width(),h=s-2*this.outerOffset,o=~~((h+this.offset)/e),n=0,r=0,a=0,l=this.getActiveItems(),f=l.length;if(this.itemHeightsDirty){for(;f>a;a++)i=l.eq(a),i.data("wookmark-height",i.outerHeight());this.itemHeightsDirty=!1}o=Math.max(1,Math.min(o,f)),n=this.outerOffset,"center"==this.align&&(n+=~~(.5+(h-(o*e-this.offset))>>1)),this.direction=this.direction||("right"==this.align?"right":"left"),r=t||null===this.columns||this.columns.length!=o||this.activeItemCount!=f?this.layoutFull(e,o,n):this.layoutColumns(e,n),this.activeItemCount=f,this.container.css("height",r),this.fillEmptySpace&&this.refreshPlaceholders(e,n),void 0!==this.onLayoutChanged&&"function"==typeof this.onLayoutChanged&&this.onLayoutChanged()}},i.prototype.sortElements=function(t){return"function"==typeof this.comparator?t.sort(this.comparator):t},i.prototype.layoutFull=function(i,e,s){var h,o,n=0,r=0,a=t.makeArray(this.getActiveItems()),l=a.length,f=null,u=null,c={position:"absolute"},d=[],m="left"==this.align?!0:!1;for(this.columns=[],a=this.sortElements(a);e>d.length;)d.push(this.outerOffset),this.columns.push([]);for(;l>n;n++){for(h=t(a[n]),f=d[0],u=0,r=0;e>r;r++)f>d[r]&&(f=d[r],u=r);o=s,(u>0||!m)&&(o+=u*i),c[this.direction]=o,c.top=f,h.css(c).data("wookmark-top",f),d[u]+=h.data("wookmark-height")+this.offset,this.columns[u].push(h)}return Math.max.apply(Math,d)},i.prototype.layoutColumns=function(t,i){for(var e,s,h,o,n,r=[],a=0,l=0;this.columns.length>a;a++){for(r.push(this.outerOffset),s=this.columns[a],n=a*t+i,e=r[a],l=0;s.length>l;l++)h=s[l],o={top:e},o[this.direction]=n,h.css(o).data("wookmark-top",e),e+=h.data("wookmark-height")+this.offset;r[a]=e}return Math.max.apply(Math,r)},i.prototype.clear=function(){clearTimeout(this.resizeTimer),t(window).unbind("resize.wookmark",this.onResize),this.container.unbind("refreshWookmark",this.onRefresh)},i}(),t.fn.wookmark=function(t){return this.wookmarkInstance?this.wookmarkInstance.update(t||{}):this.wookmarkInstance=new i(this,t||{}),this.wookmarkInstance.layout(!0),this.show()}});
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jquery-wookmark-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Road Tang
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-09-21 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: integrate jquery wookmark plugin into rails asset pipline
|
15
|
+
email: roadtang@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- .gitignore
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
- jquery-wookmark-rails.gemspec
|
24
|
+
- lib/jquery-wookmark-rails.rb
|
25
|
+
- vendor/assets/javascripts/jquery.wookmark.js
|
26
|
+
- vendor/assets/javascripts/jquery.wookmark.min.js
|
27
|
+
homepage: http://github.com/roadt/jquery-wookmark-rails
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 1.8.25
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: Jquery wookmakr for Rails
|
52
|
+
test_files: []
|
53
|
+
has_rdoc:
|