Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Fix Bug 1401291, ensures main and moz-jquery-plugins pass linting
Browse files Browse the repository at this point in the history
  • Loading branch information
schalkneethling committed Nov 27, 2017
1 parent b2f071a commit 6185b99
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
5 changes: 0 additions & 5 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
kuma/static/js/libs/*
kuma/static/js/prism-mdn/*
kuma/wiki/jinja2/wiki/ckeditor_config.js

!kuma/static/js/libs/mozilla.cookiehelper.js
!kuma/static/js/libs/mozilla.dnthelper.js
!kuma/static/js/libs/mozilla.trafficcop.js
!kuma/static/js/libs/tag-it.js
42 changes: 25 additions & 17 deletions kuma/static/js/main.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
(function(win, doc, $) {
'use strict';

/*
Track clientside errors
*/
/**
* Track clientside errors
*/
mdn.analytics.trackClientErrors();

/*
Feature detection
*/

/**
* Feature detection
*/
win.mdn.features.localStorage = (function() {
var uid = new Date;
var result;
try {
localStorage.setItem(uid, uid);
result = localStorage.getItem(uid) == uid;
result = localStorage.getItem(uid) === uid.toString();
localStorage.removeItem(uid);
return result;
} catch (exception) {
Expand Down Expand Up @@ -57,9 +56,8 @@
var $searchWrap = $nav.find('.search-wrap');
var $input = $searchWrap.find('input');
var $searchTrigger = $searchWrap.find('.search-trigger');
var placeholder = $input.attr('placeholder');

$searchTrigger.on('click', function(e) {
$searchTrigger.on('click', function() {
$input.get(0).focus();
});

Expand All @@ -76,8 +74,14 @@
return;
}

if(e) e.preventDefault();
if(timeout) clearTimeout(timeout);
if(e) {
e.preventDefault();
}

if(timeout) {
clearTimeout(timeout);
}

timeout = setTimeout(function() {
if(isAdd) {
$navItems.fadeOut(100, function() {
Expand Down Expand Up @@ -119,7 +123,9 @@
var $this = $(this);

// Allow for a special CSS class to prevent this functionality
if($this.hasClass('nodisable')) return;
if($this.hasClass('nodisable')) {
return;
}

if ($this.data(disabled)) {
ev.preventDefault();
Expand Down Expand Up @@ -157,11 +163,11 @@
// url could be relative or scheme relative or absolute
var host = doc.location.host; // host + port
var protocol = doc.location.protocol;
var sr_origin = '//' + host;
var origin = protocol + sr_origin;
var srOrigin = '//' + host;
var origin = protocol + srOrigin;
// Allow absolute or scheme relative URLs to same origin
return (url === origin || url.slice(0, origin.length + 1) === origin + '/') ||
(url === sr_origin || url.slice(0, sr_origin.length + 1) === sr_origin + '/') ||
(url === srOrigin || url.slice(0, srOrigin.length + 1) === srOrigin + '/') ||
// or any other URL that isn't scheme relative or absolute i.e relative.
!(/^(\/\/|http:|https:).*/.test(url));
}
Expand All @@ -185,7 +191,9 @@
});
$('#skip-main').each(function() { // Only one, so using each as closure
var id = this.href.split('#')[1];
if(id) $('#' + id).attr('role', 'main');
if(id) {
$('#' + id).attr('role', 'main');
}
});

/*
Expand Down
27 changes: 17 additions & 10 deletions kuma/static/js/moz-jquery-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
// Shows an 'invalid' style if something good isn't picked
requireValidOption: false,
// Callback for selection; true selection or 'silent' selection
onSelect: function(selectionObj, isSilent){},
onSelect: function(selectionObj, isSilent){}, // eslint-disable-line no-unused-vars
// Callback for when a selection is deselected via this plugin
onDeselect: function(oldSelection){},
onDeselect: function(oldSelection){}, // eslint-disable-line no-unused-vars
// URL to hit to retrieve results
autocompleteURL: '',
// Element to style and add 'valid' and 'invalid' classes to
Expand Down Expand Up @@ -117,10 +117,12 @@
$.ui.autocomplete.prototype._create.call(this);

// Create the cache
if(!this.cache) var cache = this.cache = {
terms: {},
keys: {}
};
if(!this.cache) {
var cache = this.cache = {
terms: {},
keys: {}
};
}

// Keep focus state
this.isFocused = false;
Expand All @@ -141,7 +143,6 @@
this.styleElement = $(this.options.styleElement || this.element);

// Set the 'source' method -- the one that executes searches or returns the filtered static array
var oldSource = this.source;
this.source = $.isArray(this.options.source) ?
function(request, response) {
assignLabel(self.options.source);
Expand Down Expand Up @@ -200,9 +201,15 @@
var selection = self.selection = ui.item;
if(selection.value !== undefined) {
// Call the select method if present
if(select) select.call(self, event, ui);
if(select) {
select.call(self, event, ui);
}

// Set the INPUT element's value to the item value
if(selection) self.element.val(selection.value);
if(selection) {
self.element.val(selection.value);
}

// Add the valid class
self.updateStyles(true);
// Set the title attribute
Expand Down Expand Up @@ -292,7 +299,7 @@
var valCheck = function() {
var box = $input[0];
if(box.value === placeholder) {
box.value = '';
box.value = '';
}
};

Expand Down

0 comments on commit 6185b99

Please sign in to comment.