1 // Array Remove - By John Resig (MIT Licensed)
\r
2 Array.prototype.remove = function(from, to) {
\r
3 var rest = this.slice((to || from) + 1 || this.length);
\r
4 this.length = from < 0 ? this.length + from : from;
\r
5 return this.push.apply(this, rest);
\r
8 function ResourcesModule(el, conf) {
\r
10 var defaults = {'page_limit': 5};
\r
11 this.conf = $.extend(defaults, conf);
\r
15 this.selected_category = window.location.hash.replace("#","");
\r
16 if (!this.selected_category) { this.selected_category = undefined };
\r
18 this.categories = this.el.find(".categories ul li");
\r
19 this.orig_categories = this.categories.clone();
\r
21 //this.update_page_objects();
\r
23 this.grid_height = 251;
\r
24 this.grid_width = 251;
\r
28 $(window).bind('hashchange', function() {
\r
29 self.selected_category = window.location.hash.substring(1);
\r
30 self.update_page_objects();
\r
31 self.update_selected_category();
\r
34 self.update_page_objects();
\r
35 self.update_selected_category();
\r
38 ResourcesModule.prototype.switch = function(hide, show) {
\r
39 var hide = $(hide), show = $(show);
\r
40 var toparent = hide.parent();
\r
41 var newshow = show.clone();
\r
42 toparent.append(newshow);
\r
43 hide.animate({top:"-249px"})
\r
48 complete:function(){
\r
50 newshow.css({top:0});
\r
56 ResourcesModule.prototype.resources = function() {
\r
57 this._resources = this.el.find(".resource-wrapper");
\r
58 return this._resources;
\r
61 ResourcesModule.prototype.hide = function(q) {
\r
65 ResourcesModule.prototype.animate_els = function(els) {
\r
66 $(el).css({ position:'absolute' });
\r
67 var left = i % 3 == 0 ? 0 : (i % 3) * (self.grid_width) + ((i % 3)-1) * self.grid_gap;
\r
69 var row = Math.floor(i/3);
\r
70 var top = row * (self.grid_gap + self.grid_height);
\r
72 $(el).animate({left: left}, { complete: function(){
\r
73 $(el).animate({top: top}, {complete: function(){
\r
75 self.el.height((self.grid_height + self.grid_gap) * (Math.floor(to_show.length/3) + 1));
\r
79 $(el).removeClass("first");
\r
82 $(el).addClass("first");
\r
84 $(el).removeClass("hidden");
\r
88 ResourcesModule.prototype.update_selected_category = function() {
\r
89 if (!this.selected_category) {
\r
90 this.categories.removeClass("inactive").removeClass("active");
\r
91 this.categories.show();
\r
92 this.el.find(".categories a.clear").hide();
\r
96 var to_hide = this.categories.filter("[data-id="+this.selected_category+"]");
\r
97 var to_show = this.categories.filter("[data-id!="+this.selected_category+"]");
\r
99 to_show.removeClass("active").addClass("inactive");
\r
100 to_hide.removeClass("inactive").addClass("active");
\r
101 this.el.find(".categories a.clear").show();
\r
104 ResourcesModule.prototype.update_page_objects = function() {
\r
105 var to_show = this.resources().filter("[data-category="+this.selected_category+"]");
\r
106 var to_hide = this.resources().filter("[data-category!="+this.selected_category+"]");
\r
108 if (!this.selected_category) { to_show = this.resources(); }
\r
109 _.each(to_hide, function(el){
\r
113 _.each(to_show, function(el, i){
\r
115 $(el).addClass("first");
\r
117 $(el).removeClass("first");
\r
123 $(document).ready(function(){
\r
124 var rm = new ResourcesModule($("#resources-list"), {}, []);
\r