<commit_before>/*
    Copyright 2012 UW Information Technology, University of Washington

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    Changes
    =================================================================

    <EMAIL>: attr(checked) to prop(checked); open_anytime
      option.
    <EMAIL>: cleanup of obvious bugs highighted by JSHint.
    <EMAIL>: added events to handle custom filter options;
      removed open_anytime and used the events instead.
*/

var spacescout_map = null, spacescout_markers = [], speed = 800, update_count = null;

// H = Handlebars, $ = jQuery, GM = google.maps
(function (H, $, GM) {
    var spacescout_marker_ids = {};
    // var mc = null;
    var youarehere = null;

    function openAllMarkerInfoWindow(data) {
        var source = $('#all_markers').html();
        var template = H.compile(source);
        data = buildingNameHeaders(data);
        $('#info_items').html(template({'data': data}));
        $('.loading').slideUp('fast');

        // load and update favorites
        if ($(window.spacescout_favorites.k.favorites_count_container).length == 1) {
            window.spacescout_favorites.load();

            if (window.hasOwnProperty('spacescout_favorites_refresh')
                && window.spacescout_favorites_refresh) {
                window.clearInterval(window.spacescout_favorites_refresh);
                window.spacescout_favorites_refresh = null;
            }

            // refresh favorites favorite cues every 10 seconds
            window.spacescout_favorites_refresh = window.setInterval(function () {
                window.spacescout_favorites.load();
            }, 10000);
        }

        //_lazyLoadSpaceImages();

        $(document).ready(function () {
            if ($.cookie('spot_id')) {
                var $spot = $('#' + $.cookie('spot_id'));
                var scroll_spot_id = null;

                if ($spot.parent().prev().prev().children()[1]) { // for normal case when there are two before clicked in ol
                    scroll_spot_id = $spot.parent().prev().prev().children()[1].id;
                } else if ($spot.parent().parent().prev().prev()[0]) { // if there is an ol before the current one
                    if (!$spot.parent().prev()[0] || !$spot.parent().prev().prev()[0]) { // if there are two or less spots before the one clicked in the current ol
                        scroll_spot_id = $spot.parent().parent().prev().prev().children().children().last()[0].id;
                    }
                }
                if (scroll_spot_id) {
                    document.getElementById(scroll_spot_id).scrollIntoView();
                }
                $spot.click();
                $.removeCookie('spot_id');
            }
            // LazyLoading the spot images
            var lazyload_target = isMobile ? window : '#info_list';
            $(lazyload_target).lazyScrollLoading({
                lazyItemSelector : ".lazyloader",
                onLazyItemFirstVisible : function (e, $lazyItems, $firstVisibleLazyItems) {
                    $firstVisibleLazyItems.each(function () {
                        var $img = $(this);
                        var src = $img.data('src');
                        $img.css('background', 'transparent url("'+src+'") no-repeat 50% 50%');
                    });
               }
            });
        });
    }

    window.openAllMarkerInfoWindow = openAllMarkerInfoWindow;

    function _sortByBuildingName(data) {
        data.sort(function (one, two) {
            var abuilding = one.location.building_name.toLowerCase(), bbuilding = two.location.building_name.toLowerCase();
            if (abuilding < bbuilding)
                return -1;
            if (abuilding > bbuilding)
                return 1;
            return 0;
        });
        return data;
    }

    function buildingNameHeaders(data) {
        data = _sortByBuildingName(data);

        var byBuilding = {};
        var nobuilding = 'no building';
        for (var i = 0; i < data.length; i++) {
            var bname = data[i].location.building_name;
            if (bname === null) {
                if (!byBuilding.hasOwnProperty(nobuilding)) {
                    byBuilding[nobuilding] = [data[i]];
                }
                byBuilding[nobuilding].push(data[i]);
            } else {
                if (!byBuilding.hasOwnProperty(bname)) {
                    byBuilding[bname] = [data[i]];
                } else {
                    byBuilding[bname].push(data[i]);
                }
            }
        }

        var result = [];
        for (var bname in byBuilding) {
            if (byBuilding.hasOwnProperty(bname)) {
                result.push({
                    name: bname,
                    spots: byBuilding[bname]
                });
            }
        }
        return result;
    }
    window.buildingNameHeaders = buildingNameHeaders;

    // jquery function to check if scrollable
    $.fn.hasScrollBar = function() {
        return this.get(0).scrollHeight > this.height();
    };

    function _lazyLoadSpaceImages() {
        // container lazy loading for desktop ui
        if ($('#info_list').hasScrollBar()) {
            $("img.lazy").lazyload({
                 container: $("#info_list")
             });
        } else { //mobile ui
            $("img.lazy").lazyload();
        }
    }

    function repopulate_filters(form_opts) {
        try {
            if (form_opts) {
                // set types
                if (form_opts.hasOwnProperty('type')) {
                    $.each(form_opts["type"], function () {
                        $('#'+this).prop('checked', true);
                    });
                }
            }

            // set reservability
            if (form_opts["extended_info:reservable"]) {
                $('#reservable').prop('checked', true);
            }
            // TODO: CHANGE FROM DOT NOTATION TO SQUARE BRACKETS
            // set capacity
            $('#capacity').val(form_opts.capacity);

            // set hours
            if (form_opts.open_at || form_opts.open_until) {
                $('#hours_list_input').prop('checked', true);
                $('#hours_list_container').show();
                var day, time, ampm, open_parts;<commit_msg>Fill the filters with cap=1 if capactiy in url is not a number.<commit_after>/*
    Copyright 2012 UW Information Technology, University of Washington

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    Changes
    =================================================================

    <EMAIL>: attr(checked) to prop(checked); open_anytime
      option.
    <EMAIL>: cleanup of obvious bugs highighted by JSHint.
    <EMAIL>: added events to handle custom filter options;
      removed open_anytime and used the events instead.
*/

var spacescout_map = null, spacescout_markers = [], speed = 800, update_count = null;

// H = Handlebars, $ = jQuery, GM = google.maps
(function (H, $, GM) {
    var spacescout_marker_ids = {};
    // var mc = null;
    var youarehere = null;

    function openAllMarkerInfoWindow(data) {
        var source = $('#all_markers').html();
        var template = H.compile(source);
        data = buildingNameHeaders(data);
        $('#info_items').html(template({'data': data}));
        $('.loading').slideUp('fast');

        // load and update favorites
        if ($(window.spacescout_favorites.k.favorites_count_container).length == 1) {
            window.spacescout_favorites.load();

            if (window.hasOwnProperty('spacescout_favorites_refresh')
                && window.spacescout_favorites_refresh) {
                window.clearInterval(window.spacescout_favorites_refresh);
                window.spacescout_favorites_refresh = null;
            }

            // refresh favorites favorite cues every 10 seconds
            window.spacescout_favorites_refresh = window.setInterval(function () {
                window.spacescout_favorites.load();
            }, 10000);
        }

        //_lazyLoadSpaceImages();

        $(document).ready(function () {
            if ($.cookie('spot_id')) {
                var $spot = $('#' + $.cookie('spot_id'));
                var scroll_spot_id = null;

                if ($spot.parent().prev().prev().children()[1]) { // for normal case when there are two before clicked in ol
                    scroll_spot_id = $spot.parent().prev().prev().children()[1].id;
                } else if ($spot.parent().parent().prev().prev()[0]) { // if there is an ol before the current one
                    if (!$spot.parent().prev()[0] || !$spot.parent().prev().prev()[0]) { // if there are two or less spots before the one clicked in the current ol
                        scroll_spot_id = $spot.parent().parent().prev().prev().children().children().last()[0].id;
                    }
                }
                if (scroll_spot_id) {
                    document.getElementById(scroll_spot_id).scrollIntoView();
                }
                $spot.click();
                $.removeCookie('spot_id');
            }
            // LazyLoading the spot images
            var lazyload_target = isMobile ? window : '#info_list';
            $(lazyload_target).lazyScrollLoading({
                lazyItemSelector : ".lazyloader",
                onLazyItemFirstVisible : function (e, $lazyItems, $firstVisibleLazyItems) {
                    $firstVisibleLazyItems.each(function () {
                        var $img = $(this);
                        var src = $img.data('src');
                        $img.css('background', 'transparent url("'+src+'") no-repeat 50% 50%');
                    });
               }
            });
        });
    }

    window.openAllMarkerInfoWindow = openAllMarkerInfoWindow;

    function _sortByBuildingName(data) {
        data.sort(function (one, two) {
            var abuilding = one.location.building_name.toLowerCase(), bbuilding = two.location.building_name.toLowerCase();
            if (abuilding < bbuilding)
                return -1;
            if (abuilding > bbuilding)
                return 1;
            return 0;
        });
        return data;
    }

    function buildingNameHeaders(data) {
        data = _sortByBuildingName(data);

        var byBuilding = {};
        var nobuilding = 'no building';
        for (var i = 0; i < data.length; i++) {
            var bname = data[i].location.building_name;
            if (bname === null) {
                if (!byBuilding.hasOwnProperty(nobuilding)) {
                    byBuilding[nobuilding] = [data[i]];
                }
                byBuilding[nobuilding].push(data[i]);
            } else {
                if (!byBuilding.hasOwnProperty(bname)) {
                    byBuilding[bname] = [data[i]];
                } else {
                    byBuilding[bname].push(data[i]);
                }
            }
        }

        var result = [];
        for (var bname in byBuilding) {
            if (byBuilding.hasOwnProperty(bname)) {
                result.push({
                    name: bname,
                    spots: byBuilding[bname]
                });
            }
        }
        return result;
    }
    window.buildingNameHeaders = buildingNameHeaders;

    // jquery function to check if scrollable
    $.fn.hasScrollBar = function() {
        return this.get(0).scrollHeight > this.height();
    };

    function _lazyLoadSpaceImages() {
        // container lazy loading for desktop ui
        if ($('#info_list').hasScrollBar()) {
            $("img.lazy").lazyload({
                 container: $("#info_list")
             });
        } else { //mobile ui
            $("img.lazy").lazyload();
        }
    }

    function repopulate_filters(form_opts) {
        try {
            if (form_opts) {
                // set types
                if (form_opts.hasOwnProperty('type')) {
                    $.each(form_opts["type"], function () {
                        $('#'+this).prop('checked', true);
                    });
                }
            }

            // set reservability
            if (form_opts["extended_info:reservable"]) {
                $('#reservable').prop('checked', true);
            }
            // TODO: CHANGE FROM DOT NOTATION TO SQUARE BRACKETS
            // set capacity
            if (isNaN(form_opts.capacity)) {
                $('#capacity').val(1);
            } else {
                $('#capacity').val(form_opts.capacity);
            }

            // set hours
            if (form_opts.open_at || form_opts.open_until) {
                $('#hours_list_input').prop('checked', true);
                $('#hours_list_container').show();
                var day, time, ampm, open_parts;
{'fraction_non_alphanumeric': 0.12913739407546895, 'fraction_numerical': 0.0050698920837256465, 'mean_word_length': 1.7649179014817782, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4872778', 'n_tokens_mistral': 3738, 'n_tokens_neox': 3533, 'n_words': 857}