| @@ -1,160 +1,63 @@ | ||
| 1 | -/* global prompt */ | |
| 2 | -/* global visualizer */ | |
| 3 | -/* global alert */ | |
| 1 | +(function($) { | |
| 2 | + $(document).ready(function() { | |
| 3 | + $('.type-radio').change(function() { | |
| 4 | + $('.type-label-selected').removeClass('type-label-selected'); | |
| 5 | + $(this).parent().addClass('type-label-selected'); | |
| 6 | + }); | |
| 4 | 7 | |
| 5 | -(function ($) { | |
| 6 | - $(document).ready(function () { | |
| 7 | - init_permissions(); | |
| 8 | + $('.group-title').click(function() { | |
| 9 | + var parent = $(this).parent(); | |
| 8 | 10 | |
| 9 | - $('.type-radio').change(function () { | |
| 10 | - $('.type-label-selected').removeClass('type-label-selected'); | |
| 11 | - $(this).parent().addClass('type-label-selected'); | |
| 12 | - }); | |
| 11 | + if (parent.hasClass('open')) { | |
| 12 | + parent.removeClass('open'); | |
| 13 | + } else { | |
| 14 | + $('.group.open').removeClass('open'); | |
| 15 | + parent.addClass('open'); | |
| 16 | + } | |
| 17 | + }); | |
| 13 | 18 | |
| 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'); | |
| 19 | + $('#remote-file').click(function() { | |
| 20 | + var url = $.trim(prompt(visualizer.l10n.remotecsv_prompt)); | |
| 24 | 21 | |
| 25 | - return false; | |
| 26 | - }); | |
| 27 | - $('.viz-group-title').click(function () { | |
| 28 | - var parent = $(this).parent(); | |
| 22 | + if (url != '') { | |
| 23 | + if(/^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|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F\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(url)) { | |
| 24 | + $('#remote-data').val(url); | |
| 25 | + $('#csv-file').val(''); | |
| 26 | + $('#canvas').lock(); | |
| 27 | + $('#csv-form').submit(); | |
| 28 | + } else { | |
| 29 | + alert(visualizer.l10n.invalid_source); | |
| 30 | + } | |
| 31 | + } | |
| 32 | + }); | |
| 29 | 33 | |
| 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(); | |
| 34 | + $('#csv-file').change(function() { | |
| 35 | + if ($.trim($(this).val()) != '') { | |
| 36 | + $('#remote-data').val(''); | |
| 37 | + $('#canvas').lock(); | |
| 38 | + $('#csv-form').submit(); | |
| 39 | + } | |
| 40 | + }); | |
| 39 | 41 | |
| 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 | - } | |
| 42 | + $('#thehole').load(function() { | |
| 43 | + $('#canvas').unlock(); | |
| 44 | + }); | |
| 45 | 45 | |
| 46 | - $('#canvas').lock(); | |
| 47 | - $(this).parent().submit(); | |
| 48 | - } else { | |
| 49 | - alert(visualizer.l10n.invalid_source); | |
| 50 | - } | |
| 51 | - } | |
| 52 | - }); | |
| 46 | + $('.section-title').click(function() { | |
| 47 | + $(this).toggleClass('open').parent().find('.section-items').toggle(); | |
| 48 | + }); | |
| 53 | 49 | |
| 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 | - } | |
| 50 | + $('.more-info').click(function() { | |
| 51 | + $(this).parent().find('.section-description:first').toggle(); | |
| 52 | + return false; | |
| 53 | + }); | |
| 54 | + }); | |
| 152 | 55 | })(jQuery); |
| 153 | 56 | |
| 154 | -(function ($) { | |
| 155 | - $.fn.lock = function () { | |
| 156 | - $(this).each(function () { | |
| 57 | +(function($) { | |
| 58 | + $.fn.lock = function() { | |
| 59 | + $(this).each(function() { | |
| 157 | 60 | var $this = $(this); |
| 158 | 61 | var position = $this.css('position'); |
| 159 | 62 | |
| 160 | 63 | if (!position) { |
| @@ -160,9 +63,9 @@ | ||
| 160 | 63 | if (!position) { |
| 161 | 64 | position = 'static'; |
| 162 | 65 | } |
| 163 | 66 | |
| 164 | - switch (position) { | |
| 67 | + switch(position) { | |
| 165 | 68 | case 'absolute': |
| 166 | 69 | case 'relative': |
| 167 | 70 | break; |
| 168 | 71 | default: |
| @@ -181,21 +84,21 @@ | ||
| 181 | 84 | loader.width(width).height(height); |
| 182 | 85 | |
| 183 | 86 | locker.append(loader); |
| 184 | 87 | $this.append(locker); |
| 185 | - $(window).resize(function () { | |
| 88 | + $(window).resize(function() { | |
| 186 | 89 | $this.find('.locker,.locker-loader').width($this.width()).height($this.height()); |
| 187 | 90 | }); |
| 188 | 91 | }); |
| 189 | 92 | |
| 190 | 93 | return $(this); |
| 191 | - }; | |
| 94 | + } | |
| 192 | 95 | |
| 193 | - $.fn.unlock = function () { | |
| 194 | - $(this).each(function () { | |
| 96 | + $.fn.unlock = function() { | |
| 97 | + $(this).each(function() { | |
| 195 | 98 | $(this).find('.locker').remove(); |
| 196 | 99 | $(this).css('position', $(this).data('position')); |
| 197 | 100 | }); |
| 198 | 101 | |
| 199 | 102 | return $(this); |
| 200 | - }; | |
| 103 | + } | |
| 201 | 104 | })(jQuery); |