{"size": 4358, "ext": "js", "max_stars_repo_path": "src/Jam/WebBundle/Resources/public/js/helpers.js", "max_stars_repo_name": "sloba88/jamwithme", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/Jam/WebBundle/Resources/public/js/helpers.js", "max_issues_repo_name": "sloba88/jamwithme", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/Jam/WebBundle/Resources/public/js/helpers.js", "max_forks_repo_name": "sloba88/jamwithme", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.4088050314, "max_line_length": 86, "alphanum_fraction": 0.5479577788}
'use strict';

/* global Routing */

function showError(error) {
    switch(error.code)
    {
        //TODO: log these server side also
        case error.PERMISSION_DENIED:
            console.log('User denied the request for Geolocation.');
            break;
        case error.POSITION_UNAVAILABLE:
            console.log('Location information is unavailable.');
            break;
        case error.TIMEOUT:
            console.log('The request to get user location timed out.');
            break;
        case error.UNKNOWN_ERROR:
            console.log('An unknown error occurred.');
            break;
    }
}

function getLocation(callback){
    if (navigator.geolocation){
        navigator.geolocation.getCurrentPosition(function(position) {
            return callback([position.coords.latitude, position.coords.longitude]);
        }, showError);
        return callback(false);
    }else{
        alert('Geolocation is not supported by this browser.');
        return callback(false);
    }
}

window.onerror = function(message, url, lineNumber) {
    //save error and send to server
    $.ajax({
        url: Routing.generate('api_js_error_report'),
        type: 'POST',
        data: { 'message': message, 'url': url, 'lineNumber': lineNumber }
    }).done(function( result ) {
        console.log(result);
    });
};

function addMessage(type, message, temp) {
    if ($('.fixed-alerts-container .alert').length > 4) {
        return false;
    }

    if (typeof temp == 'undefined') {
        temp = 'temp';
    } else {
        temp = '';
    }

    if (type === false) {
        type = 'danger';
    }

    var notification = $('<div/>').html(window.JST.notificationTemplate({
        type: type,
        message: message,
        temp: temp
    })).contents();

    $('.fixed-alerts-container').prepend(notification);
    setTimeout(function() {
        notification.alert('close');
    }, 4000);

    return true;
}

function matchStart(term, text) {
    return text.toUpperCase().indexOf(term.toUpperCase())===0;
}

if ($.fn.select2) {
    $.fn.select2.defaults.set('containerCssClass', 'form-control');
}

function oldMatcher (matcher) {
    function wrappedMatcher (params, data) {
        var match = $.extend(true, {}, data);

        if (params.term === null || $.trim(params.term) === '') {
            return match;
        }

        if (data.children) {
            for (var c = data.children.length - 1; c >= 0; c--) {
                var child = data.children[c];

                // Check if the child object matches
                // The old matcher returned a boolean true or false
                var doesMatch = matcher(params.term, child.text, child);

                // If the child didn't match, pop it off
                if (!doesMatch) {
                    match.children.splice(c, 1);
                }
            }

            if (match.children.length > 0) {
                return match;
            }
        }

        if (matcher(params.term, data.text, data)) {
            return match;
        }

        return null;
    }

    return wrappedMatcher;
}

function getParameterByName(name) {
    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'),
        results = regex.exec(location.search);
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}

var delay = (function(){
    var timer = 0;
    return function(callback, ms){
        clearTimeout (timer);
        timer = setTimeout(callback, ms);
    };
})();

$(function() {
    $(document).on('click', '.action-confirm', function(e){
        e.stopImmediatePropagation();
        e.stopPropagation();
        e.preventDefault();
        var self = $(this);

        //programatically create a modal
        $('body').append(window.JST.actionConfirmModalTemplate({
            message: 'Are you sure that you want to remove this?'
        }));

        $('#actionConfirmModal').modal();

        $('#actionConfirmModal').on('click', '.action-confirm-ok', function() {
            self.removeClass('action-confirm').trigger('click');
            $('#actionConfirmModal').modal('hide');
        });

        $('#actionConfirmModal').on('hidden.bs.modal', function () {
            $('#actionConfirmModal').remove();
        });
    });
});