root / cloudcmsresources / static / cloudcmsresources / js / resources_list.js @ 3158d6f6
History | View | Annotate | Download (3.5 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 |
self.update_selected_category(); |
32 |
}) |
33 |
|
34 |
self.update_page_objects(); |
35 |
self.update_selected_category(); |
36 |
} |
37 |
|
38 |
ResourcesModule.prototype.switch = function(hide, show) { |
39 |
var hide = $(hide), show = $(show); |
40 |
var toparent = hide.parent();
|
41 |
var newshow = show.clone();
|
42 |
toparent.append(newshow); |
43 |
hide.animate({top:"-249px"}) |
44 |
newshow.animate({ |
45 |
top:"-249px" |
46 |
}, |
47 |
{ |
48 |
complete:function(){ |
49 |
hide.remove(); |
50 |
newshow.css({top:0}); |
51 |
} |
52 |
}) |
53 |
} |
54 |
|
55 |
|
56 |
ResourcesModule.prototype.resources = function() { |
57 |
this._resources = this.el.find(".resource-wrapper"); |
58 |
return this._resources; |
59 |
} |
60 |
|
61 |
ResourcesModule.prototype.hide = function(q) { |
62 |
q.fadeOut(300);
|
63 |
} |
64 |
|
65 |
ResourcesModule.prototype.animate_els = function(els) { |
66 |
$(el).css({ position:'absolute' }); |
67 |
var left = i % 3 == 0 ? 0 : (i % 3) * (self.grid_width) + ((i % 3)-1) * self.grid_gap; |
68 |
|
69 |
var row = Math.floor(i/3); |
70 |
var top = row * (self.grid_gap + self.grid_height);
|
71 |
|
72 |
$(el).animate({left: left}, { complete: function(){ |
73 |
$(el).animate({top: top}, {complete: function(){ |
74 |
|
75 |
self.el.height((self.grid_height + self.grid_gap) * (Math.floor(to_show.length/3) + 1)); |
76 |
|
77 |
}}); |
78 |
}}); |
79 |
$(el).removeClass("first"); |
80 |
|
81 |
if (i % 3 == 0) { |
82 |
$(el).addClass("first"); |
83 |
} |
84 |
$(el).removeClass("hidden"); |
85 |
$(el).show();
|
86 |
} |
87 |
|
88 |
ResourcesModule.prototype.update_selected_category = function() { |
89 |
if (!this.selected_category) { |
90 |
this.categories.removeClass("inactive").removeClass("active"); |
91 |
} |
92 |
|
93 |
var to_hide = this.categories.filter("[data-id="+this.selected_category+"]"); |
94 |
var to_show = this.categories.filter("[data-id!="+this.selected_category+"]"); |
95 |
|
96 |
to_show.removeClass("active").addClass("inactive"); |
97 |
to_hide.removeClass("inactive").addClass("active"); |
98 |
} |
99 |
|
100 |
ResourcesModule.prototype.update_page_objects = function() { |
101 |
var to_show = this.resources().filter("[data-category="+this.selected_category+"]"); |
102 |
var to_hide = this.resources().filter("[data-category!="+this.selected_category+"]"); |
103 |
|
104 |
if (!this.selected_category) { to_show = this.resources(); } |
105 |
_.each(to_hide, function(el){
|
106 |
$(el).hide();
|
107 |
}); |
108 |
|
109 |
_.each(to_show, function(el, i){
|
110 |
if (i%3 == 0) { |
111 |
$(el).addClass("first"); |
112 |
} else {
|
113 |
$(el).removeClass("first"); |
114 |
} |
115 |
$(el).fadeIn(40); |
116 |
}); |
117 |
} |
118 |
|
119 |
$(document).ready(function(){ |
120 |
var rm = new ResourcesModule($("#resources-list"), {}, []); |
121 |
window.rm = rm; |
122 |
}) |
123 |
|