(function() { var $ajax, $blocks, $current_showing, $filter_links, $foto, $initial, $interior, TO, all, and_or, any, block_data, blur_unblur, categories, current_overlay, enter_fullscreen, fotorama, fullscreen_open, get_top_offset, home_page, id_to_pos, is_mobile, is_one_column, mobile, on_resize, one_column, overlay_showing, parse_query_string, pos_to_elem, pos_to_id, prev_next, project_requested, selected_block, show_ajax, switch_link, text_data, three_column, toggle_ajax, toggle_blur_active, two_column, indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; $filter_links = null; $blocks = null; $initial = true; $ajax = null; $interior = null; categories = {}; is_mobile = false; is_one_column = false; TO = false; home_page = true; overlay_showing = false; $foto = null; fotorama = null; current_overlay = false; selected_block = false; block_data = {}; text_data = {}; pos_to_id = {}; id_to_pos = {}; fullscreen_open = false; $current_showing = null; pos_to_elem = {}; fullscreen_open = false; toggle_blur_active = function(obj, to_add, to_remove) { obj.removeClass(to_remove); if (!obj.hasClass(to_add)) { return obj.addClass(to_add); } }; toggle_ajax = function(obj) { if (obj == null) { obj = null; } if (overlay_showing) { if (one_column()) { $ajax.after(selected_block); } $ajax.hide(); } else { $ajax.show(); } return !overlay_showing; }; and_or = function(is_and) { $blocks.each(function(index) { var key, matching_cats, val; matching_cats = (function() { var results; results = []; for (key in categories) { val = categories[key]; if (val) { results.push($(this).hasClass(key)); } } return results; }).call(this); if ((is_and && all(matching_cats)) || (!is_and && any(matching_cats))) { toggle_blur_active($(this), 'active', 'blur'); } else { toggle_blur_active($(this), 'blur', 'active'); } return true; }); return true; }; any = function(array) { return indexOf.call(array, true) >= 0; }; all = function(array) { return indexOf.call(array, false) < 0; }; one_column = function() { return Modernizr.mq('(max-width: 480px)'); }; mobile = function() { return Modernizr.mq('(max-width: 768px)'); }; two_column = function() { return Modernizr.mq('(max-width: 1140px)'); }; three_column = function() { return Modernizr.mq('(min-width: 1140px)'); }; blur_unblur = function() { var any_selected, key, val; any_selected = any((function() { var results; results = []; for (key in categories) { val = categories[key]; results.push(val); } return results; })()); if (any_selected) { return and_or($('#and').hasClass('active')); } else { $blocks.removeClass('blur'); return $blocks.removeClass('active'); } }; switch_link = function(obj, category_name) { obj.toggleClass('active'); categories[category_name] = obj.hasClass('active'); return blur_unblur(); }; parse_query_string = function() { var base, cat, category_keys, category_name, i, len, project, query, requested; category_keys = []; $('#categories li').each(function(index) { var category; category = $(this).text().substring(2); categories[category] = false; category_keys.push(category); return true; }); if (home_page) { base = ""; } else { base = window.location.href.split("/filter/"); base = base.length > 1 ? base[1] : void 0; } query = window.location.search.length ? window.location.search.substring(1) : ""; if ((query.indexOf("-")) !== -1) { requested = (function() { var i, len, ref, ref1, results; ref = query.split('-'); results = []; for (i = 0, len = ref.length; i < len; i++) { cat = ref[i]; if (ref1 = cat.toLowerCase(), indexOf.call(category_keys, ref1) >= 0) { results.push(cat); } } return results; })(); } else if ((query.indexOf("+")) !== -1) { $('#and').toggleClass('active'); $('#or').toggleClass('active'); requested = (function() { var i, len, ref, ref1, results; ref = query.split('+'); results = []; for (i = 0, len = ref.length; i < len; i++) { cat = ref[i]; if (ref1 = cat.toLowerCase(), indexOf.call(category_keys, ref1) >= 0) { results.push(cat); } } return results; })(); } else { requested = indexOf.call(category_keys, query) >= 0 ? [query] : []; } for (i = 0, len = requested.length; i < len; i++) { category_name = requested[i]; switch_link($('#' + category_name), category_name); } project = window.location.hash.length ? $(window.location.hash) : false; if (project.length > 0) { window.scroll(0, project.scrollTop()); overlay_showing = toggle_ajax(project); $current_showing = project; return project_requested(project); } else { return window.location.hash = ''; } }; get_top_offset = function(obj) { var fixed_top, isCSS1Compat, supportPageOffset, y; supportPageOffset = window.pageXOffset !== void 0; isCSS1Compat = document.compatMode === "CSS1Compat"; y = supportPageOffset ? window.pageYOffset : isCSS1Compat ? document.documentElement.scrollTop : document.body.scrollTop; fixed_top = $('#fixed-top').height(); if (is_mobile && document.body.clientWidth < 480) { if (y < fixed_top) { console.log("smallest and " + fixed_top); return fixed_top; } else { console.log("smallest and " + fixed_top + " + " + y); return fixed_top + y; } } else { if (y < obj.parent().offset().top) { return 0; } else if (is_mobile) { return fixed_top + y - obj.parent().offset().top; } else { return y - obj.parent().offset().top; } } }; show_ajax = function(obj) { var $visi_blocks, columns, id, last, position; id = obj.attr('id'); while (fotorama.size > 0) { fotorama.pop(); } fotorama.load(block_data[id]); if (current_overlay) { text_data[current_overlay] = $("#interior h3, #interior #medium, #interior #description, #interior #tech").detach(); } if ($ajax.hasClass(id)) { $interior.append(text_data[id]); } else { $.ajax({ url: "/projects/" + id + ".html", dataType: 'html', success: function(data, txt, xhr) { var response; response = $('').html(data); $interior.append(response.find(".exterior h3")); $interior.append(response.find(".exterior #medium")); $interior.append(response.find(".exterior #description")); $interior.append(response.find(".exterior #tech")); return $ajax.addClass(id); } }); } position = parseInt($current_showing.attr('data-pos')); if (!position) { throw "position is Nan"; } last = position === $blocks.size(); columns = one_column() ? 1 : two_column() ? 2 : 3; $visi_blocks = $('.block:visible'); console.log('position: ' + position); console.log('columns: ' + columns); if (columns === 2 && $visi_blocks.size() < $blocks.size()) { position = $visi_blocks.index(obj) + 1; last = position === $visi_blocks.size(); if (!(position % 2 === 0 || last)) { $current_showing.nextAll('.block:visible').first().after($ajax); } } else if (columns === 1 || (columns === 2 && position % 2 === 0) || (columns === 3 && position % 3 === 0) || last) { $current_showing.after($ajax); } else if (columns === 2 || (columns === 3 && position % 3 === 2)) { $current_showing.next().after($ajax); } else { $current_showing.next().next().after($ajax); } window.location.hash = '#project=' + id; $ajax.show(); return id; }; enter_fullscreen = function() { return fotorama.requestFullScreen(); }; project_requested = function(obj) { var error, error1; try { current_overlay = show_ajax(obj); } catch (error1) { error = error1; console.log('error caught: ' + error); overlay_showing = toggle_ajax(); } return $(window).resize(); }; prev_next = function(which) { var $target, error, error1, target_id, temp; try { temp = pos_to_id[id_to_pos[current_overlay]][which]; target_id = pos_to_id[temp]['id']; $target = $('#' + target_id); console.log(which + ' called ' + target_id); return project_requested($target); } catch (error1) { error = error1; return overlay_showing = toggle_ajax(); } }; on_resize = function() { is_mobile = mobile(); return is_one_column = one_column(); }; $(window).resize(function() { if (TO) { clearTimeout(TO); } return TO = setTimeout(on_resize, 200); }); $(document).mouseup(function(e) { if ($(e.target).hasClass('block')) { if (!overlay_showing) { current_overlay = show_ajax($(e.target)); } else { console.log('already open'); } } else if (overlay_showing && !$ajax.is(e.target) && $ajax.has(e.target).length === 0) { overlay_showing = toggle_ajax(); } }); $('.block').click(function() { overlay_showing = toggle_ajax($(this)); $current_showing = $(this); return project_requested($(this)); }); $('#prev-ajax').click(function() { return prev_next('prev'); }); $('#next-ajax').click(function() { return prev_next('next'); }); $('#close-ajax').click(function() { return overlay_showing = toggle_ajax(); }); $('#and, #or').click(function() { $('#or, #and').toggleClass('active'); return blur_unblur(); }); $("#categories li a").click(function() { var category_name, key, val; category_name = $(this).parent().attr('id'); if (is_mobile) { categories = (function() { var results; results = []; for (key in categories) { val = categories[key]; results.push(key[false]); } return results; })(); categories[category_name] = true; console.log(categories); return and_or(false); } else { return switch_link($(this).parent(), category_name); } }); $(function() { is_mobile = mobile(); is_one_column = one_column(); home_page = window.location.pathname === "/"; $blocks = $('.block'); $ajax = $('#ajax'); $interior = $('#interior'); $('.block a').each(function(index) { var data, id, parent, pos; parent = $(this).parent(); $(this).replaceWith($(this).children()); id = parent.attr('id'); block_data[id] = []; pos = parseInt(parent.attr('data-pos')); id_to_pos[id] = pos; data = { 'id': id, 'prev': parseInt(parent.attr('data-prev')), 'next': parseInt(parent.attr('data-next')) }; return pos_to_id[pos] = data; }); $('#fotorama a').each(function(index) { var id, type; id = $(this).attr('class'); type = $(this).attr('data-type'); if (type === 'video') { block_data[id].push({ video: $(this).attr('href') }); } else { block_data[id].push({ img: $(this).attr('href'), full: $(this).attr('data-full'), caption: $(this).attr('data-caption') ? $(this).attr('data-caption') : '' }); } return true; }); $('#fotorama img').each(function(index) { var caption, url; url = $(this).attr('src'); caption = $(this).attr('data-caption') ? $(this).attr('data-caption') : ''; $(this).replaceWith(""); return true; }); $('#fotorama iframe').each(function(index) { var url; url = $(this).attr('alt'); return $(this).replaceWith(""); }); $('#fotorama').on('fotorama:show ' + 'fotorama:fullscreenenter ' + 'fotorama:fullscreenexit', function(e, fotorama, extra) { if (e.type === 'fotorama:fullscreenenter') { fullscreen_open = true; } if (e.type === 'fotorama:fullscreenexit') { return fullscreen_open = false; } }); $foto = $('#fotorama').fotorama(); fotorama = $foto.data('fotorama'); $ajax.css('position', 'relative'); $ajax.css('left', 0); $ajax.hide(); $filter_links = $("#categories li a"); if (home_page) { $filter_links.removeAttr('href'); fotorama.destroy(); } else { $('#and').hide(); $('#or').hide(); $filter_links.each(function(index) { var base, category_name; category_name = $(this).parent().attr('id'); base = window.location.origin; $(this).attr('href', base + "?" + category_name); return true; }); } return parse_query_string(); }); }).call(this);