root / cloudcmsresources / static / cloudcmsresources / js / resources_list.js @ 7fa8ecdf
History | View | Annotate | Download (3.2 kB)
1 |
// Array Remove - By John Resig (MIT Licensed)
|
---|---|
2 |
Array.prototype.remove = function(from, to) { |
3 |
var rest = this.slice((to || from) + 1 || this.length); |
4 |
this.length = from < 0 ? this.length + from : from; |
5 |
return this.push.apply(this, rest); |
6 |
}; |
7 |
|
8 |
function ResourcesModule(el, conf) { |
9 |
|
10 |
var defaults = {'page_limit': 5}; |
11 |
this.conf = $.extend(defaults, conf); |
12 |
|
13 |
this.el = el;
|
14 |
|
15 |
this.selected_category = window.location.hash.replace("#",""); |
16 |
if (!this.selected_category) { this.selected_category = undefined }; |
17 |
|
18 |
this.categories = this.el.find(".categories ul li"); |
19 |
this.orig_categories = this.categories.clone(); |
20 |
|
21 |
//this.update_page_objects();
|
22 |
|
23 |
this.grid_height = 251; |
24 |
this.grid_width = 251; |
25 |
this.grid_gap = 22; |
26 |
|
27 |
var self = this; |
28 |
$(window).bind('hashchange', function() { |
29 |
//self.selected_category = window.location.hash.substring(1);
|
30 |
//self.update_page_objects();
|
31 |
}) |
32 |
} |
33 |
|
34 |
ResourcesModule.prototype.switch = function(hide, show) { |
35 |
var hide = $(hide), show = $(show); |
36 |
var toparent = hide.parent();
|
37 |
var newshow = show.clone();
|
38 |
toparent.append(newshow); |
39 |
hide.animate({top:"-249px"}) |
40 |
newshow.animate({ |
41 |
top:"-249px" |
42 |
}, |
43 |
{ |
44 |
complete:function(){ |
45 |
console.log("complete");
|
46 |
hide.remove(); |
47 |
newshow.css({top:0}); |
48 |
} |
49 |
}) |
50 |
} |
51 |
|
52 |
|
53 |
ResourcesModule.prototype.resources = function() { |
54 |
this._resources = this.el.find(".resource-wrapper"); |
55 |
return this._resources; |
56 |
} |
57 |
|
58 |
ResourcesModule.prototype.hide = function(q) { |
59 |
q.fadeOut(300);
|
60 |
} |
61 |
|
62 |
ResourcesModule.prototype.animate_els = function(els) { |
63 |
$(el).css({ position:'absolute' }); |
64 |
var left = i % 3 == 0 ? 0 : (i % 3) * (self.grid_width) + ((i % 3)-1) * self.grid_gap; |
65 |
|
66 |
var row = Math.floor(i/3); |
67 |
var top = row * (self.grid_gap + self.grid_height);
|
68 |
|
69 |
$(el).animate({left: left}, { complete: function(){ |
70 |
$(el).animate({top: top}, {complete: function(){ |
71 |
|
72 |
self.el.height((self.grid_height + self.grid_gap) * (Math.floor(to_show.length/3) + 1)); |
73 |
|
74 |
}}); |
75 |
}}); |
76 |
$(el).removeClass("first"); |
77 |
|
78 |
if (i % 3 == 0) { |
79 |
$(el).addClass("first"); |
80 |
} |
81 |
$(el).removeClass("hidden"); |
82 |
$(el).show();
|
83 |
} |
84 |
|
85 |
ResourcesModule.prototype.update_page_objects = function() { |
86 |
var to_show = this.resources().filter("[data-category="+this.selected_category+"]"); |
87 |
var to_hide = this.resources().filter("[data-category!="+this.selected_category+"]"); |
88 |
|
89 |
if (!this.selected_category) { to_show = this.resources(); } |
90 |
_.each(to_hide, function(el){
|
91 |
$(el).fadeOut(100); |
92 |
}); |
93 |
|
94 |
var delay = this.selected_category ? 40 : 0; |
95 |
var self = this; |
96 |
window.setTimeout(function(){
|
97 |
_.each(to_show, function(el, i) {
|
98 |
var new_main_height = (self.grid_height + self.grid_gap) * (Math.floor(to_show.length/3) + 1); |
99 |
if (self.el.height() < new_main_height) {
|
100 |
self.el.height(new_main_height); |
101 |
} |
102 |
}) |
103 |
self.animate_els(to_show); |
104 |
}, delay) |
105 |
} |
106 |
|
107 |
$(document).ready(function(){ |
108 |
var rm = new ResourcesModule($("#resources-list"), {}, []); |
109 |
window.rm = rm; |
110 |
}) |
111 |
|