| 1 |
/* global prompt */ |
| 2 |
/* global visualizer */ |
| 3 |
/* global alert */ |
| 4 |
|
| 5 |
(function ($) { |
| 6 |
$(document).ready(function () { |
| 7 |
init_permissions(); |
| 8 |
|
| 9 |
$('.type-radio').change(function () { |
| 10 |
$('.type-label-selected').removeClass('type-label-selected'); |
| 11 |
$(this).parent().addClass('type-label-selected'); |
| 12 |
}); |
| 13 |
|
| 14 |
$('#vz-chart-settings h2').click(function () { |
| 15 |
$("#vz-chart-source").hide(); |
| 16 |
$("#vz-chart-permissions").removeClass('open').addClass('bottom-fixed'); |
| 17 |
$(this).parent().removeClass('bottom-fixed').addClass('open'); |
| 18 |
$("#vz-chart-permissions .viz-group-header").hide(); |
| 19 |
return false; |
| 20 |
}); |
| 21 |
$('#vz-chart-settings .customize-section-back').click(function () { |
| 22 |
$("#vz-chart-source").show(); |
| 23 |
$(this).parent().parent().removeClass('open').addClass('bottom-fixed'); |
| 24 |
|
| 25 |
return false; |
| 26 |
}); |
| 27 |
$('.viz-group-title').click(function () { |
| 28 |
var parent = $(this).parent(); |
| 29 |
|
| 30 |
if (parent.hasClass('open')) { |
| 31 |
parent.removeClass('open'); |
| 32 |
} else { |
| 33 |
parent.parent().find('.viz-group.open').removeClass('open'); |
| 34 |
parent.addClass('open'); |
| 35 |
} |
| 36 |
}); |
| 37 |
$('#view-remote-file').click(function () { |
| 38 |
var url = $(this).parent().find('#remote-data').val(); |
| 39 |
|
| 40 |
if (url !== '') { |
| 41 |
if (/^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(url)) { |
| 42 |
if (url.substr(url.length - 8) === '/pubhtml') { |
| 43 |
url = url.substring(0, url.length - 8) + '/export?format=csv'; |
| 44 |
} |
| 45 |
|
| 46 |
$('#canvas').lock(); |
| 47 |
$(this).parent().submit(); |
| 48 |
} else { |
| 49 |
alert(visualizer.l10n.invalid_source); |
| 50 |
} |
| 51 |
} |
| 52 |
}); |
| 53 |
|
| 54 |
$('#vz-import-file').click(function (e) { |
| 55 |
e.preventDefault(); |
| 56 |
if ($.trim($(this).parent().find("#csv-file").val()) !== '') { |
| 57 |
$('#canvas').lock(); |
| 58 |
$(this).parent().submit(); |
| 59 |
} |
| 60 |
}); |
| 61 |
|
| 62 |
$('#thehole').load(function () { |
| 63 |
$('#canvas').unlock(); |
| 64 |
}); |
| 65 |
|
| 66 |
$('.viz-section-title').click(function () { |
| 67 |
$(this).toggleClass('open').parent().find('.viz-section-items').toggle(); |
| 68 |
}); |
| 69 |
|
| 70 |
$('.more-info').click(function () { |
| 71 |
$(this).parent().find('.viz-section-description:first').toggle(); |
| 72 |
return false; |
| 73 |
}); |
| 74 |
|
| 75 |
}); |
| 76 |
|
| 77 |
function init_permissions(){ |
| 78 |
$('#vz-chart-permissions h2').click(function () { |
| 79 |
$("#vz-chart-source").hide(); |
| 80 |
$("#vz-chart-permissions .viz-group-header").show(); |
| 81 |
$("#vz-chart-settings").removeClass('open').addClass('bottom-fixed'); |
| 82 |
|
| 83 |
$('#settings-button').click(function(e) { |
| 84 |
e.preventDefault(); |
| 85 |
$('#permissions-form').submit(); |
| 86 |
$('#settings-form').submit(); |
| 87 |
}); |
| 88 |
|
| 89 |
$(this).parent().removeClass('bottom-fixed').addClass('open'); |
| 90 |
|
| 91 |
return false; |
| 92 |
}); |
| 93 |
$('#vz-chart-permissions .customize-section-back').click(function () { |
| 94 |
$("#vz-chart-source").show(); |
| 95 |
|
| 96 |
$("#vz-chart-permissions .viz-group-header").hide(); |
| 97 |
$('#settings-button').click(function(e) { |
| 98 |
e.preventDefault(); |
| 99 |
$('#settings-form').submit(); |
| 100 |
}); |
| 101 |
|
| 102 |
$(this).parent().parent().removeClass('open').addClass('bottom-fixed'); |
| 103 |
|
| 104 |
return false; |
| 105 |
}); |
| 106 |
|
| 107 |
$('.visualizer-permission').chosen({ |
| 108 |
width : '50%', |
| 109 |
search_contains : true |
| 110 |
}); |
| 111 |
|
| 112 |
$('.visualizer-permission-type').each(function(x, y){ |
| 113 |
var type = $(y).attr('data-visualizer-permission-type'); |
| 114 |
var child = $('.visualizer-permission-' + type + '-specific'); |
| 115 |
if($(y).val() === 'all'){ |
| 116 |
child.next('div.chosen-container').hide(); |
| 117 |
return; |
| 118 |
} |
| 119 |
}); |
| 120 |
|
| 121 |
$('.visualizer-permission-type').on('change', function(evt, params) { |
| 122 |
var type = $(this).attr('data-visualizer-permission-type'); |
| 123 |
var child = $('.visualizer-permission-' + type + '-specific'); |
| 124 |
child.empty(); |
| 125 |
if(params.selected === 'all'){ |
| 126 |
child.next('div.chosen-container').hide(); |
| 127 |
return; |
| 128 |
} else { |
| 129 |
child.next('div.chosen-container').show(); |
| 130 |
} |
| 131 |
child.append('<option value="">' + visualizer.l10n['loading'] + '</option>').trigger('chosen:updated'); |
| 132 |
$.ajax({ |
| 133 |
url : visualizer.ajax['url'], |
| 134 |
method : 'post', |
| 135 |
data : { |
| 136 |
'action' : visualizer.ajax['actions']['permissions'], |
| 137 |
'nonce' : visualizer.ajax['nonces']['permissions'], |
| 138 |
'type' : params.selected |
| 139 |
}, |
| 140 |
success : function(d, textStatus, XMLHttpRequest){ |
| 141 |
if(d.success) { |
| 142 |
child.empty(); |
| 143 |
$.each(d.data, function(k, v){ |
| 144 |
child.append('<option value="' + k + '">' + v + '</option>'); |
| 145 |
}); |
| 146 |
child.trigger('chosen:updated'); |
| 147 |
} |
| 148 |
} |
| 149 |
}); |
| 150 |
}); |
| 151 |
} |
| 152 |
})(jQuery); |
| 153 |
|
| 154 |
(function ($) { |
| 155 |
$.fn.lock = function () { |
| 156 |
$(this).each(function () { |
| 157 |
var $this = $(this); |
| 158 |
var position = $this.css('position'); |
| 159 |
|
| 160 |
if (!position) { |
| 161 |
position = 'static'; |
| 162 |
} |
| 163 |
|
| 164 |
switch (position) { |
| 165 |
case 'absolute': |
| 166 |
case 'relative': |
| 167 |
break; |
| 168 |
default: |
| 169 |
$this.css('position', 'relative'); |
| 170 |
break; |
| 171 |
} |
| 172 |
$this.data('position', position); |
| 173 |
|
| 174 |
var width = $this.width(), |
| 175 |
height = $this.height(); |
| 176 |
|
| 177 |
var locker = $('<div class="locker"></div>'); |
| 178 |
locker.width(width).height(height); |
| 179 |
|
| 180 |
var loader = $('<div class="locker-loader"></div>'); |
| 181 |
loader.width(width).height(height); |
| 182 |
|
| 183 |
locker.append(loader); |
| 184 |
$this.append(locker); |
| 185 |
$(window).resize(function () { |
| 186 |
$this.find('.locker,.locker-loader').width($this.width()).height($this.height()); |
| 187 |
}); |
| 188 |
}); |
| 189 |
|
| 190 |
return $(this); |
| 191 |
}; |
| 192 |
|
| 193 |
$.fn.unlock = function () { |
| 194 |
$(this).each(function () { |
| 195 |
$(this).find('.locker').remove(); |
| 196 |
$(this).css('position', $(this).data('position')); |
| 197 |
}); |
| 198 |
|
| 199 |
return $(this); |
| 200 |
}; |
| 201 |
})(jQuery); |