From 8655916c6ac7b9bbfe785d1a51137baeb82c891b Mon Sep 17 00:00:00 2001 From: "Ethan T. Jorgensen" Date: Thu, 7 Mar 2019 13:16:16 -0600 Subject: [PATCH] Refactor pen.js, add JSHint rules Closes #17 --- script/pen.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/script/pen.js b/script/pen.js index 2ab8744..5fc062c 100644 --- a/script/pen.js +++ b/script/pen.js @@ -1,33 +1,36 @@ -var yearmod = 288 +/* jshint browser: true, jquery: true */ +/* global ClipboardJS */ +'use strict'; +var yearmod = 288; -$(document).ready(function() { +$(document).ready(function () { $('#year').html(getYear()); $('#input').bind('input change', run); - $('#save').click(function() { download('pencode.txt', $('#input').val()) }); - $('#load').click(function() { loadFile($('#template').val()) }); + $('#save').click(function () { download('pencode.txt', $('#input').val()); }); + $('#load').click(function () { loadFile($('#template').val()); }); $('.controlgroup').controlgroup(); // get clipboard.js set up var clip = new ClipboardJS('#copy'); - clip.on('success', function() { - alert('Copied to clipboard.') + clip.on('success', function () { + alert('Copied to clipboard.'); }); - clip.on('failure', function() { - alert('Failed to copy.') + clip.on('failure', function () { + alert('Failed to copy.'); }); // keep #copy loaded with the path currently on #template - $('#template').on('selectmenuchange', function() { - var temp = $('#template').val() - $('#copy').attr('data-clipboard-text','http://ps.ss13.net#' + temp.substring(0, temp.indexOf('.txt'))) + $('#template').on('selectmenuchange', function () { + var temp = $('#template').val(); + $('#copy').attr('data-clipboard-text','http://ps.ss13.net#' + temp.substring(0, temp.indexOf('.txt'))); }); - setTimeout(function() { + setTimeout(function () { var hash = $(location).attr('hash'); - loadFile(hash ? hash.substring(1) + '.txt' : 'instructions.txt') - }, 100); + loadFile(hash ? hash.substring(1) + '.txt' : 'instructions.txt'); + }, 100); }); @@ -102,7 +105,7 @@ function processText(str) { .replaceAll('[xynlogo]', '') .replaceAll('[editorbr]', '') - ) + ); return str; } @@ -140,7 +143,7 @@ function download(filename, text) { document.body.removeChild(element); - alert('Document saved as ' + filename) + alert('Document saved as ' + filename); } function loadFile(filename) {