<commit_before>$(document).ready(function() {
   var mapControl = L.map('map');
   var trackLayer; // Map layer which glider's track will be drawn onto
   var mapQuestAttribution = ' | Tiles Courtesy of MapQuest ';
   var osmLayer = L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg', {
                                   attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA'
                                                + mapQuestAttribution,
                                   maxZoom: 18
                            }).addTo(mapControl);

   var photoLayer = L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg', {
                                   attribution: 'Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency'
                                                + mapQuestAttribution,
                                   maxZoom: 11
                                });

   var baseLayers = {
       'MapQuest OpenStreetMap': osmLayer,
       'MapQuest Open Aerial (Photo)': photoLayer
   };

   L.control.layers(baseLayers).addTo(mapControl);

   $('#fileControl').change(function() {
      if (this.files.length > 0) {
	      var reader = new FileReader();
		  reader.onload = function(e) {
		      try {
			     $('#errorMessage').text('');
				 if (trackLayer) {
				    mapControl.removeLayer(trackLayer);
				 }

		         var model = parseIGC(this.result);

                 // Display the headers.
                 var headerTable = $('#headerInfo tbody');
                 headerTable.html('');
                 var headerName;
                 for (headerName in model.headers) {
                    headerTable.append(
                        $('

').append($('	').text(headerName))
                                      .append($('	').text(model.headers[headerName]))
                    );
                 }

                 // Set up the barogram.
				 var nPoints = model.recordTime.length;
				 var pressureBarogramData = [];
				 var gpsBarogramData = [];
				 var j;
				 var timestamp;
				 for (j = 0; j < nPoints; j++) {
				     timestamp = model.recordTime[j].getTime();
				     pressureBarogramData.push([timestamp, model.pressureAltitude[j]]);
                     gpsBarogramData.push([timestamp, model.gpsAltitude[j]]);
				 }

                 // Draw the map.
                 var trackLine = L.polyline(model.latLong, {color: 'red'});
				 trackLayer = L.layerGroup([
                     trackLine,
                     L.marker(model.latLong[0]).bindPopup('Takeoff'),
                     L.marker(model.latLong[model.latLong.length - 1]).bindPopup('Landing')
				 ]).addTo(mapControl);

				 // Reveal the map and graph. We have to do this before
                 // setting the zoom level of the map or ploting the graph.
                 $('#igcFileDisplay').show();
                 mapControl.fitBounds(trackLine.getBounds());

				 $('#barograph').plot([{
					label: 'Pressure altitude',
					data: pressureBarogramData}, {
					label: 'GPS altitude',
				    data: gpsBarogramData}], {
					 axisLabels: {
					    show: true
					 },
				     xaxis: {
						mode: 'time',
                        timeformat: '%H:%M',
						axisLabel: 'Time (UTC)'
                     },
					 yaxis: {
					    axisLabel: 'Altitude / metres'
					 }
				 });
			  } catch (e) {
			    if (e instanceof IGCException) {
				    $('#errorMessage').text(e.message);
				}
				else {
				    throw e;
				}
			  }
		  };
		  reader.readAsText(this.files[0]);
	  }
   });
});
<commit_msg>Show distance scale.<commit_after>$(document).ready(function() {
   var mapControl = L.map('map');
   var trackLayer; // Map layer which glider's track will be drawn onto
   var mapQuestAttribution = ' | Tiles Courtesy of MapQuest ';
   var osmLayer = L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg', {
                                   attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA'
                                                + mapQuestAttribution,
                                   maxZoom: 18
                            }).addTo(mapControl);

   var photoLayer = L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg', {
                                   attribution: 'Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency'
                                                + mapQuestAttribution,
                                   maxZoom: 11
                                });

   var baseLayers = {
       'MapQuest OpenStreetMap': osmLayer,
       'MapQuest Open Aerial (Photo)': photoLayer
   };

   L.control.layers(baseLayers).addTo(mapControl);
   L.control.scale().addTo(mapControl);

   $('#fileControl').change(function() {
      if (this.files.length > 0) {
	      var reader = new FileReader();
		  reader.onload = function(e) {
		      try {
			     $('#errorMessage').text('');
				 if (trackLayer) {
				    mapControl.removeLayer(trackLayer);
				 }

		         var model = parseIGC(this.result);

                 // Display the headers.
                 var headerTable = $('#headerInfo tbody');
                 headerTable.html('');
                 var headerName;
                 for (headerName in model.headers) {
                    headerTable.append(
                        $('

').append($('	').text(headerName))
                                      .append($('	').text(model.headers[headerName]))
                    );
                 }

                 // Set up the barogram.
				 var nPoints = model.recordTime.length;
				 var pressureBarogramData = [];
				 var gpsBarogramData = [];
				 var j;
				 var timestamp;
				 for (j = 0; j < nPoints; j++) {
				     timestamp = model.recordTime[j].getTime();
				     pressureBarogramData.push([timestamp, model.pressureAltitude[j]]);
                     gpsBarogramData.push([timestamp, model.gpsAltitude[j]]);
				 }

                 // Draw the map.
                 var trackLine = L.polyline(model.latLong, {color: 'red'});
				 trackLayer = L.layerGroup([
                     trackLine,
                     L.marker(model.latLong[0]).bindPopup('Takeoff'),
                     L.marker(model.latLong[model.latLong.length - 1]).bindPopup('Landing')
				 ]).addTo(mapControl);

				 // Reveal the map and graph. We have to do this before
                 // setting the zoom level of the map or ploting the graph.
                 $('#igcFileDisplay').show();
                 mapControl.fitBounds(trackLine.getBounds());

				 $('#barograph').plot([{
					label: 'Pressure altitude',
					data: pressureBarogramData}, {
					label: 'GPS altitude',
				    data: gpsBarogramData}], {
					 axisLabels: {
					    show: true
					 },
				     xaxis: {
						mode: 'time',
                        timeformat: '%H:%M',
						axisLabel: 'Time (UTC)'
                     },
					 yaxis: {
					    axisLabel: 'Altitude / metres'
					 }
				 });
			  } catch (e) {
			    if (e instanceof IGCException) {
				    $('#errorMessage').text(e.message);
				}
				else {
				    throw e;
				}
			  }
		  };
		  reader.readAsText(this.files[0]);
	  }
   });
});
<|endoftext|>


<commit_before>'use strict';

function recreate_waves(){
    // Generate and display wave HTML.
    var loop_counter = parseInt(document.getElementById('wave-count').value) - 1;
    var wave_html = '';
    do{
        wave_html += '

';
    }while(loop_counter--);
    document.getElementById('waves').innerHTML = wave_html;

    // Set orientation CSS.
    loop_counter = parseInt(document.getElementById('wave-count').value) - 1;
    if(document.getElementById('orientation').value == 1){
        // Vertical orientation.
        do{
            document.getElementById(loop_counter).style.display = 'inline-block';
            document.getElementById(loop_counter).style.height = '420px';
            document.getElementById(loop_counter).style.width = '42px';
        }while(loop_counter--);

    }else{
        // Horizontal orientation.
        do{
            document.getElementById(loop_counter).style.display = 'block';
            document.getElementById(loop_counter).style.height = '42px';
            document.getElementById(loop_counter).style.width = '100%';
        }while(loop_counter--);
    }

    // Update waves.
    update_waves();
}

function pause(new_pause_state){
    window.clearInterval(timer);

    pause_state = new_pause_state;
    // If unpaused, update waves periodically.
    if(!pause_state){
        timer = window.setInterval(
          'update_waves()',
          parseInt(document.getElementById('wave-move-interval').value)
        );
    }
}

function randomize(){
    // Set random wave RGB colors, directions, and positions.
    var wave_count = parseInt(document.getElementById('wave-count').value);
    color_generators = [
      Math.floor(Math.random() * wave_count),// R position
      [1, -1][Math.floor(Math.random() * 2)],// R direction
      Math.floor(Math.random() * wave_count),// G position
      [1, -1][Math.floor(Math.random() * 2)],// G direction
      Math.floor(Math.random() * wave_count),// B position
      [1, -1][Math.floor(Math.random() * 2)] // B direction
    ];

    update_waves();
}

function reset(){
    if(!window.confirm('Reset settings?')){
        return;
    }

    document.getElementById('orientation').value = 1;
    document.getElementById('wave-count').value = 10;
    document.getElementById('wave-move-interval').value = 100;

    randomize();
    recreate_waves();
    pause(false);
}

function update_waves(){
    // Move RGB color generators and change direction on collision with edge.
    var loop_counter = 2;
    do{
        color_generators[loop_counter * 2] += color_generators[loop_counter * 2 + 1];
        if(color_generators[loop_counter * 2] > parseInt(document.getElementById('wave-count').value) - 1){
            color_generators[loop_counter * 2 + 1] = -1;

        }else if(color_generators[loop_counter * 2] < 1){
            color_generators[loop_counter * 2 + 1] = 1;
        }
    }while(loop_counter--);

    // Update wave colors colors.
    loop_counter = parseInt(document.getElementById('wave-count').value) - 1;
    var new_colors = [];
    do{
        // Color is based on distance from generator.
        new_colors = [
          9 - Math.abs(loop_counter - color_generators[0]),
          9 - Math.abs(loop_counter - color_generators[2]),
          9 - Math.abs(loop_counter - color_generators[4]),
        ];

        // Set color CSS and prevent negative values.
        document.getElementById(loop_counter).style.backgroundColor =
          '#'
          + (new_colors[0] > 0
            ? new_colors[0]
            : 0
          )
          + (new_colors[1] > 0
            ? new_colors[1]
            : 0
          )
          + (new_colors[2] > 0
            ? new_colors[2]
            : 0
          );
    }while(loop_counter--);
}

var color_generators = [0, 0, 0, 0, 0, 0];
var pause_state = false;
var timer = 0;

document.getElementById('wave-move-interval').oninput = function(e){
    pause(pause_state);
};

window.onkeydown = function(e){
    var key = e.keyCode || e.which;

    // R: randomize wave color positions.
    if(key === 82){
        randomize();

    // P: pause or unpause.
    }else if(key === 80){
        pause(!pause_state);
    }
};

window.onload = function(){
    recreate_waves();
    randomize();

    pause(false);

    document.getElementById('orientation').onchange = recreate_waves;
    document.getElementById('wave-count').oninput = recreate_waves;
};
<commit_msg>simplified orientation code<commit_after>'use strict';

function recreate_waves(){
    // Generate and display wave HTML.
    var loop_counter = parseInt(document.getElementById('wave-count').value) - 1;
    var wave_html = '';
    do{
        wave_html += '

';
    }while(loop_counter--);
    document.getElementById('waves').innerHTML = wave_html;

    // Set orientation CSS to vertical by default...
    var display = 'inline-block';
    var height = '420px';
    var width = '42px';
    // ...or horizontal, if selected.
    if(document.getElementById('orientation').value == 0){
        display = 'block';
        height = '42px';
        width = '100%';
    }
    loop_counter = parseInt(document.getElementById('wave-count').value) - 1;
    do{
        document.getElementById(loop_counter).style.display = display;
        document.getElementById(loop_counter).style.height = height;
        document.getElementById(loop_counter).style.width = width;
    }while(loop_counter--);

    // Update waves.
    update_waves();
}

function pause(new_pause_state){
    window.clearInterval(timer);

    pause_state = new_pause_state;
    // If unpaused, update waves periodically.
    if(!pause_state){
        timer = window.setInterval(
          'update_waves()',
          parseInt(document.getElementById('wave-move-interval').value)
        );
    }
}

function randomize(){
    // Set random wave RGB colors, directions, and positions.
    var wave_count = parseInt(document.getElementById('wave-count').value);
    color_generators = [
      Math.floor(Math.random() * wave_count),// R position
      [1, -1][Math.floor(Math.random() * 2)],// R direction
      Math.floor(Math.random() * wave_count),// G position
      [1, -1][Math.floor(Math.random() * 2)],// G direction
      Math.floor(Math.random() * wave_count),// B position
      [1, -1][Math.floor(Math.random() * 2)] // B direction
    ];

    update_waves();
}

function reset(){
    if(!window.confirm('Reset settings?')){
        return;
    }

    document.getElementById('orientation').value = 1;
    document.getElementById('wave-count').value = 10;
    document.getElementById('wave-move-interval').value = 100;

    randomize();
    recreate_waves();
    pause(false);
}

function update_waves(){
    // Move RGB color generators and change direction on collision with edge.
    var loop_counter = 2;
    do{
        color_generators[loop_counter * 2] += color_generators[loop_counter * 2 + 1];
        if(color_generators[loop_counter * 2] > parseInt(document.getElementById('wave-count').value) - 1){
            color_generators[loop_counter * 2 + 1] = -1;

        }else if(color_generators[loop_counter * 2] < 1){
            color_generators[loop_counter * 2 + 1] = 1;
        }
    }while(loop_counter--);

    // Update wave colors colors.
    loop_counter = parseInt(document.getElementById('wave-count').value) - 1;
    var new_colors = [];
    do{
        // Color is based on distance from generator.
        new_colors = [
          9 - Math.abs(loop_counter - color_generators[0]),
          9 - Math.abs(loop_counter - color_generators[2]),
          9 - Math.abs(loop_counter - color_generators[4]),
        ];

        // Set color CSS and prevent negative values.
        document.getElementById(loop_counter).style.backgroundColor =
          '#'
          + (new_colors[0] > 0
            ? new_colors[0]
            : 0
          )
          + (new_colors[1] > 0
            ? new_colors[1]
            : 0
          )
          + (new_colors[2] > 0
            ? new_colors[2]
            : 0
          );
    }while(loop_counter--);
}

var color_generators = [0, 0, 0, 0, 0, 0];
var pause_state = false;
var timer = 0;

document.getElementById('wave-move-interval').oninput = function(e){
    pause(pause_state);
};

window.onkeydown = function(e){
    var key = e.keyCode || e.which;

    // R: randomize wave color positions.
    if(key === 82){
        randomize();

    // P: pause or unpause.
    }else if(key === 80){
        pause(!pause_state);
    }
};

window.onload = function(){
    recreate_waves();
    randomize();

    pause(false);

    document.getElementById('orientation').onchange = recreate_waves;
    document.getElementById('wave-count').oninput = recreate_waves;
};
<|endoftext|>


<commit_before>'use strict';

function recreate_waves(){
    settings_save();

    // Generate and display wave HTML.
    var loop_counter = settings_settings['wave-count'] - 1;
    var wave_html = '';
    do{
        wave_html += '

';
    }while(loop_counter--);
    document.getElementById('waves').innerHTML = wave_html;

    // Set orientation CSS to vertical by default...
    var display = 'inline-block';
    var height = '420px';
    var width = '42px';
    // ...or horizontal, if selected.
    if(settings_settings['orientation'] == 0){
        display = 'block';
        height = '42px';
        width = '100%';
    }
    loop_counter = settings_settings['wave-count'] - 1;
    do{
        document.getElementById(loop_counter).style.display = display;
        document.getElementById(loop_counter).style.height = height;
        document.getElementById(loop_counter).style.width = width;
    }while(loop_counter--);

    // Update waves.
    update_waves();
}

function pause(new_pause_state){
    window.clearInterval(timer);

    pause_state = new_pause_state;
    // If unpaused, update waves periodically.
    if(!pause_state){
        timer = window.setInterval(
          update_waves,
          settings_settings['wave-move-interval']
        );
    }
}

function randomize(){
    // Set random wave directions and positions.
    wave_directions = [
      [1, -1][random_integer(2)],// R direction
      [1, -1][random_integer(2)],// G direction
      [1, -1][random_integer(2)] // B direction
    ];
    waves_positions = [
      random_integer(settings_settings['wave-count']),// R position
      random_integer(settings_settings['wave-count']),// G position
      random_integer(settings_settings['wave-count']),// B position
    ];

    update_waves();
}

function update_waves(){
    // Move RGB color generators and change direction on collision with edge.
    var loop_counter = 2;
    do{
        wave_positions[loop_counter] += wave_directions[loop_counter];
        if(wave_positions[loop_counter] > settings_settings['wave-count'] - 1){
            wave_directions[loop_counter] = -1;

        }else if(wave_positions[loop_counter] < 1){
            wave_directions[loop_counter] = 1;
        }
    }while(loop_counter--);

    // Update wave colors colors.
    loop_counter = settings_settings['wave-count'] - 1;
    var new_colors = [];
    do{
        // Color is based on distance from generator.
        new_colors = [
          9 - Math.abs(loop_counter - wave_positions[0]),
          9 - Math.abs(loop_counter - wave_positions[1]),
          9 - Math.abs(loop_counter - wave_positions[2]),
        ];

        // Set color CSS and prevent negative values.
        document.getElementById(loop_counter).style.backgroundColor =
          '#'
          + (new_colors[0] > 0
            ? new_colors[0]
            : 0
          )
          + (new_colors[1] > 0
            ? new_colors[1]
            : 0
          )
          + (new_colors[2] > 0
            ? new_colors[2]
            : 0
          );
    }while(loop_counter--);
}

var pause_state = false;
var timer = 0;
var wave_directions = [0, 0, 0];
var wave_positions = [0, 0, 0];

window.onkeydown = function(e){
    var key = e.keyCode || e.which;

    // R: randomize wave color positions.
    if(key === 82){
        randomize();

    // P: pause or unpause.
    }else if(key === 80){
        pause(!pause_state);
    }
};

window.onload = function(){
    settings_init(
      'ColorWaves.htm-',
      {
        'orientation': 1,
        'wave-count': 10,
        'wave-move-interval': 100,
      }
    );

    document.getElementById('settings').innerHTML =
      '<input onclick=pause(!pause_state) type=button value=Un/[P]ause>'
        + '<input onclick=randomize() type=button value=[R]andomize>'
        + '<select id=orientation><option value=0>Horizontal</option><option value=1>Vertical</option></select>'
        + '<input id=wave-count>'
        + '<input id=wave-move-interval>'
        + '<input onclick=settings_reset();recreate_waves();pause(pause_state) type=button value=Reset>';
    settings_update();

    document.getElementById('orientation').onchange = recreate_waves;
    document.getElementById('wave-count').oninput = recreate_waves;
    document.getElementById('wave-move-interval').oninput = function(e){
        save();
        pause(pause_state);
    };

    recreate_waves();
    randomize();

    pause(false);
};
<commit_msg>fixed typo<commit_after>'use strict';

function recreate_waves(){
    settings_save();

    // Generate and display wave HTML.
    var loop_counter = settings_settings['wave-count'] - 1;
    var wave_html = '';
    do{
        wave_html += '

';
    }while(loop_counter--);
    document.getElementById('waves').innerHTML = wave_html;

    // Set orientation CSS to vertical by default...
    var display = 'inline-block';
    var height = '420px';
    var width = '42px';
    // ...or horizontal, if selected.
    if(settings_settings['orientation'] == 0){
        display = 'block';
        height = '42px';
        width = '100%';
    }
    loop_counter = settings_settings['wave-count'] - 1;
    do{
        document.getElementById(loop_counter).style.display = display;
        document.getElementById(loop_counter).style.height = height;
        document.getElementById(loop_counter).style.width = width;
    }while(loop_counter--);

    // Update waves.
    update_waves();
}

function pause(new_pause_state){
    window.clearInterval(timer);

    pause_state = new_pause_state;
    // If unpaused, update waves periodically.
    if(!pause_state){
        timer = window.setInterval(
          update_waves,
          settings_settings['wave-move-interval']
        );
    }
}

function randomize(){
    // Set random wave directions and positions.
    wave_directions = [
      [1, -1][random_integer(2)],// R
      [1, -1][random_integer(2)],// G
      [1, -1][random_integer(2)] // B
    ];
    wave_positions = [
      random_integer(settings_settings['wave-count']),// R
      random_integer(settings_settings['wave-count']),// G
      random_integer(settings_settings['wave-count']),// B
    ];

    update_waves();
}

function update_waves(){
    // Move RGB color generators and change direction on collision with edge.
    var loop_counter = 2;
    do{
        wave_positions[loop_counter] += wave_directions[loop_counter];
        if(wave_positions[loop_counter] > settings_settings['wave-count'] - 1){
            wave_directions[loop_counter] = -1;

        }else if(wave_positions[loop_counter] < 1){
            wave_directions[loop_counter] = 1;
        }
    }while(loop_counter--);

    // Update wave colors colors.
    loop_counter = settings_settings['wave-count'] - 1;
    var new_colors = [];
    do{
        // Color is based on distance from generator.
        new_colors = [
          9 - Math.abs(loop_counter - wave_positions[0]),
          9 - Math.abs(loop_counter - wave_positions[1]),
          9 - Math.abs(loop_counter - wave_positions[2]),
        ];

        // Set color CSS and prevent negative values.
        document.getElementById(loop_counter).style.backgroundColor =
          '#'
          + (new_colors[0] > 0
            ? new_colors[0]
            : 0
          )
          + (new_colors[1] > 0
            ? new_colors[1]
            : 0
          )
          + (new_colors[2] > 0
            ? new_colors[2]
            : 0
          );
    }while(loop_counter--);
}

var pause_state = false;
var timer = 0;
var wave_directions = [0, 0, 0];
var wave_positions = [0, 0, 0];

window.onkeydown = function(e){
    var key = e.keyCode || e.which;

    // R: randomize wave color positions.
    if(key === 82){
        randomize();

    // P: pause or unpause.
    }else if(key === 80){
        pause(!pause_state);
    }
};

window.onload = function(){
    settings_init(
      'ColorWaves.htm-',
      {
        'orientation': 1,
        'wave-count': 10,
        'wave-move-interval': 100,
      }
    );

    document.getElementById('settings').innerHTML =
      '<input onclick=pause(!pause_state) type=button value=Un/[P]ause>'
        + '<input onclick=randomize() type=button value=[R]andomize>'
        + '<select id=orientation><option value=0>Horizontal</option><option value=1>Vertical</option></select>'
        + '<input id=wave-count>'
        + '<input id=wave-move-interval>'
        + '<input onclick=settings_reset();recreate_waves();pause(pause_state) type=button value=Reset>';
    settings_update();

    document.getElementById('orientation').onchange = recreate_waves;
    document.getElementById('wave-count').oninput = recreate_waves;
    document.getElementById('wave-move-interval').oninput = function(e){
        save();
        pause(pause_state);
    };

    recreate_waves();
    randomize();

    pause(false);
};
<|endoftext|>


<commit_before>$(function() {

    $("input,textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // additional error messages or events
        },
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var name = $("input#name").val();
            var email = $("input#email").val();
            var phone = $("input#phone").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }
            $.ajax({
                url: "//forms.brace.io/ccub.soporte@gmail.com",
                type: "POST",
                dataType: "json",
                data: {
                    name: name,
                    phone: phone,
                    email: email,
                    message: message
                },
                cache: false,
                success: function() {
                    // Success message
                    $('#success').html("
");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("Tu mensaje ha sido enviado :) ");
                    $('#success > .alert-success')
                        .append('
');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    // Fail message
                    $('#success').html("
");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-danger').append("Ups, lo sentimos " + firstName + ", ha habido un error al enviar ti mensaje :(");
                    $('#success > .alert-danger').append('
');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
        },
        filter: function() {
            return $(this).is(":visible");
        },
    });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});

/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});
<commit_msg>changed mail<commit_after>$(function() {

    $("input,textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // additional error messages or events
        },
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var name = $("input#name").val();
            var email = $("input#email").val();
            var phone = $("input#phone").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }
            $.ajax({
                url: "//formspree.io/ccub.soporte@gmail.com",
                type: "POST",
                dataType: "json",
                data: {
                    name: name,
                    phone: phone,
                    email: email,
                    message: message
                },
                cache: false,
                success: function() {
                    // Success message
                    $('#success').html("
");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("Tu mensaje ha sido enviado :) ");
                    $('#success > .alert-success')
                        .append('
');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    // Fail message
                    $('#success').html("
");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-danger').append("Ups, lo sentimos " + firstName + ", ha habido un error al enviar ti mensaje :(");
                    $('#success > .alert-danger').append('
');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
        },
        filter: function() {
            return $(this).is(":visible");
        },
    });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});

/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});
<|endoftext|>


<commit_before>$(function() {

    $("input,textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // additional error messages or events
        },
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var name = $("input#name").val();
            var email = $("input#email").val();
            var phone = $("input#phone").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }
            $.ajax({
                url: "././mail/contact_me.php",
                type: "POST",
                data: {
                    name: name,
                    phone: phone,
                    email: email,
                    message: message
                },
                cache: false,
                success: function() {
                    // Success message
                    $('#success').html("
");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("Your message has been sent. ");
                    $('#success > .alert-success')
                        .append('
');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    // Fail message
                    $('#success').html("
");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-danger').append("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
                    $('#success > .alert-danger').append('
');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
        },
        filter: function() {
            return $(this).is(":visible");
        },
    });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});

/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});
<commit_msg>Fix mailchimp form<commit_after>$(function() {

    // $("input,textarea").jqBootstrapValidation({
    //     preventSubmit: true,
    //     submitError: function($form, event, errors) {
    //         // additional error messages or events
    //     },
    //     submitSuccess: function($form, event) {
    //         event.preventDefault(); // prevent default submit behaviour
    //         // get values from FORM
    //         var name = $("input#name").val();
    //         var email = $("input#email").val();
    //         var phone = $("input#phone").val();
    //         var message = $("textarea#message").val();
    //         var firstName = name; // For Success/Failure Message
    //         // Check for white space in name for Success/Fail message
    //         if (firstName.indexOf(' ') >= 0) {
    //             firstName = name.split(' ').slice(0, -1).join(' ');
    //         }
    //         $.ajax({
    //             url: "././mail/contact_me.php",
    //             type: "POST",
    //             data: {
    //                 name: name,
    //                 phone: phone,
    //                 email: email,
    //                 message: message
    //             },
    //             cache: false,
    //             success: function() {
    //                 // Success message
    //                 $('#success').html("
");
    //                 $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
    //                     .append("</button>");
    //                 $('#success > .alert-success')
    //                     .append("Your message has been sent. ");
    //                 $('#success > .alert-success')
    //                     .append('
');
    //
    //                 //clear all fields
    //                 $('#contactForm').trigger("reset");
    //             },
    //             error: function() {
    //                 // Fail message
    //                 $('#success').html("
");
    //                 $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
    //                     .append("</button>");
    //                 $('#success > .alert-danger').append("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
    //                 $('#success > .alert-danger').append('
');
    //                 //clear all fields
    //                 $('#contactForm').trigger("reset");
    //             },
    //         })
    //     },
    //     filter: function() {
    //         return $(this).is(":visible");
    //     },
    // });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});

/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});
<|endoftext|>


<commit_before>$(function() {

    $("#contactForm input,#contactForm textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // additional error messages or events
        },
        submitSuccess: function($form, event) {
            // Prevent spam click and default submit behaviour
            $("#btnSubmit").attr("disabled", true);
            event.preventDefault();

            // get values from FORM
            var name = $("input#name").val();
            var email = $("input#email").val();
            var phone = $("input#phone").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }
            $.ajax({
                url: "././mail/contact_me.php",
                type: "POST",
                data: {
                    name: name,
                    phone: phone,
                    email: email,
                    message: message
                },
                cache: false,
                success: function() {
                    // Enable button & show success message
                    $("#btnSubmit").attr("disabled", false);
                    $('#success').html("
");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("Your message has been sent. ");
                    $('#success > .alert-success')
                        .append('
');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    // Fail message
                    $('#success').html("
");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-danger').append("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
                    $('#success > .alert-danger').append('
');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
        },
        filter: function() {
            return $(this).is(":visible");
        },
    });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});

// When clicking on Full hide fail/success boxes
$('#name').focus(function() {
    $('#success').html('');
});
<commit_msg>fix email<commit_after>$(function() {

    $("#contactForm input,#contactForm textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // additional error messages or events
        },
        submitSuccess: function($form, event) {
            // Prevent spam click and default submit behaviour
            $("#btnSubmit").attr("disabled", true);
            event.preventDefault();

            // get values from FORM
            var name = $("input#name").val();
            var email = $("input#email").val();
            var phone = $("input#phone").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }
            $.ajax({
                url: "mail/contact_me.php",
                type: "POST",
                data: {
                    name: name,
                    phone: phone,
                    email: email,
                    message: message
                },
                cache: false,
                success: function() {
                    // Enable button & show success message
                    $("#btnSubmit").attr("disabled", false);
                    $('#success').html("
");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("Your message has been sent. ");
                    $('#success > .alert-success')
                        .append('
');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    // Fail message
                    $('#success').html("
");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-danger').append("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
                    $('#success > .alert-danger').append('
');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
        },
        filter: function() {
            return $(this).is(":visible");
        },
    });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});

// When clicking on Full hide fail/success boxes
$('#name').focus(function() {
    $('#success').html('');
});
<|endoftext|>


<commit_before>$(function() {

    $("input,textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // additional error messages or events
        },
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var name = $("input#name").val();
            var email = $("input#email").val();
            var phone = $("input#phone").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }

            console.log("Sending info message")
            $('#success').html("
");
            $('#success > .alert-info').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                .append("</button>");
            $('#success > .alert-info')
                .append("Sending your message...");
            $('#success > .alert-info')
                .append('
');

            $.ajax({
                type: "POST",
                url: "https://mandrillapp.com/api/1.0/messages/send.json",
                data: {
                  'key': '1eLy8qSRtPhZK-cyLAOVtw',
                  'message': {
                    'from_email': email,
                    'to': [
                        {
                          'email': 'jamaral7@gmail.com',
                          'name': name,
                          'type': 'to'
                        }
                      ],
                    'autotext': 'true',
                    'subject': 'ONAMAZU '+phone,
                    'html': message
                    }
                },
                cache: false,
                success: function() {
                    console.log("Success message")
                    $('#success').html("
");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("Your message has been sent. ");
                    $('#success > .alert-success')
                        .append('
');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    console.log("Fail message")
                    $('#success').html("
");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-danger').append("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
                    $('#success > .alert-danger').append('
');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
          },
            filter: function() {
                return $(this).is(":visible");
            },
        });

    //         $.ajax({
    //             url: "https://formspree.io/jamaral7@gmail.com",
    //             type: "POST",
    //             data: {
    //                 name: name,
    //                 subject: phone,
    //                 email: email,
    //                 message: message
    //             },
    //             cache: false,
    //             success: function() {
    //                 // Success message
    //                 $('#success').html("
");
    //                 $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
    //                     .append("</button>");
    //                 $('#success > .alert-success')
    //                     .append("Your message has been sent. ");
    //                 $('#success > .alert-success')
    //                     .append('
');
    //
    //                 //clear all fields
    //                 $('#contactForm').trigger("reset");
    //             },
    //             error: function() {
    //               $('#success').html("
");
    //               $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
    //                   .append("</button>");
    //               $('#success > .alert-success')
    //                   .append("Your message has been sent. ");
    //               $('#success > .alert-success')
    //                   .append('
');
    //                 // Fail message
    //                 // $('#success').html("
");
    //                 // $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
    //                 //     .append("</button>");
    //                 // $('#success > .alert-danger').append("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
    //                 // $('#success > .alert-danger').append('
');
    //                 // //clear all fields
    //                 // $('#contactForm').trigger("reset");
    //             },
    //         })
    //     },
    //     filter: function() {
    //         return $(this).is(":visible");
    //     },
    // });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});

/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});
<commit_msg>changing email service provider<commit_after>$(function() {

    $("input,textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // additional error messages or events
        },
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var name = $("input#name").val();
            var email = $("input#email").val();
            var phone = $("input#phone").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }

            console.log("Sending info message")
            $('#success').html("
");
            $('#success > .alert-info').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                .append("</button>");
            $('#success > .alert-info')
                .append("Sending your message...");
            $('#success > .alert-info')
                .append('
');

            $.ajax({
                method: "POST",
                url: "https://formspree.io/jamaral7@gmail.com",
                data: {
                    'message': message,
                    'subject': 'ONAMAZU '+phone,
                    'html': message
                    }
                },
                cache: false,
                success: function() {
                    console.log("Success message")
                    $('#success').html("
");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("Your message has been sent. ");
                    $('#success > .alert-success')
                        .append('
');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    console.log("Fail message")
                    $('#success').html("
");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-danger').append("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
                    $('#success > .alert-danger').append('
');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
          },
            filter: function() {
                return $(this).is(":visible");
            },
        });

    //         $.ajax({
    //             url: "https://formspree.io/jamaral7@gmail.com",
    //             type: "POST",
    //             data: {
    //                 name: name,
    //                 subject: phone,
    //                 email: email,
    //                 message: message
    //             },
    //             cache: false,
    //             success: function() {
    //                 // Success message
    //                 $('#success').html("
");
    //                 $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
    //                     .append("</button>");
    //                 $('#success > .alert-success')
    //                     .append("Your message has been sent. ");
    //                 $('#success > .alert-success')
    //                     .append('
');
    //
    //                 //clear all fields
    //                 $('#contactForm').trigger("reset");
    //             },
    //             error: function() {
    //               $('#success').html("
");
    //               $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
    //                   .append("</button>");
    //               $('#success > .alert-success')
    //                   .append("Your message has been sent. ");
    //               $('#success > .alert-success')
    //                   .append('
');
    //                 // Fail message
    //                 // $('#success').html("
");
    //                 // $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
    //                 //     .append("</button>");
    //                 // $('#success > .alert-danger').append("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
    //                 // $('#success > .alert-danger').append('
');
    //                 // //clear all fields
    //                 // $('#contactForm').trigger("reset");
    //             },
    //         })
    //     },
    //     filter: function() {
    //         return $(this).is(":visible");
    //     },
    // });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});

/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});
<|endoftext|>


<commit_before>/*
  Jquery Validation using jqBootstrapValidation
   example is taken from jqBootstrapValidation docs
  */
$(function() {

    $("#contactForm input,#contactForm textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // something to have when submit produces an error ?
            // Not decided if I need it yet
        },
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var name = $("input#name").val();
            var phone = $("input#phone").val();
            var email = $("input#email").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }
            $.ajax({
                url: "./bin/contact_me.php",
                type: "POST",
                data: {
                    name: name,
                    phone: phone,
                    email: email,
                    message: message
                },
                cache: false,
                success: function() {
                    // Success message
                    $('#success').html("
");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("Your message has been sent. ");
                    $('#success > .alert-success')
                        .append('
');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    // Fail message
                    $('#success').html("
");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-danger').append("Sorry " + firstName + " it seems that my mail server is not responding... Could you please email me directly to me@example.com ? Sorry for the inconvenience!");
                    $('#success > .alert-danger').append('
');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
        },
        filter: function() {
            return $(this).is(":visible");
        },
    });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});

/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});
<commit_msg>changes email<commit_after>/*
  Jquery Validation using jqBootstrapValidation
   example is taken from jqBootstrapValidation docs
  */
$(function() {

    $("#contactForm input,#contactForm textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // something to have when submit produces an error ?
            // Not decided if I need it yet
        },
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var name = $("input#name").val();
            var phone = $("input#phone").val();
            var email = $("input#email").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }
            $.ajax({
                url: "./bin/contact_me.php",
                type: "POST",
                data: {
                    name: name,
                    phone: phone,
                    email: email,
                    message: message
                },
                cache: false,
                success: function() {
                    // Success message
                    $('#success').html("
");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("Your message has been sent. ");
                    $('#success > .alert-success')
                        .append('
');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    // Fail message
                    $('#success').html("
");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-danger').append("Sorry " + firstName + " it seems that my mail server is not responding... Could you please email me directly to sales@abbydistributor.com ? Sorry for the inconvenience!");
                    $('#success > .alert-danger').append('
');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
        },
        filter: function() {
            return $(this).is(":visible");
        },
    });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});

/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});
<|endoftext|>


<commit_before>$(function() {

    $("input,textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // additional error messages or events
        },
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var name = $("input#name").val();
            var email = $("input#email").val();
            var phone = $("input#phone").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }
            $.ajax({
                url: "././mail/contact_me.php",
                type: "POST",
                data: {
                    name: name,
                    phone: phone,
                    email: email,
                    message: message
                },
                cache: false,
                success: function() {
                    // Success message
                    $('#success').html("
");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("Your message has been sent. ");
                    $('#success > .alert-success')
                        .append('
');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    // Fail message
                    $('#success').html("
");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-danger').append("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
                    $('#success > .alert-danger').append('
');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
        },
        filter: function() {
            return $(this).is(":visible");
        },
    });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});

/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});
<commit_msg>maybe fix php<commit_after>$(function() {

    $("input,textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // additional error messages or events
        },
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var name = $("input#name").val();
            var email = $("input#email").val();
            var message = $("textarea#message").val();
            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }
            $.ajax({
                url: "./mail/contact_me.php",
                type: "POST",
                data: {
                    name: name,
                    email: email,
                    message: message
                },
                cache: false,
                success: function() {
                    // Success message
                    $('#success').html("
");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("Your message has been sent. ");
                    $('#success > .alert-success')
                        .append('
');

                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
                error: function() {
                    // Fail message
                    $('#success').html("
");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×")
                        .append("</button>");
                    $('#success > .alert-danger').append("Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
                    $('#success > .alert-danger').append('
');
                    //clear all fields
                    $('#contactForm').trigger("reset");
                },
            })
        },
        filter: function() {
            return $(this).is(":visible");
        },
    });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});

/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});
<|endoftext|>


<commit_before>'use strict';

import axios from 'axios';
import resolveResponse from 'contentful-resolve-response';
import querystring from 'querystring';

export function createClient (options) {
  return new Client(options || {});
};

class Client {
  constructor ({accessToken, space, secure, host}) {
    if (!accessToken) {
      throw new TypeError('Expected property accessToken');
    }

    if (!space) {
      throw new TypeError('Expected property space');
    }

    const insecure = secure === false;
    var [hostname, port] = (host && host.split(':')) || [];

    hostname = hostname || 'cdn.contentful.com';
    port = port || (insecure ? 80 : 443);

    this.options = {
      baseUrl: `${insecure ? 'http' : 'https'}://${hostname}:${port}/spaces/${space}`,
      accessToken: accessToken
    };
  }

  _request (path, query) {
    if (!query) {
      query = {}
    };

    query.access_token = this.options.accessToken;

    const params = {
      headers: {},
      method: 'get',
      url: `${this.options.baseUrl}${path}?${querystring.stringify(query)}`
    };

    params.headers['Content-Type'] = 'application/vnd.contentful.delivery.v1+json';

    return axios(params)
      .then(function (response) {
        return response.data;
      })
      .catch(function (error) {
        throw error.data;
      });
  }

  asset (id, callback) {
    return nodeify(
      this._request('/assets/' + id).then(parseResource),
      callback
    );
  }

  assets (object, callback) {
    const query = new Query(object);
    const deferred = this._request('/assets', query).then(parseSearchResult);
    return nodeify(deferred, callback);
  }

  contentType (id, callback) {
    const deferred = this._request('/content_types/' + id).then(ContentType.parse);
    return nodeify(deferred, callback);
  }

  contentTypes (object, callback) {
    const query = new Query(object);
    const deferred = this._request('/content_types', query).then(parseSearchResult);
    return nodeify(deferred, callback);
  }

  entry (id, callback) {
    const deferred = this._request('/entries/' + id)
                   .then(Entry.parse);
    return nodeify(deferred, callback);
  }

  entries (object, callback) {
    const query = new Query(object);
    const deferred = this._request('/entries', query).then(parseSearchResult);
    return nodeify(deferred, callback);
  }

  space (callback) {
    return nodeify(this._request(''), callback);
  }

  _pagedSync (sync) {
    const self = this;
    return this._request('/sync', sync.query)
               .then(function (data) {
                 sync.append(data);

                 if (!sync.done) {
                   return self._pagedSync(sync);
                 } else {
                   return {
                     items: sync.items,
                     nextSyncToken: sync.nextSyncToken
                   };
                 }
               });
  }

  sync (object, callback) {
    if (!object || (!object.initial && !object.nextSyncToken)) {
      throw new Error('Please provide either the initial flag or a nextSyncToken for syncing');
    }
    const query = new Query(object);
    const deferred = this._pagedSync(new Sync(query)).then(function (response) {
      response.items = parseSearchResult(response);
      return response;
    });
    return nodeify(deferred, callback);
  }
}

class Asset {
  constructor ({sys, fields}) {
    this.sys = new Sys(sys);
    this.fields = fields;
  }

  static parse (object) {
    return new Asset(object);
  }
}

class Entry {
  constructor ({sys, fields}) {
    this.sys = new Sys(sys);
    this.fields = fields;
  }

  static parse (object) {
    return new Entry(object);
  }
}

class ContentType {
  constructor ({sys, fields, name, displayField}) {
    this.sys = new Sys(sys);
    this.name = name;
    this.displayField = displayField;
    this.fields = fields && fields.map(Field.parse);
  }

  static parse (object) {
    return new ContentType(object);
  }
}

class Field {
  constructor (object) {
    for (var k in object) {
      this[k] = object[k];
    }
  }

  static parse (object) {
    return new Field(object);
  }
}

class Query {
  constructor (object) {
    for (var k in object) {
      this[k] = object[k];
    }
  }

  toQueryString () {
    return querystring.stringify(this);
  }

  static parse (object) {
    return new Query(stringifyArrayValues(object));
  }
}

class Space {
  static parse (object) {
    return _.extend(new Space(), object);
  }
}

class Sys {
  constructor ({id, revision, type, locale, contentType, createdAt, linkType, updatedAt, space}) {
    this.id = id;
    this.revision = revision;
    this.type = type;
    this.locale = locale;
    this.space = space && Link.parse(space);
    this.contentType = contentType && new Link(contentType);
    this.createdAt = createdAt && new Date(createdAt);
    this.updatedAt = updatedAt && new Date(updatedAt);
  }

  static parse (object) {
    return new Sys(object);
  }
}

class Link {
  constructor ({sys}) {
    this.sys = new Sys(sys);
  }

  static parse (object) {
    return new Link(object);
  }
}

class Sync {
  constructor (query) {
    this.query = query;
    this.items = [];
    this.done = false;
  }

  append (data) {
    this.items = this.items.concat(data.items);

    if (data.nextPageUrl) {
      const nextPageUrl = data.nextPageUrl.split('?');
      this.query = _.omit(this.query, 'initial', 'type', 'sync_token');
      this.query.sync_token = querystring.parse(nextPageUrl[1]).sync_token;
    } else if (data.nextSyncUrl) {
      const nextSyncUrl = data.nextSyncUrl.split('?');
      this.nextSyncToken = querystring.parse(nextSyncUrl[1]).sync_token;
      this.done = true;
    }
  }
}

const parseableResourceTypes = {
  Asset: Asset,
  ContentType: ContentType,
  Entry: Entry,
  Space: Space
};

function isParseableResource (object) {
  return _.isObject(object) && _.isObject(object.sys) && 'type' in object.sys &&
    object.sys.type in parseableResourceTypes;
}

function parseResource (resource) {
  var Type = parseableResourceTypes[resource.sys.type];
  return Type.parse(resource);
}

function parseSearchResult (object) {
  walkMutate(object, isParseableResource, parseResource);
  const items = resolveResponse(object);
  Object.defineProperties(items, {
    limit: { value: object.limit, enumerable: false },
    skip:  { value: object.skip,  enumerable: false },
    total: { value: object.total, enumerable: false }
  });
  return items;
}

function stringifyArrayValues (object) {
  return keys(object).reduce(function (result, key) {
    const value = object[key];
    result[key] = _.isArray(value) ? value.join(',') : value;
    return result;
  }, {});
}

function walkMutate (input, pred, mutator) {
  if (pred(input)) {
    return mutator(input);
  }

  if (input && typeof input === 'object') {
    for (var key in input) {
      input[key] = walkMutate(input[key], pred, mutator);
    }
  }

  return input;
}

function nodeify (deferred, callback) {
  if (callback) {
    return deferred
    .then(function (response) {
      callback(null, response);
      return response;
    })
    .catch(function (error) {
      callback(error);
      throw error;
    });
  }
  return deferred;
}
<commit_msg>Correctly require lodash<commit_after>'use strict';

import axios from 'axios';
import resolveResponse from 'contentful-resolve-response';
import querystring from 'querystring';
import _ from 'lodash';

export function createClient (options) {
  return new Client(options || {});
};

class Client {
  constructor ({accessToken, space, secure, host}) {
    if (!accessToken) {
      throw new TypeError('Expected property accessToken');
    }

    if (!space) {
      throw new TypeError('Expected property space');
    }

    const insecure = secure === false;
    var [hostname, port] = (host && host.split(':')) || [];

    hostname = hostname || 'cdn.contentful.com';
    port = port || (insecure ? 80 : 443);

    this.options = {
      baseUrl: `${insecure ? 'http' : 'https'}://${hostname}:${port}/spaces/${space}`,
      accessToken: accessToken
    };
  }

  _request (path, query) {
    if (!query) {
      query = {}
    };

    query.access_token = this.options.accessToken;

    const params = {
      headers: {},
      method: 'get',
      url: `${this.options.baseUrl}${path}?${querystring.stringify(query)}`
    };

    params.headers['Content-Type'] = 'application/vnd.contentful.delivery.v1+json';

    return axios(params)
      .then(function (response) {
        return response.data;
      })
      .catch(function (error) {
        throw error.data;
      });
  }

  asset (id, callback) {
    return nodeify(
      this._request('/assets/' + id).then(parseResource),
      callback
    );
  }

  assets (object, callback) {
    const query = new Query(object);
    const deferred = this._request('/assets', query).then(parseSearchResult);
    return nodeify(deferred, callback);
  }

  contentType (id, callback) {
    const deferred = this._request('/content_types/' + id).then(ContentType.parse);
    return nodeify(deferred, callback);
  }

  contentTypes (object, callback) {
    const query = new Query(object);
    const deferred = this._request('/content_types', query).then(parseSearchResult);
    return nodeify(deferred, callback);
  }

  entry (id, callback) {
    const deferred = this._request('/entries/' + id)
                   .then(Entry.parse);
    return nodeify(deferred, callback);
  }

  entries (object, callback) {
    const query = new Query(object);
    const deferred = this._request('/entries', query).then(parseSearchResult);
    return nodeify(deferred, callback);
  }

  space (callback) {
    return nodeify(this._request(''), callback);
  }

  _pagedSync (sync) {
    const self = this;
    return this._request('/sync', sync.query)
               .then(function (data) {
                 sync.append(data);

                 if (!sync.done) {
                   return self._pagedSync(sync);
                 } else {
                   return {
                     items: sync.items,
                     nextSyncToken: sync.nextSyncToken
                   };
                 }
               });
  }

  sync (object, callback) {
    if (!object || (!object.initial && !object.nextSyncToken)) {
      throw new Error('Please provide either the initial flag or a nextSyncToken for syncing');
    }
    const query = new Query(object);
    const deferred = this._pagedSync(new Sync(query)).then(function (response) {
      response.items = parseSearchResult(response);
      return response;
    });
    return nodeify(deferred, callback);
  }
}

class Asset {
  constructor ({sys, fields}) {
    this.sys = new Sys(sys);
    this.fields = fields;
  }

  static parse (object) {
    return new Asset(object);
  }
}

class Entry {
  constructor ({sys, fields}) {
    this.sys = new Sys(sys);
    this.fields = fields;
  }

  static parse (object) {
    return new Entry(object);
  }
}

class ContentType {
  constructor ({sys, fields, name, displayField}) {
    this.sys = new Sys(sys);
    this.name = name;
    this.displayField = displayField;
    this.fields = fields && fields.map(Field.parse);
  }

  static parse (object) {
    return new ContentType(object);
  }
}

class Field {
  constructor (object) {
    for (var k in object) {
      this[k] = object[k];
    }
  }

  static parse (object) {
    return new Field(object);
  }
}

class Query {
  constructor (object) {
    for (var k in object) {
      this[k] = object[k];
    }
  }

  toQueryString () {
    return querystring.stringify(this);
  }

  static parse (object) {
    return new Query(stringifyArrayValues(object));
  }
}

class Space {
  static parse (object) {
    return _.extend(new Space(), object);
  }
}

class Sys {
  constructor ({id, revision, type, locale, contentType, createdAt, linkType, updatedAt, space}) {
    this.id = id;
    this.revision = revision;
    this.type = type;
    this.locale = locale;
    this.space = space && Link.parse(space);
    this.contentType = contentType && new Link(contentType);
    this.createdAt = createdAt && new Date(createdAt);
    this.updatedAt = updatedAt && new Date(updatedAt);
  }

  static parse (object) {
    return new Sys(object);
  }
}

class Link {
  constructor ({sys}) {
    this.sys = new Sys(sys);
  }

  static parse (object) {
    return new Link(object);
  }
}

class Sync {
  constructor (query) {
    this.query = query;
    this.items = [];
    this.done = false;
  }

  append (data) {
    this.items = this.items.concat(data.items);

    if (data.nextPageUrl) {
      const nextPageUrl = data.nextPageUrl.split('?');
      this.query = _.omit(this.query, 'initial', 'type', 'sync_token');
      this.query.sync_token = querystring.parse(nextPageUrl[1]).sync_token;
    } else if (data.nextSyncUrl) {
      const nextSyncUrl = data.nextSyncUrl.split('?');
      this.nextSyncToken = querystring.parse(nextSyncUrl[1]).sync_token;
      this.done = true;
    }
  }
}

const parseableResourceTypes = {
  Asset: Asset,
  ContentType: ContentType,
  Entry: Entry,
  Space: Space
};

function isParseableResource (object) {
  return _.isObject(object) && _.isObject(object.sys) && 'type' in object.sys &&
    object.sys.type in parseableResourceTypes;
}

function parseResource (resource) {
  var Type = parseableResourceTypes[resource.sys.type];
  return Type.parse(resource);
}

function parseSearchResult (object) {
  walkMutate(object, isParseableResource, parseResource);
  const items = resolveResponse(object);
  Object.defineProperties(items, {
    limit: { value: object.limit, enumerable: false },
    skip:  { value: object.skip,  enumerable: false },
    total: { value: object.total, enumerable: false }
  });
  return items;
}

function stringifyArrayValues (object) {
  return keys(object).reduce(function (result, key) {
    const value = object[key];
    result[key] = _.isArray(value) ? value.join(',') : value;
    return result;
  }, {});
}

function walkMutate (input, pred, mutator) {
  if (pred(input)) {
    return mutator(input);
  }

  if (input && typeof input === 'object') {
    for (var key in input) {
      input[key] = walkMutate(input[key], pred, mutator);
    }
  }

  return input;
}

function nodeify (deferred, callback) {
  if (callback) {
    return deferred
    .then(function (response) {
      callback(null, response);
      return response;
    })
    .catch(function (error) {
      callback(error);
      throw error;
    });
  }
  return deferred;
}
<|endoftext|>


<commit_before>var textarea    = document.getElementsByName('document[source]')[0],
    preview     = document.getElementById('preview'),
    previewLink = document.getElementById('preview-link'),
    saveButton  = document.querySelector('a[href="#save"]'),
    pos         = textarea.value.length * 2,
    dirty       = true

textarea.focus()
textarea.setSelectionRange(pos, pos)

// Preview-related function

updatePreview = function() {
  if (!dirty) return;
  var xhr = new XMLHttpRequest()
  xhr.onreadystatechange = function() {
    if (xhr.readyState == 4 && xhr.status == 200) {
      preview.innerHTML = xhr.responseText
      dirty = false
    }
  }
  xhr.open('POST', '/render', true)
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
  xhr.send('source=' + encodeURIComponent(textarea.value))
}

togglePreview = function() {
  if (window.location.hash == '#preview') {
    window.location.hash = ''
    previewLink.textContent = 'P'
    previewLink.setAttribute('title', 'Preview changes (Alt-P)')
    textarea.focus()
  } else {
    window.location.hash = '#preview'
    previewLink.textContent = 'E'
    previewLink.setAttribute('title', 'Edit document (Alt-P)')
  }
}

scrollPreview = function() {
  var editorHeight  = textarea.scrollHeight - textarea.clientHeight,
      previewHeight = preview.scrollHeight - preview.clientHeight,
      scrollRatio   = textarea.scrollTop / editorHeight

  preview.scrollTop = previewHeight * scrollRatio;
}

// Event handling

window.setTimeout(function() {
  updatePreview()
  window.setTimeout(arguments.callee, 1000)
}, 0)

textarea.addEventListener('scroll', scrollPreview);
textarea.addEventListener('keyup', function(ev) {
  dirty = true
}, false)

previewLink.addEventListener('click', function(ev) {
  togglePreview()
  ev.preventDefault()
})

saveButton.addEventListener('click', function(ev) {
  document.forms[0].submit()
  ev.preventDefault()
}, false)

keymage('alt-p', togglePreview, {preventDefault: true})
<commit_msg>Try to adjust scroll ratio to take images into account<commit_after>var textarea    = document.getElementsByName('document[source]')[0],
    preview     = document.getElementById('preview'),
    previewLink = document.getElementById('preview-link'),
    saveButton  = document.querySelector('a[href="#save"]'),
    pos         = textarea.value.length * 2,
    dirty       = true

textarea.focus()
textarea.setSelectionRange(pos, pos)

// Preview-related function

updatePreview = function() {
  if (!dirty) return;
  var xhr = new XMLHttpRequest()
  xhr.onreadystatechange = function() {
    if (xhr.readyState == 4 && xhr.status == 200) {
      preview.innerHTML = xhr.responseText
      dirty = false
    }
  }
  xhr.open('POST', '/render', true)
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
  xhr.send('source=' + encodeURIComponent(textarea.value))
}

togglePreview = function() {
  if (window.location.hash == '#preview') {
    window.location.hash = ''
    previewLink.textContent = 'P'
    previewLink.setAttribute('title', 'Preview changes (Alt-P)')
    textarea.focus()
  } else {
    window.location.hash = '#preview'
    previewLink.textContent = 'E'
    previewLink.setAttribute('title', 'Edit document (Alt-P)')
  }
}

scrollPreview = function() {
  var editorHeight  = textarea.scrollHeight - textarea.clientHeight,
      previewHeight = preview.scrollHeight - preview.clientHeight,
      scrollRatio   = textarea.scrollTop / editorHeight,
      imgs          = preview.getElementsByTagName('img')

  Array.prototype.forEach.call(imgs, function(img) {
    previewHeight += 1/scrollRatio * img.height
  })

  preview.scrollTop = previewHeight * scrollRatio;
}

// Event handling

window.setTimeout(function() {
  updatePreview()
  window.setTimeout(arguments.callee, 1000)
}, 0)

textarea.addEventListener('scroll', scrollPreview);
textarea.addEventListener('keyup', function(ev) {
  dirty = true
}, false)

previewLink.addEventListener('click', function(ev) {
  togglePreview()
  ev.preventDefault()
})

saveButton.addEventListener('click', function(ev) {
  document.forms[0].submit()
  ev.preventDefault()
}, false)

keymage('alt-p', togglePreview, {preventDefault: true})
<|endoftext|>