diff --git a/.jslintrc b/.jslintrc index 4ee1252..11db3d7 100644 --- a/.jslintrc +++ b/.jslintrc @@ -3,14 +3,11 @@ "document", "navigator", "console", - "window", + "alert", "django", - "gettext", - "windowname_to_id", - "jQuery", - "WebSocket", - "$", - "alert" + "window", + "closeOverlay", + "setTimeout" ], "adsafe": false, @@ -39,11 +36,11 @@ "vars": true, "white": false, "validthis": true, - "strict_mode":true, + "strict_mode":false, "browser": false, "devel": false, - "node": false, + "node": true, "rhino": false, "widget": false, "windows": false, diff --git a/.travis.yml b/.travis.yml index fb65a8e..20c27af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,8 +24,8 @@ before_install: - pip install --no-cache-dir -U -r requirements-test.txt - ./runflake8 - ./runisort - - npm install --save jslint -g - - jslint --config ./.jslintrc ./django_netjsongraph/static/netjsongraph/js/*.js + - npm install jslint -g + - jslint django_netjsongraph/static/netjsongraph/js/*.js install: - pip install $DJANGO diff --git a/django_netjsongraph/static/netjsongraph/js/receive-url.js b/django_netjsongraph/static/netjsongraph/js/receive-url.js index 19a553c..86fa045 100644 --- a/django_netjsongraph/static/netjsongraph/js/receive-url.js +++ b/django_netjsongraph/static/netjsongraph/js/receive-url.js @@ -1,11 +1,12 @@ -(function($) { - $(document).ready(function() { +(function ($) { + 'use strict'; + $(document).ready(function () { var p = $('.field-receive_url p, .field-receive_url > div > div'), value = window.location.origin + p.text(); - p.html(''); + p.html(''); var field = $('#id_receive_url'); - field.click(function(){ + field.click(function () { $(this).select(); }); }); -})(django.jQuery); +}(django.jQuery)); diff --git a/django_netjsongraph/static/netjsongraph/js/strategy-switcher.js b/django_netjsongraph/static/netjsongraph/js/strategy-switcher.js index 4456e3a..65701b3 100644 --- a/django_netjsongraph/static/netjsongraph/js/strategy-switcher.js +++ b/django_netjsongraph/static/netjsongraph/js/strategy-switcher.js @@ -1,18 +1,18 @@ -(function($) { - $(document).ready(function() { +(function ($) { + 'use strict'; + $(document).ready(function () { var strategy = $('#id_strategy'), fetchRows = $('#id_url').parents('.form-row'), receiveRows = $('#id_key, #id_expiration_time, #id_receive_url').parents('.form-row'); - strategy.change(function(e){ - if (strategy.val() == 'fetch'){ + strategy.change(function (e) { + if (strategy.val() === 'fetch') { fetchRows.show(); receiveRows.hide(); - } - else{ + } else { fetchRows.hide(); receiveRows.show(); } }); strategy.trigger('change'); }); -})(django.jQuery); +}(django.jQuery)); diff --git a/django_netjsongraph/static/netjsongraph/js/topology-history.js b/django_netjsongraph/static/netjsongraph/js/topology-history.js index 2dcf2d9..9b412e5 100644 --- a/django_netjsongraph/static/netjsongraph/js/topology-history.js +++ b/django_netjsongraph/static/netjsongraph/js/topology-history.js @@ -1,20 +1,21 @@ -window.initTopologyHistory = function($){ +window.initTopologyHistory = function ($) { + 'use strict'; var datepicker = $('#njg-datepicker'), today = new Date(), apiUrl = datepicker.attr('data-history-api'); today.setHours(0, 0, 0, 0); datepicker.datepicker({dateFormat: 'dd/mm/yy'}); datepicker.datepicker('setDate', today); - datepicker.change(function() {; + datepicker.change(function () { var date = datepicker.val().split('/').reverse().join('-'), url = apiUrl + '?date=' + date; // load latest data when looking currentDate - if(datepicker.datepicker('getDate').getTime() == today.getTime()){ + if (datepicker.datepicker('getDate').getTime() === today.getTime()) { url = window.__njg_default_url__; } - $.getJSON(url).done(function(data){ + $.getJSON(url).done(function (data) { window.graph = window.loadNetJsonGraph(data); - }).error(function(xhr){ + }).error(function (xhr) { alert(xhr.responseJSON.detail); }); }); diff --git a/django_netjsongraph/static/netjsongraph/js/visualize.js b/django_netjsongraph/static/netjsongraph/js/visualize.js index a3e0d5a..97bf60d 100644 --- a/django_netjsongraph/static/netjsongraph/js/visualize.js +++ b/django_netjsongraph/static/netjsongraph/js/visualize.js @@ -1,54 +1,54 @@ -django.jQuery(function($) { +django.jQuery(function ($) { + 'use strict'; var overlay = $('.djnjg-overlay'), body = $('body'), inner = overlay.find('.inner'), visualizeUrl = $('.visualizelink').attr('data-url'); - var openOverlay = function() { + var disableArrowKeys = function (e) { + var ar = [37, 38, 39, 40]; + if ($.inArray(e.keyCode, ar) >= 0) { + e.preventDefault(); + } + }; + + var openOverlay = function () { // show overlay window.__njg_el__ = '.djnjg-overlay .inner'; - $.get(visualizeUrl, function(html) { + $.get(visualizeUrl, function (html) { overlay.show(); inner.html(html); body.css('overflow', 'hidden'); inner.css('overflow', 'hidden'); - overlay.find('.close').click(function(e){ + overlay.find('.close').click(function (e) { e.preventDefault(); closeOverlay(); - }) - }) + }); + }); $(document).keydown(disableArrowKeys); }; var closeOverlay = function () { $(document).unbind('keydown', disableArrowKeys); inner.html(''); - overlay.hide() + overlay.hide(); body.attr('style', ''); }; - $('.visualizelink').click(function(e){ + $('.visualizelink').click(function (e) { openOverlay(); }); - $(document).keyup(function(e) { + $(document).keyup(function (e) { // ALT+P - if (e.altKey && e.which == 80) { + if (e.altKey && e.which === 80) { // unfocus any active input before proceeding $(document.activeElement).trigger('blur'); // corresonding raw value before proceding setTimeout(openOverlay, 15); - } - // ESC - else if (!e.ctrlKey && e.which == 27) { + } else if (!e.ctrlKey && e.which === 27) { + // ESC closeOverlay(); } }); - - var disableArrowKeys = function(e) { - var ar = new Array(37, 38, 39, 40); - if ($.inArray(e.keyCode, ar)>=0){ - e.preventDefault(); - } - } });