From 82b50fc2f16a4f85b50939f2d20074dc3c99c62d Mon Sep 17 00:00:00 2001 From: Paal Joergensen Date: Tue, 23 Oct 2018 11:25:46 +0200 Subject: [PATCH] Fix code style --- js/h5p-confirmation-dialog.js | 2 +- js/h5p-content-type.js | 2 +- js/h5p-content-upgrade-process.js | 8 ++++---- js/h5p-content-upgrade-worker.js | 1 + js/h5p-content-upgrade.js | 2 +- js/h5p-data-view.js | 2 +- js/h5p-event-dispatcher.js | 8 ++++---- js/h5p-library-details.js | 29 +++++++++++++++-------------- js/h5p-library-list.js | 4 ++-- js/h5p-resizer.js | 4 ++-- js/h5p-utils.js | 5 +++-- js/h5p-x-api-event.js | 8 ++++---- js/h5p-x-api.js | 2 +- js/h5p.js | 31 ++++++++++++++++--------------- 14 files changed, 56 insertions(+), 52 deletions(-) diff --git a/js/h5p-confirmation-dialog.js b/js/h5p-confirmation-dialog.js index a6dd998..fa623c6 100644 --- a/js/h5p-confirmation-dialog.js +++ b/js/h5p-confirmation-dialog.js @@ -351,7 +351,7 @@ H5P.ConfirmationDialog = (function (EventDispatcher) { * * @param {number|null} minHeight */ - this.setViewPortMinimumHeight = function(minHeight) { + this.setViewPortMinimumHeight = function (minHeight) { var container = document.querySelector('.h5p-container') || document.body; container.style.minHeight = (typeof minHeight === 'number') ? (minHeight + 'px') : minHeight; }; diff --git a/js/h5p-content-type.js b/js/h5p-content-type.js index 8be8fcd..47c4d21 100644 --- a/js/h5p-content-type.js +++ b/js/h5p-content-type.js @@ -11,7 +11,7 @@ * @class * @augments H5P.EventDispatcher */ -H5P.ContentType = function (isRootLibrary, library) { +H5P.ContentType = function (isRootLibrary) { function ContentType() {} diff --git a/js/h5p-content-upgrade-process.js b/js/h5p-content-upgrade-process.js index d50a09c..e683902 100644 --- a/js/h5p-content-upgrade-process.js +++ b/js/h5p-content-upgrade-process.js @@ -127,10 +127,10 @@ H5P.ContentUpgradeProcess = (function (Version) { }, {metadata: metadata}); } catch (err) { - if (console && console.log) { - console.log("Error", err.stack); - console.log("Error", err.name); - console.log("Error", err.message); + if (console && console.error) { + console.error("Error", err.stack); + console.error("Error", err.name); + console.error("Error", err.message); } next(err); } diff --git a/js/h5p-content-upgrade-worker.js b/js/h5p-content-upgrade-worker.js index 26ad038..3507a35 100644 --- a/js/h5p-content-upgrade-worker.js +++ b/js/h5p-content-upgrade-worker.js @@ -1,3 +1,4 @@ +/* global importScripts */ var H5P = H5P || {}; importScripts('h5p-version.js', 'h5p-content-upgrade-process.js'); diff --git a/js/h5p-content-upgrade.js b/js/h5p-content-upgrade.js index 9c1e4ce..bb5244a 100644 --- a/js/h5p-content-upgrade.js +++ b/js/h5p-content-upgrade.js @@ -1,4 +1,4 @@ -/*jshint -W083 */ +/* global H5PAdminIntegration H5PUtils */ (function ($, Version) { var info, $container, librariesCache = {}, scriptsCache = {}; diff --git a/js/h5p-data-view.js b/js/h5p-data-view.js index 89080e0..2f708f8 100644 --- a/js/h5p-data-view.js +++ b/js/h5p-data-view.js @@ -1,3 +1,4 @@ +/* global H5PUtils */ var H5PDataView = (function ($) { /** @@ -198,7 +199,6 @@ var H5PDataView = (function ($) { * @param number col ID of column */ H5PDataView.prototype.createFacets = function (input, col) { - var self = this; var facets = ''; if (input instanceof Array) { diff --git a/js/h5p-event-dispatcher.js b/js/h5p-event-dispatcher.js index a6707b4..2027cf7 100644 --- a/js/h5p-event-dispatcher.js +++ b/js/h5p-event-dispatcher.js @@ -10,7 +10,7 @@ var H5P = window.H5P = window.H5P || {}; * @param {boolean} [extras.bubbles] * @param {boolean} [extras.external] */ -H5P.Event = function(type, data, extras) { +H5P.Event = function (type, data, extras) { this.type = type; this.data = data; var bubbles = false; @@ -34,7 +34,7 @@ H5P.Event = function(type, data, extras) { /** * Prevent this event from bubbling up to parent */ - this.preventBubbling = function() { + this.preventBubbling = function () { bubbles = false; }; @@ -44,7 +44,7 @@ H5P.Event = function(type, data, extras) { * @returns {boolean} * true if bubbling false otherwise */ - this.getBubbles = function() { + this.getBubbles = function () { return bubbles; }; @@ -54,7 +54,7 @@ H5P.Event = function(type, data, extras) { * @returns {boolean} * true if external and not already scheduled, otherwise false */ - this.scheduleForExternal = function() { + this.scheduleForExternal = function () { if (external && !scheduledForExternal) { scheduledForExternal = true; return true; diff --git a/js/h5p-library-details.js b/js/h5p-library-details.js index 77d366b..b5ee012 100644 --- a/js/h5p-library-details.js +++ b/js/h5p-library-details.js @@ -1,4 +1,5 @@ -var H5PLibraryDetails= H5PLibraryDetails || {}; +/* global H5PAdminIntegration H5PUtils */ +var H5PLibraryDetails = H5PLibraryDetails || {}; (function ($) { @@ -68,7 +69,7 @@ var H5PLibraryDetails= H5PLibraryDetails || {}; */ H5PLibraryDetails.createContentTable = function () { // Remove it if it exists: - if(H5PLibraryDetails.$contentTable) { + if (H5PLibraryDetails.$contentTable) { H5PLibraryDetails.$contentTable.remove(); } @@ -77,10 +78,10 @@ var H5PLibraryDetails= H5PLibraryDetails || {}; var i = (H5PLibraryDetails.currentPage*H5PLibraryDetails.PAGER_SIZE); var lastIndex = (i+H5PLibraryDetails.PAGER_SIZE); - if(lastIndex > H5PLibraryDetails.currentContent.length) { + if (lastIndex > H5PLibraryDetails.currentContent.length) { lastIndex = H5PLibraryDetails.currentContent.length; } - for(; i' + content.title + ''])); } @@ -97,7 +98,7 @@ var H5PLibraryDetails= H5PLibraryDetails || {}; H5PLibraryDetails.$next = $(''); H5PLibraryDetails.$previous.on('click', function () { - if(H5PLibraryDetails.$previous.hasClass('disabled')) { + if (H5PLibraryDetails.$previous.hasClass('disabled')) { return; } @@ -107,7 +108,7 @@ var H5PLibraryDetails= H5PLibraryDetails || {}; }); H5PLibraryDetails.$next.on('click', function () { - if(H5PLibraryDetails.$next.hasClass('disabled')) { + if (H5PLibraryDetails.$next.hasClass('disabled')) { return; } @@ -127,7 +128,7 @@ var H5PLibraryDetails= H5PLibraryDetails || {}; H5PLibraryDetails.$pagerInfo.hide(); // User has updated the pageNumber - var pageNumerUpdated = function() { + var pageNumerUpdated = function () { var newPageNum = $gotoInput.val()-1; var intRegex = /^\d+$/; @@ -135,7 +136,7 @@ var H5PLibraryDetails= H5PLibraryDetails || {}; H5PLibraryDetails.$pagerInfo.css({display: 'inline-block'}); // Check if input value is valid, and that it has actually changed - if(!(intRegex.test(newPageNum) && newPageNum >= 0 && newPageNum < H5PLibraryDetails.getNumPages() && newPageNum != H5PLibraryDetails.currentPage)) { + if (!(intRegex.test(newPageNum) && newPageNum >= 0 && newPageNum < H5PLibraryDetails.getNumPages() && newPageNum != H5PLibraryDetails.currentPage)) { return; } @@ -185,7 +186,7 @@ var H5PLibraryDetails= H5PLibraryDetails || {}; H5PLibraryDetails.updatePager = function () { H5PLibraryDetails.$pagerInfo.css({display: 'inline-block'}); - if(H5PLibraryDetails.getNumPages() > 0) { + if (H5PLibraryDetails.getNumPages() > 0) { var message = H5PUtils.translateReplace(H5PLibraryDetails.library.translations.pageXOfY, { '$x': (H5PLibraryDetails.currentPage+1), '$y': H5PLibraryDetails.getNumPages() @@ -211,7 +212,7 @@ var H5PLibraryDetails= H5PLibraryDetails || {}; var searchString = $('.h5p-content-search > input').val(); // If search string same as previous, just do nothing - if(H5PLibraryDetails.currentFilter === searchString) { + if (H5PLibraryDetails.currentFilter === searchString) { return; } @@ -219,7 +220,7 @@ var H5PLibraryDetails= H5PLibraryDetails || {}; // If empty search, use the complete list H5PLibraryDetails.currentContent = H5PLibraryDetails.library.content; } - else if(H5PLibraryDetails.filterCache[searchString]) { + else if (H5PLibraryDetails.filterCache[searchString]) { // If search is cached, no need to filter H5PLibraryDetails.currentContent = H5PLibraryDetails.filterCache[searchString]; } @@ -227,10 +228,10 @@ var H5PLibraryDetails= H5PLibraryDetails || {}; var listToFilter = H5PLibraryDetails.library.content; // Check if we can filter the already filtered results (for performance) - if(searchString.length > 1 && H5PLibraryDetails.currentFilter === searchString.substr(0, H5PLibraryDetails.currentFilter.length)) { + if (searchString.length > 1 && H5PLibraryDetails.currentFilter === searchString.substr(0, H5PLibraryDetails.currentFilter.length)) { listToFilter = H5PLibraryDetails.currentContent; } - H5PLibraryDetails.currentContent = $.grep(listToFilter, function(content) { + H5PLibraryDetails.currentContent = $.grep(listToFilter, function (content) { return content.title && content.title.match(new RegExp(searchString, 'i')); }); } @@ -256,7 +257,7 @@ var H5PLibraryDetails= H5PLibraryDetails || {}; $('input', H5PLibraryDetails.$search).on('change keypress paste input', function () { // Here we start the filtering // We wait at least 500 ms after last input to perform search - if(inputTimer) { + if (inputTimer) { clearTimeout(inputTimer); } diff --git a/js/h5p-library-list.js b/js/h5p-library-list.js index 1ee1bc8..344b736 100644 --- a/js/h5p-library-list.js +++ b/js/h5p-library-list.js @@ -1,4 +1,4 @@ -/*jshint multistr: true */ +/* global H5PAdminIntegration H5PUtils */ var H5PLibraryList = H5PLibraryList || {}; (function ($) { @@ -25,7 +25,7 @@ var H5PLibraryList = H5PLibraryList || {}; */ H5PLibraryList.createLibraryList = function (libraries) { var t = H5PAdminIntegration.l10n; - if(libraries.listData === undefined || libraries.listData.length === 0) { + if (libraries.listData === undefined || libraries.listData.length === 0) { return $('
' + t.NA + '
'); } diff --git a/js/h5p-resizer.js b/js/h5p-resizer.js index 772cafd..4ed65e0 100644 --- a/js/h5p-resizer.js +++ b/js/h5p-resizer.js @@ -21,7 +21,7 @@ iframe.style.width = '100%'; // Tell iframe that it needs to resize when our window resizes - var resize = function (event) { + var resize = function () { if (iframe.contentWindow) { // Limit resize calls to avoid flickering respond('resize'); @@ -64,7 +64,7 @@ * @param {Object} data Payload * @param {Function} respond Send a response to the iframe */ - actionHandlers.resize = function (iframe, data, respond) { + actionHandlers.resize = function (iframe, data) { // Resize iframe so all content is visible. Use scrollHeight to make sure we get everything iframe.style.height = data.scrollHeight + 'px'; }; diff --git a/js/h5p-utils.js b/js/h5p-utils.js index f47d1b6..b5aa333 100644 --- a/js/h5p-utils.js +++ b/js/h5p-utils.js @@ -1,3 +1,4 @@ +/* global H5PAdminIntegration*/ var H5PUtils = H5PUtils || {}; (function ($) { @@ -9,7 +10,7 @@ var H5PUtils = H5PUtils || {}; H5PUtils.createTable = function (headers) { var $table = $('
'); - if(headers) { + if (headers) { var $thead = $(''); var $tr = $(''); @@ -44,7 +45,7 @@ var H5PUtils = H5PUtils || {}; }; } - $('', value).appendTo($tr); + $('', value).appendTo($tr); }); return $tr; diff --git a/js/h5p-x-api-event.js b/js/h5p-x-api-event.js index 4cec937..e012ac1 100644 --- a/js/h5p-x-api-event.js +++ b/js/h5p-x-api-event.js @@ -217,7 +217,7 @@ H5P.XAPIEvent.prototype.setActor = function () { * @returns {number} * The max score, or null if not defined */ -H5P.XAPIEvent.prototype.getMaxScore = function() { +H5P.XAPIEvent.prototype.getMaxScore = function () { return this.getVerifiedStatementValue(['result', 'score', 'max']); }; @@ -227,7 +227,7 @@ H5P.XAPIEvent.prototype.getMaxScore = function() { * @returns {number} * The score, or null if not defined */ -H5P.XAPIEvent.prototype.getScore = function() { +H5P.XAPIEvent.prototype.getScore = function () { return this.getVerifiedStatementValue(['result', 'score', 'raw']); }; @@ -256,7 +256,7 @@ H5P.XAPIEvent.prototype.getContentXAPIId = function (instance) { H5P.XAPIEvent.prototype.isFromChild = function () { var parentId = this.getVerifiedStatementValue(['context', 'contextActivities', 'parent', 0, 'id']); return !parentId || parentId.indexOf('subContentId') === -1; -} +}; /** * Figure out if a property exists in the statement and return it @@ -267,7 +267,7 @@ H5P.XAPIEvent.prototype.isFromChild = function () { * @returns {*} * The value of the property if it is set, null otherwise. */ -H5P.XAPIEvent.prototype.getVerifiedStatementValue = function(keys) { +H5P.XAPIEvent.prototype.getVerifiedStatementValue = function (keys) { var val = this.data.statement; for (var i = 0; i < keys.length; i++) { if (val[keys[i]] === undefined) { diff --git a/js/h5p-x-api.js b/js/h5p-x-api.js index 8a27eb9..66971cd 100644 --- a/js/h5p-x-api.js +++ b/js/h5p-x-api.js @@ -92,7 +92,7 @@ H5P.EventDispatcher.prototype.triggerXAPIScored = function (score, maxScore, ver this.trigger(event); }; -H5P.EventDispatcher.prototype.setActivityStarted = function() { +H5P.EventDispatcher.prototype.setActivityStarted = function () { if (this.activityStartTime === undefined) { // Don't trigger xAPI events in the editor if (this.contentId !== undefined && diff --git a/js/h5p.js b/js/h5p.js index 1f9d052..7f63c1f 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -89,7 +89,7 @@ H5P.init = function (target) { } // H5Ps added in normal DIV. - var $containers = H5P.jQuery('.h5p-content:not(.h5p-initialized)', target).each(function () { + H5P.jQuery('.h5p-content:not(.h5p-initialized)', target).each(function () { var $element = H5P.jQuery(this).addClass('h5p-initialized'); var $container = H5P.jQuery('
').appendTo($element); var contentId = $element.data('content-id'); @@ -301,7 +301,7 @@ H5P.init = function (target) { }); // When resize has been prepared tell parent window to resize - H5P.communicator.on('resizePrepared', function (data) { + H5P.communicator.on('resizePrepared', function () { H5P.communicator.send('resize', { scrollHeight: document.body.scrollHeight }); @@ -494,7 +494,7 @@ H5P.fullScreen = function ($element, instance, exitCallback, body, forceSemiFull } var $container = $element; - var $classes, $iframe; + var $classes, $iframe, $body; if (body === undefined) { $body = H5P.$body; } @@ -1089,7 +1089,7 @@ H5P.findCopyrights = function (info, parameters, contentId, extras) { } } - function buildFromMetadata (data, name, contentId) { + function buildFromMetadata(data, name, contentId) { if (data.metadata) { const metadataCopyrights = H5P.buildMetadataCopyrights(data.metadata, name); if (metadataCopyrights !== undefined) { @@ -1105,12 +1105,12 @@ H5P.findCopyrights = function (info, parameters, contentId, extras) { } }; -H5P.buildMetadataCopyrights = function (metadata, contentTypeName) { +H5P.buildMetadataCopyrights = function (metadata) { if (metadata && metadata.license !== undefined && metadata.license !== 'U') { var dataset = { contentType: metadata.contentType, title: metadata.title, - author: (metadata.authors && metadata.authors.length > 0) ? metadata.authors.map(function(author) { + author: (metadata.authors && metadata.authors.length > 0) ? metadata.authors.map(function (author) { return (author.role) ? author.name + ' (' + author.role + ')' : author.name; }).join(', ') : undefined, source: metadata.source, @@ -1118,7 +1118,7 @@ H5P.buildMetadataCopyrights = function (metadata, contentTypeName) { license: metadata.license, version: metadata.licenseVersion, licenseExtras: metadata.licenseExtras, - changes: (metadata.changes && metadata.changes.length > 0) ? metadata.changes.map(function(change) { + changes: (metadata.changes && metadata.changes.length > 0) ? metadata.changes.map(function (change) { return change.log + (change.author ? ', ' + change.author : '') + (change.date ? ', ' + change.date : ''); }).join(' / ') : undefined }; @@ -1181,10 +1181,10 @@ H5P.openEmbedDialog = function ($element, embedCode, resizeCode, size) { updateEmbed(); // Select text and expand textareas - $dialog.find('.h5p-embed-code-container').each(function(index, value) { - H5P.jQuery(this).css('height', this.scrollHeight + 'px').focus(function() { - H5P.jQuery(this).select(); - }); + $dialog.find('.h5p-embed-code-container').each(function () { + H5P.jQuery(this).css('height', this.scrollHeight + 'px').focus(function () { + H5P.jQuery(this).select(); + }); }); $dialog.find('.h5p-embed-code-container').eq(0).select(); positionInner(); @@ -1201,7 +1201,7 @@ H5P.openEmbedDialog = function ($element, embedCode, resizeCode, size) { $expander.addClass('h5p-open').text(H5P.t('hideAdvanced')); $content.show(); } - $dialog.find('.h5p-embed-code-container').each(function(index, value) { + $dialog.find('.h5p-embed-code-container').each(function () { H5P.jQuery(this).css('height', this.scrollHeight + 'px'); }); positionInner(); @@ -1614,7 +1614,8 @@ H5P.Coords = function (x, y, w, h) { this.y = x.y; this.w = x.w; this.h = x.h; - } else { + } + else { if (x !== undefined) { this.x = x; } @@ -1870,7 +1871,7 @@ H5P.on = function (instance, eventType, handler) { * @returns {string} UUID */ H5P.createUUID = function () { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(char) { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (char) { var random = Math.random()*16|0, newChar = char === 'x' ? random : (random&0x3|0x8); return newChar.toString(16); }); @@ -2098,7 +2099,7 @@ H5P.createTitle = function (rawTitle, maxLength) { } preloadedData[options.subContentId][dataId] = data; - contentUserDataAjax(contentId, dataId, options.subContentId, function (error, data) { + contentUserDataAjax(contentId, dataId, options.subContentId, function (error) { if (options.errorCallback && error) { options.errorCallback(error); }