Using vim-jsbeautify

This commit is contained in:
Maxime Beauchemin
2016-02-29 23:12:50 -08:00
parent a68d7428c3
commit b44d48c724
16 changed files with 1011 additions and 827 deletions

View File

@@ -21,44 +21,58 @@ require('../vendor/pygments.css');
require('../node_modules/bootstrap-toggle/css/bootstrap-toggle.min.css');
var slice;
function prepForm(){
function prepForm() {
var i = 1;
// Assigning the right id to form elements in filters
$("#filters > div").each(function() {
$(this).attr("id", function() {return "flt_" + i;})
$(this).attr("id", function() {
return "flt_" + i;
})
$(this).find("#flt_col_0")
.attr("id", function() {return "flt_col_" + i;})
.attr("name", function() {return "flt_col_" + i;});
.attr("id", function() {
return "flt_col_" + i;
})
.attr("name", function() {
return "flt_col_" + i;
});
$(this).find("#flt_op_0")
.attr("id", function() {return "flt_op_" + i;})
.attr("name", function() {return "flt_op_" + i;});
.attr("id", function() {
return "flt_op_" + i;
})
.attr("name", function() {
return "flt_op_" + i;
});
$(this).find("#flt_eq_0")
.attr("id", function() {return "flt_eq_" + i;})
.attr("name", function() {return "flt_eq_" + i;});
.attr("id", function() {
return "flt_eq_" + i;
})
.attr("name", function() {
return "flt_eq_" + i;
});
i++;
});
}
function renderSlice(){
function renderSlice() {
prepForm();
slice.render();
}
function initExploreView() {
function druidify(){
function druidify() {
$('div.alert').remove();
history.pushState({}, document.title, slice.querystring());
renderSlice();
}
function get_collapsed_fieldsets(){
function get_collapsed_fieldsets() {
var collapsed_fieldsets = $("#collapsed_fieldsets").val();
if (collapsed_fieldsets !== undefined && collapsed_fieldsets !== "") {
collapsed_fieldsets = collapsed_fieldsets.split('||');
}
else {
} else {
collapsed_fieldsets = [];
}
return collapsed_fieldsets;
@@ -69,11 +83,10 @@ function initExploreView() {
var fieldset = parent.find(".legend_label").text();
var collapsed_fieldsets = get_collapsed_fieldsets();
var index;
if (!parent.hasClass("collapsed")){
if (!parent.hasClass("collapsed")) {
if (animation) {
parent.find(".fieldset_content").slideUp();
}
else {
} else {
parent.find(".fieldset_content").hide();
}
@@ -86,8 +99,7 @@ function initExploreView() {
} else {
if (animation) {
parent.find(".fieldset_content").slideDown();
}
else {
} else {
parent.find(".fieldset_content").show();
}
parent.removeClass("collapsed");
@@ -102,11 +114,11 @@ function initExploreView() {
$("#collapsed_fieldsets").val(collapsed_fieldsets.join("||"));
}
$('legend').click(function () {
$('legend').click(function() {
toggle_fieldset($(this), true);
});
function copyURLToClipboard (url) {
function copyURLToClipboard(url) {
var textArea = document.createElement("textarea");
textArea.style.position = 'fixed';
textArea.style.left = '-1000px';
@@ -127,19 +139,26 @@ function initExploreView() {
return successful;
}
$('#shortner').click(function () {
$('#shortner').click(function() {
$.ajax({
type: "POST",
url: '/r/shortner/',
data: {'data': '/' + window.location.pathname + slice.querystring()},
data: {
'data': '/' + window.location.pathname + slice.querystring()
},
success: function(data) {
var close = '<a style="cursor: pointer;"><i class="fa fa-close" id="close_shortner"></i></a>';
var copy = '<a style="cursor: pointer;"><i class="fa fa-clipboard" title="Copy to clipboard" id="copy_url"></i></a>';
var spaces = '&nbsp;&nbsp;&nbsp;'
var close = '<a style="cursor: pointer;"><i class="fa fa-close" id="close_shortner"></i></a>';
var copy = '<a style="cursor: pointer;"><i class="fa fa-clipboard" title="Copy to clipboard" id="copy_url"></i></a>';
var spaces = '&nbsp;&nbsp;&nbsp;'
var popover = data + spaces + copy + spaces + close;
var $shortner = $('#shortner')
.popover({content: popover, placement: 'left', html: true, trigger: 'manual'})
.popover({
content: popover,
placement: 'left',
html: true,
trigger: 'manual'
})
.popover('show');
$('#copy_url').tooltip().click(function() {
@@ -152,31 +171,43 @@ function initExploreView() {
}, 1200);
}
});
$('#close_shortner').click(function(){
$('#close_shortner').click(function() {
$shortner.popover('destroy');
});
},
error: function() {alert("Error :(");},
error: function() {
alert("Error :(");
},
});
});
$("#viz_type").change(function() {$("#query").submit();});
$("#viz_type").change(function() {
$("#query").submit();
});
var collapsed_fieldsets = get_collapsed_fieldsets();
for(var i=0; i < collapsed_fieldsets.length; i++){
for (var i = 0; i < collapsed_fieldsets.length; i++) {
toggle_fieldset($('legend:contains("' + collapsed_fieldsets[i] + '")'), false);
}
$(".select2").select2({dropdownAutoWidth : true});
$(".select2Sortable").select2({dropdownAutoWidth : true});
$(".select2Sortable").select2Sortable({bindOrder: 'sortableStop'});
$(".select2").select2({
dropdownAutoWidth: true
});
$(".select2Sortable").select2({
dropdownAutoWidth: true
});
$(".select2Sortable").select2Sortable({
bindOrder: 'sortableStop'
});
$("form").show();
$('[data-toggle="tooltip"]').tooltip({container: 'body'});
$('[data-toggle="tooltip"]').tooltip({
container: 'body'
});
$(".ui-helper-hidden-accessible").remove(); // jQuery-ui 1.11+ creates a div for every tooltip
function set_filters(){
for (var i = 1; i < 10; i++){
function set_filters() {
for (var i = 1; i < 10; i++) {
var eq = px.getParam("flt_eq_" + i);
if (eq !== ''){
if (eq !== '') {
add_filter(i);
}
}
@@ -187,7 +218,7 @@ function initExploreView() {
var cp = $("#flt0").clone();
$(cp).appendTo("#filters");
$(cp).show();
if (i !== undefined){
if (i !== undefined) {
$(cp).find("#flt_eq_0").val(px.getParam("flt_eq_" + i));
$(cp).find("#flt_op_0").val(px.getParam("flt_op_" + i));
$(cp).find("#flt_col_0").val(px.getParam("flt_col_" + i));
@@ -208,7 +239,7 @@ function initExploreView() {
$("#plus").click(add_filter);
$("#btn_save").click(function () {
$("#btn_save").click(function() {
var slice_name = prompt("Name your slice!");
if (slice_name !== "" && slice_name !== null) {
$("#slice_name").val(slice_name);
@@ -217,7 +248,7 @@ function initExploreView() {
$("#query").submit();
}
});
$("#btn_overwrite").click(function () {
$("#btn_overwrite").click(function() {
var flag = confirm("Overwrite slice [" + $("#slice_name").val() + "] !?");
if (flag) {
$("#action").val("overwrite");
@@ -233,37 +264,51 @@ function initExploreView() {
return this.text.localeCompare(term) === 0;
});
if (filtered.length === 0) {
return {id: term, text: term};
return {
id: term,
text: term
};
}
}
function initSelectionToValue(element, callback) {
callback({id: element.val(), text: element.val()});
callback({
id: element.val(),
text: element.val()
});
}
function list_data(arr) {
var obj = [];
for (var i=0; i<arr.length; i++){
obj.push({id: arr[i], text: arr[i]});
for (var i = 0; i < arr.length; i++) {
obj.push({
id: arr[i],
text: arr[i]
});
}
return obj;
}
$(".select2_freeform").each(function(){
$(".select2_freeform").each(function() {
var parent = $(this).parent();
var name = $(this).attr('name');
var l = [];
var selected = '';
for(var i=0; i<this.options.length; i++) {
l.push({id: this.options[i].value, text: this.options[i].text});
if(this.options[i].selected){
for (var i = 0; i < this.options.length; i++) {
l.push({
id: this.options[i].value,
text: this.options[i].text
});
if (this.options[i].selected) {
selected = this.options[i].value;
}
}
var obj = parent.append(
'<input class="' + $(this).attr('class') + '" name="'+ name +'" type="text" value="' + selected + '">'
'<input class="' + $(this).attr('class') + '" name="' + name + '" type="text" value="' + selected + '">'
);
$("input[name='" + name +"']").select2({
$("input[name='" + name + "']").select2({
createSearchChoice: create_choices,
initSelection: initSelectionToValue,
dropdownAutoWidth : true,
dropdownAutoWidth: true,
multiple: false,
data: l,
});
@@ -279,7 +324,7 @@ $(document).ready(function() {
px.registerViz(visType);
var data = $('.slice').data('slice');
var data = $('.slice').data('slice');
slice = px.Slice(data);
//
@@ -290,9 +335,11 @@ $(document).ready(function() {
// make checkbox inputs display as toggles
$(':checkbox')
.addClass('pull-right')
.attr("data-onstyle", "default")
.bootstrapToggle({size: 'mini'});
.addClass('pull-right')
.attr("data-onstyle", "default")
.bootstrapToggle({
size: 'mini'
});
$('div.toggle').addClass('pull-right');
});