Formatting Javascript using js-beautifier

pull/75/head
Jordan Wright 2016-01-16 22:59:40 -06:00
parent e78ec27ef2
commit 2dda83814c
8 changed files with 924 additions and 875 deletions

View File

@ -67,11 +67,15 @@ $(document).ready(function(){
// Setup tooltips // Setup tooltips
$('[data-toggle="tooltip"]').tooltip() $('[data-toggle="tooltip"]').tooltip()
// Setup our graphs // Setup our graphs
var timeline_data = {series:[{ var timeline_data = {
series: [{
name: "Events", name: "Events",
data: [] data: []
}]} }]
var email_data = {series:[]} }
var email_data = {
series: []
}
var email_legend = {} var email_legend = {}
var email_series_data = {} var email_series_data = {}
var timeline_opts = { var timeline_opts = {
@ -117,10 +121,17 @@ $(document).ready(function(){
}) })
// Setup the graphs // Setup the graphs
$.each(campaign.timeline, function(i, event) { $.each(campaign.timeline, function(i, event) {
timeline_data.series[0].data.push({meta : i, x: new Date(event.time), y:1}) timeline_data.series[0].data.push({
meta: i,
x: new Date(event.time),
y: 1
})
}) })
$.each(email_series_data, function(status, count) { $.each(email_series_data, function(status, count) {
email_data.series.push({meta: status, value: count}) email_data.series.push({
meta: status,
value: count
})
}) })
var timeline_chart = new Chartist.Line('#timeline_chart', timeline_data, timeline_opts) var timeline_chart = new Chartist.Line('#timeline_chart', timeline_data, timeline_opts)
// Setup the overview chart listeners // Setup the overview chart listeners
@ -201,7 +212,9 @@ $(document).ready(function(){
bubbles = [] bubbles = []
$.each(campaign.results, function(i, result) { $.each(campaign.results, function(i, result) {
// Check that it wasn't an internal IP // Check that it wasn't an internal IP
if (result.latitude == 0 && result.longitude == 0) { return true; } if (result.latitude == 0 && result.longitude == 0) {
return true;
}
newIP = true newIP = true
$.each(bubbles, function(i, bubble) { $.each(bubbles, function(i, bubble) {
if (bubble.ip == result.ip) { if (bubble.ip == result.ip) {

View File

@ -12,7 +12,9 @@ var labels = {
function save() { function save() {
groups = [] groups = []
$.each($("#groupTable").DataTable().rows().data(), function(i, group) { $.each($("#groupTable").DataTable().rows().data(), function(i, group) {
groups.push({name: group[0]}) groups.push({
name: group[0]
})
}) })
console.log(groups) console.log(groups)
var campaign = { var campaign = {
@ -61,8 +63,7 @@ function edit(campaign){
if (groups.length == 0) { if (groups.length == 0) {
modalError("No groups found!") modalError("No groups found!")
return false; return false;
} } else {
else {
group_bh.add(groups) group_bh.add(groups)
} }
}) })
@ -71,8 +72,7 @@ function edit(campaign){
if (templates.length == 0) { if (templates.length == 0) {
modalError("No templates found!") modalError("No templates found!")
return false return false
} } else {
else {
template_bh.add(templates) template_bh.add(templates)
} }
}) })
@ -81,8 +81,7 @@ function edit(campaign){
if (pages.length == 0) { if (pages.length == 0) {
modalError("No pages found!") modalError("No pages found!")
return false return false
} } else {
else {
page_bh.add(pages) page_bh.add(pages)
} }
}) })
@ -133,7 +132,9 @@ $(document).ready(function(){
// Create the group typeahead objects // Create the group typeahead objects
groupTable = $("#groupTable").DataTable() groupTable = $("#groupTable").DataTable()
group_bh = new Bloodhound({ group_bh = new Bloodhound({
datumTokenizer: function(g) { return Bloodhound.tokenizers.whitespace(g.name) }, datumTokenizer: function(g) {
return Bloodhound.tokenizers.whitespace(g.name)
},
queryTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace,
local: [] local: []
}) })
@ -142,13 +143,16 @@ $(document).ready(function(){
hint: true, hint: true,
highlight: true, highlight: true,
minLength: 1 minLength: 1
}, }, {
{
name: "groups", name: "groups",
source: group_bh, source: group_bh,
templates: { templates: {
empty: function(data) {return '<div class="tt-suggestion">No groups matched that query</div>' }, empty: function(data) {
suggestion: function(data){ return '<div>' + data.name + '</div>' } return '<div class="tt-suggestion">No groups matched that query</div>'
},
suggestion: function(data) {
return '<div>' + data.name + '</div>'
}
} }
}) })
.bind('typeahead:select', function(ev, group) { .bind('typeahead:select', function(ev, group) {
@ -159,7 +163,9 @@ $(document).ready(function(){
}); });
// Create the template typeahead objects // Create the template typeahead objects
template_bh = new Bloodhound({ template_bh = new Bloodhound({
datumTokenizer: function(t) { return Bloodhound.tokenizers.whitespace(t.name) }, datumTokenizer: function(t) {
return Bloodhound.tokenizers.whitespace(t.name)
},
queryTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace,
local: [] local: []
}) })
@ -168,13 +174,16 @@ $(document).ready(function(){
hint: true, hint: true,
highlight: true, highlight: true,
minLength: 1 minLength: 1
}, }, {
{
name: "templates", name: "templates",
source: template_bh, source: template_bh,
templates: { templates: {
empty: function(data) {return '<div class="tt-suggestion">No templates matched that query</div>' }, empty: function(data) {
suggestion: function(data){ return '<div>' + data.name + '</div>' } return '<div class="tt-suggestion">No templates matched that query</div>'
},
suggestion: function(data) {
return '<div>' + data.name + '</div>'
}
} }
}) })
.bind('typeahead:select', function(ev, template) { .bind('typeahead:select', function(ev, template) {
@ -185,7 +194,9 @@ $(document).ready(function(){
}); });
// Create the landing page typeahead objects // Create the landing page typeahead objects
page_bh = new Bloodhound({ page_bh = new Bloodhound({
datumTokenizer: function(p) { return Bloodhound.tokenizers.whitespace(p.name) }, datumTokenizer: function(p) {
return Bloodhound.tokenizers.whitespace(p.name)
},
queryTokenizer: Bloodhound.tokenizers.whitespace, queryTokenizer: Bloodhound.tokenizers.whitespace,
local: [] local: []
}) })
@ -194,13 +205,16 @@ $(document).ready(function(){
hint: true, hint: true,
highlight: true, highlight: true,
minLength: 1 minLength: 1
}, }, {
{
name: "pages", name: "pages",
source: page_bh, source: page_bh,
templates: { templates: {
empty: function(data) {return '<div class="tt-suggestion">No pages matched that query</div>' }, empty: function(data) {
suggestion: function(data){ return '<div>' + data.name + '</div>' } return '<div class="tt-suggestion">No pages matched that query</div>'
},
suggestion: function(data) {
return '<div>' + data.name + '</div>'
}
} }
}) })
.bind('typeahead:select', function(ev, page) { .bind('typeahead:select', function(ev, page) {

View File

@ -17,8 +17,15 @@ $(document).ready(function(){
if (campaigns.length > 0) { if (campaigns.length > 0) {
$("#dashboard").show() $("#dashboard").show()
// Create the overview chart data // Create the overview chart data
var overview_data = {labels:[],series:[[]]} var overview_data = {
var average_data = {series:[]} labels: [],
series: [
[]
]
}
var average_data = {
series: []
}
var overview_opts = { var overview_opts = {
axisX: { axisX: {
showGrid: false showGrid: false
@ -60,11 +67,20 @@ $(document).ready(function(){
average += campaign.y average += campaign.y
// Add the data to the overview chart // Add the data to the overview chart
overview_data.labels.push(campaign_date) overview_data.labels.push(campaign_date)
overview_data.series[0].push({meta : i, value: campaign.y}) overview_data.series[0].push({
meta: i,
value: campaign.y
})
}) })
average = Math.floor(average / campaigns.length); average = Math.floor(average / campaigns.length);
average_data.series.push({meta: "Unsuccessful Phishes", value: 100 - average}) average_data.series.push({
average_data.series.push({meta: "Successful Phishes", value: average}) meta: "Unsuccessful Phishes",
value: 100 - average
})
average_data.series.push({
meta: "Successful Phishes",
value: average
})
// Build the charts // Build the charts
var average_chart = new Chartist.Pie("#average_chart", average_data, average_opts) var average_chart = new Chartist.Pie("#average_chart", average_data, average_opts)
var overview_chart = new Chartist.Line('#overview_chart', overview_data, overview_opts) var overview_chart = new Chartist.Line('#overview_chart', overview_data, overview_opts)

View File

@ -4,6 +4,7 @@
Author: Jordan Wright <github.com/jordan-wright> Author: Jordan Wright <github.com/jordan-wright>
*/ */
var pages = [] var pages = []
// Save attempts to POST to /templates/ // Save attempts to POST to /templates/
function save(idx) { function save(idx) {
var page = {} var page = {}
@ -69,7 +70,9 @@ function importSite(){
} }
function edit(idx) { function edit(idx) {
$("#modalSubmit").unbind('click').click(function(){save(idx)}) $("#modalSubmit").unbind('click').click(function() {
save(idx)
})
$("#html_editor").ckeditor() $("#html_editor").ckeditor()
var page = {} var page = {}
if (idx != -1) { if (idx != -1) {
@ -125,13 +128,11 @@ $(document).ready(function(){
}); });
$('.modal').on('shown.bs.modal', function(event) { $('.modal').on('shown.bs.modal', function(event) {
// Keep track of the number of open modals // Keep track of the number of open modals
if ( typeof( $('body').data( 'fv_open_modals' ) ) == 'undefined' ) if (typeof($('body').data('fv_open_modals')) == 'undefined') {
{
$('body').data('fv_open_modals', 0); $('body').data('fv_open_modals', 0);
} }
// if the z-index of this modal has been set, ignore. // if the z-index of this modal has been set, ignore.
if ( $(this).hasClass( 'fv-modal-stack' ) ) if ($(this).hasClass('fv-modal-stack')) {
{
return; return;
} }
$(this).addClass('fv-modal-stack'); $(this).addClass('fv-modal-stack');

View File

@ -15,7 +15,9 @@ var icons = {
// Save attempts to POST to /templates/ // Save attempts to POST to /templates/
function save(idx) { function save(idx) {
var template = {attachments:[]} var template = {
attachments: []
}
template.name = $("#name").val() template.name = $("#name").val()
template.subject = $("#subject").val() template.subject = $("#subject").val()
template.html = CKEDITOR.instances["html_editor"].getData(); template.html = CKEDITOR.instances["html_editor"].getData();
@ -101,15 +103,18 @@ function attach(files){
} }
function edit(idx) { function edit(idx) {
$("#modalSubmit").unbind('click').click(function(){save(idx)}) $("#modalSubmit").unbind('click').click(function() {
$("#attachmentUpload").unbind('click').click(function(){this.value=null}) save(idx)
})
$("#attachmentUpload").unbind('click').click(function() {
this.value = null
})
$("#html_editor").ckeditor() $("#html_editor").ckeditor()
$("#attachmentsTable").show() $("#attachmentsTable").show()
attachmentsTable = null attachmentsTable = null
if ($.fn.dataTable.isDataTable('#attachmentsTable')) { if ($.fn.dataTable.isDataTable('#attachmentsTable')) {
attachmentsTable = $('#attachmentsTable').DataTable(); attachmentsTable = $('#attachmentsTable').DataTable();
} } else {
else {
attachmentsTable = $("#attachmentsTable").DataTable({ attachmentsTable = $("#attachmentsTable").DataTable({
"aoColumnDefs": [{ "aoColumnDefs": [{
"targets": [3, 4], "targets": [3, 4],
@ -117,7 +122,9 @@ function edit(idx){
}] }]
}); });
} }
var template = {attachments:[]} var template = {
attachments: []
}
if (idx != -1) { if (idx != -1) {
template = templates[idx] template = templates[idx]
$("#name").val(template.name) $("#name").val(template.name)
@ -211,13 +218,11 @@ $(document).ready(function(){
}); });
$('.modal').on('shown.bs.modal', function(event) { $('.modal').on('shown.bs.modal', function(event) {
// Keep track of the number of open modals // Keep track of the number of open modals
if ( typeof( $('body').data( 'fv_open_modals' ) ) == 'undefined' ) if (typeof($('body').data('fv_open_modals')) == 'undefined') {
{
$('body').data('fv_open_modals', 0); $('body').data('fv_open_modals', 0);
} }
// if the z-index of this modal has been set, ignore. // if the z-index of this modal has been set, ignore.
if ( $(this).hasClass( 'fv-modal-stack' ) ) if ($(this).hasClass('fv-modal-stack')) {
{
return; return;
} }
$(this).addClass('fv-modal-stack'); $(this).addClass('fv-modal-stack');

View File

@ -54,7 +54,9 @@ function dismiss(){
function edit(idx) { function edit(idx) {
targets = $("#targetsTable").dataTable() targets = $("#targetsTable").dataTable()
$("#modalSubmit").unbind('click').click(function(){save(idx)}) $("#modalSubmit").unbind('click').click(function() {
save(idx)
})
if (idx == -1) { if (idx == -1) {
group = {} group = {}
} else { } else {

View File

@ -1,15 +1,13 @@
function errorFlash(message) { function errorFlash(message) {
$("#flashes").empty() $("#flashes").empty()
$("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-danger\">\ $("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-danger\">\
<i class=\"fa fa-exclamation-circle\"></i> " + message + "</div>" <i class=\"fa fa-exclamation-circle\"></i> " + message + "</div>")
)
} }
function successFlash(message) { function successFlash(message) {
$("#flashes").empty() $("#flashes").empty()
$("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-success\">\ $("#flashes").append("<div style=\"text-align:center\" class=\"alert alert-success\">\
<i class=\"fa fa-check-circle\"></i> " + message + "</div>" <i class=\"fa fa-check-circle\"></i> " + message + "</div>")
)
} }
function modalError(message) { function modalError(message) {