root / snf-astakos-app / astakos / im / static / im / js / resources_list.js @ 0f4a8a68
History | View | Annotate | Download (3.6 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 |
|
80 |
$(el).removeClass("hidden"); |
81 |
$(el).show('slow'); |
82 |
} |
83 |
|
84 |
ResourcesModule.prototype.update_selected_category = function() { |
85 |
if (!this.selected_category) { |
86 |
this.categories.removeClass("inactive").removeClass("active"); |
87 |
this.categories.show();
|
88 |
this.el.find(".categories a.clear").hide(); |
89 |
return;
|
90 |
} |
91 |
|
92 |
var to_hide = this.categories.filter("[data-id="+this.selected_category+"]"); |
93 |
var to_show = this.categories.filter("[data-id!="+this.selected_category+"]"); |
94 |
|
95 |
to_show.removeClass("active").addClass("inactive"); |
96 |
to_hide.removeClass("inactive").addClass("active"); |
97 |
this.el.find(".categories a.clear").show(); |
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('slow'); |
107 |
}); |
108 |
|
109 |
_.each(to_show, function(el, i){
|
110 |
|
111 |
$(el).fadeIn(40); |
112 |
}); |
113 |
} |
114 |
|
115 |
$(document).ready(function(){ |
116 |
var rm = new ResourcesModule($("#resources-list"), {}, []); |
117 |
window.rm = rm; |
118 |
}) |
119 |
|
120 |
|