while ($r = $q->fetch()) {
- if ($r->id != $currentStudie->id) {
+ if (null === $currentStudie || $r->id != $currentStudie->id) {
$r = CubeIT_Util_Cms::unserialize($r);
$r->point = 0;
} else if ($r->point > $listStudies[2]->point) {
$listStudies[2] = $r;
} else {
-
+
}
}
foreach ($listStudies as $i => $s) {
- $res.=$this->_case($s, $i);
+ $res.=$this->_case($s);
}
}
return $res;
}
- protected function _case($s, $i) {
+ protected function _case($s) {
$addOffline = '';
/* if ($acl && $s->online == 0) {
$c.= '<h2>' . $s->titre . '</h2>';
$c.='<h3>' . $s->description . '</h3>';
- $class = array();
- if ($i % 3 == 2) {
- $class[] = 'last';
- }
-
- return $this->link($c, $url, array('data-cat' => $s->categories, 'class' => $class));
+ return $this->link($c, $url, array('data-cat' => $s->categories));
}
}
this.storageID = $(element).parent().attr('id') + '-filter';
this.element = element;
- this.perline = parseInt(this.element.data('perline'));
+ this.columnWidth = parseInt(this.element.data('column-width'));
+ this.gutter = parseInt(this.element.data('gutter'));
this.list = $(this.element.data('list'));
+ this.container = $(this.list);
+ // Store font size for headings - used to scale fonts in resize function
+ this.headingSize = parseInt($(this.container).find('h2').css('font-size'));
+
+ // Persist filter settings
var initFilter = 0;
if (Modernizr.sessionstorage) {
var f = sessionStorage.getItem(this.storageID);
JQtaglist.prototype = {
init: function (initFilter) {
var $this = this;
- this.element.on('click', "li[data-id]", function () {
- var id = $(this).data('id');
- $this.filter(id);
+ // Run filter based on any previous settings
+ $this.filter(initFilter);
+
+ // Set up Isotope
+ this.container.isotope({
+ itemSelector: 'a',
+ layoutMode: 'masonry',
+ masonry: {
+ columnWidth: this.columnWidth,
+ gutter: this.gutter
+ },
+ animationOptions: {
+ duration: 750,
+ easing: 'linear',
+ queue: false
+ }
+ // hiddenStyle: {
+ // opacity: 0,
+ // transform: 'scale(2)'
+ // },
+ // visibleStyle: {
+ // opacity: 1,
+ // transform: 'scale(1)'
+ // }
+ });
+
+ // Also handle resizing of the window
+ $(window).on('cubeitresize', function () {
+ $this.resize();
+ });
+ $this.resize();
+ window.setTimeout(function () {
+ $this.resize();
+ }, 500);
+
+ // Make sure grid is sized properly once page has loaded fully
+ $(window).load(function () {
+ $this.resize();
+ });
+
+
+ // Set up filter buttons
+ $('.tags li').click(function () {
+ $('.tags li.active').removeClass('active');
+ $(this).addClass('active');
+
+ var filterID = $(this).data('id');
+
+ $this.filter(filterID);
return false;
});
- $this.filter(initFilter);
+
},
filter: function (id) {
- var $this = this;
- this.list.find('[data-cat]:hidden').show().removeClass('last');
- if (id != 0) {
- this.list.find('[data-cat][data-cat!="' + id + '"]').hide();
- }
- this.element.find('[data-id]').removeClass('active');
+ //fb('Filter ID: ' + id);
+
+ // Select button
+ this.element.find('.active').removeClass('active');
this.element.find('[data-id="' + id + '"]').addClass('active');
- this.updateMargins();
- setTimeout(function () {
- $this.updateMargins();
- }, 500);
+ var filterClass;
+ if (id == 0) {
+ filterClass = '*';
+ } else {
+ filterClass = '[data-cat="' + id + '"]';
+ }
+
+ //fb('Filtering... ' + filterClass);
+ this.container.isotope({
+ filter: filterClass
+ });
+
+ // Save filter for future sessions
if (Modernizr.sessionstorage) {
sessionStorage.setItem(this.storageID, id);
}
},
- updateMargins: function () {
- var i = 1;
- var $this = this;
+ resize: function () {
+
+ fb('Running resize...');
+
+ var container = this.container
+ var margin = this.gutter;
+ var naturalWidth = this.columnWidth;
+ var scaleFactor = 1;
+
+ var ww = Math.min($(window).width(), 980);
+
+ // Handle extra padding that is added for small screens
+ if ($('html').hasClass('small')) {
+ //ww = ww - parseInt($('#main .content').css('paddingLeft')) - parseInt($('#main .content').css('paddingRight'));
+ ww = ww - 40;
+ }
- this.list.find('[data-cat]:visible').each(function () {
- if (i % $this.perline == 0) {
- $(this).addClass('last');
- } else {
- $(this).removeClass('last');
+ var nbcol = Math.ceil(ww / (naturalWidth + margin));
+ var ew = Math.floor((ww - (margin * (nbcol - 1))) / nbcol);
+ if (ew > naturalWidth) {
+ nbcol++; // Add a column when elements are too big
+ ew = Math.floor((ww - (margin * (nbcol - 1))) / nbcol);
+ }
+
+ // Dynamically size text based on element width
+ if (ew < naturalWidth) {
+ scaleFactor = ew / naturalWidth;
+ $(container).find('h2').css('font-size', Math.ceil(scaleFactor * this.headingSize));
+ }
+
+ // Resize elements
+ var a = $(container).find('a');
+ $(a).css('width', ew);
+ var naturalHeight = $(a).find('img').attr('height');
+ var imageRatio = naturalWidth / naturalHeight;
+ $(a).find('img').css({width: ew, height: ew / imageRatio});
+
+ // Reset isotope grid
+ $(container).isotope({
+ masonry: {
+ columnWidth: ew,
+ gutter: margin
}
- i++;
});
+
}
+
};
jQuery.fn.taglist = function () {
registerLoader(load_taglist);
function load_taglist() {
+
+ $('#main').css('overflow-y', 'hidden'); // Stops extra scrollbars appearing
+
$('ul.tags').taglist();
}
\ No newline at end of file