site.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. "use strict";
  2. $(function () {
  3. $('.fieldlist').each(function() {
  4. var $this=$(this);
  5. var lis=$this.children('li');
  6. lis.first().children(':first').after(' <button class="btn btn-mini" type="button"><i class="icon-plus"></i></button>');
  7. lis.first().children('button').click(function() {
  8. clone_fieldlist($this.children('li:last'));
  9. });
  10. lis=lis.slice(1);
  11. lis.each(function() {
  12. append_remove_button($(this));
  13. });
  14. });
  15. $('.selectpicker').selectpicker();
  16. init_map();
  17. });
  18. function init_map() {
  19. var mapquest=L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg', {
  20. attribution: '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, '+
  21. 'Tiles courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>',
  22. subdomains: '1234'
  23. });
  24. var mapquestsat=L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg', {
  25. attribution: '&copy; Tiles courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>, '+
  26. 'Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency',
  27. subdomains: '1234',
  28. maxZoom: 11
  29. });
  30. var osm=L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  31. attribution: '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors',
  32. subdomains: 'ab'
  33. });
  34. var hyb=L.tileLayer('http://otile{s}.mqcdn.com/tiles/1.0.0/hyb/{z}/{x}/{y}.jpg', {
  35. subdomains: '1234',
  36. maxZoom: 11
  37. });
  38. var map = L.map('map', {
  39. center: new L.LatLng(46.603354, 10),
  40. zoom: 4,
  41. layers: [mapquest]
  42. });
  43. map.attributionControl.setPrefix('');
  44. L.control.layers({'MapQuest': mapquest, 'OSM Mapnik': osm, 'MapQuest Aerial': mapquestsat}).addTo(map);
  45. map.on('baselayerchange', function(a) {
  46. if(a.name == 'MapQuest Aerial') {
  47. map.addLayer(hyb);
  48. hyb.bringToFront();
  49. } else {
  50. map.removeLayer(hyb);
  51. }
  52. });
  53. }
  54. function change_input_num(li, new_num, reset=false) {
  55. li.find('input,select').each(function() {
  56. var id = $(this).attr('id').replace(/^(.*)-\d{1,4}/, '$1-'+new_num);
  57. $(this).attr({'name': id, 'id': id});
  58. if(reset)
  59. $(this).val('').removeAttr('checked');
  60. });
  61. }
  62. function append_remove_button(li) {
  63. li.children(':first').after(' <button class="btn btn-mini" type="button"><i class="icon-minus"></i></button>');
  64. li.children('button').click(function() {
  65. var ul=li.parent();
  66. li.remove();
  67. var i=0;
  68. ul.children('li').each(function() {
  69. change_input_num($(this), i);
  70. i++;
  71. });
  72. });
  73. };
  74. function clone_fieldlist(el) {
  75. var new_element = el.clone(true);
  76. var elem_id = new_element.find(':input')[0].id;
  77. var elem_num = parseInt(elem_id.replace(/^.*-(\d{1,4})/, '$1')) + 1;
  78. change_input_num(new_element, elem_num, true);
  79. new_element.children('button').remove();
  80. new_element.children('.help-inline.error-list').remove();
  81. new_element.find('.bootstrap-select').remove();
  82. append_remove_button(new_element);
  83. new_element.find('.selectpicker').data('selectpicker', null).selectpicker();
  84. el.after(new_element);
  85. }