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