Skip to content
Permalink
Browse files

More dead code removal

- No matches for showPassword and showPasswords - can thus remove jquery-showpassword
and initPassword
- no matches for .scrollTo (only scrollTop)
- no matches for .tap
- bookCovers is only used in unused templates and thus removed
- no matches for closePop
- no matches for $.fn.CustomFadeTo
- do not export functions to window function that are not used in templates
- replace eslint-disable-next-line no-undef with import statements

Additional change:
- Document customFadeIn and customFadeOut usages
  • Loading branch information...
jdlrobson authored and cdrini committed Sep 6, 2019
1 parent 788a8fb commit ce208e07eff8e5a6ddadecdc8534fbc570c2307a
@@ -19,7 +19,7 @@
var getAvailabilityV2, updateBookAvailability, updateWorkAvailability;
/* eslint-enable no-unused-vars */

function init() {
function initAvailability() {
var btnClassName = 'cta-btn';
// pages still relying on legacy client-side availability checking
var whitelist = {
@@ -243,5 +243,8 @@ function init() {
}
}

init();
export { getAvailabilityV2, updateBookAvailability, updateWorkAvailability };
initAvailability();

export {
updateWorkAvailability
};
@@ -4,8 +4,6 @@ import 'jquery-migrate';
import '../../../../vendor/js/jquery-ui/jquery-ui-1.12.1.min.js';
// For dialog boxes (e.g. add to list)
import '../../../../vendor/js/colorbox/1.5.14.js';
// jquery-show-password#1.0 not on npm, no longer getting worked on
import '../../../../vendor/js/jquery-showpassword/jquery.showpassword.js';
// jquery.form#2.36 not on npm, no longer getting worked on
import '../../../../vendor/js/jquery-form/jquery.form.js';
// jquery-validate#1.6 not on npm
@@ -20,52 +18,46 @@ import '../../../../vendor/js/flot/jquery.flot.stack.js';
import '../../../../vendor/js/flot/jquery.flot.pie.js';
import { validateEmail, validatePassword } from './account.js';
import autocompleteInit from './autocomplete';
// Used only by the openlibrary/templates/books/edit/addfield.html template
import addNewFieldInit from './add_new_field';
import automaticInit from './automatic';
import { getAvailabilityV2,
updateBookAvailability, updateWorkAvailability } from './availability';
import bookReaderInit from './bookreader_direct';
import { ungettext, ugettext, sprintf } from './i18n';
import addFadeInFunctionsTojQuery from './jquery.customFade';
import jQueryRepeat from './jquery.repeat';
import './jquery.scrollTo';
import { enumerate, htmlquote, websafe, foreach, join, len, range } from './jsdef';
import { plot_minigraph, plot_tooltip_graph } from './plot';
import initAnalytics from './ol.analytics';
import init, { closePop, bookCovers, isScrolledIntoView } from './ol.js';
import init, { bookCovers } from './ol.js';
import * as Browser from './Browser';
import { commify } from './python';
import { Subject, urlencode, renderTag, slice } from './subjects';
import { Subject, urlencode, slice } from './subjects';
import Template from './template.js';
// Add $.fn.focusNextInputField, $.fn.ol_confirm_dialog, $.fn.tap
import { closePopup, initShowPasswords, truncate, cond } from './utils';
// Add $.fn.focusNextInputField, $.fn.ol_confirm_dialog
import { closePopup, truncate, cond } from './utils';
import initValidate from './validate';
import '../../../../static/css/js-all.less';
// polyfill Promise support for IE11
import Promise from 'promise-polyfill';

// Eventually we will export all these to a single global ol, but in the mean time
// we add them to the window object for backwards compatibility.
// Can be removed once removed from templates. noop function to avoid JS errors.
window.bookCovers = bookCovers;
window.closePop = closePop;
// closePopup used in openlibrary/templates/covers/saved.html
window.closePopup = closePopup;
window.commify = commify;
window.cond = cond;
window.enumerate = enumerate;
window.foreach = foreach;
window.getAvailabilityV2 = getAvailabilityV2;
window.isScrolledIntoView = isScrolledIntoView;
window.htmlquote = htmlquote;
window.len = len;
window.plot_tooltip_graph = plot_tooltip_graph;
window.plot_minigraph = plot_minigraph;
window.range = range;
window.renderTag = renderTag;
window.slice = slice;
window.sprintf = sprintf;
window.truncate = truncate;
window.updateBookAvailability = updateBookAvailability;
window.updateWorkAvailability = updateWorkAvailability;
window.urlencode = urlencode;
window.validateEmail = validateEmail;
window.validatePassword = validatePassword;
@@ -105,7 +97,6 @@ jQuery(function () {
jQueryRepeat($);
initAnalytics($);
init($);
initShowPasswords($);
// conditionally load functionality based on what's in the page
if (document.getElementsByClassName('editions-table--progressively-enhanced').length) {
import(/* webpackChunkName: "editions-table" */ './editions-table')
@@ -1,6 +1,7 @@
// FIX IE FADE PROBLEMS
// COURTESY: Ben Novakovic http://blog.bmn.name/2008/03/jquery-fadeinfadeout-ie-cleartype-glitch/
export default function addFadeInFunctionsTojQuery($) {
// books/edit/edition.html, publishers/view.html and subjects.html
$.fn.customFadeIn = function(speed, callback) {
$(this).fadeIn(speed, function() {
if(jQuery.browser.msie)
@@ -9,6 +10,8 @@ export default function addFadeInFunctionsTojQuery($) {
callback();
});
};
// books/edit/edition.html
// covers/change.html
$.fn.customFadeOut = function(speed, callback) {
$(this).fadeOut(speed, function() {
if(jQuery.browser.msie)
@@ -17,24 +20,4 @@ export default function addFadeInFunctionsTojQuery($) {
callback();
});
};
$.fn.CustomFadeTo = function(options) {
if (options)
$(this)
.show()
.each(function() {
if (jQuery.browser.msie) {
$(this).attr('oBgColor', $(this).css('background-color'));
$(this).css({ 'background-color': (options.bgColor ? options.bgColor : '#fff') })
}
})
.fadeTo(options.speed, options.opacity, function() {
if (jQuery.browser.msie) {
if (options.opacity == 0 || options.opacity == 1) {
$(this).css({ 'background-color': $(this).attr('oBgColor') }).removeAttr('oBgColor');
$(this).get(0).style.removeAttribute('filter');
}
}
if (options.callback != undefined) options.callback();
});
};
}
@@ -8,6 +8,7 @@ import Template from './template'
export default function($){
// For v2 and v1 page support. Can be removed when no v1 support needed
var isOldJQuery = $('body').on === undefined;
// used in books/edit/exercpt, books/edit/web and books/edit/edition
$.fn.repeat = function(options) {
var addSelector, removeSelector, id, elems, t, code,
nextRowId;

This file was deleted.

@@ -19,8 +19,6 @@ export default function initAnalytics() {
'ea':values['action'],
'el':location.pathname,
'ev':1,
// startTime is defined in openlibrary\plugins\openlibrary\js\ol.js
// eslint-disable-next-line no-undef
'loadtime':(endTime.getTime() - startTime.getTime()),
'cache_bust':Math.random()
});
@@ -1,7 +1,8 @@
import { debounce } from './nonjquery_utils.js';
import * as Browser from './Browser';
import { updateWorkAvailability } from './availability';

export function isScrolledIntoView(elem) {
function isScrolledIntoView(elem) {
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop, elemBottom;
@@ -15,21 +16,14 @@ export function isScrolledIntoView(elem) {

// BOOK COVERS
// used in templates/work_search.html
// I suspect this is dead code. See #2397.
export function bookCovers(){
$('img.cover').error(function(){
$(this).closest('.SRPCover').hide();
$(this).closest('.coverMagic').find('.SRPCoverBlank').show();
});
}

// CLOSE POP-UP FROM IFRAME
// used in templates/covers/saved.html
export function closePop(){
$('#popClose').click(function(){
parent.$.fn.colorbox.close();
});
}

export default function init(){
var $searchResults = $('header#header-bar .search-component ul.search-results');
var $searchInput = $('header#header-bar .search-component .search-bar-input input[type="text"]');
@@ -196,8 +190,6 @@ export default function init(){
$('.search-bar-input [type=text]').val(q);
}

// updateWorkAvailability is defined in openlibrary\openlibrary\plugins\openlibrary\js\availability.js
// eslint-disable-next-line no-undef
updateWorkAvailability();

$(document).on('submit','.trigger', function(e) {
@@ -31,12 +31,6 @@ $.fn.ol_confirm_dialog = function(callback, options) {
this.dialog(options);
}

// Tap into jquery chain
$.fn.tap = function(callback) {
callback(this);
return this;
}

// closes active popup
// used in templates/covers/saved.html
export function closePopup() {
@@ -62,49 +56,3 @@ export function cond(predicate, true_value, false_value) {
}
}

// showPasswords implemented by Lance
export function initShowPasswords($) {
$.fn.extend({
showPasswords: function(f) {
return this.each(function() {
var c = function(a) {
var b;
a = $(a);
b = $('<input type=\'text\' />');
b.insertAfter(a).attr({
'class': a.attr('class'),
'style': a.attr('style')
});
return b
};
var d = function($this, $that) {
$that.val($this.val())
};
var e = function() {
if ($checkbox.is(':checked')) {
d($this, $clone);
$clone.show();
$this.hide()
} else {
d($clone, $this);
$clone.hide();
$this.show()
}
};
var $clone = c(this),
$this = $(this),
$checkbox = $(f);
$checkbox.click(function() {
e()
});
$this.keyup(function() {
d($this, $clone)
});
$clone.keyup(function() {
d($clone, $this)
});
e()
})
}
})
}
@@ -1,3 +1,5 @@
import { ungettext, ugettext } from './i18n';

/**
* jQuery plugin to add form validations.
*
@@ -28,9 +30,7 @@ export default function initValidate() {
);

$.validator.messages.required = '';
// _ is defined in openlibrary\plugins\openlibrary\js\i18n.js
// eslint-disable-next-line no-undef
$.validator.messages.email = _('Are you sure that\'s an email address?');
$.validator.messages.email = ugettext('Are you sure that\'s an email address?');


$.fn.ol_validate = function(options) {
@@ -42,8 +42,6 @@ export default function initValidate() {
var errors = validator.numberOfInvalids();
var message;
if (errors) {
// ungettext is defined in openlibrary\plugins\openlibrary\js\i18n.js
// eslint-disable-next-line no-undef
message = ungettext(
'Hang on... you missed a bit. It\'s highlighted below.',
'Hang on...you missed some fields. They\'re highlighted below.',

This file was deleted.

This file was deleted.

0 comments on commit ce208e0

Please sign in to comment.
You can’t perform that action at this time.