Commit 11814b66 authored by Kostas Papadimitriou's avatar Kostas Papadimitriou Committed by Giorgos Korfiatis
Browse files

Cleanup CLRF's

parent 15e08fdf
// Array Remove - By John Resig (MIT Licensed) // Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) { Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length); var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from; this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest); return this.push.apply(this, rest);
}; };
function ResourcesModule(el, conf) { function ResourcesModule(el, conf) {
var defaults = {'page_limit': 5}; var defaults = {'page_limit': 5};
this.conf = $.extend(defaults, conf); this.conf = $.extend(defaults, conf);
this.el = el; this.el = el;
this.selected_category = window.location.hash.replace("#",""); this.selected_category = window.location.hash.replace("#","");
if (!this.selected_category) { this.selected_category = undefined }; if (!this.selected_category) { this.selected_category = undefined };
this.categories = this.el.find(".categories ul li"); this.categories = this.el.find(".categories ul li");
this.orig_categories = this.categories.clone(); this.orig_categories = this.categories.clone();
//this.update_page_objects(); //this.update_page_objects();
this.grid_height = 251; this.grid_height = 251;
this.grid_width = 251; this.grid_width = 251;
this.grid_gap = 22; this.grid_gap = 22;
var self = this; var self = this;
$(window).bind('hashchange', function() { $(window).bind('hashchange', function() {
self.selected_category = window.location.hash.substring(1); self.selected_category = window.location.hash.substring(1);
self.update_page_objects(); self.update_page_objects();
self.update_selected_category(); self.update_selected_category();
}) })
self.update_page_objects(); self.update_page_objects();
self.update_selected_category(); self.update_selected_category();
} }
ResourcesModule.prototype.switch = function(hide, show) { ResourcesModule.prototype.switch = function(hide, show) {
var hide = $(hide), show = $(show); var hide = $(hide), show = $(show);
var toparent = hide.parent(); var toparent = hide.parent();
var newshow = show.clone(); var newshow = show.clone();
toparent.append(newshow); toparent.append(newshow);
hide.animate({top:"-249px"}) hide.animate({top:"-249px"})
newshow.animate({ newshow.animate({
top:"-249px" top:"-249px"
}, },
{ {
complete:function(){ complete:function(){
hide.remove(); hide.remove();
newshow.css({top:0}); newshow.css({top:0});
} }
}) })
} }
ResourcesModule.prototype.resources = function() { ResourcesModule.prototype.resources = function() {
this._resources = this.el.find(".resource-wrapper"); this._resources = this.el.find(".resource-wrapper");
return this._resources; return this._resources;
} }
ResourcesModule.prototype.hide = function(q) { ResourcesModule.prototype.hide = function(q) {
q.fadeOut(300); q.fadeOut(300);
} }
ResourcesModule.prototype.animate_els = function(els) { ResourcesModule.prototype.animate_els = function(els) {
$(el).css({ position:'absolute' }); $(el).css({ position:'absolute' });
var left = i % 3 == 0 ? 0 : (i % 3) * (self.grid_width) + ((i % 3)-1) * self.grid_gap; var left = i % 3 == 0 ? 0 : (i % 3) * (self.grid_width) + ((i % 3)-1) * self.grid_gap;
var row = Math.floor(i/3); var row = Math.floor(i/3);
var top = row * (self.grid_gap + self.grid_height); var top = row * (self.grid_gap + self.grid_height);
$(el).animate({left: left}, { complete: function(){ $(el).animate({left: left}, { complete: function(){
$(el).animate({top: top}, {complete: function(){ $(el).animate({top: top}, {complete: function(){
self.el.height((self.grid_height + self.grid_gap) * (Math.floor(to_show.length/3) + 1)); self.el.height((self.grid_height + self.grid_gap) * (Math.floor(to_show.length/3) + 1));
}}); }});
}}); }});
$(el).removeClass("hidden"); $(el).removeClass("hidden");
$(el).show('slow'); $(el).show('slow');
} }
ResourcesModule.prototype.update_selected_category = function() { ResourcesModule.prototype.update_selected_category = function() {
if (!this.selected_category) { if (!this.selected_category) {
this.categories.removeClass("inactive").removeClass("active"); this.categories.removeClass("inactive").removeClass("active");
this.categories.show(); this.categories.show();
this.el.find(".categories a.clear").hide(); this.el.find(".categories a.clear").hide();
return; return;
} }
var to_hide = this.categories.filter("[data-id="+this.selected_category+"]"); var to_hide = this.categories.filter("[data-id="+this.selected_category+"]");
var to_show = this.categories.filter("[data-id!="+this.selected_category+"]"); var to_show = this.categories.filter("[data-id!="+this.selected_category+"]");
to_show.removeClass("active").addClass("inactive"); to_show.removeClass("active").addClass("inactive");
to_hide.removeClass("inactive").addClass("active"); to_hide.removeClass("inactive").addClass("active");
this.el.find(".categories a.clear").show(); this.el.find(".categories a.clear").show();
} }
ResourcesModule.prototype.update_page_objects = function() { ResourcesModule.prototype.update_page_objects = function() {
var to_show = this.resources().filter("[data-category="+this.selected_category+"]"); var to_show = this.resources().filter("[data-category="+this.selected_category+"]");
var to_hide = this.resources().filter("[data-category!="+this.selected_category+"]"); var to_hide = this.resources().filter("[data-category!="+this.selected_category+"]");
if (!this.selected_category) { to_show = this.resources(); } if (!this.selected_category) { to_show = this.resources(); }
_.each(to_hide, function(el){ _.each(to_hide, function(el){
$(el).hide('slow'); $(el).hide('slow');
}); });
_.each(to_show, function(el, i){ _.each(to_show, function(el, i){
$(el).fadeIn(40); $(el).fadeIn(40);
}); });
} }
$(document).ready(function(){ $(document).ready(function(){
var rm = new ResourcesModule($("#resources-list"), {}, []); var rm = new ResourcesModule($("#resources-list"), {}, []);
window.rm = rm; window.rm = rm;
}) })
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment